Skip to content

feat(gemini): deploy agents to .gemini/agents with validated frontmatter - #4593

Open
Mohit Mishra (mohitmishra786) wants to merge 20 commits into
microsoft:mainfrom
mohitmishra786:2990-gemini-agents
Open

Mohit Mishra (mohitmishra786) wants to merge 20 commits into
microsoft:mainfrom
mohitmishra786:2990-gemini-agents

Conversation

@mohitmishra786

Copy link
Copy Markdown

Description

Deploy APM agents to Gemini CLI: .gemini/agents/<name>.md (project) and ~/.gemini/agents/<name>.md (-g), qualified against Gemini CLI v0.70.0.

Gemini's loader rejects an agent file with any frontmatter key outside its schema (agentLoader.ts), so a verbatim copy does not load. A new gemini_agent renderer, modelled on the Kiro preflight and run before any adopt check or write:

  • writes only name (frontmatter or file stem), description, tools, model, display_name, temperature, max_turns, timeout_mins; drops other keys;
  • leaves an omitted tools omitted, which Gemini documents as inheriting the parent session's tools (subagents);
  • skips the agent with a warning (siblings still deploy, per req-tg-009) when: description is missing; name is not a slug; a tool is not a Gemini tool name (tools reference; the check mirrors isValidToolName); model is not inherit or gemini-*; or the source declares agent-scoped MCP servers, disallowedTools, permissionMode or kind: remote. No tool or model mapping across providers.

Local bundle installs skip Gemini agents, as they already do Codex agents, because the bundle path copies files without the renderer. APM does not write Gemini's trust, acknowledgement or agents.overrides state.

Issue and approved scope

Issue: Refs #2990

Human scope-approval comment: #2990 (comment) (approach confirmed in #2990 (comment)). Review contact: Daniel Meppiel (@danielmeppiel)

This is the Gemini half. Antigravity (.agents/agents/, ~/.gemini/config/agents/) follows in a second PR, which will close the issue.

Correction to my design comment: I wrote that project agents "load only in a trusted folder". That holds only while folder trust is on. In v0.70.0 security.folderTrust.enabled defaults to true (configuration reference); trusted-folders.md still says it is off by default. With trust off, project agents load (registry.ts). The docs in this PR state the default from the configuration reference.

Evidence (Gemini CLI v0.70.0, the latest release)

Run in Docker with this branch's apm; models gemini-3-flash-preview (others returned 503 or quota errors).

  • Loader: loadAgentsFromDirectory from @google/gemini-cli-core@0.70.0 loads every APM-rendered file. The raw sources fail: Unrecognized key(s) in object: 'color', and for a Copilot-style agent name: Required and 'handoffs', 'argument-hint', 'user-invocable', 'target'.
  • User scope: gemini -p "@file-reader ..." called invoke_agent with agent_name: "file-reader" and returned a marker that exists only in the read file. The subagent's own chat log shows it called only read_file (plus Gemini's complete_task) and reported no shell tool. The shell part was delegated to shell-runner (tools: [run_shell_command]), which called run_shell_command. Each subagent's log starts with only its delegated prompt.
  • Project scope: unacknowledged project agents are not registered. Gemini showed its "New Agents Discovered" dialog listing both agents; accepting it wrote ~/.gemini/acknowledgments/agents.json with hashes equal to sha256 of the APM-deployed files. Then invoke_agent reached the project file-reader, whose log shows only read_file.
  • Update: after apm install deployed a changed file-reader, a headless run got Subagent 'file-reader' not found until it is acknowledged again. Gemini's acknowledgement prompt stays in effect. In v0.70.0 that prompt is interactive only (AppContainer.tsx), which the docs now say.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally

  • All existing tests pass (in a Python 3.12 container; the same 260 environment-dependent tests fail on unmodified main, for example test_unix_install_ownership.py and test_governance_evidence.py)

  • Added tests for new functionality

  • tests/unit/integration/test_gemini_agents.py: rendering, every rejection case, preflight before adopt, sibling isolation, reinstall/update, user-file protection, sync removal, link resolution, the tool-name check.

  • tests/integration/test_gemini_agent_lifecycle.py (APMLifecycle): project and -g install, reinstall, restore of a deleted file, update, an agent that becomes invalid (stale copy and ledger row removed), recovery, uninstall; a user agent and .gemini/settings.json with agents.overrides are left unchanged.

  • req-tg-009 conformance test for Gemini; CONFORMANCE.{md,json} regenerated.

  • The new unit and lifecycle tests fail with the agents mapping reverted.

  • CI lint chain, architecture guards and complexity ratchet pass.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.

Spec conformance (OpenAPM v0.1)

  • Test edit: req-tg-009 test for Gemini added; CONFORMANCE.{md,json} regenerated. No spec or manifest change: req-tg-009 already covers this.

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Thank you Mohit Mishra (@mohitmishra786), this matches the approach agreed on #2990, including the fail-closed handling of unsupported model values and leaving an omitted tools omitted. A maintainer will approve the CI runs for your fork, and an advisory review will follow here. The correction about Gemini folder trust is helpful; please keep that wording in the docs.

Copilot AI 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.

🟡 Changes recommended

The new test modules lack required taxonomy markers and fail the quality gate, while agent preflight accepts NaN temperatures and incorrectly rejects BOM-prefixed frontmatter.

4 open issues
What changed in this PR

Adds Gemini CLI agent deployment to APM's existing target integration system, covering project and global installs. This implements the Gemini portion of #2990; Antigravity remains separate.

