Skip to content

api(bind): add BindKindView::Keymap so the view reports keymap bindings faithfully - #3616

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/3013-bindkindview-keymap
Nov 17, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/3013-bindkindview-keymap

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

BindKindView gains a Keymap variant mirroring BindKind (rl_generic_bind ISKMAP value — old-style keyname: prefix-meta binds the sequence to the emacs-meta map, bind.c:1845-1855). Previously the capture collapsed such entries into BindKindView::Function{name: "prefix-meta"}, so a host could not tell a keymap-valued slot from a real function binding — the gap niubash #959 covered with a wildcard arm (rubash#3013, GAP-13 实体部裁定 Q-A(ii)).

  • BindView::capture maps BindKind::Keymap → BindKindView::Keymap; the dump arm still renders "seq": prefix-meta (rl_function_dumper prints ISKMAP slots that way).
  • Session::register_binding accepts the variant → BindKind::Keymap (ISKMAP 语义不变).
  • docs/api-ledger.md 两处变体清单补 Keymap; niu 侧显式臂与其账本行为配套的 niubash 半单(本 PR 只落 rubash 侧)。

Pin: issue3013_keymap_kind_round_trips_through_the_view(Control-v: prefix-meta → Keymap{emacs-meta} + register_binding 回写往返),consumer_tests 124 全绿,check-api-ledger 287 符号齐,零编译警告。

Refs #3013.

caomengxuan666 and others added 2 commits November 14, 2026 15:26
…fresh local

A local/declare operand that creates a FRESH local inside a function
binds the new mutable instance — an outer-scope readonly mark on the
same name must not fire (GNU make_local_variable, declare.def:929+ /
variables.c:5524+). The nested_readonly check consulted the flat
READONLY_VARS name mark without regard to locally_scoped, so
'local x=(7 8 9)' inside a caller holding 'local -r x' spuriously
reported 'x: readonly variable' (while still binding).

Also gate local_context on the declare family: export/readonly operands
always bind the inherited (global) variable (setattr.def:240-268), so
the non-localizing readonly refusal still fires for them — verified
against GNU 5.3.20 (export/declare -g on a global readonly inside a
function: diagnostic, then the body continues).

Same-scope re-local on a readonly local still refuses; an inner-scope
readonly mark shadowed by a fresh local stays scoped to its instance.

Fixes #3609. Refs #2666 (varenv19.sub ccc).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…gs faithfully

