code-agent

Public

66 Downloads

README

code-agent — LM Studio Plugin

A context-light coding toolkit for LM Studio chat agents: eight focused tools, a mandatory user-defined working folder, and sub-agents that do smaller tasks in the background so the main chat stays light on context.

  • Working folder first — every file tool refuses to run until set_workspace pins a project folder (the one you define). All paths resolve inside it; traversal outside is blocked.
  • Light on context — reads are line-numbered and capped, search output is bounded, and bulky subtasks can be delegated to a subagent, which returns only a short summary.
  • Safe by default — there is no delete tool anywhere in the plugin (by design), and sub-agents have no shell access at all.

Requirements

  • LM Studio with plugins enabled (node runner)
  • A chat agent with this plugin attached
  • Node.js + npm only for development/publishing, not for use

Installation

Local / development mode

cd code-agent
npm install
lms dev        # or: npm run dev

lms dev compiles src/index.ts, registers the plugin with LM Studio, and hot-reloads on changes. Enable code-agent for your chat agent in LM Studio's plugin settings. Stop it again with Ctrl+C when done.

From the Hub (after publishing)

lms get <owner>/code-agent -y

Usage

  • Tell the agent your project folder — an absolute path, e.g. "My project is in D:\AI stuff\myapp, work there." The agent calls set_workspace first; all file tools error until that succeeds. The workspace persists across chats for the lifetime of the LM Studio process (re-set it after a restart or plugin reload).
  • Ask for coding work as usual. Builds, tests and installs run through run.
  • Delegation happens automatically when a task is self-contained (multi-file research, boilerplate, repetitive edits): the agent calls subagent with the task description and receives a compact summary instead of the full working transcript — that's what keeps your main chat's context small.

Tool reference

ToolParametersWhat it does
set_workspacepathSet the project working folder (must exist). Must be called before any other tool.
list_dirpath? (default .)List a directory; lines start with D= (folder) or F= (file), folders first.
read_filepath, start?, lines? (≤ 400)Read part of a text file, line-numbered. Defaults to 100 lines; pass start to continue.
write_filepath, contentCreate or overwrite a file; missing parent folders are created.
edit_filepath, find, replace?Replace an exact, unique text match (error if it matches 0 or >1 times). Omit replace to delete the matched text.
searchpattern, path?Case-insensitive content search; returns path:line matches. Skips .git, node_modules, dist, .next, build, coverage, binary files and files > 2 MB.
runcmdRun a shell command in the working folder (builds, tests, installs). 120 s timeout; long output is truncated to the last ~6 KB.
subagenttaskDelegate a self-contained task to a background agent. Returns [subagent: N rounds, Xs] plus its summary (capped at 2000 chars).

Sub-agent limits (deliberate)

  • Only the five file tools: list_dir, read_file, search, write_file, edit_file.
  • No shell (run) and no deletes, so a sub-agent can never run code or remove anything.
  • No recursion — sub-agents cannot spawn further sub-agents.
  • Runs are serialized, so concurrent delegations can't interleave file edits.

Safety notes

  • All paths resolve under the working folder; absolute-path and .. escapes are rejected (case-insensitively on Windows).
  • Nothing in the plugin deletes files or folders — if a change requires deletion, do it yourself or ask for a run command you approve.
  • run executes arbitrary shell commands inside the workspace; that is the only unconfined surface and exists because builds/tests need it.

Development

src/
  index.ts       # entry point: registers tools provider + prompt preprocessor (loaded by LM Studio)
  workspace.ts   # working-folder state + path containment checks
  fsops.ts       # list/read/write/edit/search implementations with output caps
  subagent.ts    # the subagent tool (SDK .act() on a filtered tool subset)
  tools.ts       # the 7 core tools + provider wiring (8 total)
  preprocess.ts  # prompt preprocessor: workspace reminder / one-time delegation briefing
  • Type-check and build to dist/: npm run build (tsc). Not needed for normal use — LM Studio compiles src/index.ts itself via esbuild when you run lms dev or install from the Hub.
  • tsconfig.json targets CommonJS/ES2021 into dist/.

Publishing to the Hub

  • Set "owner" in manifest.json to your LM Studio username (the one shown by lms whoami).

  • lms login, then:

    npm run push     # = lms push
    
  • Bump "revision" in manifest.json for each update you push.

.gitignore keeps node_modules/, dist/ and .lmstudio/ out of the upload — that's intentional; installers compile src/ on their own machine at install time.