Tracked in Linear: CLI-2
Summary
kbagent project use <alias> sets a persistent default project. It writes config.default_project. Several read commands do not read that default. They use the first registered project instead. The command then acts on the wrong project, and the user gets no warning.
Found on kbagent 0.90.1.
Reproduce
- Register two or more projects. The first row of
kbagent project list must not be the project you want.
- Run
kbagent project use <wanted-alias>.
- Confirm
kbagent project list shows the default star on <wanted-alias>.
- Run
kbagent kai preflight without --project.
Result: the command reports the first project, not the pinned one.
Example: the pin was on an internal test project (id 4214). kai preflight reported a different internal test project (id 5011), which is the first row of project list.
Root cause (found — please verify)
kbagent has two project resolvers.
The correct one is resolve_project_alias in commands/_helpers.py:214. Its cascade is:
- explicit
--project
- env override (
ENV_PROJECT_ALIAS)
- the
config.default_project pin from project use
- the single-project shortcut
The kai path does not use it. KaiService.resolve_alias (services/kai_service.py:32) returns next(iter(projects)) when the alias is None. That value is the first registered project. It never reads config.default_project. The inline comment reads "Fall back to default (first project)", which conflates "default" with "first".
Same defect in other commands (found)
The same next(iter(projects)) shortcut selects the project here:
services/kai_service.py:52 — kai ping, kai preflight, kai ask, kai chat
services/docs_service.py:59 — docs query
services/component_service.py:591 — component detail
services/component_service.py:783 — component search
All four ignore the project use pin. Each acts on the first registered project.
Not a defect (leave alone)
These next(iter(...)) uses set or repoint the pin. They are correct.
config_store.py:464, config_store.py:642, commands/init.py:205 — repoint default_project when the current one becomes invalid.
config_store.py:802 — the same, for the dev-portal identity.
Scope
-
Fix the four sites. Make each honor config.default_project. Prefer routing through the shared resolve_project_alias cascade over a second copy of the logic.
-
Verify the root cause above.
-
Audit every project-selection site in kbagent. For each command group, check the no---project path. It must reach the shared cascade, not a local shortcut. Confirm these in particular:
services/snapshot_service.py:253
services/token_service.py:224
services/stream_service.py:211
Each has a _resolve_project(alias) with a required alias. Check that the command layer resolves the alias through the shared cascade before the call.
-
Add a regression test. Register two projects. Pin the second with project use. Run a no---project command. Assert it acts on the pinned project.
Workaround (until fixed)
Pass the alias explicitly.
kbagent kai preflight --project <alias>
Tracked in Linear: CLI-2
Summary
kbagent project use <alias>sets a persistent default project. It writesconfig.default_project. Several read commands do not read that default. They use the first registered project instead. The command then acts on the wrong project, and the user gets no warning.Found on kbagent 0.90.1.
Reproduce
kbagent project listmust not be the project you want.kbagent project use <wanted-alias>.kbagent project listshows the default star on<wanted-alias>.kbagent kai preflightwithout--project.Result: the command reports the first project, not the pinned one.
Example: the pin was on an internal test project (id 4214).
kai preflightreported a different internal test project (id 5011), which is the first row ofproject list.Root cause (found — please verify)
kbagent has two project resolvers.
The correct one is
resolve_project_aliasincommands/_helpers.py:214. Its cascade is:--projectENV_PROJECT_ALIAS)config.default_projectpin fromproject useThe kai path does not use it.
KaiService.resolve_alias(services/kai_service.py:32) returnsnext(iter(projects))when the alias isNone. That value is the first registered project. It never readsconfig.default_project. The inline comment reads "Fall back to default (first project)", which conflates "default" with "first".Same defect in other commands (found)
The same
next(iter(projects))shortcut selects the project here:services/kai_service.py:52—kai ping,kai preflight,kai ask,kai chatservices/docs_service.py:59—docs queryservices/component_service.py:591—component detailservices/component_service.py:783—component searchAll four ignore the
project usepin. Each acts on the first registered project.Not a defect (leave alone)
These
next(iter(...))uses set or repoint the pin. They are correct.config_store.py:464,config_store.py:642,commands/init.py:205— repointdefault_projectwhen the current one becomes invalid.config_store.py:802— the same, for the dev-portal identity.Scope
Fix the four sites. Make each honor
config.default_project. Prefer routing through the sharedresolve_project_aliascascade over a second copy of the logic.Verify the root cause above.
Audit every project-selection site in kbagent. For each command group, check the no-
--projectpath. It must reach the shared cascade, not a local shortcut. Confirm these in particular:services/snapshot_service.py:253services/token_service.py:224services/stream_service.py:211Each has a
_resolve_project(alias)with a required alias. Check that the command layer resolves the alias through the shared cascade before the call.Add a regression test. Register two projects. Pin the second with
project use. Run a no---projectcommand. Assert it acts on the pinned project.Workaround (until fixed)
Pass the alias explicitly.
kbagent kai preflight --project <alias>