BindKindView now carries a Keymap variant mirroring BindKind
(rl_generic_bind's ISKMAP value — e.g. old-style 'keyname: prefix-meta'
binds the sequence to the emacs-meta map, bind.c:1845-1855). Previously
the capture collapsed such entries into BindKindView::Function{name:
"prefix-meta"}, so a host could not distinguish a keymap-valued slot
from a real function binding (GAP-13 entity-part ruling, rubash#3013).

- capture maps BindKind::Keymap -> BindKindView::Keymap; the dump arm
  still renders the slot as 'seq: prefix-meta' (GNU rl_function_dumper
  prints ISKMAP entries that way).
- Session::register_binding accepts the variant, converting it back to
  BindKind::Keymap (ISKMAP assignment semantics unchanged).
- docs/api-ledger.md variant lists updated on both rows; the niu-side
  explicit arm + its ledger row are the paired niubash change.

Refs #3013. Refs niubash#863 GAP-13.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3616 第1轮 — 建议:FAIL
head: 6badbab base(merge-base): 27e1d0d 文件: 6 个 +171/-20(实际有效面 4 文件,见 F2)
关联 issue: #3013(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • Keymap 变体本身正确:GNU lib/readline/bind.c:1845-1855 的 PREFIX_META_HACK 对 old-style keyname 走 rl_generic_bind (ISKMAP, seq, emacs_meta_keymap, _rl_keymap)——绑定值是键位图,不是函数名;旧实现把 BindKind::Keymap 渲染成 BindKindView::Function{name:"prefix-meta"} 是失真,本 PR 改成 Keymap{name} + Session::register_binding 回写,dump 仍渲染 : prefix-meta(rl_function_dumper 对 ISKMAP slot 的输出),语义自洽。docs/api-ledger.md 两处变体清单同步。
  • 无产品行为改动(bind 视图/注册面),无旁路/翻译层。

腿(逐项给数字与名字):

  • 钉自跑:新钉在 lib 内(src/api/consumer_tests.rs 的 issue3013_keymap_kind_round_trips_through_the_view)。cargo test --lib → 1351 passed / 1 failed;新钉本身 ok(1351 比 base 的 1350 恰好多 1)。失败名 = api::consumer_tests::issue2084_session_end_restores_host_process_state(Windows-env 基线)。
  • fail-first:结构性不适用——钉引用 BindKindView::Keymap,base 27e1d0d 的 src/api/bind.rs 没有该变体(git show 27e1d0d2:src/api/bind.rs | grep -n Keymap 只有内部 BindKind::Keymap,视图侧不存在),钉在 base 上编译即红(E0599)。这不是废钉,是 API 新增的固有限制。
  • lib 双边:head 失败名集 {issue2084…} / base 失败名集 {issue2084…} / 差集 ∅(head 多 1 个通过 = 本钉)。
  • -D warnings:本 PR 文件 0 新增。
  • 卫生:fmt rc=0(bind.rs / session.rs / consumer_tests.rs 逐个);scripts/check-api-ledger.py → all 287 ledger symbols present;marker-lint OK;utf8 脚本不存在(VOID)。
  • CI:本 PR 自己的红 = niubash builds against this tree(job 132496105137):cmp rubash/docs/api-ledger.md niubash/docs/api-ledger.md → differ: byte 9927, line 194(rubash 侧把 Macro 改成 Macro / Keymap,niubash 侧账本副本未同步)。其余红 = 基线 issue2875 + master-red issue2859。niubash 编译本身没红(它的 wildcard 臂已在 niubash#959 落),红的是账本 cmp 门。
  • GNU 对照:无 shell 行为面(API 视图层),不需要 bash oracle;GNU 依据是 bind.c 源码 + 钉里的 Control-v: prefix-meta → Keymap{emacs-meta} 断言(head 实测通过)。

F 点(建议 FAIL):

未跑/VOID 的腿:

  • GNU bash oracle:本 PR 无 shell 语义面,不适用。
  • niubash 侧编译:本 lane 只测 rubash 树;niubash builds against this tree 在本 PR head 的 CI 结论已引用(编译步绿、cmp 步红)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3616 第2轮(y4)— 建议:FAIL 维持(两个阻塞均未解除,均不在本 lane 可动范围)
head: 6badbab(未变) base(merge-base): 27e1d0d 文件: 6 个 +171/-20
关联 issue: #3013(状态:open,我核过的时间:2026-11-17 本地)

第 1 轮 F 点复核:

  • F1(账本同步门):仍成立。niubash master 的 docs/api-ledger.md 经 gh api repos/unixwin/niubash/contents/docs/api-ledger.md 复核——无 BindKindView::Keymap 变体行(BindKindView 变体清单仍为 Execute / Function / Macro,line ~193/983/1541 区域);rubash 侧 origin/master:docs/api-ledger.md 同样尚无 BindKindView::Keymap(只有 BindingSpec::Keymap,line 1681)。即 niubash 配套半单未落地,合入本 PR 会让 niubash builds against this tree 的 cmp docs/api-ledger.md 门持续红。gh pr list --repo unixwin/niubash --search "keymap OR ledger OR 3013" 无相关 open PR。
  • F2(分支叠无关 commit + 旧 base):仍成立。分支仍含 f6836d58 fix(declare-local): …(已由 fix(declare-local): skip readonly refusal when the operand creates a fresh local #3610 落地),且基于 27e1d0d。规程禁止 rebase 改写已推送历史,需 owner/队长处理。

机制面(第 1 轮结论不变):BindKindView::Keymap 变体方向正确(GNU lib/readline/bind.c:1845-1855 PREFIX_META_HACK 走 ISKMAP 键位图),钉 issue3013_keymap_kind_round_trips_through_the_view 在 head 上通过。

建议:维持 FAIL——先落 niubash 侧账本/显式臂(或队长裁定 cmp 门豁免口径),再由 owner rebase 清理无关 commit 后复审。

caomengxuan666 added a commit to unixwin/niubash that referenced this pull request Nov 17, 2026
) (#1042)

Mirror the engine-side ledger update from unixwin/rubash#3616: the bind
view reports keymap-valued bindings faithfully, so the BindKindView
variant list grows Execute / Function / Macro / Keymap.  Both copies of
docs/api-ledger.md must stay byte-identical (api-ledger-sync gate).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 06:27
@caomengxuan666
caomengxuan666 merged commit 8a85f33 into master Nov 17, 2026
8 of 12 checks passed
caomengxuan666 added a commit to unixwin/niubash that referenced this pull request Nov 17, 2026
…ubash#3013) (#1045)

* docs(api-ledger): add BindKindView::Keymap row (Refs unixwin/rubash#3013)

Mirror the engine-side ledger update from unixwin/rubash#3616: the bind
view reports keymap-valued bindings faithfully, so the BindKindView
variant list grows Execute / Function / Macro / Keymap.  Both copies of
docs/api-ledger.md must stay byte-identical (api-ledger-sync gate).

* runtime(bind): handle BindKindView::Keymap explicitly (Refs unixwin/rubash#3013)

rubash#3616 adds the keymap-valued view kind (lib/readline/bind.c:1845
ISKMAP). Match it explicitly instead of leaning on wildcard arms:

- readline_live: mirror it as the function the engine's dump face
  renders for that slot (prefix-meta), so the key still reaches
  readline's own keymap dispatch.
- keymap_registry: new DroppedKind::Keymap with its fix hint.
- repl chord layer: a keymap binding is not a chord event.

Also mirrors the two api-ledger variant-list edits so both copies stay
byte-identical.

* runtime(bind): deliver keymap bindings through the explicit Keymap kind

rubash#3616's BindKindView::Keymap is now the real kind for ISKMAP
bindings, so:

- keymap_registry::delivery_kind rewrites Keymap onto the prefix-meta
  function only at the delivery boundary (no host slot of its own,
  rl_function_dumper renders that slot as prefix-meta);
- the flat bind layer matches on it and keeps an exhaustiveness arm;
- the [keymap].bind parser records BindKindView::Keymap { name } instead
  of the old prefix-meta function shim.

Checked with cargo check --workspace --locked against the rubash #3616
head: 0 errors, 0 warnings.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3616 第3轮(o2)— 判词:PASS(已合入 squash 8a85f334)

head: 5e13476(原 6badbab + merge origin/master,无冲突) base(merge-base): 27e1d0d
文件: 4 个(docs/api-ledger.md、src/api/bind.rs、src/api/consumer_tests.rs、src/api/session.rs)
关联 issue: #3013 → 已关闭(三项验收全部落地,见 issue 评论)

F1(niubash 侧账本缺 BindKindView::Keymap 行)已解:

F2(分支叠了已由 #3610 落地的旧 commit f6836d5)按规程处置,未 rebase:

  • git merge origin/master(merge commit,不改写已推送历史)后,git diff --stat origin/master...HEAD 只剩 4 个 Keymap 文件;
  • git diff origin/master...HEAD -- src/executor/declare_local.rs tests/issue3609_local_readonly_shadow.rs 为空 —— 旧 commit 的落点与 master 同形,squash 合入后对这两处零变更,无数据风险。

机制(GNU 锚点):lib/readline/bind.c:1845-1855 PREFIX_META_HACK 对 old-style keyname 走 rl_generic_bind (ISKMAP, seq, emacs_meta_keymap, _rl_keymap) —— 绑定值是键位图;视图层原先渲染成 Function{"prefix-meta"} 是失真。本 PR 的 BindKindView::Keymap { name } 与 Session::register_binding 回写使契约与现实一致,dump 面仍按 rl_function_dumper 渲染 prefix-meta。

腿:

  • 钉(lib 内 api::consumer_tests::issue3013_keymap_kind_round_trips_through_the_view)head:cargo test --lib issue3013_keymap → 1 passed / 0 failed(1377 filtered)。
  • fail-first:结构性不适用(钉引用 BindKindView::Keymap,base 无该变体 → base 上编译即红 E0599),不是废钉。
  • 交叉编译门(本轮新增硬腿):在 Windows 侧用 sibling 布局(niubash 分支 + rubash 5e13476 源树)跑 cargo check --workspace --locked → Finished,0 error / 0 warning;这同时证明了宿主侧显式臂的完备性(补了 readline_live/keymap_registry/flat layer/chord 层的 Keymap 臂)。
  • 卫生:4 个文件 rustfmt --edition 2021 --check clean。
  • CI:head 5e13476 的 niubash builds against this tree 当时红(它取 niubash master,彼时只有账本、无显式臂);niubash#1045 合入后该 job 的输入已齐(两仓 master 的账本 cmp 已相等、宿主可编译),属合入顺序造成的瞬时红,非本 PR 缺陷。API ledger tripwire 在该 head 上 pass。

未跑/VOID:本 head 的 Windows 全量 lib(上轮已核失败集合 {issue2084…},本轮产品面只增视图变体,lib 面由 lib 钉覆盖);GNU bash oracle(无 shell 语义面,API 视图层)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

Merged as squash 8a85f334. Closing evidence for the three blocking points:

F1 — ledger pairing / niubash adoption. The ledger row alone was not sufficient: niubash master then failed this PR's canary with 4 × E0004 (exhaustive matches on BindKindView::Keymap). niubash #1045 (190c539) added the explicit arms in keymap_registry::dropped_bind_for, the readline_live ABI slot mirror and both repl binding bridges, keeping the pre-#3013 prefix-meta rendering (the host readline does not mirror named keymaps). The canary's completeness gate then required a real variant rubash::api::BindKindView::Keymap record row: rubash #3837 (914845727) and niubash #1046 (3fac4730) added the identical line, so the two ledger copies are byte-identical again.

Final canary: niu-canary on rubash master da256e71 (workflow_dispatch run 44035884762) — niubash builds against this tree success, API ledger tripwire success.

F2 — stacked history. git diff origin/master...HEAD --stat = 4 files / +67−16 (src/api/bind.rs, src/api/session.rs, src/api/consumer_tests.rs, docs/api-ledger.md): exactly the Keymap delta. The declare-local commit f6836d5 already lives in master through #3610, so the stacked history disappears at squash — no data risk.

Local legs: round-trip pin issue3013_keymap_kind_round_trips_through_the_view 1 passed; ledger parity cmp rubash 1d3801042 vs niubash master = identical, 1892 lines.

#3013 is closed with the same acceptance (contract + both ledger rows + niubash explicit arms + green canary).

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.

1 participant