@askalf/dario 3.0.3 → 3.1.0
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/cc-template-data.json +889 -0
- package/dist/cc-template.d.ts +13 -402
- package/dist/cc-template.js +27 -148
- package/dist/oauth.js +20 -3
- package/dist/proxy.js +3 -4
- package/package.json +2 -2
package/dist/cc-template.d.ts
CHANGED
|
@@ -1,409 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code request template —
|
|
3
|
-
* and request shape that real Claude Code sends.
|
|
2
|
+
* Claude Code request template — auto-extracted from CC v2.1.104 MITM capture.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* flagging their own binary.
|
|
9
|
-
*
|
|
10
|
-
* Source: MITM capture + binary RE of Claude Code v2.1.100
|
|
4
|
+
* Tool definitions, system prompt, and request structure are loaded from
|
|
5
|
+
* cc-template-data.json (extracted via MITM proxy from real CC session).
|
|
6
|
+
* This ensures byte-level fidelity with real CC requests.
|
|
11
7
|
*/
|
|
12
|
-
/**
|
|
13
|
-
export declare const CC_TOOL_DEFINITIONS:
|
|
14
|
-
name: string;
|
|
15
|
-
description: string;
|
|
16
|
-
input_schema: {
|
|
17
|
-
type: "object";
|
|
18
|
-
properties: {
|
|
19
|
-
command: {
|
|
20
|
-
type: "string";
|
|
21
|
-
description: string;
|
|
22
|
-
};
|
|
23
|
-
timeout: {
|
|
24
|
-
type: "number";
|
|
25
|
-
description: string;
|
|
26
|
-
};
|
|
27
|
-
file_path?: undefined;
|
|
28
|
-
offset?: undefined;
|
|
29
|
-
limit?: undefined;
|
|
30
|
-
content?: undefined;
|
|
31
|
-
old_string?: undefined;
|
|
32
|
-
new_string?: undefined;
|
|
33
|
-
replace_all?: undefined;
|
|
34
|
-
pattern?: undefined;
|
|
35
|
-
path?: undefined;
|
|
36
|
-
output_mode?: undefined;
|
|
37
|
-
url?: undefined;
|
|
38
|
-
query?: undefined;
|
|
39
|
-
notebook_path?: undefined;
|
|
40
|
-
cell_number?: undefined;
|
|
41
|
-
new_source?: undefined;
|
|
42
|
-
prompt?: undefined;
|
|
43
|
-
description?: undefined;
|
|
44
|
-
question?: undefined;
|
|
45
|
-
};
|
|
46
|
-
required: string[];
|
|
47
|
-
};
|
|
48
|
-
} | {
|
|
49
|
-
name: string;
|
|
50
|
-
description: string;
|
|
51
|
-
input_schema: {
|
|
52
|
-
type: "object";
|
|
53
|
-
properties: {
|
|
54
|
-
file_path: {
|
|
55
|
-
type: "string";
|
|
56
|
-
description: string;
|
|
57
|
-
};
|
|
58
|
-
offset: {
|
|
59
|
-
type: "integer";
|
|
60
|
-
description: string;
|
|
61
|
-
};
|
|
62
|
-
limit: {
|
|
63
|
-
type: "integer";
|
|
64
|
-
description: string;
|
|
65
|
-
};
|
|
66
|
-
command?: undefined;
|
|
67
|
-
timeout?: undefined;
|
|
68
|
-
content?: undefined;
|
|
69
|
-
old_string?: undefined;
|
|
70
|
-
new_string?: undefined;
|
|
71
|
-
replace_all?: undefined;
|
|
72
|
-
pattern?: undefined;
|
|
73
|
-
path?: undefined;
|
|
74
|
-
output_mode?: undefined;
|
|
75
|
-
url?: undefined;
|
|
76
|
-
query?: undefined;
|
|
77
|
-
notebook_path?: undefined;
|
|
78
|
-
cell_number?: undefined;
|
|
79
|
-
new_source?: undefined;
|
|
80
|
-
prompt?: undefined;
|
|
81
|
-
description?: undefined;
|
|
82
|
-
question?: undefined;
|
|
83
|
-
};
|
|
84
|
-
required: string[];
|
|
85
|
-
};
|
|
86
|
-
} | {
|
|
87
|
-
name: string;
|
|
88
|
-
description: string;
|
|
89
|
-
input_schema: {
|
|
90
|
-
type: "object";
|
|
91
|
-
properties: {
|
|
92
|
-
file_path: {
|
|
93
|
-
type: "string";
|
|
94
|
-
description: string;
|
|
95
|
-
};
|
|
96
|
-
content: {
|
|
97
|
-
type: "string";
|
|
98
|
-
description: string;
|
|
99
|
-
};
|
|
100
|
-
command?: undefined;
|
|
101
|
-
timeout?: undefined;
|
|
102
|
-
offset?: undefined;
|
|
103
|
-
limit?: undefined;
|
|
104
|
-
old_string?: undefined;
|
|
105
|
-
new_string?: undefined;
|
|
106
|
-
replace_all?: undefined;
|
|
107
|
-
pattern?: undefined;
|
|
108
|
-
path?: undefined;
|
|
109
|
-
output_mode?: undefined;
|
|
110
|
-
url?: undefined;
|
|
111
|
-
query?: undefined;
|
|
112
|
-
notebook_path?: undefined;
|
|
113
|
-
cell_number?: undefined;
|
|
114
|
-
new_source?: undefined;
|
|
115
|
-
prompt?: undefined;
|
|
116
|
-
description?: undefined;
|
|
117
|
-
question?: undefined;
|
|
118
|
-
};
|
|
119
|
-
required: string[];
|
|
120
|
-
};
|
|
121
|
-
} | {
|
|
122
|
-
name: string;
|
|
123
|
-
description: string;
|
|
124
|
-
input_schema: {
|
|
125
|
-
type: "object";
|
|
126
|
-
properties: {
|
|
127
|
-
file_path: {
|
|
128
|
-
type: "string";
|
|
129
|
-
description: string;
|
|
130
|
-
};
|
|
131
|
-
old_string: {
|
|
132
|
-
type: "string";
|
|
133
|
-
description: string;
|
|
134
|
-
};
|
|
135
|
-
new_string: {
|
|
136
|
-
type: "string";
|
|
137
|
-
description: string;
|
|
138
|
-
};
|
|
139
|
-
replace_all: {
|
|
140
|
-
type: "boolean";
|
|
141
|
-
description: string;
|
|
142
|
-
default: boolean;
|
|
143
|
-
};
|
|
144
|
-
command?: undefined;
|
|
145
|
-
timeout?: undefined;
|
|
146
|
-
offset?: undefined;
|
|
147
|
-
limit?: undefined;
|
|
148
|
-
content?: undefined;
|
|
149
|
-
pattern?: undefined;
|
|
150
|
-
path?: undefined;
|
|
151
|
-
output_mode?: undefined;
|
|
152
|
-
url?: undefined;
|
|
153
|
-
query?: undefined;
|
|
154
|
-
notebook_path?: undefined;
|
|
155
|
-
cell_number?: undefined;
|
|
156
|
-
new_source?: undefined;
|
|
157
|
-
prompt?: undefined;
|
|
158
|
-
description?: undefined;
|
|
159
|
-
question?: undefined;
|
|
160
|
-
};
|
|
161
|
-
required: string[];
|
|
162
|
-
};
|
|
163
|
-
} | {
|
|
164
|
-
name: string;
|
|
165
|
-
description: string;
|
|
166
|
-
input_schema: {
|
|
167
|
-
type: "object";
|
|
168
|
-
properties: {
|
|
169
|
-
pattern: {
|
|
170
|
-
type: "string";
|
|
171
|
-
description: string;
|
|
172
|
-
};
|
|
173
|
-
path: {
|
|
174
|
-
type: "string";
|
|
175
|
-
description: string;
|
|
176
|
-
};
|
|
177
|
-
command?: undefined;
|
|
178
|
-
timeout?: undefined;
|
|
179
|
-
file_path?: undefined;
|
|
180
|
-
offset?: undefined;
|
|
181
|
-
limit?: undefined;
|
|
182
|
-
content?: undefined;
|
|
183
|
-
old_string?: undefined;
|
|
184
|
-
new_string?: undefined;
|
|
185
|
-
replace_all?: undefined;
|
|
186
|
-
output_mode?: undefined;
|
|
187
|
-
url?: undefined;
|
|
188
|
-
query?: undefined;
|
|
189
|
-
notebook_path?: undefined;
|
|
190
|
-
cell_number?: undefined;
|
|
191
|
-
new_source?: undefined;
|
|
192
|
-
prompt?: undefined;
|
|
193
|
-
description?: undefined;
|
|
194
|
-
question?: undefined;
|
|
195
|
-
};
|
|
196
|
-
required: string[];
|
|
197
|
-
};
|
|
198
|
-
} | {
|
|
199
|
-
name: string;
|
|
200
|
-
description: string;
|
|
201
|
-
input_schema: {
|
|
202
|
-
type: "object";
|
|
203
|
-
properties: {
|
|
204
|
-
pattern: {
|
|
205
|
-
type: "string";
|
|
206
|
-
description: string;
|
|
207
|
-
};
|
|
208
|
-
path: {
|
|
209
|
-
type: "string";
|
|
210
|
-
description: string;
|
|
211
|
-
};
|
|
212
|
-
output_mode: {
|
|
213
|
-
type: "string";
|
|
214
|
-
enum: string[];
|
|
215
|
-
description: string;
|
|
216
|
-
};
|
|
217
|
-
command?: undefined;
|
|
218
|
-
timeout?: undefined;
|
|
219
|
-
file_path?: undefined;
|
|
220
|
-
offset?: undefined;
|
|
221
|
-
limit?: undefined;
|
|
222
|
-
content?: undefined;
|
|
223
|
-
old_string?: undefined;
|
|
224
|
-
new_string?: undefined;
|
|
225
|
-
replace_all?: undefined;
|
|
226
|
-
url?: undefined;
|
|
227
|
-
query?: undefined;
|
|
228
|
-
notebook_path?: undefined;
|
|
229
|
-
cell_number?: undefined;
|
|
230
|
-
new_source?: undefined;
|
|
231
|
-
prompt?: undefined;
|
|
232
|
-
description?: undefined;
|
|
233
|
-
question?: undefined;
|
|
234
|
-
};
|
|
235
|
-
required: string[];
|
|
236
|
-
};
|
|
237
|
-
} | {
|
|
238
|
-
name: string;
|
|
239
|
-
description: string;
|
|
240
|
-
input_schema: {
|
|
241
|
-
type: "object";
|
|
242
|
-
properties: {
|
|
243
|
-
url: {
|
|
244
|
-
type: "string";
|
|
245
|
-
description: string;
|
|
246
|
-
};
|
|
247
|
-
command?: undefined;
|
|
248
|
-
timeout?: undefined;
|
|
249
|
-
file_path?: undefined;
|
|
250
|
-
offset?: undefined;
|
|
251
|
-
limit?: undefined;
|
|
252
|
-
content?: undefined;
|
|
253
|
-
old_string?: undefined;
|
|
254
|
-
new_string?: undefined;
|
|
255
|
-
replace_all?: undefined;
|
|
256
|
-
pattern?: undefined;
|
|
257
|
-
path?: undefined;
|
|
258
|
-
output_mode?: undefined;
|
|
259
|
-
query?: undefined;
|
|
260
|
-
notebook_path?: undefined;
|
|
261
|
-
cell_number?: undefined;
|
|
262
|
-
new_source?: undefined;
|
|
263
|
-
prompt?: undefined;
|
|
264
|
-
description?: undefined;
|
|
265
|
-
question?: undefined;
|
|
266
|
-
};
|
|
267
|
-
required: string[];
|
|
268
|
-
};
|
|
269
|
-
} | {
|
|
270
|
-
name: string;
|
|
271
|
-
description: string;
|
|
272
|
-
input_schema: {
|
|
273
|
-
type: "object";
|
|
274
|
-
properties: {
|
|
275
|
-
query: {
|
|
276
|
-
type: "string";
|
|
277
|
-
description: string;
|
|
278
|
-
};
|
|
279
|
-
command?: undefined;
|
|
280
|
-
timeout?: undefined;
|
|
281
|
-
file_path?: undefined;
|
|
282
|
-
offset?: undefined;
|
|
283
|
-
limit?: undefined;
|
|
284
|
-
content?: undefined;
|
|
285
|
-
old_string?: undefined;
|
|
286
|
-
new_string?: undefined;
|
|
287
|
-
replace_all?: undefined;
|
|
288
|
-
pattern?: undefined;
|
|
289
|
-
path?: undefined;
|
|
290
|
-
output_mode?: undefined;
|
|
291
|
-
url?: undefined;
|
|
292
|
-
notebook_path?: undefined;
|
|
293
|
-
cell_number?: undefined;
|
|
294
|
-
new_source?: undefined;
|
|
295
|
-
prompt?: undefined;
|
|
296
|
-
description?: undefined;
|
|
297
|
-
question?: undefined;
|
|
298
|
-
};
|
|
299
|
-
required: string[];
|
|
300
|
-
};
|
|
301
|
-
} | {
|
|
302
|
-
name: string;
|
|
303
|
-
description: string;
|
|
304
|
-
input_schema: {
|
|
305
|
-
type: "object";
|
|
306
|
-
properties: {
|
|
307
|
-
notebook_path: {
|
|
308
|
-
type: "string";
|
|
309
|
-
description: string;
|
|
310
|
-
};
|
|
311
|
-
cell_number: {
|
|
312
|
-
type: "integer";
|
|
313
|
-
description: string;
|
|
314
|
-
};
|
|
315
|
-
new_source: {
|
|
316
|
-
type: "string";
|
|
317
|
-
description: string;
|
|
318
|
-
};
|
|
319
|
-
command?: undefined;
|
|
320
|
-
timeout?: undefined;
|
|
321
|
-
file_path?: undefined;
|
|
322
|
-
offset?: undefined;
|
|
323
|
-
limit?: undefined;
|
|
324
|
-
content?: undefined;
|
|
325
|
-
old_string?: undefined;
|
|
326
|
-
new_string?: undefined;
|
|
327
|
-
replace_all?: undefined;
|
|
328
|
-
pattern?: undefined;
|
|
329
|
-
path?: undefined;
|
|
330
|
-
output_mode?: undefined;
|
|
331
|
-
url?: undefined;
|
|
332
|
-
query?: undefined;
|
|
333
|
-
prompt?: undefined;
|
|
334
|
-
description?: undefined;
|
|
335
|
-
question?: undefined;
|
|
336
|
-
};
|
|
337
|
-
required: string[];
|
|
338
|
-
};
|
|
339
|
-
} | {
|
|
340
|
-
name: string;
|
|
341
|
-
description: string;
|
|
342
|
-
input_schema: {
|
|
343
|
-
type: "object";
|
|
344
|
-
properties: {
|
|
345
|
-
prompt: {
|
|
346
|
-
type: "string";
|
|
347
|
-
description: string;
|
|
348
|
-
};
|
|
349
|
-
description: {
|
|
350
|
-
type: "string";
|
|
351
|
-
description: string;
|
|
352
|
-
};
|
|
353
|
-
command?: undefined;
|
|
354
|
-
timeout?: undefined;
|
|
355
|
-
file_path?: undefined;
|
|
356
|
-
offset?: undefined;
|
|
357
|
-
limit?: undefined;
|
|
358
|
-
content?: undefined;
|
|
359
|
-
old_string?: undefined;
|
|
360
|
-
new_string?: undefined;
|
|
361
|
-
replace_all?: undefined;
|
|
362
|
-
pattern?: undefined;
|
|
363
|
-
path?: undefined;
|
|
364
|
-
output_mode?: undefined;
|
|
365
|
-
url?: undefined;
|
|
366
|
-
query?: undefined;
|
|
367
|
-
notebook_path?: undefined;
|
|
368
|
-
cell_number?: undefined;
|
|
369
|
-
new_source?: undefined;
|
|
370
|
-
question?: undefined;
|
|
371
|
-
};
|
|
372
|
-
required: string[];
|
|
373
|
-
};
|
|
374
|
-
} | {
|
|
8
|
+
/** CC's exact tool definitions — loaded from MITM capture. */
|
|
9
|
+
export declare const CC_TOOL_DEFINITIONS: {
|
|
375
10
|
name: string;
|
|
376
11
|
description: string;
|
|
377
|
-
input_schema:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
};
|
|
384
|
-
command?: undefined;
|
|
385
|
-
timeout?: undefined;
|
|
386
|
-
file_path?: undefined;
|
|
387
|
-
offset?: undefined;
|
|
388
|
-
limit?: undefined;
|
|
389
|
-
content?: undefined;
|
|
390
|
-
old_string?: undefined;
|
|
391
|
-
new_string?: undefined;
|
|
392
|
-
replace_all?: undefined;
|
|
393
|
-
pattern?: undefined;
|
|
394
|
-
path?: undefined;
|
|
395
|
-
output_mode?: undefined;
|
|
396
|
-
url?: undefined;
|
|
397
|
-
query?: undefined;
|
|
398
|
-
notebook_path?: undefined;
|
|
399
|
-
cell_number?: undefined;
|
|
400
|
-
new_source?: undefined;
|
|
401
|
-
prompt?: undefined;
|
|
402
|
-
description?: undefined;
|
|
403
|
-
};
|
|
404
|
-
required: string[];
|
|
405
|
-
};
|
|
406
|
-
})[];
|
|
12
|
+
input_schema: Record<string, unknown>;
|
|
13
|
+
}[];
|
|
14
|
+
/** CC's static system prompt (~25KB). */
|
|
15
|
+
export declare const CC_SYSTEM_PROMPT: string;
|
|
16
|
+
/** CC's agent identity string. */
|
|
17
|
+
export declare const CC_AGENT_IDENTITY: string;
|
|
407
18
|
/** Client tool name → CC tool mapping with parameter translation. */
|
|
408
19
|
interface ToolMapping {
|
|
409
20
|
ccTool: string;
|
|
@@ -415,7 +26,7 @@ interface ToolMapping {
|
|
|
415
26
|
* Replaces the entire request structure — tools, fields, ordering — with
|
|
416
27
|
* what real CC sends. Only the conversation content is preserved.
|
|
417
28
|
*/
|
|
418
|
-
export declare function buildCCRequest(clientBody: Record<string, unknown>, billingTag: string,
|
|
29
|
+
export declare function buildCCRequest(clientBody: Record<string, unknown>, billingTag: string, cache1h: {
|
|
419
30
|
type: 'ephemeral';
|
|
420
31
|
ttl: '1h';
|
|
421
32
|
}, identity: {
|
package/dist/cc-template.js
CHANGED
|
@@ -1,151 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code request template —
|
|
3
|
-
* and request shape that real Claude Code sends.
|
|
2
|
+
* Claude Code request template — auto-extracted from CC v2.1.104 MITM capture.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* flagging their own binary.
|
|
9
|
-
*
|
|
10
|
-
* Source: MITM capture + binary RE of Claude Code v2.1.100
|
|
4
|
+
* Tool definitions, system prompt, and request structure are loaded from
|
|
5
|
+
* cc-template-data.json (extracted via MITM proxy from real CC session).
|
|
6
|
+
* This ensures byte-level fidelity with real CC requests.
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'Read',
|
|
28
|
-
description: 'Reads a file from the local filesystem. The file_path parameter must be an absolute path.',
|
|
29
|
-
input_schema: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
file_path: { type: 'string', description: 'The absolute path to the file to read' },
|
|
33
|
-
offset: { type: 'integer', description: 'The line number to start reading from' },
|
|
34
|
-
limit: { type: 'integer', description: 'The number of lines to read' },
|
|
35
|
-
},
|
|
36
|
-
required: ['file_path'],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'Write',
|
|
41
|
-
description: 'Writes a file to the local filesystem. This tool will overwrite the existing file if there is one.',
|
|
42
|
-
input_schema: {
|
|
43
|
-
type: 'object',
|
|
44
|
-
properties: {
|
|
45
|
-
file_path: { type: 'string', description: 'The absolute path to the file to write' },
|
|
46
|
-
content: { type: 'string', description: 'The content to write to the file' },
|
|
47
|
-
},
|
|
48
|
-
required: ['file_path', 'content'],
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: 'Edit',
|
|
53
|
-
description: 'Performs exact string replacements in files. The edit will FAIL if old_string is not unique in the file.',
|
|
54
|
-
input_schema: {
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
file_path: { type: 'string', description: 'The absolute path to the file to modify' },
|
|
58
|
-
old_string: { type: 'string', description: 'The text to replace' },
|
|
59
|
-
new_string: { type: 'string', description: 'The text to replace it with' },
|
|
60
|
-
replace_all: { type: 'boolean', description: 'Replace all occurrences', default: false },
|
|
61
|
-
},
|
|
62
|
-
required: ['file_path', 'old_string', 'new_string'],
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'Glob',
|
|
67
|
-
description: 'Fast file pattern matching tool that works with any codebase size. Returns matching file paths.',
|
|
68
|
-
input_schema: {
|
|
69
|
-
type: 'object',
|
|
70
|
-
properties: {
|
|
71
|
-
pattern: { type: 'string', description: 'The glob pattern to match files against' },
|
|
72
|
-
path: { type: 'string', description: 'The directory to search in' },
|
|
73
|
-
},
|
|
74
|
-
required: ['pattern'],
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'Grep',
|
|
79
|
-
description: 'A powerful search tool built on ripgrep. Supports full regex syntax.',
|
|
80
|
-
input_schema: {
|
|
81
|
-
type: 'object',
|
|
82
|
-
properties: {
|
|
83
|
-
pattern: { type: 'string', description: 'The regular expression pattern to search for' },
|
|
84
|
-
path: { type: 'string', description: 'File or directory to search in' },
|
|
85
|
-
output_mode: { type: 'string', enum: ['content', 'files_with_matches', 'count'], description: 'Output mode' },
|
|
86
|
-
},
|
|
87
|
-
required: ['pattern'],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: 'WebFetch',
|
|
92
|
-
description: 'Fetches a URL from the internet and returns the content.',
|
|
93
|
-
input_schema: {
|
|
94
|
-
type: 'object',
|
|
95
|
-
properties: {
|
|
96
|
-
url: { type: 'string', description: 'The URL to fetch' },
|
|
97
|
-
},
|
|
98
|
-
required: ['url'],
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'WebSearch',
|
|
103
|
-
description: 'Searches the web using a search engine and returns results.',
|
|
104
|
-
input_schema: {
|
|
105
|
-
type: 'object',
|
|
106
|
-
properties: {
|
|
107
|
-
query: { type: 'string', description: 'The search query' },
|
|
108
|
-
},
|
|
109
|
-
required: ['query'],
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'NotebookEdit',
|
|
114
|
-
description: 'Edits a Jupyter notebook cell.',
|
|
115
|
-
input_schema: {
|
|
116
|
-
type: 'object',
|
|
117
|
-
properties: {
|
|
118
|
-
notebook_path: { type: 'string', description: 'Path to the notebook file' },
|
|
119
|
-
cell_number: { type: 'integer', description: 'Cell number to edit' },
|
|
120
|
-
new_source: { type: 'string', description: 'New cell source code' },
|
|
121
|
-
},
|
|
122
|
-
required: ['notebook_path', 'cell_number', 'new_source'],
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: 'Agent',
|
|
127
|
-
description: 'Launch a new agent to handle complex tasks. The agent runs in an isolated context.',
|
|
128
|
-
input_schema: {
|
|
129
|
-
type: 'object',
|
|
130
|
-
properties: {
|
|
131
|
-
prompt: { type: 'string', description: 'The task for the agent to perform' },
|
|
132
|
-
description: { type: 'string', description: 'A short description of the task' },
|
|
133
|
-
},
|
|
134
|
-
required: ['description', 'prompt'],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: 'AskUserQuestion',
|
|
139
|
-
description: 'Ask the user a question and wait for their response.',
|
|
140
|
-
input_schema: {
|
|
141
|
-
type: 'object',
|
|
142
|
-
properties: {
|
|
143
|
-
question: { type: 'string', description: 'The question to ask' },
|
|
144
|
-
},
|
|
145
|
-
required: ['question'],
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
];
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { join, dirname } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
// Load template data at module init — fail fast if missing
|
|
13
|
+
const TEMPLATE = JSON.parse(readFileSync(join(__dirname, 'cc-template-data.json'), 'utf-8'));
|
|
14
|
+
/** CC's exact tool definitions — loaded from MITM capture. */
|
|
15
|
+
export const CC_TOOL_DEFINITIONS = TEMPLATE.tools;
|
|
16
|
+
/** CC's static system prompt (~25KB). */
|
|
17
|
+
export const CC_SYSTEM_PROMPT = TEMPLATE.system_prompt;
|
|
18
|
+
/** CC's agent identity string. */
|
|
19
|
+
export const CC_AGENT_IDENTITY = TEMPLATE.agent_identity;
|
|
149
20
|
const TOOL_MAP = {
|
|
150
21
|
// Direct maps
|
|
151
22
|
bash: { ccTool: 'Bash', translateArgs: (a) => ({ command: a.cmd || a.command || a.c || '' }) },
|
|
@@ -181,7 +52,7 @@ const TOOL_MAP = {
|
|
|
181
52
|
* Replaces the entire request structure — tools, fields, ordering — with
|
|
182
53
|
* what real CC sends. Only the conversation content is preserved.
|
|
183
54
|
*/
|
|
184
|
-
export function buildCCRequest(clientBody, billingTag,
|
|
55
|
+
export function buildCCRequest(clientBody, billingTag, cache1h, identity) {
|
|
185
56
|
const model = clientBody.model || 'claude-sonnet-4-6';
|
|
186
57
|
const isHaiku = model.toLowerCase().includes('haiku');
|
|
187
58
|
const messages = clientBody.messages || [];
|
|
@@ -311,13 +182,21 @@ export function buildCCRequest(clientBody, billingTag, agentIdentity, cache1h, i
|
|
|
311
182
|
// ── Build the CC request from template ──
|
|
312
183
|
// Key order matches CC v2.1.104 MITM capture exactly:
|
|
313
184
|
// model, messages, system, tools, metadata, max_tokens, thinking, context_management, output_config, stream
|
|
185
|
+
//
|
|
186
|
+
// System prompt structure (3 blocks, matching real CC):
|
|
187
|
+
// [0] billing tag (no cache)
|
|
188
|
+
// [1] agent identity (1h cache)
|
|
189
|
+
// [2] CC's full 25KB system prompt + client's custom prompt appended (1h cache)
|
|
190
|
+
const fullSystemPrompt = systemText
|
|
191
|
+
? `${CC_SYSTEM_PROMPT}\n\n${systemText}`
|
|
192
|
+
: CC_SYSTEM_PROMPT;
|
|
314
193
|
const ccRequest = {
|
|
315
194
|
model,
|
|
316
195
|
messages,
|
|
317
196
|
system: [
|
|
318
197
|
{ type: 'text', text: billingTag },
|
|
319
|
-
{ type: 'text', text:
|
|
320
|
-
{ type: 'text', text:
|
|
198
|
+
{ type: 'text', text: CC_AGENT_IDENTITY, cache_control: cache1h },
|
|
199
|
+
{ type: 'text', text: fullSystemPrompt, cache_control: cache1h },
|
|
321
200
|
],
|
|
322
201
|
};
|
|
323
202
|
// Tools come before metadata in CC's key order
|
package/dist/oauth.js
CHANGED
|
@@ -15,6 +15,9 @@ const OAUTH_TOKEN_URL = 'https://platform.claude.com/v1/oauth/token';
|
|
|
15
15
|
const OAUTH_SCOPES = 'org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload';
|
|
16
16
|
// Refresh 30 min before expiry
|
|
17
17
|
const REFRESH_BUFFER_MS = 30 * 60 * 1000;
|
|
18
|
+
// After a failed refresh, don't retry for 60s to avoid spam
|
|
19
|
+
let lastRefreshFailure = 0;
|
|
20
|
+
const REFRESH_COOLDOWN_MS = 60 * 1000;
|
|
18
21
|
// In-memory credential cache — avoids disk reads on every request
|
|
19
22
|
let credentialsCache = null;
|
|
20
23
|
let credentialsCacheTime = 0;
|
|
@@ -210,6 +213,8 @@ async function doRefreshTokens() {
|
|
|
210
213
|
signal: AbortSignal.timeout(15000),
|
|
211
214
|
});
|
|
212
215
|
if (!res.ok) {
|
|
216
|
+
const errBody = await res.text().catch(() => '');
|
|
217
|
+
console.error(`[dario] Refresh attempt ${attempt + 1}/3 failed: HTTP ${res.status} — ${errBody.slice(0, 200)}`);
|
|
213
218
|
if (res.status === 401 || res.status === 403) {
|
|
214
219
|
throw new Error(`Refresh token rejected (${res.status}). Run \`dario login\` to re-authenticate.`);
|
|
215
220
|
}
|
|
@@ -240,10 +245,22 @@ export async function getAccessToken() {
|
|
|
240
245
|
if (oauth.expiresAt > Date.now() + REFRESH_BUFFER_MS) {
|
|
241
246
|
return oauth.accessToken;
|
|
242
247
|
}
|
|
243
|
-
// Need refresh
|
|
248
|
+
// Need refresh — but don't spam if we just failed
|
|
249
|
+
if (Date.now() - lastRefreshFailure < REFRESH_COOLDOWN_MS) {
|
|
250
|
+
// Still in cooldown from a recent failure, use current token even if expiring
|
|
251
|
+
return oauth.accessToken;
|
|
252
|
+
}
|
|
244
253
|
console.log('[dario] Token expiring soon, refreshing...');
|
|
245
|
-
|
|
246
|
-
|
|
254
|
+
try {
|
|
255
|
+
const refreshed = await refreshTokens();
|
|
256
|
+
return refreshed.accessToken;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
lastRefreshFailure = Date.now();
|
|
260
|
+
console.error(`[dario] Refresh failed: ${err instanceof Error ? err.message : err}. Will retry in 60s. Run \`dario login\` if this persists.`);
|
|
261
|
+
// Return current token — it might still work for a few more minutes
|
|
262
|
+
return oauth.accessToken;
|
|
263
|
+
}
|
|
247
264
|
}
|
|
248
265
|
/**
|
|
249
266
|
* Get token status info.
|