@clinebot/core 0.0.7 → 0.0.10

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 (67) hide show
  1. package/dist/auth/cline.d.ts +2 -0
  2. package/dist/auth/codex.d.ts +5 -1
  3. package/dist/auth/oca.d.ts +7 -1
  4. package/dist/auth/types.d.ts +2 -0
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.node.d.ts +1 -0
  7. package/dist/index.node.js +164 -162
  8. package/dist/input/mention-enricher.d.ts +1 -0
  9. package/dist/providers/local-provider-service.d.ts +1 -1
  10. package/dist/runtime/session-runtime.d.ts +1 -1
  11. package/dist/session/default-session-manager.d.ts +13 -17
  12. package/dist/session/runtime-oauth-token-manager.d.ts +4 -2
  13. package/dist/session/session-agent-events.d.ts +15 -0
  14. package/dist/session/session-config-builder.d.ts +13 -0
  15. package/dist/session/session-manager.d.ts +2 -2
  16. package/dist/session/session-team-coordination.d.ts +12 -0
  17. package/dist/session/session-telemetry.d.ts +9 -0
  18. package/dist/session/unified-session-persistence-service.d.ts +12 -16
  19. package/dist/session/utils/helpers.d.ts +1 -1
  20. package/dist/session/utils/types.d.ts +1 -1
  21. package/dist/telemetry/core-events.d.ts +122 -0
  22. package/dist/tools/definitions.d.ts +1 -1
  23. package/dist/tools/executors/file-read.d.ts +1 -1
  24. package/dist/tools/index.d.ts +1 -1
  25. package/dist/tools/presets.d.ts +1 -1
  26. package/dist/tools/schemas.d.ts +46 -3
  27. package/dist/tools/types.d.ts +3 -3
  28. package/dist/types/config.d.ts +1 -1
  29. package/dist/types/provider-settings.d.ts +4 -4
  30. package/dist/types.d.ts +1 -1
  31. package/package.json +4 -3
  32. package/src/auth/cline.ts +35 -1
  33. package/src/auth/codex.ts +27 -2
  34. package/src/auth/oca.ts +31 -4
  35. package/src/auth/types.ts +3 -0
  36. package/src/index.ts +27 -0
  37. package/src/input/mention-enricher.test.ts +3 -0
  38. package/src/input/mention-enricher.ts +3 -0
  39. package/src/providers/local-provider-service.ts +6 -7
  40. package/src/runtime/hook-file-hooks.ts +11 -10
  41. package/src/runtime/session-runtime.ts +1 -1
  42. package/src/session/default-session-manager.e2e.test.ts +2 -1
  43. package/src/session/default-session-manager.ts +367 -601
  44. package/src/session/runtime-oauth-token-manager.ts +21 -14
  45. package/src/session/session-agent-events.ts +159 -0
  46. package/src/session/session-config-builder.ts +111 -0
  47. package/src/session/session-host.ts +13 -0
  48. package/src/session/session-manager.ts +2 -2
  49. package/src/session/session-team-coordination.ts +198 -0
  50. package/src/session/session-telemetry.ts +95 -0
  51. package/src/session/unified-session-persistence-service.test.ts +81 -0
  52. package/src/session/unified-session-persistence-service.ts +470 -469
  53. package/src/session/utils/helpers.ts +1 -1
  54. package/src/session/utils/types.ts +1 -1
  55. package/src/storage/provider-settings-legacy-migration.ts +3 -3
  56. package/src/telemetry/core-events.ts +344 -0
  57. package/src/tools/definitions.test.ts +121 -7
  58. package/src/tools/definitions.ts +60 -24
  59. package/src/tools/executors/file-read.test.ts +29 -5
  60. package/src/tools/executors/file-read.ts +17 -6
  61. package/src/tools/index.ts +2 -0
  62. package/src/tools/presets.ts +1 -1
  63. package/src/tools/schemas.ts +65 -5
  64. package/src/tools/types.ts +7 -3
  65. package/src/types/config.ts +1 -1
  66. package/src/types/provider-settings.ts +6 -6
  67. package/src/types.ts +1 -1
