@framers/agentos-ext-cli-executor

中文文档
1.3.4发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2万

AgentOS 的 CLI 执行器扩展名 - 执行 shell 命令并管理文件

中文使用文档
文档目录27 节
  1. 特征
  2. 安装
  3. 快速启动
  4. 工具
  5. shell 执行
  6. 文件读取
  7. 文件写入
  8. 列表( d)
  9. 已读文档
  10. 创建 pdf
  11. 创建页面( b)
  12. 创建( d)
  13. 警卫
  14. 危险图案检测
  15. 自定义块列表
  16. 故障安全检查(危险)
  17. 风险评估
  18. 配置
  19. 文件系统政策( 建议)
  20. 代理工作空间助手
  21. 使用大小写
  22. 代码生成和执行
  23. 项目设置
  24. 逻辑分析
  25. 文档处理管道
  26. 二一理论
  27. 许可证

代理OS 的 CLI 执行器扩展

执行 shell 命令,运行脚本,并为 AgentOS 代理管理文件. 这是两种基本原始(与Web浏览器相通)之一,能够使自建递归性代理能力.

特征

  • 执行壳牌: 运行输出抓取的任意 shell 命令
  • 文件管理: 读取、撰写和列出文件/目录
  • 文件一/O: 读取并写入 xlsx, csv, docx, 和 pdf 文件
  • 安保管制: 危险命令检测和屏蔽
  • 横线: 在 Windows、 macOS 和 Linux 上工作

安装

npm install @framers/agentos-ext-cli-executor

快速启动

import { ExtensionManager } from '@framers/agentos';
import { createExtensionPack } from '@framers/agentos-ext-cli-executor';

const extensionManager = new ExtensionManager();

// Load the pack into the runtime
await extensionManager.loadPackFromFactory(
  createExtensionPack({
    options: {
      defaultShell: 'bash',
      timeout: 60000,
      blockedCommands: ['rm -rf /', 'format'],
      // Restrict file_* tools to a per-agent workspace
      filesystem: { allowRead: true, allowWrite: true },
      agentWorkspace: { agentId: 'my-agent' },
    },
    logger: console,
  }),
  '@framers/agentos-ext-cli-executor',
);

工具

shell 执行

执行 shell 命令 .

const result = await gmi.executeTool('shell_execute', {
  command: 'npm install lodash',
  cwd: '/path/to/project',
  timeout: 30000
});
// Returns: { command, exitCode, stdout, stderr, duration, success }

文件读取

读取文件内容 .

const result = await gmi.executeTool('file_read', {
  path: './package.json',
  encoding: 'utf-8'
});
// Returns: { path, content, size, truncated, encoding }

// Read last 50 lines
const logs = await gmi.executeTool('file_read', {
  path: './app.log',
  lines: 50,
  fromEnd: true
});

文件写入

将内容写入文件 .

const result = await gmi.executeTool('file_write', {
  path: './config.json',
  content: JSON.stringify({ key: 'value' }),
  createDirs: true
});
// Returns: { path, bytesWritten, created, appended }

列表( d)

列表目录内容 .

const result = await gmi.executeTool('list_directory', {
  path: './src',
  recursive: true,
  pattern: '*.ts',
  includeStats: true
});
// Returns: { path, entries: [{ name, path, type, size, ... }], count }

已读文档

从二进制文档格式(xlsx,xls,csv,tsv,docx,pdf)中读取文本.

// Read an Excel spreadsheet
const result = await gmi.executeTool('read_document', {
  path: './data/report.xlsx',
  sheet: 'Q1 Revenue',  // optional: specific sheet
  maxRows: 200          // optional: limit rows (default: 500)
});
// Returns: { path, format, size, content (markdown tables), structured: { sheets }, metadata }

// Read a Word document
const doc = await gmi.executeTool('read_document', {
  path: './docs/proposal.docx'
});
// Returns: { path, format, size, content (extracted text), metadata }

// Read a PDF
const pdf = await gmi.executeTool('read_document', {
  path: './reports/annual.pdf'
});
// Returns: { path, format, size, content (extracted text), metadata: { pages, info } }

说明: file_read 自动将二进制格式(.xlsx,.docx,.pdf)重定向到 read_document 带有帮助的错误信息.

创建 pdf

