@causyne/agent 1.20.118 → 1.20.121
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/errorClassifier.js +113 -0
- package/src/agent/errorClassifier.ts +161 -0
- package/src/agent/promptIntent.js +200 -0
- package/src/agent/promptIntent.ts +203 -0
- package/src/agent/toolArgValidator.js +97 -0
- package/src/agent/toolArgValidator.ts +112 -0
- package/src/agentLoop.js +51 -351
- package/src/agentLoop.ts +69 -363
- package/src/autoUpdate.js +111 -8
- package/src/autoUpdate.ts +144 -8
- package/src/browser/causyneBrowser.js +231 -136
- package/src/browser/causyneBrowser.ts +229 -140
- package/src/browser/searchProviders.js +41 -30
- package/src/browser/searchProviders.ts +24 -14
- package/src/browser/workspacePathSafety.js +50 -0
- package/src/browser/workspacePathSafety.ts +50 -0
- package/src/browser/workspacePreview.js +27 -4
- package/src/browser/workspacePreview.ts +28 -4
- package/src/cliMode.js +17 -3
- package/src/commands.js +15 -22
- package/src/config.js +42 -63
- package/src/configVault.js +204 -0
- package/src/configVault.ts +213 -0
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/creative/liveBridge.js +34 -1
- package/src/creative/liveBridge.ts +28 -1
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +304 -0
- package/src/headlessCli.ts +380 -0
- package/src/mcp/mcpClient.js +38 -11
- package/src/mcp/mcpClient.ts +44 -11
- package/src/mcp/mcpRegistry.js +2 -5
- package/src/mcp/mcpRegistry.ts +2 -5
- package/src/mcp/mcpSecurity.js +189 -0
- package/src/mcp/mcpSecurity.ts +190 -0
- package/src/observer/evidence.js +23 -0
- package/src/observer/evidence.ts +21 -0
- package/src/osKeychain.js +209 -0
- package/src/osKeychain.ts +245 -0
- package/src/providers/anthropic.js +61 -28
- package/src/providers/base.js +14 -0
- package/src/providers/byokHttp.js +354 -0
- package/src/providers/byokHttp.ts +454 -0
- package/src/providers/byokStream.js +657 -0
- package/src/providers/byokStream.ts +759 -0
- package/src/providers/dashscope-byok.js +47 -32
- package/src/providers/deepseek.js +43 -39
- package/src/providers/gemini.js +73 -38
- package/src/providers/moonshot.js +43 -33
- package/src/providers/muse.js +10 -10
- package/src/providers/ollama.js +46 -31
- package/src/providers/openai-compatible.js +57 -32
- package/src/providers/openrouter.js +77 -113
- package/src/providers/openrouter.ts +99 -118
- package/src/providers/qwen-byok.js +46 -23
- package/src/providers/toolContracts.js +9 -3
- package/src/providers/toolContracts.ts +9 -3
- package/src/providers/wireNormalizer.js +238 -0
- package/src/providers/wireNormalizer.ts +279 -0
- package/src/providers/xai.js +43 -33
- package/src/sandbox.js +77 -56
- package/src/sandboxPolicy.js +1208 -0
- package/src/sandboxPolicy.ts +1300 -0
- package/src/sessionJournal.js +47 -0
- package/src/sessionJournal.ts +49 -0
- package/src/tools/browserAutomator.js +13 -1
- package/src/tools/browserAutomator.ts +13 -0
- package/src/tools/creativeApps.js +2 -1
- package/src/tools/creativeApps.ts +2 -1
- package/src/tools/gameAssetFetcher.js +130 -26
- package/src/tools/gameAssetHarvester.js +80 -58
- package/src/tools/nativeEngine.js +1 -1
- package/src/tools/nativeEngine.ts +1 -1
- package/src/tools/osSandbox.js +473 -0
- package/src/tools/osSandbox.ts +554 -0
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/registry.js +13 -0
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +39 -6
- package/src/tools/sysRun.ts +53 -7
- package/src/tools/toolScanner.js +596 -140
- package/src/tools/toolScanner.ts +665 -147
- package/src/tools/toolSelfRepair.js +243 -114
- package/src/tools/toolSelfRepair.ts +262 -111
- package/src/tools/webFetch.js +161 -24
- package/src/tools/webFetch.ts +157 -22
- package/src/tools/webSearch.js +33 -4
- package/src/tools/webSearch.ts +27 -4
- package/src/tui/sessionPicker.js +132 -35
- package/src/tui/sessionPicker.ts +153 -32
- package/src/tui/sessionPickerView.js +277 -34
- package/src/tui/sessionPickerView.ts +328 -34
- package/src/tui/statusLine.js +3 -0
- package/src/tui/statusLine.ts +5 -0
- package/src/tui/workspaceIdentity.js +133 -0
- package/src/tui/workspaceIdentity.ts +146 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — Subprocess Environment Secret Isolation (CWE-526)
|
|
3
|
+
*
|
|
4
|
+
* Strips host LLM provider API keys, Causyne internal vault/auth secrets, and
|
|
5
|
+
* high-value cloud/registry secret credentials before spawning shell tools so
|
|
6
|
+
* prompt-injected shell commands or untrusted build scripts cannot exfiltrate
|
|
7
|
+
* ambient credentials via `env` / `printenv`.
|
|
8
|
+
*
|
|
9
|
+
* Developers who intentionally need a specific variable inside a subprocess
|
|
10
|
+
* (for example, running an integration test suite) can opt in via
|
|
11
|
+
* `CAUSYNE_PASSTHROUGH_ENV=VAR_A,VAR_B`. Internal Causyne vault/dev secrets
|
|
12
|
+
* remain permanently excluded from subprocesses.
|
|
13
|
+
*/
|
|
14
|
+
export const ALWAYS_BLOCKED_SUBPROCESS_ENV = new Set([
|
|
15
|
+
'CAUSYNE_VAULT_KEY',
|
|
16
|
+
'CAUSYNE_DEV_SECRET',
|
|
17
|
+
'CAUSYNE_DEV_TOKEN'
|
|
18
|
+
]);
|
|
19
|
+
export const SENSITIVE_EXACT_ENV_KEYS = new Set([
|
|
20
|
+
// LLM & AI provider API keys
|
|
21
|
+
'OPENAI_API_KEY',
|
|
22
|
+
'OPENAI_ADMIN_KEY',
|
|
23
|
+
'OPENAI_ORG_KEY',
|
|
24
|
+
'ANTHROPIC_API_KEY',
|
|
25
|
+
'CLAUDE_API_KEY',
|
|
26
|
+
'GEMINI_API_KEY',
|
|
27
|
+
'GOOGLE_API_KEY',
|
|
28
|
+
'GOOGLE_GENERATIVE_AI_API_KEY',
|
|
29
|
+
'OPENROUTER_API_KEY',
|
|
30
|
+
'DEEPSEEK_API_KEY',
|
|
31
|
+
'XAI_API_KEY',
|
|
32
|
+
'GROK_API_KEY',
|
|
33
|
+
'MOONSHOT_API_KEY',
|
|
34
|
+
'KIMI_API_KEY',
|
|
35
|
+
'DASHSCOPE_API_KEY',
|
|
36
|
+
'QWEN_API_KEY',
|
|
37
|
+
'MUSE_API_KEY',
|
|
38
|
+
'META_API_KEY',
|
|
39
|
+
'LLAMA_API_KEY',
|
|
40
|
+
'MISTRAL_API_KEY',
|
|
41
|
+
'COHERE_API_KEY',
|
|
42
|
+
'GROQ_API_KEY',
|
|
43
|
+
'TOGETHER_API_KEY',
|
|
44
|
+
'PERPLEXITY_API_KEY',
|
|
45
|
+
'FIREWORKS_API_KEY',
|
|
46
|
+
'CEREBRAS_API_KEY',
|
|
47
|
+
'SAMBANOVA_API_KEY',
|
|
48
|
+
'HUGGINGFACE_API_KEY',
|
|
49
|
+
'HF_TOKEN',
|
|
50
|
+
'HUGGING_FACE_HUB_TOKEN',
|
|
51
|
+
'REPLICATE_API_TOKEN',
|
|
52
|
+
'VOYAGE_API_KEY',
|
|
53
|
+
'ELEVENLABS_API_KEY',
|
|
54
|
+
'FAL_KEY',
|
|
55
|
+
'STABILITY_API_KEY',
|
|
56
|
+
'AZURE_OPENAI_API_KEY',
|
|
57
|
+
// Causyne internal auth / vault credentials
|
|
58
|
+
'CAUSYNE_API_KEY',
|
|
59
|
+
'CAUSYNE_AUTH_TOKEN',
|
|
60
|
+
'CAUSYNE_ACCESS_TOKEN',
|
|
61
|
+
'CAUSYNE_SECRET',
|
|
62
|
+
'CAUSYNE_VAULT_KEY',
|
|
63
|
+
'CAUSYNE_DEV_SECRET',
|
|
64
|
+
'CAUSYNE_DEV_TOKEN',
|
|
65
|
+
// Cloud, package registry, VCS, and infrastructure raw secrets
|
|
66
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
67
|
+
'AWS_SESSION_TOKEN',
|
|
68
|
+
'AWS_SECURITY_TOKEN',
|
|
69
|
+
'NPM_TOKEN',
|
|
70
|
+
'NODE_AUTH_TOKEN',
|
|
71
|
+
'YARN_NPM_AUTH_TOKEN',
|
|
72
|
+
'PYPI_API_TOKEN',
|
|
73
|
+
'TWINE_PASSWORD',
|
|
74
|
+
'CARGO_REGISTRY_TOKEN',
|
|
75
|
+
'RUBYGEMS_API_KEY',
|
|
76
|
+
'NUGET_API_KEY',
|
|
77
|
+
'GITHUB_TOKEN',
|
|
78
|
+
'GH_TOKEN',
|
|
79
|
+
'GITLAB_TOKEN',
|
|
80
|
+
'BITBUCKET_TOKEN',
|
|
81
|
+
'SLACK_BOT_TOKEN',
|
|
82
|
+
'SLACK_TOKEN',
|
|
83
|
+
'DISCORD_TOKEN',
|
|
84
|
+
'TELEGRAM_BOT_TOKEN',
|
|
85
|
+
'STRIPE_SECRET_KEY',
|
|
86
|
+
'STRIPE_API_KEY',
|
|
87
|
+
'SENDGRID_API_KEY',
|
|
88
|
+
'TWILIO_AUTH_TOKEN',
|
|
89
|
+
'DATABASE_PASSWORD',
|
|
90
|
+
'DB_PASSWORD',
|
|
91
|
+
'PGPASSWORD',
|
|
92
|
+
'MYSQL_PWD',
|
|
93
|
+
'REDIS_PASSWORD',
|
|
94
|
+
'DOCKER_PASSWORD',
|
|
95
|
+
'GCP_SERVICE_ACCOUNT_KEY',
|
|
96
|
+
'GOOGLE_APPLICATION_CREDENTIALS_JSON',
|
|
97
|
+
'CLOUDFLARE_API_TOKEN',
|
|
98
|
+
'VERCEL_TOKEN',
|
|
99
|
+
'NETLIFY_AUTH_TOKEN',
|
|
100
|
+
'FLY_API_TOKEN',
|
|
101
|
+
'DIGITALOCEAN_ACCESS_TOKEN',
|
|
102
|
+
'HEROKU_API_KEY',
|
|
103
|
+
'DATADOG_API_KEY',
|
|
104
|
+
'SENTRY_AUTH_TOKEN'
|
|
105
|
+
]);
|
|
106
|
+
const SENSITIVE_ENV_SUFFIXES = [
|
|
107
|
+
'_API_KEY',
|
|
108
|
+
'_SECRET_KEY',
|
|
109
|
+
'_PRIVATE_KEY',
|
|
110
|
+
'_ACCESS_SECRET',
|
|
111
|
+
'_AUTH_SECRET',
|
|
112
|
+
'_CLIENT_SECRET',
|
|
113
|
+
'_SIGNING_KEY',
|
|
114
|
+
'_ENCRYPTION_KEY',
|
|
115
|
+
'_MASTER_KEY',
|
|
116
|
+
'_VAULT_KEY',
|
|
117
|
+
'_SECRET_TOKEN',
|
|
118
|
+
'_ACCESS_TOKEN',
|
|
119
|
+
'_AUTH_TOKEN',
|
|
120
|
+
'_REFRESH_TOKEN'
|
|
121
|
+
];
|
|
122
|
+
/**
|
|
123
|
+
* Parses `CAUSYNE_PASSTHROUGH_ENV` (comma-separated exact variable names) into
|
|
124
|
+
* an uppercased allowlist while excluding permanently blocked internal keys.
|
|
125
|
+
*/
|
|
126
|
+
export function parsePassthroughAllowlist(env, extra) {
|
|
127
|
+
const allow = new Set();
|
|
128
|
+
const addEntry = (raw) => {
|
|
129
|
+
const trimmed = raw.trim().toUpperCase();
|
|
130
|
+
if (!trimmed || trimmed === '*')
|
|
131
|
+
return;
|
|
132
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(trimmed))
|
|
133
|
+
return;
|
|
134
|
+
allow.add(trimmed);
|
|
135
|
+
};
|
|
136
|
+
const envValue = env.CAUSYNE_PASSTHROUGH_ENV;
|
|
137
|
+
if (typeof envValue === 'string' && envValue.trim().length > 0) {
|
|
138
|
+
for (const part of envValue.split(',')) {
|
|
139
|
+
addEntry(part);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(extra)) {
|
|
143
|
+
for (const part of extra) {
|
|
144
|
+
if (typeof part === 'string')
|
|
145
|
+
addEntry(part);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return allow;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns true if an environment variable name represents a secret credential
|
|
152
|
+
* that must be stripped from shell subprocesses by default.
|
|
153
|
+
*/
|
|
154
|
+
export function isSensitiveEnvKey(key) {
|
|
155
|
+
if (typeof key !== 'string' || key.length === 0)
|
|
156
|
+
return false;
|
|
157
|
+
const upper = key.toUpperCase();
|
|
158
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(upper))
|
|
159
|
+
return true;
|
|
160
|
+
if (SENSITIVE_EXACT_ENV_KEYS.has(upper))
|
|
161
|
+
return true;
|
|
162
|
+
if (upper.startsWith('CAUSYNE_')) {
|
|
163
|
+
if (upper.includes('KEY') ||
|
|
164
|
+
upper.includes('TOKEN') ||
|
|
165
|
+
upper.includes('SECRET') ||
|
|
166
|
+
upper.includes('PASSWORD') ||
|
|
167
|
+
upper.includes('CREDENTIAL')) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const suffix of SENSITIVE_ENV_SUFFIXES) {
|
|
172
|
+
if (upper.endsWith(suffix))
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns a copy of `baseEnv` (default `process.env`) with sensitive API keys
|
|
179
|
+
* and secrets removed unless explicitly listed in `CAUSYNE_PASSTHROUGH_ENV` or
|
|
180
|
+
* `options.passthrough`. Internal vault/dev keys are never passed through.
|
|
181
|
+
*/
|
|
182
|
+
export function sanitizeSubprocessEnv(baseEnv, options) {
|
|
183
|
+
const source = baseEnv ?? process.env;
|
|
184
|
+
const allowlist = parsePassthroughAllowlist(source, options?.passthrough);
|
|
185
|
+
const sanitized = {};
|
|
186
|
+
for (const [key, value] of Object.entries(source)) {
|
|
187
|
+
if (value === undefined)
|
|
188
|
+
continue;
|
|
189
|
+
const upper = key.toUpperCase();
|
|
190
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(upper))
|
|
191
|
+
continue;
|
|
192
|
+
if (isSensitiveEnvKey(key) && !allowlist.has(upper))
|
|
193
|
+
continue;
|
|
194
|
+
sanitized[key] = value;
|
|
195
|
+
}
|
|
196
|
+
return sanitized;
|
|
197
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — Subprocess Environment Secret Isolation (CWE-526)
|
|
3
|
+
*
|
|
4
|
+
* Strips host LLM provider API keys, Causyne internal vault/auth secrets, and
|
|
5
|
+
* high-value cloud/registry secret credentials before spawning shell tools so
|
|
6
|
+
* prompt-injected shell commands or untrusted build scripts cannot exfiltrate
|
|
7
|
+
* ambient credentials via `env` / `printenv`.
|
|
8
|
+
*
|
|
9
|
+
* Developers who intentionally need a specific variable inside a subprocess
|
|
10
|
+
* (for example, running an integration test suite) can opt in via
|
|
11
|
+
* `CAUSYNE_PASSTHROUGH_ENV=VAR_A,VAR_B`. Internal Causyne vault/dev secrets
|
|
12
|
+
* remain permanently excluded from subprocesses.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const ALWAYS_BLOCKED_SUBPROCESS_ENV: ReadonlySet<string> = new Set([
|
|
16
|
+
'CAUSYNE_VAULT_KEY',
|
|
17
|
+
'CAUSYNE_DEV_SECRET',
|
|
18
|
+
'CAUSYNE_DEV_TOKEN'
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export const SENSITIVE_EXACT_ENV_KEYS: ReadonlySet<string> = new Set([
|
|
22
|
+
// LLM & AI provider API keys
|
|
23
|
+
'OPENAI_API_KEY',
|
|
24
|
+
'OPENAI_ADMIN_KEY',
|
|
25
|
+
'OPENAI_ORG_KEY',
|
|
26
|
+
'ANTHROPIC_API_KEY',
|
|
27
|
+
'CLAUDE_API_KEY',
|
|
28
|
+
'GEMINI_API_KEY',
|
|
29
|
+
'GOOGLE_API_KEY',
|
|
30
|
+
'GOOGLE_GENERATIVE_AI_API_KEY',
|
|
31
|
+
'OPENROUTER_API_KEY',
|
|
32
|
+
'DEEPSEEK_API_KEY',
|
|
33
|
+
'XAI_API_KEY',
|
|
34
|
+
'GROK_API_KEY',
|
|
35
|
+
'MOONSHOT_API_KEY',
|
|
36
|
+
'KIMI_API_KEY',
|
|
37
|
+
'DASHSCOPE_API_KEY',
|
|
38
|
+
'QWEN_API_KEY',
|
|
39
|
+
'MUSE_API_KEY',
|
|
40
|
+
'META_API_KEY',
|
|
41
|
+
'LLAMA_API_KEY',
|
|
42
|
+
'MISTRAL_API_KEY',
|
|
43
|
+
'COHERE_API_KEY',
|
|
44
|
+
'GROQ_API_KEY',
|
|
45
|
+
'TOGETHER_API_KEY',
|
|
46
|
+
'PERPLEXITY_API_KEY',
|
|
47
|
+
'FIREWORKS_API_KEY',
|
|
48
|
+
'CEREBRAS_API_KEY',
|
|
49
|
+
'SAMBANOVA_API_KEY',
|
|
50
|
+
'HUGGINGFACE_API_KEY',
|
|
51
|
+
'HF_TOKEN',
|
|
52
|
+
'HUGGING_FACE_HUB_TOKEN',
|
|
53
|
+
'REPLICATE_API_TOKEN',
|
|
54
|
+
'VOYAGE_API_KEY',
|
|
55
|
+
'ELEVENLABS_API_KEY',
|
|
56
|
+
'FAL_KEY',
|
|
57
|
+
'STABILITY_API_KEY',
|
|
58
|
+
'AZURE_OPENAI_API_KEY',
|
|
59
|
+
|
|
60
|
+
// Causyne internal auth / vault credentials
|
|
61
|
+
'CAUSYNE_API_KEY',
|
|
62
|
+
'CAUSYNE_AUTH_TOKEN',
|
|
63
|
+
'CAUSYNE_ACCESS_TOKEN',
|
|
64
|
+
'CAUSYNE_SECRET',
|
|
65
|
+
'CAUSYNE_VAULT_KEY',
|
|
66
|
+
'CAUSYNE_DEV_SECRET',
|
|
67
|
+
'CAUSYNE_DEV_TOKEN',
|
|
68
|
+
|
|
69
|
+
// Cloud, package registry, VCS, and infrastructure raw secrets
|
|
70
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
71
|
+
'AWS_SESSION_TOKEN',
|
|
72
|
+
'AWS_SECURITY_TOKEN',
|
|
73
|
+
'NPM_TOKEN',
|
|
74
|
+
'NODE_AUTH_TOKEN',
|
|
75
|
+
'YARN_NPM_AUTH_TOKEN',
|
|
76
|
+
'PYPI_API_TOKEN',
|
|
77
|
+
'TWINE_PASSWORD',
|
|
78
|
+
'CARGO_REGISTRY_TOKEN',
|
|
79
|
+
'RUBYGEMS_API_KEY',
|
|
80
|
+
'NUGET_API_KEY',
|
|
81
|
+
'GITHUB_TOKEN',
|
|
82
|
+
'GH_TOKEN',
|
|
83
|
+
'GITLAB_TOKEN',
|
|
84
|
+
'BITBUCKET_TOKEN',
|
|
85
|
+
'SLACK_BOT_TOKEN',
|
|
86
|
+
'SLACK_TOKEN',
|
|
87
|
+
'DISCORD_TOKEN',
|
|
88
|
+
'TELEGRAM_BOT_TOKEN',
|
|
89
|
+
'STRIPE_SECRET_KEY',
|
|
90
|
+
'STRIPE_API_KEY',
|
|
91
|
+
'SENDGRID_API_KEY',
|
|
92
|
+
'TWILIO_AUTH_TOKEN',
|
|
93
|
+
'DATABASE_PASSWORD',
|
|
94
|
+
'DB_PASSWORD',
|
|
95
|
+
'PGPASSWORD',
|
|
96
|
+
'MYSQL_PWD',
|
|
97
|
+
'REDIS_PASSWORD',
|
|
98
|
+
'DOCKER_PASSWORD',
|
|
99
|
+
'GCP_SERVICE_ACCOUNT_KEY',
|
|
100
|
+
'GOOGLE_APPLICATION_CREDENTIALS_JSON',
|
|
101
|
+
'CLOUDFLARE_API_TOKEN',
|
|
102
|
+
'VERCEL_TOKEN',
|
|
103
|
+
'NETLIFY_AUTH_TOKEN',
|
|
104
|
+
'FLY_API_TOKEN',
|
|
105
|
+
'DIGITALOCEAN_ACCESS_TOKEN',
|
|
106
|
+
'HEROKU_API_KEY',
|
|
107
|
+
'DATADOG_API_KEY',
|
|
108
|
+
'SENTRY_AUTH_TOKEN'
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
const SENSITIVE_ENV_SUFFIXES: readonly string[] = [
|
|
112
|
+
'_API_KEY',
|
|
113
|
+
'_SECRET_KEY',
|
|
114
|
+
'_PRIVATE_KEY',
|
|
115
|
+
'_ACCESS_SECRET',
|
|
116
|
+
'_AUTH_SECRET',
|
|
117
|
+
'_CLIENT_SECRET',
|
|
118
|
+
'_SIGNING_KEY',
|
|
119
|
+
'_ENCRYPTION_KEY',
|
|
120
|
+
'_MASTER_KEY',
|
|
121
|
+
'_VAULT_KEY',
|
|
122
|
+
'_SECRET_TOKEN',
|
|
123
|
+
'_ACCESS_TOKEN',
|
|
124
|
+
'_AUTH_TOKEN',
|
|
125
|
+
'_REFRESH_TOKEN'
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
export interface SanitizeSubprocessEnvOptions {
|
|
129
|
+
passthrough?: readonly string[] | undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Parses `CAUSYNE_PASSTHROUGH_ENV` (comma-separated exact variable names) into
|
|
134
|
+
* an uppercased allowlist while excluding permanently blocked internal keys.
|
|
135
|
+
*/
|
|
136
|
+
export function parsePassthroughAllowlist(
|
|
137
|
+
env: NodeJS.ProcessEnv,
|
|
138
|
+
extra?: readonly string[]
|
|
139
|
+
): Set<string> {
|
|
140
|
+
const allow = new Set<string>();
|
|
141
|
+
const addEntry = (raw: string): void => {
|
|
142
|
+
const trimmed = raw.trim().toUpperCase();
|
|
143
|
+
if (!trimmed || trimmed === '*') return;
|
|
144
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(trimmed)) return;
|
|
145
|
+
allow.add(trimmed);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const envValue = env.CAUSYNE_PASSTHROUGH_ENV;
|
|
149
|
+
if (typeof envValue === 'string' && envValue.trim().length > 0) {
|
|
150
|
+
for (const part of envValue.split(',')) {
|
|
151
|
+
addEntry(part);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(extra)) {
|
|
155
|
+
for (const part of extra) {
|
|
156
|
+
if (typeof part === 'string') addEntry(part);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return allow;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns true if an environment variable name represents a secret credential
|
|
164
|
+
* that must be stripped from shell subprocesses by default.
|
|
165
|
+
*/
|
|
166
|
+
export function isSensitiveEnvKey(key: string): boolean {
|
|
167
|
+
if (typeof key !== 'string' || key.length === 0) return false;
|
|
168
|
+
const upper = key.toUpperCase();
|
|
169
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(upper)) return true;
|
|
170
|
+
if (SENSITIVE_EXACT_ENV_KEYS.has(upper)) return true;
|
|
171
|
+
|
|
172
|
+
if (upper.startsWith('CAUSYNE_')) {
|
|
173
|
+
if (
|
|
174
|
+
upper.includes('KEY') ||
|
|
175
|
+
upper.includes('TOKEN') ||
|
|
176
|
+
upper.includes('SECRET') ||
|
|
177
|
+
upper.includes('PASSWORD') ||
|
|
178
|
+
upper.includes('CREDENTIAL')
|
|
179
|
+
) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
for (const suffix of SENSITIVE_ENV_SUFFIXES) {
|
|
185
|
+
if (upper.endsWith(suffix)) return true;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Returns a copy of `baseEnv` (default `process.env`) with sensitive API keys
|
|
192
|
+
* and secrets removed unless explicitly listed in `CAUSYNE_PASSTHROUGH_ENV` or
|
|
193
|
+
* `options.passthrough`. Internal vault/dev keys are never passed through.
|
|
194
|
+
*/
|
|
195
|
+
export function sanitizeSubprocessEnv(
|
|
196
|
+
baseEnv?: NodeJS.ProcessEnv,
|
|
197
|
+
options?: SanitizeSubprocessEnvOptions
|
|
198
|
+
): NodeJS.ProcessEnv {
|
|
199
|
+
const source = baseEnv ?? process.env;
|
|
200
|
+
const allowlist = parsePassthroughAllowlist(source, options?.passthrough);
|
|
201
|
+
const sanitized: NodeJS.ProcessEnv = {};
|
|
202
|
+
|
|
203
|
+
for (const [key, value] of Object.entries(source)) {
|
|
204
|
+
if (value === undefined) continue;
|
|
205
|
+
const upper = key.toUpperCase();
|
|
206
|
+
if (ALWAYS_BLOCKED_SUBPROCESS_ENV.has(upper)) continue;
|
|
207
|
+
if (isSensitiveEnvKey(key) && !allowlist.has(upper)) continue;
|
|
208
|
+
sanitized[key] = value;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return sanitized;
|
|
212
|
+
}
|
package/src/tools/sysRun.js
CHANGED
|
@@ -14,6 +14,8 @@ import fs from 'node:fs';
|
|
|
14
14
|
import os from 'node:os';
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
import { isLaunchOnlyPrompt, isServerLaunchCommand } from '../launchIntent.js';
|
|
17
|
+
import { sanitizeSubprocessEnv } from './subprocessEnv.js';
|
|
18
|
+
import { resolveOsSandboxMode, wrapCommandWithOsSandbox } from './osSandbox.js';
|
|
17
19
|
/**
|
|
18
20
|
* Strips ANSI escape sequences and terminal control codes from string output.
|
|
19
21
|
*/
|
|
@@ -50,7 +52,7 @@ export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test
|
|
|
50
52
|
* and language runtimes so ADB, emulator, and build tools function out-of-the-box.
|
|
51
53
|
*/
|
|
52
54
|
export function getEnhancedEnv(baseEnv) {
|
|
53
|
-
const env =
|
|
55
|
+
const env = sanitizeSubprocessEnv(baseEnv || process.env);
|
|
54
56
|
// 1. Discover ANDROID_HOME / ANDROID_SDK_ROOT across standard platform locations
|
|
55
57
|
if (!env.ANDROID_HOME && !env.ANDROID_SDK_ROOT) {
|
|
56
58
|
const candidateDirs = [
|
|
@@ -297,11 +299,34 @@ export const sysRun = {
|
|
|
297
299
|
const shellArgs = os.platform() === 'win32' ? ['/c', executedCommand] : ['-c', executedCommand];
|
|
298
300
|
let child;
|
|
299
301
|
try {
|
|
300
|
-
|
|
302
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
303
|
+
const explicitSandbox = context.osSandbox;
|
|
304
|
+
const wrapOptions = typeof explicitSandbox === 'string'
|
|
305
|
+
? {
|
|
306
|
+
mode: explicitSandbox,
|
|
307
|
+
strict: resolvedMode.strict,
|
|
308
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
309
|
+
cwd,
|
|
310
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
311
|
+
}
|
|
312
|
+
: {
|
|
313
|
+
mode: explicitSandbox?.mode ?? resolvedMode.mode,
|
|
314
|
+
strict: explicitSandbox?.strict ?? resolvedMode.strict,
|
|
315
|
+
allowNetwork: explicitSandbox?.allowNetwork ?? resolvedMode.allowNetwork,
|
|
316
|
+
cwd,
|
|
317
|
+
workspaceRoots: explicitSandbox?.workspaceRoots ?? context.parentLoop?.sandbox?.workspacePaths ?? [cwd],
|
|
318
|
+
...(explicitSandbox?.allowDevCaches !== undefined ? { allowDevCaches: explicitSandbox.allowDevCaches } : {}),
|
|
319
|
+
...(explicitSandbox?.includeTempDirs !== undefined ? { includeTempDirs: explicitSandbox.includeTempDirs } : {}),
|
|
320
|
+
...(explicitSandbox?.extraDenyReadPaths ? { extraDenyReadPaths: explicitSandbox.extraDenyReadPaths } : {}),
|
|
321
|
+
...(explicitSandbox?.homeDir ? { homeDir: explicitSandbox.homeDir } : {}),
|
|
322
|
+
...(explicitSandbox?.tmpDir ? { tmpDir: explicitSandbox.tmpDir } : {})
|
|
323
|
+
};
|
|
324
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, wrapOptions);
|
|
325
|
+
child = spawn(wrapped.command, wrapped.args, {
|
|
301
326
|
cwd,
|
|
302
327
|
signal,
|
|
303
328
|
env: getEnhancedEnv(),
|
|
304
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
329
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
305
330
|
});
|
|
306
331
|
}
|
|
307
332
|
catch (err) {
|
|
@@ -479,18 +504,26 @@ export const sysRunBg = {
|
|
|
479
504
|
required: ['command', 'label']
|
|
480
505
|
}
|
|
481
506
|
},
|
|
482
|
-
async execute(args) {
|
|
507
|
+
async execute(args, context = {}) {
|
|
483
508
|
try {
|
|
484
509
|
const cwd = args.cwd ? args.cwd.replace(/^~\//, os.homedir() + '/') : process.cwd();
|
|
485
510
|
const shell = os.platform() === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
486
511
|
const shellArgs = os.platform() === 'win32' ? ['/c', args.command] : ['-c', args.command];
|
|
512
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
513
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, {
|
|
514
|
+
mode: resolvedMode.mode,
|
|
515
|
+
strict: resolvedMode.strict,
|
|
516
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
517
|
+
cwd,
|
|
518
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
519
|
+
});
|
|
487
520
|
return await new Promise(resolve => {
|
|
488
|
-
const child = spawn(
|
|
521
|
+
const child = spawn(wrapped.command, wrapped.args, {
|
|
489
522
|
cwd,
|
|
490
523
|
detached: true,
|
|
491
524
|
stdio: 'ignore',
|
|
492
525
|
env: getEnhancedEnv(),
|
|
493
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
526
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
494
527
|
});
|
|
495
528
|
child.once('error', error => resolve({ success: false, error: error.message }));
|
|
496
529
|
child.once('spawn', () => {
|
package/src/tools/sysRun.ts
CHANGED
|
@@ -15,6 +15,13 @@ import fs from 'node:fs';
|
|
|
15
15
|
import os from 'node:os';
|
|
16
16
|
import path from 'node:path';
|
|
17
17
|
import { isLaunchOnlyPrompt, isServerLaunchCommand } from '../launchIntent.js';
|
|
18
|
+
import { sanitizeSubprocessEnv } from './subprocessEnv.js';
|
|
19
|
+
import {
|
|
20
|
+
resolveOsSandboxMode,
|
|
21
|
+
wrapCommandWithOsSandbox,
|
|
22
|
+
type OsSandboxMode,
|
|
23
|
+
type OsSandboxWrapOptions
|
|
24
|
+
} from './osSandbox.js';
|
|
18
25
|
|
|
19
26
|
export interface SysRunArgs {
|
|
20
27
|
command: string;
|
|
@@ -36,7 +43,14 @@ export interface SysRunResult {
|
|
|
36
43
|
export interface SysRunContext {
|
|
37
44
|
signal?: AbortSignal | undefined;
|
|
38
45
|
skipCache?: boolean | undefined;
|
|
39
|
-
|
|
46
|
+
osSandbox?: OsSandboxMode | Partial<OsSandboxWrapOptions> | undefined;
|
|
47
|
+
parentLoop?: {
|
|
48
|
+
currentTaskPrompt?: string;
|
|
49
|
+
userPrompt?: string;
|
|
50
|
+
workspaceRoot?: string;
|
|
51
|
+
config?: { osSandbox?: string };
|
|
52
|
+
sandbox?: { workspacePaths?: string[] };
|
|
53
|
+
} | undefined;
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
export interface SysRunBgArgs {
|
|
@@ -93,7 +107,7 @@ export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test
|
|
|
93
107
|
* and language runtimes so ADB, emulator, and build tools function out-of-the-box.
|
|
94
108
|
*/
|
|
95
109
|
export function getEnhancedEnv(baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
96
|
-
const env: NodeJS.ProcessEnv =
|
|
110
|
+
const env: NodeJS.ProcessEnv = sanitizeSubprocessEnv(baseEnv || process.env);
|
|
97
111
|
|
|
98
112
|
// 1. Discover ANDROID_HOME / ANDROID_SDK_ROOT across standard platform locations
|
|
99
113
|
if (!env.ANDROID_HOME && !env.ANDROID_SDK_ROOT) {
|
|
@@ -368,11 +382,35 @@ export const sysRun = {
|
|
|
368
382
|
|
|
369
383
|
let child: ReturnType<typeof spawn>;
|
|
370
384
|
try {
|
|
371
|
-
|
|
385
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
386
|
+
const explicitSandbox = context.osSandbox;
|
|
387
|
+
const wrapOptions: OsSandboxWrapOptions = typeof explicitSandbox === 'string'
|
|
388
|
+
? {
|
|
389
|
+
mode: explicitSandbox,
|
|
390
|
+
strict: resolvedMode.strict,
|
|
391
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
392
|
+
cwd,
|
|
393
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
394
|
+
}
|
|
395
|
+
: {
|
|
396
|
+
mode: explicitSandbox?.mode ?? resolvedMode.mode,
|
|
397
|
+
strict: explicitSandbox?.strict ?? resolvedMode.strict,
|
|
398
|
+
allowNetwork: explicitSandbox?.allowNetwork ?? resolvedMode.allowNetwork,
|
|
399
|
+
cwd,
|
|
400
|
+
workspaceRoots: explicitSandbox?.workspaceRoots ?? context.parentLoop?.sandbox?.workspacePaths ?? [cwd],
|
|
401
|
+
...(explicitSandbox?.allowDevCaches !== undefined ? { allowDevCaches: explicitSandbox.allowDevCaches } : {}),
|
|
402
|
+
...(explicitSandbox?.includeTempDirs !== undefined ? { includeTempDirs: explicitSandbox.includeTempDirs } : {}),
|
|
403
|
+
...(explicitSandbox?.extraDenyReadPaths ? { extraDenyReadPaths: explicitSandbox.extraDenyReadPaths } : {}),
|
|
404
|
+
...(explicitSandbox?.homeDir ? { homeDir: explicitSandbox.homeDir } : {}),
|
|
405
|
+
...(explicitSandbox?.tmpDir ? { tmpDir: explicitSandbox.tmpDir } : {})
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, wrapOptions);
|
|
409
|
+
child = spawn(wrapped.command, wrapped.args, {
|
|
372
410
|
cwd,
|
|
373
411
|
signal,
|
|
374
412
|
env: getEnhancedEnv(),
|
|
375
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
413
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
376
414
|
});
|
|
377
415
|
} catch (err: unknown) {
|
|
378
416
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
@@ -546,18 +584,26 @@ export const sysRunBg = {
|
|
|
546
584
|
}
|
|
547
585
|
},
|
|
548
586
|
|
|
549
|
-
async execute(args: SysRunBgArgs): Promise<SysRunBgResult> {
|
|
587
|
+
async execute(args: SysRunBgArgs, context: SysRunContext = {}): Promise<SysRunBgResult> {
|
|
550
588
|
try {
|
|
551
589
|
const cwd = args.cwd ? args.cwd.replace(/^~\//, os.homedir() + '/') : process.cwd();
|
|
552
590
|
const shell = os.platform() === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
553
591
|
const shellArgs = os.platform() === 'win32' ? ['/c', args.command] : ['-c', args.command];
|
|
592
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
593
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, {
|
|
594
|
+
mode: resolvedMode.mode,
|
|
595
|
+
strict: resolvedMode.strict,
|
|
596
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
597
|
+
cwd,
|
|
598
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
599
|
+
});
|
|
554
600
|
return await new Promise<SysRunBgResult>(resolve => {
|
|
555
|
-
const child = spawn(
|
|
601
|
+
const child = spawn(wrapped.command, wrapped.args, {
|
|
556
602
|
cwd,
|
|
557
603
|
detached: true,
|
|
558
604
|
stdio: 'ignore',
|
|
559
605
|
env: getEnhancedEnv(),
|
|
560
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
606
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
561
607
|
});
|
|
562
608
|
child.once('error', error => resolve({ success: false, error: error.message }));
|
|
563
609
|
child.once('spawn', () => {
|