Skip to content

fix(cli): migrate meta --write reads export default X as an export, not a second use - #39449

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-39396-wip
Dec 4, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-39396-wip

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread
Fixes #39396

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:开发者用命令行升级项目元数据时,按官方生成器写法的对象文件,改动现在会自动写回,不再大批列成"需手改"。
  • 为什么做:升级验收中,标准生成器写出的项目十处改动有七处被误判为"多处共用"而留给人工,替升级用户省掉这部分手工活。
  • 出错会怎样:判错时改动会写进一个确实被别处共用的对象定义;真正的别处引用仍按原样拒写,本改动只在升级命令里,撤回即可恢复原行为。
  • 要你做什么:无。

What changes

os migrate meta --write refuses to edit a literal whose binding is read somewhere the walk did not go ([shared]). The generator's module shape, export const X = …; then export default X;, was refused: the reference count in authored-source-codemod.ts read the identifier in export default X; as a second use of X.

  • isReference: the identifier in export default X; is no longer a read when X is a module-level variable of that module. It is treated like the export { X } specifier, which was already skipped.
  • bindingOfExport: for the same statement, the module's default export now resolves to the binding X and not to a separate default binding. So a default import of the module (import person from './contact.object') counts as a use of X. Without this half, skipping the export line would hide a real second use that comes through the default import. The ablation below pins it.
  • Anything else stays as before and is counted: export default (X), export default someImport, a call or a literal.

Tests

New packages/cli/src/utils/authored-source-codemod-39396.test.ts, which runs the planner in-process over temp projects:

  1. Generator shape, barrel export { contact } from …: the edit is written. Red on main (expected [ 'shared' ] to deeply equal []), green after the fix.
  2. Generator shape, barrel export { default as contact } from …: the edit is written. This was already green; it pins that the bindingOfExport change did not break it.
  3. Another module default-imports the object module and reads it: still [shared].
  4. Another module imports contact by name and reads it: still [shared].
  5. The module reads contact again itself: still [shared].

Ablation: with the bindingOfExport half reverted (on disk, same run), case 3 goes red (expected [] to deeply equal [ 'shared' ]). Without the isReference half, case 1 stays red as on main.

Acceptance notes

  • The fix covers export default X; where X is a module-level const. If export default X; re-exports an imported binding, it is still counted as a use, as before. That keeps the refusal on the safe side, and the generator never writes that shape.
  • A barrel re-export (export { X } from …) is still not a use. Only modules that import and read X are counted, as before this change.

Verification

Read first:

  1. packages/cli/src/utils/authored-source-codemod.ts, the bindingOfExport hunk. This is the riskiest change: it moves default-import uses onto X.
  2. packages/cli/src/utils/authored-source-codemod.ts, the isReference and defaultExportedLocal hunk.
  3. packages/cli/src/utils/authored-source-codemod-39396.test.ts.

Two-minute check: pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 src/utils/authored-source-codemod-39396.test.ts should report 5 passed.

