From bbaeaedf6c087c325b696863778216b648ef1ddf Mon Sep 17 00:00:00 2001 From: Mike North Date: Sat, 6 Jun 2026 08:49:01 -0700 Subject: [PATCH 1/2] Seed a comprehensive .gitignore on init and stop refresh-managing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fresh `aipm init` previously wrote only a 4-line `.gitignore`, so a brand-new scaffold could easily commit secrets. The seeded `.gitignore` is now comprehensive — it ignores `.env*`, `*.log`, `coverage`, common caches, and `scratch/`, while retaining `node_modules/`, `*.tsbuildinfo`, `*.local.*`, and `.DS_Store`. Build output (`dist/`) is deliberately still tracked, per the build/freshness contract. `.gitignore` is also removed from the `aipm init --refresh` managed set and is now seed-only: `init` writes it, the user owns it thereafter. Because users legitimately extend `.gitignore`, keeping it managed caused every refresh to report it as a perpetual conflict (and `--force` would clobber the additions). The `.aipm/scaffold.json` sidecar now tracks only `.github/workflows/ci.yml`. Resolves #19. --- .changeset/gitignore-seed-only.md | 14 ++++ docs/specs/scaffold-refresh-and-upgrade.md | 39 ++++++----- packages/core/src/pipeline/init-template.ts | 70 +++++++++++++++---- packages/core/src/pipeline/init.test.ts | 26 ++++++- .../src/pipeline/scaffold-refresh.test.ts | 37 ++++++---- 5 files changed, 140 insertions(+), 46 deletions(-) create mode 100644 .changeset/gitignore-seed-only.md diff --git a/.changeset/gitignore-seed-only.md b/.changeset/gitignore-seed-only.md new file mode 100644 index 00000000..c7c01a71 --- /dev/null +++ b/.changeset/gitignore-seed-only.md @@ -0,0 +1,14 @@ +--- +'@ai-plugin-marketplace/core': minor +--- + +`aipm init` now seeds a comprehensive `.gitignore` and stops refresh-managing it. + +- **Safety fix:** a fresh `aipm init` previously wrote only a 4-line `.gitignore`, so a brand-new + scaffold could easily commit secrets. The seeded `.gitignore` now ignores `.env*`, `*.log`, + `coverage`, common caches, and `scratch/` (while retaining `node_modules/`, `*.tsbuildinfo`, + `*.local.*`, and `.DS_Store`). Build output (`dist/`) is deliberately still tracked. +- **No more perpetual refresh conflict:** `.gitignore` is now **seed-only** — written by `init` and + owned by the user thereafter. It has been removed from the `aipm init --refresh` managed set + (`.aipm/scaffold.json` now tracks only `.github/workflows/ci.yml`), so user additions to + `.gitignore` are never clobbered or perpetually flagged as conflicts. diff --git a/docs/specs/scaffold-refresh-and-upgrade.md b/docs/specs/scaffold-refresh-and-upgrade.md index c582569e..99c3679a 100644 --- a/docs/specs/scaffold-refresh-and-upgrade.md +++ b/docs/specs/scaffold-refresh-and-upgrade.md @@ -3,10 +3,11 @@ ## Motivation A marketplace/consumer repo (the `template`, or any repo created by `aipm init`) carries -**toolkit-owned scaffold files** — chiefly `.github/workflows/ci.yml` and `.gitignore` — whose -canonical content lives in the toolkit's `init-template.ts` render functions. Today there is no way -to refresh those files when the toolkit evolves: they must be hand-edited in lockstep, and they -drift. Two concrete symptoms: +**toolkit-owned scaffold files** — chiefly `.github/workflows/ci.yml` — whose canonical content +lives in the toolkit's `init-template.ts` render functions. Today there is no way to refresh those +files when the toolkit evolves: they must be hand-edited in lockstep, and they drift. (`.gitignore` +is also seeded by `init`, but it is **not** refresh-managed — see the file-ownership table — because +users legitimately extend it.) Two concrete symptoms: 1. **Drift.** The `template`'s `ci.yml` (node 24, branch filters, a freshness `git status` step) has diverged from what `aipm init` renders (node 20, no freshness step) — two representations of the @@ -37,16 +38,16 @@ This is distinct from `aipm migrate` (schema/breaking migrations), which stays s ## File ownership — what refresh manages -| File / area | Managed by refresh? | Why | -| --------------------------------------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `.github/workflows/ci.yml` | **Yes** | Pure tooling recipe; should track the toolkit. | -| `.gitignore` | **Yes** | Toolkit baseline (`node_modules/`, OS cruft, etc.). | -| `package.json` **dependencies** | **No** | Version bumps are `pnpm up`'s job + lockfile. (Future work: refresh could _report_ when pinned `cli`/`core` drift from the rendered pins; not implemented yet.) | -| `package.json` other fields | **No** | User owns `scripts`, added deps, etc. | -| `aipm.workspace.ts` | **No** | Repo identity (marketplace name/owner/description) — authored. | -| `README.md`, `CONTRIBUTING.md` | **No** | Authored prose. | -| `plugins/**` | **No** | User content. | -| Registries, `dist/`, root Gemini/Kiro emission, hook JSON | **No** | Owned by `aipm build`, freshness-checked separately. | +| File / area | Managed by refresh? | Why | +| --------------------------------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `.github/workflows/ci.yml` | **Yes** | Pure tooling recipe; should track the toolkit. | +| `.gitignore` | **No** | Seeded by `aipm init` (comprehensive baseline incl. `.env*`); user owns it thereafter — users extend it freely, so refresh must not clobber or perpetually flag it. | +| `package.json` **dependencies** | **No** | Version bumps are `pnpm up`'s job + lockfile. (Future work: refresh could _report_ when pinned `cli`/`core` drift from the rendered pins; not implemented yet.) | +| `package.json` other fields | **No** | User owns `scripts`, added deps, etc. | +| `aipm.workspace.ts` | **No** | Repo identity (marketplace name/owner/description) — authored. | +| `README.md`, `CONTRIBUTING.md` | **No** | Authored prose. | +| `plugins/**` | **No** | User content. | +| Registries, `dist/`, root Gemini/Kiro emission, hook JSON | **No** | Owned by `aipm build`, freshness-checked separately. | The managed set is intentionally small: the files that are _pure tooling recipe_ and break or rot when they lag the toolkit. @@ -98,8 +99,10 @@ versions: → `aipm build` → freshness `git status` gate → `aipm validate`; pnpm version from `package.json#packageManager`). - `package.json`: add `packageManager: "pnpm@"` (a named constant), correct version pins. -- `.gitignore`: canonical lean list (includes `*.local.*`, `.DS_Store`, `node_modules/`, - `*.tsbuildinfo`). +- `.gitignore`: comprehensive baseline — ignores `.env*` (so secrets can't be committed from a fresh + scaffold), `*.log`, `coverage`, common caches, `scratch/`, plus `node_modules/`, `*.tsbuildinfo`, + `*.local.*`, and `.DS_Store`. Deliberately does **not** ignore `dist/` (committed build output). + Seed-only — `init` writes it, the user owns it thereafter (it is not in the refresh-managed set). - Greenfield `init` keeps its existing registry/`README` behavior: it still seeds empty hand-authored registries (`{ "plugins": [] }`) and a simple starter `README.md`, and does **not** emit `aipm.workspace.ts`. This keeps a fresh repo `validate`-clean without coupling `init` to the @@ -124,8 +127,8 @@ to the rendered pins is possible future work; not implemented.)_ ## Backward compatibility - `aipm init ` is unchanged except for the corrected version pins, the added - `packageManager` field, and the canonical CI-workflow/`.gitignore` renders. It still seeds the - empty registries and starter `README.md` as before. + `packageManager` field, the canonical CI-workflow render, and the comprehensive (seed-only) + `.gitignore`. It still seeds the empty registries and starter `README.md` as before. - It additionally seeds the `.aipm/scaffold.json` refresh sidecar. - `--refresh` is purely additive. - The `.aipm/scaffold.json` sidecar is additive and ignored by older tooling. diff --git a/packages/core/src/pipeline/init-template.ts b/packages/core/src/pipeline/init-template.ts index dcb389f5..c89d387c 100644 --- a/packages/core/src/pipeline/init-template.ts +++ b/packages/core/src/pipeline/init-template.ts @@ -156,43 +156,83 @@ jobs: `; } -/** `.gitignore` for a consumer repo: dependencies, build intermediates, OS/local cruft. */ +/** + * `.gitignore` for a consumer repo. Comprehensive baseline covering dependencies, build + * intermediates, logs, test coverage, caches, environment/secret files, scratch artifacts, and + * OS/local cruft. Notably ignores `.env*` so a freshly scaffolded repo cannot accidentally commit + * secrets. + * + * Deliberately does **not** ignore `dist/`: toolkit build output (per-plugin `dist/` bundles and + * `hooks/*.json`) is committed for consumer install and the freshness check — see the build + * contract and `.gitattributes`. + * + * This is **seed-only**: `aipm init` writes it, but it is intentionally absent from + * {@link buildManagedScaffoldFiles} so `aipm init --refresh` never clobbers or perpetually flags + * the user's own additions (`.gitignore` is something users legitimately extend). + */ function renderGitignore(): string { - return `node_modules/ + return `# Dependencies +node_modules/ + +# Build intermediates +*.tsbuildinfo + +# Logs +*.log +logs/ + +# Test coverage +coverage/ +*.lcov + +# Caches +.cache/ +.eslintcache +.npm/ + +# Environment / secrets +.env +.env.* +!.env.example + +# Scratch & manual-test artifacts +scratch/ + +# OS / editor cruft .DS_Store + +# Local overrides *.local.* -*.tsbuildinfo `; } /** * Toolkit-owned **scaffold** files that `aipm init --refresh` keeps in sync with the installed - * tooling: the CI workflow and `.gitignore`. These are pure tooling recipes — their content is - * independent of the repo name and the pinned toolkit version, so refresh can re-render them with - * no inputs and compare byte-for-byte. (Files with repo identity or user content — `package.json`, - * `aipm.workspace.ts`, `README.md`, plugins, `aipm build` output — are deliberately NOT here.) + * tooling: the CI workflow. It is a pure tooling recipe — its content is independent of the repo + * name and the pinned toolkit version, so refresh can re-render it with no inputs and compare + * byte-for-byte. (Files with repo identity or user content — `package.json`, `aipm.workspace.ts`, + * `README.md`, plugins, `aipm build` output — are deliberately NOT here. `.gitignore` is seeded by + * `init` but NOT managed, since users extend it freely.) * * Output is deterministic and stably ordered. */ export function buildManagedScaffoldFiles(): InitFile[] { - return [ - { path: '.gitignore', content: renderGitignore() }, - { path: '.github/workflows/ci.yml', content: renderCiWorkflow() }, - ]; + return [{ path: '.github/workflows/ci.yml', content: renderCiWorkflow() }]; } /** * Build the complete, deterministic seed file set for a consumer repo named `name`, pinning the * `cli`/`core` dev dependencies to carets of `cliVersion`/`coreVersion` respectively. * - * The set mirrors §3.2: `package.json`, the {@link buildManagedScaffoldFiles managed scaffold - * files} (`.gitignore`, CI workflow), `README.md`, both repo-root marketplace registries, and an - * empty `plugins/` (seeded with `.gitkeep` so the directory is tracked). Output is a pure function - * of the inputs — stable ordering, no timestamps. + * The set mirrors §3.2: `package.json`, the seed-only `.gitignore`, the + * {@link buildManagedScaffoldFiles managed scaffold files} (CI workflow), `README.md`, both + * repo-root marketplace registries, and an empty `plugins/` (seeded with `.gitkeep` so the + * directory is tracked). Output is a pure function of the inputs — stable ordering, no timestamps. */ export function buildInitFiles(name: string, cliVersion: string, coreVersion: string): InitFile[] { return [ { path: 'package.json', content: renderPackageJson(name, cliVersion, coreVersion) }, + { path: '.gitignore', content: renderGitignore() }, { path: 'README.md', content: renderReadme(name) }, { path: '.claude-plugin/marketplace.json', content: renderEmptyMarketplace() }, { path: '.cursor-plugin/marketplace.json', content: renderEmptyMarketplace() }, diff --git a/packages/core/src/pipeline/init.test.ts b/packages/core/src/pipeline/init.test.ts index c44e3326..1587025e 100644 --- a/packages/core/src/pipeline/init.test.ts +++ b/packages/core/src/pipeline/init.test.ts @@ -144,12 +144,36 @@ describe('runInit', () => { }; expect(sidecar.version).toBe(1); const paths = (sidecar.files ?? []).map((f) => f.path).sort(); - expect(paths).toEqual(['.github/workflows/ci.yml', '.gitignore']); + // `.gitignore` is seed-only (not refresh-managed), so the sidecar tracks only `ci.yml` (#19). + expect(paths).toEqual(['.github/workflows/ci.yml']); for (const f of sidecar.files ?? []) { expect(f.hash, `${f.path} hash`).toMatch(/^sha256-[0-9a-f]{64}$/); } }); + it('seeds a comprehensive .gitignore that protects secrets and common cruft (#19)', async () => { + // Safety acceptance: a fresh scaffold must ignore `.env*` so secrets can't be committed, plus + // logs/coverage/scratch — while retaining the originally-required `*.local.*` and `.DS_Store`. + const repoDir = path.join(tmpDir, 'gitignore-seed'); + await runInit(repoDir); + const gitignore = read(repoDir, '.gitignore'); + for (const pattern of [ + '.env', + '.env.*', + '*.log', + 'coverage/', + 'scratch/', + 'node_modules/', + '*.tsbuildinfo', + '*.local.*', + '.DS_Store', + ]) { + expect(gitignore.split('\n')).toContain(pattern); + } + // Build output is deliberately committed — refresh/freshness depends on it — so never ignore it. + expect(gitignore.split('\n')).not.toContain('dist/'); + }); + it('emits a private, ESM package.json with the aipm scripts (§3.2)', async () => { const repoDir = path.join(tmpDir, 'pkg-shape'); await runInit(repoDir); diff --git a/packages/core/src/pipeline/scaffold-refresh.test.ts b/packages/core/src/pipeline/scaffold-refresh.test.ts index 57bc35d2..e1397bde 100644 --- a/packages/core/src/pipeline/scaffold-refresh.test.ts +++ b/packages/core/src/pipeline/scaffold-refresh.test.ts @@ -130,10 +130,23 @@ describe('runRefreshScaffold', () => { it('reports all managed files unchanged immediately after init', () => { const outcomes = runRefreshScaffold(repoDir); - expect(outcomes.map((o) => o.path).sort()).toEqual([CI_REL, GITIGNORE_REL]); + // `.gitignore` is seed-only; the only refresh-managed file is `ci.yml` (#19). + expect(outcomes.map((o) => o.path).sort()).toEqual([CI_REL]); expect(outcomes.every((o) => o.status === 'unchanged')).toBe(true); }); + it('never refresh-manages .gitignore: it stays out of outcomes and user edits survive (#19)', () => { + // `.gitignore` is seeded by init but owned by the user thereafter. Refresh must never report it + // (no perpetual conflict) nor touch it (no clobbering user additions), with or without --force. + const edited = `${read(GITIGNORE_REL)}my-custom-dir/\n`; + write(GITIGNORE_REL, edited); + for (const opts of [undefined, { force: true }]) { + const outcomes = runRefreshScaffold(repoDir, opts); + expect(outcomes.some((o) => o.path === GITIGNORE_REL)).toBe(false); + expect(read(GITIGNORE_REL)).toBe(edited); + } + }); + it('reports a conflict and leaves a user-edited file untouched (no --force)', () => { write(CI_REL, 'name: Custom\n'); const outcomes = runRefreshScaffold(repoDir); @@ -150,27 +163,27 @@ describe('runRefreshScaffold', () => { }); it('recreates a deleted managed file', () => { - fs.rmSync(path.join(repoDir, GITIGNORE_REL)); + fs.rmSync(path.join(repoDir, CI_REL)); const outcomes = runRefreshScaffold(repoDir); - expect(statusFor(GITIGNORE_REL, outcomes)).toBe('recreated'); - expect(exists(GITIGNORE_REL)).toBe(true); + expect(statusFor(CI_REL, outcomes)).toBe('recreated'); + expect(exists(CI_REL)).toBe(true); }); it('updates a pristine file that lags the render', () => { // Simulate an older toolkit render: stale on-disk content whose hash the sidecar still records. - const stale = 'stale-ignore\n'; - write(GITIGNORE_REL, stale); + const stale = 'name: Stale CI\n'; + write(CI_REL, stale); write( SIDECAR_REL, `${JSON.stringify( - { version: 1, files: [{ path: GITIGNORE_REL, hash: hashScaffoldContent(stale) }] }, + { version: 1, files: [{ path: CI_REL, hash: hashScaffoldContent(stale) }] }, null, 2, )}\n`, ); const outcomes = runRefreshScaffold(repoDir); - expect(statusFor(GITIGNORE_REL, outcomes)).toBe('updated'); - expect(read(GITIGNORE_REL)).not.toBe(stale); + expect(statusFor(CI_REL, outcomes)).toBe('updated'); + expect(read(CI_REL)).not.toBe(stale); }); it('bootstraps a sidecar-less repo: adopts in-sync files and re-seeds the sidecar', () => { @@ -182,10 +195,10 @@ describe('runRefreshScaffold', () => { it('bootstraps a sidecar-less repo: flags diverged files as conflicts', () => { fs.rmSync(path.join(repoDir, SIDECAR_REL)); - write(GITIGNORE_REL, 'hand-rolled\n'); + write(CI_REL, 'name: Hand-rolled\n'); const outcomes = runRefreshScaffold(repoDir); - expect(statusFor(GITIGNORE_REL, outcomes)).toBe('conflict'); - expect(read(GITIGNORE_REL)).toBe('hand-rolled\n'); + expect(statusFor(CI_REL, outcomes)).toBe('conflict'); + expect(read(CI_REL)).toBe('name: Hand-rolled\n'); }); it('converges: after --force, a subsequent refresh reports unchanged', () => { From 6a15cc5bb410c7f0ed044cea52183e1863c69441 Mon Sep 17 00:00:00 2001 From: Mike North Date: Sat, 6 Jun 2026 08:58:44 -0700 Subject: [PATCH 2/2] Reference architecture spec for committed dist/, not .gitattributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address PR review: the `.gitignore` doc comment cited `.gitattributes` as the source of the committed-`dist/` contract, but `.gitattributes` only marks docs/api-report as linguist-generated and `aipm init` seeds no `.gitattributes` into consumer repos. Point at the actual spec instead — architecture.md §P5 (committed generated outputs) and §10.5 (freshness check). --- packages/core/src/pipeline/init-template.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/pipeline/init-template.ts b/packages/core/src/pipeline/init-template.ts index c89d387c..dfa732b4 100644 --- a/packages/core/src/pipeline/init-template.ts +++ b/packages/core/src/pipeline/init-template.ts @@ -163,8 +163,8 @@ jobs: * secrets. * * Deliberately does **not** ignore `dist/`: toolkit build output (per-plugin `dist/` bundles and - * `hooks/*.json`) is committed for consumer install and the freshness check — see the build - * contract and `.gitattributes`. + * generated hook JSON) is committed and freshness-checked — see `docs/specs/architecture.md` §P5 + * ("Both authored sources and generated outputs are committed") and §10.5 (Freshness check). * * This is **seed-only**: `aipm init` writes it, but it is intentionally absent from * {@link buildManagedScaffoldFiles} so `aipm init --refresh` never clobbers or perpetually flags