Changes:

  • Adds frontmatter validation and rendering before agent adoption or deployment, with warnings for unsupported agents.
  • Prevents local bundles from bypassing Gemini agent validation.
  • Adds rendering, lifecycle, and conformance coverage, and updates target documentation.
File Description
tests/​unit/​integration/​test_gemini_agents.py Tests validation, rendering, deployment, and cleanup.
tests/​unit/​integration/​test_data_driven_dispatch.py Adds the Gemini agents dispatch bucket.
tests/​unit/​integration/​test_agent_integrator.py Excludes Gemini from verbatim-copy expectations.
tests/​unit/​install/​test_install_local_bundle.py Tests Gemini bundle-agent skipping.
tests/​unit/​core/​test_target_catalog.py Records the Gemini agent mapping.
tests/​spec_conformance/​test_manifest_reqs.py Adds Gemini tool-validation conformance coverage.
tests/​integration/​test_gemini_agent_lifecycle.py Exercises project and global agent lifecycles.
tests/​integration/​test_architecture_confirmed_bypass_mutations.py Tests detection of bundle-validation bypasses.
src/​apm_cli/​integration/​targets.py Maps Gemini agents to validated Markdown.
src/​apm_cli/​integration/​agent_integrator.py Implements Gemini validation and rendering.
src/​apm_cli/​install/​local_bundle_paths.py Blocks unvalidated bundle-agent copies.
src/​apm_cli/​core/​target_detection.py Includes agents in the Gemini target description.
scripts/​architecture_linter/​checks/​marketplace_package_and_registration.py Extends the bundle-layout guard.
packages/​apm-guide/​.apm/​skills/​apm-usage/​package-authoring.md Documents Gemini agent authoring constraints.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents Gemini bundle-agent skipping.
docs/​src/​content/​docs/​reference/​targets-matrix.md Describes agent support and Gemini acknowledgement requirements.
docs/​src/​content/​docs/​reference/​manifest-schema.md Lists the Gemini agent destination.
docs/​src/​content/​docs/​reference/​cli/​audit.md Adds Gemini agents to documented audit coverage.
CONFORMANCE.md Updates the requirement coverage count.
CONFORMANCE.json Registers the new conformance test.
CHANGELOG.md Announces Gemini agent deployment.

Review effort: Balanced

@danielmeppiel

Daniel Meppiel (danielmeppiel) commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_with_followups

Community PR #4593 lets APM deploy agents to Gemini CLI. It follows the #2990 design, but it silently drops frontmatter keys that restrict access, and the scope record asks for exactly that to be fixed.

panel-mode=lean; personas=python-architect,test-coverage-expert,supply-chain-security-expert,doc-writer(adhoc: maintainer guidance names the docs and apm-guide updates),apm-ceo

cc Mohit Mishra (@mohitmishra786) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

This is the right PR from the right kind of contributor. It adds Gemini as a native agent target through the normal apm install. It follows the maintainer guidance on #2990 point by point:

  • One render-and-validate owner, modelled on the Kiro preflight.
  • Constants kept beside that owner in agent_integrator.py.
  • The agent is rendered before any mkdir or adoption check, then handed to _deploy_rendered_agent.
  • No kind: remote is ever written, and files are named <name>.md only.
  • An unsupported model or tool skips the agent with a warning instead of being mapped.
  • APM never writes Gemini trust or acknowledgement state.
  • A real-CLI lifecycle test covers project and -g scope.
  • Docs, apm-guide and the CHANGELOG are updated.

The tests and the manual check on Gemini CLI v0.70.0 support the main promise. The PR body says the new tests fail when the agents mapping is reverted, and the exact 4-key frontmatter and ledger-row assertions make that believable. Fork CI was still running when the panel reviewed, so the evidence is not final yet.

The one real disagreement is about severity. Python Architect marked the silent drop of restriction-bearing keys as blocking-severity; Supply Chain Security raised the same problem (hooks, disable-model-invocation, infer) as recommended. The panel sides with the higher severity, for two reasons. First, the #2990 scope record says unsupported fields must be refused or clearly diagnosed without silently broadening access. A closed nine-key deny set breaks that rule whenever another harness adds a restriction key: Cursor readonly, OpenCode permission, Claude hooks and disable-model-invocation are all dropped today. When tools is also omitted, the agent then gets every Gemini session tool, including write_file and run_shell_command. Second, this is default install behavior, where the panel leans toward security. Both personas agree on a small fix that does not change the design:

  • Skip the agent with an actionable warning when a known restriction-bearing key is present.
  • Move the Codex dropped-field diagnostic into one shared helper, so every other dropped key gets a named warning.

The other findings are ordinary work: write-set and failure-integrity lifecycle steps, a name-equals-file-stem identity check, a complete and shorter docs list, and the smoke marker. None of them argues against the approach. The Antigravity follow-up PR inherits whatever pattern lands here, so the shape is worth settling now.

Dissent. Python Architect (blocking-severity) and Supply Chain Security (recommended) disagree on how severe the silent drop of restriction-bearing keys is; the panel weighs it higher because it touches an explicit #2990 scope clause on default install behavior. The lifecycle_smoke finding carries evidence outcome unknown (the test has not run in a PR-time job), so it is ranked low.

Aligned with: Portable by manifest: Gemini agents install, update, restore and uninstall through the ordinary manifest and lockfile pipeline, with ledger rows asserted; a failed-install integrity step is still missing. Secure by default: tools, model, kind and trust handling fail closed, except unrecognized frontmatter keys, which are dropped with no warning and can widen tool access. Multi-harness: a fifth native agent target that follows the Kiro pattern; settle the renderer shape before Antigravity adds another branch. OSS community: an external contributor delivered an accepted, scoped issue with manual evidence against the real client. Pragmatic as npm: an incompatible agent is skipped with one actionable warning instead of failing the install, and user files and settings are left alone.

