Skip to content

fix(cosh-ng): [shell] default to native mode - #2759

Open
kongche-jbw wants to merge 2 commits into
alibaba:mainfrom
kongche-jbw:fix/cosh-ng/native-shell-default
Open

fix(cosh-ng): [shell] default to native mode#2759
kongche-jbw wants to merge 2 commits into
alibaba:mainfrom
kongche-jbw:fix/cosh-ng/native-shell-default

Conversation

@kongche-jbw

@kongche-jbw kongche-jbw commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Why

The current marker injection forces Bash tracing options and exposes Cosh traps,
internal helpers, and session tokens to user-visible shell state. This change
makes transparent shell ownership the default and keeps the legacy marker path
behind an explicit enhanced setting.

What changed

  • Add ShellIntegration::Native and ShellIntegration::Enhanced.
  • Start in Native by default, loading bash or zsh without Cosh marker rcfiles,
    traps, OSC routing, session tokens, or input interception.
  • Support shell.integration = "enhanced" and
    COSH_SHELL_INTEGRATION=enhanced as explicit opt-ins.
  • Route hello, /, ??, and all other Native input bytes directly to the
    child PTY.
  • Add typed $, , , /, *, !, and · card identities. Permission
    cards can only originate from structured tool permission events.
  • Update the bilingual README, user guide, configuration reference, and design
    documentation.

Related issue

closes #2687

User / Agent impact

cosh now behaves like the selected native shell by default. Implicit natural
language, slash-command routing, command-boundary events, and Agent handoff
require Enhanced integration. Existing enhanced behavior remains available,
and visible UI cards now identify their typed origin with stable symbols.

Risk and compatibility

  • Public CLI, API, configuration, or documented behavior changed
  • Privileged or security-sensitive behavior changed
  • Migration or rollback guidance is needed

The default interaction policy changes intentionally. Users who need the legacy
workflow can set shell.integration = "enhanced" or launch with
COSH_SHELL_INTEGRATION=enhanced. Enhanced still uses the existing global hook
implementation, so its xtrace and helper-isolation work remains tracked by
#2683. Same-child-shell hot switching, a Native Agent panel, and the Direct Exec
executor are not included.

Validation

Final local revision: bbc0f155a6856ff17039438f9df92d06812cf921.

  • cargo fmt --all -- --check
  • crates/cosh-shell/scripts/check-layout.sh
  • scripts/check-test-inventory.sh — lib/bin overlap 696/696
  • cargo clippy --package cosh-shell --lib --tests -- -D warnings
  • Review regressions: invalid integration, Native worker suppression, and Native-default resume launch — 3 passed
  • cargo test --package cosh-shell --lib — 1353 passed
  • cargo test --package cosh-shell --test shell_host -- --test-threads=4 — 164 passed
  • cargo test --package cosh-shell --test raw_cli renderer:: -- --test-threads=4 — 15 passed
  • cargo test --package cosh-shell --test raw_cli splits_agent_cards -- --test-threads=4 — 2 passed
  • Exact raw CLI lifecycle and startup regressions — 3 passed
  • Native/Enhanced PTY regressions — 6 passed
  • cargo doc --package cosh-shell --no-deps
  • python3 scripts/docs-link-check.py

The PTY regressions cover Bash options and traps, user PROMPT_COMMAND, marker
and token absence, xtrace, Native bash/zsh startup, Native handling of hello,
/, and ??, and explicit Enhanced marker routing. The CI-failure regressions
cover typed card titles, split Agent cards, provider cancellation, startup
banners, and the lib/bin duplicate-test ceiling.

Documentation and rollback

English and Chinese component READMEs, quickstarts, shell guides,
configuration references, and the integration/card design are updated. Roll
back the default behavior per session with
COSH_SHELL_INTEGRATION=enhanced cosh, or persist
shell.integration = "enhanced" in the user configuration.

