Repository navigation
refactor(integrations): generate the shared Python plugin helpers from one source - #2318
Conversation
…m one source Claude Code, Codex, WorkBuddy, and Hermes install their plugin directories without the PowerContext package, so each ships its own copy of the client configuration, prepared-context, prompt-privacy, and bootstrap-context helpers. Twelve copies were kept identical by hand, and a test could only report that one had drifted. The helpers now live once in src/powercontext_integration_lifecycle/, a top-level package like src/powercontext_service_bootstrap. Importing it loads nothing from the SDK, and the Python API reference does not list it. The wheel includes it. Ruff checks it against Python 3.9, because the Claude Code copies often run on the macOS system Python, and checks every copy the same way, so that a fix Ruff applies to a copy cannot make the copy drift. `make integration-lifecycle` writes every copy where its plugin already imports it, marked as generated. `make check` fails when a copy is missing or differs from its source, or when a plugin keeps a same-named copy that the generator does not write. A test runs the same check, so the unit test jobs still catch a stale copy, as they did with the shared-files test. Git decides which plugin files count, so ignored build output and installed dependencies are not mistaken for copies. Another test keeps the source standard-library only and free of sibling imports: Claude Code runs its hooks with the python3 on PATH, Hermes installs no dependency for its plugin, and the copies do not keep the package layout. The copies gain only the generated-file comment, so plugin behavior, layout, and installation are unchanged, and the Claude Code and Codex characterization fixtures pass as recorded. The recall-query bound test now exercises the source module. The shared-files test keeps the JavaScript prompt-privacy module and the TypeScript transport, which have no generator yet.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
…tor/python-lifecycle-module
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed commit 62f23f2. Centralizing the four existing helpers and generating their twelve plugin copies is a reasonable, behavior-preserving way to prevent drift while keeping each plugin independently installable. The new wheel package is internal shared code; there are no new database tables or public HTTP/MCP/SDK contracts. No blocking findings.
knqiufan
left a comment
There was a problem hiding this comment.
Reviewed the shared helper generation and its integration consumers. No blocking correctness findings; focused tests passed.
Which issue or RFC does this PR close?
Part of #2250 (plan step 3, first item: the Python module and the generate/check command). Moving the Claude Code and Codex hooks onto the module comes in later PRs.
Rationale for this change
Claude Code, Codex, WorkBuddy, and Hermes install their plugin directories without the PowerContext package, so each plugin ships its own copies of up to four helpers: client configuration, prepared context, prompt privacy, and bootstrap context. Each helper's copies are byte-identical, 12 files in all, and
tests/test_integration_shared_files.pyfails when one of them drifts, but a change to a helper still has to be repeated in every copy.This PR keeps one source for the helpers and generates the copies from it, as #2250 plans. No plugin code moves: each plugin keeps importing its copy from the same path.
The source is a top-level package,
src/powercontext_integration_lifecycle/, as proposed in the follow-up comment on #2250. Underpowercontext.client, importing the module would runpowercontext/client/__init__.py, which importshttpx. The website's Python API reference would also publish it, and itsnormalize_server_urlwould sit next to an SDK function of the same name that behaves differently. Likesrc/powercontext_service_bootstrap, the top-level package imports with the standard library alone. It still ships in the wheel, so framework adapters can import it later; this PR adds no such import. Moving it later changes paths only.What changes are included in this PR?
src/powercontext_integration_lifecycle/holdsclient_config.py,prepared_context.py,prompt_privacy.py, andbootstrap_context.py, byte-identical to the current copies. The package is added to the wheel'spackages. Ruff checks it and every copy with thepy39target, as it already checks the Claude Code plugin, because the Claude Code copies often run on the macOS system Python 3.9. With the defaultpy311target, Ruff's automatic fixes (fix = true) would rewrite a Codex, WorkBuddy, or Hermes copy alone, for exampletimezone.utctodatetime.UTC, and the copy would no longer match its source.scripts/generate_integration_lifecycle.pywrites each copy to the path its plugin imports it from today. Below the license header, each copy gets two comment lines that name its source andmake integration-lifecycle.client_config.pypowercontext_client_config.pyin Claude Code, Codex, and Hermes;hooks/powercontext_client_config.pyin WorkBuddyprepared_context.pyhooks/prepared_context.pyin Claude Code, Codex, and WorkBuddyprompt_privacy.pyhooks/prompt_privacy.pyin Claude Code, Codex, and WorkBuddybootstrap_context.pyhooks/bootstrap_context.pyin Claude Code and CodexWith
--check, the script fails when a copy is missing or differs from its source. It also fails when a plugin has a file named like a copy that the generator does not write, such as a new hand-made copy. It finds those files withgit ls-files, so ignored build output and installed dependencies do not count.make integration-lifecyclewrites the copies.make integration-lifecycle-checkruns the check and is part ofmake check.AGENTS.mdgets a short section after "Generated API Contract": edit the source instead of the copies, and keep it standard-library only and runnable on Python 3.9..github/ci-paths.tomlselects thetestsandhermessuites when the generator changes. The source is undersrc/, which already selects every suite.tests/test_ci_changes.pycovers the new rule.Tests:
tests/test_integration_lifecycle.pyruns the generator's check, so the unit test jobs still catch a stale copy, as they do today through the shared-files test. It also fails when a source module imports anything outside the standard library, or imports a sibling module: Claude Code runs its hooks with thepython3onPATH, Hermes installs no dependency for its plugin, and each copy sits alone in its plugin.tests/test_recall_query_bound.py, from fix(integrations): bound the recall query in Pi, OpenCode, DSH, and Bub #2252, imports the source module instead of loading the Claude Code copy.tests/test_integration_shared_files.pykeeps onlyshared/prompt-privacy.mjsandsrc/transport.ts, which have no generator yet.Not included:
client/transport_policy.py, which feat(integrations): keep host plugins thin and make them work behind the gateway #2250 also plans to fold into the module. It depends on pydantic and validates URLs and settings differently fromclient_config, so folding it in changes behavior. It needs its own PR.hooks/diagnostics.pyand the Scope clients. They need the host declarations that come with moving the hook flows.Are there any user-facing changes?
No. Each copy gains only a blank line and the two comment lines, so plugin behavior, file layout, and installation are unchanged. The wheel gains the top-level package
powercontext_integration_lifecycle. Nothing inpowercontextimports it, and the Python API reference does not list it.For contributors, a shared helper is now edited in
src/powercontext_integration_lifecycle/, andmake integration-lifecycleupdates its copies.make checkand the unit tests reject an edited copy.How was this change tested?
uv run pytest tests/test_integration_lifecycle.py tests/test_integration_shared_files.py tests/test_recall_query_bound.py tests/test_hook_characterization.py tests/test_ci_changes.py: 181 passed. The Claude Code and Codex characterization fixtures from test(integrations): characterize the Claude Code and Codex hooks #2255 pass unchanged.uv run pytest -n 6 tests/claude_code_plugin tests/codex_plugin --require-claude-code-python-floor: 390 passed and 4 skipped, whichtest_client_transport.pyskips by design. The Python 3.9 tests ran on the macOS system Python 3.9.6.-I -S, the package and its four modules import, and nopowercontextmodule is loaded.uv build --wheel: the wheel containspowercontext_integration_lifecycle/with its five files.make integration-lifecycle-checkreported a deleted Hermes copy as missing, an edited Codex copy as drifted, and an untrackedbootstrap_context.pyin the WorkBuddy plugin as a file the generator does not write, andtests/test_integration_lifecycle.pyfailed on the same tree. With the files restored, both passed.ruff check --select UP017 --stdin-filename <path>accepted a module that usestimezone.utc. For the Codex plugin's ownsettings.py, which is not a copy, it still reported UP017.uv run prek run -a: every hook passes exceptty check, whose 4 diagnostics are in files this PR does not change and appear on master0c1dfc28as well: theSeekDBGraphStorecalls intests/builtin/test_code_publication.py, andsocket.SO_PEERCRED, which macOS lacks.make -k check:integration-lifecycle-checkand the other targets pass, exceptupgrade-policy-check, which fails on master0c1dfc28as well ("Persistence changed (file set or content; CRLF/LF normalized): update the compatibility review"; this PR leaves the persistence digest unchanged), andworkflow-actions-check, which runs prek and fails on the same ty diagnostics. Without-k,make checkstops atupgrade-policy-check, so until that is fixed thequalityjob runs neitherintegration-lifecycle-checknor prek and ty. The unit test jobs still run the copy check throughtests/test_integration_lifecycle.py.make unit-test: 7012 passed, 333 skipped, and 19 failed. The 19 fail on master0c1dfc28on the same machine, and none is in a file this PR changes: 4 intests/test_upgrade_release_gate.py, 3 intests/builtin/test_code_publication.py, 3 intests/builtin/persistence/test_mysql_vector_admission.py, and 9 intests/test_source_management.py.make e2e-test: 1190 passed, 513 skipped, and 5 failed. The 5, intests/e2e/test_source_collect.pyandtests/e2e/test_source_deployment.py, fail on master0c1dfc28as well, because Source background processes require Linux.make docs-test: passed.AI usage statement
This PR was prepared with Claude Code (Claude Opus 5.5). It wrote the change and the tests, ran the checks, and reviewed the change for correctness. I reviewed the change and the results.