Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
5. **通道语义**:缺省 `channel:"exec"`(stdout/stderr 分离、**层上下文拼装**——层的 cwd/env/enter 进入管线〔`docker exec`/`ssh` 形态〕在独立通道自动非交互重放,exec 直达层内环境);`channel:"pty"` 继承层内交互状态(su/cd),但 **stderr 混流是终端物理语义**,不是 bug。多跳 PTY 链与交互式二次跳转对 exec 通道**显式拒绝**——这是诚实行为,换 pty 或把途径机收敛为 `-J`。`-J`/`--host` 传 ssh-config **别名**时,别名解析用的是**本运行环境**的 `~/.ssh/config`——沙箱/远端会话里可能没有该条目(连接层报错会带此提示),跨环境请用 `user@host[:port]` 字面量。`jump` 只支持**单跳**(结构化 `SshJumpSpec` 正门/字符串白名单解析——跳板参数会拼进经 shell 执行的 ProxyCommand,白名单外字符直接拒绝);多跳逗号链显式拒绝,多跳正门是层模型 `sshInto` 逐跳派生。
6. **跨流顺序**:双文件落盘后的聚合序是**本地到达序**(近似),不承诺进程真实写入序。
7. **方言适配自动进行**:base64/sha256 按连接探测缓存(OPNsense/Alpine 形态已测)——但你自己的远端脚本原语若依赖 GNU 方言,请同样探测,勿硬编码。
8. **CAS 校验 ≠ 写入原子性(两轴正交,看 `writeMode` 字段)**:受控编辑/传输缺省 tmp+mv 原子替换(`atomic-replace`);**Docker 单文件 bind mount 挂载点 mv 不可用**(EBUSY/EXDEV)——自动降级保留 inode 写入(`inplace-write`):写入中断可能暴露半截文件,消费方须知。已知挂载环境可显式传 `writeMode:"inplace"` 跳过失败尝试。`mutex`(锁保护)与 `verification`(校验等级)同理都是独立轴——别把四个保证混读成一个「成功」。
8. **CAS(Compare-and-Swap,比较后写回)**。受控编辑读取 UTF-8 文件及其版本信息,按字面匹配替换片段,然后在写回前比对文件的修改时间、大小和内容指纹。发现文件版本变化时拒绝写回。分别查看 `mutex`(锁保护)与 `writeMode`(写入方式):`atomic-replace` 通过临时文件替换目标,`inplace-write` 保留 inode,中断可能留下部分内容。Docker 单文件 bind mount 可自动降级为原地写入,已知挂载点也可显式传 `writeMode:"inplace"`。大文件回退路径前后核验,并报告 `mutex:"degraded"` 和 `writeMode:"inplace-write"`。文件传输另用 `verification` 报告传输校验等级。
9. **PTY 键入大数据的边界(依赖面声明)**:canonical 行规程的 4096 在 Linux 实测是 **read 分段线而非丢弃线**(无 readline 的 sh 层 + 消费者忙/闲双场景、单行 16K 均完整——缓冲满时 master 写入被流控阻塞退避不丢;回归已钉住,退化即红)。但这**不是跨平台统一保证**(BSD 规程/老内核行为无承诺);传输数据一律经 b64 中继(字母表对行规程/ICRNL/INTR/EOF 结构免疫,控制字符回归锁定)。非 Linux 环境 tmux 层传超大单行前先小载荷探路。

## 环境规格与漂移
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

---

## 0.2.9

- MCP 新增 `list_directory`、`set_active_layer` 和非递归的 `delete_file`。
- `read_stream` 的 MCP 文本块显示日志帧和相应游标。后台会话与观察窗的选择条件移到工具描述首句。
- 命令和受控编辑拒绝无效目标参数,避免误用默认层。批量 `push_ssh` 返回前核对连接句柄,报告建连期间被移除或替换的层。
- 中英文 Skill 将任务选型放在入口,并解释 Compare-and-Swap(CAS)的写前检查、锁保护和写入方式。

## 0.2.8

