@causyne/agent 1.20.8 → 1.20.10

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.
Files changed (74) hide show
  1. package/package.json +2 -1
  2. package/src/agentLoop.js +291 -103
  3. package/src/agentLoop.ts +322 -109
  4. package/src/browser/causyneBrowser.js +36 -0
  5. package/src/browser/causyneBrowser.ts +36 -1
  6. package/src/commands.js +25 -0
  7. package/src/compiledSkills.js +7330 -319
  8. package/src/computerUse/types.js +8 -0
  9. package/src/computerUse/types.ts +121 -0
  10. package/src/computerUse/visionGrounding.js +87 -29
  11. package/src/computerUse/visionGrounding.ts +108 -36
  12. package/src/contextManager.js +16 -0
  13. package/src/decisionPolicy.js +7 -9
  14. package/src/decisionPolicy.ts +7 -9
  15. package/src/documentEngine/antiSlopAuditor.js +13 -43
  16. package/src/documentEngine/antiSlopAuditor.ts +15 -47
  17. package/src/documentEngine/documentForge.js +3 -3
  18. package/src/documentEngine/documentForge.ts +3 -3
  19. package/src/launchIntent.js +3 -3
  20. package/src/launchIntent.ts +3 -3
  21. package/src/planCache.js +4 -14
  22. package/src/planCache.ts +4 -14
  23. package/src/providers/acp.js +4 -2
  24. package/src/providers/acp.ts +4 -2
  25. package/src/providers/antigravity.js +191 -28
  26. package/src/providers/antigravity.ts +192 -27
  27. package/src/providers/base.d.ts +2 -0
  28. package/src/providers/pi.js +3 -1
  29. package/src/providers/pi.ts +4 -2
  30. package/src/provisioning/capabilityProvisioner.js +2 -7
  31. package/src/provisioning/npmInstall.js +19 -0
  32. package/src/provisioning/npmInstall.ts +19 -0
  33. package/src/sandbox.js +7 -10
  34. package/src/smartToolsUse.js +223 -0
  35. package/src/smartToolsUse.ts +284 -0
  36. package/src/stallGuard.js +356 -0
  37. package/src/stallGuard.ts +432 -0
  38. package/src/taskShape.js +7 -7
  39. package/src/taskShape.ts +7 -7
  40. package/src/toolPacks.js +5 -5
  41. package/src/tools/blenderAutomator.js +198 -11
  42. package/src/tools/browserAutomator.js +3 -3
  43. package/src/tools/browserAutomator.ts +3 -3
  44. package/src/tools/documentForge.js +1 -1
  45. package/src/tools/documentForge.ts +1 -1
  46. package/src/tools/fsRead.js +91 -80
  47. package/src/tools/fsRead.ts +125 -0
  48. package/src/tools/peerAgent.js +1 -1
  49. package/src/tools/peerAgent.ts +1 -1
  50. package/src/tools/screenshot.js +5 -1
  51. package/src/tools/screenshot.ts +5 -1
  52. package/src/tools/toolScanner.js +19 -0
  53. package/src/tools/toolScanner.ts +17 -0
  54. package/src/tools/toolSelfRepair.js +63 -1
  55. package/src/tools/toolSelfRepair.ts +61 -1
  56. package/src/tools/visionInspector.js +80 -142
  57. package/src/tools/visionInspector.ts +110 -0
  58. package/src/tui/chatboxClipboard.js +152 -0
  59. package/src/tui/chatboxClipboard.ts +201 -0
  60. package/src/tui/clipboardSync.js +38 -7
  61. package/src/tui/clipboardSync.ts +39 -7
  62. package/src/tui/codeProgress.js +89 -18
  63. package/src/tui/codeProgress.ts +102 -17
  64. package/src/tui/codeStreamRenderer.js +7 -2
  65. package/src/tui/codeStreamRenderer.ts +7 -2
  66. package/src/tui/composerControls.js +9 -0
  67. package/src/tui/composerControls.ts +9 -0
  68. package/src/tui/dialogs.js +8 -3
  69. package/src/tui/diff.d.ts +1 -0
  70. package/src/tui/lineEditor.js +166 -14
  71. package/src/tui/mouseHover.js +6 -2
  72. package/src/tui/mouseHover.ts +7 -2
  73. package/src/tui/prompt.js +96 -19
  74. package/src/tui/stageSurface.js +3 -1
@@ -234,37 +234,166 @@ export const blenderAct = {
234
234
  }
235
235
  else if (action.type === 'autoFrameCamera') {
236
236
  {
237
- const camCode = `import bpy, math\ncam = bpy.context.scene.camera\nif not cam:\n cd = bpy.data.cameras.new('Cam')\n cam = bpy.data.objects.new('Cam', cd)\n bpy.context.scene.collection.objects.link(cam)\n bpy.context.scene.camera = cam\ncam.location = (10, -10, 8)\ncam.rotation_euler = (math.radians(50), 0, math.radians(45))\nif hasattr(cam.data, "lens"): cam.data.lens = ${action.focal_length || 65.0}\nprint('Headless 65mm camera framed at studio angle')`;
237
+ const camCode = `import bpy, math
238
+ cam = bpy.context.scene.camera
239
+ if not cam:
240
+ cd = bpy.data.cameras.new('Cam')
241
+ cam = bpy.data.objects.new('Cam', cd)
242
+ bpy.context.scene.collection.objects.link(cam)
243
+ bpy.context.scene.camera = cam
244
+ cam.location = (10, -10, 8)
245
+ cam.rotation_euler = (math.radians(50), 0, math.radians(45))
246
+ if hasattr(cam.data, "lens"):
247
+ cam.data.lens = ${action.focal_length || 65.0}
248
+ print('Headless 65mm camera framed at studio angle')`;
238
249
  await runHeadlessCli(null, camCode, results);
239
250
  }
240
251
  }
