mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-27 20:00:51 +00:00
Includes all Phase 3 rounds (1-5), Node unit test mock compatibility fixes, and Codex review fixes (pinyin readiness subscribers & KnownHostsManager mount retention).
76 lines
2.6 KiB
JavaScript
76 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { AGENT_KINDS, listAgentToolSpecs, listCattyToolSpecs } = require("../electron/capabilities/codegen/toolSurfaces.cjs");
|
|
|
|
const generatedDir = path.join(
|
|
__dirname,
|
|
"../infrastructure/ai/harness/generated",
|
|
);
|
|
|
|
function writeSpecs(filename, specs) {
|
|
const outputPath = path.join(generatedDir, filename);
|
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
fs.writeFileSync(outputPath, `${JSON.stringify(specs, null, 2)}\n`, "utf8");
|
|
return { outputPath, count: specs.length };
|
|
}
|
|
|
|
const sidebarSpecs = listCattyToolSpecs();
|
|
const globalAgentSpecs = listAgentToolSpecs(AGENT_KINDS.GLOBAL);
|
|
|
|
const sidebar = writeSpecs("cattyToolSpecs.json", sidebarSpecs);
|
|
const globalAgent = writeSpecs("globalAgentToolSpecs.json", globalAgentSpecs);
|
|
|
|
const globalByCapabilityId = {};
|
|
for (const spec of globalAgentSpecs) {
|
|
if (spec.capabilityId && spec.toolName && !globalByCapabilityId[spec.capabilityId]) {
|
|
globalByCapabilityId[spec.capabilityId] = spec.toolName;
|
|
}
|
|
}
|
|
const sidebarByRpcMethod = {};
|
|
const sidebarToolNameToCapability = {};
|
|
const sidebarRpcMethodToCapability = {};
|
|
const freshApprovalSet = new Set();
|
|
const grantableSet = new Set();
|
|
for (const spec of sidebarSpecs) {
|
|
if (spec.rpcMethod && spec.toolName && !sidebarByRpcMethod[spec.rpcMethod]) {
|
|
sidebarByRpcMethod[spec.rpcMethod] = spec.toolName;
|
|
}
|
|
if (spec.toolName && spec.capabilityId) {
|
|
sidebarToolNameToCapability[spec.toolName] = spec.capabilityId;
|
|
}
|
|
if (spec.rpcMethod && spec.capabilityId) {
|
|
sidebarRpcMethodToCapability[spec.rpcMethod] = spec.capabilityId;
|
|
}
|
|
if (spec.policy?.requiresFreshApproval && spec.capabilityId) {
|
|
freshApprovalSet.add(spec.capabilityId);
|
|
}
|
|
if (
|
|
spec.policy?.write
|
|
&& !spec.policy?.bypassesApproval
|
|
&& !spec.policy?.requiresFreshApproval
|
|
&& spec.capabilityId
|
|
) {
|
|
grantableSet.add(spec.capabilityId);
|
|
}
|
|
}
|
|
const indexOutputPath = path.join(generatedDir, "toolNameIndex.json");
|
|
fs.writeFileSync(
|
|
indexOutputPath,
|
|
`${JSON.stringify({
|
|
globalByCapabilityId,
|
|
sidebarByRpcMethod,
|
|
sidebarToolNameToCapability,
|
|
sidebarRpcMethodToCapability,
|
|
freshApprovalOnlyCapabilities: [...freshApprovalSet].sort(),
|
|
grantableCapabilityIds: [...grantableSet].sort(),
|
|
}, null, 2)}\n`,
|
|
"utf8",
|
|
);
|
|
|
|
process.stdout.write(`Wrote ${sidebar.count} sidebar tool specs to ${sidebar.outputPath}\n`);
|
|
process.stdout.write(`Wrote ${globalAgent.count} global agent tool specs to ${globalAgent.outputPath}\n`);
|
|
process.stdout.write(`Wrote compact tool name index to ${indexOutputPath}\n`);
|