zen-code 4.6.1 → 4.6.2

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.
@@ -1,4 +1,4 @@
1
- import { A as s, C as m, F as o, e as c, S as i, a as p, d as h, b as k, h as n, f as g, g as T, T as f, c as l } from "./graphBuilder-B3IJ7dB2.mjs";
1
+ import { A as s, C as m, F as o, e as c, S as i, a as p, d as h, b as k, h as n, f as g, g as T, T as f, c as l } from "./graphBuilder-mpLrx9tk.mjs";
2
2
  import { FileSystemSkillStore as y } from "./FileSystemSkillStore-yvEvcRxB.mjs";
3
3
  import { FileSystemPluginStore as F } from "./FileSystemPluginStore-ChortK7z.mjs";
4
4
  import "lowdb";
@@ -0,0 +1,463 @@
1
+ import { B as C, u as v, c as x, T as $, m as I } from "./app-Cynj004J.mjs";
2
+ import "./graphBuilder-mpLrx9tk.mjs";
3
+ import { createClient as O, createCluster as N } from "redis";
4
+ const W = [
5
+ {
6
+ index: "checkpoints",
7
+ prefix: "checkpoint:",
8
+ schema: {
9
+ "$.thread_id": {
10
+ type: "TAG",
11
+ AS: "thread_id"
12
+ },
13
+ "$.checkpoint_ns": {
14
+ type: "TAG",
15
+ AS: "checkpoint_ns"
16
+ },
17
+ "$.checkpoint_id": {
18
+ type: "TAG",
19
+ AS: "checkpoint_id"
20
+ },
21
+ "$.parent_checkpoint_id": {
22
+ type: "TAG",
23
+ AS: "parent_checkpoint_id"
24
+ },
25
+ "$.checkpoint_ts": {
26
+ type: "NUMERIC",
27
+ AS: "checkpoint_ts"
28
+ },
29
+ "$.has_writes": {
30
+ type: "TAG",
31
+ AS: "has_writes"
32
+ },
33
+ "$.source": {
34
+ type: "TAG",
35
+ AS: "source"
36
+ },
37
+ "$.step": {
38
+ type: "NUMERIC",
39
+ AS: "step"
40
+ }
41
+ }
42
+ },
43
+ {
44
+ index: "checkpoint_blobs",
45
+ prefix: "checkpoint_blob:",
46
+ schema: {
47
+ "$.thread_id": {
48
+ type: "TAG",
49
+ AS: "thread_id"
50
+ },
51
+ "$.checkpoint_ns": {
52
+ type: "TAG",
53
+ AS: "checkpoint_ns"
54
+ },
55
+ "$.checkpoint_id": {
56
+ type: "TAG",
57
+ AS: "checkpoint_id"
58
+ },
59
+ "$.channel": {
60
+ type: "TAG",
61
+ AS: "channel"
62
+ },
63
+ "$.version": {
64
+ type: "TAG",
65
+ AS: "version"
66
+ },
67
+ "$.type": {
68
+ type: "TAG",
69
+ AS: "type"
70
+ }
71
+ }
72
+ },
73
+ {
74
+ index: "checkpoint_writes",
75
+ prefix: "checkpoint_write:",
76
+ schema: {
77
+ "$.thread_id": {
78
+ type: "TAG",
79
+ AS: "thread_id"
80
+ },
81
+ "$.checkpoint_ns": {
82
+ type: "TAG",
83
+ AS: "checkpoint_ns"
84
+ },
85
+ "$.checkpoint_id": {
86
+ type: "TAG",
87
+ AS: "checkpoint_id"
88
+ },
89
+ "$.task_id": {
90
+ type: "TAG",
91
+ AS: "task_id"
92
+ },
93
+ "$.idx": {
94
+ type: "NUMERIC",
95
+ AS: "idx"
96
+ },
97
+ "$.channel": {
98
+ type: "TAG",
99
+ AS: "channel"
100
+ },
101
+ "$.type": {
102
+ type: "TAG",
103
+ AS: "type"
104
+ }
105
+ }
106
+ }
107
+ ];
108
+ var E = class T extends C {
109
+ client;
110
+ ttlConfig;
111
+ constructor(e, t) {
112
+ super(), this.client = e, this.ttlConfig = t;
113
+ }
114
+ static async fromUrl(e, t) {
115
+ const s = O({ url: e });
116
+ await s.connect();
117
+ const i = new T(s, t);
118
+ return await i.ensureIndexes(), i;
119
+ }
120
+ static async fromCluster(e, t) {
121
+ const s = N({ rootNodes: e });
122
+ await s.connect();
123
+ const i = new T(s, t);
124
+ return await i.ensureIndexes(), i;
125
+ }
126
+ async get(e) {
127
+ return (await this.getTuple(e))?.checkpoint;
128
+ }
129
+ async getTuple(e) {
130
+ const t = e.configurable?.thread_id, s = e.configurable?.checkpoint_ns ?? "", i = e.configurable?.checkpoint_id;
131
+ if (!t) return;
132
+ let c, o;
133
+ if (i)
134
+ c = `checkpoint:${t}:${s}:${i}`, o = await this.client.json.get(c);
135
+ else {
136
+ const r = `checkpoint:${t}:${s}:*`, p = await this.client.keys(r);
137
+ if (p.length === 0) return;
138
+ p.sort(), c = p[p.length - 1], o = await this.client.json.get(c);
139
+ }
140
+ if (!o) return;
141
+ this.ttlConfig?.refreshOnRead && this.ttlConfig?.defaultTTL && await this.applyTTL(c);
142
+ const { checkpoint: f, pendingWrites: n } = await this.loadCheckpointWithWrites(o);
143
+ return await this.createCheckpointTuple(o, f, n);
144
+ }
145
+ async put(e, t, s, i) {
146
+ await this.ensureIndexes();
147
+ const c = e.configurable?.thread_id, o = e.configurable?.checkpoint_ns ?? "", f = e.configurable?.checkpoint_id;
148
+ if (!c) throw new Error("thread_id is required");
149
+ const n = t.id || v(0), r = `checkpoint:${c}:${o}:${n}`, p = x(t);
150
+ if (p.channel_values && i !== void 0) if (Object.keys(i).length === 0) p.channel_values = {};
151
+ else {
152
+ const u = {};
153
+ for (const a of Object.keys(i)) a in p.channel_values && (u[a] = p.channel_values[a]);
154
+ p.channel_values = u;
155
+ }
156
+ const l = {
157
+ thread_id: c,
158
+ checkpoint_ns: o === "" ? "__empty__" : o,
159
+ checkpoint_id: n,
160
+ parent_checkpoint_id: f || null,
161
+ checkpoint: p,
162
+ metadata: s,
163
+ checkpoint_ts: Date.now(),
164
+ has_writes: "false"
165
+ };
166
+ return this.addSearchableMetadataFields(l, s), await this.client.json.set(r, "$", l), this.ttlConfig?.defaultTTL && await this.applyTTL(r), { configurable: {
167
+ thread_id: c,
168
+ checkpoint_ns: o,
169
+ checkpoint_id: n
170
+ } };
171
+ }
172
+ async *list(e, t) {
173
+ if (await this.ensureIndexes(), t?.filter !== void 0) {
174
+ const i = Object.values(t.filter).some((n) => n === null), c = [];
175
+ if (e?.configurable?.thread_id) {
176
+ const n = e.configurable.thread_id.replace(/[-.@]/g, "\\$&");
177
+ c.push(`(@thread_id:{${n}})`);
178
+ }
179
+ if (e?.configurable?.checkpoint_ns !== void 0) {
180
+ const n = e.configurable.checkpoint_ns;
181
+ if (n === "") c.push("(@checkpoint_ns:{__empty__})");
182
+ else {
183
+ const r = n.replace(/[-.@]/g, "\\$&");
184
+ c.push(`(@checkpoint_ns:{${r}})`);
185
+ }
186
+ }
187
+ if (!t?.before && t?.filter)
188
+ for (const [n, r] of Object.entries(t.filter)) r === void 0 || r === null || (typeof r == "string" ? c.push(`(@${n}:{${r}})`) : typeof r == "number" ? c.push(`(@${n}:[${r} ${r}])`) : typeof r == "object" && Object.keys(r).length);
189
+ c.length === 0 && c.push("*");
190
+ const o = c.join(" "), f = t?.limit ?? 10;
191
+ try {
192
+ const n = t?.before && !e?.configurable?.thread_id ? 1e3 : t?.before ? f * 10 : f;
193
+ let p = (await this.client.ft.search("checkpoints", o, {
194
+ LIMIT: {
195
+ from: 0,
196
+ size: n
197
+ },
198
+ SORTBY: {
199
+ BY: "checkpoint_ts",
200
+ DIRECTION: "DESC"
201
+ }
202
+ })).documents, l = 0;
203
+ for (const u of p) {
204
+ if (l >= f) break;
205
+ if (t?.before?.configurable?.checkpoint_id) {
206
+ const k = u.value.checkpoint_id, d = t.before.configurable.checkpoint_id;
207
+ if (k >= d) continue;
208
+ }
209
+ const a = u.value;
210
+ let h = !0;
211
+ if ((i || t?.before) && t?.filter) {
212
+ for (const [k, d] of Object.entries(t.filter)) if (d === null) {
213
+ if (a.metadata?.[k] !== null) {
214
+ h = !1;
215
+ break;
216
+ }
217
+ } else if (d !== void 0) {
218
+ const b = a.metadata?.[k];
219
+ if (typeof d == "object" && d !== null) {
220
+ if (g(b) !== g(d)) {
221
+ h = !1;
222
+ break;
223
+ }
224
+ } else if (b !== d) {
225
+ h = !1;
226
+ break;
227
+ }
228
+ }
229
+ if (!h) continue;
230
+ }
231
+ const { checkpoint: y, pendingWrites: _ } = await this.loadCheckpointWithWrites(a);
232
+ yield await this.createCheckpointTuple(a, y, _), l++;
233
+ }
234
+ return;
235
+ } catch (n) {
236
+ if (!n.message?.includes("no such index")) throw n;
237
+ }
238
+ if (e?.configurable?.thread_id) {
239
+ const n = e.configurable.thread_id, r = e.configurable.checkpoint_ns ?? "", p = `checkpoint:${n}:${r}:*`, l = await this.client.keys(p);
240
+ l.sort().reverse();
241
+ let u = l;
242
+ if (t?.before?.configurable?.checkpoint_id) {
243
+ const y = t.before.configurable.thread_id || n, _ = t.before.configurable.checkpoint_ns ?? r, k = `checkpoint:${y}:${_}:${t.before.configurable.checkpoint_id}`, d = l.indexOf(k);
244
+ d > 0 ? u = l.slice(d + 1) : d === 0 && (u = []);
245
+ }
246
+ const a = t?.limit ?? 10, h = u.slice(0, a);
247
+ for (const y of h) {
248
+ const _ = await this.client.json.get(y);
249
+ if (_) {
250
+ let k = !0;
251
+ for (const [S, m] of Object.entries(t.filter)) {
252
+ const A = _.metadata?.[S];
253
+ if (m === null) {
254
+ if (A !== null) {
255
+ k = !1;
256
+ break;
257
+ }
258
+ } else if (A !== m) {
259
+ k = !1;
260
+ break;
261
+ }
262
+ }
263
+ if (!k) continue;
264
+ const { checkpoint: d, pendingWrites: b } = await this.loadCheckpointWithWrites(_);
265
+ yield await this.createCheckpointTuple(_, d, b);
266
+ }
267
+ }
268
+ } else {
269
+ const n = e?.configurable?.checkpoint_ns !== void 0 ? `checkpoint:*:${e.configurable.checkpoint_ns === "" ? "__empty__" : e.configurable.checkpoint_ns}:*` : "checkpoint:*", r = await this.client.keys(n), p = [];
270
+ for (const a of r) {
271
+ const h = await this.client.json.get(a);
272
+ h && p.push({
273
+ key: a,
274
+ doc: h
275
+ });
276
+ }
277
+ p.sort((a, h) => h.doc.checkpoint_ts - a.doc.checkpoint_ts);
278
+ let l = 0;
279
+ const u = t?.limit ?? 10;
280
+ for (const { doc: a } of p) {
281
+ if (l >= u) break;
282
+ if (t?.before?.configurable?.checkpoint_id) {
283
+ const k = a.checkpoint_id, d = t.before.configurable.checkpoint_id;
284
+ if (k >= d) continue;
285
+ }
286
+ let h = !0;
287
+ if (t?.filter) {
288
+ for (const [k, d] of Object.entries(t.filter)) if (d === null) {
289
+ if (a.metadata?.[k] !== null) {
290
+ h = !1;
291
+ break;
292
+ }
293
+ } else if (d !== void 0) {
294
+ const b = a.metadata?.[k];
295
+ if (typeof d == "object" && d !== null) {
296
+ if (g(b) !== g(d)) {
297
+ h = !1;
298
+ break;
299
+ }
300
+ } else if (b !== d) {
301
+ h = !1;
302
+ break;
303
+ }
304
+ }
305
+ if (!h) continue;
306
+ }
307
+ const { checkpoint: y, pendingWrites: _ } = await this.loadCheckpointWithWrites(a);
308
+ yield await this.createCheckpointTuple(a, y, _), l++;
309
+ }
310
+ }
311
+ return;
312
+ }
313
+ const s = {
314
+ ...t,
315
+ filter: {}
316
+ };
317
+ yield* this.list(e, s);
318
+ }
319
+ async putWrites(e, t, s) {
320
+ await this.ensureIndexes();
321
+ const i = e.configurable?.thread_id, c = e.configurable?.checkpoint_ns ?? "", o = e.configurable?.checkpoint_id;
322
+ if (!i || !o) throw new Error("thread_id and checkpoint_id are required");
323
+ const f = [], n = performance.now() * 1e3;
324
+ for (let l = 0; l < t.length; l++) {
325
+ const [u, a] = t[l], h = `checkpoint_write:${i}:${c}:${o}:${s}:${l}`;
326
+ f.push(h);
327
+ const y = {
328
+ thread_id: i,
329
+ checkpoint_ns: c,
330
+ checkpoint_id: o,
331
+ task_id: s,
332
+ idx: l,
333
+ channel: u,
334
+ type: typeof a == "object" ? "json" : "string",
335
+ value: a,
336
+ timestamp: n,
337
+ global_idx: n + l
338
+ };
339
+ await this.client.json.set(h, "$", y);
340
+ }
341
+ if (f.length > 0) {
342
+ const l = `write_keys_zset:${i}:${c}:${o}`, u = {};
343
+ f.forEach((a, h) => {
344
+ u[a] = n + h;
345
+ }), await this.client.zAdd(l, Object.entries(u).map(([a, h]) => ({
346
+ score: h,
347
+ value: a
348
+ }))), this.ttlConfig?.defaultTTL && await this.applyTTL(...f, l);
349
+ }
350
+ const r = `checkpoint:${i}:${c}:${o}`;
351
+ if (await this.client.exists(r)) {
352
+ const l = await this.client.json.get(r);
353
+ l && (l.has_writes = "true", await this.client.json.set(r, "$", l));
354
+ }
355
+ }
356
+ async deleteThread(e) {
357
+ const t = `checkpoint:${e}:*`, s = await this.client.keys(t);
358
+ s.length > 0 && await this.client.del(s);
359
+ const i = `writes:${e}:*`, c = await this.client.keys(i);
360
+ c.length > 0 && await this.client.del(c);
361
+ }
362
+ async end() {
363
+ await this.client.quit();
364
+ }
365
+ async loadPendingWrites(e, t, s) {
366
+ const i = `checkpoint_write:${e}:${t}:${s}:*`, c = await this.client.keys(i);
367
+ if (c.length === 0) return;
368
+ const o = [];
369
+ for (const n of c) {
370
+ const r = await this.client.json.get(n);
371
+ r && o.push(r);
372
+ }
373
+ o.sort((n, r) => (n.global_idx || 0) - (r.global_idx || 0));
374
+ const f = [];
375
+ for (const n of o) {
376
+ const r = await this.serde.loadsTyped("json", JSON.stringify(n.value));
377
+ f.push([
378
+ n.task_id,
379
+ n.channel,
380
+ r
381
+ ]);
382
+ }
383
+ return f;
384
+ }
385
+ async loadCheckpointWithWrites(e) {
386
+ const t = await this.serde.loadsTyped("json", JSON.stringify(e.checkpoint));
387
+ if (t.v < 4 && e.parent_checkpoint_id != null) {
388
+ const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns;
389
+ await this.migratePendingSends(t, e.thread_id, i, e.parent_checkpoint_id);
390
+ }
391
+ let s;
392
+ if (e.has_writes === "true") {
393
+ const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns;
394
+ s = await this.loadPendingWrites(e.thread_id, i, e.checkpoint_id);
395
+ }
396
+ return {
397
+ checkpoint: t,
398
+ pendingWrites: s
399
+ };
400
+ }
401
+ async migratePendingSends(e, t, s, i) {
402
+ const c = await this.loadPendingWrites(t, s, i);
403
+ if (!c || c.length === 0) return;
404
+ const o = c.filter(([, n]) => n === $);
405
+ if (o.length === 0) return;
406
+ const f = [];
407
+ for (const [, , n] of o) f.push(n);
408
+ e.channel_values ??= {}, e.channel_values[$] = f, e.channel_versions[$] = Object.keys(e.channel_versions).length > 0 ? I(...Object.values(e.channel_versions)) : 1;
409
+ }
410
+ async createCheckpointTuple(e, t, s) {
411
+ const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns, c = await this.serde.loadsTyped("json", JSON.stringify(e.metadata));
412
+ return {
413
+ config: { configurable: {
414
+ thread_id: e.thread_id,
415
+ checkpoint_ns: i,
416
+ checkpoint_id: e.checkpoint_id
417
+ } },
418
+ checkpoint: t,
419
+ metadata: c,
420
+ parentConfig: e.parent_checkpoint_id ? { configurable: {
421
+ thread_id: e.thread_id,
422
+ checkpoint_ns: i,
423
+ checkpoint_id: e.parent_checkpoint_id
424
+ } } : void 0,
425
+ pendingWrites: s
426
+ };
427
+ }
428
+ addSearchableMetadataFields(e, t) {
429
+ t && ("source" in t && (e.source = t.source), "step" in t && (e.step = t.step), "writes" in t && (e.writes = typeof t.writes == "object" ? JSON.stringify(t.writes) : t.writes), "score" in t && (e.score = t.score));
430
+ }
431
+ async applyTTL(...e) {
432
+ if (!this.ttlConfig?.defaultTTL) return;
433
+ const t = Math.floor(this.ttlConfig.defaultTTL * 60), s = await Promise.allSettled(e.map((i) => this.client.expire(i, t)));
434
+ for (let i = 0; i < s.length; i++) s[i].status === "rejected" && console.warn(`Failed to set TTL for key ${e[i]}:`, s[i].reason);
435
+ }
436
+ async ensureIndexes() {
437
+ for (const e of W) try {
438
+ await this.client.ft.create(e.index, e.schema, {
439
+ ON: "JSON",
440
+ PREFIX: e.prefix
441
+ });
442
+ } catch (t) {
443
+ t.message?.includes("Index already exists") || console.error(`Failed to create index ${e.index}:`, t.message);
444
+ }
445
+ }
446
+ };
447
+ function g(w) {
448
+ if (w === null || typeof w != "object") return JSON.stringify(w);
449
+ if (Array.isArray(w)) return JSON.stringify(w.map((s) => g(s)));
450
+ const e = {}, t = Object.keys(w).sort();
451
+ for (const s of t) e[s] = w[s];
452
+ return JSON.stringify(e, (s, i) => {
453
+ if (i !== null && typeof i == "object" && !Array.isArray(i)) {
454
+ const c = {}, o = Object.keys(i).sort();
455
+ for (const f of o) c[f] = i[f];
456
+ return c;
457
+ }
458
+ return i;
459
+ });
460
+ }
461
+ export {
462
+ E as RedisSaver
463
+ };
@@ -0,0 +1,211 @@
1
+ import { l as n } from "./graphBuilder-mpLrx9tk.mjs";
2
+ import { D as b, u as j, y as v, t as R, B as T, z as L, E as x, G as A, r as $, w as _, s as C, M as I, P as E, x as z, q as U, v as F, p as W, H as K } from "./graphBuilder-mpLrx9tk.mjs";
3
+ import r from "node:fs/promises";
4
+ import { join as m } from "node:path";
5
+ import { l as d } from "./load-Cjl9cJ0o.mjs";
6
+ const k = `
7
+
8
+ ## Project Documentation
9
+
10
+ {docs_content}`;
11
+ class g {
12
+ name = "AgentsMdMiddleware";
13
+ stateSchema = void 0;
14
+ contextSchema = void 0;
15
+ tools = [];
16
+ projectRoot;
17
+ systemPromptTemplate;
18
+ /**
19
+ * Initialize the documentation middleware.
20
+ *
21
+ * @param projectRoot - Path to the project root directory (defaults to process.cwd())
22
+ */
23
+ constructor(s = {}) {
24
+ this.projectRoot = s.projectRoot || process.cwd(), this.systemPromptTemplate = k;
25
+ }
26
+ /**
27
+ * Find and read the project documentation file.
28
+ * Priority: CLAUDE.md > AGENTS.md
29
+ *
30
+ * @returns The content of the first found documentation file, or null if none exist
31
+ */
32
+ async findDocumentationFile() {
33
+ const s = ["CLAUDE.md", "AGENTS.md"];
34
+ for (const i of s) {
35
+ const l = m(this.projectRoot, i);
36
+ try {
37
+ return await r.access(l), { content: await r.readFile(l, "utf-8"), filename: i };
38
+ } catch {
39
+ continue;
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ /**
45
+ * Inject project documentation into the system prompt.
46
+ *
47
+ * This runs on every model call to ensure documentation info is always available.
48
+ *
49
+ * @param request - The model request being processed
50
+ * @param handler - The handler function to call with the modified request
51
+ * @returns The model response from the handler
52
+ */
53
+ async wrapModelCall(s, i) {
54
+ const l = await this.findDocumentationFile();
55
+ if (!l)
56
+ return await i(s);
57
+ const t = this.systemPromptTemplate.replace("{docs_content}", l.content);
58
+ let e;
59
+ s.systemPrompt ? e = s.systemPrompt + `
60
+
61
+ ` + t : e = t;
62
+ const a = new n(e), o = {
63
+ ...s,
64
+ systemMessage: a
65
+ };
66
+ return await i(o);
67
+ }
68
+ }
69
+ const u = `
70
+
71
+ ## Skills System
72
+
73
+ You have access to a skills library that provides specialized capabilities and domain knowledge.
74
+
75
+ {skills_locations}
76
+
77
+ **Available Skills:**
78
+
79
+ {skills_list}
80
+
81
+ **How to Use Skills (Progressive Disclosure):**
82
+
83
+ Skills follow a **progressive disclosure** pattern - you know they exist (name + description above), but you only read the full instructions when needed:
84
+
85
+ 1. **Recognize when a skill applies**: Check if the user's task matches any skill's description
86
+ 2. **Read the skill's full instructions**: The skill list above shows the exact path to use with read_file
87
+ 3. **Follow the skill's instructions**: SKILL.md contains step-by-step workflows, best practices, and examples
88
+ 4. **Access supporting files**: Skills may include Python scripts, configs, or reference docs - use absolute paths
89
+
90
+ **When to Use Skills:**
91
+ - When the user's request matches a skill's domain (e.g., "research X" → web-research skill)
92
+ - When you need specialized knowledge or structured workflows
93
+ - When a skill provides proven patterns for complex tasks
94
+
95
+ **Skills are Self-Documenting:**
96
+ - Each SKILL.md tells you exactly what the skill does and how to use it
97
+ - The skill list above shows the full path for each skill's SKILL.md file
98
+
99
+ **Executing Skill Scripts:**
100
+ Skills may contain Python scripts or other executable files. Always use absolute paths from the skill list.
101
+
102
+ **Example Workflow:**
103
+
104
+ User: "Can you research the latest developments in quantum computing?"
105
+
106
+ 1. Check available skills above → See "web-research" skill with its full path
107
+ 2. Read the skill using the path shown in the list
108
+ 3. Follow the skill's research workflow (search → organize → synthesize)
109
+ 4. Use any helper scripts with absolute paths
110
+
111
+ Remember: Skills are tools to make you more capable and consistent. When in doubt, check if a skill exists for the task!
112
+ `;
113
+ class P {
114
+ name = "SkillsMiddleware";
115
+ // No context schema needed
116
+ stateSchema = void 0;
117
+ // No context schema needed
118
+ contextSchema = void 0;
119
+ // No additional tools
120
+ tools = [];
121
+ skillsDir;
122
+ assistantId;
123
+ projectSkillsDir;
124
+ userSkillsDisplay;
125
+ systemPromptTemplate;
126
+ /**
127
+ * Initialize the skills middleware.
128
+ *
129
+ * @param skillsDir - Path to the user-level skills directory (per-agent)
130
+ * @param assistantId - The agent identifier for path references in prompts
131
+ * @param projectSkillsDir - Optional path to project-level skills directory
132
+ */
133
+ constructor(s = {}) {
134
+ this.skillsDir = s.skillsDir, this.assistantId = s.assistantId, this.projectSkillsDir = s.projectSkillsDir || "./.claude/skills", this.skillsDir && !this.assistantId && console.warn("user skills directory is provided, but assistant id is not provided"), this.assistantId && (this.userSkillsDisplay = `~/.claude/${this.assistantId}/skills`), this.systemPromptTemplate = u;
135
+ }
136
+ /**
137
+ * Format skills locations for display in system prompt.
138
+ */
139
+ formatSkillsLocations() {
140
+ const s = [];
141
+ return this.userSkillsDisplay && s.push(`**User Skills**: \`${this.userSkillsDisplay}\``), this.projectSkillsDir && s.push(`**Project Skills**: \`${this.projectSkillsDir}\` (overrides user skills)`), s.join(`
142
+ `);
143
+ }
144
+ /**
145
+ * Format skills metadata for display in system prompt.
146
+ */
147
+ formatSkillsList(s) {
148
+ if (!s.length) {
149
+ const e = [`${this.userSkillsDisplay}/`];
150
+ return this.projectSkillsDir && e.push(`${this.projectSkillsDir}/`), `(No skills available yet. You can create skills in ${e.join(" or ")})`;
151
+ }
152
+ const i = s.filter((e) => e.source === "user"), l = s.filter((e) => e.source === "project"), t = [];
153
+ if (i.length) {
154
+ t.push("**User Skills:**");
155
+ for (const e of i)
156
+ t.push(`- **${e.name}**: ${e.description}`), t.push(` → Read \`${e.path}\` for full instructions`);
157
+ t.push("");
158
+ }
159
+ if (l.length) {
160
+ t.push("**Project Skills:**");
161
+ for (const e of l)
162
+ t.push(`- **${e.name}**: ${e.description}`), t.push(` → Read \`${e.path}\` for full instructions`);
163
+ }
164
+ return t.join(`
165
+ `);
166
+ }
167
+ /**
168
+ * Inject skills documentation into the system prompt.
169
+ *
170
+ * This runs on every model call to ensure skills info is always available.
171
+ *
172
+ * @param request - The model request being processed
173
+ * @param handler - The handler function to call with the modified request
174
+ * @returns The model response from the handler
175
+ */
176
+ async wrapModelCall(s, i) {
177
+ const l = d(this.skillsDir, this.projectSkillsDir), t = this.formatSkillsLocations(), e = this.formatSkillsList(l), a = this.systemPromptTemplate.replace("{skills_locations}", t).replace("{skills_list}", e);
178
+ let o;
179
+ s.systemPrompt ? o = s.systemPrompt + `
180
+
181
+ ` + a : o = a;
182
+ const h = new n(o), p = {
183
+ ...s,
184
+ systemMessage: h
185
+ };
186
+ return await i(p);
187
+ }
188
+ }
189
+ export {
190
+ b as AgentPackage,
191
+ j as AgentPackageSchema,
192
+ v as AgentRepository,
193
+ R as AgentSchema,
194
+ T as AgentSerializer,
195
+ L as AgentValidator,
196
+ g as AgentsMdMiddleware,
197
+ x as BaseStorage,
198
+ A as MemoryStorage,
199
+ $ as MiddlewareCustomParamsSchema,
200
+ _ as MiddlewareRegistry,
201
+ C as MiddlewareSchema,
202
+ I as ModelSchema,
203
+ E as PromptSchema,
204
+ P as SkillsMiddleware,
205
+ z as StandardAgent,
206
+ U as ToolCustomParamsSchema,
207
+ F as ToolRegistry,
208
+ W as ToolSchema,
209
+ K as anthropicPromptCachingMiddleware,
210
+ d as listSkills
211
+ };