Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:3641397194 wq Gpt6 Astra ToolboxEngine

From Leeroopedia
Knowledge Sources
Domains Tool_Design, Plugin_Architecture, Security
Last Updated 2026-10-26 12:00 GMT

Overview

Concrete tool for executing named security tools with schema validation, workspace containment, and task lifecycle management, provided by the ColdBrew Zero toolbox library.

Description

The ToolboxEngine class is the execution engine for the original 16-tool security toolbox. It validates tool arguments against schemas, dispatches to type-specific handlers (network, binary, IDA, workflow), and provides workspace containment for file operations.

The engine manages a workspace directory where all file operations occur. The `file()` method resolves any file argument to a `realpathSync` inside the workspace, rejecting paths that escape via `..` or symlinks. The `directory()` method creates nested directories with per-level symlink validation. The `importSample()` method copies external files into `samples/<sha256prefix>-<name>` with content-addressed deduplication.

The `start()` method runs tools as async tasks with a 4-concurrent / 100-total limit, cancellation via AbortController, and persistence to `runs/<uuid>/result.json` + `report.md`. The `workflow()` method chains multiple tools for web recon or reverse engineering pipelines.

Usage

  • Agent loop: `execute(name, args, ctx)` is called by `runAgent` for each tool decision.
  • Direct execution: `start(name, args)` runs a tool as a managed task with cancellation and persistence.
  • Workflow execution: `execute('run_workflow', args)` chains multiple tools automatically.
  • Sample import: `importSample(source)` copies an external file into the workspace for analysis.
  • Catalog: `catalog()` returns the tool list and schemas for display to the AI model.

Code Reference

Source Location

  • Repository: ColdBrew Zero
  • File: desktop/src/lib/toolbox/engine.js

Signature

class ToolboxEngine {
  constructor({ workspace, emit = () => {} })

  catalog() -> { version, original, runtime, workspace, tools }
  directory(relative) -> string  // creates and validates within workspace
  file(value) -> string  // resolves and validates file within workspace
  read(value) -> Buffer
  importSample(source) -> { file, name, bytes, sha256 }

  async execute(name, args = {}, ctx = {}) -> result  // dispatch to handler
  async workflow(args, ctx = {}) -> { mode, status, stages }  // chain tools

  start(name, args = {}, runner) -> task view  // async task with limits
  get(id) -> task view  // structuredClone of task (no controller/promise)
  list() -> Array  // task summaries (no result/events)
  wait(id) -> Promise  // await task completion
  cancel(id) -> task view  // abort via AbortController
  save(task) -> void  // persist to runs/<id>/result.json + report.md
}

Import

const { ToolboxEngine } = require('./toolbox/engine');

I/O Contract

Inputs

Name Type Required Description
workspace string Yes Workspace directory path (created if missing, realpath-resolved)
emit function No /// Event emitter callback (default: no-op)
name string Yes (execute) Tool name from TOOLS registry
args object No (execute) Tool arguments (validated against tool.inputSchema)
ctx.signal AbortSignal No (execute) Cancellation signal
ctx.emit function No (execute) /// Stage event emitter

Outputs

Name Type Description
execute() returns object Tool-specific result (varies by tool)
workflow() returns object 'partial'|'failed', stages: [{tool, status, result?}] }
start() returns object Task view: { id, name, args, status, startedAt, events, result, report? }
catalog() returns object { version, original: true, tools: TOOLS }
importSample() returns object { file: relativePath, name, bytes, sha256 }

Usage Examples

Direct Tool Execution

const { ToolboxEngine } = require('./toolbox/engine');

const engine = new ToolboxEngine({ workspace: '/tmp/toolbox-workspace' });

// Execute a network tool
const result = await engine.execute('resolve_host', { host: 'example.com' }, {});
console.log(result); // { host: 'example.com', addresses: ['93.184.216.34'], ... }

// Execute a binary tool (requires file in workspace)
const sample = engine.importSample('/tmp/suspicious.exe');
const analysis = await engine.execute('analyze_binary',
  { file: sample.file }, {});
console.log(analysis.format); // 'pe64' | 'elf' | ...

Web Workflow (Multi-Tool Chain)

const { ToolboxEngine } = require('./toolbox/engine');

const engine = new ToolboxEngine({ workspace: '/tmp/toolbox-workspace' });

const result = await engine.workflow({
  mode: 'web',
  url: 'https://example.com',
  ports: '80,443',
  maxPages: 12,
  timeoutMs: 1000
}, { signal: AbortSignal.timeout(60000) });

console.log(`Status: ${result.status}`);
for (const stage of result.stages) {
  console.log(`  ${stage.tool}: ${stage.status}`);
}
// Stages: resolve_host → scan_ports → inspect_http → crawl_site → find_paths → check_web

Reverse Workflow with IDA

const { ToolboxEngine } = require('./toolbox/engine');

const engine = new ToolboxEngine({ workspace: '/tmp/toolbox-workspace' });
const sample = engine.importSample('/tmp/target.exe');

const result = await engine.workflow({
  mode: 'reverse',
  file: sample.file,
  useIda: true,
  idaUrl: 'http://localhost:13337/mcp'
}, {});

// Stages: analyze_binary → ida_connect → ida_call (read tool)

Patch Bytes (Creates Derived File)

const { ToolboxEngine } = require('./toolbox/engine');

const engine = new ToolboxEngine({ workspace: '/tmp/toolbox-workspace' });
const sample = engine.importSample('/tmp/target.exe');

const result = await engine.execute('patch_bytes', {
  file: sample.file,
  patches: [{ offset: 4096, bytes: '9090', encoding: 'hex' }],
  expectedSha256: 'abc123...'
}, {});
console.log(result.file); // 'patched/uuid-target.exe'
console.log(result.sourceUnchanged); // true
console.log(result.file + '.json'); // manifest file

Async Task with Cancellation

const { ToolboxEngine } = require('./toolbox/engine');

const engine = new ToolboxEngine({ workspace: '/tmp/toolbox' });

// Start as managed task (4 concurrent max, 100 total)
const task = engine.start('crawl_site',
  { url: 'https://example.com', maxPages: 50 });

console.log(task.status); // 'queued' → 'running' → 'completed'

// Wait for completion
const final = await engine.wait(task.id);
console.log(final.result);

// Or cancel mid-run
engine.cancel(task.id);
console.log(engine.get(task.id).status); // 'cancelled'

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment