{"slug": "logslim-compact-test-build-output-before-your-ai-agent-reads-it", "title": "Logslim – compact test/build output before your AI agent reads it", "summary": "Logslim, an open-source CLI and GitHub Action, reduces test and build log output by 80-95% for AI agents and human reviewers, compacting noisy CI logs into structured failure summaries with fix hints. The tool, available as an MIT-licensed npm package, deduplicates repeated warnings, collapses stack frames, and posts readable PR comments, saving tokens when agents like Claude Code or Cursor read test output.", "body_md": "**CI failed? Get a 5-line PR summary — not a 400-line Actions log.**\n\n**Agent reading test output? Cut 80–95% of the tokens.**\n\nWhen tests or builds fail, you scroll GitHub Actions logs. When Claude Code or Cursor runs\n`npm test`\n\n, the agent reads **everything** — progress bars, 120 identical warnings, 40 frames\nof `node_modules`\n\n. logslim fixes both:\n\n**CI / humans**— GitHub Action posts structured failures on your PR (file, line, fix hints)** Agents / tokens**— CLI + MCP compacts noisy output before an LLM reads it (~80–95% savings on failures)\n\n```\nnpx logslim -- npm test\n```\n\nNo account. No API key. MIT open source.\n\nWhen CI fails, post a readable summary on the pull request instead of making reviewers dig through Actions logs.\n\n```\npermissions:\n  contents: read\n  pull-requests: write\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-node@v4\n        with:\n          node-version: 20\n      - run: npm ci\n\n      - name: Run tests\n        id: test\n        run: npm test 2>&1 | tee test-output.log\n        continue-on-error: true\n\n      - name: Post failure summary\n        if: steps.test.outcome == 'failure' && github.event_name == 'pull_request'\n        uses: P156HAM/logslim/action@v0.3.0\n        with:\n          log-file: test-output.log\n          exit-code: 1\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n\n      - name: Fail job\n        if: steps.test.outcome == 'failure'\n        run: exit 1\n```\n\n**What gets posted on the PR:**\n\n- Structured failures with\n`file:line`\n\nand messages - Fix hints for known codes (\n`TS2339`\n\n,`ERESOLVE`\n\n, …) - Link to the full CI log\n- Token/log reduction stats (useful when agents also read the output)\n\nThe Action uses the same engine as the CLI — compaction, error extraction, and code cards.\nYou get **human-readable PR comments** and **agent-ready JSON** from one tool.\n\n| Input | Default | Purpose |\n|---|---|---|\n`log-file` |\n(required) |\nPath to captured test/build log |\n`exit-code` |\n`1` |\nExit code of the failed command |\n`github-token` |\n(required) |\n`secrets.GITHUB_TOKEN` with `pull-requests: write` |\n`logslim-version` |\n`0.3.0` |\nnpm version to run |\n`skip-on-success` |\n`true` |\nDon't comment when no failure detected |\n\n```\ngit clone https://github.com/P156HAM/logslim.git\ncd logslim && npm install && npm run build && npm run demo\n```\n\nOr without cloning:\n\n``` js\nnpx logslim -- node -e \"console.log('ok'); for(let i=0;i<30;i++)console.log('warn '+i); throw Error('fail')\"\n```\n\n**BEFORE** — what the agent reads today (~18 lines here; real runs are 500–3000):\n\n```\nPASS src/utils.test.ts\n  console.warn deprecated prop id=1000\n  console.warn deprecated prop id=1001\n  console.warn deprecated prop id=1002\n  ... (same warning ×120)\nFAIL src/checkout/cart.test.ts\n  Expected: 89.10\n  Received: 99.00\n      at cart.test.ts:48:27\n      at node_modules/jest-circus/build/utils.js:298:28\n      at node_modules/jest-circus/build/utils.js:231:10\n      at node_modules/jest-circus/build/run.js:252:3\n      ... (15 more node_modules frames)\nTest Suites: 1 failed, 1 passed, 2 total\n```\n\n**AFTER** — what logslim gives the agent:\n\n```\nPASS src/utils.test.ts\n  console.warn deprecated prop id=1000\n  console.warn deprecated prop id=1001\n  console.warn deprecated prop id=1002\n  (+5 similar lines omitted by logslim)\nFAIL src/checkout/cart.test.ts\n  Expected: 89.10\n  Received: 99.00\n      at cart.test.ts:48:27\n      at node_modules/jest-circus/build/utils.js:298:28\n      … 3 vendor/internal frames collapsed by logslim\nTest Suites: 1 failed, 1 passed, 2 total\n```\n\nSame failure. Same fix. ~**92% fewer tokens**.\n\n```\n  npm test  ──►  logslim  ──►  agent / CI / you\n                  │\n                  ├─ 1. Strip ANSI colors & spinner garbage\n                  ├─ 2. Dedupe repeated lines (warn spam)\n                  ├─ 3. Collapse node_modules stack frames\n                  ├─ 4. Group similar lines (timestamps/ids masked)\n                  ├─ 5. Extract structured errors (file, line, message)\n                  ├─ 6. Attach fix cards for known codes (TS2339, ERESOLVE…)\n                  └─ 7. Optional token budget (trim middle, keep errors)\n```\n\n**Failure mode (default):** tests pass → light cleanup only. Tests fail → full pipeline.\nYou only pay the compaction cost when something actually broke.\n\nEvery removed section is **marked in place** (`(+47 similar lines omitted by logslim)`\n\n)\nso the agent knows data was elided and can re-run the raw command if needed.\n\n```\nnpm install -g logslim\n# or zero-install:\nnpx logslim -- npm test\n```\n\nRequires Node 18+.\n\n```\nlogslim -- npm test\nlogslim -- python -m pytest -x\nlogslim -- npx tsc --noEmit\n```\n\nExit code is preserved. Output on stdout is compacted. Stats on stderr.\n\n```\nnpm test 2>&1 | logslim\nnpm test; logslim --exit-code $? 2>&1 < full.log   # if you saved output\nlogslim --json -- npm test\n{\n  \"exitCode\": 1,\n  \"failed\": true,\n  \"compacted\": \"FAIL src/checkout/cart.test.ts\\n...\",\n  \"errors\": [\n    {\n      \"file\": \"cart.test.ts\",\n      \"line\": 48,\n      \"message\": \"Expected: 89.10, Received: 99.00\",\n      \"kind\": \"assertion\"\n    }\n  ],\n  \"codes\": [\n    {\n      \"id\": \"TS2339\",\n      \"lang\": \"typescript\",\n      \"meaning\": \"Property does not exist on type\",\n      \"fix_steps\": [\n        \"Check for typos\",\n        \"Extend the interface\",\n        \"Use optional chaining\"\n      ]\n    }\n  ],\n  \"stats\": {\n    \"tokensIn\": 3296,\n    \"tokensOut\": 252,\n    \"saved\": 0.92,\n    \"applied\": \"full\"\n  }\n}\n```\n\nThe agent reads `compacted`\n\n+ `errors`\n\n+ `codes`\n\n— not thousands of lines of prose.\n\n```\nlogslim --json --attach git,ci -- npm test\n```\n\nPrepends: `branch: feat/x | commit: a3f2c1d | pr: #42`\n\n(from `GITHUB_*`\n\nenv vars).\n\n| Flag | What it does |\n|---|---|\n`--mode failure` |\nCompact hard only on failure (default) |\n`--mode full` |\nAlways compact hard |\n`--mode light` |\nStrip ANSI only, never aggressive dedupe |\n`--json` |\nStructured output (see above) |\n`--attach git,ci` |\nPrepend branch/commit/CI metadata |\n`--budget 2000` |\nHard token cap; errors + head/tail survive |\n`--exit-code N` |\nFor pipe mode when you know the exit code |\n`--no-codes` |\nSkip error code fix cards |\n`--no-stats` |\nHide stderr savings footer |\n\nLets the agent call compaction as a **tool** — no manual piping.\n\n**Project .mcp.json or Claude Desktop config:**\n\n```\n{\n  \"mcpServers\": {\n    \"logslim\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"logslim-mcp\"]\n    }\n  }\n}\n```\n\n**Tool:** `compact_output`\n\n— pass `output`\n\n(raw log text) and optional `exit_code`\n\n.\nReturns compacted text, extracted errors, fix cards, and stats.\n\nLocal dev:\n\n```\nnpm run build && npm run mcp\n```\n\nAdd to `CLAUDE.md`\n\n, `AGENTS.md`\n\n, or `.cursor/rules`\n\n:\n\n```\nWhen running tests, builds, or linters that produce verbose output:\n\n- Prefer: `logslim --mode failure --json -- <command>`\n- Read the `compacted`, `errors`, and `codes` fields before debugging.\n- If output was elided, re-run the raw command only if you need full logs.\n```\n\nWhen logs contain known codes, logslim attaches a **short fix card** (~30 tokens)\ninstead of making the agent guess or search docs.\n\n| Family | Examples | Source |\n|---|---|---|\n| TypeScript | TS2339, TS2554, TS2307 | `errors/typescript.json` |\n| Node | ECONNREFUSED, ENOTFOUND | `errors/node.json` |\n| npm | ERESOLVE, ELIFECYCLE | `errors/npm.json` |\n\nHand-curated pocket references — not scraped docs. **PRs welcome** to add codes.\n\n| Log type | Lines | Tokens | Saved |\n|---|---|---|---|\n| Jest (warn spam + 1 failure) | 149 → 25 | ~3,300 → ~250 | 92% |\n| Webpack build (asset noise + 2 TS errors) | 548 → 55 | ~8,900 → ~1,000 | 88% |\n| Pytest (25 identical failures) | 356 → 153 | ~4,300 → ~1,500 | 64% |\n\nToken counts are estimated (~4 chars/token). Good for relative savings, not billing.\n\n``` js\nimport { compact, process } from \"logslim\";\n\nconst { text, stats } = compact(rawLog, { mode: \"failure\", exitCode: 1 });\n\nconst result = process(rawLog, {\n  mode: \"failure\",\n  exitCode: 1,\n  attach: [\"git\", \"ci\"],\n});\n// result.text, result.errors, result.codes, result.stats\n```\n\n| Use it | Skip it |\n|---|---|\n| CI failed and you want a PR summary, not a 400-line log | Tests passed and output is already short |\n| AI agents running tests/builds locally or in CI | You already tee full logs to disk for audit |\n| Long repetitive failure output (jest, pytest, webpack) | Platform already truncates well enough for you |\n| MCP workflows where tool output hits context limits | You need full logs for compliance archive |\n\nKeep full logs if you need them:\n\n```\nnpm test 2>&1 | tee full.log | logslim\nnpm install\nnpm test\nnpm run build\nnpm run demo\n```\n\nlogslim gets sharper every time it learns a new error code or a new log format — and both are easy first contributions:\n\n**Add an error fix card**(TypeScript / Node / npm) — a ~5-minute, pure-JSON PR.** Share a log that compacts badly**— paste real output from a tool logslim mangles.** Add support for a new runner**— Playwright, pytest, vitest, cargo, gradle…\n\nStart here: ** good first issues**\n·\n\n[CONTRIBUTING.md](/P156HAM/logslim/blob/main/CONTRIBUTING.md)MIT — use freely, no account required.", "url": "https://wpnews.pro/news/logslim-compact-test-build-output-before-your-ai-agent-reads-it", "canonical_source": "https://github.com/P156HAM/logslim", "published_at": "2026-06-20 08:13:20+00:00", "updated_at": "2026-06-20 08:37:06.488656+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "large-language-models"], "entities": ["Logslim", "GitHub Actions", "Claude Code", "Cursor", "npm", "P156HAM"], "alternates": {"html": "https://wpnews.pro/news/logslim-compact-test-build-output-before-your-ai-agent-reads-it", "markdown": "https://wpnews.pro/news/logslim-compact-test-build-output-before-your-ai-agent-reads-it.md", "text": "https://wpnews.pro/news/logslim-compact-test-build-output-before-your-ai-agent-reads-it.txt", "jsonld": "https://wpnews.pro/news/logslim-compact-test-build-output-before-your-ai-agent-reads-it.jsonld"}}