UNPKG

akm-cli

Version:

akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur

75 lines (74 loc) • 3.28 kB
// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. import { modelFromArgs, withoutModelFlag, } from "../harness.js"; import { ClaudeCodeProvider } from "./session-log.js"; export { ClaudeCodeProvider } from "./session-log.js"; /** * The model-work tool policy on Claude Code, verified against 2.1.283: * - `--restricted` ignores the user, project and local settings files (whose * allow rules would otherwise pre-approve any command or path) and confines * the file tools to the working directory; * - `--strict-mcp-config` starts no MCP server, and `--tools` offers only Read * and Bash: no Edit; * - `--allowedTools` pre-approves Read and `akm search`, `akm show` and * `akm curate`, and `--permission-mode dontAsk` denies everything else instead * of prompting, including a compound, redirected or substituted command; * - `--no-session-persistence` keeps the run out of Claude Code's transcripts, * which `akm extract` would otherwise harvest as the user's own sessions. * The config's `args` are left out of a model-work run, because `--add-dir`, * `--settings` or a second `--allowedTools` would widen the policy; only the model * they name is kept. */ export const MODEL_WORK_CLAUDE_FLAGS = Object.freeze([ "--restricted", "--strict-mcp-config", "--tools", "Read,Bash", "--allowedTools", "Read,Bash(akm search *),Bash(akm show *),Bash(akm curate *)", "--permission-mode", "dontAsk", "--no-session-persistence", ]); export class ClaudeHarness { id = "claude"; displayName = "Claude Code"; // Home-relative config dir scanned by `akm setup` (#567). Claude Code has a // session-log provider, so offering it as a stash source is functional. setupDetectionDir = ".claude"; profile = { bin: "claude", args: [] }; models = { fast: "claude-haiku-4-5-20251001", balanced: "claude-sonnet-4-6", reasoning: "claude-opus-4-7", }; // Claude Code exports its session id to the commands it runs. Only a concrete id // attributes a run to this harness, not the bare "running under Claude Code" fact. identityEnv = ["CLAUDE_CODE_SESSION_ID"]; sessionLogProvider = () => new ClaudeCodeProvider(); systemPrompt = true; nativeAgent = true; confinable = true; build({ bin, args }, req) { const argv = [bin]; let model = req.model; if (req.modelWork) { argv.push(...MODEL_WORK_CLAUDE_FLAGS); model ??= modelFromArgs(args); } else { argv.push(...(model ? withoutModelFlag(args) : args)); } if (req.agent) argv.push("--agent", req.agent); if (req.systemPrompt) argv.push("--append-system-prompt", req.systemPrompt); if (model) argv.push("--model", model); if (req.prompt === undefined) return { argv }; // In print mode Claude Code writes its errors (auth, rate limit, output limit) on stdout and exits 1. return { argv: [...argv, "-p"], stdin: req.prompt, failureStream: "stdout" }; } }