从文本内容创建真实的 PDF 文档 .

const result = await gmi.executeTool('create_pdf', {
  path: './output/report.pdf',
  content: 'Annual Report\n\nRevenue increased 25% year over year...',
  title: 'Annual Report 2026',
  author: 'Research Agent',
  fontSize: 11
});
// Returns: { path, pages, bytes }

创建页面( b)

从结构化数据创建 Excel (.xlsx) 或 CSV 文件 .

// From headers + rows (2D array)
const result = await gmi.executeTool('create_spreadsheet', {
  path: './output/data.xlsx',
  headers: ['Name', 'Age', 'City'],
  rows: [['Alice', 30, 'NYC'], ['Bob', 25, 'SF']],
  sheetName: 'Contacts'
});
// Returns: { path, format, rows, bytes }

// From array of objects
const result = await gmi.executeTool('create_spreadsheet', {
  path: './output/users.xlsx',
  data: [
    { name: 'Alice', age: 30, city: 'NYC' },
    { name: 'Bob', age: 25, city: 'SF' }
  ]
});

// From a markdown table
const result = await gmi.executeTool('create_spreadsheet', {
  path: './output/report.csv',
  markdown: '| Product | Sales |\n| --- | --- |\n| Widget | 1500 |\n| Gadget | 2300 |'
});

// CSV output (auto-detected from extension)
const csv = await gmi.executeTool('create_spreadsheet', {
  path: './output/export.csv',
  headers: ['id', 'value'],
  rows: [['1', '100'], ['2', '200']]
});

创建( d)

从文本或下标内容创建 Word 文档(.docx) .

const result = await gmi.executeTool('create_document', {
  path: './output/report.docx',
  content: '# Quarterly Report\n\n## Summary\n\nRevenue was **$1.5M**, up *25%* from last quarter.\n\n- Widget sales: $800K\n- Gadget sales: $700K',
  title: 'Q1 Report',
  author: 'Research Agent'
});
// Returns: { path, paragraphs, bytes }

支持的下标 : # headings (H1-H6), (中文(简体) ), **bold**, (中文(简体) ), *italic*, (中文(简体) ), - bullet lists。 。 。 .

说明: file_write 自动将.pdf,.xlsx,和.docx重定向到专用的创建工具,并带有有帮助的错误信息.

警卫

该扩展包括内置安全控制:

危险图案检测

与这些模式相匹配的命令默认被屏蔽 :

  • rm -rf / (重复删除根)
  • format C: (格式驱动器)
  • 叉子炸弹
  • 直接磁盘写入
  • 系统关闭/重启命令

自定义块列表

createExtensionPack({
  options: {
    blockedCommands: ['sudo', 'su', 'chmod 777'],
    allowedCommands: ['npm', 'node', 'python', 'git'] // Whitelist mode
  }
});

故障安全检查(危险)

如果您需要完全控制(例如,在被锁定的容器或本地dev中),可以禁用所有命令安全检查:

createExtensionPack({
  options: {
    dangerouslySkipSecurityChecks: true
  }
});

风险评估

每项命令都按风险等级评估:

风险水平实例
safels, (中文(简体) ), cat, (中文(简体) ), npm list
lowecho "text" > file.txt
mediumrm file.txt, (中文(简体) ), eval
highsudo,“曲线”
criticalrm -rf /,阻断模式

配置

选项类型默认说明
defaultShell字符串auto要使用的外壳( bash, powershell, cmd, zsh)
timeout编号60000默认超时( 毫秒)
workingDirectory字符串process.cwd()默认工作目录
filesystem对象undefined文件QQ工具的可选政策( 读取/ 写出 + 根)
agentWorkspace对象undefined可选的代理工作空间目录帮助器
allowedCommands字符串 [][]命令白名单( 空 = 全部)
blockedCommands字符串 [][]命令黑名单( 内置危险模式外加)
dangerouslySkipSecurityChecks布尔false禁用所有命令安全检查( 只在信任的环境中使用)
env对象{}环境变量

默认情况下 file_* 工具可以访问任何路径(遗产行为). 要执行安全的文件系统沙盒, 请配置 filesystem + 根数 :

createExtensionPack({
  options: {
    filesystem: {
      allowRead: true,
      allowWrite: true,
      readRoots: ['/Users/me/Documents/AgentOS/agents/my-agent'],
      writeRoots: ['/Users/me/Documents/AgentOS/agents/my-agent'],
    },
  },
});

