@supa-media/claude 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Supa Media LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @supa-media/claude
2
+
3
+ **Claude Code configuration for a Supa app, kept in one place and synced in.**
4
+ Ships a `CLAUDE.md`, a conservative permissions file, an empty hooks file, and
5
+ seven slash-command templates; `supa-claude sync` copies them into your repo with
6
+ your app's name substituted, and never clobbers a file you've edited unless you
7
+ ask it to.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add -D @supa-media/claude
13
+ ```
14
+
15
+ Or run it one-off, without adding a dependency:
16
+
17
+ ```bash
18
+ npx @supa-media/claude sync
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ npx @supa-media/claude sync Sync templates and generate CLAUDE.md
25
+ npx @supa-media/claude sync --force Overwrite existing files
26
+ npx @supa-media/claude sync --dry-run Print the plan, write nothing
27
+ npx @supa-media/claude help Show usage
28
+ ```
29
+
30
+ `sync` is the only command (and the default when none is given). `--help` / `-h`
31
+ work anywhere. The project root is the nearest ancestor of the cwd containing a
32
+ `package.json`.
33
+
34
+ ## What it writes
35
+
36
+ | Path | Source | Substituted |
37
+ | --- | --- | --- |
38
+ | `CLAUDE.md` (project root) | `templates/CLAUDE.md` | yes |
39
+ | `.claude/settings.json` | `templates/settings.json` | no — copied verbatim |
40
+ | `.claude/hooks.json` | `templates/hooks.json` | yes |
41
+ | `.claude/commands/*.md` | `templates/commands/` | yes |
42
+
43
+ The seven commands: `auto-worker`, `feature-validate`, `fix-ci`, `ios-build`,
44
+ `isolate`, `lock-up`, `review-cycle`.
45
+
46
+ Every file follows the same rule: **created if absent, skipped if it already
47
+ exists**, and rewritten only under `--force` (and then only when the content
48
+ actually differs). Each run prints created / updated / skipped / unchanged.
49
+
50
+ ## Configuration
51
+
52
+ Values are read from `supa.config.ts`, `.js`, or `.mjs` in the project root,
53
+ falling back to `package.json`'s `name` for both name fields.
54
+
55
+ | Value | Substitutes |
56
+ | --- | --- |
57
+ | `appName` (or `name`) | `{{APP_NAME}}` |
58
+ | `displayName` | `{{APP_DISPLAY_NAME}}` (defaults to `appName`) |
59
+ | `githubOwner` (or `owner`) | the literal word `OWNER` |
60
+ | `githubRepo` (or `repo`) | the literal string `"REPO"` |
61
+
62
+ The owner/repo tokens exist for the GitHub GraphQL queries in
63
+ `commands/review-cycle.md`; leave them unset and the templates keep their
64
+ placeholders with the accompanying "replace OWNER and REPO" notes.
65
+
66
+ > **⚠️ The config file is scanned with regexes, not imported.** Each pattern
67
+ > takes the **first** match anywhere in the file, so an unrelated `name:` earlier
68
+ > in the config wins. And the GitHub substitution is a blind global replace of the
69
+ > bare word `OWNER` and the quoted string `"REPO"` — an unquoted `REPO` (e.g. in a
70
+ > `repos/OWNER/REPO/...` path) is left alone, and any other occurrence of the word
71
+ > `OWNER` in a template you add will be replaced too.
72
+
73
+ ## Permissions
74
+
75
+ `templates/settings.json` ships a deliberately conservative
76
+ `permissions.allow` list — routine, reversible commands only:
77
+
78
+ - **pnpm** — `install`, and the `dev:`/`build:`/`test:`/`lint:`/`typecheck:`/`clean:`/`--filter:` prefixes, plus `convex:dashboard` and `convex:logs`
79
+ - **Convex** — `npx convex dev`, `npx convex run`, `npx convex logs`
80
+ - **Build/test** — `npx tsc`, `node --test`
81
+ - **Read-only git and gh** — `status`, `diff`, `log`, `show`, `branch`, `fetch`; `gh pr view|list|diff|checks`, `gh run view|list`, `gh api graphql`
82
+ - **Local git writes** — `git add`, `git commit`, `git checkout`
83
+
84
+ It also denies reads of `.env` and `.env.*`, at the project root and nested.
85
+
86
+ Everything not listed still prompts — deliberately. That includes `git push`,
87
+ `git reset --hard`, `git clean`, `gh pr merge`, `convex deploy`, and `eas`: the
88
+ commands that publish, deploy, or destroy work. This is a floor, not a finished
89
+ policy. **Widen it for your own repo** once you know which of those you're
90
+ comfortable granting; `sync` will not overwrite an existing
91
+ `.claude/settings.json` without `--force`, so your edits survive later syncs.
92
+
93
+ `templates/hooks.json` ships **empty** — a starting point for your own
94
+ `PreToolUse` / `PostToolUse` / `Stop` entries. Any `command` you register must
95
+ point at a script that actually exists in your repo; a missing script makes the
96
+ hook fail on every invocation.
97
+
98
+ No tests ship with this package.
99
+
100
+ ---
101
+
102
+ Part of the **Supa Media framework** — https://github.com/Supa-Media/supa-framework. MIT.
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@supa-media/claude",
3
+ "version": "1.0.2",
4
+ "description": "Claude Code configuration templates for Supa apps",
5
+ "type": "module",
6
+ "bin": {
7
+ "supa-claude": "src/sync.js"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "templates",
12
+ "LICENSE"
13
+ ],
14
+ "keywords": [
15
+ "supa",
16
+ "claude",
17
+ "ai",
18
+ "agent",
19
+ "configuration"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Supa-Media/supa-framework.git",
24
+ "directory": "packages/claude"
25
+ },
26
+ "publishConfig": {
27
+ "registry": "https://registry.npmjs.org"
28
+ },
29
+ "license": "MIT"
30
+ }
package/src/sync.js ADDED
@@ -0,0 +1,319 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @supa-media/claude sync
5
+ *
6
+ * Syncs Claude Code configuration templates into a Supa app's .claude/ directory
7
+ * and generates CLAUDE.md from the template with app-specific values.
8
+ *
9
+ * Usage:
10
+ * npx @supa-media/claude sync
11
+ * npx @supa-media/claude sync --force # overwrite existing files without prompting
12
+ * npx @supa-media/claude sync --dry-run # show what would be changed without writing
13
+ */
14
+
15
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync } from "fs";
16
+ import { join, dirname, relative, resolve } from "path";
17
+ import { fileURLToPath } from "url";
18
+
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+ const TEMPLATES_DIR = join(__dirname, "..", "templates");
22
+
23
+ // --- Helpers ---
24
+
25
+ function findProjectRoot(startDir) {
26
+ let dir = startDir;
27
+ while (dir !== dirname(dir)) {
28
+ if (existsSync(join(dir, "package.json"))) {
29
+ return dir;
30
+ }
31
+ dir = dirname(dir);
32
+ }
33
+ return null;
34
+ }
35
+
36
+ function loadSupaConfig(projectRoot) {
37
+ // Try loading supa.config.ts values. Since we can't import TS directly,
38
+ // we parse the file for common values as a best-effort approach.
39
+ const configPaths = [
40
+ join(projectRoot, "supa.config.ts"),
41
+ join(projectRoot, "supa.config.js"),
42
+ join(projectRoot, "supa.config.mjs"),
43
+ ];
44
+
45
+ for (const configPath of configPaths) {
46
+ if (existsSync(configPath)) {
47
+ const content = readFileSync(configPath, "utf-8");
48
+ return parseSupaConfig(content);
49
+ }
50
+ }
51
+
52
+ // Fall back to package.json for app name
53
+ const pkgPath = join(projectRoot, "package.json");
54
+ if (existsSync(pkgPath)) {
55
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
56
+ return {
57
+ appName: pkg.name || "my-supa-app",
58
+ appDisplayName: pkg.name || "My Supa App",
59
+ };
60
+ }
61
+
62
+ return { appName: "my-supa-app", appDisplayName: "My Supa App" };
63
+ }
64
+
65
+ function parseSupaConfig(content) {
66
+ const config = {};
67
+
68
+ // Extract appName or name
69
+ const nameMatch = content.match(/(?:appName|name)\s*:\s*["']([^"']+)["']/);
70
+ config.appName = nameMatch ? nameMatch[1] : "my-supa-app";
71
+
72
+ // Extract displayName
73
+ const displayMatch = content.match(/displayName\s*:\s*["']([^"']+)["']/);
74
+ config.appDisplayName = displayMatch ? displayMatch[1] : config.appName;
75
+
76
+ // Extract GitHub owner/repo if present
77
+ const ownerMatch = content.match(/(?:githubOwner|owner)\s*:\s*["']([^"']+)["']/);
78
+ config.githubOwner = ownerMatch ? ownerMatch[1] : null;
79
+
80
+ const repoMatch = content.match(/(?:githubRepo|repo)\s*:\s*["']([^"']+)["']/);
81
+ config.githubRepo = repoMatch ? repoMatch[1] : null;
82
+
83
+ return config;
84
+ }
85
+
86
+ function applyTemplateVars(content, config) {
87
+ let result = content;
88
+ result = result.replace(/\{\{APP_NAME\}\}/g, config.appName);
89
+ result = result.replace(/\{\{APP_DISPLAY_NAME\}\}/g, config.appDisplayName || config.appName);
90
+
91
+ if (config.githubOwner) {
92
+ result = result.replace(/OWNER/g, config.githubOwner);
93
+ }
94
+ if (config.githubRepo) {
95
+ result = result.replace(/"REPO"/g, `"${config.githubRepo}"`);
96
+ }
97
+
98
+ return result;
99
+ }
100
+
101
+ function filesAreEqual(path, newContent) {
102
+ if (!existsSync(path)) return false;
103
+ const existing = readFileSync(path, "utf-8");
104
+ return existing === newContent;
105
+ }
106
+
107
+ function ensureDir(dirPath) {
108
+ if (!existsSync(dirPath)) {
109
+ mkdirSync(dirPath, { recursive: true });
110
+ }
111
+ }
112
+
113
+ function getAllFiles(dir, baseDir = dir) {
114
+ const files = [];
115
+ for (const entry of readdirSync(dir)) {
116
+ const fullPath = join(dir, entry);
117
+ const stat = statSync(fullPath);
118
+ if (stat.isDirectory()) {
119
+ files.push(...getAllFiles(fullPath, baseDir));
120
+ } else {
121
+ files.push(relative(baseDir, fullPath));
122
+ }
123
+ }
124
+ return files;
125
+ }
126
+
127
+ // --- Main sync logic ---
128
+
129
+ function sync(projectRoot, options = {}) {
130
+ const { force = false, dryRun = false } = options;
131
+ const config = loadSupaConfig(projectRoot);
132
+ const claudeDir = join(projectRoot, ".claude");
133
+ const commandsDir = join(claudeDir, "commands");
134
+
135
+ const results = {
136
+ created: [],
137
+ updated: [],
138
+ skipped: [],
139
+ unchanged: [],
140
+ };
141
+
142
+ console.log(`\n @supa-media/claude sync`);
143
+ console.log(` Project: ${config.appName}`);
144
+ console.log(` Target: ${claudeDir}\n`);
145
+
146
+ if (dryRun) {
147
+ console.log(" (dry run - no files will be written)\n");
148
+ }
149
+
150
+ // --- 1. Sync CLAUDE.md to project root ---
151
+ const claudeMdTemplate = readFileSync(join(TEMPLATES_DIR, "CLAUDE.md"), "utf-8");
152
+ const claudeMdContent = applyTemplateVars(claudeMdTemplate, config);
153
+ const claudeMdPath = join(projectRoot, "CLAUDE.md");
154
+
155
+ if (!existsSync(claudeMdPath)) {
156
+ if (!dryRun) writeFileSync(claudeMdPath, claudeMdContent);
157
+ results.created.push("CLAUDE.md");
158
+ } else if (force) {
159
+ if (!filesAreEqual(claudeMdPath, claudeMdContent)) {
160
+ if (!dryRun) writeFileSync(claudeMdPath, claudeMdContent);
161
+ results.updated.push("CLAUDE.md");
162
+ } else {
163
+ results.unchanged.push("CLAUDE.md");
164
+ }
165
+ } else {
166
+ results.skipped.push("CLAUDE.md (exists, use --force to overwrite)");
167
+ }
168
+
169
+ // --- 2. Sync settings.json ---
170
+ ensureDir(claudeDir);
171
+ const settingsTemplate = readFileSync(join(TEMPLATES_DIR, "settings.json"), "utf-8");
172
+ const settingsPath = join(claudeDir, "settings.json");
173
+
174
+ if (!existsSync(settingsPath)) {
175
+ if (!dryRun) writeFileSync(settingsPath, settingsTemplate);
176
+ results.created.push(".claude/settings.json");
177
+ } else if (force) {
178
+ if (!filesAreEqual(settingsPath, settingsTemplate)) {
179
+ if (!dryRun) writeFileSync(settingsPath, settingsTemplate);
180
+ results.updated.push(".claude/settings.json");
181
+ } else {
182
+ results.unchanged.push(".claude/settings.json");
183
+ }
184
+ } else {
185
+ results.skipped.push(".claude/settings.json (exists)");
186
+ }
187
+
188
+ // --- 3. Sync hooks.json ---
189
+ const hooksTemplate = readFileSync(join(TEMPLATES_DIR, "hooks.json"), "utf-8");
190
+ const hooksContent = applyTemplateVars(hooksTemplate, config);
191
+ const hooksPath = join(claudeDir, "hooks.json");
192
+
193
+ if (!existsSync(hooksPath)) {
194
+ if (!dryRun) writeFileSync(hooksPath, hooksContent);
195
+ results.created.push(".claude/hooks.json");
196
+ } else if (force) {
197
+ if (!filesAreEqual(hooksPath, hooksContent)) {
198
+ if (!dryRun) writeFileSync(hooksPath, hooksContent);
199
+ results.updated.push(".claude/hooks.json");
200
+ } else {
201
+ results.unchanged.push(".claude/hooks.json");
202
+ }
203
+ } else {
204
+ results.skipped.push(".claude/hooks.json (exists)");
205
+ }
206
+
207
+ // --- 4. Sync command templates ---
208
+ ensureDir(commandsDir);
209
+ const commandTemplatesDir = join(TEMPLATES_DIR, "commands");
210
+ const commandFiles = getAllFiles(commandTemplatesDir);
211
+
212
+ for (const relPath of commandFiles) {
213
+ const templatePath = join(commandTemplatesDir, relPath);
214
+ const templateContent = readFileSync(templatePath, "utf-8");
215
+ const content = applyTemplateVars(templateContent, config);
216
+ const destPath = join(commandsDir, relPath);
217
+
218
+ ensureDir(dirname(destPath));
219
+
220
+ if (!existsSync(destPath)) {
221
+ if (!dryRun) writeFileSync(destPath, content);
222
+ results.created.push(`.claude/commands/${relPath}`);
223
+ } else if (force) {
224
+ if (!filesAreEqual(destPath, content)) {
225
+ if (!dryRun) writeFileSync(destPath, content);
226
+ results.updated.push(`.claude/commands/${relPath}`);
227
+ } else {
228
+ results.unchanged.push(`.claude/commands/${relPath}`);
229
+ }
230
+ } else {
231
+ // Check if the file content matches - if so, it's unchanged
232
+ if (filesAreEqual(destPath, content)) {
233
+ results.unchanged.push(`.claude/commands/${relPath}`);
234
+ } else {
235
+ results.skipped.push(`.claude/commands/${relPath} (exists, use --force to overwrite)`);
236
+ }
237
+ }
238
+ }
239
+
240
+ // --- Print results ---
241
+ if (results.created.length > 0) {
242
+ console.log(" Created:");
243
+ for (const f of results.created) console.log(` + ${f}`);
244
+ }
245
+
246
+ if (results.updated.length > 0) {
247
+ console.log(" Updated:");
248
+ for (const f of results.updated) console.log(` ~ ${f}`);
249
+ }
250
+
251
+ if (results.skipped.length > 0) {
252
+ console.log(" Skipped:");
253
+ for (const f of results.skipped) console.log(` - ${f}`);
254
+ }
255
+
256
+ if (results.unchanged.length > 0) {
257
+ console.log(" Unchanged:");
258
+ for (const f of results.unchanged) console.log(` = ${f}`);
259
+ }
260
+
261
+ const totalChanges = results.created.length + results.updated.length;
262
+ if (totalChanges === 0 && results.skipped.length === 0) {
263
+ console.log(" Everything is up to date.\n");
264
+ } else if (totalChanges > 0) {
265
+ console.log(`\n ${totalChanges} file(s) synced.\n`);
266
+ } else {
267
+ console.log(`\n No changes made. Use --force to overwrite existing files.\n`);
268
+ }
269
+
270
+ return results;
271
+ }
272
+
273
+ // --- CLI ---
274
+
275
+ function main() {
276
+ const args = process.argv.slice(2);
277
+ const command = args.find((a) => !a.startsWith("--")) || "sync";
278
+ const force = args.includes("--force");
279
+ const dryRun = args.includes("--dry-run");
280
+
281
+ if (command === "help" || args.includes("--help") || args.includes("-h")) {
282
+ console.log(`
283
+ @supa-media/claude - Claude Code configuration for Supa apps
284
+
285
+ Usage:
286
+ npx @supa-media/claude sync Sync templates into .claude/ and generate CLAUDE.md
287
+ npx @supa-media/claude sync --force Overwrite existing files
288
+ npx @supa-media/claude sync --dry-run Preview changes without writing files
289
+ npx @supa-media/claude help Show this help message
290
+
291
+ Configuration:
292
+ The sync command reads app-specific values from supa.config.ts (or .js/.mjs)
293
+ in your project root. Supported fields:
294
+
295
+ appName - Used in CLAUDE.md template (e.g., project naming)
296
+ displayName - Human-readable app name
297
+ githubOwner - GitHub org/user for GraphQL queries in review-cycle
298
+ githubRepo - GitHub repo name for GraphQL queries in review-cycle
299
+
300
+ If no config file is found, values are read from package.json.
301
+ `);
302
+ process.exit(0);
303
+ }
304
+
305
+ if (command !== "sync") {
306
+ console.error(` Unknown command: ${command}\n Run 'npx @supa-media/claude help' for usage.`);
307
+ process.exit(1);
308
+ }
309
+
310
+ const projectRoot = findProjectRoot(process.cwd());
311
+ if (!projectRoot) {
312
+ console.error(" Could not find project root (no package.json found).");
313
+ process.exit(1);
314
+ }
315
+
316
+ sync(projectRoot, { force, dryRun });
317
+ }
318
+
319
+ main();