claude-code-best/src/commands
unraid f2e9af4927 feat: harden autonomy lifecycle, OOM bounds, and provider-boundary finalization
This PR consolidates a coordinated batch of fixes around autonomy run/flow lifecycle, scheduled task deduplication, provider-boundary state finalization, and matching memory-bound treatments for adjacent long-running subsystems (REPL fullscreen scrollback, skill-search/skill-learning runtime activation). All changes were developed and reviewed together because they touched the same lifecycle invariants and were uncovered by the same long-running session reproductions.

## Lifecycle correctness

- Queued autonomy prompts are not injected unless the persisted run was successfully claimed; queued run claiming is now terminal-safe so a once-consumed/cancelled/failed run can not slip back into `queued`.
- Autonomy run/flow finalization happens on completion, provider error, generator close, and cancellation — not just the happy path. New `src/__tests__/queryAutonomyProviderBoundary.test.ts` covers these provider-boundary transitions.
- `requestManagedAutonomyFlowCancel` and `resumeManagedAutonomyFlowPrompt` carry `rootDir` and `currentDir` explicitly across detached async boundaries (proactive-tick, cron, daemon restart) instead of inferring from process state.
- Active runs/flows are protected from janitor pruning so a running step can not be garbage-collected mid-flight (`src/utils/autonomyAuthority.ts`).
- Heartbeat parser now ignores fenced code blocks; the two-phase commit window for autonomy state transitions is documented in `docs/internals/autonomy-jira.md`.

## Ownership and dedup

- `src/utils/autonomyRuns.ts`: ownership stamping (run id + rootDir carried end-to-end), source-based dedup against active runs.
- `src/hooks/useScheduledTasks.ts`: scheduled ticks deduplicate against runs already active on the same source label.
- `src/utils/processUserInput/processSlashCommand.tsx`: forked slash commands now thread the autonomy `runId` so completion finalizers can find the originating run for deferred completion.
- New `src/utils/autonomyQueueLifecycle.ts` and tests collect the queue-side lifecycle invariants in one place.

## Memory bounds (related, same review pass)

- `src/screens/REPL.tsx`: caps fullscreen scrollback after the compact boundary and updates trailing progress rows in place. Long-running fullscreen sessions could otherwise retain thousands of post-compaction messages and duplicate progress rows, keeping Ink trees alive long after their useful context had moved on.
- `src/services/skillSearch/*` and `src/services/skillLearning/*`: runtime activation is strictly opt-in via existing env toggles; session caches are capped so long-running processes can not grow them forever. Build presence is preserved so operators can still discover and opt into the slash commands.

## CI / test contract

- `tests/integration/dependency-overrides.test.ts`: smoke test no longer drives Mermaid's browser renderer; it validates the package-resolution contract directly so CI does not regress on unrelated browser timing.
- New `tests/integration/autonomy-lifecycle-user-flow.test.ts`: end-to-end CLI subprocess flow exercising `status --deep`, `flows`, `flow <id>`, `flow resume`, `flow cancel` against persisted state.
- `src/entrypoints/cli.tsx`: `claude autonomy …` routes through an entrypoint fast path that reuses the slash-command formatter without booting the full interactive CLI. Stdout is flushed before forced exit so coverage subprocesses do not terminate with empty stdout.
- `packages/builtin-tools/src/tools/RemoteTriggerTool/__tests__/RemoteTriggerTool.test.ts`: stabilized to prevent audit flake under coverage.

## Tests added

- `src/__tests__/queryAutonomyProviderBoundary.test.ts`
- `src/hooks/__tests__/useScheduledTasks.test.ts`
- `src/utils/__tests__/autonomyAuthority.test.ts`
- `src/utils/__tests__/autonomyFlows.test.ts` (extended)
- `src/utils/__tests__/autonomyPersistence.test.ts` (extended)
- `src/utils/__tests__/autonomyQueueLifecycle.test.ts`
- `src/utils/__tests__/autonomyRuns.test.ts` (extended)
- `src/utils/processUserInput/__tests__/processSlashCommand.test.ts`
- `tests/integration/autonomy-lifecycle-user-flow.test.ts`

## Docs

- `docs/agent/sur-loop-scheduled-oom.md`: System Understanding Report covering the scheduled/loop OOM problem, the call graphs investigated, and the lifecycle invariants this PR establishes.
- `docs/agent/sur-skill-overflow-bugs.md`: SUR for the related skill-overflow context.
- `docs/internals/autonomy-jira.md`: documents the two-phase commit window and ownership stamping invariants.
- `docs/memory-leak-audit.md`: audit notes covering the REPL/scrollback and skill-search bounds.

