Use Template
Clone a game template from the gallery into a new project. This is a fast copy — working code in seconds, not an AI pipeline.
Behavior
Parse arguments: <template-id> [project-name]
- If no arguments provided, read
site/manifest.json, display a numbered list of all templates with their engine/complexity/description, and ask the user to pick one.
template-id is required. project-name defaults to template-id.
Look up template in site/manifest.json by id. If not found, show available IDs and abort.
Determine target directory:
- If current working directory is inside the
game-creator repository → examples/<project-name>/
- Otherwise →
./<project-name>/
- If target already exists, abort with error.
Copy the template source directory to the target, excluding:
node_modules/
dist/
output/
.herenow/
progress.md
test-results/
playwright-report/
Update project metadata:
- In
package.json: set "name" to the project name
- In
index.html (if exists): update <title> to a formatted version of the project name
Install dependencies: Run npm install in the target directory.
Print next steps:
Template cloned successfully!
cd <project-name>
npm run dev
Implementation
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Find game-creator root (contains site/manifest.json)
function findRoot(dir) {
let d = dir;
while (d !== path.dirname(d)) {
if (fs.existsSync(path.join(d, 'gallery', 'manifest.json'))) return d;
d = path.dirname(d);
}
return null;
}
const root = findRoot(process.cwd());
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'gallery', 'manifest.json'), 'utf-8'));
// Parse args
const [templateId, projectName] = args; // provided by the agent
const template = manifest.find(t => t.id === templateId);
const name = projectName || templateId;
// Validate project name — reject path traversal and special characters
if (/[\/\\]|^\.\.?$|\.\./.test(name)) {
throw new Error(`Invalid project name: "${name}". Must not contain path separators or ".." sequences.`);
}
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name)) {
throw new Error(`Invalid project name: "${name}". Use only alphanumeric characters, hyphens, underscores, and dots.`);
}
// Determine target
const inGameCreator = process.cwd().startsWith(root);
const target = inGameCreator
? path.join(root, 'examples', name)
: path.join(process.cwd(), name);
// Verify resolved path stays within expected parent directory
const expectedParent = inGameCreator ? path.join(root, 'examples') : process.cwd();
if (!path.resolve(target).startsWith(path.resolve(expectedParent))) {
throw new Error('Target directory resolved outside expected parent. Aborting.');
}
// Copy with exclusions
const EXCLUDE = ['node_modules', 'dist', 'output', '.herenow', 'progress.md', 'test-results', 'playwright-report'];
function copyDir(src, dst) {
fs.mkdirSync(dst, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
if (EXCLUDE.includes(entry.name)) continue;
const s = path.join(src, entry.name);
const d = path.join(dst, entry.name);
if (entry.isDirectory()) copyDir(s, d);
else fs.copyFileSync(s, d);
}
}
copyDir(path.join(root, template.source), target);
// Update package.json
const pkgPath = path.join(target, 'package.json');
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
pkg.name = name;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
}
// Update index.html title
const indexPath = path.join(target, 'index.html');
if (fs.existsSync(indexPath)) {
let html = fs.readFileSync(indexPath, 'utf-8');
const prettyName = name.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
html = html.replace(/<title>[^<]*<\/title>/, `<title>${prettyName}</title>`);
fs.writeFileSync(indexPath, html);
}
// Install
execSync('npm install', { cwd: target, stdio: 'inherit' });
// Optional anonymous telemetry — tracks which templates are popular
// Data sent: event type ("clone"), template ID, source ("skill"), schema version
// No PII, IP addresses, file paths, or user-identifiable data is transmitted
// Opt out: set DO_NOT_TRACK=1 or DISABLE_TELEMETRY=1 in your environment
if (!process.env.DO_NOT_TRACK && !process.env.DISABLE_TELEMETRY) {
const https = require('https');
const telemetryUrl = process.env.TELEMETRY_URL || 'https://gallery-telemetry.up.railway.app';
https.get(`${telemetryUrl}/t?event=clone&template=${encodeURIComponent(templateId)}&source=skill&v=1`)
.on('error', () => {});
}
Example Usage
/use-template flappy-bird my-game
/use-template threejs-3d-starter space-shooter
/use-template castle-siege
Security Notes
- Path validation: Project names are validated to reject path traversal (
..), path separators, and special characters. The resolved target path is verified to stay within the expected parent directory.
- npm install: Runs
npm install from the copied template's package.json, which contains only pinned dependencies from the template (Phaser/Three.js, Vite). No arbitrary packages are installed.
- Telemetry: Anonymous, opt-out usage telemetry sends only the template ID and event type (no PII, paths, or user data). Disable with
DO_NOT_TRACK=1 or DISABLE_TELEMETRY=1 environment variables.
- Template source: Templates are copied from the local
site/manifest.json registry within the plugin — no external templates are fetched at clone time.
Key Difference from /viral-game and /make-game
/use-template is a 10-second copy. You get working, runnable code instantly and customize it manually. /viral-game is a 10-minute AI pipeline that scaffolds, designs, adds audio, tests, deploys, and monetizes from a text prompt or tweet URL — opinionated and one-shot. /make-game is the deeper, multi-session game-dev workflow with milestones, ADRs, and docs/STATE.md for projects that need to evolve over time.
1---2name: use-template3description: Clone a game template from the gallery as a starting point. Use when the user says "use a template", "start from a template", "clone flappy-bird", "use the platformer template", or wants to quickly bootstrap a game from an existing example. Do NOT use for creating a game from scratch (use viral-game for one-shot builds or make-game for milestone-driven projects).4argument-hint: "[template-id] [project-name]"5license: MIT6metadata:7 source: https://skillmd.com/skills/playableintelligence/use-template8 author: OpusGameLabs9 version: 1.3.010 tags: [game, template, scaffold, clone, gallery]11---1213# Use Template1415Clone a game template from the gallery into a new project. This is a fast copy — working code in seconds, not an AI pipeline.1617## Behavior18191. **Parse arguments**: `<template-id> [project-name]`20 - If no arguments provided, read `site/manifest.json`, display a numbered list of all templates with their engine/complexity/description, and ask the user to pick one.21 - `template-id` is required. `project-name` defaults to `template-id`.22232. **Look up template** in `site/manifest.json` by `id`. If not found, show available IDs and abort.24253. **Determine target directory**:26 - If current working directory is inside the `game-creator` repository → `examples/<project-name>/`27 - Otherwise → `./<project-name>/`28 - If target already exists, abort with error.29304. **Copy the template source directory** to the target, **excluding**:31 - `node_modules/`32 - `dist/`33 - `output/`34 - `.herenow/`35 - `progress.md`36 - `test-results/`37 - `playwright-report/`38395. **Update project metadata**:40 - In `package.json`: set `"name"` to the project name41 - In `index.html` (if exists): update `<title>` to a formatted version of the project name42436. **Install dependencies**: Run `npm install` in the target directory.44457. **Print next steps**:46 ```47 Template cloned successfully!4849 cd <project-name>50 npm run dev51 ```5253## Implementation5455```javascript56const fs = require('fs');57const path = require('path');58const { execSync } = require('child_process');5960// Find game-creator root (contains site/manifest.json)61function findRoot(dir) {62 let d = dir;63 while (d !== path.dirname(d)) {64 if (fs.existsSync(path.join(d, 'gallery', 'manifest.json'))) return d;65 d = path.dirname(d);66 }67 return null;68}6970const root = findRoot(process.cwd());71const manifest = JSON.parse(fs.readFileSync(path.join(root, 'gallery', 'manifest.json'), 'utf-8'));7273// Parse args74const [templateId, projectName] = args; // provided by the agent75const template = manifest.find(t => t.id === templateId);76const name = projectName || templateId;7778// Validate project name — reject path traversal and special characters79if (/[\/\\]|^\.\.?$|\.\./.test(name)) {80 throw new Error(`Invalid project name: "${name}". Must not contain path separators or ".." sequences.`);81}82if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name)) {83 throw new Error(`Invalid project name: "${name}". Use only alphanumeric characters, hyphens, underscores, and dots.`);84}8586// Determine target87const inGameCreator = process.cwd().startsWith(root);88const target = inGameCreator89 ? path.join(root, 'examples', name)90 : path.join(process.cwd(), name);9192// Verify resolved path stays within expected parent directory93const expectedParent = inGameCreator ? path.join(root, 'examples') : process.cwd();94if (!path.resolve(target).startsWith(path.resolve(expectedParent))) {95 throw new Error('Target directory resolved outside expected parent. Aborting.');96}9798// Copy with exclusions99const EXCLUDE = ['node_modules', 'dist', 'output', '.herenow', 'progress.md', 'test-results', 'playwright-report'];100101function copyDir(src, dst) {102 fs.mkdirSync(dst, { recursive: true });103 for (const entry of fs.readdirSync(src, { withFileTypes: true })) {104 if (EXCLUDE.includes(entry.name)) continue;105 const s = path.join(src, entry.name);106 const d = path.join(dst, entry.name);107 if (entry.isDirectory()) copyDir(s, d);108 else fs.copyFileSync(s, d);109 }110}111112copyDir(path.join(root, template.source), target);113114// Update package.json115const pkgPath = path.join(target, 'package.json');116if (fs.existsSync(pkgPath)) {117 const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));118 pkg.name = name;119 fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');120}121122// Update index.html title123const indexPath = path.join(target, 'index.html');124if (fs.existsSync(indexPath)) {125 let html = fs.readFileSync(indexPath, 'utf-8');126 const prettyName = name.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());127 html = html.replace(/<title>[^<]*<\/title>/, `<title>${prettyName}</title>`);128 fs.writeFileSync(indexPath, html);129}130131// Install132execSync('npm install', { cwd: target, stdio: 'inherit' });133134// Optional anonymous telemetry — tracks which templates are popular135// Data sent: event type ("clone"), template ID, source ("skill"), schema version136// No PII, IP addresses, file paths, or user-identifiable data is transmitted137// Opt out: set DO_NOT_TRACK=1 or DISABLE_TELEMETRY=1 in your environment138if (!process.env.DO_NOT_TRACK && !process.env.DISABLE_TELEMETRY) {139 const https = require('https');140 const telemetryUrl = process.env.TELEMETRY_URL || 'https://gallery-telemetry.up.railway.app';141 https.get(`${telemetryUrl}/t?event=clone&template=${encodeURIComponent(templateId)}&source=skill&v=1`)142 .on('error', () => {});143}144```145146## Example Usage147148```149/use-template flappy-bird my-game150/use-template threejs-3d-starter space-shooter151/use-template castle-siege152```153154## Security Notes155156- **Path validation**: Project names are validated to reject path traversal (`..`), path separators, and special characters. The resolved target path is verified to stay within the expected parent directory.157- **npm install**: Runs `npm install` from the copied template's `package.json`, which contains only pinned dependencies from the template (Phaser/Three.js, Vite). No arbitrary packages are installed.158- **Telemetry**: Anonymous, opt-out usage telemetry sends only the template ID and event type (no PII, paths, or user data). Disable with `DO_NOT_TRACK=1` or `DISABLE_TELEMETRY=1` environment variables.159- **Template source**: Templates are copied from the local `site/manifest.json` registry within the plugin — no external templates are fetched at clone time.160161## Key Difference from /viral-game and /make-game162163`/use-template` is a **10-second copy**. You get working, runnable code instantly and customize it manually. `/viral-game` is a **10-minute AI pipeline** that scaffolds, designs, adds audio, tests, deploys, and monetizes from a text prompt or tweet URL — opinionated and one-shot. `/make-game` is the deeper, multi-session game-dev workflow with milestones, ADRs, and `docs/STATE.md` for projects that need to evolve over time.