@kynver-app/runtime 0.1.123 → 0.1.128

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 (38) hide show
  1. package/dist/chat/chat-claim-loop.d.ts +11 -0
  2. package/dist/chat/command-allowlist.d.ts +8 -0
  3. package/dist/chat/command-executor.d.ts +13 -0
  4. package/dist/cli.js +54 -17782
  5. package/dist/cron/cron-cli-bin.d.ts +7 -0
  6. package/dist/cron/cron-readiness.d.ts +35 -0
  7. package/dist/disk-gate.d.ts +7 -0
  8. package/dist/index.js +71 -19281
  9. package/dist/mesh-liveness/mesh-cron-lease-store.d.ts +9 -0
  10. package/dist/server/cleanup.js +16 -4054
  11. package/dist/server/default-repo.js +1 -458
  12. package/dist/server/harness-notice.js +15 -287
  13. package/dist/server/heavy-verification.js +1 -223
  14. package/dist/server/landing.js +1 -44
  15. package/dist/server/memory-cost-enforce.js +2 -480
  16. package/dist/server/memory-cost.js +2 -184
  17. package/dist/server/monitor.js +8 -1805
  18. package/dist/server/orchestration.js +1 -444
  19. package/dist/server/pr-evidence.js +1 -163
  20. package/dist/server/repo-search.js +1 -224
  21. package/dist/server/worker-policy.js +1 -432
  22. package/dist/worker-persona-catalog.js +1 -138
  23. package/package.json +3 -2
  24. package/dist/cli.js.map +0 -7
  25. package/dist/index.js.map +0 -7
  26. package/dist/server/cleanup.js.map +0 -7
  27. package/dist/server/default-repo.js.map +0 -7
  28. package/dist/server/harness-notice.js.map +0 -7
  29. package/dist/server/heavy-verification.js.map +0 -7
  30. package/dist/server/landing.js.map +0 -7
  31. package/dist/server/memory-cost-enforce.js.map +0 -7
  32. package/dist/server/memory-cost.js.map +0 -7
  33. package/dist/server/monitor.js.map +0 -7
  34. package/dist/server/orchestration.js.map +0 -7
  35. package/dist/server/pr-evidence.js.map +0 -7
  36. package/dist/server/repo-search.js.map +0 -7
  37. package/dist/server/worker-policy.js.map +0 -7
  38. package/dist/worker-persona-catalog.js.map +0 -7
