Skip to content

Commit 1f8daee

Browse files
fix(cli): health parses legacy routing tables without weakening missing-agent checks (preview.2 INT-1) (#2307)
* fix(cli): parse legacy routing tables in health Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 995eea17-c356-4912-90ea-5e5b144e7ba9 * fix(cli): merge mixed legacy routing sections Parse flattened compatibility sections alongside canonical routing tables while excluding rows already consumed by the normal table parser. Preserve source order and fail health when either section references an unknown agent. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 995eea17-c356-4912-90ea-5e5b144e7ba9 --------- Co-authored-by: B'Elanna (Squad) <tamirdresher@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 995eea17-c356-4912-90ea-5e5b144e7ba9
1 parent 75b15cf commit 1f8daee

12 files changed

Lines changed: 901 additions & 159 deletions

‎.changeset/kind-routes-health.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@bradygaster/squad-cli": patch
3+
"@bradygaster/squad-sdk": patch
4+
---
5+
6+
Accept documented legacy routing table headers, column orders, and the historical flattened long-table layout. `squad health` validates every parsed target against the team or casting registry, fails for missing targets and zero rules, and reports duplicate or conflicting work types as deterministic warnings.

‎packages/squad-cli/src/cli/commands/health.ts‎

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ function loadKnownRoutingAgentKeys(squadDir: string): Set<string> {
362362
);
363363
for (const agent of team.agents) {
364364
const key = normalizeAgentRef(agent.name);
365-
if (key.startsWith('@')) keys.add(key);
365+
if (key) keys.add(key);
366366
}
367367
// Built-ins are legitimate routing targets only while their installed charter exists. A route
368368
// to an unavailable built-in is a real configuration inconsistency and must fail health.
@@ -401,14 +401,23 @@ function checkRouting(squadDir: string): HealthCheckItem {
401401

402402
const unresolved = new Set<string>();
403403
const referenced = new Set<string>();
404-
const workTypes = new Set<string>();
405-
const duplicates = new Set<string>();
404+
const routeGroups = new Map<
405+
string,
406+
{ display: string; routes: Map<string, { agents: string[]; count: number }> }
407+
>();
406408

407409
for (const rule of parsed.rules) {
408410
const workType = rule.workType.trim().toLowerCase();
409-
if (workTypes.has(workType)) duplicates.add(rule.workType);
410-
workTypes.add(workType);
411-
411+
const normalizedAgents = rule.agents.map(normalizeAgentRef);
412+
const routeKey = normalizedAgents.join('\u0000');
413+
const group = routeGroups.get(workType) ?? {
414+
display: rule.workType,
415+
routes: new Map(),
416+
};
417+
const route = group.routes.get(routeKey);
418+
if (route) route.count++;
419+
else group.routes.set(routeKey, { agents: [...rule.agents], count: 1 });
420+
routeGroups.set(workType, group);
412421
}
413422

414423
const agentReferences =
@@ -423,19 +432,37 @@ function checkRouting(squadDir: string): HealthCheckItem {
423432
}
424433
}
425434

426-
const diagnostics = [
427-
...[...duplicates]
435+
const routeDiagnostics = [...routeGroups.values()]
436+
.filter(
437+
({ routes }) =>
438+
routes.size > 1 ||
439+
[...routes.values()].some(({ count }) => count > 1),
440+
)
441+
.sort((a, b) => a.display.localeCompare(b.display))
442+
.map(({ display, routes }) => {
443+
const rendered = [...routes.values()]
444+
.sort((a, b) => a.agents.join(', ').localeCompare(b.agents.join(', ')))
445+
.map(({ agents, count }) =>
446+
`${agents.join(', ')}${count > 1 ? ` (${count} rows)` : ''}`,
447+
)
448+
.join(' | ');
449+
return `${routes.size > 1 ? 'conflicting' : 'duplicate'} route: ${display} -> ${rendered}`;
450+
});
451+
const unresolvedDiagnostics = [...unresolved]
428452
.sort((a, b) => a.localeCompare(b))
429-
.map((workType) => `duplicate work type: ${workType}`),
430-
...[...unresolved]
431-
.sort((a, b) => a.localeCompare(b))
432-
.map((agent) => `unknown agent: ${agent}`),
433-
];
434-
if (diagnostics.length > 0) {
453+
.map((agent) => `unknown agent: ${agent}`);
454+
if (unresolvedDiagnostics.length > 0) {
435455
return fail(
436456
'routing',
437457
'routing.md contains invalid or unresolved references',
438-
diagnostics,
458+
[...routeDiagnostics, ...unresolvedDiagnostics],
459+
);
460+
}
461+
if (routeDiagnostics.length > 0) {
462+
return warnItem(
463+
'routing',
464+
`routing.md has ${parsed.rules.length} rules with duplicate or conflicting work types`,
465+
routeDiagnostics,
439466
);
440467
}
441468

0 commit comments

Comments
 (0)