zen-code 3.0.4 → 4.0.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.
@@ -1,6 +1,6 @@
1
- import { r as P, u as d, p as _ } from "./graphBuilder-B6OHvcgJ.mjs";
1
+ import { r as P, u as d, s as _ } from "./graphBuilder-ulTm2bmI.mjs";
2
2
  var v, m, g = 0, O = 0;
3
- function h(r, e, n) {
3
+ function s(r, e, n) {
4
4
  var f = 0, t = e || new Array(16);
5
5
  r = r || {};
6
6
  var i = r.node, a = r.clockseq;
@@ -8,8 +8,8 @@ function h(r, e, n) {
8
8
  var u = r.random || (r.rng || P)();
9
9
  i == null && (i = [u[0], u[1], u[2], u[3], u[4], u[5]], !v && !r._v6 && (i[0] |= 1, v = i)), a == null && (a = (u[6] << 8 | u[7]) & 16383, m === void 0 && !r._v6 && (m = a));
10
10
  }
11
- var c = r.msecs !== void 0 ? r.msecs : Date.now(), o = r.nsecs !== void 0 ? r.nsecs : O + 1, p = c - g + (o - O) / 1e4;
12
- if (p < 0 && r.clockseq === void 0 && (a = a + 1 & 16383), (p < 0 || c > g) && r.nsecs === void 0 && (o = 0), o >= 1e4)
11
+ var c = r.msecs !== void 0 ? r.msecs : Date.now(), o = r.nsecs !== void 0 ? r.nsecs : O + 1, j = c - g + (o - O) / 1e4;
12
+ if (j < 0 && r.clockseq === void 0 && (a = a + 1 & 16383), (j < 0 || c > g) && r.nsecs === void 0 && (o = 0), o >= 1e4)
13
13
  throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
14
14
  g = c, O = o, m = a, c += 122192928e5;
15
15
  var l = ((c & 268435455) * 1e4 + o) % 4294967296;
@@ -20,14 +20,14 @@ function h(r, e, n) {
20
20
  t[f + b] = i[b];
21
21
  return e || d(t);
22
22
  }
23
- function s(r) {
23
+ function h(r) {
24
24
  var e = typeof r == "string" ? _(r) : r, n = S(e);
25
25
  return typeof r == "string" ? d(n) : n;
26
26
  }
27
27
  function S(r, e = !1) {
28
28
  return Uint8Array.of((r[6] & 15) << 4 | r[7] >> 4 & 15, (r[7] & 15) << 4 | (r[4] & 240) >> 4, (r[4] & 15) << 4 | (r[5] & 240) >> 4, (r[5] & 15) << 4 | (r[0] & 240) >> 4, (r[0] & 15) << 4 | (r[1] & 240) >> 4, (r[1] & 15) << 4 | (r[2] & 240) >> 4, 96 | r[2] & 15, r[3], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]);
29
29
  }
30
- function j(r, e) {
30
+ function p(r, e) {
31
31
  var n = Object.keys(r);
32
32
  if (Object.getOwnPropertySymbols) {
33
33
  var f = Object.getOwnPropertySymbols(r);
@@ -40,9 +40,9 @@ function j(r, e) {
40
40
  function w(r) {
41
41
  for (var e = 1; e < arguments.length; e++) {
42
42
  var n = arguments[e] != null ? arguments[e] : {};
43
- e % 2 ? j(Object(n), !0).forEach(function(f) {
43
+ e % 2 ? p(Object(n), !0).forEach(function(f) {
44
44
  k(r, f, n[f]);
45
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(n)) : j(Object(n)).forEach(function(f) {
45
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(n)) : p(Object(n)).forEach(function(f) {
46
46
  Object.defineProperty(r, f, Object.getOwnPropertyDescriptor(n, f));
47
47
  });
48
48
  }
@@ -66,10 +66,10 @@ function q(r, e) {
66
66
  return (e === "string" ? String : Number)(r);
67
67
  }
68
68
  function E(r = {}, e, n = 0) {
69
- var f = h(w(w({}, r), {}, {
69
+ var f = s(w(w({}, r), {}, {
70
70
  _v6: !0
71
71
  }), new Uint8Array(16));
72
- return f = s(f), d(f);
72
+ return f = h(f), d(f);
73
73
  }
74
74
  function A(r) {
75
75
  return E({ clockseq: r });
@@ -0,0 +1,212 @@
1
+ import { S as n } from "./graphBuilder-ulTm2bmI.mjs";
2
+ import { n as b, f as j, k as v, A as R, m as T, l as L, B as A, o as x, d as $, i as C, e as _, M as I, P as E, j as U, b as z, h as F, a as W, q as K, p as Y } from "./graphBuilder-ulTm2bmI.mjs";
3
+ import r from "node:fs/promises";
4
+ import { join as p } 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 = p(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), m = {
183
+ ...s,
184
+ systemMessage: h
185
+ };
186
+ return await i(m);
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
+ A as BaseStorage,
198
+ x as MemoryStorage,
199
+ $ as MiddlewareCustomParamsSchema,
200
+ C as MiddlewareRegistry,
201
+ _ as MiddlewareSchema,
202
+ I as ModelSchema,
203
+ E as PromptSchema,
204
+ P as SkillsMiddleware,
205
+ U as StandardAgent,
206
+ z as ToolCustomParamsSchema,
207
+ F as ToolRegistry,
208
+ W as ToolSchema,
209
+ K as anthropicPromptCachingMiddleware,
210
+ Y as fromLangChainTool,
211
+ d as listSkills
212
+ };
@@ -1,6 +1,6 @@
1
- import { u as C } from "./id-BclYO3iE.mjs";
2
- import { B as v, c as x, T as $, m as I } from "./app-D748EsP_.mjs";
3
- import "./graphBuilder-B6OHvcgJ.mjs";
1
+ import { u as C } from "./id-BHzJB_zk.mjs";
2
+ import { B as v, c as x, T as $, m as I } from "./app-QzdcE86p.mjs";
3
+ import "./graphBuilder-ulTm2bmI.mjs";
4
4
  import { createClient as O, createCluster as N } from "redis";
5
5
  const W = [
6
6
  {
@@ -0,0 +1,119 @@
1
+ import { existsSync as d, readdirSync as A, lstatSync as b, statSync as k, readFileSync as x } from "node:fs";
2
+ import { resolve as m, join as y } from "node:path";
3
+ import { parse as N } from "yaml";
4
+ const Y = 10 * 1024 * 1024, j = 64, p = 1024;
5
+ function S(t, o) {
6
+ try {
7
+ const n = m(t), i = m(o), e = n.substring(i.length);
8
+ return n === i || e.startsWith("/") || e === "";
9
+ } catch {
10
+ return !1;
11
+ }
12
+ }
13
+ function z(t) {
14
+ return t ? t.length > j ? [!1, "name exceeds 64 characters"] : /^[a-z0-9]+(-[a-z0-9]+)*$/.test(t) ? [!0, ""] : [!1, "name must be lowercase alphanumeric with single hyphens only"] : [!1, "name is required"];
15
+ }
16
+ function C(t) {
17
+ const o = ["architecture", "bug-fix", "workflow", "configuration", "optimization"];
18
+ return t ? o.includes(t) ? [!0, ""] : [!1, `category must be one of: ${o.join(", ")}`] : [!1, "category is required"];
19
+ }
20
+ function I(t, o) {
21
+ try {
22
+ const n = k(t);
23
+ if (n.size > Y)
24
+ return console.warn(`Skipping ${t}: file too large (${n.size} bytes)`), null;
25
+ const i = x(t, "utf-8"), e = /^---\s*\n(.*?)\n---\s*\n/s, a = i.match(e);
26
+ if (!a)
27
+ return console.warn(`Skipping ${t}: no valid YAML frontmatter found`), null;
28
+ const c = a[1];
29
+ let r;
30
+ try {
31
+ r = N(c);
32
+ } catch (M) {
33
+ return console.warn(`Invalid YAML in ${t}: ${M}`), null;
34
+ }
35
+ if (typeof r != "object" || r === null)
36
+ return console.warn(`Skipping ${t}: frontmatter is not a mapping`), null;
37
+ const s = r.name, l = r.description, u = r.tags, g = r.category;
38
+ if (!s || !l || !u || !g)
39
+ return console.warn(`Skipping ${t}: missing required fields (name, description, tags, category)`), null;
40
+ const [_, w] = z(String(s));
41
+ _ || console.warn(
42
+ `Memory '${s}' in ${t} does not follow naming convention: ${w}. Consider renaming to be compliant.`
43
+ );
44
+ const [h, E] = C(String(g));
45
+ if (!h)
46
+ return console.warn(`Skipping ${t}: ${E}`), null;
47
+ let f = String(l);
48
+ if (f.length > p && (console.warn(`Description exceeds ${p} chars in ${t}, truncating`), f = f.substring(0, p)), !Array.isArray(u))
49
+ return console.warn(`Skipping ${t}: tags must be an array`), null;
50
+ const v = u.map(String);
51
+ return {
52
+ name: String(s),
53
+ description: f,
54
+ tags: v,
55
+ category: String(g),
56
+ path: t,
57
+ source: o,
58
+ created: r.created,
59
+ last_updated: r.last_updated,
60
+ priority: r.priority || "medium",
61
+ context_scope: r.context_scope || "project"
62
+ };
63
+ } catch (n) {
64
+ return console.warn(`Error reading ${t}: ${n.message}`), null;
65
+ }
66
+ }
67
+ function $(t, o) {
68
+ if (!d(t))
69
+ return [];
70
+ let n;
71
+ try {
72
+ n = m(t);
73
+ } catch {
74
+ return [];
75
+ }
76
+ const i = [];
77
+ let e;
78
+ try {
79
+ e = A(t);
80
+ } catch {
81
+ return [];
82
+ }
83
+ for (const a of e) {
84
+ const c = y(t, a);
85
+ if (!S(c, n))
86
+ continue;
87
+ let r;
88
+ try {
89
+ r = b(c);
90
+ } catch {
91
+ continue;
92
+ }
93
+ if (!r.isDirectory())
94
+ continue;
95
+ const s = y(c, "MEMORY.md");
96
+ if (!d(s) || !S(s, n))
97
+ continue;
98
+ const l = I(s, o);
99
+ l && i.push(l);
100
+ }
101
+ return i;
102
+ }
103
+ function q(t, o) {
104
+ const n = /* @__PURE__ */ new Map();
105
+ if (t) {
106
+ const i = $(t, "user");
107
+ for (const e of i)
108
+ n.set(e.name, e);
109
+ }
110
+ if (o) {
111
+ const i = $(o, "project");
112
+ for (const e of i)
113
+ n.set(e.name, e);
114
+ }
115
+ return Array.from(n.values());
116
+ }
117
+ export {
118
+ q as l
119
+ };
@@ -0,0 +1,105 @@
1
+ import { existsSync as S, readdirSync as _, lstatSync as L, statSync as v, readFileSync as I } from "node:fs";
2
+ import { resolve as m, join as d } from "node:path";
3
+ import { parse as b } from "yaml";
4
+ const A = 10 * 1024 * 1024, E = 64, f = 1024;
5
+ function g(t, o) {
6
+ try {
7
+ const n = m(t), s = m(o), e = n.substring(s.length);
8
+ return n === s || e.startsWith("/") || e === "";
9
+ } catch {
10
+ return !1;
11
+ }
12
+ }
13
+ function N(t, o) {
14
+ return t ? t.length > E ? [!1, "name exceeds 64 characters"] : /^[a-z0-9]+(-[a-z0-9]+)*$/.test(t) ? t !== o ? [!1, `name '${t}' must match directory name '${o}'`] : [!0, ""] : [!1, "name must be lowercase alphanumeric with single hyphens only"] : [!1, "name is required"];
15
+ }
16
+ function x(t, o) {
17
+ try {
18
+ const n = v(t);
19
+ if (n.size > A)
20
+ return console.warn(`Skipping ${t}: file too large (${n.size} bytes)`), null;
21
+ const s = I(t, "utf-8"), e = /^---\s*\n(.*?)\n---\s*\n/s, c = s.match(e);
22
+ if (!c)
23
+ return console.warn(`Skipping ${t}: no valid YAML frontmatter found`), null;
24
+ const a = c[1];
25
+ let r;
26
+ try {
27
+ r = b(a);
28
+ } catch (w) {
29
+ return console.warn(`Invalid YAML in ${t}: ${w}`), null;
30
+ }
31
+ if (typeof r != "object" || r === null)
32
+ return console.warn(`Skipping ${t}: frontmatter is not a mapping`), null;
33
+ const i = r.name, l = r.description;
34
+ if (!i || !l)
35
+ return console.warn(`Skipping ${t}: missing required 'name' or 'description'`), null;
36
+ const p = t.split("/").slice(-2)[0], [$, h] = N(String(i), p);
37
+ $ || console.warn(`Skill '${i}' in ${t} does not follow Agent Skills spec: ${h}. Consider renaming to be spec-compliant.`);
38
+ let u = String(l);
39
+ return u.length > f && (console.warn(`Description exceeds ${f} chars in ${t}, truncating`), u = u.substring(0, f)), {
40
+ name: String(i),
41
+ description: u,
42
+ path: t,
43
+ source: o,
44
+ license: r.license,
45
+ compatibility: r.compatibility,
46
+ metadata: r.metadata,
47
+ allowed_tools: r["allowed-tools"]
48
+ };
49
+ } catch (n) {
50
+ return console.warn(`Error reading ${t}: ${n.message}`), null;
51
+ }
52
+ }
53
+ function y(t, o) {
54
+ if (!S(t))
55
+ return [];
56
+ let n;
57
+ try {
58
+ n = m(t);
59
+ } catch {
60
+ return [];
61
+ }
62
+ const s = [];
63
+ let e;
64
+ try {
65
+ e = _(t);
66
+ } catch {
67
+ return [];
68
+ }
69
+ for (const c of e) {
70
+ const a = d(t, c);
71
+ if (!g(a, n))
72
+ continue;
73
+ let r;
74
+ try {
75
+ r = L(a);
76
+ } catch {
77
+ continue;
78
+ }
79
+ if (!r.isDirectory())
80
+ continue;
81
+ const i = d(a, "SKILL.md");
82
+ if (!S(i) || !g(i, n))
83
+ continue;
84
+ const l = x(i, o);
85
+ l && s.push(l);
86
+ }
87
+ return s;
88
+ }
89
+ function k(t, o) {
90
+ const n = /* @__PURE__ */ new Map();
91
+ if (t) {
92
+ const s = y(t, "user");
93
+ for (const e of s)
94
+ n.set(e.name, e);
95
+ }
96
+ if (o) {
97
+ const s = y(o, "project");
98
+ for (const e of s)
99
+ n.set(e.name, e);
100
+ }
101
+ return Array.from(n.values());
102
+ }
103
+ export {
104
+ k as l
105
+ };
@@ -0,0 +1,115 @@
1
+ import { l } from "./load-Bh8eo6qE.mjs";
2
+ import { S as h } from "./graphBuilder-ulTm2bmI.mjs";
3
+ const M = `## Memory System
4
+
5
+ 你可以访问一个包含之前任务和经验知识的记忆库。
6
+
7
+ {memories_locations}
8
+
9
+ **可用的记忆:**
10
+
11
+ {memories_list}
12
+
13
+ **如何使用记忆:**
14
+
15
+ 记忆采用 **渐进式披露** 模式 - 你知道它们存在(上面有元数据),但只在需要时才读取完整内容:
16
+
17
+ 1. **识别适用的记忆**: 检查当前任务是否匹配任何记忆的描述或标签
18
+ 2. **读取完整记忆内容**: 使用 read_file 工具,路径见上面的列表
19
+ 3. **应用知识**: 使用记忆中的信息来指导当前任务
20
+
21
+ **何时使用记忆:**
22
+ - 遇到与之前任务类似的问题时
23
+ - 需要回忆项目特定的约定或模式时
24
+ - 需要参考之前的解决方案或决策时
25
+ - 需要记住配置或设置细节时
26
+
27
+ 记住:记忆是帮助你变得更强大和一致的工具。有疑问时,检查是否有相关的记忆存在!
28
+ `;
29
+ class f {
30
+ name = "MemoriesMiddleware";
31
+ // No context schema needed
32
+ stateSchema = void 0;
33
+ // No context schema needed
34
+ contextSchema = void 0;
35
+ // No additional tools
36
+ tools = [];
37
+ memoriesDir;
38
+ assistantId;
39
+ projectMemoriesDir;
40
+ userMemoriesDisplay;
41
+ systemPromptTemplate;
42
+ /**
43
+ * Initialize the memories middleware.
44
+ *
45
+ * @param memoriesDir - Path to the user-level memories directory (per-agent)
46
+ * @param assistantId - The agent identifier for path references in prompts
47
+ * @param projectMemoriesDir - Optional path to project-level memories directory
48
+ */
49
+ constructor(e = {}) {
50
+ this.memoriesDir = e.memoriesDir, this.assistantId = e.assistantId, this.projectMemoriesDir = e.projectMemoriesDir || "./.claude/memories", this.memoriesDir && !this.assistantId && console.warn("user memories directory is provided, but assistant id is not provided"), this.assistantId && (this.userMemoriesDisplay = `~/.claude/${this.assistantId}/memories`), this.systemPromptTemplate = M;
51
+ }
52
+ /**
53
+ * Format memories locations for display in system prompt.
54
+ */
55
+ formatMemoriesLocations() {
56
+ const e = [];
57
+ return this.userMemoriesDisplay && e.push(`**User Memories**: \`${this.userMemoriesDisplay}\``), this.projectMemoriesDir && e.push(`**Project Memories**: \`${this.projectMemoriesDir}\` (overrides user memories)`), e.join(`
58
+ `);
59
+ }
60
+ /**
61
+ * Format memories metadata for display in system prompt.
62
+ */
63
+ formatMemoriesList(e) {
64
+ if (!e.length) {
65
+ const s = [`${this.userMemoriesDisplay}/`];
66
+ return this.projectMemoriesDir && s.push(`${this.projectMemoriesDir}/`), `(No memories available yet. You can create memories in ${s.join(" or ")})`;
67
+ }
68
+ const n = ["architecture", "bug-fix", "workflow", "configuration", "optimization"], r = /* @__PURE__ */ new Map();
69
+ for (const s of e)
70
+ r.has(s.category) || r.set(s.category, []), r.get(s.category).push(s);
71
+ const t = [];
72
+ for (const s of n) {
73
+ const o = r.get(s);
74
+ if (!o || o.length === 0)
75
+ continue;
76
+ t.push(`**${s.charAt(0).toUpperCase() + s.slice(1)} Memories:**`);
77
+ const m = { high: 0, medium: 1, low: 2 };
78
+ o.sort((i, a) => {
79
+ const c = m[i.priority || "medium"] ?? 1, p = m[a.priority || "medium"] ?? 1;
80
+ return c !== p ? c - p : i.name.localeCompare(a.name);
81
+ });
82
+ for (const i of o) {
83
+ const a = i.tags.length > 0 ? ` [${i.tags.join(", ")}]` : "";
84
+ t.push(`- **${i.name}**: ${i.description}${a}`), t.push(` → Read \`${i.path}\` for full content`);
85
+ }
86
+ t.push("");
87
+ }
88
+ return t.join(`
89
+ `);
90
+ }
91
+ /**
92
+ * Inject memories documentation into the system prompt.
93
+ *
94
+ * This runs on every model call to ensure memories info is always available.
95
+ *
96
+ * @param request - The model request being processed
97
+ * @param handler - The handler function to call with the modified request
98
+ * @returns The model response from the handler
99
+ */
100
+ async wrapModelCall(e, n) {
101
+ const r = l(this.memoriesDir, this.projectMemoriesDir), t = this.formatMemoriesLocations(), s = this.formatMemoriesList(r), o = this.systemPromptTemplate.replace("{memories_locations}", t).replace("{memories_list}", s);
102
+ let m;
103
+ e.systemPrompt ? m = e.systemPrompt + `
104
+
105
+ ` + o : m = o;
106
+ const i = new h(m), a = {
107
+ ...e,
108
+ systemMessage: i
109
+ };
110
+ return await n(a);
111
+ }
112
+ }
113
+ export {
114
+ f as MemoriesMiddleware
115
+ };