Growth signal. Gemini CLI agent support from a community contributor is a strong release-note line: APM deploys the same agent package to Claude, Copilot, Codex, Kiro and Gemini, and refuses to drop guarantees silently along the way. If the restriction-key fix lands in this PR, the second half of that sentence becomes true and worth stating.

Panel summary

Persona B R N Takeaway
Python Architect 1 2 0 Gemini preflight is the single render+validate owner and runs before adopt and mkdir. Fix the fail-open drop of restricting keys and the name vs file-stem split.
Test Coverage Expert 0 3 0 Real-CLI Gemini lifecycle is solid and plausibly fails-before; add .gemini write-set snapshot, a failed-command integrity step, and PR-time smoke selection.
Supply Chain Security Expert 0 3 0 Tool, model and trust handling fail closed, but the renderer silently drops keys that restrict access, such as hooks and disable-model-invocation. Refuse them or allowlist keys.
Doc Writer 0 3 0 Required doc surfaces updated, CHANGELOG and ASCII clean, folder-trust wording kept. Fix the incomplete rejection list, trim the matrix paragraph, add a guide gotcha.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 5 follow-ups

  1. [Python Architect] (blocking-severity) Replace the silent drop with allowlist-or-diagnose. Skip the agent with a Fix: hint when it has a restriction-bearing key: hooks, readonly, permission, disable-model-invocation: true, or infer: false. Move the Codex dropped-field warning into one shared helper and call it from the Gemini preflight, so every other dropped key is named in a warning. Add unit tests, for example: an agent with hooks and no tools is not written to .gemini/agents. (Merges the Supply Chain Security findings on hooks and on disable-model-invocation/infer.) -- The [FEATURE] Be able to configure sub-agents for gemini and antigravity #2990 scope record requires that unsupported fields never silently broaden access. Today a dropped restriction key plus an omitted tools list gives the agent every Gemini session tool.
  2. [Test Coverage Expert] Add a lifecycle scenario that seeds only .gemini/settings.json and installs a package whose only agent is invalid; assert the .gemini tree is byte-identical and no agents dir exists. In the valid steps, assert that the only change under .gemini is the deployed agent file, and that trustedFolders.json and the acknowledgements store are absent or unchanged in both project and -g scope. (Merges the Supply Chain Security trust/ack snapshot finding.) -- Render-before-mkdir and never touching trust or acknowledgement state are covered only by unit tests today; both lifecycle scenarios pre-create .gemini/agents, so the CLI tier never exercises either promise.
  3. [Test Coverage Expert] Add a failed-command step to the project lifecycle test: point the ref at a SHA that does not exist, run install, assert a non-zero exit, and assert the deployed agent bytes and lockfile rows are unchanged. -- Failure-state integrity is a [FEATURE] Be able to configure sub-agents for gemini and antigravity #2990 Done-when item, and every current lifecycle step asserts success.
  4. [Python Architect] Require the frontmatter name, when present, to equal the file stem; otherwise skip with a warning naming the expected file name. Add a unit test. -- Today the file name and agent name can differ, so a package agent can shadow a user agent by name while collision and adoption checks, which compare file paths, see no conflict. The maintainer guidance was <name>.md only.
  5. [Doc Writer] Write one complete list of refused keys and accepted tool forms (including disallowed-tools, agent_card_url, agent_card_json, auth, discovered_tool_<name> and the leading-underscore rule) in targets-matrix.md and package-authoring.md, updated for the restriction-key change. Split the long Gemini Agents bullet into 3-4 sub-bullets and move upstream source-file links into the integrator comment, keeping the folder-trust wording. Add the "Gemini skips the whole agent" gotcha to producer/write-primitives.md. -- The reference docs must match the code, and producers never see the whole-agent skip on the page they read.

Recommendation

The approach matches #2990 and should land once a small set of fixes is added to this PR. The one item to finish first is the allowlist-or-diagnose change for restriction-bearing frontmatter keys, with its unit tests, because it closes an explicit scope-record clause. In the same PR, fold in the .gemini write-set and failed-install lifecycle steps, the name-equals-stem check and the docs list. Fork CI at 7fcf617 already shows two PR-caused failures to fix here: (a) Architecture Ratchet Contracts / Test Architecture Ratchets (taxonomy tm006): tests/unit/integration/test_gemini_agents.py needs a module-level pytestmark with one behavioral marker (pytest.mark.unit) and a pytest.mark.promise(...) id from tests/quality/promise-catalog.json, and tests/integration/test_gemini_agent_lifecycle.py needs a pytest.mark.promise(...) too (the ratchet suggests P-OWN-distributed-agents-output-preparation and P-OWN-agent-plugin-package-projection); (b) the assertion-quality baseline (AQ003, observed 19 vs allowed 18) flags the new req-tg-009 test in tests/spec_conformance/test_manifest_reqs.py; make it assert on the warning output or the files left on disk, not only on return values. uv run --extra dev python -m tests.quality.taxonomy --changed reproduces (a) locally. Confirm the remaining Lifecycle Smoke shards finish green before landing. The renderer-shape cleanup (one return shape, a format_id -> renderer mapping, and a static guard against mkdir inside integrate_agents_for_target) and the lifecycle_smoke marker on the project-scope test can land here or open the Antigravity PR, but should be settled before that next branch is added.


Full per-persona findings

