mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 11:33:10 +00:00
refactor(setup): share Kiro agent selection (#15586)
This commit is contained in:
1 parent
14971020db
commit
5f226de4ae
2 files changed
+14
-30
No files matched your search
@@ -1067,8 +1067,8 @@ export const readEffectiveClientRegistrationConfiguration = async (
|
||||
sources.push(...upper);
|
||||
|
||||
if (client.name === "kiro" && project.mode !== "ownership") {
|
||||
const ambiguous = kiroAmbiguousAgentFailure(sources, client, platform);
|
||||
if (ambiguous !== undefined) return err(ambiguous);
|
||||
const agent = selectKiroAgentConfigurationPath(sources, client, platform);
|
||||
if (!agent.ok) return agent;
|
||||
}
|
||||
|
||||
const original = projectRegistration(sources, client, platform);
|
||||
@@ -1228,11 +1228,12 @@ const projectViewOfUserRegistration = (
|
||||
};
|
||||
};
|
||||
|
||||
const kiroAmbiguousAgentFailure = (
|
||||
/** Select the agent that defines REA, or report an ambiguous registration. */
|
||||
export const selectKiroAgentConfigurationPath = (
|
||||
sources: readonly ClientConfigurationSource[],
|
||||
client: Pick<SetupClient, "configPath">,
|
||||
platform: NodeJS.Platform,
|
||||
): ClientConfigurationFileError | undefined => {
|
||||
): Result<string | undefined, ClientConfigurationFileError> => {
|
||||
const distinctAgents = [
|
||||
...new Set(
|
||||
sources.flatMap((source) => {
|
||||
@@ -1248,13 +1249,13 @@ const kiroAmbiguousAgentFailure = (
|
||||
}),
|
||||
),
|
||||
];
|
||||
if (distinctAgents.length <= 1) return undefined;
|
||||
return {
|
||||
if (distinctAgents.length <= 1) return ok(distinctAgents[0]);
|
||||
return err({
|
||||
kind: "malformed",
|
||||
path: distinctAgents[0] ?? client.configPath,
|
||||
scope: "user",
|
||||
detail: `Kiro defines ${PRODUCT_IDENTITY.mcpServerKey} in more than one agent file (${distinctAgents.join(", ")}). Kiro loads the selected agent, so the registration stays unchanged until one agent file defines it.`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const readEffectiveUserConfiguration = async (
|
||||
@@ -1271,12 +1272,12 @@ const readEffectiveUserConfiguration = async (
|
||||
);
|
||||
if (!nativeSources.ok) return nativeSources;
|
||||
if (client.name === "kiro") {
|
||||
const ambiguous = kiroAmbiguousAgentFailure(
|
||||
const agent = selectKiroAgentConfigurationPath(
|
||||
nativeSources.value,
|
||||
client,
|
||||
platform,
|
||||
);
|
||||
if (ambiguous !== undefined) return err(ambiguous);
|
||||
if (!agent.ok) return agent;
|
||||
}
|
||||
const nativeDocument = mergeClientConfigurationDocuments(
|
||||
nativeSources.value,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { readClientPolicyBlock } from "./GeminiClientSettings.js";
|
||||
import {
|
||||
readClientConfigurationFiles,
|
||||
selectKiroAgentConfigurationPath,
|
||||
inlineRegistrationEnvironment,
|
||||
inlineRegistrationOrigins,
|
||||
inlineCaution,
|
||||
@@ -16,7 +17,6 @@ import {
|
||||
} from "./ClientConfigurationFiles.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { ConfigurationError } from "../domain/configurationErrors.js";
|
||||
import { isKiroAgentConfigurationPath } from "./SupportedClientLocations.js";
|
||||
import {
|
||||
effectiveClientServer,
|
||||
clientServerListedDisabled,
|
||||
@@ -129,26 +129,9 @@ const kiroRegistrationClient = async (
|
||||
throwCleanupFailure(files.error);
|
||||
return err(files.error.detail);
|
||||
}
|
||||
const agents = [
|
||||
...new Set(
|
||||
files.value.flatMap((source) => {
|
||||
if (
|
||||
source.sourcePath === undefined ||
|
||||
!isKiroAgentConfigurationPath(source.sourcePath, platform)
|
||||
)
|
||||
return [];
|
||||
return effectiveClientServer(source, PRODUCT_IDENTITY.mcpServerKey) ===
|
||||
undefined
|
||||
? []
|
||||
: [source.sourcePath];
|
||||
}),
|
||||
),
|
||||
];
|
||||
if (agents.length > 1)
|
||||
return err(
|
||||
`Kiro defines ${PRODUCT_IDENTITY.mcpServerKey} in more than one agent file (${agents.join(", ")}). Kiro loads the selected agent, so the registration stays unchanged until one agent file defines it.`,
|
||||
);
|
||||
const target = agents[0] ?? client.configPath;
|
||||
const agent = selectKiroAgentConfigurationPath(files.value, client, platform);
|
||||
if (!agent.ok) return err(agent.error.detail);
|
||||
const target = agent.value ?? client.configPath;
|
||||
return ok(
|
||||
target === client.configPath &&
|
||||
(client.configPaths === undefined ||
|
||||
|
||||
Reference in new issue
Block a user