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:0xsline OpenChatCut Tool Catalog

From Leeroopedia
Knowledge Sources
Domains Tooling, CLI, Agent
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete tool surface for the `occ` CLI that defines which editor tools can run headlessly (without a browser), validates tool invocations, and parses `--ops` JSON into structured tool operations.

Description

The Tool Catalog module provides the CLI's tool whitelist and parsing utilities. It bridges the full editor tool surface (`TOOL_SCHEMAS` from `src/agent/tools.ts`) and the offline headless subset (`offlineExternalToolSchemas` from `server/external-agent/offline-tools.ts`).

Key functions:

  • `headlessToolNames()` — Returns the set of tool names that can run without a browser.
  • `requireHeadlessTool(tool)` — Validates that a tool is headless-safe; throws `CliError` with an actionable message if not.
  • `parseToolOps(text)` — Parses a JSON `--ops` string into an array of validated `ToolOp` objects.
  • `toolRows(all)` — Returns tool metadata rows for the `occ tools ls` command.

Growing the headless set means reviewing a tool's runtime dependencies in the shared policy — never bypassing it here.

Usage

  • CLI tool listing: `occ tools ls` and `occ tools ls --all` use `toolRows()`.
  • CLI tool validation: Before dispatching any tool, `requireHeadlessTool()` gates access.
  • CLI `--ops` parsing: `parseToolOps()` converts the JSON array into validated `ToolOp[]`.

Code Reference

Source Location

Signature

export interface ToolRow {
  readonly name: string;
  readonly headless: boolean;
  readonly description: string;
}

export interface ToolOp {
  readonly tool: string;
  readonly args: Record<string, unknown>;
}

export function headlessToolNames(): Set<string>;
export function toolRows(all: boolean): ToolRow[];
export function requireHeadlessTool(tool: string): void;
export function parseToolOp(value: unknown, index: number): ToolOp;
export function parseToolOps(text: string): ToolOp[];
export function parseJsonObject(text: string, label: string): Record<string, unknown>;

Import

import {
  headlessToolNames,
  toolRows,
  requireHeadlessTool,
  parseToolOps,
  type ToolOp,
} from './tool-catalog.ts';

I/O Contract

Inputs

Name Type Required Description
tool string Yes Tool name to validate (for `requireHeadlessTool`)
text string Yes JSON string to parse (for `parseToolOps`)
all boolean No Whether to include browser-only tools in `toolRows`

Outputs

Name Type Description
headlessToolNames() returns Set<string> Set of headless-safe tool names
toolRows() returns ToolRow[] Sorted tool metadata rows
requireHeadlessTool() returns void Throws CliError if tool is not headless-safe
parseToolOps() returns ToolOp[] Array of validated { tool, args } operations

Usage Examples

Parsing CLI --ops

import { parseToolOps } from './tool-catalog.ts';

// Parse a JSON --ops argument
const ops = parseToolOps(`[
  { "tool": "import_media", "args": { "path": "/videos/clip.mp4" } },
  { "tool": "split_clip", "args": { "clipId": "abc", "frame": 120 } }
]`);

for (const op of ops) {
  console.log(`Tool: ${op.tool}, Args:`, op.args);
}

Listing Headless Tools

import { headlessToolNames, toolRows } from './tool-catalog.ts';

// Check if a tool is headless-safe
const headless = headlessToolNames();
console.log('import_media headless?', headless.has('import_media'));

// List all tools for `occ tools ls --all`
const rows = toolRows(true);
for (const row of rows) {
  const flag = row.headless ? '✓' : '✗';
  console.log(`${flag} ${row.name}: ${row.description}`);
}

Related Pages

Implements Principle

Requires Environment

Page Connections

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