Domain-aware output truncation for shell command execution. Compresses verbose output while preserving critical information.
This skill provides intelligent truncation for common command patterns:
+)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.
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);
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/");
const executor = createFilteredExecutor(myExecFn, {
outputTransform: false, // Bypass all filtering, return raw
oversizedOutputLog: 10000, // Log when raw output > 10KB
});
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);
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`);
}
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);
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 | Purpose |
|---|---|
| -------- | --------- |
mod.ts | Core truncation functions (git diff/log, grep, ls, build) |
filter-registry.ts | Command pattern matching + filter composition |
filtered-executor.ts | Wraps exec functions with configurable filtering |
index.ts | Public API re-exports + createFilteredExecutor factory |
README.md — Practical examples and copy-pasteable snippetsscripts/exec-truncate-wrapper.sh — Shell wrapper for CLI usescripts/simple-truncater.py — Pure Python reimplementation共 1 个版本