本页内容
Sommatic 文档
打开控制台

Local File System

在宿主机上读写文件。

以 Markdown 查看
在以下应用中打开
输入与输出 可用 io.local.file 版本 1.0.0 执行方式: async

在运行 worker 的主机文件系统上读取、写入、追加、删除或列出指定路径。

工作原理

  1. 解析配置。path、operation(默认 read)、content(默认为空)和 encoding(默认 utf8)缺失时回退到输入 payload 中的同名键。
  2. path 为空时从 error 失败输出。
  3. 执行操作:read 以 encoding 解码并返回文件内容;write 用 content 覆盖文件;append 在末尾追加 content;delete 删除文件;list 返回目录中的条目名称。
  4. 从 out 返回 { result };任何文件系统错误都从 error 输出。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-write-export",
  "label": "Write export",
  "operator_slug": "io.local.file",
  "operator_version": "1.0.0",
  "config": {
    "path": "/data/exports/orders-{{ $json.date }}.csv",
    "operation": "write",
    "content": "{{ $json.csv }}"
  }
}

配置

path string 必填

绝对路径

operation string 必填

默认值: read

可选值: readwriteappenddeletelist

content string 可选

要写入/追加的内容

encoding string 可选

默认值: utf8

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

encoding
仅对 read 生效。write 和 append 始终写入 UTF-8 文本。
path
相对路径以编排器进程的工作目录为基准解析。

输出端口

out 默认

操作成功。read 时 result 为文本,list 时为名称数组,其他操作为 { written | appended | deleted: true, path }。

数据
{
  "result": {
    "written": true,
    "path": "/data/exports/orders-2026-11-25.csv"
  }
}
error

缺少 path、操作未知,或文件系统拒绝了该调用。

数据
{
  "error": "ENOENT: no such file or directory, open '/data/exports/missing.csv'"
}

在表达式中

后续节点可通过 $("Local File System").item.json.<路径> 读取此节点输出中的内容(请把 Local File System 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Local File System").item.json.resultstring= {…}文件内容或操作成功状态
$("Local File System").item.json.result.writtenboolean编辑器不提示= true—
$("Local File System").item.json.result.pathstring编辑器不提示= "/data/exports/orders-2026-11-25.csv"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
path is required error 配置和输入 payload 中都没有路径。请使用绝对路径。
Unsupported operation: <operation> error operation 不是 read、write、append、delete 或 list。
ENOENT: no such file or directory, <syscall> '<path>' error 主机上不存在该文件或其父目录。write 和 append 不会创建缺失的目录。
EACCES: permission denied, <syscall> '<path>' error 编排器进程对该路径没有权限。

输入契约

path string 必填
operation string 必填
content string 可选
encoding string 可选

输出契约

result string 可选

文件内容或操作成功状态

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "io.local.file",
  "name": "Local File System",
  "category": "io",
  "version": "1.0.0",
  "description": "Read/Write files on host machine.",
  "capabilities": [
    "fs",
    "local",
    "file"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "path": {
        "type": "string",
        "description": "Absolute path"
      },
      "operation": {
        "type": "string",
        "enum": [
          "read",
          "write",
          "append",
          "delete",
          "list"
        ],
        "default": "read"
      },
      "content": {
        "type": "string",
        "description": "Content to write/append"
      },
      "encoding": {
        "type": "string",
        "default": "utf8"
      }
    },
    "required": [
      "path",
      "operation"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "path": {
        "type": "string"
      },
      "operation": {
        "type": "string"
      },
      "content": {
        "type": "string"
      },
      "encoding": {
        "type": "string"
      }
    },
    "required": [
      "path",
      "operation"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "string",
        "description": "File content or operation success status"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "FS operation succeeded",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "FS operation failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent",
    "local-agent"
  ],
  "tags": [
    "local",
    "files"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
能力
fslocalfile
标签
localfiles

说明与限制

  • 路径指向运行 worker 的主机或容器,其环境可能是临时的;写入的文件在重新部署后不会保留。
  • write 会直接覆盖且不提示确认,delete 不可恢复。list 不递归。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档