Local gate readings at 2f03593
  • New test file: 5 passed with the fix. On main code: 1 failed, 4 passed (case 1, expected [ 'shared' ] to deeply equal []).
  • Codemod-adjacent suites (migrate-meta-write, -composed, -protocol-range, -own-field-row-38924, -default-range, -default-range-window, -strict-factories, plus the new file): 8 files, 77 passed, 1 skipped.
  • pnpm --filter @objectstack/cli typecheck: exit 0.
  • dispatch-gates.mjs --commands: 68 derived. 63 exited 0 on the first run. check:i18n, check:i18n-coverage and check:i18n-walk-parity exited 3 (CLI not built) and exited 0 after building the CLI. 2 NOT MEASURED: check-plugin-teardown-shape.mjs --self-test (shallow clone, pinned fixture commit unreachable) and check:dual-build-cjs-loads (needs every package's dist). --ran reports 68 derived, 66 run, 2 NOT-MEASURED, 0 UNRUN.
  • Overlap: overlap-check.mjs is clean. git merge-tree --write-tree against claude/issue-39392-wip (2e00cd3), which edits the same file in the form-move path, merges cleanly.
  • NOT MEASURED: the full @objectstack/cli unit layer and test:repo. Both are left to CI, as declared.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6

… not a second use

The stock generator writes `export const X = …; export default X;`. The
codemod's reference count read the `export default X;` identifier as another
use of X and refused every edit in such a module as [shared]. That line
hands X out like `export { X }` does, so it is no longer counted; instead a
default import of the module now counts against X itself, so a module that
imports the default and reads it still makes the edit [shared].

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

4 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
  • the SDK route bridge reached 71 of 256 client-bound route-ledger rows — the other 185 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 185: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 125 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 — 41 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 c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c → packageMentionDocs.

Which tree this was computed on

This run read content/docs from c87eccfbaa72849908442c562810370b0ae2fa25 — the merge of head 2f035937cca1574477d8139328a9ecaa33aba24d into base c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c, 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 c87eccfbaa72849908442c562810370b0ae2fa25 && git checkout c87eccfbaa72849908442c562810370b0ae2fa25
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c 2f035937cca1574477d8139328a9ecaa33aba24d && git checkout -B drift-repro c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c && git merge --no-ff 2f035937cca1574477d8139328a9ecaa33aba24d

node scripts/docs-audit/affected-docs.mjs --json c9ea363d71087bd9d16e0a8ee6de0c5f76331e0c

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

@github-actions github-actions Bot added 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 Dec 4, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4czfEjskBjZM6jhKWFR

2026-12-04T00:46Z · L1-a verdict: ACCEPT at head 2f035937cc (zone em-upgrade, card #39396) — CI not yet green at read time

席位核对

Checklist verdict. Shape: open, draft, base main, Fixes #39396 first line, no keyword on another card; Fixes is right (the card's expected state: an export-default of the same binding is not a second use, and those edits are written). Clause-②: no · Metadata-protocol: none hold: the CLI's write planner changes, nothing an author can write. Three files: packages/cli/src/utils/authored-source-codemod.ts, its -39396 test, a @objectstack/cli: patch changeset whose sentences match the diff (the generator shape is written; a real second use by named import, default import or a local read is still [shared]). No contract-review face is touched (no packages/spec/src/**, no governed path, no narrowing), so no L2 is owed.

Code read.

  • isReference skips the identifier of export default X; only when defaultExportedLocal finds a top-level variable statement declaring X; an import, a call, a literal or (X) returns undefined and stays a read, as before.
  • bindingOfExport(mod, 'default') for that same statement now returns `${mod.path}#X`, the key format this function already uses for named exports (file#local), so a default import that reads the module is counted against X. The two halves move together: the skipped line's use is transferred to the module's importers, not dropped.
  • Only top-level statements are scanned, so an inner-scope X cannot be mistaken for the exported one.

The point the zone asked to judge. Accepted. Treating export default X; like export { X } is the existing rule for specifiers applied to the one export form it missed, and the bindingOfExport half keeps the refusal's safety: a real second use through import person from './contact.object' still yields [shared] (case 3). The report's ablation shows each half pinned: reverting the bindingOfExport half turns case 3 red; without the isReference half case 1 stays red as on main.

Evidence. New test 5/5 on the branch, 1 failed / 4 passed on main code; adjacent codemod suites 77 passed, 1 skipped; CLI typecheck exit 0. Shared file with in-flight claude/issue-39392-wip (#39392): git merge-tree against 2e00cd31 is clean per the report; whichever lands second re-runs on the merged base. Gates at this head: 2 success, 18 expected skip, 22 pending at read time (floor checks among them): landing needs every check green or expected skip on the head that lands.

Pointer for #39396: ACCEPT → PR #39449 (this comment). Not governed: the zone lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4cxRh6Sbfo2Xm49JPx6

2026-12-04T01:23Z · Landing (zone em-upgrade). L1 ACCEPT 7397220605 at head 2f035937; no L2 owed (no contract face). check-governed-merges.mjs --pr 39449: NOT governed, 167 changed lines. Every check on the head is success or skipped. Shares authored-source-codemod.ts with #39453 (merge-tree clean); whichever lands second re-runs on the merged base in the queue.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 4, 2026 01:24
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge December 4, 2026 01:24
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 8682ef1 Dec 4, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-39396-wip branch December 4, 2026 01: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

Development

Successfully merging this pull request may close these issues.

cli: os migrate meta --write reads the stock generator's export const X = …; export default X; as a second use and skips it as not written [shared]

2 participants