mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-10 17:35:11 +08:00
Auto-install the Netx Ops agent preset on plugin activate.
Copy presets into ~/.dsh/.agent-presets (not a Windows junction — DSH discovery skips those) so dsh plugin add alone surfaces Custom → Netx Ops with skills. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4854101afd
commit
5179eb74b1
9 changed files with 174 additions and 82 deletions
44
lib/index.js
44
lib/index.js
|
|
@ -1,4 +1,8 @@
|
|||
// src/index.ts
|
||||
import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import z from "@deepseek-ai/schemastery";
|
||||
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
||||
import * as DshSettings from "@deepseek-ai/dsh-settings";
|
||||
|
|
@ -6,6 +10,7 @@ import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|||
var name = "netxops";
|
||||
var inject = ["tools"];
|
||||
var NETXOPS_SETTINGS_NAMESPACE = "netxops";
|
||||
var NETXOPS_PRESET_ID = "netxops";
|
||||
var DEFAULT_TOKEN_REF = "NETX_API_TOKEN";
|
||||
var Config2 = z.object({
|
||||
apiUrl: z.string().default("http://127.0.0.1:8890"),
|
||||
|
|
@ -13,8 +18,40 @@ var Config2 = z.object({
|
|||
pythonCommand: z.string().default("python"),
|
||||
tokenCredentialRef: z.string().role("credential-ref").default(DEFAULT_TOKEN_REF),
|
||||
toolCallTimeoutMs: z.number().step(1).min(1000).default(120000),
|
||||
failOnStartupError: z.boolean().default(false)
|
||||
failOnStartupError: z.boolean().default(false),
|
||||
installAgentPreset: z.boolean().default(true)
|
||||
});
|
||||
function packageRoot() {
|
||||
return join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
}
|
||||
function resolveDshHome() {
|
||||
const fromEnv = process.env.DSH_HOME?.trim();
|
||||
if (fromEnv !== undefined && fromEnv.length > 0)
|
||||
return fromEnv;
|
||||
return join(homedir(), ".dsh");
|
||||
}
|
||||
function ensureAgentPresetInstalled(logger) {
|
||||
const src = join(packageRoot(), "presets", NETXOPS_PRESET_ID);
|
||||
const composition = join(src, "agent.cordis.yml");
|
||||
if (!existsSync(composition)) {
|
||||
logger.warn("netxops: bundled preset missing at %s — skip user-preset install", src);
|
||||
return;
|
||||
}
|
||||
const destParent = join(resolveDshHome(), ".agent-presets");
|
||||
const dest = join(destParent, NETXOPS_PRESET_ID);
|
||||
try {
|
||||
mkdirSync(destParent, { recursive: true });
|
||||
if (existsSync(dest)) {
|
||||
rmSync(dest, { recursive: true, force: true });
|
||||
}
|
||||
cpSync(src, dest, { recursive: true });
|
||||
writeFileSync(join(dest, ".dsh-netxops-managed"), `${new Date().toISOString()}
|
||||
`, "utf8");
|
||||
logger.info("netxops: agent preset installed at %s", dest);
|
||||
} catch (error) {
|
||||
logger.error("netxops: failed to install agent preset: %s", error);
|
||||
}
|
||||
}
|
||||
async function resolveToken(ctx, refName) {
|
||||
const credentials = ctx.get("credentials");
|
||||
if (credentials === undefined)
|
||||
|
|
@ -37,6 +74,9 @@ function apply(ctx, config = Config2({})) {
|
|||
let mcpFiber;
|
||||
let remounting = Promise.resolve();
|
||||
let generation = 0;
|
||||
if (config.installAgentPreset) {
|
||||
ensureAgentPresetInstalled(ctx.logger);
|
||||
}
|
||||
const remount = () => {
|
||||
remounting = remounting.then(async () => {
|
||||
const gen = ++generation;
|
||||
|
|
@ -102,8 +142,10 @@ function apply(ctx, config = Config2({})) {
|
|||
export {
|
||||
name,
|
||||
inject,
|
||||
ensureAgentPresetInstalled,
|
||||
apply,
|
||||
NETXOPS_SETTINGS_NAMESPACE,
|
||||
NETXOPS_PRESET_ID,
|
||||
DEFAULT_TOKEN_REF,
|
||||
Config2 as Config
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue