@clinebot/core 0.0.6 → 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 (83) hide show
  1. package/dist/agents/hooks-config-loader.d.ts +1 -0
  2. package/dist/auth/cline.d.ts +2 -0
  3. package/dist/auth/codex.d.ts +5 -1
  4. package/dist/auth/oca.d.ts +7 -1
  5. package/dist/auth/types.d.ts +2 -0
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.node.d.ts +2 -0
  8. package/dist/index.node.js +164 -162
  9. package/dist/input/mention-enricher.d.ts +1 -0
  10. package/dist/providers/local-provider-service.d.ts +1 -1
  11. package/dist/runtime/session-runtime.d.ts +1 -1
  12. package/dist/session/default-session-manager.d.ts +13 -17
  13. package/dist/session/rpc-spawn-lease.d.ts +7 -0
  14. package/dist/session/runtime-oauth-token-manager.d.ts +4 -2
  15. package/dist/session/session-agent-events.d.ts +15 -0
  16. package/dist/session/session-config-builder.d.ts +13 -0
  17. package/dist/session/session-manager.d.ts +2 -2
  18. package/dist/session/session-team-coordination.d.ts +12 -0
  19. package/dist/session/session-telemetry.d.ts +9 -0
  20. package/dist/session/unified-session-persistence-service.d.ts +12 -16
  21. package/dist/session/utils/helpers.d.ts +1 -1
  22. package/dist/session/utils/types.d.ts +1 -1
  23. package/dist/storage/provider-settings-legacy-migration.d.ts +25 -0
  24. package/dist/telemetry/core-events.d.ts +122 -0
  25. package/dist/tools/definitions.d.ts +1 -1
  26. package/dist/tools/executors/file-read.d.ts +1 -1
  27. package/dist/tools/index.d.ts +1 -1
  28. package/dist/tools/presets.d.ts +1 -1
  29. package/dist/tools/schemas.d.ts +48 -11
  30. package/dist/tools/types.d.ts +3 -3
  31. package/dist/types/config.d.ts +1 -1
  32. package/dist/types/events.d.ts +1 -1
  33. package/dist/types/provider-settings.d.ts +4 -4
  34. package/dist/types.d.ts +1 -1
  35. package/package.json +4 -3
  36. package/src/agents/hooks-config-loader.ts +2 -0
  37. package/src/auth/cline.ts +35 -1
  38. package/src/auth/codex.ts +27 -2
  39. package/src/auth/oca.ts +31 -4
  40. package/src/auth/types.ts +3 -0
  41. package/src/index.node.ts +4 -0
  42. package/src/index.ts +27 -0
  43. package/src/input/file-indexer.test.ts +40 -0
  44. package/src/input/file-indexer.ts +21 -0
  45. package/src/input/mention-enricher.test.ts +3 -0
  46. package/src/input/mention-enricher.ts +3 -0
  47. package/src/providers/local-provider-service.ts +6 -7
  48. package/src/runtime/hook-file-hooks.test.ts +51 -1
  49. package/src/runtime/hook-file-hooks.ts +91 -11
  50. package/src/runtime/session-runtime.ts +1 -1
  51. package/src/session/default-session-manager.e2e.test.ts +2 -1
  52. package/src/session/default-session-manager.ts +367 -601
  53. package/src/session/rpc-spawn-lease.test.ts +49 -0
  54. package/src/session/rpc-spawn-lease.ts +122 -0
  55. package/src/session/runtime-oauth-token-manager.ts +21 -14
  56. package/src/session/session-agent-events.ts +159 -0
  57. package/src/session/session-config-builder.ts +111 -0
  58. package/src/session/session-graph.ts +2 -0
  59. package/src/session/session-host.ts +21 -0
  60. package/src/session/session-manager.ts +2 -2
  61. package/src/session/session-team-coordination.ts +198 -0
  62. package/src/session/session-telemetry.ts +95 -0
  63. package/src/session/unified-session-persistence-service.test.ts +81 -0
  64. package/src/session/unified-session-persistence-service.ts +470 -469
  65. package/src/session/utils/helpers.ts +1 -1
  66. package/src/session/utils/types.ts +1 -1
  67. package/src/storage/provider-settings-legacy-migration.test.ts +133 -1
  68. package/src/storage/provider-settings-legacy-migration.ts +63 -11
  69. package/src/telemetry/core-events.ts +344 -0
  70. package/src/tools/definitions.test.ts +203 -36
  71. package/src/tools/definitions.ts +66 -28
  72. package/src/tools/executors/editor.test.ts +35 -0
  73. package/src/tools/executors/editor.ts +33 -46
  74. package/src/tools/executors/file-read.test.ts +29 -5
  75. package/src/tools/executors/file-read.ts +17 -6
  76. package/src/tools/index.ts +2 -0
  77. package/src/tools/presets.ts +1 -1
  78. package/src/tools/schemas.ts +88 -38
  79. package/src/tools/types.ts +7 -3
  80. package/src/types/config.ts +1 -1
  81. package/src/types/events.ts +6 -1
  82. package/src/types/provider-settings.ts +6 -6
  83. package/src/types.ts +1 -1
