---
# 内置节点：执行 Node.js
description: |
  Execute Node.js script via agentflow apply -ai run-tool-nodejs.

  **Success/Failure:** Determined by script process **exit code**—0 = success, non-0 = failed.
  **Result Output:** Script stdout directly becomes result slot content (plain text, e.g., `console.log("hello")`).
  When stdout is empty and exit code is non-0, stderr info will be written to failure message.

  **JSON Compatible (Optional):** If stdout is `{"err_code":0,"message":{"result":"..."}}` format, err_code will override exit code semantics, message.result writes to result slot. Only use when needing different success/failure semantics than exit code.

  **Direct Execution Mode (Recommended):** Set `script` field in flow.yaml instance, pipeline will skip AI and execute directly.
  `script` supports ${} placeholders (workspaceRoot, flowName, runDir, flowDir and all input/output slots), values are auto shell-quoted.
  flowDir is absolute path of current pipeline flow.yaml directory, can be used to reference scripts in same directory.
  Example: `script: node ${flowDir}/scripts/my-check.mjs --root ${workspaceRoot} --input ${todo}`

  **Pin Path Constraint (Important):** File paths read/written by script **must be passed via pins**, forbidden to construct output paths inside script.
  - All input slots with type 'file' (e.g., `figma_tree`, `semantic_outline`) are parsed from upstream connections by pipeline, script receives via CLI args.
  - All output slots with type 'file' (e.g., `restore_todolist`, `screenshot_map`) are generated by pipeline as absolute paths following `output/<instanceId>/node_<instanceId>_<slot>.md` convention, script receives via CLI args and writes directly.
  - Use `${slotName}` in `script` field to get correct path, e.g., `--figma-tree ${figma_tree} --output ${restore_todolist}`.
  - **Forbidden** to use `outDirForNode`, manually write `node_<instance>_xxx.json` etc. in script—this causes script output path mismatch with pipeline parser convention, downstream nodes cannot find files.

  **AI Execution Mode (Legacy):** Without `script` field, AI agent reads body and manually executes commands.

  **Underlying Usage:**
  agentflow apply -ai run-tool-nodejs <workspaceRoot> <flowName> <uuid> <instanceId> [execId] -- <scriptCmd> [args...]
displayName: NodeJs
input:
  - type: node
    name: prev
    default: ""
output:
  - type: node
    name: next
    default: ""
  - type: text
    name: result
    default: ""
---
${USER_PROMPT}
