@clinebot/core 0.0.14 → 0.0.16

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.
Files changed (33) hide show
  1. package/dist/account/cline-account-service.d.ts +2 -1
  2. package/dist/account/index.d.ts +1 -1
  3. package/dist/account/types.d.ts +5 -0
  4. package/dist/index.node.d.ts +2 -0
  5. package/dist/index.node.js +178 -174
  6. package/dist/session/default-session-manager.d.ts +2 -1
  7. package/dist/session/file-session-service.d.ts +5 -0
  8. package/dist/session/session-host.d.ts +2 -1
  9. package/dist/storage/file-team-store.d.ts +27 -0
  10. package/dist/storage/sqlite-session-store.d.ts +1 -0
  11. package/dist/storage/team-store.d.ts +13 -0
  12. package/package.json +4 -4
  13. package/src/account/cline-account-service.ts +7 -0
  14. package/src/account/index.ts +1 -0
  15. package/src/account/types.ts +6 -0
  16. package/src/agents/agent-config-loader.test.ts +3 -3
  17. package/src/agents/hooks-config-loader.test.ts +20 -0
  18. package/src/agents/hooks-config-loader.ts +1 -0
  19. package/src/agents/user-instruction-config-loader.test.ts +6 -6
  20. package/src/index.node.ts +39 -0
  21. package/src/runtime/hook-file-hooks.test.ts +34 -0
  22. package/src/runtime/hook-file-hooks.ts +34 -4
  23. package/src/runtime/runtime-builder.team-persistence.test.ts +4 -5
  24. package/src/runtime/runtime-builder.ts +2 -3
  25. package/src/session/default-session-manager.ts +5 -1
  26. package/src/session/file-session-service.ts +280 -0
  27. package/src/session/session-host.test.ts +29 -0
  28. package/src/session/session-host.ts +17 -3
  29. package/src/session/session-team-coordination.ts +6 -5
  30. package/src/session/unified-session-persistence-service.test.ts +7 -3
  31. package/src/storage/file-team-store.ts +257 -0
  32. package/src/storage/sqlite-session-store.ts +5 -0
  33. package/src/storage/team-store.ts +35 -0
@@ -6,11 +6,12 @@ import { ProviderSettingsManager } from "../storage/provider-settings-manager";
6
6
  import { type ToolExecutors } from "../tools";
7
7
  import type { CoreSessionEvent } from "../types/events";
8
8
  import type { SessionRecord } from "../types/sessions";
9
+ import type { FileSessionService } from "./file-session-service";
9
10
  import type { RpcCoreSessionService } from "./rpc-session-service";
10
11
  import { RuntimeOAuthTokenManager } from "./runtime-oauth-token-manager";
11
12
  import type { SendSessionInput, SessionAccumulatedUsage, SessionManager, StartSessionInput, StartSessionResult } from "./session-manager";
12
13
  import type { CoreSessionService } from "./session-service";
