# @framers/agentos-ext-cli-executor 中文文档

规范地址：https://npmcn.com/package/%40framers/agentos-ext-cli-executor/

版本：1\.3\.4
npm 元数据更新时间：2026-11-11T08:00:53.405Z
中文译文更新时间：2026-11-15T12:23:03.884Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40framers/agentos-ext-cli-executor
原文对照：https://npmcn.com/package/%40framers/agentos-ext-cli-executor/?lang=original
项目主页：https://github.com/framerslab/agentos-extensions/tree/master/registry/curated/system/cli-executor#readme
源码仓库：https://github.com/framerslab/agentos-extensions

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：154 kB，44 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=22
- 运行依赖：4 个
- peer 依赖：@framers/agentos \>=0\.10\.40
- 首次发布：2026-02-06T12:58:13.159Z
- 最新版本发布：2026-11-11T08:00:52.934Z
- 近 30 天下载量：20278（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 8 个）

## 中文简介

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

## 安装

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

也可以使用：`pnpm add @framers/agentos-ext-cli-executor`、`yarn add @framers/agentos-ext-cli-executor`、`bun add @framers/agentos-ext-cli-executor`

## README

# 代理OS 的 CLI 执行器扩展

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

## 特征

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

## 安装

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

## 快速启动

```typescript
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 命令 .

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

### 文件读取

读取文件内容 .

```typescript
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
});
```

### 文件写入

将内容写入文件 .

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

### 列表( d)

列表目录内容 .

```typescript
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)中读取文本.

```typescript
// 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 文档 .

```typescript
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 文件 .

```typescript
// 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) .

```typescript
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:` (格式驱动器)
-   叉子炸弹
-   直接磁盘写入
-   系统关闭/重启命令

### 自定义块列表

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

### 故障安全检查(危险)

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

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

### 风险评估

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

| 风险水平 | 实例 |
| --- | --- |
| `safe` | `ls`, (中文(简体) ), `cat`, (中文(简体) ), `npm list` |
| `low` | `echo "text" > file.txt` |
| `medium` | `rm file.txt`, (中文(简体) ), `eval` |
| `high` | `sudo`,“曲线” |
| `critical` | `rm -rf /`,阻断模式 |

## 配置

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

### 文件系统政策( 建议)

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

```ts
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`,扩展默认为工作空间目录的根.

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

## 使用大小写

### 代码生成和执行

```typescript
// 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
});
```

### 项目设置

```typescript
// 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'
});
```

### 逻辑分析

```typescript
// 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;
```

### 文档处理管道

```typescript
// 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 是什么？

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 和提交记录判断。

