GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — 1. 修复 src/commands/fork/index.ts — 将空 stub 改为有效的 Command 定义 2. 新增 src/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 by 2228293026 · Pull Request #221 · claude-code-best/claude-code Conversation
|
📝 WalkthroughWalkthroughAdds a new local-JSX "fork" command that starts subagents via AgentTool, gated by a FORK_SUBAGENT feature flag, prevents forking from within forked workers, validates arguments and conversation context, initiates the fork asynchronously, and replaces the command stub with a typed command descriptor. Changes
Sequence DiagramsequenceDiagram
actor User
participant Command as Fork Command Handler
participant Context as Message Context
participant AgentTool
participant Callback as onDone
User->>Command: /fork <directive>
Command->>Command: Check FORK_SUBAGENT flag
alt feature disabled
Command->>Callback: emit system message (feature disabled)
Command-->>User: returns null
else feature enabled
Command->>Context: isInForkChild(context.messages)?
alt in fork child
Command->>Callback: emit system message (cannot fork inside fork)
Command-->>User: returns null
else not in fork child
Command->>Command: trim/validate directive
alt directive empty
Command->>Callback: emit usage/help message
Command-->>User: returns null
else valid directive
Command->>Context: find last assistant message
alt no assistant message
Command->>Callback: emit error (no context to fork)
Command-->>User: returns null
else assistant message found
Command->>AgentTool: AgentTool.call(input, context, canUseTool, assistantMessage) (not awaited)
AgentTool-->>Command: returns Promise (handled via .catch)
Command->>Callback: emit system message (fork started)
Command-->>User: returns null
end
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
src/commands/fork/fork.tsx (1)
31-39: Consider a narrower type assertion.The
as anyworks but loses type safety. If the message types are available, a more specific assertion would be safer:const lastAssistantMessage = [...context.messages].reverse().find( (m): m is Extract<typeof m, { type: 'assistant' }> => m.type === 'assistant' )However, if the complex type import is genuinely cumbersome, the current approach with the explanatory comment is acceptable.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/fork/fork.tsx` around lines 31 - 39, Replace the broad "as any" on lastAssistantMessage with a narrower type guard: change the find callback on context.messages to a type predicate that asserts the item is an assistant message (e.g., use a predicate like (m): m is /* AssistantMessage type */ => m.type === 'assistant' or use Extract<> to derive the assistant variant), so lastAssistantMessage is strongly typed rather than any; update any necessary imports or local typedefs for the assistant message shape and keep the existing onDone usage intact.
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/fork/fork.tsx`:
- Around line 55-68: AgentTool.call is async but invoked as a fire-and-forget
with void, so rejections become unhandled; instead attach error handling to the
returned promise (e.g., call AgentTool.call(...).catch(...)) to log errors and
surface failure to the user via logForDebugging and onDone. Locate the
fire-and-forget invocation of AgentTool.call and replace it with a promise chain
that catches errors and calls logForDebugging(`Fork command error: ${error}`, {
level: 'error' }) and onDone(`Fork failed: ${error instanceof Error ?
error.message : String(error)}`, { display: 'system' }) so async failures are
handled.
---
Nitpick comments:
In `@src/commands/fork/fork.tsx`:
- Around line 31-39: Replace the broad "as any" on lastAssistantMessage with a
narrower type guard: change the find callback on context.messages to a type
predicate that asserts the item is an assistant message (e.g., use a predicate
like (m): m is /* AssistantMessage type */ => m.type === 'assistant' or use
Extract<> to derive the assistant variant), so lastAssistantMessage is strongly
typed rather than any; update any necessary imports or local typedefs for the
assistant message shape and keep the existing onDone usage intact.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4d1aa8f0-386b-437f-b714-4971dbf968e0
src/commands/fork/fork.tsxsrc/commands/fork/index.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
src/commands/fork/fork.tsx (1)
32-34: Consider usingfindLastand typed assertion.The spread-then-reverse pattern works but
findLast(ES2023) is more idiomatic. Theas anyassertion could be replaced with a more specific type import if the type complexity is manageable.♻️ Optional improvement using findLast
- const lastAssistantMessage = [...context.messages].reverse().find( - m => m.type === 'assistant' - ) as any // Type assertion to avoid complex type import + const lastAssistantMessage = context.messages.findLast( + m => m.type === 'assistant' + )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/fork/fork.tsx` around lines 32 - 34, Replace the spread-and-reverse scan with the ES2023 Array.prototype.findLast to locate the last assistant message from context.messages (replace the current lastAssistantMessage initialization that uses [...context.messages].reverse().find(...)). Also remove the blanket "as any" and instead import or reference the concrete message type (e.g., Message or AssistantMessage) and use a proper typed assertion or type guard when assigning to lastAssistantMessage so the variable has a specific type rather than any.
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/fork/fork.tsx`:
- Around line 72-74: The file has an unmatched extra closing brace causing a
syntax error: inside the exported async function call the try-catch block and
function are already closed but a stray `}` remains; remove the extraneous
closing brace so that the braces for the try-catch and the function `call` (the
exported async function) properly match and the file compiles.
---
Nitpick comments:
In `@src/commands/fork/fork.tsx`:
- Around line 32-34: Replace the spread-and-reverse scan with the ES2023
Array.prototype.findLast to locate the last assistant message from
context.messages (replace the current lastAssistantMessage initialization that
uses [...context.messages].reverse().find(...)). Also remove the blanket "as
any" and instead import or reference the concrete message type (e.g., Message or
AssistantMessage) and use a proper typed assertion or type guard when assigning
to lastAssistantMessage so the variable has a specific type rather than any.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4abb759a-1009-4b2e-85a4-c05abcdfeaef
src/commands/fork/fork.tsx
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/fork/fork.tsx`:
- Around line 3-6: The imports in fork.tsx directly reference tool internals
(AgentTool, isInForkChild) and utilities instead of using the project's public
entrypoints and path aliases; update the imports to use the centralized module
exports (e.g., import AgentTool and any fork-related helpers from the repo's
tool registry entrypoints such as the Tool/ tools.ts public exports using the
src/* path alias) and keep type imports (LocalJSXCommandOnDone,
LocalJSXCommandContext) sourced from the canonical types export; replace
deep-relative imports for AgentTool, isInForkChild, and logForDebugging with
their corresponding public exports so the file uses the approved import
boundaries and TSConfig alias style.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fa80aed2-1323-4200-807c-ffec64245fd3
src/commands/fork/fork.tsx
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import { AgentTool } from '../../tools/AgentTool/AgentTool.js' | ||
| import { isInForkChild } from '../../tools/AgentTool/forkSubagent.js' | ||
| import { logForDebugging } from '../../utils/debug.js' | ||
| import type { LocalJSXCommandOnDone, LocalJSXCommandContext } from '../../types/command.js' |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Use repository import entrypoints instead of deep relative tool imports.
Lines 3-6 bypass the project’s required import boundaries (src/tools.ts, src/Tool.ts) and src/* alias style.
-import { AgentTool } from '../../tools/AgentTool/AgentTool.js' -import { isInForkChild } from '../../tools/AgentTool/forkSubagent.js' -import { logForDebugging } from '../../utils/debug.js' -import type { LocalJSXCommandOnDone, LocalJSXCommandContext } from '../../types/command.js' +import { AgentTool } from 'src/tools.ts' +import { isInForkChild } from 'src/Tool.ts' +import { logForDebugging } from 'src/utils/debug.js' +import type { LocalJSXCommandOnDone, LocalJSXCommandContext } from 'src/types/command.js'
As per coding guidelines: "Import tool registry and utilities via src/tools.ts and src/Tool.ts, not by directly requiring individual tool directories" and "TSConfig path alias src/* maps to ./src/*."
Verify each finding against the current code and only fix it if needed.
In `@src/commands/fork/fork.tsx` around lines 3 - 6, The imports in fork.tsx
directly reference tool internals (AgentTool, isInForkChild) and utilities
instead of using the project's public entrypoints and path aliases; update the
imports to use the centralized module exports (e.g., import AgentTool and any
fork-related helpers from the repo's tool registry entrypoints such as the Tool/
tools.ts public exports using the src/* path alias) and keep type imports
(LocalJSXCommandOnDone, LocalJSXCommandContext) sourced from the canonical types
export; replace deep-relative imports for AgentTool, isInForkChild, and
logForDebugging with their corresponding public exports so the file uses the
approved import boundaries and TSConfig alias style.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 (claude-code-best#221) * 1. 修复 src/commands/fork/index.ts — 将空 stub 改为有效的 Command 定义 2. 新增 src/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 * Update src/commands/fork/fork.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix --------- Co-authored-by: HitMargin <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 (claude-code-best#221) * 1. 修复 src/commands/fork/index.ts — 将空 stub 改为有效的 Command 定义 2. 新增 src/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 * Update src/commands/fork/fork.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix --------- Co-authored-by: HitMargin <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 (claude-code-best#221) * 1. 修复 src/commands/fork/index.ts — 将空 stub 改为有效的 Command 定义 2. 新增 src/commands/fork/fork.tsx — 完整实现 /fork 命令,复用了 AgentTool 的 fork 子 agent 逻辑 * Update src/commands/fork/fork.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix --------- Co-authored-by: HitMargin <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.