@kriya-ai/harness 0.2.5 → 2.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.
Files changed (132) hide show
  1. package/RELEASE_NOTES.md +121 -0
  2. package/SAFETY.md +181 -0
  3. package/THIRD_PARTY_NOTICES.md +113 -0
  4. package/bin/kriya.js +188 -2
  5. package/bundle/cordis.patch.yml +49 -0
  6. package/contract/SOURCE.md +3 -3
  7. package/contract/contract.json +498 -3
  8. package/contract/schemas/api.json +64 -0
  9. package/contract/schemas/auth_matrix.json +44 -0
  10. package/contract/schemas/component_states.json +33 -0
  11. package/contract/schemas/design_tokens.json +34 -0
  12. package/contract/schemas/scene_direction.json +82 -0
  13. package/contract/schemas/threat_model.json +44 -0
  14. package/package.json +2 -1
  15. package/plugins/changes/client.js +5 -3
  16. package/plugins/deploy/index.js +215 -0
  17. package/plugins/deploy/package.json +13 -0
  18. package/plugins/grounding/index.js +81 -0
  19. package/plugins/grounding/lookup.js +373 -0
  20. package/plugins/grounding/package.json +13 -0
  21. package/plugins/kriya-tools/index.js +2 -1
  22. package/plugins/loop/index.js +376 -10
  23. package/plugins/mcp/index.js +79 -0
  24. package/plugins/mcp/package.json +13 -0
  25. package/plugins/mirror/index.js +17 -0
  26. package/plugins/overview/client.js +5 -2
  27. package/plugins/preview/client.js +12 -6
  28. package/plugins/progress/client.js +7 -4
  29. package/plugins/repo/index.js +230 -0
  30. package/plugins/repo/package.json +13 -0
  31. package/plugins/repo/repo.js +348 -0
  32. package/plugins/runstrip/client.js +426 -0
  33. package/plugins/runstrip/index.js +301 -0
  34. package/plugins/runstrip/package.json +23 -0
  35. package/src/cartridges.js +133 -0
  36. package/src/contracts.js +130 -0
  37. package/src/critic.js +78 -0
  38. package/src/daemon.js +7 -1
  39. package/src/doctor.js +67 -0
  40. package/src/edit/core/effects.js +185 -0
  41. package/src/edit/core/ffmpeg.js +65 -6
  42. package/src/edit/core/layout.js +46 -1
  43. package/src/edit/core/ops.js +169 -2
  44. package/src/edit/core/plan.js +65 -9
  45. package/src/edit/core/project.d.ts +24 -0
  46. package/src/edit/core/project.js +64 -0
  47. package/src/edit/core/solver.js +34 -6
  48. package/src/edit/core/style-brief.js +211 -0
  49. package/src/edit/core/style-packs.js +57 -0
  50. package/src/edit/core/type-kit.js +173 -0
  51. package/src/edit/director/ask.js +37 -3
  52. package/src/edit/director/assembly.js +829 -0
  53. package/src/edit/director/continuity.js +9 -1
  54. package/src/edit/director/custom-motion.js +88 -0
  55. package/src/edit/director/graphics.js +44 -10
  56. package/src/edit/director/intent.js +125 -0
  57. package/src/edit/director/mentions.js +52 -0
  58. package/src/edit/director/plan.js +43 -11
  59. package/src/edit/director/revise.js +132 -9
  60. package/src/edit/director/viewer.js +136 -0
  61. package/src/edit/director/watch-fix.js +119 -0
  62. package/src/edit/engine/captions.js +110 -5
  63. package/src/edit/engine/confine.js +81 -4
  64. package/src/edit/engine/custom.js +243 -0
  65. package/src/edit/engine/dna2.js +893 -0
  66. package/src/edit/engine/fonts.js +218 -0
  67. package/src/edit/engine/graphics.js +271 -10
  68. package/src/edit/engine/index.js +14 -5
  69. package/src/edit/engine/motion.js +148 -13
  70. package/src/edit/engine/music-bed.js +59 -1
  71. package/src/edit/engine/packs.js +11 -0
  72. package/src/edit/engine/reference2.js +26 -0
  73. package/src/edit/engine/sfx.js +56 -1
  74. package/src/edit/engine/tool.js +21 -5
  75. package/src/edit/gates/assembly.js +194 -0
  76. package/src/edit/gates/copy.js +7 -4
  77. package/src/edit/gates/index.js +72 -7
  78. package/src/edit/gates/reference.js +115 -0
  79. package/src/edit/gates/tile.js +96 -0
  80. package/src/edit/host/client.js +4 -3
  81. package/src/edit/host/clips.js +33 -0
  82. package/src/edit/host/jobs.js +9 -3
  83. package/src/edit/host/layers.js +134 -0
  84. package/src/edit/host/main.js +10 -3
  85. package/src/edit/host/paths.js +21 -3
  86. package/src/edit/host/preview.js +108 -0
  87. package/src/edit/host/projects.js +443 -34
  88. package/src/edit/host/server.js +235 -20
  89. package/src/edit/host/tavi.js +77 -0
  90. package/src/edit/loop/make.js +28 -3
  91. package/src/edit/recipes/assembly.js +352 -0
  92. package/src/edit/recipes/graphic-clips.js +4 -2
  93. package/src/edit/recipes/openings.js +36 -0
  94. package/src/edit/recipes/reel.js +104 -14
  95. package/src/edit/recipes/reference-look.js +29 -0
  96. package/src/edit/recipes/short-from-long.js +3 -3
  97. package/src/edit/recipes/sound.js +71 -0
  98. package/src/edit/runtime/cli.js +26 -5
  99. package/src/edit/runtime/fetch.js +4 -4
  100. package/src/edit/runtime/licences.js +7 -1
  101. package/src/explore.js +103 -0
  102. package/src/failure.js +1 -1
  103. package/src/gate-commands.js +114 -0
  104. package/src/gates/api.js +127 -0
  105. package/src/gates/commands.js +111 -0
  106. package/src/gates/detectors.js +370 -0
  107. package/src/gates/http.js +62 -0
  108. package/src/gates/index.js +196 -0
  109. package/src/gates/page.js +264 -0
  110. package/src/gates/sast.js +64 -0
  111. package/src/gates/stack.js +110 -0
  112. package/src/gates/tenant.js +162 -0
  113. package/src/gates/three.js +407 -0
  114. package/src/gates/ui.js +111 -0
  115. package/src/launch.js +15 -3
  116. package/src/loop.js +199 -7
  117. package/src/mcp.js +126 -0
  118. package/src/milestones.js +188 -0
  119. package/src/modes.js +32 -0
  120. package/src/orchestra.js +43 -0
  121. package/src/outcomes.js +88 -0
  122. package/src/profiles.js +5 -0
  123. package/src/receipts.js +238 -0
  124. package/src/release.js +356 -0
  125. package/src/runstrip.js +122 -0
  126. package/src/stack.js +120 -0
  127. package/src/verify.js +67 -20
  128. package/studio/dist/fonts/fraunces.woff2 +0 -0
  129. package/studio/dist/fonts/geist.woff2 +0 -0
  130. package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
  131. package/studio/dist/studio.css +449 -1
  132. package/studio/dist/studio.js +3 -3