代理工作空间助手

为了简化安全默认, 您可以配置 agentWorkspace当与 filesystem.allowRead/allowWrite,扩展默认为工作空间目录的根.

createExtensionPack({
  options: {
    filesystem: { allowRead: true, allowWrite: true },
    agentWorkspace: {
      agentId: 'my-agent',
      // baseDir defaults to ~/Documents/AgentOS
      subdirs: ['assets', 'exports', 'tmp'],
    },
  },
});

使用大小写

代码生成和执行

// Write generated code
await gmi.executeTool('file_write', {
  path: './generated/app.py',
  content: generatedPythonCode,
  createDirs: true
});

// Execute it
await gmi.executeTool('shell_execute', {
  command: 'python ./generated/app.py',
  timeout: 30000
});

项目设置

// Create project structure
await gmi.executeTool('shell_execute', {
  command: 'npx create-react-app my-app --template typescript'
});

// Install dependencies
await gmi.executeTool('shell_execute', {
  command: 'npm install axios lodash',
  cwd: './my-app'
});

逻辑分析

// Read recent logs
const logs = await gmi.executeTool('file_read', {
  path: '/var/log/app.log',
  lines: 100,
  fromEnd: true
});

// Parse and analyze
const errorCount = logs.output.content.match(/ERROR/g)?.length || 0;

文档处理管道

// Read a spreadsheet, analyze it, write a report
const data = await gmi.executeTool('read_document', {
  path: './data/sales.xlsx',
  sheet: 'Q1'
});

// Create a summary report as Word doc
await gmi.executeTool('create_document', {
  path: './output/summary.docx',
  content: `# Sales Summary\n\n${data.output.content}`,
  title: 'Q1 Sales Summary'
});

// Export processed data as CSV
await gmi.executeTool('create_spreadsheet', {
  path: './output/processed.csv',
  headers: ['Region', 'Total'],
  rows: processedData
});

// Generate PDF invoice
await gmi.executeTool('create_pdf', {
  path: './output/invoice.pdf',
  content: invoiceText,
  title: 'Invoice #1234'
});

二一理论

这一扩展与Web浏览器扩展相结合,提供了递归自建剂所需的两个基本能力:

  1. CLI 执行者 (本扩展名)

    • 执行任意代码
    • 管理文件
    • 安装依赖关系
    • 运行测试并构建
  2. 网页浏览器 (见网页浏览器扩展名)

    • 搜索信息
    • 读取文档
    • 学习新技术
    • 核查执行情况

一个聪明的特工可以:

  1. 确定它需要学习的东西 网络搜索
  2. 查找文档/讲座 网络刮取
  3. 写入代码 – 文件写入
  4. 执行和测试 — shell 执行
  5. 调试和重排 ~ 重复

许可证

Apache-2.0 框架.dev

版本与发布记录

@framers/agentos-ext-cli-executor 共发布 8 个版本,首次发布于 2026/02/06;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.4latest2026/11/114 天前
1.3.32026/11/0115 天前
1.3.22026/10/2125 天前
1.3.12026/10/111 个月前
1.3.02026/10/081 个月前
1.2.02026/03/138 个月前

关于 @framers/agentos-ext-cli-executor 的常见问题

@framers/agentos-ext-cli-executor 是什么?

AgentOS 的 CLI 执行器扩展名 - 执行 shell 命令并管理文件

如何安装 @framers/agentos-ext-cli-executor?

在项目目录运行 npm install @framers/agentos-ext-cli-executor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@framers/agentos(>=0.10.40)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@framers/agentos-ext-cli-executor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@framers/agentos-ext-cli-executor 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@framers/agentos-ext-cli-executor 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@framers/agentos-ext-cli-executor 可以商用吗?

@framers/agentos-ext-cli-executor 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@framers/agentos-ext-cli-executor 的下载量有多少?

根据 npm 官方下载统计,@framers/agentos-ext-cli-executor 在 2026/10/16 – 2026/11/14 这 30 天内被下载 20,278 次,日均约 676 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@framers/agentos-ext-cli-executor 还在维护吗?

最新版本 1.3.4 发布于 2026/11/11(4 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。