harnesstap 1.2.0 → 1.3.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.
Files changed (202) hide show
  1. package/README.md +28 -15
  2. package/dist/apply-QSS4242W.js +67 -0
  3. package/dist/apply-QSS4242W.js.map +1 -0
  4. package/dist/approve-CNYQY6DC.js +181 -0
  5. package/dist/approve-CNYQY6DC.js.map +1 -0
  6. package/dist/audit-V4SUV7KA.js +434 -0
  7. package/dist/audit-V4SUV7KA.js.map +1 -0
  8. package/dist/auth-63FOHIQ3.js +220 -0
  9. package/dist/auth-63FOHIQ3.js.map +1 -0
  10. package/dist/bin.js +166 -0
  11. package/dist/bin.js.map +1 -0
  12. package/dist/chunk-2H7UOFLK.js +11 -0
  13. package/dist/chunk-2H7UOFLK.js.map +1 -0
  14. package/dist/chunk-2NE3QYMP.js +103 -0
  15. package/dist/chunk-2NE3QYMP.js.map +1 -0
  16. package/dist/chunk-2P2EOYEW.js +1140 -0
  17. package/dist/chunk-2P2EOYEW.js.map +1 -0
  18. package/dist/chunk-37E5M4JX.js +34 -0
  19. package/dist/chunk-37E5M4JX.js.map +1 -0
  20. package/dist/chunk-37LQQWMF.js +496 -0
  21. package/dist/chunk-37LQQWMF.js.map +1 -0
  22. package/dist/chunk-3FIWOI3H.js +98 -0
  23. package/dist/chunk-3FIWOI3H.js.map +1 -0
  24. package/dist/chunk-3PGC6OA3.js +540 -0
  25. package/dist/chunk-3PGC6OA3.js.map +1 -0
  26. package/dist/chunk-4IHKBIY3.js +118 -0
  27. package/dist/chunk-4IHKBIY3.js.map +1 -0
  28. package/dist/chunk-4ZUBRLSP.js +17 -0
  29. package/dist/chunk-4ZUBRLSP.js.map +1 -0
  30. package/dist/chunk-5F3LNDZG.js +9 -0
  31. package/dist/chunk-5F3LNDZG.js.map +1 -0
  32. package/dist/chunk-5TXI6BI2.js +1359 -0
  33. package/dist/chunk-5TXI6BI2.js.map +1 -0
  34. package/dist/chunk-6P5IO4BX.js +235 -0
  35. package/dist/chunk-6P5IO4BX.js.map +1 -0
  36. package/dist/chunk-ABXUKHAU.js +571 -0
  37. package/dist/chunk-ABXUKHAU.js.map +1 -0
  38. package/dist/chunk-AOUDSNRK.js +1357 -0
  39. package/dist/chunk-AOUDSNRK.js.map +1 -0
  40. package/dist/chunk-BNDJJAEI.js +311 -0
  41. package/dist/chunk-BNDJJAEI.js.map +1 -0
  42. package/dist/chunk-C2IWSFF5.js +818 -0
  43. package/dist/chunk-C2IWSFF5.js.map +1 -0
  44. package/dist/chunk-CHQGE2HF.js +283 -0
  45. package/dist/chunk-CHQGE2HF.js.map +1 -0
  46. package/dist/chunk-DEJLP7QJ.js +681 -0
  47. package/dist/chunk-DEJLP7QJ.js.map +1 -0
  48. package/dist/chunk-DJ6FN6EW.js +532 -0
  49. package/dist/chunk-DJ6FN6EW.js.map +1 -0
  50. package/dist/chunk-E4WRTRMH.js +1173 -0
  51. package/dist/chunk-E4WRTRMH.js.map +1 -0
  52. package/dist/chunk-E5QXNU3K.js +238 -0
  53. package/dist/chunk-E5QXNU3K.js.map +1 -0
  54. package/dist/chunk-EMTBGOR3.js +2959 -0
  55. package/dist/chunk-EMTBGOR3.js.map +1 -0
  56. package/dist/chunk-FFWYIGQ4.js +18 -0
  57. package/dist/chunk-FFWYIGQ4.js.map +1 -0
  58. package/dist/chunk-I6XFZLTJ.js +9 -0
  59. package/dist/chunk-I6XFZLTJ.js.map +1 -0
  60. package/dist/chunk-IHWAOIAU.js +172 -0
  61. package/dist/chunk-IHWAOIAU.js.map +1 -0
  62. package/dist/chunk-IHZUYG66.js +583 -0
  63. package/dist/chunk-IHZUYG66.js.map +1 -0
  64. package/dist/chunk-JQOKQKQT.js +158 -0
  65. package/dist/chunk-JQOKQKQT.js.map +1 -0
  66. package/dist/chunk-JRFUTIEH.js +426 -0
  67. package/dist/chunk-JRFUTIEH.js.map +1 -0
  68. package/dist/chunk-KCBI6JQC.js +115 -0
  69. package/dist/chunk-KCBI6JQC.js.map +1 -0
  70. package/dist/chunk-KDUQMINL.js +60 -0
  71. package/dist/chunk-KDUQMINL.js.map +1 -0
  72. package/dist/chunk-KLR2DURP.js +656 -0
  73. package/dist/chunk-KLR2DURP.js.map +1 -0
  74. package/dist/chunk-KRI4R7EM.js +25 -0
  75. package/dist/chunk-KRI4R7EM.js.map +1 -0
  76. package/dist/chunk-LYQMK6SV.js +87 -0
  77. package/dist/chunk-LYQMK6SV.js.map +1 -0
  78. package/dist/chunk-MK3Q37ZN.js +183 -0
  79. package/dist/chunk-MK3Q37ZN.js.map +1 -0
  80. package/dist/chunk-MSGAGV7B.js +346 -0
  81. package/dist/chunk-MSGAGV7B.js.map +1 -0
  82. package/dist/chunk-MZQRSERO.js +430 -0
  83. package/dist/chunk-MZQRSERO.js.map +1 -0
  84. package/dist/chunk-N3WIJXXM.js +691 -0
  85. package/dist/chunk-N3WIJXXM.js.map +1 -0
  86. package/dist/chunk-NAGAJ5UM.js +145 -0
  87. package/dist/chunk-NAGAJ5UM.js.map +1 -0
  88. package/dist/chunk-NFYPBTKO.js +302 -0
  89. package/dist/chunk-NFYPBTKO.js.map +1 -0
  90. package/dist/chunk-NPO2IG6G.js +491 -0
  91. package/dist/chunk-NPO2IG6G.js.map +1 -0
  92. package/dist/chunk-OS6NUIBJ.js +38 -0
  93. package/dist/chunk-OS6NUIBJ.js.map +1 -0
  94. package/dist/chunk-PFUK3HJ4.js +296 -0
  95. package/dist/chunk-PFUK3HJ4.js.map +1 -0
  96. package/dist/chunk-PMQ55GDB.js +115 -0
  97. package/dist/chunk-PMQ55GDB.js.map +1 -0
  98. package/dist/chunk-QIVE2YFJ.js +514 -0
  99. package/dist/chunk-QIVE2YFJ.js.map +1 -0
  100. package/dist/chunk-QKXD3EUF.js +691 -0
  101. package/dist/chunk-QKXD3EUF.js.map +1 -0
  102. package/dist/chunk-RNQYUWF6.js +32 -0
  103. package/dist/chunk-RNQYUWF6.js.map +1 -0
  104. package/dist/chunk-S2E4SSQV.js +41 -0
  105. package/dist/chunk-S2E4SSQV.js.map +1 -0
  106. package/dist/chunk-SN4BXX3B.js +186 -0
  107. package/dist/chunk-SN4BXX3B.js.map +1 -0
  108. package/dist/chunk-SNVAMWB7.js +40 -0
  109. package/dist/chunk-SNVAMWB7.js.map +1 -0
  110. package/dist/chunk-T5VRREN4.js +696 -0
  111. package/dist/chunk-T5VRREN4.js.map +1 -0
  112. package/dist/chunk-TKBMHZTS.js +10945 -0
  113. package/dist/chunk-TKBMHZTS.js.map +1 -0
  114. package/dist/chunk-TNJPTUE4.js +35 -0
  115. package/dist/chunk-TNJPTUE4.js.map +1 -0
  116. package/dist/chunk-TQ2NA4Z4.js +24 -0
  117. package/dist/chunk-TQ2NA4Z4.js.map +1 -0
  118. package/dist/chunk-TXXDMDPN.js +998 -0
  119. package/dist/chunk-TXXDMDPN.js.map +1 -0
  120. package/dist/chunk-UWXUBU7V.js +184 -0
  121. package/dist/chunk-UWXUBU7V.js.map +1 -0
  122. package/dist/chunk-UYRK2H24.js +141 -0
  123. package/dist/chunk-UYRK2H24.js.map +1 -0
  124. package/dist/chunk-V4IXIM3C.js +806 -0
  125. package/dist/chunk-V4IXIM3C.js.map +1 -0
  126. package/dist/chunk-VFHVXXP4.js +6438 -0
  127. package/dist/chunk-VFHVXXP4.js.map +1 -0
  128. package/dist/chunk-VQVUJYYY.js +244 -0
  129. package/dist/chunk-VQVUJYYY.js.map +1 -0
  130. package/dist/chunk-VZQG2JDV.js +9 -0
  131. package/dist/chunk-VZQG2JDV.js.map +1 -0
  132. package/dist/chunk-W7HQ5X3S.js +610 -0
  133. package/dist/chunk-W7HQ5X3S.js.map +1 -0
  134. package/dist/chunk-WMSQAFK5.js +65 -0
  135. package/dist/chunk-WMSQAFK5.js.map +1 -0
  136. package/dist/chunk-WMYTBJPB.js +364 -0
  137. package/dist/chunk-WMYTBJPB.js.map +1 -0
  138. package/dist/chunk-WNLFNCOH.js +7795 -0
  139. package/dist/chunk-WNLFNCOH.js.map +1 -0
  140. package/dist/chunk-WRX7CB2M.js +6448 -0
  141. package/dist/chunk-WRX7CB2M.js.map +1 -0
  142. package/dist/chunk-XGTTOO4R.js +84 -0
  143. package/dist/chunk-XGTTOO4R.js.map +1 -0
  144. package/dist/chunk-YSXRBUR4.js +682 -0
  145. package/dist/chunk-YSXRBUR4.js.map +1 -0
  146. package/dist/chunk-YTC2EG64.js +1759 -0
  147. package/dist/chunk-YTC2EG64.js.map +1 -0
  148. package/dist/compile-J3UGQSS3.js +161 -0
  149. package/dist/compile-J3UGQSS3.js.map +1 -0
  150. package/dist/config-5BPSZND3.js +438 -0
  151. package/dist/config-5BPSZND3.js.map +1 -0
  152. package/dist/doctor-BVFKLJVO.js +111 -0
  153. package/dist/doctor-BVFKLJVO.js.map +1 -0
  154. package/dist/environment-3RI5H32O.js +2745 -0
  155. package/dist/environment-3RI5H32O.js.map +1 -0
  156. package/dist/github-YFJQVH5K.js +114 -0
  157. package/dist/github-YFJQVH5K.js.map +1 -0
  158. package/dist/harness-ECGHPEKA.js +746 -0
  159. package/dist/harness-ECGHPEKA.js.map +1 -0
  160. package/dist/help-ELPNPPEM.js +2079 -0
  161. package/dist/help-ELPNPPEM.js.map +1 -0
  162. package/dist/help-UL5XLY3I.js +1892 -0
  163. package/dist/help-UL5XLY3I.js.map +1 -0
  164. package/dist/index.d.ts +164 -1
  165. package/dist/index.js +50 -59246
  166. package/dist/index.js.map +1 -1
  167. package/dist/init-UJQTDHW7.js +873 -0
  168. package/dist/init-UJQTDHW7.js.map +1 -0
  169. package/dist/lock-XUMJ63NZ.js +455 -0
  170. package/dist/lock-XUMJ63NZ.js.map +1 -0
  171. package/dist/marketplace-ZUMOLVXE.js +495 -0
  172. package/dist/marketplace-ZUMOLVXE.js.map +1 -0
  173. package/dist/mcp-RZA5O2ND.js +202 -0
  174. package/dist/mcp-RZA5O2ND.js.map +1 -0
  175. package/dist/migrate-CYQI2FH6.js +1043 -0
  176. package/dist/migrate-CYQI2FH6.js.map +1 -0
  177. package/dist/open-AWOAWLKO.js +32 -0
  178. package/dist/open-AWOAWLKO.js.map +1 -0
  179. package/dist/pack-2QD5ZUIO.js +99 -0
  180. package/dist/pack-2QD5ZUIO.js.map +1 -0
  181. package/dist/plugin-GQSSSFX4.js +64 -0
  182. package/dist/plugin-GQSSSFX4.js.map +1 -0
  183. package/dist/plugin-from-project-SIQUFYIO.js +16 -0
  184. package/dist/plugin-from-project-SIQUFYIO.js.map +1 -0
  185. package/dist/policy-CT4JRCJI.js +105 -0
  186. package/dist/policy-CT4JRCJI.js.map +1 -0
  187. package/dist/profile-4JQ6LECP.js +1886 -0
  188. package/dist/profile-4JQ6LECP.js.map +1 -0
  189. package/dist/project-JG7QWXRG.js +1392 -0
  190. package/dist/project-JG7QWXRG.js.map +1 -0
  191. package/dist/resource-QRMR6CSD.js +555 -0
  192. package/dist/resource-QRMR6CSD.js.map +1 -0
  193. package/dist/version-LZ5POOXY.js +17 -0
  194. package/dist/version-LZ5POOXY.js.map +1 -0
  195. package/package.json +21 -14
  196. package/schemas/ap-package.v1.json +36 -0
  197. package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
  198. package/schemas/fixtures/confidence.ap.json +13 -0
  199. package/schemas/fixtures/context7.ap.json +13 -0
  200. package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
  201. package/schemas/fixtures/superpowers.ap.json +13 -0
  202. package/schemas/fixtures/third-party-skills.ap.json +13 -0
