evolcore 0.0.8 → 0.0.9

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 (213) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +37 -3
  3. package/dist/agents/baseagent.js +111 -19
  4. package/dist/agents/claude-runner.js +30 -2
  5. package/dist/agents/codex-app-server-client.js +31 -0
  6. package/dist/agents/codex-runner.js +3 -0
  7. package/dist/aun/msg/group.js +9 -9
  8. package/dist/aun/msg/p2p.js +11 -6
  9. package/dist/aun/msg/upload.js +43 -29
  10. package/dist/aun/outbox.js +48 -5
  11. package/dist/channels/aun.js +199 -50
  12. package/dist/cli/aun-commands.js +10 -7
  13. package/dist/cli/daemon-commands.js +19 -4
  14. package/dist/cli/index.js +11 -1
  15. package/dist/cli/init.js +103 -4
  16. package/dist/cli/model.js +5 -5
  17. package/dist/config/builtin-role-templates.js +4 -3
  18. package/dist/config/config-field-policy.js +6 -2
  19. package/dist/config/config-manager.js +48 -11
  20. package/dist/config/role-schema.js +18 -3
  21. package/dist/config/role-service.js +3 -3
  22. package/dist/config/role-store.js +4 -3
  23. package/dist/config-store.js +4 -0
  24. package/dist/core/auth/operation-authorizer.js +3 -1
  25. package/dist/core/bootstrap-service.js +0 -12
  26. package/dist/core/channel-loader.js +5 -1
  27. package/dist/core/command/command-handler.js +1 -1
  28. package/dist/core/command/evol-menu-version-gate.js +3 -2
  29. package/dist/core/command/menu-handler.js +33 -22
  30. package/dist/core/command/menu-protocol.js +7 -4
  31. package/dist/core/command/slash-handler.js +4 -4
  32. package/dist/core/inference/text-inference.js +18 -5
  33. package/dist/core/message/message-bridge.js +17 -6
  34. package/dist/core/message/response-engine.js +22 -3
  35. package/dist/core/model/config-scope.js +3 -3
  36. package/dist/core/permission/tool-policy.js +18 -0
  37. package/dist/index.js +43 -26
  38. package/dist/ipc.js +1 -1
  39. package/dist/product.js +1 -0
  40. package/dist/utils/autostart.js +27 -0
  41. package/dist/utils/ecweb-utils.js +15 -2
  42. package/dist/utils/macos-autostart.js +179 -0
  43. package/dist/utils/windows-autostart.js +130 -0
  44. package/ecagent/dist/agent-loop.d.ts +1 -1
  45. package/ecagent/dist/agent-loop.js +1 -1
  46. package/ecagent/dist/agent.d.ts +1 -1
  47. package/ecagent/dist/agent.js +1 -1
  48. package/ecagent/dist/harness/agent-harness.d.ts +1 -1
  49. package/ecagent/dist/harness/compaction/branch-summarization.d.ts +1 -1
  50. package/ecagent/dist/harness/compaction/compaction.d.ts +1 -1
  51. package/ecagent/dist/harness/compaction/utils.d.ts +1 -1
  52. package/ecagent/dist/harness/messages.d.ts +1 -1
  53. package/ecagent/dist/harness/session/session.d.ts +1 -1
  54. package/ecagent/dist/harness/types.d.ts +1 -1
  55. package/ecagent/dist/proxy.d.ts +1 -1
  56. package/ecagent/dist/proxy.js +1 -1
  57. package/ecagent/dist/types.d.ts +1 -1
  58. package/kits/migrations/migrate-role-config-v5.mjs +27 -2
  59. package/kits/schemas/agent-config.schema.10.json +19 -1
  60. package/kits/schemas/daemon.schema.4.json +4 -0
  61. package/kits/schemas/defaults.schema.4.json +15 -1
  62. package/kits/schemas/relation-config.schema.8.json +22 -1
  63. package/kits/schemas/role-config.schema.1.json +2 -2
  64. package/package.json +2 -4
  65. package/ecagent/dist/agent-loop.d.ts.map +0 -1
  66. package/ecagent/dist/agent-loop.js.map +0 -1
  67. package/ecagent/dist/agent.d.ts.map +0 -1
  68. package/ecagent/dist/agent.js.map +0 -1
  69. package/ecagent/dist/harness/agent-harness.d.ts.map +0 -1
  70. package/ecagent/dist/harness/agent-harness.js.map +0 -1
  71. package/ecagent/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
  72. package/ecagent/dist/harness/compaction/branch-summarization.js.map +0 -1
  73. package/ecagent/dist/harness/compaction/compaction.d.ts.map +0 -1
  74. package/ecagent/dist/harness/compaction/compaction.js.map +0 -1
  75. package/ecagent/dist/harness/compaction/utils.d.ts.map +0 -1
  76. package/ecagent/dist/harness/compaction/utils.js.map +0 -1
  77. package/ecagent/dist/harness/env/nodejs.d.ts.map +0 -1
  78. package/ecagent/dist/harness/env/nodejs.js.map +0 -1
  79. package/ecagent/dist/harness/messages.d.ts.map +0 -1
  80. package/ecagent/dist/harness/messages.js.map +0 -1
  81. package/ecagent/dist/harness/prompt-templates.d.ts.map +0 -1
  82. package/ecagent/dist/harness/prompt-templates.js.map +0 -1
  83. package/ecagent/dist/harness/session/jsonl-repo.d.ts.map +0 -1
  84. package/ecagent/dist/harness/session/jsonl-repo.js.map +0 -1
  85. package/ecagent/dist/harness/session/jsonl-storage.d.ts.map +0 -1
  86. package/ecagent/dist/harness/session/jsonl-storage.js.map +0 -1
  87. package/ecagent/dist/harness/session/memory-repo.d.ts.map +0 -1
  88. package/ecagent/dist/harness/session/memory-repo.js.map +0 -1
  89. package/ecagent/dist/harness/session/memory-storage.d.ts.map +0 -1
  90. package/ecagent/dist/harness/session/memory-storage.js.map +0 -1
  91. package/ecagent/dist/harness/session/repo-utils.d.ts.map +0 -1
  92. package/ecagent/dist/harness/session/repo-utils.js.map +0 -1
  93. package/ecagent/dist/harness/session/session.d.ts.map +0 -1
  94. package/ecagent/dist/harness/session/session.js.map +0 -1
  95. package/ecagent/dist/harness/session/uuid.d.ts.map +0 -1
  96. package/ecagent/dist/harness/session/uuid.js.map +0 -1
  97. package/ecagent/dist/harness/skills.d.ts.map +0 -1
  98. package/ecagent/dist/harness/skills.js.map +0 -1
  99. package/ecagent/dist/harness/system-prompt.d.ts.map +0 -1
  100. package/ecagent/dist/harness/system-prompt.js.map +0 -1
  101. package/ecagent/dist/harness/types.d.ts.map +0 -1
  102. package/ecagent/dist/harness/types.js.map +0 -1
  103. package/ecagent/dist/harness/utils/shell-output.d.ts.map +0 -1
  104. package/ecagent/dist/harness/utils/shell-output.js.map +0 -1
  105. package/ecagent/dist/harness/utils/truncate.d.ts.map +0 -1
  106. package/ecagent/dist/harness/utils/truncate.js.map +0 -1
  107. package/ecagent/dist/index.d.ts.map +0 -1
  108. package/ecagent/dist/index.js.map +0 -1
  109. package/ecagent/dist/node.d.ts.map +0 -1
  110. package/ecagent/dist/node.js.map +0 -1
  111. package/ecagent/dist/proxy.d.ts.map +0 -1
  112. package/ecagent/dist/proxy.js.map +0 -1
  113. package/ecagent/dist/runtime/api/lazy.d.ts.map +0 -1
  114. package/ecagent/dist/runtime/api/lazy.js.map +0 -1
  115. package/ecagent/dist/runtime/api/pi-messages.d.ts.map +0 -1
  116. package/ecagent/dist/runtime/api/pi-messages.js.map +0 -1
  117. package/ecagent/dist/runtime/api/pi-messages.lazy.d.ts.map +0 -1
  118. package/ecagent/dist/runtime/api/pi-messages.lazy.js.map +0 -1
  119. package/ecagent/dist/runtime/auth/context.d.ts.map +0 -1
  120. package/ecagent/dist/runtime/auth/context.js.map +0 -1
  121. package/ecagent/dist/runtime/auth/credential-store.d.ts.map +0 -1
  122. package/ecagent/dist/runtime/auth/credential-store.js.map +0 -1
  123. package/ecagent/dist/runtime/auth/helpers.d.ts.map +0 -1
  124. package/ecagent/dist/runtime/auth/helpers.js.map +0 -1
  125. package/ecagent/dist/runtime/auth/resolve.d.ts.map +0 -1
  126. package/ecagent/dist/runtime/auth/resolve.js.map +0 -1
  127. package/ecagent/dist/runtime/auth/types.d.ts.map +0 -1
  128. package/ecagent/dist/runtime/auth/types.js.map +0 -1
  129. package/ecagent/dist/runtime/compat.d.ts.map +0 -1
  130. package/ecagent/dist/runtime/compat.js.map +0 -1
  131. package/ecagent/dist/runtime/index.d.ts.map +0 -1
  132. package/ecagent/dist/runtime/index.js.map +0 -1
  133. package/ecagent/dist/runtime/models.d.ts.map +0 -1
  134. package/ecagent/dist/runtime/models.js.map +0 -1
  135. package/ecagent/dist/runtime/oauth.d.ts.map +0 -1
  136. package/ecagent/dist/runtime/oauth.js.map +0 -1
  137. package/ecagent/dist/runtime/providers/faux.d.ts.map +0 -1
  138. package/ecagent/dist/runtime/providers/faux.js.map +0 -1
  139. package/ecagent/dist/runtime/types.d.ts.map +0 -1
  140. package/ecagent/dist/runtime/types.js.map +0 -1
  141. package/ecagent/dist/runtime/utils/diagnostics.d.ts.map +0 -1
  142. package/ecagent/dist/runtime/utils/diagnostics.js.map +0 -1
  143. package/ecagent/dist/runtime/utils/event-stream.d.ts.map +0 -1
  144. package/ecagent/dist/runtime/utils/event-stream.js.map +0 -1
  145. package/ecagent/dist/runtime/utils/headers.d.ts.map +0 -1
  146. package/ecagent/dist/runtime/utils/headers.js.map +0 -1
  147. package/ecagent/dist/runtime/utils/json-parse.d.ts.map +0 -1
  148. package/ecagent/dist/runtime/utils/json-parse.js.map +0 -1
  149. package/ecagent/dist/runtime/utils/oauth/types.d.ts.map +0 -1
  150. package/ecagent/dist/runtime/utils/oauth/types.js.map +0 -1
  151. package/ecagent/dist/runtime/utils/overflow.d.ts.map +0 -1
  152. package/ecagent/dist/runtime/utils/overflow.js.map +0 -1
  153. package/ecagent/dist/runtime/utils/provider-env.d.ts.map +0 -1
  154. package/ecagent/dist/runtime/utils/provider-env.js.map +0 -1
  155. package/ecagent/dist/runtime/utils/retry.d.ts.map +0 -1
  156. package/ecagent/dist/runtime/utils/retry.js.map +0 -1
  157. package/ecagent/dist/runtime/utils/typebox-helpers.d.ts.map +0 -1
  158. package/ecagent/dist/runtime/utils/typebox-helpers.js.map +0 -1
  159. package/ecagent/dist/runtime/utils/validation.d.ts.map +0 -1
  160. package/ecagent/dist/runtime/utils/validation.js.map +0 -1
  161. package/ecagent/dist/types.d.ts.map +0 -1
  162. package/ecagent/dist/types.js.map +0 -1
  163. package/ecagent/package.json +0 -93
  164. package/ecagent/src/agent-loop.ts +0 -792
  165. package/ecagent/src/agent.ts +0 -575
  166. package/ecagent/src/harness/agent-harness.ts +0 -1029
  167. package/ecagent/src/harness/compaction/branch-summarization.ts +0 -261
  168. package/ecagent/src/harness/compaction/compaction.ts +0 -753
  169. package/ecagent/src/harness/compaction/utils.ts +0 -144
  170. package/ecagent/src/harness/env/nodejs.ts +0 -569
  171. package/ecagent/src/harness/messages.ts +0 -164
  172. package/ecagent/src/harness/prompt-templates.ts +0 -267
  173. package/ecagent/src/harness/session/jsonl-repo.ts +0 -179
  174. package/ecagent/src/harness/session/jsonl-storage.ts +0 -314
  175. package/ecagent/src/harness/session/memory-repo.ts +0 -50
  176. package/ecagent/src/harness/session/memory-storage.ts +0 -133
  177. package/ecagent/src/harness/session/repo-utils.ts +0 -51
  178. package/ecagent/src/harness/session/session.ts +0 -338
  179. package/ecagent/src/harness/session/uuid.ts +0 -54
  180. package/ecagent/src/harness/skills.ts +0 -375
  181. package/ecagent/src/harness/system-prompt.ts +0 -34
  182. package/ecagent/src/harness/types.ts +0 -838
  183. package/ecagent/src/harness/utils/shell-output.ts +0 -135
  184. package/ecagent/src/harness/utils/truncate.ts +0 -344
  185. package/ecagent/src/index.ts +0 -46
  186. package/ecagent/src/node.ts +0 -2
  187. package/ecagent/src/proxy.ts +0 -367
  188. package/ecagent/src/runtime/api/lazy.ts +0 -70
  189. package/ecagent/src/runtime/api/pi-messages.lazy.ts +0 -4
  190. package/ecagent/src/runtime/api/pi-messages.ts +0 -436
  191. package/ecagent/src/runtime/auth/context.ts +0 -45
  192. package/ecagent/src/runtime/auth/credential-store.ts +0 -47
  193. package/ecagent/src/runtime/auth/helpers.ts +0 -46
  194. package/ecagent/src/runtime/auth/resolve.ts +0 -141
  195. package/ecagent/src/runtime/auth/types.ts +0 -182
  196. package/ecagent/src/runtime/compat.ts +0 -158
  197. package/ecagent/src/runtime/index.ts +0 -31
  198. package/ecagent/src/runtime/models.ts +0 -452
  199. package/ecagent/src/runtime/oauth.ts +0 -1
  200. package/ecagent/src/runtime/providers/faux.ts +0 -538
  201. package/ecagent/src/runtime/types.ts +0 -718
  202. package/ecagent/src/runtime/utils/diagnostics.ts +0 -45
  203. package/ecagent/src/runtime/utils/event-stream.ts +0 -88
  204. package/ecagent/src/runtime/utils/headers.ts +0 -18
  205. package/ecagent/src/runtime/utils/json-parse.ts +0 -124
  206. package/ecagent/src/runtime/utils/oauth/types.ts +0 -79
  207. package/ecagent/src/runtime/utils/overflow.ts +0 -165
  208. package/ecagent/src/runtime/utils/provider-env.ts +0 -52
  209. package/ecagent/src/runtime/utils/retry.ts +0 -101
  210. package/ecagent/src/runtime/utils/typebox-helpers.ts +0 -24
  211. package/ecagent/src/runtime/utils/validation.ts +0 -310
  212. package/ecagent/src/types.ts +0 -430
  213. package/ecagent/tsconfig.build.json +0 -32
