Skip to content

fix(create-objectstack)!: refuse a current-dir scaffold that would overwrite existing files - #29267

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-fveq44
Nov 2, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-fveq44

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #29134

Clause-②: no (narrowing) — measured: on base 49aba82b a no-name and an "" run in a current directory holding README.md + package.json exited 0 and replaced both files; on head 791e47c3 the same runs exit 1, name both files, and leave the directory byte-identical. Nothing is widened.
Metadata-protocol: none

维护者速读

  • 改了什么:在当前目录运行 create-objectstack(不带名字或名字为空)时,若模板文件会覆盖目录里已有的文件,脚手架直接拒绝(退出码 1),列出这些文件,什么都不写。
  • 为什么改:以前当前目录完全不检查,用户已有的 README.md 和 package.json 会被静默覆盖且退出码为 0;而指定名字的非空目录早就会被拒绝。
  • 风险与回滚:只多拒绝一种情形;只含模板不写的文件(如 .git/、笔记文件)的目录照常生成。回滚即撤销本 PR。
  • 先看:packages/create-objectstack/src/index.ts 的碰撞拒绝块;src/template-copy.ts 的 findTemplateCollisions;新测试 src/scaffold-current-dir-collision.test.ts。
  • 两分钟验证:在含 README.md 的空项目目录里跑 npx tsx packages/create-objectstack/src/index.ts --skip-install --skip-skills,应看到退出码 1、列出 README.md,文件内容不变。
  • 需要你做的:无,席位落地。

What changes

  • packages/create-objectstack/src/template-copy.ts: new read-only findTemplateCollisions(src, dest) walks the template the way copyDir does (same alias restoration, so _gitignore is checked as .gitignore) and returns every project-relative path that already exists where the template writes a file, or where a non-directory stands in place of a template directory. copyDir itself is unchanged apart from sharing the alias helper.
  • packages/create-objectstack/src/index.ts: before the first write (before mkdirSync and the copy), a non-empty target is checked; any collision prints Directory is not empty and the template would overwrite N existing files: DIR, lists each path, says nothing was written and names the two ways out (move the files aside, or scaffold into a new named directory), then exits 1. The named non-empty refusal (Directory already exists and is not empty) is untouched and still runs first; an empty target skips the walk.
  • Rule shape: the one the card prefers, scoped to collisions. A current directory holding only files the template does not write still scaffolds and keeps those files, which is what the existing comment and the "the directory already had contents" summary already intend.
  • .changeset/29134-current-dir-overwrite-refusal.md: create-objectstack patch, BREAKING banner, both declaration lines, ADR-0087 not-required (no-migration-prescription).

Tests

New src/scaffold-current-dir-collision.test.ts (8 cases, real CLI through tsx, the no-build pattern of scaffold-description.test.ts):

  • no name and "" in a directory with a colliding README.md / package.json plus a non-colliding notes.txt: exit 1, the whole tree byte-identical, both paths named, notes.txt not named;
  • a directory holding only .git/HEAD and notes.txt: scaffolds (exit 0, package.json name is the directory name), both files untouched;
  • an empty current directory: scaffolds as before (Created files:);
  • a named non-empty directory: the old refusal and message, nothing written;
  • findTemplateCollisions unit cases: the aliased .gitignore, a file standing where the template needs src/, a shared src/ with only user files (no collision).

No existing test needed editing.

Acceptance notes

  • No new CLI flag: a --force (overwrite on purpose) is a product choice and is left to the maintainer; see the report's open question.
  • Out of the template copy, two writers are not covered by this check and already do not overwrite: AGENTS.md and .github/copilot-instructions.md are written with exclusive create. The package-manager install and the skills installer write what they write, as before.

Verification