241
252
  else if (action.type === 'smartGeometry') {
242
253
  {
243
- const geomCode = `import bpy, math\ntargets = [bpy.data.objects.get(${JSON.stringify(action.name || "")})] if ${JSON.stringify(action.name || "")} else [o for o in bpy.context.scene.objects if o.type == 'MESH' and o.visible_get() and not any(k in o.name.lower() for k in ['floor', 'plane', 'backdrop', 'studio', 'ground', 'cove'])]\ntargets = [t for t in targets if t]\nfor o in targets:\n if hasattr(o.data, "use_auto_smooth"): o.data.use_auto_smooth = True\n for p in o.data.polygons: p.use_smooth = True\n if not any(m.type == 'BEVEL' for m in o.modifiers):\n bev = o.modifiers.new(name="StudioBevel", type='BEVEL'); bev.width = ${action.bevel_width || 0.015}; bev.segments = 3; bev.limit_method = 'ANGLE'; bev.angle_limit = math.radians(35)\n if ${action.subsurf !== false} and not any(m.type == 'SUBSURF' for m in o.modifiers):\n sub = o.modifiers.new(name="StudioSubsurf", type='SUBSURF'); sub.levels = 2; sub.render_levels = 2\nprint("Headless applied Studio Bevel and Subsurf")`;
254
+ const geomCode = `import bpy, math
255
+ target_name = ${JSON.stringify(action.name || "")}
256
+ targets = [bpy.data.objects.get(target_name)] if target_name else [o for o in bpy.context.scene.objects if o.type == 'MESH' and o.visible_get() and not any(k in o.name.lower() for k in ['floor', 'plane', 'backdrop', 'studio', 'ground', 'cove'])]
257
+ targets = [t for t in targets if t]
258
+ for o in targets:
259
+ if hasattr(o.data, "use_auto_smooth"):
260
+ o.data.use_auto_smooth = True
261
+ for p in o.data.polygons:
262
+ p.use_smooth = True
263
+ if not any(m.type == 'BEVEL' for m in o.modifiers):
264
+ bev = o.modifiers.new(name="StudioBevel", type='BEVEL')
265
+ bev.width = ${action.bevel_width || 0.015}
266
+ bev.segments = 3
267
+ bev.limit_method = 'ANGLE'
268
+ bev.angle_limit = math.radians(35)
269
+ if ${action.subsurf !== false} and not any(m.type == 'SUBSURF' for m in o.modifiers):
270
+ sub = o.modifiers.new(name="StudioSubsurf", type='SUBSURF')
271
+ sub.levels = 2
272
+ sub.render_levels = 2
273
+ print("Headless applied Studio Bevel and Subsurf")`;
244
274
  await runHeadlessCli(null, geomCode, results);
245
275
  }
246
276
  }
247
277
  else if (action.type === 'smartMaterial') {
248
278
  {
249
- const matCode = `import bpy, time\npreset = ${JSON.stringify(action.preset || "custom")}.lower()\ntargets = [bpy.data.objects.get(${JSON.stringify(action.name || "")})] if ${JSON.stringify(action.name || "")} else [o for o in bpy.context.scene.objects if o.type == 'MESH' and o.visible_get() and not any(k in o.name.lower() for k in ['floor', 'plane', 'backdrop', 'studio', 'ground', 'cove'])]\ntargets = [t for t in targets if t]\nmat = bpy.data.materials.new(name=f"CausynePBR_{preset.capitalize()}_{int(time.time()*1000)%10000}"); mat.use_nodes = True; nodes = mat.node_tree.nodes; links = mat.node_tree.links; nodes.clear()\nbsdf = nodes.new(type="ShaderNodeBsdfPrincipled"); bsdf.location = (0, 0); out = nodes.new(type="ShaderNodeOutputMaterial"); out.location = (300, 0); links.new(bsdf.outputs["BSDF"], out.inputs["Surface"])\nif preset in ["gold", "gold_brushed", "aztec_gold"]:\n bsdf.inputs["Base Color"].default_value = (1.0, 0.766, 0.336, 1.0); bsdf.inputs["Metallic"].default_value = 1.0; bsdf.inputs["Roughness"].default_value = 0.18\nelif preset in ["sandstone", "ancient_stone", "pyramid_stone"]:\n bsdf.inputs["Base Color"].default_value = (0.68, 0.55, 0.40, 1.0); bsdf.inputs["Roughness"].default_value = 0.85\nelif preset in ["velvet", "cushion_velvet", "watch_cushion"]:\n bsdf.inputs["Base Color"].default_value = (0.05, 0.06, 0.08, 1.0); bsdf.inputs["Roughness"].default_value = 0.9\nelif preset in ["chrome", "steel", "watch_case"]:\n bsdf.inputs["Base Color"].default_value = (0.88, 0.89, 0.90, 1.0); bsdf.inputs["Metallic"].default_value = 1.0; bsdf.inputs["Roughness"].default_value = 0.08\nfor o in targets:\n if len(o.data.materials) == 0: o.data.materials.append(mat)\n else: o.data.materials[0] = mat\nprint(f"Headless applied Smart PBR Material ({preset})")`;
279
+ const matCode = `import bpy, time
280
+ preset = ${JSON.stringify(action.preset || "custom")}.lower()
281
+ target_name = ${JSON.stringify(action.name || "")}
282
+ targets = [bpy.data.objects.get(target_name)] if target_name else [o for o in bpy.context.scene.objects if o.type == 'MESH' and o.visible_get() and not any(k in o.name.lower() for k in ['floor', 'plane', 'backdrop', 'studio', 'ground', 'cove'])]
283
+ targets = [t for t in targets if t]
284
+ mat = bpy.data.materials.new(name=f"CausynePBR_{preset.capitalize()}_{int(time.time()*1000)%10000}")
285
+ mat.use_nodes = True
286
+ nodes = mat.node_tree.nodes
287
+ links = mat.node_tree.links
288
+ nodes.clear()
289
+ bsdf = nodes.new(type="ShaderNodeBsdfPrincipled")
290
+ bsdf.location = (0, 0)
291
+ out = nodes.new(type="ShaderNodeOutputMaterial")
292
+ out.location = (300, 0)
293
+ links.new(bsdf.outputs["BSDF"], out.inputs["Surface"])
294
+ if preset in ["gold", "gold_brushed", "aztec_gold"]:
295
+ bsdf.inputs["Base Color"].default_value = (1.0, 0.766, 0.336, 1.0)
296
+ bsdf.inputs["Metallic"].default_value = 1.0
297
+ bsdf.inputs["Roughness"].default_value = 0.18
298
+ elif preset in ["sandstone", "ancient_stone", "pyramid_stone"]:
299
+ bsdf.inputs["Base Color"].default_value = (0.68, 0.55, 0.40, 1.0)
300
+ bsdf.inputs["Roughness"].default_value = 0.85
301
+ elif preset in ["velvet", "cushion_velvet", "watch_cushion"]:
302
+ bsdf.inputs["Base Color"].default_value = (0.05, 0.06, 0.08, 1.0)
303
+ bsdf.inputs["Roughness"].default_value = 0.9
304
+ elif preset in ["chrome", "steel", "watch_case"]:
305
+ bsdf.inputs["Base Color"].default_value = (0.88, 0.89, 0.90, 1.0)
306
+ bsdf.inputs["Metallic"].default_value = 1.0
307
+ bsdf.inputs["Roughness"].default_value = 0.08
308
+ for o in targets:
309
+ if len(o.data.materials) == 0:
310
+ o.data.materials.append(mat)
311
+ else:
312
+ o.data.materials[0] = mat
313
+ print(f"Headless applied Smart PBR Material ({preset})")`;
250
314
  await runHeadlessCli(null, matCode, results);
251
315
  }
252
316
  }
