算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
scaffold-cli-command【设计与创意】Scaffold a new CLI command using Commander.js with options, action handler, three output modes (human-readable, quiet, JSON), and optional ceremony variant. Covers command naming, option design, shared context patterns, error handling, and integration testing. Use when adding a command to an existing Commander.js CLI, designing a new CLI tool from sc…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
一貫したオプション処理、3 出力モード、統合テスト付きで Commander.js CLI アプリケーションに新しいコマンドを加える。
gather、audit、sync)cli/index.js)<name> または [names...] のような位置引数)コマンドの行動を伝える動詞を選ぶ。コマンドをカテゴリにグループ化する:
| Category | Verbs | Pattern |
|---|---|---|
| CRUD | install, uninstall, list, search | Operates on content |
| Lifecycle | init, sync, audit | Manages project state |
| Ceremony | gather, scatter, tend, campfire | Warm narrative output |
命名慣習:
install-skill ではなく — 何かはオプションに指定させる)<required> または [optional] または [variadic...]program
.command('gather <name>')
.description('Gather a team around the campfire')
期待結果: コマンド名、説明、位置引数が定義された。
失敗時: 動詞が既存コマンドと重複するなら、組み合わせる(既存コマンドにオプションを加える)か説明で明確に区別する。
すべてのコマンドは標準共有オプションセットとコマンド固有のものをサポートすべき。
標準オプション(必要に応じて含める):
.option('-n, --dry-run', 'Preview without making changes')
.option('-q, --quiet', 'Suppress human-readable output')
.option('--json', 'Output as JSON')
.option('-f, --framework <id>', 'Target specific framework')
.option('-g, --global', 'Use global scope')
.option('--scope <scope>', 'Scope: project, workspace, global', 'project')
.option('--source <path>', 'Path to tool root directory')
コマンド固有オプション — コマンドに必要なものだけ加える:
.option('--ceremonial', 'Show each item arriving individually')
.option('--only <items>', 'Comma-separated subset to include')
.option('-y, --yes', 'Skip confirmation prompts')
設計ルール:
-n)--dry-run)期待結果: 標準とカスタムオプション両方を持つ完全なオプションチェーン。
失敗時: あまりに多くのオプションが蓄積(>8)したら、サブコマンドに分割するか関連オプションをグループ化することを検討する。
アクションハンドラは一貫したパターンに従う:
.action(async (name, options) => {
// 1. Get shared context (registries, adapters, paths)
const ctx = getContext(options);
// 2. Resolve what to operate on
const items = resolveItems(ctx, name, options);
if (!items || items.length === 0) {
reporter.error('Nothing found.');
process.exit(1);
}
// 3. Preview if dry-run
if (options.dryRun) reporter.printDryRun();
// 4. Execute the operation
const results = await executeOperation(items, ctx, options);
// 5. Output results (3 modes)
if (options.json) {
console.log(JSON.stringify(results, null, 2));
} else if (options.quiet) {
reporter.printResults(results);
} else {
printHumanOutput(results, options);
}
})
getContext() 共有ヘルパーが集約する:
期待結果: 5 ステップパターンに従うアクションハンドラ: context → resolve → preview → execute → output。
失敗時: コマンドが resolve-then-execute パターンに合わない(例: detect のように純粋に情報的)なら、簡略化: context → compute → output。
すべてのコマンドは 3 出力モードをサポートすべき:
Default (human-readable):
Installing 3 item(s) to Claude Code...
+ create-skill [claude-code] .claude/skills/create-skill
+ write-tests [claude-code] .claude/skills/write-tests
= commit-changes [claude-code] (skipped)
2 installed, 1 skipped
Quiet (--quiet):
標準レポーター出力 — ステータスアイコン(+、-、=、!)付きの簡潔な行、セレモニーなし、装飾なし。
JSON (--json):
{
"command": "install",
"items": 3,
"installed": 2,
"skipped": 1,
"failed": 0
}
実装パターン:
if (options.json) {
console.log(JSON.stringify(data, null, 2));
return;
}
if (options.quiet) {
reporter.printResults(results);
return;
}
// Default: human-readable output
printHumanReadable(results, options);
期待結果: 3 モードすべてが有用な出力を生む。JSON は解析可能。Quiet は簡潔。Default は情報的。
失敗時: コマンドに意味のある JSON 表現がない(例: detect)なら、JSON モードをスキップして理由を文書化する。
トランザクション報告ではなく温かい物語出力から利益を受けるコマンドのため:
if (options.json) {
ceremonyReporter.printJson(data);
} else if (options.quiet) {
reporter.printResults(results);
} else {
ceremonyReporter.printArrival({
teamId: name,
agents,
results: { installed, skipped, failed },
ceremonial: options.ceremonial || false,
});
}
セレモニー出力はボイスルールに従う:
詳細なターミナル出力パターンは design-cli-output スキルを参照。
期待結果: すべてのボイスルールに従い温かく情報的な物語を生むセレモニー出力。
失敗時: セレモニー出力が強制に感じる、または標準出力を超えて情報を加えないなら、スキップする。すべてのコマンドがセレモニーバリアントを必要とするわけではない。
// Unknown item
if (!item) {
reporter.error(`Unknown: ${name}. Use 'tool list' to browse.`);
process.exit(1);
}
// Confirmation for destructive actions
if (!options.yes && !options.quiet && !options.dryRun) {
const answer = await askYesNo('Proceed?');
if (!answer) {
console.log(' Cancelled.');
return;
}
}
// State validation
if (!state.fires[name]) {
reporter.error(`Not active. Nothing to remove.`);
process.exit(1);
}
エラー設計原則:
process.exit(1)--yes で迂回)期待結果: すべてのエラーパスが助けになるメッセージを生む。破壊的操作は確認を要求する。
失敗時: 確認プロンプトがスクリプトに干渉するなら、--yes と --quiet の両方が迂回することを保証する。
import { describe, it, after } from 'node:test';
import assert from 'node:assert/strict';
import { execSync } from 'child_process';
const CLI = 'node cli/index.js';
function run(args) {
return execSync(`${CLI} ${args}`, { encoding: 'utf8', timeout: 10000 });
}
describe('new-command', () => {
after(() => { /* cleanup created files/state */ });
it('dry-run shows preview', () => {
const out = run('new-command arg --dry-run');
assert.match(out, /DRY RUN/);
});
it('--json outputs valid JSON', () => {
const out = run('new-command arg --json');
const start = out.indexOf('{');
const data = JSON.parse(out.slice(start));
assert.equal(data.command, 'new-command');
});
it('rejects unknown input', () => {
assert.throws(() => run('new-command nonexistent'), /Unknown/);
});
});
包括的な CLI テストパターンは test-cli-application スキルを参照。
期待結果: 少なくとも 3 テスト: dry-run、JSON 出力、エラーケース。複雑コマンドにはより多く。
失敗時: execSync がタイムアウトしたら、タイムアウトを増やすかコマンドをブロックする対話プロンプトを確認する。
--help に現れる--dry-run、--quiet、--json)が正しく動く--yes で迂回)--json を実装する。--yes を提供し --quiet がプロンプトを抑制することを保証する。process.exit(1) を使う。CLI 出力を解析するツールはまず終了コードを確認する。--scope のようなオプションはユーザーが毎回指定する必要がないよう合理的な既定を持つべき。--quiet フラグは「マシン用の最小出力」を意味する。セレモニーテキストが quiet モードに漏れたら、スクリプトは予期しない出力で壊れる。build-cli-plugin — コマンドが操作するアダプタ/プラグインを構築test-cli-application — ステップ7 の基本を超える包括的 CLI テストパターンdesign-cli-output — すべての冗長度レベルのターミナル出力設計install-almanac-content — よく構造化された CLI コマンドスキルの例