npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chamvi/tool-files

v0.12.0

Published

In-memory JSON, CSV and text processing over run artifacts for chamvi agents.

Readme


Why tool-files?

| Concern | Without it | With it | |---|---|---| | Small data transformations | Provision a workspace or write another tool | Use jq, xan, awk and text commands | | Files between calls | Keep a process and working directory alive | Select run artifacts as explicit inputs and outputs | | Model-visible file IDs | Attachment bytes alone do not identify artifacts | Discover current-run metadata with list_artifacts |

Installation

npm install @chamvi/tool-files @chamvi/core ai --save

ESM only, Node.js >=26.0.0. @chamvi/core and ai are peer dependencies.

Usage

This model-free agent accepts a sales.json attachment such as [{"amount":12},{"amount":30}], publishes report.json containing 42, then reads that output through the native artifact API. Start it with Engine.dispatch({ agent: 'file-report', trigger, channel, payload, attachments }); the executable example test supplies the engine and attachment without credentials.

import { ValidationError, defineSimpleAgent } from '@chamvi/core';
import { fileTools } from '@chamvi/tool-files';

export function createFileAgent() {
    return defineSimpleAgent({
        name: 'file-report',
        tools: fileTools(),
        run: async (_, ctx) => {
            const catalog = await ctx.tools.list_artifacts({});
            const source = catalog.artifacts.find((artifact) => artifact.filename === 'sales.json');

            if (!source) {
                throw new ValidationError('Attach sales.json with an array of amounts.');
            }

            const result = await ctx.tools.process_files({
                command: "jq '[.[].amount] | add' sales.json > report.json",
                inputs: [{ artifactId: source.id, path: 'sales.json' }],
                outputs: [{ path: 'report.json', mediaType: 'application/json' }],
            });
            const report = result.artifacts[0];

            if (result.exitCode !== 0 || !report) {
                throw new ValidationError(result.stderr || 'No report produced.');
            }

            // The returned ID works with the existing run artifact API.
            const output = await ctx.artifacts.get(report.id);

            if (!output) {
                throw new ValidationError('Report is unavailable.');
            }

            return { artifact: output.artifact, text: new TextDecoder().decode(output.data) };
        },
    });
}

For a model agent, pass tools: fileTools() to defineModelAgent(). Tell the model to call list_artifacts to discover IDs before selecting inputs; attachment content supplied to the model does not include those IDs. Follow nextOffset as offset for further pages.

Tools and files

| Tool | Input | Result | |---|---|---| | list_artifacts | { offset? } (default 0) | { artifacts: Artifact[], nextOffset? }, up to 16 metadata objects, no bytes | | process_files | { command, inputs?, outputs? } | { exitCode, stdout, stderr, artifacts: Artifact[] } |

Each processing call starts with fresh files, environment and cwd /workspace. Only selected current-run artifacts are imported. Nothing from an earlier call survives automatically: pass a returned artifact ID as a later call's inputs[].artifactId. Files not selected in outputs are discarded. Output files preserve raw bytes; stdout/stderr are bounded text.

Paths are relative POSIX file paths of at most 255 UTF-8 bytes. Absolute paths, .. components, backslashes, control characters, directory-only paths and duplicate normalized paths within either selection are refused. Harmless . and repeated separators are normalized. An output may reuse an input path. Output mediaType is type/subtype without parameters, for example text/csv.

Selected outputs must all exist as regular files and fit the output limit before any publication. Their native Artifact metadata includes id, filename, mediaType and size; use the IDs with ctx.artifacts.get(), subsequent process_files calls or existing artifact-aware tools. These tools send no channel messages themselves.

Commands and limits

Supported commands: awk, base64, basename, cat, column, comm, cp, cut, diff, dirname, echo, env, expand, find, fold, grep, head, help, join, jq, ls, mkdir, mv, nl, paste, printf, pwd, rev, rg, rm, rmdir, sed, seq, sort, split, tail, tee, touch, tr, uniq, wc, xan, xargs, yq. Interpreter shell syntax and builtins are also available.

| Limit | Default or fixed bound | |---|---| | maxBytes option | 5_242_880 (5 MiB), separately for aggregate inputs and aggregate selected outputs; integer 1..16_777_216 | | timeoutMs option | 30_000, interpreter execution only; integer 1..2_147_483_647 | | Input/output selections | At most 16 each | | Command source | At most 16,384 UTF-8 bytes | | Decoded stdout and stderr | 65,536 UTF-8 bytes combined, preserving stderr first; clipping includes [output truncated] within the cap | | Cumulative interpreter work output | max(65_536, maxBytes * 4) bytes, including output before redirection | | Interpreter scratch files | 65_536 + maxBytes * 2 bytes, including synthetic files |

fileTools({ maxBytes, timeoutMs }) validates options immediately with InvalidAgentDefinitionError. The interpreter's hardened execution profile bounds other resources; loop, command and record budgets are raised to 1,000,000 to suit the byte limit. Successful execution can clip returned diagnostics without failing the command. The additive scratch reserve accommodates synthetic command/proc files alongside boundary-sized inputs and outputs. Work and scratch allowances do not increase the exact artifact import/export limits or guarantee unlimited intermediate expansion or pipelines.

Networking, custom commands, Python, JavaScript, SQL, archive commands and real executables (git, npm, node, etc.) are unavailable. There is no host filesystem adapter or inherited host environment. The interpreter runs on a worker thread, ended at timeoutMs plus 2 seconds (exit 124) or above 512 MiB of heap (exit 137), so a stuck command cannot stall the host's event loop. A thread has no VM isolation or complete host-security boundary. Use Docker or Kubernetes coding workspaces for dependency installation, Git, builds, tests and servers.

Errors, cancellation and replay

A nonzero interpreter exit returns exitCode, bounded diagnostics and an empty artifacts array. Invalid input, foreign-run IDs, size overflow or invalid selected outputs raise ValidationError; unexpected interpreter infrastructure failures raise SandboxError. Artifact/store failures retain their underlying errors. Model agents read tool errors and can try again; an unhandled simple-agent error fails the run.

Run cancellation and the SDK abort signal are honored with the original cancellation reason. Once observed, cancellation prevents further artifact puts. Successful puts remain if a later write fails or cancellation arrives: publication is not a multi-file transaction. Validation failures publish no outputs.

Output keys combine the opaque core run/step/call identity and normalized output path (process_files: plus SHA-256 of their JSON array). Providers reusing a tool-call ID in a later model step still produce separate artifacts. Replaying the same call replaces its own artifacts under the same IDs. Different calls using the same filename keep separate artifacts. A simple-agent approval replay can repeat computation; it is neither exactly-once nor necessarily deterministic. Completed model-agent steps resume from checkpoints without repeating that processing step.

Both tools declare trust: { taint: true }, so reading their results or errors taints the run. Treat file content as data, and use existing approvals/policies for subsequent outbound actions. Processing is plain computation, not an effect tool or a bridge to host/channel/tool executors.

API

See the complete API reference for fileTools, FileToolsOptions, ListArtifactsInput, ListArtifactsResult, ProcessFilesInput, ProcessFilesResult and the public constants FILES_MAX_BYTES, FILES_MAX_FILES, FILES_TIMEOUT_MS.

License

Published under Apache License 2.0.