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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

---

## 0.2.7

- SDK `runBatch`、CLI `batch` 和 MCP `run_batch` 支持在计划或步骤的 `layer` 中指定多个命名层。多层步骤按 `id@layer` 报告,`after` 等待前置步骤的所有实例成功,整个批次共享并发上限。
- 批次启动前拒绝重复层名、展开后的 ID 冲突和可能覆盖同一本地文件的多层下载。MCP 文本模式按展开实例和实际采集的输出流分摊预算。

## 0.2.6

- Docker 镜像补齐本地执行所需的 Bash,默认 MCP 层可直接执行命令。
Expand Down
7 changes: 4 additions & 3 deletions docs/skills/SKILL.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: filaxis-runtime
version: 0.2.6
version: 0.2.7
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.

Expand Down Expand Up @@ -58,9 +58,10 @@ filaxis exec --layer <name> --timeout 8000 -- "(printf 'PING\n'; sleep 1) | nc 1
## MCP Practical Guidelines

- **Batch inspection and multi-step fixes with `run_batch`**: Combine multiple `read_file`, `run_command`, `edit_file`, `put`, and `get` steps into a single parallel `run_batch` call instead of sequential single-tool loops.
- **Layer targeting precedence**: Top-level `layer` sets the batch default; per-step `layer` overrides only that step; omitting both uses the active default layer. `filaxis batch --request-file plan.json` shares the same precedence (step `layer` > plan `layer` > `--layer`/`--host` > local).
- **Layer targeting precedence & multi-layer fan-out**: Both top-level `layer` and per-step `layer` accept either a single layer name or a non-empty array of layer names (top-level sets the batch default; per-step overrides only that step; omitting both uses the active default layer). Multi-layer arrays expand each step into `id@layer` instances that run in parallel up to `max_parallel` (single-element arrays keep the original `id`), and downstream `after` dependencies wait for all expanded instances to succeed (`kind: "get"` rejects multi-layer arrays to avoid overwriting the same `local_path`). `filaxis batch --request-file plan.json` shares the same precedence and array expansion (step `layer` > plan `layer` > `--layer`/`--host` > local).
- **Local targeting**: Layer arrays look up registered or saved names. SDK callers can register the local host with `stack.addLayer("local", { driver: "local" })`. The CLI and standalone MCP server leave the local default unnamed.
- **Concurrency & ordering (`max_parallel` and `after`)**: Independent steps run in parallel up to `max_parallel`. Use `after: ["step-id"]` to serialize dependent steps (e.g., edit config -> validate -> reload service), even across layers.
- **Cross-batch coordination**: `after` applies within a single batch. Serialize concurrent batches modifying the same resource externally (e.g., keyed by environment identity + file path).
- **Resource coordination**: `after` references the original step IDs declared in the same batch. Fan-out executes once per layer name, and different names may point to the same environment. Serialize operations that modify the same resource using its environment identity and file path.
- **Text vs. structured output**: `run_batch` text previews share 4 KiB across streams and cap at 8 KiB total (prioritizing failed steps and edit guarantees). Clients that only read text blocks can pass `output: "text"`; use the default `output: "full"` to read full `structuredContent`. `run_command` previews up to 8 KiB per stream.
- **Start working right after connecting**: Do not waste turns running `hostname` or `list_layers` after `push_ssh`/`push_into` — the first `run_command`'s exit code and output confirm the layer.
- **Targeted file reading & minimal edits**: Inspect specific line ranges or recent logs (`sed -n '20,40p' <path>` or `docker logs --tail 30 <container>`). For `edit_file`, copy only the exact target lines with minimal unique context into `old`.
Expand Down
7 changes: 4 additions & 3 deletions docs/skills/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: filaxis-runtime
version: 0.2.6
version: 0.2.7
description: |
牵丝 Filaxis 远程执行运行时的技能剧本总入口——选型决策树(exec 还是观察还是会话)+ 核心契约速查 + 四份场景剧本索引。

