-
Notifications
You must be signed in to change notification settings - Fork 104
fix: deploy root project .apm/ primitives without a sub-package stub #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edenfunf
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
edenfunf:fix/root-apm-primitives-714
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+301
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8c5a993
fix: deploy root project .apm/ primitives without a sub-package stub
edenfunf bf73996
Merge branch 'main' into fix/root-apm-primitives-714
danielmeppiel 35ad682
refactor: simplify root primitive detection and harden error handling
edenfunf e0c708e
Merge branch 'main' into fix/root-apm-primitives-714
danielmeppiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -797,8 +797,17 @@ def install(ctx, packages, runtime, exclude, only, update, dry_run, force, verbo | |
| old_mcp_configs = builtins.dict(_existing_lock.mcp_configs) | ||
| old_local_deployed = builtins.list(_existing_lock.local_deployed_files) | ||
|
|
||
| # Also enter the APM install path when the project root has local .apm/ | ||
| # primitives, even if there are no external APM dependencies (#714). | ||
| from apm_cli.core.scope import get_deploy_root as _get_deploy_root | ||
| _cli_project_root = _get_deploy_root(scope) | ||
| _cli_root_apm = _cli_project_root / ".apm" | ||
| _cli_has_root_primitives = ( | ||
| _cli_root_apm.exists() and _cli_root_apm.is_dir() | ||
| ) or (_cli_project_root / "SKILL.md").exists() | ||
|
|
||
| apm_diagnostics = None | ||
| if should_install_apm and has_any_apm_deps: | ||
| if should_install_apm and (has_any_apm_deps or _cli_has_root_primitives): | ||
| if not APM_DEPS_AVAILABLE: | ||
| logger.error("APM dependency system not available") | ||
| logger.progress(f"Import error: {_APM_IMPORT_ERROR}") | ||
|
|
@@ -1400,12 +1409,21 @@ def _install_apm_dependencies( | |
| apm_deps = apm_package.get_apm_dependencies() | ||
| dev_apm_deps = apm_package.get_dev_apm_dependencies() | ||
| all_apm_deps = apm_deps + dev_apm_deps | ||
| if not all_apm_deps: | ||
| return InstallResult() | ||
|
|
||
| project_root = get_deploy_root(scope) | ||
| apm_dir = get_apm_dir(scope) | ||
|
|
||
| # Check whether the project root itself has local .apm/ primitives (#714). | ||
| # Users should be able to keep root-level .apm/ rules alongside their apm.yml | ||
| # without creating a dummy sub-package stub. | ||
| _root_apm_dir = project_root / ".apm" | ||
| _root_has_local_primitives = ( | ||
| _root_apm_dir.exists() and _root_apm_dir.is_dir() | ||
| ) or (project_root / "SKILL.md").exists() | ||
|
edenfunf marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second time the check appears in the file, seems error prone. Could extract to function. |
||
|
|
||
| if not all_apm_deps and not _root_has_local_primitives: | ||
| return InstallResult() | ||
|
|
||
| # T5: Check for existing lockfile - use locked versions for reproducible installs | ||
| from apm_cli.deps.lockfile import LockFile, get_lockfile_path | ||
| lockfile_path = get_lockfile_path(apm_dir) | ||
|
|
@@ -1613,7 +1631,7 @@ def _collect_descendants(node, visited=None): | |
| if dep.get_identity() in only_identities | ||
| ] | ||
|
|
||
| if not deps_to_install: | ||
| if not deps_to_install and not _root_has_local_primitives: | ||
| if logger: | ||
| logger.nothing_to_install() | ||
| return InstallResult() | ||
|
|
@@ -2549,6 +2567,61 @@ def _collect_descendants(node, visited=None): | |
| # Continue with other packages instead of failing completely | ||
| continue | ||
|
|
||
| # ------------------------------------------------------------------ | ||
| # Integrate root project's own .apm/ primitives (#714). | ||
| # | ||
| # Users should not need a dummy "./agent/apm.yml" stub to get their | ||
| # root-level .apm/ rules deployed alongside external dependencies. | ||
| # Treat the project root as an implicit local package: any primitives | ||
| # found in <project_root>/.apm/ are integrated after all declared | ||
| # dependency packages have been processed. | ||
| # ------------------------------------------------------------------ | ||
| if _root_has_local_primitives and _targets: | ||
| from apm_cli.models.apm_package import PackageInfo as _PackageInfo | ||
| _root_pkg_info = _PackageInfo( | ||
| package=apm_package, | ||
| install_path=project_root, | ||
| ) | ||
| if logger: | ||
| logger.download_complete("<project root>", ref_suffix="local") | ||
| try: | ||
| _root_result = _integrate_package_primitives( | ||
| _root_pkg_info, project_root, | ||
| targets=_targets, | ||
| prompt_integrator=prompt_integrator, | ||
| agent_integrator=agent_integrator, | ||
| skill_integrator=skill_integrator, | ||
| instruction_integrator=instruction_integrator, | ||
| command_integrator=command_integrator, | ||
| hook_integrator=hook_integrator, | ||
| force=force, | ||
| managed_files=managed_files, | ||
| diagnostics=diagnostics, | ||
| package_name="<root>", | ||
| logger=logger, | ||
| scope=scope, | ||
| ) | ||
| total_prompts_integrated += _root_result["prompts"] | ||
| total_agents_integrated += _root_result["agents"] | ||
| total_instructions_integrated += _root_result["instructions"] | ||
| total_commands_integrated += _root_result["commands"] | ||
| total_hooks_integrated += _root_result["hooks"] | ||
| total_links_resolved += _root_result["links_resolved"] | ||
| installed_count += 1 | ||
| except Exception as e: | ||
| import traceback as _tb | ||
| diagnostics.error( | ||
| f"Failed to integrate root project primitives: {e}", | ||
| package="<root>", | ||
| detail=_tb.format_exc(), | ||
| ) | ||
|
edenfunf marked this conversation as resolved.
|
||
| # When root integration is the *only* action (no external deps), | ||
| # a failure means nothing was deployed — surface it clearly. | ||
| if not all_apm_deps and logger: | ||
| logger.error( | ||
| f"Root project primitives could not be integrated: {e}" | ||
| ) | ||
|
|
||
| # Update .gitignore | ||
| _update_gitignore_for_apm_modules(logger=logger) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we be processing it in case the project contains a Skill.md in root? I think that would be confusing UX