- MCP 和 Agent Toolkit 的 `push_ssh` 可按目标或 SSH 配置别名列表批量建立命名层,逐目标报告新建、复用或连接失败,并返回可用于 `run_batch.layer` 的实际层名。
Expand Down
8 changes: 4 additions & 4 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (stop.status === "unknown") {
| Long-running sessions | `execSession` returns immediately. Output is recorded in separate `.out` and `.err` files and is available through a recent-output buffer, line watchers, and readiness checks. |
| Streaming observation | A separate SSH channel streams live output. It can share the SSH master connection through ControlMaster where available. |
| Persistent sessions | The tmux backend can reattach across processes by `terminalId` and restore the working directory. |
| File transfer and editing | `putFile` and `getFile` verify size and, when available, SHA-256 with support for GNU, BSD, and BusyBox tools. `editFile` performs compare-and-swap edits and reports the write mode, lock protection, and verification level. |
| File transfer and editing | `putFile` and `getFile` report the verification level, using size and SHA-256 when available. `editFile` uses compare-and-swap (CAS) to check the file version before writing, and reports the lock protection and write mode. |
| Environment discovery | Discover installed tools and GPU capabilities, select suitable layers with `matchLayers({ needs })`, and flag saved results when fingerprints drift. |
| Connection management | Reuse connections by topology fingerprint. Filaxis reconnects with backoff and tracks degraded layers. |
| SSH host verification | Trust on first use by default, with explicit strict mode and a configurable `known_hosts` file. The SDK accepts private-key paths. |
Expand Down Expand Up @@ -86,12 +86,12 @@ Or launch it directly with `npx` in your MCP client configuration:
}
```

Exposed MCP tools (15 tools):
Exposed MCP tools (18 tools):

- **Execution & batching**: `run_command`, `run_batch`
- **Long-running sessions & observation windows**: `spawn_and_observe`, `stop_and_verify`, `observe_stream`, `read_stream`, `close_stream`
- **File operations & transfers**: `read_file`, `edit_file`, `put_file`, `get_file`
- **Layer management**: `push_ssh`, `push_into`, `list_layers`, `remove_layer`
- **Files and directories**: `list_directory`, `read_file`, `edit_file`, `put_file`, `get_file`, `delete_file`
- **Layer management**: `push_ssh`, `push_into`, `list_layers`, `set_active_layer`, `remove_layer`

The npm package includes the [English agent skill](./docs/skills/SKILL.en.md), [four playbooks](./docs/skills/), and the [runtime contract](./AGENTS.md). Register the skill according to your agent's conventions.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ stack.events.on("exit", (e) => console.log("session", e.sessionId, "exit", e.exi
| 观察流 | 内置 | 独立 SSH channel 真流式直推(无轮询);ControlMaster 复用;注意力衰减回收 |
| 持久会话 | 内置 | tmux 后端 terminalId 跨进程 re-attach + cwd 恢复 |
| 文件传输 | 内置 | `putFile/getFile` base64 管道分块 + size/sha256 双校验 + **方言适配**(GNU/BSD/busybox——OPNsense/Alpine 不再必错) |
| 受控编辑 | 内置 | `editFile` CAS 原子写回(写入形态/锁保护/校验等级三轴显式报告,见 AGENTS.md 第 8 条) |
| 受控编辑 | 内置 | `editFile` 用 Compare-and-Swap(CAS)在写回前核对文件版本。结果分别报告锁保护和写入方式,详见 AGENTS.md 第 8 条。 |
| 环境规格 | 内置 | 两段式自发现(语言/GPU/关键包)蒸馏落盘;`matchLayers({needs})` 按需选层;指纹漂移标 stale |
| 连接治理 | 内置 | 连接拓扑指纹复用(同拓扑零重建);3 次退避自动重连;层状态机与退化哨兵 |
| 安全边界 | 内置 | host key 策略显式(tofu 缺省/strict+known_hosts);凭据只传路径永不外泄;渲染永不含密钥内容 |
Expand Down Expand Up @@ -87,12 +87,12 @@ filaxis mcp-config --format toml # TOML,使用 mcp_servers(Codex)
}
```

暴露的 15 个 MCP 工具速览:
暴露的 18 个 MCP 工具速览:

- **命令与批处理**:`run_command`、`run_batch`
- **长跑会话与观察窗**:`spawn_and_observe`、`stop_and_verify`、`observe_stream`、`read_stream`、`close_stream`
- **文件读写与传输**:`read_file`、`edit_file`、`put_file`、`get_file`
- **多层连接管理**:`push_ssh`、`push_into`、`list_layers`、`remove_layer`
- **文件与目录**:`list_directory`、`read_file`、`edit_file`、`put_file`、`get_file`、`delete_file`
- **多层连接管理**:`push_ssh`、`push_into`、`list_layers`、`set_active_layer`、`remove_layer`

npm 包包含 [Skill 入口与四份子剧本](docs/skills/SKILL.md),以及配套的 [AGENTS.md](AGENTS.md)。需要登记 Skill 时,由 Agent 按自身平台的规则处理这些文件。