Premise on base 49aba82 (card's reproduction)

No-name run and "" run in a temp my-app/ holding README.md (# my notes) and package.json ({"name":"mine"}): both EXIT=0, README.md now starts # My App, package.json now "name": "my-app". Named non-empty dir: EXIT=1, Directory already exists and is not empty.

Head 791e47c, same reproduction

Both runs EXIT=1, files unchanged, output names README.md and package.json and says nothing was written.

Ablation of the refusal (negative pin)

scripts/ablation-replace.mjs on index.ts, anchor if (collisions.length > 0) { x1 -> x0, replacement x0 -> x1, blob c402bf41f8e7 -> ee6ac763dfa4. The test file goes red: × refuses with no name …, × refuses with an empty name …, AssertionError: expected +0 to be 1, Tests 2 failed | 6 passed (8). Restored: blob == HEAD c402bf41f8e7, git diff HEAD empty. The suite runs src/ through tsx and vitest with no dist/ in the path, so no rebuild leg applies.

Package suite, typecheck, lint, gates, dogfood at 791e47c
  • os-verify-lock.sh -c "pnpm --filter 'create-objectstack^...' build && pnpm --filter create-objectstack build && pnpm --filter create-objectstack test && pnpm --filter create-objectstack typecheck": VERDICT command-exit 0; Test Files 23 passed (23), Tests 356 passed (356); tsc --noEmit lists the new test file (count 1).
  • eslint over packages/create-objectstack with --no-inline-config (the pnpm lint command, package-scoped): exit 0.
  • dispatch-gates.mjs --commands: 57 derived families, all exit 0; --ran reconciliation: 57 derived, 57 run, 0 NOT-MEASURED (derived zero, every line carries its exit code). Three first exited 3 on prerequisites and were re-run green: check:type-check-debt and check:dual-build-cjs-loads after the dogfood closure build, check-plugin-teardown-shape --self-test after fetching its pinned fixture commit.
  • Full dogfood (owed by the narrowing arm): VERDICT command-exit 0, Test Files 388 passed | 3 skipped (391), Tests 3208 passed | 28 skipped (3236).

Generated by Claude Code

…rwrite existing files

A run with no name (or an empty one) copied the template over the current
directory, replacing an existing README.md and package.json with exit 0.
The collisions are now found before the first write: any template file
that would replace an existing one refuses the run with exit 1, naming the
paths, and nothing is written. Files the template does not write may stay.

Claude-Session: https://claude.ai/code/session_01ADHkmQNsRpYUsG5efyi5Ur
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 60 of 216 client-bound route-ledger rows — the other 156 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 156: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 101 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 13 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 0b058828e0b0b5ea417f9e9baf8a5d3317578835 — the merge of head 791e47c3443134c115160aa63e50264152cd19de into base 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 0b058828e0b0b5ea417f9e9baf8a5d3317578835 && git checkout 0b058828e0b0b5ea417f9e9baf8a5d3317578835
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae 791e47c3443134c115160aa63e50264152cd19de && git checkout -B drift-repro 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae && git merge --no-ff 791e47c3443134c115160aa63e50264152cd19de

node scripts/docs-audit/affected-docs.mjs --json 74a19dd857d5b7bddd8409bd04332cc10c6ad5ae

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY

Contract-review-claim: session_01ADHkmQjPiXgNoSaEpqeGvY · head 791e47c3443134c115160aa63e50264152cd19de · 2026-11-02T10:45Z

The lane seat runs this PR's review at CONTRACT_REVIEW_TIER (declared Clause-②: no (narrowing)), in an isolated reviewer.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 791e47c3443134c115160aa63e50264152cd19de
Local-runs: none
Scope: packages/create-objectstack/src/index.ts, packages/create-objectstack/src/template-copy.ts, packages/create-objectstack/src/scaffold-current-dir-collision.test.ts + packages/create-objectstack/src/templates/blank/ (the template tree the walk reads, incl. _gitignore, .github/workflows/ci.yml, src/), packages/create-objectstack/src/index.ts topLevelNames / writeIfAbsent / rewriteProjectIdentity (the other writers of the run), packages/create-objectstack/src/rewrite-identity.ts, packages/create-objectstack/src/runtime-image.ts, packages/create-objectstack/src/scaffold-description.test.ts (the tsx pattern the new test copies), packages/create-objectstack/package.json (exports), .changeset/29134-current-dir-overwrite-refusal.md (read for ②), scripts/check-adr-0087-registration.mjs (CATEGORIES). Remainder of the diff at TIER_DEFAULT: none — the narrowing face's floor covers every non-prose path; the changeset is judged in ② only.

Inputs read: card #29134 body + all 3 comments (triage 6572501857, claim 6574098591, dev report 6575170911); PR #29267 body, file list (4 files, +249/−6), net diff origin/main...791e47c3; check-runs on 791e47c3 (final tally below). Reviewed 2026-11-02T10:58Z.

① Derived judgments

  • CLI behaviour (public surface of create-objectstack) — a no-name / "" run in a current directory where a template file already exists now exits 1 and writes nothing; on main it exited 0 and replaced the files. Narrowing, declared Clause-②: no (narrowing) on PR body and changeset. Right. Read in the tree: the check sits inside the try, after the unchanged named-dir refusal and the targetWasEmpty snapshot, before fs.mkdirSync and loadBundled — nothing is written before process.exit(1).
  • Scoped-to-collisions rule, not blanket non-empty refusal — a current dir holding only .git/, notes.txt, or a user-populated src/ without template-named files still scaffolds. Right: it matches the card's "Expected" (refuse to overwrite existing files, naming them) and the claim's expected shape; the targetWasEmpty short-circuit keeps the empty-dir path byte-identical to main.
  • No new accept-set: findTemplateCollisions is a new export of src/template-copy.ts, which package.json#exports does not expose (only ./created-summary); the bin is the sole public entry. Right — no published API surface added, no check:api-surface owed.
  • copyDir refactor (outputName shared) — behaviour-neutral: same isFile()-gated alias lookup. Right. The two walks share the alias rule, so _gitignore is checked and written as .gitignore (unit test pins it).
  • Other writers of the run are covered or exclusive-create — every writeFileSync/copyFileSync outside the copy writes a template file (rewriteProjectIdentity → package.json / manifest / config / README; rewrite-identity.ts; runtime-image.ts → Dockerfile) or goes through writeIfAbsent (flag: 'wx': AGENTS.md, .github/copilot-instructions.md). The PR body's acceptance note is accurate against the tree. <pm> install and the skills installer write their own trees, as before — out of the card's reach.
  • Claim boundary — no packages/spec/**, no new CLI flag, no new gate: holds on the file list.
  • Prose — packages/create-objectstack/README.md ("Scaffold in the current directory") and content/docs stay true: the current-dir path still scaffolds unless it would overwrite. Docs Drift check listed nothing. No drift.

② Semver level

  • Changeset .changeset/29134-current-dir-overwrite-refusal.md: 'create-objectstack': patch, BREAKING banner, Clause-②: no (narrowing) and Metadata-protocol: none line-initial in both the PR body and the changeset body. Correct level: Metadata-protocol: none ⇒ patch; a non-protocol narrowing ships patch and keeps its BREAKING banner and ADR-0087 disposition (AGENTS.md Post-Task Checklist step 3). Not skip-changeset — the package publishes.
  • ADR-0087 marker: <!-- adr-0087: not-required (no-migration-prescription) … --> — no-migration-prescription is in CATEGORIES of scripts/check-adr-0087-registration.mjs; nothing an author writes is removed or renamed (no schema key, no export, no config field), so no tombstone and no FROM → TO mapping is owed. The remedy line is present. Check Changeset on the head: success.
  • Clause-②: line — no (narrowing): right. On the measured case exit 0 → exit 1 with nothing written; nothing widened; the (narrowing) arm is the one that makes this review owed at CONTRACT_REVIEW_TIER.

③ Boundary flags

  • open_question 1 — --force opt-in to overwrite? Answered: A (no flag). The claim's file surface forbids a new CLI flag; the remedy is a mv or a named directory, both printed by the refusal. Option B is a product choice and stays a maintainer question, not a blocker on this card.
  • open_question 2 — new sentence Directory is not empty and the template would overwrite N existing files: DIR, no error code in this CLI? Answered: A (land as worded). It keeps the existing "Directory … not empty" lead, adds the count, lists each path, and says nothing was written; the test pins the count and both path lines.
  • deviation: harness attribution block on PR lines 1–2, Fixes #29134 on line 3 — accepted (os-dev harness exception).
  • deviation: no MCP assignee/reviewer write — accepted; the standard order forbids MCP writes.
  • deviation: dogfood ran in the background while gates ran unlocked; three gates first exited 3 on prerequisites and re-ran green — accepted; the head's check-runs are the gate verdicts here, and they are green.
  • Nothing escalated.

④ Design judgment

packages/create-objectstack/src/template-copy.ts — findTemplateCollisions. Judged against copyDir (the writer it must predict) and the blank template tree on the head. The walk is readdirSync(src, withFileTypes) → outputName → lstatSync(dest/outName), recursing only where both sides are directories; a file where the template needs a directory is a collision; a template file over any existing entry is a collision; absent entries are skipped. Tried to break it: (a) _gitignore vs a user .gitignore — caught via the shared alias (unit test). (b) User .github/ holding other workflows — walked, no false positive unless workflows/ci.yml exists; the later writeIfAbsent for copilot-instructions keeps the user's copy. (c) A symlink standing where the template writes — lstatSync sees it, so it is a collision; copyFileSync would have written through it, so conservative is right. (d) A file named src — caught; without the check copyDir's mkdirSync('src') would have thrown ENOTDIR mid-copy, leaving a half-written tree, so the pre-check is strictly better than the previous failure mode. (e) Case-insensitive filesystems — a user readme.md is seen by lstatSync as colliding with README.md, which is exactly what the copy would have overwritten; the printed name is the template's, acceptable. No must-fix.

packages/create-objectstack/src/index.ts — the refusal block. Placement: after the unchanged !isCurrentDir refusal and the targetWasEmpty read, inside the try, before mkdirSync/loadBundled. A thrown readdirSync/bundledTemplateDir error is caught by the existing catch → printError → exit 1, same as the pre-change loadBundled throw. targetWasEmpty (topLevelNames returns an empty set for a missing dir) short-circuits the walk for the empty and not-yet-existing cases, so the named-dir and empty-current-dir paths run no new code. The named-dir non-empty refusal still fires first, so its message is unchanged (test pins it). bundledTemplateDir extracted from loadBundled without changing the "missing on disk" throw. No must-fix. One note, not a finding: the sentence says "overwrite N existing files" even when an entry is a file blocking a template directory — the count and list are still correct, and the alternative outcome on main was an ENOTDIR crash halfway, so the wording is at worst slightly generous.

packages/create-objectstack/src/scaffold-current-dir-collision.test.ts. Judged against the card's reproduction and the scenario it is accepted against. It spawns the real CLI through tsx (the scaffold-description.test.ts pattern, index.ts parses on import), with --template blank --skip-install --skip-skills. The two refusal cases (no name, "") assert exit 1, a whole-tree byte snapshot unchanged, the count line, both colliding paths as their own lines, the non-colliding notes.txt absent from the list, and no "Environment created!". The non-colliding case (.git/HEAD + notes.txt) asserts exit 0, the "already had contents" summary, package.json name from the directory, and both user files byte-identical. The empty-dir and named-non-empty cases pin the unchanged paths. Three unit cases pin the alias, the file-where-directory case, and the shared-src/ no-collision case. The dev's ablation (anchor if (collisions.length > 0) { removed → the two refusal cases red with expected +0 to be 1) is consistent with the test shape; I did not re-run it. Coverage gap worth naming, should-fix (non-blocking): no test asserts the --template lookup still precedes the collision walk for a template that is retired/unknown — but only blank exists in src/templates/, so the case is unreachable on this tree. No must-fix.

Narrowing against the published spec on main. It takes no declared capability away: scaffolding into the current directory remains available whenever it would not replace a user file; it makes the spec's own refusal ("Directory already exists and is not empty", previously named-dir only) real on the current-dir path, scoped to the files that would actually be lost. The card's "Expected" is met in its first form (refuse to overwrite existing files, naming the files it would replace).

Must-fix: none. Should-fix: none blocking (one coverage note above).

Check-runs on 791e47c3 (all complete at read time): 50 total — 36 success, 14 skipped (UI, docs, opt-in and schedule lanes with no paths hit), 0 failure/cancelled/neutral. Green among them: Test Core (8/8 shards + aggregate), TypeScript Type Check (workspace, source gates, debt ledger, consumer gates), Lint & Repo Gates (ESLint, repo & tooling, docs & code guards, CI/release/engine gates, PM dispatch-gates, scoped lanes), Check Changeset, Governed Surface Queue Guard, PR-body guards, Check PR Size, Dogfood Regression Gate, Scaffold with repo dist, Build Core. These conclusions are the gate verdicts; nothing was re-run locally.

Implemented-by: claude/project-thread-fveq44
Reviewed-by: session_01ADHkmQjPiXgNoSaEpqeGvY

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY

席位核对 · ACCEPT · domain:server seat 1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY · 2026-11-02T11:00Z

Head 791e47c344, report 6575170911 (on #29134), claim on #29134. Clause-②: no (narrowing) → contract review owed at CONTRACT_REVIEW_TIER: record 6575443702 on this head, PASS, no must-fix, no should-fix.

item reading
Shape Draft, base main, Fixes #29134. 4 files (+249 / −6): read-only findTemplateCollisions in template-copy.ts, the refusal before the first write in index.ts, new scaffold-current-dir-collision.test.ts (8 cases), a create-objectstack patch changeset with BREAKING banner and ADR-0087 not-required (no-migration-prescription). Metadata-protocol: none. No packages/spec/**, no new flag, no new gate. findTemplateCollisions is not in package.json#exports. Not governed.
Rule Scaffolding into the current directory with no name (or "") refuses with exit 1 before writing anything, naming each path that would be overwritten. Files that don't collide (.git/, notes) still scaffold untouched. The named non-empty-directory refusal is unchanged.
Evidence Base 49aba82b: both runs exited 0 and overwrote README.md / package.json. Head: package 356/356, typecheck 0, ablation red 2/8 then restored, gates 57/57, dogfood VERDICT 0. CI on this head: 50 check-runs, 36 green, 14 skipped, none red; check-expected-skips OK.
Open questions --force: no flag (the claim forbids a new CLI flag; a maintainer can ask for one later). Wording: as is. Both as the review answers.
Landing 「按照 pm-dispatch 规则复核过的都授权」 (Leehom, 2026-10-25T11:35Z): ready and auto-merge through the relay.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 11:01
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 2, 2026 11:01
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit ad224b7 Nov 2, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-fveq44 branch November 2, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant