← 返回
未分类 中文

Exec Truncate

AI agent tool for compressing/executing shell commands with domain-aware output truncation. Use when exec tool output needs to be compressed, when running gi...
AI代理工具,用于压缩/执行shell命令并提供领域感知的输出截断。适用于需要压缩exec工具输出或运行gi...
ether-btc
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 334
下载
💾 0
安装
1
版本
#latest

概述

Exec-Truncate Skill

Domain-aware output truncation for shell command execution. Compresses verbose output while preserving critical information.

What It Does

This skill provides intelligent truncation for common command patterns:

  • git diff — Keeps first 100 + last 20 lines, shows only additions (+)
  • git log — Condensed one-liners with short hashes (7 chars), subjects, branches
  • grep/rg/find — Caps at 50 matches, strips path prefixes
  • ls -la/ls -l — Max 100 entries, keeps filename + abbreviated size
  • build tools — Strips ANSI codes, progress bars; keeps errors/warnings only

Integration Note

This is a standalone skill, not wired into OpenClaw's exec tool. OpenClaw distributions are compiled/bundled, so this runs as a utility the AI applies manually to output it already has.

Available Functions

Individual Truncation Functions

import {
  truncateGitDiff,
  truncateGitLog,
  truncateGrepOutput,
  truncateLsOutput,
  truncateBuildOutput,
  truncateExecOutput,
} from "./mod.ts";

// Direct usage
const truncated = truncateGitDiff(rawOutput);
const condensed = truncateGitLog(rawOutput);
const matches = truncateGrepOutput(rawOutput, 50); // custom max
const listing = truncateLsOutput(rawOutput);
const build = truncateBuildOutput(rawOutput);

// Auto-dispatcher (routes based on command string)
const result = truncateExecOutput("git diff HEAD~5", rawOutput);

FilteredExecutor (Recommended for Programmatic Use)

import { createFilteredExecutor } from "./index.ts";

// Wrap your exec function
const executor = createFilteredExecutor(
  async (cmd: string) => {
    const { stdout } = await Deno.Command.output(cmd, { shell: true });
    return new TextDecoder().decode(stdout);
  }
);

// Execute with automatic truncation
const diff = await executor.run("git diff HEAD~5");
const log = await executor.run("git log --oneline -20");
const grep = await executor.run("grep -r 'TODO' src/");

Config Options (Phase 3)

const executor = createFilteredExecutor(myExecFn, {
  outputTransform: false,       // Bypass all filtering, return raw
  oversizedOutputLog: 10000,  // Log when raw output > 10KB
});

Usage Examples

Manual Truncation Pattern

When you already have exec output and want to compress it:

// 1. Run command normally
const raw = await exec("git diff HEAD~10");

// 2. Apply truncation
const compressed = truncateGitDiff(raw);

// 3. Use the compressed result
console.log(compressed);

Batch Processing

import { truncateExecOutput } from "./mod.ts";

const commands = [
  "git diff HEAD~5",
  "git log --oneline -20",
  "grep -r 'TODO' src/"
];

for (const cmd of commands) {
  const raw = await exec(cmd);
  const compressed = truncateExecOutput(cmd, raw);
  console.log(`=== ${cmd} ===\n${compressed}\n`);
}

Custom Filtering

import { FilterRegistry, FilteredExecutor } from "./index.ts";

const customRegistry = new FilterRegistry();
customRegistry.register(/^npm run /i, (_cmd, output) => {
  // Custom logic for npm scripts
  return output.split("\n").slice(0, 30).join("\n");
});

const executor = new FilteredExecutor(myExecFn, customRegistry);

Fail-Safe Behavior

All truncation functions are wrapped in truncateWithFailSafe. If ANY error occurs during processing (TypeError, RangeError, regex crash), the original output is returned unchanged with an error logged to stderr.

Module Overview

ModulePurpose
-----------------
mod.tsCore truncation functions (git diff/log, grep, ls, build)
filter-registry.tsCommand pattern matching + filter composition
filtered-executor.tsWraps exec functions with configurable filtering
index.tsPublic API re-exports + createFilteredExecutor factory

See Also

  • README.md — Practical examples and copy-pasteable snippets
  • scripts/exec-truncate-wrapper.sh — Shell wrapper for CLI use
  • scripts/simple-truncater.py — Pure Python reimplementation

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 13:32 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Caveman Input Compression

ether-btc
将工作区引导文件压缩为简化语言以减少每次会话加载时的输入token,覆盖前会自动创建.original.md备份
★ 0 📥 438

Correlation Memory Search

ether-btc
OpenClaw 的关联感知记忆搜索插件——在查询记忆时自动检索相关决策上下文。零外部依赖。
★ 0 📥 370

OpenClaw Config Safety v2

ether-btc
安全地验证、规范化、导出和导入 openclaw.json 配置文件,自动备份并在应用更改或升级前进行模式校验。
★ 0 📥 307