@@ -0,0 +1,1173 @@
1
+ import {
2
+ canonicalApmRepoUrl
3
+ } from "./chunk-DEJLP7QJ.js";
4
+ import {
5
+ BundleSymlinkError,
6
+ assertContainedPath,
7
+ getPluginById,
8
+ listContainedRegularFiles,
9
+ parseHooksJsonContent,
10
+ recoverOriginLocator,
11
+ resolutionKey,
12
+ skillMetadataFromDir
13
+ } from "./chunk-TKBMHZTS.js";
14
+ import {
15
+ formatCount
16
+ } from "./chunk-ABXUKHAU.js";
17
+
18
+ // src/services/apm-policy.ts
19
+ import { createHash } from "crypto";
20
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
21
+ import { isAbsolute, join as join2, relative, resolve } from "path";
22
+ import picomatch from "picomatch";
23
+ import { parse as parseYaml } from "yaml";
24
+
25
+ // src/services/apm-overlay.ts
26
+ import { existsSync, lstatSync, readFileSync, readdirSync } from "fs";
27
+ import { join } from "path";
28
+ import matter from "gray-matter";
29
+ var APM_NATIVE_PRIMITIVE_DIRS = ["agents", "skills", "commands", "hooks"];
30
+ var APM_APPLY_PRIMITIVE_DIRS = [
31
+ ...APM_NATIVE_PRIMITIVE_DIRS,
32
+ "instructions",
33
+ "prompts"
34
+ ];
35
+ var APM_WARN_ONLY_DIRS = ["chatmodes", "mcp"];
36
+ function isRecord(value) {
37
+ return value !== null && typeof value === "object" && !Array.isArray(value);
38
+ }
39
+ function isDirectory(path) {
40
+ try {
41
+ return existsSync(path) && lstatSync(path).isDirectory() && !lstatSync(path).isSymbolicLink();
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+ function skippedRootSourceWarning(dir) {
47
+ return `Skipping root-level ${dir}/ because .apm/ is present. Move publishable files to .apm/${dir}/ or remove ${dir}/ to silence this warning.`;
48
+ }
49
+ function matchesExclude(relativePath, patterns) {
50
+ return patterns.some((pattern) => {
51
+ const normalized = pattern.replace(/^\.\//, "").replace(/\\/g, "/");
52
+ if (normalized.endsWith("/**")) {
53
+ const prefix = normalized.slice(0, -3);
54
+ return relativePath === prefix || relativePath.startsWith(`${prefix}/`);
55
+ }
56
+ if (normalized.endsWith("/*")) {
57
+ const prefix = normalized.slice(0, -2);
58
+ if (!relativePath.startsWith(`${prefix}/`)) return false;
59
+ return !relativePath.slice(prefix.length + 1).includes("/");
60
+ }
61
+ return relativePath === normalized || relativePath.startsWith(`${normalized}/`);
62
+ });
63
+ }
64
+ function listSourceFiles(projectRoot, sourceRelative, exclude) {
65
+ const absolute = join(projectRoot, sourceRelative);
66
+ if (!existsSync(absolute)) {
67
+ return [];
68
+ }
69
+ if (lstatSync(absolute).isSymbolicLink()) {
70
+ throw new BundleSymlinkError(sourceRelative);
71
+ }
72
+ if (!lstatSync(absolute).isDirectory()) {
73
+ return [];
74
+ }
75
+ return listContainedRegularFiles(absolute).filter((child) => !child.split("/").some((segment) => segment.startsWith("."))).map((child) => `${sourceRelative}/${child}`).filter((relativePath) => !matchesExclude(relativePath, exclude));
76
+ }
77
+ function nativeBasename(relativePath) {
78
+ const base = relativePath.split("/").pop() ?? relativePath;
79
+ return base.replace(/\.(agent|prompt|instructions)\.md$/i, "").replace(/\.md$/i, "");
80
+ }
81
+ function sourceDir(prefix, dir) {
82
+ return prefix ? `${prefix}/${dir}` : dir;
83
+ }
84
+ function parseMarkdown(projectRoot, relativePath) {
85
+ const raw = readFileSync(join(projectRoot, relativePath), "utf-8");
86
+ const parsed = matter(raw);
87
+ return {
88
+ data: isRecord(parsed.data) ? { ...parsed.data } : {},
89
+ content: parsed.content
90
+ };
91
+ }
92
+ function applyToGlobs(data) {
93
+ const raw = data.applyTo ?? data.apply_to;
94
+ if (typeof raw === "string" && raw.trim()) {
95
+ return [raw.trim()];
96
+ }
97
+ if (Array.isArray(raw)) {
98
+ return raw.filter((entry) => typeof entry === "string" && entry.trim().length > 0).map((entry) => entry.trim());
99
+ }
100
+ return [];
101
+ }
102
+ function skillFromPath(projectRoot, skillMdRelative) {
103
+ const { data, content } = parseMarkdown(projectRoot, skillMdRelative);
104
+ const skillDirRelative = skillMdRelative.replace(/\/SKILL\.md$/i, "");
105
+ const dirName = skillDirRelative.split("/").pop() ?? "skill";
106
+ const metadata = skillMetadataFromDir(
107
+ join(projectRoot, skillDirRelative)
108
+ );
109
+ return {
110
+ name: typeof data.name === "string" && data.name.trim() ? data.name.trim() : dirName,
111
+ description: typeof data.description === "string" ? data.description : "",
112
+ content: content.trim(),
113
+ skillDirRelative,
114
+ skillMdRelative,
115
+ metadata
116
+ };
117
+ }
118
+ function markdownPrimitive(type, projectRoot, relativePath) {
119
+ const { data, content } = parseMarkdown(projectRoot, relativePath);
120
+ const name = typeof data.name === "string" && data.name.trim() ? data.name.trim() : nativeBasename(relativePath);
121
+ const description = typeof data.description === "string" ? data.description : "";
122
+ delete data.name;
123
+ delete data.description;
124
+ delete data.applyTo;
125
+ delete data.apply_to;
126
+ return {
127
+ type,
128
+ name,
129
+ description,
130
+ content: content.trim(),
131
+ metadata: data,
132
+ sourceRelative: relativePath
133
+ };
134
+ }
135
+ function collectSkills(projectRoot, skillsPrefix, exclude) {
136
+ const files = listSourceFiles(projectRoot, skillsPrefix, exclude);
137
+ const skills = [];
138
+ const seen = /* @__PURE__ */ new Set();
139
+ for (const relativePath of files) {
140
+ if (!relativePath.endsWith("/SKILL.md") && relativePath !== `${skillsPrefix}/SKILL.md`) {
141
+ continue;
142
+ }
143
+ const skill = skillFromPath(projectRoot, relativePath);
144
+ if (seen.has(skill.name)) continue;
145
+ seen.add(skill.name);
146
+ skills.push(skill);
147
+ }
148
+ return skills;
149
+ }
150
+ function collectMarkdownDir(type, projectRoot, dirRelative, exclude) {
151
+ const files = listSourceFiles(projectRoot, dirRelative, exclude);
152
+ const primitives = [];
153
+ const seen = /* @__PURE__ */ new Set();
154
+ for (const relativePath of files) {
155
+ if (!relativePath.endsWith(".md")) continue;
156
+ const primitive = markdownPrimitive(type, projectRoot, relativePath);
157
+ const key = `${primitive.type}:${primitive.name}`;
158
+ if (seen.has(key)) continue;
159
+ seen.add(key);
160
+ primitives.push(primitive);
161
+ }
162
+ return primitives;
163
+ }
164
+ function collectInstructions(projectRoot, dirRelative, exclude) {
165
+ const files = listSourceFiles(projectRoot, dirRelative, exclude);
166
+ const primitives = [];
167
+ const seen = /* @__PURE__ */ new Set();
168
+ for (const relativePath of files) {
169
+ if (!relativePath.endsWith(".md")) continue;
170
+ const { data, content } = parseMarkdown(projectRoot, relativePath);
171
+ const name = typeof data.name === "string" && data.name.trim() ? data.name.trim() : nativeBasename(relativePath);
172
+ const description = typeof data.description === "string" ? data.description : "";
173
+ const globs = applyToGlobs(data);
174
+ const key = globs.length > 0 ? `rule:${name}` : `instruction:${name}`;
175
+ if (seen.has(key)) continue;
176
+ seen.add(key);
177
+ if (globs.length > 0) {
178
+ const metadata = { globs, always_apply: false };
179
+ primitives.push({
180
+ type: "rule",
181
+ name,
182
+ description,
183
+ content: content.trim(),
184
+ metadata,
185
+ sourceRelative: relativePath
186
+ });
187
+ continue;
188
+ }
189
+ primitives.push({
190
+ type: "instruction",
191
+ name,
192
+ description,
193
+ content: content.trim(),
194
+ metadata: {},
195
+ sourceRelative: relativePath
196
+ });
197
+ }
198
+ return primitives;
199
+ }
200
+ function collectHooks(projectRoot, dirRelative, exclude) {
201
+ const files = listSourceFiles(projectRoot, dirRelative, exclude);
202
+ const primitives = [];
203
+ const seen = /* @__PURE__ */ new Set();
204
+ for (const relativePath of files) {
205
+ if (!relativePath.endsWith(".json")) continue;
206
+ const raw = readFileSync(join(projectRoot, relativePath), "utf-8");
207
+ const parsed = parseHooksJsonContent(raw, relativePath);
208
+ if (parsed.length > 0) {
209
+ for (const resource of parsed) {
210
+ const key2 = `hook:${resource.name}`;
211
+ if (seen.has(key2)) continue;
212
+ seen.add(key2);
213
+ primitives.push({
214
+ type: "hook",
215
+ name: resource.name,
216
+ description: resource.description,
217
+ content: resource.content,
218
+ metadata: isRecord(resource.metadata) ? { ...resource.metadata } : {},
219
+ sourceRelative: relativePath
220
+ });
221
+ }
222
+ continue;
223
+ }
224
+ const name = relativePath.replace(/^.*\//, "").replace(/\.json$/i, "").replaceAll("/", "-") || "hook";
225
+ const key = `hook:${name}`;
226
+ if (seen.has(key)) continue;
227
+ seen.add(key);
228
+ primitives.push({
229
+ type: "hook",
230
+ name,
231
+ description: "",
232
+ content: raw,
233
+ metadata: {},
234
+ sourceRelative: relativePath
235
+ });
236
+ }
237
+ return primitives;
238
+ }
239
+ function collectFromPrefix(projectRoot, prefix, exclude, includeInstructionsAndPrompts) {
240
+ const skills = collectSkills(projectRoot, sourceDir(prefix, "skills"), exclude);
241
+ const primitives = skills.map((skill) => ({
242
+ type: "skill",
243
+ name: skill.name,
244
+ description: skill.description,
245
+ content: skill.content,
246
+ metadata: { ...skill.metadata },
247
+ sourceRelative: skill.skillMdRelative
248
+ }));
249
+ primitives.push(
250
+ ...collectMarkdownDir("agent", projectRoot, sourceDir(prefix, "agents"), exclude)
251
+ );
252
+ primitives.push(
253
+ ...collectMarkdownDir("command", projectRoot, sourceDir(prefix, "commands"), exclude)
254
+ );
255
+ primitives.push(
256
+ ...collectHooks(projectRoot, sourceDir(prefix, "hooks"), exclude)
257
+ );
258
+ if (includeInstructionsAndPrompts) {
259
+ primitives.push(
260
+ ...collectInstructions(projectRoot, sourceDir(prefix, "instructions"), exclude)
261
+ );
262
+ primitives.push(
263
+ ...collectMarkdownDir("command", projectRoot, sourceDir(prefix, "prompts"), exclude)
264
+ );
265
+ }
266
+ const seen = /* @__PURE__ */ new Set();
267
+ const unique = [];
268
+ for (const primitive of primitives) {
269
+ const key = `${primitive.type}:${primitive.name}`;
270
+ if (seen.has(key)) continue;
271
+ seen.add(key);
272
+ unique.push(primitive);
273
+ }
274
+ return { skills, primitives: unique };
275
+ }
276
+ function collectSkillMdFiles(rootPath, skillsDirRelative) {
277
+ return collectSkills(rootPath, skillsDirRelative.split("\\").join("/"), []);
278
+ }
279
+ function inspectApmOverlay(rootPath, options = {}) {
280
+ const exclude = options.exclude ?? [];
281
+ const apmDir = join(rootPath, ".apm");
282
+ const apmPresent = existsSync(apmDir);
283
+ const warnings = [];
284
+ const skippedKinds = [];
285
+ const skippedRootDirs = [];
286
+ if (apmPresent) {
287
+ if (lstatSync(apmDir).isSymbolicLink()) {
288
+ throw new BundleSymlinkError(".apm");
289
+ }
290
+ const collected2 = collectFromPrefix(rootPath, ".apm", exclude, true);
291
+ for (const dir of APM_NATIVE_PRIMITIVE_DIRS) {
292
+ if (existsSync(join(rootPath, dir))) {
293
+ skippedRootDirs.push(dir);
294
+ warnings.push(skippedRootSourceWarning(dir));
295
+ }
296
+ }
297
+ for (const dir of APM_WARN_ONLY_DIRS) {
298
+ if (isDirectory(join(apmDir, dir))) {
299
+ skippedKinds.push(`.apm/${dir}`);
300
+ warnings.push(
301
+ `Local .apm/${dir} primitives are present but not applied; MCP comes from apm.yml and chatmodes are not a HarnessTap resource type`
302
+ );
303
+ }
304
+ }
305
+ if (collected2.primitives.length === 0 && skippedKinds.length === 0) {
306
+ const hasApplyDir = APM_APPLY_PRIMITIVE_DIRS.some((dir) => isDirectory(join(apmDir, dir)));
307
+ if (!hasApplyDir && readdirSync(apmDir).filter((entry) => !entry.startsWith(".")).length === 0) {
308
+ warnings.push("Local .apm/ directory is present but contains no primitives to apply");
309
+ } else if (collected2.primitives.length === 0) {
310
+ warnings.push("Local .apm/ directory is present but contains no applyable primitives");
311
+ }
312
+ }
313
+ return {
314
+ present: true,
315
+ fromApm: true,
316
+ skills: collected2.skills,
317
+ primitives: collected2.primitives,
318
+ skippedKinds,
319
+ skippedRootDirs,
320
+ warnings
321
+ };
322
+ }
323
+ const rootHasNative = APM_NATIVE_PRIMITIVE_DIRS.some((dir) => existsSync(join(rootPath, dir)));
324
+ if (!rootHasNative) {
325
+ return void 0;
326
+ }
327
+ const collected = collectFromPrefix(rootPath, "", exclude, false);
328
+ return {
329
+ present: false,
330
+ fromApm: false,
331
+ skills: collected.skills,
332
+ primitives: collected.primitives,
333
+ skippedKinds,
334
+ skippedRootDirs,
335
+ warnings
336
+ };
337
+ }
338
+
339
+ // src/services/apm-policy.ts
340
+ var APM_POLICY_FILENAME = "apm-policy.yml";
341
+ var POLICY_HASH_ALGORITHMS = ["sha256", "sha384", "sha512"];
342
+ var POLICY_ENFORCEMENTS = ["off", "warn", "block"];
343
+ var POLICY_FETCH_FAILURES = ["warn", "block"];
344
+ var PolicyError = class extends Error {
345
+ violations;
346
+ constructor(message, violations = []) {
347
+ super(message);
348
+ this.name = "PolicyError";
349
+ this.violations = violations;
350
+ }
351
+ };
352
+ function isRecord2(value) {
353
+ return value !== null && typeof value === "object" && !Array.isArray(value);
354
+ }
355
+ function isVendorExtensionKey(key) {
356
+ return /^x-[a-z][a-z0-9-]*$/.test(key);
357
+ }
358
+ function stringList(value, field) {
359
+ if (value === void 0 || value === null) {
360
+ return null;
361
+ }
362
+ if (!Array.isArray(value)) {
363
+ throw new PolicyError(`${field} must be a list or null`);
364
+ }
365
+ return value.map((entry, index) => {
366
+ if (typeof entry !== "string" || entry.trim().length === 0) {
367
+ throw new PolicyError(`${field}[${index}] must be a non-empty string`);
368
+ }
369
+ return entry.trim();
370
+ });
371
+ }
372
+ function parseEnum(value, allowed, field, fallback) {
373
+ if (value === void 0 || value === null || value === "") {
374
+ return fallback;
375
+ }
376
+ if (typeof value !== "string" || !allowed.includes(value)) {
377
+ throw new PolicyError(`${field} must be one of: ${allowed.join(", ")}`);
378
+ }
379
+ return value;
380
+ }
381
+ var KNOWN_TOP_LEVEL = /* @__PURE__ */ new Set([
382
+ "name",
383
+ "version",
384
+ "extends",
385
+ "enforcement",
386
+ "fetch_failure",
387
+ "cache",
388
+ "dependencies",
389
+ "mcp",
390
+ "compilation",
391
+ "manifest",
392
+ "unmanaged_files",
393
+ "security",
394
+ "registry_source",
395
+ "executables",
396
+ "bin_deploy",
397
+ "discovery"
398
+ ]);
399
+ function parsePolicyHashAlgorithm(hash, explicit) {
400
+ if (explicit !== void 0 && explicit !== null && explicit !== "") {
401
+ if (typeof explicit !== "string") {
402
+ throw new PolicyError("policy.hash_algorithm must be a string");
403
+ }
404
+ const lowered = explicit.toLowerCase();
405
+ if (lowered === "md5" || lowered === "sha1") {
406
+ throw new PolicyError("policy.hash_algorithm must be sha256, sha384, or sha512");
407
+ }
408
+ if (!POLICY_HASH_ALGORITHMS.includes(lowered)) {
409
+ throw new PolicyError("policy.hash_algorithm must be sha256, sha384, or sha512");
410
+ }
411
+ return lowered;
412
+ }
413
+ const prefix = hash.split(":")[0]?.toLowerCase();
414
+ if (prefix && POLICY_HASH_ALGORITHMS.includes(prefix)) {
415
+ return prefix;
416
+ }
417
+ throw new PolicyError(
418
+ "policy.hash must include a sha256:, sha384:, or sha512: prefix, or set policy.hash_algorithm"
419
+ );
420
+ }
421
+ function parseApmPolicyPin(value) {
422
+ if (value === void 0 || value === null) {
423
+ return void 0;
424
+ }
425
+ if (!isRecord2(value)) {
426
+ throw new PolicyError("apm.yml policy must be a mapping");
427
+ }
428
+ if (typeof value.hash !== "string" || value.hash.trim().length === 0) {
429
+ return void 0;
430
+ }
431
+ const hash = value.hash.trim();
432
+ const algorithm = parsePolicyHashAlgorithm(hash, value.hash_algorithm);
433
+ return { hash, algorithm };
434
+ }
435
+ function hashPolicyBytes(bytes, algorithm) {
436
+ return `${algorithm}:${createHash(algorithm).update(bytes).digest("hex")}`;
437
+ }
438
+ function policyHashesMatch(expected, actual) {
439
+ return expected.trim().toLowerCase() === actual.trim().toLowerCase();
440
+ }
441
+ function normalizeContentType(value) {
442
+ const key = value.trim().toLowerCase();
443
+ switch (key) {
444
+ case "skill":
445
+ case "skills":
446
+ return "skill";
447
+ case "agent":
448
+ case "agents":
449
+ return "agent";
450
+ case "command":
451
+ case "commands":
452
+ case "prompt":
453
+ case "prompts":
454
+ return "command";
455
+ case "hook":
456
+ case "hooks":
457
+ return "hook";
458
+ case "instruction":
459
+ case "instructions":
460
+ case "rule":
461
+ case "rules":
462
+ return "instruction";
463
+ case "mcp":
464
+ case "mcp_server":
465
+ case "mcp-server":
466
+ return "mcp";
467
+ default:
468
+ return void 0;
469
+ }
470
+ }
471
+ function primitiveFromResourceType(type) {
472
+ switch (type) {
473
+ case "skill":
474
+ return "skill";
475
+ case "agent":
476
+ return "agent";
477
+ case "command":
478
+ return "command";
479
+ case "hook":
480
+ return "hook";
481
+ case "instruction":
482
+ case "rule":
483
+ return "instruction";
484
+ case "mcp_server":
485
+ return "mcp";
486
+ case "permission":
487
+ case "env_var":
488
+ case "model_config":
489
+ case "plugin":
490
+ return void 0;
491
+ default: {
492
+ const _exhaustive = type;
493
+ return _exhaustive;
494
+ }
495
+ }
496
+ }
497
+ function parseYamlMapping(raw, filePath) {
498
+ let parsed;
499
+ try {
500
+ parsed = parseYaml(raw);
501
+ } catch (error) {
502
+ const message = error instanceof Error ? error.message : String(error);
503
+ throw new PolicyError(`Invalid YAML in ${filePath}: ${message}`);
504
+ }
505
+ if (!isRecord2(parsed)) {
506
+ throw new PolicyError(`${filePath} must be a YAML mapping`);
507
+ }
508
+ return parsed;
509
+ }
510
+ function parseApmPolicyDocument(raw, filePath) {
511
+ const document = parseYamlMapping(raw, filePath);
512
+ const warnings = [];
513
+ for (const key of Object.keys(document)) {
514
+ if (isVendorExtensionKey(key) || KNOWN_TOP_LEVEL.has(key)) {
515
+ continue;
516
+ }
517
+ warnings.push(`Unknown top-level policy key ${key} is ignored`);
518
+ }
519
+ const dependencies = isRecord2(document.dependencies) ? document.dependencies : {};
520
+ const mcp = isRecord2(document.mcp) ? document.mcp : {};
521
+ const manifest = isRecord2(document.manifest) ? document.manifest : {};
522
+ const contentTypes = isRecord2(manifest.content_types) ? manifest.content_types : {};
523
+ const contentTypesAllow = stringList(contentTypes.allow, "manifest.content_types.allow");
524
+ if (contentTypesAllow) {
525
+ for (const entry of contentTypesAllow) {
526
+ if (!normalizeContentType(entry)) {
527
+ throw new PolicyError(
528
+ `manifest.content_types.allow entry ${entry} is not a supported primitive`
529
+ );
530
+ }
531
+ }
532
+ }
533
+ const extendsRef = typeof document.extends === "string" && document.extends.trim().length > 0 ? document.extends.trim() : void 0;
534
+ const fetchFailure = parseEnum(
535
+ document.fetch_failure,
536
+ POLICY_FETCH_FAILURES,
537
+ "fetch_failure",
538
+ "warn"
539
+ );
540
+ if (extendsRef) {
541
+ const message = "apm-policy.yml extends is not fetched in this slice; inline the parent rules";
542
+ if (fetchFailure === "block") {
543
+ throw new PolicyError(message);
544
+ }
545
+ warnings.push(message);
546
+ }
547
+ const executables = parseOrgExecutables(document.executables);
548
+ const binDeploy = parseBinDeploy(document.bin_deploy);
549
+ warnings.push(...executables.warnings);
550
+ return {
551
+ name: typeof document.name === "string" ? document.name : "",
552
+ version: typeof document.version === "string" ? document.version : "",
553
+ enforcement: parseEnum(document.enforcement, POLICY_ENFORCEMENTS, "enforcement", "warn"),
554
+ fetchFailure,
555
+ ...extendsRef ? { extends: extendsRef } : {},
556
+ dependenciesAllow: stringList(dependencies.allow, "dependencies.allow"),
557
+ dependenciesDeny: stringList(dependencies.deny, "dependencies.deny"),
558
+ mcpAllow: stringList(mcp.allow, "mcp.allow"),
559
+ mcpDeny: stringList(mcp.deny, "mcp.deny"),
560
+ trustTransitive: mcp.trust_transitive === void 0 ? false : mcp.trust_transitive === true,
561
+ contentTypesAllow,
562
+ executables,
563
+ binDeployDenyAll: binDeploy.denyAll,
564
+ binDeployDeny: binDeploy.deny,
565
+ binDeployNonEmpty: binDeploy.nonEmpty,
566
+ warnings
567
+ };
568
+ }
569
+ function emptyOrgExecutables(present, nonEmpty) {
570
+ return {
571
+ present,
572
+ nonEmpty,
573
+ denyAll: false,
574
+ deny: [],
575
+ require: [],
576
+ recommend: [],
577
+ enforce: [],
578
+ warnings: []
579
+ };
580
+ }
581
+ function parseOrgExecutables(value) {
582
+ if (value === void 0) {
583
+ return emptyOrgExecutables(false, false);
584
+ }
585
+ if (value === null) {
586
+ return emptyOrgExecutables(true, false);
587
+ }
588
+ if (!isRecord2(value)) {
589
+ throw new PolicyError("executables must be a mapping");
590
+ }
591
+ const nonEmpty = Object.keys(value).length > 0;
592
+ const deny = stringList(value.deny, "executables.deny") ?? [];
593
+ const require2 = stringList(value.require, "executables.require") ?? [];
594
+ const recommend = stringList(value.recommend, "executables.recommend") ?? [];
595
+ const enforce = stringList(value.enforce, "executables.enforce") ?? [];
596
+ const warnings = [];
597
+ if (enforce.length > 0) {
598
+ warnings.push(
599
+ "executables.enforce is accepted but inert in this release; treated as recommend"
600
+ );
601
+ }
602
+ if (value.deny_all !== void 0 && value.deny_all !== null && typeof value.deny_all !== "boolean") {
603
+ throw new PolicyError("executables.deny_all must be a boolean");
604
+ }
605
+ return {
606
+ present: true,
607
+ nonEmpty,
608
+ denyAll: value.deny_all === true,
609
+ deny,
610
+ require: require2,
611
+ recommend: [.../* @__PURE__ */ new Set([...recommend, ...enforce])],
612
+ enforce,
613
+ warnings
614
+ };
615
+ }
616
+ function parseBinDeploy(value) {
617
+ if (value === void 0 || value === null) {
618
+ return { denyAll: false, deny: [], nonEmpty: false };
619
+ }
620
+ if (!isRecord2(value)) {
621
+ throw new PolicyError("bin_deploy must be a mapping");
622
+ }
623
+ if (value.deny_all !== void 0 && value.deny_all !== null && typeof value.deny_all !== "boolean") {
624
+ throw new PolicyError("bin_deploy.deny_all must be a boolean");
625
+ }
626
+ return {
627
+ denyAll: value.deny_all === true,
628
+ deny: stringList(value.deny, "bin_deploy.deny") ?? [],
629
+ nonEmpty: Object.keys(value).length > 0
630
+ };
631
+ }
632
+ function projectPolicyPath(projectRoot) {
633
+ return join2(projectRoot, APM_POLICY_FILENAME);
634
+ }
635
+ function toPosix(path) {
636
+ return path.split("\\").join("/");
637
+ }
638
+ function resolvePolicyFile(projectRoot, policyPath) {
639
+ if (policyPath && policyPath.trim().length > 0) {
640
+ const resolved = isAbsolute(policyPath) ? resolve(policyPath) : resolve(projectRoot, policyPath);
641
+ const rel = toPosix(relative(projectRoot, resolved));
642
+ assertContainedPath(projectRoot, rel);
643
+ return resolved;
644
+ }
645
+ const discovered = projectPolicyPath(projectRoot);
646
+ return existsSync2(discovered) ? discovered : void 0;
647
+ }
648
+ function pinViolation(code, message) {
649
+ return { code, message };
650
+ }
651
+ function loadProjectPolicy(options) {
652
+ const projectRoot = resolve(options.projectRoot);
653
+ const warnings = [];
654
+ const pin = options.pin;
655
+ let filePath;
656
+ try {
657
+ filePath = resolvePolicyFile(projectRoot, options.policyPath);
658
+ } catch (error) {
659
+ const message = error instanceof Error ? error.message : String(error);
660
+ return {
661
+ status: "failed",
662
+ pin,
663
+ warnings,
664
+ violations: [pinViolation("policy-path", message)]
665
+ };
666
+ }
667
+ if (!filePath || !existsSync2(filePath)) {
668
+ if (pin) {
669
+ return {
670
+ status: "failed",
671
+ pin,
672
+ warnings,
673
+ violations: [
674
+ pinViolation(
675
+ "policy-missing",
676
+ `apm.yml pins policy.hash but ${APM_POLICY_FILENAME} is missing`
677
+ )
678
+ ]
679
+ };
680
+ }
681
+ if (options.requirePolicy) {
682
+ return {
683
+ status: "failed",
684
+ warnings,
685
+ violations: [
686
+ pinViolation(
687
+ "policy-required",
688
+ `No ${APM_POLICY_FILENAME} found (required by --require-policy)`
689
+ )
690
+ ]
691
+ };
692
+ }
693
+ return { status: "skipped", skippedReason: "no-policy", warnings, violations: [] };
694
+ }
695
+ const bytes = readFileSync2(filePath);
696
+ if (pin) {
697
+ const actual = hashPolicyBytes(bytes, pin.algorithm);
698
+ if (!policyHashesMatch(pin.hash, actual)) {
699
+ return {
700
+ status: "failed",
701
+ source: toPosix(relative(projectRoot, filePath)) || APM_POLICY_FILENAME,
702
+ pin,
703
+ warnings,
704
+ violations: [
705
+ pinViolation(
706
+ "policy-hash-mismatch",
707
+ `Pinned policy.hash does not match ${APM_POLICY_FILENAME} (${actual})`
708
+ )
709
+ ]
710
+ };
711
+ }
712
+ }
713
+ try {
714
+ const policy = parseApmPolicyDocument(bytes.toString("utf8"), filePath);
715
+ return {
716
+ status: "evaluated",
717
+ source: toPosix(relative(projectRoot, filePath)) || APM_POLICY_FILENAME,
718
+ policy,
719
+ pin,
720
+ warnings: [...warnings, ...policy.warnings],
721
+ violations: []
722
+ };
723
+ } catch (error) {
724
+ const message = error instanceof Error ? error.message : String(error);
725
+ return {
726
+ status: "failed",
727
+ source: toPosix(relative(projectRoot, filePath)) || APM_POLICY_FILENAME,
728
+ pin,
729
+ warnings,
730
+ violations: [pinViolation("policy-parse", message)]
731
+ };
732
+ }
733
+ }
734
+ function hostFromCanonicalRepo(repoUrl) {
735
+ if (repoUrl.startsWith("file://")) {
736
+ return void 0;
737
+ }
738
+ const host = repoUrl.split("/")[0];
739
+ return host && (host.includes(".") || host === "localhost") ? host.toLowerCase() : void 0;
740
+ }
741
+ function gitIdentities(identity, host) {
742
+ const ids = /* @__PURE__ */ new Set([identity]);
743
+ if (host && identity.startsWith(`${host}/`)) {
744
+ ids.add(identity.slice(host.length + 1));
745
+ }
746
+ if (host) {
747
+ ids.add(host);
748
+ }
749
+ ids.add("git");
750
+ return [...ids];
751
+ }
752
+ function catalogIdentities(identity) {
753
+ return [.../* @__PURE__ */ new Set([identity, "catalog"])];
754
+ }
755
+ function localIdentities(identity) {
756
+ const ids = /* @__PURE__ */ new Set([identity, "local", ".", "./"]);
757
+ if (identity.startsWith("./") || identity.startsWith("../")) {
758
+ ids.add(identity);
759
+ }
760
+ return [...ids];
761
+ }
762
+ function matchPolicyPattern(pattern, candidates) {
763
+ const normalized = pattern.trim();
764
+ if (!normalized) {
765
+ return false;
766
+ }
767
+ if (candidates.includes(normalized)) {
768
+ return true;
769
+ }
770
+ const match = picomatch(normalized, { dot: true });
771
+ if (candidates.some((candidate) => match(candidate))) {
772
+ return true;
773
+ }
774
+ if (normalized.endsWith("/*")) {
775
+ const prefix = normalized.slice(0, -2);
776
+ return candidates.some(
777
+ (candidate) => candidate === prefix || candidate.startsWith(`${prefix}/`)
778
+ );
779
+ }
780
+ return false;
781
+ }
782
+ function sourceCandidates(source) {
783
+ switch (source.kind) {
784
+ case "git":
785
+ return gitIdentities(source.identity, source.host);
786
+ case "catalog":
787
+ return catalogIdentities(source.identity);
788
+ case "local":
789
+ return localIdentities(source.path ?? source.identity);
790
+ case "marketplace":
791
+ return [.../* @__PURE__ */ new Set([source.identity, "marketplace"])];
792
+ default: {
793
+ const _exhaustive = source.kind;
794
+ return _exhaustive;
795
+ }
796
+ }
797
+ }
798
+ function sourceMatches(patterns, source) {
799
+ const candidates = sourceCandidates(source);
800
+ return patterns.find((pattern) => matchPolicyPattern(pattern, candidates));
801
+ }
802
+ function mcpCandidates(entry) {
803
+ return [.../* @__PURE__ */ new Set([entry.identity, entry.name])];
804
+ }
805
+ function mcpMatches(patterns, entry) {
806
+ const candidates = mcpCandidates(entry);
807
+ return patterns.find((pattern) => matchPolicyPattern(pattern, candidates));
808
+ }
809
+ function uniquePrimitives(values) {
810
+ return [...new Set(values.filter((value) => value !== void 0))].sort();
811
+ }
812
+ function sourceFromApmDependency(dep, depth = 1) {
813
+ if (dep.sourceKind === "git") {
814
+ const identity = canonicalApmRepoUrl(dep.originRef);
815
+ return {
816
+ kind: "git",
817
+ name: dep.name,
818
+ identity,
819
+ ...hostFromCanonicalRepo(identity) ? { host: hostFromCanonicalRepo(identity) } : {},
820
+ depth
821
+ };
822
+ }
823
+ if (dep.sourceKind === "catalog") {
824
+ return { kind: "catalog", name: dep.name, identity: dep.originRef, depth };
825
+ }
826
+ if (dep.sourceKind === "marketplace") {
827
+ return { kind: "marketplace", name: dep.name, identity: dep.originRef, depth };
828
+ }
829
+ return {
830
+ kind: "local",
831
+ name: dep.name,
832
+ identity: dep.originRef,
833
+ path: dep.originRef,
834
+ depth
835
+ };
836
+ }
837
+ function sourceFromLockEntry(entry) {
838
+ if (entry.source === "git" || entry.repo_url) {
839
+ const identity = entry.repo_url ? canonicalApmRepoUrl(entry.repo_url) : entry.name;
840
+ return {
841
+ kind: "git",
842
+ name: entry.name,
843
+ identity,
844
+ ...hostFromCanonicalRepo(identity) ? { host: hostFromCanonicalRepo(identity) } : {},
845
+ depth: entry.depth
846
+ };
847
+ }
848
+ if (entry.source === "catalog") {
849
+ return {
850
+ kind: "catalog",
851
+ name: entry.name,
852
+ identity: entry.repo_url ?? entry.name,
853
+ depth: entry.depth
854
+ };
855
+ }
856
+ if (entry.source === "marketplace") {
857
+ return {
858
+ kind: "marketplace",
859
+ name: entry.name,
860
+ identity: entry.name,
861
+ depth: entry.depth
862
+ };
863
+ }
864
+ return {
865
+ kind: "local",
866
+ name: entry.name,
867
+ identity: entry.name,
868
+ path: entry.name,
869
+ depth: entry.depth
870
+ };
871
+ }
872
+ function sourceFromSelectedPlugin(name, source, depth, pluginId, repoUrl) {
873
+ if (repoUrl) {
874
+ const identity = canonicalApmRepoUrl(repoUrl);
875
+ return {
876
+ kind: "git",
877
+ name,
878
+ identity,
879
+ ...hostFromCanonicalRepo(identity) ? { host: hostFromCanonicalRepo(identity) } : {},
880
+ depth
881
+ };
882
+ }
883
+ if (pluginId) {
884
+ const plugin = getPluginById(pluginId);
885
+ if (plugin) {
886
+ const locator = recoverOriginLocator(plugin);
887
+ if (locator?.kind === "git") {
888
+ const identity = canonicalApmRepoUrl(locator.url);
889
+ return {
890
+ kind: "git",
891
+ name,
892
+ identity,
893
+ ...hostFromCanonicalRepo(identity) ? { host: hostFromCanonicalRepo(identity) } : {},
894
+ depth
895
+ };
896
+ }
897
+ if (locator?.kind === "catalog") {
898
+ return {
899
+ kind: "catalog",
900
+ name,
901
+ identity: `${locator.org}/${locator.catalog}/${locator.slug}`,
902
+ depth
903
+ };
904
+ }
905
+ if (locator?.kind === "marketplace") {
906
+ return { kind: "marketplace", name, identity: locator.ref, depth };
907
+ }
908
+ }
909
+ }
910
+ if (source === "catalog") {
911
+ return { kind: "catalog", name, identity: name, depth };
912
+ }
913
+ if (source === "marketplace") {
914
+ return { kind: "marketplace", name, identity: name, depth };
915
+ }
916
+ if (source === "git") {
917
+ return { kind: "git", name, identity: name, depth };
918
+ }
919
+ return { kind: "local", name, identity: name, path: name, depth };
920
+ }
921
+ function mergeSources(sources) {
922
+ const byKey = /* @__PURE__ */ new Map();
923
+ for (const source of sources) {
924
+ const key = `${source.kind}:${source.identity}`;
925
+ const existing = byKey.get(key);
926
+ if (!existing || source.depth < existing.depth) {
927
+ byKey.set(key, source);
928
+ }
929
+ }
930
+ return [...byKey.values()].sort((left, right) => left.identity.localeCompare(right.identity));
931
+ }
932
+ function declaredMcpNames(deps) {
933
+ return new Set(deps.map((dep) => dep.name));
934
+ }
935
+ function mcpFromManifest(deps) {
936
+ return deps.map((dep) => ({
937
+ name: dep.name,
938
+ identity: dep.registryId ?? dep.name,
939
+ depth: 0,
940
+ declaredInManifest: true
941
+ }));
942
+ }
943
+ function mcpFromLock(servers, declared) {
944
+ if (!servers) {
945
+ return [];
946
+ }
947
+ return servers.map((server) => ({
948
+ name: server.name,
949
+ identity: server.name,
950
+ depth: declared.has(server.name) ? 0 : 1,
951
+ declaredInManifest: declared.has(server.name)
952
+ }));
953
+ }
954
+ function overlayPrimitives(projectRoot) {
955
+ try {
956
+ const overlay = inspectApmOverlay(projectRoot);
957
+ if (!overlay) {
958
+ return [];
959
+ }
960
+ const types = [
961
+ ...overlay.skills.map(() => "skill"),
962
+ ...overlay.primitives.map((primitive) => primitiveFromResourceType(primitive.type))
963
+ ];
964
+ return uniquePrimitives(types);
965
+ } catch {
966
+ return [];
967
+ }
968
+ }
969
+ function buildAuditInstallPlan(options) {
970
+ const declared = declaredMcpNames(options.mcpDependencies ?? []);
971
+ const sources = mergeSources([
972
+ ...(options.apmDependencies ?? []).map((dep) => sourceFromApmDependency(dep, 1)),
973
+ ...(options.lock?.plugins ?? []).map(sourceFromLockEntry)
974
+ ]);
975
+ const primitives = uniquePrimitives([
976
+ ...overlayPrimitives(options.projectRoot),
977
+ ...options.lock?.mcp_servers?.length ? ["mcp"] : [],
978
+ ...options.mcpDependencies?.length ? ["mcp"] : []
979
+ ]);
980
+ const mcp = [
981
+ ...mcpFromManifest(options.mcpDependencies ?? []),
982
+ ...mcpFromLock(options.lock?.mcp_servers, declared).filter(
983
+ (entry) => !declared.has(entry.name)
984
+ )
985
+ ];
986
+ return { sources, primitives, mcp };
987
+ }
988
+ function buildApplyInstallPlan(options) {
989
+ const declared = declaredMcpNames(options.mcpDependencies ?? []);
990
+ const gitByName = new Map((options.gitLocks ?? []).map((entry) => [entry.name, entry.repo_url]));
991
+ const sources = mergeSources([
992
+ ...(options.apmDependencies ?? []).map((dep) => sourceFromApmDependency(dep, 1)),
993
+ ...options.resolution.selected.filter((plugin) => plugin.depth > 0).map(
994
+ (plugin) => sourceFromSelectedPlugin(
995
+ plugin.name,
996
+ plugin.source,
997
+ plugin.depth,
998
+ plugin.pluginId,
999
+ gitByName.get(plugin.name)
1000
+ )
1001
+ )
1002
+ ]);
1003
+ const primitives = uniquePrimitives(
1004
+ options.resources.map((resource) => primitiveFromResourceType(resource.type))
1005
+ );
1006
+ const depthByResource = new Map(
1007
+ options.resolution.decisions.map((decision) => [decision.key, decision.winner.depth])
1008
+ );
1009
+ const mcp = options.resources.filter((resource) => resource.type === "mcp_server").map((resource) => {
1010
+ const depth = depthByResource.get(resolutionKey(resource)) ?? 0;
1011
+ return {
1012
+ name: resource.name,
1013
+ identity: resource.origin_ref || resource.name,
1014
+ depth,
1015
+ declaredInManifest: declared.has(resource.name)
1016
+ };
1017
+ });
1018
+ return { sources, primitives, mcp };
1019
+ }
1020
+ function evaluatePolicy(policy, plan) {
1021
+ const violations = [];
1022
+ for (const source of plan.sources) {
1023
+ const denied = sourceMatches(policy.dependenciesDeny ?? [], source);
1024
+ if (denied) {
1025
+ violations.push({
1026
+ code: "source-denied",
1027
+ subject: source.identity,
1028
+ message: `Source ${source.identity} matches deny pattern ${denied}`
1029
+ });
1030
+ continue;
1031
+ }
1032
+ if (policy.dependenciesAllow) {
1033
+ const allowed = sourceMatches(policy.dependenciesAllow, source);
1034
+ if (!allowed) {
1035
+ violations.push({
1036
+ code: "source-not-allowed",
1037
+ subject: source.identity,
1038
+ message: `Source ${source.identity} (${source.kind}) is not in dependencies.allow`
1039
+ });
1040
+ }
1041
+ }
1042
+ }
1043
+ if (policy.contentTypesAllow) {
1044
+ const allowed = new Set(
1045
+ policy.contentTypesAllow.map(normalizeContentType).filter((value) => value !== void 0)
1046
+ );
1047
+ for (const primitive of plan.primitives) {
1048
+ if (!allowed.has(primitive)) {
1049
+ violations.push({
1050
+ code: "primitive-not-allowed",
1051
+ subject: primitive,
1052
+ message: `Primitive ${primitive} is not in manifest.content_types.allow`
1053
+ });
1054
+ }
1055
+ }
1056
+ }
1057
+ for (const entry of plan.mcp) {
1058
+ const denied = mcpMatches(policy.mcpDeny ?? [], entry);
1059
+ if (denied) {
1060
+ violations.push({
1061
+ code: "mcp-denied",
1062
+ subject: entry.name,
1063
+ message: `MCP server ${entry.name} matches deny pattern ${denied}`
1064
+ });
1065
+ continue;
1066
+ }
1067
+ const allowListed = mcpMatches(policy.mcpAllow ?? [], entry);
1068
+ const transitive = entry.depth > 0 && !entry.declaredInManifest;
1069
+ if (transitive && !policy.trustTransitive && !allowListed) {
1070
+ violations.push({
1071
+ code: "mcp-transitive",
1072
+ subject: entry.name,
1073
+ message: `Transitive MCP server ${entry.name} is not declared in apm.yml dependencies.mcp or mcp.allow (mcp.trust_transitive is false)`
1074
+ });
1075
+ continue;
1076
+ }
1077
+ if (policy.mcpAllow && !allowListed && !entry.declaredInManifest) {
1078
+ violations.push({
1079
+ code: "mcp-not-allowed",
1080
+ subject: entry.name,
1081
+ message: `MCP server ${entry.name} is not in mcp.allow`
1082
+ });
1083
+ }
1084
+ }
1085
+ return violations;
1086
+ }
1087
+ function evaluationFromLoad(loaded, plan) {
1088
+ if (loaded.status === "skipped") {
1089
+ return {
1090
+ status: "skipped",
1091
+ skippedReason: "no-policy",
1092
+ enforcement: "off",
1093
+ warnings: loaded.warnings,
1094
+ violations: [],
1095
+ blocks: false
1096
+ };
1097
+ }
1098
+ if (loaded.status === "failed" || !loaded.policy) {
1099
+ return {
1100
+ status: "failed",
1101
+ source: loaded.source,
1102
+ enforcement: "block",
1103
+ warnings: loaded.warnings,
1104
+ violations: loaded.violations,
1105
+ blocks: true
1106
+ };
1107
+ }
1108
+ const violations = evaluatePolicy(loaded.policy, plan);
1109
+ const enforcement = loaded.policy.enforcement;
1110
+ const blocks = enforcement === "block" && violations.length > 0;
1111
+ return {
1112
+ status: "evaluated",
1113
+ source: loaded.source,
1114
+ name: loaded.policy.name || void 0,
1115
+ enforcement,
1116
+ warnings: loaded.warnings,
1117
+ violations,
1118
+ blocks
1119
+ };
1120
+ }
1121
+ function loadAndEvaluateProjectPolicy(options) {
1122
+ const loaded = loadProjectPolicy({
1123
+ projectRoot: options.projectRoot,
1124
+ ...options.policyPath ? { policyPath: options.policyPath } : {},
1125
+ ...options.pin ? { pin: options.pin } : {},
1126
+ ...options.requirePolicy ? { requirePolicy: true } : {}
1127
+ });
1128
+ return evaluationFromLoad(loaded, options.plan);
1129
+ }
1130
+ function formatPolicyViolations(violations) {
1131
+ if (violations.length === 1 && violations[0]) {
1132
+ return violations[0].message;
1133
+ }
1134
+ return [
1135
+ `${formatCount(violations.length, "policy violation")}`,
1136
+ ...violations.map((violation) => `- ${violation.message}`)
1137
+ ].join("\n");
1138
+ }
1139
+ function evaluateApplyPolicy(options) {
1140
+ const plan = buildApplyInstallPlan({
1141
+ resolution: options.resolution,
1142
+ resources: options.resources,
1143
+ apmDependencies: options.apmDependencies,
1144
+ mcpDependencies: options.mcpDependencies,
1145
+ gitLocks: options.gitLocks
1146
+ });
1147
+ return loadAndEvaluateProjectPolicy({
1148
+ projectRoot: options.projectRoot,
1149
+ ...options.pin ? { pin: options.pin } : {},
1150
+ plan
1151
+ });
1152
+ }
1153
+ function assertPolicyAllowsApply(evaluation) {
1154
+ if (!evaluation.blocks) {
1155
+ return;
1156
+ }
1157
+ throw new PolicyError(formatPolicyViolations(evaluation.violations), evaluation.violations);
1158
+ }
1159
+
1160
+ export {
1161
+ skippedRootSourceWarning,
1162
+ collectSkillMdFiles,
1163
+ inspectApmOverlay,
1164
+ PolicyError,
1165
+ parseApmPolicyPin,
1166
+ loadProjectPolicy,
1167
+ matchPolicyPattern,
1168
+ buildAuditInstallPlan,
1169
+ loadAndEvaluateProjectPolicy,
1170
+ evaluateApplyPolicy,
1171
+ assertPolicyAllowsApply
1172
+ };
1173
+ //# sourceMappingURL=chunk-E4WRTRMH.js.map