Python Architect

  • [blocking] Unknown frontmatter keys are dropped silently, and the deny list is fail-open, so keys that restrict access (Cursor readonly, OpenCode permission) disappear without any warning at src/apm_cli/integration/agent_integrator.py:1228
    _preflight_render_gemini_agent keeps only name, description, tools, model and the optional fields, and drops every other key with no diagnostic. _GEMINI_AGENT_REJECTED_FIELDS is a closed list of nine keys. Cursor readonly: true and OpenCode permission: {edit: deny, bash: deny} are dropped, tools stays omitted, and Gemini gives the agent every session tool. A closed deny list fails open whenever a harness adds a restriction key. The Codex path in the same file already warns about dropped keys (_MAX_DROPPED_FIELDS_SHOWN, _display_dropped_field_key) but inline.
    Suggested: Extract the Codex dropped-fields diagnostic into one helper and call it from the Gemini preflight; add readonly and permission to the rejected set, or skip the agent when tools is omitted and any key outside a known-safe set is present.
  • [recommended] Deployed file name comes from the file stem but the Gemini agent name can come from frontmatter, so file-based collision checks miss agent-name collisions at src/apm_cli/integration/agent_integrator.py:1225
    A package agent code-review.md with name: reviewer can shadow a user's .gemini/agents/reviewer.md; collision and adopt checks are keyed on file paths. Two values decide one identity.
    Suggested: Require the frontmatter name, when present, to equal the stem. Add a unit test.
  • [recommended] Per-format if/elif renderers return different tuple shapes and render-before-mkdir order rests only on unit tests; settle before Antigravity adds the next branch at src/apm_cli/integration/agent_integrator.py:381
    Kiro returns (rendered, ok: bool), Gemini (rendered | None, links: int). The else branch still mkdirs eagerly though _deploy_rendered_agent owns mkdir. The install-deployment-agent-render-then-adopt guard covers adoption and writes for the Gemini branch, but not render-before-mkdir.
    Suggested: One renderer shape, a format_id -> renderer mapping, drop the eager-mkdir else branch, and extend check_agent_render_then_adopt to refuse mkdir() inside integrate_agents_for_target.

Test Coverage Expert

  • [recommended] No real-CLI test snapshots the files written under .gemini: render-before-mkdir and no trust/acknowledgement writes are untested at that tier at tests/integration/test_gemini_agent_lifecycle.py
    Both scenarios pre-create .gemini/agents in _seed_gemini_dir; only the unit test test_gemini_agent_rejected_with_warning_and_nothing_written asserts render-before-mkdir.
    Suggested: Seed only .gemini/settings.json with an all-invalid package; assert a byte snapshot of .gemini is unchanged. Use a tree snapshot diff in the valid steps.
    Proof (missing at): tests/integration/test_gemini_agent_lifecycle.py::test_gemini_agent_all_invalid_leaves_gemini_tree_untouched -- proves: Installing a package whose Gemini agents are all invalid leaves my .gemini directory byte-identical. [secure-by-default,multi-harness-support]
  • [recommended] Failure-state integrity has no regression trap: every lifecycle step asserts returncode == 0 at tests/integration/test_gemini_agent_lifecycle.py
    invalid-update is a successful install that skips an agent; it proves stale cleanup, not integrity after a failed command.
    Suggested: Point the ref at a non-existent SHA, assert non-zero exit and unchanged deployed bytes and ledger rows.
    Proof (missing at): tests/integration/test_gemini_agent_lifecycle.py::test_gemini_agent_project_lifecycle (failed-update step) -- proves: If an install fails partway, the Gemini agents and lockfile records I already had stay exactly as they were. [portability-by-manifest,secure-by-default]
  • [recommended] The Gemini lifecycle test is not marked lifecycle_smoke, so no PR-time CI job runs it; it first runs in the merge_group hermetic integration shards at tests/integration/test_gemini_agent_lifecycle.py:31
    Precedent is mixed: test_kiro_agent_lifecycle.py has no smoke marker; test_kiro_prompt_lifecycle.py and test_opencode_v2_lifecycle.py do. The fail-before claim is credible from the exact frontmatter and ledger-row assertions.
    Suggested: Add pytest.mark.lifecycle_smoke to the project-scope test after checking its duration.
    Proof (unknown): tests/integration/test_gemini_agent_lifecycle.py::test_gemini_agent_project_lifecycle -- proves: The real apm binary keeps the deployed Gemini agent and lockfile in agreement across the lifecycle. [multi-harness-support,portability-by-manifest]

Supply Chain Security Expert

  • [recommended] Claude subagent hooks (for example PreToolUse deny guards) are silently dropped, so the deployed Gemini agent loses that guard at src/apm_cli/integration/agent_integrator.py:159
    A Claude agent that omits tools and relies on a hooks deny guard deploys with full session tools and no guard. Agents with Claude or Copilot tool names are already caught by is_gemini_agent_tool.
    Suggested: Add hooks to the rejected set, or switch to an allowlist that accepts known cosmetic keys and rejects any other, or at least warn per dropped key as Codex does.
    Proof (missing at): tests/unit/integration/test_gemini_agents.py -- proves: An agent whose source restricts tool use via hooks is never deployed to Gemini without that restriction. [secure-by-default,multi-harness-support]
  • [recommended] disable-model-invocation: true and Copilot infer: false are silently dropped, so Gemini can auto-delegate to an agent its author marked model-uninvocable at src/apm_cli/integration/agent_integrator.py:1218
    _warn_user_invocable_dropped covers only user-invocable / visibility.
    Suggested: Skip with a Fix: hint, or at minimum warn, when either is set.
  • [recommended] Lifecycle test does not check that Gemini trust and acknowledgement state is left untouched at tests/integration/test_gemini_agent_lifecycle.py
    No code path writes them today; a cheap absence or equality check traps a future pre-acknowledgement regression.
    Suggested: Assert ~/.gemini/trustedFolders.json and the acknowledgements store are absent or byte-identical across install, update and uninstall in both scopes.
    Proof (missing at): tests/integration/test_gemini_agent_lifecycle.py -- proves: Installing or updating Gemini agents never pre-trusts a folder or pre-acknowledges an agent. [secure-by-default]

