-
Notifications
You must be signed in to change notification settings - Fork 18.8k
feat: open source claude code ✨ #41447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gameroman
wants to merge
2
commits into
anthropics:main
Choose a base branch
from
bunjavascript:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { randomBytes } from 'crypto' | ||
| import type { AppState } from './state/AppState.js' | ||
| import type { AgentId } from './types/ids.js' | ||
| import { getTaskOutputPath } from './utils/task/diskOutput.js' | ||
|
|
||
| export type TaskType = | ||
| | 'local_bash' | ||
| | 'local_agent' | ||
| | 'remote_agent' | ||
| | 'in_process_teammate' | ||
| | 'local_workflow' | ||
| | 'monitor_mcp' | ||
| | 'dream' | ||
|
|
||
| export type TaskStatus = | ||
| | 'pending' | ||
| | 'running' | ||
| | 'completed' | ||
| | 'failed' | ||
| | 'killed' | ||
|
|
||
| /** | ||
| * True when a task is in a terminal state and will not transition further. | ||
| * Used to guard against injecting messages into dead teammates, evicting | ||
| * finished tasks from AppState, and orphan-cleanup paths. | ||
| */ | ||
| export function isTerminalTaskStatus(status: TaskStatus): boolean { | ||
| return status === 'completed' || status === 'failed' || status === 'killed' | ||
| } | ||
|
|
||
| export type TaskHandle = { | ||
| taskId: string | ||
| cleanup?: () => void | ||
| } | ||
|
|
||
| export type SetAppState = (f: (prev: AppState) => AppState) => void | ||
|
|
||
| export type TaskContext = { | ||
| abortController: AbortController | ||
| getAppState: () => AppState | ||
| setAppState: SetAppState | ||
| } | ||
|
|
||
| // Base fields shared by all task states | ||
| export type TaskStateBase = { | ||
| id: string | ||
| type: TaskType | ||
| status: TaskStatus | ||
| description: string | ||
| toolUseId?: string | ||
| startTime: number | ||
| endTime?: number | ||
| totalPausedMs?: number | ||
| outputFile: string | ||
| outputOffset: number | ||
| notified: boolean | ||
| } | ||
|
|
||
| export type LocalShellSpawnInput = { | ||
| command: string | ||
| description: string | ||
| timeout?: number | ||
| toolUseId?: string | ||
| agentId?: AgentId | ||
| /** UI display variant: description-as-label, dialog title, status bar pill. */ | ||
| kind?: 'bash' | 'monitor' | ||
| } | ||
|
|
||
| // What getTaskByType dispatches for: kill. spawn/render were never | ||
| // called polymorphically (removed in #22546). All six kill implementations | ||
| // use only setAppState — getAppState/abortController were dead weight. | ||
| export type Task = { | ||
| name: string | ||
| type: TaskType | ||
| kill(taskId: string, setAppState: SetAppState): Promise<void> | ||
| } | ||
|
|
||
| // Task ID prefixes | ||
| const TASK_ID_PREFIXES: Record<string, string> = { | ||
| local_bash: 'b', // Keep as 'b' for backward compatibility | ||
| local_agent: 'a', | ||
| remote_agent: 'r', | ||
| in_process_teammate: 't', | ||
| local_workflow: 'w', | ||
| monitor_mcp: 'm', | ||
| dream: 'd', | ||
| } | ||
|
|
||
| // Get task ID prefix | ||
| function getTaskIdPrefix(type: TaskType): string { | ||
| return TASK_ID_PREFIXES[type] ?? 'x' | ||
| } | ||
|
|
||
| // Case-insensitive-safe alphabet (digits + lowercase) for task IDs. | ||
| // 36^8 ≈ 2.8 trillion combinations, sufficient to resist brute-force symlink attacks. | ||
| const TASK_ID_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz' | ||
|
|
||
| export function generateTaskId(type: TaskType): string { | ||
| const prefix = getTaskIdPrefix(type) | ||
| const bytes = randomBytes(8) | ||
| let id = prefix | ||
| for (let i = 0; i < 8; i++) { | ||
| id += TASK_ID_ALPHABET[bytes[i]! % TASK_ID_ALPHABET.length] | ||
| } | ||
| return id | ||
| } | ||
|
|
||
| export function createTaskStateBase( | ||
| id: string, | ||
| type: TaskType, | ||
| description: string, | ||
| toolUseId?: string, | ||
| ): TaskStateBase { | ||
| return { | ||
| id, | ||
| type, | ||
| status: 'pending', | ||
| description, | ||
| toolUseId, | ||
| startTime: Date.now(), | ||
| outputFile: getTaskOutputPath(id), | ||
| outputOffset: 0, | ||
| notified: false, | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.