## Invariants this PR establishes

1. Queued autonomy prompts are not injected unless the persisted run was successfully claimed.
2. Terminal run/flow states are terminal — completion, failure, and cancellation all finalize state regardless of which provider/error path triggered them.
3. Autonomy run/flow `rootDir` is carried explicitly across detached async boundaries instead of inferred from a shared singleton.
4. State-only CLI subcommands (`autonomy status|runs|flows|flow …`) bypass full interactive bootstrap so they do not hold unrelated handles open.
5. REPL fullscreen scrollback and skill-search/skill-learning session caches are explicitly bounded.

## Validation

```bash
bun run typecheck
CI=true GITHUB_ACTIONS=true bun test            # 3996 pass / 0 fail across 305 files
bun test src/__tests__/queryAutonomyProviderBoundary.test.ts \
         src/hooks/__tests__/useScheduledTasks.test.ts \
         src/utils/__tests__/autonomy{Runs,Flows,Authority,QueueLifecycle,Persistence}.test.ts \
         src/utils/processUserInput/__tests__/processSlashCommand.test.ts \
         tests/integration/autonomy-lifecycle-user-flow.test.ts
```

## Origin

This PR is the consolidated, upstream-targeted version of two fork-side review PRs (fix/loop-scheduled-autonomy-oom and fix/autonomy-lifecycle). The fork-side review history is preserved at https://github.com/amDosion/claude-code-bast/pull/7 . The fork's own internal `chore: keep fork current with upstream` sync commits and the `docs: update contributors` automation are intentionally not included in this PR.