253
317
  else if (action.type === 'cinematicAtmosphere') {
254
318
  {
255
- const atmoCode = `import bpy, math\nw = bpy.context.scene.world or bpy.data.worlds.new("CausyneWorld"); bpy.context.scene.world = w; w.use_nodes = True; nodes = w.node_tree.nodes; links = w.node_tree.links; nodes.clear()\nbg = nodes.new("ShaderNodeBackground"); out = nodes.new("ShaderNodeOutputWorld"); sky = nodes.new("ShaderNodeTexSky"); sky.sky_type = 'MULTIPLE_SCATTERING' if hasattr(sky, 'sky_type') else 'HOSEK_WILKIE'; if hasattr(sky, 'sun_elevation'): sky.sun_elevation = math.radians(${action.sun_elevation || 12.0}); sky.sun_rotation = math.radians(-45.0); links.new(sky.outputs["Color"], bg.inputs["Color"]); links.new(bg.outputs["Background"], out.inputs["Surface"])\nif ${action.volumetric_fog !== false}:\n fm = bpy.data.materials.new("CausyneFog"); fm.use_nodes = True; fn = fm.node_tree.nodes; fl = fm.node_tree.links; fn.clear(); vol = fn.new("ShaderNodeVolumeScatter"); vol.inputs["Density"].default_value = ${action.fog_density || 0.015}; fo = fn.new("ShaderNodeOutputMaterial"); fl.new(vol.outputs["Volume"], fo.inputs["Volume"])\n bpy.ops.mesh.primitive_cube_add(size=40.0, location=(0,0,10)); fb = bpy.context.active_object; fb.name = "CausyneAtmosphereVolume"; fb.display_type = 'WIRE'; fb.data.materials.append(fm)\nprint("Headless applied Cinematic Atmosphere (Nishita Sky + Volumetric Fog)")`;
319
+ const atmoCode = `import bpy, math
320
+ w = bpy.context.scene.world or bpy.data.worlds.new("CausyneWorld")
321
+ bpy.context.scene.world = w
322
+ w.use_nodes = True
323
+ nodes = w.node_tree.nodes
324
+ links = w.node_tree.links
325
+ nodes.clear()
326
+ bg = nodes.new("ShaderNodeBackground")
327
+ out = nodes.new("ShaderNodeOutputWorld")
328
+ sky = nodes.new("ShaderNodeTexSky")
329
+ sky.sky_type = 'MULTIPLE_SCATTERING' if hasattr(sky, 'sky_type') else 'HOSEK_WILKIE'
330
+ if hasattr(sky, 'sun_elevation'):
331
+ sky.sun_elevation = math.radians(${action.sun_elevation || 12.0})
332
+ sky.sun_rotation = math.radians(-45.0)
333
+ links.new(sky.outputs["Color"], bg.inputs["Color"])
334
+ links.new(bg.outputs["Background"], out.inputs["Surface"])
335
+ if ${action.volumetric_fog !== false}:
336
+ fm = bpy.data.materials.new("CausyneFog")
337
+ fm.use_nodes = True
338
+ fn = fm.node_tree.nodes
339
+ fl = fm.node_tree.links
340
+ fn.clear()
341
+ vol = fn.new("ShaderNodeVolumeScatter")
342
+ vol.inputs["Density"].default_value = ${action.fog_density || 0.015}
343
+ fo = fn.new("ShaderNodeOutputMaterial")
344
+ fl.new(vol.outputs["Volume"], fo.inputs["Volume"])
345
+ bpy.ops.mesh.primitive_cube_add(size=40.0, location=(0,0,10))
346
+ fb = bpy.context.active_object
347
+ fb.name = "CausyneAtmosphereVolume"
348
+ fb.display_type = 'WIRE'
349
+ fb.data.materials.append(fm)
350
+ print("Headless applied Cinematic Atmosphere (Nishita Sky + Volumetric Fog)")`;
256
351
  await runHeadlessCli(null, atmoCode, results);
257
352
  }
258
353
  }