Doc Writer

  • [recommended] The documented rejected-key list omits keys the code rejects (disallowed-tools, agent_card_url, agent_card_json, auth) and the discovered_tool_<name> and leading-underscore rules at docs/src/content/docs/reference/targets-matrix.md:240
    The reference page should match _GEMINI_AGENT_REJECTED_FIELDS.
    Suggested: Use one complete list in targets-matrix.md and package-authoring.md.
  • [recommended] Trim the targets-matrix Gemini Agents bullet (about 30 lines, 7 inline links) at docs/src/content/docs/reference/targets-matrix.md:227
    Length comes from upstream source-file links that are maintainer evidence, and one prose wall.
    Suggested: Split into 3-4 sub-bullets; keep the subagents, tools and configuration links and the folder-trust text; move agentLoader.ts, registry.ts, AppContainer.tsx links to the integrator comment.
  • [recommended] The producer guide Agents gotcha does not mention that Gemini skips the whole agent rather than dropping a field at docs/src/content/docs/producer/write-primitives.md:82
    A portable Claude-style agent (tools: [Read], model: sonnet) is not deployed to Gemini at all.
    Suggested: Replace the Codex sentence with one that also names the Gemini whole-agent skip and links the targets matrix.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
microsoft#4593)

Gemini's frontmatter regex allows a leading BOM and its z.number() schema
rejects NaN, so the preflight now parses through yaml_io.loads_frontmatter
(which strips the BOM, as the prompt and instruction integrators do) and
rejects a NaN temperature. Infinity stays accepted, as in Gemini.

The new test modules carry taxonomy markers and assert on-disk state; the
two pure-logic tests move to test_gemini_agent_rules.py (unit).
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
microsoft#4593)

Gemini's frontmatter regex allows a leading BOM and its z.number() schema
rejects NaN, so the preflight now parses through yaml_io.loads_frontmatter
(which strips the BOM, as the prompt and instruction integrators do) and
rejects a NaN temperature. Infinity stays accepted, as in Gemini.

The new test modules carry taxonomy markers and assert on-disk state; the
two pure-logic tests move to test_gemini_agent_rules.py (unit).
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

Dropping a key that restricts an agent, with no tools list, would give it
every Gemini session tool. An agent is now skipped with a warning when it
declares hooks, isolation, permissions or permission, or sets readonly:
true, disable-model-invocation: true, infer: false or disabled/disable:
true (Claude, Copilot, Cursor and OpenCode docs linked in the code).

Every other dropped key is named in a warning through a helper extracted
from the Codex renderer, whose messages are unchanged.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
Gemini identifies an agent by its 'name' while APM's collision and
adoption checks compare file paths, so code-review.md with name: reviewer
could shadow a user's reviewer.md unnoticed. Such an agent is now skipped
with a warning naming the expected file.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…rosoft#4593)

A package whose only agent is invalid leaves a .gemini tree holding only
settings.json byte-identical, with no agents directory. In the project and
-g installs the deployed agent is the only change under .gemini, so APM
never writes trustedFolders.json or Gemini's acknowledgement store.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…microsoft#4593)

The project lifecycle points the ref at a commit that does not exist,
expects a non-zero exit, and checks that the deployed agent and the
lockfile bytes are unchanged before restoring the valid ref.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…t#4593)

The targets matrix and apm-usage skill now carry one complete list of the
keys that skip an agent and the accepted tool forms, including the
restriction keys, the name-equals-stem rule and the leading-underscore
rule. The Gemini agents bullet is split into sub-bullets, upstream source
links move to the integrator comment, and the producer guide notes that
Gemini skips the whole agent rather than one field.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

The project-scope Gemini lifecycle is hermetic (local git, no network) and
takes about 4 s, so it now runs in the required PR-time job instead of only
in the merge-group shards.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

integrate_agents_for_target now calls a single _render_agent_for_target,
which picks the renderer by format_id and always returns (rendered or None,
links_resolved). The eager mkdir for copy and Codex targets is gone:
_deploy_rendered_agent creates the parent only when it writes, so a package
whose agents are all skipped leaves the target tree untouched.

The render-then-adopt guard now refuses mkdir() in the agent loop (with a
bypass mutation case), and the Codex link-resolution guard checks the new
dispatch point. This settles the shape before Antigravity adds a renderer.
@mohitmishra786

