@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
|
@@ -52,6 +52,74 @@ export interface DocumentForgeArgs {
|
|
|
52
52
|
inspectImagesDir?: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
interface DocumentForgeContext {
|
|
56
|
+
workspaceRoot?: string;
|
|
57
|
+
workspacePaths?: string[];
|
|
58
|
+
grantAllAccess?: boolean;
|
|
59
|
+
parentLoop?: { workspaceRoot?: string };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveDocPath(raw: string, context?: DocumentForgeContext): string {
|
|
63
|
+
const trimmed = raw.trim();
|
|
64
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
65
|
+
return resolveUserPath(trimmed);
|
|
66
|
+
}
|
|
67
|
+
if (path.isAbsolute(trimmed)) return path.resolve(trimmed);
|
|
68
|
+
const baseRoot = context?.parentLoop?.workspaceRoot?.trim()
|
|
69
|
+
|| context?.workspaceRoot?.trim()
|
|
70
|
+
|| context?.workspacePaths?.find((p): p is string => typeof p === 'string' && p.trim().length > 0)?.trim();
|
|
71
|
+
return path.resolve(baseRoot ? resolveUserPath(baseRoot) : process.cwd(), trimmed);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function canonicalDocPath(target: string): string {
|
|
75
|
+
const resolved = path.resolve(target);
|
|
76
|
+
try {
|
|
77
|
+
return fs.realpathSync(resolved);
|
|
78
|
+
} catch {
|
|
79
|
+
let current = resolved;
|
|
80
|
+
const missing: string[] = [];
|
|
81
|
+
for (let i = 0; i < 64; i++) {
|
|
82
|
+
const parent = path.dirname(current);
|
|
83
|
+
if (parent === current) break;
|
|
84
|
+
missing.unshift(path.basename(current));
|
|
85
|
+
current = parent;
|
|
86
|
+
try {
|
|
87
|
+
return path.join(fs.realpathSync(current), ...missing);
|
|
88
|
+
} catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return resolved;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function assertDocScope(target: string, context?: DocumentForgeContext, isWrite = false): void {
|
|
97
|
+
if (isWrite && fs.existsSync(target) && fs.lstatSync(target).isSymbolicLink()) {
|
|
98
|
+
throw new Error(`Refusing to overwrite symbolic link: ${target}`);
|
|
99
|
+
}
|
|
100
|
+
if (!context || context.grantAllAccess === true) return;
|
|
101
|
+
const configured = Array.isArray(context.workspacePaths)
|
|
102
|
+
? context.workspacePaths.filter((p): p is string => typeof p === 'string' && p.trim().length > 0).map(p => p.trim())
|
|
103
|
+
: [];
|
|
104
|
+
const roots = configured.length > 0
|
|
105
|
+
? configured
|
|
106
|
+
: [context.parentLoop?.workspaceRoot, context.workspaceRoot]
|
|
107
|
+
.filter((p): p is string => typeof p === 'string' && p.trim().length > 0)
|
|
108
|
+
.map(p => p.trim());
|
|
109
|
+
if (roots.length === 0) return;
|
|
110
|
+
const physical = canonicalDocPath(target);
|
|
111
|
+
for (const root of roots) {
|
|
112
|
+
try {
|
|
113
|
+
const realRoot = fs.realpathSync(resolveUserPath(root));
|
|
114
|
+
const rel = path.relative(realRoot, physical);
|
|
115
|
+
if (rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel))) return;
|
|
116
|
+
} catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`Document path resolves outside the selected workspace: ${target}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
55
123
|
export const documentForgeTool = {
|
|
56
124
|
schema: {
|
|
57
125
|
name: 'document_forge',
|
|
@@ -159,107 +227,124 @@ export const documentForgeTool = {
|
|
|
159
227
|
}
|
|
160
228
|
},
|
|
161
229
|
|
|
162
|
-
async execute(args: DocumentForgeArgs = {},
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
case 'compile_document': {
|
|
167
|
-
if (!args.documentSpec) {
|
|
168
|
-
return { success: false, error: 'compile_document requires documentSpec.' };
|
|
169
|
-
}
|
|
170
|
-
const compiled = compileDocumentHtml(args.documentSpec);
|
|
171
|
-
if (args.outputPath) {
|
|
172
|
-
const target = resolveUserPath(args.outputPath);
|
|
173
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
174
|
-
fs.writeFileSync(target, compiled.html, 'utf8');
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
success: true,
|
|
178
|
-
html: compiled.html,
|
|
179
|
-
outputPath: args.outputPath ? resolveUserPath(args.outputPath) : undefined
|
|
180
|
-
};
|
|
230
|
+
async execute(args: DocumentForgeArgs = {}, context: DocumentForgeContext = {}): Promise<{ success: boolean; [key: string]: any }> {
|
|
231
|
+
try {
|
|
232
|
+
if (!args || typeof args !== 'object' || Array.isArray(args)) {
|
|
233
|
+
return { success: false, error: 'document_forge requires an arguments object.' };
|
|
181
234
|
}
|
|
235
|
+
const action = args.action || 'compile_document';
|
|
182
236
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
237
|
+
switch (action) {
|
|
238
|
+
case 'compile_document': {
|
|
239
|
+
if (!args.documentSpec) {
|
|
240
|
+
return { success: false, error: 'compile_document requires documentSpec.' };
|
|
241
|
+
}
|
|
242
|
+
const compiled = compileDocumentHtml(args.documentSpec);
|
|
243
|
+
let resolvedOut: string | undefined;
|
|
244
|
+
if (args.outputPath) {
|
|
245
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
246
|
+
assertDocScope(resolvedOut, context, true);
|
|
247
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
248
|
+
fs.writeFileSync(resolvedOut, compiled.html, 'utf8');
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
success: true,
|
|
252
|
+
html: compiled.html,
|
|
253
|
+
outputPath: resolvedOut
|
|
254
|
+
};
|
|
186
255
|
}
|
|
187
|
-
const src = resolveUserPath(args.sourceHtmlPath);
|
|
188
|
-
const out = resolveUserPath(args.outputPdfPath);
|
|
189
|
-
const res = await renderHtmlToPdf(src, out);
|
|
190
|
-
return res;
|
|
191
|
-
}
|
|
192
256
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
257
|
+
case 'render_pdf': {
|
|
258
|
+
if (!args.sourceHtmlPath || !args.outputPdfPath) {
|
|
259
|
+
return { success: false, error: 'render_pdf requires sourceHtmlPath and outputPdfPath.' };
|
|
260
|
+
}
|
|
261
|
+
const src = resolveDocPath(args.sourceHtmlPath, context);
|
|
262
|
+
const out = resolveDocPath(args.outputPdfPath, context);
|
|
263
|
+
assertDocScope(src, context, false);
|
|
264
|
+
assertDocScope(out, context, true);
|
|
265
|
+
const res = await renderHtmlToPdf(src, out);
|
|
266
|
+
return res;
|
|
196
267
|
}
|
|
197
|
-
const pdf = resolveUserPath(args.outputPdfPath);
|
|
198
|
-
const imgDir = args.inspectImagesDir ? resolveUserPath(args.inspectImagesDir) : undefined;
|
|
199
|
-
const res = await inspectPdfPages(pdf, imgDir);
|
|
200
|
-
return res;
|
|
201
|
-
}
|
|
202
268
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
269
|
+
case 'inspect_pages': {
|
|
270
|
+
if (!args.outputPdfPath) {
|
|
271
|
+
return { success: false, error: 'inspect_pages requires outputPdfPath.' };
|
|
272
|
+
}
|
|
273
|
+
const pdf = resolveDocPath(args.outputPdfPath, context);
|
|
274
|
+
assertDocScope(pdf, context, false);
|
|
275
|
+
const imgDir = args.inspectImagesDir ? resolveDocPath(args.inspectImagesDir, context) : undefined;
|
|
276
|
+
if (imgDir) assertDocScope(imgDir, context, true);
|
|
277
|
+
const res = await inspectPdfPages(pdf, imgDir);
|
|
278
|
+
return res;
|
|
206
279
|
}
|
|
207
|
-
const res = auditTextContent(args.textContent);
|
|
208
|
-
return { success: true, ...res };
|
|
209
|
-
}
|
|
210
280
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
281
|
+
case 'audit_text': {
|
|
282
|
+
if (!args.textContent) {
|
|
283
|
+
return { success: false, error: 'audit_text requires textContent parameter.' };
|
|
284
|
+
}
|
|
285
|
+
const res = auditTextContent(args.textContent);
|
|
286
|
+
return { success: true, ...res };
|
|
214
287
|
}
|
|
215
|
-
const res = auditBudgetArithmetic(args.budgetSpec);
|
|
216
|
-
return { success: true, ...res };
|
|
217
|
-
}
|
|
218
288
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const target = resolveUserPath(args.outputPath);
|
|
226
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
227
|
-
fs.writeFileSync(target, formatted.html, 'utf8');
|
|
289
|
+
case 'audit_budget': {
|
|
290
|
+
if (!args.budgetSpec) {
|
|
291
|
+
return { success: false, error: 'audit_budget requires budgetSpec parameter.' };
|
|
292
|
+
}
|
|
293
|
+
const res = auditBudgetArithmetic(args.budgetSpec);
|
|
294
|
+
return { success: true, ...res };
|
|
228
295
|
}
|
|
229
|
-
return {
|
|
230
|
-
success: true,
|
|
231
|
-
html: formatted.html,
|
|
232
|
-
outputPath: args.outputPath ? resolveUserPath(args.outputPath) : undefined
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
296
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
297
|
+
case 'format_screenplay': {
|
|
298
|
+
if (!args.screenplaySpec) {
|
|
299
|
+
return { success: false, error: 'format_screenplay requires screenplaySpec.' };
|
|
300
|
+
}
|
|
301
|
+
const formatted = formatScreenplayHtml(args.screenplaySpec);
|
|
302
|
+
let resolvedOut: string | undefined;
|
|
303
|
+
if (args.outputPath) {
|
|
304
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
305
|
+
assertDocScope(resolvedOut, context, true);
|
|
306
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
307
|
+
fs.writeFileSync(resolvedOut, formatted.html, 'utf8');
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
success: true,
|
|
311
|
+
html: formatted.html,
|
|
312
|
+
outputPath: resolvedOut
|
|
313
|
+
};
|
|
239
314
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
315
|
+
|
|
316
|
+
case 'format_shotlist': {
|
|
317
|
+
if (!args.shotList || !Array.isArray(args.shotList.shots)) {
|
|
318
|
+
return { success: false, error: 'format_shotlist requires shotList with a shots array.' };
|
|
319
|
+
}
|
|
320
|
+
const formatted = formatShotListHtml(args.shotList.title, args.shotList.shots);
|
|
321
|
+
let resolvedOut: string | undefined;
|
|
322
|
+
if (args.outputPath) {
|
|
323
|
+
resolvedOut = resolveDocPath(args.outputPath, context);
|
|
324
|
+
assertDocScope(resolvedOut, context, true);
|
|
325
|
+
fs.mkdirSync(path.dirname(resolvedOut), { recursive: true });
|
|
326
|
+
fs.writeFileSync(resolvedOut, formatted.html, 'utf8');
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
success: true,
|
|
330
|
+
html: formatted.html,
|
|
331
|
+
outputPath: resolvedOut
|
|
332
|
+
};
|
|
245
333
|
}
|
|
246
|
-
return {
|
|
247
|
-
success: true,
|
|
248
|
-
html: formatted.html,
|
|
249
|
-
outputPath: args.outputPath ? resolveUserPath(args.outputPath) : undefined
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
334
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
335
|
+
case 'analyze_vo': {
|
|
336
|
+
if (!args.voBlocks || !Array.isArray(args.voBlocks)) {
|
|
337
|
+
return { success: false, error: 'analyze_vo requires voBlocks array.' };
|
|
338
|
+
}
|
|
339
|
+
const res = analyzeVoiceOverTiming(args.voBlocks);
|
|
340
|
+
return { success: true, analysis: res };
|
|
256
341
|
}
|
|
257
|
-
const res = analyzeVoiceOverTiming(args.voBlocks);
|
|
258
|
-
return { success: true, analysis: res };
|
|
259
|
-
}
|
|
260
342
|
|
|
261
|
-
|
|
262
|
-
|
|
343
|
+
default:
|
|
344
|
+
return { success: false, error: `Unsupported document_forge action: ${action}` };
|
|
345
|
+
}
|
|
346
|
+
} catch (error: unknown) {
|
|
347
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
263
348
|
}
|
|
264
349
|
}
|
|
265
350
|
};
|
package/src/tools/fsEdit.js
CHANGED
|
@@ -2,30 +2,88 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { atomicWriteFileSync } from '../infra/atomicWriter.js';
|
|
5
|
+
function expandHome(value) {
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
if (trimmed === '~')
|
|
8
|
+
return os.homedir();
|
|
9
|
+
if (trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
10
|
+
return path.join(os.homedir(), trimmed.slice(2));
|
|
11
|
+
}
|
|
12
|
+
return trimmed;
|
|
13
|
+
}
|
|
14
|
+
function insideRoot(root, target) {
|
|
15
|
+
const rel = path.relative(root, target);
|
|
16
|
+
return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
|
|
17
|
+
}
|
|
18
|
+
async function assertWithinEditScope(target, context) {
|
|
19
|
+
if (!context || context.grantAllAccess === true)
|
|
20
|
+
return;
|
|
21
|
+
const configured = Array.isArray(context.workspacePaths)
|
|
22
|
+
? context.workspacePaths.filter((p) => typeof p === 'string' && p.trim().length > 0).map(p => p.trim())
|
|
23
|
+
: [];
|
|
24
|
+
const roots = configured.length > 0
|
|
25
|
+
? configured
|
|
26
|
+
: [context.parentLoop?.workspaceRoot, context.workspaceRoot]
|
|
27
|
+
.filter((p) => typeof p === 'string' && p.trim().length > 0)
|
|
28
|
+
.map(p => p.trim());
|
|
29
|
+
if (roots.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
const realTarget = await fs.realpath(target);
|
|
32
|
+
for (const root of roots) {
|
|
33
|
+
try {
|
|
34
|
+
const realRoot = await fs.realpath(path.resolve(expandHome(root)));
|
|
35
|
+
if (insideRoot(realRoot, realTarget))
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Target resolves outside the selected workspace: ${target}`);
|
|
43
|
+
}
|
|
44
|
+
const MAX_FUZZY_CHARS = 8_192;
|
|
5
45
|
function getLevenshteinDistance(a, b) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
46
|
+
let s1 = a;
|
|
47
|
+
let s2 = b;
|
|
48
|
+
if (s1.length > s2.length) {
|
|
49
|
+
const tmp = s1;
|
|
50
|
+
s1 = s2;
|
|
51
|
+
s2 = tmp;
|
|
52
|
+
}
|
|
53
|
+
const m = s1.length;
|
|
54
|
+
const n = s2.length;
|
|
55
|
+
if (m === 0)
|
|
56
|
+
return n;
|
|
57
|
+
let prev = new Int32Array(m + 1);
|
|
58
|
+
let curr = new Int32Array(m + 1);
|
|
59
|
+
for (let j = 0; j <= m; j++)
|
|
60
|
+
prev[j] = j;
|
|
61
|
+
for (let i = 1; i <= n; i++) {
|
|
62
|
+
curr[0] = i;
|
|
63
|
+
const ch2 = s2.charCodeAt(i - 1);
|
|
64
|
+
for (let j = 1; j <= m; j++) {
|
|
65
|
+
const cost = s1.charCodeAt(j - 1) === ch2 ? 0 : 1;
|
|
66
|
+
const del = prev[j] + 1;
|
|
67
|
+
const ins = curr[j - 1] + 1;
|
|
68
|
+
const sub = prev[j - 1] + cost;
|
|
69
|
+
curr[j] = del < ins ? (del < sub ? del : sub) : (ins < sub ? ins : sub);
|
|
20
70
|
}
|
|
71
|
+
const swap = prev;
|
|
72
|
+
prev = curr;
|
|
73
|
+
curr = swap;
|
|
21
74
|
}
|
|
22
|
-
return
|
|
75
|
+
return prev[m];
|
|
23
76
|
}
|
|
24
77
|
function calculateConfidence(original, match) {
|
|
25
|
-
const dist = getLevenshteinDistance(original, match);
|
|
26
78
|
const maxLen = Math.max(original.length, match.length);
|
|
27
79
|
if (maxLen === 0)
|
|
28
80
|
return 100;
|
|
81
|
+
if (maxLen > MAX_FUZZY_CHARS)
|
|
82
|
+
return 0;
|
|
83
|
+
// Impossible to reach 90% confidence when length difference alone exceeds 10%
|
|
84
|
+
if (Math.abs(original.length - match.length) / maxLen > 0.1)
|
|
85
|
+
return 0;
|
|
86
|
+
const dist = getLevenshteinDistance(original, match);
|
|
29
87
|
return ((maxLen - dist) / maxLen) * 100;
|
|
30
88
|
}
|
|
31
89
|
export const fsEdit = {
|
|
@@ -51,7 +109,7 @@ export const fsEdit = {
|
|
|
51
109
|
required: ['path', 'edits']
|
|
52
110
|
}
|
|
53
111
|
},
|
|
54
|
-
async execute(args) {
|
|
112
|
+
async execute(args, context) {
|
|
55
113
|
try {
|
|
56
114
|
if (!args || typeof args !== 'object') {
|
|
57
115
|
return { success: false, error: 'fs_edit requires an object with path and edits array.' };
|
|
@@ -62,42 +120,55 @@ export const fsEdit = {
|
|
|
62
120
|
if (!Array.isArray(args.edits) || args.edits.length === 0) {
|
|
63
121
|
return { success: false, error: 'fs_edit requires a non-empty edits array.' };
|
|
64
122
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
123
|
+
const expandedPath = expandHome(args.path);
|
|
124
|
+
const baseRoot = context?.parentLoop?.workspaceRoot?.trim()
|
|
125
|
+
|| context?.workspaceRoot?.trim()
|
|
126
|
+
|| context?.workspacePaths?.find((p) => typeof p === 'string' && p.trim().length > 0)?.trim();
|
|
127
|
+
const target = path.isAbsolute(expandedPath)
|
|
128
|
+
? path.resolve(expandedPath)
|
|
129
|
+
: path.resolve(baseRoot ? path.resolve(expandHome(baseRoot)) : process.cwd(), expandedPath);
|
|
130
|
+
const stat = await fs.lstat(target);
|
|
131
|
+
if (stat.isSymbolicLink()) {
|
|
132
|
+
return { success: false, error: `Refusing to edit symbolic link ${target}; edit a regular file in the selected workspace.` };
|
|
133
|
+
}
|
|
134
|
+
if (!stat.isFile()) {
|
|
135
|
+
return { success: false, error: `Target is not a regular file: ${target}` };
|
|
136
|
+
}
|
|
137
|
+
await assertWithinEditScope(target, context);
|
|
138
|
+
const originalMode = stat.mode & 0o777;
|
|
69
139
|
const originalContent = await fs.readFile(target, 'utf8');
|
|
70
140
|
let workingContent = originalContent;
|
|
71
141
|
let replacements = 0;
|
|
72
142
|
for (let i = 0; i < args.edits.length; i++) {
|
|
73
143
|
const edit = args.edits[i];
|
|
74
|
-
if (!edit || typeof edit.searchContent !== 'string' || typeof edit.replaceContent !== 'string') {
|
|
144
|
+
if (!edit || typeof edit.searchContent !== 'string' || edit.searchContent.length === 0 || typeof edit.replaceContent !== 'string') {
|
|
75
145
|
return {
|
|
76
146
|
success: false,
|
|
77
|
-
error: `ATOMIC ROLLBACK: Edit index ${i} is missing valid searchContent or replaceContent strings. Rollback complete.`
|
|
147
|
+
error: `ATOMIC ROLLBACK: Edit index ${i} is missing valid non-empty searchContent or replaceContent strings. Rollback complete.`
|
|
78
148
|
};
|
|
79
149
|
}
|
|
80
150
|
// Try exact match first
|
|
81
151
|
if (workingContent.includes(edit.searchContent)) {
|
|
82
|
-
workingContent = workingContent.replace(edit.searchContent, edit.replaceContent);
|
|
152
|
+
workingContent = workingContent.replace(edit.searchContent, () => edit.replaceContent);
|
|
83
153
|
replacements++;
|
|
84
154
|
continue;
|
|
85
155
|
}
|
|
86
156
|
// Fuzzy Match Fallback
|
|
87
157
|
const lines = workingContent.split('\n');
|
|
88
158
|
const oldLines = edit.searchContent.split('\n');
|
|
89
|
-
let
|
|
159
|
+
let bestIndex = -1;
|
|
90
160
|
let highestConfidence = 0;
|
|
91
161
|
for (let j = 0; j <= lines.length - oldLines.length; j++) {
|
|
92
162
|
const chunk = lines.slice(j, j + oldLines.length).join('\n');
|
|
93
163
|
const conf = calculateConfidence(edit.searchContent, chunk);
|
|
94
164
|
if (conf > highestConfidence) {
|
|
95
165
|
highestConfidence = conf;
|
|
96
|
-
|
|
166
|
+
bestIndex = j;
|
|
97
167
|
}
|
|
98
168
|
}
|
|
99
|
-
if (highestConfidence >= 90 &&
|
|
100
|
-
|
|
169
|
+
if (highestConfidence >= 90 && bestIndex !== -1) {
|
|
170
|
+
lines.splice(bestIndex, oldLines.length, edit.replaceContent);
|
|
171
|
+
workingContent = lines.join('\n');
|
|
101
172
|
replacements++;
|
|
102
173
|
}
|
|
103
174
|
else {
|
|
@@ -107,8 +178,8 @@ export const fsEdit = {
|
|
|
107
178
|
};
|
|
108
179
|
}
|
|
109
180
|
}
|
|
110
|
-
// Commit the transaction atomically
|
|
111
|
-
atomicWriteFileSync(target, workingContent, { encoding: 'utf8' });
|
|
181
|
+
// Commit the transaction atomically, preserving original file permissions
|
|
182
|
+
atomicWriteFileSync(target, workingContent, { encoding: 'utf8', mode: originalMode });
|
|
112
183
|
return { success: true, output: `Transaction Success: ${replacements} replacement(s) safely applied to ${args.path}` };
|
|
113
184
|
}
|
|
114
185
|
catch (e) {
|