pi-thread-engine 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PLAN.md +30 -53
- package/README.md +221 -214
- package/_lib/contract.ts +116 -0
- package/docs/HELLO_PYTHON.md +68 -0
- package/extensions/index.ts +111 -78
- package/package.json +15 -6
- package/src/core/executor.ts +12 -6
- package/src/core/registry.test.ts +32 -0
- package/src/core/registry.ts +290 -290
- package/src/core/types.ts +107 -107
- package/src/core/worktree.ts +309 -263
- package/src/hello-world.test.ts +30 -0
- package/src/hello-world.ts +25 -0
- package/src/worktree-lifecycle.test.ts +124 -0
package/src/core/types.ts
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
/** Thread types from the thread engineering framework */
|
|
2
|
-
export type ThreadType = "base" | "parallel" | "chained" | "fusion" | "meta" | "long" | "zero" | "worktree" | "plan" | "scheduled" | "monitor";
|
|
3
|
-
|
|
4
|
-
/** Thread lifecycle states */
|
|
5
|
-
export type ThreadState = "pending" | "running" | "paused" | "completed" | "failed" | "killed" | "needs_input";
|
|
6
|
-
|
|
7
|
-
/** How a thread is executed */
|
|
8
|
-
export type ExecutionBackend = "subagent" | "native";
|
|
9
|
-
|
|
10
|
-
/** A single unit of work within a thread */
|
|
11
|
-
export interface ThreadTask {
|
|
12
|
-
usage?: { inputTokens: number; outputTokens: number; cacheRead: number; totalTokens: number; cost: number };
|
|
13
|
-
id: string;
|
|
14
|
-
label: string;
|
|
15
|
-
prompt: string;
|
|
16
|
-
model?: string;
|
|
17
|
-
state: ThreadState;
|
|
18
|
-
startedAt?: number;
|
|
19
|
-
completedAt?: number;
|
|
20
|
-
result?: string;
|
|
21
|
-
error?: string;
|
|
22
|
-
/** interactive_shell session ID or subagent run ID */
|
|
23
|
-
sessionId?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Thread configuration */
|
|
27
|
-
export interface ThreadConfig {
|
|
28
|
-
type: ThreadType;
|
|
29
|
-
tasks: ThreadTask[];
|
|
30
|
-
/** Execution backend */
|
|
31
|
-
backend: ExecutionBackend;
|
|
32
|
-
/** For fusion threads: models to compete */
|
|
33
|
-
models?: string[];
|
|
34
|
-
/** For zero threads: verification command */
|
|
35
|
-
verifyCommand?: string;
|
|
36
|
-
/** For chained threads: require human checkpoint between phases */
|
|
37
|
-
checkpoints?: boolean;
|
|
38
|
-
/** Working directory */
|
|
39
|
-
cwd?: string;
|
|
40
|
-
/** Subagent agent name to use (default: "worker") */
|
|
41
|
-
agent?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** A thread — the fundamental unit of tracked work */
|
|
45
|
-
export interface Thread {
|
|
46
|
-
id: string;
|
|
47
|
-
type: ThreadType;
|
|
48
|
-
label: string;
|
|
49
|
-
state: ThreadState;
|
|
50
|
-
config: ThreadConfig;
|
|
51
|
-
tasks: ThreadTask[];
|
|
52
|
-
createdAt: number;
|
|
53
|
-
startedAt?: number;
|
|
54
|
-
completedAt?: number;
|
|
55
|
-
/** Duration in ms */
|
|
56
|
-
duration?: number;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** A story — a goal decomposed into thread phases */
|
|
60
|
-
export interface Story {
|
|
61
|
-
id: string;
|
|
62
|
-
goal: string;
|
|
63
|
-
state: "planning" | "executing" | "verifying" | "done" | "failed";
|
|
64
|
-
phases: StoryPhase[];
|
|
65
|
-
createdAt: number;
|
|
66
|
-
completedAt?: number;
|
|
67
|
-
/** Verification command */
|
|
68
|
-
verify?: string;
|
|
69
|
-
/** Files changed */
|
|
70
|
-
artifacts: string[];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface StoryPhase {
|
|
74
|
-
name: string;
|
|
75
|
-
threadType: ThreadType;
|
|
76
|
-
threadId?: string;
|
|
77
|
-
state: ThreadState;
|
|
78
|
-
description: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Short status line for dashboard */
|
|
82
|
-
export interface ThreadSummary {
|
|
83
|
-
id: string;
|
|
84
|
-
type: ThreadType;
|
|
85
|
-
label: string;
|
|
86
|
-
state: ThreadState;
|
|
87
|
-
progress: string;
|
|
88
|
-
elapsed: string;
|
|
89
|
-
totalTokens: number;
|
|
90
|
-
totalCost: number;
|
|
91
|
-
backend: ExecutionBackend;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Thread event for state changes */
|
|
95
|
-
export type ThreadEvent =
|
|
96
|
-
| { type: "thread_created"; thread: Thread }
|
|
97
|
-
| { type: "thread_started"; thread: Thread }
|
|
98
|
-
| { type: "task_started"; thread: Thread; task: ThreadTask }
|
|
99
|
-
| { type: "task_completed"; thread: Thread; task: ThreadTask }
|
|
100
|
-
| { type: "task_failed"; thread: Thread; task: ThreadTask }
|
|
101
|
-
| { type: "thread_completed"; thread: Thread }
|
|
102
|
-
| { type: "thread_failed"; thread: Thread }
|
|
103
|
-
| { type: "thread_killed"; thread: Thread }
|
|
104
|
-
| { type: "story_created"; story: Story }
|
|
105
|
-
| { type: "story_phase_started"; story: Story; phase: StoryPhase }
|
|
106
|
-
| { type: "story_completed"; story: Story }
|
|
107
|
-
| { type: "story_failed"; story: Story };
|
|
1
|
+
/** Thread types from the thread engineering framework */
|
|
2
|
+
export type ThreadType = "base" | "parallel" | "chained" | "fusion" | "meta" | "long" | "zero" | "worktree" | "plan" | "scheduled" | "monitor";
|
|
3
|
+
|
|
4
|
+
/** Thread lifecycle states */
|
|
5
|
+
export type ThreadState = "pending" | "running" | "paused" | "completed" | "failed" | "killed" | "needs_input";
|
|
6
|
+
|
|
7
|
+
/** How a thread is executed */
|
|
8
|
+
export type ExecutionBackend = "subagent" | "native";
|
|
9
|
+
|
|
10
|
+
/** A single unit of work within a thread */
|
|
11
|
+
export interface ThreadTask {
|
|
12
|
+
usage?: { inputTokens: number; outputTokens: number; cacheRead: number; totalTokens: number; cost: number };
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
prompt: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
state: ThreadState;
|
|
18
|
+
startedAt?: number;
|
|
19
|
+
completedAt?: number;
|
|
20
|
+
result?: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
/** interactive_shell session ID or subagent run ID */
|
|
23
|
+
sessionId?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Thread configuration */
|
|
27
|
+
export interface ThreadConfig {
|
|
28
|
+
type: ThreadType;
|
|
29
|
+
tasks: ThreadTask[];
|
|
30
|
+
/** Execution backend */
|
|
31
|
+
backend: ExecutionBackend;
|
|
32
|
+
/** For fusion threads: models to compete */
|
|
33
|
+
models?: string[];
|
|
34
|
+
/** For zero threads: verification command */
|
|
35
|
+
verifyCommand?: string;
|
|
36
|
+
/** For chained threads: require human checkpoint between phases */
|
|
37
|
+
checkpoints?: boolean;
|
|
38
|
+
/** Working directory */
|
|
39
|
+
cwd?: string;
|
|
40
|
+
/** Subagent agent name to use (default: "worker") */
|
|
41
|
+
agent?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A thread — the fundamental unit of tracked work */
|
|
45
|
+
export interface Thread {
|
|
46
|
+
id: string;
|
|
47
|
+
type: ThreadType;
|
|
48
|
+
label: string;
|
|
49
|
+
state: ThreadState;
|
|
50
|
+
config: ThreadConfig;
|
|
51
|
+
tasks: ThreadTask[];
|
|
52
|
+
createdAt: number;
|
|
53
|
+
startedAt?: number;
|
|
54
|
+
completedAt?: number;
|
|
55
|
+
/** Duration in ms */
|
|
56
|
+
duration?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A story — a goal decomposed into thread phases */
|
|
60
|
+
export interface Story {
|
|
61
|
+
id: string;
|
|
62
|
+
goal: string;
|
|
63
|
+
state: "planning" | "executing" | "verifying" | "done" | "failed";
|
|
64
|
+
phases: StoryPhase[];
|
|
65
|
+
createdAt: number;
|
|
66
|
+
completedAt?: number;
|
|
67
|
+
/** Verification command */
|
|
68
|
+
verify?: string;
|
|
69
|
+
/** Files changed */
|
|
70
|
+
artifacts: string[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface StoryPhase {
|
|
74
|
+
name: string;
|
|
75
|
+
threadType: ThreadType;
|
|
76
|
+
threadId?: string;
|
|
77
|
+
state: ThreadState;
|
|
78
|
+
description: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Short status line for dashboard */
|
|
82
|
+
export interface ThreadSummary {
|
|
83
|
+
id: string;
|
|
84
|
+
type: ThreadType;
|
|
85
|
+
label: string;
|
|
86
|
+
state: ThreadState;
|
|
87
|
+
progress: string;
|
|
88
|
+
elapsed: string;
|
|
89
|
+
totalTokens: number;
|
|
90
|
+
totalCost: number;
|
|
91
|
+
backend: ExecutionBackend;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Thread event for state changes */
|
|
95
|
+
export type ThreadEvent =
|
|
96
|
+
| { type: "thread_created"; thread: Thread }
|
|
97
|
+
| { type: "thread_started"; thread: Thread }
|
|
98
|
+
| { type: "task_started"; thread: Thread; task: ThreadTask }
|
|
99
|
+
| { type: "task_completed"; thread: Thread; task: ThreadTask }
|
|
100
|
+
| { type: "task_failed"; thread: Thread; task: ThreadTask }
|
|
101
|
+
| { type: "thread_completed"; thread: Thread }
|
|
102
|
+
| { type: "thread_failed"; thread: Thread }
|
|
103
|
+
| { type: "thread_killed"; thread: Thread }
|
|
104
|
+
| { type: "story_created"; story: Story }
|
|
105
|
+
| { type: "story_phase_started"; story: Story; phase: StoryPhase }
|
|
106
|
+
| { type: "story_completed"; story: Story }
|
|
107
|
+
| { type: "story_failed"; story: Story };
|