@clinebot/core 0.0.0
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/README.md +88 -0
- package/dist/account/cline-account-service.d.ts +34 -0
- package/dist/account/index.d.ts +3 -0
- package/dist/account/rpc.d.ts +38 -0
- package/dist/account/types.d.ts +74 -0
- package/dist/agents/agent-config-loader.d.ts +18 -0
- package/dist/agents/agent-config-parser.d.ts +25 -0
- package/dist/agents/hooks-config-loader.d.ts +23 -0
- package/dist/agents/index.d.ts +11 -0
- package/dist/agents/plugin-config-loader.d.ts +22 -0
- package/dist/agents/plugin-loader.d.ts +9 -0
- package/dist/agents/plugin-sandbox.d.ts +12 -0
- package/dist/agents/unified-config-file-watcher.d.ts +77 -0
- package/dist/agents/user-instruction-config-loader.d.ts +63 -0
- package/dist/auth/client.d.ts +11 -0
- package/dist/auth/cline.d.ts +41 -0
- package/dist/auth/codex.d.ts +39 -0
- package/dist/auth/oca.d.ts +22 -0
- package/dist/auth/server.d.ts +22 -0
- package/dist/auth/types.d.ts +72 -0
- package/dist/auth/utils.d.ts +32 -0
- package/dist/chat/chat-schema.d.ts +145 -0
- package/dist/default-tools/constants.d.ts +23 -0
- package/dist/default-tools/definitions.d.ts +96 -0
- package/dist/default-tools/executors/apply-patch-parser.d.ts +68 -0
- package/dist/default-tools/executors/apply-patch.d.ts +26 -0
- package/dist/default-tools/executors/bash.d.ts +49 -0
- package/dist/default-tools/executors/editor.d.ts +31 -0
- package/dist/default-tools/executors/file-read.d.ts +40 -0
- package/dist/default-tools/executors/index.d.ts +44 -0
- package/dist/default-tools/executors/search.d.ts +50 -0
- package/dist/default-tools/executors/web-fetch.d.ts +58 -0
- package/dist/default-tools/index.d.ts +57 -0
- package/dist/default-tools/presets.d.ts +124 -0
- package/dist/default-tools/schemas.d.ts +121 -0
- package/dist/default-tools/types.d.ts +237 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +220 -0
- package/dist/input/file-indexer.d.ts +5 -0
- package/dist/input/index.d.ts +4 -0
- package/dist/input/mention-enricher.d.ts +12 -0
- package/dist/mcp/config-loader.d.ts +15 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/manager.d.ts +24 -0
- package/dist/mcp/types.d.ts +66 -0
- package/dist/runtime/hook-file-hooks.d.ts +18 -0
- package/dist/runtime/rules.d.ts +5 -0
- package/dist/runtime/runtime-builder.d.ts +5 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +19 -0
- package/dist/runtime/session-runtime.d.ts +36 -0
- package/dist/runtime/tool-approval.d.ts +9 -0
- package/dist/runtime/workflows.d.ts +13 -0
- package/dist/server/index.d.ts +47 -0
- package/dist/server/index.js +641 -0
- package/dist/session/default-session-manager.d.ts +77 -0
- package/dist/session/rpc-session-service.d.ts +12 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +28 -0
- package/dist/session/session-artifacts.d.ts +19 -0
- package/dist/session/session-graph.d.ts +15 -0
- package/dist/session/session-host.d.ts +21 -0
- package/dist/session/session-manager.d.ts +50 -0
- package/dist/session/session-manifest.d.ts +30 -0
- package/dist/session/session-service.d.ts +113 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +30 -0
- package/dist/session/unified-session-persistence-service.d.ts +93 -0
- package/dist/session/workspace-manager.d.ts +28 -0
- package/dist/session/workspace-manifest.d.ts +25 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +13 -0
- package/dist/storage/provider-settings-manager.d.ts +20 -0
- package/dist/storage/sqlite-session-store.d.ts +29 -0
- package/dist/storage/sqlite-team-store.d.ts +31 -0
- package/dist/storage/team-store.d.ts +2 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/projections.d.ts +8 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/config.d.ts +37 -0
- package/dist/types/events.d.ts +54 -0
- package/dist/types/provider-settings.d.ts +20 -0
- package/dist/types/sessions.d.ts +9 -0
- package/dist/types/storage.d.ts +37 -0
- package/dist/types/workspace.d.ts +7 -0
- package/dist/types.d.ts +26 -0
- package/package.json +63 -0
- package/src/account/cline-account-service.test.ts +101 -0
- package/src/account/cline-account-service.ts +267 -0
- package/src/account/index.ts +20 -0
- package/src/account/rpc.test.ts +62 -0
- package/src/account/rpc.ts +172 -0
- package/src/account/types.ts +80 -0
- package/src/agents/agent-config-loader.test.ts +234 -0
- package/src/agents/agent-config-loader.ts +107 -0
- package/src/agents/agent-config-parser.ts +191 -0
- package/src/agents/hooks-config-loader.ts +97 -0
- package/src/agents/index.ts +84 -0
- package/src/agents/plugin-config-loader.test.ts +91 -0
- package/src/agents/plugin-config-loader.ts +160 -0
- package/src/agents/plugin-loader.test.ts +102 -0
- package/src/agents/plugin-loader.ts +105 -0
- package/src/agents/plugin-sandbox.test.ts +120 -0
- package/src/agents/plugin-sandbox.ts +471 -0
- package/src/agents/unified-config-file-watcher.test.ts +196 -0
- package/src/agents/unified-config-file-watcher.ts +483 -0
- package/src/agents/user-instruction-config-loader.test.ts +158 -0
- package/src/agents/user-instruction-config-loader.ts +438 -0
- package/src/auth/client.test.ts +40 -0
- package/src/auth/client.ts +25 -0
- package/src/auth/cline.test.ts +130 -0
- package/src/auth/cline.ts +414 -0
- package/src/auth/codex.test.ts +170 -0
- package/src/auth/codex.ts +466 -0
- package/src/auth/oca.test.ts +215 -0
- package/src/auth/oca.ts +546 -0
- package/src/auth/server.ts +216 -0
- package/src/auth/types.ts +78 -0
- package/src/auth/utils.test.ts +128 -0
- package/src/auth/utils.ts +247 -0
- package/src/chat/chat-schema.ts +82 -0
- package/src/default-tools/constants.ts +35 -0
- package/src/default-tools/definitions.test.ts +233 -0
- package/src/default-tools/definitions.ts +632 -0
- package/src/default-tools/executors/apply-patch-parser.ts +520 -0
- package/src/default-tools/executors/apply-patch.ts +359 -0
- package/src/default-tools/executors/bash.ts +205 -0
- package/src/default-tools/executors/editor.ts +231 -0
- package/src/default-tools/executors/file-read.test.ts +25 -0
- package/src/default-tools/executors/file-read.ts +94 -0
- package/src/default-tools/executors/index.ts +75 -0
- package/src/default-tools/executors/search.ts +278 -0
- package/src/default-tools/executors/web-fetch.ts +259 -0
- package/src/default-tools/index.ts +161 -0
- package/src/default-tools/presets.test.ts +63 -0
- package/src/default-tools/presets.ts +168 -0
- package/src/default-tools/schemas.ts +228 -0
- package/src/default-tools/types.ts +324 -0
- package/src/index.ts +119 -0
- package/src/input/file-indexer.d.ts +11 -0
- package/src/input/file-indexer.test.ts +87 -0
- package/src/input/file-indexer.ts +280 -0
- package/src/input/index.ts +7 -0
- package/src/input/mention-enricher.test.ts +82 -0
- package/src/input/mention-enricher.ts +119 -0
- package/src/mcp/config-loader.test.ts +238 -0
- package/src/mcp/config-loader.ts +219 -0
- package/src/mcp/index.ts +26 -0
- package/src/mcp/manager.test.ts +106 -0
- package/src/mcp/manager.ts +262 -0
- package/src/mcp/types.ts +88 -0
- package/src/runtime/hook-file-hooks.test.ts +106 -0
- package/src/runtime/hook-file-hooks.ts +736 -0
- package/src/runtime/index.ts +27 -0
- package/src/runtime/rules.ts +34 -0
- package/src/runtime/runtime-builder.team-persistence.test.ts +203 -0
- package/src/runtime/runtime-builder.test.ts +215 -0
- package/src/runtime/runtime-builder.ts +515 -0
- package/src/runtime/runtime-parity.test.ts +132 -0
- package/src/runtime/sandbox/subprocess-sandbox.ts +207 -0
- package/src/runtime/session-runtime.ts +44 -0
- package/src/runtime/tool-approval.ts +104 -0
- package/src/runtime/workflows.test.ts +119 -0
- package/src/runtime/workflows.ts +54 -0
- package/src/server/index.ts +282 -0
- package/src/session/default-session-manager.e2e.test.ts +354 -0
- package/src/session/default-session-manager.test.ts +816 -0
- package/src/session/default-session-manager.ts +1286 -0
- package/src/session/index.ts +37 -0
- package/src/session/rpc-session-service.ts +189 -0
- package/src/session/runtime-oauth-token-manager.test.ts +137 -0
- package/src/session/runtime-oauth-token-manager.ts +265 -0
- package/src/session/session-artifacts.ts +106 -0
- package/src/session/session-graph.ts +90 -0
- package/src/session/session-host.ts +190 -0
- package/src/session/session-manager.ts +56 -0
- package/src/session/session-manifest.ts +29 -0
- package/src/session/session-service.team-persistence.test.ts +48 -0
- package/src/session/session-service.ts +610 -0
- package/src/session/sqlite-rpc-session-backend.ts +303 -0
- package/src/session/unified-session-persistence-service.ts +781 -0
- package/src/session/workspace-manager.ts +98 -0
- package/src/session/workspace-manifest.ts +100 -0
- package/src/storage/artifact-store.ts +1 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/provider-settings-legacy-migration.test.ts +175 -0
- package/src/storage/provider-settings-legacy-migration.ts +637 -0
- package/src/storage/provider-settings-manager.test.ts +111 -0
- package/src/storage/provider-settings-manager.ts +129 -0
- package/src/storage/session-store.ts +1 -0
- package/src/storage/sqlite-session-store.ts +270 -0
- package/src/storage/sqlite-team-store.ts +443 -0
- package/src/storage/team-store.ts +5 -0
- package/src/team/index.ts +4 -0
- package/src/team/projections.ts +285 -0
- package/src/types/common.ts +14 -0
- package/src/types/config.ts +64 -0
- package/src/types/events.ts +46 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider-settings.ts +43 -0
- package/src/types/sessions.ts +16 -0
- package/src/types/storage.ts +64 -0
- package/src/types/workspace.ts +7 -0
- package/src/types.ts +127 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TeamEvent,
|
|
3
|
+
TeamOutcome,
|
|
4
|
+
TeamOutcomeFragment,
|
|
5
|
+
TeamRuntimeState,
|
|
6
|
+
} from "@clinebot/agents";
|
|
7
|
+
import type {
|
|
8
|
+
TeamProgressLifecycleEvent,
|
|
9
|
+
TeamProgressSummary,
|
|
10
|
+
} from "@clinebot/shared";
|
|
11
|
+
|
|
12
|
+
function toIsoNow(): string {
|
|
13
|
+
return new Date().toISOString();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function pct(numerator: number, denominator: number): number {
|
|
17
|
+
if (denominator <= 0) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
return Math.round((numerator / denominator) * 100);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function collectMissingRequiredSections(
|
|
24
|
+
outcomes: TeamOutcome[],
|
|
25
|
+
fragments: TeamOutcomeFragment[],
|
|
26
|
+
): string[] {
|
|
27
|
+
const approvedSections = new Set<string>();
|
|
28
|
+
for (const fragment of fragments) {
|
|
29
|
+
if (fragment.status === "reviewed") {
|
|
30
|
+
approvedSections.add(`${fragment.outcomeId}:${fragment.section}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const missing = new Set<string>();
|
|
34
|
+
for (const outcome of outcomes) {
|
|
35
|
+
if (outcome.status === "finalized") {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
for (const section of outcome.requiredSections) {
|
|
39
|
+
if (!approvedSections.has(`${outcome.id}:${section}`)) {
|
|
40
|
+
missing.add(`${outcome.id}:${section}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...missing].sort((a, b) => a.localeCompare(b));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function buildTeamProgressSummary(
|
|
48
|
+
teamName: string,
|
|
49
|
+
state: TeamRuntimeState,
|
|
50
|
+
): TeamProgressSummary {
|
|
51
|
+
const membersByStatus: Record<"idle" | "running" | "stopped", number> = {
|
|
52
|
+
idle: 0,
|
|
53
|
+
running: 0,
|
|
54
|
+
stopped: 0,
|
|
55
|
+
};
|
|
56
|
+
const tasksByStatus: Record<
|
|
57
|
+
"pending" | "in_progress" | "blocked" | "completed",
|
|
58
|
+
number
|
|
59
|
+
> = {
|
|
60
|
+
pending: 0,
|
|
61
|
+
in_progress: 0,
|
|
62
|
+
blocked: 0,
|
|
63
|
+
completed: 0,
|
|
64
|
+
};
|
|
65
|
+
const runsByStatus: Record<
|
|
66
|
+
"queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted",
|
|
67
|
+
number
|
|
68
|
+
> = {
|
|
69
|
+
queued: 0,
|
|
70
|
+
running: 0,
|
|
71
|
+
completed: 0,
|
|
72
|
+
failed: 0,
|
|
73
|
+
cancelled: 0,
|
|
74
|
+
interrupted: 0,
|
|
75
|
+
};
|
|
76
|
+
const outcomesByStatus: Record<"draft" | "in_review" | "finalized", number> =
|
|
77
|
+
{
|
|
78
|
+
draft: 0,
|
|
79
|
+
in_review: 0,
|
|
80
|
+
finalized: 0,
|
|
81
|
+
};
|
|
82
|
+
const fragmentsByStatus: Record<"draft" | "reviewed" | "rejected", number> = {
|
|
83
|
+
draft: 0,
|
|
84
|
+
reviewed: 0,
|
|
85
|
+
rejected: 0,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let leadCount = 0;
|
|
89
|
+
let teammateCount = 0;
|
|
90
|
+
for (const member of state.members) {
|
|
91
|
+
membersByStatus[member.status] += 1;
|
|
92
|
+
if (member.role === "lead") {
|
|
93
|
+
leadCount += 1;
|
|
94
|
+
} else {
|
|
95
|
+
teammateCount += 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const blockedTaskIds: string[] = [];
|
|
100
|
+
const readyTaskIds: string[] = [];
|
|
101
|
+
const completedTaskCount = state.tasks.filter(
|
|
102
|
+
(task) => task.status === "completed",
|
|
103
|
+
).length;
|
|
104
|
+
const taskById = new Map(state.tasks.map((task) => [task.id, task] as const));
|
|
105
|
+
for (const task of state.tasks) {
|
|
106
|
+
tasksByStatus[task.status] += 1;
|
|
107
|
+
if (task.status === "blocked") {
|
|
108
|
+
blockedTaskIds.push(task.id);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (task.status !== "pending") {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const depsSatisfied = task.dependsOn.every((depId) => {
|
|
115
|
+
const dependency = taskById.get(depId);
|
|
116
|
+
return dependency?.status === "completed";
|
|
117
|
+
});
|
|
118
|
+
if (depsSatisfied) {
|
|
119
|
+
readyTaskIds.push(task.id);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const activeRunIds: string[] = [];
|
|
124
|
+
let latestRunId: string | undefined;
|
|
125
|
+
let latestRunTs = 0;
|
|
126
|
+
for (const run of state.runs) {
|
|
127
|
+
runsByStatus[run.status] += 1;
|
|
128
|
+
if (run.status === "queued" || run.status === "running") {
|
|
129
|
+
activeRunIds.push(run.id);
|
|
130
|
+
}
|
|
131
|
+
const startedAtTs = run.startedAt.getTime();
|
|
132
|
+
if (startedAtTs >= latestRunTs) {
|
|
133
|
+
latestRunTs = startedAtTs;
|
|
134
|
+
latestRunId = run.id;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (const outcome of state.outcomes) {
|
|
139
|
+
outcomesByStatus[outcome.status] += 1;
|
|
140
|
+
}
|
|
141
|
+
for (const fragment of state.outcomeFragments) {
|
|
142
|
+
fragmentsByStatus[fragment.status] += 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
teamName,
|
|
147
|
+
updatedAt: toIsoNow(),
|
|
148
|
+
members: {
|
|
149
|
+
total: state.members.length,
|
|
150
|
+
byStatus: membersByStatus,
|
|
151
|
+
leadCount,
|
|
152
|
+
teammateCount,
|
|
153
|
+
},
|
|
154
|
+
tasks: {
|
|
155
|
+
total: state.tasks.length,
|
|
156
|
+
byStatus: tasksByStatus,
|
|
157
|
+
blockedTaskIds,
|
|
158
|
+
readyTaskIds,
|
|
159
|
+
completionPct: pct(completedTaskCount, state.tasks.length),
|
|
160
|
+
},
|
|
161
|
+
runs: {
|
|
162
|
+
total: state.runs.length,
|
|
163
|
+
byStatus: runsByStatus,
|
|
164
|
+
activeRunIds,
|
|
165
|
+
latestRunId,
|
|
166
|
+
},
|
|
167
|
+
outcomes: {
|
|
168
|
+
total: state.outcomes.length,
|
|
169
|
+
byStatus: outcomesByStatus,
|
|
170
|
+
finalizedPct: pct(outcomesByStatus.finalized, state.outcomes.length),
|
|
171
|
+
missingRequiredSections: collectMissingRequiredSections(
|
|
172
|
+
state.outcomes,
|
|
173
|
+
state.outcomeFragments,
|
|
174
|
+
),
|
|
175
|
+
},
|
|
176
|
+
fragments: {
|
|
177
|
+
total: state.outcomeFragments.length,
|
|
178
|
+
byStatus: fragmentsByStatus,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function toTeamProgressLifecycleEvent(input: {
|
|
184
|
+
teamName: string;
|
|
185
|
+
sessionId: string;
|
|
186
|
+
event: TeamEvent;
|
|
187
|
+
}): TeamProgressLifecycleEvent {
|
|
188
|
+
const { event } = input;
|
|
189
|
+
switch (event.type) {
|
|
190
|
+
case "team_task_updated":
|
|
191
|
+
return {
|
|
192
|
+
teamName: input.teamName,
|
|
193
|
+
sessionId: input.sessionId,
|
|
194
|
+
eventType: event.type,
|
|
195
|
+
ts: toIsoNow(),
|
|
196
|
+
taskId: event.task.id,
|
|
197
|
+
agentId: event.task.assignee ?? event.task.createdBy,
|
|
198
|
+
};
|
|
199
|
+
case "run_queued":
|
|
200
|
+
case "run_started":
|
|
201
|
+
case "run_completed":
|
|
202
|
+
case "run_failed":
|
|
203
|
+
case "run_cancelled":
|
|
204
|
+
case "run_interrupted":
|
|
205
|
+
return {
|
|
206
|
+
teamName: input.teamName,
|
|
207
|
+
sessionId: input.sessionId,
|
|
208
|
+
eventType: event.type,
|
|
209
|
+
ts: toIsoNow(),
|
|
210
|
+
runId: event.run.id,
|
|
211
|
+
taskId: event.run.taskId,
|
|
212
|
+
agentId: event.run.agentId,
|
|
213
|
+
message: event.run.error,
|
|
214
|
+
};
|
|
215
|
+
case "run_progress":
|
|
216
|
+
return {
|
|
217
|
+
teamName: input.teamName,
|
|
218
|
+
sessionId: input.sessionId,
|
|
219
|
+
eventType: event.type,
|
|
220
|
+
ts: toIsoNow(),
|
|
221
|
+
runId: event.run.id,
|
|
222
|
+
taskId: event.run.taskId,
|
|
223
|
+
agentId: event.run.agentId,
|
|
224
|
+
message: event.message,
|
|
225
|
+
};
|
|
226
|
+
case "outcome_created":
|
|
227
|
+
case "outcome_finalized":
|
|
228
|
+
return {
|
|
229
|
+
teamName: input.teamName,
|
|
230
|
+
sessionId: input.sessionId,
|
|
231
|
+
eventType: event.type,
|
|
232
|
+
ts: toIsoNow(),
|
|
233
|
+
outcomeId: event.outcome.id,
|
|
234
|
+
};
|
|
235
|
+
case "outcome_fragment_attached":
|
|
236
|
+
case "outcome_fragment_reviewed":
|
|
237
|
+
return {
|
|
238
|
+
teamName: input.teamName,
|
|
239
|
+
sessionId: input.sessionId,
|
|
240
|
+
eventType: event.type,
|
|
241
|
+
ts: toIsoNow(),
|
|
242
|
+
outcomeId: event.fragment.outcomeId,
|
|
243
|
+
fragmentId: event.fragment.id,
|
|
244
|
+
agentId: event.fragment.sourceAgentId,
|
|
245
|
+
};
|
|
246
|
+
case "team_message":
|
|
247
|
+
return {
|
|
248
|
+
teamName: input.teamName,
|
|
249
|
+
sessionId: input.sessionId,
|
|
250
|
+
eventType: event.type,
|
|
251
|
+
ts: toIsoNow(),
|
|
252
|
+
taskId: event.message.taskId,
|
|
253
|
+
agentId: event.message.fromAgentId,
|
|
254
|
+
message: event.message.subject,
|
|
255
|
+
};
|
|
256
|
+
case "team_mission_log":
|
|
257
|
+
return {
|
|
258
|
+
teamName: input.teamName,
|
|
259
|
+
sessionId: input.sessionId,
|
|
260
|
+
eventType: event.type,
|
|
261
|
+
ts: toIsoNow(),
|
|
262
|
+
taskId: event.entry.taskId,
|
|
263
|
+
agentId: event.entry.agentId,
|
|
264
|
+
message: event.entry.summary,
|
|
265
|
+
};
|
|
266
|
+
case "teammate_spawned":
|
|
267
|
+
case "teammate_shutdown":
|
|
268
|
+
case "task_start":
|
|
269
|
+
case "task_end":
|
|
270
|
+
case "agent_event":
|
|
271
|
+
return {
|
|
272
|
+
teamName: input.teamName,
|
|
273
|
+
sessionId: input.sessionId,
|
|
274
|
+
eventType: event.type,
|
|
275
|
+
ts: toIsoNow(),
|
|
276
|
+
agentId: event.agentId,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
teamName: input.teamName,
|
|
281
|
+
sessionId: input.sessionId,
|
|
282
|
+
eventType: (event as TeamEvent).type,
|
|
283
|
+
ts: toIsoNow(),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SESSION_STATUS_VALUES } from "@clinebot/shared";
|
|
2
|
+
|
|
3
|
+
export const SESSION_STATUSES = SESSION_STATUS_VALUES;
|
|
4
|
+
|
|
5
|
+
export type SessionStatus = (typeof SESSION_STATUSES)[number];
|
|
6
|
+
|
|
7
|
+
export enum SessionSource {
|
|
8
|
+
CLI = "cli",
|
|
9
|
+
CLI_SUBAGENT = "cli-subagent",
|
|
10
|
+
CORE = "core",
|
|
11
|
+
CORE_SUBAGENT = "core-subagent",
|
|
12
|
+
DESKTOP = "desktop",
|
|
13
|
+
DESKTOP_CHAT = "desktop-chat",
|
|
14
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentConfig,
|
|
3
|
+
AgentHooks,
|
|
4
|
+
HookErrorMode,
|
|
5
|
+
TeamEvent,
|
|
6
|
+
Tool,
|
|
7
|
+
} from "@clinebot/agents";
|
|
8
|
+
import type { providers as LlmsProviders } from "@clinebot/llms";
|
|
9
|
+
import type {
|
|
10
|
+
AgentMode,
|
|
11
|
+
BasicLogger,
|
|
12
|
+
SessionExecutionConfig,
|
|
13
|
+
SessionPromptConfig,
|
|
14
|
+
SessionWorkspaceConfig,
|
|
15
|
+
} from "@clinebot/shared";
|
|
16
|
+
|
|
17
|
+
export type CoreAgentMode = AgentMode;
|
|
18
|
+
|
|
19
|
+
export interface CoreModelConfig {
|
|
20
|
+
providerId: string;
|
|
21
|
+
modelId: string;
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
providerConfig?: LlmsProviders.ProviderConfig;
|
|
26
|
+
knownModels?: Record<string, LlmsProviders.ModelInfo>;
|
|
27
|
+
/**
|
|
28
|
+
* Request model-side thinking/reasoning when supported.
|
|
29
|
+
*/
|
|
30
|
+
thinking?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CoreRuntimeFeatures {
|
|
34
|
+
enableTools: boolean;
|
|
35
|
+
enableSpawnAgent: boolean;
|
|
36
|
+
enableAgentTeams: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CoreSessionConfig
|
|
40
|
+
extends CoreModelConfig,
|
|
41
|
+
CoreRuntimeFeatures,
|
|
42
|
+
Omit<SessionWorkspaceConfig, "workspaceRoot">,
|
|
43
|
+
Omit<SessionPromptConfig, "systemPrompt">,
|
|
44
|
+
Omit<
|
|
45
|
+
SessionExecutionConfig,
|
|
46
|
+
| "enableTools"
|
|
47
|
+
| "teamName"
|
|
48
|
+
| "missionLogIntervalSteps"
|
|
49
|
+
| "missionLogIntervalMs"
|
|
50
|
+
> {
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
workspaceRoot?: string;
|
|
53
|
+
systemPrompt: string;
|
|
54
|
+
teamName?: string;
|
|
55
|
+
missionLogIntervalSteps?: number;
|
|
56
|
+
missionLogIntervalMs?: number;
|
|
57
|
+
hooks?: AgentHooks;
|
|
58
|
+
hookErrorMode?: HookErrorMode;
|
|
59
|
+
logger?: BasicLogger;
|
|
60
|
+
extraTools?: Tool[];
|
|
61
|
+
pluginPaths?: string[];
|
|
62
|
+
extensions?: AgentConfig["extensions"];
|
|
63
|
+
onTeamEvent?: (event: TeamEvent) => void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface SessionChunkEvent {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
stream: "stdout" | "stderr" | "agent";
|
|
4
|
+
chunk: string;
|
|
5
|
+
ts: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SessionEndedEvent {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
reason: string;
|
|
11
|
+
ts: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SessionToolEvent {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
hookEventName: "tool_call" | "tool_result" | "agent_end" | "session_shutdown";
|
|
17
|
+
agentId?: string;
|
|
18
|
+
conversationId?: string;
|
|
19
|
+
parentAgentId?: string;
|
|
20
|
+
iteration?: number;
|
|
21
|
+
toolName?: string;
|
|
22
|
+
inputTokens?: number;
|
|
23
|
+
outputTokens?: number;
|
|
24
|
+
ts?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SessionTeamProgressEvent {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
teamName: string;
|
|
30
|
+
lifecycle: import("@clinebot/shared").TeamProgressLifecycleEvent;
|
|
31
|
+
summary: import("@clinebot/shared").TeamProgressSummary;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type CoreSessionEvent =
|
|
35
|
+
| { type: "chunk"; payload: SessionChunkEvent }
|
|
36
|
+
| {
|
|
37
|
+
type: "agent_event";
|
|
38
|
+
payload: {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
event: import("@clinebot/agents").AgentEvent;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
| { type: "team_progress"; payload: SessionTeamProgressEvent }
|
|
44
|
+
| { type: "ended"; payload: SessionEndedEvent }
|
|
45
|
+
| { type: "hook"; payload: SessionToolEvent }
|
|
46
|
+
| { type: "status"; payload: { sessionId: string; status: string } };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type { SessionSource, SessionStatus } from "./common";
|
|
2
|
+
export type {
|
|
3
|
+
CoreAgentMode,
|
|
4
|
+
CoreModelConfig,
|
|
5
|
+
CoreRuntimeFeatures,
|
|
6
|
+
CoreSessionConfig,
|
|
7
|
+
} from "./config";
|
|
8
|
+
export type {
|
|
9
|
+
CoreSessionEvent,
|
|
10
|
+
SessionChunkEvent,
|
|
11
|
+
SessionEndedEvent,
|
|
12
|
+
SessionTeamProgressEvent,
|
|
13
|
+
SessionToolEvent,
|
|
14
|
+
} from "./events";
|
|
15
|
+
export type {
|
|
16
|
+
ProviderConfig,
|
|
17
|
+
ProviderSettings,
|
|
18
|
+
ProviderTokenSource,
|
|
19
|
+
StoredProviderSettings,
|
|
20
|
+
StoredProviderSettingsEntry,
|
|
21
|
+
} from "./provider-settings";
|
|
22
|
+
export type { SessionRecord, SessionRef } from "./sessions";
|
|
23
|
+
export type { ArtifactStore, SessionStore, TeamStore } from "./storage";
|
|
24
|
+
export type { WorkspaceInfo } from "./workspace";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { providers } from "@clinebot/llms";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export type ProviderConfig = providers.ProviderConfig;
|
|
5
|
+
export type ProviderSettings = providers.ProviderSettings;
|
|
6
|
+
export const ProviderSettingsSchema: z.ZodType<ProviderSettings> =
|
|
7
|
+
providers.ProviderSettingsSchema;
|
|
8
|
+
export const toProviderConfig = providers.toProviderConfig;
|
|
9
|
+
|
|
10
|
+
export type ProviderTokenSource = "manual" | "oauth" | "migration";
|
|
11
|
+
|
|
12
|
+
export interface StoredProviderSettingsEntry {
|
|
13
|
+
settings: ProviderSettings;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
tokenSource: ProviderTokenSource;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface StoredProviderSettings {
|
|
19
|
+
version: 1;
|
|
20
|
+
lastUsedProvider?: string;
|
|
21
|
+
providers: Record<string, StoredProviderSettingsEntry>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const StoredProviderSettingsEntrySchema: z.ZodType<StoredProviderSettingsEntry> =
|
|
25
|
+
z.object({
|
|
26
|
+
settings: providers.ProviderSettingsSchema,
|
|
27
|
+
updatedAt: z.string().datetime(),
|
|
28
|
+
tokenSource: z.enum(["manual", "oauth", "migration"]).default("manual"),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const StoredProviderSettingsSchema: z.ZodType<StoredProviderSettings> =
|
|
32
|
+
z.object({
|
|
33
|
+
version: z.literal(1),
|
|
34
|
+
lastUsedProvider: z.string().min(1).optional(),
|
|
35
|
+
providers: z.record(z.string(), StoredProviderSettingsEntrySchema),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export function emptyStoredProviderSettings(): StoredProviderSettings {
|
|
39
|
+
return {
|
|
40
|
+
version: 1,
|
|
41
|
+
providers: {},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SessionLineage,
|
|
3
|
+
SessionRuntimeRecordShape,
|
|
4
|
+
} from "@clinebot/shared";
|
|
5
|
+
import type { SessionSource, SessionStatus } from "./common";
|
|
6
|
+
|
|
7
|
+
export interface SessionRef extends SessionLineage {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SessionRecord
|
|
12
|
+
extends SessionRef,
|
|
13
|
+
Omit<SessionRuntimeRecordShape, "source" | "status"> {
|
|
14
|
+
source: SessionSource;
|
|
15
|
+
status: SessionStatus;
|
|
16
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TeamEvent,
|
|
3
|
+
TeamRuntimeState,
|
|
4
|
+
TeamTeammateSpec,
|
|
5
|
+
} from "@clinebot/agents";
|
|
6
|
+
import type { SessionStatus } from "./common";
|
|
7
|
+
import type { SessionRecord } from "./sessions";
|
|
8
|
+
|
|
9
|
+
export interface SessionStore {
|
|
10
|
+
init(): Promise<void> | void;
|
|
11
|
+
create(record: SessionRecord): Promise<void> | void;
|
|
12
|
+
updateStatus(
|
|
13
|
+
sessionId: string,
|
|
14
|
+
status: SessionStatus,
|
|
15
|
+
exitCode?: number | null,
|
|
16
|
+
): Promise<void> | void;
|
|
17
|
+
update(
|
|
18
|
+
record: Partial<SessionRecord> & { sessionId: string },
|
|
19
|
+
): Promise<void> | void;
|
|
20
|
+
get(
|
|
21
|
+
sessionId: string,
|
|
22
|
+
): Promise<SessionRecord | undefined> | SessionRecord | undefined;
|
|
23
|
+
list(limit?: number): Promise<SessionRecord[]> | SessionRecord[];
|
|
24
|
+
delete(sessionId: string, cascade?: boolean): Promise<boolean> | boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TeamStore {
|
|
28
|
+
listTeamNames(): Promise<string[]> | string[];
|
|
29
|
+
readState(
|
|
30
|
+
teamName: string,
|
|
31
|
+
): Promise<TeamRuntimeState | undefined> | TeamRuntimeState | undefined;
|
|
32
|
+
readHistory(teamName: string, limit?: number): Promise<unknown[]> | unknown[];
|
|
33
|
+
loadRuntime(teamName: string):
|
|
34
|
+
| Promise<{
|
|
35
|
+
state?: TeamRuntimeState;
|
|
36
|
+
teammates: TeamTeammateSpec[];
|
|
37
|
+
interruptedRunIds: string[];
|
|
38
|
+
}>
|
|
39
|
+
| {
|
|
40
|
+
state?: TeamRuntimeState;
|
|
41
|
+
teammates: TeamTeammateSpec[];
|
|
42
|
+
interruptedRunIds: string[];
|
|
43
|
+
};
|
|
44
|
+
handleTeamEvent(teamName: string, event: TeamEvent): Promise<void> | void;
|
|
45
|
+
persistRuntime(
|
|
46
|
+
teamName: string,
|
|
47
|
+
state: TeamRuntimeState,
|
|
48
|
+
teammates: TeamTeammateSpec[],
|
|
49
|
+
): Promise<void> | void;
|
|
50
|
+
markInProgressRunsInterrupted(
|
|
51
|
+
teamName: string,
|
|
52
|
+
reason: string,
|
|
53
|
+
): Promise<string[]> | string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ArtifactStore {
|
|
57
|
+
appendTranscript(sessionId: string, text: string): Promise<void> | void;
|
|
58
|
+
appendHook(sessionId: string, payload: unknown): Promise<void> | void;
|
|
59
|
+
writeMessages(sessionId: string, messages: unknown[]): Promise<void> | void;
|
|
60
|
+
readTranscript(
|
|
61
|
+
sessionId: string,
|
|
62
|
+
maxChars?: number,
|
|
63
|
+
): Promise<string> | string;
|
|
64
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { providers as LlmsProviders } from "@clinebot/llms";
|
|
2
|
+
import type { CoreSessionEvent } from "./types/events";
|
|
3
|
+
|
|
4
|
+
export type {
|
|
5
|
+
AgentConfigWatcher,
|
|
6
|
+
AgentConfigWatcherEvent,
|
|
7
|
+
AgentYamlConfig,
|
|
8
|
+
BuildAgentConfigOverridesOptions,
|
|
9
|
+
CreateAgentConfigWatcherOptions,
|
|
10
|
+
CreateInstructionWatcherOptions,
|
|
11
|
+
CreateRulesConfigDefinitionOptions,
|
|
12
|
+
CreateSkillsConfigDefinitionOptions,
|
|
13
|
+
CreateUserInstructionConfigWatcherOptions,
|
|
14
|
+
CreateWorkflowsConfigDefinitionOptions,
|
|
15
|
+
LoadAgentPluginFromPathOptions,
|
|
16
|
+
ParseMarkdownFrontmatterResult,
|
|
17
|
+
ParseYamlFrontmatterResult,
|
|
18
|
+
ResolveAgentPluginPathsOptions,
|
|
19
|
+
RuleConfig,
|
|
20
|
+
SkillConfig,
|
|
21
|
+
UnifiedConfigDefinition,
|
|
22
|
+
UnifiedConfigFileCandidate,
|
|
23
|
+
UnifiedConfigFileContext,
|
|
24
|
+
UnifiedConfigRecord,
|
|
25
|
+
UnifiedConfigWatcherEvent,
|
|
26
|
+
UnifiedConfigWatcherOptions,
|
|
27
|
+
UserInstructionConfig,
|
|
28
|
+
UserInstructionConfigType,
|
|
29
|
+
UserInstructionConfigWatcher,
|
|
30
|
+
UserInstructionConfigWatcherEvent,
|
|
31
|
+
WorkflowConfig,
|
|
32
|
+
} from "./agents";
|
|
33
|
+
export {
|
|
34
|
+
createAgentConfigDefinition,
|
|
35
|
+
createAgentConfigWatcher,
|
|
36
|
+
createRulesConfigDefinition,
|
|
37
|
+
createSkillsConfigDefinition,
|
|
38
|
+
createUserInstructionConfigWatcher,
|
|
39
|
+
createWorkflowsConfigDefinition,
|
|
40
|
+
discoverPluginModulePaths,
|
|
41
|
+
loadAgentPluginFromPath,
|
|
42
|
+
loadAgentPluginsFromPaths,
|
|
43
|
+
parseAgentConfigFromYaml,
|
|
44
|
+
parsePartialAgentConfigFromYaml,
|
|
45
|
+
parseRuleConfigFromMarkdown,
|
|
46
|
+
parseSkillConfigFromMarkdown,
|
|
47
|
+
parseWorkflowConfigFromMarkdown,
|
|
48
|
+
RULES_CONFIG_DIRECTORY_NAME,
|
|
49
|
+
resolveAgentPluginPaths,
|
|
50
|
+
resolveAgentTools,
|
|
51
|
+
resolveAndLoadAgentPlugins,
|
|
52
|
+
resolveDocumentsRulesDirectoryPath,
|
|
53
|
+
resolveDocumentsWorkflowsDirectoryPath,
|
|
54
|
+
resolvePluginConfigSearchPaths,
|
|
55
|
+
resolveRulesConfigSearchPaths,
|
|
56
|
+
resolveSkillsConfigSearchPaths,
|
|
57
|
+
resolveWorkflowsConfigSearchPaths,
|
|
58
|
+
SKILLS_CONFIG_DIRECTORY_NAME,
|
|
59
|
+
toPartialAgentConfig,
|
|
60
|
+
UnifiedConfigFileWatcher,
|
|
61
|
+
WORKFLOWS_CONFIG_DIRECTORY_NAME,
|
|
62
|
+
} from "./agents";
|
|
63
|
+
export type {
|
|
64
|
+
ChatMessage,
|
|
65
|
+
ChatSessionConfig,
|
|
66
|
+
ChatSessionStatus,
|
|
67
|
+
ChatSummary,
|
|
68
|
+
ChatViewState,
|
|
69
|
+
} from "./chat/chat-schema";
|
|
70
|
+
export type {
|
|
71
|
+
SandboxCallOptions,
|
|
72
|
+
SubprocessSandboxOptions,
|
|
73
|
+
} from "./runtime/sandbox/subprocess-sandbox";
|
|
74
|
+
export { SubprocessSandbox } from "./runtime/sandbox/subprocess-sandbox";
|
|
75
|
+
export type {
|
|
76
|
+
BuiltRuntime as RuntimeEnvironment,
|
|
77
|
+
RuntimeBuilder,
|
|
78
|
+
RuntimeBuilderInput,
|
|
79
|
+
SessionRuntime,
|
|
80
|
+
} from "./runtime/session-runtime";
|
|
81
|
+
export type {
|
|
82
|
+
CreateSessionHostOptions,
|
|
83
|
+
SessionHost,
|
|
84
|
+
} from "./session/session-host";
|
|
85
|
+
export type {
|
|
86
|
+
SendSessionInput,
|
|
87
|
+
SessionManager,
|
|
88
|
+
StartSessionInput,
|
|
89
|
+
StartSessionResult,
|
|
90
|
+
} from "./session/session-manager";
|
|
91
|
+
export type { SessionManifest } from "./session/session-manifest";
|
|
92
|
+
export type {
|
|
93
|
+
CreateRootSessionWithArtifactsInput,
|
|
94
|
+
RootSessionArtifacts,
|
|
95
|
+
} from "./session/session-service";
|
|
96
|
+
export type {
|
|
97
|
+
WorkspaceManager,
|
|
98
|
+
WorkspaceManagerEvent,
|
|
99
|
+
} from "./session/workspace-manager";
|
|
100
|
+
export type { WorkspaceManifest } from "./session/workspace-manifest";
|
|
101
|
+
export type { SessionSource, SessionStatus } from "./types/common";
|
|
102
|
+
export type {
|
|
103
|
+
CoreAgentMode,
|
|
104
|
+
CoreModelConfig,
|
|
105
|
+
CoreRuntimeFeatures,
|
|
106
|
+
CoreSessionConfig,
|
|
107
|
+
} from "./types/config";
|
|
108
|
+
export type {
|
|
109
|
+
CoreSessionEvent,
|
|
110
|
+
SessionChunkEvent,
|
|
111
|
+
SessionEndedEvent,
|
|
112
|
+
SessionTeamProgressEvent,
|
|
113
|
+
SessionToolEvent,
|
|
114
|
+
} from "./types/events";
|
|
115
|
+
export type { SessionRecord, SessionRef } from "./types/sessions";
|
|
116
|
+
export type { ArtifactStore, SessionStore, TeamStore } from "./types/storage";
|
|
117
|
+
export type { WorkspaceInfo } from "./types/workspace";
|
|
118
|
+
|
|
119
|
+
// Backward-compat alias used by CLI persistence.
|
|
120
|
+
export interface StoredMessages {
|
|
121
|
+
version: 1;
|
|
122
|
+
updatedAt: string;
|
|
123
|
+
messages: LlmsProviders.MessageWithMetadata[];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Backward-compat alias with previous event naming.
|
|
127
|
+
export type SessionEvent = CoreSessionEvent;
|