clanker-agent/packages/coding-agent/test/agent-session-dynamic-tools.test.ts
Harivansh Rathi 67168d8289 chore: rebrand companion-os to clanker-agent
- Rename all package names from companion-* to clanker-*
- Update npm scopes from @mariozechner to @harivansh-afk
- Rename config directories .companion -> .clanker
- Rename environment variables COMPANION_* -> CLANKER_*
- Update all documentation, README files, and install scripts
- Rename package directories (companion-channels, companion-grind, companion-teams)
- Update GitHub URLs to harivansh-afk/clanker-agent
- Preserve full git history from companion-cloud monorepo
2026-03-26 16:22:52 -04:00

90 lines
2.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { existsSync, mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { getModel } from "@mariozechner/clanker-ai";
import { Type } from "@sinclair/typebox";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { DefaultResourceLoader } from "../src/core/resource-loader.js";
import { createAgentSession } from "../src/core/sdk.js";
import { SessionManager } from "../src/core/session-manager.js";
import { SettingsManager } from "../src/core/settings-manager.js";
describe("AgentSession dynamic tool registration", () => {
let tempDir: string;
let agentDir: string;
beforeEach(() => {
tempDir = join(
tmpdir(),
`clanker-dynamic-tool-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
);
agentDir = join(tempDir, "agent");
mkdirSync(agentDir, { recursive: true });
});
afterEach(() => {
if (tempDir && existsSync(tempDir)) {
rmSync(tempDir, { recursive: true, force: true });
}
});
it("refreshes tool registry when tools are registered after initialization", async () => {
const settingsManager = SettingsManager.create(tempDir, agentDir);
const sessionManager = SessionManager.inMemory();
const resourceLoader = new DefaultResourceLoader({
cwd: tempDir,
agentDir,
settingsManager,
extensionFactories: [
clanker => {
clanker.on("session_start", () => {
clanker.registerTool({
name: "dynamic_tool",
label: "Dynamic Tool",
description: "Tool registered from session_start",
promptSnippet: "Run dynamic test behavior",
promptGuidelines: [
"Use dynamic_tool when the user asks for dynamic behavior tests.",
],
parameters: Type.Object({}),
execute: async () => ({
content: [{ type: "text", text: "ok" }],
details: {},
}),
});
});
},
],
});
await resourceLoader.reload();
const { session } = await createAgentSession({
cwd: tempDir,
agentDir,
model: getModel("anthropic", "claude-sonnet-4-5")!,
settingsManager,
sessionManager,
resourceLoader,
});
expect(session.getAllTools().map((tool) => tool.name)).not.toContain(
"dynamic_tool",
);
await session.bindExtensions({});
expect(session.getAllTools().map((tool) => tool.name)).toContain(
"dynamic_tool",
);
expect(session.getActiveToolNames()).toContain("dynamic_tool");
expect(session.systemPrompt).toContain(
"- dynamic_tool: Run dynamic test behavior",
);
expect(session.systemPrompt).toContain(
"- Use dynamic_tool when the user asks for dynamic behavior tests.",
);
session.dispose();
});
});