Repository navigation
Commit c102bec
fix(init): read agent-name bindings the way Python does, or decline
Addresses the six blocking review findings on #371. Each was reproduced
against the pre-fix code before being fixed, and each fix has a test that
fails without it.
The ranking shipped in the previous commit read Python name binding with a
flattened `ast.walk` and first-write-wins heuristics, which produced
misleading `agent.name` values in several statically reproducible cases —
including the fail-closed case #324 explicitly requires.
**An unresolved application root now blocks selection entirely.** With
`root_agent = LlmAgent(name=f"{tier}-coordinator", sub_agents=[worker])`,
detection dropped the root and wrote `agent.name: WorkerAgent`. Letting the
rest of the field rank looks conservative, but everything remaining is by
construction *not* the root, so it silently declares a worker as the
reviewed identity. A dynamic name, a factory call such as
`App(root_agent=build_root())`, or a symbol no single construction defines
now all produce CHANGE_ME plus the reason. The previous test asserted the
old behaviour and is replaced — it encoded the bug.
The block is deliberately workspace-wide rather than scoped to the file
that declares the unresolved root. Scoping it would let a resolved root
elsewhere win, which is precisely the class of "assert an identity we
cannot justify" this PR exists to remove.
**References resolve to the reaching assignment.** For
`agent = Agent(name="OldWorker"); agent = Agent(name="ActualRoot");
App(root_agent=agent)`, both constructions were classified as roots and
source order picked the overwritten one. Bindings are now matched by
nearest scope then latest line before the reference.
**Scopes are no longer flattened.** A function-local `root_agent` was
promoted to application root and outranked every real module-level agent;
the ADK convention is about the *module* symbol `adk run` imports. A
helper-local `from other import AGENT_NAME` could likewise supply the value
a module-level construction reads from a different module. Imports are now
keyed by scope, and `from config import AGENT_NAME as NAME` looks up
`AGENT_NAME` in the target module rather than the alias.
**Constants require exactly one binding.** `setdefault` made
`NAME = "OldAgent"; NAME = "CurrentAgent"` resolve to `OldAgent`, a value
Python never passes, and a conditional or computed later write was ignored
rather than triggering the promised fail-closed result. A symbol bound more
than once anywhere in the file — later, conditional, computed, in another
scope, or as a parameter — is now never resolved. That single rule is what
makes reading module-level constants safe at all.
**Conflicting import roots leave the identity unresolved.** `from config
import AGENT_NAME` resolves against the agent directory or the workspace
root depending on `sys.path`; when both exist in-workspace and disagree,
which one Python picks is not ours to assume. Package `__init__.py` now
also precedes the module file, matching Python's own finder.
**Child edges require a verified agent constructor.** The `sub_agents=` /
`handoffs=` branch ran for any call, so `configure(handoffs=[coordinator])`
demoted the coordinator and handed the identity to an unrelated worker.
**The zero-install byte-parity claim now holds.** It did not: the script
walked the filesystem while canonical detection lists through Git, so a
`.gitignore`d module could win a ranking `init` can never produce, and a
Python symlink escaping the workspace both contributed a name and leaked
its outside absolute path into `path`. Both reproduced. The script now uses
the same bounded `git ls-files` inventory when Git can read the workspace,
containment-checks every fallback-walk path, and bounds Python *parses*
rather than the whole inventory — a global file cap let an asset-heavy
repository exhaust its budget before reaching any source. Three parity
tests cover the three cases and all three fail on the previous script.
Two consistency fixes from the review body:
- `cli/detect.py` printed candidate zero rather than calling
`select_agent_name`, so with only `Agent(name="t")` the human-readable
`detect` reported `t` while `init` wrote CHANGE_ME. It now reports what
`init` will write, and prints the rejection reasons when nothing is
selectable. That was the fourth copy of the selection rule.
- `docs/agent-recipes.md` claimed `project_name_candidates[]` shares the
enriched shape; it remains `{value, source}`.
Sample selections are unchanged, and both originally reported repositories
still resolve correctly (`Strix`, `SmartCloserAgent`).
Co-Authored-By: Claude Opus 5 <[email protected]>1 parent b8b5bac commit c102bec
9 files changed
Lines changed: 1060 additions & 140 deletions
File tree
- docs
- src/agents_shipgate/cli
- discovery
- tests
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
40 | 73 | | |
41 | 74 | | |
42 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
846 | 852 | | |
847 | 853 | | |
848 | 854 | | |
849 | 855 | | |
850 | | - | |
851 | | - | |
852 | | - | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
853 | 863 | | |
854 | 864 | | |
855 | 865 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
122 | 136 | | |
123 | 137 | | |
124 | 138 | | |
| |||
0 commit comments