agentleFS
DataArtDataArt/artisyn-log-hub/.claude/skills/nodejs-script/SKILL.md

nodejs-script

Skill12 starsChanged 7 days agoMITView on GitHub

Always use this skill when writing, editing, or reviewing any Node.js script in this project.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Use CommonJS. Never use ESM (import/export).

    line 10
  2. Very specific:

    Use only Node.js built-ins: fs, path, crypto, child_process, os, util.

    line 28
  3. Very specific:

    If a utility is needed (e.g.

    line 29
  4. Distinctive:

    Prefer explicit exits over falling off the end of the script.

    line 56
  5. Distinctive:

    Write diagnostics to stderr, not stdout (stdout may be parsed by the harness):

    line 60
  6. Very specific:

    Use console.error() only if you're sure the harness ignores stderr.

    line 66
  7. Very specific:

    Always use path.join() / path.resolve().

    line 70
  8. Very specific:

    Use execFileSync with an array of args, never execSync with a shell string (avoids injection):

    line 79
  9. Distinctive:

    Do not silently swallow errors inside helper functions — let them propagate to the top-level catch.

    line 105
  10. Distinctive:

    Always ensure the output directory exists before writing:

    line 109
  11. Very specific:

    Read from process.env or parse a .env file inline.

    line 118
  12. Distinctive:

    Run lint and fix before finishing:

    line 148

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Review or write the Node.js script using these conventions:

Module System

Use CommonJS. Never use ESM (import/export).

const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');

Sync over Async

This is a CLI hook — keep everything synchronous. Do not use async/await, Promises, or callbacks.

  • File I/O: fs.readFileSync, fs.writeFileSync, fs.mkdirSync
  • Subprocesses: execFileSync or spawnSync (never exec, execFile, spawn)
  • stdin: fs.readFileSync('/dev/stdin', 'utf8') or process.stdin.fd

No External Dependencies

Use only Node.js built-ins: fs, path, crypto, child_process, os, util. If a utility is needed (e.g. .env parsing, arg parsing), write a small inline function.

Code Style (matches ESLint config)

  • Single quotes for strings
  • Semicolons required
  • const by default; let only when reassigned; never var
  • Strict equality: === / !==
  • 2-space indentation

stdin Handling (for Claude Code hooks)

Hook scripts receive event data via stdin as JSON:

const raw = fs.readFileSync(process.stdin.fd, 'utf8');
const event = JSON.parse(raw);

Wrap in try/catch — stdin may be empty or malformed.

Exit Codes

  • process.exit(0) — success
  • process.exit(1) — unrecoverable error
  • process.exit(2) — block the action (for PreToolUse hooks that want to prevent tool execution)

Prefer explicit exits over falling off the end of the script.

Logging

Write diagnostics to stderr, not stdout (stdout may be parsed by the harness):

process.stderr.write('Error: ...\n');

Use console.error() only if you're sure the harness ignores stderr.

Path Handling

Always use path.join() / path.resolve(). Never concatenate paths with string +.

const dir = path.resolve(__dirname, '../telemetry');
const file = path.join(dir, `${Date.now()}.json`);

Subprocess Calls

Use execFileSync with an array of args, never execSync with a shell string (avoids injection):

const out = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
  encoding: 'utf8',
  timeout: 2000,
}).trim();

Wrap in try/catch — the command may not exist or may fail.

Error Handling

Top-level scripts should have a single try/catch guard:

try {
  const raw = fs.readFileSync(process.stdin.fd, 'utf8');
  // ... main logic ...
  process.exit(0);
} catch (err) {
  process.stderr.write(`telemetry-hook error: ${err.message}\n`);
  process.exit(1);
}

Do not silently swallow errors inside helper functions — let them propagate to the top-level catch.

File Writing

Always ensure the output directory exists before writing:

fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');

Environment Variables

Read from process.env or parse a .env file inline. Never use dotenv package.

Simple inline .env parser:

function loadEnv(envPath) {
  try {
    const vars = {};
    for (const line of fs.readFileSync(envPath, 'utf8').split(/\r?\n/)) {
      const trimmed = line.trim();
      if (!trimmed || trimmed.startsWith('#')) continue;
      const eq = trimmed.indexOf('=');
      if (eq === -1) continue;
      const key = trimmed.slice(0, eq).trim();
      let val = trimmed.slice(eq + 1).trim();
      if ((val.startsWith('"') && val.endsWith('"')) ||
          (val.startsWith("'") && val.endsWith("'"))) {
        val = val.slice(1, -1);
      }
      vars[key] = val;
    }
    return vars;
  } catch {
    return {};
  }
}

After Changes

Run lint and fix before finishing:

npm run lint:fix
npm run lint

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.