@clinebot/core 0.0.27 → 0.0.29
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 +7 -0
- package/dist/ClineCore.d.ts +28 -2
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/account/cline-account-service.d.ts +1 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/types.d.ts +5 -0
- package/dist/account/types.d.ts.map +1 -1
- package/dist/auth/bounded-ttl-cache.d.ts +14 -0
- package/dist/auth/bounded-ttl-cache.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +27 -2
- package/dist/auth/cline.d.ts.map +1 -1
- package/dist/auth/oca.d.ts.map +1 -1
- package/dist/chat/chat-schema.d.ts +8 -8
- package/dist/extensions/config/agent-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/agent-config-parser.d.ts +2 -2
- package/dist/extensions/config/agent-config-parser.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/hooks-config-loader.d.ts +1 -1
- package/dist/extensions/config/hooks-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/config}/index.d.ts +2 -4
- package/dist/extensions/config/index.d.ts.map +1 -0
- package/dist/{runtime/commands.d.ts → extensions/config/runtime-commands.d.ts} +2 -3
- package/dist/extensions/config/runtime-commands.d.ts.map +1 -0
- package/dist/extensions/config/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/extensions/context/agentic-compaction.d.ts +13 -0
- package/dist/extensions/context/agentic-compaction.d.ts.map +1 -0
- package/dist/extensions/context/basic-compaction.d.ts +9 -0
- package/dist/extensions/context/basic-compaction.d.ts.map +1 -0
- package/dist/extensions/context/compaction-shared.d.ts +60 -0
- package/dist/extensions/context/compaction-shared.d.ts.map +1 -0
- package/dist/extensions/context/compaction.d.ts +20 -0
- package/dist/extensions/context/compaction.d.ts.map +1 -0
- package/dist/extensions/index.d.ts +5 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/mcp/client.d.ts +3 -0
- package/dist/extensions/mcp/client.d.ts.map +1 -0
- package/dist/extensions/mcp/config-loader.d.ts.map +1 -0
- package/dist/extensions/mcp/index.d.ts +9 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -0
- package/dist/{mcp → extensions/mcp}/manager.d.ts +1 -2
- package/dist/extensions/mcp/manager.d.ts.map +1 -0
- package/dist/extensions/mcp/name-transform.d.ts +3 -0
- package/dist/extensions/mcp/name-transform.d.ts.map +1 -0
- package/dist/extensions/mcp/policies.d.ts +15 -0
- package/dist/extensions/mcp/policies.d.ts.map +1 -0
- package/dist/extensions/mcp/tools.d.ts +4 -0
- package/dist/extensions/mcp/tools.d.ts.map +1 -0
- package/dist/{mcp → extensions/mcp}/types.d.ts +29 -1
- package/dist/extensions/mcp/types.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-config-loader.d.ts +1 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-loader.d.ts +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -0
- package/dist/extensions/plugin/plugin-module-import.d.ts +5 -0
- package/dist/extensions/plugin/plugin-module-import.d.ts.map +1 -0
- package/dist/{agents → extensions/plugin}/plugin-sandbox.d.ts +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -0
- package/dist/extensions/plugin-sandbox-bootstrap.js +485 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/persistent.d.ts +64 -0
- package/dist/hooks/persistent.d.ts.map +1 -0
- package/dist/hooks/subprocess-runner.d.ts +22 -0
- package/dist/hooks/subprocess-runner.d.ts.map +1 -0
- package/dist/hooks/subprocess.d.ts +189 -0
- package/dist/hooks/subprocess.d.ts.map +1 -0
- package/dist/index.d.ts +22 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +560 -447
- package/dist/prompt/default-system.d.ts +2 -0
- package/dist/prompt/default-system.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +1 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -1
- package/dist/runtime/checkpoint-hooks.d.ts +21 -0
- package/dist/runtime/checkpoint-hooks.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -1
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -1
- package/dist/runtime/rules.d.ts +1 -1
- package/dist/runtime/rules.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts +1 -1
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +25 -5
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/team-runtime-registry.d.ts +1 -1
- package/dist/runtime/team-runtime-registry.d.ts.map +1 -1
- package/dist/runtime/tool-approval.d.ts +1 -1
- package/dist/session/default-session-manager.d.ts +4 -3
- package/dist/session/default-session-manager.d.ts.map +1 -1
- package/dist/session/file-session-service.d.ts +1 -1
- package/dist/session/file-session-service.d.ts.map +1 -1
- package/dist/session/{unified-session-persistence-service.d.ts → persistence-service.d.ts} +11 -42
- package/dist/session/persistence-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -1
- package/dist/session/rpc-session-service.d.ts.map +1 -1
- package/dist/session/session-agent-events.d.ts +1 -1
- package/dist/session/session-artifacts.d.ts.map +1 -1
- package/dist/session/session-config-builder.d.ts.map +1 -1
- package/dist/session/session-graph.d.ts +1 -1
- package/dist/session/session-graph.d.ts.map +1 -1
- package/dist/session/session-host.d.ts.map +1 -1
- package/dist/session/session-manager.d.ts +6 -5
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manifest.d.ts +1 -1
- package/dist/session/session-service.d.ts +3 -2
- package/dist/session/session-service.d.ts.map +1 -1
- package/dist/session/session-team-coordination.d.ts +2 -1
- package/dist/session/session-team-coordination.d.ts.map +1 -1
- package/dist/session/utils/helpers.d.ts +51 -3
- package/dist/session/utils/helpers.d.ts.map +1 -1
- package/dist/session/utils/types.d.ts +41 -7
- package/dist/session/utils/types.d.ts.map +1 -1
- package/dist/session/workspace-manager.d.ts +1 -2
- package/dist/session/workspace-manager.d.ts.map +1 -1
- package/dist/session/workspace-manifest.d.ts +1 -22
- package/dist/session/workspace-manifest.d.ts.map +1 -1
- package/dist/storage/file-team-store.d.ts +2 -1
- package/dist/storage/file-team-store.d.ts.map +1 -1
- package/dist/storage/sqlite-team-store.d.ts +4 -1
- package/dist/storage/sqlite-team-store.d.ts.map +1 -1
- package/dist/storage/team-store.d.ts.map +1 -1
- package/dist/team/delegated-agent.d.ts +44 -0
- package/dist/team/delegated-agent.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -1
- package/dist/team/multi-agent.d.ts +229 -0
- package/dist/team/multi-agent.d.ts.map +1 -0
- package/dist/team/projections.d.ts +2 -2
- package/dist/team/projections.d.ts.map +1 -1
- package/dist/team/runtime.d.ts +5 -0
- package/dist/team/runtime.d.ts.map +1 -0
- package/dist/team/spawn-agent-tool.d.ts +85 -0
- package/dist/team/spawn-agent-tool.d.ts.map +1 -0
- package/dist/team/subagent-prompts.d.ts +4 -0
- package/dist/team/subagent-prompts.d.ts.map +1 -0
- package/dist/team/team-tools.d.ts +35 -0
- package/dist/team/team-tools.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +11 -1
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/{LoggerTelemetryAdapter.d.ts → TelemetryLoggerSink.d.ts} +10 -4
- package/dist/telemetry/TelemetryLoggerSink.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -1
- package/dist/telemetry/index.js +15 -28
- package/dist/tools/definitions.d.ts +4 -3
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/model-tool-routing.d.ts.map +1 -1
- package/dist/tools/presets.d.ts +26 -0
- package/dist/tools/presets.d.ts.map +1 -1
- package/dist/tools/schemas.d.ts +8 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/types.d.ts +23 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types/config.d.ts +47 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/provider-settings.d.ts +1 -1
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types/storage.d.ts +2 -1
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types.d.ts +7 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/ClineCore.test.ts +150 -0
- package/src/ClineCore.ts +114 -8
- package/src/account/cline-account-service.test.ts +84 -0
- package/src/account/cline-account-service.ts +2 -2
- package/src/account/index.ts +1 -0
- package/src/account/types.ts +6 -0
- package/src/auth/bounded-ttl-cache.test.ts +38 -0
- package/src/auth/bounded-ttl-cache.ts +53 -0
- package/src/auth/cline.test.ts +173 -36
- package/src/auth/cline.ts +395 -93
- package/src/auth/oca.test.ts +125 -0
- package/src/auth/oca.ts +17 -4
- package/src/{agents → extensions/config}/agent-config-loader.test.ts +1 -1
- package/src/{agents → extensions/config}/agent-config-parser.ts +2 -2
- package/src/{agents → extensions/config}/hooks-config-loader.ts +1 -1
- package/src/{agents → extensions/config}/index.ts +7 -11
- package/src/{runtime/commands.test.ts → extensions/config/runtime-commands.test.ts} +20 -3
- package/src/{runtime/commands.ts → extensions/config/runtime-commands.ts} +1 -8
- package/src/{agents → extensions/config}/unified-config-file-watcher.ts +15 -2
- package/src/{agents → extensions/config}/user-instruction-config-loader.test.ts +90 -2
- package/src/{agents → extensions/config}/user-instruction-config-loader.ts +126 -12
- package/src/extensions/context/agentic-compaction.ts +119 -0
- package/src/extensions/context/basic-compaction.ts +275 -0
- package/src/extensions/context/compaction-shared.ts +458 -0
- package/src/extensions/context/compaction.test.ts +477 -0
- package/src/extensions/context/compaction.ts +203 -0
- package/src/extensions/index.ts +12 -0
- package/src/extensions/mcp/client.ts +420 -0
- package/src/{mcp → extensions/mcp}/index.ts +16 -0
- package/src/{mcp → extensions/mcp}/manager.test.ts +1 -2
- package/src/{mcp → extensions/mcp}/manager.ts +3 -5
- package/src/extensions/mcp/name-transform.ts +33 -0
- package/src/extensions/mcp/policies.ts +47 -0
- package/src/extensions/mcp/tools.ts +47 -0
- package/src/{mcp → extensions/mcp}/types.ts +35 -7
- package/src/{agents → extensions/plugin}/plugin-config-loader.test.ts +18 -13
- package/src/{agents → extensions/plugin}/plugin-config-loader.ts +1 -1
- package/src/{agents → extensions/plugin}/plugin-loader.test.ts +41 -4
- package/src/extensions/plugin/plugin-loader.ts +106 -0
- package/src/extensions/plugin/plugin-module-import.ts +278 -0
- package/src/{agents → extensions/plugin}/plugin-sandbox-bootstrap.ts +30 -92
- package/src/{agents → extensions/plugin}/plugin-sandbox.test.ts +60 -3
- package/src/{agents → extensions/plugin}/plugin-sandbox.ts +146 -56
- package/src/hooks/index.ts +25 -0
- package/src/hooks/persistent.ts +661 -0
- package/src/hooks/subprocess-runner.ts +196 -0
- package/src/hooks/subprocess.ts +669 -0
- package/src/index.ts +200 -118
- package/src/prompt/default-system.ts +21 -0
- package/src/providers/local-provider-registry.ts +1 -1
- package/src/providers/local-provider-service.test.ts +23 -2
- package/src/providers/local-provider-service.ts +2 -2
- package/src/runtime/checkpoint-hooks.test.ts +167 -0
- package/src/runtime/checkpoint-hooks.ts +186 -0
- package/src/runtime/hook-file-hooks.test.ts +40 -1
- package/src/runtime/hook-file-hooks.ts +35 -16
- package/src/runtime/index.ts +4 -19
- package/src/runtime/rules.ts +4 -1
- package/src/runtime/runtime-builder.team-persistence.test.ts +3 -6
- package/src/runtime/runtime-builder.test.ts +266 -160
- package/src/runtime/runtime-builder.ts +120 -47
- package/src/runtime/runtime-parity.test.ts +22 -22
- package/src/runtime/session-runtime.ts +36 -6
- package/src/runtime/{sandbox/subprocess-sandbox.ts → subprocess-sandbox.ts} +24 -3
- package/src/runtime/team-runtime-registry.ts +1 -4
- package/src/runtime/tool-approval.ts +1 -1
- package/src/session/default-session-manager.e2e.test.ts +2 -2
- package/src/session/default-session-manager.test.ts +553 -9
- package/src/session/default-session-manager.ts +140 -46
- package/src/session/file-session-service.ts +3 -3
- package/src/session/index.ts +6 -6
- package/src/session/persistence-service.test.ts +212 -0
- package/src/session/{unified-session-persistence-service.ts → persistence-service.ts} +106 -172
- package/src/session/rpc-session-service.ts +3 -3
- package/src/session/runtime-oauth-token-manager.ts +1 -1
- package/src/session/session-agent-events.ts +1 -1
- package/src/session/session-artifacts.ts +32 -4
- package/src/session/session-config-builder.ts +22 -9
- package/src/session/session-graph.ts +1 -1
- package/src/session/session-host.ts +19 -11
- package/src/session/session-manager.ts +11 -6
- package/src/session/session-service.team-persistence.test.ts +1 -1
- package/src/session/session-service.ts +6 -9
- package/src/session/session-team-coordination.ts +7 -3
- package/src/session/session-telemetry.ts +1 -1
- package/src/session/utils/helpers.test.ts +160 -0
- package/src/session/utils/helpers.ts +289 -42
- package/src/session/utils/types.ts +47 -7
- package/src/session/workspace-manager.ts +5 -3
- package/src/session/workspace-manifest.ts +3 -49
- package/src/storage/file-team-store.ts +2 -5
- package/src/storage/provider-settings-legacy-migration.ts +2 -2
- package/src/storage/provider-settings-manager.test.ts +1 -1
- package/src/storage/sqlite-team-store.ts +212 -125
- package/src/storage/team-store.ts +1 -5
- package/src/team/delegated-agent.ts +131 -0
- package/src/team/index.ts +1 -0
- package/src/team/multi-agent.lifecycle.test.ts +201 -0
- package/src/team/multi-agent.ts +1666 -0
- package/src/team/projections.ts +2 -4
- package/src/team/runtime.ts +54 -0
- package/src/team/spawn-agent-tool.test.ts +387 -0
- package/src/team/spawn-agent-tool.ts +207 -0
- package/src/team/subagent-prompts.ts +41 -0
- package/src/team/team-tools.test.ts +802 -0
- package/src/team/team-tools.ts +792 -0
- package/src/telemetry/OpenTelemetryProvider.test.ts +25 -3
- package/src/telemetry/OpenTelemetryProvider.ts +108 -18
- package/src/telemetry/TelemetryLoggerSink.test.ts +42 -0
- package/src/telemetry/{LoggerTelemetryAdapter.ts → TelemetryLoggerSink.ts} +21 -14
- package/src/telemetry/TelemetryService.test.ts +7 -7
- package/src/telemetry/TelemetryService.ts +2 -4
- package/src/tools/definitions.test.ts +76 -0
- package/src/tools/definitions.ts +41 -2
- package/src/tools/executors/apply-patch.ts +1 -1
- package/src/tools/executors/editor.ts +1 -1
- package/src/tools/executors/file-read.ts +1 -1
- package/src/tools/executors/search.ts +1 -1
- package/src/tools/executors/web-fetch.ts +1 -1
- package/src/tools/index.ts +6 -1
- package/src/tools/model-tool-routing.ts +2 -0
- package/src/tools/presets.test.ts +8 -0
- package/src/tools/presets.ts +40 -2
- package/src/tools/schemas.ts +19 -0
- package/src/tools/types.ts +31 -2
- package/src/types/config.ts +61 -7
- package/src/types/events.ts +1 -1
- package/src/types/index.ts +0 -1
- package/src/types/provider-settings.ts +1 -1
- package/src/types/storage.ts +2 -5
- package/src/types.ts +32 -44
- package/dist/agents/agent-config-loader.d.ts.map +0 -1
- package/dist/agents/agent-config-parser.d.ts.map +0 -1
- package/dist/agents/hooks-config-loader.d.ts.map +0 -1
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/plugin-config-loader.d.ts.map +0 -1
- package/dist/agents/plugin-loader.d.ts.map +0 -1
- package/dist/agents/plugin-sandbox-bootstrap.js +0 -446
- package/dist/agents/plugin-sandbox.d.ts.map +0 -1
- package/dist/agents/unified-config-file-watcher.d.ts.map +0 -1
- package/dist/agents/user-instruction-config-loader.d.ts.map +0 -1
- package/dist/mcp/config-loader.d.ts.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/manager.d.ts.map +0 -1
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/runtime/commands.d.ts.map +0 -1
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +0 -1
- package/dist/runtime/skills.d.ts +0 -14
- package/dist/runtime/skills.d.ts.map +0 -1
- package/dist/runtime/workflows.d.ts +0 -14
- package/dist/runtime/workflows.d.ts.map +0 -1
- package/dist/session/unified-session-persistence-service.d.ts.map +0 -1
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +0 -1
- package/dist/types/workspace.d.ts +0 -8
- package/dist/types/workspace.d.ts.map +0 -1
- package/src/agents/plugin-loader.ts +0 -175
- package/src/runtime/skills.ts +0 -44
- package/src/runtime/workflows.test.ts +0 -119
- package/src/runtime/workflows.ts +0 -45
- package/src/session/unified-session-persistence-service.test.ts +0 -85
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
- package/src/types/workspace.ts +0 -7
- /package/dist/{agents → extensions/config}/agent-config-loader.d.ts +0 -0
- /package/dist/{agents → extensions/config}/unified-config-file-watcher.d.ts +0 -0
- /package/dist/{agents → extensions/config}/user-instruction-config-loader.d.ts +0 -0
- /package/dist/{mcp → extensions/mcp}/config-loader.d.ts +0 -0
- /package/dist/runtime/{sandbox/subprocess-sandbox.d.ts → subprocess-sandbox.d.ts} +0 -0
- /package/src/{agents → extensions/config}/agent-config-loader.ts +0 -0
- /package/src/{agents → extensions/config}/hooks-config-loader.test.ts +0 -0
- /package/src/{agents → extensions/config}/unified-config-file-watcher.test.ts +0 -0
- /package/src/{mcp → extensions/mcp}/config-loader.test.ts +0 -0
- /package/src/{mcp → extensions/mcp}/config-loader.ts +0 -0
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { basename, resolve } from "node:path";
|
|
2
|
+
import type { WorkspaceInfo } from "@clinebot/shared";
|
|
3
|
+
import { processWorkspaceInfo } from "@clinebot/shared";
|
|
2
4
|
import simpleGit from "simple-git";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import type { WorkspaceInfo } from "../types/workspace";
|
|
5
|
-
|
|
6
|
-
export const WorkspaceInfoSchema = z.object({
|
|
7
|
-
rootPath: z.string().min(1),
|
|
8
|
-
hint: z.string().min(1).optional(),
|
|
9
|
-
associatedRemoteUrls: z.array(z.string().min(1)).optional(),
|
|
10
|
-
latestGitCommitHash: z.string().min(1).optional(),
|
|
11
|
-
latestGitBranchName: z.string().min(1).optional(),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export const WorkspaceManifestSchema = z.object({
|
|
15
|
-
currentWorkspacePath: z.string().min(1).optional(),
|
|
16
|
-
workspaces: z.record(z.string().min(1), WorkspaceInfoSchema),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export type WorkspaceManifest = z.infer<typeof WorkspaceManifestSchema>;
|
|
20
|
-
|
|
21
|
-
export function emptyWorkspaceManifest(): WorkspaceManifest {
|
|
22
|
-
return { workspaces: {} };
|
|
23
|
-
}
|
|
24
5
|
|
|
25
6
|
export function normalizeWorkspacePath(workspacePath: string): string {
|
|
26
7
|
return resolve(workspacePath);
|
|
@@ -67,34 +48,7 @@ export async function generateWorkspaceInfo(
|
|
|
67
48
|
return info;
|
|
68
49
|
}
|
|
69
50
|
|
|
70
|
-
export function upsertWorkspaceInfo(
|
|
71
|
-
manifest: WorkspaceManifest,
|
|
72
|
-
info: WorkspaceInfo,
|
|
73
|
-
): WorkspaceManifest {
|
|
74
|
-
const nextManifest: WorkspaceManifest = {
|
|
75
|
-
...manifest,
|
|
76
|
-
workspaces: {
|
|
77
|
-
...manifest.workspaces,
|
|
78
|
-
[info.rootPath]: info,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
if (!nextManifest.currentWorkspacePath) {
|
|
82
|
-
nextManifest.currentWorkspacePath = info.rootPath;
|
|
83
|
-
}
|
|
84
|
-
return WorkspaceManifestSchema.parse(nextManifest);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
51
|
export async function buildWorkspaceMetadata(cwd: string): Promise<string> {
|
|
88
52
|
const workspaceInfo = await generateWorkspaceInfo(cwd);
|
|
89
|
-
|
|
90
|
-
workspaces: {
|
|
91
|
-
[workspaceInfo.rootPath]: {
|
|
92
|
-
hint: workspaceInfo.hint,
|
|
93
|
-
associatedRemoteUrls: workspaceInfo.associatedRemoteUrls,
|
|
94
|
-
latestGitCommitHash: workspaceInfo.latestGitCommitHash,
|
|
95
|
-
latestGitBranchName: workspaceInfo.latestGitBranchName,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
return `# Workspace Configuration\n${JSON.stringify(workspaceConfig, null, 2)}`;
|
|
53
|
+
return processWorkspaceInfo(workspaceInfo);
|
|
100
54
|
}
|
|
@@ -8,12 +8,9 @@ import {
|
|
|
8
8
|
writeFileSync,
|
|
9
9
|
} from "node:fs";
|
|
10
10
|
import { join } from "node:path";
|
|
11
|
-
import type {
|
|
12
|
-
TeamEvent,
|
|
13
|
-
TeamRuntimeState,
|
|
14
|
-
TeamTeammateSpec,
|
|
15
|
-
} from "@clinebot/agents";
|
|
11
|
+
import type { TeamRuntimeState, TeamTeammateSpec } from "@clinebot/shared";
|
|
16
12
|
import { resolveTeamDataDir } from "@clinebot/shared/storage";
|
|
13
|
+
import type { TeamEvent } from "../team";
|
|
17
14
|
import type { TeamStore } from "../types/storage";
|
|
18
15
|
|
|
19
16
|
function nowIso(): string {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import * as LlmsModels from "@clinebot/llms
|
|
4
|
-
import * as LlmsProviders from "@clinebot/llms
|
|
3
|
+
import * as LlmsModels from "@clinebot/llms";
|
|
4
|
+
import * as LlmsProviders from "@clinebot/llms";
|
|
5
5
|
import { resolveClineDataDir } from "@clinebot/shared/storage";
|
|
6
6
|
import type { ProviderSettings } from "../types/provider-settings";
|
|
7
7
|
import { emptyStoredProviderSettings } from "../types/provider-settings";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import * as LlmsModels from "@clinebot/llms
|
|
4
|
+
import * as LlmsModels from "@clinebot/llms";
|
|
5
5
|
import { afterEach, describe, expect, it } from "vitest";
|
|
6
6
|
import { ProviderSettingsManager } from "./provider-settings-manager";
|
|
7
7
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
TeamRuntimeState,
|
|
6
|
-
TeamTeammateSpec,
|
|
7
|
-
} from "@clinebot/
|
|
3
|
+
import {
|
|
4
|
+
safeJsonParse,
|
|
5
|
+
type TeamRuntimeState,
|
|
6
|
+
type TeamTeammateSpec,
|
|
7
|
+
} from "@clinebot/shared";
|
|
8
8
|
import { loadSqliteDb, nowIso, type SqliteDb } from "@clinebot/shared/db";
|
|
9
9
|
import { resolveTeamDataDir } from "@clinebot/shared/storage";
|
|
10
|
+
import type { TeamEvent } from "../team";
|
|
10
11
|
import type { TeamStore } from "../types/storage";
|
|
11
12
|
|
|
12
13
|
function defaultTeamDir(): string {
|
|
@@ -41,6 +42,43 @@ interface TeamRunRow {
|
|
|
41
42
|
run_id: string;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function parseTeammatesJson(raw: string): TeamTeammateSpec[] {
|
|
46
|
+
const parsed = safeJsonParse<unknown>(raw);
|
|
47
|
+
if (!Array.isArray(parsed)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const out: TeamTeammateSpec[] = [];
|
|
51
|
+
for (const entry of parsed) {
|
|
52
|
+
if (!entry || typeof entry !== "object") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const rec = entry as Record<string, unknown>;
|
|
56
|
+
const agentId = rec.agentId;
|
|
57
|
+
const rolePrompt = rec.rolePrompt;
|
|
58
|
+
if (typeof agentId !== "string" || !agentId.trim()) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (typeof rolePrompt !== "string" || !rolePrompt.trim()) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const spec: TeamTeammateSpec = {
|
|
65
|
+
agentId: agentId.trim(),
|
|
66
|
+
rolePrompt,
|
|
67
|
+
};
|
|
68
|
+
if (typeof rec.modelId === "string" && rec.modelId.trim()) {
|
|
69
|
+
spec.modelId = rec.modelId.trim();
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
typeof rec.maxIterations === "number" &&
|
|
73
|
+
Number.isFinite(rec.maxIterations)
|
|
74
|
+
) {
|
|
75
|
+
spec.maxIterations = Math.max(1, Math.floor(rec.maxIterations));
|
|
76
|
+
}
|
|
77
|
+
out.push(spec);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
44
82
|
function reviveTeamRuntimeStateDates(
|
|
45
83
|
state: TeamRuntimeState,
|
|
46
84
|
): TeamRuntimeState {
|
|
@@ -122,6 +160,22 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
122
160
|
private ensureSchema(db: SqliteDb): void {
|
|
123
161
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
124
162
|
db.exec("PRAGMA busy_timeout = 5000;");
|
|
163
|
+
// Single-row table so ALTER-based upgrades can run in order (baseline = 1).
|
|
164
|
+
// Session/schedule schemas use separate migration paths in @clinebot/shared.
|
|
165
|
+
db.exec(`
|
|
166
|
+
CREATE TABLE IF NOT EXISTS team_store_schema_version (
|
|
167
|
+
lock INTEGER PRIMARY KEY CHECK (lock = 1),
|
|
168
|
+
version INTEGER NOT NULL
|
|
169
|
+
);
|
|
170
|
+
`);
|
|
171
|
+
const versionRow = db
|
|
172
|
+
.prepare("SELECT version FROM team_store_schema_version WHERE lock = 1")
|
|
173
|
+
.get() as { version: number } | null;
|
|
174
|
+
if (!versionRow) {
|
|
175
|
+
db.prepare(
|
|
176
|
+
"INSERT INTO team_store_schema_version (lock, version) VALUES (1, 1)",
|
|
177
|
+
).run();
|
|
178
|
+
}
|
|
125
179
|
db.exec(`
|
|
126
180
|
CREATE TABLE IF NOT EXISTS team_events (
|
|
127
181
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -230,6 +284,23 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
230
284
|
.all(...params) as T[];
|
|
231
285
|
}
|
|
232
286
|
|
|
287
|
+
/** Runs `work` in a single SQLite transaction (rollback on any error). */
|
|
288
|
+
private withTransaction(work: () => void): void {
|
|
289
|
+
const db = this.getRawDb();
|
|
290
|
+
db.exec("BEGIN IMMEDIATE;");
|
|
291
|
+
try {
|
|
292
|
+
work();
|
|
293
|
+
db.exec("COMMIT;");
|
|
294
|
+
} catch (error) {
|
|
295
|
+
try {
|
|
296
|
+
db.exec("ROLLBACK;");
|
|
297
|
+
} catch {
|
|
298
|
+
// ignore secondary failure
|
|
299
|
+
}
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
233
304
|
listTeamNames(): string[] {
|
|
234
305
|
return this.queryAll<{ team_name: string }>(
|
|
235
306
|
`SELECT team_name FROM team_runtime_snapshot ORDER BY team_name ASC`,
|
|
@@ -244,9 +315,15 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
244
315
|
if (!row) {
|
|
245
316
|
return undefined;
|
|
246
317
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
318
|
+
const parsed = safeJsonParse<TeamRuntimeState>(row.state_json);
|
|
319
|
+
if (!parsed) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
return reviveTeamRuntimeStateDates(parsed);
|
|
324
|
+
} catch {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
250
327
|
}
|
|
251
328
|
|
|
252
329
|
readHistory(teamName: string, limit = 200): unknown[] {
|
|
@@ -257,11 +334,19 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
257
334
|
}>(
|
|
258
335
|
`SELECT event_type, payload_json, ts FROM team_events WHERE team_name = ? ORDER BY id DESC LIMIT ?`,
|
|
259
336
|
[sanitizeTeamName(teamName), limit],
|
|
260
|
-
).
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
337
|
+
).flatMap((row) => {
|
|
338
|
+
try {
|
|
339
|
+
return [
|
|
340
|
+
{
|
|
341
|
+
eventType: row.event_type,
|
|
342
|
+
payload: JSON.parse(row.payload_json),
|
|
343
|
+
ts: row.ts,
|
|
344
|
+
},
|
|
345
|
+
];
|
|
346
|
+
} catch {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
265
350
|
}
|
|
266
351
|
|
|
267
352
|
loadRuntime(teamName: string): TeamRuntimeLoadResult {
|
|
@@ -272,7 +357,7 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
272
357
|
[safeTeamName],
|
|
273
358
|
);
|
|
274
359
|
const teammates = snapshotRow
|
|
275
|
-
? (
|
|
360
|
+
? parseTeammatesJson(snapshotRow.teammates_json)
|
|
276
361
|
: [];
|
|
277
362
|
const interruptedRunIds = this.markInProgressRunsInterrupted(
|
|
278
363
|
safeTeamName,
|
|
@@ -311,123 +396,125 @@ export class SqliteTeamStore implements TeamStore {
|
|
|
311
396
|
): void {
|
|
312
397
|
const safeTeamName = sanitizeTeamName(teamName);
|
|
313
398
|
const now = nowIso();
|
|
314
|
-
this.
|
|
315
|
-
`INSERT INTO team_runtime_snapshot (team_name, state_json, teammates_json, updated_at)
|
|
316
|
-
VALUES (?, ?, ?, ?)
|
|
317
|
-
ON CONFLICT(team_name) DO UPDATE SET
|
|
318
|
-
state_json = excluded.state_json,
|
|
319
|
-
teammates_json = excluded.teammates_json,
|
|
320
|
-
updated_at = excluded.updated_at`,
|
|
321
|
-
[safeTeamName, JSON.stringify(state), JSON.stringify(teammates), now],
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
for (const task of state.tasks) {
|
|
399
|
+
this.withTransaction(() => {
|
|
325
400
|
this.run(
|
|
326
|
-
`INSERT INTO
|
|
327
|
-
VALUES (?, ?, ?,
|
|
328
|
-
ON CONFLICT(team_name
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
status = excluded.status,
|
|
332
|
-
assignee = excluded.assignee,
|
|
333
|
-
depends_on_json = excluded.depends_on_json,
|
|
334
|
-
summary = excluded.summary,
|
|
335
|
-
version = team_tasks.version + 1,
|
|
401
|
+
`INSERT INTO team_runtime_snapshot (team_name, state_json, teammates_json, updated_at)
|
|
402
|
+
VALUES (?, ?, ?, ?)
|
|
403
|
+
ON CONFLICT(team_name) DO UPDATE SET
|
|
404
|
+
state_json = excluded.state_json,
|
|
405
|
+
teammates_json = excluded.teammates_json,
|
|
336
406
|
updated_at = excluded.updated_at`,
|
|
337
|
-
[
|
|
338
|
-
safeTeamName,
|
|
339
|
-
task.id,
|
|
340
|
-
task.title,
|
|
341
|
-
task.description,
|
|
342
|
-
task.status,
|
|
343
|
-
task.assignee ?? null,
|
|
344
|
-
JSON.stringify(task.dependsOn ?? []),
|
|
345
|
-
task.summary ?? null,
|
|
346
|
-
task.updatedAt.toISOString(),
|
|
347
|
-
],
|
|
407
|
+
[safeTeamName, JSON.stringify(state), JSON.stringify(teammates), now],
|
|
348
408
|
);
|
|
349
|
-
}
|
|
350
409
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
run.heartbeatAt ? run.heartbeatAt.toISOString() : null,
|
|
378
|
-
],
|
|
379
|
-
);
|
|
380
|
-
}
|
|
410
|
+
for (const task of state.tasks) {
|
|
411
|
+
this.run(
|
|
412
|
+
`INSERT INTO team_tasks (team_name, task_id, title, description, status, assignee, depends_on_json, summary, version, updated_at)
|
|
413
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?)
|
|
414
|
+
ON CONFLICT(team_name, task_id) DO UPDATE SET
|
|
415
|
+
title = excluded.title,
|
|
416
|
+
description = excluded.description,
|
|
417
|
+
status = excluded.status,
|
|
418
|
+
assignee = excluded.assignee,
|
|
419
|
+
depends_on_json = excluded.depends_on_json,
|
|
420
|
+
summary = excluded.summary,
|
|
421
|
+
version = team_tasks.version + 1,
|
|
422
|
+
updated_at = excluded.updated_at`,
|
|
423
|
+
[
|
|
424
|
+
safeTeamName,
|
|
425
|
+
task.id,
|
|
426
|
+
task.title,
|
|
427
|
+
task.description,
|
|
428
|
+
task.status,
|
|
429
|
+
task.assignee ?? null,
|
|
430
|
+
JSON.stringify(task.dependsOn ?? []),
|
|
431
|
+
task.summary ?? null,
|
|
432
|
+
task.updatedAt.toISOString(),
|
|
433
|
+
],
|
|
434
|
+
);
|
|
435
|
+
}
|
|
381
436
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
437
|
+
for (const run of state.runs ?? []) {
|
|
438
|
+
this.run(
|
|
439
|
+
`INSERT INTO team_runs (team_name, run_id, agent_id, task_id, status, message, started_at, ended_at, error, lease_owner, heartbeat_at, version)
|
|
440
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)
|
|
441
|
+
ON CONFLICT(team_name, run_id) DO UPDATE SET
|
|
442
|
+
agent_id = excluded.agent_id,
|
|
443
|
+
task_id = excluded.task_id,
|
|
444
|
+
status = excluded.status,
|
|
445
|
+
message = excluded.message,
|
|
446
|
+
started_at = excluded.started_at,
|
|
447
|
+
ended_at = excluded.ended_at,
|
|
448
|
+
error = excluded.error,
|
|
449
|
+
lease_owner = excluded.lease_owner,
|
|
450
|
+
heartbeat_at = excluded.heartbeat_at,
|
|
451
|
+
version = team_runs.version + 1`,
|
|
452
|
+
[
|
|
453
|
+
safeTeamName,
|
|
454
|
+
run.id,
|
|
455
|
+
run.agentId,
|
|
456
|
+
run.taskId ?? null,
|
|
457
|
+
run.status,
|
|
458
|
+
run.message,
|
|
459
|
+
run.startedAt ? run.startedAt.toISOString() : null,
|
|
460
|
+
run.endedAt ? run.endedAt.toISOString() : null,
|
|
461
|
+
run.error ?? null,
|
|
462
|
+
run.leaseOwner ?? null,
|
|
463
|
+
run.heartbeatAt ? run.heartbeatAt.toISOString() : null,
|
|
464
|
+
],
|
|
465
|
+
);
|
|
466
|
+
}
|
|
402
467
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
468
|
+
for (const outcome of state.outcomes ?? []) {
|
|
469
|
+
this.run(
|
|
470
|
+
`INSERT INTO team_outcomes (team_name, outcome_id, title, status, schema_json, finalized_at, version)
|
|
471
|
+
VALUES (?, ?, ?, ?, ?, ?, 1)
|
|
472
|
+
ON CONFLICT(team_name, outcome_id) DO UPDATE SET
|
|
473
|
+
title = excluded.title,
|
|
474
|
+
status = excluded.status,
|
|
475
|
+
schema_json = excluded.schema_json,
|
|
476
|
+
finalized_at = excluded.finalized_at,
|
|
477
|
+
version = team_outcomes.version + 1`,
|
|
478
|
+
[
|
|
479
|
+
safeTeamName,
|
|
480
|
+
outcome.id,
|
|
481
|
+
outcome.title,
|
|
482
|
+
outcome.status,
|
|
483
|
+
JSON.stringify({ requiredSections: outcome.requiredSections }),
|
|
484
|
+
outcome.finalizedAt ? outcome.finalizedAt.toISOString() : null,
|
|
485
|
+
],
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
for (const fragment of state.outcomeFragments ?? []) {
|
|
490
|
+
this.run(
|
|
491
|
+
`INSERT INTO team_outcome_fragments (team_name, outcome_id, fragment_id, section, source_agent_id, source_run_id, content, status, reviewed_by, reviewed_at, version)
|
|
492
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)
|
|
493
|
+
ON CONFLICT(team_name, fragment_id) DO UPDATE SET
|
|
494
|
+
outcome_id = excluded.outcome_id,
|
|
495
|
+
section = excluded.section,
|
|
496
|
+
source_agent_id = excluded.source_agent_id,
|
|
497
|
+
source_run_id = excluded.source_run_id,
|
|
498
|
+
content = excluded.content,
|
|
499
|
+
status = excluded.status,
|
|
500
|
+
reviewed_by = excluded.reviewed_by,
|
|
501
|
+
reviewed_at = excluded.reviewed_at,
|
|
502
|
+
version = team_outcome_fragments.version + 1`,
|
|
503
|
+
[
|
|
504
|
+
safeTeamName,
|
|
505
|
+
fragment.outcomeId,
|
|
506
|
+
fragment.id,
|
|
507
|
+
fragment.section,
|
|
508
|
+
fragment.sourceAgentId,
|
|
509
|
+
fragment.sourceRunId ?? null,
|
|
510
|
+
fragment.content,
|
|
511
|
+
fragment.status,
|
|
512
|
+
fragment.reviewedBy ?? null,
|
|
513
|
+
fragment.reviewedAt ? fragment.reviewedAt.toISOString() : null,
|
|
514
|
+
],
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
431
518
|
}
|
|
432
519
|
|
|
433
520
|
markInProgressRunsInterrupted(teamName: string, reason: string): string[] {
|
|
@@ -28,11 +28,7 @@ export function createLocalTeamStore(options: SqliteTeamStoreOptions = {}): {
|
|
|
28
28
|
const store = new SqliteTeamStore(options);
|
|
29
29
|
store.init();
|
|
30
30
|
return store;
|
|
31
|
-
} catch
|
|
32
|
-
console.warn(
|
|
33
|
-
"SQLite team persistence unavailable, falling back to file-based team storage.",
|
|
34
|
-
error,
|
|
35
|
-
);
|
|
31
|
+
} catch {
|
|
36
32
|
const store = new FileTeamStore({ teamDir: options.teamDir });
|
|
37
33
|
store.init();
|
|
38
34
|
return store;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Agent } from "@clinebot/agents";
|
|
2
|
+
import type {
|
|
3
|
+
AgentConfig,
|
|
4
|
+
AgentEvent,
|
|
5
|
+
AgentHooks,
|
|
6
|
+
BasicLogger,
|
|
7
|
+
HookErrorMode,
|
|
8
|
+
ITelemetryService,
|
|
9
|
+
Tool,
|
|
10
|
+
ToolApprovalRequest,
|
|
11
|
+
ToolApprovalResult,
|
|
12
|
+
} from "@clinebot/shared";
|
|
13
|
+
import {
|
|
14
|
+
buildSubAgentSystemPrompt,
|
|
15
|
+
buildTeammateSystemPrompt,
|
|
16
|
+
} from "./subagent-prompts";
|
|
17
|
+
|
|
18
|
+
type AgentExtension = NonNullable<AgentConfig["extensions"]>[number];
|
|
19
|
+
|
|
20
|
+
export type DelegatedAgentConnectionConfig = Pick<
|
|
21
|
+
AgentConfig,
|
|
22
|
+
| "providerId"
|
|
23
|
+
| "modelId"
|
|
24
|
+
| "apiKey"
|
|
25
|
+
| "baseUrl"
|
|
26
|
+
| "headers"
|
|
27
|
+
| "providerConfig"
|
|
28
|
+
| "knownModels"
|
|
29
|
+
| "thinking"
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
export interface DelegatedAgentRuntimeConfig
|
|
33
|
+
extends DelegatedAgentConnectionConfig {
|
|
34
|
+
cwd?: string;
|
|
35
|
+
providerId: string;
|
|
36
|
+
clinePlatform?: string;
|
|
37
|
+
clineIdeName?: string;
|
|
38
|
+
maxIterations?: number;
|
|
39
|
+
hooks?: AgentHooks;
|
|
40
|
+
extensions?: AgentExtension[];
|
|
41
|
+
logger?: BasicLogger;
|
|
42
|
+
telemetry?: ITelemetryService;
|
|
43
|
+
workspaceMetadata?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DelegatedAgentConfigProvider {
|
|
47
|
+
getRuntimeConfig(): DelegatedAgentRuntimeConfig;
|
|
48
|
+
getConnectionConfig(): DelegatedAgentConnectionConfig;
|
|
49
|
+
updateConnectionDefaults(
|
|
50
|
+
overrides: Partial<DelegatedAgentConnectionConfig>,
|
|
51
|
+
): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type DelegatedAgentKind = "subagent" | "teammate";
|
|
55
|
+
|
|
56
|
+
export interface BuildDelegatedAgentConfigOptions {
|
|
57
|
+
kind: DelegatedAgentKind;
|
|
58
|
+
prompt: string;
|
|
59
|
+
tools: Tool[];
|
|
60
|
+
configProvider: DelegatedAgentConfigProvider;
|
|
61
|
+
parentAgentId?: string;
|
|
62
|
+
maxIterations?: number;
|
|
63
|
+
abortSignal?: AbortSignal;
|
|
64
|
+
onEvent?: (event: AgentEvent) => void;
|
|
65
|
+
hookErrorMode?: HookErrorMode;
|
|
66
|
+
toolPolicies?: AgentConfig["toolPolicies"];
|
|
67
|
+
requestToolApproval?: (
|
|
68
|
+
request: ToolApprovalRequest,
|
|
69
|
+
) => Promise<ToolApprovalResult> | ToolApprovalResult;
|
|
70
|
+
role?: string;
|
|
71
|
+
cwd?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createDelegatedAgentConfigProvider(
|
|
75
|
+
initialConfig: DelegatedAgentRuntimeConfig,
|
|
76
|
+
): DelegatedAgentConfigProvider {
|
|
77
|
+
let runtimeConfig: DelegatedAgentRuntimeConfig = { ...initialConfig };
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
getRuntimeConfig: () => runtimeConfig,
|
|
81
|
+
getConnectionConfig: () => ({
|
|
82
|
+
providerId: runtimeConfig.providerId,
|
|
83
|
+
modelId: runtimeConfig.modelId,
|
|
84
|
+
apiKey: runtimeConfig.apiKey,
|
|
85
|
+
baseUrl: runtimeConfig.baseUrl,
|
|
86
|
+
headers: runtimeConfig.headers,
|
|
87
|
+
providerConfig: runtimeConfig.providerConfig,
|
|
88
|
+
knownModels: runtimeConfig.knownModels,
|
|
89
|
+
thinking: runtimeConfig.thinking,
|
|
90
|
+
}),
|
|
91
|
+
updateConnectionDefaults: (overrides) => {
|
|
92
|
+
runtimeConfig = {
|
|
93
|
+
...runtimeConfig,
|
|
94
|
+
...overrides,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function buildDelegatedAgentConfig(
|
|
101
|
+
options: BuildDelegatedAgentConfigOptions,
|
|
102
|
+
): AgentConfig & { role?: string } {
|
|
103
|
+
const runtimeConfig = options.configProvider.getRuntimeConfig();
|
|
104
|
+
const systemPrompt =
|
|
105
|
+
options.kind === "teammate"
|
|
106
|
+
? buildTeammateSystemPrompt(options.prompt, runtimeConfig)
|
|
107
|
+
: buildSubAgentSystemPrompt(options.prompt, runtimeConfig);
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
...options.configProvider.getConnectionConfig(),
|
|
111
|
+
systemPrompt,
|
|
112
|
+
tools: options.tools,
|
|
113
|
+
maxIterations: options.maxIterations ?? runtimeConfig.maxIterations,
|
|
114
|
+
parentAgentId: options.parentAgentId,
|
|
115
|
+
abortSignal: options.abortSignal,
|
|
116
|
+
onEvent: options.onEvent,
|
|
117
|
+
hooks: runtimeConfig.hooks,
|
|
118
|
+
extensions: runtimeConfig.extensions,
|
|
119
|
+
hookErrorMode: options.hookErrorMode,
|
|
120
|
+
toolPolicies: options.toolPolicies,
|
|
121
|
+
requestToolApproval: options.requestToolApproval,
|
|
122
|
+
logger: runtimeConfig.logger,
|
|
123
|
+
role: options.role,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function createDelegatedAgent(
|
|
128
|
+
options: BuildDelegatedAgentConfigOptions,
|
|
129
|
+
): Agent {
|
|
130
|
+
return new Agent(buildDelegatedAgentConfig(options));
|
|
131
|
+
}
|
package/src/team/index.ts
CHANGED