@clinebot/core 0.0.20 → 0.0.21
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 +6 -4
- 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,589 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
AgentTeamsRuntime,
|
|
5
|
-
bootstrapAgentTeams,
|
|
6
|
-
type TeamEvent,
|
|
7
|
-
type TeamTeammateSpec,
|
|
8
|
-
type Tool,
|
|
9
|
-
} from "@clinebot/agents";
|
|
10
|
-
import { resolveSkillsConfigSearchPaths } from "@clinebot/shared/storage";
|
|
11
|
-
import { nanoid } from "nanoid";
|
|
12
|
-
import {
|
|
13
|
-
createUserInstructionConfigWatcher,
|
|
14
|
-
type SkillConfig,
|
|
15
|
-
type UserInstructionConfigWatcher,
|
|
16
|
-
} from "../agents";
|
|
17
|
-
import { createLocalTeamStore } from "../storage/team-store";
|
|
18
|
-
import {
|
|
19
|
-
createBuiltinTools,
|
|
20
|
-
DEFAULT_MODEL_TOOL_ROUTING_RULES,
|
|
21
|
-
resolveToolRoutingConfig,
|
|
22
|
-
type SkillsExecutor,
|
|
23
|
-
type ToolExecutors,
|
|
24
|
-
ToolPresets,
|
|
25
|
-
type ToolRoutingRule,
|
|
26
|
-
} from "../tools";
|
|
27
|
-
import type { CoreAgentMode, CoreSessionConfig } from "../types/config";
|
|
28
|
-
import type {
|
|
29
|
-
RuntimeBuilder,
|
|
30
|
-
RuntimeBuilderInput,
|
|
31
|
-
BuiltRuntime as RuntimeEnvironment,
|
|
32
|
-
} from "./session-runtime";
|
|
33
|
-
|
|
34
|
-
type SkillsExecutorMetadataItem = {
|
|
35
|
-
id: string;
|
|
36
|
-
name: string;
|
|
37
|
-
description?: string;
|
|
38
|
-
disabled: boolean;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const WORKSPACE_CONFIGURATION_MARKER = "# Workspace Configuration";
|
|
42
|
-
|
|
43
|
-
type SkillsExecutorWithMetadata = SkillsExecutor & {
|
|
44
|
-
configuredSkills?: SkillsExecutorMetadataItem[];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export function createTeamName(): string {
|
|
48
|
-
return `agent-team-${nanoid(5)}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function createBuiltinToolsList(
|
|
52
|
-
cwd: string,
|
|
53
|
-
providerId: string,
|
|
54
|
-
mode: CoreAgentMode,
|
|
55
|
-
modelId: string,
|
|
56
|
-
toolRoutingRules: ToolRoutingRule[] | undefined,
|
|
57
|
-
skillsExecutor?: SkillsExecutorWithMetadata,
|
|
58
|
-
executorOverrides?: Partial<ToolExecutors>,
|
|
59
|
-
): Tool[] {
|
|
60
|
-
const preset =
|
|
61
|
-
mode === "plan" ? ToolPresets.readonly : ToolPresets.development;
|
|
62
|
-
const toolRoutingConfig = resolveToolRoutingConfig(
|
|
63
|
-
providerId,
|
|
64
|
-
modelId,
|
|
65
|
-
mode,
|
|
66
|
-
toolRoutingRules ?? DEFAULT_MODEL_TOOL_ROUTING_RULES,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
return createBuiltinTools({
|
|
70
|
-
cwd,
|
|
71
|
-
...preset,
|
|
72
|
-
...toolRoutingConfig,
|
|
73
|
-
enableSkills: !!skillsExecutor,
|
|
74
|
-
executors: {
|
|
75
|
-
...(skillsExecutor
|
|
76
|
-
? {
|
|
77
|
-
skills: skillsExecutor,
|
|
78
|
-
}
|
|
79
|
-
: {}),
|
|
80
|
-
...(executorOverrides ?? {}),
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const SKILL_FILE_NAME = "SKILL.md";
|
|
86
|
-
|
|
87
|
-
function listAvailableSkillNames(
|
|
88
|
-
watcher: UserInstructionConfigWatcher,
|
|
89
|
-
allowedSkillNames?: ReadonlyArray<string>,
|
|
90
|
-
): string[] {
|
|
91
|
-
return listConfiguredSkills(watcher, allowedSkillNames)
|
|
92
|
-
.filter((skill) => !skill.disabled)
|
|
93
|
-
.map((skill) => skill.name.trim())
|
|
94
|
-
.filter((name) => name.length > 0)
|
|
95
|
-
.sort((a, b) => a.localeCompare(b));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function normalizeSkillToken(token: string): string {
|
|
99
|
-
return token.trim().replace(/^\/+/, "").toLowerCase();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function toAllowedSkillSet(
|
|
103
|
-
allowedSkillNames?: ReadonlyArray<string>,
|
|
104
|
-
): Set<string> | undefined {
|
|
105
|
-
if (!allowedSkillNames || allowedSkillNames.length === 0) {
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
const normalized = allowedSkillNames
|
|
109
|
-
.map(normalizeSkillToken)
|
|
110
|
-
.filter((token) => token.length > 0);
|
|
111
|
-
return normalized.length > 0 ? new Set(normalized) : undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function isSkillAllowed(
|
|
115
|
-
skillId: string,
|
|
116
|
-
skillName: string,
|
|
117
|
-
allowedSkills?: Set<string>,
|
|
118
|
-
): boolean {
|
|
119
|
-
if (!allowedSkills) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
const normalizedId = normalizeSkillToken(skillId);
|
|
123
|
-
const normalizedName = normalizeSkillToken(skillName);
|
|
124
|
-
const bareId = normalizedId.includes(":")
|
|
125
|
-
? (normalizedId.split(":").at(-1) ?? normalizedId)
|
|
126
|
-
: normalizedId;
|
|
127
|
-
const bareName = normalizedName.includes(":")
|
|
128
|
-
? (normalizedName.split(":").at(-1) ?? normalizedName)
|
|
129
|
-
: normalizedName;
|
|
130
|
-
return (
|
|
131
|
-
allowedSkills.has(normalizedId) ||
|
|
132
|
-
allowedSkills.has(normalizedName) ||
|
|
133
|
-
allowedSkills.has(bareId) ||
|
|
134
|
-
allowedSkills.has(bareName)
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function listConfiguredSkills(
|
|
139
|
-
watcher: UserInstructionConfigWatcher,
|
|
140
|
-
allowedSkillNames?: ReadonlyArray<string>,
|
|
141
|
-
): SkillsExecutorMetadataItem[] {
|
|
142
|
-
const allowedSkills = toAllowedSkillSet(allowedSkillNames);
|
|
143
|
-
const snapshot = watcher.getSnapshot("skill");
|
|
144
|
-
return [...snapshot.entries()]
|
|
145
|
-
.map(([id, record]) => {
|
|
146
|
-
const skill = record.item as SkillConfig;
|
|
147
|
-
return {
|
|
148
|
-
id,
|
|
149
|
-
name: skill.name.trim(),
|
|
150
|
-
description: skill.description?.trim(),
|
|
151
|
-
disabled: skill.disabled === true,
|
|
152
|
-
};
|
|
153
|
-
})
|
|
154
|
-
.filter((skill) => isSkillAllowed(skill.id, skill.name, allowedSkills));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function hasSkillsFiles(workspacePath: string): boolean {
|
|
158
|
-
for (const directoryPath of resolveSkillsConfigSearchPaths(workspacePath)) {
|
|
159
|
-
if (!existsSync(directoryPath)) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const directSkillPath = join(directoryPath, SKILL_FILE_NAME);
|
|
164
|
-
if (existsSync(directSkillPath)) {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
const entries = readdirSync(directoryPath, { withFileTypes: true });
|
|
170
|
-
for (const entry of entries) {
|
|
171
|
-
if (!entry.isDirectory()) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (existsSync(join(directoryPath, entry.name, SKILL_FILE_NAME))) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
} catch {
|
|
179
|
-
// Ignore inaccessible directories while probing for local skills.
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function resolveSkillRecord(
|
|
187
|
-
watcher: UserInstructionConfigWatcher,
|
|
188
|
-
requestedSkill: string,
|
|
189
|
-
allowedSkillNames?: ReadonlyArray<string>,
|
|
190
|
-
): { id: string; skill: SkillConfig } | { error: string } {
|
|
191
|
-
const allowedSkills = toAllowedSkillSet(allowedSkillNames);
|
|
192
|
-
const normalized = requestedSkill.trim().replace(/^\/+/, "").toLowerCase();
|
|
193
|
-
if (!normalized) {
|
|
194
|
-
return { error: "Missing skill name." };
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const snapshot = watcher.getSnapshot("skill");
|
|
198
|
-
const scopedEntries = [...snapshot.entries()].filter(([id, record]) => {
|
|
199
|
-
const skill = record.item as SkillConfig;
|
|
200
|
-
return isSkillAllowed(id, skill.name, allowedSkills);
|
|
201
|
-
});
|
|
202
|
-
const scopedSnapshot = new Map(scopedEntries);
|
|
203
|
-
const exact = scopedSnapshot.get(normalized);
|
|
204
|
-
if (exact) {
|
|
205
|
-
const skill = exact.item as SkillConfig;
|
|
206
|
-
if (skill.disabled === true) {
|
|
207
|
-
return {
|
|
208
|
-
error: `Skill "${skill.name}" is configured but disabled.`,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
id: normalized,
|
|
213
|
-
skill,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const bareName = normalized.includes(":")
|
|
218
|
-
? (normalized.split(":").at(-1) ?? normalized)
|
|
219
|
-
: normalized;
|
|
220
|
-
|
|
221
|
-
const suffixMatches = [...scopedSnapshot.entries()].filter(([id]) => {
|
|
222
|
-
if (id === bareName) {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
return id.endsWith(`:${bareName}`);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (suffixMatches.length === 1) {
|
|
229
|
-
const [id, record] = suffixMatches[0];
|
|
230
|
-
const skill = record.item as SkillConfig;
|
|
231
|
-
if (skill.disabled === true) {
|
|
232
|
-
return {
|
|
233
|
-
error: `Skill "${skill.name}" is configured but disabled.`,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
id,
|
|
238
|
-
skill,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (suffixMatches.length > 1) {
|
|
243
|
-
return {
|
|
244
|
-
error: `Skill "${requestedSkill}" is ambiguous. Use one of: ${suffixMatches.map(([id]) => id).join(", ")}`,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const available = listAvailableSkillNames(watcher, allowedSkillNames);
|
|
249
|
-
return {
|
|
250
|
-
error:
|
|
251
|
-
available.length > 0
|
|
252
|
-
? `Skill "${requestedSkill}" not found. Available skills: ${available.join(", ")}`
|
|
253
|
-
: "No skills are currently available.",
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function createSkillsExecutor(
|
|
258
|
-
watcher: UserInstructionConfigWatcher,
|
|
259
|
-
watcherReady: Promise<void>,
|
|
260
|
-
allowedSkillNames?: ReadonlyArray<string>,
|
|
261
|
-
): SkillsExecutorWithMetadata {
|
|
262
|
-
const runningSkills = new Set<string>();
|
|
263
|
-
const executor: SkillsExecutorWithMetadata = async (skillName, args) => {
|
|
264
|
-
await watcherReady;
|
|
265
|
-
const resolved = resolveSkillRecord(watcher, skillName, allowedSkillNames);
|
|
266
|
-
if ("error" in resolved) {
|
|
267
|
-
return resolved.error;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const { id, skill } = resolved;
|
|
271
|
-
if (runningSkills.has(id)) {
|
|
272
|
-
return `Skill "${skill.name}" is already running.`;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
runningSkills.add(id);
|
|
276
|
-
try {
|
|
277
|
-
const trimmedArgs = args?.trim();
|
|
278
|
-
const argsTag = trimmedArgs
|
|
279
|
-
? `\n<command-args>${trimmedArgs}</command-args>`
|
|
280
|
-
: "";
|
|
281
|
-
const description = skill.description?.trim()
|
|
282
|
-
? `Description: ${skill.description.trim()}\n\n`
|
|
283
|
-
: "";
|
|
284
|
-
|
|
285
|
-
return `<command-name>${skill.name}</command-name>${argsTag}\n<command-instructions>\n${description}${skill.instructions}\n</command-instructions>`;
|
|
286
|
-
} finally {
|
|
287
|
-
runningSkills.delete(id);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
Object.defineProperty(executor, "configuredSkills", {
|
|
291
|
-
get: () => listConfiguredSkills(watcher, allowedSkillNames),
|
|
292
|
-
enumerable: true,
|
|
293
|
-
configurable: false,
|
|
294
|
-
});
|
|
295
|
-
return executor;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function shutdownTeamRuntime(
|
|
299
|
-
teamRuntime: AgentTeamsRuntime | undefined,
|
|
300
|
-
reason: string,
|
|
301
|
-
): void {
|
|
302
|
-
if (!teamRuntime) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
for (const teammateId of teamRuntime.getTeammateIds()) {
|
|
306
|
-
try {
|
|
307
|
-
teamRuntime.shutdownTeammate(teammateId, reason);
|
|
308
|
-
} catch {
|
|
309
|
-
// Best-effort shutdown for all teammates.
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function extractWorkspaceMetadataFromSystemPrompt(
|
|
315
|
-
systemPrompt: string,
|
|
316
|
-
): string | undefined {
|
|
317
|
-
const markerIndex = systemPrompt.lastIndexOf(WORKSPACE_CONFIGURATION_MARKER);
|
|
318
|
-
if (markerIndex < 0) {
|
|
319
|
-
return undefined;
|
|
320
|
-
}
|
|
321
|
-
const metadata = systemPrompt.slice(markerIndex).trim();
|
|
322
|
-
return metadata.length > 0 ? metadata : undefined;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function normalizeConfig(
|
|
326
|
-
config: CoreSessionConfig,
|
|
327
|
-
): Required<
|
|
328
|
-
Pick<
|
|
329
|
-
CoreSessionConfig,
|
|
330
|
-
| "mode"
|
|
331
|
-
| "enableTools"
|
|
332
|
-
| "enableSpawnAgent"
|
|
333
|
-
| "enableAgentTeams"
|
|
334
|
-
| "missionLogIntervalSteps"
|
|
335
|
-
| "missionLogIntervalMs"
|
|
336
|
-
>
|
|
337
|
-
> {
|
|
338
|
-
return {
|
|
339
|
-
mode: config.mode === "plan" ? "plan" : "act",
|
|
340
|
-
enableTools: config.enableTools !== false,
|
|
341
|
-
enableSpawnAgent: config.enableSpawnAgent !== false,
|
|
342
|
-
enableAgentTeams: config.enableAgentTeams !== false,
|
|
343
|
-
missionLogIntervalSteps:
|
|
344
|
-
typeof config.missionLogIntervalSteps === "number" &&
|
|
345
|
-
Number.isFinite(config.missionLogIntervalSteps)
|
|
346
|
-
? config.missionLogIntervalSteps
|
|
347
|
-
: 3,
|
|
348
|
-
missionLogIntervalMs:
|
|
349
|
-
typeof config.missionLogIntervalMs === "number" &&
|
|
350
|
-
Number.isFinite(config.missionLogIntervalMs)
|
|
351
|
-
? config.missionLogIntervalMs
|
|
352
|
-
: 120000,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
export class DefaultRuntimeBuilder implements RuntimeBuilder {
|
|
357
|
-
build(input: RuntimeBuilderInput): RuntimeEnvironment {
|
|
358
|
-
const {
|
|
359
|
-
config,
|
|
360
|
-
hooks,
|
|
361
|
-
extensions,
|
|
362
|
-
logger,
|
|
363
|
-
createSpawnTool,
|
|
364
|
-
onTeamRestored,
|
|
365
|
-
userInstructionWatcher: sharedUserInstructionWatcher,
|
|
366
|
-
defaultToolExecutors,
|
|
367
|
-
} = input;
|
|
368
|
-
const onTeamEvent = input.onTeamEvent ?? (() => {});
|
|
369
|
-
const normalized = normalizeConfig(config);
|
|
370
|
-
const tools: Tool[] = [];
|
|
371
|
-
const effectiveTeamName = config.teamName?.trim() || createTeamName();
|
|
372
|
-
let teamToolsRegistered = false;
|
|
373
|
-
const watcherProvided = Boolean(sharedUserInstructionWatcher);
|
|
374
|
-
let userInstructionWatcher = sharedUserInstructionWatcher;
|
|
375
|
-
let watcherReady = Promise.resolve();
|
|
376
|
-
let skillsExecutor: SkillsExecutorWithMetadata | undefined;
|
|
377
|
-
|
|
378
|
-
if (
|
|
379
|
-
!userInstructionWatcher &&
|
|
380
|
-
normalized.enableTools &&
|
|
381
|
-
hasSkillsFiles(config.cwd)
|
|
382
|
-
) {
|
|
383
|
-
userInstructionWatcher = createUserInstructionConfigWatcher({
|
|
384
|
-
skills: { workspacePath: config.cwd },
|
|
385
|
-
rules: { workspacePath: config.cwd },
|
|
386
|
-
workflows: { workspacePath: config.cwd },
|
|
387
|
-
});
|
|
388
|
-
watcherReady = userInstructionWatcher.start().catch(() => {});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (
|
|
392
|
-
normalized.enableTools &&
|
|
393
|
-
userInstructionWatcher &&
|
|
394
|
-
(watcherProvided ||
|
|
395
|
-
hasSkillsFiles(config.cwd) ||
|
|
396
|
-
listConfiguredSkills(userInstructionWatcher, config.skills).length > 0)
|
|
397
|
-
) {
|
|
398
|
-
skillsExecutor = createSkillsExecutor(
|
|
399
|
-
userInstructionWatcher,
|
|
400
|
-
watcherReady,
|
|
401
|
-
config.skills,
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (normalized.enableTools) {
|
|
406
|
-
tools.push(
|
|
407
|
-
...createBuiltinToolsList(
|
|
408
|
-
config.cwd,
|
|
409
|
-
config.providerId,
|
|
410
|
-
normalized.mode,
|
|
411
|
-
config.modelId,
|
|
412
|
-
config.toolRoutingRules,
|
|
413
|
-
skillsExecutor,
|
|
414
|
-
defaultToolExecutors,
|
|
415
|
-
),
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
let teamRuntime: AgentTeamsRuntime | undefined;
|
|
420
|
-
const teamStore = normalized.enableAgentTeams
|
|
421
|
-
? createLocalTeamStore()
|
|
422
|
-
: undefined;
|
|
423
|
-
const restoredTeam = teamStore?.loadRuntime(effectiveTeamName);
|
|
424
|
-
const restoredTeamState = restoredTeam?.state;
|
|
425
|
-
const restoredTeammateSpecs = restoredTeam?.teammates ?? [];
|
|
426
|
-
const teammateSpecs = new Map(
|
|
427
|
-
restoredTeammateSpecs.map((spec) => [spec.agentId, spec] as const),
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
const ensureTeamRuntime = (): AgentTeamsRuntime | undefined => {
|
|
431
|
-
if (!normalized.enableAgentTeams) {
|
|
432
|
-
return undefined;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
if (!teamRuntime) {
|
|
436
|
-
teamRuntime = new AgentTeamsRuntime({
|
|
437
|
-
teamName: effectiveTeamName,
|
|
438
|
-
leadAgentId: "lead",
|
|
439
|
-
missionLogIntervalSteps: normalized.missionLogIntervalSteps,
|
|
440
|
-
missionLogIntervalMs: normalized.missionLogIntervalMs,
|
|
441
|
-
onTeamEvent: (event: TeamEvent) => {
|
|
442
|
-
onTeamEvent(event);
|
|
443
|
-
if (teamRuntime && teamStore) {
|
|
444
|
-
if (
|
|
445
|
-
event.type === "teammate_spawned" &&
|
|
446
|
-
event.teammate?.rolePrompt
|
|
447
|
-
) {
|
|
448
|
-
const spec: TeamTeammateSpec = {
|
|
449
|
-
agentId: event.agentId,
|
|
450
|
-
rolePrompt: event.teammate.rolePrompt,
|
|
451
|
-
modelId: event.teammate.modelId,
|
|
452
|
-
maxIterations: event.teammate.maxIterations,
|
|
453
|
-
};
|
|
454
|
-
teammateSpecs.set(spec.agentId, spec);
|
|
455
|
-
}
|
|
456
|
-
if (event.type === "teammate_shutdown") {
|
|
457
|
-
teammateSpecs.delete(event.agentId);
|
|
458
|
-
}
|
|
459
|
-
teamStore.handleTeamEvent(effectiveTeamName, event);
|
|
460
|
-
teamStore.persistRuntime(
|
|
461
|
-
effectiveTeamName,
|
|
462
|
-
teamRuntime.exportState(),
|
|
463
|
-
Array.from(teammateSpecs.values()),
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
});
|
|
468
|
-
if (restoredTeamState) {
|
|
469
|
-
teamRuntime.hydrateState(restoredTeamState);
|
|
470
|
-
teamRuntime.markStaleRunsInterrupted("runtime_recovered");
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
if (!teamToolsRegistered) {
|
|
475
|
-
if (!teamRuntime) {
|
|
476
|
-
return undefined;
|
|
477
|
-
}
|
|
478
|
-
teamToolsRegistered = true;
|
|
479
|
-
|
|
480
|
-
const teamBootstrap = bootstrapAgentTeams({
|
|
481
|
-
runtime: teamRuntime,
|
|
482
|
-
leadAgentId: "lead",
|
|
483
|
-
restoredFromPersistence: Boolean(restoredTeamState),
|
|
484
|
-
restoredTeammates: restoredTeammateSpecs,
|
|
485
|
-
createBaseTools: normalized.enableTools
|
|
486
|
-
? () =>
|
|
487
|
-
createBuiltinToolsList(
|
|
488
|
-
config.cwd,
|
|
489
|
-
config.providerId,
|
|
490
|
-
normalized.mode,
|
|
491
|
-
config.modelId,
|
|
492
|
-
config.toolRoutingRules,
|
|
493
|
-
skillsExecutor,
|
|
494
|
-
defaultToolExecutors,
|
|
495
|
-
)
|
|
496
|
-
: undefined,
|
|
497
|
-
teammateRuntime: {
|
|
498
|
-
providerId: config.providerId,
|
|
499
|
-
modelId: config.modelId,
|
|
500
|
-
cwd: config.cwd,
|
|
501
|
-
apiKey: config.apiKey ?? "",
|
|
502
|
-
baseUrl: config.baseUrl,
|
|
503
|
-
headers: config.headers,
|
|
504
|
-
providerConfig: config.providerConfig,
|
|
505
|
-
knownModels: config.knownModels,
|
|
506
|
-
thinking: config.thinking,
|
|
507
|
-
clineWorkspaceMetadata:
|
|
508
|
-
config.providerId === "cline"
|
|
509
|
-
? extractWorkspaceMetadataFromSystemPrompt(config.systemPrompt)
|
|
510
|
-
: undefined,
|
|
511
|
-
maxIterations: config.maxIterations,
|
|
512
|
-
hooks,
|
|
513
|
-
extensions: extensions ?? config.extensions,
|
|
514
|
-
logger: logger ?? config.logger,
|
|
515
|
-
},
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
if (teamBootstrap.restoredFromPersistence) {
|
|
519
|
-
onTeamRestored?.();
|
|
520
|
-
}
|
|
521
|
-
tools.push(...teamBootstrap.tools);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
return teamRuntime;
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
if (normalized.enableSpawnAgent && createSpawnTool) {
|
|
528
|
-
const spawnTool = createSpawnTool();
|
|
529
|
-
tools.push({
|
|
530
|
-
...spawnTool,
|
|
531
|
-
execute: async (spawnInput, context) => {
|
|
532
|
-
ensureTeamRuntime();
|
|
533
|
-
return spawnTool.execute(spawnInput, context);
|
|
534
|
-
},
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
if (normalized.enableAgentTeams) {
|
|
539
|
-
ensureTeamRuntime();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
const completionGuard = teamRuntime
|
|
543
|
-
? () => {
|
|
544
|
-
const rt = teamRuntime;
|
|
545
|
-
if (!rt) return undefined;
|
|
546
|
-
const tasks = rt.listTasks();
|
|
547
|
-
const hasInProgress = tasks.some(
|
|
548
|
-
(t) => t.status === "in_progress" || t.status === "pending",
|
|
549
|
-
);
|
|
550
|
-
const runs = rt.listRuns({});
|
|
551
|
-
const hasActiveRuns = runs.some(
|
|
552
|
-
(r) => r.status === "running" || r.status === "queued",
|
|
553
|
-
);
|
|
554
|
-
if (hasInProgress || hasActiveRuns) {
|
|
555
|
-
const pending = tasks
|
|
556
|
-
.filter(
|
|
557
|
-
(t) => t.status === "in_progress" || t.status === "pending",
|
|
558
|
-
)
|
|
559
|
-
.map((t) => `${t.id} (${t.status}): ${t.title}`)
|
|
560
|
-
.join(", ");
|
|
561
|
-
const activeRunSummary = runs
|
|
562
|
-
.filter((r) => r.status === "running" || r.status === "queued")
|
|
563
|
-
.map((r) => `${r.id} (${r.status})`)
|
|
564
|
-
.join(", ");
|
|
565
|
-
const parts = [];
|
|
566
|
-
if (pending) parts.push(`Unfinished tasks: ${pending}`);
|
|
567
|
-
if (activeRunSummary)
|
|
568
|
-
parts.push(`Active runs: ${activeRunSummary}`);
|
|
569
|
-
return `[SYSTEM] You still have team obligations. ${parts.join(". ")}. Use team_run_task to delegate work, or team_complete_task to mark tasks done, or team_await_run / team_await_all_runs to wait for active runs. Do NOT stop until all tasks are completed.`;
|
|
570
|
-
}
|
|
571
|
-
return undefined;
|
|
572
|
-
}
|
|
573
|
-
: undefined;
|
|
574
|
-
|
|
575
|
-
return {
|
|
576
|
-
tools,
|
|
577
|
-
logger: logger ?? config.logger,
|
|
578
|
-
telemetry: input.telemetry ?? config.telemetry,
|
|
579
|
-
teamRuntime,
|
|
580
|
-
completionGuard,
|
|
581
|
-
shutdown: (reason: string) => {
|
|
582
|
-
shutdownTeamRuntime(teamRuntime, reason);
|
|
583
|
-
if (!watcherProvided) {
|
|
584
|
-
userInstructionWatcher?.stop();
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
}
|