Expand Down
3 changes: 2 additions & 1 deletion bin/filaxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ async function main() {
} catch (e) {
throw new Error(`JSON 载荷解析失败(${o.requestFile ?? "stdin"}): ${(e as Error).message}`);
}
if (typeof req.old !== "string" || typeof req.new !== "string") {
if (!req || typeof req.old !== "string" || typeof req.new !== "string"
|| (req.all !== undefined && typeof req.all !== "boolean")) {
throw new Error('JSON 载荷需含字符串字段 "old" 与 "new"(可选 "all": boolean)');
}
old = req.old;
Expand Down
51 changes: 21 additions & 30 deletions docs/skills/SKILL.en.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
---
name: filaxis-runtime
version: 0.2.8
metadata:
version: "0.2.9"
description: |
Entry skill guide for the Filaxis remote execution runtime (@syrkos/filaxis) — 30-second execution mode selector, MCP/CLI/SDK recipes, and core execution contracts for reliable SSH, Docker, and multi-hop agent operations.

Read before starting:
- Any cross-layer or remote command execution, log observation, background session, file edit/transfer, or multi-host troubleshooting task
- Interpreting `unknown` termination outcomes or 3-axis file-write guarantees (`mutex`, `writeMode`, `verification`)
- Diagnosing connection failures (SSH config aliases, jump hosts, or no-ProxyJump bastion traversal)

Skip when:
- Running simple local one-off commands directly in the host shell
- Working on tasks unrelated to remote execution or Filaxis
Use Filaxis (@syrkos/filaxis) to run commands across layers, batch inspections, manage background jobs, follow logs, or operate on files.
Also use it to diagnose SSH aliases and jump hosts or interpret unknown outcomes and write guarantees. Skip for simple local shell commands and tasks unrelated to Filaxis.
---

# Filaxis Agent Skill — Quick Start & Runtime Guide
Expand All @@ -26,7 +19,21 @@ description: |

---

## 10-Second Start: Copy-Paste CLI Recipes (Do Not Read Source Code First)
## Choose an entry point

Match the task to an entry point and read the relevant playbook. After execution, check the exit code, readiness marker, or file result. Verify an unknown outcome before deciding whether to retry.

| Task | MCP tool or reference |
|---|---|
| Wait for one finite command and collect its exit code | `run_command` |
| Batch inspections or apply dependencies across layers | `run_batch`. For bastions or multi-host investigation, read [Cross-host diagnosis](./cross-host-diagnosis.md) |
| Start a background service, wait for readiness, or verify its exit code | `spawn_and_observe` → `stop_and_verify`. Read [Long-running jobs](./longrun-observe.md) |
| Follow logs with a cursor and close the view when finished | `observe_stream` → `read_stream` → `close_stream`. Read [Observation windows](./stream-window.md) |
| List a directory, read, edit, transfer, or delete a file | `list_directory`, `read_file`, `edit_file`, `put_file`, `get_file`, `delete_file`. Read [File operations](./file-sync.md) |
| Switch back to an existing layer as the default | Find its name with `list_layers` and call `set_active_layer`. Pass `layer` for a one-call override |
| Observe a command for a limited interval in the CLI | `filaxis observe` |

## CLI quick start

> Reading package source files upfront wastes hundreds of thousands of tokens. Use these recipes directly:

Expand Down Expand Up @@ -94,7 +101,7 @@ const ctr = await stack.layerInto("prod", "web", "docker exec -i nginx sh");
const res = await host.driver.exec("uptime", { timeoutMs: 10_000 });
console.log(res.exitCode, res.stdout, res.stderr);

// 3. Controlled CAS edit (pass writeMode: "inplace" for Docker single-file bind mounts)
// 3. Controlled edit with a pre-write version check (writeMode: "inplace" for single-file bind mounts)
const ed = await editFile(ctr.driver, "/etc/nginx/nginx.conf", "worker_processes 1;", "worker_processes auto;", {
writeMode: "auto",
});
Expand Down Expand Up @@ -122,22 +129,6 @@ await stack.removeLayer("prod", { destroy: true });

---

## 30-Second Decision Tree

```
Will the command exit on its own?
├─ Yes (one-off: curl / nginx -t / systemctl status) ──→ run_command / exec (exit code is data)
├─ No (tail -f / top / long-running daemon / training)
│ ├─ Quick time-bounded snapshot ───────────────────→ CLI observe (default 8s snapshot)
│ ├─ Wait for ready marker / error pattern & verify exit → spawn_and_observe + stop_and_verify
│ └─ Live non-destructive stream cursor / paging ───→ observe_stream → read_stream → close_stream
└─ Modifying or moving remote files
├─ Text config / code edits ──────────────────────→ edit_file (CAS + lock + writeMode)
└─ Binary or full-file transfers ─────────────────→ put_file / get_file (or run_batch)
```

---

## Core Execution Contracts (Never Violate These)

| Contract | Rule |
Expand All @@ -146,7 +137,7 @@ Will the command exit on its own?
| **Exit code is data** | Nonzero command exit codes do **not** throw in `exec` / `run_command`. Only execution failures (timeout, abort, dead transport) reject or error. |
| **Completion sentinel required** | Missing completion markers (disconnect, remote kill, local abort) produce `outcome: "unknown"` — never fabricate exit code `0` and never blindly replay non-idempotent commands. |
| **No never-ending commands in `exec`** | `exec` / `run_command` waits for completion — `tail -f` or `top` will time out. Use `observe_stream` (for streaming logs) or `spawn_and_observe` (for managed background jobs). |
| **Three orthogonal write axes** | Inspect `mutex` (lock protection), `write_mode` (`atomic-replace` vs. `inplace-write` for bind mounts), and `verification` (size / SHA-256) independently. |
| **Controlled edits** | CAS stands for compare-and-swap. Filaxis checks modification time, size, and a content fingerprint before writing and rejects a version conflict. Check `mutex` and `write_mode` separately. For file transfers, check `verification`. |
| **PTY combines stderr** | `channel: "pty"` merges stdout and stderr by terminal semantics; default `exec` keeps them separate. |
| **SSH aliases are host-local** | `--host` and `-J` / `jump` aliases resolve against the runtime host's `~/.ssh/config`. Use explicit `user@host[:port]` literals when running across containers or sandboxes. |

Expand Down
Loading