feat(FN-3612): preserve fusion context in hermes runtime skill forwarding
Merges five commits implementing centralized runtime skill forwarding that preserves Fusion context across the Hermes runtime layer. The engine's `agent-runtime` and `agent-session-helpers` were updated to forward skills at runtime, with `runtime-adapter.ts` and its types extended to carry context. Fusion-Task-Id: FN-3612
This commit is contained in:
@@ -165,6 +165,41 @@ describe("Hermes runtime integration via engine resolution pipeline", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("forwards skillSelection.requestedSkillNames as runtime skills for plugin runtimes", async () => {
|
||||
const hermesCreateSession = vi.fn().mockResolvedValue({
|
||||
session: { runtime: "hermes", prompt: vi.fn() },
|
||||
sessionFile: "/tmp/hermes.session.json",
|
||||
});
|
||||
const hermesRegistration = createHermesRegistration(() => ({
|
||||
id: "hermes",
|
||||
name: "Hermes Runtime",
|
||||
createSession: hermesCreateSession,
|
||||
promptWithFallback: vi.fn().mockResolvedValue(undefined),
|
||||
describeModel: vi.fn().mockReturnValue("anthropic/claude-sonnet-4-5"),
|
||||
}));
|
||||
|
||||
const pluginRunner = createMockPluginRunner({
|
||||
getRuntimeById: vi.fn().mockReturnValue(hermesRegistration),
|
||||
});
|
||||
|
||||
await createResolvedAgentSession({
|
||||
sessionPurpose: "executor",
|
||||
runtimeHint: "hermes",
|
||||
pluginRunner,
|
||||
cwd: "/tmp/project",
|
||||
systemPrompt: "You are helpful",
|
||||
skillSelection: {
|
||||
projectRootDir: "/tmp/project",
|
||||
requestedSkillNames: ["fusion"],
|
||||
sessionPurpose: "executor",
|
||||
},
|
||||
});
|
||||
|
||||
expect(hermesCreateSession).toHaveBeenCalledWith(expect.objectContaining({
|
||||
skills: ["fusion"],
|
||||
}));
|
||||
});
|
||||
|
||||
it("falls back to default pi runtime when Hermes factory throws", async () => {
|
||||
const hermesRegistration = createHermesRegistration(() => {
|
||||
throw new Error("factory exploded");
|
||||
|
||||
@@ -22,6 +22,13 @@ import type { FallbackModelUsedPayload } from "./pi.js";
|
||||
* Options for creating an agent session.
|
||||
* Mirrors the options accepted by createFnAgent.
|
||||
*/
|
||||
export interface AgentRuntimeContext {
|
||||
sessionPurpose?: string;
|
||||
toolMode?: "coding" | "readonly";
|
||||
customToolNames?: string[];
|
||||
requestedSkillNames?: string[];
|
||||
}
|
||||
|
||||
export interface AgentRuntimeOptions {
|
||||
/** Working directory for the agent session */
|
||||
cwd: string;
|
||||
@@ -55,6 +62,8 @@ export interface AgentRuntimeOptions {
|
||||
skillSelection?: SkillSelectionContext;
|
||||
/** Convenience: skill names to include in the session */
|
||||
skills?: string[];
|
||||
/** Runtime-facing context for non-pi runtimes that cannot consume JS ToolDefinition objects directly. */
|
||||
runtimeContext?: AgentRuntimeContext;
|
||||
/**
|
||||
* Last-chance abort hook fired by the runtime *immediately before* the
|
||||
* underlying LLM session is instantiated — i.e., after all of the runtime's
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
import type { AgentRuntimeOptions } from "./agent-runtime.js";
|
||||
import type { SkillSelectionContext } from "./skill-resolver.js";
|
||||
import type { PluginRunner } from "./plugin-runner.js";
|
||||
import type { AgentSession } from "@mariozechner/pi-coding-agent";
|
||||
import { resolveRuntime, buildRuntimeResolutionContext, type SessionPurpose } from "./runtime-resolution.js";
|
||||
@@ -17,6 +18,16 @@ import { promptWithFallback, describeModel } from "./pi.js";
|
||||
/** Logger for agent session helpers */
|
||||
const sessionLog = createLogger("agent-session");
|
||||
|
||||
function extractSkillNamesFromSelection(skillSelection: SkillSelectionContext | undefined): string[] {
|
||||
if (!skillSelection || !Array.isArray(skillSelection.requestedSkillNames)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return skillSelection.requestedSkillNames
|
||||
.map((name) => (typeof name === "string" ? name.trim() : ""))
|
||||
.filter((name) => name.length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for creating an agent session with runtime resolution.
|
||||
*/
|
||||
@@ -115,7 +126,17 @@ export function extractRuntimeModel(
|
||||
export async function createResolvedAgentSession(
|
||||
options: ResolvedSessionOptions,
|
||||
): Promise<ResolvedSessionResult> {
|
||||
const { sessionPurpose, pluginRunner, runtimeHint, ...runtimeOptions } = options;
|
||||
const { sessionPurpose, pluginRunner, runtimeHint, ...runtimeOptionsRaw } = options;
|
||||
|
||||
const skillNamesFromSelection = extractSkillNamesFromSelection(runtimeOptionsRaw.skillSelection);
|
||||
const mergedSkillNames = runtimeOptionsRaw.skills && runtimeOptionsRaw.skills.length > 0
|
||||
? runtimeOptionsRaw.skills
|
||||
: skillNamesFromSelection;
|
||||
|
||||
const runtimeOptions: AgentRuntimeOptions = {
|
||||
...runtimeOptionsRaw,
|
||||
...(mergedSkillNames.length > 0 ? { skills: mergedSkillNames } : {}),
|
||||
};
|
||||
|
||||
// Build the resolution context
|
||||
const context = buildRuntimeResolutionContext(sessionPurpose, pluginRunner, runtimeHint);
|
||||
|
||||
Reference in New Issue
Block a user