@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,198 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig, Tool } from "@clinebot/agents";
|
|
2
|
-
import YAML from "yaml";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { ALL_DEFAULT_TOOL_NAMES, type DefaultToolName } from "../tools";
|
|
5
|
-
|
|
6
|
-
const AgentConfigFrontmatterSchema = z.object({
|
|
7
|
-
name: z.string().trim().min(1),
|
|
8
|
-
description: z.string().trim().min(1),
|
|
9
|
-
modelId: z.string().trim().min(1).optional(),
|
|
10
|
-
tools: z.union([z.string(), z.array(z.string())]).optional(),
|
|
11
|
-
skills: z.union([z.string(), z.array(z.string())]).optional(),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const allowedToolNames = new Set<string>(ALL_DEFAULT_TOOL_NAMES);
|
|
15
|
-
|
|
16
|
-
export interface AgentYamlConfig {
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
modelId?: string;
|
|
20
|
-
tools: DefaultToolName[];
|
|
21
|
-
skills?: string[];
|
|
22
|
-
systemPrompt: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ParseYamlFrontmatterResult {
|
|
26
|
-
data: Record<string, unknown>;
|
|
27
|
-
body: string;
|
|
28
|
-
hadFrontmatter: boolean;
|
|
29
|
-
parseError?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface BuildAgentConfigOverridesOptions {
|
|
33
|
-
availableTools?: ReadonlyArray<Tool>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface PartialAgentConfigOverrides
|
|
37
|
-
extends Partial<Pick<AgentConfig, "modelId" | "systemPrompt" | "tools">> {
|
|
38
|
-
skills?: string[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function isAgentConfigYamlFile(fileName: string): boolean {
|
|
42
|
-
return /\.(yaml|yml)$/i.test(fileName);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function normalizeAgentConfigName(name: string): string {
|
|
46
|
-
return name.trim().toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function parseYamlFrontmatter(markdown: string): ParseYamlFrontmatterResult {
|
|
50
|
-
const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
51
|
-
const match = markdown.match(frontmatterRegex);
|
|
52
|
-
if (!match) {
|
|
53
|
-
return { data: {}, body: markdown, hadFrontmatter: false };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const [, yamlContent, body] = match;
|
|
57
|
-
try {
|
|
58
|
-
const parsed = YAML.parse(yamlContent);
|
|
59
|
-
const data =
|
|
60
|
-
parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
61
|
-
? (parsed as Record<string, unknown>)
|
|
62
|
-
: {};
|
|
63
|
-
return { data, body, hadFrontmatter: true };
|
|
64
|
-
} catch (error) {
|
|
65
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
-
return {
|
|
67
|
-
data: {},
|
|
68
|
-
body: markdown,
|
|
69
|
-
hadFrontmatter: true,
|
|
70
|
-
parseError: message,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function normalizeToolName(toolName: string): DefaultToolName {
|
|
76
|
-
const trimmed = toolName.trim();
|
|
77
|
-
if (!trimmed) {
|
|
78
|
-
throw new Error("Tool name cannot be empty.");
|
|
79
|
-
}
|
|
80
|
-
if (!allowedToolNames.has(trimmed)) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Unknown tool '${trimmed}'. Expected one of: ${ALL_DEFAULT_TOOL_NAMES.join(", ")}.`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return trimmed as DefaultToolName;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function parseToolNames(
|
|
89
|
-
tools: string | string[] | undefined,
|
|
90
|
-
): DefaultToolName[] {
|
|
91
|
-
if (!tools) {
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
const rawTools = Array.isArray(tools) ? tools : tools.split(",");
|
|
95
|
-
return Array.from(new Set(rawTools.map(normalizeToolName)));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function normalizeSkillName(skillName: string): string {
|
|
99
|
-
const trimmed = skillName.trim();
|
|
100
|
-
if (!trimmed) {
|
|
101
|
-
throw new Error("Skill name cannot be empty.");
|
|
102
|
-
}
|
|
103
|
-
return trimmed;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function parseSkills(
|
|
107
|
-
skills: string | string[] | undefined,
|
|
108
|
-
): string[] | undefined {
|
|
109
|
-
if (skills === undefined) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
const rawSkills = Array.isArray(skills) ? skills : skills.split(",");
|
|
113
|
-
return Array.from(new Set(rawSkills.map(normalizeSkillName)));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function parseAgentConfigFromYaml(content: string): AgentYamlConfig {
|
|
117
|
-
const { data, body, hadFrontmatter, parseError } =
|
|
118
|
-
parseYamlFrontmatter(content);
|
|
119
|
-
if (parseError) {
|
|
120
|
-
throw new Error(`Failed to parse YAML frontmatter: ${parseError}`);
|
|
121
|
-
}
|
|
122
|
-
if (!hadFrontmatter) {
|
|
123
|
-
throw new Error("Missing YAML frontmatter block in agent config file.");
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const parsedFrontmatter = AgentConfigFrontmatterSchema.parse(data);
|
|
127
|
-
const systemPrompt = body.trim();
|
|
128
|
-
if (!systemPrompt) {
|
|
129
|
-
throw new Error("Missing system prompt body in agent config file.");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
name: parsedFrontmatter.name,
|
|
134
|
-
description: parsedFrontmatter.description,
|
|
135
|
-
modelId: parsedFrontmatter.modelId,
|
|
136
|
-
tools: parseToolNames(parsedFrontmatter.tools),
|
|
137
|
-
skills: parseSkills(parsedFrontmatter.skills),
|
|
138
|
-
systemPrompt,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function resolveAgentTools(
|
|
143
|
-
toolNames: ReadonlyArray<DefaultToolName>,
|
|
144
|
-
availableTools: ReadonlyArray<Tool>,
|
|
145
|
-
): Tool[] {
|
|
146
|
-
if (toolNames.length === 0) {
|
|
147
|
-
return [];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const toolIndex = new Map<string, Tool>(
|
|
151
|
-
availableTools.map((tool) => [tool.name, tool]),
|
|
152
|
-
);
|
|
153
|
-
return toolNames.map((toolName) => {
|
|
154
|
-
const resolved = toolIndex.get(toolName);
|
|
155
|
-
if (!resolved) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
`Configured tool '${toolName}' is unavailable. Available tools: ${availableTools.map((tool) => tool.name).join(", ")}.`,
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
return resolved;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function toPartialAgentConfig(
|
|
165
|
-
config: AgentYamlConfig,
|
|
166
|
-
options?: BuildAgentConfigOverridesOptions,
|
|
167
|
-
): PartialAgentConfigOverrides {
|
|
168
|
-
const partial: PartialAgentConfigOverrides = {
|
|
169
|
-
systemPrompt: config.systemPrompt,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
if (config.modelId) {
|
|
173
|
-
partial.modelId = config.modelId;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (config.tools.length > 0) {
|
|
177
|
-
if (!options?.availableTools) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
"Configured tools cannot be converted into AgentConfig.tools without availableTools.",
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
partial.tools = resolveAgentTools(config.tools, options.availableTools);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (config.skills !== undefined) {
|
|
186
|
-
partial.skills = [...config.skills];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return partial;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function parsePartialAgentConfigFromYaml(
|
|
193
|
-
content: string,
|
|
194
|
-
options?: BuildAgentConfigOverridesOptions,
|
|
195
|
-
): PartialAgentConfigOverrides {
|
|
196
|
-
const parsed = parseAgentConfigFromYaml(content);
|
|
197
|
-
return toPartialAgentConfig(parsed, options);
|
|
198
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
HookConfigFileName,
|
|
4
|
-
toHookConfigFileName,
|
|
5
|
-
} from "./hooks-config-loader";
|
|
6
|
-
|
|
7
|
-
describe("hooks config loader", () => {
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
delete process.env.CLINE_DATA_DIR;
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("recognizes PowerShell hook files", () => {
|
|
13
|
-
expect(toHookConfigFileName("PreToolUse.ps1")).toBe(
|
|
14
|
-
HookConfigFileName.PreToolUse,
|
|
15
|
-
);
|
|
16
|
-
expect(toHookConfigFileName("TaskError.ps1")).toBe(
|
|
17
|
-
HookConfigFileName.TaskError,
|
|
18
|
-
);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
-
import { basename, extname, join } from "node:path";
|
|
3
|
-
import type { HookEventName } from "@clinebot/agents";
|
|
4
|
-
import {
|
|
5
|
-
HOOKS_CONFIG_DIRECTORY_NAME,
|
|
6
|
-
resolveDocumentsHooksDirectoryPath,
|
|
7
|
-
resolveHooksConfigSearchPaths as resolveHooksConfigSearchPathsFromShared,
|
|
8
|
-
} from "@clinebot/shared/storage";
|
|
9
|
-
|
|
10
|
-
export { HOOKS_CONFIG_DIRECTORY_NAME, resolveDocumentsHooksDirectoryPath };
|
|
11
|
-
|
|
12
|
-
export function resolveHooksConfigSearchPaths(
|
|
13
|
-
workspacePath?: string,
|
|
14
|
-
): string[] {
|
|
15
|
-
return resolveHooksConfigSearchPathsFromShared(workspacePath);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum HookConfigFileName {
|
|
19
|
-
TaskStart = "TaskStart",
|
|
20
|
-
TaskResume = "TaskResume",
|
|
21
|
-
TaskCancel = "TaskCancel",
|
|
22
|
-
TaskComplete = "TaskComplete",
|
|
23
|
-
TaskError = "TaskError",
|
|
24
|
-
PreToolUse = "PreToolUse",
|
|
25
|
-
PostToolUse = "PostToolUse",
|
|
26
|
-
UserPromptSubmit = "UserPromptSubmit",
|
|
27
|
-
PreCompact = "PreCompact",
|
|
28
|
-
SessionShutdown = "SessionShutdown",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const HOOK_CONFIG_FILE_EVENT_MAP: Readonly<
|
|
32
|
-
Record<HookConfigFileName, HookEventName | undefined>
|
|
33
|
-
> = {
|
|
34
|
-
[HookConfigFileName.TaskStart]: "agent_start",
|
|
35
|
-
[HookConfigFileName.TaskResume]: "agent_resume",
|
|
36
|
-
[HookConfigFileName.TaskCancel]: "agent_abort",
|
|
37
|
-
[HookConfigFileName.TaskComplete]: "agent_end",
|
|
38
|
-
[HookConfigFileName.TaskError]: "agent_error",
|
|
39
|
-
[HookConfigFileName.PreToolUse]: "tool_call",
|
|
40
|
-
[HookConfigFileName.PostToolUse]: "tool_result",
|
|
41
|
-
[HookConfigFileName.UserPromptSubmit]: "prompt_submit",
|
|
42
|
-
[HookConfigFileName.PreCompact]: undefined,
|
|
43
|
-
[HookConfigFileName.SessionShutdown]: "session_shutdown",
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const HOOK_CONFIG_FILE_LOOKUP = new Map<string, HookConfigFileName>(
|
|
47
|
-
Object.values(HookConfigFileName).map((name) => [name.toLowerCase(), name]),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const SUPPORTED_HOOK_FILE_EXTENSIONS = new Set([
|
|
51
|
-
"",
|
|
52
|
-
".sh",
|
|
53
|
-
".bash",
|
|
54
|
-
".zsh",
|
|
55
|
-
".js",
|
|
56
|
-
".mjs",
|
|
57
|
-
".cjs",
|
|
58
|
-
".ts",
|
|
59
|
-
".mts",
|
|
60
|
-
".cts",
|
|
61
|
-
".py",
|
|
62
|
-
".ps1",
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
export function toHookConfigFileName(
|
|
66
|
-
fileName: string,
|
|
67
|
-
): HookConfigFileName | undefined {
|
|
68
|
-
const extension = extname(fileName).toLowerCase();
|
|
69
|
-
if (!SUPPORTED_HOOK_FILE_EXTENSIONS.has(extension)) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
const key = basename(fileName, extension).trim().toLowerCase();
|
|
73
|
-
return HOOK_CONFIG_FILE_LOOKUP.get(key);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface HookConfigFileEntry {
|
|
77
|
-
fileName: HookConfigFileName;
|
|
78
|
-
hookEventName?: HookEventName;
|
|
79
|
-
path: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function listHookConfigFiles(
|
|
83
|
-
workspacePath?: string,
|
|
84
|
-
): HookConfigFileEntry[] {
|
|
85
|
-
const entries: HookConfigFileEntry[] = [];
|
|
86
|
-
const seen = new Set<string>();
|
|
87
|
-
const directories = resolveHooksConfigSearchPaths(workspacePath).filter(
|
|
88
|
-
(directory) => existsSync(directory),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
for (const directory of directories) {
|
|
92
|
-
try {
|
|
93
|
-
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
94
|
-
if (!entry.isFile()) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const fileName = toHookConfigFileName(entry.name);
|
|
98
|
-
if (!fileName) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const path = join(directory, entry.name);
|
|
102
|
-
if (seen.has(path)) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
seen.add(path);
|
|
106
|
-
entries.push({
|
|
107
|
-
fileName,
|
|
108
|
-
hookEventName: HOOK_CONFIG_FILE_EVENT_MAP[fileName],
|
|
109
|
-
path,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
} catch {
|
|
113
|
-
// Best-effort listing across config roots.
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
118
|
-
}
|
package/src/agents/index.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
AgentConfigWatcher,
|
|
3
|
-
AgentConfigWatcherEvent,
|
|
4
|
-
AgentYamlConfig,
|
|
5
|
-
BuildAgentConfigOverridesOptions,
|
|
6
|
-
CreateAgentConfigWatcherOptions,
|
|
7
|
-
ParseYamlFrontmatterResult,
|
|
8
|
-
PartialAgentConfigOverrides,
|
|
9
|
-
} from "./agent-config-loader";
|
|
10
|
-
export {
|
|
11
|
-
AGENT_CONFIG_DIRECTORY_NAME,
|
|
12
|
-
createAgentConfigDefinition,
|
|
13
|
-
createAgentConfigWatcher,
|
|
14
|
-
parseAgentConfigFromYaml,
|
|
15
|
-
parsePartialAgentConfigFromYaml,
|
|
16
|
-
readAgentConfigsFromDisk,
|
|
17
|
-
resolveAgentConfigSearchPaths,
|
|
18
|
-
resolveAgentsConfigDirPath,
|
|
19
|
-
resolveAgentTools,
|
|
20
|
-
resolveDocumentsAgentConfigDirectoryPath,
|
|
21
|
-
toPartialAgentConfig,
|
|
22
|
-
} from "./agent-config-loader";
|
|
23
|
-
export {
|
|
24
|
-
HOOK_CONFIG_FILE_EVENT_MAP,
|
|
25
|
-
HOOKS_CONFIG_DIRECTORY_NAME,
|
|
26
|
-
type HookConfigFileEntry,
|
|
27
|
-
HookConfigFileName,
|
|
28
|
-
listHookConfigFiles,
|
|
29
|
-
resolveDocumentsHooksDirectoryPath,
|
|
30
|
-
resolveHooksConfigSearchPaths,
|
|
31
|
-
toHookConfigFileName,
|
|
32
|
-
} from "./hooks-config-loader";
|
|
33
|
-
export type { ResolveAgentPluginPathsOptions } from "./plugin-config-loader";
|
|
34
|
-
export {
|
|
35
|
-
discoverPluginModulePaths,
|
|
36
|
-
resolveAgentPluginPaths,
|
|
37
|
-
resolveAndLoadAgentPlugins,
|
|
38
|
-
resolvePluginConfigSearchPaths,
|
|
39
|
-
} from "./plugin-config-loader";
|
|
40
|
-
export type { LoadAgentPluginFromPathOptions } from "./plugin-loader";
|
|
41
|
-
export {
|
|
42
|
-
loadAgentPluginFromPath,
|
|
43
|
-
loadAgentPluginsFromPaths,
|
|
44
|
-
} from "./plugin-loader";
|
|
45
|
-
export type {
|
|
46
|
-
UnifiedConfigDefinition,
|
|
47
|
-
UnifiedConfigFileCandidate,
|
|
48
|
-
UnifiedConfigFileContext,
|
|
49
|
-
UnifiedConfigRecord,
|
|
50
|
-
UnifiedConfigWatcherEvent,
|
|
51
|
-
UnifiedConfigWatcherOptions,
|
|
52
|
-
} from "./unified-config-file-watcher";
|
|
53
|
-
export { UnifiedConfigFileWatcher } from "./unified-config-file-watcher";
|
|
54
|
-
export type {
|
|
55
|
-
CreateInstructionWatcherOptions,
|
|
56
|
-
CreateRulesConfigDefinitionOptions,
|
|
57
|
-
CreateSkillsConfigDefinitionOptions,
|
|
58
|
-
CreateUserInstructionConfigWatcherOptions,
|
|
59
|
-
CreateWorkflowsConfigDefinitionOptions,
|
|
60
|
-
ParseMarkdownFrontmatterResult,
|
|
61
|
-
RuleConfig,
|
|
62
|
-
SkillConfig,
|
|
63
|
-
UserInstructionConfig,
|
|
64
|
-
UserInstructionConfigType,
|
|
65
|
-
UserInstructionConfigWatcher,
|
|
66
|
-
UserInstructionConfigWatcherEvent,
|
|
67
|
-
WorkflowConfig,
|
|
68
|
-
} from "./user-instruction-config-loader";
|
|
69
|
-
export {
|
|
70
|
-
createRulesConfigDefinition,
|
|
71
|
-
createSkillsConfigDefinition,
|
|
72
|
-
createUserInstructionConfigWatcher,
|
|
73
|
-
createWorkflowsConfigDefinition,
|
|
74
|
-
parseRuleConfigFromMarkdown,
|
|
75
|
-
parseSkillConfigFromMarkdown,
|
|
76
|
-
parseWorkflowConfigFromMarkdown,
|
|
77
|
-
RULES_CONFIG_DIRECTORY_NAME,
|
|
78
|
-
resolveDocumentsRulesDirectoryPath,
|
|
79
|
-
resolveDocumentsWorkflowsDirectoryPath,
|
|
80
|
-
resolveRulesConfigSearchPaths,
|
|
81
|
-
resolveSkillsConfigSearchPaths,
|
|
82
|
-
resolveWorkflowsConfigSearchPaths,
|
|
83
|
-
SKILLS_CONFIG_DIRECTORY_NAME,
|
|
84
|
-
WORKFLOWS_CONFIG_DIRECTORY_NAME,
|
|
85
|
-
} from "./user-instruction-config-loader";
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { setHomeDir } from "@clinebot/shared/storage";
|
|
5
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
-
import {
|
|
7
|
-
discoverPluginModulePaths,
|
|
8
|
-
resolveAgentPluginPaths,
|
|
9
|
-
resolvePluginConfigSearchPaths,
|
|
10
|
-
} from "./plugin-config-loader";
|
|
11
|
-
|
|
12
|
-
describe("plugin-config-loader", () => {
|
|
13
|
-
const envSnapshot = {
|
|
14
|
-
HOME: process.env.HOME,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
process.env.HOME = envSnapshot.HOME;
|
|
19
|
-
setHomeDir(envSnapshot.HOME ?? "~");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("discovers plugin modules recursively", async () => {
|
|
23
|
-
const root = await mkdtemp(join(tmpdir(), "core-plugin-config-loader-"));
|
|
24
|
-
try {
|
|
25
|
-
const nested = join(root, "nested");
|
|
26
|
-
await mkdir(nested, { recursive: true });
|
|
27
|
-
await writeFile(join(root, "a.mjs"), "export default {}", "utf8");
|
|
28
|
-
await writeFile(join(nested, "b.ts"), "export default {}", "utf8");
|
|
29
|
-
await writeFile(
|
|
30
|
-
join(root, ".a.mjs.cline-plugin.mjs"),
|
|
31
|
-
"export default {}",
|
|
32
|
-
"utf8",
|
|
33
|
-
);
|
|
34
|
-
await writeFile(join(root, "ignore.txt"), "noop", "utf8");
|
|
35
|
-
|
|
36
|
-
const discovered = discoverPluginModulePaths(root);
|
|
37
|
-
expect(discovered).toEqual([join(root, "a.mjs"), join(nested, "b.ts")]);
|
|
38
|
-
} finally {
|
|
39
|
-
await rm(root, { recursive: true, force: true });
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("resolves plugin paths from explicit files/directories", async () => {
|
|
44
|
-
const root = await mkdtemp(join(tmpdir(), "core-plugin-config-loader-"));
|
|
45
|
-
try {
|
|
46
|
-
process.env.HOME = root;
|
|
47
|
-
setHomeDir(root);
|
|
48
|
-
const pluginsDir = join(root, "plugins");
|
|
49
|
-
await mkdir(pluginsDir, { recursive: true });
|
|
50
|
-
const filePath = join(root, "direct.mjs");
|
|
51
|
-
const dirPluginPath = join(pluginsDir, "dir-plugin.mjs");
|
|
52
|
-
await writeFile(filePath, "export default {}", "utf8");
|
|
53
|
-
await writeFile(dirPluginPath, "export default {}", "utf8");
|
|
54
|
-
|
|
55
|
-
const resolved = resolveAgentPluginPaths({
|
|
56
|
-
pluginPaths: ["./direct.mjs", "./plugins"],
|
|
57
|
-
workspacePath: join(root, "workspace"),
|
|
58
|
-
cwd: root,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(resolved).toEqual([filePath, dirPluginPath]);
|
|
62
|
-
} finally {
|
|
63
|
-
await rm(root, { recursive: true, force: true });
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("prefers package manifest plugin entries for configured directories", async () => {
|
|
68
|
-
const root = await mkdtemp(join(tmpdir(), "core-plugin-config-loader-"));
|
|
69
|
-
try {
|
|
70
|
-
const pluginDir = join(root, "plugin-package");
|
|
71
|
-
const srcDir = join(pluginDir, "src");
|
|
72
|
-
await mkdir(srcDir, { recursive: true });
|
|
73
|
-
const declaredEntry = join(srcDir, "index.ts");
|
|
74
|
-
const ignoredEntry = join(pluginDir, "ignored.mjs");
|
|
75
|
-
await writeFile(
|
|
76
|
-
join(pluginDir, "package.json"),
|
|
77
|
-
JSON.stringify({
|
|
78
|
-
name: "plugin-package",
|
|
79
|
-
private: true,
|
|
80
|
-
cline: {
|
|
81
|
-
plugins: ["./src/index.ts"],
|
|
82
|
-
},
|
|
83
|
-
}),
|
|
84
|
-
"utf8",
|
|
85
|
-
);
|
|
86
|
-
await writeFile(declaredEntry, "export default {}", "utf8");
|
|
87
|
-
await writeFile(ignoredEntry, "export default {}", "utf8");
|
|
88
|
-
|
|
89
|
-
const resolved = resolveAgentPluginPaths({
|
|
90
|
-
pluginPaths: ["./plugin-package"],
|
|
91
|
-
cwd: root,
|
|
92
|
-
workspacePath: join(root, "workspace"),
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(resolved).toContain(declaredEntry);
|
|
96
|
-
expect(resolved).not.toContain(ignoredEntry);
|
|
97
|
-
} finally {
|
|
98
|
-
await rm(root, { recursive: true, force: true });
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("includes shared search-path plugins", async () => {
|
|
103
|
-
const home = await mkdtemp(
|
|
104
|
-
join(tmpdir(), "core-plugin-config-loader-home-"),
|
|
105
|
-
);
|
|
106
|
-
const workspace = await mkdtemp(
|
|
107
|
-
join(tmpdir(), "core-plugin-config-loader-workspace-"),
|
|
108
|
-
);
|
|
109
|
-
try {
|
|
110
|
-
process.env.HOME = home;
|
|
111
|
-
setHomeDir(home);
|
|
112
|
-
const workspacePlugins = join(workspace, ".clinerules", "plugins");
|
|
113
|
-
const userPlugins = join(home, ".cline", "plugins");
|
|
114
|
-
const documentsPlugins = join(home, "Documents", "Plugins");
|
|
115
|
-
await mkdir(workspacePlugins, { recursive: true });
|
|
116
|
-
await mkdir(userPlugins, { recursive: true });
|
|
117
|
-
await mkdir(documentsPlugins, { recursive: true });
|
|
118
|
-
const workspacePlugin = join(workspacePlugins, "workspace.mjs");
|
|
119
|
-
const userPlugin = join(userPlugins, "user.mjs");
|
|
120
|
-
const documentsPlugin = join(documentsPlugins, "documents.mjs");
|
|
121
|
-
await writeFile(workspacePlugin, "export default {}", "utf8");
|
|
122
|
-
await writeFile(userPlugin, "export default {}", "utf8");
|
|
123
|
-
await writeFile(documentsPlugin, "export default {}", "utf8");
|
|
124
|
-
|
|
125
|
-
const searchPaths = resolvePluginConfigSearchPaths(workspace);
|
|
126
|
-
expect(searchPaths).toHaveLength(3);
|
|
127
|
-
expect(searchPaths).toContain(workspacePlugins);
|
|
128
|
-
expect(searchPaths).toContain(userPlugins);
|
|
129
|
-
expect(searchPaths).toContain(documentsPlugins);
|
|
130
|
-
|
|
131
|
-
const resolved = resolveAgentPluginPaths({ workspacePath: workspace });
|
|
132
|
-
expect(resolved).toContain(workspacePlugin);
|
|
133
|
-
expect(resolved).toContain(userPlugin);
|
|
134
|
-
expect(resolved).toContain(documentsPlugin);
|
|
135
|
-
} finally {
|
|
136
|
-
await rm(home, { recursive: true, force: true });
|
|
137
|
-
await rm(workspace, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import type { AgentConfig } from "@clinebot/agents";
|
|
3
|
-
import {
|
|
4
|
-
discoverPluginModulePaths as discoverPluginModulePathsFromShared,
|
|
5
|
-
resolveConfiguredPluginModulePaths,
|
|
6
|
-
resolvePluginConfigSearchPaths as resolvePluginConfigSearchPathsFromShared,
|
|
7
|
-
} from "@clinebot/shared/storage";
|
|
8
|
-
import { loadAgentPluginsFromPaths } from "./plugin-loader";
|
|
9
|
-
import { loadSandboxedPlugins } from "./plugin-sandbox";
|
|
10
|
-
|
|
11
|
-
type AgentPlugin = NonNullable<AgentConfig["extensions"]>[number];
|
|
12
|
-
|
|
13
|
-
export function resolvePluginConfigSearchPaths(
|
|
14
|
-
workspacePath?: string,
|
|
15
|
-
): string[] {
|
|
16
|
-
return resolvePluginConfigSearchPathsFromShared(workspacePath);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function discoverPluginModulePaths(directoryPath: string): string[] {
|
|
20
|
-
return discoverPluginModulePathsFromShared(directoryPath);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ResolveAgentPluginPathsOptions {
|
|
24
|
-
pluginPaths?: ReadonlyArray<string>;
|
|
25
|
-
workspacePath?: string;
|
|
26
|
-
cwd?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function resolveAgentPluginPaths(
|
|
30
|
-
options: ResolveAgentPluginPathsOptions = {},
|
|
31
|
-
): string[] {
|
|
32
|
-
const cwd = options.cwd ?? process.cwd();
|
|
33
|
-
const discoveredFromSearchPaths = resolvePluginConfigSearchPaths(
|
|
34
|
-
options.workspacePath,
|
|
35
|
-
)
|
|
36
|
-
.flatMap((directoryPath) => discoverPluginModulePaths(directoryPath))
|
|
37
|
-
.filter((path) => existsSync(path));
|
|
38
|
-
const configuredPaths = resolveConfiguredPluginModulePaths(
|
|
39
|
-
options.pluginPaths ?? [],
|
|
40
|
-
cwd,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const deduped: string[] = [];
|
|
44
|
-
const seen = new Set<string>();
|
|
45
|
-
for (const path of [...configuredPaths, ...discoveredFromSearchPaths]) {
|
|
46
|
-
if (seen.has(path)) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
seen.add(path);
|
|
50
|
-
deduped.push(path);
|
|
51
|
-
}
|
|
52
|
-
return deduped;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface ResolveAndLoadAgentPluginsOptions
|
|
56
|
-
extends ResolveAgentPluginPathsOptions {
|
|
57
|
-
mode?: "sandbox" | "in_process";
|
|
58
|
-
exportName?: string;
|
|
59
|
-
importTimeoutMs?: number;
|
|
60
|
-
hookTimeoutMs?: number;
|
|
61
|
-
contributionTimeoutMs?: number;
|
|
62
|
-
onEvent?: (event: { name: string; payload?: unknown }) => void;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function resolveAndLoadAgentPlugins(
|
|
66
|
-
options: ResolveAndLoadAgentPluginsOptions = {},
|
|
67
|
-
): Promise<{
|
|
68
|
-
extensions: AgentPlugin[];
|
|
69
|
-
shutdown?: () => Promise<void>;
|
|
70
|
-
}> {
|
|
71
|
-
const paths = resolveAgentPluginPaths(options);
|
|
72
|
-
if (paths.length === 0) {
|
|
73
|
-
return { extensions: [] };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (options.mode === "in_process") {
|
|
77
|
-
return {
|
|
78
|
-
extensions: await loadAgentPluginsFromPaths(paths, {
|
|
79
|
-
cwd: options.cwd,
|
|
80
|
-
exportName: options.exportName,
|
|
81
|
-
}),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const sandboxed = await loadSandboxedPlugins({
|
|
86
|
-
pluginPaths: paths,
|
|
87
|
-
exportName: options.exportName,
|
|
88
|
-
importTimeoutMs: options.importTimeoutMs,
|
|
89
|
-
hookTimeoutMs: options.hookTimeoutMs,
|
|
90
|
-
contributionTimeoutMs: options.contributionTimeoutMs,
|
|
91
|
-
onEvent: options.onEvent,
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
extensions: sandboxed.extensions ?? [],
|
|
95
|
-
shutdown: sandboxed.shutdown,
|
|
96
|
-
};
|
|
97
|
-
}
|