259
354
  else if (action.type === 'smartGeoNodes') {
260
355
  {
261
- const gnCode = `import bpy\ngen = ${JSON.stringify(action.generator || "masonry_brick_wall")}\ntargets = [o for o in bpy.context.scene.objects if o.type == 'MESH' and "Volume" not in o.name and "Floor" not in o.name]\nfor o in targets:\n mod = o.modifiers.new(name=f"GeoNode_{gen}", type='NODES')\n ng = bpy.data.node_groups.get(f"GN_{gen}")\n if not ng:\n ng = bpy.data.node_groups.new(f"GN_{gen}", 'GeometryNodeTree')\n ng.interface.new_socket("Geometry", in_out='INPUT', socket_type='NodeSocketGeometry')\n ng.interface.new_socket("Geometry", in_out='OUTPUT', socket_type='NodeSocketGeometry')\n gi = ng.nodes.new('NodeGroupInput'); gi.location = (-400,0); go = ng.nodes.new('NodeGroupOutput'); go.location = (400,0)\n if gen == "masonry_brick_wall":\n s = ng.nodes.new('GeometryNodeSubdivideMesh'); s.location = (-150,0); s.inputs["Level"].default_value = ${action.subdivisions || 3}\n ng.links.new(gi.outputs["Geometry"], s.inputs["Mesh"]); ng.links.new(s.outputs["Mesh"], go.inputs["Geometry"])\n else: ng.links.new(gi.outputs["Geometry"], go.inputs["Geometry"])\n mod.node_group = ng\nprint(f"Headless attached Geometry Nodes ({gen})")`;
356
+ const gnCode = `import bpy
357
+ gen = ${JSON.stringify(action.generator || "masonry_brick_wall")}
358
+ targets = [o for o in bpy.context.scene.objects if o.type == 'MESH' and "Volume" not in o.name and "Floor" not in o.name]
359
+ for o in targets:
360
+ mod = o.modifiers.new(name=f"GeoNode_{gen}", type='NODES')
361
+ ng = bpy.data.node_groups.get(f"GN_{gen}")
362
+ if not ng:
363
+ ng = bpy.data.node_groups.new(f"GN_{gen}", 'GeometryNodeTree')
364
+ ng.interface.new_socket("Geometry", in_out='INPUT', socket_type='NodeSocketGeometry')
365
+ ng.interface.new_socket("Geometry", in_out='OUTPUT', socket_type='NodeSocketGeometry')
366
+ gi = ng.nodes.new('NodeGroupInput')
367
+ gi.location = (-400,0)
368
+ go = ng.nodes.new('NodeGroupOutput')
369
+ go.location = (400,0)
370
+ if gen == "masonry_brick_wall":
371
+ s = ng.nodes.new('GeometryNodeSubdivideMesh')
372
+ s.location = (-150,0)
373
+ s.inputs["Level"].default_value = ${action.subdivisions || 3}
374
+ ng.links.new(gi.outputs["Geometry"], s.inputs["Mesh"])
375
+ ng.links.new(s.outputs["Mesh"], go.inputs["Geometry"])
376
+ else:
377
+ ng.links.new(gi.outputs["Geometry"], go.inputs["Geometry"])
378
+ mod.node_group = ng
379
+ print(f"Headless attached Geometry Nodes ({gen})")`;
262
380
  await runHeadlessCli(null, gnCode, results);
263
381
  }
264
382
  }
265
383
  else if (action.type === 'setupStudioLighting') {
266
384
  {
267
- const lightCode = `import bpy, math\nfor o in list(bpy.context.scene.objects):\n if o.type == 'LIGHT': bpy.data.objects.remove(o, do_unlink=True)\nkd = bpy.data.lights.new('Key', 'AREA'); kd.energy = ${action.key_energy || 800}; kd.size = 5.0; ko = bpy.data.objects.new('Key', kd); ko.location = (6, -6, 8); ko.rotation_euler = (math.radians(45), 0, math.radians(45)); bpy.context.scene.collection.objects.link(ko)\nprint('Headless studio lighting built')`;
385
+ const lightCode = `import bpy, math
386
+ for o in list(bpy.context.scene.objects):
387
+ if o.type == 'LIGHT':
388
+ bpy.data.objects.remove(o, do_unlink=True)
389
+ kd = bpy.data.lights.new('Key', 'AREA')
390
+ kd.energy = ${action.key_energy || 800}
391
+ kd.size = 5.0
392
+ ko = bpy.data.objects.new('Key', kd)
393
+ ko.location = (6, -6, 8)
394
+ ko.rotation_euler = (math.radians(45), 0, math.radians(45))
395
+ bpy.context.scene.collection.objects.link(ko)
396
+ print('Headless studio lighting built')`;
268
397
  await runHeadlessCli(null, lightCode, results);
269
398
  }
270
399
  }