@github-actions github-actions Bot added component:cosh-ng src/cosh-ng scope:documentation ./docs/|./*.md|./NOTICE labels Aug 22, 2026

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 原生 / 增强集成在 raw_shell 入口上仍有混合路径:run_raw 默认 native_mode=true,且在读取配置前就调用 bootstrap_process_path_from_shell,当配置为 enhanced 时会落入“增强集成 + 原生启动路径”的组合,可能重新暴露 marker 行为。
[P2] 原生集成依赖 marker 缺失来避免 AI 拦截,但配置层仍允许 analysis_modeai_enabled 处于开启状态,存在“配置开启但行为静默禁用”的认知偏差。
[P2] shell.integrationCOSH_SHELL_INTEGRATION 对非法值完全静默回退到 native,易导致配置写错时增强模式无法开启且难以排查,建议增加最小可见校验或日志。


🤖 Generated by QoderView workflow run

Comment on lines +31 to +32
impl ShellIntegration {
pub(crate) fn from_config(value: &str) -> Self {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] COSH_SHELL_INTEGRATION 环境覆盖与配置含义可能混淆

CoshConfig::defaultshell_integration 设为 "native"apply_shell_integration_environment_override 会直接把 COSH_SHELL_INTEGRATION 的原始字符串写回配置,ShellIntegration::from_config 则仅在严格等于 "enhanced" 时切换为增强,否则都视为 Native。这意味着用户传入 COSH_SHELL_INTEGRATION=Nativenative (带空格)或其他大小写/拼写变体时不会报错,只是静默回退到原生;同时无论是配置文件还是环境变量,只有 "enhanced" 一档,缺少显式的非法值反馈。

从运维角度看,配置/环境写错时很难排查“为什么始终没有增强集成”。可以考虑在解析时增加简单校验:当 value 既不是 "native" 也不是 "enhanced" 时,在 stderr 打一条提示或者在日志中记录一条配置警告,并在未来需要时扩展为 Result 返回,让 CLI 能够在明显错误配置时显式失败而不是悄然降级。


🤖 Generated by QoderFix in Qoder

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4aa84f61. Parsing already tolerated case and surrounding whitespace, but other invalid values did silently fall back. The parser now accepts only native or enhanced; invalid config or environment input exits with status 2 and an actionable stderr message. Added an exact raw CLI regression test.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bad3096a60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

config.login_shell = login;
if config.native_mode {
let cosh_config = load_config();
config.integration = ShellIntegration::from_config(&cosh_config.shell_integration);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor --resume when Native is the default

When cosh --resume or cosh --resume <id> is launched without an explicit integration override, this selects Native but still only queues the request in pending_launch. render_session_launch consumes that request exclusively after a ShellReady event, while the new passthrough parser never emits ShellReady, so the explicit resume flag silently drops the user into an ordinary shell without opening or restoring the requested session. The launch path should either select Enhanced for resume requests or reject the incompatible combination visibly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4aa84f61. --resume is an explicit Agent action, so it now selects Enhanced integration even when Native is configured by default. This restores the ShellReady boundary before consuming pending_launch. The existing value and picker integration test now removes the integration override and covers both default-Native launch paths.

Comment on lines 113 to 115
if config.native_mode && config.integration.uses_markers() {
bootstrap_process_path_from_shell(&shell_kind, login);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip unreachable startup workers in Native sessions

With the new default Native integration, the parser cannot produce the ShellReady event required by render_startup_banner, but run_raw still starts the recommendation-store worker, startup health scan, shell-rewrite worker, and—under the default AI-enabled, cosh-core, TTY configuration—the ai_configured subprocess used only by that banner. Consequently every ordinary default shell performs database, diagnostic, and subprocess work whose results can never be displayed or consumed; these Enhanced-only workers should not be started for Native sessions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4aa84f61. Native sessions no longer start the recommendation store/history observer, shell-rewrite worker, startup health scan, analyzer cancellation, or startup auth probe. Enhanced sessions keep the existing behavior. A raw CLI regression verifies that default Native neither invokes cosh-core for startup auth nor creates the recommendation store.

@kongche-jbw
kongche-jbw force-pushed the fix/cosh-ng/native-shell-default branch 2 times, most recently from 07989da to 4c7ecd1 Compare August 22, 2026 05:40
Make shell ownership the default integration policy.

Native sessions load user startup files directly.

They bypass marker generation, OSC routing, and input interception.

Enhanced remains an explicit opt-in while hook isolation is redesigned.

Fixes: 9ecda4b ("feat(shell): add cosh-shell crate with Phase 0 fixes")
Signed-off-by: kongche-jbw <kongche.jbw@alibaba-inc.com>
Give every card an explicit identity and stable symbol.

Do not infer routing or permission behavior from visible text.

Permission cards bind to structured runtime requests.

Direct execution remains an argv-only contract.

Its executor and native-session Agent panel remain future work.

Signed-off-by: kongche-jbw <kongche.jbw@alibaba-inc.com>
@kongche-jbw
kongche-jbw force-pushed the fix/cosh-ng/native-shell-default branch from 4c7ecd1 to bbc0f15 Compare August 22, 2026 06:11
@kongche-jbw

Copy link
Copy Markdown
Collaborator Author

Review summary triage:

  • The reported “Enhanced integration + native startup path” mix is not a defect: load_config() runs before bootstrap, marker bootstrap is guarded by the resolved integration, and native_mode independently controls whether user startup files load.
  • Keeping ai_enabled/analysis_mode configured while Native owns input is intentional. Integration controls interception; those settings become effective after an explicit Enhanced action such as --resume or an Enhanced configuration.
  • Invalid integration fallback, Native --resume, and unreachable Enhanced startup workers were valid findings and are fixed in 4aa84f61.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh-ng src/cosh-ng scope:documentation ./docs/|./*.md|./NOTICE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1][cosh-ng] 强制 functrace/errtrace/extdebug 全局暴露:用户 trap 对 cosh 内部触发、$-/set -o 谎报、泄漏内部实现与 token

1 participant