@@ -1,480 +1,2 @@
1
- // src/installed-package-versions.ts
2
- import { readFile } from "node:fs/promises";
3
- import { homedir as homedir3 } from "node:os";
4
- import path4 from "node:path";
5
-
6
- // src/memory-cost-package-version-guard.ts
7
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
8
- import path3 from "node:path";
9
-
10
- // src/default-repo-discovery.ts
11
- import { existsSync, readFileSync } from "node:fs";
12
- import { homedir as homedir2 } from "node:os";
13
- import path2 from "node:path";
14
- import { fileURLToPath } from "node:url";
15
-
16
- // src/git.ts
17
- import { spawnSync } from "node:child_process";
18
-
19
- // src/util.ts
20
- function hiddenSpawnOptions(opts) {
21
- if (process.platform !== "win32") return opts;
22
- return { windowsHide: true, ...opts };
23
- }
24
-
25
- // src/worker-env.ts
26
- var FORBIDDEN_WORKER_ENV_KEYS = [
27
- "ANTHROPIC_API_KEY",
28
- "ANALYST_API_KEY",
29
- "RECRUITER_API_KEY",
30
- "AUTH_SECRET",
31
- "NEXTAUTH_SECRET",
32
- "DATABASE_URL",
33
- "PRODUCTION_DATABASE_URL",
34
- "KYNVER_PRODUCTION_DATABASE_URL",
35
- "REDIS_URL",
36
- "GOOGLE_CLIENT_SECRET",
37
- "GITHUB_CLIENT_SECRET",
38
- "KYNVER_API_KEY",
39
- "KYNVER_SERVICE_SECRET",
40
- "KYNVER_RUNTIME_SECRET",
41
- "KYNVER_CRON_SECRET",
42
- "OPENCLAW_CRON_SECRET",
43
- "QSTASH_TOKEN",
44
- "QSTASH_CURRENT_SIGNING_KEY",
45
- "QSTASH_NEXT_SIGNING_KEY",
46
- "TOOL_SECRETS_KEK",
47
- "TOOL_EXECUTOR_DISPATCH_SECRET",
48
- "CLOUDFLARE_API_TOKEN",
49
- "STRIPE_SECRET_KEY",
50
- "STRIPE_WEBHOOK_SECRET",
51
- "STRIPE_IDENTITY_WEBHOOK_SECRET",
52
- "VOYAGE_API_KEY",
53
- "PERPLEXITY_API_KEY",
54
- "FRED_API_KEY",
55
- "FMP_API_KEY",
56
- "CURSOR_API_KEY"
57
- ];
58
- var FORBIDDEN_KEY_SET = new Set(FORBIDDEN_WORKER_ENV_KEYS);
59
-
60
- // src/git.ts
61
- function gitCapture(cwd, args) {
62
- try {
63
- const res = spawnSync(
64
- "git",
65
- args,
66
- hiddenSpawnOptions({ cwd, encoding: "utf8" })
67
- );
68
- return {
69
- status: res.status,
70
- stdout: res.stdout || "",
71
- stderr: res.stderr || "",
72
- error: res.error ? res.error.message : null
73
- };
74
- } catch (error) {
75
- return {
76
- status: null,
77
- stdout: "",
78
- stderr: "",
79
- error: error.message
80
- };
81
- }
82
- }
83
-
84
- // src/path-values.ts
85
- import { homedir } from "node:os";
86
- import path from "node:path";
87
- function expandHomePath(value) {
88
- if (value === "~") return homedir();
89
- if (value.startsWith("~/") || value.startsWith("~\\")) {
90
- return path.join(homedir(), value.slice(2));
91
- }
92
- return value;
93
- }
94
- function resolveUserPath(value) {
95
- return path.resolve(expandHomePath(value));
96
- }
97
-
98
- // src/default-repo-discovery.ts
99
- var WELL_KNOWN_REPO_DIRS = [
100
- "Kynver",
101
- "repos/Kynver",
102
- "repos/kynver-source-main",
103
- "code/Kynver",
104
- "projects/Kynver"
105
- ];
106
- function readPackageName(repoRoot) {
107
- const pkgPath = path2.join(repoRoot, "package.json");
108
- if (!existsSync(pkgPath)) return null;
109
- try {
110
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
111
- return typeof pkg.name === "string" ? pkg.name.trim() : null;
112
- } catch {
113
- return null;
114
- }
115
- }
116
- function isKynverMonorepoRoot(repoRoot) {
117
- return readPackageName(repoRoot) === "kynver";
118
- }
119
- function gitRepoRoot(startDir) {
120
- const resolvedStart = path2.resolve(startDir);
121
- if (!existsSync(resolvedStart)) return null;
122
- const probe = gitCapture(resolvedStart, ["rev-parse", "--show-toplevel"]);
123
- if (probe.status !== 0) return null;
124
- const root = probe.stdout.trim();
125
- return root.length ? path2.resolve(root) : null;
126
- }
127
- function resolveRuntimePackageRoot(moduleUrl = import.meta.url) {
128
- let dir = path2.dirname(fileURLToPath(moduleUrl));
129
- for (let depth = 0; depth < 8; depth += 1) {
130
- const pkgPath = path2.join(dir, "package.json");
131
- if (existsSync(pkgPath)) {
132
- try {
133
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
134
- if (pkg.name === "@kynver-app/runtime") return dir;
135
- } catch {
136
- }
137
- }
138
- const parent = path2.dirname(dir);
139
- if (parent === dir) break;
140
- dir = parent;
141
- }
142
- return null;
143
- }
144
- function pushCandidate(seen, out, repo, source) {
145
- if (!repo) return;
146
- const resolved = path2.resolve(repo);
147
- if (seen.has(resolved)) return;
148
- if (!isKynverMonorepoRoot(resolved)) return;
149
- seen.add(resolved);
150
- out.push({ repo: resolved, source });
151
- }
152
- function discoverDefaultRepoCandidates(opts) {
153
- const cwd = opts?.cwd ?? process.cwd();
154
- const seen = /* @__PURE__ */ new Set();
155
- const candidates = [];
156
- pushCandidate(seen, candidates, gitRepoRoot(cwd), "cwd_git");
157
- const runtimePkgRoot = resolveRuntimePackageRoot(opts?.runtimeModuleUrl ?? import.meta.url);
158
- if (runtimePkgRoot) {
159
- pushCandidate(seen, candidates, gitRepoRoot(runtimePkgRoot), "runtime_checkout");
160
- }
161
- const home = homedir2();
162
- for (const rel of WELL_KNOWN_REPO_DIRS) {
163
- pushCandidate(seen, candidates, resolveUserPath(path2.join(home, rel)), "well_known_path");
164
- }
165
- return candidates;
166
- }
167
- function discoverDefaultRepo(opts) {
168
- return discoverDefaultRepoCandidates(opts)[0] ?? null;
169
- }
170
-
171
- // src/memory-cost-package-version-guard.ts
172
- var MEMORY_COST_PACKAGE_MIN_VERSIONS = {
173
- "@kynver-app/runtime": "0.1.83",
174
- "@kynver-app/openclaw-agent-os": "0.1.43",
175
- "@kynver-app/mcp-agent-os": "0.3.34"
176
- };
177
- var MEMORY_COST_MANAGED_PACKAGES = Object.keys(
178
- MEMORY_COST_PACKAGE_MIN_VERSIONS
179
- );
180
- var DISPLAY_NAMES = {
181
- "@kynver-app/runtime": "Kynver runtime",
182
- "@kynver-app/openclaw-agent-os": "OpenClaw AgentOS plugin",
183
- "@kynver-app/mcp-agent-os": "AgentOS MCP server"
184
- };
185
- var REPO_PACKAGE_JSON_RELATIVE = {
186
- "@kynver-app/runtime": "packages/kynver-runtime/package.json",
187
- "@kynver-app/openclaw-agent-os": "packages/kynver-openclaw-agent-os/package.json",
188
- "@kynver-app/mcp-agent-os": "packages/kynver-mcp-agent-os/package.json"
189
- };
190
- function parseSemverParts(version) {
191
- const core = version.trim().split("-")[0]?.split("+")[0];
192
- if (!core) return null;
193
- const parts = core.split(".");
194
- if (parts.length < 1 || parts.length > 3) return null;
195
- const nums = parts.map((p) => Number.parseInt(p, 10));
196
- if (nums.some((n) => !Number.isFinite(n) || n < 0)) return null;
197
- while (nums.length < 3) nums.push(0);
198
- return [nums[0], nums[1], nums[2]];
199
- }
200
- function compareSemver(a, b) {
201
- const pa = parseSemverParts(a);
202
- const pb = parseSemverParts(b);
203
- if (!pa || !pb) return 0;
204
- for (let i = 0; i < 3; i += 1) {
205
- if (pa[i] > pb[i]) return 1;
206
- if (pa[i] < pb[i]) return -1;
207
- }
208
- return 0;
209
- }
210
- function semverAtLeast(version, minimum) {
211
- return compareSemver(version, minimum) >= 0;
212
- }
213
- function maxSemver(versions) {
214
- let best = null;
215
- for (const version of versions) {
216
- if (!best || compareSemver(version, best) > 0) best = version;
217
- }
218
- return best;
219
- }
220
- function readPackageJsonVersion(packageJsonPath) {
221
- try {
222
- const parsed = JSON.parse(readFileSync2(packageJsonPath, "utf8"));
223
- return typeof parsed.version === "string" && parsed.version.trim() ? parsed.version.trim() : null;
224
- } catch {
225
- return null;
226
- }
227
- }
228
- function resolveRepoRoot(cwd, explicitRepoRoot) {
229
- const candidates = [explicitRepoRoot, process.env.KYNVER_REPO, cwd].filter(
230
- (value) => Boolean(value?.trim())
231
- );
232
- for (const candidate of candidates) {
233
- const resolved = path3.resolve(candidate);
234
- if (existsSync2(path3.join(resolved, "packages/kynver-runtime/package.json")) && existsSync2(path3.join(resolved, "package.json"))) {
235
- return resolved;
236
- }
237
- }
238
- const discovered = discoverDefaultRepo({ cwd });
239
- return discovered?.repo ?? null;
240
- }
241
- function probeRepoPackageVersions(input = {}) {
242
- const cwd = input.cwd ?? process.cwd();
243
- const repoRoot = resolveRepoRoot(cwd, input.repoRoot);
244
- if (!repoRoot) return {};
245
- const out = {};
246
- for (const packageName of MEMORY_COST_MANAGED_PACKAGES) {
247
- const packageJsonPath = path3.join(repoRoot, REPO_PACKAGE_JSON_RELATIVE[packageName]);
248
- const version = readPackageJsonVersion(packageJsonPath);
249
- if (!version) continue;
250
- out[packageName] = { version, source: "repo", path: packageJsonPath };
251
- }
252
- return out;
253
- }
254
- function repoSourceCommands(packageName) {
255
- if (packageName === "@kynver-app/runtime") {
256
- return ["npm run kynver:build", "npm run kynver"];
257
- }
258
- return [`npm run build -w ${packageName}`];
259
- }
260
- function buildRemediation(input) {
261
- const { packageName, minimumVersion, effectiveVersion, effectiveSource, repoVersion } = input;
262
- const lines = [];
263
- if (repoVersion && semverAtLeast(repoVersion, minimumVersion)) {
264
- lines.push(
265
- `Use the monorepo checkout (${repoVersion}) instead of a stale npm install: ${repoSourceCommands(packageName).join("; ")}.`
266
- );
267
- lines.push("Do not publish npm packages or wait on an operator release.");
268
- return lines;
269
- }
270
- if (effectiveVersion) {
271
- lines.push(
272
- `Upgrade ${packageName} from ${effectiveVersion} to >= ${minimumVersion} (npm install -g ${packageName}@latest or align OpenClaw npm prefix).`
273
- );
274
- } else {
275
- lines.push(`Install ${packageName} >= ${minimumVersion} before running memory-heavy AgentOS paths.`);
276
- }
277
- if (packageName === "@kynver-app/runtime") {
278
- lines.push("Repo-source alternative: npm run kynver:build && npm run kynver");
279
- }
280
- if (effectiveSource === "installed" && repoVersion) {
281
- lines.push(`Repo checkout reports ${repoVersion}; rebuild/link repo source if you develop from the monorepo.`);
282
- }
283
- return lines;
284
- }
285
- function pickEffectiveCandidate(candidates) {
286
- if (candidates.length === 0) return { version: null, source: "unknown" };
287
- const best = maxSemver(candidates.map((candidate) => candidate.version));
288
- if (!best) return { version: null, source: "unknown" };
289
- const winner = candidates.find((candidate) => candidate.version === best) ?? candidates[0];
290
- return { version: winner.version, source: winner.source };
291
- }
292
- function evaluateMemoryCostPackageVersionGuard(input = {}) {
293
- const normalize = (value, fallbackSource) => {
294
- if (!value) return null;
295
- if (typeof value === "string") return { version: value, source: fallbackSource };
296
- return value;
297
- };
298
- const packages = MEMORY_COST_MANAGED_PACKAGES.map((packageName) => {
299
- const minimumVersion = MEMORY_COST_PACKAGE_MIN_VERSIONS[packageName];
300
- const candidates = [];
301
- const installed = normalize(input.installed?.[packageName], "installed");
302
- const repo = normalize(input.repo?.[packageName], "repo");
303
- const self = normalize(input.self?.[packageName], "self");
304
- if (installed) candidates.push(installed);
305
- if (repo) candidates.push(repo);
306
- if (self) candidates.push(self);
307
- const { version: effectiveVersion, source: effectiveSource } = pickEffectiveCandidate(candidates);
308
- const repoVersion = repo?.version ?? null;
309
- const ok2 = effectiveVersion ? semverAtLeast(effectiveVersion, minimumVersion) : false;
310
- const remediation = ok2 ? [] : buildRemediation({
311
- packageName,
312
- minimumVersion,
313
- effectiveVersion,
314
- effectiveSource,
315
- repoVersion
316
- });
317
- const summary2 = ok2 ? `${DISPLAY_NAMES[packageName]} ${effectiveVersion} meets memory-cost minimum ${minimumVersion} (${effectiveSource}).` : `${DISPLAY_NAMES[packageName]} is below memory-cost minimum ${minimumVersion}` + (effectiveVersion ? ` (effective ${effectiveVersion} via ${effectiveSource})` : " (no version detected)") + ".";
318
- return {
319
- packageName,
320
- displayName: DISPLAY_NAMES[packageName],
321
- minimumVersion,
322
- effectiveVersion,
323
- effectiveSource,
324
- ok: ok2,
325
- summary: summary2,
326
- remediation
327
- };
328
- });
329
- const violations = packages.filter((row) => !row.ok);
330
- const ok = violations.length === 0;
331
- const summary = ok ? "All managed AgentOS packages meet memory-cost minimum versions." : `Memory-cost package guard blocked ${violations.length} stale package(s): ${violations.map((row) => `${row.packageName} < ${row.minimumVersion}`).join("; ")}.`;
332
- return { ok, summary, packages };
333
- }
334
- var MemoryCostPackageVersionGuardError = class extends Error {
335
- result;
336
- constructor(result) {
337
- const lines = [
338
- result.summary,
339
- ...result.packages.filter((row) => !row.ok).flatMap((row) => [`- ${row.summary}`, ...row.remediation.map((line) => ` \u2192 ${line}`)])
340
- ];
341
- super(lines.join("\n"));
342
- this.name = "MemoryCostPackageVersionGuardError";
343
- this.result = result;
344
- }
345
- };
346
- function assertMemoryCostPackageVersionGuard(input = {}) {
347
- const result = evaluateMemoryCostPackageVersionGuard(input);
348
- if (!result.ok) throw new MemoryCostPackageVersionGuardError(result);
349
- return result;
350
- }
351
-
352
- // src/installed-package-versions.ts
353
- var MANAGED_PACKAGES = [
354
- "@kynver-app/runtime",
355
- "@kynver-app/openclaw-agent-os",
356
- "@kynver-app/mcp-agent-os"
357
- ];
358
- function trim(value) {
359
- const out = value?.trim();
360
- return out ? out : null;
361
- }
362
- function unique(values) {
363
- return [...new Set(values.filter((value) => Boolean(value)))];
364
- }
365
- function moduleRoots() {
366
- const home = homedir3();
367
- const openClawPrefix = trim(process.env.KYNVER_OPENCLAW_NPM_ROOT) ?? trim(process.env.OPENCLAW_NPM_ROOT) ?? path4.join(home, ".openclaw", "npm");
368
- const npmGlobalRoot = trim(process.env.KYNVER_NPM_GLOBAL_ROOT) ?? trim(process.env.KYNVER_NPM_GLOBAL_MODULES_ROOT) ?? (trim(process.env.NPM_CONFIG_PREFIX) ? path4.join(trim(process.env.NPM_CONFIG_PREFIX), "lib", "node_modules") : path4.join(home, ".npm-global", "lib", "node_modules"));
369
- return unique([
370
- path4.join(openClawPrefix, "lib", "node_modules"),
371
- path4.join(openClawPrefix, "node_modules"),
372
- npmGlobalRoot.endsWith("node_modules") ? npmGlobalRoot : path4.join(npmGlobalRoot, "lib", "node_modules")
373
- ]);
374
- }
375
- async function readVersion(packageJsonPath) {
376
- try {
377
- const parsed = JSON.parse(await readFile(packageJsonPath, "utf8"));
378
- return typeof parsed.version === "string" && parsed.version.trim() ? parsed.version.trim() : null;
379
- } catch {
380
- return null;
381
- }
382
- }
383
- function installedPackageJsonCandidates(packageName) {
384
- const roots = moduleRoots();
385
- const seen = /* @__PURE__ */ new Set();
386
- const out = [];
387
- for (const root of roots) {
388
- const candidate = path4.join(root, packageName, "package.json");
389
- if (seen.has(candidate)) continue;
390
- seen.add(candidate);
391
- out.push(candidate);
392
- }
393
- return out;
394
- }
395
- async function collectInstalledPackageVersions(observedAt = (/* @__PURE__ */ new Date()).toISOString()) {
396
- const out = {};
397
- for (const packageName of MANAGED_PACKAGES) {
398
- let best = null;
399
- for (const packageJsonPath of installedPackageJsonCandidates(packageName)) {
400
- const version = await readVersion(packageJsonPath);
401
- if (!version) continue;
402
- if (!best || compareSemver(version, best.version) > 0) {
403
- best = { version, path: packageJsonPath };
404
- }
405
- }
406
- if (best) {
407
- out[packageName] = { version: best.version, observedAt, path: best.path };
408
- }
409
- }
410
- return out;
411
- }
412
-
413
- // src/package-version.ts
414
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
415
- import { dirname, join } from "node:path";
416
- import { fileURLToPath as fileURLToPath2 } from "node:url";
417
- function resolvePackageRoot(moduleUrl) {
418
- let dir = dirname(fileURLToPath2(moduleUrl));
419
- for (let depth = 0; depth < 6; depth += 1) {
420
- if (existsSync3(join(dir, "package.json"))) return dir;
421
- const parent = dirname(dir);
422
- if (parent === dir) break;
423
- dir = parent;
424
- }
425
- throw new Error(`package.json not found above ${dirname(fileURLToPath2(moduleUrl))}`);
426
- }
427
- function readOwnPackageVersion(moduleUrl = import.meta.url) {
428
- const pkgPath = join(resolvePackageRoot(moduleUrl), "package.json");
429
- const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
430
- if (typeof pkg.version !== "string" || !pkg.version.trim()) {
431
- throw new Error(`Missing package.json version at ${pkgPath}`);
432
- }
433
- return pkg.version;
434
- }
435
- var PACKAGE_VERSION = readOwnPackageVersion();
436
-
437
- // src/memory-cost-package-version-guard-enforce.ts
438
- function installedVersionMap(observed) {
439
- const out = {};
440
- for (const [packageName, row] of Object.entries(observed)) {
441
- if (!row?.version) continue;
442
- out[packageName] = {
443
- version: row.version,
444
- source: "installed",
445
- path: row.path
446
- };
447
- }
448
- return out;
449
- }
450
- async function buildMemoryCostPackageGuardInput(input = {}) {
451
- const [installed, repo] = await Promise.all([
452
- collectInstalledPackageVersions(),
453
- Promise.resolve(probeRepoPackageVersions({ cwd: input.cwd, repoRoot: input.repoRoot }))
454
- ]);
455
- const self = {};
456
- const runtimeSelfVersion = input.selfPackageName === "@kynver-app/runtime" && input.selfVersion ? input.selfVersion : PACKAGE_VERSION;
457
- self["@kynver-app/runtime"] = { version: runtimeSelfVersion, source: "self" };
458
- if (input.selfPackageName && input.selfVersion && input.selfPackageName !== "@kynver-app/runtime") {
459
- self[input.selfPackageName] = { version: input.selfVersion, source: "self" };
460
- }
461
- return {
462
- installed: installedVersionMap(installed),
463
- repo,
464
- self
465
- };
466
- }
467
- async function evaluateMemoryCostPackageGuardAtStartup(input = {}) {
468
- const guardInput = await buildMemoryCostPackageGuardInput(input);
469
- return evaluateMemoryCostPackageVersionGuard(guardInput);
470
- }
471
- async function enforceMemoryCostPackageGuardAtStartup(input = {}) {
472
- const guardInput = await buildMemoryCostPackageGuardInput(input);
473
- return assertMemoryCostPackageVersionGuard(guardInput);
474
- }
475
- export {
476
- buildMemoryCostPackageGuardInput,
477
- enforceMemoryCostPackageGuardAtStartup,
478
- evaluateMemoryCostPackageGuardAtStartup
479
- };
480
- //# sourceMappingURL=memory-cost-enforce.js.map
1
+ import{readFile as ge}from"node:fs/promises";import{homedir as de}from"node:os";import l from"node:path";import{existsSync as T,readFileSync as se}from"node:fs";import d from"node:path";import{existsSync as P,readFileSync as I}from"node:fs";import{homedir as Z}from"node:os";import a from"node:path";import{fileURLToPath as q}from"node:url";import{spawnSync as z}from"node:child_process";function M(e){return process.platform!=="win32"?e:{windowsHide:!0,...e}}var X=["ANTHROPIC_API_KEY","ANALYST_API_KEY","RECRUITER_API_KEY","AUTH_SECRET","NEXTAUTH_SECRET","DATABASE_URL","PRODUCTION_DATABASE_URL","KYNVER_PRODUCTION_DATABASE_URL","REDIS_URL","GOOGLE_CLIENT_SECRET","GITHUB_CLIENT_SECRET","KYNVER_API_KEY","KYNVER_SERVICE_SECRET","KYNVER_RUNTIME_SECRET","KYNVER_CRON_SECRET","OPENCLAW_CRON_SECRET","QSTASH_TOKEN","QSTASH_CURRENT_SIGNING_KEY","QSTASH_NEXT_SIGNING_KEY","TOOL_SECRETS_KEK","TOOL_EXECUTOR_DISPATCH_SECRET","CLOUDFLARE_API_TOKEN","STRIPE_SECRET_KEY","STRIPE_WEBHOOK_SECRET","STRIPE_IDENTITY_WEBHOOK_SECRET","VOYAGE_API_KEY","PERPLEXITY_API_KEY","FRED_API_KEY","FMP_API_KEY","CURSOR_API_KEY"],be=new Set(X);function b(e,r){try{let t=z("git",r,M({cwd:e,encoding:"utf8"}));return{status:t.status,stdout:t.stdout||"",stderr:t.stderr||"",error:t.error?t.error.message:null}}catch(t){return{status:null,stdout:"",stderr:"",error:t.message}}}import{homedir as x}from"node:os";import N from"node:path";function Q(e){return e==="~"?x():e.startsWith("~/")||e.startsWith("~\\")?N.join(x(),e.slice(2)):e}function O(e){return N.resolve(Q(e))}var ee=["Kynver","repos/Kynver","repos/kynver-source-main","code/Kynver","projects/Kynver"];function re(e){let r=a.join(e,"package.json");if(!P(r))return null;try{let t=JSON.parse(I(r,"utf8"));return typeof t.name=="string"?t.name.trim():null}catch{return null}}function te(e){return re(e)==="kynver"}function w(e){let r=a.resolve(e);if(!P(r))return null;let t=b(r,["rev-parse","--show-toplevel"]);if(t.status!==0)return null;let n=t.stdout.trim();return n.length?a.resolve(n):null}function ne(e=import.meta.url){let r=a.dirname(q(e));for(let t=0;t<8;t+=1){let n=a.join(r,"package.json");if(P(n))try{if(JSON.parse(I(n,"utf8")).name==="@kynver-app/runtime")return r}catch{}let o=a.dirname(r);if(o===r)break;r=o}return null}function v(e,r,t,n){if(!t)return;let o=a.resolve(t);e.has(o)||te(o)&&(e.add(o),r.push({repo:o,source:n}))}function oe(e){let r=e?.cwd??process.cwd(),t=new Set,n=[];v(t,n,w(r),"cwd_git");let o=ne(e?.runtimeModuleUrl??import.meta.url);o&&v(t,n,w(o),"runtime_checkout");let i=Z();for(let s of ee)v(t,n,O(a.join(i,s)),"well_known_path");return n}function V(e){return oe(e)[0]??null}var D={"@kynver-app/runtime":"0.1.83","@kynver-app/openclaw-agent-os":"0.1.43","@kynver-app/mcp-agent-os":"0.3.34"},K=Object.keys(D),E={"@kynver-app/runtime":"Kynver runtime","@kynver-app/openclaw-agent-os":"OpenClaw AgentOS plugin","@kynver-app/mcp-agent-os":"AgentOS MCP server"},ie={"@kynver-app/runtime":"packages/kynver-runtime/package.json","@kynver-app/openclaw-agent-os":"packages/kynver-openclaw-agent-os/package.json","@kynver-app/mcp-agent-os":"packages/kynver-mcp-agent-os/package.json"};function G(e){let r=e.trim().split("-")[0]?.split("+")[0];if(!r)return null;let t=r.split(".");if(t.length<1||t.length>3)return null;let n=t.map(o=>Number.parseInt(o,10));if(n.some(o=>!Number.isFinite(o)||o<0))return null;for(;n.length<3;)n.push(0);return[n[0],n[1],n[2]]}function f(e,r){let t=G(e),n=G(r);if(!t||!n)return 0;for(let o=0;o<3;o+=1){if(t[o]>n[o])return 1;if(t[o]<n[o])return-1}return 0}function $(e,r){return f(e,r)>=0}function ae(e){let r=null;for(let t of e)(!r||f(t,r)>0)&&(r=t);return r}function ue(e){try{let r=JSON.parse(se(e,"utf8"));return typeof r.version=="string"&&r.version.trim()?r.version.trim():null}catch{return null}}function ce(e,r){let t=[r,process.env.KYNVER_REPO,e].filter(o=>!!o?.trim());for(let o of t){let i=d.resolve(o);if(T(d.join(i,"packages/kynver-runtime/package.json"))&&T(d.join(i,"package.json")))return i}return V({cwd:e})?.repo??null}function j(e={}){let r=e.cwd??process.cwd(),t=ce(r,e.repoRoot);if(!t)return{};let n={};for(let o of K){let i=d.join(t,ie[o]),s=ue(i);s&&(n[o]={version:s,source:"repo",path:i})}return n}function le(e){return e==="@kynver-app/runtime"?["npm run kynver:build","npm run kynver"]:[`npm run build -w ${e}`]}function pe(e){let{packageName:r,minimumVersion:t,effectiveVersion:n,effectiveSource:o,repoVersion:i}=e,s=[];return i&&$(i,t)?(s.push(`Use the monorepo checkout (${i}) instead of a stale npm install: ${le(r).join("; ")}.`),s.push("Do not publish npm packages or wait on an operator release."),s):(n?s.push(`Upgrade ${r} from ${n} to >= ${t} (npm install -g ${r}@latest or align OpenClaw npm prefix).`):s.push(`Install ${r} >= ${t} before running memory-heavy AgentOS paths.`),r==="@kynver-app/runtime"&&s.push("Repo-source alternative: npm run kynver:build && npm run kynver"),o==="installed"&&i&&s.push(`Repo checkout reports ${i}; rebuild/link repo source if you develop from the monorepo.`),s)}function me(e){if(e.length===0)return{version:null,source:"unknown"};let r=ae(e.map(n=>n.version));if(!r)return{version:null,source:"unknown"};let t=e.find(n=>n.version===r)??e[0];return{version:t.version,source:t.source}}function R(e={}){let r=(s,u)=>s?typeof s=="string"?{version:s,source:u}:s:null,t=K.map(s=>{let u=D[s],m=[],_=r(e.installed?.[s],"installed"),y=r(e.repo?.[s],"repo"),A=r(e.self?.[s],"self");_&&m.push(_),y&&m.push(y),A&&m.push(A);let{version:c,source:g}=me(m),B=y?.version??null,k=c?$(c,u):!1,J=k?[]:pe({packageName:s,minimumVersion:u,effectiveVersion:c,effectiveSource:g,repoVersion:B}),W=k?`${E[s]} ${c} meets memory-cost minimum ${u} (${g}).`:`${E[s]} is below memory-cost minimum ${u}`+(c?` (effective ${c} via ${g})`:" (no version detected)")+".";return{packageName:s,displayName:E[s],minimumVersion:u,effectiveVersion:c,effectiveSource:g,ok:k,summary:W,remediation:J}}),n=t.filter(s=>!s.ok),o=n.length===0,i=o?"All managed AgentOS packages meet memory-cost minimum versions.":`Memory-cost package guard blocked ${n.length} stale package(s): ${n.map(s=>`${s.packageName} < ${s.minimumVersion}`).join("; ")}.`;return{ok:o,summary:i,packages:t}}var C=class extends Error{result;constructor(r){let t=[r.summary,...r.packages.filter(n=>!n.ok).flatMap(n=>[`- ${n.summary}`,...n.remediation.map(o=>` \u2192 ${o}`)])];super(t.join(`
2
+ `)),this.name="MemoryCostPackageVersionGuardError",this.result=r}};function Y(e={}){let r=R(e);if(!r.ok)throw new C(r);return r}var fe=["@kynver-app/runtime","@kynver-app/openclaw-agent-os","@kynver-app/mcp-agent-os"];function p(e){let r=e?.trim();return r||null}function ye(e){return[...new Set(e.filter(r=>!!r))]}function ke(){let e=de(),r=p(process.env.KYNVER_OPENCLAW_NPM_ROOT)??p(process.env.OPENCLAW_NPM_ROOT)??l.join(e,".openclaw","npm"),t=p(process.env.KYNVER_NPM_GLOBAL_ROOT)??p(process.env.KYNVER_NPM_GLOBAL_MODULES_ROOT)??(p(process.env.NPM_CONFIG_PREFIX)?l.join(p(process.env.NPM_CONFIG_PREFIX),"lib","node_modules"):l.join(e,".npm-global","lib","node_modules"));return ye([l.join(r,"lib","node_modules"),l.join(r,"node_modules"),t.endsWith("node_modules")?t:l.join(t,"lib","node_modules")])}async function ve(e){try{let r=JSON.parse(await ge(e,"utf8"));return typeof r.version=="string"&&r.version.trim()?r.version.trim():null}catch{return null}}function Pe(e){let r=ke(),t=new Set,n=[];for(let o of r){let i=l.join(o,e,"package.json");t.has(i)||(t.add(i),n.push(i))}return n}async function L(e=new Date().toISOString()){let r={};for(let t of fe){let n=null;for(let o of Pe(t)){let i=await ve(o);i&&(!n||f(i,n.version)>0)&&(n={version:i,path:o})}n&&(r[t]={version:n.version,observedAt:e,path:n.path})}return r}import{existsSync as Ee,readFileSync as Ce}from"node:fs";import{dirname as S,join as U}from"node:path";import{fileURLToPath as F}from"node:url";function Re(e){let r=S(F(e));for(let t=0;t<6;t+=1){if(Ee(U(r,"package.json")))return r;let n=S(r);if(n===r)break;r=n}throw new Error(`package.json not found above ${S(F(e))}`)}function Se(e=import.meta.url){let r=U(Re(e),"package.json"),t=JSON.parse(Ce(r,"utf8"));if(typeof t.version!="string"||!t.version.trim())throw new Error(`Missing package.json version at ${r}`);return t.version}var H=Se();function he(e){let r={};for(let[t,n]of Object.entries(e))n?.version&&(r[t]={version:n.version,source:"installed",path:n.path});return r}async function h(e={}){let[r,t]=await Promise.all([L(),Promise.resolve(j({cwd:e.cwd,repoRoot:e.repoRoot}))]),n={},o=e.selfPackageName==="@kynver-app/runtime"&&e.selfVersion?e.selfVersion:H;return n["@kynver-app/runtime"]={version:o,source:"self"},e.selfPackageName&&e.selfVersion&&e.selfPackageName!=="@kynver-app/runtime"&&(n[e.selfPackageName]={version:e.selfVersion,source:"self"}),{installed:he(r),repo:t,self:n}}async function _e(e={}){let r=await h(e);return R(r)}async function Ae(e={}){let r=await h(e);return Y(r)}export{h as buildMemoryCostPackageGuardInput,Ae as enforceMemoryCostPackageGuardAtStartup,_e as evaluateMemoryCostPackageGuardAtStartup};