arc attach 把本地目录反向挂载进一个远程 arc daemon,在那台远程 daemon 的 /modules/{namespace} 下暴露成一个 provider。这跟 arc afs mount 方向相反:不是把远程的东西挂进本地 AFS,而是把本地的东西让远程 AFS 看得到。
用法
arc attach --to <url> [options]严格必填的只有 --to;还需要传什么取决于你要挂的是下面三种东西里的哪一种:
- 目录 attach(默认那种):
--namespace <name>+--source <dir>——把本地目录暴露成一个挂在远程/modules/{namespace}下的 provider - host attach:
--as-host——把这台主机的 HostFace 导出到远程的/peers/{peer.json.id}(不需要--namespace/--source) - engine attach:单独用
--as-engine <name>——以这个 id 挂一个裸的 code-agents engine;和--as-host搭配用时,它只是显示用的元数据
选项
--to <url>(必填):目标 daemon 的 URL,比如ws://host:4900或ws://host:4900/ws/attach--namespace <name>:在目标上暴露用的 namespace,挂在/modules/{namespace}下(目录 attach 用)--source <dir>:要暴露成 provider 的本地目录(目录 attach 用)--as-engine <name>:单独的 engine id;配合--as-host用时只是显示元数据(远程 id 用的是peer.json的id)--as-host:把这台主机的 HostFace 导出到目标的/peers/{peer.json.id}--readonly:把这个源暴露成只读(目录 attach 用)--replace:替换这个 namespace 下已存在的 session--token <token>:远程 daemon 的所有者访问令牌(本地回环目标可以跳过)--browser:为授权流程打开浏览器(默认true);配合--token传--no-browser用于无人值守场景--json:在 stdout 打印机器可读的事件,而不是默认的人类文本--view:输出 view 格式(json等价于--json)--instance <name>/-i:这条命令作用在哪个本地 ARC 实例;省略即default--home <dir>:实例根(这台主机的peer.json和凭证放在哪;通常用不到)。要指定作用在哪个实例,用--instance
按 Ctrl+C(SIGINT)时,arc attach 会优雅地断开,让远程那边干净地卸载。
示例
arc attach --to ws://host:4900 --namespace my-local-src --source ./src --readonly
arc attach --to ws://host:4900 --as-host--json
加了 --json 之后,每一条进度行(Attaching...、to:、namespace:、source:、Press Ctrl+C to detach.、Detaching...)都挪到 stderr,stdout 只留下按行分隔的 JSON 事件——脚本 pipe arc attach ... --json 的 stdout 时可以直接当纯 JSON 解析,不用过滤掉人类可读的文字:
$ arc attach --to ws://127.0.0.1:PORT/ws/attach --source /tmp --namespace test --jsonstdout(成功 attach 时只有这一行):
{"event":"attached","sessionId":"sess_test_...","namespace":"test","targetPath":"/modules/test"}stderr(全部进度,banner 已省略):
Attaching...
to: ws://127.0.0.1:PORT/ws/attach
namespace: test
source: /tmp
Press Ctrl+C to detach.失败的时候,--json 并不会在 stdout 多出一个对应的 JSON 对象——stdout 留空,报错依然只是 stderr 上那行人类文本 ERROR: ...,缺必需参数组合和连接失败都是这样,退出码都是 5:
$ arc attach --to ws://127.0.0.1:1/ws/attach --source /tmp --jsonstdout:(空)
stderr:
ERROR: attach requires --namespace and --source, or --as-engine, or --as-host$ arc attach --to ws://127.0.0.1:9/ws/attach --namespace test --source /tmp --jsonstdout:(空)
stderr:
Attaching...
to: ws://127.0.0.1:9/ws/attach
namespace: test
source: /tmp
ERROR: attach failed [cockpit-unreachable]: connect ECONNREFUSED 127.0.0.1:9