@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,280 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
readFileSync,
|
|
5
|
-
renameSync,
|
|
6
|
-
writeFileSync,
|
|
7
|
-
} from "node:fs";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
10
|
-
import type { SessionRow } from "./session-service";
|
|
11
|
-
import type {
|
|
12
|
-
PersistedSessionUpdateInput,
|
|
13
|
-
SessionPersistenceAdapter,
|
|
14
|
-
} from "./unified-session-persistence-service";
|
|
15
|
-
import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
|
|
16
|
-
|
|
17
|
-
interface FileSessionIndex {
|
|
18
|
-
version: 1;
|
|
19
|
-
sessions: Record<string, SessionRow>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface FileSpawnRequest {
|
|
23
|
-
id: number;
|
|
24
|
-
rootSessionId: string;
|
|
25
|
-
parentAgentId: string;
|
|
26
|
-
task?: string;
|
|
27
|
-
systemPrompt?: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
consumedAt?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface FileSpawnQueue {
|
|
33
|
-
version: 1;
|
|
34
|
-
nextId: number;
|
|
35
|
-
requests: FileSpawnRequest[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function nowIso(): string {
|
|
39
|
-
return new Date().toISOString();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function atomicWriteJson(path: string, value: unknown): void {
|
|
43
|
-
const tempPath = `${path}.tmp`;
|
|
44
|
-
writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
45
|
-
renameSync(tempPath, path);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function defaultSessionsDir(): string {
|
|
49
|
-
return resolveSessionDataDir();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class FileSessionPersistenceAdapter implements SessionPersistenceAdapter {
|
|
53
|
-
constructor(
|
|
54
|
-
private readonly sessionsDirPath: string = defaultSessionsDir(),
|
|
55
|
-
) {}
|
|
56
|
-
|
|
57
|
-
ensureSessionsDir(): string {
|
|
58
|
-
if (!existsSync(this.sessionsDirPath)) {
|
|
59
|
-
mkdirSync(this.sessionsDirPath, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
return this.sessionsDirPath;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private indexPath(): string {
|
|
65
|
-
return join(this.ensureSessionsDir(), "sessions.index.json");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private spawnQueuePath(): string {
|
|
69
|
-
return join(this.ensureSessionsDir(), "subagent-spawn-queue.json");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private readIndex(): FileSessionIndex {
|
|
73
|
-
const path = this.indexPath();
|
|
74
|
-
if (!existsSync(path)) {
|
|
75
|
-
return { version: 1, sessions: {} };
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSessionIndex;
|
|
79
|
-
if (parsed?.version === 1 && parsed.sessions) {
|
|
80
|
-
return parsed;
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
// Ignore invalid persistence and fall back to an empty index.
|
|
84
|
-
}
|
|
85
|
-
return { version: 1, sessions: {} };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private writeIndex(index: FileSessionIndex): void {
|
|
89
|
-
atomicWriteJson(this.indexPath(), index);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private readQueue(): FileSpawnQueue {
|
|
93
|
-
const path = this.spawnQueuePath();
|
|
94
|
-
if (!existsSync(path)) {
|
|
95
|
-
return { version: 1, nextId: 1, requests: [] };
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const parsed = JSON.parse(readFileSync(path, "utf8")) as FileSpawnQueue;
|
|
99
|
-
if (
|
|
100
|
-
parsed?.version === 1 &&
|
|
101
|
-
typeof parsed.nextId === "number" &&
|
|
102
|
-
Array.isArray(parsed.requests)
|
|
103
|
-
) {
|
|
104
|
-
return parsed;
|
|
105
|
-
}
|
|
106
|
-
} catch {
|
|
107
|
-
// Ignore invalid persistence and fall back to an empty queue.
|
|
108
|
-
}
|
|
109
|
-
return { version: 1, nextId: 1, requests: [] };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private writeQueue(queue: FileSpawnQueue): void {
|
|
113
|
-
atomicWriteJson(this.spawnQueuePath(), queue);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async upsertSession(row: SessionRow): Promise<void> {
|
|
117
|
-
const index = this.readIndex();
|
|
118
|
-
index.sessions[row.sessionId] = row;
|
|
119
|
-
this.writeIndex(index);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async getSession(sessionId: string): Promise<SessionRow | undefined> {
|
|
123
|
-
return this.readIndex().sessions[sessionId];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async listSessions(options: {
|
|
127
|
-
limit: number;
|
|
128
|
-
parentSessionId?: string;
|
|
129
|
-
status?: string;
|
|
130
|
-
}): Promise<SessionRow[]> {
|
|
131
|
-
return Object.values(this.readIndex().sessions)
|
|
132
|
-
.filter((row) =>
|
|
133
|
-
options.parentSessionId !== undefined
|
|
134
|
-
? row.parentSessionId === options.parentSessionId
|
|
135
|
-
: true,
|
|
136
|
-
)
|
|
137
|
-
.filter((row) =>
|
|
138
|
-
options.status !== undefined ? row.status === options.status : true,
|
|
139
|
-
)
|
|
140
|
-
.sort((a, b) => b.startedAt.localeCompare(a.startedAt))
|
|
141
|
-
.slice(0, options.limit);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async updateSession(
|
|
145
|
-
input: PersistedSessionUpdateInput,
|
|
146
|
-
): Promise<{ updated: boolean; statusLock: number }> {
|
|
147
|
-
const index = this.readIndex();
|
|
148
|
-
const existing = index.sessions[input.sessionId];
|
|
149
|
-
if (!existing) {
|
|
150
|
-
return { updated: false, statusLock: 0 };
|
|
151
|
-
}
|
|
152
|
-
if (
|
|
153
|
-
input.expectedStatusLock !== undefined &&
|
|
154
|
-
existing.statusLock !== input.expectedStatusLock
|
|
155
|
-
) {
|
|
156
|
-
return { updated: false, statusLock: existing.statusLock };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const nextStatusLock =
|
|
160
|
-
input.expectedStatusLock !== undefined
|
|
161
|
-
? input.expectedStatusLock + 1
|
|
162
|
-
: existing.statusLock;
|
|
163
|
-
const next: SessionRow = {
|
|
164
|
-
...existing,
|
|
165
|
-
status: input.status ?? existing.status,
|
|
166
|
-
endedAt:
|
|
167
|
-
input.endedAt !== undefined
|
|
168
|
-
? input.endedAt
|
|
169
|
-
: (existing.endedAt ?? null),
|
|
170
|
-
exitCode:
|
|
171
|
-
input.exitCode !== undefined
|
|
172
|
-
? input.exitCode
|
|
173
|
-
: (existing.exitCode ?? null),
|
|
174
|
-
prompt:
|
|
175
|
-
input.prompt !== undefined ? input.prompt : (existing.prompt ?? null),
|
|
176
|
-
metadata:
|
|
177
|
-
input.metadata !== undefined
|
|
178
|
-
? (input.metadata ?? null)
|
|
179
|
-
: (existing.metadata ?? null),
|
|
180
|
-
parentSessionId:
|
|
181
|
-
input.parentSessionId !== undefined
|
|
182
|
-
? (input.parentSessionId ?? null)
|
|
183
|
-
: (existing.parentSessionId ?? null),
|
|
184
|
-
parentAgentId:
|
|
185
|
-
input.parentAgentId !== undefined
|
|
186
|
-
? (input.parentAgentId ?? null)
|
|
187
|
-
: (existing.parentAgentId ?? null),
|
|
188
|
-
agentId:
|
|
189
|
-
input.agentId !== undefined
|
|
190
|
-
? (input.agentId ?? null)
|
|
191
|
-
: (existing.agentId ?? null),
|
|
192
|
-
conversationId:
|
|
193
|
-
input.conversationId !== undefined
|
|
194
|
-
? (input.conversationId ?? null)
|
|
195
|
-
: (existing.conversationId ?? null),
|
|
196
|
-
statusLock: nextStatusLock,
|
|
197
|
-
isSubagent:
|
|
198
|
-
input.setRunning || input.parentSessionId !== undefined
|
|
199
|
-
? true
|
|
200
|
-
: existing.isSubagent,
|
|
201
|
-
updatedAt: nowIso(),
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
if (input.setRunning) {
|
|
205
|
-
next.status = "running";
|
|
206
|
-
next.endedAt = null;
|
|
207
|
-
next.exitCode = null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
index.sessions[input.sessionId] = next;
|
|
211
|
-
this.writeIndex(index);
|
|
212
|
-
return { updated: true, statusLock: next.statusLock };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
|
|
216
|
-
const index = this.readIndex();
|
|
217
|
-
const existing = index.sessions[sessionId];
|
|
218
|
-
if (!existing) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
delete index.sessions[sessionId];
|
|
222
|
-
if (cascade) {
|
|
223
|
-
for (const row of Object.values(index.sessions)) {
|
|
224
|
-
if (row.parentSessionId === sessionId) {
|
|
225
|
-
delete index.sessions[row.sessionId];
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
this.writeIndex(index);
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async enqueueSpawnRequest(input: {
|
|
234
|
-
rootSessionId: string;
|
|
235
|
-
parentAgentId: string;
|
|
236
|
-
task?: string;
|
|
237
|
-
systemPrompt?: string;
|
|
238
|
-
}): Promise<void> {
|
|
239
|
-
const queue = this.readQueue();
|
|
240
|
-
queue.requests.push({
|
|
241
|
-
id: queue.nextId,
|
|
242
|
-
rootSessionId: input.rootSessionId,
|
|
243
|
-
parentAgentId: input.parentAgentId,
|
|
244
|
-
task: input.task,
|
|
245
|
-
systemPrompt: input.systemPrompt,
|
|
246
|
-
createdAt: nowIso(),
|
|
247
|
-
});
|
|
248
|
-
queue.nextId += 1;
|
|
249
|
-
this.writeQueue(queue);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async claimSpawnRequest(
|
|
253
|
-
rootSessionId: string,
|
|
254
|
-
parentAgentId: string,
|
|
255
|
-
): Promise<string | undefined> {
|
|
256
|
-
const queue = this.readQueue();
|
|
257
|
-
const request = queue.requests.find(
|
|
258
|
-
(item) =>
|
|
259
|
-
item.rootSessionId === rootSessionId &&
|
|
260
|
-
item.parentAgentId === parentAgentId &&
|
|
261
|
-
!item.consumedAt,
|
|
262
|
-
);
|
|
263
|
-
if (!request) {
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
request.consumedAt = nowIso();
|
|
267
|
-
this.writeQueue(queue);
|
|
268
|
-
return request.task;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export class FileSessionService extends UnifiedSessionPersistenceService {
|
|
273
|
-
constructor(sessionsDir?: string) {
|
|
274
|
-
super(new FileSessionPersistenceAdapter(sessionsDir));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
override ensureSessionsDir(): string {
|
|
278
|
-
return super.ensureSessionsDir();
|
|
279
|
-
}
|
|
280
|
-
}
|
package/src/session/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export { DefaultSessionManager } from "./default-session-manager";
|
|
2
|
-
export { RpcCoreSessionService } from "./rpc-session-service";
|
|
3
|
-
export {
|
|
4
|
-
deriveSubsessionStatus,
|
|
5
|
-
makeSubSessionId,
|
|
6
|
-
makeTeamTaskSubSessionId,
|
|
7
|
-
sanitizeSessionToken,
|
|
8
|
-
} from "./session-graph";
|
|
9
|
-
export type {
|
|
10
|
-
CreateSessionHostOptions,
|
|
11
|
-
SessionBackend,
|
|
12
|
-
SessionHost,
|
|
13
|
-
} from "./session-host";
|
|
14
|
-
export { createSessionHost, resolveSessionBackend } from "./session-host";
|
|
15
|
-
export type {
|
|
16
|
-
SendSessionInput,
|
|
17
|
-
SessionAccumulatedUsage,
|
|
18
|
-
SessionManager,
|
|
19
|
-
StartSessionInput,
|
|
20
|
-
StartSessionResult,
|
|
21
|
-
} from "./session-manager";
|
|
22
|
-
export type { SessionManifest } from "./session-manifest";
|
|
23
|
-
export type {
|
|
24
|
-
CreateRootSessionWithArtifactsInput,
|
|
25
|
-
RootSessionArtifacts,
|
|
26
|
-
} from "./session-service";
|
|
27
|
-
export { CoreSessionService } from "./session-service";
|
|
28
|
-
export type {
|
|
29
|
-
WorkspaceManager,
|
|
30
|
-
WorkspaceManagerEvent,
|
|
31
|
-
} from "./workspace-manager";
|
|
32
|
-
export { InMemoryWorkspaceManager } from "./workspace-manager";
|
|
33
|
-
export type { WorkspaceManifest } from "./workspace-manifest";
|
|
34
|
-
export {
|
|
35
|
-
buildWorkspaceMetadata,
|
|
36
|
-
emptyWorkspaceManifest,
|
|
37
|
-
generateWorkspaceInfo,
|
|
38
|
-
normalizeWorkspacePath,
|
|
39
|
-
upsertWorkspaceInfo,
|
|
40
|
-
WorkspaceInfoSchema,
|
|
41
|
-
WorkspaceManifestSchema,
|
|
42
|
-
} from "./workspace-manifest";
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { RpcSessionClient, type RpcSessionRow } from "@clinebot/rpc";
|
|
3
|
-
import type { SessionRow } from "./session-service";
|
|
4
|
-
import type {
|
|
5
|
-
PersistedSessionUpdateInput,
|
|
6
|
-
SessionPersistenceAdapter,
|
|
7
|
-
} from "./unified-session-persistence-service";
|
|
8
|
-
import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
|
|
9
|
-
|
|
10
|
-
// ── Adapter ──────────────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
class RpcSessionPersistenceAdapter implements SessionPersistenceAdapter {
|
|
13
|
-
constructor(private readonly client: RpcSessionClient) {}
|
|
14
|
-
|
|
15
|
-
ensureSessionsDir(): string {
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async upsertSession(row: SessionRow): Promise<void> {
|
|
20
|
-
await this.client.upsertSession(row as RpcSessionRow);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getSession(sessionId: string): Promise<SessionRow | undefined> {
|
|
24
|
-
const row = await this.client.getSession(sessionId);
|
|
25
|
-
return (row as SessionRow | undefined) ?? undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async listSessions(options: {
|
|
29
|
-
limit: number;
|
|
30
|
-
parentSessionId?: string;
|
|
31
|
-
status?: string;
|
|
32
|
-
}): Promise<SessionRow[]> {
|
|
33
|
-
const rows = await this.client.listSessions(options);
|
|
34
|
-
return rows as SessionRow[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async updateSession(
|
|
38
|
-
input: PersistedSessionUpdateInput,
|
|
39
|
-
): Promise<{ updated: boolean; statusLock: number }> {
|
|
40
|
-
return this.client.updateSession({
|
|
41
|
-
sessionId: input.sessionId,
|
|
42
|
-
status: input.status,
|
|
43
|
-
endedAt: input.endedAt,
|
|
44
|
-
exitCode: input.exitCode,
|
|
45
|
-
prompt: input.prompt,
|
|
46
|
-
metadata: input.metadata,
|
|
47
|
-
parentSessionId: input.parentSessionId,
|
|
48
|
-
parentAgentId: input.parentAgentId,
|
|
49
|
-
agentId: input.agentId,
|
|
50
|
-
conversationId: input.conversationId,
|
|
51
|
-
expectedStatusLock: input.expectedStatusLock,
|
|
52
|
-
setRunning: input.setRunning,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async deleteSession(sessionId: string, cascade: boolean): Promise<boolean> {
|
|
57
|
-
return this.client.deleteSession(sessionId, cascade);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async enqueueSpawnRequest(input: {
|
|
61
|
-
rootSessionId: string;
|
|
62
|
-
parentAgentId: string;
|
|
63
|
-
task?: string;
|
|
64
|
-
systemPrompt?: string;
|
|
65
|
-
}): Promise<void> {
|
|
66
|
-
await this.client.enqueueSpawnRequest(input);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async claimSpawnRequest(
|
|
70
|
-
rootSessionId: string,
|
|
71
|
-
parentAgentId: string,
|
|
72
|
-
): Promise<string | undefined> {
|
|
73
|
-
return this.client.claimSpawnRequest(rootSessionId, parentAgentId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ── Service ──────────────────────────────────────────────────────────
|
|
78
|
-
|
|
79
|
-
export interface RpcCoreSessionServiceOptions {
|
|
80
|
-
address?: string;
|
|
81
|
-
sessionsDir: string;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class RpcCoreSessionService extends UnifiedSessionPersistenceService {
|
|
85
|
-
private readonly sessionsDirPath: string;
|
|
86
|
-
private readonly client: RpcSessionClient;
|
|
87
|
-
|
|
88
|
-
constructor(options: RpcCoreSessionServiceOptions) {
|
|
89
|
-
const client = new RpcSessionClient({
|
|
90
|
-
address: options.address?.trim() || "127.0.0.1:4317",
|
|
91
|
-
});
|
|
92
|
-
super(new RpcSessionPersistenceAdapter(client));
|
|
93
|
-
this.sessionsDirPath = options.sessionsDir;
|
|
94
|
-
this.client = client;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
override ensureSessionsDir(): string {
|
|
98
|
-
if (!existsSync(this.sessionsDirPath)) {
|
|
99
|
-
mkdirSync(this.sessionsDirPath, { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
return this.sessionsDirPath;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
close(): void {
|
|
105
|
-
this.client.close();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { tryAcquireRpcSpawnLease } from "./rpc-spawn-lease";
|
|
6
|
-
|
|
7
|
-
describe("tryAcquireRpcSpawnLease", () => {
|
|
8
|
-
const tempDirs: string[] = [];
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
delete process.env.CLINE_DATA_DIR;
|
|
12
|
-
for (const dir of tempDirs.splice(0)) {
|
|
13
|
-
rmSync(dir, { recursive: true, force: true });
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("allows only one active lease per address", () => {
|
|
18
|
-
const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
|
|
19
|
-
tempDirs.push(dataDir);
|
|
20
|
-
process.env.CLINE_DATA_DIR = dataDir;
|
|
21
|
-
|
|
22
|
-
const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
23
|
-
const second = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
24
|
-
|
|
25
|
-
expect(first).toBeDefined();
|
|
26
|
-
expect(second).toBeUndefined();
|
|
27
|
-
|
|
28
|
-
first?.release();
|
|
29
|
-
|
|
30
|
-
const third = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
31
|
-
expect(third).toBeDefined();
|
|
32
|
-
third?.release();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("lets different addresses acquire independent leases", () => {
|
|
36
|
-
const dataDir = mkdtempSync(path.join(os.tmpdir(), "rpc-spawn-lease-"));
|
|
37
|
-
tempDirs.push(dataDir);
|
|
38
|
-
process.env.CLINE_DATA_DIR = dataDir;
|
|
39
|
-
|
|
40
|
-
const first = tryAcquireRpcSpawnLease("127.0.0.1:4317");
|
|
41
|
-
const second = tryAcquireRpcSpawnLease("127.0.0.1:4318");
|
|
42
|
-
|
|
43
|
-
expect(first).toBeDefined();
|
|
44
|
-
expect(second).toBeDefined();
|
|
45
|
-
|
|
46
|
-
first?.release();
|
|
47
|
-
second?.release();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
closeSync,
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
openSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
rmSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { dirname, resolve } from "node:path";
|
|
11
|
-
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
12
|
-
|
|
13
|
-
const DEFAULT_LEASE_TTL_MS = 15_000;
|
|
14
|
-
|
|
15
|
-
interface RpcSpawnLeaseRecord {
|
|
16
|
-
address: string;
|
|
17
|
-
pid: number;
|
|
18
|
-
createdAt: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface RpcSpawnLease {
|
|
22
|
-
path: string;
|
|
23
|
-
release: () => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function encodeAddress(address: string): string {
|
|
27
|
-
return Buffer.from(address).toString("base64url");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getLeasePath(address: string): string {
|
|
31
|
-
return resolve(
|
|
32
|
-
resolveSessionDataDir(),
|
|
33
|
-
"rpc",
|
|
34
|
-
"spawn-leases",
|
|
35
|
-
`${encodeAddress(address)}.lock`,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isProcessAlive(pid: number): boolean {
|
|
40
|
-
if (!Number.isInteger(pid) || pid <= 0) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
process.kill(pid, 0);
|
|
45
|
-
return true;
|
|
46
|
-
} catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function shouldClearLease(path: string, ttlMs: number): boolean {
|
|
52
|
-
try {
|
|
53
|
-
const raw = readFileSync(path, "utf8");
|
|
54
|
-
const parsed = JSON.parse(raw) as Partial<RpcSpawnLeaseRecord>;
|
|
55
|
-
const createdAt = Number(parsed.createdAt ?? 0);
|
|
56
|
-
if (!Number.isFinite(createdAt) || createdAt <= 0) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
if (Date.now() - createdAt > ttlMs) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return !isProcessAlive(Number(parsed.pid ?? 0));
|
|
63
|
-
} catch {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function tryAcquireRpcSpawnLease(
|
|
69
|
-
address: string,
|
|
70
|
-
options?: { ttlMs?: number },
|
|
71
|
-
): RpcSpawnLease | undefined {
|
|
72
|
-
const ttlMs = Math.max(1_000, options?.ttlMs ?? DEFAULT_LEASE_TTL_MS);
|
|
73
|
-
const path = getLeasePath(address);
|
|
74
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
75
|
-
|
|
76
|
-
if (existsSync(path) && shouldClearLease(path, ttlMs)) {
|
|
77
|
-
rmSync(path, { force: true });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let fd: number | undefined;
|
|
81
|
-
try {
|
|
82
|
-
fd = openSync(path, "wx");
|
|
83
|
-
const record: RpcSpawnLeaseRecord = {
|
|
84
|
-
address,
|
|
85
|
-
pid: process.pid,
|
|
86
|
-
createdAt: Date.now(),
|
|
87
|
-
};
|
|
88
|
-
writeFileSync(fd, JSON.stringify(record), "utf8");
|
|
89
|
-
} catch {
|
|
90
|
-
if (typeof fd === "number") {
|
|
91
|
-
try {
|
|
92
|
-
closeSync(fd);
|
|
93
|
-
} catch {
|
|
94
|
-
// Best effort.
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let released = false;
|
|
101
|
-
return {
|
|
102
|
-
path,
|
|
103
|
-
release: () => {
|
|
104
|
-
if (released) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
released = true;
|
|
108
|
-
try {
|
|
109
|
-
if (typeof fd === "number") {
|
|
110
|
-
closeSync(fd);
|
|
111
|
-
}
|
|
112
|
-
} catch {
|
|
113
|
-
// Best effort.
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
rmSync(path, { force: true });
|
|
117
|
-
} catch {
|
|
118
|
-
// Best effort.
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
}
|