Files
Netcatty/electron/scripts/scriptCodegen.cjs
T
陈大猫 67f8108713 feat(plugins): add reviewed privileged terminal data pipeline (#2402)
* feat(plugins): add privileged terminal data pipeline

* fix(plugins): harden terminal interceptor lifecycle

* fix(plugins): close terminal interceptor lifecycle gaps

* fix(plugins): preserve terminal interceptor state transitions

* fix(plugin): close terminal pipeline lifecycle gaps

* fix(plugin): harden terminal interceptor startup

* fix(plugin): isolate terminal output route attempts

* fix(plugin): isolate reused terminal sessions

* fix(plugin): harden terminal interceptor boundaries

* fix(plugin): harden terminal replay metadata

* fix(plugin): preserve terminal replay provenance

* fix(plugin): close terminal pipeline lifecycle races

* fix(plugin): harden terminal route handoff

* fix(plugin): contain terminal handoff failures

* fix(plugin): route terminal attachment through RPC

* fix(plugin): validate terminal attachment RPC

* fix(plugin): close unexpected runtime ports

* fix(plugin): canonicalize terminal data frames

* fix(plugin): close terminal pipeline lifecycle gaps

* fix(plugin): close terminal interceptor review gaps

* fix(plugin): harden terminal interceptor protocol handling

* fix(plugin): preserve terminal flow compatibility

* fix(plugin): preserve terminal protocol accounting

* fix(plugin): bound terminal interceptor lifecycle

* fix(plugin): close terminal interceptor review gaps

---------

Co-authored-by: ryan-wong-coder <wangsiyuan19990317@gmail.com>
2026-07-23 09:42:47 +08:00

42 lines
1.3 KiB
JavaScript

"use strict";
const HEADER = "// Auto-generated by Netcatty Script Recorder\n";
function escapeJsString(value) {
return JSON.stringify(String(value ?? ""));
}
function stepsToJavaScript(steps, recordedAt) {
const lines = [
HEADER.trimEnd(),
recordedAt ? `// Recorded on ${recordedAt}` : "",
"",
"async function main() {",
].filter(Boolean);
for (let index = 0; index < steps.length; index += 1) {
const step = steps[index];
if (step.type === "send") {
if (step.sensitive) {
lines.push(` const sensitiveValue${index} = await nct.dialog.prompt("Enter sensitive value", "", { sensitive: true });`);
lines.push(` await nct.screen.sendLine(sensitiveValue${index}, { sensitive: true });`);
continue;
}
lines.push(` await nct.screen.sendLine(${escapeJsString(step.value)});`);
} else if (step.type === "waitFor") {
lines.push(` await nct.screen.waitForText(${escapeJsString(step.value)}, ${step.timeoutMs || 5000});`);
} else if (step.type === "waitForPrompt") {
lines.push(` await nct.screen.waitForPrompt(${step.timeoutMs || 30000});`);
} else if (step.type === "sleep") {
lines.push(` await nct.session.sleep(${Number(step.value) || 1000});`);
}
}
lines.push("}", "", "await main();");
return lines.join("\n");
}
module.exports = {
stepsToJavaScript,
};