[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M76WVTG9Z3C5D6JDJFBWQ88F":3,"skill-same:01M76WVTG9Z3C5D6JDJFBWQ88F":51},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":25,"repositoryHtmlUrl":26,"repositoryHomepageUrl":27,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M76WVTG9Z3C5D6JDJFBWQ88F","magus-buzz-from-shell",null,"egladman\u002Fmagus","egladman","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F8713153?v=4","01M75H42QB5A4X82APZF4H44GM","Eli Gladman","01M75H42R1K59Z7JWAP621J849",3,"GPL-3.0","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-buzz-from-shell\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"# Rewriting shell as Buzz\n\n{{if .Full}}A shell script ported line by line into Buzz is worse than the shell it replaced.\nEvery `curl`, `jq` and `sed` becomes a `proc\\exec` call with a hand-built argument list.\nThe temp files and traps survive only to feed those tools, and the result still parses text.\n\nPort what the script DOES instead. Name its inputs and outputs, and decide whether it\nshould be a script at all. Then write each step with the host module that already does it.\n`proc\\exec` is left for the one real external program the script exists to run.\n\nThis skill teaches the rewrite. {{skill \"buzz-lang\"}} teaches the syntax; load it first\nif you have not written Buzz in this session.{{else}}Port what script DOES, never its lines.\nLine-by-line port: every `curl`\u002F`jq`\u002F`sed` becomes `proc\\exec`, temp files and traps survive only to feed them, result still parses text.\n`proc\\exec` only for real external program script exists to run.\nSyntax: {{skill \"buzz-lang\"}}; load it first.{{end}}\n\n## The rewrite, in order\n\n{{if .Full}}1. Write down what the script reads, what it writes, and what it prints. Ignore how.\n2. Decide where the result belongs: a target, a `{{cmd \"buzz\"}}` script, or still shell.\n   The next section decides it.\n3. Map each external tool to its module with the idiom table below. A tool with no row is\n   usually a list or string method.\n4. Delete the scaffolding the tools needed. That means temp files that passed data\n   between them and the traps that cleaned those files. It also means `[ -f ]` guards\n   before a read that raises anyway, `die` helpers and `set -euo pipefail`.\n5. Parse arguments with `flags\\parse`, and put each step in a named function.\n6. Add a `test` block for each pure function, then `{{cmd \"buzz\"}} --check`,\n   `{{cmd \"buzz\"}} -t`, and a real run.\n7. Prove the port: run the old script and the new one on the same input and diff what\n   each wrote. A port is done when the outputs match, not when it checks.{{else}}1. List what script reads, writes, prints. Ignore how.\n2. Decide: target, `{{cmd \"buzz\"}}` script, or still shell (next section).\n3. Map each tool -> module (idiom table). Tool with no row: usually list or string method.\n4. Delete scaffolding tools needed: temp files between them, traps cleaning them, `[ -f ]` before read that raises anyway, `die` helpers, `set -euo pipefail`.\n5. `flags\\parse` for arguments; each step named function.\n6. `test` block per pure function -> `{{cmd \"buzz\"}} --check` -> `{{cmd \"buzz\"}} -t` -> real run.\n7. Prove port: run old and new on same input, diff what each wrote. Done when outputs match, not when it checks.{{end}}\n\n## Target, script, or still shell\n\n{{if .Full}}Ask two questions. Does running it twice on the same inputs write the same files?\nDoes other work read what it writes? Two yeses make it a target. Then magus caches it,\nsandboxes it, reruns it only when an input changed, and orders it with `ctx.needs`.\n\n| the script | becomes |\n| --- | --- |\n| generates files a build, test or doc reads | a target that declares them with `ctx.writesFiles` |\n| verifies or gates (`--check`, lint, drift) | a target that `ci` needs |\n| runs one project's toolchain (a test runner, a bundler) | a target, or a spell op when every project of that type needs it |\n| acts on the machine or repository state: worktrees, branches, a download on demand, a report | a `{{cmd \"buzz\"}}` script with `flags\\parse` |\n| runs where magus is absent: inside a container image, before magus is installed | still shell, kept small |\n| exists to exercise the shell itself: completion checks, a terminal recording | still shell |\n\nA script that writes a generated file is the most common miss. As a script it reruns from\nscratch, and nothing notices when the file goes stale.{{else}}Two questions: same inputs twice -> same files written? Other work reads what it writes? Both yes -> target (cached, sandboxed, affected-tracked, ordered by `ctx.needs`).\n- generates files build\u002Ftest\u002Fdoc reads: target, declare with `ctx.writesFiles`\n- verifies or gates (`--check`, lint, drift): target `ci` needs\n- runs one project's toolchain: target, or spell op when every project of that type needs it\n- acts on machine or repo state (worktrees, branches, download on demand, report): `{{cmd \"buzz\"}}` script + `flags\\parse`\n- runs where magus absent (container image, before install): still shell, kept small\n- exercises shell itself (completion checks, terminal recording): still shell\nMost common miss: script writing generated file. Reruns from scratch; nothing notices when stale.{{end}}\n\n```buzz\nimport \"magus\";\nimport \"proc\";\n\nexport fun generate(ctx: magus\\Context, args: [str]) > void !> any {\n    ctx.writesFiles([\"gen\u002Fapi.md\"]);\n    proc\\exec(\"node\", args: [\"tools\u002Fgen-api.mjs\", \"--write\", \".\"]);\n}\n```\n\n{{if .Full}}Here `proc\\exec` is right: the generator IS the external program. Everything around it\n(checking the output, writing a file, diffing) is a module call.{{else}}`proc\\exec` right here: generator IS external program. Everything around it: module calls.{{end}}\n\n## Idiom table\n\n{{if .Full}}`{{cmd \"describe\"}} module \u003Cname>` prints every member with its signature. Check it before\nassuming a row's call takes the arguments you expect.\n\n| shell | Buzz |\n| --- | --- |\n| `set -euo pipefail`, `\\|\\| exit 1` | nothing: a host call raises; declare `!> any` |\n| `echo \"msg\" >&2; exit 1` | `throw \"msg\";` |\n| `trap 'rm -rf \"$TMP\"' EXIT` | usually nothing: keep the data in memory |\n| `curl -fsSL --retry 5 URL` | `http\\get(url, opts: http\\Options{ fail = true }, retry: http\\Retry{ attempts = 5 })` |\n| `curl -o file URL` | `http\\download(url, dest: file)` |\n| `jq`, `yq` | `json\\parse`, `yaml\\parse`, then index; `json\\stringify` |\n| `grep PAT file`, `grep -c` | `fs\\readLines(file).filter(...)`, `.len()` |\n| `sed 's\u002Fa\u002Fb\u002Fg'` | `text.replace(\"a\", with: \"b\")` |\n| `cut -d: -f2`, `awk '{print $2}'` | `line.split(\":\")[1]`, `strings\\fields(line)[1]` |\n| `wc -l`, `sort`, `uniq`, `head -n` | `.len()`, `.sort(fn)`, a map as a set, `.sub(0, len: n)` |\n| `KEY=value` file | `env\\parseDotenv(fs\\readFile(file))` |\n| `sha256sum`, `shasum -a 256` | `crypto\\sha256File(path)` |\n| `tar xzf a.tgz --strip-components=1 -C d` | `archive\\uncompress(src, dest: d, opts: archive\\Options{ strip = 1 })` |\n| `tar czf`, `zip` | `archive\\compress(src, dest: \"a.tar.gz\")` |\n| `find . -name '*.md'`, `dir\u002F*\u002F` | `fs\\glob(\"**\u002F*.md\")`; `fs\\walk` to prune while walking |\n| `[ -f ]`, `[ -d ]`, `[ -e ]` | `fs\\isFile`, `fs\\isDir`, `fs\\exists`, often not needed |\n| `command -v tool` | `proc\\which(tool)`, which raises when absent |\n| `mkdir -p`, `rm -rf`, `cp -R`, `mv` | `fs\\mkdirAll`, `fs\\removeAll`, `fs\\copyDir`, `fs\\rename` |\n| `cat > f \u003C\u003CEOF` | `fs\\writeFile`, or `template\\render` for a generated file |\n| `${VAR:?}`, `${VAR:-x}` | `env\\require(\"VAR\")`, `env\\getOr(\"VAR\", def: \"x\")` |\n| `VAR=x cmd` | `os\\withEnv({\"VAR\": \"x\"}, callback: ...)` |\n| `\"${1:?usage}\"`, `getopts` | `flags\\parse(args, switches: [...], valued: [...])` |\n| `until cmd; do sleep 2; done` | `os\\retry(5, fn: ...)`, or `http\\Retry` for HTTP |\n| `git ...` | `vcs\\status`, `vcs\\ref`, `vcs\\commit`, `vcs\\history`, `vcs\\changedFiles`; `vcs\\cmd` for the rest |\n| `( cd d && tool )` | `proc\\exec(\"tool\", args: [...], dir: d)` |\n| `a \\| b` across two real tools | `proc\\exec(\"b\", opts: proc\\ExecOptions{ stdin = first.stdout })` |\n| `magus ... -o json \\| jq` | `magus\\describe.\u003Cnoun>`, `magus\\graph().query`, `magus\\graph().refs`: typed records |\n| `{{cmd \"run\"}} t p` | `ctx.needs(t)` inside a target; `magus\\run([...])` in a script |{{else}}Signatures: `{{cmd \"describe\"}} module \u003Cname>`. Check before assuming arguments.\n\nshell: Buzz\n- `set -euo pipefail`, `|| exit 1`: nothing; host call raises; declare `!> any`\n- `echo \"msg\" >&2; exit 1`: `throw \"msg\";`\n- `trap 'rm -rf \"$TMP\"' EXIT`: usually nothing; keep data in memory\n- `curl -fsSL --retry 5 URL`: `http\\get(url, opts: http\\Options{ fail = true }, retry: http\\Retry{ attempts = 5 })`\n- `curl -o file URL`: `http\\download(url, dest: file)`\n- `jq`, `yq`: `json\\parse`, `yaml\\parse`, then index; `json\\stringify`\n- `grep PAT file`, `grep -c`: `fs\\readLines(file).filter(...)`, `.len()`\n- `sed 's\u002Fa\u002Fb\u002Fg'`: `text.replace(\"a\", with: \"b\")`\n- `cut -d: -f2`, `awk '{print $2}'`: `line.split(\":\")[1]`, `strings\\fields(line)[1]`\n- `wc -l`, `sort`, `uniq`, `head -n`: `.len()`, `.sort(fn)`, map as set, `.sub(0, len: n)`\n- `KEY=value` file: `env\\parseDotenv(fs\\readFile(file))`\n- `sha256sum`, `shasum -a 256`: `crypto\\sha256File(path)`\n- `tar xzf a.tgz --strip-components=1 -C d`: `archive\\uncompress(src, dest: d, opts: archive\\Options{ strip = 1 })`\n- `tar czf`, `zip`: `archive\\compress(src, dest: \"a.tar.gz\")`\n- `find . -name '*.md'`, `dir\u002F*\u002F`: `fs\\glob(\"**\u002F*.md\")`; `fs\\walk` to prune while walking\n- `[ -f ]`, `[ -d ]`, `[ -e ]`: `fs\\isFile`, `fs\\isDir`, `fs\\exists`; often not needed\n- `command -v tool`: `proc\\which(tool)`, raises when absent\n- `mkdir -p`, `rm -rf`, `cp -R`, `mv`: `fs\\mkdirAll`, `fs\\removeAll`, `fs\\copyDir`, `fs\\rename`\n- `cat > f \u003C\u003CEOF`: `fs\\writeFile`, or `template\\render` for generated file\n- `${VAR:?}`, `${VAR:-x}`: `env\\require(\"VAR\")`, `env\\getOr(\"VAR\", def: \"x\")`\n- `VAR=x cmd`: `os\\withEnv({\"VAR\": \"x\"}, callback: ...)`\n- `\"${1:?usage}\"`, `getopts`: `flags\\parse(args, switches: [...], valued: [...])`\n- `until cmd; do sleep 2; done`: `os\\retry(5, fn: ...)`, or `http\\Retry` for HTTP\n- `git ...`: `vcs\\status`, `vcs\\ref`, `vcs\\commit`, `vcs\\history`, `vcs\\changedFiles`; `vcs\\cmd` for rest\n- `( cd d && tool )`: `proc\\exec(\"tool\", args: [...], dir: d)`\n- `a | b` across two real tools: `proc\\exec(\"b\", opts: proc\\ExecOptions{ stdin = first.stdout })`\n- `magus ... -o json | jq`: `magus\\describe.\u003Cnoun>`, `magus\\graph().query`, `magus\\graph().refs`: typed records\n- `{{cmd \"run\"}} t p`: `ctx.needs(t)` inside target; `magus\\run([...])` in script{{end}}\n\n## Pairs\n\n{{if .Full}}Each pair is the shell as it is usually written, then the Buzz it becomes. Every Buzz\nblock checks as written.{{else}}Shell as usually written, then Buzz. Every Buzz block checks.{{end}}\n\n### Failure and exit codes\n\n```sh\nset -euo pipefail\n[ -f \"$1\" ] || { echo \"pin: $1 missing\" >&2; exit 1; }\npinned=$(cut -d' ' -f1 \"$1\")\n```\n\n```buzz\nimport \"std\";\nimport \"fs\";\n\nfun main(args: [str]) > void !> any {\n    if (args.len() != 1) {\n        throw \"usage: pin \u003Cfile>\";\n    }\n    final pinned = fs\\readFile(args[0]).split(\" \")[0];\n    std\\print(pinned);\n}\n```\n\n{{if .Full}}`fs\\readFile` raises with the path in its message, so the `[ -f ]` guard has nothing left\nto add. `throw` ends the run non-zero with the message on stderr. Check a condition only\nwhen the message you would write says more than the raised one.{{else}}`fs\\readFile` raises naming path; `[ -f ]` guard adds nothing. `throw` ends run non-zero, message on stderr. Check condition only when your message says more than raised one.{{end}}\n\n### HTTP, JSON and temp files\n\n```sh\nTMP=\"$(mktemp -d)\"; trap 'rm -rf \"$TMP\"' EXIT\ncurl -fsSL --retry 5 --retry-all-errors --retry-delay 2 \"$API&offset=$o\" -o \"$TMP\u002Fpage.json\"\njq -e '(.rows | length) == 100' \"$TMP\u002Fpage.json\" >\u002Fdev\u002Fnull || exit 1\n```\n\n```buzz\nimport \"http\";\nimport \"encoding\u002Fjson\";\n\nfun fetchPage(api: str, offset: int) > [any] !> any {\n    final res = http\\get(\"{api}&offset={offset}&length=100\",\n        opts: http\\Options{ fail = true },\n        retry: http\\Retry{ attempts = 5, delayMs = 2000.0, allErrors = true });\n    final rows: [any] = json\\parse(res.body)[\"rows\"];\n    if (rows.len() != 100) {\n        throw \"page at offset {offset} returned {rows.len()} rows, not 100\";\n    }\n    return rows;\n}\n```\n\n{{if .Full}}The temp directory and its trap existed because `jq` reads files. With the body in memory\nboth go. Without a `retry` argument a request runs exactly once. When a real directory is\nneeded, [reference.md](reference.md#a-temp-directory-that-must-exist) removes it on both\npaths.{{else}}Temp dir and trap existed because `jq` reads files; body in memory -> both go. No `retry` argument: request runs once. Real directory needed: [reference.md](reference.md#a-temp-directory-that-must-exist).{{end}}\n\n### Digests, counts and key=value files\n\n```sh\nrows=$(wc -l \u003C\"$OUT\" | tr -d ' ')\nsum=$(sha256sum \"$OUT\" 2>\u002Fdev\u002Fnull | cut -d' ' -f1 || shasum -a 256 \"$OUT\" | cut -d' ' -f1)\nSHA=\"$(grep '^upstream_sha=' versions.lock | cut -d= -f2)\"\n```\n\n```buzz\nimport \"std\";\nimport \"fs\";\nimport \"crypto\";\nimport \"env\";\n\nfun main(args: [str]) > void !> any {\n    final rows = fs\\readLines(\"verified.jsonl\").len();\n    final sum = crypto\\sha256File(\"verified.jsonl\");\n    final sha = env\\parseDotenv(fs\\readFile(\"versions.lock\"))[\"upstream_sha\"];\n    if (sha == null) {\n        throw \"versions.lock has no upstream_sha\";\n    }\n    std\\print(\"{rows} rows, sha256 {sum}, upstream {sha!}\");\n}\n```\n\n{{if .Full}}The `sha256sum`-or-`shasum` fallback is a portability workaround for a tool, and the\nmodule needs none.{{else}}`sha256sum`-or-`shasum` fallback: portability workaround for tool; module needs none.{{end}}\n\n### Globs, find and directory loops\n\n```sh\nfor appdir in \"$REPO\"\u002Fapps\u002F*\u002F; do\n    app=\"$(basename \"$appdir\")\"\ndone\nfind . -name '*.md' -not -path '.\u002Fnode_modules\u002F*'\n```\n\n```buzz\nimport \"std\";\nimport \"fs\";\nimport \"path\";\n\nfun main(args: [str]) > void !> any {\n    foreach (p in fs\\glob(\"apps\u002F*\")) {\n        if (fs\\isDir(p.value)) {\n            std\\print(fs\\basename(p.value));\n        }\n    }\n    foreach (p in fs\\glob(\"**\u002F*.md\")) {\n        if (!path\\matches(\"node_modules\u002F**\", path: p.value)) {\n            std\\print(p.value);\n        }\n    }\n}\n```\n\n{{if .Full}}`fs\\glob` yields `Path` objects; read `.value`. A glob with no match is an empty list,\nnever the literal pattern the shell hands back.{{else}}`fs\\glob` yields `Path`; read `.value`. No match: empty list, never literal pattern.{{end}}\n\n### Editing a file in place\n\n```sh\nsed -i '' \"s|$pattern|$replacement|g\" \"$file\"\n```\n\n```buzz\nimport \"fs\";\n\nfun replaceIn(file: str, pattern: str, replacement: str) > void !> any {\n    final source = fs\\readFile(file);\n    if (source.indexOf(pattern) == null) {\n        throw \"{file}: pattern not found: {pattern}\";\n    }\n    fs\\writeFile(file, content: source.replace(pattern, with: replacement));\n}\n```\n\n{{if .Full}}`sed` exits 0 when the pattern matches nothing, so the shell edit silently does nothing\nonce the source moves. The Buzz edit fails loudly. It also needs no regex escaping and\nbehaves the same on GNU and BSD.{{else}}`sed` exits 0 when pattern matches nothing: edit silently no-ops once source moves. Buzz edit fails loudly; no regex escaping; same on GNU and BSD.{{end}}\n\n### Heredocs that generate a file\n\n```sh\ncat > \"$dir\u002Fmagusfile.buzz\" \u003C\u003CEOF\nimport \"spells\u002F$spell\";\nmagus\\\\project({\"spells\": [$spell]});\nEOF\n```\n\n```buzz\nimport \"fs\";\nimport \"template\";\n\nfinal PROJECT = `import \"spells\u002F{{\"{{spell}}\"}}\";\nmagus\\project({\"spells\": [{{\"{{spell}}\"}}]});\n`;\n\nfun writeProject(dir: str, spell: str) > void !> any {\n    fs\\writeFile(fs\\join(dir, name: \"magusfile.buzz\"), content: template\\render(PROJECT, data: {\"spell\": spell}));\n}\n```\n\n{{if .Full}}Put Mustache in a backtick string: in a double-quoted string `{name}` interpolates. A\ntemplate keeps the generated text readable as one block, where a run of `echo` and\n`printf` lines hides it.{{else}}Mustache in backtick string: double-quoted `{name}` interpolates. Template keeps generated text one readable block; `echo`\u002F`printf` runs hide it.{{end}}\n\n### Environment and arguments\n\n```sh\nWT=\"$(cd \"${1:?usage: check.sh \u003Cworktree>}\" && pwd)\"\nTOKEN=\"${GITHUB_TOKEN:?}\"\nLEVEL=\"${LOG_LEVEL:-info}\"\nMAGUS_X=0 some-tool\n```\n\n```buzz\nimport \"std\";\nimport \"env\";\nimport \"os\";\nimport \"path\";\nimport \"proc\";\nimport \"flags\";\n\nfinal USAGE = \"usage: magus buzz check.buzz -- [--dry-run] \u003Cworktree>\";\n\nfun main(args: [str]) > void !> any {\n    final parsed = flags\\parse(args, switches: [\"--dry-run\"], valued: [\"--level\"]);\n    if (parsed.unknown.len() > 0 or parsed.positionals.len() != 1) {\n        throw USAGE;\n    }\n    final worktree = path\\abs(parsed.positionals[0]);\n    final token = env\\require(\"GITHUB_TOKEN\");\n    final level = parsed.values[\"--level\"] ?? env\\getOr(\"LOG_LEVEL\", def: \"info\");\n    std\\print(\"{worktree} {level} token={token.len() > 0}\");\n    os\\withEnv({\"MAGUS_X\": \"0\"}, callback: fun () > void !> any {\n        proc\\exec(\"some-tool\");\n    });\n}\n```\n\n{{if .Full}}`flags\\parse` returns every undeclared argument in `unknown` rather than guessing. Refuse\nthem. `os\\withEnv` sets the variable for the processes the callback starts, never for the\nscript itself.{{else}}`flags\\parse` returns undeclared arguments in `unknown`; refuse them. `os\\withEnv` sets variable for processes callback starts, never script itself.{{end}}\n\n### Version control\n\n```sh\nbranch=$(git rev-parse --abbrev-ref HEAD)\n[ -z \"$(git status --porcelain)\" ] || { echo dirty >&2; exit 1; }\ngit -C \"$REPO\" checkout -q --detach \"$SHA\"\n```\n\n```buzz\nimport \"std\";\nimport \"vcs\";\n\nfun main(args: [str]) > void !> any {\n    final branch = vcs\\ref() ?? \"(detached)\";\n    if (!vcs\\status().clean) {\n        throw \"the working tree has uncommitted changes\";\n    }\n    vcs\\cmd([\"checkout\", \"-q\", \"--detach\", args[0]], opts: vcs\\CommandOptions{ dir = \"repo\" });\n    std\\print(\"left {branch}; head now {vcs\\commit().short}\");\n}\n```\n\n{{if .Full}}`proc\\exec(\"git\", ...)` is refused: version-control binaries run through `vcs\\cmd`,\nwhich holds them to the lease. Prefer the typed members; they also work for hg, sl\nand jj. Reach for `vcs\\cmd` only when no member answers.{{else}}`proc\\exec(\"git\", ...)` refused: VCS binaries run through `vcs\\cmd` (held to the lease). Prefer typed members (also hg, sl, jj); `vcs\\cmd` only when no member answers.{{end}}\n\n{{if .Full}}[reference.md](reference.md) has four cases: running the real tool a script exists for;\npiping between two tools; asking magus for a typed record; one whole rewrite.{{else}}Real tool, pipes between tools, asking magus, whole rewrite: [reference.md](reference.md).{{end}}\n\n## Anti-patterns\n\n{{if .Full}}Each WRONG block checks and runs. That is the trouble: nothing flags it but review.{{else}}Each WRONG block checks and runs; only review catches it.{{end}}\n\n{{if .Full}}**Shelling out to what a module does.** The call depends on a binary being installed,\non its flags (GNU or BSD), and on parsing its text.{{else}}Shelling out to what module does: depends on installed binary, its flags (GNU or BSD), parsing its text.{{end}}\n\n```buzz\nimport \"proc\";\n\nfun wrongDigest(file: str) > str !> any {\n    return proc\\exec(\"sha256sum\", args: [file], opts: proc\\ExecOptions{ quiet = true }).stdout.split(\" \")[0];\n}\n```\n\n```buzz\nimport \"crypto\";\n\nfun digest(file: str) > str !> any {\n    return crypto\\sha256File(file);\n}\n```\n\n{{if .Full}}**Building a command line from strings.** `proc\\shell`, or `sh -c` with interpolated\nvalues, brings back quoting, word splitting and injection. A path with a space breaks it.{{else}}Building command line from strings: `proc\\shell` or `sh -c` with interpolated values brings back quoting, word splitting, injection. Path with space breaks it.{{end}}\n\n```buzz\nimport \"proc\";\n\nfun wrongUnpack(src: str, dest: str) > void !> any {\n    proc\\exec(\"sh\", args: [\"-c\", \"tar xzf {src} -C {dest} --strip-components=1\"]);\n}\n```\n\n```buzz\nimport \"archive\";\n\nfun unpack(src: str, dest: str) > void !> any {\n    archive\\uncompress(src, dest: dest, opts: archive\\Options{ strip = 1 });\n}\n```\n\n{{if .Full}}**Ignoring a typed result.** `allowFailure` hands the decision to you. Dropping the\nresult turns a failure into success, which is exactly what `set -e` was preventing.{{else}}Ignoring typed result: `allowFailure` hands decision to you; dropping result turns failure into success.{{end}}\n\n```buzz\nimport \"proc\";\n\nfun wrongLint() > void !> any {\n    proc\\exec(\"eslint\", args: [\".\"], opts: proc\\ExecOptions{ allowFailure = true });\n}\n```\n\n```buzz\nimport \"proc\";\n\nfun lint() > bool !> any {\n    final res = proc\\exec(\"eslint\", args: [\".\"], opts: proc\\ExecOptions{ allowFailure = true, quiet = true });\n    if (!res.ok and res.code != 1) {\n        throw \"eslint crashed (exit {res.code}): {res.stderr}\";\n    }\n    return res.ok;\n}\n```\n\n{{if .Full}}Omit `allowFailure` unless you read `.ok` or `.code` on the next line.{{else}}Omit `allowFailure` unless next line reads `.ok` or `.code`.{{end}}\n\n{{if .Full}}**Parsing text a typed member returns.** Splitting `magus\\cmd(...).stdout` or\n`vcs\\cmd([\"status\", \"--porcelain\"]).stdout` re-derives a record magus already built, and\nbreaks when the text format changes.{{else}}Parsing text typed member returns: splitting `magus\\cmd(...).stdout` or `vcs\\cmd([\"status\", \"--porcelain\"]).stdout` re-derives record magus built; breaks when format changes.{{end}}\n\n```buzz\nimport \"vcs\";\n\nfun wrongDirty() > bool !> any {\n    return vcs\\cmd([\"status\", \"--porcelain\"], opts: vcs\\CommandOptions{ quiet = true }).stdout.trim() != \"\";\n}\n```\n\n```buzz\nimport \"vcs\";\n\nfun dirty() > bool !> any {\n    return vcs\\isDirty();\n}\n```\n\n{{if .Full}}**Porting the scaffolding.** These have no job left in Buzz. Delete them, never\ntranslate them:\n\n- a `die` helper: use `throw`;\n- an existence check before a read: the read raises;\n- a temp file that passed data from one tool to the next;\n- a trap cleaning that temp file;\n- a retry loop with `sleep`: use `http\\Retry` or `os\\retry`;\n- `command -v` choosing between two tools that do the same thing;\n- globals assigned in one function and read in another: return a value.{{else}}Porting scaffolding: delete, never translate:\n- `die` helper: `throw`\n- existence check before read: read raises\n- temp file passing data tool -> tool, and trap cleaning it\n- retry loop with `sleep`: `http\\Retry` or `os\\retry`\n- `command -v` choosing between two tools doing same thing\n- globals set in one function, read in another: return value{{end}}\n\n{{if .Full}}**Keeping a generator as a script.** A script that writes files other work reads belongs\nin a target. Otherwise its output is never cached, never checked for drift, and never\nrerun when its inputs change.{{else}}Generator kept as script: writes files other work reads -> target. Otherwise never cached, never drift-checked, never rerun on input change.{{end}}\n\n## Verify the port\n\n```sh\n{{cmd \"buzz\"}} --check new.buzz\n{{cmd \"buzz\"}} -t new.buzz\n{{cmd \"buzz\"}} new.buzz -- \u003Cargs>\n```\n\n{{if .Full}}Then run the old script and the new one on the same input and diff what each wrote. A\ntarget is verified by `{{cmd \"run\"}} \u003Ctarget> \u003Cproject>`, then once more to show the cache\nhit. Delete the `.sh` in the same commit that adds its replacement, so no caller keeps\nrunning the old one.{{else}}Then run old and new on same input, diff what each wrote. Target: `{{cmd \"run\"}} \u003Ctarget> \u003Cproject>`, then again to show cache hit. Delete `.sh` in same commit adding replacement; no caller keeps running old one.{{end}}\n",{},"main","5f0df014d9eaf4aea1a930b0bd13c3338e2642de","internal\u002Fagent\u002Fskills\u002Fmagus-buzz-from-shell",0,"https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus","http:\u002F\u002Feli.gladman.cc\u002Fmagus\u002F","https:\u002F\u002Fgithub.com\u002Fegladman","eli.gladman.cc","2026-11-14 12:23:44",{"source":7,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add egladman\u002Fmagus --skill magus-buzz-from-shell",{"tool":37,"command":38},"bunx","bunx skills add egladman\u002Fmagus --skill magus-buzz-from-shell",{"tool":40,"command":41},"pnpm","pnpm dlx skills add egladman\u002Fmagus --skill magus-buzz-from-shell","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-buzz-from-shell\u002FSKILL.md",true,[45],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"reference.md","REFERENCE","参考文档",4801,"https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-buzz-from-shell\u002Freference.md",[52,58,64,70,76,82],{"skillNo":53,"name":54,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":18},"01M76WWZ75J70NCG0TR23XDDE6","magus-workspace-rules","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-workspace-rules\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":18},"01M76WWX72SY78KG03AVYFE768","magus-vcs-hygiene","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-vcs-hygiene\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":18},"01M76WWTJYGRCKKXH948KN6RR3","magus-upstream-source","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-upstream-source\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":18},"01M76WWRTBBAPNKM0PA2NG5Q3N","magus-upstream-docs","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-upstream-docs\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":18},"01M76WWNTF03H9S5CN22QBX5ZK","magus-test-design","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-test-design\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M76WWJX1FPSWYD1RB8JXNF3C","magus-sdk","https:\u002F\u002Fgithub.com\u002Fegladman\u002Fmagus\u002Fblob\u002Fmain\u002Finternal\u002Fagent\u002Fskills\u002Fmagus-sdk\u002FSKILL.md",[],[]]