@@ -274,14 +403,31 @@ export const blenderAct = {
274
403
  const fmts = action.formats || ['blend', 'glb'];
275
404
 
276
405
  {
277
- const exportCode = `import bpy, os\nd = "${destDir}"\nos.makedirs(d, exist_ok=True)\nif "blend" in ${JSON.stringify(fmts)}:\n bpy.ops.wm.save_as_mainfile(filepath=os.path.join(d, "${prefix}.blend"))\nif "glb" in ${JSON.stringify(fmts)}:\n bpy.ops.export_scene.gltf(filepath=os.path.join(d, "${prefix}.glb"), export_format="GLB")\nif "obj" in ${JSON.stringify(fmts)}:\n if hasattr(bpy.ops.wm, "obj_export"): bpy.ops.wm.obj_export(filepath=os.path.join(d, "${prefix}.obj"))\n else: bpy.ops.export_scene.obj(filepath=os.path.join(d, "${prefix}.obj"))\nprint(f"Headless exported formats to {d}")`;
406
+ const exportCode = `import bpy, os
407
+ d = "${destDir}"
408
+ os.makedirs(d, exist_ok=True)
409
+ if "blend" in ${JSON.stringify(fmts)}:
410
+ bpy.ops.wm.save_as_mainfile(filepath=os.path.join(d, "${prefix}.blend"))
411
+ if "glb" in ${JSON.stringify(fmts)}:
412
+ bpy.ops.export_scene.gltf(filepath=os.path.join(d, "${prefix}.glb"), export_format="GLB")
413
+ if "obj" in ${JSON.stringify(fmts)}:
414
+ if hasattr(bpy.ops.wm, "obj_export"):
415
+ bpy.ops.wm.obj_export(filepath=os.path.join(d, "${prefix}.obj"))
416
+ else:
417
+ bpy.ops.export_scene.obj(filepath=os.path.join(d, "${prefix}.obj"))
418
+ print(f"Headless exported formats to {d}")`;
278
419
  await runHeadlessCli(null, exportCode, results);
279
420
  }
280
421
  }
281
422
  else if (action.type === 'clearScene') {
282
423
  const keep = action.keep_lights_camera !== false;
283
424
  {
284
- const clearCode = `import bpy\nfor o in list(bpy.context.scene.objects):\n if ${keep} and o.type in ['CAMERA', 'LIGHT']: continue\n bpy.data.objects.remove(o, do_unlink=True)\nprint("Headless cleared scene meshes")`;
425
+ const clearCode = `import bpy
426
+ for o in list(bpy.context.scene.objects):
427
+ if ${keep} and o.type in ['CAMERA', 'LIGHT']:
428
+ continue
429
+ bpy.data.objects.remove(o, do_unlink=True)
430
+ print("Headless cleared scene meshes")`;
285
431
  await runHeadlessCli(null, clearCode, results);
286
432
  }
287
433
  }
