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

41 lines (40 loc) • 1.55 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/. /** * The model the config's own `args` select, as `--model X` or `--model=X` (the * last one wins). */ export function modelFromArgs(args) { let model; for (let index = 0; index < args.length; index += 1) { const arg = args[index]; if (arg === "--model") model = args[index + 1]; else if (arg?.startsWith("--model=")) model = arg.slice("--model=".length); } return model; } /** `args` without any `flag X` or `flag=X`, for a builder that adds that flag itself, so it is passed once. */ export function withoutFlag(args, flag) { const kept = []; for (let index = 0; index < args.length; index += 1) { const arg = args[index]; if (arg === undefined) continue; if (arg === flag) index += 1; else if (!arg.startsWith(`${flag}=`)) kept.push(arg); } return kept; } /** `args` without any `--model X` or `--model=X`, for a builder that adds the request's model itself, so it is passed once. */ export function withoutModelFlag(args) { return withoutFlag(args, "--model"); } /** `args` less a leading `subcommand` the builder writes itself, so an authored one is not doubled. */ export function withoutLeading(args, subcommand) { return args[0] === subcommand ? args.slice(1) : [...args]; }