[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled

This commit is contained in:
2026-09-13 18:24:01 +08:00
commit 3c72efcb7f
3255 changed files with 907009 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
"use strict";
const { CAPABILITY_STATUS, CAPABILITY_SURFACES } = require("../constants.cjs");
const {
getCapabilityByCliCommand,
listCapabilities,
} = require("../registry.cjs");
const { TOOL_INPUT_FIELDS } = require("../schemas/toolInputs.cjs");
/** Maps TOOL_INPUT_FIELDS keys to CLI flag names and opts property names. */
const CLI_FIELD_BINDINGS = Object.freeze({
hostId: { flag: "--host-id", optKey: "hostId" },
filename: { flag: "--filename", optKey: "filename" },
snippetId: { flag: "--snippet-id", optKey: "snippetId" },
scriptId: { flag: "--script-id", optKey: "scriptId" },
runId: { flag: "--run-id", optKey: "runId" },
ruleId: { flag: "--rule-id", optKey: "ruleId" },
notes: { flag: "--notes", optKey: "notes" },
sessionId: { flag: "--session", optKey: "sessionId" },
variables: { flag: "--variables", optKey: "variables" },
wait: { flag: "--wait", optKey: "wait" },
scriptIds: { flag: "--script-ids", optKey: "scriptIds" },
label: { flag: "--label", optKey: "label" },
kind: { flag: "--kind", optKey: "kind" },
trigger: { flag: "--trigger", optKey: "trigger" },
triggerPattern: { flag: "--trigger-pattern", optKey: "triggerPattern" },
targets: { flag: "--targets", optKey: "targets" },
targetGroups: { flag: "--target-groups", optKey: "targetGroups" },
targetsAllHosts: { flag: "--targets-all-hosts", optKey: "targetsAllHosts" },
description: { flag: "--description", optKey: "description" },
language: { flag: "--language", optKey: "language" },
package: { flag: "--package", optKey: "package" },
shortkey: { flag: "--shortkey", optKey: "shortkey" },
noAutoRun: { flag: "--no-auto-run", optKey: "noAutoRun" },
multiLineRunMode: { flag: "--multi-line-run-mode", optKey: "multiLineRunMode" },
path: { flag: "--remote-path", optKey: "remotePath" },
remotePath: { flag: "--remote-path", optKey: "remotePath" },
localPath: { flag: "--local-path", optKey: "localPath" },
oldPath: { flag: "--old-remote-path", optKey: "oldRemotePath" },
newPath: { flag: "--new-remote-path", optKey: "newRemotePath" },
content: { flag: "--content", optKey: "content" },
mode: { flag: "--mode", optKey: "mode" },
command: { flag: "--", optKey: "command" },
jobId: { flag: "--job", optKey: "jobId" },
offset: { flag: "--offset", optKey: "offset" },
});
function resolveCliRpcMethod(capability) {
if (!capability) return null;
return capability.surfaces?.[CAPABILITY_SURFACES.BUILTIN]?.rpcMethod
|| capability.surfaces?.[CAPABILITY_SURFACES.GLOBAL]?.rpcMethod
|| capability.surfaces?.[CAPABILITY_SURFACES.PUBLIC]?.rpcMethod
|| null;
}
function getCliRpcMethod(commandParts) {
const capability = getCapabilityByCliCommand(commandParts);
return resolveCliRpcMethod(capability);
}
function listCliCapabilities(options = {}) {
const surface = options.surface || CAPABILITY_SURFACES.CLI;
const status = Object.prototype.hasOwnProperty.call(options, "status")
? options.status
: CAPABILITY_STATUS.IMPLEMENTED;
return listCapabilities({ surface, status: status || undefined })
.filter((capability) => Array.isArray(capability.surfaces?.[surface]?.command))
.map((capability) => ({
id: capability.id,
domain: capability.domain,
status: capability.status,
description: capability.description,
command: capability.surfaces[surface].command,
rpcMethod: resolveCliRpcMethod(capability),
policy: capability.policy,
}));
}
function formatCliHelpLines(options = {}) {
return listCliCapabilities(options).flatMap((entry) => {
const statusSuffix = entry.status === CAPABILITY_STATUS.PLANNED ? " (planned)" : "";
return [` netcatty-tool-cli ${entry.command.join(" ")}${statusSuffix}`];
});
}
function buildCatalogCliParams(capabilityId, opts, createError) {
const fields = TOOL_INPUT_FIELDS[capabilityId];
if (!fields) {
return {};
}
const params = {};
for (const [fieldName, fieldDef] of Object.entries(fields)) {
const binding = CLI_FIELD_BINDINGS[fieldName];
if (!binding) continue;
let value = opts[binding.optKey];
if (fieldName === "command" && Array.isArray(value)) {
value = value.length === 1 ? value[0] : null;
}
if (fieldName === "variables" && typeof value === "string" && value.trim()) {
try {
value = JSON.parse(value);
} catch {
throw createError("INVALID_ARGUMENT", `--variables must be valid JSON for ${capabilityId}.`);
}
}
if (fieldName === "offset" && value != null) {
value = Number(value);
}
if (value == null || value === "") {
if (!fieldDef.optional) {
throw createError(
"INVALID_ARGUMENT",
`Missing required ${binding.flag} for ${capabilityId}.`,
);
}
continue;
}
params[fieldName] = value;
}
return params;
}
module.exports = {
CLI_FIELD_BINDINGS,
buildCatalogCliParams,
getCliRpcMethod,
listCliCapabilities,
formatCliHelpLines,
resolveCliRpcMethod,
};

View File

@@ -0,0 +1,91 @@
"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const {
getCliRpcMethod,
listCliCapabilities,
buildCatalogCliParams,
} = require("./cliAdapter.cjs");
const { CAPABILITY_STATUS } = require("../constants.cjs");
function fakeCreateError(code, message) {
const err = new Error(message);
err.code = code;
return err;
}
test("getCliRpcMethod resolves implemented cli commands to rpc methods", () => {
assert.equal(getCliRpcMethod(["exec"]), "netcatty/exec");
assert.equal(getCliRpcMethod(["attachment", "read"]), "netcatty/readAttachment");
assert.equal(getCliRpcMethod(["sftp", "list"]), "netcatty/sftp/list");
assert.equal(getCliRpcMethod(["vault", "host", "get"]), "vault/host/get");
assert.equal(getCliRpcMethod(["portforward", "rules", "list"]), "portforward/rules/list");
assert.equal(getCliRpcMethod(["capabilities"]), null);
});
test("listCliCapabilities returns implemented commands by default", () => {
const entries = listCliCapabilities();
assert.ok(entries.some((entry) => entry.id === "terminal.execute"));
assert.ok(entries.some((entry) => entry.id === "attachment.list"));
assert.ok(entries.some((entry) => entry.id === "attachment.read"));
assert.ok(entries.some((entry) => entry.id === "vault.host.get"));
assert.ok(entries.every((entry) => entry.status === CAPABILITY_STATUS.IMPLEMENTED));
assert.ok(entries.every((entry) => entry.rpcMethod));
});
test("listCliCapabilities can include planned commands", () => {
const entries = listCliCapabilities({ status: CAPABILITY_STATUS.PLANNED });
assert.ok(entries.length >= 0);
});
test("buildCatalogCliParams maps vault host get flags", () => {
const params = buildCatalogCliParams("vault.host.get", { hostId: "host-1" }, fakeCreateError);
assert.deepEqual(params, { hostId: "host-1" });
});
test("buildCatalogCliParams maps attachment filename", () => {
const params = buildCatalogCliParams(
"attachment.read",
{ filename: "hosts.csv" },
fakeCreateError,
);
assert.deepEqual(params, { filename: "hosts.csv" });
});
test("buildCatalogCliParams parses snippet variables JSON", () => {
const params = buildCatalogCliParams("vault.snippets.run", {
snippetId: "snip-1",
sessionId: "sess-1",
variables: "{\"name\":\"prod\"}",
}, fakeCreateError);
assert.equal(params.snippetId, "snip-1");
assert.equal(params.sessionId, "sess-1");
assert.deepEqual(params.variables, { name: "prod" });
});
test("buildCatalogCliParams maps snippet multi-line run mode", () => {
const params = buildCatalogCliParams("vault.snippets.create", {
label: "login",
content: "user\npass",
multiLineRunMode: "lineDelay",
}, fakeCreateError);
assert.equal(params.multiLineRunMode, "lineDelay");
});
test("buildCatalogCliParams maps dynamic script group targets", () => {
const params = buildCatalogCliParams("vault.scripts.targets.set", {
scriptId: "script-1",
targetGroups: '["Production","Staging/Web"]',
}, fakeCreateError);
assert.equal(params.scriptId, "script-1");
assert.equal(params.targetGroups, '["Production","Staging/Web"]');
});
test("buildCatalogCliParams throws for missing required fields", () => {
assert.throws(
() => buildCatalogCliParams("vault.host.get", {}, fakeCreateError),
/Missing required --host-id/,
);
});