Expand Down Expand Up @@ -47,10 +47,11 @@ filaxis exec --layer <名> --timeout 8000 -- "(printf 'PING
**MCP 形态实战指引**(第十二季盲测 B 组教训):
- **定位/巡检期用 `run_batch` 打包**——多个 read_file/run_command 一次调用并行
执行(B 组逐个调 18 步 vs CLI 组打包 11 步——这是 MCP 形态省步数的最大杠杆);
- `run_batch` 的顶层 `layer` 和步骤 `layer` 可以同时传。顶层是批次默认值,步骤的 `layer` 只覆盖本步。两处都省略的步骤使用调用时的默认层。结果逐步标明命名层。
- `run_batch` 的顶层 `layer` 和步骤 `layer` 均支持传单个层名或层名数组(也可同时传:顶层是批次默认值,步骤的 `layer` 仅覆盖本步;两处都省略时使用调用时的默认层)。传多个层名数组时,步骤按 `id@layer` 展开并在 `max_parallel` 并发池内并行执行,下游 `after` 需等被依赖步骤的所有展开实例均 ok 后才启动(`kind: "get"` 不支持多层数组,防并发覆盖同一 `local_path`);单元素数组保留原 `id`。结果逐步标明命名层。
- CLI 的 `filaxis batch --request-file plan.json` 同样支持这两个字段,并从 `filaxis layer save` 保存的层中解析名称。优先级依次为步骤 `layer`、计划 `layer`、命令行的 `--layer` 或 `--host`,全省略时使用本机。
- 层名数组只查已注册或保存的层。SDK 可用 `stack.addLayer("local", { driver: "local" })` 把本机加入命名层;CLI 和独立 MCP 服务的本机默认目标不会自动注册为 `local`。
- `max_parallel` 是整个批次的并发上限。无依赖的步骤可以并行,包括同层的独立巡检。需要先改配置、再验证、最后重载时,用 `after` 引用前置步骤的 `id`。依赖可以跨层,前置步骤成功后才会启动后续步骤。
- `after` 的作用域是当前批次。多个批次可能同时修改同一资源时,由调用方按实际资源串行化,例如用「环境身份 + 配置路径」作为互斥键。同一环境可能有多个层名。`run_batch` 本身不提供跨批次资源锁。
- `after` 引用当前批次计划里声明的原始步骤 ID。同一环境可能有多个层名,扇出按层名各执行一次。多个步骤或批次可能同时修改同一资源时,由调用方按实际资源串行化,例如用「环境身份 + 配置路径」作为互斥键。
- `run_batch` 文本逐步展示状态、退出码、编辑的写入方式和锁状态,以及 stdout/stderr 预览。所有输出流共用 4 KiB,整个文本字段序列化后最多 8 KiB,超出时优先显示失败步骤和编辑保障。只看文本块的 MCP 客户端请传 `output: "text"`。需要完整输出时用默认的 `output: "full"`,从 `structuredContent` 取。`run_command` 的文本各流最多预览 8 KiB。
- `output: "text"` 在本机和 SSH 层按预算采集 `exec` / `read` 预览,并继续读取完成哨兵来核实退出码。SSH 文件中转仍在磁盘接收完整输出,回读只取有界的首尾。其他层需要支持限量采集才能在文本模式下执行这些步骤。
- 建链后立即干活,**不要**逐个 hostname/list_layers 验证——首个 run_command
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@syrkos/filaxis",
"version": "0.2.6",
"version": "0.2.7",
"description": "牵丝 Filaxis — 面向自动化与 Agent 的远程执行运行时 SDK(Syrkos · 漩核)。千里一线,执行有迹。",
"type": "module",
"license": "Apache-2.0",
Expand Down
29 changes: 21 additions & 8 deletions src/agent-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { RuntimeStack } from "./runtime-stack.js";
import { editFile } from "./file-edit.js";
import { transferLayerFile, validateFileTransferFields, type FileTransferTransport, type LayerFileTransferResult } from "./layer-file-transfer.js";
import type { TransferResult } from "./file-transfer.js";
import { BATCH_STEP_KINDS, runBatch, type BatchStepWithDeps } from "./batch.js";
import { BATCH_STEP_KINDS, runBatch, type BatchLayerTarget, type BatchStepWithDeps } from "./batch.js";
import type { RuntimeDriver } from "./driver.js";
import { SessionOwnership, type StopResult } from "./session-ownership.js";

