Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演
JavaScript ai-artai-videochrome-extensionclaude-codecodexhiggsfieldjimenglocal-firstmcpmidjourneymoodboardprompt-engineeringprompt-libraryprompt-managerreference-libraryseedancevisual-bookmarksweb-clipper
import test from "node:test";
import assert from "node:assert/strict";
import {
AGENT_TASK_KEYS,
COMPOSER_AGENT_VERSION,
DEFAULT_AGENT_INSTRUCTION,
DEFAULT_TASK_METHODS,
DEFAULT_AGENT_INSTRUCTION_EN,
DEFAULT_TASK_METHODS_EN,
agentInstructionFor,
compileAgentAutoExecutionPrompt,
compileAgentExecutionPrompt,
compileAgentPlanningPrompt,
composerAssemblyLayers,
normalizeComposerAgentSettings,
taskMethodFor,
updateAgentTaskMethod,
updateAgentInstruction,
resetAgentInstruction,
resetAgentTaskMethod
} from "../extension/composer-agent.js";
test("light agent compiles routing, button questions, and local search without a dimension contract", () => {
const settings = normalizeComposerAgentSettings();
assert.equal(settings.agentVersion, COMPOSER_AGENT_VERSION);
assert.equal(settings.agentInstruction.text, DEFAULT_AGENT_INSTRUCTION);
assert.deepEqual(Object.keys(settings.taskMethods), [...AGENT_TASK_KEYS]);
const planning = compileAgentPlanningPrompt({ settings, routeMode: "auto", targetType: "video", outputLanguage: "en" });
for (const route of ["compose", "analyze_materials", "chat"]) assert.match(planning, new RegExp(`${route}:`));
assert.doesNotMatch(planning, /extract_project_method/);
assert.match(planning, /two to three|二到三个/);
assert.match(planning, /案例库查询由执行阶段的可用工具完成/);
assert.doesNotMatch(planning, /dimensionUses|conflicts|preserveMode|productionReview/);
const execution = compileAgentExecutionPrompt({ settings, route: "compose", targetType: "image", outputLanguage: "en", productionReviewEnabled: true });
assert.match(execution, /self-contained|自包含/);
assert.match(execution, /Visible facts/);
assert.match(execution, /use only the specified/);
assert.match(execution, /不要输出审核报告/);
assert.doesNotMatch(execution, /plan\.|dimensionUses|preservedFeatures/);
});
test("English defaults reach planning, execution and assembly without translating user edits", () => {
const settings = normalizeComposerAgentSettings();
for (const compile of [compileAgentPlanningPrompt, compileAgentExecutionPrompt, compileAgentAutoExecutionPrompt]) {
const prompt = compile({ settings, outputLanguage: "en", route: "compose", targetType: "video" });
assert.ok(prompt.includes(DEFAULT_AGENT_INSTRUCTION_EN));
assert.ok(prompt.includes(DEFAULT_TASK_METHODS_EN["compose.video"]));
assert.ok(!prompt.includes(DEFAULT_AGENT_INSTRUCTION));
}
const layers = composerAssemblyLayers({ settings, routeMode: "compose", outputLanguage: "en", targetType: "video" });
assert.equal(layers.find(item => item.id === "agent").content, DEFAULT_AGENT_INSTRUCTION_EN);
assert.equal(layers.find(item => item.id === "task").content, DEFAULT_TASK_METHODS_EN["compose.video"]);
for (const key of AGENT_TASK_KEYS) {
const [route, target] = key.split(".");
assert.equal(taskMethodFor(settings, route, target, "en"), DEFAULT_TASK_METHODS_EN[key]);
assert.equal(taskMethodFor(settings, route, target, "zh-CN"), DEFAULT_TASK_METHODS[key]);
}
const edited = updateAgentTaskMethod(updateAgentInstruction(settings, "用户写的系统指令"), "compose.video", "用户写的视频方法");
assert.equal(agentInstructionFor(edited, "en"), "用户写的系统指令");
assert.equal(taskMethodFor(edited, "compose", "video", "en"), "用户写的视频方法");
assert.equal(agentInstructionFor(resetAgentInstruction(edited), "en"), DEFAULT_AGENT_INSTRUCTION_EN);
assert.equal(taskMethodFor(resetAgentTaskMethod(edited, "compose.video"), "compose", "video", "en"), DEFAULT_TASK_METHODS_EN["compose.video"]);
});
test("saving unchanged English defaults keeps them language-aware after a storage round trip", () => {
const saved = normalizeComposerAgentSettings(JSON.parse(JSON.stringify(updateAgentTaskMethod(
updateAgentInstruction({}, DEFAULT_AGENT_INSTRUCTION_EN), "compose.image", DEFAULT_TASK_METHODS_EN["compose.image"]
))));
assert.equal(saved.agentInstruction.customized, false);
assert.equal(saved.taskMethods["compose.image"].customized, false);
assert.equal(agentInstructionFor(saved, "zh-CN"), DEFAULT_AGENT_INSTRUCTION);
assert.equal(taskMethodFor(saved, "compose", "image", "zh-CN"), DEFAULT_TASK_METHODS["compose.image"]);
assert.equal(agentInstructionFor(saved, "en"), DEFAULT_AGENT_INSTRUCTION_EN);
});
test("automatic execution chooses and completes one task in the same response", () => {
const prompt = compileAgentAutoExecutionPrompt({
settings: normalizeComposerAgentSettings(),
targetType: "video",
outputLanguage: "zh-CN",
productionReviewEnabled: true
});
assert.match(prompt, /第一行必须只输出.*\{"route":"compose\|analyze_materials\|chat","status":"ready\|needs_clarification"\}/s);
assert.match(prompt, /compose:/);
assert.match(prompt, /analyze_materials:/);
assert.match(prompt, /chat:/);
assert.match(prompt, /同一次响应/);
assert.match(prompt, /视频模型/);
assert.doesNotMatch(prompt, /suggestedTitle|librarySearch|隐藏推理/);
});
test("assembly inspector exposes the user request and explicit retrieval fact without hidden reasoning", () => {
const layers = composerAssemblyLayers({
settings: normalizeComposerAgentSettings(),
routeMode: "auto",
targetType: "image",
outputLanguage: "zh-CN",
userRequest: "参考雾夜角色,生成东方庭院提示词",
skills: "1. /国风视觉\n保持有根的视觉方向。",
references: "@参考1 手选原文\n\n@检索1 [guide] 教程原文",
retrieval: "已授权 · 查询:雾夜角色 · 采用 1 条来源",
expectedModelCalls: 1
});
assert.deepEqual(layers.map((item) => item.id), ["agent", "task", "user", "skills", "references", "retrieval", "runtime"]);
assert.match(layers.find((item) => item.id === "user").content, /东方庭院/);
assert.match(layers.find((item) => item.id === "skills").content, /国风视觉/);
assert.match(layers.find((item) => item.id === "references").content, /@参考1.*@检索1/s);
assert.match(layers.find((item) => item.id === "retrieval").content, /已授权.*雾夜角色/s);
assert.match(layers.find((item) => item.id === "runtime").content, /预计 1 次模型请求/);
});
test("legacy editable methods migrate without carrying the old harness schema", () => {
const untouched = normalizeComposerAgentSettings({ methods: {
image: { "zh-CN": { text: "旧默认中文", customized: false }, en: { text: "Old default English", customized: false } }
} });
assert.equal(untouched.taskMethods["compose.image"].text, DEFAULT_TASK_METHODS["compose.image"]);
const conflicting = normalizeComposerAgentSettings({ methods: {
image: {
"zh-CN": { text: "中文历史方法", customized: true },
en: { text: "English legacy method", customized: true }
}
} });
assert.equal(taskMethodFor(conflicting, "compose", "image", "zh-CN"), "中文历史方法");
assert.equal(taskMethodFor(conflicting, "compose", "image", "en"), "English legacy method");
const merged = updateAgentTaskMethod(conflicting, "compose.image", "Unified method");
assert.equal(merged.taskMethods["compose.image"].text, "Unified method");
assert.equal(merged.migrationCandidates["compose.image"], undefined);
});
test("editable instructions may intentionally be empty", () => {
const settings = normalizeComposerAgentSettings({
agentInstruction: { text: "" },
taskMethods: { chat: { text: "" } }
});
assert.equal(settings.agentInstruction.text, "");
assert.equal(taskMethodFor(settings, "chat", "image", "zh-CN"), "");
});
test("saved defaults follow the current agent version while customized instructions stay intact", () => {
const migrated = normalizeComposerAgentSettings({
agentInstruction: { text: "old default", customized: false, basedOnVersion: "3.0.0" },
taskMethods: { "compose.image": { text: "old default method", customized: false, basedOnVersion: "3.0.0" } }
});
assert.equal(migrated.agentInstruction.text, DEFAULT_AGENT_INSTRUCTION);
assert.equal(migrated.taskMethods["compose.image"].text, DEFAULT_TASK_METHODS["compose.image"]);
const customized = normalizeComposerAgentSettings({
agentInstruction: { text: "my instruction", customized: true, basedOnVersion: "3.0.0" }
});
assert.equal(customized.agentInstruction.text, "my instruction");
});