@@ -0,0 +1,373 @@
1
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs"
2
+ import { dirname, join, relative, resolve, sep } from "node:path"
3
+
4
+ // Harness 2.0 grounding (Kriya-Tavi docs/kriya-harness/upgrade_2.0/
5
+ // GROUNDING_AND_CONNECTORS.md §5, WD-20): facts about the packages a project
6
+ // has installed, read from their own files: type definitions, stubs,
7
+ // changelogs and lockfiles. Exact for the installed version, local, free and
8
+ // deterministic. Nothing is imported, required or executed (importing a
9
+ // module runs its code), nothing goes on the network, and nothing outside the
10
+ // project folder is read.
11
+
12
+ export const MAX_ANSWER = 8 * 1024
13
+ const MAX_FILE = 2 * 1024 * 1024
14
+ const MAX_FILES = 60
15
+ const MAX_DECL_LINES = 60
16
+
17
+ export class GroundingError extends Error {}
18
+
19
+ const NPM_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i
20
+ const PY_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
21
+ const SYMBOL = /^[A-Za-z_$][\w$]{0,99}$/
22
+
23
+ const cut = (text) => (text.length <= MAX_ANSWER ? text : `${text.slice(0, MAX_ANSWER - 30)}\n… (cut at 8 KB)`)
24
+
25
+ /** A file's text, if it is a regular file inside `root` and not too large. */
26
+ function readInside(root, file) {
27
+ try {
28
+ const real = realpathSync(file)
29
+ const base = realpathSync(root)
30
+ if (real !== base && !real.startsWith(base + sep)) return undefined
31
+ const st = statSync(real)
32
+ if (!st.isFile() || st.size > MAX_FILE) return undefined
33
+ return readFileSync(real, "utf8")
34
+ } catch {
35
+ return undefined
36
+ }
37
+ }
38
+ const readJson = (root, file) => {
39
+ const text = readInside(root, file)
40
+ if (text === undefined) return undefined
41
+ try {
42
+ return JSON.parse(text)
43
+ } catch {
44
+ return undefined
45
+ }
46
+ }
47
+
48
+ /* ─────────────────────────────── where ─────────────────────────────── */
49
+
50
+ /** The installed package's folder: node_modules, else a Python environment in the project. */
51
+ export function findPackage(root, name) {
52
+ if (typeof name !== "string" || !(NPM_NAME.test(name) || PY_NAME.test(name))) throw new GroundingError("That isn't a package name.")
53
+ const npm = join(root, "node_modules", name)
54
+ if (NPM_NAME.test(name) && readJson(root, join(npm, "package.json"))) return { kind: "npm", dir: npm }
55
+ for (const site of sitePackages(root)) {
56
+ const module = name.replace(/-/g, "_")
57
+ for (const candidate of [join(site, module), join(site, name), join(site, name.toLowerCase().replace(/-/g, "_"))])
58
+ if (existsSync(candidate) && readInside(root, join(candidate, "__init__.py")) !== undefined) return { kind: "python", dir: candidate, site, module }
59
+ for (const candidate of [join(site, `${module}.py`), join(site, `${module}.pyi`)])
60
+ if (readInside(root, candidate) !== undefined) return { kind: "python", dir: site, site, module, single: candidate }
61
+ }
62
+ // Types only (@types/<pkg>)
63
+ if (NPM_NAME.test(name) && typesPackage(root, name)) return { kind: "npm", dir: npm, typesOnly: true }
64
+ return undefined
65
+ }
66
+
67
+ /** site-packages of a virtual environment in the project (.venv, venv, env). */
68
+ export function sitePackages(root) {
69
+ const out = []
70
+ for (const env of [".venv", "venv", "env"]) {
71
+ for (const lib of ["lib", "Lib"]) {
72
+ const dir = join(root, env, lib)
73
+ if (!existsSync(dir)) continue
74
+ if (lib === "Lib" && existsSync(join(dir, "site-packages"))) out.push(join(dir, "site-packages"))
75
+ else
76
+ for (const py of safeList(dir).filter((d) => /^python\d/.test(d)))
77
+ if (existsSync(join(dir, py, "site-packages"))) out.push(join(dir, py, "site-packages"))
78
+ }
79
+ }
80
+ return out
81
+ }
82
+
83
+ const safeList = (dir) => {
84
+ try {
85
+ return readdirSync(dir).sort()
86
+ } catch {
87
+ return []
88
+ }
89
+ }
90
+
91
+ const typesName = (name) => (name.startsWith("@") ? name.slice(1).replace("/", "__") : name)
92
+ function typesPackage(root, name) {
93
+ const dir = join(root, "node_modules", "@types", typesName(name))
94
+ return readJson(root, join(dir, "package.json")) ? dir : undefined
95
+ }
96
+
97
+ /** The `types` entry of an exports value, searched in a fixed order. */
98
+ function exportsTypes(value) {
99
+ if (!value) return undefined
100
+ if (typeof value === "string") return /\.d\.[cm]?ts$/.test(value) ? value : undefined
101
+ if (Array.isArray(value)) {
102
+ for (const v of value) {
103
+ const found = exportsTypes(v)
104
+ if (found) return found
105
+ }
106
+ return undefined
107
+ }
108
+ if (typeof value === "object") {
109
+ if (typeof value.types === "string") return value.types
110
+ for (const key of ["import", "require", "node", "default"]) {
111
+ const found = exportsTypes(value[key])
112
+ if (found) return found
113
+ }
114
+ }
115
+ return undefined
116
+ }
117
+
118
+ /** The package's declaration entry: types/typings, exports["."].types, index.d.ts; then @types/<pkg>. */
119
+ export function typesEntry(root, name) {
120
+ const dir = join(root, "node_modules", name)
121
+ const pkg = readJson(root, join(dir, "package.json"))
122
+ const tries = []
123
+ if (pkg) {
124
+ for (const field of [pkg.types, pkg.typings]) if (typeof field === "string") tries.push(join(dir, field))
125
+ const dot = pkg.exports && typeof pkg.exports === "object" && !Array.isArray(pkg.exports) && "." in pkg.exports ? pkg.exports["."] : pkg.exports
126
+ const fromExports = exportsTypes(dot)
127
+ if (fromExports) tries.push(join(dir, fromExports))
128
+ tries.push(join(dir, "index.d.ts"))
129
+ }
130
+ for (const file of tries) if (readInside(root, file) !== undefined) return { file, from: "package" }
131
+ const types = typesPackage(root, name)
132
+ if (types) {
133
+ const tpkg = readJson(root, join(types, "package.json"))
134
+ for (const file of [tpkg?.types, tpkg?.typings, "index.d.ts"].filter((f) => typeof f === "string").map((f) => join(types, f)))
135
+ if (readInside(root, file) !== undefined) return { file, from: "@types" }
136
+ }
137
+ return undefined
138
+ }
139
+
140
+ /* ────────────────────────────── lookup ────────────────────────────── */
141
+
142
+ const RE_EXPORT = /^\s*export\s+(?:\*|\{[^}]*\}|\*\s+as\s+\w+)\s+from\s+["'](\.{1,2}\/[^"']+)["']/gm
143
+ const REFERENCE = /^\s*\/\/\/\s*<reference\s+path=["']([^"']+)["']/gm
144
+
145
+ /** The declaration files reachable from an entry through relative re-exports (bounded). */
146
+ function declarationFiles(root, entry) {
147
+ const seen = []
148
+ const queue = [entry]
149
+ while (queue.length && seen.length < MAX_FILES) {
150
+ const file = queue.shift()
151
+ if (seen.some((s) => s.file === file)) continue
152
+ const text = readInside(root, file)
153
+ if (text === undefined) continue
154
+ seen.push({ file, text })
155
+ for (const re of [RE_EXPORT, REFERENCE]) {
156
+ re.lastIndex = 0
157
+ for (const m of text.matchAll(re)) {
158
+ const target = resolve(dirname(file), m[1])
159
+ for (const f of [target, `${target}.d.ts`, target.replace(/\.(m|c)?js$/, ".d.$1ts"), join(target, "index.d.ts")])
160
+ if (/\.d\.[cm]?ts$/.test(f) && readInside(root, f) !== undefined) {
161
+ queue.push(f)
162
+ break
163
+ }
164
+ }
165
+ }
166
+ }
167
+ return seen
168
+ }
169
+
170
+ const DECL = (name) =>
171
+ new RegExp(String.raw`^\s*(?:export\s+)?(?:declare\s+)?(?:default\s+)?(?:abstract\s+)?(?:async\s+)?(?:function\*?|class|interface|type|const|let|var|enum|namespace|module)\s+${name.replace(/\$/g, "\\$")}\b`)
172
+ const MEMBER = (name) => new RegExp(String.raw`^\s+(?:readonly\s+|static\s+|public\s+|protected\s+)*${name.replace(/\$/g, "\\$")}\??\s*[(:<]`)
173
+
174
+ /** One declaration from line `i`: its doc comment and its text until braces balance or a `;` ends it. */
175
+ function declarationAt(lines, i) {
176
+ let start = i
177
+ if (lines[i - 1]?.trim().endsWith("*/")) {
178
+ let j = i - 1
179
+ while (j >= 0 && !lines[j].includes("/**")) j--
180
+ if (j >= 0) start = j
181
+ }
182
+ const out = []
183
+ let depth = 0
184
+ for (let k = i; k < lines.length && k < i + MAX_DECL_LINES; k++) {
185
+ const line = lines[k]
186
+ out.push(line)
187
+ depth += (line.match(/[{(]/g) ?? []).length - (line.match(/[})]/g) ?? []).length
188
+ if (depth <= 0 && (/[;}]\s*$/.test(line) || (k === i && !/[{(]\s*$/.test(line) && /\)\s*:\s*[^=]+;?$/.test(line)))) break
189
+ }
190
+ return [...lines.slice(start, i), ...out].join("\n")
191
+ }
192
+
193
+ function searchTs(root, files, symbol) {
194
+ const exact = []
195
+ const prefix = new Set()
196
+ const decl = DECL(symbol)
197
+ const member = MEMBER(symbol)
198
+ for (const { file, text } of files) {
199
+ const lines = text.split("\n")
200
+ lines.forEach((line, i) => {
201
+ if (decl.test(line) || member.test(line)) exact.push(`// ${relative(root, file)}:${i + 1}\n${declarationAt(lines, i)}`)
202
+ else {
203
+ const m = /^\s*(?:export\s+)?(?:declare\s+)?(?:function|class|interface|type|const|enum)\s+([A-Za-z_$][\w$]*)/.exec(line)
204
+ if (m && m[1] !== symbol && m[1].startsWith(symbol)) prefix.add(m[1])
205
+ }
206
+ })
207
+ }
208
+ return { exact, prefix: [...prefix].sort().slice(0, 30) }
209
+ }
210
+
211
+ function pythonFiles(root, found) {
212
+ if (found.single) return [found.single]
213
+ const out = []
214
+ const walk = (dir, depth) => {
215
+ for (const entry of safeList(dir)) {
216
+ if (out.length >= MAX_FILES * 4) return
217
+ const full = join(dir, entry)
218
+ if (entry === "__pycache__" || entry.startsWith(".")) continue
219
+ let st
220
+ try {
221
+ st = statSync(full)
222
+ } catch {
223
+ continue
224
+ }
225
+ if (st.isDirectory() && depth < 4) walk(full, depth + 1)
226
+ else if (/\.pyi?$/.test(entry)) out.push(full)
227
+ }
228
+ }
229
+ walk(found.dir, 0)
230
+ // Stubs first: they are the declared API
231
+ return out.sort((a, b) => Number(b.endsWith(".pyi")) - Number(a.endsWith(".pyi")) || a.localeCompare(b))
232
+ }
233
+
234
+ function searchPython(root, found, symbol) {
235
+ const files = pythonFiles(root, found)
236
+ const stubs = files.filter((f) => f.endsWith(".pyi"))
237
+ const exact = []
238
+ const prefix = new Set()
239
+ const def = new RegExp(String.raw`^(\s*)(?:async\s+)?(?:def|class)\s+${symbol}\b`)
240
+ for (const file of stubs.length ? stubs : files) {
241
+ const text = readInside(root, file)
242
+ if (text === undefined) continue
243
+ const lines = text.split("\n")
244
+ lines.forEach((line, i) => {
245
+ if (def.test(line)) {
246
+ // From stubs the whole signature; from source only the def/class lines (never run, never imported)
247
+ const block = [line]
248
+ for (let k = i + 1; k < lines.length && k < i + 8 && !/:\s*(#.*)?$/.test(lines[k - 1]); k++) block.push(lines[k])
249
+ exact.push(`# ${relative(root, file)}:${i + 1}${stubs.length ? "" : " (source; stubs not shipped)"}\n${block.join("\n")}`)
250
+ } else {
251
+ const m = /^\s*(?:async\s+)?(?:def|class)\s+([A-Za-z_]\w*)/.exec(line)
252
+ if (m && m[1] !== symbol && m[1].startsWith(symbol)) prefix.add(m[1])
253
+ }
254
+ })
255
+ if (exact.length >= 20) break
256
+ }
257
+ return { exact, prefix: [...prefix].sort().slice(0, 30), from: stubs.length ? "stubs" : "source" }
258
+ }
259
+
260
+ /** api_lookup: the installed declaration(s) of `symbol` in `pkg`, with doc comments; exact name, then names starting with it. */
261
+ export function apiLookup(root, pkg, symbol) {
262
+ if (typeof symbol !== "string" || !SYMBOL.test(symbol)) throw new GroundingError("Give one exported name, e.g. createClient.")
263
+ const found = findPackage(root, pkg)
264
+ if (!found) return { package: pkg, symbol, text: `${pkg} isn't installed in this project (node_modules or a .venv).` }
265
+ let result
266
+ let from
267
+ if (found.kind === "npm") {
268
+ const entry = typesEntry(root, pkg)
269
+ if (!entry) return { package: pkg, symbol, text: `${pkg} ships no type definitions and there is no @types/${typesName(pkg)} installed.` }
270
+ result = searchTs(root, declarationFiles(root, entry.file), symbol)
271
+ from = entry.from === "@types" ? `@types/${typesName(pkg)}` : "its type definitions"
272
+ } else {
273
+ result = searchPython(root, found, symbol)
274
+ from = result.from === "stubs" ? "its .pyi stubs" : "its source (def and class lines only)"
275
+ }
276
+ const version = apiVersion(root, pkg).installed
277
+ const head = `${pkg}${version ? ` ${version}` : ""}, from ${from}:`
278
+ const text = result.exact.length
279
+ ? `${head}\n\n${result.exact.slice(0, 20).join("\n\n")}${result.exact.length > 20 ? `\n\n(20 of ${result.exact.length} declarations shown)` : ""}`
280
+ : `${head} no declaration named ${symbol}.${result.prefix.length ? ` Names starting with it: ${result.prefix.join(", ")}.` : ""}`
281
+ return { package: pkg, symbol, found: result.exact.length, text: cut(text) }
282
+ }
283
+
284
+ /* ───────────────────────────── versions ───────────────────────────── */
285
+
286
+ const LOCK_VERSION = (lock, name) => lock?.packages?.[`node_modules/${name}`]?.version ?? lock?.dependencies?.[name]?.version
287
+
288
+ /** api_version: what the project declares, what its lockfile pins, what is installed. */
289
+ export function apiVersion(root, name) {
290
+ const found = findPackage(root, name)
291
+ const out = { package: name }
292
+ const manifest = readJson(root, join(root, "package.json"))
293
+ for (const field of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
294
+ const v = manifest?.[field]?.[name]
295
+ if (typeof v === "string") {
296
+ out.declared = v
297
+ break
298
+ }
299
+ }
300
+ const locked = LOCK_VERSION(readJson(root, join(root, "package-lock.json")), name)
301
+ if (locked) out.locked = locked
302
+ else {
303
+ const pnpm = readInside(root, join(root, "pnpm-lock.yaml"))
304
+ const m = pnpm && new RegExp(String.raw`^\s{2,}'?${name.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}'?:\s*\n(?:\s+specifier:.*\n)?\s+version:\s*'?([0-9][^\s'(]*)`, "m").exec(pnpm)
305
+ if (m) out.locked = m[1]
306
+ }
307
+ if (found?.kind === "npm" && !found.typesOnly) out.installed = readJson(root, join(found.dir, "package.json"))?.version
308
+ if (found?.kind === "python") {
309
+ for (const site of sitePackages(root)) {
310
+ const info = safeList(site).find((d) => new RegExp(String.raw`^${name.replace(/[-_.]/g, "[-_.]")}-([^-]+)\.(dist|egg)-info$`, "i").test(d))
311
+ if (info) {
312
+ out.installed = /-([^-]+)\.(?:dist|egg)-info$/.exec(info)[1]
313
+ break
314
+ }
315
+ }
316
+ if (!out.declared) {
317
+ const req = readInside(root, join(root, "requirements.txt")) ?? ""
318
+ const m = new RegExp(String.raw`^${name.replace(/[-_.]/g, "[-_.]")}\s*([<>=!~][^#\n]*)`, "im").exec(req)
319
+ if (m) out.declared = m[1].trim()
320
+ }
321
+ }
322
+ if (!found) out.note = "not installed"
323
+ return out
324
+ }
325
+
326
+ /* ───────────────────────────── changelog ───────────────────────────── */
327
+
328
+ const parse = (v) => {
329
+ const m = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(String(v ?? ""))
330
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : undefined
331
+ }
332
+ const cmp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]
333
+ const HEADING = /^(#{1,3})\s+\[?v?(\d+\.\d+(?:\.\d+)?)\]?/
334
+
335
+ /**
336
+ * api_changes: the installed package's changelog sections after the version
337
+ * the code was written for (`since`, else the lower bound of what the
338
+ * project declares) up to the installed one.
339
+ */
340
+ export function apiChanges(root, name, since) {
341
+ const found = findPackage(root, name)
342
+ if (!found || found.typesOnly) return { package: name, text: `${name} isn't installed in this project.` }
343
+ const version = apiVersion(root, name)
344
+ const installed = parse(version.installed)
345
+ const from = parse(since) ?? parse(version.declared)
346
+ const dir = found.dir
347
+ const file = safeList(dir).find((f) => /^(changelog|history|changes)(\.md|\.rst|\.txt)?$/i.test(f))
348
+ const text = file && readInside(root, join(dir, file))
349
+ if (!text) return { package: name, installed: version.installed, text: `${name} ${version.installed ?? ""} ships no changelog.`.replace(" ", " ") }
350
+ const lines = text.split("\n")
351
+ const kept = []
352
+ let keep = false
353
+ let level = 0
354
+ for (const line of lines) {
355
+ const h = HEADING.exec(line)
356
+ if (h && (!level || h[1].length <= level)) {
357
+ const v = parse(h[2])
358
+ level = h[1].length
359
+ keep = Boolean(v && (!from || cmp(v, from) > 0) && (!installed || cmp(v, installed) <= 0))
360
+ }
361
+ if (keep) kept.push(line)
362
+ }
363
+ const range = `${from ? from.join(".") : "the start"} → ${version.installed ?? "installed"}`
364
+ return {
365
+ package: name,
366
+ installed: version.installed,
367
+ ...(from && { since: from.join(".") }),
368
+ text: cut(kept.length ? `${name} ${file}, ${range}:\n\n${kept.join("\n").trim()}` : `${name} ${file} has no sections between ${range}.`),
369
+ }
370
+ }
371
+
372
+ /** Whether the project has installed packages at all (for the prompt hint). */
373
+ export const hasInstalled = (root) => existsSync(join(root, "node_modules")) || sitePackages(root).length > 0
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@kriya-ai/harness-grounding",
3
+ "description": "Facts about the project's installed packages from their own type definitions, stubs, changelogs and lockfiles; nothing imported or run",
4
+ "version": "0.1.0",
5
+ "private": true,
6
+ "type": "module",
7
+ "main": "index.js",
8
+ "exports": {
9
+ ".": "./index.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "license": "UNLICENSED"
13
+ }
@@ -33,7 +33,8 @@ export function kriyaSkills({ now = Date.now } = {}) {
33
33
  name: skill.id,
34
34
  description: skill.description,
35
35
  whenToUse: `A Kriya skill (${skill.name}, v${skill.version}). Use when the request is about: ${skill.activation.keywords.slice(0, 12).join(", ")}.`,
36
- invocation: { modelInvocable: true, userInvocable: true },
36
+ // Harness 2.0 cartridges come with modelInvocable false: the loop mounts them, the model's catalogue doesn't list them
37
+ invocation: { modelInvocable: skill.invocation?.modelInvocable !== false, userInvocable: true },
37
38
  source: "custom",
38
39
  provider: "kriya",
39
40
  rank: RANK,