-
Notifications
You must be signed in to change notification settings - Fork 8
feat(cli): add copy-list system to fetch shared files after scaffolding #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b689dc
The `skills-lock.json` change is a pre-existing modification that was…
Drew-Macgibbon 17d7805
feat(cli): add copy-list system to fetch shared files after scaffolding
Drew-Macgibbon 1209db5
chore(astronera): switch to workspace dependency for local layer testing
Drew-Macgibbon d3ae573
fix(layer): resolve all lint errors across layer and cli
Drew-Macgibbon 1a500f7
fix(cli): add input validation to copy-files to resolve CodeQL warnings
Drew-Macgibbon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "repo": "incubrain/foundry", | ||
| "ref": "main", | ||
| "files": [ | ||
| { "src": "scripts/install-skills.sh" }, | ||
| { "src": ".agents/rules/architecture.md" }, | ||
| { "src": ".agents/rules/conventions.md" }, | ||
| { "src": ".agents/rules/decisions.md" }, | ||
| { "src": ".agents/rules/anti-patterns.md" }, | ||
| { "src": ".claude/settings.json" }, | ||
| { "src": ".claude/skills.json" }, | ||
| { "src": ".claude/agents/codebase-explorer.md" }, | ||
| { "src": ".claude/agents/nuxt-dev.md" }, | ||
| { "src": ".claude/agents/signal-reviewer.md" }, | ||
| { "src": "skills/docs-writer/SKILL.md" }, | ||
| { "src": "skills/docs-writer/references/MDC-SYNTAX.md" }, | ||
| { "src": "skills/docs-writer/references/COMPONENTS.md" }, | ||
| { "src": ".prettierrc" }, | ||
| { "src": "deploy/vercel.website.json", "dest": "deploy/vercel.json" } | ||
| ] | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { readFile, writeFile, mkdir } from 'node:fs/promises' | ||
| import { resolve, dirname, join, relative } from 'node:path' | ||
| import type { CopyListConfig } from './types' | ||
|
|
||
| const GITHUB_RAW = 'https://raw.githubusercontent.com' | ||
| const REPO_PATTERN = /^[\w.-]+\/[\w.-]+$/ | ||
| const REF_PATTERN = /^[\w./-]+$/ | ||
| const PATH_PATTERN = /^[\w./-]+$/ | ||
|
|
||
| function validateRepo(repo: string): void { | ||
| if (!REPO_PATTERN.test(repo)) { | ||
| throw new Error(`Invalid repo format: "${repo}" (expected "owner/name")`) | ||
| } | ||
| } | ||
|
|
||
| function validateRef(ref: string): void { | ||
| if (!REF_PATTERN.test(ref)) { | ||
| throw new Error(`Invalid ref format: "${ref}"`) | ||
| } | ||
| } | ||
|
|
||
| function validateFilePath(filePath: string): void { | ||
| if (!PATH_PATTERN.test(filePath) || filePath.includes('..')) { | ||
| throw new Error(`Invalid file path: "${filePath}"`) | ||
| } | ||
| } | ||
|
|
||
| function safeDest(projectDir: string, dest: string): string { | ||
| const destPath = resolve(projectDir, dest) | ||
| const rel = relative(projectDir, destPath) | ||
| if (rel.startsWith('..') || resolve(destPath) !== destPath) { | ||
| throw new Error(`Path traversal blocked: "${dest}" resolves outside project`) | ||
| } | ||
| return destPath | ||
| } | ||
|
|
||
| export async function processCopyList(projectDir: string): Promise<void> { | ||
| const configPath = join(projectDir, 'copy-list.json') | ||
|
|
||
| let raw: string | ||
| try { | ||
| raw = await readFile(configPath, 'utf-8') | ||
| } | ||
| catch { | ||
| return | ||
| } | ||
|
|
||
| const config: CopyListConfig = JSON.parse(raw) | ||
| const repo = config.repo ?? 'incubrain/foundry' | ||
| const ref = config.ref ?? 'main' | ||
| const { files } = config | ||
|
|
||
| validateRepo(repo) | ||
| validateRef(ref) | ||
|
|
||
| console.log(`\nFetching ${files.length} shared files from ${repo}@${ref}...`) | ||
|
|
||
| const results = await Promise.allSettled( | ||
| files.map(async (file) => { | ||
| validateFilePath(file.src) | ||
| const dest = file.dest ?? file.src | ||
| validateFilePath(dest) | ||
|
|
||
| const url = `${GITHUB_RAW}/${repo}/${ref}/${file.src}` | ||
| const destPath = safeDest(projectDir, dest) | ||
|
|
||
| const response = await fetch(url) | ||
| if (!response.ok) { | ||
| throw new Error(`${file.src}: ${response.status} ${response.statusText}`) | ||
| } | ||
|
|
||
| const content = await response.text() | ||
| await mkdir(dirname(destPath), { recursive: true }) | ||
| await writeFile(destPath, content, 'utf-8') | ||
Check warningCode scanning / CodeQL Network data written to file Medium
Write to file system depends on
Untrusted data Error loading related location Loading
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 1a500f7 |
||
| console.log(` + ${dest}`) | ||
| }), | ||
| ) | ||
|
|
||
| const failed = results.filter((r): r is PromiseRejectedResult => r.status === 'rejected') | ||
| if (failed.length > 0) { | ||
| console.warn(`\n${failed.length} file(s) failed to fetch:`) | ||
| for (const f of failed) { | ||
| console.warn(` - ${f.reason}`) | ||
| } | ||
| } | ||
|
|
||
| console.log(`\nDone. ${files.length - failed.length}/${files.length} shared files copied.`) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
File data in outbound network request Medium
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 1a500f7