Expand Down Expand Up @@ -80,7 +80,7 @@ export interface AgentToolHandlers {
}>;
remove_layer(args: { name: string; destroy?: boolean }): Promise<{ removed: string }>;
// ── 批次组合(第十一季:一次调用描述多原子操作——减少 Planner 轮次)──
run_batch(args: { steps: Array<Record<string, unknown>>; stop_on_fail?: boolean; max_parallel?: number; layer?: string; output?: "text" | "full" }): Promise<{
run_batch(args: { steps: Array<Record<string, unknown>>; stop_on_fail?: boolean; max_parallel?: number; layer?: BatchLayerTarget; output?: "text" | "full" }): Promise<{
status: "ok" | "fail"; failed_step?: string;
steps: Array<{
id: string; layer?: string; kind: string; status: string; exit_code?: number; outcome?: "unknown"; stdout?: string; stderr?: string; error?: string; skipped_because?: string;
Expand Down Expand Up @@ -118,6 +118,15 @@ const fileTransferProperties = {
timeout_ms: { type: "integer", minimum: 1, maximum: 2147483647, description: "每次 SSH 命令或 SFTP 进程的超时毫秒数,缺省 120000" },
};

const layerNameSchema = { type: "string", minLength: 1, pattern: "\\S" };
const batchLayerSchema = (description: string) => ({
anyOf: [
layerNameSchema,
{ type: "array", minItems: 1, uniqueItems: true, items: layerNameSchema },
],
description,
});

/** 工具定义单一来源(REQ-0003 MCP tools/list 同源序列化——零漂移) */
export const TOOL_DEFS: AgentToolDef[] = [
// run_batch 置顶(第十三季黑盒实测:Lazy schema 按序读 6 个基础
Expand All @@ -129,9 +138,10 @@ export const TOOL_DEFS: AgentToolDef[] = [
name: "run_batch",
description:
"批次组合:一次调用描述多个文件或命令操作(exec/edit/read/put/get),按依赖边(after)拓扑执行——" +
"步骤 layer 可覆盖批次 layer;after 可跨层引用步骤 id。无依赖步骤并行,顺序链靠 after 显式保序;默认任一步失败即停(未启动步骤标 " +
"skipped)。返回逐步骤状态与证据(退出码/输出/编辑明细)。**不做自动回滚**(配置恢复≠运行" +
"状态回滚——重载可能已产生外部副作用),失败现场交回调用方决策。",
"批次与步骤 layer 均支持层名或层名数组。多个层名按 id@layer 展开,单个层名保留原 id;kind=get 只接受单层。" +
"after 引用计划中声明的步骤 id,等待该步骤在所有目标层成功。" +
"无依赖步骤并行,顺序链靠 after 显式保序;默认任一步失败即停(未启动步骤标 skipped)。返回逐步骤状态与证据(退出码/输出/编辑明细)。" +
"**不做自动回滚**(配置恢复≠运行状态回滚——重载可能已产生外部副作用),失败现场交回调用方决策。",
parameters: {
type: "object",
additionalProperties: false,
Expand All @@ -147,7 +157,7 @@ export const TOOL_DEFS: AgentToolDef[] = [
...fileTransferProperties,
id: { type: "string", description: "步骤唯一 id(after 引用用)" },
kind: { type: "string", enum: BATCH_STEP_KINDS },
layer: { type: "string", minLength: 1, description: "当前步骤的目标层名,覆盖批次默认层" },
layer: batchLayerSchema("覆盖批次默认层。多个层名按 id@layer 展开,单元素数组保留原 id;kind=get 只接受单层"),
command: { type: "string", description: "kind=exec:shell 命令" },
expect_exit: { type: "array", items: { type: "number" }, description: "kind=exec:预期退出码集合(缺省 [0])" },
timeout_ms: { type: "number", description: "kind=exec:超时毫秒" },
Expand All @@ -173,7 +183,7 @@ export const TOOL_DEFS: AgentToolDef[] = [
},
stop_on_fail: { type: "boolean", description: "失败即停(缺省 true)" },
max_parallel: { type: "number", description: "并行度上限(缺省 3)" },
layer: { type: "string", minLength: 1, description: "批次默认目标层名(缺省=调用时的默认层)" },
layer: batchLayerSchema("批次默认目标层名或层名数组(缺省=调用时的默认层;传数组时未覆盖 layer 的步骤自动展开到各层并行执行)"),
output: { type: "string", enum: ["text", "full"], description: "MCP 输出模式。text 适合只读文本块的客户端,保留简短预览;full(默认)另在 structuredContent 保留完整输出" },
},
required: ["steps"],
Expand All @@ -185,7 +195,7 @@ export const TOOL_DEFS: AgentToolDef[] = [
function: {
name: "run_command",
description:
"执行会自行结束的一次性命令(多条命令/多文件操作请改用 run_batch 一次并行打包;" +
"执行会自行结束的一次性命令(多条命令或多文件操作请用 run_batch;同一命令发往多个层时可传 layer 数组;" +
"持续盯实时输出且不关心退出码的命令如 tail -f 请改用 observe_stream 直接启动并流式读取;" +
"需后台起停服务、等就绪标记并核实进程退出码的任务请改用 spawn_and_observe)。" +
"退出码如实返回(非零不是异常——是数据,供条件分支);只有无法执行(超时/中断/连接死)才报错。stdout 与 stderr 分离返回。",
Expand Down Expand Up @@ -541,6 +551,9 @@ export function createAgentToolkit(stack: RuntimeStack, opts: AgentToolkitOption
get layer(): Promise<RuntimeDriver> { return layer(); }, // 惰性 getter(失败不缓存+注册命名表——Hydrogen R7 #4)
handlers: {
async run_command({ command, timeout_ms, layer: layerName }) {
if (Array.isArray(layerName)) {
throw new Error("run_command 的 layer 仅支持单个层名;同一命令发往多个层请改用 run_batch 并传 layer 数组");
}
const drv = await resolveDrv(layerName);
const r = await drv.exec(command, { timeoutMs: timeout_ms });
return {
Expand Down
Loading