@clinebot/core 0.0.18 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/cline-account-service.d.ts +3 -2
- package/dist/account/cline-account-service.d.ts.map +1 -0
- package/dist/account/index.d.ts +1 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/rpc.d.ts +1 -0
- package/dist/account/rpc.d.ts.map +1 -0
- package/dist/account/types.d.ts +1 -0
- package/dist/account/types.d.ts.map +1 -0
- package/dist/agents/agent-config-loader.d.ts +1 -0
- package/dist/agents/agent-config-loader.d.ts.map +1 -0
- package/dist/agents/agent-config-parser.d.ts +1 -0
- package/dist/agents/agent-config-parser.d.ts.map +1 -0
- package/dist/agents/hooks-config-loader.d.ts +1 -0
- package/dist/agents/hooks-config-loader.d.ts.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/plugin-config-loader.d.ts +1 -0
- package/dist/agents/plugin-config-loader.d.ts.map +1 -0
- package/dist/agents/plugin-loader.d.ts +1 -0
- package/dist/agents/plugin-loader.d.ts.map +1 -0
- package/dist/agents/plugin-sandbox.d.ts +1 -0
- package/dist/agents/plugin-sandbox.d.ts.map +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts +1 -0
- package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts +1 -0
- package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/cline.d.ts +1 -0
- package/dist/auth/cline.d.ts.map +1 -0
- package/dist/auth/codex.d.ts +1 -0
- package/dist/auth/codex.d.ts.map +1 -0
- package/dist/auth/oca.d.ts +1 -0
- package/dist/auth/oca.d.ts.map +1 -0
- package/dist/auth/server.d.ts +1 -0
- package/dist/auth/server.d.ts.map +1 -0
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/chat/chat-schema.d.ts +13 -12
- package/dist/chat/chat-schema.d.ts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +2 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +303 -302
- package/dist/input/file-indexer.d.ts +1 -0
- package/dist/input/file-indexer.d.ts.map +1 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/mention-enricher.d.ts +1 -0
- package/dist/input/mention-enricher.d.ts.map +1 -0
- package/dist/mcp/config-loader.d.ts +1 -0
- package/dist/mcp/config-loader.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/manager.d.ts +1 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/providers/local-provider-registry.d.ts +36 -0
- package/dist/providers/local-provider-registry.d.ts.map +1 -0
- package/dist/providers/local-provider-service.d.ts +2 -1
- package/dist/providers/local-provider-service.d.ts.map +1 -0
- package/dist/runtime/commands.d.ts +1 -0
- package/dist/runtime/commands.d.ts.map +1 -0
- package/dist/runtime/hook-file-hooks.d.ts +1 -0
- package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -0
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
- package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
- package/dist/runtime/session-runtime.d.ts +2 -0
- package/dist/runtime/session-runtime.d.ts.map +1 -0
- package/dist/runtime/skills.d.ts +1 -0
- package/dist/runtime/skills.d.ts.map +1 -0
- package/dist/runtime/tool-approval.d.ts +1 -0
- package/dist/runtime/tool-approval.d.ts.map +1 -0
- package/dist/runtime/workflows.d.ts +1 -0
- package/dist/runtime/workflows.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +4 -0
- package/dist/session/default-session-manager.d.ts.map +1 -0
- package/dist/session/file-session-service.d.ts +1 -0
- package/dist/session/file-session-service.d.ts.map +1 -0
- package/dist/session/rpc-session-service.d.ts +1 -0
- package/dist/session/rpc-session-service.d.ts.map +1 -0
- package/dist/session/rpc-spawn-lease.d.ts +1 -0
- package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
- package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
- package/dist/session/session-agent-events.d.ts +20 -1
- package/dist/session/session-agent-events.d.ts.map +1 -0
- package/dist/session/session-artifacts.d.ts +1 -0
- package/dist/session/session-artifacts.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +1 -0
- package/dist/session/session-config-builder.d.ts.map +1 -0
- package/dist/session/session-graph.d.ts +1 -0
- package/dist/session/session-graph.d.ts.map +1 -0
- package/dist/session/session-host.d.ts +1 -0
- package/dist/session/session-host.d.ts.map +1 -0
- package/dist/session/session-manager.d.ts +1 -0
- package/dist/session/session-manager.d.ts.map +1 -0
- package/dist/session/session-manifest.d.ts +2 -1
- package/dist/session/session-manifest.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +1 -0
- package/dist/session/session-service.d.ts.map +1 -0
- package/dist/session/session-team-coordination.d.ts +1 -0
- package/dist/session/session-team-coordination.d.ts.map +1 -0
- package/dist/session/session-telemetry.d.ts +3 -1
- package/dist/session/session-telemetry.d.ts.map +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
- package/dist/session/unified-session-persistence-service.d.ts +1 -0
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
- package/dist/session/utils/helpers.d.ts +1 -0
- package/dist/session/utils/helpers.d.ts.map +1 -0
- package/dist/session/utils/types.d.ts +1 -0
- package/dist/session/utils/types.d.ts.map +1 -0
- package/dist/session/utils/usage.d.ts +1 -0
- package/dist/session/utils/usage.d.ts.map +1 -0
- package/dist/session/workspace-manager.d.ts +1 -0
- package/dist/session/workspace-manager.d.ts.map +1 -0
- package/dist/session/workspace-manifest.d.ts +1 -0
- package/dist/session/workspace-manifest.d.ts.map +1 -0
- package/dist/storage/file-team-store.d.ts +1 -0
- package/dist/storage/file-team-store.d.ts.map +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
- package/dist/storage/provider-settings-manager.d.ts +1 -0
- package/dist/storage/provider-settings-manager.d.ts.map +1 -0
- package/dist/storage/sqlite-session-store.d.ts +1 -0
- package/dist/storage/sqlite-session-store.d.ts.map +1 -0
- package/dist/storage/sqlite-team-store.d.ts +1 -0
- package/dist/storage/sqlite-team-store.d.ts.map +1 -0
- package/dist/storage/team-store.d.ts +1 -0
- package/dist/storage/team-store.d.ts.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/projections.d.ts +1 -0
- package/dist/team/projections.d.ts.map +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
- package/dist/telemetry/TelemetryService.d.ts +1 -0
- package/dist/telemetry/TelemetryService.d.ts.map +1 -0
- package/dist/telemetry/core-events.d.ts +55 -22
- package/dist/telemetry/core-events.d.ts.map +1 -0
- package/dist/telemetry/opentelemetry.d.ts +1 -0
- package/dist/telemetry/opentelemetry.d.ts.map +1 -0
- package/dist/tools/constants.d.ts +1 -0
- package/dist/tools/constants.d.ts.map +1 -0
- package/dist/tools/definitions.d.ts +8 -1
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
- package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
- package/dist/tools/executors/apply-patch.d.ts +1 -0
- package/dist/tools/executors/apply-patch.d.ts.map +1 -0
- package/dist/tools/executors/bash.d.ts +2 -1
- package/dist/tools/executors/bash.d.ts.map +1 -0
- package/dist/tools/executors/editor.d.ts +1 -0
- package/dist/tools/executors/editor.d.ts.map +1 -0
- package/dist/tools/executors/file-read.d.ts +1 -0
- package/dist/tools/executors/file-read.d.ts.map +1 -0
- package/dist/tools/executors/index.d.ts +14 -7
- package/dist/tools/executors/index.d.ts.map +1 -0
- package/dist/tools/executors/search.d.ts +1 -0
- package/dist/tools/executors/search.d.ts.map +1 -0
- package/dist/tools/executors/web-fetch.d.ts +1 -0
- package/dist/tools/executors/web-fetch.d.ts.map +1 -0
- package/dist/tools/helpers.d.ts +15 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/model-tool-routing.d.ts +1 -0
- package/dist/tools/model-tool-routing.d.ts.map +1 -0
- package/dist/tools/presets.d.ts +1 -0
- package/dist/tools/presets.d.ts.map +1 -0
- package/dist/tools/schemas.d.ts +41 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/types.d.ts +3 -2
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/events.d.ts +1 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/provider-settings.d.ts +1 -0
- package/dist/types/provider-settings.d.ts.map +1 -0
- package/dist/types/sessions.d.ts +1 -0
- package/dist/types/sessions.d.ts.map +1 -0
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/workspace.d.ts +1 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +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,327 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { readdir } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { isMainThread, parentPort, Worker } from "node:worker_threads";
|
|
5
|
-
|
|
6
|
-
const DEFAULT_INDEX_TTL_MS = 15_000;
|
|
7
|
-
const STALE_CACHE_EVICTION_MS = 10 * 60_000;
|
|
8
|
-
const WORKER_INDEX_REQUEST_TIMEOUT_MS = 1_000;
|
|
9
|
-
const DEFAULT_EXCLUDE_DIRS = new Set([
|
|
10
|
-
".git",
|
|
11
|
-
"node_modules",
|
|
12
|
-
"dist",
|
|
13
|
-
"build",
|
|
14
|
-
".next",
|
|
15
|
-
"coverage",
|
|
16
|
-
".turbo",
|
|
17
|
-
".cache",
|
|
18
|
-
"target",
|
|
19
|
-
"out",
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
interface CacheEntry {
|
|
23
|
-
files: Set<string>;
|
|
24
|
-
lastBuiltAt: number;
|
|
25
|
-
lastAccessedAt: number;
|
|
26
|
-
pending: Promise<Set<string>> | null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface FastFileIndexOptions {
|
|
30
|
-
ttlMs?: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface IndexRequestMessage {
|
|
34
|
-
type: "index";
|
|
35
|
-
requestId: number;
|
|
36
|
-
cwd: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface IndexResponseMessage {
|
|
40
|
-
type: "indexResult";
|
|
41
|
-
requestId: number;
|
|
42
|
-
files?: string[];
|
|
43
|
-
error?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const CACHE = new Map<string, CacheEntry>();
|
|
47
|
-
|
|
48
|
-
function pruneStaleCacheEntries(now: number): void {
|
|
49
|
-
if (CACHE.size <= 1) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
for (const [cwd, entry] of CACHE.entries()) {
|
|
53
|
-
if (entry.pending) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (now - entry.lastAccessedAt > STALE_CACHE_EVICTION_MS) {
|
|
57
|
-
CACHE.delete(cwd);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function toPosixRelative(cwd: string, absolutePath: string): string {
|
|
63
|
-
return path.relative(cwd, absolutePath).split(path.sep).join("/");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function listFilesWithRg(cwd: string): Promise<Set<string>> {
|
|
67
|
-
const output = await new Promise<string>((resolve, reject) => {
|
|
68
|
-
const child = spawn("rg", ["--files", "--hidden", "-g", "!.git"], {
|
|
69
|
-
cwd,
|
|
70
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
let stdout = "";
|
|
74
|
-
let stderr = "";
|
|
75
|
-
|
|
76
|
-
child.stdout.on("data", (chunk: Buffer | string) => {
|
|
77
|
-
stdout += chunk.toString();
|
|
78
|
-
});
|
|
79
|
-
child.stderr.on("data", (chunk: Buffer | string) => {
|
|
80
|
-
stderr += chunk.toString();
|
|
81
|
-
});
|
|
82
|
-
child.on("error", reject);
|
|
83
|
-
child.on("close", (code: number | null) => {
|
|
84
|
-
if (code === 0) {
|
|
85
|
-
resolve(stdout);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
reject(new Error(stderr || `rg exited with code ${code}`));
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const files = output
|
|
93
|
-
.split(/\r?\n/)
|
|
94
|
-
.map((line) => line.trim())
|
|
95
|
-
.filter((line) => line.length > 0)
|
|
96
|
-
.map((line) => line.replace(/\\/g, "/"));
|
|
97
|
-
|
|
98
|
-
return new Set(files);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function walkDir(
|
|
102
|
-
cwd: string,
|
|
103
|
-
dir: string,
|
|
104
|
-
files: Set<string>,
|
|
105
|
-
): Promise<void> {
|
|
106
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
107
|
-
for (const entry of entries) {
|
|
108
|
-
const absolutePath = path.join(dir, entry.name);
|
|
109
|
-
if (entry.isDirectory()) {
|
|
110
|
-
if (DEFAULT_EXCLUDE_DIRS.has(entry.name)) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
await walkDir(cwd, absolutePath, files);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (entry.isFile()) {
|
|
117
|
-
files.add(toPosixRelative(cwd, absolutePath));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function listFilesFallback(cwd: string): Promise<Set<string>> {
|
|
123
|
-
const files = new Set<string>();
|
|
124
|
-
await walkDir(cwd, cwd, files);
|
|
125
|
-
return files;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function buildIndex(cwd: string): Promise<Set<string>> {
|
|
129
|
-
try {
|
|
130
|
-
return await listFilesWithRg(cwd);
|
|
131
|
-
} catch {
|
|
132
|
-
return listFilesFallback(cwd);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function startWorkerServer(): void {
|
|
137
|
-
if (isMainThread || !parentPort) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const port = parentPort;
|
|
141
|
-
|
|
142
|
-
port.on("message", (message: IndexRequestMessage) => {
|
|
143
|
-
if (message.type !== "index") {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
void buildIndex(message.cwd)
|
|
148
|
-
.then((files) => {
|
|
149
|
-
const response: IndexResponseMessage = {
|
|
150
|
-
type: "indexResult",
|
|
151
|
-
requestId: message.requestId,
|
|
152
|
-
files: Array.from(files),
|
|
153
|
-
};
|
|
154
|
-
port.postMessage(response);
|
|
155
|
-
})
|
|
156
|
-
.catch((error: unknown) => {
|
|
157
|
-
const response: IndexResponseMessage = {
|
|
158
|
-
type: "indexResult",
|
|
159
|
-
requestId: message.requestId,
|
|
160
|
-
error:
|
|
161
|
-
error instanceof Error
|
|
162
|
-
? error.message
|
|
163
|
-
: "Failed to build file index",
|
|
164
|
-
};
|
|
165
|
-
port.postMessage(response);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
class FileIndexWorkerClient {
|
|
171
|
-
private readonly worker = new Worker(new URL(import.meta.url));
|
|
172
|
-
private nextRequestId = 0;
|
|
173
|
-
private pending = new Map<
|
|
174
|
-
number,
|
|
175
|
-
{
|
|
176
|
-
resolve: (files: string[]) => void;
|
|
177
|
-
reject: (reason: Error) => void;
|
|
178
|
-
}
|
|
179
|
-
>();
|
|
180
|
-
|
|
181
|
-
constructor() {
|
|
182
|
-
// Keep indexing opportunistic: this worker should never block process exit.
|
|
183
|
-
this.worker.unref();
|
|
184
|
-
this.worker.on("message", (message: IndexResponseMessage) => {
|
|
185
|
-
if (message.type !== "indexResult") {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const request = this.pending.get(message.requestId);
|
|
189
|
-
if (!request) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
this.pending.delete(message.requestId);
|
|
193
|
-
if (message.error) {
|
|
194
|
-
request.reject(new Error(message.error));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
request.resolve(message.files ?? []);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
this.worker.on("error", (error: Error) => {
|
|
201
|
-
this.flushPending(error);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
this.worker.on("exit", (code) => {
|
|
205
|
-
if (code !== 0) {
|
|
206
|
-
this.flushPending(
|
|
207
|
-
new Error(`File index worker exited with code ${code}`),
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
requestIndex(cwd: string): Promise<string[]> {
|
|
214
|
-
const requestId = ++this.nextRequestId;
|
|
215
|
-
const result = new Promise<string[]>((resolve, reject) => {
|
|
216
|
-
const timeout = setTimeout(() => {
|
|
217
|
-
this.pending.delete(requestId);
|
|
218
|
-
reject(new Error("Timed out waiting for file index worker response"));
|
|
219
|
-
}, WORKER_INDEX_REQUEST_TIMEOUT_MS);
|
|
220
|
-
timeout.unref();
|
|
221
|
-
this.pending.set(requestId, {
|
|
222
|
-
resolve: (files) => {
|
|
223
|
-
clearTimeout(timeout);
|
|
224
|
-
resolve(files);
|
|
225
|
-
},
|
|
226
|
-
reject: (reason) => {
|
|
227
|
-
clearTimeout(timeout);
|
|
228
|
-
reject(reason);
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const message: IndexRequestMessage = {
|
|
234
|
-
type: "index",
|
|
235
|
-
requestId,
|
|
236
|
-
cwd,
|
|
237
|
-
};
|
|
238
|
-
this.worker.postMessage(message);
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private flushPending(error: Error): void {
|
|
243
|
-
for (const [requestId, request] of this.pending.entries()) {
|
|
244
|
-
request.reject(error);
|
|
245
|
-
this.pending.delete(requestId);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
startWorkerServer();
|
|
251
|
-
|
|
252
|
-
let workerClient: FileIndexWorkerClient | null | undefined;
|
|
253
|
-
|
|
254
|
-
function getWorkerClient(): FileIndexWorkerClient | null {
|
|
255
|
-
if (!isMainThread) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
if (workerClient === undefined) {
|
|
259
|
-
workerClient = new FileIndexWorkerClient();
|
|
260
|
-
}
|
|
261
|
-
return workerClient;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async function buildIndexInBackground(cwd: string): Promise<Set<string>> {
|
|
265
|
-
const workerClient = getWorkerClient();
|
|
266
|
-
if (!workerClient) {
|
|
267
|
-
return buildIndex(cwd);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
try {
|
|
271
|
-
const files = await workerClient.requestIndex(cwd);
|
|
272
|
-
return new Set(files);
|
|
273
|
-
} catch {
|
|
274
|
-
return buildIndex(cwd);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export async function getFileIndex(
|
|
279
|
-
cwd: string,
|
|
280
|
-
options: FastFileIndexOptions = {},
|
|
281
|
-
): Promise<Set<string>> {
|
|
282
|
-
const ttlMs = options.ttlMs ?? DEFAULT_INDEX_TTL_MS;
|
|
283
|
-
const now = Date.now();
|
|
284
|
-
pruneStaleCacheEntries(now);
|
|
285
|
-
const existing = CACHE.get(cwd);
|
|
286
|
-
|
|
287
|
-
if (
|
|
288
|
-
existing &&
|
|
289
|
-
ttlMs > 0 &&
|
|
290
|
-
now - existing.lastBuiltAt <= ttlMs &&
|
|
291
|
-
existing.files.size > 0
|
|
292
|
-
) {
|
|
293
|
-
existing.lastAccessedAt = now;
|
|
294
|
-
return existing.files;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (existing?.pending) {
|
|
298
|
-
existing.lastAccessedAt = now;
|
|
299
|
-
return existing.pending;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const pending = buildIndexInBackground(cwd).then((files) => {
|
|
303
|
-
CACHE.set(cwd, {
|
|
304
|
-
files,
|
|
305
|
-
lastBuiltAt: Date.now(),
|
|
306
|
-
lastAccessedAt: Date.now(),
|
|
307
|
-
pending: null,
|
|
308
|
-
});
|
|
309
|
-
return files;
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
CACHE.set(cwd, {
|
|
313
|
-
files: existing?.files ?? new Set<string>(),
|
|
314
|
-
lastBuiltAt: existing?.lastBuiltAt ?? 0,
|
|
315
|
-
lastAccessedAt: now,
|
|
316
|
-
pending,
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
return pending;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export async function prewarmFileIndex(
|
|
323
|
-
cwd: string,
|
|
324
|
-
options: FastFileIndexOptions = {},
|
|
325
|
-
): Promise<void> {
|
|
326
|
-
await getFileIndex(cwd, { ...options, ttlMs: 0 });
|
|
327
|
-
}
|
package/src/input/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { FastFileIndexOptions } from "./file-indexer";
|
|
2
|
-
export { getFileIndex, prewarmFileIndex } from "./file-indexer";
|
|
3
|
-
export type {
|
|
4
|
-
MentionEnricherOptions,
|
|
5
|
-
MentionEnrichmentResult,
|
|
6
|
-
} from "./mention-enricher";
|
|
7
|
-
export { enrichPromptWithMentions } from "./mention-enricher";
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { enrichPromptWithMentions } from "./mention-enricher";
|
|
6
|
-
|
|
7
|
-
vi.mock("node:worker_threads", async () => {
|
|
8
|
-
const actual = await vi.importActual<typeof import("node:worker_threads")>(
|
|
9
|
-
"node:worker_threads",
|
|
10
|
-
);
|
|
11
|
-
return {
|
|
12
|
-
...actual,
|
|
13
|
-
isMainThread: false,
|
|
14
|
-
parentPort: null,
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
async function createTempWorkspace(): Promise<string> {
|
|
19
|
-
return mkdtemp(path.join(os.tmpdir(), "core-mentions-"));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe("enrichPromptWithMentions", () => {
|
|
23
|
-
it("returns matched files for matching @path mentions", async () => {
|
|
24
|
-
const cwd = await createTempWorkspace();
|
|
25
|
-
try {
|
|
26
|
-
const sourcePath = path.join(cwd, "src", "index.ts");
|
|
27
|
-
await mkdir(path.dirname(sourcePath), { recursive: true });
|
|
28
|
-
await writeFile(sourcePath, "export const answer = 42\n", "utf8");
|
|
29
|
-
|
|
30
|
-
const result = await enrichPromptWithMentions(
|
|
31
|
-
"Review @src/index.ts",
|
|
32
|
-
cwd,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
expect(result.mentions).toEqual(["src/index.ts"]);
|
|
36
|
-
expect(result.matchedFiles).toEqual(["src/index.ts"]);
|
|
37
|
-
expect(result.ignoredMentions).toEqual([]);
|
|
38
|
-
expect(result.prompt).toBe("Review @src/index.ts");
|
|
39
|
-
} finally {
|
|
40
|
-
await rm(cwd, { recursive: true, force: true });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("ignores emails and unmatched mentions", async () => {
|
|
45
|
-
const cwd = await createTempWorkspace();
|
|
46
|
-
try {
|
|
47
|
-
await writeFile(path.join(cwd, "README.md"), "# Demo\n", "utf8");
|
|
48
|
-
|
|
49
|
-
const result = await enrichPromptWithMentions(
|
|
50
|
-
"Ping me at test@example.com and check @missing/file.ts.",
|
|
51
|
-
cwd,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
expect(result.mentions).toEqual(["missing/file.ts"]);
|
|
55
|
-
expect(result.matchedFiles).toEqual([]);
|
|
56
|
-
expect(result.ignoredMentions).toEqual(["missing/file.ts"]);
|
|
57
|
-
expect(result.prompt).toBe(
|
|
58
|
-
"Ping me at test@example.com and check @missing/file.ts.",
|
|
59
|
-
);
|
|
60
|
-
} finally {
|
|
61
|
-
await rm(cwd, { recursive: true, force: true });
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("respects maxTotalBytes while keeping prompt unchanged", async () => {
|
|
66
|
-
const cwd = await createTempWorkspace();
|
|
67
|
-
try {
|
|
68
|
-
await writeFile(path.join(cwd, "a.ts"), "123", "utf8");
|
|
69
|
-
await writeFile(path.join(cwd, "b.ts"), "const b = 2\n", "utf8");
|
|
70
|
-
|
|
71
|
-
const result = await enrichPromptWithMentions(
|
|
72
|
-
"Use @a.ts and @b.ts",
|
|
73
|
-
cwd,
|
|
74
|
-
{ maxTotalBytes: 5, maxFiles: 2, maxFileBytes: 5 },
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(result.mentions).toEqual(["a.ts", "b.ts"]);
|
|
78
|
-
expect(result.matchedFiles).toEqual(["a.ts"]);
|
|
79
|
-
expect(result.ignoredMentions).toEqual(["b.ts"]);
|
|
80
|
-
expect(result.prompt).toBe("Use @a.ts and @b.ts");
|
|
81
|
-
} finally {
|
|
82
|
-
await rm(cwd, { recursive: true, force: true });
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { stat } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { type FastFileIndexOptions, getFileIndex } from "./file-indexer";
|
|
4
|
-
|
|
5
|
-
const TRAILING_PUNCTUATION = /[),.:;!?`'"]+$/;
|
|
6
|
-
const LEADING_WRAPPERS = /^[(`'"]+/;
|
|
7
|
-
|
|
8
|
-
export interface MentionEnricherOptions extends FastFileIndexOptions {
|
|
9
|
-
maxFiles?: number;
|
|
10
|
-
maxFileBytes?: number;
|
|
11
|
-
maxTotalBytes?: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface MentionEnrichmentResult {
|
|
15
|
-
prompt: string;
|
|
16
|
-
mentions: string[];
|
|
17
|
-
matchedFiles: string[];
|
|
18
|
-
ignoredMentions: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function extractMentionTokens(input: string): string[] {
|
|
22
|
-
const matches = input.matchAll(/(^|[\s])@([^\s]+)/g);
|
|
23
|
-
const mentions: string[] = [];
|
|
24
|
-
for (const match of matches) {
|
|
25
|
-
const token = (match[2] ?? "").trim();
|
|
26
|
-
if (token.length === 0) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const normalized = token
|
|
30
|
-
.replace(LEADING_WRAPPERS, "")
|
|
31
|
-
.replace(TRAILING_PUNCTUATION, "");
|
|
32
|
-
if (normalized.length === 0 || normalized.includes("@")) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
mentions.push(normalized);
|
|
36
|
-
}
|
|
37
|
-
return Array.from(new Set(mentions));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function normalizeMentionPath(
|
|
41
|
-
mention: string,
|
|
42
|
-
cwd: string,
|
|
43
|
-
): string | undefined {
|
|
44
|
-
const candidate = mention.replace(/\\/g, "/");
|
|
45
|
-
const maybeAbsolute = path.isAbsolute(candidate)
|
|
46
|
-
? path.resolve(candidate)
|
|
47
|
-
: path.resolve(cwd, candidate);
|
|
48
|
-
const relative = path.relative(cwd, maybeAbsolute);
|
|
49
|
-
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
return relative.split(path.sep).join("/");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function enrichPromptWithMentions(
|
|
56
|
-
input: string,
|
|
57
|
-
cwd: string,
|
|
58
|
-
options: MentionEnricherOptions = {},
|
|
59
|
-
): Promise<MentionEnrichmentResult> {
|
|
60
|
-
const mentions = extractMentionTokens(input);
|
|
61
|
-
if (mentions.length === 0) {
|
|
62
|
-
return {
|
|
63
|
-
prompt: input,
|
|
64
|
-
mentions: [],
|
|
65
|
-
matchedFiles: [],
|
|
66
|
-
ignoredMentions: [],
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const maxFiles = options.maxFiles;
|
|
71
|
-
const maxFileBytes = options.maxFileBytes;
|
|
72
|
-
const maxTotalBytes = options.maxTotalBytes;
|
|
73
|
-
const fileList = await getFileIndex(cwd, { ttlMs: options.ttlMs });
|
|
74
|
-
const matched: string[] = [];
|
|
75
|
-
const ignored: string[] = [];
|
|
76
|
-
const attachments: Array<{ path: string; content: string }> = [];
|
|
77
|
-
let totalBytes = 0;
|
|
78
|
-
|
|
79
|
-
for (const mention of mentions) {
|
|
80
|
-
if (maxFiles && attachments.length >= maxFiles) {
|
|
81
|
-
ignored.push(mention);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const relativePath = normalizeMentionPath(mention, cwd);
|
|
86
|
-
if (!relativePath || !fileList.has(relativePath)) {
|
|
87
|
-
ignored.push(mention);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!maxFileBytes || !maxTotalBytes) {
|
|
92
|
-
matched.push(relativePath);
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const absolutePath = path.join(cwd, relativePath);
|
|
97
|
-
try {
|
|
98
|
-
const fileStat = await stat(absolutePath);
|
|
99
|
-
if (!fileStat.isFile()) {
|
|
100
|
-
ignored.push(mention);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const nextBytes = totalBytes + maxFileBytes;
|
|
104
|
-
if (nextBytes > maxTotalBytes) {
|
|
105
|
-
ignored.push(mention);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
totalBytes += nextBytes;
|
|
110
|
-
matched.push(relativePath);
|
|
111
|
-
} catch {
|
|
112
|
-
ignored.push(mention);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
prompt: input,
|
|
118
|
-
mentions,
|
|
119
|
-
matchedFiles: matched,
|
|
120
|
-
ignoredMentions: ignored,
|
|
121
|
-
};
|
|
122
|
-
}
|