3efebf8805
- agent-loop: raise repetition-detection floor to 180 chars and clear thinking replay anchors when collapsing a detected loop. - providers/google: ignore empty text parts, retain terminal thoughtSignatures, and stop function-call signatures clobbering the prior block. - autolearn: capture goal-mode at the turn boundary; harden managed-skill writes against hard-links/symlinks (O_NOFOLLOW + nlink); refuse minting managed skills whose name an authored skill already claims. - eager tasks: thread agentKind through the session so a custom top-level agentId still gets always-mode delegation; split Eager Tasks prompt into hard vs soft. - title-generator: race the online title model against a local tiny-model fallback. - eager-todo: keep the soft reminder aligned with the todo init schema. - mcp/stdio: keep close() detaching the read loop instead of awaiting it. - stream loop: fix collapsing and tool-call thought-signature handling.
90 lines
3.6 KiB
TypeScript
90 lines
3.6 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { AuthStorage } from "@oh-my-pi/pi-ai";
|
|
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";
|
|
import { ModelRegistry } from "@oh-my-pi/pi-coding-agent/config/model-registry";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
import type { AgentSession } from "@oh-my-pi/pi-coding-agent/session/agent-session";
|
|
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import { Snowflake } from "@oh-my-pi/pi-utils";
|
|
|
|
// Guards the auto-learn tool ACTIVATION wiring in createAgentSession: createTools
|
|
// force-includes manage_skill into the built registry for an enabled top-level
|
|
// session, but an explicit `toolNames` whitelist would otherwise drop it from the
|
|
// active set — so the SDK must re-activate it (mirroring the `yield` invariant),
|
|
// or the nudge/guidance would point at a tool the model cannot call. No memory
|
|
// backend is configured (manage_skill needs only `autolearn.enabled`), so the
|
|
// session starts without a heavy backend.
|
|
describe("createAgentSession auto-learn tool activation", () => {
|
|
let registryDir: string;
|
|
let authStorage: AuthStorage;
|
|
let modelRegistry: ModelRegistry;
|
|
const sessions: AgentSession[] = [];
|
|
|
|
beforeAll(async () => {
|
|
registryDir = path.join(os.tmpdir(), `pi-autolearn-active-${Snowflake.next()}`);
|
|
fs.mkdirSync(registryDir, { recursive: true });
|
|
authStorage = await AuthStorage.create(path.join(registryDir, "auth.db"));
|
|
modelRegistry = new ModelRegistry(authStorage);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
for (const session of sessions) await session.dispose().catch(() => {});
|
|
authStorage.close();
|
|
if (fs.existsSync(registryDir)) fs.rmSync(registryDir, { recursive: true, force: true });
|
|
});
|
|
|
|
async function activeToolNames(settings: Settings): Promise<string[]> {
|
|
const { session } = await createAgentSession({
|
|
cwd: registryDir,
|
|
agentDir: registryDir,
|
|
modelRegistry,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings,
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
toolNames: ["read"],
|
|
});
|
|
sessions.push(session);
|
|
return session.getActiveToolNames();
|
|
}
|
|
|
|
it("activates force-included manage_skill in a restricted top-level session", async () => {
|
|
const names = await activeToolNames(Settings.isolated({ "autolearn.enabled": true }));
|
|
expect(names).toContain("read");
|
|
// Built by createTools' force-include AND activated by the SDK's explicit-list
|
|
// re-inclusion, so guidance/controller point at a callable tool.
|
|
expect(names).toContain("manage_skill");
|
|
});
|
|
|
|
it("initializes the selected memory backend before an auto-learn session can run", async () => {
|
|
const { session } = await createAgentSession({
|
|
cwd: registryDir,
|
|
agentDir: registryDir,
|
|
modelRegistry,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings: Settings.isolated({
|
|
"autolearn.enabled": true,
|
|
"memory.backend": "hindsight",
|
|
"hindsight.apiUrl": "http://127.0.0.1:1",
|
|
"hindsight.mentalModelsEnabled": false,
|
|
}),
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
toolNames: ["read"],
|
|
});
|
|
sessions.push(session);
|
|
|
|
expect(session.getHindsightSessionState()).toBeDefined();
|
|
});
|
|
|
|
it("omits manage_skill from a restricted session when auto-learn is off", async () => {
|
|
const names = await activeToolNames(Settings.isolated({}));
|
|
expect(names).toContain("read");
|
|
expect(names).not.toContain("manage_skill");
|
|
});
|
|
});
|