@clinebot/core 0.0.7 → 0.0.11
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/auth/cline.d.ts +2 -0
- package/dist/auth/codex.d.ts +5 -1
- package/dist/auth/oca.d.ts +7 -1
- package/dist/auth/types.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.node.js +124 -122
- package/dist/input/mention-enricher.d.ts +1 -0
- package/dist/providers/local-provider-service.d.ts +1 -1
- package/dist/runtime/session-runtime.d.ts +1 -1
- package/dist/session/default-session-manager.d.ts +13 -17
- package/dist/session/runtime-oauth-token-manager.d.ts +4 -2
- package/dist/session/session-agent-events.d.ts +15 -0
- package/dist/session/session-config-builder.d.ts +13 -0
- package/dist/session/session-manager.d.ts +2 -2
- package/dist/session/session-team-coordination.d.ts +12 -0
- package/dist/session/session-telemetry.d.ts +9 -0
- package/dist/session/unified-session-persistence-service.d.ts +12 -16
- package/dist/session/utils/helpers.d.ts +2 -2
- package/dist/session/utils/types.d.ts +2 -1
- package/dist/telemetry/core-events.d.ts +122 -0
- package/dist/tools/definitions.d.ts +1 -1
- package/dist/tools/executors/file-read.d.ts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/presets.d.ts +1 -1
- package/dist/tools/schemas.d.ts +46 -3
- package/dist/tools/types.d.ts +3 -3
- package/dist/types/config.d.ts +1 -1
- package/dist/types/provider-settings.d.ts +4 -4
- package/dist/types.d.ts +1 -1
- package/package.json +4 -3
- package/src/auth/cline.ts +35 -1
- package/src/auth/codex.ts +27 -2
- package/src/auth/oca.ts +31 -4
- package/src/auth/types.ts +3 -0
- package/src/index.ts +27 -0
- package/src/input/mention-enricher.test.ts +3 -0
- package/src/input/mention-enricher.ts +3 -0
- package/src/providers/local-provider-service.ts +6 -7
- package/src/runtime/hook-file-hooks.ts +11 -10
- package/src/runtime/session-runtime.ts +1 -1
- package/src/session/default-session-manager.e2e.test.ts +2 -1
- package/src/session/default-session-manager.test.ts +131 -0
- package/src/session/default-session-manager.ts +372 -602
- package/src/session/runtime-oauth-token-manager.ts +21 -14
- package/src/session/session-agent-events.ts +159 -0
- package/src/session/session-config-builder.ts +111 -0
- package/src/session/session-host.ts +13 -0
- package/src/session/session-manager.ts +2 -2
- package/src/session/session-team-coordination.ts +198 -0
- package/src/session/session-telemetry.ts +95 -0
- package/src/session/unified-session-persistence-service.test.ts +81 -0
- package/src/session/unified-session-persistence-service.ts +470 -469
- package/src/session/utils/helpers.ts +14 -4
- package/src/session/utils/types.ts +2 -1
- package/src/storage/provider-settings-legacy-migration.ts +3 -3
- package/src/telemetry/core-events.ts +344 -0
- package/src/tools/definitions.test.ts +121 -7
- package/src/tools/definitions.ts +60 -24
- package/src/tools/executors/file-read.test.ts +29 -5
- package/src/tools/executors/file-read.ts +17 -6
- package/src/tools/index.ts +2 -0
- package/src/tools/presets.ts +1 -1
- package/src/tools/schemas.ts +65 -5
- package/src/tools/types.ts +7 -3
- package/src/types/config.ts +1 -1
- package/src/types/provider-settings.ts +6 -6
- 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(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 (
|
|
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
|
|
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
|
|
108
|
+
return lines.join("\n");
|
|
98
109
|
};
|
|
99
110
|
}
|
package/src/tools/index.ts
CHANGED
package/src/tools/presets.ts
CHANGED
|
@@ -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
|
* },
|
package/src/tools/schemas.ts
CHANGED
|
@@ -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
|
-
|
|
22
|
-
.array(
|
|
64
|
+
files: z
|
|
65
|
+
.array(ReadFileRequestSchema)
|
|
23
66
|
.describe(
|
|
24
|
-
"Array of
|
|
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
|
-
.
|
|
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
|
*/
|
package/src/tools/types.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ToolContext } from "@clinebot/agents";
|
|
8
|
-
import type {
|
|
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
|
|
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
|
-
|
|
46
|
+
request: ReadFileRequest,
|
|
43
47
|
context: ToolContext,
|
|
44
48
|
) => Promise<string>;
|
|
45
49
|
|
package/src/types/config.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LlmsProviders } from "@clinebot/llms";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
export type ProviderConfig =
|
|
5
|
-
export type ProviderSettings =
|
|
4
|
+
export type ProviderConfig = LlmsProviders.ProviderConfig;
|
|
5
|
+
export type ProviderSettings = LlmsProviders.ProviderSettings;
|
|
6
6
|
export const ProviderSettingsSchema: z.ZodType<ProviderSettings> =
|
|
7
|
-
|
|
8
|
-
export const 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:
|
|
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