Skip to content

Commit ff17dcb

Browse files
authored
feat(TaskRegistry): introduce TaskRegistry and migrate clineStack (#1014)
* feat(TaskRegistry): introduce TaskRegistry and migrate clineStack * refactor(tests): replace `as any` casts with bracket notation for private member access * chore(eslint): enforce no-explicit-any with bulk suppressions for existing violations * docs(TaskRegistry): push method * fixup! chore(eslint): enforce no-explicit-any with bulk suppressions for existing violations
1 parent dfb8d69 commit ff17dcb

13 files changed

Lines changed: 2596 additions & 195 deletions

packages/config-eslint/base.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import js from "@eslint/js"
22
import eslintConfigPrettier from "eslint-config-prettier"
33
import turboPlugin from "eslint-plugin-turbo"
44
import tseslint from "typescript-eslint"
5-
import onlyWarn from "eslint-plugin-only-warn"
6-
75
/**
86
* A shared ESLint configuration for the repository.
97
*
@@ -21,11 +19,6 @@ export const config = [
2119
"turbo/no-undeclared-env-vars": "off",
2220
},
2321
},
24-
{
25-
plugins: {
26-
onlyWarn,
27-
},
28-
},
2922
{
3023
ignores: ["dist/**"],
3124
},

packages/config-eslint/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@next/eslint-plugin-next": "15.5.20",
1313
"eslint": "9.39.4",
1414
"eslint-config-prettier": "10.1.8",
15-
"eslint-plugin-only-warn": "1.2.1",
1615
"eslint-plugin-react": "7.37.5",
1716
"eslint-plugin-react-hooks": "5.2.0",
1817
"eslint-plugin-turbo": "2.10.0",

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
import { ClineProvider } from "../../core/webview/ClineProvider"
2+
import { TaskRegistry } from "../../core/task/TaskRegistry"
3+
import { type Task } from "../../core/task/Task"
4+
5+
type ProviderStubFields = {
6+
delegationTransitionLocks?: Map<string, Promise<void>>
7+
cancelledDelegationChildIds?: Set<string>
8+
log?: ReturnType<typeof vi.fn>
9+
taskHistoryStore?: { get: (id: string) => unknown }
10+
taskRegistry?: TaskRegistry
11+
clineStack?: Task[]
12+
tasks?: Task[]
13+
runDelegationTransition?: unknown
14+
removeClineFromStack?: unknown
15+
evictCurrentTask?: unknown
16+
}
17+
18+
type PrivateProviderMethods = {
19+
runDelegationTransition: (this: unknown, ...args: unknown[]) => unknown
20+
removeClineFromStack: (this: unknown, ...args: unknown[]) => unknown
21+
evictCurrentTask: (this: unknown, ...args: unknown[]) => unknown
22+
}
223

324
/**
425
* Augments a plain stub object with the instance fields and bound methods that
526
* ClineProvider methods read from `this` (runDelegationTransition,
627
* delegationTransitionLocks, cancelledDelegationChildIds, cancellingDelegationChildIds),
7-
* so tests can call private methods via `(ClineProvider.prototype as any).method.call(stub, …)`
28+
* so tests can call private ClineProvider methods against a plain object
829
* without instantiating a real ClineProvider.
30+
*
31+
* Pass `tasks` (array of Task mocks) to pre-seed the registry in stack order.
32+
* The legacy `clineStack` key is accepted and converted automatically.
933
*/
10-
export function makeProviderStub<T extends object>(stub: T): T {
11-
const s = stub as any
12-
const proto = ClineProvider.prototype as any
34+
export function makeProviderStub<T extends object>(stub: T): ClineProvider {
35+
const s = stub as T & ProviderStubFields
36+
const proto = ClineProvider.prototype as unknown as PrivateProviderMethods
1337
s.delegationTransitionLocks ??= new Map()
1438
s.cancelledDelegationChildIds ??= new Set()
1539
s.log ??= vi.fn()
1640
s.taskHistoryStore ??= { get: () => undefined }
17-
s.runDelegationTransition = proto.runDelegationTransition.bind(s)
41+
42+
// Convert legacy clineStack array into a TaskRegistry
43+
if (!s.taskRegistry) {
44+
const registry = new TaskRegistry()
45+
const seed: Task[] = s.clineStack ?? s.tasks ?? []
46+
for (const t of seed) registry.push(t)
47+
s.taskRegistry = registry
48+
}
49+
delete s.clineStack
50+
51+
s.runDelegationTransition ??= proto.runDelegationTransition.bind(s)
1852
s.removeClineFromStack ??= proto.removeClineFromStack.bind(s)
1953
s.evictCurrentTask ??= proto.evictCurrentTask.bind(s)
20-
return s
54+
return s as unknown as ClineProvider
2155
}

0 commit comments

Comments
 (0)