@clinebot/core 0.0.20 → 0.0.22
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/dist/account/cline-account-service.d.ts +3 -2
- package/dist/account/cline-account-service.d.ts.map +1 -0
- package/dist/account/index.d.ts +1 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/rpc.d.ts +1 -0
- package/dist/account/rpc.d.ts.map +1 -0
- package/dist/account/types.d.ts +1 -0
- package/dist/account/types.d.ts.map +1 -0
- package/dist/agents/agent-config-loader.d.ts +1 -0
- package/dist/agents/agent-config-loader.d.ts.map +1 -0
- package/dist/agents/agent-config-parser.d.ts +1 -0
- package/dist/agents/agent-config-parser.d.ts.map +1 -0
- package/dist/agents/hooks-config-loader.d.ts +1 -0
- package/dist/agents/hooks-config-loader.d.ts.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/plugin-config-loader.d.ts +1 -0
- package/dist/agents/plugin-config-loader.d.ts.map +1 -0
- package/dist/agents/plugin-loader.d.ts +1 -0
- package/dist/agents/plugin-loader.d.ts.map +1 -0
- package/dist/agents/plugin-sandbox.d.ts +1 -0
- package/dist/agents/plugin-sandbox.d.ts.map +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +1 -0
- package/dist/auth/cline.d.ts.map +1 -0
- package/dist/auth/codex.d.ts +1 -0
- package/dist/auth/codex.d.ts.map +1 -0
- package/dist/auth/oca.d.ts +1 -0
- package/dist/auth/oca.d.ts.map +1 -0
- package/dist/auth/server.d.ts +1 -0
- package/dist/auth/server.d.ts.map +1 -0
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/chat/chat-schema.d.ts +13 -12
- package/dist/chat/chat-schema.d.ts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +303 -302
- package/dist/input/file-indexer.d.ts +1 -0
- package/dist/input/file-indexer.d.ts.map +1 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/mention-enricher.d.ts +1 -0
- package/dist/input/mention-enricher.d.ts.map +1 -0
- package/dist/mcp/config-loader.d.ts +1 -0
- package/dist/mcp/config-loader.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/manager.d.ts +1 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/providers/local-provider-registry.d.ts +36 -0
- package/dist/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +2 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -0
- package/dist/runtime/commands.d.ts +1 -0
- package/dist/runtime/commands.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -0
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -0
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +2 -0
- package/dist/runtime/session-runtime.d.ts.map +1 -0
- package/dist/runtime/skills.d.ts +1 -0
- package/dist/runtime/skills.d.ts.map +1 -0
- package/dist/runtime/tool-approval.d.ts +1 -0
- package/dist/runtime/tool-approval.d.ts.map +1 -0
- package/dist/runtime/workflows.d.ts +1 -0
- package/dist/runtime/workflows.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +4 -0
- package/dist/session/default-session-manager.d.ts.map +1 -0
- package/dist/session/file-session-service.d.ts +1 -0
- package/dist/session/file-session-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -0
- package/dist/session/rpc-session-service.d.ts.map +1 -0
- package/dist/session/rpc-spawn-lease.d.ts +1 -0
- package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
- package/dist/session/session-agent-events.d.ts +20 -1
- package/dist/session/session-agent-events.d.ts.map +1 -0
- package/dist/session/session-artifacts.d.ts +1 -0
- package/dist/session/session-artifacts.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +1 -0
- package/dist/session/session-config-builder.d.ts.map +1 -0
- package/dist/session/session-graph.d.ts +1 -0
- package/dist/session/session-graph.d.ts.map +1 -0
- package/dist/session/session-host.d.ts +1 -0
- package/dist/session/session-host.d.ts.map +1 -0
- package/dist/session/session-manager.d.ts +1 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +2 -1
- package/dist/session/session-manifest.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +1 -0
- package/dist/session/session-service.d.ts.map +1 -0
- package/dist/session/session-team-coordination.d.ts +1 -0
- package/dist/session/session-team-coordination.d.ts.map +1 -0
- package/dist/session/session-telemetry.d.ts +3 -1
- package/dist/session/session-telemetry.d.ts.map +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
- package/dist/session/unified-session-persistence-service.d.ts +1 -0
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
- package/dist/session/utils/helpers.d.ts +1 -0
- package/dist/session/utils/helpers.d.ts.map +1 -0
- package/dist/session/utils/types.d.ts +1 -0
- package/dist/session/utils/types.d.ts.map +1 -0
- package/dist/session/utils/usage.d.ts +1 -0
- package/dist/session/utils/usage.d.ts.map +1 -0
- package/dist/session/workspace-manager.d.ts +1 -0
- package/dist/session/workspace-manager.d.ts.map +1 -0
- package/dist/session/workspace-manifest.d.ts +1 -0
- package/dist/session/workspace-manifest.d.ts.map +1 -0
- package/dist/storage/file-team-store.d.ts +1 -0
- package/dist/storage/file-team-store.d.ts.map +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
- package/dist/storage/provider-settings-manager.d.ts +1 -0
- package/dist/storage/provider-settings-manager.d.ts.map +1 -0
- package/dist/storage/sqlite-session-store.d.ts +1 -0
- package/dist/storage/sqlite-session-store.d.ts.map +1 -0
- package/dist/storage/sqlite-team-store.d.ts +1 -0
- package/dist/storage/sqlite-team-store.d.ts.map +1 -0
- package/dist/storage/team-store.d.ts +1 -0
- package/dist/storage/team-store.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/projections.d.ts +1 -0
- package/dist/team/projections.d.ts.map +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -0
- package/dist/telemetry/core-events.d.ts +55 -22
- package/dist/telemetry/core-events.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +1 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/tools/constants.d.ts +1 -0
- package/dist/tools/constants.d.ts.map +1 -0
- package/dist/tools/definitions.d.ts +8 -1
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch.d.ts +1 -0
- package/dist/tools/executors/apply-patch.d.ts.map +1 -0
- package/dist/tools/executors/bash.d.ts +2 -1
- package/dist/tools/executors/bash.d.ts.map +1 -0
- package/dist/tools/executors/editor.d.ts +1 -0
- package/dist/tools/executors/editor.d.ts.map +1 -0
- package/dist/tools/executors/file-read.d.ts +1 -0
- package/dist/tools/executors/file-read.d.ts.map +1 -0
- package/dist/tools/executors/index.d.ts +14 -7
- package/dist/tools/executors/index.d.ts.map +1 -0
- package/dist/tools/executors/search.d.ts +1 -0
- package/dist/tools/executors/search.d.ts.map +1 -0
- package/dist/tools/executors/web-fetch.d.ts +1 -0
- package/dist/tools/executors/web-fetch.d.ts.map +1 -0
- package/dist/tools/helpers.d.ts +15 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/model-tool-routing.d.ts +1 -0
- package/dist/tools/model-tool-routing.d.ts.map +1 -0
- package/dist/tools/presets.d.ts +1 -0
- package/dist/tools/presets.d.ts.map +1 -0
- package/dist/tools/schemas.d.ts +41 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/types.d.ts +3 -2
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/provider-settings.d.ts +1 -0
- package/dist/types/provider-settings.d.ts.map +1 -0
- package/dist/types/sessions.d.ts +1 -0
- package/dist/types/sessions.d.ts.map +1 -0
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/workspace.d.ts +1 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/account/cline-account-service.test.ts +0 -101
- package/src/account/cline-account-service.ts +0 -287
- package/src/account/index.ts +0 -22
- package/src/account/rpc.test.ts +0 -62
- package/src/account/rpc.ts +0 -172
- package/src/account/types.ts +0 -98
- package/src/agents/agent-config-loader.test.ts +0 -236
- package/src/agents/agent-config-loader.ts +0 -108
- package/src/agents/agent-config-parser.ts +0 -198
- package/src/agents/hooks-config-loader.test.ts +0 -20
- package/src/agents/hooks-config-loader.ts +0 -118
- package/src/agents/index.ts +0 -85
- package/src/agents/plugin-config-loader.test.ts +0 -140
- package/src/agents/plugin-config-loader.ts +0 -97
- package/src/agents/plugin-loader.test.ts +0 -228
- package/src/agents/plugin-loader.ts +0 -172
- package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
- package/src/agents/plugin-sandbox.test.ts +0 -317
- package/src/agents/plugin-sandbox.ts +0 -341
- package/src/agents/unified-config-file-watcher.test.ts +0 -196
- package/src/agents/unified-config-file-watcher.ts +0 -483
- package/src/agents/user-instruction-config-loader.test.ts +0 -158
- package/src/agents/user-instruction-config-loader.ts +0 -438
- package/src/auth/client.test.ts +0 -40
- package/src/auth/client.ts +0 -25
- package/src/auth/cline.test.ts +0 -130
- package/src/auth/cline.ts +0 -420
- package/src/auth/codex.test.ts +0 -170
- package/src/auth/codex.ts +0 -491
- package/src/auth/oca.test.ts +0 -215
- package/src/auth/oca.ts +0 -573
- package/src/auth/server.ts +0 -216
- package/src/auth/types.ts +0 -81
- package/src/auth/utils.test.ts +0 -128
- package/src/auth/utils.ts +0 -247
- package/src/chat/chat-schema.ts +0 -82
- package/src/index.node.ts +0 -285
- package/src/index.ts +0 -211
- package/src/input/file-indexer.d.ts +0 -11
- package/src/input/file-indexer.test.ts +0 -127
- package/src/input/file-indexer.ts +0 -327
- package/src/input/index.ts +0 -7
- package/src/input/mention-enricher.test.ts +0 -85
- package/src/input/mention-enricher.ts +0 -122
- package/src/mcp/config-loader.test.ts +0 -238
- package/src/mcp/config-loader.ts +0 -219
- package/src/mcp/index.ts +0 -26
- package/src/mcp/manager.test.ts +0 -106
- package/src/mcp/manager.ts +0 -262
- package/src/mcp/types.ts +0 -88
- package/src/providers/local-provider-service.ts +0 -608
- package/src/runtime/commands.test.ts +0 -98
- package/src/runtime/commands.ts +0 -83
- package/src/runtime/hook-file-hooks.test.ts +0 -237
- package/src/runtime/hook-file-hooks.ts +0 -859
- package/src/runtime/index.ts +0 -37
- package/src/runtime/rules.ts +0 -34
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
- package/src/runtime/runtime-builder.test.ts +0 -371
- package/src/runtime/runtime-builder.ts +0 -589
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
- package/src/runtime/session-runtime.ts +0 -46
- package/src/runtime/skills.ts +0 -44
- package/src/runtime/tool-approval.ts +0 -104
- package/src/runtime/workflows.test.ts +0 -119
- package/src/runtime/workflows.ts +0 -45
- package/src/session/default-session-manager.e2e.test.ts +0 -384
- package/src/session/default-session-manager.test.ts +0 -1741
- package/src/session/default-session-manager.ts +0 -1233
- package/src/session/file-session-service.ts +0 -280
- package/src/session/index.ts +0 -42
- package/src/session/rpc-session-service.ts +0 -107
- package/src/session/rpc-spawn-lease.test.ts +0 -49
- package/src/session/rpc-spawn-lease.ts +0 -122
- package/src/session/runtime-oauth-token-manager.test.ts +0 -137
- package/src/session/runtime-oauth-token-manager.ts +0 -272
- package/src/session/session-agent-events.ts +0 -159
- package/src/session/session-artifacts.ts +0 -106
- package/src/session/session-config-builder.ts +0 -113
- package/src/session/session-graph.ts +0 -92
- package/src/session/session-host.test.ts +0 -29
- package/src/session/session-host.ts +0 -242
- package/src/session/session-manager.ts +0 -69
- package/src/session/session-manifest.ts +0 -29
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/session-service.ts +0 -673
- package/src/session/session-team-coordination.ts +0 -229
- package/src/session/session-telemetry.ts +0 -95
- package/src/session/sqlite-rpc-session-backend.ts +0 -303
- package/src/session/unified-session-persistence-service.test.ts +0 -85
- package/src/session/unified-session-persistence-service.ts +0 -996
- package/src/session/utils/helpers.ts +0 -139
- package/src/session/utils/types.ts +0 -57
- package/src/session/utils/usage.ts +0 -32
- package/src/session/workspace-manager.ts +0 -98
- package/src/session/workspace-manifest.ts +0 -100
- package/src/storage/artifact-store.ts +0 -1
- package/src/storage/file-team-store.ts +0 -257
- package/src/storage/index.ts +0 -11
- package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
- package/src/storage/provider-settings-legacy-migration.ts +0 -689
- package/src/storage/provider-settings-manager.test.ts +0 -145
- package/src/storage/provider-settings-manager.ts +0 -150
- package/src/storage/session-store.ts +0 -1
- package/src/storage/sqlite-session-store.ts +0 -275
- package/src/storage/sqlite-team-store.ts +0 -454
- package/src/storage/team-store.ts +0 -40
- package/src/team/index.ts +0 -4
- package/src/team/projections.ts +0 -285
- package/src/telemetry/ITelemetryAdapter.ts +0 -94
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
- package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
- package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
- package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
- package/src/telemetry/OpenTelemetryProvider.ts +0 -322
- package/src/telemetry/TelemetryService.test.ts +0 -134
- package/src/telemetry/TelemetryService.ts +0 -141
- package/src/telemetry/core-events.ts +0 -344
- package/src/telemetry/opentelemetry.ts +0 -20
- package/src/tools/constants.ts +0 -35
- package/src/tools/definitions.test.ts +0 -658
- package/src/tools/definitions.ts +0 -726
- package/src/tools/executors/apply-patch-parser.ts +0 -520
- package/src/tools/executors/apply-patch.ts +0 -359
- package/src/tools/executors/bash.ts +0 -205
- package/src/tools/executors/editor.test.ts +0 -35
- package/src/tools/executors/editor.ts +0 -219
- package/src/tools/executors/file-read.test.ts +0 -49
- package/src/tools/executors/file-read.ts +0 -110
- package/src/tools/executors/index.ts +0 -75
- package/src/tools/executors/search.ts +0 -278
- package/src/tools/executors/web-fetch.ts +0 -259
- package/src/tools/index.ts +0 -168
- package/src/tools/model-tool-routing.test.ts +0 -86
- package/src/tools/model-tool-routing.ts +0 -132
- package/src/tools/presets.test.ts +0 -62
- package/src/tools/presets.ts +0 -168
- package/src/tools/schemas.ts +0 -284
- package/src/tools/types.ts +0 -328
- package/src/types/common.ts +0 -14
- package/src/types/config.ts +0 -84
- package/src/types/events.ts +0 -74
- package/src/types/index.ts +0 -24
- package/src/types/provider-settings.ts +0 -43
- package/src/types/sessions.ts +0 -16
- package/src/types/storage.ts +0 -64
- package/src/types/workspace.ts +0 -7
- package/src/types.ts +0 -128
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import type { AgentResult, TeamEvent } from "@clinebot/agents";
|
|
2
|
-
import { formatUserInputBlock } from "@clinebot/shared";
|
|
3
|
-
import {
|
|
4
|
-
buildTeamProgressSummary,
|
|
5
|
-
toTeamProgressLifecycleEvent,
|
|
6
|
-
} from "../team";
|
|
7
|
-
import type { CoreSessionEvent } from "../types/events";
|
|
8
|
-
import type { ActiveSession, TeamRunUpdate } from "./utils/types";
|
|
9
|
-
|
|
10
|
-
export function trackTeamRunState(
|
|
11
|
-
session: ActiveSession,
|
|
12
|
-
event: TeamEvent,
|
|
13
|
-
): void {
|
|
14
|
-
switch (event.type) {
|
|
15
|
-
case "run_queued":
|
|
16
|
-
case "run_started":
|
|
17
|
-
session.activeTeamRunIds.add(event.run.id);
|
|
18
|
-
break;
|
|
19
|
-
case "run_completed":
|
|
20
|
-
case "run_failed":
|
|
21
|
-
case "run_cancelled":
|
|
22
|
-
case "run_interrupted": {
|
|
23
|
-
let runError: string | undefined;
|
|
24
|
-
if (event.type === "run_failed") {
|
|
25
|
-
runError = event.run.error;
|
|
26
|
-
} else if (
|
|
27
|
-
event.type === "run_cancelled" ||
|
|
28
|
-
event.type === "run_interrupted"
|
|
29
|
-
) {
|
|
30
|
-
runError = event.run.error ?? event.reason;
|
|
31
|
-
}
|
|
32
|
-
session.activeTeamRunIds.delete(event.run.id);
|
|
33
|
-
session.pendingTeamRunUpdates.push({
|
|
34
|
-
runId: event.run.id,
|
|
35
|
-
agentId: event.run.agentId,
|
|
36
|
-
taskId: event.run.taskId,
|
|
37
|
-
status: event.type.replace("run_", "") as TeamRunUpdate["status"],
|
|
38
|
-
error: runError,
|
|
39
|
-
iterations: event.run.result?.iterations,
|
|
40
|
-
});
|
|
41
|
-
notifyTeamRunWaiters(session);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
default:
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function dispatchTeamEventToBackend(
|
|
50
|
-
rootSessionId: string,
|
|
51
|
-
event: TeamEvent,
|
|
52
|
-
invokeOptional: (method: string, ...args: unknown[]) => Promise<void>,
|
|
53
|
-
): Promise<void> {
|
|
54
|
-
switch (event.type) {
|
|
55
|
-
case "run_progress":
|
|
56
|
-
await invokeOptional(
|
|
57
|
-
"onTeamTaskProgress",
|
|
58
|
-
rootSessionId,
|
|
59
|
-
event.run.agentId,
|
|
60
|
-
event.message,
|
|
61
|
-
{ kind: event.message === "heartbeat" ? "heartbeat" : "progress" },
|
|
62
|
-
);
|
|
63
|
-
break;
|
|
64
|
-
case "agent_event":
|
|
65
|
-
if (
|
|
66
|
-
event.event.type === "content_start" &&
|
|
67
|
-
event.event.contentType === "text" &&
|
|
68
|
-
typeof event.event.text === "string"
|
|
69
|
-
) {
|
|
70
|
-
const snippet = event.event.text
|
|
71
|
-
.replace(/\s+/g, " ")
|
|
72
|
-
.trim()
|
|
73
|
-
.slice(0, 120);
|
|
74
|
-
if (snippet) {
|
|
75
|
-
await invokeOptional(
|
|
76
|
-
"onTeamTaskProgress",
|
|
77
|
-
rootSessionId,
|
|
78
|
-
event.agentId,
|
|
79
|
-
snippet,
|
|
80
|
-
{ kind: "text" },
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
case "task_start":
|
|
86
|
-
await invokeOptional(
|
|
87
|
-
"onTeamTaskStart",
|
|
88
|
-
rootSessionId,
|
|
89
|
-
event.agentId,
|
|
90
|
-
event.message,
|
|
91
|
-
);
|
|
92
|
-
break;
|
|
93
|
-
case "task_end": {
|
|
94
|
-
if (event.error) {
|
|
95
|
-
await invokeOptional(
|
|
96
|
-
"onTeamTaskEnd",
|
|
97
|
-
rootSessionId,
|
|
98
|
-
event.agentId,
|
|
99
|
-
"failed",
|
|
100
|
-
`[error] ${event.error.message}`,
|
|
101
|
-
event.messages,
|
|
102
|
-
);
|
|
103
|
-
} else if (event.result?.finishReason === "aborted") {
|
|
104
|
-
await invokeOptional(
|
|
105
|
-
"onTeamTaskEnd",
|
|
106
|
-
rootSessionId,
|
|
107
|
-
event.agentId,
|
|
108
|
-
"cancelled",
|
|
109
|
-
"[done] aborted",
|
|
110
|
-
event.result.messages,
|
|
111
|
-
);
|
|
112
|
-
} else {
|
|
113
|
-
await invokeOptional(
|
|
114
|
-
"onTeamTaskEnd",
|
|
115
|
-
rootSessionId,
|
|
116
|
-
event.agentId,
|
|
117
|
-
"completed",
|
|
118
|
-
`[done] ${event.result?.finishReason ?? "completed"}`,
|
|
119
|
-
event.result?.messages,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
default:
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function emitTeamProgress(
|
|
130
|
-
session: ActiveSession,
|
|
131
|
-
rootSessionId: string,
|
|
132
|
-
event: TeamEvent,
|
|
133
|
-
emit: (event: CoreSessionEvent) => void,
|
|
134
|
-
): void {
|
|
135
|
-
if (!session.runtime.teamRuntime) return;
|
|
136
|
-
const teamName = session.config.teamName?.trim() || "team";
|
|
137
|
-
emit({
|
|
138
|
-
type: "team_progress",
|
|
139
|
-
payload: {
|
|
140
|
-
sessionId: rootSessionId,
|
|
141
|
-
teamName,
|
|
142
|
-
lifecycle: toTeamProgressLifecycleEvent({
|
|
143
|
-
teamName,
|
|
144
|
-
sessionId: rootSessionId,
|
|
145
|
-
event,
|
|
146
|
-
}),
|
|
147
|
-
summary: buildTeamProgressSummary(
|
|
148
|
-
teamName,
|
|
149
|
-
session.runtime.teamRuntime.exportState(),
|
|
150
|
-
),
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function hasPendingTeamRunWork(session: ActiveSession): boolean {
|
|
156
|
-
return (
|
|
157
|
-
session.activeTeamRunIds.size > 0 ||
|
|
158
|
-
session.pendingTeamRunUpdates.length > 0
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function shouldAutoContinueTeamRuns(
|
|
163
|
-
session: ActiveSession,
|
|
164
|
-
finishReason: AgentResult["finishReason"],
|
|
165
|
-
): boolean {
|
|
166
|
-
if (session.aborting) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
const canAutoContinue =
|
|
170
|
-
finishReason === "completed" || finishReason === "max_iterations";
|
|
171
|
-
if (!canAutoContinue) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
return (
|
|
175
|
-
session.config.enableAgentTeams === true && hasPendingTeamRunWork(session)
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function notifyTeamRunWaiters(session: ActiveSession): void {
|
|
180
|
-
const waiters = session.teamRunWaiters.splice(0);
|
|
181
|
-
for (const resolve of waiters) resolve();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export async function waitForTeamRunUpdates(
|
|
185
|
-
session: ActiveSession,
|
|
186
|
-
): Promise<TeamRunUpdate[]> {
|
|
187
|
-
while (true) {
|
|
188
|
-
if (session.aborting) return [];
|
|
189
|
-
if (session.pendingTeamRunUpdates.length > 0) {
|
|
190
|
-
const updates = [...session.pendingTeamRunUpdates];
|
|
191
|
-
session.pendingTeamRunUpdates.length = 0;
|
|
192
|
-
return updates;
|
|
193
|
-
}
|
|
194
|
-
if (session.activeTeamRunIds.size === 0) return [];
|
|
195
|
-
await new Promise<void>((resolve) => {
|
|
196
|
-
session.teamRunWaiters.push(resolve);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function buildTeamRunContinuationPrompt(
|
|
202
|
-
session: ActiveSession,
|
|
203
|
-
updates: TeamRunUpdate[],
|
|
204
|
-
): string {
|
|
205
|
-
const lines = updates.map((u) => {
|
|
206
|
-
const parts = [`- ${u.runId} (${u.agentId}) -> ${u.status}`];
|
|
207
|
-
if (u.taskId) parts.push(` task=${u.taskId}`);
|
|
208
|
-
if (typeof u.iterations === "number")
|
|
209
|
-
parts.push(` iterations=${u.iterations}`);
|
|
210
|
-
if (u.error) parts.push(` error=${u.error}`);
|
|
211
|
-
return parts.join("");
|
|
212
|
-
});
|
|
213
|
-
const remaining = session.activeTeamRunIds.size;
|
|
214
|
-
const instruction =
|
|
215
|
-
remaining > 0
|
|
216
|
-
? `There are still ${remaining} teammate run(s) in progress. Continue coordination and decide whether to wait for more updates.`
|
|
217
|
-
: "No teammate runs are currently in progress. Continue coordination using these updates.";
|
|
218
|
-
return formatModePrompt(
|
|
219
|
-
`System-delivered teammate async run updates:\n${lines.join("\n")}\n\n${instruction}`,
|
|
220
|
-
session.config.mode,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export function formatModePrompt(
|
|
225
|
-
prompt: string,
|
|
226
|
-
mode: "act" | "plan" | undefined,
|
|
227
|
-
): string {
|
|
228
|
-
return formatUserInputBlock(prompt, mode === "plan" ? "plan" : "act");
|
|
229
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { ITelemetryService } from "@clinebot/shared";
|
|
2
|
-
import {
|
|
3
|
-
listHookConfigFiles,
|
|
4
|
-
resolveDocumentsHooksDirectoryPath,
|
|
5
|
-
} from "../agents/hooks-config-loader";
|
|
6
|
-
import type { enrichPromptWithMentions } from "../input";
|
|
7
|
-
import {
|
|
8
|
-
captureHookDiscovery,
|
|
9
|
-
captureMentionFailed,
|
|
10
|
-
captureMentionSearchResults,
|
|
11
|
-
captureMentionUsed,
|
|
12
|
-
captureTaskCreated,
|
|
13
|
-
captureTaskRestarted,
|
|
14
|
-
} from "../telemetry/core-events";
|
|
15
|
-
import type { SessionSource } from "../types/common";
|
|
16
|
-
import type { CoreSessionConfig } from "../types/config";
|
|
17
|
-
|
|
18
|
-
export function emitSessionCreationTelemetry(
|
|
19
|
-
config: CoreSessionConfig,
|
|
20
|
-
sessionId: string,
|
|
21
|
-
source: SessionSource,
|
|
22
|
-
isRestart: boolean,
|
|
23
|
-
workspacePath: string,
|
|
24
|
-
): void {
|
|
25
|
-
if (isRestart) {
|
|
26
|
-
captureTaskRestarted(config.telemetry, {
|
|
27
|
-
ulid: sessionId,
|
|
28
|
-
apiProvider: config.providerId,
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
captureTaskCreated(config.telemetry, {
|
|
32
|
-
ulid: sessionId,
|
|
33
|
-
apiProvider: config.providerId,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
captureHookDiscoveryTelemetry(config.telemetry, { workspacePath });
|
|
37
|
-
config.telemetry?.capture({
|
|
38
|
-
event: "session.started",
|
|
39
|
-
properties: {
|
|
40
|
-
sessionId,
|
|
41
|
-
source,
|
|
42
|
-
providerId: config.providerId,
|
|
43
|
-
modelId: config.modelId,
|
|
44
|
-
enableTools: config.enableTools,
|
|
45
|
-
enableSpawnAgent: config.enableSpawnAgent,
|
|
46
|
-
enableAgentTeams: config.enableAgentTeams,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function captureHookDiscoveryTelemetry(
|
|
52
|
-
telemetry: ITelemetryService | undefined,
|
|
53
|
-
options: { workspacePath: string },
|
|
54
|
-
): void {
|
|
55
|
-
const globalHooksDir = resolveDocumentsHooksDirectoryPath();
|
|
56
|
-
const entries = listHookConfigFiles(options.workspacePath);
|
|
57
|
-
const counts = new Map<string, { global: number; workspace: number }>();
|
|
58
|
-
for (const entry of entries) {
|
|
59
|
-
const hookName = entry.hookEventName ?? "unknown";
|
|
60
|
-
const current = counts.get(hookName) ?? { global: 0, workspace: 0 };
|
|
61
|
-
if (
|
|
62
|
-
entry.path === globalHooksDir ||
|
|
63
|
-
entry.path.startsWith(`${globalHooksDir}/`)
|
|
64
|
-
) {
|
|
65
|
-
current.global += 1;
|
|
66
|
-
} else {
|
|
67
|
-
current.workspace += 1;
|
|
68
|
-
}
|
|
69
|
-
counts.set(hookName, current);
|
|
70
|
-
}
|
|
71
|
-
for (const [hookName, count] of counts.entries()) {
|
|
72
|
-
captureHookDiscovery(telemetry, hookName, count.global, count.workspace);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function emitMentionTelemetry(
|
|
77
|
-
telemetry: ITelemetryService | undefined,
|
|
78
|
-
enriched: Awaited<ReturnType<typeof enrichPromptWithMentions>>,
|
|
79
|
-
): void {
|
|
80
|
-
for (const mention of enriched.mentions) {
|
|
81
|
-
captureMentionSearchResults(
|
|
82
|
-
telemetry,
|
|
83
|
-
mention,
|
|
84
|
-
enriched.matchedFiles.includes(mention) ? 1 : 0,
|
|
85
|
-
"file",
|
|
86
|
-
!enriched.matchedFiles.includes(mention),
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
for (const matched of enriched.matchedFiles) {
|
|
90
|
-
captureMentionUsed(telemetry, "file", matched.length);
|
|
91
|
-
}
|
|
92
|
-
for (const ignored of enriched.ignoredMentions) {
|
|
93
|
-
captureMentionFailed(telemetry, "file", "not_found", ignored);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RpcSessionBackend,
|
|
3
|
-
RpcSessionRow,
|
|
4
|
-
RpcSessionStatus,
|
|
5
|
-
RpcSessionUpdateInput,
|
|
6
|
-
RpcSpawnQueueItem,
|
|
7
|
-
} from "@clinebot/rpc";
|
|
8
|
-
import {
|
|
9
|
-
asBool,
|
|
10
|
-
asOptionalString,
|
|
11
|
-
asString,
|
|
12
|
-
nowIso,
|
|
13
|
-
toBoolInt,
|
|
14
|
-
} from "@clinebot/shared/db";
|
|
15
|
-
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
16
|
-
|
|
17
|
-
export interface SqliteRpcSessionBackendOptions {
|
|
18
|
-
sessionsDir?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class SqliteRpcSessionBackend implements RpcSessionBackend {
|
|
22
|
-
private readonly store: SqliteSessionStore;
|
|
23
|
-
|
|
24
|
-
constructor(options: SqliteRpcSessionBackendOptions = {}) {
|
|
25
|
-
this.store = new SqliteSessionStore({ sessionsDir: options.sessionsDir });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public init(): void {
|
|
29
|
-
this.store.init();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public upsertSession(row: RpcSessionRow): void {
|
|
33
|
-
this.store.run(
|
|
34
|
-
`INSERT OR REPLACE INTO sessions (
|
|
35
|
-
session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
|
|
36
|
-
provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
|
|
37
|
-
parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
|
|
38
|
-
metadata_json, transcript_path, hook_path, messages_path, updated_at
|
|
39
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
40
|
-
[
|
|
41
|
-
row.sessionId,
|
|
42
|
-
row.source,
|
|
43
|
-
row.pid,
|
|
44
|
-
row.startedAt,
|
|
45
|
-
row.endedAt ?? null,
|
|
46
|
-
row.exitCode ?? null,
|
|
47
|
-
row.status,
|
|
48
|
-
row.statusLock,
|
|
49
|
-
toBoolInt(row.interactive),
|
|
50
|
-
row.provider,
|
|
51
|
-
row.model,
|
|
52
|
-
row.cwd,
|
|
53
|
-
row.workspaceRoot,
|
|
54
|
-
row.teamName ?? null,
|
|
55
|
-
toBoolInt(row.enableTools),
|
|
56
|
-
toBoolInt(row.enableSpawn),
|
|
57
|
-
toBoolInt(row.enableTeams),
|
|
58
|
-
row.parentSessionId ?? null,
|
|
59
|
-
row.parentAgentId ?? null,
|
|
60
|
-
row.agentId ?? null,
|
|
61
|
-
row.conversationId ?? null,
|
|
62
|
-
toBoolInt(row.isSubagent),
|
|
63
|
-
row.prompt ?? null,
|
|
64
|
-
row.metadata ? JSON.stringify(row.metadata) : null,
|
|
65
|
-
row.transcriptPath,
|
|
66
|
-
row.hookPath,
|
|
67
|
-
row.messagesPath ?? null,
|
|
68
|
-
row.updatedAt || nowIso(),
|
|
69
|
-
],
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public getSession(sessionId: string): RpcSessionRow | undefined {
|
|
74
|
-
const row = this.store.queryOne<Record<string, unknown>>(
|
|
75
|
-
`SELECT session_id, source, pid, started_at, ended_at, exit_code, status, status_lock, interactive,
|
|
76
|
-
provider, model, cwd, workspace_root, team_name, enable_tools, enable_spawn, enable_teams,
|
|
77
|
-
parent_session_id, parent_agent_id, agent_id, conversation_id, is_subagent, prompt,
|
|
78
|
-
metadata_json, transcript_path, hook_path, messages_path, updated_at
|
|
79
|
-
FROM sessions WHERE session_id = ?`,
|
|
80
|
-
[sessionId],
|
|
81
|
-
);
|
|
82
|
-
if (!row) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
sessionId: asString(row.session_id),
|
|
87
|
-
source: asString(row.source),
|
|
88
|
-
pid: Number(row.pid ?? 0),
|
|
89
|
-
startedAt: asString(row.started_at),
|
|
90
|
-
endedAt: (row.ended_at as string | null | undefined) ?? null,
|
|
91
|
-
exitCode: (row.exit_code as number | null | undefined) ?? null,
|
|
92
|
-
status: asString(row.status) as RpcSessionStatus,
|
|
93
|
-
statusLock: Number(row.status_lock ?? 0),
|
|
94
|
-
interactive: asBool(row.interactive),
|
|
95
|
-
provider: asString(row.provider),
|
|
96
|
-
model: asString(row.model),
|
|
97
|
-
cwd: asString(row.cwd),
|
|
98
|
-
workspaceRoot: asString(row.workspace_root),
|
|
99
|
-
teamName: asOptionalString(row.team_name),
|
|
100
|
-
enableTools: asBool(row.enable_tools),
|
|
101
|
-
enableSpawn: asBool(row.enable_spawn),
|
|
102
|
-
enableTeams: asBool(row.enable_teams),
|
|
103
|
-
parentSessionId: asOptionalString(row.parent_session_id),
|
|
104
|
-
parentAgentId: asOptionalString(row.parent_agent_id),
|
|
105
|
-
agentId: asOptionalString(row.agent_id),
|
|
106
|
-
conversationId: asOptionalString(row.conversation_id),
|
|
107
|
-
isSubagent: asBool(row.is_subagent),
|
|
108
|
-
prompt: asOptionalString(row.prompt),
|
|
109
|
-
metadata: (() => {
|
|
110
|
-
const raw = asOptionalString(row.metadata_json);
|
|
111
|
-
if (!raw) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
const parsed = JSON.parse(raw) as unknown;
|
|
116
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
117
|
-
return parsed as Record<string, unknown>;
|
|
118
|
-
}
|
|
119
|
-
} catch {
|
|
120
|
-
// Ignore malformed metadata payloads.
|
|
121
|
-
}
|
|
122
|
-
return undefined;
|
|
123
|
-
})(),
|
|
124
|
-
transcriptPath: asString(row.transcript_path),
|
|
125
|
-
hookPath: asString(row.hook_path),
|
|
126
|
-
messagesPath: asOptionalString(row.messages_path),
|
|
127
|
-
updatedAt: asString(row.updated_at) || nowIso(),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public listSessions(options: {
|
|
132
|
-
limit: number;
|
|
133
|
-
parentSessionId?: string;
|
|
134
|
-
status?: string;
|
|
135
|
-
}): RpcSessionRow[] {
|
|
136
|
-
const where: string[] = [];
|
|
137
|
-
const params: unknown[] = [];
|
|
138
|
-
if (options.parentSessionId) {
|
|
139
|
-
where.push("parent_session_id = ?");
|
|
140
|
-
params.push(options.parentSessionId);
|
|
141
|
-
}
|
|
142
|
-
if (options.status) {
|
|
143
|
-
where.push("status = ?");
|
|
144
|
-
params.push(options.status);
|
|
145
|
-
}
|
|
146
|
-
const whereClause = where.length > 0 ? `WHERE ${where.join(" AND ")}` : "";
|
|
147
|
-
const limit = Math.max(1, Math.floor(options.limit));
|
|
148
|
-
const rows = this.store.queryAll<{ session_id?: string }>(
|
|
149
|
-
`SELECT session_id FROM sessions ${whereClause} ORDER BY started_at DESC LIMIT ?`,
|
|
150
|
-
[...params, limit],
|
|
151
|
-
);
|
|
152
|
-
const out: RpcSessionRow[] = [];
|
|
153
|
-
for (const row of rows) {
|
|
154
|
-
if (!row.session_id) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const item = this.getSession(row.session_id);
|
|
158
|
-
if (item) {
|
|
159
|
-
out.push(item);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return out;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public updateSession(input: RpcSessionUpdateInput): {
|
|
166
|
-
updated: boolean;
|
|
167
|
-
statusLock: number;
|
|
168
|
-
} {
|
|
169
|
-
const existing = this.getSession(input.sessionId);
|
|
170
|
-
if (!existing) {
|
|
171
|
-
return { updated: false, statusLock: 0 };
|
|
172
|
-
}
|
|
173
|
-
if (
|
|
174
|
-
typeof input.expectedStatusLock === "number" &&
|
|
175
|
-
existing.statusLock !== input.expectedStatusLock
|
|
176
|
-
) {
|
|
177
|
-
return { updated: false, statusLock: existing.statusLock };
|
|
178
|
-
}
|
|
179
|
-
const nextLock = existing.statusLock + 1;
|
|
180
|
-
const nextStatus = input.setRunning
|
|
181
|
-
? "running"
|
|
182
|
-
: (input.status ?? existing.status);
|
|
183
|
-
const nextEndedAt =
|
|
184
|
-
input.setRunning === true
|
|
185
|
-
? null
|
|
186
|
-
: input.endedAt !== undefined
|
|
187
|
-
? input.endedAt
|
|
188
|
-
: (existing.endedAt ?? null);
|
|
189
|
-
const nextExitCode =
|
|
190
|
-
input.setRunning === true
|
|
191
|
-
? null
|
|
192
|
-
: input.exitCode !== undefined
|
|
193
|
-
? input.exitCode
|
|
194
|
-
: (existing.exitCode ?? null);
|
|
195
|
-
const nextPrompt =
|
|
196
|
-
input.prompt !== undefined
|
|
197
|
-
? (input.prompt ?? undefined)
|
|
198
|
-
: existing.prompt;
|
|
199
|
-
const nextMetadata =
|
|
200
|
-
input.metadata !== undefined
|
|
201
|
-
? (input.metadata ?? undefined)
|
|
202
|
-
: existing.metadata;
|
|
203
|
-
|
|
204
|
-
this.store.run(
|
|
205
|
-
`UPDATE sessions
|
|
206
|
-
SET status = ?, ended_at = ?, exit_code = ?, prompt = ?, metadata_json = ?,
|
|
207
|
-
parent_session_id = ?, parent_agent_id = ?, agent_id = ?, conversation_id = ?,
|
|
208
|
-
status_lock = ?, updated_at = ?
|
|
209
|
-
WHERE session_id = ?`,
|
|
210
|
-
[
|
|
211
|
-
nextStatus,
|
|
212
|
-
nextEndedAt,
|
|
213
|
-
nextExitCode,
|
|
214
|
-
nextPrompt ?? null,
|
|
215
|
-
nextMetadata ? JSON.stringify(nextMetadata) : null,
|
|
216
|
-
input.parentSessionId !== undefined
|
|
217
|
-
? (input.parentSessionId ?? null)
|
|
218
|
-
: (existing.parentSessionId ?? null),
|
|
219
|
-
input.parentAgentId !== undefined
|
|
220
|
-
? (input.parentAgentId ?? null)
|
|
221
|
-
: (existing.parentAgentId ?? null),
|
|
222
|
-
input.agentId !== undefined
|
|
223
|
-
? (input.agentId ?? null)
|
|
224
|
-
: (existing.agentId ?? null),
|
|
225
|
-
input.conversationId !== undefined
|
|
226
|
-
? (input.conversationId ?? null)
|
|
227
|
-
: (existing.conversationId ?? null),
|
|
228
|
-
nextLock,
|
|
229
|
-
nowIso(),
|
|
230
|
-
input.sessionId,
|
|
231
|
-
],
|
|
232
|
-
);
|
|
233
|
-
return { updated: true, statusLock: nextLock };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public deleteSession(sessionId: string): boolean {
|
|
237
|
-
const changes =
|
|
238
|
-
this.store.run("DELETE FROM sessions WHERE session_id = ?", [sessionId])
|
|
239
|
-
.changes ?? 0;
|
|
240
|
-
return changes > 0;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
public deleteSessionsByParent(parentSessionId: string): void {
|
|
244
|
-
this.store.run("DELETE FROM sessions WHERE parent_session_id = ?", [
|
|
245
|
-
parentSessionId,
|
|
246
|
-
]);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
public enqueueSpawnRequest(input: {
|
|
250
|
-
rootSessionId: string;
|
|
251
|
-
parentAgentId: string;
|
|
252
|
-
task?: string;
|
|
253
|
-
systemPrompt?: string;
|
|
254
|
-
}): void {
|
|
255
|
-
this.store.run(
|
|
256
|
-
`INSERT INTO subagent_spawn_queue (root_session_id, parent_agent_id, task, system_prompt, created_at, consumed_at)
|
|
257
|
-
VALUES (?, ?, ?, ?, ?, NULL)`,
|
|
258
|
-
[
|
|
259
|
-
input.rootSessionId,
|
|
260
|
-
input.parentAgentId,
|
|
261
|
-
input.task ?? null,
|
|
262
|
-
input.systemPrompt ?? null,
|
|
263
|
-
nowIso(),
|
|
264
|
-
],
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public claimSpawnRequest(
|
|
269
|
-
rootSessionId: string,
|
|
270
|
-
parentAgentId: string,
|
|
271
|
-
): RpcSpawnQueueItem | undefined {
|
|
272
|
-
const row = this.store.queryOne<Record<string, unknown>>(
|
|
273
|
-
`SELECT id, root_session_id, parent_agent_id, task, system_prompt, created_at, consumed_at
|
|
274
|
-
FROM subagent_spawn_queue
|
|
275
|
-
WHERE root_session_id = ? AND parent_agent_id = ? AND consumed_at IS NULL
|
|
276
|
-
ORDER BY id ASC LIMIT 1`,
|
|
277
|
-
[rootSessionId, parentAgentId],
|
|
278
|
-
);
|
|
279
|
-
if (!row || typeof row.id !== "number") {
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
|
-
const consumedAt = nowIso();
|
|
283
|
-
this.store.run(
|
|
284
|
-
"UPDATE subagent_spawn_queue SET consumed_at = ? WHERE id = ?",
|
|
285
|
-
[consumedAt, row.id],
|
|
286
|
-
);
|
|
287
|
-
return {
|
|
288
|
-
id: row.id,
|
|
289
|
-
rootSessionId: asString(row.root_session_id),
|
|
290
|
-
parentAgentId: asString(row.parent_agent_id),
|
|
291
|
-
task: asOptionalString(row.task),
|
|
292
|
-
systemPrompt: asOptionalString(row.system_prompt),
|
|
293
|
-
createdAt: asString(row.created_at),
|
|
294
|
-
consumedAt,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function createSqliteRpcSessionBackend(
|
|
300
|
-
options: SqliteRpcSessionBackendOptions = {},
|
|
301
|
-
): RpcSessionBackend {
|
|
302
|
-
return new SqliteRpcSessionBackend(options);
|
|
303
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { SqliteSessionStore } from "../storage/sqlite-session-store";
|
|
6
|
-
import { SessionSource } from "../types/common";
|
|
7
|
-
import { CoreSessionService } from "./session-service";
|
|
8
|
-
|
|
9
|
-
describe("UnifiedSessionPersistenceService", () => {
|
|
10
|
-
const tempDirs: string[] = [];
|
|
11
|
-
const stores: Array<SqliteSessionStore> = [];
|
|
12
|
-
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
for (const store of stores.splice(0)) {
|
|
15
|
-
store.close();
|
|
16
|
-
}
|
|
17
|
-
for (const dir of tempDirs.splice(0)) {
|
|
18
|
-
rmSync(dir, { recursive: true, force: true });
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("reconciles dead running sessions into failed manifests with terminal markers", async () => {
|
|
23
|
-
const sessionsDir = mkdtempSync(join(tmpdir(), "stale-session-reconcile-"));
|
|
24
|
-
tempDirs.push(sessionsDir);
|
|
25
|
-
|
|
26
|
-
const store = new SqliteSessionStore({ sessionsDir });
|
|
27
|
-
stores.push(store);
|
|
28
|
-
const service = new CoreSessionService(store);
|
|
29
|
-
const sessionId = "stale-root-session";
|
|
30
|
-
const artifacts = await service.createRootSessionWithArtifacts({
|
|
31
|
-
sessionId,
|
|
32
|
-
source: SessionSource.CLI,
|
|
33
|
-
pid: 999_999_999,
|
|
34
|
-
interactive: false,
|
|
35
|
-
provider: "mock-provider",
|
|
36
|
-
model: "mock-model",
|
|
37
|
-
cwd: "/tmp/project",
|
|
38
|
-
workspaceRoot: "/tmp/project",
|
|
39
|
-
enableTools: true,
|
|
40
|
-
enableSpawn: true,
|
|
41
|
-
enableTeams: false,
|
|
42
|
-
prompt: "hello",
|
|
43
|
-
startedAt: "2026-01-01T00:00:00.000Z",
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const reconciled = await service.reconcileDeadSessions();
|
|
47
|
-
expect(reconciled).toBe(1);
|
|
48
|
-
|
|
49
|
-
const rows = await service.listSessions(10);
|
|
50
|
-
expect(rows).toHaveLength(1);
|
|
51
|
-
expect(rows[0]).toMatchObject({
|
|
52
|
-
sessionId,
|
|
53
|
-
status: "failed",
|
|
54
|
-
exitCode: 1,
|
|
55
|
-
});
|
|
56
|
-
expect(rows[0]?.endedAt).toBeTruthy();
|
|
57
|
-
|
|
58
|
-
const manifest = JSON.parse(
|
|
59
|
-
readFileSync(artifacts.manifestPath, "utf8"),
|
|
60
|
-
) as Record<string, unknown>;
|
|
61
|
-
expect(manifest.status).toBe("failed");
|
|
62
|
-
expect(manifest.exit_code).toBe(1);
|
|
63
|
-
expect(manifest.ended_at).toBeTruthy();
|
|
64
|
-
expect(manifest.metadata).toMatchObject({
|
|
65
|
-
terminal_marker: "failed_external_process_exit",
|
|
66
|
-
terminal_marker_pid: 999_999_999,
|
|
67
|
-
terminal_marker_source: "stale_session_reconciler",
|
|
68
|
-
});
|
|
69
|
-
expect(
|
|
70
|
-
(manifest.metadata as Record<string, unknown>).terminal_marker_at,
|
|
71
|
-
).toBeTruthy();
|
|
72
|
-
|
|
73
|
-
expect(existsSync(artifacts.hookPath)).toBe(true);
|
|
74
|
-
expect(existsSync(artifacts.transcriptPath)).toBe(true);
|
|
75
|
-
expect(readFileSync(artifacts.hookPath, "utf8")).toContain(
|
|
76
|
-
'"hookName":"session_shutdown"',
|
|
77
|
-
);
|
|
78
|
-
expect(readFileSync(artifacts.hookPath, "utf8")).toContain(
|
|
79
|
-
'"reason":"failed_external_process_exit"',
|
|
80
|
-
);
|
|
81
|
-
expect(readFileSync(artifacts.transcriptPath, "utf8")).toContain(
|
|
82
|
-
"[shutdown] failed_external_process_exit",
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|