Mohit Mishra (mohitmishra786) commented Nov 21, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review. Every finding is addressed in this PR, one commit each; details below. Commits refer to the current head (rebased on main after #3714 and #4282; see the end).

CI failures listed under Recommendation (taxonomy tm006, AQ003 baseline) were fixed in 5cce5a9, before this panel ran on 7fcf617. Two differences from the panel's suggestion:

  • test_gemini_agents.py is component, not unit, because it writes under tmp_path, and pyproject.toml defines unit as "pure logic with no filesystem and no CLI". The two pure-logic tests moved to test_gemini_agent_rules.py (unit).
  • The promise markers are P-INV-I1, P-LAW-idempotency.byte_stable and req-tg-009, because those are what the tests assert. The ratchet's suggestions (P-OWN-distributed-agents-output-preparation, P-OWN-agent-plugin-package-projection) name unrelated owners.

1. Restriction-bearing keys (Python Architect, blocking; Supply Chain Security) -- 93b6944

An agent is now skipped with a Fix: warning when it declares a key whose loss would change what it may do. I checked each key against the harness's own docs instead of the panel's list:

Key Harness and doc Handling
hooks, isolation Claude Code subagents ("Lifecycle hooks scoped to this subagent"; isolation: worktree) skip if present
permissions, legacy permission OpenCode agents (ordered allow/ask/deny rules) skip if present
readonly: true Cursor subagents ("no file edits, no state-changing shell commands") skip at that value
disable-model-invocation: true, infer: false GitHub Copilot custom agents (infer is retired, same meaning) skip at that value
disabled: true, legacy disable: true OpenCode agents skip at that value

Two corrections to the panel's list:

  • disable-model-invocation is a Copilot agent key; the Claude docs mention it only for skills.
  • isolation (Claude) and OpenCode's current permissions / disabled were missing from the list and are now covered. OpenCode hidden is not, because its docs say it "controls visibility, not security".

The Codex dropped-field warning is now a shared _warn_dropped_fields helper. Codex messages are unchanged (its tests pass as before), and the Gemini preflight uses it, so every other dropped key is named in a warning.

Tests: each key in the rejection table, with no tools list (so a skipped key would otherwise give the agent every session tool); the non-restricting values (readonly: false, infer: true, ...) deploy with a dropped-key warning. 14 of these tests fail on the previous commit.

2. .gemini write set and trust/ack state (Test Coverage, Supply Chain Security) -- f1573ad

  • A new lifecycle scenario seeds only .gemini/settings.json and installs a package whose only agent is invalid. The .gemini tree stays byte-identical and no agents/ dir is created. I checked that it catches a regression by temporarily adding a mkdir before the preflight; it failed as expected.
  • In the project and -g installs, the deployed agent is the only change under .gemini, and trustedFolders.json and acknowledgments/ are absent.

3. Failed-command integrity (Test Coverage) -- 8696b82

The project lifecycle points the ref at 0000…, expects a non-zero exit with "No install transaction changes were committed", and checks that the deployed agent and the lockfile bytes are unchanged. It then restores the valid ref. The failure comes from the missing commit (reference is not a tree), not from anything incidental.

4. Name equals file stem (Python Architect) -- fce7d00

When name is set it must equal the file stem. Otherwise the agent is skipped with a warning naming the expected file (rename the source to reviewer.agent.md, or remove 'name'). A test covers the shadowing case: a package code-review.md with name: reviewer next to a user reviewer.md. The checks were also split into three helpers to stay inside the return-count limit.

5. Docs (Doc Writer) -- 2e8bb2e

  • targets-matrix.md and the apm-usage skill carry one complete list: every refused key, the accepted tool forms (including discovered_tool_<name>), name equals stem, and the leading-underscore rule.
  • The Gemini bullet is split into four sub-bullets. The subagents, tools and configuration links and the folder-trust wording are kept. The registry.ts / AppContainer.tsx references moved to the integrator comment.
  • producer/write-primitives.md now says Gemini skips the whole agent and links the target section.
  • The docs site build and the generated-link checker pass (897 links).

6. Lifecycle Smoke (Test Coverage) -- 908790c

test_gemini_agent_project_lifecycle is marked lifecycle_smoke. It is hermetic (local git, no network) and takes about 4 s. tests/quality/test_ci_topology.py passes.

7. Renderer shape (Python Architect) -- dcbd72d

Done here rather than in the Antigravity PR:

  • integrate_agents_for_target calls one _render_agent_for_target. It picks the renderer by format_id and always returns (rendered | None, links_resolved). Kiro goes through a thin adapter, so _preflight_render_kiro_agent and its callers are unchanged.
  • The eager mkdir for copy and Codex targets is gone; _deploy_rendered_agent creates the parent only when it writes. Behaviour change: a package whose agents are all skipped no longer leaves an empty agents directory for those targets either.
  • install-deployment-agent-render-then-adopt now refuses mkdir() in the agent loop, with a bypass mutation case. install-deployment-codex-agent-link-resolution checks the new dispatch point with the same conditions (resolve_links=self.resolve_links, result assigned to links_resolved).

Verification on the rebased head: ruff, the duplication check, auth-signal and architecture lint, and the complexity ratchet are clean. The tests/quality suite (including taxonomy and AQ003) passes, as do the architecture owner-rule and bypass mutation suites, the Gemini/Kiro/Codex/OpenCode/global-adoption agent lifecycle tests, and unit plus spec conformance. In my container the same environment-dependent tests fail as on unmodified main (test_unix_install_ownership.py, test_governance_evidence.py, test_shared_apm_workflow_contract.py, one test_token_manager_lifecycle.py case); none are touched by this PR.

Rebase on #3714: main now renders bundle agents to Codex TOML. Gemini bundle agents stay skipped (_UNSUPPORTED_PLUGIN_FORMAT_IDS = {"gemini_command", "gemini_agent"}), because the bundle path cannot run the Gemini validation. test_only_codex_agents_are_rendered_across_agent_targets therefore excludes gemini_agent, and a separate test checks the Gemini skip warnings. The apm-usage bundle sentence now says Codex agents are rendered and Gemini agents and commands are skipped (4d9fd40). The CHANGELOG line now mentions access restrictions (e90412c).

Rebase on #4282 (write seam): _deploy_rendered_agent keeps write_seam.mkdir, and the eager agent-loop mkdir that #4282 converted stays removed (7). The render-then-adopt guard still catches a write_seam.mkdir or Path.mkdir call in the loop. On the rebased head the full PR-time Lifecycle Smoke selection passes in my container (including test_m_source.py after #4619), except 12 installer-shell and JS-hook cases that fail identically on unmodified main there (no fish/zsh/node in the image).

Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
microsoft#4593)

Gemini's frontmatter regex allows a leading BOM and its z.number() schema
rejects NaN, so the preflight now parses through yaml_io.loads_frontmatter
(which strips the BOM, as the prompt and instruction integrators do) and
rejects a NaN temperature. Infinity stays accepted, as in Gemini.

The new test modules carry taxonomy markers and assert on-disk state; the
two pure-logic tests move to test_gemini_agent_rules.py (unit).
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

Dropping a key that restricts an agent, with no tools list, would give it
every Gemini session tool. An agent is now skipped with a warning when it
declares hooks, isolation, permissions or permission, or sets readonly:
true, disable-model-invocation: true, infer: false or disabled/disable:
true (Claude, Copilot, Cursor and OpenCode docs linked in the code).

Every other dropped key is named in a warning through a helper extracted
from the Codex renderer, whose messages are unchanged.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
Gemini identifies an agent by its 'name' while APM's collision and
adoption checks compare file paths, so code-review.md with name: reviewer
could shadow a user's reviewer.md unnoticed. Such an agent is now skipped
with a warning naming the expected file.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…rosoft#4593)

A package whose only agent is invalid leaves a .gemini tree holding only
settings.json byte-identical, with no agents directory. In the project and
-g installs the deployed agent is the only change under .gemini, so APM
never writes trustedFolders.json or Gemini's acknowledgement store.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…microsoft#4593)

The project lifecycle points the ref at a commit that does not exist,
expects a non-zero exit, and checks that the deployed agent and the
lockfile bytes are unchanged before restoring the valid ref.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…t#4593)

The targets matrix and apm-usage skill now carry one complete list of the
keys that skip an agent and the accepted tool forms, including the
restriction keys, the name-equals-stem rule and the leading-underscore
rule. The Gemini agents bullet is split into sub-bullets, upstream source
links move to the integrator comment, and the producer guide notes that
Gemini skips the whole agent rather than one field.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

The project-scope Gemini lifecycle is hermetic (local git, no network) and
takes about 4 s, so it now runs in the required PR-time job instead of only
in the merge-group shards.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Nov 21, 2026
…icrosoft#4593)

integrate_agents_for_target now calls a single _render_agent_for_target,
which picks the renderer by format_id and always returns (rendered or None,
links_resolved). The eager mkdir for copy and Codex targets is gone:
_deploy_rendered_agent creates the parent only when it writes, so a package
whose agents are all skipped leaves the target tree untouched.

The render-then-adopt guard now refuses mkdir() in the agent loop (with a
bypass mutation case), and the Codex link-resolution guard checks the new
dispatch point. This settles the shape before Antigravity adds a renderer.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…rosoft#4593)

A package whose only agent is invalid leaves a .gemini tree holding only
settings.json byte-identical, with no agents directory. In the project and
-g installs the deployed agent is the only change under .gemini, so APM
never writes trustedFolders.json or Gemini's acknowledgement store.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…microsoft#4593)

The project lifecycle points the ref at a commit that does not exist,
expects a non-zero exit, and checks that the deployed agent and the
lockfile bytes are unchanged before restoring the valid ref.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…t#4593)

The targets matrix and apm-usage skill now carry one complete list of the
keys that skip an agent and the accepted tool forms, including the
restriction keys, the name-equals-stem rule and the leading-underscore
rule. The Gemini agents bullet is split into sub-bullets, upstream source
links move to the integrator comment, and the producer guide notes that
Gemini skips the whole agent rather than one field.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…icrosoft#4593)

The project-scope Gemini lifecycle is hermetic (local git, no network) and
takes about 4 s, so it now runs in the required PR-time job instead of only
in the merge-group shards.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…icrosoft#4593)

integrate_agents_for_target now calls a single _render_agent_for_target,
which picks the renderer by format_id and always returns (rendered or None,
links_resolved). The eager mkdir for copy and Codex targets is gone:
_deploy_rendered_agent creates the parent only when it writes, so a package
whose agents are all skipped leaves the target tree untouched.

The render-then-adopt guard now refuses mkdir() in the agent loop (with a
bypass mutation case), and the Codex link-resolution guard checks the new
dispatch point. This settles the shape before Antigravity adds a renderer.
Mohit Mishra (mohitmishra786) added a commit to mohitmishra786/apm that referenced this pull request Dec 1, 2026
…ents (microsoft#4593)

After microsoft#3714 local bundle install renders packed Markdown agents to Codex
TOML, so the apm-usage sentence no longer says Codex agents are skipped;
Gemini agents and Gemini commands still are.
@mohitmishra786

Mohit Mishra (mohitmishra786) commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

Daniel Meppiel (@danielmeppiel) Rebased on main again after 0.39.1 and 0.39.2. The only conflict was the changelog, and the entry stays under [Unreleased]. There are no code changes since your last look. Lint, the architecture linter, the conformance regeneration and the unit suite pass locally on 454174a0e.

The CI runs on this fork PR are still waiting for approval, so none have run since the last rebase. Could you approve them, and let me know if anything needs changing before this can merge? I

Copilot AI 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.

🟡 Changes recommended

YAML serialization leaves numeric-looking strings such as 1e3 unquoted, causing Gemini to interpret them as numbers and reject the deployed agent.

1 open issue
2 resolved since last review

Review effort: Balanced

…ter (microsoft#2990)

Gemini CLI v0.70.0 loads local subagents from .gemini/agents/*.md and
~/.gemini/agents/*.md and rejects a file with any frontmatter key outside
its schema, so a verbatim copy does not load. The gemini_agent renderer
keeps only the schema keys, takes name from frontmatter or the file stem,
and skips (with a warning) an agent Gemini would reject or that APM cannot
carry without changing its access: foreign tool or model names,
agent-scoped MCP servers, disallowedTools, permissionMode, kind: remote.
It runs before any adopt check or write, like the Kiro preflight.

Local bundle installs skip Gemini agents, as they do Codex agents, since
they cannot run the renderer.
The Gemini rejection now names the approved tool set, as req-tg-009
requires, and a conformance test checks fail-closed before adopt with a
conformant sibling still deployed. CONFORMANCE.{md,json} regenerated.
microsoft#4593)

Gemini's frontmatter regex allows a leading BOM and its z.number() schema
rejects NaN, so the preflight now parses through yaml_io.loads_frontmatter
(which strips the BOM, as the prompt and instruction integrators do) and
rejects a NaN temperature. Infinity stays accepted, as in Gemini.

The new test modules carry taxonomy markers and assert on-disk state; the
two pure-logic tests move to test_gemini_agent_rules.py (unit).
…icrosoft#4593)

Dropping a key that restricts an agent, with no tools list, would give it
every Gemini session tool. An agent is now skipped with a warning when it
declares hooks, isolation, permissions or permission, or sets readonly:
true, disable-model-invocation: true, infer: false or disabled/disable:
true (Claude, Copilot, Cursor and OpenCode docs linked in the code).

Every other dropped key is named in a warning through a helper extracted
from the Codex renderer, whose messages are unchanged.
Gemini identifies an agent by its 'name' while APM's collision and
adoption checks compare file paths, so code-review.md with name: reviewer
could shadow a user's reviewer.md unnoticed. Such an agent is now skipped
with a warning naming the expected file.
…rosoft#4593)

A package whose only agent is invalid leaves a .gemini tree holding only
settings.json byte-identical, with no agents directory. In the project and
-g installs the deployed agent is the only change under .gemini, so APM
never writes trustedFolders.json or Gemini's acknowledgement store.
…microsoft#4593)

The project lifecycle points the ref at a commit that does not exist,
expects a non-zero exit, and checks that the deployed agent and the
lockfile bytes are unchanged before restoring the valid ref.
…t#4593)

The targets matrix and apm-usage skill now carry one complete list of the
keys that skip an agent and the accepted tool forms, including the
restriction keys, the name-equals-stem rule and the leading-underscore
rule. The Gemini agents bullet is split into sub-bullets, upstream source
links move to the integrator comment, and the producer guide notes that
Gemini skips the whole agent rather than one field.
…icrosoft#4593)

The project-scope Gemini lifecycle is hermetic (local git, no network) and
takes about 4 s, so it now runs in the required PR-time job instead of only
in the merge-group shards.
…icrosoft#4593)

integrate_agents_for_target now calls a single _render_agent_for_target,
which picks the renderer by format_id and always returns (rendered or None,
links_resolved). The eager mkdir for copy and Codex targets is gone:
_deploy_rendered_agent creates the parent only when it writes, so a package
whose agents are all skipped leaves the target tree untouched.

The render-then-adopt guard now refuses mkdir() in the agent loop (with a
bypass mutation case), and the Codex link-resolution guard checks the new
dispatch point. This settles the shape before Antigravity adds a renderer.
…ents (microsoft#4593)

After microsoft#3714 local bundle install renders packed Markdown agents to Codex
TOML, so the apm-usage sentence no longer says Codex agents are skipped;
Gemini agents and Gemini commands still are.
…microsoft#4593)

math.isnan() on an integer too large for a double raised OverflowError and
aborted the whole agent loop. Gemini's js-yaml reads such a value as a
string, which z.number() rejects, so the agent is now skipped with the
usual warning and its siblings still deploy. A 308-digit value, which
still fits a double and loads in Gemini v0.70.0, is kept.
…icrosoft#4593)

Gemini's z.number().int().positive() checks the value, so max_turns: 10.0
and timeout_mins: 5.0 load in Gemini v0.70.0 but were skipped because
Python parses them as floats. Both now pass when positive and integral.
The same check rejects a positive integer too large for a double, which
Gemini reads as a string and refuses; it was accepted before.
…icrosoft#4593)

verbatim_destinations returned None only for Kiro, the other agent format
that renders its output. Gemini agents are rendered too, so they now return
None as well. Today a Gemini target already replays live because it also
deploys commands, which the drift records do not map.
main takes changelog.d/<pr>.<section>.md fragments instead of lines under
[Unreleased]; the entry text is unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…oft#4593)

Gemini CLI reads agent frontmatter with js-yaml, a YAML 1.2 reader. It
reads plain 1e3, 1e-3 or 0o17 as numbers. PyYAML resolves them by YAML 1.1
rules as strings and so writes them unquoted. An agent named 1e3, or with
such a description or display_name, deployed but Gemini rejected it with
"Expected string, received number".

yaml_to_str gains an opt-in quote_strings mode that quotes every string
value and keeps keys, numbers and booleans plain. The Gemini renderer uses
it. Checked with loadAgentsFromDirectory from @google/gemini-cli-core
0.70.0: such agents now load and keep the exact string values.
…soft#4593)

Gemini now carries the agents primitive, so the harness conformance
contract generates HC-DEPLOY-01.agents cells for it at project and user
scope. Add test_hc_deploy_01_agents on the surface-witness Scene kit
(microsoft#5778): install checks the registry path, the lock row, the native
frontmatter and body, and emits the OBLIGATION receipt; uninstall emits
the absence receipt. List both cells as required in the ratchet.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

3 participants