@@ -12,14 +12,38 @@ describe("createFileReadExecutor", () => {
12
12
 
13
13
  try {
14
14
  const readFile = createFileReadExecutor();
15
- const result = await readFile(filePath, {
16
- agentId: "agent-1",
17
- conversationId: "conv-1",
18
- iteration: 1,
19
- });
15
+ const result = await readFile(
16
+ { path: filePath },
17
+ {
18
+ agentId: "agent-1",
19
+ conversationId: "conv-1",
20
+ iteration: 1,
21
+ },
22
+ );
20
23
  expect(result).toBe("1 | hello absolute path");
21
24
  } finally {
22
25
  await fs.rm(dir, { recursive: true, force: true });
23
26
  }
24
27
  });
28
+
29
+ it("returns only the requested inclusive line range", async () => {
30
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "agents-file-read-"));
31
+ const filePath = path.join(dir, "example.txt");
32
+ await fs.writeFile(filePath, "alpha\nbeta\ngamma\ndelta", "utf-8");
33
+
34
+ try {
35
+ const readFile = createFileReadExecutor();
36
+ const result = await readFile(
37
+ { path: filePath, start_line: 2, end_line: 3 },
38
+ {
39
+ agentId: "agent-1",
40
+ conversationId: "conv-1",
41
+ iteration: 1,
42
+ },
43
+ );
44
+ expect(result).toBe("2 | beta\n3 | gamma");
45
+ } finally {
46
+ await fs.rm(dir, { recursive: true, force: true });
47
+ }
48
+ });
25
49
  });
@@ -7,6 +7,7 @@
7
7
  import * as fs from "node:fs/promises";
8
8
  import * as path from "node:path";
9
9
  import type { ToolContext } from "@clinebot/agents";
10
+ import type { ReadFileRequest } from "../schemas.js";
10
11
  import type { FileReadExecutor } from "../types.js";
11
12
 
12
13
  /**
@@ -48,7 +49,7 @@ const DEFAULT_FILE_READ_OPTIONS: Required<FileReadExecutorOptions> = {
48
49
  * includeLineNumbers: true,
49
50
  * })
50
51
  *
51
- * const content = await readFile("/path/to/file.ts", context)
52
+ * const content = await readFile({ path: "/path/to/file.ts" }, context)
52
53
  * ```
53
54
  */
