Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/gitignore-seed-only.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 21 additions & 18 deletions docs/specs/scaffold-refresh-and-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -98,8 +99,10 @@ versions:
→ `aipm build` → freshness `git status` gate → `aipm validate`; pnpm version from
`package.json#packageManager`).
- `package.json`: add `packageManager: "pnpm@<pinned>"` (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
Expand All @@ -124,8 +127,8 @@ to the rendered pins is possible future work; not implemented.)_
## Backward compatibility

- `aipm init <empty-dir>` 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.
Expand Down
70 changes: 55 additions & 15 deletions packages/core/src/pipeline/init-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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
* 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() },
Expand Down
26 changes: 25 additions & 1 deletion packages/core/src/pipeline/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 25 additions & 12 deletions packages/core/src/pipeline/scaffold-refresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
Loading