@@ -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,16 +98,22 @@ 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
- const CommandInputSchema = z.string();
104
+ const CommandInputSchema = z
105
+ .string()
106
+ .max(2000)
107
+ .describe(
108
+ "The non-interactive shell command to execute - MUST keep input short and concise to avoid timeouts",
109
+ );
56
110
  /**
57
111
  * Schema for run_commands tool input
58
112
  */
59
113
  export const RunCommandsInputSchema = z.object({
60
114
  commands: z
61
115
  .array(CommandInputSchema)
62
- .describe("Array of shell commands to execute."),
116
+ .describe("Array of shell commands to execute"),
63
117
  });
64
118
 
65
119
  /**
@@ -67,8 +121,9 @@ export const RunCommandsInputSchema = z.object({
67
121
  */
68
122
  export const RunCommandsInputUnionSchema = z.union([
69
123
  RunCommandsInputSchema,
70
- z.array(CommandInputSchema),
71
- CommandInputSchema,
124
+ z.object({ commands: CommandInputSchema }),
125
+ z.array(z.string()),
126
+ z.string(),
72
127
  ]);
73
128
 
74
129
  /**
@@ -93,46 +148,36 @@ export const FetchWebContentInputSchema = z.object({
93
148
  */
94
149
  export const EditFileInputSchema = z
95
150
  .object({
96
- command: z
97
- .enum(["create", "str_replace", "insert"])
98
- .describe("Editor command to execute: create, str_replace, insert"),
99
- path: z.string().min(1).describe("Absolute file path"),
100
- file_text: z
151
+ path: z
101
152
  .string()
102
- .nullish()
103
- .describe("Full file content required for 'create' command"),
104
- old_str: z
153
+ .min(1)
154
+ .describe("The absolute file path for the action to be performed on"),
155
+ old_text: z
105
156
  .string()
106
- .nullish()
157
+ .max(3000)
158
+ .nullable()
159
+ .optional()
107
160
  .describe(
108
- "Exact text to replace (must match exactly once) for 'str_replace' command",
161
+ "Exact text to replace (must match exactly once). Omit this when creating a missing file or inserting via insert_line.",
109
162
  ),
110
- new_str: z
163
+ new_text: z
111
164
  .string()
112
- .nullish()
113
- .describe("Replacement text for 'str_replace' or 'insert' commands"),
165
+ .max(3000)
166
+ .describe(
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.",
168
+ ),
114
169
  insert_line: z
115
170
  .number()
116
171
  .int()
117
- .nullish()
118
- .describe("Optional one-based line index for 'insert' command"),
119
- })
120
- .refine((v) => v.command !== "create" || v.file_text != null, {
121
- path: ["file_text"],
122
- message: "file_text is required for command=create",
123
- })
124
- .refine((v) => v.command !== "str_replace" || v.old_str != null, {
125
- path: ["old_str"],
126
- message: "old_str is required for command=str_replace",
127
- })
128
- .refine((v) => v.command !== "insert" || v.insert_line != null, {
129
- path: ["insert_line"],
130
- message: "insert_line is required for command=insert",
172
+ .nullable()
173
+ .optional()
174
+ .describe(
175
+ "Optional one-based line index. When provided, the tool inserts new_text at that line instead of performing a replacement edit.",
176
+ ),
131
177
  })
132
- .refine((v) => v.command !== "insert" || v.new_str != null, {
133
- path: ["new_str"],
134
- message: "new_str is required for command=insert",
135
- });
178
+ .describe(
179
+ "Edit a text file by replacing old_text with new_text, create the file with new_text if it does not exist, or insert new_text at insert_line when insert_line is provided. IMPORTANT: large edits can time out, so use small chunks and multiple calls when possible.",
180
+ );
136
181
 
137
182
  /**
138
183
  * Schema for apply_patch tool input
@@ -188,6 +233,11 @@ export const AskQuestionInputSchema = z.object({
188
233
  // Type Definitions (derived from Zod schemas)
189
234
  // =============================================================================
190
235
 
236
+ /**
237
+ * Input for a single file read request
238
+ */
239
+ export type ReadFileRequest = z.infer<typeof ReadFileRequestSchema>;
240
+
191
241
  /**
192
242
  * Input for the read_files tool
193
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,
@@ -13,7 +13,12 @@ export interface SessionEndedEvent {
13
13
 
14
14
  export interface SessionToolEvent {
15
15
  sessionId: string;
16
- hookEventName: "tool_call" | "tool_result" | "agent_end" | "session_shutdown";
16
+ hookEventName:
17
+ | "tool_call"
18
+ | "tool_result"
19
+ | "agent_end"
20
+ | "agent_error"
21
+ | "session_shutdown";
17
22
  agentId?: string;
18
23
  conversationId?: string;
19
24
  parentAgentId?: string;
@@ -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 {