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
93 lines
4.9 KiB
TypeScript
93 lines
4.9 KiB
TypeScript
import { DEFAULT_SCRIPT_TEMPLATE } from './snippetScript.ts';
|
|
|
|
const WRAPPER_RULES = `## Script source wrapping
|
|
|
|
Netcatty executes scripts as async JavaScript in a Node vm sandbox:
|
|
|
|
- If the source is already an async IIFE or async arrow, it runs as-is.
|
|
- If the source contains \`async function main()\`, it is wrapped and \`await main()\` is called.
|
|
- Otherwise bare statements are wrapped in \`(async () => { ... })()\`.
|
|
|
|
Only JavaScript is executed. The \`language: python\` field is a UI label only — there is no Python runtime.`;
|
|
|
|
const TRIGGER_GUIDE = `## Triggers and host targeting
|
|
|
|
| trigger | Behavior |
|
|
|---------|----------|
|
|
| manual | Run from Vault or via scripts_run / snippets_run |
|
|
| onConnect | Runs after SSH connect (global targetsAllHosts, dynamic targetGroups, then host connectScriptIds queue) |
|
|
| onOutput | Runs when terminal output matches triggerPattern (regex) |
|
|
|
|
Use \`targets\` (host id array), \`targetGroups\` (dynamic group path array), or \`targetsAllHosts: true\` to scope runs. Group paths include nested groups and are resolved against the latest host inventory.
|
|
For per-host onConnect order, use \`host_connect_scripts_set\`. Group-scoped scripts remain inherited and are not copied into host queues.`;
|
|
|
|
const NCT_API = `## nct API reference
|
|
|
|
Global \`nct.version\` exposes the runtime version.
|
|
|
|
### nct.screen
|
|
- \`await nct.screen.waitForPrompt(ms?)\` — wait for shell prompt (# root / $ user)
|
|
- \`await nct.screen.waitForText(text, ms?)\` — wait for exact text; regex characters are treated literally
|
|
- \`await nct.screen.waitForRegex(pattern, ms?)\` — wait for regex output; string patterns match multiline output
|
|
- \`await nct.screen.waitFor(pattern, ms?)\` — compatibility helper; plain strings are literal, and legacy \`/regex/flags\` strings still work
|
|
- \`await nct.screen.waitForAny(patterns, ms?)\` — wait until any pattern matches
|
|
- \`await nct.screen.sendLine(cmd)\` — type command + Enter
|
|
- \`await nct.screen.send(text)\` — raw keys without Enter
|
|
- \`await nct.screen.getText(start?, end?)\` — read terminal buffer
|
|
- \`await nct.screen.clear()\` — clear screen
|
|
- Properties: \`rows\`, \`cols\`, \`currentRow\`
|
|
|
|
Use \`waitForText("请选择SSH资源")\` for literal prompts.
|
|
Use \`waitForRegex(".*请选择SSH资源.*登录方式.*")\` for regex or output split across terminal lines.
|
|
|
|
### nct.session
|
|
- \`nct.session.connected\` — whether the current terminal session is connected
|
|
- \`nct.session.name\` — session display name, usually the saved host label
|
|
- \`nct.session.hostname\` — hostname or address of the current session
|
|
- \`nct.session.username\` — username of the current session
|
|
- \`await nct.session.sleep(ms)\` — alias \`await nct.sleep(ms)\`
|
|
- \`await nct.session.startLog(path)\` / \`stopLog()\`
|
|
- \`await nct.session.disconnect()\`
|
|
|
|
### nct.dialog (requires non-Observer permission mode)
|
|
- \`await nct.dialog.confirm(msg)\` → boolean
|
|
- \`await nct.dialog.prompt(msg, default?)\` → string
|
|
- \`await nct.dialog.alert(msg)\`
|
|
- \`await nct.dialog.form({ title?, message?, fields })\` → object; fields support \`select\`, \`checkbox\`, \`radio\`, \`textarea\`, and \`number\`
|
|
- \`await nct.dialog.select(msg, options, default?)\` → string
|
|
- \`await nct.dialog.radio(msg, options, default?)\` → string
|
|
- \`await nct.dialog.checkbox(msg, defaultChecked?)\` → boolean
|
|
|
|
\`select\` and \`radio\` options may be strings or \`{ label, value, description?, disabled? }\`; option values must be non-empty and unique within the field.
|
|
\`textarea\` returns string values; \`number\` returns number values or \`undefined\` when optional and empty. \`number\` fields support submit-time \`min\`, \`max\`, and \`step\` validation.
|
|
Fields may use \`visibleWhen: { field, equals|notEquals|truthy|falsy }\` for conditional display; \`visibleWhen.field\` must reference an earlier field. Hidden fields are not validated and are omitted from the submitted object.
|
|
\`form\` returns an object keyed by visible field \`name\`. Field names must not be \`__proto__\`, \`prototype\`, or \`constructor\`. Text, number, select, and radio fields are required/defaulted by default; checkbox fields are optional boolean fields unless \`required: true\` is set.
|
|
|
|
### nct.progress
|
|
- \`nct.progress.start(label, total)\` — opt-in determinate bar
|
|
- \`nct.progress.step(detail?)\` / \`set(n, detail?)\` / \`done()\`
|
|
|
|
### nct.log
|
|
- \`nct.log(message)\` — append to script run log panel`;
|
|
|
|
/** Markdown reference for AI agents — single source for scripts_reference tool and prompts. */
|
|
export function getScriptApiReference(): string {
|
|
return [
|
|
'# Netcatty automation script reference',
|
|
'',
|
|
'Automation scripts are Vault snippets with `kind: "script"`. They run in the active terminal session via the nct JavaScript API.',
|
|
'',
|
|
WRAPPER_RULES,
|
|
'',
|
|
TRIGGER_GUIDE,
|
|
'',
|
|
NCT_API,
|
|
'',
|
|
'## Minimal template',
|
|
'',
|
|
'```javascript',
|
|
DEFAULT_SCRIPT_TEMPLATE.trim(),
|
|
'```',
|
|
].join('\n');
|
|
}
|