Skip to content

feat: --encoded-command takes a base64 payload for agent/CI callers - #271

Merged
caomengxuan666 merged 1 commit into
fix/upstream-xgr-oneshotfrom
fix/upstream-xgr-encoded-command
Oct 12, 2026
Merged

caomengxuan666 merged 1 commit into
fix/upstream-xgr-oneshotfrom
fix/upstream-xgr-encoded-command

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

来源

适配自 x2410516039/xgr-niubash 提交 890f3b1 + deb7211(2026-09-16),保留原作者署名。Stacked on #270(走其 one-shot 路径;若 #270 先合并,本 PR base 会自动改回 master)。

问题

agent 宿主向 niu -c 传复杂命令要过两层引号地狱(宿主包装层 → shell 解析层),heredoc/嵌套引号易碎,base64 | niu 又多一个进程与一层管道。作者的做法:新增 launcher 词 niu --encoded-command <b64>,RFC 4648 base64 载荷直达执行器——零引号、零中间解释层、零额外子进程。

v1: 前缀是他的现场教训:base64 载荷可能以 / 开头(sextet 63,概率 1/64),MSYS 路径启发式会把它改写成 Windows 路径,命令在经 Git Bash 中转时被静默破坏;v1: 把首字符钉在 'v' 上,接收端剥离。

契约(与 -c 对齐)

  • BASH_ENV/NIU_ENV 照常 source(GNU bash 对 -c shells 的行为)
  • 载荷暴露为 BASH_EXECUTION_STRING;带 __RUBASH_IS_C 诊断标签(parser 错误取 $0: -c: line N: 形态,niubash#160)
  • padding 可省略、ASCII 空白忽略(预折行载荷直接可用);非 UTF-8 载荷拒绝并报错
  • 走 one-shot 快路径(perf: one-shot fast path for non-interactive -c invocations #270)

验证

  • 新增解码单测:padding 有无、空白、v1: 前缀、非法字符、非 UTF-8 拒绝(本分析移植时对测试向量逐一用独立实现复验过,含 //8= → 0xFF 0xFF 的非 UTF-8 案例)
  • 运行时冒烟:--encoded-command ZWNobyBoZWxsbw== → hello;v1: 变体同
  • 全量测试失败集与 master 逐名一致(同 perf: one-shot fast path for non-interactive -c invocations #270 的对比方法);cargo check --locked / cargo fmt --check --all 干净

New launcher word  executes an RFC 4648
base64 command string through the same one-shot path as -c. Agents get
a quoting-free channel: no heredoc gymnastics, no base64.exe
subprocess, and no second interpretation layer between the caller and
the parser. Padding is optional and ASCII whitespace is ignored so
pre-wrapped payloads pass through untouched; the payload must decode
to valid UTF-8. An optional  prefix is stripped defensively —
MSYS path conversion rewrites arguments starting with '/', and a base64
payload can start with '/' (sextet 63); 'v' pins the first character.

Same -c contract applies: BASH_ENV/NIU_ENV are sourced, the payload is
exposed as BASH_EXECUTION_STRING, and parser diagnostics carry the
__RUBASH_IS_C tag (niubash#160).

Adapted from x2410516039/xgr-niubash commits 890f3b1 + deb7211
(2026-09-16). The v1: prefix came from a live failure: routing the
payload through a Git Bash wrapper rewrote a leading '/' and corrupted
the command. Verified here: decode unit tests (padding, whitespace,
v1: prefix, invalid character, non-UTF-8 rejection), cargo check/fmt
clean.
@caomengxuan666
caomengxuan666 merged commit ab06e85 into fix/upstream-xgr-oneshot Oct 12, 2026
2 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/upstream-xgr-encoded-command branch October 13, 2026 02:06
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…1.4.0 section (#326)

- The [Unreleased] entries (#284/#287, #293-#304, #313) move into
  [1.4.0]; [Unreleased] is empty again.
- Newly recorded (today's wave): Git Bash compatible factory default
  prompt (#292, headline), WT-form shortcuts (#290/#211), the paste
  burst trailing-Enter fix (#308/#291), self-update SHA256 + release
  pinning (#311/#312), managed-block convergence (#324), completion
  tables/NIU_COMPDEFS/NIU_ENV probe (#305-#307), -s on-demand stdin
  (rubash#586 host half), bash/rbash invocation faces (#321/#322).
- Older gaps recorded: closed-stdout pipe contract (#245/#286), history
  session-end write-back (#265), sh POSIX contract (#262), PWD persona
  alignment (#283), one-shot fast path (#270), --cwd-state (#272),
  --encoded-command (#271), REPL-command highlighting (#281), docs
  passes (#255/#225/#226/#227), MSRV (#267), easter-egg prune (#264).

CHANGELOG-only change; no version claims.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants