mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
Feat/integrate lint preview (#285)
* feat: 适配 zed acp 协议 * docs: 完善 acp 文档 * feat: integrate feature branches + daemon/job 命令层级化 + 跨平台后台引擎 Cherry-picked from origin/lint/preview (637c908), excluding lint-only changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: correct detectMimeFromBase64 to decode raw bytes from base64 Cherry-picked from origin/lint/preview (ee36954). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: daemon 子进程 spawn 跨平台修复 + CliLaunchSpec 集中化重构 Cherry-picked from origin/lint/preview (c5f52cd), excluding lint-only formatting changes. - 新建 src/utils/cliLaunch.ts: 集中化 CLI 子进程启动层 - 修复 --daemon-worker=kind 等号格式解析 - 修复 daemon/bg fast path 缺少 setShellIfWindows() - 修复 checkPathExists 用 existsSync 替代 execSync('dir') - 7 个 spawn 站点迁移到 CliLaunchSpec Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: merge tsconfig.base.json into tsconfig.json with full compiler options The cherry-pick from637c908dropped jsx/strict/etc settings when removing tsconfig.base.json. This commit restores them in a single tsconfig.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: merge tsconfig.base.json into tsconfig.json with full compiler options The cherry-pick from637c908dropped jsx/strict/etc settings when removing tsconfig.base.json. This commit restores them in a single tsconfig.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
80
src/proactive/__tests__/state.baseline.test.ts
Normal file
80
src/proactive/__tests__/state.baseline.test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { beforeEach, describe, expect, test } from 'bun:test'
|
||||
import {
|
||||
activateProactive,
|
||||
deactivateProactive,
|
||||
getActivationSource,
|
||||
getNextTickAt,
|
||||
isContextBlocked,
|
||||
isProactiveActive,
|
||||
isProactivePaused,
|
||||
pauseProactive,
|
||||
resumeProactive,
|
||||
setContextBlocked,
|
||||
setNextTickAt,
|
||||
shouldTick,
|
||||
subscribeToProactiveChanges,
|
||||
} from '../index'
|
||||
|
||||
function resetProactiveState() {
|
||||
activateProactive('reset')
|
||||
setContextBlocked(false)
|
||||
setNextTickAt(null)
|
||||
deactivateProactive()
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
resetProactiveState()
|
||||
})
|
||||
|
||||
describe('proactive state baseline', () => {
|
||||
test('activateProactive enables proactive mode and records the source', () => {
|
||||
activateProactive('baseline_test')
|
||||
|
||||
expect(isProactiveActive()).toBe(true)
|
||||
expect(isProactivePaused()).toBe(false)
|
||||
expect(isContextBlocked()).toBe(false)
|
||||
expect(getActivationSource()).toBe('baseline_test')
|
||||
expect(shouldTick()).toBe(true)
|
||||
})
|
||||
|
||||
test('pauseProactive suppresses ticking and clears nextTickAt', () => {
|
||||
activateProactive('pause_case')
|
||||
setNextTickAt(Date.now() + 30_000)
|
||||
|
||||
pauseProactive()
|
||||
|
||||
expect(isProactivePaused()).toBe(true)
|
||||
expect(getNextTickAt()).toBeNull()
|
||||
expect(shouldTick()).toBe(false)
|
||||
|
||||
resumeProactive()
|
||||
expect(isProactivePaused()).toBe(false)
|
||||
expect(shouldTick()).toBe(true)
|
||||
})
|
||||
|
||||
test('setContextBlocked clears nextTickAt and blocks ticking', () => {
|
||||
activateProactive('blocked_case')
|
||||
setNextTickAt(Date.now() + 5_000)
|
||||
|
||||
setContextBlocked(true)
|
||||
|
||||
expect(isContextBlocked()).toBe(true)
|
||||
expect(getNextTickAt()).toBeNull()
|
||||
expect(shouldTick()).toBe(false)
|
||||
})
|
||||
|
||||
test('subscribers are notified on state changes', () => {
|
||||
let notifications = 0
|
||||
const unsubscribe = subscribeToProactiveChanges(() => {
|
||||
notifications += 1
|
||||
})
|
||||
|
||||
activateProactive('subscriber_case')
|
||||
setNextTickAt(Date.now() + 1_000)
|
||||
setContextBlocked(true)
|
||||
deactivateProactive()
|
||||
unsubscribe()
|
||||
|
||||
expect(notifications).toBeGreaterThanOrEqual(3)
|
||||
})
|
||||
})
|
||||
@@ -6,7 +6,10 @@
|
||||
* proactive mode is active and not blocked.
|
||||
*/
|
||||
import { useEffect, useRef } from 'react'
|
||||
import type { QueuedCommand } from '../types/textInputTypes.js'
|
||||
import { TICK_TAG } from '../constants/xml.js'
|
||||
import { getCwd } from '../utils/cwd.js'
|
||||
import { createProactiveAutonomyCommands } from '../utils/autonomyRuns.js'
|
||||
import {
|
||||
isProactiveActive,
|
||||
isProactivePaused,
|
||||
@@ -24,8 +27,7 @@ type UseProactiveOpts = {
|
||||
queuedCommandsLength: number
|
||||
hasActiveLocalJsxUI: boolean
|
||||
isInPlanMode: boolean
|
||||
onSubmitTick: (prompt: string) => void
|
||||
onQueueTick: (prompt: string) => void
|
||||
onQueueTick: (command: QueuedCommand) => void
|
||||
}
|
||||
|
||||
export function useProactive(opts: UseProactiveOpts): void {
|
||||
@@ -70,14 +72,19 @@ export function useProactive(opts: UseProactiveOpts): void {
|
||||
return
|
||||
}
|
||||
|
||||
const tickContent = `<${TICK_TAG}>${new Date().toLocaleTimeString()}</${TICK_TAG}>`
|
||||
|
||||
// If nothing is in the queue, submit directly; otherwise queue
|
||||
if (queuedCommandsLength === 0) {
|
||||
optsRef.current.onSubmitTick(tickContent)
|
||||
} else {
|
||||
optsRef.current.onQueueTick(tickContent)
|
||||
}
|
||||
void (async () => {
|
||||
const commands = await createProactiveAutonomyCommands({
|
||||
basePrompt: `<${TICK_TAG}>${new Date().toLocaleTimeString()}</${TICK_TAG}>`,
|
||||
currentDir: getCwd(),
|
||||
})
|
||||
for (const command of commands) {
|
||||
// Always queue proactive turns. This avoids races where the prompt
|
||||
// is built asynchronously, a user turn starts meanwhile, and a
|
||||
// direct-submit path would silently drop the autonomy turn after
|
||||
// consuming its heartbeat due-state.
|
||||
optsRef.current.onQueueTick(command)
|
||||
}
|
||||
})()
|
||||
|
||||
// Schedule next tick
|
||||
scheduleTick()
|
||||
|
||||
Reference in New Issue
Block a user