The autonomy CLI handler `rootDir` threading that the fork added (78f64d8a, 98d04ddb) is intentionally omitted here because upstream `a2cfaf91` (fix: 修复 RemoteTriggerTool 和 autonomy 测试的全量运行失败) already performed the equivalent change with an additional `currentDir` option. Keeping the upstream version avoids regressing that improvement.
2026-04-29 14:04:27 +08:00
..
__tests__ feat: 添加 autonomy 自主模式命令系统 2026-04-22 22:38:09 +08:00
add-dir Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
agents 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
agents-platform feat: 完成stub 2026-03-31 20:40:16 +08:00
ant-trace feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
assistant Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
attach feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
autofix-pr feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
backfill-sessions feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
branch feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
break-cache feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
bridge feat: 添加 summary 命令 TypeScript 重写与其他命令增强 2026-04-22 22:38:09 +08:00
btw feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
buddy feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
bughunter feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
chrome fix(types): clean type fixes across 92 files 2026-04-09 23:45:56 +08:00
claim-main feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
clear fix: 修复长时间运行会话的内存泄漏问题 2026-04-26 21:14:00 +08:00
color feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
compact chore: 清理仓库审计问题——修正 CLAUDE.md、删除冗余 yoga-layout、清除 621 个未使用的类型 stub (#354) 2026-04-25 08:54:18 +08:00
config 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
context feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
copy Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
cost feat: build 2026-03-31 19:22:47 +08:00
ctx_viz feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
daemon Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
debug-tool-call feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
desktop 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
detach feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
diff 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
doctor 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
effort 添加deepseek-v4-pro支持选择max思考深度 (#365) 2026-04-26 09:00:43 +08:00
env feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
exit 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
export 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
extra-usage 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
fast Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
feedback 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
files feat: build 2026-03-31 19:22:47 +08:00
fork feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
good-claude feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
heapdump feat: build 2026-03-31 19:22:47 +08:00
help 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
history feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
hooks 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
ide fix: resolve dependency audit findings precisely (#361) 2026-04-26 19:49:54 +08:00
install-github-app chore: 清理仓库审计问题——修正 CLAUDE.md、删除冗余 yoga-layout、清除 621 个未使用的类型 stub (#354) 2026-04-25 08:54:18 +08:00
install-slack-app feat: build 2026-03-31 19:22:47 +08:00
issue feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
job Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
keybindings feat: build 2026-03-31 19:22:47 +08:00
lang Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
login feat: 正式启用 auto mode (#307) 2026-04-20 10:20:27 +08:00
logout Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
mcp 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
memory Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
mobile Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
mock-limits feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
model fix: resolve dependency audit findings precisely (#361) 2026-04-26 19:49:54 +08:00
oauth-refresh feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
onboarding feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
output-style 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
passes 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
peers fix: bound agent communication memory growth (#369) 2026-04-27 14:47:18 +08:00
perf-issue feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
permissions 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
pipe-status feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
pipes feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
plan feat(remote-control): 优化 Web 展示、状态同步与桥接控制流程 (#288) 2026-04-17 16:21:27 +08:00
plugin fix: resolve dependency audit findings precisely (#361) 2026-04-26 19:49:54 +08:00
poor fix: bound agent communication memory growth (#369) 2026-04-27 14:47:18 +08:00
pr_comments feat: build 2026-03-31 19:22:47 +08:00
privacy-settings 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
rate-limit-options Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
release-notes feat: build 2026-03-31 19:22:47 +08:00
reload-plugins feat: build 2026-03-31 19:22:47 +08:00
remote-env 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
remote-setup fix(types): clean type fixes across 92 files 2026-04-09 23:45:56 +08:00
remoteControlServer refactor: 解耦 BRIDGE_MODE 与 DAEMON,禁用 DAEMON 降低内存占用 2026-04-24 10:01:05 +08:00
rename feat: 完成第二版类型清理 2026-03-31 23:03:47 +08:00
reset-limits feat: 问就是封包 2026-03-31 23:32:58 +08:00
resume fix(types): clean type fixes across 92 files 2026-04-09 23:45:56 +08:00
review feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
rewind feat: build 2026-03-31 19:22:47 +08:00
sandbox-toggle Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
send Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
session Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
share feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
skill-learning feat: harden autonomy lifecycle, OOM bounds, and provider-boundary finalization 2026-04-29 14:04:27 +08:00
skill-search feat: harden autonomy lifecycle, OOM bounds, and provider-boundary finalization 2026-04-29 14:04:27 +08:00
skills 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
stats 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
status 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
stickers feat: build 2026-03-31 19:22:47 +08:00
summary feat: 添加 summary 命令 TypeScript 重写与其他命令增强 2026-04-22 22:38:09 +08:00
tag Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
tasks 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
teleport feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
terminalSetup chore: 清理仓库审计问题——修正 CLAUDE.md、删除冗余 yoga-layout、清除 621 个未使用的类型 stub (#354) 2026-04-25 08:54:18 +08:00
theme Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
thinkback Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
thinkback-play feat: build 2026-03-31 19:22:47 +08:00
upgrade 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
usage 更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121) 2026-04-04 23:24:27 +08:00
vim feat: build 2026-03-31 19:22:47 +08:00
voice feat: 集成豆包 ASR 语音识别后端,支持 /voice doubao 切换 (#357) 2026-04-25 13:57:30 +08:00
workflows feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
advisor.ts feat: build 2026-03-31 19:22:47 +08:00
autonomy.ts feat: 添加 autonomy 自主模式命令系统 2026-04-22 22:38:09 +08:00
autonomyPanel.tsx feat: 添加 autonomy 自主模式命令系统 2026-04-22 22:38:09 +08:00
bridge-kick.ts feat: build 2026-03-31 19:22:47 +08:00
brief.ts feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
commit-push-pr.ts feat: build 2026-03-31 19:22:47 +08:00
commit.ts feat: build 2026-03-31 19:22:47 +08:00
coordinator.ts feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
createMovedToPluginCommand.ts feat: build 2026-03-31 19:22:47 +08:00
force-snip.ts feat: 添加 summary 命令 TypeScript 重写与其他命令增强 2026-04-22 22:38:09 +08:00
init-verifiers.ts feat: build 2026-03-31 19:22:47 +08:00
init.ts Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
insights.ts feat: 添加 summary 命令 TypeScript 重写与其他命令增强 2026-04-22 22:38:09 +08:00
install.tsx Revert "Revert "feat: 第一个可以用的 ink 组件抽象 (#158)" (#175)" 2026-04-07 16:17:48 +08:00
monitor.ts feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
proactive.ts feat(remote-control): 优化 Web 展示、状态同步与桥接控制流程 (#288) 2026-04-17 16:21:27 +08:00
provider.ts feat: 全部类型问题解决 2026-04-11 10:24:00 +08:00
review.ts feat: build 2026-03-31 19:22:47 +08:00
security-review.ts feat: build 2026-03-31 19:22:47 +08:00
statusline.tsx feat: 工具层及 mcp 大重构 (#252) 2026-04-13 09:52:05 +08:00
subscribe-pr.ts feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
torch.ts Feat/integrate lint preview (#285) 2026-04-16 20:59:29 +08:00
ultraplan.tsx feat: 添加 summary 命令 TypeScript 重写与其他命令增强 2026-04-22 22:38:09 +08:00
version.ts feat: build 2026-03-31 19:22:47 +08:00