@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
|
@@ -176,28 +176,30 @@ export const deferredMcpSearch = {
|
|
|
176
176
|
|
|
177
177
|
async execute(args: SearchArgs, context: SearchContext = {}): Promise<SearchResult> {
|
|
178
178
|
try {
|
|
179
|
-
const
|
|
179
|
+
const safeArgs: SearchArgs = args && typeof args === 'object' && !Array.isArray(args) ? args : {};
|
|
180
|
+
const safeContext: SearchContext = context && typeof context === 'object' ? context : {};
|
|
181
|
+
const rawQueries = (safeArgs as any).queries;
|
|
180
182
|
const joinedQueries = Array.isArray(rawQueries)
|
|
181
183
|
? rawQueries.map((item) => String(item ?? '').trim()).filter(Boolean).join(' ')
|
|
182
184
|
: (typeof rawQueries === 'string' ? rawQueries : '');
|
|
183
|
-
const rawQuery = Array.isArray(
|
|
184
|
-
?
|
|
185
|
-
:
|
|
185
|
+
const rawQuery = Array.isArray(safeArgs.query)
|
|
186
|
+
? safeArgs.query.map((item) => String(item ?? '').trim()).filter(Boolean).join(' ')
|
|
187
|
+
: safeArgs.query;
|
|
186
188
|
const query = String(
|
|
187
|
-
rawQuery ?? (
|
|
188
|
-
(
|
|
189
|
+
rawQuery ?? (safeArgs as any).q ?? (safeArgs as any).search ?? (safeArgs as any).term ??
|
|
190
|
+
(safeArgs as any).regex ?? (safeArgs as any).description ?? (safeArgs as any).pattern ?? joinedQueries ?? ''
|
|
189
191
|
).trim();
|
|
190
192
|
if (query.length > MAX_TOOL_SEARCH_QUERY) {
|
|
191
193
|
return { success: false, error: `Search query exceeds ${MAX_TOOL_SEARCH_QUERY} characters. Use a shorter capability description.` };
|
|
192
194
|
}
|
|
193
|
-
const requestedPack =
|
|
194
|
-
const definitions =
|
|
195
|
-
? await
|
|
195
|
+
const requestedPack = safeArgs.pack ? String(safeArgs.pack).toLowerCase() : null;
|
|
196
|
+
const definitions = safeContext.parentLoop?.searchableTools
|
|
197
|
+
? await safeContext.parentLoop.searchableTools() : await toolDefinitions();
|
|
196
198
|
const hints = new Map(buildToolsList(definitions).map((entry) => [entry.name, entry.hint]));
|
|
197
|
-
if (Array.isArray(
|
|
199
|
+
if (Array.isArray(safeArgs.names) && safeArgs.names.length > 0) {
|
|
198
200
|
const available = new Map(definitions.map((definition) => [definition.name.toLowerCase(), definition.name]));
|
|
199
|
-
const chosen = [...new Set(
|
|
200
|
-
if (chosen.length !== new Set(
|
|
201
|
+
const chosen = [...new Set(safeArgs.names.map((name) => available.get(String(name).toLowerCase())).filter((name): name is string => Boolean(name)))];
|
|
202
|
+
if (chosen.length !== new Set(safeArgs.names.map((name) => String(name).toLowerCase())).size) {
|
|
201
203
|
return { success: false, error: 'One or more selected tools are unavailable under the current policy. Select exact names from the current catalog.' };
|
|
202
204
|
}
|
|
203
205
|
return { success: true, output: `Selected ${chosen.length} tool schemas for your next turn:\n${chosen.map((name) => `- ${name}: ${hints.get(name) || 'tool'}`).join('\n')}`, _unlock_tools: chosen };
|
|
@@ -209,7 +211,17 @@ export const deferredMcpSearch = {
|
|
|
209
211
|
|
|
210
212
|
// Whole-pack load. Cheaper than five searches when the agent already
|
|
211
213
|
// knows it is starting a game or a media pipeline.
|
|
212
|
-
if (requestedPack
|
|
214
|
+
if (requestedPack === 'all') {
|
|
215
|
+
const allPackTools = definitions.filter(d => !isResidentTool(d.name));
|
|
216
|
+
return {
|
|
217
|
+
success: true,
|
|
218
|
+
output: `Loaded all capability packs (${allPackTools.length} tools). These are now callable:\n` +
|
|
219
|
+
allPackTools.map(d => `- ${d.name}: ${hints.get(d.name) || 'tool'}`).join('\n'),
|
|
220
|
+
_unlock_packs: [...PACK_NAMES],
|
|
221
|
+
_unlock_tools: allPackTools.map(d => d.name)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (requestedPack && Object.hasOwn(PACKS, requestedPack)) {
|
|
213
225
|
const packTools = definitions.filter(d => packForTool(d.name) === requestedPack);
|
|
214
226
|
return {
|
|
215
227
|
success: true,
|
|
@@ -220,7 +232,7 @@ export const deferredMcpSearch = {
|
|
|
220
232
|
};
|
|
221
233
|
}
|
|
222
234
|
|
|
223
|
-
const limit = typeof
|
|
235
|
+
const limit = typeof safeArgs.limit === 'number' && Number.isInteger(safeArgs.limit) && safeArgs.limit > 0 ? Math.min(safeArgs.limit, 25) : 8;
|
|
224
236
|
const lower = query.toLowerCase();
|
|
225
237
|
const terms = queryTerms(query);
|
|
226
238
|
const pattern = buildPattern(query);
|
package/src/tools/desktopOpen.js
CHANGED
|
@@ -8,6 +8,24 @@ import { spawn } from 'node:child_process';
|
|
|
8
8
|
import os from 'node:os';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import fs from 'node:fs';
|
|
11
|
+
function isUnsafeUriScheme(value) {
|
|
12
|
+
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(value);
|
|
13
|
+
if (!match)
|
|
14
|
+
return false;
|
|
15
|
+
const scheme = match[1].toLowerCase();
|
|
16
|
+
// Allow single-letter Windows drive paths like C:\foo
|
|
17
|
+
if (scheme.length === 1 && (value[2] === '\\' || value[2] === '/'))
|
|
18
|
+
return false;
|
|
19
|
+
return scheme !== 'http' && scheme !== 'https';
|
|
20
|
+
}
|
|
21
|
+
function hasControlChars(value) {
|
|
22
|
+
for (let i = 0; i < value.length; i++) {
|
|
23
|
+
const code = value.charCodeAt(i);
|
|
24
|
+
if (code < 0x20 || code === 0x7f)
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
11
29
|
export function resolveOpenTarget(rawTarget, workspaceRoot = process.cwd()) {
|
|
12
30
|
let target = (rawTarget || '').trim();
|
|
13
31
|
if (!target)
|
|
@@ -34,18 +52,37 @@ export function resolveOpenTarget(rawTarget, workspaceRoot = process.cwd()) {
|
|
|
34
52
|
}
|
|
35
53
|
return target;
|
|
36
54
|
}
|
|
55
|
+
const BLOCKED_WINDOWS_APPS = new Set([
|
|
56
|
+
'cmd', 'cmd.exe', 'powershell', 'powershell.exe', 'pwsh', 'pwsh.exe',
|
|
57
|
+
'wscript', 'wscript.exe', 'cscript', 'cscript.exe', 'mshta', 'mshta.exe',
|
|
58
|
+
'rundll32', 'rundll32.exe', 'regsvr32', 'regsvr32.exe', 'bash', 'bash.exe', 'sh', 'sh.exe'
|
|
59
|
+
]);
|
|
37
60
|
export async function openWithNativeOS(target, app) {
|
|
61
|
+
if (hasControlChars(target) || target.startsWith('-')) {
|
|
62
|
+
throw new Error(`Refusing unsafe desktop.open target: "${target}"`);
|
|
63
|
+
}
|
|
64
|
+
const cleanApp = typeof app === 'string' && app.trim() ? app.trim() : undefined;
|
|
65
|
+
if (cleanApp) {
|
|
66
|
+
if (hasControlChars(cleanApp) || cleanApp.startsWith('-')) {
|
|
67
|
+
throw new Error(`Refusing unsafe desktop.open application name: "${cleanApp}"`);
|
|
68
|
+
}
|
|
69
|
+
if (os.platform() === 'win32') {
|
|
70
|
+
if (cleanApp.includes('/') || cleanApp.includes('\\') || BLOCKED_WINDOWS_APPS.has(cleanApp.toLowerCase())) {
|
|
71
|
+
throw new Error(`Refusing unsafe Windows application launch target: "${cleanApp}"`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
38
75
|
return new Promise((resolve, reject) => {
|
|
39
76
|
let command;
|
|
40
77
|
let cliArgs;
|
|
41
78
|
const platform = os.platform();
|
|
42
79
|
if (platform === 'darwin') {
|
|
43
80
|
command = '/usr/bin/open';
|
|
44
|
-
cliArgs =
|
|
81
|
+
cliArgs = cleanApp ? ['-a', cleanApp, target] : [target];
|
|
45
82
|
}
|
|
46
83
|
else if (platform === 'win32') {
|
|
47
|
-
if (
|
|
48
|
-
command =
|
|
84
|
+
if (cleanApp) {
|
|
85
|
+
command = cleanApp;
|
|
49
86
|
cliArgs = [target];
|
|
50
87
|
}
|
|
51
88
|
else {
|
|
@@ -59,21 +96,30 @@ export async function openWithNativeOS(target, app) {
|
|
|
59
96
|
cliArgs = [target];
|
|
60
97
|
}
|
|
61
98
|
try {
|
|
99
|
+
let settled = false;
|
|
62
100
|
const child = spawn(command, cliArgs, {
|
|
63
101
|
detached: true,
|
|
64
|
-
stdio: 'ignore'
|
|
102
|
+
stdio: 'ignore',
|
|
103
|
+
windowsHide: true
|
|
65
104
|
});
|
|
66
105
|
child.unref();
|
|
67
|
-
child.on('error', (err) => {
|
|
68
|
-
reject(err);
|
|
69
|
-
});
|
|
70
106
|
// Brief tick to ensure the binary was dispatched without immediate spawn error
|
|
71
|
-
setTimeout(() => {
|
|
107
|
+
const timer = setTimeout(() => {
|
|
108
|
+
if (settled)
|
|
109
|
+
return;
|
|
110
|
+
settled = true;
|
|
72
111
|
resolve({
|
|
73
112
|
success: true,
|
|
74
113
|
output: `Successfully dispatched native OS open event for: ${target}`
|
|
75
114
|
});
|
|
76
115
|
}, 50);
|
|
116
|
+
child.on('error', (err) => {
|
|
117
|
+
if (settled)
|
|
118
|
+
return;
|
|
119
|
+
settled = true;
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
reject(err);
|
|
122
|
+
});
|
|
77
123
|
}
|
|
78
124
|
catch (e) {
|
|
79
125
|
reject(e);
|
|
@@ -97,8 +143,21 @@ export const desktopOpen = {
|
|
|
97
143
|
if (!args || typeof args.target !== 'string' || !args.target.trim()) {
|
|
98
144
|
return { success: false, error: 'Missing required "target" parameter for desktop.open' };
|
|
99
145
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
146
|
+
const rawTarget = args.target.trim();
|
|
147
|
+
if (hasControlChars(rawTarget)) {
|
|
148
|
+
return { success: false, error: 'Target contains disallowed control characters.' };
|
|
149
|
+
}
|
|
150
|
+
if (isUnsafeUriScheme(rawTarget)) {
|
|
151
|
+
return { success: false, error: `Unsupported or unsafe URI scheme in target: "${rawTarget}". Only http://, https://, and local file paths are allowed.` };
|
|
152
|
+
}
|
|
153
|
+
if (args.app !== undefined && typeof args.app !== 'string') {
|
|
154
|
+
return { success: false, error: 'Optional "app" parameter must be a string.' };
|
|
155
|
+
}
|
|
156
|
+
const workspaceRoot = context?.parentLoop?.workspaceRoot?.trim()
|
|
157
|
+
|| context?.workspaceRoot?.trim()
|
|
158
|
+
|| context?.workspacePaths?.find((p) => typeof p === 'string' && p.trim().length > 0)?.trim()
|
|
159
|
+
|| process.cwd();
|
|
160
|
+
const resolvedTarget = resolveOpenTarget(rawTarget, workspaceRoot);
|
|
102
161
|
try {
|
|
103
162
|
const nativeResult = await openWithNativeOS(resolvedTarget, args.app);
|
|
104
163
|
return { success: true, output: nativeResult.output };
|
package/src/tools/desktopOpen.ts
CHANGED
|
@@ -23,11 +23,30 @@ export interface DesktopOpenResult {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface DesktopOpenContext {
|
|
26
|
+
workspaceRoot?: string | undefined;
|
|
27
|
+
workspacePaths?: string[] | undefined;
|
|
26
28
|
parentLoop?: {
|
|
27
29
|
workspaceRoot?: string | undefined;
|
|
28
30
|
} | undefined;
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
function isUnsafeUriScheme(value: string): boolean {
|
|
34
|
+
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(value);
|
|
35
|
+
if (!match) return false;
|
|
36
|
+
const scheme = match[1]!.toLowerCase();
|
|
37
|
+
// Allow single-letter Windows drive paths like C:\foo
|
|
38
|
+
if (scheme.length === 1 && (value[2] === '\\' || value[2] === '/')) return false;
|
|
39
|
+
return scheme !== 'http' && scheme !== 'https';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hasControlChars(value: string): boolean {
|
|
43
|
+
for (let i = 0; i < value.length; i++) {
|
|
44
|
+
const code = value.charCodeAt(i);
|
|
45
|
+
if (code < 0x20 || code === 0x7f) return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
31
50
|
export function resolveOpenTarget(rawTarget: string, workspaceRoot: string = process.cwd()): string {
|
|
32
51
|
let target = (rawTarget || '').trim();
|
|
33
52
|
if (!target) return target;
|
|
@@ -58,7 +77,27 @@ export function resolveOpenTarget(rawTarget: string, workspaceRoot: string = pro
|
|
|
58
77
|
return target;
|
|
59
78
|
}
|
|
60
79
|
|
|
80
|
+
const BLOCKED_WINDOWS_APPS = new Set([
|
|
81
|
+
'cmd', 'cmd.exe', 'powershell', 'powershell.exe', 'pwsh', 'pwsh.exe',
|
|
82
|
+
'wscript', 'wscript.exe', 'cscript', 'cscript.exe', 'mshta', 'mshta.exe',
|
|
83
|
+
'rundll32', 'rundll32.exe', 'regsvr32', 'regsvr32.exe', 'bash', 'bash.exe', 'sh', 'sh.exe'
|
|
84
|
+
]);
|
|
85
|
+
|
|
61
86
|
export async function openWithNativeOS(target: string, app?: string): Promise<{ success: boolean; output: string }> {
|
|
87
|
+
if (hasControlChars(target) || target.startsWith('-')) {
|
|
88
|
+
throw new Error(`Refusing unsafe desktop.open target: "${target}"`);
|
|
89
|
+
}
|
|
90
|
+
const cleanApp = typeof app === 'string' && app.trim() ? app.trim() : undefined;
|
|
91
|
+
if (cleanApp) {
|
|
92
|
+
if (hasControlChars(cleanApp) || cleanApp.startsWith('-')) {
|
|
93
|
+
throw new Error(`Refusing unsafe desktop.open application name: "${cleanApp}"`);
|
|
94
|
+
}
|
|
95
|
+
if (os.platform() === 'win32') {
|
|
96
|
+
if (cleanApp.includes('/') || cleanApp.includes('\\') || BLOCKED_WINDOWS_APPS.has(cleanApp.toLowerCase())) {
|
|
97
|
+
throw new Error(`Refusing unsafe Windows application launch target: "${cleanApp}"`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
62
101
|
return new Promise((resolve, reject) => {
|
|
63
102
|
let command: string;
|
|
64
103
|
let cliArgs: string[];
|
|
@@ -66,10 +105,10 @@ export async function openWithNativeOS(target: string, app?: string): Promise<{
|
|
|
66
105
|
const platform = os.platform();
|
|
67
106
|
if (platform === 'darwin') {
|
|
68
107
|
command = '/usr/bin/open';
|
|
69
|
-
cliArgs =
|
|
108
|
+
cliArgs = cleanApp ? ['-a', cleanApp, target] : [target];
|
|
70
109
|
} else if (platform === 'win32') {
|
|
71
|
-
if (
|
|
72
|
-
command =
|
|
110
|
+
if (cleanApp) {
|
|
111
|
+
command = cleanApp;
|
|
73
112
|
cliArgs = [target];
|
|
74
113
|
} else {
|
|
75
114
|
const sysRoot = process.env.SYSTEMROOT || process.env.windir || 'C:\\Windows';
|
|
@@ -82,23 +121,30 @@ export async function openWithNativeOS(target: string, app?: string): Promise<{
|
|
|
82
121
|
}
|
|
83
122
|
|
|
84
123
|
try {
|
|
124
|
+
let settled = false;
|
|
85
125
|
const child = spawn(command, cliArgs, {
|
|
86
126
|
detached: true,
|
|
87
|
-
stdio: 'ignore'
|
|
127
|
+
stdio: 'ignore',
|
|
128
|
+
windowsHide: true
|
|
88
129
|
});
|
|
89
130
|
child.unref();
|
|
90
131
|
|
|
91
|
-
child.on('error', (err) => {
|
|
92
|
-
reject(err);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
132
|
// Brief tick to ensure the binary was dispatched without immediate spawn error
|
|
96
|
-
setTimeout(() => {
|
|
133
|
+
const timer = setTimeout(() => {
|
|
134
|
+
if (settled) return;
|
|
135
|
+
settled = true;
|
|
97
136
|
resolve({
|
|
98
137
|
success: true,
|
|
99
138
|
output: `Successfully dispatched native OS open event for: ${target}`
|
|
100
139
|
});
|
|
101
140
|
}, 50);
|
|
141
|
+
|
|
142
|
+
child.on('error', (err) => {
|
|
143
|
+
if (settled) return;
|
|
144
|
+
settled = true;
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
reject(err);
|
|
147
|
+
});
|
|
102
148
|
} catch (e) {
|
|
103
149
|
reject(e);
|
|
104
150
|
}
|
|
@@ -123,9 +169,22 @@ export const desktopOpen = {
|
|
|
123
169
|
if (!args || typeof args.target !== 'string' || !args.target.trim()) {
|
|
124
170
|
return { success: false, error: 'Missing required "target" parameter for desktop.open' };
|
|
125
171
|
}
|
|
172
|
+
const rawTarget = args.target.trim();
|
|
173
|
+
if (hasControlChars(rawTarget)) {
|
|
174
|
+
return { success: false, error: 'Target contains disallowed control characters.' };
|
|
175
|
+
}
|
|
176
|
+
if (isUnsafeUriScheme(rawTarget)) {
|
|
177
|
+
return { success: false, error: `Unsupported or unsafe URI scheme in target: "${rawTarget}". Only http://, https://, and local file paths are allowed.` };
|
|
178
|
+
}
|
|
126
179
|
|
|
127
|
-
|
|
128
|
-
|
|
180
|
+
if (args.app !== undefined && typeof args.app !== 'string') {
|
|
181
|
+
return { success: false, error: 'Optional "app" parameter must be a string.' };
|
|
182
|
+
}
|
|
183
|
+
const workspaceRoot = context?.parentLoop?.workspaceRoot?.trim()
|
|
184
|
+
|| context?.workspaceRoot?.trim()
|
|
185
|
+
|| context?.workspacePaths?.find((p): p is string => typeof p === 'string' && p.trim().length > 0)?.trim()
|
|
186
|
+
|| process.cwd();
|
|
187
|
+
const resolvedTarget = resolveOpenTarget(rawTarget, workspaceRoot);
|
|
129
188
|
|
|
130
189
|
try {
|
|
131
190
|
const nativeResult = await openWithNativeOS(resolvedTarget, args.app);
|
|
@@ -12,6 +12,72 @@ import { compileDocumentHtml, renderHtmlToPdf, inspectPdfPages } from '../docume
|
|
|
12
12
|
import { formatScreenplayHtml, formatShotListHtml, analyzeVoiceOverTiming } from '../documentEngine/screenplayFormatter.js';
|
|
13
13
|
import { auditTextContent, auditBudgetArithmetic } from '../documentEngine/antiSlopAuditor.js';
|
|
14
14
|
import { resolveUserPath } from '../utils/paths.js';
|
|
15
|
+
function resolveDocPath(raw, context) {
|
|
16
|
+
const trimmed = raw.trim();
|
|
17
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
18
|
+
return resolveUserPath(trimmed);
|
|
19
|
+
}
|
|
20
|
+
if (path.isAbsolute(trimmed))
|
|
21
|
+
return path.resolve(trimmed);
|
|
22
|
+
const baseRoot = context?.parentLoop?.workspaceRoot?.trim()
|
|
23
|
+
|| context?.workspaceRoot?.trim()
|
|
24
|
+
|| context?.workspacePaths?.find((p) => typeof p === 'string' && p.trim().length > 0)?.trim();
|
|
25
|
+
return path.resolve(baseRoot ? resolveUserPath(baseRoot) : process.cwd(), trimmed);
|
|
26
|
+
}
|
|
27
|
+
function canonicalDocPath(target) {
|
|
28
|
+
const resolved = path.resolve(target);
|
|
29
|
+
try {
|
|
30
|
+
return fs.realpathSync(resolved);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
let current = resolved;
|
|
34
|
+
const missing = [];
|
|
35
|
+
for (let i = 0; i < 64; i++) {
|
|
36
|
+
const parent = path.dirname(current);
|
|
37
|
+
if (parent === current)
|
|
38
|
+
break;
|
|
39
|
+
missing.unshift(path.basename(current));
|
|
40
|
+
current = parent;
|
|
41
|
+
try {
|
|
42
|
+
return path.join(fs.realpathSync(current), ...missing);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return resolved;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function assertDocScope(target, context, isWrite = false) {
|
|
52
|
+
if (isWrite && fs.existsSync(target) && fs.lstatSync(target).isSymbolicLink()) {
|
|
53
|
+
throw new Error(`Refusing to overwrite symbolic link: ${target}`);
|
|
54
|
+
}
|
|
55
|
+
if (!context || context.grantAllAccess === true)
|
|
56
|
+
return;
|
|
57
|
+
const configured = Array.isArray(context.workspacePaths)
|
|
58
|
+
? context.workspacePaths.filter((p) => typeof p === 'string' && p.trim().length > 0).map(p => p.trim())
|
|
59
|
+
: [];
|
|
60
|
+
const roots = configured.length > 0
|
|
61
|
+
? configured
|
|
62
|
+
: [context.parentLoop?.workspaceRoot, context.workspaceRoot]
|
|
63
|
+
.filter((p) => typeof p === 'string' && p.trim().length > 0)
|
|
64
|
+
.map(p => p.trim());
|
|
65
|
+
if (roots.length === 0)
|
|
66
|
+
return;
|
|
67
|
+
const physical = canonicalDocPath(target);
|
|
68
|
+
for (const root of roots) {
|
|
69
|
+
try {
|
|
70
|
+
const realRoot = fs.realpathSync(resolveUserPath(root));
|
|
71
|
+
const rel = path.relative(realRoot, physical);
|
|
72
|
+
if (rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel)))
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`Document path resolves outside the selected workspace: ${target}`);
|
|
80
|
+
}
|
|
15
81
|
export const documentForgeTool = {
|
|
16
82
|
schema: {
|
|
17
83
|
name: 'document_forge',
|
|
@@ -118,98 +184,117 @@ export const documentForgeTool = {
|
|
|
118
184
|
}
|
|
119
185
|
}
|
|
120
186
|
},
|
|
121
|
-
async execute(args = {},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (!args.documentSpec) {
|
|
126
|
-
return { success: false, error: 'compile_document requires documentSpec.' };
|
|
127
|
-
}
|
|
128
|
-
const compiled = compileDocumentHtml(args.documentSpec);
|
|
129
|
-
if (args.outputPath) {
|
|
130
|
-
const target = resolveUserPath(args.outputPath);
|
|
131
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
132
|
-
fs.writeFileSync(target, compiled.html, 'utf8');
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
success: true,
|
|
136
|
-
html: compiled.html,
|
|
137
|
-
outputPath: args.outputPath ? resolveUserPath(args.outputPath) : undefined
|
|
138
|
-
};
|
|
187
|
+
async execute(args = {}, context = {}) {
|
|
188
|
+
try {
|
|
189
|
+
if (!args || typeof args !== 'object' || Array.isArray(args)) {
|
|
190
|
+
return { success: false, error: 'document_forge requires an arguments object.' };
|
|
139
191
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
192
|
+
const action = args.action || 'compile_document';
|
|
193
|
+
switch (action) {
|
|
194
|
+
case 'compile_document': {
|
|
195
|
+
if (!args.documentSpec) {
|
|
196
|
+
return { success: false, error: 'compile_document requires documentSpec.' };
|
|
197
|
+
}
|
|
198
|
+
const compiled = compileDocumentHtml(args.documentSpec);
|
|
199
|
+
let resolvedOut;
|
|
200
|
+
if (args.outputPath) {
|
|
201
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
202
|
+
assertDocScope(resolvedOut, context, true);
|
|
203
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
204
|
+
fs.writeFileSync(resolvedOut, compiled.html, 'utf8');
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
success: true,
|
|
208
|
+
html: compiled.html,
|
|
209
|
+
outputPath: resolvedOut
|
|
210
|
+
};
|
|
143
211
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const imgDir = args.inspectImagesDir ? resolveUserPath(args.inspectImagesDir) : undefined;
|
|
155
|
-
const res = await inspectPdfPages(pdf, imgDir);
|
|
156
|
-
return res;
|
|
157
|
-
}
|
|
158
|
-
case 'audit_text': {
|
|
159
|
-
if (!args.textContent) {
|
|
160
|
-
return { success: false, error: 'audit_text requires textContent parameter.' };
|
|
212
|
+
case 'render_pdf': {
|
|
213
|
+
if (!args.sourceHtmlPath || !args.outputPdfPath) {
|
|
214
|
+
return { success: false, error: 'render_pdf requires sourceHtmlPath and outputPdfPath.' };
|
|
215
|
+
}
|
|
216
|
+
const src = resolveDocPath(args.sourceHtmlPath, context);
|
|
217
|
+
const out = resolveDocPath(args.outputPdfPath, context);
|
|
218
|
+
assertDocScope(src, context, false);
|
|
219
|
+
assertDocScope(out, context, true);
|
|
220
|
+
const res = await renderHtmlToPdf(src, out);
|
|
221
|
+
return res;
|
|
161
222
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
223
|
+
case 'inspect_pages': {
|
|
224
|
+
if (!args.outputPdfPath) {
|
|
225
|
+
return { success: false, error: 'inspect_pages requires outputPdfPath.' };
|
|
226
|
+
}
|
|
227
|
+
const pdf = resolveDocPath(args.outputPdfPath, context);
|
|
228
|
+
assertDocScope(pdf, context, false);
|
|
229
|
+
const imgDir = args.inspectImagesDir ? resolveDocPath(args.inspectImagesDir, context) : undefined;
|
|
230
|
+
if (imgDir)
|
|
231
|
+
assertDocScope(imgDir, context, true);
|
|
232
|
+
const res = await inspectPdfPages(pdf, imgDir);
|
|
233
|
+
return res;
|
|
168
234
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return { success:
|
|
235
|
+
case 'audit_text': {
|
|
236
|
+
if (!args.textContent) {
|
|
237
|
+
return { success: false, error: 'audit_text requires textContent parameter.' };
|
|
238
|
+
}
|
|
239
|
+
const res = auditTextContent(args.textContent);
|
|
240
|
+
return { success: true, ...res };
|
|
175
241
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
242
|
+
case 'audit_budget': {
|
|
243
|
+
if (!args.budgetSpec) {
|
|
244
|
+
return { success: false, error: 'audit_budget requires budgetSpec parameter.' };
|
|
245
|
+
}
|
|
246
|
+
const res = auditBudgetArithmetic(args.budgetSpec);
|
|
247
|
+
return { success: true, ...res };
|
|
181
248
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
249
|
+
case 'format_screenplay': {
|
|
250
|
+
if (!args.screenplaySpec) {
|
|
251
|
+
return { success: false, error: 'format_screenplay requires screenplaySpec.' };
|
|
252
|
+
}
|
|
253
|
+
const formatted = formatScreenplayHtml(args.screenplaySpec);
|
|
254
|
+
let resolvedOut;
|
|
255
|
+
if (args.outputPath) {
|
|
256
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
257
|
+
assertDocScope(resolvedOut, context, true);
|
|
258
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
259
|
+
fs.writeFileSync(resolvedOut, formatted.html, 'utf8');
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
success: true,
|
|
263
|
+
html: formatted.html,
|
|
264
|
+
outputPath: resolvedOut
|
|
265
|
+
};
|
|
191
266
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
267
|
+
case 'format_shotlist': {
|
|
268
|
+
if (!args.shotList || !Array.isArray(args.shotList.shots)) {
|
|
269
|
+
return { success: false, error: 'format_shotlist requires shotList with a shots array.' };
|
|
270
|
+
}
|
|
271
|
+
const formatted = formatShotListHtml(args.shotList.title, args.shotList.shots);
|
|
272
|
+
let resolvedOut;
|
|
273
|
+
if (args.outputPath) {
|
|
274
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
275
|
+
assertDocScope(resolvedOut, context, true);
|
|
276
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
277
|
+
fs.writeFileSync(resolvedOut, formatted.html, 'utf8');
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
success: true,
|
|
281
|
+
html: formatted.html,
|
|
282
|
+
outputPath: resolvedOut
|
|
283
|
+
};
|
|
197
284
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
case 'analyze_vo': {
|
|
205
|
-
if (!args.voBlocks || !Array.isArray(args.voBlocks)) {
|
|
206
|
-
return { success: false, error: 'analyze_vo requires voBlocks array.' };
|
|
285
|
+
case 'analyze_vo': {
|
|
286
|
+
if (!args.voBlocks || !Array.isArray(args.voBlocks)) {
|
|
287
|
+
return { success: false, error: 'analyze_vo requires voBlocks array.' };
|
|
288
|
+
}
|
|
289
|
+
const res = analyzeVoiceOverTiming(args.voBlocks);
|
|
290
|
+
return { success: true, analysis: res };
|
|
207
291
|
}
|
|
208
|
-
|
|
209
|
-
|
|
292
|
+
default:
|
|
293
|
+
return { success: false, error: `Unsupported document_forge action: ${action}` };
|
|
210
294
|
}
|
|
211
|
-
|
|
212
|
-
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
213
298
|
}
|
|
214
299
|
}
|
|
215
300
|
};
|