Files
Netcatty/scripts/generate-capability-tools.cjs
T
陈大猫 681a200f3f perf(memory): implement Phase 1–2 idle, window, and terminal memory optimizations (#4476)
* perf(memory): implement Phase 1–2 idle, window, and terminal memory optimizations

- Fix kittyKeyboardBroadcast closure leak while preserving hibernated broadcast via detached top-level handler
- Replace dense KeywordHighlighter line caches with sparse packed triples and 53-bit numeric fingerprints
- Deduplicate hibernation snapshots and compress large scrollbacks via native gzip
- Eliminate cold-start terminalWorker wakes (portForwarding, transfer concurrency, empty monitor updates, cold MCP cancel, and stateless local shell/path queries)
- Auto-destroy hidden Settings and Tray windows after a configurable 20s idle grace window
- Tune Electron V8/GPU startup flags, switch V8 cache to code, and stream large app:// assets
- Split renderer entry bundle (App, NotesManager, MonitorPanels, globalAgentToolSpecs) and enable Chromium sandbox: true on all BrowserWindows via esbuild-bundled preload and IPC upload staging
- Add MRU=1 hidden WebGL context budget, dynamic main-window backgroundThrottling, bounded SSH/Fig caches, and lazy native addon loading

* fix(memory): fix CI unit test compatibility for tray spellcheck, pty mocks, and sync toolNameIndex

* fix(terminal): defer hibernate snapshot gzip until after live listeners detach

Addresses Codex P1 review finding on PR #4476:
- Add compress?: boolean option to serializeTerminalForHibernate so
  fullHibernateRuntime avoids awaiting gzip while the live output
  listener is still attached to the old xterm instance
- Compress the retained snapshot asynchronously only after live listeners
  are detached, runtime is disposed, and beginHibernatedSessionListeners
  is buffering all incoming output into hibernatePendingBufferRef
- Guard async swap with hibernateCompressionGenRef so wake/clear/new
  snapshots can never be overwritten by an earlier compression promise

* fix(terminal): preserve Kitty broadcast key-pairing sets across hibernate detach

Addresses Codex P2 review finding on PR #4476:
- Pass existing broadcastEncodedKeys, broadcastLegacySuppressedKeys, and
  broadcastWin32ShiftEnterTextKeys (plain string sets) into the detached
  hibernated broadcast handler so in-flight key-up releases are preserved
2026-11-27 23:23:01 +08:00

48 lines
1.7 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 = {};
for (const spec of sidebarSpecs) {
if (spec.rpcMethod && spec.toolName && !sidebarByRpcMethod[spec.rpcMethod]) {
sidebarByRpcMethod[spec.rpcMethod] = spec.toolName;
}
}
const indexOutputPath = path.join(generatedDir, "toolNameIndex.json");
fs.writeFileSync(
indexOutputPath,
`${JSON.stringify({ globalByCapabilityId, sidebarByRpcMethod }, 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`);