@causyne/agent 1.20.120 → 1.20.122
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 +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +117 -0
- package/src/agent/errorClassifier.ts +165 -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 +33 -344
- package/src/agentLoop.ts +51 -352
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +116 -10
- package/src/autoUpdate.ts +149 -10
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/cliMode.js +16 -2
- package/src/commands.js +10 -9
- package/src/config.js +288 -272
- package/src/config.ts +342 -0
- package/src/configVault.js +271 -0
- package/src/configVault.ts +273 -0
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +305 -0
- package/src/headlessCli.ts +381 -0
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- 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/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +263 -0
- package/src/osKeychain.ts +287 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +328 -385
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +397 -0
- package/src/providers/byokHttp.ts +497 -0
- package/src/providers/byokStream.js +748 -0
- package/src/providers/byokStream.ts +863 -0
- package/src/providers/dashscope-byok.js +98 -81
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +74 -64
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +229 -253
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +71 -64
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +116 -93
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +114 -65
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +194 -98
- package/src/providers/openrouter.ts +202 -97
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +97 -71
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +74 -64
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +486 -530
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +1287 -0
- package/src/sandboxPolicy.ts +1381 -0
- package/src/sessionJournal.js +55 -3
- package/src/sessionJournal.ts +58 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +513 -0
- package/src/tools/osSandbox.ts +588 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +108 -35
- package/src/tools/sysRun.ts +119 -31
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
|
@@ -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,14 +52,14 @@ 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 = [
|
|
57
59
|
path.join(os.homedir(), 'Library', 'Android', 'sdk'), // macOS
|
|
58
60
|
path.join(os.homedir(), 'Android', 'Sdk'), // Linux
|
|
59
61
|
'/usr/lib/android-sdk', // Linux package
|
|
60
|
-
path.join(process.env.LOCALAPPDATA
|
|
62
|
+
...(process.env.LOCALAPPDATA ? [path.join(process.env.LOCALAPPDATA, 'Android', 'Sdk')] : []) // Windows
|
|
61
63
|
];
|
|
62
64
|
for (const dir of candidateDirs) {
|
|
63
65
|
if (dir && fs.existsSync(dir)) {
|
|
@@ -182,8 +184,9 @@ export function isFinalCommandSearch(rawCommand) {
|
|
|
182
184
|
lastStmt = subshellMatch[1].trim();
|
|
183
185
|
}
|
|
184
186
|
const pipeParts = lastStmt.split('|');
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
+
const rawFinalCmd = pipeParts.at(-1)?.trim().replace(/["'\)\s]+$/, '') || '';
|
|
188
|
+
const finalCmd = rawFinalCmd.replace(/^(?:adb\s+(?:-s\s+\S+\s+)?shell|ssh\s+\S+)\s+/i, '');
|
|
189
|
+
return /^(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:(?:\/(?:usr\/)?bin\/)?(?:grep|egrep|fgrep|diff|test|which|where|cmp|pidof|pgrep|find))(?:\s|$)/.test(finalCmd);
|
|
187
190
|
}
|
|
188
191
|
/**
|
|
189
192
|
* Commands that are strictly read-only and idempotent.
|
|
@@ -216,10 +219,37 @@ export function isPersistentServerCommand(cmd) {
|
|
|
216
219
|
}
|
|
217
220
|
export const SERVER_READY_PATTERN = /(?:https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0):[0-9]+|serving\s+http\s+on|server\s+(?:running|started)|ready\s+in\s+[0-9]+|terra_server_running)/i;
|
|
218
221
|
const COMMAND_CACHE_TTL_MS = 60_000;
|
|
222
|
+
const MAX_CACHE_ENTRIES = 64;
|
|
219
223
|
const commandCache = new Map();
|
|
224
|
+
function setCachedResult(key, entry) {
|
|
225
|
+
if (commandCache.size >= MAX_CACHE_ENTRIES && !commandCache.has(key)) {
|
|
226
|
+
const oldest = commandCache.keys().next().value;
|
|
227
|
+
if (oldest !== undefined)
|
|
228
|
+
commandCache.delete(oldest);
|
|
229
|
+
}
|
|
230
|
+
commandCache.set(key, entry);
|
|
231
|
+
}
|
|
220
232
|
export function clearSysRunCache() {
|
|
221
233
|
commandCache.clear();
|
|
222
234
|
}
|
|
235
|
+
function resolveSysCwd(rawCwd, context) {
|
|
236
|
+
const expand = (p) => {
|
|
237
|
+
const trimmed = p.trim();
|
|
238
|
+
if (trimmed === '~')
|
|
239
|
+
return os.homedir();
|
|
240
|
+
if (trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
241
|
+
return path.join(os.homedir(), trimmed.slice(2));
|
|
242
|
+
}
|
|
243
|
+
return trimmed;
|
|
244
|
+
};
|
|
245
|
+
const fallbackBase = context?.parentLoop?.workspaceRoot?.trim()
|
|
246
|
+
? path.resolve(expand(context.parentLoop.workspaceRoot))
|
|
247
|
+
: process.cwd();
|
|
248
|
+
if (!rawCwd || !rawCwd.trim())
|
|
249
|
+
return fallbackBase;
|
|
250
|
+
const expanded = expand(rawCwd);
|
|
251
|
+
return path.isAbsolute(expanded) ? path.resolve(expanded) : path.resolve(fallbackBase, expanded);
|
|
252
|
+
}
|
|
223
253
|
export const sysRun = {
|
|
224
254
|
schema: {
|
|
225
255
|
name: 'sysRun',
|
|
@@ -236,7 +266,7 @@ export const sysRun = {
|
|
|
236
266
|
},
|
|
237
267
|
async execute(args, context = {}) {
|
|
238
268
|
const rawCommand = (args?.command || '').trim();
|
|
239
|
-
const cwd = args?.cwd
|
|
269
|
+
const cwd = resolveSysCwd(args?.cwd, context);
|
|
240
270
|
let timeoutMs = 60000;
|
|
241
271
|
const rawTimeout = args?.timeout;
|
|
242
272
|
if (typeof rawTimeout === 'number' && Number.isFinite(rawTimeout) && rawTimeout > 0) {
|
|
@@ -257,9 +287,12 @@ export const sysRun = {
|
|
|
257
287
|
timeoutMs = val <= 600 ? Math.round(val * 1000) : Math.round(val);
|
|
258
288
|
}
|
|
259
289
|
}
|
|
260
|
-
if (timeoutMs < 1000) {
|
|
290
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 1000) {
|
|
261
291
|
timeoutMs = 1000;
|
|
262
292
|
}
|
|
293
|
+
else if (timeoutMs > 2_147_483_647) {
|
|
294
|
+
timeoutMs = 2_147_483_647;
|
|
295
|
+
}
|
|
263
296
|
const signal = context.signal;
|
|
264
297
|
// A foreground server waits forever for requests. Keep launch-only turns
|
|
265
298
|
// responsive and make it explicit that starting is not a readiness check.
|
|
@@ -297,11 +330,34 @@ export const sysRun = {
|
|
|
297
330
|
const shellArgs = os.platform() === 'win32' ? ['/c', executedCommand] : ['-c', executedCommand];
|
|
298
331
|
let child;
|
|
299
332
|
try {
|
|
300
|
-
|
|
333
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
334
|
+
const explicitSandbox = context.osSandbox;
|
|
335
|
+
const wrapOptions = typeof explicitSandbox === 'string'
|
|
336
|
+
? {
|
|
337
|
+
mode: explicitSandbox,
|
|
338
|
+
strict: resolvedMode.strict,
|
|
339
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
340
|
+
cwd,
|
|
341
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
342
|
+
}
|
|
343
|
+
: {
|
|
344
|
+
mode: explicitSandbox?.mode ?? resolvedMode.mode,
|
|
345
|
+
strict: explicitSandbox?.strict ?? resolvedMode.strict,
|
|
346
|
+
allowNetwork: explicitSandbox?.allowNetwork ?? resolvedMode.allowNetwork,
|
|
347
|
+
cwd,
|
|
348
|
+
workspaceRoots: explicitSandbox?.workspaceRoots ?? context.parentLoop?.sandbox?.workspacePaths ?? [cwd],
|
|
349
|
+
...(explicitSandbox?.allowDevCaches !== undefined ? { allowDevCaches: explicitSandbox.allowDevCaches } : {}),
|
|
350
|
+
...(explicitSandbox?.includeTempDirs !== undefined ? { includeTempDirs: explicitSandbox.includeTempDirs } : {}),
|
|
351
|
+
...(explicitSandbox?.extraDenyReadPaths ? { extraDenyReadPaths: explicitSandbox.extraDenyReadPaths } : {}),
|
|
352
|
+
...(explicitSandbox?.homeDir ? { homeDir: explicitSandbox.homeDir } : {}),
|
|
353
|
+
...(explicitSandbox?.tmpDir ? { tmpDir: explicitSandbox.tmpDir } : {})
|
|
354
|
+
};
|
|
355
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, wrapOptions);
|
|
356
|
+
child = spawn(wrapped.command, wrapped.args, {
|
|
301
357
|
cwd,
|
|
302
358
|
signal,
|
|
303
359
|
env: getEnhancedEnv(),
|
|
304
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
360
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
305
361
|
});
|
|
306
362
|
}
|
|
307
363
|
catch (err) {
|
|
@@ -318,6 +374,14 @@ export const sysRun = {
|
|
|
318
374
|
const MAX_LENGTH = 50000;
|
|
319
375
|
let outputBuffer = '';
|
|
320
376
|
let isDetached = false;
|
|
377
|
+
const detachChild = () => {
|
|
378
|
+
child.stdout?.removeAllListeners('data');
|
|
379
|
+
child.stderr?.removeAllListeners('data');
|
|
380
|
+
child.stdout?.destroy();
|
|
381
|
+
child.stderr?.destroy();
|
|
382
|
+
child.stdin?.destroy();
|
|
383
|
+
child.unref();
|
|
384
|
+
};
|
|
321
385
|
const checkServerDetach = () => {
|
|
322
386
|
if (isDetached)
|
|
323
387
|
return;
|
|
@@ -328,7 +392,7 @@ export const sysRun = {
|
|
|
328
392
|
clearTimeout(timeoutId);
|
|
329
393
|
if (serverGraceTimer)
|
|
330
394
|
clearTimeout(serverGraceTimer);
|
|
331
|
-
|
|
395
|
+
detachChild();
|
|
332
396
|
resolve({
|
|
333
397
|
success: true,
|
|
334
398
|
output: cleanSubprocessOutput(outputBuffer),
|
|
@@ -368,7 +432,7 @@ export const sysRun = {
|
|
|
368
432
|
isDetached = true;
|
|
369
433
|
if (timeoutId)
|
|
370
434
|
clearTimeout(timeoutId);
|
|
371
|
-
|
|
435
|
+
detachChild();
|
|
372
436
|
resolve({
|
|
373
437
|
success: true,
|
|
374
438
|
output: cleanSubprocessOutput(outputBuffer) || 'Server process started and running in background.',
|
|
@@ -378,15 +442,24 @@ export const sysRun = {
|
|
|
378
442
|
}
|
|
379
443
|
}, 2500);
|
|
380
444
|
}
|
|
445
|
+
let settled = false;
|
|
446
|
+
const finish = (result) => {
|
|
447
|
+
if (settled)
|
|
448
|
+
return;
|
|
449
|
+
settled = true;
|
|
450
|
+
if (timeoutId)
|
|
451
|
+
clearTimeout(timeoutId);
|
|
452
|
+
if (serverGraceTimer)
|
|
453
|
+
clearTimeout(serverGraceTimer);
|
|
454
|
+
resolve(result);
|
|
455
|
+
};
|
|
381
456
|
let timeoutId;
|
|
382
457
|
if (timeoutMs > 0) {
|
|
383
458
|
timeoutId = setTimeout(() => {
|
|
384
|
-
if (isDetached)
|
|
459
|
+
if (isDetached || settled)
|
|
385
460
|
return;
|
|
386
|
-
if (serverGraceTimer)
|
|
387
|
-
clearTimeout(serverGraceTimer);
|
|
388
461
|
child.kill('SIGKILL');
|
|
389
|
-
|
|
462
|
+
finish({
|
|
390
463
|
success: false,
|
|
391
464
|
output: cleanSubprocessOutput(outputBuffer),
|
|
392
465
|
error: `Process timed out after ${timeoutMs}ms`,
|
|
@@ -395,13 +468,9 @@ export const sysRun = {
|
|
|
395
468
|
}, timeoutMs);
|
|
396
469
|
}
|
|
397
470
|
child.on('error', (err) => {
|
|
398
|
-
if (isDetached)
|
|
471
|
+
if (isDetached || settled)
|
|
399
472
|
return;
|
|
400
|
-
|
|
401
|
-
clearTimeout(timeoutId);
|
|
402
|
-
if (serverGraceTimer)
|
|
403
|
-
clearTimeout(serverGraceTimer);
|
|
404
|
-
resolve({
|
|
473
|
+
finish({
|
|
405
474
|
success: false,
|
|
406
475
|
output: cleanSubprocessOutput(outputBuffer),
|
|
407
476
|
error: err.message,
|
|
@@ -409,25 +478,21 @@ export const sysRun = {
|
|
|
409
478
|
});
|
|
410
479
|
});
|
|
411
480
|
child.on('close', (code) => {
|
|
412
|
-
if (isDetached)
|
|
481
|
+
if (isDetached || settled)
|
|
413
482
|
return;
|
|
414
|
-
if (timeoutId)
|
|
415
|
-
clearTimeout(timeoutId);
|
|
416
|
-
if (serverGraceTimer)
|
|
417
|
-
clearTimeout(serverGraceTimer);
|
|
418
483
|
const cleanOutput = cleanSubprocessOutput(outputBuffer);
|
|
419
484
|
const exitCode = typeof code === 'number' ? code : 1;
|
|
420
485
|
if (exitCode === 0) {
|
|
421
486
|
const res = { success: true, output: cleanOutput, exitCode: 0 };
|
|
422
487
|
if (isIdempotent) {
|
|
423
|
-
|
|
488
|
+
setCachedResult(cacheKey, {
|
|
424
489
|
output: cleanOutput,
|
|
425
490
|
exitCode: 0,
|
|
426
491
|
success: true,
|
|
427
492
|
timestamp: Date.now()
|
|
428
493
|
});
|
|
429
494
|
}
|
|
430
|
-
|
|
495
|
+
finish(res);
|
|
431
496
|
}
|
|
432
497
|
else if (exitCode === 1 && isFinalCommandSearch(rawCommand)) {
|
|
433
498
|
// Semantic Exit Code Normalization: Search tool found 0 matching lines.
|
|
@@ -438,7 +503,7 @@ export const sysRun = {
|
|
|
438
503
|
note: 'Command executed successfully with 0 search matches.'
|
|
439
504
|
};
|
|
440
505
|
if (isIdempotent) {
|
|
441
|
-
|
|
506
|
+
setCachedResult(cacheKey, {
|
|
442
507
|
output: res.output,
|
|
443
508
|
exitCode: 1,
|
|
444
509
|
success: true,
|
|
@@ -446,7 +511,7 @@ export const sysRun = {
|
|
|
446
511
|
timestamp: Date.now()
|
|
447
512
|
});
|
|
448
513
|
}
|
|
449
|
-
|
|
514
|
+
finish(res);
|
|
450
515
|
}
|
|
451
516
|
else {
|
|
452
517
|
let errorMsg = `Command exited with code ${exitCode}`;
|
|
@@ -454,10 +519,10 @@ export const sysRun = {
|
|
|
454
519
|
errorMsg = 'adb failed: multiple devices/emulators connected. Pass `-s <serial>` (e.g. `adb -s emulator-5554 ...`) or set `export ANDROID_SERIAL=<serial>`.';
|
|
455
520
|
}
|
|
456
521
|
if (signal && signal.aborted) {
|
|
457
|
-
|
|
522
|
+
finish({ success: false, output: cleanOutput, error: 'Process killed by user.', exitCode: 1 });
|
|
458
523
|
}
|
|
459
524
|
else {
|
|
460
|
-
|
|
525
|
+
finish({ success: false, output: cleanOutput, error: errorMsg, exitCode });
|
|
461
526
|
}
|
|
462
527
|
}
|
|
463
528
|
});
|
|
@@ -479,18 +544,26 @@ export const sysRunBg = {
|
|
|
479
544
|
required: ['command', 'label']
|
|
480
545
|
}
|
|
481
546
|
},
|
|
482
|
-
async execute(args) {
|
|
547
|
+
async execute(args, context = {}) {
|
|
483
548
|
try {
|
|
484
|
-
const cwd = args
|
|
549
|
+
const cwd = resolveSysCwd(args?.cwd, context);
|
|
485
550
|
const shell = os.platform() === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
486
551
|
const shellArgs = os.platform() === 'win32' ? ['/c', args.command] : ['-c', args.command];
|
|
552
|
+
const resolvedMode = resolveOsSandboxMode(process.env, context.parentLoop?.config?.osSandbox);
|
|
553
|
+
const wrapped = wrapCommandWithOsSandbox(shell, shellArgs, {
|
|
554
|
+
mode: resolvedMode.mode,
|
|
555
|
+
strict: resolvedMode.strict,
|
|
556
|
+
allowNetwork: resolvedMode.allowNetwork,
|
|
557
|
+
cwd,
|
|
558
|
+
workspaceRoots: context.parentLoop?.sandbox?.workspacePaths ?? [cwd]
|
|
559
|
+
});
|
|
487
560
|
return await new Promise(resolve => {
|
|
488
|
-
const child = spawn(
|
|
561
|
+
const child = spawn(wrapped.command, wrapped.args, {
|
|
489
562
|
cwd,
|
|
490
563
|
detached: true,
|
|
491
564
|
stdio: 'ignore',
|
|
492
565
|
env: getEnhancedEnv(),
|
|
493
|
-
...(os.platform() === 'win32' ? { windowsVerbatimArguments: true } : {})
|
|
566
|
+
...(os.platform() === 'win32' && !wrapped.sandboxed ? { windowsVerbatimArguments: true } : {})
|
|
494
567
|
});
|
|
495
568
|
child.once('error', error => resolve({ success: false, error: error.message }));
|
|
496
569
|
child.once('spawn', () => {
|