@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,196 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, unlink, writeFile } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { basename, join } from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import {
|
|
6
|
-
type AgentYamlConfig,
|
|
7
|
-
parseAgentConfigFromYaml,
|
|
8
|
-
} from "./agent-config-loader";
|
|
9
|
-
import {
|
|
10
|
-
UnifiedConfigFileWatcher,
|
|
11
|
-
type UnifiedConfigWatcherEvent,
|
|
12
|
-
} from "./unified-config-file-watcher";
|
|
13
|
-
|
|
14
|
-
const WAIT_TIMEOUT_MS = 8_000;
|
|
15
|
-
const WAIT_INTERVAL_MS = 25;
|
|
16
|
-
|
|
17
|
-
async function waitForEvent<TType extends string, TItem>(
|
|
18
|
-
events: Array<UnifiedConfigWatcherEvent<TType, TItem>>,
|
|
19
|
-
predicate: (event: UnifiedConfigWatcherEvent<TType, TItem>) => boolean,
|
|
20
|
-
timeoutMs = WAIT_TIMEOUT_MS,
|
|
21
|
-
): Promise<UnifiedConfigWatcherEvent<TType, TItem>> {
|
|
22
|
-
const startedAt = Date.now();
|
|
23
|
-
while (Date.now() - startedAt < timeoutMs) {
|
|
24
|
-
const match = events.find(predicate);
|
|
25
|
-
if (match) {
|
|
26
|
-
return match;
|
|
27
|
-
}
|
|
28
|
-
await new Promise((resolve) => setTimeout(resolve, WAIT_INTERVAL_MS));
|
|
29
|
-
}
|
|
30
|
-
throw new Error("Timed out waiting for watcher event.");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("UnifiedConfigFileWatcher", () => {
|
|
34
|
-
const tempRoots: string[] = [];
|
|
35
|
-
|
|
36
|
-
afterEach(async () => {
|
|
37
|
-
await Promise.all(
|
|
38
|
-
tempRoots.map((dir) => rm(dir, { recursive: true, force: true })),
|
|
39
|
-
);
|
|
40
|
-
tempRoots.length = 0;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("emits upsert and remove events with config type for agent configs", async () => {
|
|
44
|
-
const tempRoot = await mkdtemp(
|
|
45
|
-
join(tmpdir(), "core-unified-config-watcher-"),
|
|
46
|
-
);
|
|
47
|
-
tempRoots.push(tempRoot);
|
|
48
|
-
const agentsDir = join(tempRoot, "agents");
|
|
49
|
-
await mkdir(agentsDir, { recursive: true });
|
|
50
|
-
const agentFilePath = join(agentsDir, "reviewer.yaml");
|
|
51
|
-
await writeFile(
|
|
52
|
-
agentFilePath,
|
|
53
|
-
`---
|
|
54
|
-
name: Reviewer
|
|
55
|
-
description: Reviews patches
|
|
56
|
-
tools: read_files
|
|
57
|
-
---
|
|
58
|
-
Review code carefully.`,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const watcher = new UnifiedConfigFileWatcher([
|
|
62
|
-
{
|
|
63
|
-
type: "agent" as const,
|
|
64
|
-
directories: [agentsDir],
|
|
65
|
-
includeFile: (fileName) => /\.(yaml|yml)$/i.test(fileName),
|
|
66
|
-
parseFile: (context) => parseAgentConfigFromYaml(context.content),
|
|
67
|
-
resolveId: (config) => config.name.toLowerCase(),
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
const events: Array<
|
|
72
|
-
UnifiedConfigWatcherEvent<
|
|
73
|
-
"agent",
|
|
74
|
-
ReturnType<typeof parseAgentConfigFromYaml>
|
|
75
|
-
>
|
|
76
|
-
> = [];
|
|
77
|
-
const unsubscribe = watcher.subscribe((event) => events.push(event));
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
await watcher.start();
|
|
81
|
-
await waitForEvent(
|
|
82
|
-
events,
|
|
83
|
-
(event) => event.kind === "upsert" && event.record.id === "reviewer",
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
events.length = 0;
|
|
87
|
-
await writeFile(
|
|
88
|
-
agentFilePath,
|
|
89
|
-
`---
|
|
90
|
-
name: Reviewer
|
|
91
|
-
description: Reviews patches
|
|
92
|
-
---
|
|
93
|
-
Review code with strictness.`,
|
|
94
|
-
);
|
|
95
|
-
await watcher.refreshType("agent");
|
|
96
|
-
await waitForEvent(
|
|
97
|
-
events,
|
|
98
|
-
(event) => event.kind === "upsert" && event.record.type === "agent",
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
events.length = 0;
|
|
102
|
-
await unlink(agentFilePath);
|
|
103
|
-
await watcher.refreshType("agent");
|
|
104
|
-
await waitForEvent(
|
|
105
|
-
events,
|
|
106
|
-
(event) => event.kind === "remove" && event.type === "agent",
|
|
107
|
-
);
|
|
108
|
-
} finally {
|
|
109
|
-
unsubscribe();
|
|
110
|
-
watcher.stop();
|
|
111
|
-
}
|
|
112
|
-
}, 15_000);
|
|
113
|
-
|
|
114
|
-
it("supports one watcher instance for multiple config types", async () => {
|
|
115
|
-
const tempRoot = await mkdtemp(
|
|
116
|
-
join(tmpdir(), "core-unified-config-watcher-"),
|
|
117
|
-
);
|
|
118
|
-
tempRoots.push(tempRoot);
|
|
119
|
-
const agentsDir = join(tempRoot, "agents");
|
|
120
|
-
const skillsDir = join(tempRoot, "skills");
|
|
121
|
-
await mkdir(agentsDir, { recursive: true });
|
|
122
|
-
await mkdir(skillsDir, { recursive: true });
|
|
123
|
-
|
|
124
|
-
await writeFile(
|
|
125
|
-
join(agentsDir, "researcher.yaml"),
|
|
126
|
-
`---
|
|
127
|
-
name: Researcher
|
|
128
|
-
description: Finds context
|
|
129
|
-
---
|
|
130
|
-
Investigate related code paths.`,
|
|
131
|
-
);
|
|
132
|
-
await writeFile(
|
|
133
|
-
join(skillsDir, "SKILL.md"),
|
|
134
|
-
`---
|
|
135
|
-
name: incident-response
|
|
136
|
-
description: Handle incidents
|
|
137
|
-
---
|
|
138
|
-
Escalation playbook`,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const watcher = new UnifiedConfigFileWatcher<
|
|
142
|
-
"agent" | "skill",
|
|
143
|
-
AgentYamlConfig | { path: string }
|
|
144
|
-
>([
|
|
145
|
-
{
|
|
146
|
-
type: "agent" as const,
|
|
147
|
-
directories: [agentsDir],
|
|
148
|
-
includeFile: (fileName) => /\.(yaml|yml)$/i.test(fileName),
|
|
149
|
-
parseFile: (context) =>
|
|
150
|
-
parseAgentConfigFromYaml(context.content) as
|
|
151
|
-
| AgentYamlConfig
|
|
152
|
-
| { path: string },
|
|
153
|
-
resolveId: (config) =>
|
|
154
|
-
"name" in config ? config.name.toLowerCase() : "invalid-agent-config",
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
type: "skill" as const,
|
|
158
|
-
directories: [skillsDir],
|
|
159
|
-
includeFile: (fileName) => fileName === "SKILL.md",
|
|
160
|
-
parseFile: (context) => ({ path: context.filePath }),
|
|
161
|
-
resolveId: (_parsed, context) => basename(context.directoryPath),
|
|
162
|
-
},
|
|
163
|
-
]);
|
|
164
|
-
|
|
165
|
-
const events: Array<
|
|
166
|
-
UnifiedConfigWatcherEvent<
|
|
167
|
-
"agent" | "skill",
|
|
168
|
-
AgentYamlConfig | { path: string }
|
|
169
|
-
>
|
|
170
|
-
> = [];
|
|
171
|
-
const unsubscribe = watcher.subscribe((event) => events.push(event));
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
await watcher.start();
|
|
175
|
-
await waitForEvent(
|
|
176
|
-
events,
|
|
177
|
-
(event) =>
|
|
178
|
-
event.kind === "upsert" &&
|
|
179
|
-
(event.record.type === "agent" || event.record.type === "skill"),
|
|
180
|
-
);
|
|
181
|
-
expect(
|
|
182
|
-
events.some(
|
|
183
|
-
(event) => event.kind === "upsert" && event.record.type === "agent",
|
|
184
|
-
),
|
|
185
|
-
).toBe(true);
|
|
186
|
-
expect(
|
|
187
|
-
events.some(
|
|
188
|
-
(event) => event.kind === "upsert" && event.record.type === "skill",
|
|
189
|
-
),
|
|
190
|
-
).toBe(true);
|
|
191
|
-
} finally {
|
|
192
|
-
unsubscribe();
|
|
193
|
-
watcher.stop();
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { type FSWatcher, watch } from "node:fs";
|
|
3
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
export interface UnifiedConfigFileContext<TType extends string = string> {
|
|
7
|
-
type: TType;
|
|
8
|
-
directoryPath: string;
|
|
9
|
-
fileName: string;
|
|
10
|
-
filePath: string;
|
|
11
|
-
content: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface UnifiedConfigFileCandidate {
|
|
15
|
-
directoryPath: string;
|
|
16
|
-
fileName: string;
|
|
17
|
-
filePath: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface UnifiedConfigDefinition<
|
|
21
|
-
TType extends string = string,
|
|
22
|
-
TItem = unknown,
|
|
23
|
-
> {
|
|
24
|
-
type: TType;
|
|
25
|
-
directories: ReadonlyArray<string>;
|
|
26
|
-
discoverFiles?: (
|
|
27
|
-
directoryPath: string,
|
|
28
|
-
) => Promise<ReadonlyArray<UnifiedConfigFileCandidate>>;
|
|
29
|
-
includeFile?: (fileName: string, filePath: string) => boolean;
|
|
30
|
-
parseFile: (context: UnifiedConfigFileContext<TType>) => TItem;
|
|
31
|
-
resolveId: (item: TItem, context: UnifiedConfigFileContext<TType>) => string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface UnifiedConfigWatcherOptions {
|
|
35
|
-
debounceMs?: number;
|
|
36
|
-
emitParseErrors?: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface UnifiedConfigRecord<
|
|
40
|
-
TType extends string = string,
|
|
41
|
-
TItem = unknown,
|
|
42
|
-
> {
|
|
43
|
-
type: TType;
|
|
44
|
-
id: string;
|
|
45
|
-
item: TItem;
|
|
46
|
-
filePath: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type UnifiedConfigWatcherEvent<
|
|
50
|
-
TType extends string = string,
|
|
51
|
-
TItem = unknown,
|
|
52
|
-
> =
|
|
53
|
-
| {
|
|
54
|
-
kind: "upsert";
|
|
55
|
-
record: UnifiedConfigRecord<TType, TItem>;
|
|
56
|
-
}
|
|
57
|
-
| {
|
|
58
|
-
kind: "remove";
|
|
59
|
-
type: TType;
|
|
60
|
-
id: string;
|
|
61
|
-
filePath: string;
|
|
62
|
-
}
|
|
63
|
-
| {
|
|
64
|
-
kind: "error";
|
|
65
|
-
type: TType;
|
|
66
|
-
error: unknown;
|
|
67
|
-
filePath?: string;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
interface InternalRecord<TType extends string, TItem>
|
|
71
|
-
extends UnifiedConfigRecord<TType, TItem> {
|
|
72
|
-
fingerprint: string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function toFingerprint(content: string): string {
|
|
76
|
-
return createHash("sha1").update(content).digest("hex");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function isErrnoException(error: unknown): error is NodeJS.ErrnoException {
|
|
80
|
-
return Boolean(error && typeof error === "object" && "code" in error);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function isMissingDirectoryError(error: unknown): boolean {
|
|
84
|
-
return isErrnoException(error) && error.code === "ENOENT";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export class UnifiedConfigFileWatcher<
|
|
88
|
-
TType extends string = string,
|
|
89
|
-
TItem = unknown,
|
|
90
|
-
> {
|
|
91
|
-
private readonly definitions: ReadonlyArray<
|
|
92
|
-
UnifiedConfigDefinition<TType, TItem>
|
|
93
|
-
>;
|
|
94
|
-
private readonly debounceMs: number;
|
|
95
|
-
private readonly emitParseErrors: boolean;
|
|
96
|
-
private readonly listeners = new Set<
|
|
97
|
-
(event: UnifiedConfigWatcherEvent<TType, TItem>) => void
|
|
98
|
-
>();
|
|
99
|
-
private readonly recordsByType = new Map<
|
|
100
|
-
TType,
|
|
101
|
-
Map<string, InternalRecord<TType, TItem>>
|
|
102
|
-
>();
|
|
103
|
-
private readonly watchersByDirectory = new Map<string, FSWatcher>();
|
|
104
|
-
private readonly baseTypesByDirectory = new Map<string, Set<TType>>();
|
|
105
|
-
private watchedTypesByDirectory = new Map<string, Set<TType>>();
|
|
106
|
-
private readonly discoveredDirectoriesByType = new Map<TType, Set<string>>();
|
|
107
|
-
private readonly definitionsByType = new Map<
|
|
108
|
-
TType,
|
|
109
|
-
UnifiedConfigDefinition<TType, TItem>
|
|
110
|
-
>();
|
|
111
|
-
private readonly pendingTypes = new Set<TType>();
|
|
112
|
-
private flushTimer: NodeJS.Timeout | undefined;
|
|
113
|
-
private refreshQueue: Promise<void> = Promise.resolve();
|
|
114
|
-
private started = false;
|
|
115
|
-
|
|
116
|
-
constructor(
|
|
117
|
-
definitions: ReadonlyArray<UnifiedConfigDefinition<TType, TItem>>,
|
|
118
|
-
options?: UnifiedConfigWatcherOptions,
|
|
119
|
-
) {
|
|
120
|
-
if (definitions.length === 0) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
"UnifiedConfigFileWatcher requires at least one definition.",
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.definitions = definitions;
|
|
127
|
-
this.debounceMs = options?.debounceMs ?? 75;
|
|
128
|
-
this.emitParseErrors = options?.emitParseErrors ?? false;
|
|
129
|
-
|
|
130
|
-
for (const definition of definitions) {
|
|
131
|
-
if (this.definitionsByType.has(definition.type)) {
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Duplicate unified config definition type '${definition.type}'.`,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
this.definitionsByType.set(definition.type, definition);
|
|
137
|
-
this.recordsByType.set(definition.type, new Map());
|
|
138
|
-
this.discoveredDirectoriesByType.set(definition.type, new Set());
|
|
139
|
-
for (const directoryPath of definition.directories) {
|
|
140
|
-
const existing = this.baseTypesByDirectory.get(directoryPath);
|
|
141
|
-
if (existing) {
|
|
142
|
-
existing.add(definition.type);
|
|
143
|
-
} else {
|
|
144
|
-
this.baseTypesByDirectory.set(
|
|
145
|
-
directoryPath,
|
|
146
|
-
new Set([definition.type]),
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
subscribe(
|
|
154
|
-
listener: (event: UnifiedConfigWatcherEvent<TType, TItem>) => void,
|
|
155
|
-
): () => void {
|
|
156
|
-
this.listeners.add(listener);
|
|
157
|
-
return () => {
|
|
158
|
-
this.listeners.delete(listener);
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async start(): Promise<void> {
|
|
163
|
-
if (this.started) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this.started = true;
|
|
167
|
-
await this.refreshAll();
|
|
168
|
-
this.startDirectoryWatchers();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
stop(): void {
|
|
172
|
-
this.started = false;
|
|
173
|
-
if (this.flushTimer) {
|
|
174
|
-
clearTimeout(this.flushTimer);
|
|
175
|
-
this.flushTimer = undefined;
|
|
176
|
-
}
|
|
177
|
-
this.pendingTypes.clear();
|
|
178
|
-
for (const watcher of this.watchersByDirectory.values()) {
|
|
179
|
-
watcher.close();
|
|
180
|
-
}
|
|
181
|
-
this.watchersByDirectory.clear();
|
|
182
|
-
this.watchedTypesByDirectory = new Map();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async refreshAll(): Promise<void> {
|
|
186
|
-
await this.enqueueRefresh(async () => {
|
|
187
|
-
for (const definition of this.definitions) {
|
|
188
|
-
await this.refreshTypeInternal(definition);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async refreshType(type: TType): Promise<void> {
|
|
194
|
-
const definition = this.definitionsByType.get(type);
|
|
195
|
-
if (!definition) {
|
|
196
|
-
throw new Error(`Unknown unified config type '${type}'.`);
|
|
197
|
-
}
|
|
198
|
-
await this.enqueueRefresh(async () => {
|
|
199
|
-
await this.refreshTypeInternal(definition);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
getSnapshot(type: TType): Map<string, UnifiedConfigRecord<TType, TItem>> {
|
|
204
|
-
const records = this.recordsByType.get(type);
|
|
205
|
-
return new Map(
|
|
206
|
-
[...(records?.entries() ?? [])].map(([id, record]) => [
|
|
207
|
-
id,
|
|
208
|
-
{ ...record },
|
|
209
|
-
]),
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
getAllSnapshots(): Map<
|
|
214
|
-
TType,
|
|
215
|
-
Map<string, UnifiedConfigRecord<TType, TItem>>
|
|
216
|
-
> {
|
|
217
|
-
const snapshot = new Map<
|
|
218
|
-
TType,
|
|
219
|
-
Map<string, UnifiedConfigRecord<TType, TItem>>
|
|
220
|
-
>();
|
|
221
|
-
for (const [type, records] of this.recordsByType.entries()) {
|
|
222
|
-
snapshot.set(
|
|
223
|
-
type,
|
|
224
|
-
new Map(
|
|
225
|
-
[...records.entries()].map(([id, record]) => [id, { ...record }]),
|
|
226
|
-
),
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
return snapshot;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private emit(event: UnifiedConfigWatcherEvent<TType, TItem>): void {
|
|
233
|
-
for (const listener of this.listeners) {
|
|
234
|
-
listener(event);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private enqueueRefresh(action: () => Promise<void>): Promise<void> {
|
|
239
|
-
this.refreshQueue = this.refreshQueue.then(action, action);
|
|
240
|
-
return this.refreshQueue;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private startDirectoryWatchers(): void {
|
|
244
|
-
this.syncDirectoryWatchers();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private syncDirectoryWatchers(): void {
|
|
248
|
-
const desiredTypesByDirectory = this.buildDesiredTypesByDirectory();
|
|
249
|
-
|
|
250
|
-
for (const [directoryPath, watcher] of this.watchersByDirectory.entries()) {
|
|
251
|
-
if (desiredTypesByDirectory.has(directoryPath)) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
watcher.close();
|
|
255
|
-
this.watchersByDirectory.delete(directoryPath);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
this.watchedTypesByDirectory = desiredTypesByDirectory;
|
|
259
|
-
|
|
260
|
-
for (const directoryPath of desiredTypesByDirectory.keys()) {
|
|
261
|
-
if (this.watchersByDirectory.has(directoryPath)) {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
const watcher = watch(directoryPath, () => {
|
|
267
|
-
const types = this.watchedTypesByDirectory.get(directoryPath);
|
|
268
|
-
if (!types) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
for (const type of types) {
|
|
272
|
-
this.pendingTypes.add(type);
|
|
273
|
-
}
|
|
274
|
-
this.scheduleFlush();
|
|
275
|
-
});
|
|
276
|
-
this.watchersByDirectory.set(directoryPath, watcher);
|
|
277
|
-
watcher.on("error", (error) => {
|
|
278
|
-
const types = this.watchedTypesByDirectory.get(directoryPath);
|
|
279
|
-
if (!types) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
for (const type of types) {
|
|
283
|
-
this.emit({
|
|
284
|
-
kind: "error",
|
|
285
|
-
type,
|
|
286
|
-
error,
|
|
287
|
-
filePath: directoryPath,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
} catch (error) {
|
|
292
|
-
if (!isMissingDirectoryError(error)) {
|
|
293
|
-
const types = desiredTypesByDirectory.get(directoryPath);
|
|
294
|
-
if (!types) {
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
for (const type of types) {
|
|
298
|
-
this.emit({
|
|
299
|
-
kind: "error",
|
|
300
|
-
type,
|
|
301
|
-
error,
|
|
302
|
-
filePath: directoryPath,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
private scheduleFlush(): void {
|
|
311
|
-
if (this.flushTimer) {
|
|
312
|
-
clearTimeout(this.flushTimer);
|
|
313
|
-
}
|
|
314
|
-
this.flushTimer = setTimeout(() => {
|
|
315
|
-
this.flushTimer = undefined;
|
|
316
|
-
const types = [...this.pendingTypes];
|
|
317
|
-
this.pendingTypes.clear();
|
|
318
|
-
void this.enqueueRefresh(async () => {
|
|
319
|
-
for (const type of types) {
|
|
320
|
-
const definition = this.definitionsByType.get(type);
|
|
321
|
-
if (!definition) {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
await this.refreshTypeInternal(definition);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}, this.debounceMs);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private async refreshTypeInternal(
|
|
331
|
-
definition: UnifiedConfigDefinition<TType, TItem>,
|
|
332
|
-
): Promise<void> {
|
|
333
|
-
const { records: nextRecords, discoveredDirectories } =
|
|
334
|
-
await this.loadDefinition(definition);
|
|
335
|
-
const previousRecords =
|
|
336
|
-
this.recordsByType.get(definition.type) ??
|
|
337
|
-
new Map<string, InternalRecord<TType, TItem>>();
|
|
338
|
-
|
|
339
|
-
for (const [id, previousRecord] of previousRecords.entries()) {
|
|
340
|
-
if (nextRecords.has(id)) {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
this.emit({
|
|
344
|
-
kind: "remove",
|
|
345
|
-
type: definition.type,
|
|
346
|
-
id,
|
|
347
|
-
filePath: previousRecord.filePath,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
for (const [id, nextRecord] of nextRecords.entries()) {
|
|
352
|
-
const previousRecord = previousRecords.get(id);
|
|
353
|
-
if (
|
|
354
|
-
previousRecord &&
|
|
355
|
-
previousRecord.filePath === nextRecord.filePath &&
|
|
356
|
-
previousRecord.fingerprint === nextRecord.fingerprint
|
|
357
|
-
) {
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
this.emit({
|
|
361
|
-
kind: "upsert",
|
|
362
|
-
record: {
|
|
363
|
-
type: nextRecord.type,
|
|
364
|
-
id,
|
|
365
|
-
item: nextRecord.item,
|
|
366
|
-
filePath: nextRecord.filePath,
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
this.recordsByType.set(definition.type, nextRecords);
|
|
372
|
-
this.discoveredDirectoriesByType.set(
|
|
373
|
-
definition.type,
|
|
374
|
-
discoveredDirectories,
|
|
375
|
-
);
|
|
376
|
-
if (this.started) {
|
|
377
|
-
this.syncDirectoryWatchers();
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
private async loadDefinition(
|
|
382
|
-
definition: UnifiedConfigDefinition<TType, TItem>,
|
|
383
|
-
): Promise<{
|
|
384
|
-
records: Map<string, InternalRecord<TType, TItem>>;
|
|
385
|
-
discoveredDirectories: Set<string>;
|
|
386
|
-
}> {
|
|
387
|
-
const records = new Map<string, InternalRecord<TType, TItem>>();
|
|
388
|
-
const discoveredDirectories = new Set<string>();
|
|
389
|
-
|
|
390
|
-
for (const directoryPath of definition.directories) {
|
|
391
|
-
discoveredDirectories.add(directoryPath);
|
|
392
|
-
const fileCandidates = definition.discoverFiles
|
|
393
|
-
? await definition.discoverFiles(directoryPath)
|
|
394
|
-
: await this.readDirectoryFileCandidates(directoryPath);
|
|
395
|
-
|
|
396
|
-
for (const candidate of fileCandidates) {
|
|
397
|
-
const fileName = candidate.fileName;
|
|
398
|
-
const filePath = candidate.filePath;
|
|
399
|
-
discoveredDirectories.add(candidate.directoryPath);
|
|
400
|
-
if (
|
|
401
|
-
definition.includeFile &&
|
|
402
|
-
!definition.includeFile(fileName, filePath)
|
|
403
|
-
) {
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
try {
|
|
407
|
-
const content = await readFile(filePath, "utf8");
|
|
408
|
-
const context: UnifiedConfigFileContext<TType> = {
|
|
409
|
-
type: definition.type,
|
|
410
|
-
directoryPath: candidate.directoryPath,
|
|
411
|
-
fileName,
|
|
412
|
-
filePath,
|
|
413
|
-
content,
|
|
414
|
-
};
|
|
415
|
-
const parsed = definition.parseFile(context);
|
|
416
|
-
const id = definition.resolveId(parsed, context).trim();
|
|
417
|
-
if (!id) {
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
records.set(id, {
|
|
421
|
-
type: definition.type,
|
|
422
|
-
id,
|
|
423
|
-
item: parsed,
|
|
424
|
-
filePath,
|
|
425
|
-
fingerprint: toFingerprint(content),
|
|
426
|
-
});
|
|
427
|
-
} catch (error) {
|
|
428
|
-
if (this.emitParseErrors) {
|
|
429
|
-
this.emit({
|
|
430
|
-
kind: "error",
|
|
431
|
-
type: definition.type,
|
|
432
|
-
error,
|
|
433
|
-
filePath,
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return { records, discoveredDirectories };
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
private buildDesiredTypesByDirectory(): Map<string, Set<TType>> {
|
|
443
|
-
const desired = new Map<string, Set<TType>>();
|
|
444
|
-
for (const [directoryPath, types] of this.baseTypesByDirectory.entries()) {
|
|
445
|
-
desired.set(directoryPath, new Set(types));
|
|
446
|
-
}
|
|
447
|
-
for (const [
|
|
448
|
-
type,
|
|
449
|
-
directories,
|
|
450
|
-
] of this.discoveredDirectoriesByType.entries()) {
|
|
451
|
-
for (const directoryPath of directories) {
|
|
452
|
-
const existing = desired.get(directoryPath);
|
|
453
|
-
if (existing) {
|
|
454
|
-
existing.add(type);
|
|
455
|
-
} else {
|
|
456
|
-
desired.set(directoryPath, new Set([type]));
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return desired;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
private async readDirectoryFileCandidates(
|
|
464
|
-
directoryPath: string,
|
|
465
|
-
): Promise<UnifiedConfigFileCandidate[]> {
|
|
466
|
-
try {
|
|
467
|
-
const entries = await readdir(directoryPath, { withFileTypes: true });
|
|
468
|
-
return entries
|
|
469
|
-
.filter((entry) => entry.isFile())
|
|
470
|
-
.map((entry) => ({
|
|
471
|
-
directoryPath,
|
|
472
|
-
fileName: entry.name,
|
|
473
|
-
filePath: join(directoryPath, entry.name),
|
|
474
|
-
}))
|
|
475
|
-
.sort((a, b) => a.fileName.localeCompare(b.fileName));
|
|
476
|
-
} catch (error) {
|
|
477
|
-
if (isMissingDirectoryError(error)) {
|
|
478
|
-
return [];
|
|
479
|
-
}
|
|
480
|
-
throw error;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|