Skip to content

feat(release): add api_surface.py and a2ui-release-notes Generator/Critic skill - #4524

Open
gspencergoog wants to merge 3 commits into
a2ui-project:mainfrom
gspencergoog:changelog-pr5-api-skill
Open

gspencergoog wants to merge 3 commits into
a2ui-project:mainfrom
gspencergoog:changelog-pr5-api-skill

Conversation

@gspencergoog

Copy link
Copy Markdown
Collaborator

Summary

Adds .github/scripts/api_surface.py, advisory PR workflows (.github/workflows/api_surface.yml and .github/workflows/api_surface_comment.yml), and the .agents/skills/a2ui-release-notes/SKILL.md skill for generating and auditing CHANGELOG.md entries across all 18 packages in .github/release_packages.json (#4215). Combines static public API diffs (TypeScript .d.ts bundles via npm tarball or worktree build, Python AST __all__, and degraded Dart/Swift file scanning) with release_notes.py check-notes and write-section validation.

Reviewer Focus

  • .github/scripts/api_surface.py: check public API extraction and diffing for npm (tarball fetch with host/size validation and isolated worktree build fallback), Python AST, and Dart/Swift degraded modes, plus PR merge-base mode.
  • .github/workflows/api_surface.yml and .github/workflows/api_surface_comment.yml: check untrusted pull_request_target artifact separation (read-only PR job uploads JSON/Markdown artifact; privileged workflow posts/updates sticky PR comment).
  • .agents/skills/a2ui-release-notes/SKILL.md: verify Generator/Critic release-note drafting workflow, 18-package coverage including @a2ui/sandbox, and ecosystem release dependency order.

Changes

  • Added .github/scripts/api_surface.py (Python stdlib only) with per-package --since..--until API surface diffing and --pr merge-base detection.
  • Added .github/scripts/tests/test_api_surface.py covering TypeScript .d.ts extraction, npm tarball/worktree fallback, Python AST diffs, Dart/Swift degraded modes, and PR CLI rendering.
  • Added .github/workflows/api_surface.yml and .github/workflows/api_surface_comment.yml to compute advisory API-surface diffs on pull requests and update a sticky summary comment safely across forks.
  • Added .agents/skills/a2ui-release-notes/SKILL.md guiding agents through release_notes.py context, api_surface.py, deterministic check-notes validation, and write-section across all 18 packages.

Testing

  • GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 python3 -m unittest discover -s .github/scripts/tests -> 224 tests passed (including 20 test_api_surface.py tests).
  • uvx pyink==25.12.0 --check .github/scripts/api_surface.py .github/scripts/tests/test_api_surface.py -> passed.
  • prettier --check on .github/workflows/api_surface.yml, .github/workflows/api_surface_comment.yml, and .agents/skills/a2ui-release-notes/SKILL.md -> passed.
  • python3 scripts/fix_licenses.py --check -> passed.
  • lint_skill.py .agents/skills/a2ui-release-notes -> 0 errors, 0 warnings.
  • uvx zizmor .github/workflows/api_surface.yml .github/workflows/api_surface_comment.yml -> 0 findings.
  • cognitive_complexity.py .github/scripts/api_surface.py -> max complexity 15 (0 functions over 15).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new automated pipeline and tooling for generating A2UI release notes, including a detailed workflow guide, a static public API surface differ script supporting TypeScript and Python, and a comprehensive test suite. The review feedback is highly constructive, pointing out critical areas for improvement in the API surface differ script. Specifically, the reviewer identified a potential negative slicing bug in relative Python import resolution, suggested printing captured yarn build errors to improve debuggability, recommended filtering out test files from the approximate public files list on build failures, and advised expanding test directory exclusions to cover singular 'test/' paths. Addressing these issues will significantly enhance the robustness and maintainability of the release notes automation tool.

Comment thread .github/scripts/api_surface.py Resolved
Comment thread .github/scripts/api_surface.py Resolved
Comment thread .github/scripts/api_surface.py Resolved
Comment thread .github/scripts/api_surface.py Resolved
@gspencergoog
gspencergoog requested a review from ditman December 2, 2026 21:26

@ditman ditman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Left inline comments on SKILL.md, the two workflows, and api_surface.py (including reproducer tests for the parser and security bugs).

Before investing more in fixing individual edge cases in the 2,245-line regex/AST differ in api_surface.py, it's worth considering off-the-shelf options for extracting APIs without adding flow complexity:

  • Python: griffe (uvx griffe check <pkg> -a <since> -b <until>) reads both git refs natively via load_git—no extra before/after checkout needed—and handles __all__, @property/setters, @overload, Enum, async, posonly, and breaking-change classification out of the box with zero repo deps.
  • TypeScript: api_surface.py already builds/extracts before-and-after .d.ts directories (npm tarball or worktree yarn build), and typescript is already in the Yarn workspace—so swapping the ~700-line regex parse_dts_tree for a small Node script using the TS Compiler API (ts.createProgram + checker.getExportsOfModule) or @microsoft/api-extractor drops into the exact same before/after flow with zero regex fragility.


# Generating A2UI release notes

This skill prepares release pull requests for any of the 19 published packages

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to mention that there are "19" published packages... "for the packages registered in ./github/release_packages.json" should be enough

2. Run a Generator pass to produce risk-ordered bullets and a SemVer bump
recommendation.
3. Run the deterministic gate (`release_notes.py check-notes`) for Gates 1 and 3.
4. Run a fresh-context Critic pass to audit semantic Gates 2, 4, and 5.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are "Gates"?


Store intermediate JSON artifacts in a temporary directory outside the
repository (for example via `mktemp -d`) so scratch files are never committed to
the release branch.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this adds complexity/brittleness, we can just .gitignore a known location within the repo.


```bash
git checkout -b release/<scope>-<date> "${REMOTE}/main"
WORK_DIR=$(mktemp -d)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commands being run verbatim, or is this just an example for the model? Just to know how deeply these commands need to be reviewed (now and later)

| Python (`python`) | `a2ui-core` -> `a2ui-agent-sdk` -> `a2ui-a2a` -> `a2ui-adk`, `a2ui-agent-experimental` |
| Dart (`pub`) | `dart-a2ui_core` -> `dart-a2ui_agent`, `dart-a2ui_flutter`, `a2ui_cli` |
| TypeScript (`npm`) | `web_core` -> `sandbox`, `markdown-it`, `agent`, `catalog-vegachart` -> `catalog-mcp`, `lit`, `react`, `angular` |
| Swift (`swiftpm`) | `swift` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be much better to have a deterministic tool that generates these lists, rather than maintaining this list here. (Actually don't we already have an implementation of this? we reviewed it in python)

Comment on lines +99 to +107
TS_FUNC_RE = re.compile(
r"^(?:export\s+)?(?:default\s+)?(?:declare\s+)?(?:async\s+)?function\s+"
r"(?P<name>[A-Za-z_$][\w$]*)\s*(?P<generics><[^>]*>)?\s*\("
)
TS_TYPE_RE = re.compile(
r"^(?:export\s+)?(?:declare\s+)?type\s+(?P<name>[A-Za-z_$][\w$]*)"
r"(?:\s*<[^>]*>)?\s*=\s*(?P<rhs>.+)$",
re.DOTALL,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug (hits live @a2ui/web_core): TS_FUNC_RE, TS_TYPE_RE, and TS_MEMBER_METHOD_RE match generic parameter lists with <[^>]*>, which fails on nested generics (<C extends CatalogInterface<string>>). Running parse_dts_tree on @a2ui/web_core silently drops real public exports like linkCatalogs and AgentFunctionHandler. (Related: TS_BLOCK_RE at L113 stops at { inside <T extends { id: string }>.)

Reproducer test (currently fails—linkCatalogs is missing):

def test_ts_nested_generics_parsed(self):
    dts = "export declare function linkCatalogs<C extends CatalogInterface<string>>(c: C): C;\n"
    self.assertIn("linkCatalogs", apis.parse_dts_content(dts, "src/index.d.ts"))

Comment on lines +853 to +863
decs = _decorator_names(stmt)
full_name = f"{cls_name}.{stmt.name}"
if "property" in decs:
ret = _py_ann(stmt.returns)
sig = f"property {full_name}: {ret}" if ret else f"property {full_name}"
return SymbolInfo(
name=full_name,
kind="property",
signature=sig,
file=rel_path,
value_type=ret,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug (hits live a2ui-core): _py_class_member_from_func only checks "property" in decs, so @foo.setter (decs == {"setter"}) is parsed as kind="method" and overwrites the @property entry in _record_py_export. On live a2ui-core, ComponentModel.properties is misclassified as a method (def ComponentModel.properties(new_props: ...) -> None).

Reproducer test (currently fails with kind == "method"):

def test_py_property_with_setter_stays_property(self):
    src = "class C:\n @property\n def x(self) -> int: return 1\n @x.setter\n def x(self, v: int) -> None: pass\n"
    mod = apis._parse_py_module(src, "python/a2ui_core/src/p.py", "python/a2ui_core")
    surface = {}
    apis._record_py_export(surface, set(), {mod.module_name: mod}, mod, "C", "")
    self.assertEqual(surface["C.x"].kind, "property")

Comment on lines +896 to +906
def _extract_py_class_members(
class_node: ast.ClassDef, rel_path: str
) -> list[SymbolInfo]:
members: list[SymbolInfo] = []
for stmt in class_node.body:
member: SymbolInfo | None = None
if isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef)):
member = _py_class_member_from_func(class_node.name, stmt, rel_path)
elif isinstance(stmt, ast.AnnAssign):
member = _py_class_member_from_ann(class_node.name, stmt, rel_path)
if member is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug (hits live a2ui-core): _extract_py_class_members ignores ast.Assign, so Enum members and unannotated class constants are completely invisible. On live a2ui-core, both RpcErrorCode and A2uiProtocolVersion extract 0 members, so removing or renaming enum values produces an empty diff.

Reproducer test (currently fails—removing ERR yields removed: []):

def test_py_enum_member_removal_detected(self):
    before = apis._parse_py_module("import enum\nclass S(str, enum.Enum):\n OK = 'ok'\n ERR = 'err'\n", "p/src/s.py", "p")
    after = apis._parse_py_module("import enum\nclass S(str, enum.Enum):\n OK = 'ok'\n", "p/src/s.py", "p")
    s_before, s_after = {}, {}
    apis._record_py_export(s_before, set(), {before.module_name: before}, before, "S", "")
    apis._record_py_export(s_after, set(), {after.module_name: after}, after, "S", "")
    self.assertIn("S.ERR", s_before)
    self.assertNotIn("S.ERR", s_after)

Comment on lines +531 to +541
def _classify_callable_change(
before: SymbolInfo, after: SymbolInfo, *, check_param_names: bool
) -> bool | str:
if before.params is None or after.params is None:
return "unknown"
old_pos, old_kw, old_var, old_kwarg = _split_param_kinds(before.params)
new_pos, new_kw, new_var, new_kwarg = _split_param_kinds(after.params)
verdict = _compare_positional_params(
old_pos, new_pos, old_var, new_var, check_names=check_param_names
)
verdict = _combine_breaking(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug: _classify_callable_change / _compare_single_param miss two Python breaking changes:

  1. SymbolInfo doesn't track is_async, so def fetch(url: str) -> str → async def fetch(url: str) -> str is classified as breaking: False.
  2. _compare_single_param (L478) never checks old.kind == "positional" and new.kind == "posonly", so def connect(host: str) → def connect(host: str, /) (breaks keyword callers) is also classified as breaking: False.

Reproducer test (both currently return breaking: False):

def test_py_async_and_posonly_are_breaking(self):
    b1 = apis._parse_py_module("def fetch(url: str) -> str: ...\n", "p/src/m.py", "p").defs["fetch"]
    a1 = apis._parse_py_module("async def fetch(url: str) -> str: ...\n", "p/src/m.py", "p").defs["fetch"]
    self.assertIs(apis._classify_callable_change(b1, a1, check_param_names=True), True)

    b2 = apis._parse_py_module("def connect(host: str) -> None: ...\n", "p/src/m.py", "p").defs["connect"]
    a2 = apis._parse_py_module("def connect(host: str, /) -> None: ...\n", "p/src/m.py", "p").defs["connect"]
    self.assertIs(apis._classify_callable_change(b2, a2, check_param_names=True), True)

Comment on lines +1482 to +1492
def _apply_ts_export_list(
stmt: str,
locals_by_name: dict[str, list[SymbolInfo]],
exported: dict[str, SymbolInfo],
) -> None:
match = TS_EXPORT_LIST_RE.match(stmt)
if not match:
return
for raw_item in match.group("items").split(","):
item = _normalize_ws(raw_item).removeprefix("type ").strip()
if not item:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Bug: _apply_ts_export_list only looks up re-exported names in the current file's locals_by_name (ignoring from './foo.js'), while parse_dts_tree parses every .d.ts file in dist/ regardless of entrypoints. As a result, export { Foo as PublicFoo } from './foo.js' never emits PublicFoo, and removing a re-export from index.d.ts while foo.d.ts remains in dist/ reports removed: [].

(Also in this area: _merge_ts_symbol at L1463 drops the set half of a get/set pair and is order-dependent for 3+ overloads; _parse_ts_method at L1314 ignores the ? optional marker on interface methods.)

Reproducer test (currently fails—'PublicFoo' is not emitted):

def test_ts_barrel_reexport_alias_emitted(self):
    surface = apis.parse_dts_tree({
        "dist/foo.d.ts": "export declare class Foo { run(): void; }\n",
        "dist/index.d.ts": "export { Foo as PublicFoo } from './foo.js';\n",
    })
    self.assertIn("PublicFoo", surface)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants