code-foundry 0.1.4

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.
Files changed (50) hide show
  1. package/.editorconfig +18 -0
  2. package/.env.example +3 -0
  3. package/.gitattributes +9 -0
  4. package/.githooks/pre-commit +67 -0
  5. package/.github/CODEOWNERS +4 -0
  6. package/.github/CODE_OF_CONDUCT.md +41 -0
  7. package/.github/CONTRIBUTING.md +198 -0
  8. package/.github/ISSUE_TEMPLATE/bug_report.yml +56 -0
  9. package/.github/ISSUE_TEMPLATE/config.yml +5 -0
  10. package/.github/ISSUE_TEMPLATE/feature_request.yml +38 -0
  11. package/.github/PULL_REQUEST_TEMPLATE.md +29 -0
  12. package/.github/SECURITY.md +23 -0
  13. package/.github/actions/cache/action.yml +43 -0
  14. package/.github/actions/codeql/action.yml +29 -0
  15. package/.github/actions/setup/action.yml +776 -0
  16. package/.github/dependabot.yml +42 -0
  17. package/.github/scripts/bootstrap.sh +20 -0
  18. package/.github/scripts/changed-files.sh +96 -0
  19. package/.github/scripts/ci.sh +636 -0
  20. package/.github/scripts/codeql-languages.sh +86 -0
  21. package/.github/scripts/doctor.sh +103 -0
  22. package/.github/scripts/format-fast-path.sh +80 -0
  23. package/.github/scripts/init-repo.sh +134 -0
  24. package/.github/scripts/security.sh +209 -0
  25. package/.github/scripts/sitecustomize.py +17 -0
  26. package/.github/scripts/sync-codeowners.sh +76 -0
  27. package/.github/scripts/sync-protection.sh +137 -0
  28. package/.github/scripts/sync-template.sh +432 -0
  29. package/.github/scripts/turbo-cache-probe.sh +102 -0
  30. package/.github/template.yml +7 -0
  31. package/.github/template.yml.example +8 -0
  32. package/.github/workflows/ci.yml +166 -0
  33. package/.github/workflows/codeql.yml +160 -0
  34. package/.github/workflows/draft-pr.yml +59 -0
  35. package/.github/workflows/release-pr.yml +66 -0
  36. package/.github/workflows/release.yml +103 -0
  37. package/.github/workflows/security.yml +228 -0
  38. package/.github/workflows/test.yml +175 -0
  39. package/.gitignore +77 -0
  40. package/.mise.toml +6 -0
  41. package/.prettierrc +6 -0
  42. package/AGENTS.md +155 -0
  43. package/CHANGELOG.md +3 -0
  44. package/LICENSE +616 -0
  45. package/NOTICE +7 -0
  46. package/README.md +172 -0
  47. package/package.json +44 -0
  48. package/release-please-config.json +16 -0
  49. package/ruff.toml +6 -0
  50. package/src/cli.mjs +137 -0
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # Code Foundry
2
+
3
+ [![npm version](https://img.shields.io/npm/v/code-foundry?logo=npm&logoColor=white)](https://www.npmjs.com/package/code-foundry)
4
+ [![npm downloads](https://img.shields.io/npm/dm/code-foundry?logo=npm&logoColor=white)](https://www.npmjs.com/package/code-foundry)
5
+ [![CI](../../actions/workflows/ci.yml/badge.svg?branch=main)](../../actions/workflows/ci.yml)
6
+ [![Latest GitHub release](https://img.shields.io/badge/GitHub%20release-latest-181717?logo=github)](../../releases/latest)
7
+
8
+ `code-foundry` is a repository factory for TypeScript, Rust, Python, Solidity,
9
+ and mixed-language projects. It installs agent-ready instructions, fast native
10
+ testing, security automation, release workflows, hooks, and repository policy
11
+ from one versioned package.
12
+
13
+ ## Quick start
14
+
15
+ ```bash
16
+ npx code-foundry init
17
+ ```
18
+
19
+ Or select the project profile explicitly:
20
+
21
+ ```bash
22
+ npx code-foundry init \
23
+ --languages typescript,python \
24
+ --features all \
25
+ --package-manager bun
26
+ ```
27
+
28
+ Use `code-foundry sync` to update an existing repository and
29
+ `code-foundry doctor` to validate it. Add `--dry-run` to preview changes.
30
+
31
+ ## Setup
32
+
33
+ 1. Install [mise](https://mise.jdx.dev/).
34
+ 2. Run `bash .github/scripts/bootstrap.sh` to install the pinned toolchain, enable hooks, and validate the repository.
35
+ 3. Add the repository's standard scripts (`format:check`, `lint`, `type-check`, `build`, `test:unit`, `test:integration`, `test:e2e`, and `test:smoke`) when available. The shared scripts also recognize legacy aliases and skip checks that do not apply to the repository's languages or package manager.
36
+
37
+ ## Applying the baseline to an existing repository
38
+
39
+ Run the sync script from the repository root. It updates shared workflows, GitHub forms, hooks, policy files, and tool configuration while preserving the repository's README, `.mise.toml` selections, extra workflows, and application code.
40
+
41
+ ```bash
42
+ bash .github/scripts/init-repo.sh
43
+ ```
44
+
45
+ Use `bash .github/scripts/sync-template.sh --source ... --check` to preview differences. For local template development, pass the template checkout as `--source` and `--ref staging`.
46
+
47
+ The initializer is intentionally flag-driven so the same baseline can be used as a small repository package. Language selection controls CodeQL and records the repository profile; feature selection controls which standard workflows are installed. `auto` detects supported languages, while `all` enables every standard workflow.
48
+
49
+ ```bash
50
+ # Preview a TypeScript + Python repository without changing files
51
+ bash .github/scripts/init-repo.sh \
52
+ --languages typescript,python \
53
+ --features all \
54
+ --dry-run
55
+
56
+ # Initialize a Rust repository with only the core automation
57
+ bash .github/scripts/init-repo.sh \
58
+ --languages rust \
59
+ --features ci,codeql,security,test
60
+ ```
61
+
62
+ Supported languages are `typescript`, `rust`, `python`, and `solidity`. Supported feature flags are `ci`, `codeql`, `security`, `test`, `draft-pr`, `release-pr`, `release`, and `dependabot`. Use `--prune` only when you explicitly want disabled standard workflows removed; custom workflows are always preserved. The selected profile is stored in `.github/template.yml`, which makes later syncs repeatable and lets workflows consume repository-specific settings without duplicating the template scripts.
63
+
64
+ ## Releases and publishing
65
+
66
+ The standard release workflow uses [Release Please](https://github.com/googleapis/release-please) after changes reach `main`. It opens or updates a versioned release pull request, maintains `CHANGELOG.md`, creates the GitHub release after that PR is merged, and applies semantic version bumps from Conventional Commits. The reusable `release-please-config.json` groups feature, fix, performance, dependency, documentation, test, CI, and maintenance changes in generated notes:
67
+
68
+ - `fix:` → patch, such as `1.2.3` → `1.2.4`
69
+ - `feat:` → minor, such as `1.2.3` → `1.3.0`
70
+ - `feat!:`, `fix!:`, or `BREAKING CHANGE:` → major, such as `1.2.3` → `2.0.0`
71
+
72
+ Before `1.0.0`, `feat:` intentionally increments the minor version. This keeps pre-1.0 releases useful without treating every feature as a breaking major.
73
+
74
+ Use `Release-As: 2.0.0` in a commit or pull request body when a specific version is required. Existing `CHANGELOG.md` files are preserved by sync and remain repository-owned.
75
+
76
+ Release behavior is configured in `.github/template.yml`:
77
+
78
+ ```yaml
79
+ release_type: auto # auto, node, python, rust, simple, or none
80
+ npm_publish: false # true only for a package published to npm
81
+ ```
82
+
83
+ `auto` selects the first matching package type (`package.json`, `pyproject.toml`, `Cargo.toml`, or `version.txt`). Use `none` when the repository should not release automatically. Solidity-only repositories use `simple` with a root `version.txt`. For a repository containing multiple independently released packages, add a Release Please manifest/configuration and select the appropriate Release Please strategy rather than treating the repository as one package.
84
+
85
+ GitHub Actions needs permission to open release pull requests. Configure a repository or organization secret named `RELEASE_PLEASE_TOKEN` containing a narrowly scoped token or GitHub App token if the default `GITHUB_TOKEN` is not allowed to create pull requests. Keep `contents`, `issues`, and `pull-requests` permissions enabled for the release workflow.
86
+
87
+ For npm publication, set `npm_publish: true` and configure npm trusted publishing (recommended) for this repository’s `release.yml` workflow, or provide an `NPM_TOKEN` secret. The workflow detects which method is configured, and publication occurs only after Release Please creates a release tag, so ordinary pushes cannot publish packages. Keep `publishConfig.access` in `package.json` aligned with the package’s intended visibility; the baseline publishes public packages. If npm publication is enabled without either configuration, the publish job fails instead of silently skipping the release.
88
+
89
+ The release flow is: promote `staging` into `main`; let Release Please open or update the version/changelog PR; merge that PR to create the GitHub release and tag; then publish to npm only when `npm_publish: true`.
90
+
91
+ For a repository that does not yet contain the scripts, the initializer can be invoked directly from the published package or a downloaded copy of `init-repo.sh`; it fetches the matching sync helper automatically. The generated `.github/template.yml` is the stable configuration contract used by the package and later syncs.
92
+
93
+ CI formatting and linting use the preloaded `ubuntu-latest` runner by default because dependency setup is usually faster there. Set `REPO_FOUNDRY_FAST_RUNNER=ubuntu-slim` only after measuring a repository where the lean image is faster; use `ubuntu-latest` for dependency-heavy or native-toolchain projects.
94
+
95
+ Rust Build and Type-Check jobs keep compiler caches enabled. JavaScript-only Build and Type-Check jobs skip framework cache archives by default because hosted-runner compression can exceed the build time; opt in with `REPO_FOUNDRY_CACHE_BUILD=true` when a repository’s measurements show a repeatable warm-cache win.
96
+
97
+ Branch protection is an administrator operation and is opt-in:
98
+
99
+ ```bash
100
+ bash .github/scripts/init-repo.sh --protection
101
+ ```
102
+
103
+ The protection helper preserves unrelated provider checks, replaces stale template check names, and skips CodeQL analysis checks for private repositories where the workflow is intentionally skipped.
104
+
105
+ The repository name, owner, branch names, and release metadata are resolved by GitHub Actions at runtime through `${{ github.* }}` values. Keep organization-specific details out of this baseline.
106
+
107
+ `CODEOWNERS` is repository-aware. Initialization queries the target GitHub repository and writes its personal owner or repository administrators into the default rule. For organization repositories, administrator discovery requires an authenticated `gh` session with collaborator visibility; if discovery is unavailable, the file retains an `@OWNER` placeholder that should be replaced before merging protected changes.
108
+
109
+ CI and hooks use Prettier and ESLint for JavaScript/TypeScript, default `rustfmt` and Clippy with warnings-as-errors for Rust, and Ruff formatting/linting for Python.
110
+
111
+ The initializer generates a minimal `.mise.toml` from the selected language and package-manager profile instead of installing every supported tool on every runner. TypeScript/Solidity profiles always pin Node and add Bun only for Bun projects; npm, pnpm, and Yarn use Node/Corepack. CI and Security also honor an explicit `package_manager` profile before inspecting lockfiles. Existing `.mise.toml` files are preserved. Initialization also generates a committed `mise.lock` when mise is available; CI then installs exact tool URLs and checksums without repeating registry/API resolution. Workflow setup restores lockfile-keyed package caches for Bun/npm/pnpm/Yarn, Cargo, and pip; cache misses remain safe because dependencies are always re-created from their lockfiles or manifests. Set `REPO_FOUNDRY_CACHE_PACKAGES=true` when a large Bun project has a measured warm-cache win; the default `auto` policy skips oversized archives.
112
+
113
+ Rust profiles declare `rustfmt` and `clippy` as mise components, so they are installed once with the cached toolchain instead of being added separately by each formatting or lint job. Rust Build jobs cache only reusable debug dependency/build-script artifacts plus Cargo fingerprints; Test jobs disable build and materialized-environment caches to avoid restoring and saving large incremental trees or Python virtual environments in parallel. Cargo’s advisory database and audit tools remain separate caches whose keys follow the security script, so dependency updates do not redownload the scanner. Cargo fingerprints invalidate stale objects safely, while keeping build caches separate prevents a large Rust build from displacing dependency-download caches or parallel jobs from racing to save one partial cache.
114
+
115
+ The shared cache action separates restore-only jobs from jobs allowed to save a cache after completion. Standard parallel CI and Test jobs pass `cache-save: false`, so they can reuse warm data without paying for redundant post-job archive uploads; the Unit and Security paths retain saving where it improves later runs. Repository-specific workflows can use the same local action when they need the same restore-only behavior.
116
+
117
+ When an exact `Cargo.lock` dependency cache is restored, CI enables Cargo offline mode for compilation and tests, eliminating avoidable registry/index checks. Cache misses continue using normal online resolution. npm projects intentionally skip the installed-`node_modules` cache because `npm ci` removes that directory before installation; they still reuse the package-download cache.
118
+
119
+ Applicable jobs cache installed JavaScript dependencies only when a lockfile, workspace, or dependency entry exists; dependency-free package manifests skip both the cache lookup and install. Installed JavaScript dependencies use an `auto` policy: compact pnpm/Yarn layouts are reusable, while Bun recreates its potentially large `node_modules` tree from the cached package store. Package-store caching also defaults to `auto`: normal projects retain it, while Bun repositories with more than 512 KiB of tracked lockfiles skip the large archive when a clean registry install is typically faster. Set `cache-packages: true` or `false` to override that heuristic. Set `cache-installed: true` on the setup action when a specific Bun repository benefits from restoring its materialized tree, or `false` to force lockfile installation for any manager. Jobs also cache Corepack package-manager shims, generic fallback ESLint/Prettier state, and Python virtual environments by manifest/dependency configuration hash. Repository-owned format/lint scripts skip those fallback cache paths entirely, avoiding recursive cache scans and post-job archive work when the script does not create the cache. Formatter and linter configuration is isolated to lint-state caches, so changing formatting rules does not invalidate installed dependencies. Mutable installed environments use exact-key restores only, preventing a lockfile change from downloading stale `node_modules` or a stale virtual environment that must then be replaced. Corepack remains warm even when an installed-dependency cache is already a hit; npm and pnpm installs prefer restored package stores and npm skips redundant audit/funding work because Security runs the authoritative dependency audit separately. The generic ESLint and Prettier fallbacks enable content-based built-in caches so restored lint/format state survives fresh Git checkouts; repository-defined scripts remain authoritative. Cache misses always fall back to a clean install; cached environments must never contain credentials or generated secrets.
120
+
121
+ When a repository uses multiple supported ecosystems, JavaScript, Rust, and Python dependency installation runs concurrently inside each setup job. A failure in any installer still fails the job after all active installers finish, preserving complete diagnostics without making network waits additive. CI disables Turbo and Next.js telemetry so framework jobs do not spend time on nonessential telemetry startup or network work.
122
+
123
+ Installers also short-circuit cleanly: JavaScript projects without dependency entries do not run a package install, and Python source-only projects reuse the shared Ruff tool without creating a virtual environment. Workspace manifests and project dependency files still take the normal locked-install path.
124
+
125
+ E2E jobs cache Playwright, Cypress, and Puppeteer browser directories by dependency/configuration hash, avoiding repeated browser downloads while invalidating safely when the browser configuration or lockfiles change. Coverage artifacts are uploaded only when a test actually produces coverage output.
126
+
127
+ Repositories with Turborepo automatically cache local `.turbo/cache` results per workflow job and dependency/configuration hash when remote caching is unavailable. Fallback restores can reuse valid artifacts produced by another workflow job, while Turbo’s task hashes discard stale results. Vercel Remote Caching remains available through `TURBO_TOKEN` and `TURBO_TEAM`; when both are set, the default path passes Turbo’s `--cache=remote:rw` mode to repository scripts so local archive work is avoided. The lint, type-check, and build jobs first perform a conservative manifest-only remote-cache probe for Bun projects; when every executable task is already a hit, they install only the pinned toolchain and restore results without installing project dependencies. Any miss falls back automatically to the normal locked install. Set `cache-turbo: true` when a repository intentionally wants both local and remote caching.
128
+
129
+ New Python profiles include pinned `uv` as an accelerated, pip-compatible installer and pinned Ruff as the shared formatter/linter. Repositories with `pyproject.toml` and `uv.lock` use `uv sync --frozen` to materialize the exact environment without repeat resolution; requirements-file projects continue using the uv/pip-compatible fallback. Existing repositories without `uv` continue using pip automatically, while existing custom tool selections and dependency-file formats remain supported.
130
+
131
+ Python Security audits use an isolated cache for `uv tool run` environments containing `pip-audit` when uv is available, so application lockfile changes do not redownload the scanner. They retain the same pip fallback used by CI installation. Independent `requirements.txt` and `requirements-dev.txt` audits run concurrently and aggregate failures. JavaScript, Rust, and Python audit jobs run concurrently when their ecosystems are present. The Python matrix is profile-gated so repositories without applicable Python inputs avoid a no-op runner; JavaScript and Rust retain independent detection so active audits start without waiting for the profile job. Every active ecosystem still reports a failure if its audit fails.
132
+
133
+ CI and Test jobs perform a source-only applicability check before setup. Empty integration, E2E, smoke, or language-specific jobs remain visible as successful required checks but skip runner tool installation and dependency setup.
134
+
135
+ On pull requests and ordinary pushes, CI, Test, and Security also recognize governance-only changes (README, license, issue/PR templates, CODEOWNERS, Code of Conduct, CONTRIBUTING, and SECURITY) and leave the required jobs successful without installing tools or running unrelated checks. Any source, dependency, workflow, profile, or build configuration change runs the full applicable checks; an unavailable diff always falls back to running them.
136
+
137
+ Security dependency audits apply the same fail-open change detection per ecosystem: JavaScript, Rust, and Python audits skip setup for source-only pushes and pull requests that do not change that ecosystem's manifests, lockfiles, audit allowlist, or shared tool configuration. Scheduled scans, manual runs, and uncertain diffs always audit normally.
138
+
139
+ The shared setup action accepts `install-javascript`, `install-python`, and `install-rust` switches. They default to `true` for compatibility, while the standard CI jobs disable ecosystems that their task cannot use: formatting skips project Cargo/Python installs, and lint, type-check, and build skip Python dependency installation. Test jobs pass their task profile (`unit`, `integration`, `e2e`, or `smoke`) and disable unrelated ecosystem caches, dependency installs, and mise tools; mixed-language repositories therefore pay only for languages used by that suite. Mise tool installation defaults to `auto`, so each job installs only configured tools for languages actually detected in the repository. Repositories without `.mise.toml` skip mise entirely and use the runner/project environment; callers can use `mise-scope: all` when a task intentionally spans every configured ecosystem.
140
+
141
+ It also accepts `mise-scope` (`auto`, `all`, `javascript`, `python`, or `rust`). Security's parallel ecosystem matrix uses this to install only the active language toolchain and restore only its package caches; callers that omit it get automatic profile-based tool selection, while `all` remains available for tasks that intentionally span every configured ecosystem.
142
+
143
+ Lightweight orchestration jobs use GitHub's `ubuntu-slim` runner: Draft PR, Release PR, release detection, Release Please, npm publication, dependency review, CodeQL language detection, and dependency audits. Build, format, lint, type-check, integration/E2E/smoke tests, and active CodeQL analysis use full `ubuntu-latest` runners because toolchain initialization, native libraries, browsers, and source analysis may benefit from full runner resources. Unit tests default to `ubuntu-slim` for small projects, but dependency-heavy or native suites should set the repository variable `REPO_FOUNDRY_UNIT_RUNNER=ubuntu-latest`; measurements across the maintained monorepos showed materially faster installs and test execution on the full runner.
144
+
145
+ Release and Security metadata jobs also use blobless checkouts where a checkout is needed, reducing source transfer while preserving on-demand manifest access.
146
+
147
+ CodeQL keeps every configured language check visible but skips analyzers whose source, dependencies, or configuration were untouched by a push or pull request. Unchanged analyzer jobs use `ubuntu-slim` and skip both checkout and analysis while remaining visible to branch protection; changed analyzers use full `ubuntu-latest` runners. Its detection job uses a blobless, sparse checkout because it only needs Git paths, metadata, and repository manifests; analyzer jobs still use full checkouts. Scheduled and manually dispatched CodeQL runs remain full scans.
148
+
149
+ CodeQL uploads SARIF findings for GitHub code scanning but does not archive the intermediate database in the reusable baseline; this keeps coverage and alert processing while avoiding an unnecessary database transfer. The required workflow check gates on successful SARIF upload acknowledgment and does not wait for GitHub’s asynchronous post-upload processing, shortening the CI critical path while retaining the uploaded findings.
150
+
151
+ Coverage is enforced at 80% for Python and Bun test suites when those ecosystems expose coverage support. Rust projects must keep their native test suites green; repositories with `cargo-llvm-cov` should enforce the same 80% line target in their Cargo coverage configuration.
152
+
153
+ ## Test runner standard
154
+
155
+ For TypeScript and JavaScript tests, use Bun's native test runner by default. Do not add Vitest to projects based on this template. Preserve specialized native runners such as Matchstick for The Graph and Hardhat for smart contracts.
156
+
157
+ ## Optional Turborepo remote caching
158
+
159
+ Turborepo repositories can use Vercel Remote Caching without changing the workflows. Add these repository settings:
160
+
161
+ - Secret: `TURBO_TOKEN`
162
+ - Repository variable: `TURBO_TEAM`
163
+
164
+ CI and Test pass those values to every job. Non-Turborepo repositories and repositories without the settings simply use their normal local cache behavior. This does not require the repository to deploy to Vercel.
165
+
166
+ ## License
167
+
168
+ Unless a repository says otherwise, new material is licensed under the GNU Affero General Public License v3.0-or-later. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
169
+
170
+ ## GitHub security behavior
171
+
172
+ The CodeQL workflow uses GitHub's official CodeQL actions, detects Actions, TypeScript, Python, and Rust automatically, and runs each language in parallel. It runs automatically for public repositories and skips itself for private repositories unless GitHub Code Security is enabled. Dependency Review is isolated in the Security workflow and runs only for public pull requests. If GitHub's Code Scanning default setup is enabled, disable that generated `dynamic/github-code-scanning/codeql` workflow after installing this checked-in workflow; otherwise GitHub will run two CodeQL analyzers. The default setup can be disabled with `gh api --method PATCH repos/OWNER/REPO/code-scanning/default-setup -f state=not-configured` when Code Security is available.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "code-foundry",
3
+ "version": "0.1.4",
4
+ "description": "A fast, language-aware repository factory for agent-ready workflows, testing, security, and release automation.",
5
+ "type": "module",
6
+ "license": "AGPL-3.0-or-later",
7
+ "packageManager": "bun@1.3.14",
8
+ "bin": {
9
+ "code-foundry": "src/cli.mjs"
10
+ },
11
+ "files": [
12
+ "src",
13
+ ".github",
14
+ ".githooks",
15
+ ".editorconfig",
16
+ ".gitattributes",
17
+ ".gitignore",
18
+ "CHANGELOG.md",
19
+ "release-please-config.json",
20
+ ".mise.toml",
21
+ ".prettierrc",
22
+ ".env.example",
23
+ "AGENTS.md",
24
+ "LICENSE",
25
+ "NOTICE",
26
+ "README.md",
27
+ "ruff.toml"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20"
31
+ },
32
+ "scripts": {
33
+ "build": "node --check src/cli.mjs",
34
+ "format:check": "node --check src/cli.mjs",
35
+ "lint": "node --check src/cli.mjs",
36
+ "test": "node --check src/cli.mjs",
37
+ "type-check": "node --check src/cli.mjs",
38
+ "pack:check": "npm pack --dry-run",
39
+ "prepublishOnly": "npm test && npm run pack:check"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3
+ "bump-minor-pre-major": true,
4
+ "changelog-sections": [
5
+ { "type": "feat", "section": "Features" },
6
+ { "type": "fix", "section": "Bug Fixes" },
7
+ { "type": "perf", "section": "Performance" },
8
+ { "type": "revert", "section": "Reverts" },
9
+ { "type": "deps", "section": "Dependencies" },
10
+ { "type": "docs", "section": "Documentation" },
11
+ { "type": "test", "section": "Tests" },
12
+ { "type": "ci", "section": "CI" },
13
+ { "type": "refactor", "section": "Maintenance" },
14
+ { "type": "chore", "section": "Maintenance" }
15
+ ]
16
+ }
package/ruff.toml ADDED
@@ -0,0 +1,6 @@
1
+ target-version = "py311"
2
+ line-length = 100
3
+
4
+ [lint]
5
+ select = ["E", "F", "W", "I", "UP", "B", "SIM"]
6
+ ignore = ["E501"]
package/src/cli.mjs ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from 'node:fs'
4
+ import { resolve } from 'node:path'
5
+ import { spawnSync } from 'node:child_process'
6
+ import { fileURLToPath } from 'node:url'
7
+
8
+ const packageRoot = resolve(fileURLToPath(new URL('..', import.meta.url)))
9
+
10
+ const usage = `code-foundry — initialize and maintain agent-ready repositories
11
+
12
+ Usage:
13
+ code-foundry init [options]
14
+ code-foundry sync [options]
15
+ code-foundry doctor [--target PATH]
16
+
17
+ Init/sync options:
18
+ --target PATH Repository directory (default: current directory)
19
+ --source PATH_OR_URL Template source override
20
+ --ref REF Template branch or tag (default: main)
21
+ --languages LIST auto or typescript,rust,python,solidity
22
+ --features LIST all or ci,codeql,security,test,draft-pr,release-pr,release,dependabot
23
+ --package-manager NAME auto, bun, pnpm, yarn, or npm
24
+ --release-type NAME auto, node, python, rust, simple, or none
25
+ --npm-publish Enable npm publication in the release workflow
26
+ --dry-run Preview changes without writing files
27
+ --prune Remove disabled standard workflows
28
+ --protection Synchronize main branch protections (init only)
29
+ --no-bootstrap Skip mise/hooks/doctor bootstrap after init
30
+ -h, --help Show this help
31
+ `
32
+
33
+ function fail(message) {
34
+ console.error(`code-foundry: ${message}`)
35
+ process.exit(2)
36
+ }
37
+
38
+ function parseArgs(argv) {
39
+ const command = argv[0] && !argv[0].startsWith('-') ? argv.shift() : 'init'
40
+ const options = {
41
+ target: process.cwd(),
42
+ source: packageRoot,
43
+ ref: 'main',
44
+ languages: 'auto',
45
+ features: 'all',
46
+ packageManager: 'auto',
47
+ releaseType: 'auto',
48
+ npmPublish: false,
49
+ languagesSet: false,
50
+ featuresSet: false,
51
+ dryRun: false,
52
+ prune: false,
53
+ protection: false,
54
+ bootstrap: true,
55
+ }
56
+ const values = new Map([
57
+ ['--target', 'target'],
58
+ ['--source', 'source'],
59
+ ['--ref', 'ref'],
60
+ ['--languages', 'languages'],
61
+ ['--features', 'features'],
62
+ ['--package-manager', 'packageManager'],
63
+ ['--release-type', 'releaseType'],
64
+ ])
65
+
66
+ while (argv.length) {
67
+ const arg = argv.shift()
68
+ if (arg === '-h' || arg === '--help') {
69
+ console.log(usage)
70
+ process.exit(0)
71
+ }
72
+ if (values.has(arg)) {
73
+ const value = argv.shift()
74
+ if (!value || value.startsWith('-')) fail(`${arg} requires a value`)
75
+ options[values.get(arg)] = value
76
+ if (arg === '--languages') options.languagesSet = true
77
+ if (arg === '--features') options.featuresSet = true
78
+ continue
79
+ }
80
+ if (arg === '--dry-run') options.dryRun = true
81
+ else if (arg === '--prune') options.prune = true
82
+ else if (arg === '--protection') options.protection = true
83
+ else if (arg === '--no-bootstrap') options.bootstrap = false
84
+ else if (arg === '--npm-publish') options.npmPublish = true
85
+ else fail(`unknown option: ${arg}`)
86
+ }
87
+
88
+ return { command, options }
89
+ }
90
+
91
+ function run(script, args, target) {
92
+ const scriptPath = resolve(packageRoot, '.github/scripts', script)
93
+ if (!existsSync(scriptPath)) fail(`package is missing ${script}`)
94
+ const result = spawnSync('bash', [scriptPath, ...args], {
95
+ cwd: target,
96
+ stdio: 'inherit',
97
+ env: process.env,
98
+ })
99
+ if (result.error) fail(result.error.message)
100
+ if (result.status !== 0) process.exit(result.status ?? 1)
101
+ }
102
+
103
+ function main() {
104
+ const { command, options } = parseArgs(process.argv.slice(2))
105
+ const target = resolve(options.target)
106
+ const common = ['--source', options.source, '--ref', options.ref]
107
+ if (options.languagesSet) common.push('--languages', options.languages)
108
+ if (options.featuresSet) common.push('--features', options.features)
109
+ if (options.prune) common.push('--prune')
110
+ if (options.dryRun) common.push('--check')
111
+ else common.push('--apply')
112
+
113
+ if (command === 'init') {
114
+ const initArgs = [
115
+ '--source', options.source,
116
+ '--ref', options.ref,
117
+ '--languages', options.languages,
118
+ '--features', options.features,
119
+ '--package-manager', options.packageManager,
120
+ '--release-type', options.releaseType,
121
+ ]
122
+ if (options.protection) initArgs.push('--protection')
123
+ if (options.dryRun) initArgs.push('--dry-run')
124
+ if (options.prune) initArgs.push('--prune')
125
+ if (options.npmPublish) initArgs.push('--npm-publish')
126
+ if (!options.bootstrap) initArgs.push('--no-bootstrap')
127
+ run('init-repo.sh', initArgs, target)
128
+ } else if (command === 'sync') {
129
+ run('sync-template.sh', common, target)
130
+ } else if (command === 'doctor') {
131
+ run('doctor.sh', [], target)
132
+ } else {
133
+ fail(`unknown command: ${command}`)
134
+ }
135
+ }
136
+
137
+ main()