mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 00:50:44 +00:00
* feat(ai): add MiMo Code (mimo) agent support scaffolding
Registry/wiring only: discovery entry, managed-agent metadata, model presets, icon, i18n and Settings UI for Xiaomi's MiMo Code CLI (an OpenCode fork). The SDK driver is intentionally not wired yet - it depends on the pending @mimo-ai/sdk parity probe, so DRIVER_REGISTRY keeps a TODO and run-turn/list-models reject the mimo backend until then.
* feat(ai): add MiMo Code (mimo) agent support
Adds Xiaomi's MiMo Code CLI as a managed agent backend, mirroring the existing
OpenCode integration (discovery, managed-agent metadata, model presets, icon,
i18n, Settings UI) and adding the SDK driver that was left as a TODO in the
scaffolding commit.
Driver notes:
- New electron/bridges/aiBridge/sdk/mimoDriver.cjs reuses the pure translation
helpers exported by opencodeDriver.cjs (config/prompt building, event
translation, model mapping) because MiMo Code is an OpenCode fork and speaks
the same wire protocol.
- It does NOT use @mimo-ai/sdk's createOpencode(). On 0.1.15 that helper spawns
a binary named "opencode", waits for an "opencode server listening" banner,
and passes config via OPENCODE_CONFIG_CONTENT; the mimo CLI prints
"mimocode server listening on <url>", reads MIMOCODE_CONFIG_CONTENT, and ships
as "mimo"/"mimo.exe". So createOpencode() can only ever time out. The driver
runs "mimo serve" itself, parses the readiness URL, and attaches the SDK's
createOpencodeClient({ baseUrl }).
- Binary resolution honours binPath, MIMOCODE_BIN and MIMOCODE_BIN_PATH, then
falls back to PATH via resolveCliFromPath (the npm shim is mimo.cmd on
Windows, which Node cannot spawn directly).
- @mimo-ai/sdk ^0.1.15 added as a dependency.
Verified on Windows against mimo 0.1.15 + @mimo-ai/sdk 0.1.15:
- "mimo serve --port" boots and reports its URL; driver parses it.
- SDK symbols used all exist: createOpencodeClient, client.config.providers(),
client.global.event() (SSE stream), client.session.create/abort/promptAsync.
- Live provider catalog reads 2 providers (xiaomi, mimo); MIMO_MODEL_PRESETS
updated to the real lower-case provider-prefixed ids and its TODO removed.
- Server process is killed on close (taskkill tree kill), no orphan processes.
Not yet verified at runtime:
- A full end-to-end turn (no prompt was sent, so no tokens were spent): text /
reasoning / tool-part streaming and abort handling are untested against a
live model.
- MIMOCODE_CONFIG_CONTENT accepting the OpenCode config schema (permission,
mcp, model, share, autoupdate) end-to-end; only that the env var exists in
the binary has been confirmed.
- Whether the loopback server needs MIMOCODE_SERVER_PASSWORD when the API
client attaches.
- The placeholder public/ai/agents/mimo.svg still needs an official asset.
- Multi-turn resume (resumeSessionId) and MCP injection against the live CLI.
* feat(ai): inject MIMOCODE_BIN for discovered MiMo Code agents
Mirror the OpenCode OPENCODE_BIN handling so a discovered or re-detected
mimo binary path reaches the driver, and cover it with the same assertion
shape as the opencode managed-agent env test.
* fix(ai): use MiMo branding in the mimo driver
* test(ai): cover the mimo driver
Add a unit test file for the MiMo Code driver, matching the existing
opencode driver test in shape, runner (node:test via node --test) and
`.test.cjs` extension. It is the last driver in the registry without
one.
Coverage:
- spawn/launch: `mimo serve --hostname/--port` argv, binary resolution
(explicit binPath / MIMOCODE_BIN / MIMOCODE_BIN_PATH), pass-through
env and MIMOCODE_CONFIG_CONTENT; `child_process.spawn` is stubbed, so
no real `mimo` process is ever started.
- readiness: parsing of `mimocode server listening on <url>` from
stdout (including split chunks) and stderr, the OpenCode spelling,
and the MIMO_SERVE_TIMEOUT_MS timeout path (asserts the rejection and
that the child is killed).
- abort/cleanup: stopMimoProcess kill/idempotency/swallow, the Windows
taskkill tree kill, server.close() teardown, and abort mid-turn with
a throwing close().
- branding: OpenCode -> MiMo Code for the busy/idle/status, failed and
tool-failure fallback strings, with tool output and non-brand
technical errors left verbatim.
- happy path: session create -> streamed event translation -> done,
plus listMimoModels catalog mapping and the empty/aborted paths.
* fix(ai): filter MiMo events by session and stop the server behind the npm shim
Address review on #3500:
- The global SSE stream carries every session on the server, and
runMimoTurn translated all of them, so another session's text could leak
into the reply and its session.idle could end the turn early. Skip events
whose session id is not ours, reusing the OpenCode driver's
getOpenCodeSessionIdFromEvent (now exported). Covered by a test with
interleaved sessions.
- On macOS/Linux the official @mimo-ai/cli `mimo` is a Node shim that runs
the native binary through spawnSync, so killing the shim left the server
listening. `mimo serve` is now spawned detached on POSIX and
stopMimoProcess signals its whole process group (SIGTERM, then SIGKILL
after a grace period). Windows keeps taskkill /T.
Verified against the real @mimo-ai/cli@0.1.15 npm shim: on Linux (WSL
Ubuntu 22.04) the listener is the native .mimocode child; before this change
it was still listening 3s after close(), now the port is released within 1s
and no mimo process remains. On Windows the .cmd shim path also releases the
port within 1s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix: harden MiMo CLI integration before merge
* fix: wait for MiMo events and handle setup cancellation
* fix: finish MiMo stream handling and scope skill access
* fix: preflight MiMo skill paths before one server startup
* fix: scope MiMo skill reads to trusted roots
* fix: allow MiMo skills from ancestor project roots
* fix: honor MiMo observer and confirm command permissions
* fix: clear MiMo approval when its service exits
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
393 lines
20 KiB
JavaScript
393 lines
20 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
|
|
const {
|
|
buildNetcattySkillsOpenCodePathAllowlist,
|
|
buildOpenCodeNativeSkillEnvDenyPatterns,
|
|
buildOpenCodeNativeSkillPermissionPatterns,
|
|
buildOpenCodeNativeSkillsPermissionRules,
|
|
buildOpenCodeSkillsPermissionRules,
|
|
filterMimoTrustedSkillPaths,
|
|
toOpenCodeDirectoryPermissionPatterns,
|
|
toOpenCodeDirectoryGlob,
|
|
toOpenCodeFileParentPermissionPatterns,
|
|
toOpenCodeFileParentGlob,
|
|
} = require("./netcattySkillsOpenCodePermissions.cjs");
|
|
|
|
// Mirrors OpenCode's Wildcard.match (packages/core/src/util/wildcard.ts):
|
|
// inputs and patterns are normalized to forward slashes, "*" matches any
|
|
// run of characters, and matching is anchored to the whole string.
|
|
function openCodeWildcardMatch(input, pattern) {
|
|
const normalized = input.replaceAll("\\", "/");
|
|
const escaped = pattern
|
|
.replaceAll("\\", "/")
|
|
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
.replace(/\*/g, ".*")
|
|
.replace(/\?/g, ".");
|
|
return new RegExp(`^${escaped}$`, "s").test(normalized);
|
|
}
|
|
|
|
function matchesAnyPattern(input, patterns) {
|
|
return patterns.some((pattern) => openCodeWildcardMatch(input, pattern));
|
|
}
|
|
|
|
// Mirrors OpenCode's Permission.evaluate: rules come from Object.entries of
|
|
// the config map in insertion order, and the last matching rule wins.
|
|
function evaluateOpenCodeRuleMap(input, ruleMap) {
|
|
let action;
|
|
for (const [pattern, ruleAction] of Object.entries(ruleMap)) {
|
|
if (openCodeWildcardMatch(input, pattern)) action = ruleAction;
|
|
}
|
|
return action;
|
|
}
|
|
|
|
test("toOpenCodeFileParentGlob maps files to parent directory globs", () => {
|
|
assert.equal(
|
|
toOpenCodeFileParentGlob("/Applications/Netcatty.app/Contents/MacOS/netcatty-tool-cli"),
|
|
"/Applications/Netcatty.app/Contents/MacOS/**",
|
|
);
|
|
assert.equal(
|
|
toOpenCodeFileParentGlob("/tmp/netcatty/skills/netcatty-tool-cli/SKILL.md"),
|
|
"/tmp/netcatty/skills/netcatty-tool-cli/**",
|
|
);
|
|
});
|
|
|
|
test("toOpenCodeDirectoryGlob keeps directory roots stable when missing on disk", () => {
|
|
assert.equal(
|
|
toOpenCodeDirectoryGlob("/Users/me/Library/Application Support/netcatty/netcatty-tool-cli"),
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**",
|
|
);
|
|
});
|
|
|
|
test("toOpenCodeDirectoryPermissionPatterns includes exact and wildcard forms", () => {
|
|
assert.deepEqual(
|
|
toOpenCodeDirectoryPermissionPatterns("/Users/me/Library/Application Support/netcatty/netcatty-tool-cli"),
|
|
[
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/*",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**",
|
|
],
|
|
);
|
|
});
|
|
|
|
test("toOpenCodeFileParentPermissionPatterns normalizes Windows paths", () => {
|
|
assert.deepEqual(
|
|
toOpenCodeFileParentPermissionPatterns(
|
|
"C:\\Users\\me\\AppData\\Local\\Programs\\Netcatty\\resources\\app.asar.unpacked\\electron\\cli\\netcatty-tool-cli.cmd",
|
|
{ platform: "win32", pathModule: path.win32 },
|
|
),
|
|
[
|
|
"C:/Users/me/AppData/Local/Programs/Netcatty/resources/app.asar.unpacked/electron/cli",
|
|
"C:/Users/me/AppData/Local/Programs/Netcatty/resources/app.asar.unpacked/electron/cli/*",
|
|
"C:/Users/me/AppData/Local/Programs/Netcatty/resources/app.asar.unpacked/electron/cli/**",
|
|
],
|
|
);
|
|
});
|
|
|
|
test("buildNetcattySkillsOpenCodePathAllowlist dedupes launcher and script roots", () => {
|
|
const launcher = "/Applications/Netcatty.app/Contents/MacOS/netcatty-tool-cli";
|
|
const script = "/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/electron/cli/netcatty-tool-cli.cjs";
|
|
const skill = "/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/skills/netcatty-tool-cli/SKILL.md";
|
|
const patterns = buildNetcattySkillsOpenCodePathAllowlist({
|
|
launcherPath: launcher,
|
|
cliScriptPath: script,
|
|
skillPath: skill,
|
|
discoveryFilePath: "/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/discovery.json",
|
|
cliStateDir: "/Users/me/Library/Application Support/netcatty/netcatty-tool-cli",
|
|
});
|
|
|
|
assert.deepEqual(patterns, [
|
|
"/Applications/Netcatty.app/Contents/MacOS",
|
|
"/Applications/Netcatty.app/Contents/MacOS/*",
|
|
"/Applications/Netcatty.app/Contents/MacOS/**",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/electron/cli",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/electron/cli/*",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/electron/cli/**",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/skills/netcatty-tool-cli",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/skills/netcatty-tool-cli/*",
|
|
"/Applications/Netcatty.app/Contents/Resources/app.asar.unpacked/skills/netcatty-tool-cli/**",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/*",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**",
|
|
]);
|
|
});
|
|
|
|
test("buildNetcattySkillsOpenCodePathAllowlist includes temp dir and extra attachment paths", () => {
|
|
const patterns = buildNetcattySkillsOpenCodePathAllowlist({
|
|
discoveryFilePath: "/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/discovery.json",
|
|
tempDir: "/var/folders/tmp/Netcatty",
|
|
extraFilePaths: ["/var/folders/tmp/Netcatty/ai-attachment-1.png"],
|
|
});
|
|
|
|
assert.deepEqual(patterns, [
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/*",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**",
|
|
"/var/folders/tmp/Netcatty",
|
|
"/var/folders/tmp/Netcatty/*",
|
|
"/var/folders/tmp/Netcatty/**",
|
|
]);
|
|
});
|
|
|
|
test("buildNetcattySkillsOpenCodePathAllowlist includes OpenCode-compatible Windows directory resources", () => {
|
|
const patterns = buildNetcattySkillsOpenCodePathAllowlist({
|
|
launcherPath: "C:\\Users\\me\\AppData\\Local\\Programs\\Netcatty\\resources\\app.asar.unpacked\\electron\\cli\\netcatty-tool-cli.cmd",
|
|
cliScriptPath: "C:\\Users\\me\\AppData\\Local\\Programs\\Netcatty\\resources\\app.asar.unpacked\\electron\\cli\\netcatty-tool-cli.cjs",
|
|
skillPath: "C:\\Users\\me\\AppData\\Local\\Programs\\Netcatty\\resources\\app.asar.unpacked\\skills\\netcatty-tool-cli\\SKILL.md",
|
|
discoveryFilePath: "C:\\Users\\me\\AppData\\Roaming\\netcatty\\netcatty-tool-cli\\discovery.json",
|
|
runtimeBinaryPath: "C:\\Users\\me\\AppData\\Local\\Programs\\Netcatty\\Netcatty.exe",
|
|
tempDir: "C:\\Users\\me\\AppData\\Local\\Temp\\Netcatty",
|
|
extraFilePaths: ["C:\\Users\\me\\AppData\\Local\\Temp\\Netcatty\\attachment.png"],
|
|
}, { platform: "win32", pathModule: path.win32 });
|
|
|
|
assert.equal(patterns.includes("C:/Users/me/AppData/Local/Programs/Netcatty/resources/app.asar.unpacked/electron/cli/*"), true);
|
|
assert.equal(patterns.includes("C:/Users/me/AppData/Roaming/netcatty/netcatty-tool-cli/*"), true);
|
|
assert.equal(patterns.includes("C:/Users/me/AppData/Local/Temp/Netcatty/*"), true);
|
|
assert.equal(patterns.includes("C:/Users/me/AppData/Local/Programs/Netcatty/*"), true);
|
|
});
|
|
|
|
test("buildOpenCodeSkillsPermissionRules allowlists Netcatty CLI paths and denies other external access", () => {
|
|
const rules = buildOpenCodeSkillsPermissionRules([
|
|
"/Applications/Netcatty.app/Contents/MacOS/**",
|
|
"/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**",
|
|
]);
|
|
|
|
assert.equal(rules.bash, "allow");
|
|
assert.equal(rules.skill, "allow");
|
|
assert.equal(rules.list, "deny");
|
|
assert.equal(rules.external_directory["*"], "deny");
|
|
assert.equal(rules.external_directory["/Applications/Netcatty.app/Contents/MacOS/**"], "allow");
|
|
assert.equal(rules.external_directory["/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**"], "allow");
|
|
assert.equal(rules.read["/Applications/Netcatty.app/Contents/MacOS/**"], "allow");
|
|
assert.equal(rules.read["/Users/me/Library/Application Support/netcatty/netcatty-tool-cli/**"], "allow");
|
|
assert.equal(rules.read["*"], undefined);
|
|
// Allowlist entries must come after the catch-all deny so OpenCode's
|
|
// last-matching-rule-wins evaluation keeps them effective.
|
|
assert.equal(Object.keys(rules.external_directory)[0], "*");
|
|
});
|
|
|
|
test("buildOpenCodeNativeSkillsPermissionRules keeps OpenCode native skill dirs readable", () => {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules();
|
|
assert.equal(rules.skill, "allow");
|
|
assert.equal(rules.external_directory["*"], "deny");
|
|
for (const pattern of buildOpenCodeNativeSkillPermissionPatterns()) {
|
|
assert.equal(rules.external_directory[pattern], "allow");
|
|
assert.equal(rules.read[pattern], "allow");
|
|
}
|
|
for (const pattern of buildOpenCodeNativeSkillEnvDenyPatterns()) {
|
|
assert.equal(rules.read[pattern], "deny");
|
|
}
|
|
});
|
|
|
|
test("native skill read rules re-deny dot-env files inside skill dirs (last match wins)", () => {
|
|
const { read } = buildOpenCodeNativeSkillsPermissionRules();
|
|
|
|
// Regular skill files stay allowed.
|
|
assert.equal(evaluateOpenCodeRuleMap("../../.opencode/skills/foo/references/doc.md", read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("C:/Users/me/.config/opencode/skills/foo/SKILL.md", read), "allow");
|
|
|
|
// Dot-env secret files under skill dirs must not be silently readable.
|
|
assert.equal(evaluateOpenCodeRuleMap("../../.opencode/skills/foo/.env", read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("C:/Users/me/.config/opencode/skills/foo/.env", read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.claude/skills/foo/.env.local", read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("..\\..\\.agents\\skills\\foo\\references\\prod.env", read), "deny");
|
|
});
|
|
|
|
test("native skill patterns match OpenCode permission requests for skill files (issue #1939)", () => {
|
|
const patterns = buildOpenCodeNativeSkillPermissionPatterns();
|
|
|
|
// external_directory asks with an absolute parent-directory glob
|
|
// (forward slashes on Windows after FSUtil.normalizePathPattern).
|
|
assert.equal(matchesAnyPattern("C:/Users/me/.opencode/skills/my-skill/references/*", patterns), true);
|
|
assert.equal(matchesAnyPattern("/home/me/.config/opencode/skills/my-skill/*", patterns), true);
|
|
assert.equal(matchesAnyPattern("/Users/me/.claude/skills/my-skill/references/*", patterns), true);
|
|
assert.equal(matchesAnyPattern("/Users/me/.agents/skills/my-skill/*", patterns), true);
|
|
assert.equal(matchesAnyPattern("/Users/me/.cache/opencode/skills/abc123/my-skill/*", patterns), true);
|
|
|
|
// read asks with a worktree-relative path (Windows backslashes included).
|
|
assert.equal(matchesAnyPattern("..\\..\\.opencode\\skills\\my-skill\\references\\doc.md", patterns), true);
|
|
assert.equal(matchesAnyPattern("../.config/opencode/skills/my-skill/SKILL.md", patterns), true);
|
|
assert.equal(matchesAnyPattern(".opencode/skills/my-skill/references/doc.md", patterns), true);
|
|
|
|
// unrelated external paths stay denied
|
|
assert.equal(matchesAnyPattern("C:/Users/me/Documents/secret.txt/*", patterns), false);
|
|
assert.equal(matchesAnyPattern("../../etc/passwd", patterns), false);
|
|
assert.equal(matchesAnyPattern("C:/Users/me/.ssh/id_rsa", patterns), false);
|
|
});
|
|
|
|
test("MiMo native skills can read references from default and overridden roots without reading env files", () => {
|
|
const options = {
|
|
mimo: true,
|
|
cwd: "/work/project",
|
|
env: {
|
|
HOME: "/home/me",
|
|
MIMOCODE_HOME: "/opt/mimo-home",
|
|
MIMOCODE_CONFIG_DIR: "/opt/mimo-extra",
|
|
XDG_CONFIG_HOME: "/opt/xdg-config",
|
|
},
|
|
};
|
|
const rules = buildOpenCodeSkillsPermissionRules(["/opt/netcatty-tool/**"], options);
|
|
const readable = [
|
|
"/home/me/.mimocode/skills/one/references/guide.md",
|
|
"/home/me/.config/mimocode/skill/one/references/guide.md",
|
|
"/home/me/.local/share/mimocode/builtin_skills/0.1.15/skills/one/references/guide.md",
|
|
"/home/me/.cache/mimocode/skills/one/references/guide.md",
|
|
"/opt/mimo-home/data/compose/0.1.15/skills/one/references/guide.md",
|
|
"/opt/mimo-home/config/skill/one/references/guide.md",
|
|
"/opt/mimo-extra/skills/one/references/guide.md",
|
|
"/opt/xdg-config/mimocode/skills/one/references/guide.md",
|
|
];
|
|
for (const file of readable) {
|
|
assert.equal(evaluateOpenCodeRuleMap(file, rules.read), "allow", file);
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file), rules.external_directory), "allow", file);
|
|
}
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/mimo-home/config/skill/one/.env", rules.read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("../../opt/mimo-home/config/skill/one/references/guide.md", rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("../../opt/mimo-home/config/skill/one/.env", rules.read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.mimocode/skills/one/.env.local", rules.read), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/unrelated/secret.md", rules.read), undefined);
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/other/.mimocode/skills/private/secret.txt", rules.read), undefined);
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/unrelated", rules.external_directory), "deny");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.mimocode/skills/one/references/guide.md", buildOpenCodeNativeSkillsPermissionRules().read), undefined);
|
|
});
|
|
|
|
test("MiMo native skills can read macOS built-in skill references", () => {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules({
|
|
mimo: true,
|
|
platform: "darwin",
|
|
cwd: "/Users/me/work/project",
|
|
env: { HOME: "/Users/me" },
|
|
});
|
|
const file = "/Users/me/Library/Application Support/mimocode/builtin_skills/0.1.15/skills/one/references/guide.md";
|
|
assert.equal(evaluateOpenCodeRuleMap(file, rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("../../Library/Application Support/mimocode/builtin_skills/0.1.15/skills/one/references/guide.md", rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file), rules.external_directory), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("../../Library/Application Support/mimocode/builtin_skills/0.1.15/skills/one/.env", rules.read), "deny");
|
|
});
|
|
|
|
test("MiMo native skill reads include ancestor projects but exclude unrelated projects", () => {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules({
|
|
mimo: true,
|
|
cwd: "/work/project/subdir",
|
|
env: { HOME: "/home/me" },
|
|
});
|
|
assert.equal(evaluateOpenCodeRuleMap("/work/project/.mimocode/skills/one/reference.md", rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/work/project/.agents/skills/one/reference.md", rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/other/.mimocode/skills/one/secret.txt", rules.read), undefined);
|
|
});
|
|
|
|
test("MiMo native skill reads accept a canonical path for an aliased project directory", () => {
|
|
const project = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mimo-aliased-project-"));
|
|
try {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules({ mimo: true, cwd: project });
|
|
const canonical = fs.realpathSync(project);
|
|
assert.equal(evaluateOpenCodeRuleMap(`${canonical}/.mimocode/skills/one/reference.md`, rules.read), "allow");
|
|
} finally {
|
|
fs.rmSync(project, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("MiMo native skills can read Windows built-in skill references", () => {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules({
|
|
mimo: true,
|
|
platform: "win32",
|
|
pathModule: path.win32,
|
|
cwd: "C:\\Users\\me\\work\\project",
|
|
env: { LOCALAPPDATA: "C:\\Users\\me\\AppData\\Local" },
|
|
});
|
|
const file = "C:/Users/me/AppData/Local/mimocode/builtin_skills/0.1.15/skills/one/references/guide.md";
|
|
assert.equal(evaluateOpenCodeRuleMap(file, rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file), rules.external_directory), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("../../AppData/Local/mimocode/builtin_skills/0.1.15/skills/one/references/guide.md", rules.read), "allow");
|
|
});
|
|
|
|
test("MiMo native skill access follows enabled external roots", () => {
|
|
const regular = buildOpenCodeNativeSkillsPermissionRules({ mimo: true, cwd: "/work/project", env: { HOME: "/home/me" } });
|
|
for (const file of ["/home/me/.claude/skills/one/SKILL.md", "/home/me/.codex/skills/one/SKILL.md", "/home/me/.opencode/skills/one/SKILL.md"]) {
|
|
assert.equal(evaluateOpenCodeRuleMap(file, regular.read), undefined, file);
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file), regular.external_directory), "deny", file);
|
|
}
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.agents/skills/one/SKILL.md", regular.read), "allow");
|
|
const disabledAgents = buildOpenCodeNativeSkillsPermissionRules({ mimo: true, cwd: "/work/project", env: { HOME: "/home/me", MIMOCODE_DISABLE_AGENTS_SKILLS: "true" } });
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.agents/skills/one/SKILL.md", disabledAgents.read), undefined);
|
|
const enabled = buildOpenCodeNativeSkillsPermissionRules({ mimo: true, cwd: "/work/project", env: {
|
|
HOME: "/home/me",
|
|
MIMOCODE_ENABLE_CLAUDE_CODE_SKILLS: "true",
|
|
MIMOCODE_ENABLE_CODEX_SKILLS: "true",
|
|
MIMOCODE_ENABLE_OPENCODE_SKILLS: "true",
|
|
} });
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.claude/skills/one/SKILL.md", enabled.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.codex/skills/one/SKILL.md", enabled.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.opencode/skills/one/SKILL.md", enabled.read), "allow");
|
|
const numeric = buildOpenCodeNativeSkillsPermissionRules({ mimo: true, cwd: "/work/project", env: {
|
|
HOME: "/home/me",
|
|
MIMOCODE_ENABLE_CODEX_SKILLS: "1",
|
|
MIMOCODE_DISABLE_AGENTS_SKILLS: "1",
|
|
} });
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.codex/skills/one/SKILL.md", numeric.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/home/me/.agents/skills/one/SKILL.md", numeric.read), undefined);
|
|
});
|
|
|
|
test("MiMo native skill rules allow configured custom skill paths", () => {
|
|
const rules = buildOpenCodeNativeSkillsPermissionRules({
|
|
mimo: true,
|
|
cwd: "/work/project",
|
|
env: { HOME: "/home/me" },
|
|
skillPaths: ["/opt/team-skills", "./project-skills", "~/personal-skills"],
|
|
});
|
|
for (const file of [
|
|
"/opt/team-skills/one/references/checklist.md",
|
|
"/work/project/project-skills/one/references/checklist.md",
|
|
"/home/me/personal-skills/one/references/checklist.md",
|
|
]) {
|
|
assert.equal(evaluateOpenCodeRuleMap(file, rules.read), "allow", file);
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file), rules.external_directory), "allow", file);
|
|
assert.equal(evaluateOpenCodeRuleMap(path.posix.dirname(file) + "/.env", rules.read), "deny", file);
|
|
}
|
|
assert.equal(evaluateOpenCodeRuleMap("../../opt/team-skills/one/references/checklist.md", rules.read), "allow");
|
|
assert.equal(evaluateOpenCodeRuleMap("/opt/unrelated/checklist.md", rules.read), undefined);
|
|
});
|
|
|
|
test("MiMo custom skill paths trust the project or the user's global config", () => {
|
|
const project = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mimo-skills-project-"));
|
|
const external = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mimo-skills-external-"));
|
|
const local = path.join(project, "skills");
|
|
const linked = path.join(project, "linked");
|
|
fs.mkdirSync(local);
|
|
fs.symlinkSync(external, linked);
|
|
try {
|
|
assert.deepEqual(
|
|
filterMimoTrustedSkillPaths([local, external, linked, "/etc"], { cwd: project }),
|
|
[fs.realpathSync(local)],
|
|
);
|
|
assert.deepEqual(
|
|
filterMimoTrustedSkillPaths([local, external, linked], { cwd: project, globalSkillPaths: [external] }),
|
|
[fs.realpathSync(local), fs.realpathSync(external)],
|
|
);
|
|
} finally {
|
|
fs.rmSync(project, { recursive: true, force: true });
|
|
fs.rmSync(external, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("MiMo skill paths use the checked target if a project link changes later", () => {
|
|
const project = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mimo-linked-project-"));
|
|
const external = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mimo-linked-external-"));
|
|
const local = path.join(project, "skills");
|
|
const linked = path.join(project, "linked-skills");
|
|
fs.mkdirSync(local);
|
|
fs.symlinkSync(local, linked);
|
|
try {
|
|
const checked = filterMimoTrustedSkillPaths([linked], { cwd: project });
|
|
fs.rmSync(linked);
|
|
fs.symlinkSync(external, linked);
|
|
assert.deepEqual(checked, [fs.realpathSync(local)]);
|
|
} finally {
|
|
fs.rmSync(project, { recursive: true, force: true });
|
|
fs.rmSync(external, { recursive: true, force: true });
|
|
}
|
|
});
|