54
55
  export function createFileReadExecutor(
@@ -59,7 +60,11 @@ export function createFileReadExecutor(
59
60
  ...options,
60
61
  };
61
62
 
62
- return async (filePath: string, _context: ToolContext): Promise<string> => {
63
+ return async (
64
+ request: ReadFileRequest,
65
+ _context: ToolContext,
66
+ ): Promise<string> => {
67
+ const { path: filePath, start_line, end_line } = request;
63
68
  const resolvedPath = path.isAbsolute(filePath)
64
69
  ? path.normalize(filePath)
65
70
  : path.resolve(process.cwd(), filePath);
@@ -81,19 +86,25 @@ export function createFileReadExecutor(
81
86
 
82
87
  // Read file content
83
88
  const content = await fs.readFile(resolvedPath, encoding);
89
+ const allLines = content.split("\n");
90
+ const rangeStart = Math.max((start_line ?? 1) - 1, 0);
91
+ const rangeEndExclusive = Math.min(
92
+ end_line ?? allLines.length,
93
+ allLines.length,
94
+ );
95
+ const lines = allLines.slice(rangeStart, rangeEndExclusive);
84
96
 
85
97
  // Optionally add line numbers - one-based indexing for better readability
86
98
  if (includeLineNumbers) {
87
- const lines = content.split("\n");
88
- const maxLineNumWidth = String(lines.length).length;
99
+ const maxLineNumWidth = String(allLines.length).length;
89
100
  return lines
90
101
  .map(
91
102
  (line, i) =>
92
- `${String(i + 1).padStart(maxLineNumWidth, " ")} | ${line}`,
103
+ `${String(rangeStart + i + 1).padStart(maxLineNumWidth, " ")} | ${line}`,
93
104
  )
94
105
  .join("\n");
95
106
  }
96
107
 
97
- return content;
108
+ return lines.join("\n");
98
109
  };
99
110
  }
@@ -60,6 +60,8 @@ export {
60
60
  EditFileInputSchema,
61
61
  type FetchWebContentInput,
62
62
  FetchWebContentInputSchema,
63
+ type ReadFileRequest,
64
+ ReadFileRequestSchema,
63
65
  type ReadFilesInput,
64
66
  ReadFilesInputSchema,
65
67
  type RunCommandsInput,
@@ -147,7 +147,7 @@ export function createToolPoliciesWithPreset(
147
147
  * ```typescript
148
148
  * const tools = createDefaultToolsWithPreset("readonly", {
149
149
  * executors: {
150
- * readFile: async (path) => fs.readFile(path, "utf-8"),
150
+ * readFile: async ({ path }) => fs.readFile(path, "utf-8"),
151
151
  * search: async (query, cwd) => searchFiles(query, cwd),
152
152
  * webFetch: async (url, prompt) => fetchAndAnalyze(url, prompt),
153
153
  * },
@@ -14,14 +14,57 @@ const AbsolutePath = z
14
14
  .string()
15
15
  .describe("The absolute file path of a text file to read content from");
16
16
 
17
+ export const ReadFileLineRangeSchema = z
18
+ .object({
19
+ start_line: z
20
+ .number()
21
+ .int()
22
+ .positive()
23
+ .optional()
24
+ .describe("Optional one-based starting line number to read from"),
25
+ end_line: z
26
+ .number()
27
+ .int()
28
+ .positive()
29
+ .optional()
30
+ .describe("Optional one-based ending line number to read through"),
31
+ })
32
+ .refine(
33
+ ({ start_line, end_line }) =>
34
+ start_line === undefined ||
35
+ end_line === undefined ||
36
+ start_line <= end_line,
37
+ {
38
+ message: "start_line must be less than or equal to end_line",
39
+ path: ["end_line"],
40
+ },
41
+ );
42
+
43
+ export const ReadFileRequestSchema = z
44
+ .object({
45
+ path: AbsolutePath,
46
+ start_line: ReadFileLineRangeSchema.shape.start_line,
47
+ end_line: ReadFileLineRangeSchema.shape.end_line,
48
+ })
49
+ .refine(
50
+ ({ start_line, end_line }) =>
51
+ start_line === undefined ||
52
+ end_line === undefined ||
53
+ start_line <= end_line,
54
+ {
55
+ message: "start_line must be less than or equal to end_line",
56
+ path: ["end_line"],
57
+ },
58
+ );
59
+
17
60
  /**
18
61
  * Schema for read_files tool input
19
62
  */
20
63
  export const ReadFilesInputSchema = z.object({
21
- file_paths: z
22
- .array(AbsolutePath)
64
+ files: z
65
+ .array(ReadFileRequestSchema)
23
66
  .describe(
24
- "Array of absolute file paths to get full content from. Prefer this tool over running terminal command to get file content for better performance and reliability.",
67
+ "Array of file read requests. Omit start_line and end_line to return the full file content; provide them to return only that inclusive one-based line range. Prefer this tool over running terminal command to get file content for better performance and reliability.",
25
68
  ),
26
69
  });
27
70
 
@@ -30,8 +73,13 @@ export const ReadFilesInputSchema = z.object({
30
73
  */
31
74
  export const ReadFilesInputUnionSchema = z.union([
32
75
  ReadFilesInputSchema,
76
+ ReadFileRequestSchema,
77
+ z.array(ReadFileRequestSchema),
33
78
  z.array(z.string()),
34
79
  z.string(),
80
+ z.object({ files: ReadFileRequestSchema }),
81
+ z.object({ file_paths: z.array(AbsolutePath) }),
82
+ z.object({ file_paths: z.string() }),
35
83
  ]);
36
84
 
37
85
  /**
@@ -50,11 +98,15 @@ export const SearchCodebaseUnionInputSchema = z.union([
50
98
  SearchCodebaseInputSchema,
51
99
  z.array(z.string()),
52
100
  z.string(),
101
+ z.object({ queries: z.string() }),
53
102
  ]);
54
103
 
55
104
  const CommandInputSchema = z
56
105
  .string()
57
- .describe("The non-interactive shell command to execute");
106
+ .max(2000)
107
+ .describe(
108
+ "The non-interactive shell command to execute - MUST keep input short and concise to avoid timeouts",
109
+ );
58
110
  /**
59
111
  * Schema for run_commands tool input
60
112
  */
@@ -69,6 +121,7 @@ export const RunCommandsInputSchema = z.object({
69
121
  */
70
122
  export const RunCommandsInputUnionSchema = z.union([
71
123
  RunCommandsInputSchema,
124
+ z.object({ commands: CommandInputSchema }),
72
125
  z.array(z.string()),
73
126
  z.string(),
74
127
  ]);
@@ -101,6 +154,7 @@ export const EditFileInputSchema = z
101
154
  .describe("The absolute file path for the action to be performed on"),
102
155
  old_text: z
103
156
  .string()
157
+ .max(3000)
104
158
  .nullable()
105
159
  .optional()
106
160
  .describe(
@@ -108,8 +162,9 @@ export const EditFileInputSchema = z
108
162
  ),
109
163
  new_text: z
110
164
  .string()
165
+ .max(3000)
111
166
  .describe(
112
- "The new content to write when creating a missing file, the replacement text for edits, or the inserted text when insert_line is provided",
167
+ "The new content to write when creating a missing file, the replacement text for edits, or the inserted text when insert_line is provided - IMPORTANT: keep this as small as possible to avoid timeouts. For large edits, use multiple calls with small chunks of new_text and precise old_text to iteratively edit the file.",
113
168
  ),
114
169
  insert_line: z
115
170
  .number()
@@ -178,6 +233,11 @@ export const AskQuestionInputSchema = z.object({
178
233
  // Type Definitions (derived from Zod schemas)
179
234
  // =============================================================================
180
235
 
236
+ /**
237
+ * Input for a single file read request
238
+ */
239
+ export type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
240
+
181
241
  /**
182
242
  * Input for the read_files tool
183
243
  */
@@ -5,7 +5,11 @@
5
5
  */
6
6
 
7
7
  import type { ToolContext } from "@clinebot/agents";
8
- import type { ApplyPatchInput, EditFileInput } from "./schemas";
8
+ import type {
9
+ ApplyPatchInput,
10
+ EditFileInput,
11
+ ReadFileRequest,
12
+ } from "./schemas";
9
13
 
10
14
  // =============================================================================
11
15
  // Tool Result Types
@@ -34,12 +38,12 @@ export interface ToolOperationResult {
34
38
  /**
35
39
  * Executor for reading files
36
40
  *
37
- * @param filePath - Absolute path to the file to read
41
+ * @param request - File path and optional inclusive line range to read
38
42
  * @param context - Tool execution context
39
43
  * @returns The file content as a string
40
44
  */
41
45
  export type FileReadExecutor = (
42
- filePath: string,
46
+ request: ReadFileRequest,
43
47
  context: ToolContext,
44
48
  ) => Promise<string>;
45
49
 
@@ -7,7 +7,7 @@ import type {
7
7
  TeamEvent,
8
8
  Tool,
9
9
  } from "@clinebot/agents";
10
- import type { providers as LlmsProviders } from "@clinebot/llms";
10
+ import type { LlmsProviders } from "@clinebot/llms";
11
11
  import type {
12
12
  AgentMode,
13
13
  BasicLogger,
@@ -1,11 +1,11 @@
1
- import { providers } from "@clinebot/llms";
1
+ import { LlmsProviders } from "@clinebot/llms";
2
2
  import { z } from "zod";
3
3
 
4
- export type ProviderConfig = providers.ProviderConfig;
5
- export type ProviderSettings = providers.ProviderSettings;
4
+ export type ProviderConfig = LlmsProviders.ProviderConfig;
5
+ export type ProviderSettings = LlmsProviders.ProviderSettings;
6
6
  export const ProviderSettingsSchema: z.ZodType<ProviderSettings> =
7
- providers.ProviderSettingsSchema;
8
- export const toProviderConfig = providers.toProviderConfig;
7
+ LlmsProviders.ProviderSettingsSchema;
8
+ export const toProviderConfig = LlmsProviders.toProviderConfig;
9
9
 
10
10
  export type ProviderTokenSource = "manual" | "oauth" | "migration";
11
11
 
@@ -23,7 +23,7 @@ export interface StoredProviderSettings {
23
23
 
24
24
  export const StoredProviderSettingsEntrySchema: z.ZodType<StoredProviderSettingsEntry> =
25
25
  z.object({
26
- settings: providers.ProviderSettingsSchema,
26
+ settings: LlmsProviders.ProviderSettingsSchema,
27
27
  updatedAt: z.string().datetime(),
28
28
  tokenSource: z.enum(["manual", "oauth", "migration"]).default("manual"),
29
29
  });
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { providers as LlmsProviders } from "@clinebot/llms";
1
+ import type { LlmsProviders } from "@clinebot/llms";
2
2
  import type { CoreSessionEvent } from "./types/events";
3
3
 
4
4
  export type {