Skip to content

Commit ec7ab53

Browse files
fix(node): normalize chunk parsing and lint scope (#4529)
1 parent d1bf74b commit ec7ab53

File tree

12 files changed

+532
-9
lines changed

12 files changed

+532
-9
lines changed

.changeset/tidy-shrimps-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@module-federation/node": patch
3+
---
4+
5+
Fix node chunk parsing and align node webpack-path lint handling.

.codex/skills/changeset-pr/SKILL.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ description: Create or update a `.changeset/*.md` file for the current branch or
99

1010
Create a repo-correct changeset for the current branch, or update an existing one without widening scope unnecessarily. Verify both syntax and package scope before handoff.
1111

12+
Ground the changeset in the live branch diff, not stale branch intent. Always inspect the current branch state against its base before choosing package scope or release type.
13+
1214
## Workflow
1315

1416
1. Confirm whether a changeset is needed.
15-
2. Identify the publishable package scope from the branch diff.
17+
2. Identify the publishable package scope from the live branch diff.
1618
3. Create or edit one `.changeset/*.md` file.
1719
4. Validate the file against repo config and branch scope.
1820
5. Report the exact commands run and any ambiguity that remains.
@@ -27,6 +29,16 @@ Read [references/repo-conventions.md](./references/repo-conventions.md) when you
2729

2830
## Determine Scope
2931

32+
First inspect the live branch state:
33+
34+
```bash
35+
git diff --name-status origin/main...HEAD
36+
git diff --stat origin/main...HEAD
37+
git log --oneline --decorate --no-merges origin/main..HEAD
38+
```
39+
40+
Use that to separate real publishable-package behavior changes from repo-local docs, skills, tooling, or cleanup.
41+
3042
Start with the helper script:
3143

3244
```bash
@@ -82,20 +94,21 @@ python3 .codex/skills/changeset-pr/scripts/inspect_changeset_scope.py --base ori
8294
2. Validate that Changesets can parse and plan the release:
8395

8496
```bash
85-
pnpm exec changeset status --verbose
97+
python3 .codex/skills/changeset-pr/scripts/run_changeset_status.py --verbose
8698
```
8799

88100
3. When machine-readable output is useful:
89101

90102
```bash
91-
pnpm exec changeset status --output /tmp/changeset-status.json
103+
python3 .codex/skills/changeset-pr/scripts/run_changeset_status.py --output /tmp/changeset-status.json
92104
```
93105

94106
Interpretation:
95107

96108
- `status` verifies parseability and computed release planning.
97109
- `status` does not prove the changeset is branch-local or minimal in this repo because other pending changesets may already exist.
98110
- Fixed-group packages can cause broader or higher bumps than the frontmatter alone suggests.
111+
- Prefer the helper script over direct `pnpm exec changeset status` in Codex runs because shell wrappers in non-TTY sessions can add `/dev/tty` noise or otherwise make the raw CLI output unreliable.
99112

100113
## Update Existing Changesets
101114

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import argparse
5+
import json
6+
import subprocess
7+
import sys
8+
from pathlib import Path
9+
10+
11+
def run(cmd: list[str], cwd: Path) -> str:
12+
result = subprocess.run(
13+
cmd,
14+
cwd=str(cwd),
15+
check=True,
16+
capture_output=True,
17+
text=True,
18+
)
19+
return result.stdout.strip()
20+
21+
22+
def find_repo_root(start: Path) -> Path:
23+
return Path(run(["git", "rev-parse", "--show-toplevel"], start))
24+
25+
26+
def find_changeset_cli(repo_root: Path) -> Path:
27+
candidates = [
28+
repo_root / "node_modules" / "@changesets" / "cli" / "bin.js",
29+
repo_root / "node_modules" / ".bin" / "changeset",
30+
]
31+
for candidate in candidates:
32+
if candidate.exists():
33+
return candidate
34+
raise FileNotFoundError("Unable to locate Changesets CLI under node_modules")
35+
36+
37+
def main() -> int:
38+
parser = argparse.ArgumentParser(
39+
description="Run Changesets status without shell wrappers so output is stable in non-TTY environments."
40+
)
41+
parser.add_argument(
42+
"--repo-root",
43+
default=".",
44+
help="Repo root. Defaults to current working directory.",
45+
)
46+
parser.add_argument(
47+
"--output",
48+
help="Optional path to write Changesets JSON output.",
49+
)
50+
parser.add_argument(
51+
"--verbose",
52+
action="store_true",
53+
help="Pass --verbose to Changesets status.",
54+
)
55+
parser.add_argument(
56+
"--json",
57+
action="store_true",
58+
help="Emit a small JSON wrapper with command, exit code, stdout, and stderr.",
59+
)
60+
args = parser.parse_args()
61+
62+
repo_root = find_repo_root(Path(args.repo_root).resolve())
63+
cli = find_changeset_cli(repo_root)
64+
65+
cmd = ["node", str(cli), "status"]
66+
if args.verbose:
67+
cmd.append("--verbose")
68+
if args.output:
69+
cmd.extend(["--output", str(Path(args.output).resolve())])
70+
71+
proc = subprocess.run(
72+
cmd,
73+
cwd=str(repo_root),
74+
capture_output=True,
75+
text=True,
76+
check=False,
77+
)
78+
79+
if args.json:
80+
payload = {
81+
"command": cmd,
82+
"exit_code": proc.returncode,
83+
"stdout": proc.stdout,
84+
"stderr": proc.stderr,
85+
}
86+
sys.stdout.write(json.dumps(payload, indent=2) + "\n")
87+
else:
88+
if proc.stdout:
89+
sys.stdout.write(proc.stdout)
90+
if proc.stderr:
91+
sys.stderr.write(proc.stderr)
92+
93+
return proc.returncode
94+
95+
96+
if __name__ == "__main__":
97+
raise SystemExit(main())
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
name: gh-pr-metadata
3+
description: Update the current GitHub PR title and body for this repository so they match the repo's pull request template and conventional-commit title style. Use when a PR title is vague or misformatted, when the PR body is missing required sections or checklist items, when Codex needs to normalize PR metadata before review or merge, or when GitHub comments/checks indicate the PR title or body should be corrected.
4+
---
5+
6+
# GH PR Metadata
7+
8+
## Overview
9+
10+
Normalize the current branch's GitHub PR metadata to this repo's expectations. Keep the title in conventional-commit style, keep the body aligned to `.github/pull_request_template.md`, and validate before handoff.
11+
12+
Ground the PR metadata in the live branch state, not stale branch names or old commit subjects. Always inspect the current branch diff versus its base before rewriting the PR title/body.
13+
14+
Read [references/repo-pr-format.md](./references/repo-pr-format.md) when you need the exact section order, checklist items, or a title example.
15+
16+
## Workflow
17+
18+
1. Resolve the current branch PR.
19+
20+
```bash
21+
gh pr view --json number,title,body,url,headRefName,baseRefName
22+
```
23+
24+
2. Inspect the current branch state against the PR base branch.
25+
26+
At minimum, check:
27+
28+
```bash
29+
git diff --name-status origin/<base>...HEAD
30+
git diff --stat origin/<base>...HEAD
31+
git log --oneline --decorate --no-merges origin/<base>..HEAD
32+
```
33+
34+
Use these to answer:
35+
- what files actually differ from the base right now
36+
- which changes are functional versus cleanup/tooling/docs
37+
- whether the existing PR title/body still matches the current branch after rebases, reverts, or scope narrowing
38+
39+
3. Validate the current title and body.
40+
41+
```bash
42+
python3 .codex/skills/gh-pr-metadata/scripts/validate_pr_metadata.py
43+
```
44+
45+
4. If the PR body needs a clean template scaffold, print one:
46+
47+
```bash
48+
python3 .codex/skills/gh-pr-metadata/scripts/validate_pr_metadata.py --print-template
49+
```
50+
51+
5. Rewrite the PR title in conventional-commit style.
52+
53+
Rules:
54+
- Prefer `type(scope): summary`
55+
- Keep the title short and direct
56+
- Use repo-typical types such as `fix`, `feat`, `docs`, `refactor`, `chore`, `test`, `ci`, `build`, `perf`, `revert`
57+
- Keep the scope tight to the affected package or subsystem when useful
58+
- Do not add prefixes like `[codex]`
59+
- Make sure the title describes the current branch diff, not the original branch intent if the branch was later narrowed or partially reverted
60+
61+
6. Rewrite the PR body to preserve the repo template structure:
62+
- `## Description`
63+
- `## Related Issue`
64+
- `## Types of changes`
65+
- `## Checklist`
66+
67+
7. Update the PR with `gh`.
68+
69+
Prefer writing the body to a temporary file first, then:
70+
71+
```bash
72+
gh pr edit --title "<new-title>" --body-file /tmp/pr-body.md
73+
```
74+
75+
8. Re-run validation and report whether the PR metadata is now compliant.
76+
77+
```bash
78+
python3 .codex/skills/gh-pr-metadata/scripts/validate_pr_metadata.py
79+
```
80+
81+
## Body Guidance
82+
83+
- Keep `Description` prose-first and specific to the branch.
84+
- Reflect the branch as it exists now, especially after rebases, cleanups, or partial reverts.
85+
- Summarize the real file-level themes from the live diff instead of copying commit messages mechanically.
86+
- Put issue references in `Related Issue`; if there is no issue, say so plainly instead of deleting the section.
87+
- In `Types of changes`, check only the boxes that actually apply.
88+
- In `Checklist`, preserve all repo checklist items and mark only the items that are true.
89+
- Do not remove required sections just because the PR is small.
90+
- Keep the body concise; do not turn it into a changelog dump.
91+
92+
## Title Guidance
93+
94+
Good examples:
95+
- `fix(node): normalize remote chunk parsing`
96+
- `chore(manifest): drop extra compat cleanup`
97+
- `docs(agents): prefer normalized webpack path requires`
98+
99+
Bad examples:
100+
- `update pr`
101+
- `fix stuff`
102+
- `[codex] cleanup`
103+
104+
## Validation
105+
106+
Use the helper script to detect:
107+
- non-conventional PR titles
108+
- missing or reordered template sections
109+
- missing repo checklist items
110+
111+
The script validates either the current PR from `gh` or explicit `--title` / `--body-file` input.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: 'GH PR Metadata'
3+
short_description: 'Normalize PR title and body'
4+
default_prompt: "Use $gh-pr-metadata to update this repo's PR title and body to match the template and conventional-commit style."
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Repo PR Format
2+
3+
Source files:
4+
- `.github/pull_request_template.md`
5+
- `AGENTS.md`
6+
7+
## Required PR Body Sections
8+
9+
Keep these sections in this order:
10+
11+
1. `## Description`
12+
2. `## Related Issue`
13+
3. `## Types of changes`
14+
4. `## Checklist`
15+
16+
## Required Checklist Items
17+
18+
Types of changes:
19+
- `- [ ] Docs change / refactoring / dependency upgrade`
20+
- `- [ ] Bug fix (non-breaking change which fixes an issue)`
21+
- `- [ ] New feature (non-breaking change which adds functionality)`
22+
23+
Checklist:
24+
- `- [ ] I have added tests to cover my changes.`
25+
- `- [ ] All new and existing tests passed.`
26+
- `- [ ] I have updated the documentation.`
27+
28+
## Title Convention
29+
30+
Prefer conventional-commit style:
31+
32+
```text
33+
type(scope): short summary
34+
```
35+
36+
Examples:
37+
- `fix(node): normalize remote chunk parsing`
38+
- `docs(agents): prefer normalized webpack path requires`
39+
- `chore(manifest): drop extra compat cleanup`
40+
41+
Avoid:
42+
- bracketed prefixes like `[codex]`
43+
- vague summaries like `update pr`
44+
- titles that do not describe the branch's actual change
45+

0 commit comments

Comments
 (0)