mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-16 15:18:07 +00:00
* plan: mcp-activity * plan: mcp-activity list format * plan: mcp-activity answers and live step lines * mcp: a silent line per step of Claude's work, completed at its end * plan: mcp-activity as implemented * mcp: finalize step lines within a day and load only the hook's modules * plan: mcp-activity review decisions as implemented * plan: mcp-live-answers * plan: mcp-live-answers answers and the end line with the usage * plan: mcp-live-answers end line with the plan usage, shared fast request * plan: mcp-live-answers keeps tokens in context * mcp: end live step lines by the wall clock * mcp: exact spec ranges and measured hook load time * mcp: Claude's answers live as Claude writes them, and one end line per turn A prompt that starts a turn gets an empty silent live message, which the turn's first text, step or answer fills. The MessageDisplay hook, dist/display.js, passes each batch of Claude's text to the service, and the hub streams each text into a silent live message, updated at most every 3 s and finalized at its end. At Stop the streamed answer is claimed, or the answer is posted silent, and the end line !- ✅ Done in DURATION! follows as the turn's only alert. * plan: mcp-live-answers as implemented * mcp: one refusal post for a refused answer, in the turn's opening message A text that a group preference refuses counts as the answer at Stop, so the answer is not posted again. A refused post that would fill the opening message fills it with its refusal text. A refused text ends at once, also when it outgrows a message, and an update scheduled before its end is skipped. Plan decision 37. * mcp: live posts survive a lost opening message and end within a day A failed update of the opening message drops it, and the post is sent as a new message; a text that was never posted no longer stands for the answer. Texts and opening messages end 23 hours after their send by the wall clock, as steps do. When the update with a refusal fails too, the opening message gets ⏹️ Stopped and the end line follows. The opening message is kept before User's post and sent after it. * mcp: a dropped opening message ends with ⏹️ Stopped When the update of the opening message fails without a refusal, the hub finalizes it, so after a transient failure it does not stay live.
75 lines
4.6 KiB
TypeScript
75 lines
4.6 KiB
TypeScript
import {spawn} from "child_process"
|
|
import {readFileSync} from "fs"
|
|
import {join} from "path"
|
|
import {configVariables, defaultConfig} from "../../src/config"
|
|
|
|
const read = (file: string): any => JSON.parse(readFileSync(join(__dirname, "../..", file), "utf8"))
|
|
const packageJson = read("package.json")
|
|
const cli = (args: string): string => `node "\${CLAUDE_PLUGIN_ROOT}/dist/cli.js" ${args}`
|
|
|
|
describe("plugin", () => {
|
|
it("has the package version and the config defaults", () => {
|
|
const plugin = read(".claude-plugin/plugin.json")
|
|
expect(plugin.name).toBe("simplex")
|
|
expect(plugin.version).toBe(packageJson.version)
|
|
expect(plugin.userConfig.main_group.default).toBe(defaultConfig.mainGroup)
|
|
expect(plugin.userConfig.approve.default).toBe(defaultConfig.approve)
|
|
expect(plugin.userConfig.approve.description).toBe("requests: you approve connections and messages in the SimpleX app. host: Claude Code asks you instead, after an admin or owner approves this in the session's group.")
|
|
expect(plugin.userConfig.expire_hours.default).toBe(defaultConfig.expireHours)
|
|
expect(Object.keys(plugin.userConfig)).toEqual(["main_group", "approve", "expire_hours"])
|
|
})
|
|
|
|
it("starts the session server of the plugin's own build with the options as variables", () => {
|
|
const {simplex} = read(".mcp.json").mcpServers
|
|
expect(simplex.command).toBe("node")
|
|
expect(simplex.args).toEqual(["${CLAUDE_PLUGIN_ROOT}/dist/cli.js", "session"])
|
|
expect(simplex.env).toEqual({
|
|
[configVariables.mainGroup]: "${user_config.main_group}",
|
|
[configVariables.approve]: "${user_config.approve}",
|
|
[configVariables.expireHours]: "${user_config.expire_hours}",
|
|
})
|
|
})
|
|
|
|
it("lets a tool call wait for the longest expiry, the responses and a margin", () => {
|
|
const responseWaitHours = 24
|
|
const marginMs = 10 * 60_000
|
|
const maxExpireHours = read(".claude-plugin/plugin.json").userConfig.expire_hours.max
|
|
expect(maxExpireHours).toBe(23)
|
|
expect(read(".mcp.json").mcpServers.simplex.timeout).toBe((maxExpireHours + responseWaitHours) * 3_600_000 + marginMs)
|
|
})
|
|
|
|
it("runs the hooks from the plugin's own build, allows the plugin's tools, runs the turn hook at the start and the end of every tool use and after each compaction, asks the session server before every tool use whether its tool is approved, and runs the display hook synchronously for MessageDisplay", () => {
|
|
const {hooks} = read("hooks/hooks.json")
|
|
expect(hooks.SessionStart[0].hooks[0]).toEqual({type: "command", command: cli("hook session-start"), timeout: 600})
|
|
expect(hooks.PreToolUse[0].matcher).toBe("mcp__plugin_simplex_simplex__.*")
|
|
expect(hooks.PreToolUse[0].hooks[0]).toEqual({type: "command", command: 'node "${CLAUDE_PLUGIN_ROOT}/plugin/allow.js"'})
|
|
for (const event of ["UserPromptSubmit", "Stop", "PostModelSwitch", "PostCompact"]) expect(hooks[event]).toEqual([{hooks: [{type: "command", command: cli("hook turn"), async: true}]}])
|
|
const steps = {matcher: "*", hooks: [{type: "command", command: cli("hook turn"), async: true}]}
|
|
expect(hooks.PreToolUse[1]).toEqual({...steps, hooks: [...steps.hooks, {type: "mcp_tool", server: "plugin:simplex:simplex", tool: "pre_tool_use", input: {tool: "${tool_name}"}, timeout: 5}]})
|
|
for (const event of ["PostToolUse", "PostToolUseFailure"]) expect(hooks[event]).toEqual([steps])
|
|
expect(hooks.MessageDisplay).toEqual([{hooks: [{type: "command", command: 'node "${CLAUDE_PLUGIN_ROOT}/dist/display.js"', timeout: 2}]}])
|
|
})
|
|
|
|
it("ships the build, its bundled dependencies and the plugin files in the package, without a lockfile", () => {
|
|
expect(packageJson.files).toEqual(["dist", "README.md", ".claude-plugin", ".mcp.json", "hooks", "plugin"])
|
|
expect(packageJson.bundleDependencies).toBe(true)
|
|
})
|
|
|
|
it("allows a tool call", async () => {
|
|
const stdout = await new Promise<string>((resolve, reject) => {
|
|
const child = spawn(process.execPath, [join(__dirname, "../../plugin/allow.js")], {stdio: ["ignore", "pipe", "inherit"]})
|
|
let text = ""
|
|
child.stdout.on("data", chunk => (text += chunk))
|
|
child.on("error", reject)
|
|
child.on("close", () => resolve(text))
|
|
})
|
|
expect(JSON.parse(stdout)).toEqual({hookSpecificOutput: {hookEventName: "PreToolUse", permissionDecision: "allow"}})
|
|
})
|
|
|
|
it("lists the plugin in the marketplace with an npm source", () => {
|
|
const marketplace = JSON.parse(readFileSync(join(__dirname, "../../../../.claude-plugin/marketplace.json"), "utf8"))
|
|
expect(marketplace.name).toBe("simplex-chat")
|
|
expect(marketplace.plugins).toEqual([expect.objectContaining({name: "simplex", source: {source: "npm", package: "@simplex-chat/mcp"}})])
|
|
})
|
|
})
|