13
- type SessionBackend = CoreSessionService | RpcCoreSessionService;
14
+ type SessionBackend = CoreSessionService | RpcCoreSessionService | FileSessionService;
14
15
  export interface DefaultSessionManagerOptions {
15
16
  distinctId: string;
16
17
  sessionService: SessionBackend;
@@ -0,0 +1,5 @@
1
+ import { UnifiedSessionPersistenceService } from "./unified-session-persistence-service";
2
+ export declare class FileSessionService extends UnifiedSessionPersistenceService {
3
+ constructor(sessionsDir?: string);
4
+ ensureSessionsDir(): string;
5
+ }
@@ -1,10 +1,11 @@
1
1
  import type { AgentConfig, ToolApprovalRequest, ToolApprovalResult } from "@clinebot/agents";
2
2
  import type { ITelemetryService } from "@clinebot/shared";
3
3
  import type { ToolExecutors } from "../tools";
4
+ import { FileSessionService } from "./file-session-service";
4
5
  import { RpcCoreSessionService } from "./rpc-session-service";
5
6
  import type { SessionManager } from "./session-manager";
6
7
  import { CoreSessionService } from "./session-service";
7
- export type SessionBackend = RpcCoreSessionService | CoreSessionService;
8
+ export type SessionBackend = RpcCoreSessionService | CoreSessionService | FileSessionService;
8
9
  export interface CreateSessionHostOptions {
9
10
  distinctId?: string;
10
11
  sessionService?: SessionBackend;
@@ -0,0 +1,27 @@
1
+ import type { TeamEvent, TeamRuntimeState, TeamTeammateSpec } from "@clinebot/agents";
2
+ import type { TeamStore } from "../types/storage";
3
+ export interface FileTeamStoreOptions {
4
+ teamDir?: string;
5
+ }
6
+ export interface TeamRuntimeLoadResult {
7
+ state?: TeamRuntimeState;
8
+ teammates: TeamTeammateSpec[];
9
+ interruptedRunIds: string[];
10
+ }
11
+ export declare class FileTeamStore implements TeamStore {
12
+ private readonly teamDirPath;
13
+ constructor(options?: FileTeamStoreOptions);
14
+ init(): void;
15
+ listTeamNames(): string[];
16
+ readState(teamName: string): TeamRuntimeState | undefined;
17
+ readHistory(teamName: string, limit?: number): unknown[];
18
+ loadRuntime(teamName: string): TeamRuntimeLoadResult;
19
+ handleTeamEvent(teamName: string, event: TeamEvent): void;
20
+ persistRuntime(teamName: string, state: TeamRuntimeState, teammates: TeamTeammateSpec[]): void;
21
+ markInProgressRunsInterrupted(teamName: string, reason: string): string[];
22
+ private ensureTeamDir;
23
+ private ensureTeamSubdir;
24
+ private statePath;
25
+ private historyPath;
26
+ private readEnvelope;
27
+ }
@@ -13,6 +13,7 @@ export declare class SqliteSessionStore implements SessionStore {
13
13
  ensureSessionsDir(): string;
14
14
  sessionDbPath(): string;
15
15
  getRawDb(): SqliteDb;
16
+ close(): void;
16
17
  run(sql: string, params?: unknown[]): {
17
18
  changes?: number;
18
19
  };
@@ -1,2 +1,15 @@
1
1
  export type { TeamStore } from "../types/storage";
2
+ export { FileTeamStore, type FileTeamStoreOptions, } from "./file-team-store";
2
3
  export { SqliteTeamStore, type SqliteTeamStoreOptions, } from "./sqlite-team-store";
4
+ import { FileTeamStore } from "./file-team-store";
5
+ import { type SqliteTeamStoreOptions } from "./sqlite-team-store";
6
+ export declare function createLocalTeamStore(options?: SqliteTeamStoreOptions): {
7
+ init(): void;
8
+ listTeamNames(): string[];
9
+ readState(teamName: string): ReturnType<FileTeamStore["readState"]>;
10
+ readHistory(teamName: string, limit?: number): unknown[];
11
+ loadRuntime(teamName: string): ReturnType<FileTeamStore["loadRuntime"]>;
12
+ handleTeamEvent: FileTeamStore["handleTeamEvent"];
13
+ persistRuntime: FileTeamStore["persistRuntime"];
14
+ markInProgressRunsInterrupted: FileTeamStore["markInProgressRunsInterrupted"];
15
+ };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@clinebot/core",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "main": "./dist/index.node.js",
5
5
  "dependencies": {
6
- "@clinebot/agents": "0.0.14",
7
- "@clinebot/llms": "0.0.14",
8
- "@clinebot/shared": "0.0.14",
6
+ "@clinebot/agents": "0.0.16",
7
+ "@clinebot/llms": "0.0.16",
8
+ "@clinebot/shared": "0.0.16",
9
9
  "@opentelemetry/api": "^1.9.0",
10
10
  "@opentelemetry/api-logs": "^0.56.0",
11
11
  "@opentelemetry/exporter-logs-otlp-http": "^0.56.0",
@@ -6,6 +6,7 @@ import type {
6
6
  ClineAccountPaymentTransaction,
7
7
  ClineAccountUsageTransaction,
8
8
  ClineAccountUser,
9
+ UserRemoteConfigResponse,
9
10
  } from "./types";
10
11
 
11
12
  const DEFAULT_TIMEOUT_MS = 30_000;
@@ -63,6 +64,12 @@ export class ClineAccountService {
63
64
  return this.request<ClineAccountUser>("/api/v1/users/me");
64
65
  }
65
66
 
67
+ public async fetchRemoteConfig(): Promise<UserRemoteConfigResponse> {
68
+ return this.request<UserRemoteConfigResponse>(
69
+ "/api/v1/users/me/remote-config",
70
+ );
71
+ }
72
+
66
73
  public async fetchBalance(userId?: string): Promise<ClineAccountBalance> {
67
74
  const resolvedUserId = await this.resolveUserId(userId);
68
75
  return this.request<ClineAccountBalance>(
@@ -17,4 +17,5 @@ export type {
17
17
  ClineAccountPaymentTransaction,
18
18
  ClineAccountUsageTransaction,
19
19
  ClineAccountUser,
20
+ UserRemoteConfigResponse,
20
21
  } from "./types";
@@ -16,6 +16,12 @@ export interface ClineAccountUser {
16
16
  organizations: ClineAccountOrganization[];
17
17
  }
18
18
 
19
+ export interface UserRemoteConfigResponse {
20
+ organizationId: string;
21
+ value: string;
22
+ enabled: boolean;
23
+ }
24
+
19
25
  export interface ClineAccountBalance {
20
26
  balance: number;
21
27
  userId: string;
@@ -39,7 +39,7 @@ describe("agent config YAML loader", () => {
39
39
  it("resolves default agents settings directory from CLINE_DATA_DIR", () => {
40
40
  process.env.CLINE_DATA_DIR = "/tmp/cline-data";
41
41
  expect(resolveAgentsConfigDirPath()).toBe(
42
- `/tmp/cline-data/settings/${AGENT_CONFIG_DIRECTORY_NAME}`,
42
+ join("/tmp/cline-data", "settings", AGENT_CONFIG_DIRECTORY_NAME),
43
43
  );
44
44
  });
45
45
 
@@ -47,7 +47,7 @@ describe("agent config YAML loader", () => {
47
47
  process.env.CLINE_DATA_DIR = "/tmp/cline-data";
48
48
  expect(resolveAgentConfigSearchPaths()).toEqual([
49
49
  resolveDocumentsAgentConfigDirectoryPath(),
50
- `/tmp/cline-data/settings/${AGENT_CONFIG_DIRECTORY_NAME}`,
50
+ join("/tmp/cline-data", "settings", AGENT_CONFIG_DIRECTORY_NAME),
51
51
  ]);
52
52
  });
53
53
 
@@ -57,7 +57,7 @@ describe("agent config YAML loader", () => {
57
57
  expect(definition.type).toBe("agent");
58
58
  expect(definition.directories).toEqual([
59
59
  resolveDocumentsAgentConfigDirectoryPath(),
60
- `/tmp/cline-data/settings/${AGENT_CONFIG_DIRECTORY_NAME}`,
60
+ join("/tmp/cline-data", "settings", AGENT_CONFIG_DIRECTORY_NAME),
61
61
  ]);
62
62
  expect(definition.includeFile?.("agent.yaml", "/tmp/agent.yaml")).toBe(
63
63
  true,
@@ -0,0 +1,20 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+ import {
3
+ HookConfigFileName,
4
+ toHookConfigFileName,
5
+ } from "./hooks-config-loader";
6
+
7
+ describe("hooks config loader", () => {
8
+ afterEach(() => {
9
+ delete process.env.CLINE_DATA_DIR;
10
+ });
11
+
12
+ it("recognizes PowerShell hook files", () => {
13
+ expect(toHookConfigFileName("PreToolUse.ps1")).toBe(
14
+ HookConfigFileName.PreToolUse,
15
+ );
16
+ expect(toHookConfigFileName("TaskError.ps1")).toBe(
17
+ HookConfigFileName.TaskError,
18
+ );
19
+ });
20
+ });
@@ -59,6 +59,7 @@ const SUPPORTED_HOOK_FILE_EXTENSIONS = new Set([
59
59
  ".mts",
60
60
  ".cts",
61
61
  ".py",
62
+ ".ps1",
62
63
  ]);
63
64
 
64
65
  export function toHookConfigFileName(
@@ -46,17 +46,17 @@ describe("user instruction config loader", () => {
46
46
  const workspacePath = "/repo/demo";
47
47
  expect(resolveSkillsConfigSearchPaths(workspacePath)).toEqual(
48
48
  expect.arrayContaining([
49
- "/repo/demo/.clinerules/skills",
50
- "/repo/demo/.cline/skills",
51
- "/repo/demo/.claude/skills",
52
- "/repo/demo/.agents/skills",
49
+ join(workspacePath, ".clinerules", "skills"),
50
+ join(workspacePath, ".cline", "skills"),
51
+ join(workspacePath, ".claude", "skills"),
52
+ join(workspacePath, ".agents", "skills"),
53
53
  ]),
54
54
  );
55
55
  expect(resolveRulesConfigSearchPaths(workspacePath)).toEqual(
56
- expect.arrayContaining(["/repo/demo/.clinerules"]),
56
+ expect.arrayContaining([join(workspacePath, ".clinerules")]),
57
57
  );
58
58
  expect(resolveWorkflowsConfigSearchPaths(workspacePath)).toEqual(
59
- expect.arrayContaining(["/repo/demo/.clinerules/workflows"]),
59
+ expect.arrayContaining([join(workspacePath, ".clinerules", "workflows")]),
60
60
  );
61
61
  });
62
62
 
package/src/index.node.ts CHANGED
@@ -103,6 +103,23 @@ export {
103
103
  export async function loadOpenTelemetryAdapter() {
104
104
  return import("./telemetry/opentelemetry.js");
105
105
  }
106
+ export {
107
+ type ClineAccountBalance,
108
+ type ClineAccountOperations,
109
+ type ClineAccountOrganization,
110
+ type ClineAccountOrganizationBalance,
111
+ type ClineAccountOrganizationUsageTransaction,
112
+ type ClineAccountPaymentTransaction,
113
+ ClineAccountService,
114
+ type ClineAccountServiceOptions,
115
+ type ClineAccountUsageTransaction,
116
+ type ClineAccountUser,
117
+ executeRpcClineAccountAction,
118
+ isRpcClineAccountActionRequest,
119
+ RpcClineAccountService,
120
+ type RpcProviderActionExecutor,
121
+ type UserRemoteConfigResponse,
122
+ } from "./account";
106
123
  export { startLocalOAuthServer } from "./auth/server";
107
124
  export type {
108
125
  OAuthCredentials,
@@ -127,6 +144,28 @@ export {
127
144
  getFileIndex,
128
145
  prewarmFileIndex,
129
146
  } from "./input";
147
+ export {
148
+ hasMcpSettingsFile,
149
+ InMemoryMcpManager,
150
+ type LoadMcpSettingsOptions,
151
+ loadMcpSettingsFile,
152
+ type McpConnectionStatus,
153
+ type McpManager,
154
+ type McpManagerOptions,
155
+ type McpServerClient,
156
+ type McpServerClientFactory,
157
+ type McpServerRegistration,
158
+ type McpServerSnapshot,
159
+ type McpServerTransportConfig,
160
+ type McpSettingsFile,
161
+ type McpSseTransportConfig,
162
+ type McpStdioTransportConfig,
163
+ type McpStreamableHttpTransportConfig,
164
+ type RegisterMcpServersFromSettingsOptions,
165
+ registerMcpServersFromSettingsFile,
166
+ resolveDefaultMcpSettingsPath,
167
+ resolveMcpServerRegistrations,
168
+ } from "./mcp";
130
169
  export {
131
170
  addLocalProvider,
132
171
  ensureCustomProvidersLoaded,
@@ -172,6 +172,40 @@ describe("createHookConfigFileHooks", () => {
172
172
  }
173
173
  });
174
174
 
175
+ it.skipIf(process.platform !== "win32")(
176
+ "executes PowerShell hook files on Windows",
177
+ async () => {
178
+ const { workspace } = await createWorkspaceWithHook(
179
+ "PreToolUse.ps1",
180
+ 'Write-Output \'HOOK_CONTROL\t{"cancel": false, "context": "powershell-ok"}\'\n',
181
+ );
182
+ try {
183
+ const hooks = createHookConfigFileHooks({
184
+ cwd: workspace,
185
+ workspacePath: workspace,
186
+ });
187
+ expect(hooks?.onToolCallStart).toBeTypeOf("function");
188
+ const control = await hooks?.onToolCallStart?.({
189
+ agentId: "agent_1",
190
+ conversationId: "conv_1",
191
+ parentAgentId: null,
192
+ iteration: 1,
193
+ call: {
194
+ id: "call_1",
195
+ name: "read_file",
196
+ input: { path: "README.md" },
197
+ },
198
+ });
199
+ expect(control).toMatchObject({
200
+ cancel: false,
201
+ context: "powershell-ok",
202
+ });
203
+ } finally {
204
+ await rm(workspace, { recursive: true, force: true });
205
+ }
206
+ },
207
+ );
208
+
175
209
  it("maps TaskError hook files to agent_error stop events", async () => {
176
210
  const outputPath = join(tmpdir(), `hooks-task-error-${Date.now()}.json`);
177
211
  const { workspace } = await createWorkspaceWithHook(
@@ -345,10 +345,33 @@ function parseShebangCommand(path: string): string[] | undefined {
345
345
  }
346
346
  }
347
347
 
348
+ function normalizeHookInterpreter(tokens: string[]): string[] | undefined {
349
+ if (tokens.length === 0) {
350
+ return undefined;
351
+ }
352
+ const [rawCommand, ...rest] = tokens;
353
+ const normalizedCommand = rawCommand.replace(/\\/g, "/").toLowerCase();
354
+ const commandName = normalizedCommand.split("/").at(-1) ?? normalizedCommand;
355
+
356
+ if (commandName === "env") {
357
+ return normalizeHookInterpreter(rest);
358
+ }
359
+
360
+ if (commandName === "bash" || commandName === "sh" || commandName === "zsh") {
361
+ return [commandName, ...rest];
362
+ }
363
+
364
+ if (commandName === "python3" || commandName === "python") {
365
+ return [process.platform === "win32" ? "python" : commandName, ...rest];
366
+ }
367
+
368
+ return tokens;
369
+ }
370
+
348
371
  function inferHookCommand(path: string): string[] {
349
372
  const shebang = parseShebangCommand(path);
350
373
  if (shebang && shebang.length > 0) {
351
- return [...shebang, path];
374
+ return [...(normalizeHookInterpreter(shebang) ?? shebang), path];
352
375
  }
353
376
  const lowered = path.toLowerCase();
354
377
  if (
@@ -356,7 +379,7 @@ function inferHookCommand(path: string): string[] {
356
379
  lowered.endsWith(".bash") ||
357
380
  lowered.endsWith(".zsh")
358
381
  ) {
359
- return ["/bin/bash", path];
382
+ return ["bash", path];
360
383
  }
361
384
  if (
362
385
  lowered.endsWith(".js") ||
@@ -373,10 +396,17 @@ function inferHookCommand(path: string): string[] {
373
396
  return ["bun", "run", path];
374
397
  }
375
398
  if (lowered.endsWith(".py")) {
376
- return ["python3", path];
399
+ return [process.platform === "win32" ? "python" : "python3", path];
400
+ }
401
+ if (lowered.endsWith(".ps1")) {
402
+ return [
403
+ process.platform === "win32" ? "powershell" : "pwsh",
404
+ "-File",
405
+ path,
406
+ ];
377
407
  }
378
408
  // Default to bash for legacy hook files with no extension/shebang.
379
- return ["/bin/bash", path];
409
+ return ["bash", path];
380
410
  }
381
411
 
382
412
  function createHookCommandMap(workspacePath: string): HookCommandMap {
@@ -49,13 +49,12 @@ vi.mock("../default-tools", () => ({
49
49
  },
50
50
  }));
51
51
 
52
- let teamStoreInstance: MockSqliteTeamStore | undefined;
53
- class MockSqliteTeamStore {
52
+ let teamStoreInstance: MockTeamStore | undefined;
53
+ class MockTeamStore {
54
54
  constructor() {
55
55
  teamStoreInstance = this;
56
56
  }
57
57
 
58
- init = vi.fn();
59
58
  loadRuntime = vi.fn(() => ({
60
59
  state: {
61
60
  teamId: "team_1",
@@ -82,8 +81,8 @@ class MockSqliteTeamStore {
82
81
  persistRuntime = vi.fn();
83
82
  }
84
83
 
85
- vi.mock("../storage/sqlite-team-store", () => ({
86
- SqliteTeamStore: MockSqliteTeamStore,
84
+ vi.mock("../storage/team-store", () => ({
85
+ createLocalTeamStore: () => new MockTeamStore(),
87
86
  }));
88
87
 
89
88
  describe("DefaultRuntimeBuilder team persistence boundary", () => {
@@ -14,7 +14,7 @@ import {
14
14
  type SkillConfig,
15
15
  type UserInstructionConfigWatcher,
16
16
  } from "../agents";
17
- import { SqliteTeamStore } from "../storage/sqlite-team-store";
17
+ import { createLocalTeamStore } from "../storage/team-store";
18
18
  import {
19
19
  createBuiltinTools,
20
20
  DEFAULT_MODEL_TOOL_ROUTING_RULES,
@@ -418,9 +418,8 @@ export class DefaultRuntimeBuilder implements RuntimeBuilder {
418
418
 
419
419
  let teamRuntime: AgentTeamsRuntime | undefined;
420
420
  const teamStore = normalized.enableAgentTeams
421
- ? new SqliteTeamStore()
421
+ ? createLocalTeamStore()
422
422
  : undefined;
423
- teamStore?.init();
424
423
  const restoredTeam = teamStore?.loadRuntime(effectiveTeamName);
425
424
  const restoredTeamState = restoredTeam?.state;
426
425
  const restoredTeammateSpecs = restoredTeam?.teammates ?? [];
@@ -36,6 +36,7 @@ import { SessionSource, type SessionStatus } from "../types/common";
36
36
  import type { CoreSessionConfig } from "../types/config";
37
37
  import type { CoreSessionEvent } from "../types/events";
38
38
  import type { SessionRecord } from "../types/sessions";
39
+ import type { FileSessionService } from "./file-session-service";
39
40
  import type { RpcCoreSessionService } from "./rpc-session-service";
40
41
  import {
41
42
  OAuthReauthRequiredError,
@@ -92,7 +93,10 @@ import {
92
93
  createInitialAccumulatedUsage,
93
94
  } from "./utils/usage";
94
95
 
95
- type SessionBackend = CoreSessionService | RpcCoreSessionService;
96
+ type SessionBackend =
97
+ | CoreSessionService
98
+ | RpcCoreSessionService
99
+ | FileSessionService;
96
100
 
97
101
  const MAX_SCAN_LIMIT = 5000;
98
102
  const MAX_USER_FILE_BYTES = 20 * 1_000 * 1_024;