View File

@@ -0,0 +1,9 @@
"use strict";
const cliAdapter = require("./cliAdapter.cjs");
const mcpAdapter = require("./mcpAdapter.cjs");
module.exports = {
...cliAdapter,
...mcpAdapter,
};

View File

@@ -0,0 +1,38 @@
"use strict";
const { CAPABILITY_STATUS, CAPABILITY_SURFACES } = require("../constants.cjs");
const {
getCapabilityByMcpTool,
getCapabilityByRpcMethod,
listCapabilities,
} = require("../registry.cjs");
function listMcpTools(surface = CAPABILITY_SURFACES.BUILTIN, options = {}) {
const status = options.status || CAPABILITY_STATUS.IMPLEMENTED;
return listCapabilities({ surface, status })
.filter((capability) => capability.surfaces?.[surface]?.mcpTool)
.map((capability) => ({
id: capability.id,
toolName: capability.surfaces[surface].mcpTool,
rpcMethod: capability.surfaces[surface].rpcMethod,
description: capability.description,
policy: capability.policy,
status: capability.status,
}));
}
function getMcpToolRpcMethod(toolName, surface = CAPABILITY_SURFACES.BUILTIN) {
const capability = getCapabilityByMcpTool(toolName, surface);
return capability?.surfaces?.[surface]?.rpcMethod || null;
}
function getMcpToolNameForRpcMethod(rpcMethod, surface = CAPABILITY_SURFACES.BUILTIN) {
const capability = getCapabilityByRpcMethod(rpcMethod, surface);
return capability?.surfaces?.[surface]?.mcpTool || null;
}
module.exports = {
listMcpTools,
getMcpToolRpcMethod,
getMcpToolNameForRpcMethod,
};

View File

@@ -0,0 +1,33 @@
"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const {
listMcpTools,
getMcpToolRpcMethod,
getMcpToolNameForRpcMethod,
} = require("./mcpAdapter.cjs");
const { CAPABILITY_SURFACES } = require("../constants.cjs");
test("listMcpTools exposes builtin terminal tools", () => {
const tools = listMcpTools(CAPABILITY_SURFACES.BUILTIN);
assert.ok(tools.some((tool) => tool.toolName === "terminal_execute"));
assert.ok(tools.every((tool) => tool.rpcMethod));
});
test("getMcpToolRpcMethod resolves tool names", () => {
assert.equal(
getMcpToolRpcMethod("terminal_execute", CAPABILITY_SURFACES.BUILTIN),
"netcatty/exec",
);
});
test("public surface includes sftp tools for future public mcp registration", () => {
const tools = listMcpTools(CAPABILITY_SURFACES.PUBLIC);
assert.ok(tools.some((tool) => tool.toolName === "sftp_list"));
assert.equal(
getMcpToolNameForRpcMethod("public/sftp/list", CAPABILITY_SURFACES.PUBLIC),
"sftp_list",
);
});