@@ -306,7 +452,10 @@ export const blenderAct = {
306
452
  else if (action.type === 'captureViewport') {
307
453
  const targetPath = action.filepath || path.join(getWorkspaceTempDir(), `causyne_3d_preview_${Date.now()}.png`);
308
454
  {
309
- const captureCode = `import bpy, os\nos.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)\nbpy.ops.render.opengl(write_still=True, filepath="${targetPath}")\nprint("Captured headless viewport to ${targetPath}")`;
455
+ const captureCode = `import bpy, os
456
+ os.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)
457
+ bpy.ops.render.opengl(write_still=True, filepath="${targetPath}")
458
+ print("Captured headless viewport to ${targetPath}")`;
310
459
  try {
311
460
  await runHeadlessCli(null, captureCode, results);
312
461
  } catch (cliErr) {
@@ -322,8 +471,46 @@ export const blenderAct = {
322
471
 
323
472
  {
324
473
  const renderCode = isAnimation ?
325
- `import bpy, os, time\nos.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)\nbpy.context.scene.frame_start = ${startFrame}\nbpy.context.scene.frame_end = ${endFrame}\nif "${action.engine || ''}": bpy.context.scene.render.engine = "${action.engine || ''}"\ntry:\n bpy.context.scene.render.filepath = "${targetPath}"\n bpy.context.scene.render.image_settings.file_format = 'FFMPEG'\n if hasattr(bpy.context.scene.render, 'ffmpeg'):\n bpy.context.scene.render.ffmpeg.format = 'MPEG4' if "${targetPath}".lower().endswith('.mp4') else 'MKV'\n bpy.context.scene.render.ffmpeg.codec = 'H264'\n bpy.ops.render.render(animation=True)\n print(f"Rendered MP4 animation directly to ${targetPath}")\nexcept Exception:\n import subprocess, shutil as sh_util\n td = os.path.join(os.path.dirname("${targetPath}"), ".causyne_temp_frames_" + str(int(time.time())))\n os.makedirs(td, exist_ok=True)\n bpy.context.scene.render.image_settings.file_format = 'PNG'\n bpy.context.scene.render.filepath = os.path.join(td, "frame_")\n bpy.ops.render.render(animation=True)\n fps = getattr(bpy.context.scene.render, "fps", 30)\n fb = sh_util.which("ffmpeg")\n if not fb:\n for cand in ["/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg", "C:\\\\Program Files\\\\ffmpeg\\\\bin\\\\ffmpeg.exe"]:\n if os.path.exists(cand): fb = cand; break\n if not fb: fb = "ffmpeg"\n subprocess.run([fb, "-y", "-framerate", str(fps), "-i", os.path.join(td, "frame_%04d.png"), "-c:v", "libx264", "-pix_fmt", "yuv420p", "${targetPath}"], check=True)\n sh_util.rmtree(td, ignore_errors=True)\n print(f"Rendered MP4 animation via sequence to ${targetPath}")` :
326
- `import bpy, os\nos.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)\nbpy.context.scene.render.filepath = "${targetPath}"\nif "${action.engine || ''}": bpy.context.scene.render.engine = "${action.engine || ''}"\nbpy.ops.render.render(write_still=True)\nprint(f"Rendered still frame to ${targetPath}")`;
474
+ `import bpy, os, time
475
+ os.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)
476
+ bpy.context.scene.frame_start = ${startFrame}
477
+ bpy.context.scene.frame_end = ${endFrame}
478
+ if "${action.engine || ''}":
479
+ bpy.context.scene.render.engine = "${action.engine || ''}"
480
+ try:
481
+ bpy.context.scene.render.filepath = "${targetPath}"
482
+ bpy.context.scene.render.image_settings.file_format = 'FFMPEG'
483
+ if hasattr(bpy.context.scene.render, 'ffmpeg'):
484
+ bpy.context.scene.render.ffmpeg.format = 'MPEG4' if "${targetPath}".lower().endsWith('.mp4') else 'MKV'
485
+ bpy.context.scene.render.ffmpeg.codec = 'H264'
486
+ bpy.ops.render.render(animation=True)
487
+ print(f"Rendered MP4 animation directly to ${targetPath}")
488
+ except Exception:
489
+ import subprocess, shutil as sh_util
490
+ td = os.path.join(os.path.dirname("${targetPath}"), ".causyne_temp_frames_" + str(int(time.time())))
491
+ os.makedirs(td, exist_ok=True)
492
+ bpy.context.scene.render.image_settings.file_format = 'PNG'
493
+ bpy.context.scene.render.filepath = os.path.join(td, "frame_")
494
+ bpy.ops.render.render(animation=True)
495
+ fps = getattr(bpy.context.scene.render, "fps", 30)
496
+ fb = sh_util.which("ffmpeg")
497
+ if not fb:
498
+ for cand in ["/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg", "C:\\\\Program Files\\\\ffmpeg\\\\bin\\\\ffmpeg.exe"]:
499
+ if os.path.exists(cand):
500
+ fb = cand
501
+ break
502
+ if not fb:
503
+ fb = "ffmpeg"
504
+ subprocess.run([fb, "-y", "-framerate", str(fps), "-i", os.path.join(td, "frame_%04d.png"), "-c:v", "libx264", "-pix_fmt", "yuv420p", "${targetPath}"], check=True)
505
+ sh_util.rmtree(td, ignore_errors=True)
506
+ print(f"Rendered MP4 animation via sequence to ${targetPath}")` :
507
+ `import bpy, os
508
+ os.makedirs(os.path.dirname("${targetPath}"), exist_ok=True)
509
+ bpy.context.scene.render.filepath = "${targetPath}"
510
+ if "${action.engine || ''}":
511
+ bpy.context.scene.render.engine = "${action.engine || ''}"
512
+ bpy.ops.render.render(write_still=True)
513
+ print(f"Rendered still frame to ${targetPath}")`;
327
514
  try {
328
515
  await runHeadlessCli(null, renderCode, results);
329
516
  } catch (cliErr) {
@@ -5,7 +5,7 @@ const SUPPORTED_ACTION_TYPES = [
5
5
  'listTabs', 'list_tabs',
6
6
  'closeTab', 'close_tab',
7
7
  'search',
8
- 'goto', 'open', 'navigate',
8
+ 'goto', 'open', 'navigate', 'preview',
9
9
  'snapshot', 'scrape',
10
10
  'click', 'clickIndex',
11
11
  'type', 'typeIndex', 'fill',
@@ -45,7 +45,7 @@ function normalizeActions(args) {
45
45
  export const browserAct = {
46
46
  schema: {
47
47
  name: 'browser.act',
48
- description: `Use the dedicated Causyne Browser for resilient search, navigation, search macros (${getSupportedSearchMacros().slice(0, 6).join(', ')}, etc.), accessible snapshots (including child iframes and structured forms/tables), interaction, deterministic schema extraction, and workspace-scoped uploads/downloads. Take a snapshot before interacting by ref.`,
48
+ description: `Use the dedicated Causyne Browser for search, public navigation, and preview of a workspace HTML file (type preview, filePath), accessible snapshots, interaction, extraction, and workspace-scoped screenshots. Use preview followed by snapshot and screenshot to check a local web page; a saved screenshot alone is not visual inspection by the model.`,
49
49
  parameters: {
50
50
  type: 'object',
51
51
  properties: {
@@ -94,7 +94,7 @@ export const browserAct = {
94
94
  { type: 'string' },
95
95
  { type: 'array', items: { type: 'string' } }
96
96
  ],
97
- description: 'Workspace-relative file path(s) for upload action.'
97
+ description: 'Workspace-relative HTML path for preview, or file path(s) for upload.'
98
98
  },
99
99
  outputFile: { type: 'string', description: 'Download or screenshot destination inside the selected workspace.' },
100
100
  fullPage: { type: 'boolean', description: 'Capture the complete page for a screenshot instead of the visible viewport.' }
@@ -17,7 +17,7 @@ const SUPPORTED_ACTION_TYPES: BrowserActionType[] = [
17
17
  'listTabs', 'list_tabs',
18
18
  'closeTab', 'close_tab',
19
19
  'search',
20
- 'goto', 'open', 'navigate',
20
+ 'goto', 'open', 'navigate', 'preview',
21
21
  'snapshot', 'scrape',
22
22
  'click', 'clickIndex',
23
23
  'type', 'typeIndex', 'fill',
@@ -58,7 +58,7 @@ function normalizeActions(args: Record<string, unknown> | undefined): BrowserAct
58
58
  export const browserAct = {
59
59
  schema: {
60
60
  name: 'browser.act',
61
- description: `Use the dedicated Causyne Browser for resilient search, navigation, search macros (${getSupportedSearchMacros().slice(0, 6).join(', ')}, etc.), accessible snapshots (including child iframes and structured forms/tables), interaction, deterministic schema extraction, and workspace-scoped uploads/downloads. Take a snapshot before interacting by ref.`,
61
+ description: `Use the dedicated Causyne Browser for search, public navigation, and preview of a workspace HTML file (type preview, filePath), accessible snapshots, interaction, extraction, and workspace-scoped screenshots. Use preview followed by snapshot and screenshot to check a local web page; a saved screenshot alone is not visual inspection by the model.`,
62
62
  parameters: {
63
63
  type: 'object',
64
64
  properties: {
@@ -107,7 +107,7 @@ export const browserAct = {
107
107
  { type: 'string' },
108
108
  { type: 'array', items: { type: 'string' } }
109
109
  ],
110
- description: 'Workspace-relative file path(s) for upload action.'
110
+ description: 'Workspace-relative HTML path for preview, or file path(s) for upload.'
111
111
  },
112
112
  outputFile: { type: 'string', description: 'Download or screenshot destination inside the selected workspace.' },
113
113
  fullPage: { type: 'boolean', description: 'Capture the complete page for a screenshot instead of the visible viewport.' }
@@ -15,7 +15,7 @@ import { resolveUserPath } from '../utils/paths.js';
15
15
  export const documentForgeTool = {
16
16
  schema: {
17
17
  name: 'document_forge',
18
- description: 'Causyne Document Forge: Professional document & media production harness. Generates pixel-perfect A4/Letter publications via HTML/CSS-First Paged Media and Headless Chrome, renders vector PDFs (<2MB compliant), extracts page images for visual QA ("Lihat Hasilnya"), audits anti-slop and math integrity, formats Hollywood Courier 12pt screenplays, creates production shot lists, and times VO narration.',
18
+ description: 'Causyne Document Forge: Professional document & media production harness. Generates pixel-perfect A4/Letter publications via HTML/CSS-First Paged Media and Headless Chrome, renders vector PDFs (<2MB compliant), extracts page images for visual QA ("Inspect Results"), audits anti-slop and math integrity, formats Hollywood Courier 12pt screenplays, creates production shot lists, and times VO narration.',
19
19
  parameters: {
20
20
  type: 'object',
21
21
  properties: {
@@ -55,7 +55,7 @@ export interface DocumentForgeArgs {
55
55
  export const documentForgeTool = {
56
56
  schema: {
57
57
  name: 'document_forge',
58
- description: 'Causyne Document Forge: Professional document & media production harness. Generates pixel-perfect A4/Letter publications via HTML/CSS-First Paged Media and Headless Chrome, renders vector PDFs (<2MB compliant), extracts page images for visual QA ("Lihat Hasilnya"), audits anti-slop and math integrity, formats Hollywood Courier 12pt screenplays, creates production shot lists, and times VO narration.',
58
+ description: 'Causyne Document Forge: Professional document & media production harness. Generates pixel-perfect A4/Letter publications via HTML/CSS-First Paged Media and Headless Chrome, renders vector PDFs (<2MB compliant), extracts page images for visual QA ("Inspect Results"), audits anti-slop and math integrity, formats Hollywood Courier 12pt screenplays, creates production shot lists, and times VO narration.',
59
59
  parameters: {
60
60
  type: 'object',
61
61
  properties: {
@@ -1,87 +1,98 @@
1
- import fs from 'fs';
2
- import readline from 'readline';
3
- import path from 'path';
4
- import os from 'os';
5
-
6
- // Phase 3 AGI Upgrade: Fast Binary Detection
1
+ import fs from 'node:fs';
2
+ import readline from 'node:readline';
3
+ import path from 'node:path';
4
+ import os from 'node:os';
5
+ const BINARY_EXTENSIONS = /\.(png|jpe?g|webp|gif|svg|bmp|ico|blend\d?|glb|gltf|wasm|zip|tar|gz|bz2|xz|7z|rar|mp4|mov|avi|mkv|webm|mp3|wav|ogg|flac|aac|m4a|pdf|exe|dll|dylib|so|bin|iso|dmg)$/i;
6
+ /** Fast Binary Detection: inspect the first 1024 bytes for a null byte. */
7
7
  async function isBinary(filePath) {
8
- try {
9
- const fd = await fs.promises.open(filePath, 'r');
10
- const buffer = Buffer.alloc(1024);
11
- const { bytesRead } = await fd.read(buffer, 0, 1024, 0);
12
- await fd.close();
13
-
14
- for (let i = 0; i < bytesRead; i++) {
15
- if (buffer[i] === 0) return true; // Null byte indicates binary
8
+ try {
9
+ const fd = await fs.promises.open(filePath, 'r');
10
+ const buffer = Buffer.alloc(1024);
11
+ const { bytesRead } = await fd.read(buffer, 0, 1024, 0);
12
+ await fd.close();
13
+ for (let i = 0; i < bytesRead; i++) {
14
+ if (buffer[i] === 0)
15
+ return true;
16
+ }
17
+ return false;
18
+ }
19
+ catch {
20
+ return false;
16
21
  }
17
- return false;
18
- } catch (e) {
19
- return false;
20
- }
21
22
  }
22
-
23
23
  export const fsRead = {
24
- schema: {
25
- name: 'fs.read',
26
- description: 'Read file contents intelligently. Automatically pages large files to protect Context Window.',
27
- parameters: {
28
- type: 'object',
29
- properties: {
30
- path: { type: 'string' },
31
- startLine: { type: 'number' },
32
- endLine: { type: 'number' }
33
- },
34
- required: ['path']
35
- }
36
- },
37
- async execute(args) {
38
- try {
39
- const target = args.path.replace(/^~\//, os.homedir() + '/');
40
-
41
- if (!fs.existsSync(target)) {
42
- return { success: false, error: "File does not exist." };
43
- }
44
-
45
- // Phase 3 AGI Upgrade: Binary Rejection
46
- if (await isBinary(target)) {
47
- return { success: false, error: "Cannot read binary file as text. Use viewImage or OCR tools instead." };
48
- }
49
-
50
- const start = args.startLine ? Math.max(1, args.startLine) : 1;
51
- let end = args.endLine ? args.endLine : start + 799;
52
-
53
- // Phase 3 AGI Upgrade: Mandatory Paging Limit (800)
54
- if (end - start + 1 > 800) {
55
- end = start + 799;
56
- }
57
-
58
- let currentLine = 1;
59
- let outputLines = [];
60
- let totalLines = 0;
61
-
62
- // Phase 3 AGI Upgrade: Stream (no full buffering)
63
- const rl = readline.createInterface({
64
- input: fs.createReadStream(target),
65
- crlfDelay: Infinity
66
- });
67
-
68
- for await (const line of rl) {
69
- totalLines++;
70
- if (currentLine >= start && currentLine <= end) {
71
- outputLines.push(line);
24
+ schema: {
25
+ name: 'fs.read',
26
+ description: 'Read file contents intelligently. Automatically pages large files to protect Context Window.',
27
+ parameters: {
28
+ type: 'object',
29
+ properties: {
30
+ path: { type: 'string' },
31
+ startLine: { type: 'number' },
32
+ endLine: { type: 'number' }
33
+ },
34
+ required: ['path']
35
+ }
36
+ },
37
+ async execute(args) {
38
+ try {
39
+ if (!args || typeof args.path !== 'string' || !args.path.trim()) {
40
+ return { success: false, error: 'Missing required parameter: path' };
41
+ }
42
+ const target = args.path.replace(/^~\//, os.homedir() + '/');
43
+ if (!fs.existsSync(target)) {
44
+ return { success: false, error: 'File does not exist.' };
45
+ }
46
+ const ext = path.extname(target).toLowerCase();
47
+ const isKnownBinaryExt = BINARY_EXTENSIONS.test(ext);
48
+ // Fast check for binary media/executables to prevent token context blowup
49
+ if (isKnownBinaryExt || (await isBinary(target))) {
50
+ let stat = null;
51
+ try {
52
+ stat = fs.statSync(target);
53
+ }
54
+ catch {
55
+ // ignore stat error
56
+ }
57
+ const sizeStr = stat ? `${(stat.size / 1024).toFixed(1)} KB` : 'unknown size';
58
+ const isImage = /\.(png|jpe?g|webp|gif|svg|bmp|ico)$/i.test(ext);
59
+ return {
60
+ success: false,
61
+ isBinary: true,
62
+ error: isImage
63
+ ? `Cannot read image file '${path.basename(target)}' as plain text. Use view_image (or vision inspection). File metadata: ${sizeStr}, format: ${ext.replace('.', '').toUpperCase() || 'IMAGE'}.`
64
+ : `Cannot read binary file '${path.basename(target)}' as plain text. File size: ${sizeStr}.`
65
+ };
66
+ }
67
+ const start = typeof args.startLine === 'number' && args.startLine > 0 ? Math.floor(args.startLine) : 1;
68
+ let end = typeof args.endLine === 'number' && args.endLine >= start ? Math.floor(args.endLine) : start + 799;
69
+ // Mandatory Paging Limit: at most 800 lines per read to preserve context
70
+ if (end - start + 1 > 800) {
71
+ end = start + 799;
72
+ }
73
+ let currentLine = 1;
74
+ const outputLines = [];
75
+ let totalLines = 0;
76
+ const rl = readline.createInterface({
77
+ input: fs.createReadStream(target),
78
+ crlfDelay: Infinity
79
+ });
80
+ for await (const line of rl) {
81
+ totalLines++;
82
+ if (currentLine >= start && currentLine <= end) {
83
+ outputLines.push(line);
84
+ }
85
+ currentLine++;
86
+ }
87
+ let finalOutput = outputLines.join('\n');
88
+ if (totalLines > end) {
89
+ finalOutput += `\n\n[WARNING: File truncated at line ${end} out of ${totalLines}. Use { startLine: ${end + 1}, endLine: ${end + 800} } to read more.]`;
90
+ }
91
+ return { success: true, output: finalOutput };
92
+ }
93
+ catch (e) {
94
+ const msg = e instanceof Error ? e.message : String(e);
95
+ return { success: false, error: msg };
72
96
  }
73
- currentLine++;
74
- }
75
-
76
- let finalOutput = outputLines.join('\n');
77
-
78
- if (totalLines > end) {
79
- finalOutput += `\n\n[WARNING: File truncated at line ${end} out of ${totalLines}. Use { startLine: ${end + 1}, endLine: ${end + 800} } to read more.]`;
80
- }
81
-
82
- return { success: true, output: finalOutput };
83
- } catch (e) {
84
- return { success: false, error: e.message };
85
97
  }
86
- }
87
98
  };