@@ -1,375 +0,0 @@
1
- import ignore from "ignore";
2
- import { parse } from "yaml";
3
- import { type ExecutionEnv, type FileInfo, type Result, type Skill, toError } from "./types.ts";
4
-
5
- const MAX_NAME_LENGTH = 64;
6
- const MAX_DESCRIPTION_LENGTH = 1024;
7
- const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
8
-
9
- type IgnoreMatcher = ReturnType<typeof ignore>;
10
-
11
- export type SkillDiagnosticCode =
12
- | "file_info_failed"
13
- | "list_failed"
14
- | "read_failed"
15
- | "parse_failed"
16
- | "invalid_metadata";
17
-
18
- /** Warning produced while loading skills. */
19
- export interface SkillDiagnostic {
20
- /** Diagnostic severity. Currently only warnings are emitted. */
21
- type: "warning";
22
- /** Stable diagnostic code. */
23
- code: SkillDiagnosticCode;
24
- /** Human-readable diagnostic message. */
25
- message: string;
26
- /** Path associated with the diagnostic. */
27
- path: string;
28
- }
29
-
30
- interface SkillFrontmatter {
31
- name?: string;
32
- description?: string;
33
- "disable-model-invocation"?: boolean;
34
- [key: string]: unknown;
35
- }
36
-
37
- /** Format a skill invocation prompt, optionally appending additional user instructions. */
38
- export function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string {
39
- const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\n\n${skill.content}\n</skill>`;
40
- return additionalInstructions ? `${skillBlock}\n\n${additionalInstructions}` : skillBlock;
41
- }
42
-
43
- /**
44
- * Load skills from one or more directories.
45
- *
46
- * Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files as skills, honors ignore files,
47
- * and returns diagnostics for invalid skill files. Missing input directories are skipped.
48
- */
49
- export async function loadSkills(
50
- env: ExecutionEnv,
51
- dirs: string | string[],
52
- ): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {
53
- const skills: Skill[] = [];
54
- const diagnostics: SkillDiagnostic[] = [];
55
- for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
56
- const rootInfoResult = await env.fileInfo(dir);
57
- if (!rootInfoResult.ok) {
58
- if (rootInfoResult.error.code !== "not_found") {
59
- diagnostics.push({
60
- type: "warning",
61
- code: "file_info_failed",
62
- message: rootInfoResult.error.message,
63
- path: dir,
64
- });
65
- }
66
- continue;
67
- }
68
- const rootInfo = rootInfoResult.value;
69
- if ((await resolveKind(env, rootInfo, diagnostics)) !== "directory") continue;
70
- const result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path);
71
- skills.push(...result.skills);
72
- diagnostics.push(...result.diagnostics);
73
- }
74
- return { skills, diagnostics };
75
- }
76
-
77
- /**
78
- * Load skills from source-tagged directories.
79
- *
80
- * Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not
81
- * interpret source values; applications define their own provenance shape.
82
- */
83
- export async function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(
84
- env: ExecutionEnv,
85
- inputs: Array<{ path: string; source: TSource }>,
86
- mapSkill?: (skill: Skill, source: TSource) => TSkill,
87
- ): Promise<{
88
- skills: Array<{ skill: TSkill; source: TSource }>;
89
- diagnostics: Array<SkillDiagnostic & { source: TSource }>;
90
- }> {
91
- const skills: Array<{ skill: TSkill; source: TSource }> = [];
92
- const diagnostics: Array<SkillDiagnostic & { source: TSource }> = [];
93
- for (const input of inputs) {
94
- const result = await loadSkills(env, input.path);
95
- for (const skill of result.skills) {
96
- skills.push({ skill: mapSkill ? mapSkill(skill, input.source) : (skill as TSkill), source: input.source });
97
- }
98
- for (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });
99
- }
100
- return { skills, diagnostics };
101
- }
102
-
103
- async function loadSkillsFromDirInternal(
104
- env: ExecutionEnv,
105
- dir: string,
106
- includeRootFiles: boolean,
107
- ignoreMatcher: IgnoreMatcher,
108
- rootDir: string,
109
- ): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {
110
- const skills: Skill[] = [];
111
- const diagnostics: SkillDiagnostic[] = [];
112
-
113
- const dirInfoResult = await env.fileInfo(dir);
114
- if (!dirInfoResult.ok) {
115
- if (dirInfoResult.error.code !== "not_found") {
116
- diagnostics.push({
117
- type: "warning",
118
- code: "file_info_failed",
119
- message: dirInfoResult.error.message,
120
- path: dir,
121
- });
122
- }
123
- return { skills, diagnostics };
124
- }
125
- const dirInfo = dirInfoResult.value;
126
- if ((await resolveKind(env, dirInfo, diagnostics)) !== "directory") return { skills, diagnostics };
127
-
128
- await addIgnoreRules(env, ignoreMatcher, dir, rootDir, diagnostics);
129
-
130
- const entriesResult = await env.listDir(dir);
131
- if (!entriesResult.ok) {
132
- diagnostics.push({ type: "warning", code: "list_failed", message: entriesResult.error.message, path: dir });
133
- return { skills, diagnostics };
134
- }
135
- const entries = entriesResult.value;
136
-
137
- for (const entry of entries) {
138
- if (entry.name !== "SKILL.md") continue;
139
- const fullPath = entry.path;
140
- const kind = await resolveKind(env, entry, diagnostics);
141
- if (kind !== "file") continue;
142
- const relPath = relativeEnvPath(rootDir, fullPath);
143
- if (ignoreMatcher.ignores(relPath)) continue;
144
-
145
- const result = await loadSkillFromFile(env, fullPath);
146
- if (result.skill) skills.push(result.skill);
147
- diagnostics.push(...result.diagnostics);
148
- return { skills, diagnostics };
149
- }
150
-
151
- for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
152
- if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
153
- const fullPath = entry.path;
154
- const kind = await resolveKind(env, entry, diagnostics);
155
- if (!kind) continue;
156
-
157
- const relPath = relativeEnvPath(rootDir, fullPath);
158
- const ignorePath = kind === "directory" ? `${relPath}/` : relPath;
159
- if (ignoreMatcher.ignores(ignorePath)) continue;
160
-
161
- if (kind === "directory") {
162
- const result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir);
163
- skills.push(...result.skills);
164
- diagnostics.push(...result.diagnostics);
165
- continue;
166
- }
167
-
168
- if (kind !== "file" || !includeRootFiles || !entry.name.endsWith(".md")) continue;
169
- const result = await loadSkillFromFile(env, fullPath);
170
- if (result.skill) skills.push(result.skill);
171
- diagnostics.push(...result.diagnostics);
172
- }
173
-
174
- return { skills, diagnostics };
175
- }
176
-
177
- async function addIgnoreRules(
178
- env: ExecutionEnv,
179
- ig: IgnoreMatcher,
180
- dir: string,
181
- rootDir: string,
182
- diagnostics: SkillDiagnostic[],
183
- ): Promise<void> {
184
- const relativeDir = relativeEnvPath(rootDir, dir);
185
- const prefix = relativeDir ? `${relativeDir}/` : "";
186
-
187
- for (const filename of IGNORE_FILE_NAMES) {
188
- const ignorePath = joinEnvPath(dir, filename);
189
- const info = await env.fileInfo(ignorePath);
190
- if (!info.ok) {
191
- if (info.error.code !== "not_found") {
192
- diagnostics.push({
193
- type: "warning",
194
- code: "file_info_failed",
195
- message: info.error.message,
196
- path: ignorePath,
197
- });
198
- }
199
- continue;
200
- }
201
- if (info.value.kind !== "file") continue;
202
- const content = await env.readTextFile(ignorePath);
203
- if (!content.ok) {
204
- diagnostics.push({ type: "warning", code: "read_failed", message: content.error.message, path: ignorePath });
205
- continue;
206
- }
207
- const patterns = content.value
208
- .split(/\r?\n/)
209
- .map((line) => prefixIgnorePattern(line, prefix))
210
- .filter((line): line is string => Boolean(line));
211
- if (patterns.length > 0) ig.add(patterns);
212
- }
213
- }
214
-
215
- function prefixIgnorePattern(line: string, prefix: string): string | null {
216
- const trimmed = line.trim();
217
- if (!trimmed) return null;
218
- if (trimmed.startsWith("#") && !trimmed.startsWith("\\#")) return null;
219
-
220
- let pattern = line;
221
- let negated = false;
222
- if (pattern.startsWith("!")) {
223
- negated = true;
224
- pattern = pattern.slice(1);
225
- } else if (pattern.startsWith("\\!")) {
226
- pattern = pattern.slice(1);
227
- }
228
- if (pattern.startsWith("/")) pattern = pattern.slice(1);
229
- const prefixed = prefix ? `${prefix}${pattern}` : pattern;
230
- return negated ? `!${prefixed}` : prefixed;
231
- }
232
-
233
- async function loadSkillFromFile(
234
- env: ExecutionEnv,
235
- filePath: string,
236
- ): Promise<{ skill: Skill | null; diagnostics: SkillDiagnostic[] }> {
237
- const diagnostics: SkillDiagnostic[] = [];
238
- const rawContent = await env.readTextFile(filePath);
239
- if (!rawContent.ok) {
240
- diagnostics.push({ type: "warning", code: "read_failed", message: rawContent.error.message, path: filePath });
241
- return { skill: null, diagnostics };
242
- }
243
-
244
- const parsed = parseFrontmatter<SkillFrontmatter>(rawContent.value);
245
- if (!parsed.ok) {
246
- diagnostics.push({ type: "warning", code: "parse_failed", message: parsed.error.message, path: filePath });
247
- return { skill: null, diagnostics };
248
- }
249
-
250
- const { frontmatter, body } = parsed.value;
251
- const skillDir = dirnameEnvPath(filePath);
252
- const parentDirName = basenameEnvPath(skillDir);
253
- const description = typeof frontmatter.description === "string" ? frontmatter.description : undefined;
254
-
255
- for (const error of validateDescription(description)) {
256
- diagnostics.push({ type: "warning", code: "invalid_metadata", message: error, path: filePath });
257
- }
258
-
259
- const frontmatterName = typeof frontmatter.name === "string" ? frontmatter.name : undefined;
260
- const name = frontmatterName || parentDirName;
261
- for (const error of validateName(name, parentDirName)) {
262
- diagnostics.push({ type: "warning", code: "invalid_metadata", message: error, path: filePath });
263
- }
264
-
265
- if (!description || description.trim() === "") {
266
- return { skill: null, diagnostics };
267
- }
268
-
269
- return {
270
- skill: {
271
- name,
272
- description,
273
- content: body,
274
- filePath,
275
- disableModelInvocation: frontmatter["disable-model-invocation"] === true,
276
- },
277
- diagnostics,
278
- };
279
- }
280
-
281
- function validateName(name: string, parentDirName: string): string[] {
282
- const errors: string[] = [];
283
- if (name !== parentDirName) errors.push(`name "${name}" does not match parent directory "${parentDirName}"`);
284
- if (name.length > MAX_NAME_LENGTH) errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
285
- if (!/^[a-z0-9-]+$/.test(name)) {
286
- errors.push("name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)");
287
- }
288
- if (name.startsWith("-") || name.endsWith("-")) errors.push("name must not start or end with a hyphen");
289
- if (name.includes("--")) errors.push("name must not contain consecutive hyphens");
290
- return errors;
291
- }
292
-
293
- function validateDescription(description: string | undefined): string[] {
294
- const errors: string[] = [];
295
- if (!description || description.trim() === "") {
296
- errors.push("description is required");
297
- } else if (description.length > MAX_DESCRIPTION_LENGTH) {
298
- errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
299
- }
300
- return errors;
301
- }
302
-
303
- function parseFrontmatter<T extends Record<string, unknown>>(
304
- content: string,
305
- ): Result<{ frontmatter: T; body: string }, Error> {
306
- try {
307
- const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
308
- if (!normalized.startsWith("---")) return { ok: true, value: { frontmatter: {} as T, body: normalized } };
309
- const endIndex = normalized.indexOf("\n---", 3);
310
- if (endIndex === -1) return { ok: true, value: { frontmatter: {} as T, body: normalized } };
311
- const yamlString = normalized.slice(4, endIndex);
312
- const body = normalized.slice(endIndex + 4).trim();
313
- return { ok: true, value: { frontmatter: (parse(yamlString) ?? {}) as T, body } };
314
- } catch (error) {
315
- return { ok: false, error: toError(error) };
316
- }
317
- }
318
-
319
- async function resolveKind(
320
- env: ExecutionEnv,
321
- info: FileInfo,
322
- diagnostics: SkillDiagnostic[],
323
- ): Promise<"file" | "directory" | undefined> {
324
- if (info.kind === "file" || info.kind === "directory") return info.kind;
325
- const canonicalPath = await env.canonicalPath(info.path);
326
- if (!canonicalPath.ok) {
327
- if (canonicalPath.error.code !== "not_found") {
328
- diagnostics.push({
329
- type: "warning",
330
- code: "file_info_failed",
331
- message: canonicalPath.error.message,
332
- path: info.path,
333
- });
334
- }
335
- return undefined;
336
- }
337
- const target = await env.fileInfo(canonicalPath.value);
338
- if (!target.ok) {
339
- if (target.error.code !== "not_found") {
340
- diagnostics.push({
341
- type: "warning",
342
- code: "file_info_failed",
343
- message: target.error.message,
344
- path: info.path,
345
- });
346
- }
347
- return undefined;
348
- }
349
- return target.value.kind === "file" || target.value.kind === "directory" ? target.value.kind : undefined;
350
- }
351
-
352
- function joinEnvPath(base: string, child: string): string {
353
- return `${base.replace(/\/+$/, "")}/${child.replace(/^\/+/, "")}`;
354
- }
355
-
356
- function dirnameEnvPath(path: string): string {
357
- const normalized = path.replace(/\/+$/, "");
358
- const slashIndex = normalized.lastIndexOf("/");
359
- return slashIndex <= 0 ? "/" : normalized.slice(0, slashIndex);
360
- }
361
-
362
- function basenameEnvPath(path: string): string {
363
- const normalized = path.replace(/\/+$/, "");
364
- const slashIndex = normalized.lastIndexOf("/");
365
- return slashIndex === -1 ? normalized : normalized.slice(slashIndex + 1);
366
- }
367
-
368
- function relativeEnvPath(root: string, path: string): string {
369
- const normalizedRoot = root.replace(/\/+$/, "");
370
- const normalizedPath = path.replace(/\/+$/, "");
371
- if (normalizedPath === normalizedRoot) return "";
372
- return normalizedPath.startsWith(`${normalizedRoot}/`)
373
- ? normalizedPath.slice(normalizedRoot.length + 1)
374
- : normalizedPath.replace(/^\/+/, "");
375
- }
@@ -1,34 +0,0 @@
1
- import type { Skill } from "./types.ts";
2
-
3
- export function formatSkillsForSystemPrompt(skills: Skill[]): string {
4
- const visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);
5
- if (visibleSkills.length === 0) return "";
6
-
7
- const lines = [
8
- "The following skills provide specialized instructions for specific tasks.",
9
- "Read the full skill file when the task matches its description.",
10
- "When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
11
- "",
12
- "<available_skills>",
13
- ];
14
-
15
- for (const skill of visibleSkills) {
16
- lines.push(" <skill>");
17
- lines.push(` <name>${escapeXml(skill.name)}</name>`);
18
- lines.push(` <description>${escapeXml(skill.description)}</description>`);
19
- lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
20
- lines.push(" </skill>");
21
- }
22
-
23
- lines.push("</available_skills>");
24
- return lines.join("\n");
25
- }
26
-
27
- function escapeXml(value: string): string {
28
- return value
29
- .replace(/&/g, "&amp;")
30
- .replace(/</g, "&lt;")
31
- .replace(/>/g, "&gt;")
32
- .replace(/"/g, "&quot;")
33
- .replace(/'/g, "&apos;");
34
- }