writing-repo-scripts

Enforces authoring rules for Node .mjs repository automation scripts under scripts/**.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/tomada1114/quick-reply-drill --skill writing-repo-scripts-tomada1114
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: writing-repo-scripts
Source: https://github.com/tomada1114/quick-reply-drill/tree/main/.agents/skills/writing-repo-scripts
Command: npx skills add https://github.com/tomada1114/quick-reply-drill --skill writing-repo-scripts-tomada1114

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Repository automation scripts that must run before dependencies are installed often break in subtle ways: they import packages that do not exist yet, inherit GIT_DIR from a git hook and write to the wrong repository, or emit errors an automated agent cannot act on. This Skill defines the authoring contract that prevents those failures. ## Core Features & Use Cases - Dependency-free .mjs authoring: Restricts scripts to node:* builtins and shared helpers under scripts/lib/, with explicit imports of Node globals and no compile step. - Git hook safety: Explains how an inherited GIT_DIR or GIT_INDEX_FILE outranks cwd and -C, and requires isolatedGitEnv from scripts/lib/git-env.mjs for any spawned git call. - Typing and JSON narrowing: Requires JSDoc boundary types under allowJs/checkJs and narrowing JSON.parse output through readKey/readString in scripts/lib/json.mjs instead of casts. - CLI guard and stderr contract: Mandates the import.meta.main guard for dual importable/runnable files and an ERR_<STAGE>_* error format stating what failed, expected versus actual, and the next safe command. - Use Case: A lefthook pre-commit run fails because a spawned git command wrote to the outer repository's index; this Skill diagnoses the inherited GIT_DIR cause and prescribes the isolatedGitEnv fix. ## Quick Start Ask the AI to write a new repository automation script under scripts/ that follows this Skill's rules for imports, git isolation, typing, and error reporting.

Frequently Asked Questions about writing-repo-scripts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Node script that runs before dependencies are installed?▼

Author it as an .mjs file importing only node:* builtins and shared helpers under scripts/lib/, never anything from node_modules. If the script needs an installed tool, spawn it at run time so the script still loads when the dependency is absent.

Why does a spawned git command write to the wrong repository in a git hook?▼

Git exports GIT_DIR to every hook it runs, and an inherited GIT_DIR outranks both a cwd and an explicit -C flag. Clear the GIT_* variables with isolatedGitEnv from scripts/lib/git-env.mjs before spawning any git call that names its target repository.

How do I make a Node script both importable in tests and runnable as a CLI?▼

Guard the CLI half with import.meta.main, which is true only for the module Node was started with, even through symlinked bin shims. Do not use import.meta.url.endsWith checks, which cannot distinguish an entry point from an imported module.

How should JSON.parse output be typed under checkJs?▼

Receive JSON.parse output as unknown and narrow it through readKey and readString helpers in scripts/lib/json.mjs rather than casting directly. This avoids conflicts between noPropertyAccessFromIndexSignature and the typed-lint dot-notation rule on Record types.

What should an automation script print to stderr when it fails?▼

Print what failed, the path or export involved, expected versus actual values, an ERR_<STAGE>_* code, and the next safe command to run. Never include secrets or absolute home paths, since the reader is an automated agent rather than a human.