ygl-trees 0.66.0 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- //#region \0rolldown/runtime.js
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __esmMin = (fn, res, err) => () => {
11
- if (err) throw err[0];
12
- try {
13
- return fn && (res = fn(fn = 0)), res;
14
- } catch (e) {
15
- throw err = [e], e;
16
- }
17
- };
18
- var __exportAll = (all, no_symbols) => {
19
- let target = {};
20
- for (var name in all) __defProp(target, name, {
21
- get: all[name],
22
- enumerable: true
23
- });
24
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
25
- return target;
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
29
- key = keys[i];
30
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
31
- get: ((k) => from[k]).bind(null, key),
32
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
33
- });
34
- }
35
- return to;
36
- };
37
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
38
- value: mod,
39
- enumerable: true
40
- }) : target, mod));
41
- var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
- //#endregion
3
+ const require_rolldown_runtime = require("./rolldown-runtime-C96Ew50Q.cjs");
43
4
  let node_os = require("node:os");
44
- node_os = __toESM(node_os);
5
+ node_os = require_rolldown_runtime.__toESM(node_os);
45
6
  let node_path = require("node:path");
46
- node_path = __toESM(node_path);
7
+ node_path = require_rolldown_runtime.__toESM(node_path);
47
8
  let node_sqlite3_wasm = require("node-sqlite3-wasm");
48
9
  let node_fs = require("node:fs");
49
- node_fs = __toESM(node_fs);
10
+ node_fs = require_rolldown_runtime.__toESM(node_fs);
50
11
  let node_crypto = require("node:crypto");
51
12
  let _deepseek_ai_cordis = require("@deepseek-ai/cordis");
52
13
  let _deepseek_ai_cordis_plugin_timer = require("@deepseek-ai/cordis-plugin-timer");
53
- _deepseek_ai_cordis_plugin_timer = __toESM(_deepseek_ai_cordis_plugin_timer);
14
+ _deepseek_ai_cordis_plugin_timer = require_rolldown_runtime.__toESM(_deepseek_ai_cordis_plugin_timer);
54
15
  let node_child_process = require("node:child_process");
55
16
  let _deepseek_ai_dsh_atomic_write = require("@deepseek-ai/dsh-atomic-write");
56
17
  require("reflect-metadata");
57
18
  let typeorm = require("typeorm");
58
19
  let _deepseek_ai_schemastery = require("@deepseek-ai/schemastery");
59
- _deepseek_ai_schemastery = __toESM(_deepseek_ai_schemastery);
20
+ _deepseek_ai_schemastery = require_rolldown_runtime.__toESM(_deepseek_ai_schemastery);
60
21
  //#region packages/core/text/src/text.ts
61
- var text_exports = /* @__PURE__ */ __exportAll({
22
+ var text_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
62
23
  clip: () => clip,
63
24
  contentHash: () => contentHash,
64
25
  ngram: () => ngram,
@@ -167,7 +128,7 @@ function splitTags(v) {
167
128
  return (v || "").split(/[,,;;\s]+/).map((s) => s.trim()).filter(Boolean);
168
129
  }
169
130
  var CJK, CJK_RUN_RE, CJK_ONLY_RE;
170
- var init_text = __esmMin((() => {
131
+ var init_text = require_rolldown_runtime.__esmMin((() => {
171
132
  CJK = "\\u4e00-\\u9fff\\u3400-\\u4dbf\\uf900-\\ufaff";
172
133
  new RegExp(`[${CJK}]`, "u");
173
134
  CJK_RUN_RE = new RegExp(`[${CJK}]+|[^\\s${CJK}]+`, "gu");
@@ -181,7 +142,7 @@ var init_text = __esmMin((() => {
181
142
  * Everything — skills, research state, evidence, drafts, knowledge notes and
182
143
  * schedules — lives in one SQLite file. No sidecar JSON, no git-as-database.
183
144
  */
184
- var db_exports = /* @__PURE__ */ __exportAll({
145
+ var db_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
185
146
  COND_KINDS: () => COND_KINDS,
186
147
  DB: () => DB,
187
148
  EDGE_MODES: () => EDGE_MODES,
@@ -195,7 +156,7 @@ function dbPath(home) {
195
156
  return node_path.join(home, "ygl-trees.db");
196
157
  }
197
158
  var SCHEMA_SQL, DB, EDGE_RELS, EDGE_MODES, COND_KINDS;
198
- var init_db = __esmMin((() => {
159
+ var init_db = require_rolldown_runtime.__esmMin((() => {
199
160
  init_text();
200
161
  SCHEMA_SQL = `
201
162
  -- ---------------------------------------------------------------- meta
@@ -550,35 +511,50 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_skill_refs ON skill_refs(skill_id, path);
550
511
  this.path = file;
551
512
  node_fs.mkdirSync(node_path.dirname(file), { recursive: true });
552
513
  const useLock = opts?.lock === true;
553
- const lockDir = `${file}.lock`;
514
+ const legacyLockDir = `${file}.lock`;
515
+ if (node_fs.existsSync(node_path.join(legacyLockDir, "pid"))) try {
516
+ node_fs.rmSync(legacyLockDir, {
517
+ recursive: true,
518
+ force: true
519
+ });
520
+ } catch {}
521
+ const lockDir = `${file}.ygllock`;
554
522
  if (useLock && node_fs.existsSync(lockDir)) {
555
523
  let holder = "unknown";
556
524
  try {
557
525
  holder = node_fs.readFileSync(node_path.join(lockDir, "pid"), "utf8").trim();
558
526
  } catch {}
559
- try {
560
- const st = node_fs.statSync(lockDir);
561
- if (Date.now() - st.mtimeMs > 9e5) node_fs.rmSync(lockDir, {
527
+ const mine = holder === String(process.pid);
528
+ let holderAlive;
529
+ if (mine) holderAlive = false;
530
+ else try {
531
+ process.kill(Number(holder), 0);
532
+ holderAlive = true;
533
+ } catch (e) {
534
+ holderAlive = e.code === "EPERM";
535
+ }
536
+ if (!holderAlive) try {
537
+ node_fs.rmSync(lockDir, {
562
538
  recursive: true,
563
539
  force: true
564
540
  });
565
- else throw new Error(`database is locked by another process (pid: ${holder}).\n lock: ${lockDir}\n if no other ygl-trees is running, remove it: rmdir "${lockDir}"\n (stale locks auto-clear after 15 minutes)`);
566
- } catch (e) {
567
- if (String(e.message).includes("locked by another")) throw e;
568
- throw new Error(`database is locked: ${lockDir} (holder unreadable)`);
569
- }
541
+ } catch {}
542
+ else throw new Error(`database is locked by another process (pid: ${holder}).\n lock: ${lockDir}\n if this is a webui serve dashboard, it shares WAL safely — CLI reads work,\n write commands need the serve process stopped (or YGL_TEST=1 to bypass)\n if no other ygl-trees is running, remove it: rmdir "${lockDir}"`);
570
543
  }
571
544
  if (useLock) try {
572
545
  node_fs.mkdirSync(lockDir, { recursive: true });
573
546
  node_fs.writeFileSync(node_path.join(lockDir, "pid"), String(process.pid));
574
- process.on("exit", () => {
575
- try {
547
+ const cleanup = () => {
548
+ for (let i = 0; i < 3; i++) try {
576
549
  node_fs.rmSync(lockDir, {
577
550
  recursive: true,
578
551
  force: true
579
552
  });
553
+ return;
580
554
  } catch {}
581
- });
555
+ };
556
+ process.on("beforeExit", cleanup);
557
+ process.on("exit", cleanup);
582
558
  } catch {}
583
559
  this.db = new node_sqlite3_wasm.Database(file);
584
560
  this.db.exec("PRAGMA journal_mode=WAL");
@@ -589,7 +565,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_skill_refs ON skill_refs(skill_id, path);
589
565
  /** Release the write lock (called by close() and process exit). */
590
566
  releaseLock() {
591
567
  try {
592
- const lockDir = `${this.path}.lock`;
568
+ const lockDir = `${this.path}.ygllock`;
593
569
  if (node_fs.existsSync(lockDir)) node_fs.rmSync(lockDir, {
594
570
  recursive: true,
595
571
  force: true
@@ -599,7 +575,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_skill_refs ON skill_refs(skill_id, path);
599
575
  /** Static: force-release a lock (for cleanup hooks). */
600
576
  static releaseLockFor(file) {
601
577
  try {
602
- const lockDir = `${file}.lock`;
578
+ const lockDir = `${file}.ygllock`;
603
579
  if (node_fs.existsSync(lockDir)) node_fs.rmSync(lockDir, {
604
580
  recursive: true,
605
581
  force: true
@@ -919,8 +895,14 @@ function parse(argv) {
919
895
  const flags = {};
920
896
  let rest = false;
921
897
  const takesValue = (name) => !BOOLEAN_FLAGS.has(name);
922
- /** `-1` looks like a flag but is a negative number — accept it as a value. */
923
- const isValue = (s) => !s.startsWith("-") || /^-\d+(\.\d+)?$/.test(s);
898
+ /** A token is a flag boundary only if this parser could itself consume it as
899
+ * a flag: `--`, a long `--name`, or a single-letter `-x`. Any other token
900
+ * starting with `-` (e.g. `- 双平台…`, `-1`, `-abc`) can never be parsed as
901
+ * a flag, so a value-taking flag safely claims it — `--quote "- text"`
902
+ * keeps its value instead of collapsing to `true` and leaking the text
903
+ * into positionals. */
904
+ const looksLikeFlag = (s) => s === "--" || s.startsWith("--") || /^-[A-Za-z]$/.test(s);
905
+ const isValue = (s) => !looksLikeFlag(s);
924
906
  for (let i = 0; i < argv.length; i++) {
925
907
  const a = argv[i];
926
908
  if (rest) {
@@ -973,7 +955,8 @@ var DatabaseService = class extends _deepseek_ai_cordis.Service {
973
955
  db;
974
956
  constructor(ctx, dbFile) {
975
957
  super(ctx, "database");
976
- this.db = new DB(dbFile, { lock: process.env.YGL_TEST !== "1" });
958
+ const lock = process.env.YGL_TEST !== "1" && process.env.YGL_SERVE !== "1";
959
+ this.db = new DB(dbFile, { lock });
977
960
  }
978
961
  };
979
962
  function apply$3(ctx, config) {
@@ -1403,7 +1386,7 @@ function mapOutcome(r, high = .7, low = .4) {
1403
1386
  };
1404
1387
  }
1405
1388
  var GATEWAY_URL, MODEL_ID, NO_TOKEN;
1406
- var init_eval = __esmMin((() => {
1389
+ var init_eval = require_rolldown_runtime.__esmMin((() => {
1407
1390
  GATEWAY_URL = "https://ai-gateway.vercel.sh/v4/ai/evaluation-model";
1408
1391
  MODEL_ID = "typesafe-ai/jev";
1409
1392
  NO_TOKEN = "no evaluator configured (set config decision_model_llm_token, or AI_GATEWAY_API_KEY / ~/.vercel.ai-gateway.env)";
@@ -1915,7 +1898,7 @@ var TreeStore = class {
1915
1898
  /** Full-text search over nodes. Title/key substring hits outrank same-hit
1916
1899
  * rows (same ranking semantics as kb/skill/source search). */
1917
1900
  nodeSearch(treeId, q, limit = 20) {
1918
- const tokens = Array.from(new Set(String((init_text(), __toCommonJS(text_exports)).ngram(q) || "").split(/\s+/).filter(Boolean)));
1901
+ const tokens = Array.from(new Set(String((init_text(), require_rolldown_runtime.__toCommonJS(text_exports)).ngram(q) || "").split(/\s+/).filter(Boolean)));
1919
1902
  if (!tokens.length) return [];
1920
1903
  const agg = /* @__PURE__ */ new Map();
1921
1904
  const st = this.db.db.prepare(`SELECT n.id,n.key,n.name,n.tier, bm25(nodes_fts) AS score
@@ -2569,7 +2552,7 @@ function apply(ctx) {
2569
2552
  *
2570
2553
  * @module @ygl/ops-tools/plugins
2571
2554
  */
2572
- var plugins_exports = /* @__PURE__ */ __exportAll({
2555
+ var plugins_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
2573
2556
  initProfile: () => initProfile,
2574
2557
  installPlugin: () => installPlugin,
2575
2558
  listPlugins: () => listPlugins,
@@ -2655,7 +2638,8 @@ function pnpm(home, args) {
2655
2638
  q(exe),
2656
2639
  ...args.map(q),
2657
2640
  "--dir",
2658
- q(profileDir(home))
2641
+ q(profileDir(home)),
2642
+ "--ignore-workspace"
2659
2643
  ].join(" "), {
2660
2644
  stdio: "pipe",
2661
2645
  shell: true
@@ -2665,7 +2649,8 @@ function pnpm(home, args) {
2665
2649
  (0, node_child_process.execFileSync)(pm, [
2666
2650
  ...args,
2667
2651
  "--dir",
2668
- profileDir(home)
2652
+ profileDir(home),
2653
+ "--ignore-workspace"
2669
2654
  ], { stdio: "pipe" });
2670
2655
  }
2671
2656
  function resolvePm(pm) {
@@ -2818,7 +2803,7 @@ function loadUserPlugins(home) {
2818
2803
  };
2819
2804
  }
2820
2805
  var PROFILE_PKG, cachedPm, q2;
2821
- var init_plugins = __esmMin((() => {
2806
+ var init_plugins = require_rolldown_runtime.__esmMin((() => {
2822
2807
  PROFILE_PKG = () => ({
2823
2808
  name: "ygl-user-plugins",
2824
2809
  private: true,
@@ -2911,8 +2896,12 @@ async function bootApp(opts) {
2911
2896
  }
2912
2897
  for (const [g, c] of Object.entries(up.commands || {})) if (typeof c.run === "function") pluginCommands[g] = c;
2913
2898
  }
2914
- await new Promise((r) => setImmediate(r));
2915
- const db = app.database?.db || new DB(opts.dbFile, { lock: process.env.YGL_TEST !== "1" });
2899
+ let db = app.database?.db;
2900
+ for (let i = 0; i < 50 && !db; i++) {
2901
+ await new Promise((r) => setImmediate(r));
2902
+ db = app.database?.db;
2903
+ }
2904
+ db = db || new DB(opts.dbFile, { lock: process.env.YGL_TEST !== "1" });
2916
2905
  const store = app.research?.store || new Store(db);
2917
2906
  if (startupIssues.length) throw new StartupError(`${startupIssues.length} plugin issue(s) during startup`, startupIssues);
2918
2907
  return {
@@ -3045,7 +3034,7 @@ function runPluginCommand(env, action, rest, args) {
3045
3034
  bad(ctx, `'${name}' is not in the user bundle`);
3046
3035
  return 1;
3047
3036
  }
3048
- const bundle = (init_plugins(), __toCommonJS(plugins_exports)).readUserBundle(home).find((p) => p.name === name);
3037
+ const bundle = (init_plugins(), require_rolldown_runtime.__toCommonJS(plugins_exports)).readUserBundle(home).find((p) => p.name === name);
3049
3038
  out(ctx, JSON.stringify(bundle?.config ?? {}, null, 2));
3050
3039
  return 0;
3051
3040
  }
@@ -3456,7 +3445,7 @@ function preflightTypeCheck(db) {
3456
3445
  function __decorateMetadata(k, v) {
3457
3446
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3458
3447
  }
3459
- var init_decorateMetadata = __esmMin((() => {}));
3448
+ var init_decorateMetadata = require_rolldown_runtime.__esmMin((() => {}));
3460
3449
  //#endregion
3461
3450
  //#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorate.js
3462
3451
  function __decorate(decorators, target, key, desc) {
@@ -3465,7 +3454,7 @@ function __decorate(decorators, target, key, desc) {
3465
3454
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3466
3455
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3467
3456
  }
3468
- var init_decorate = __esmMin((() => {}));
3457
+ var init_decorate = require_rolldown_runtime.__esmMin((() => {}));
3469
3458
  //#endregion
3470
3459
  //#region packages/research/pipeline/src/entities.ts
3471
3460
  /**
@@ -3480,7 +3469,7 @@ var init_decorate = __esmMin((() => {}));
3480
3469
  * stay raw SQL in store.ts (see docs/plan.md TypeORM boundaries).
3481
3470
  */
3482
3471
  var Project, Query, Source, QuerySource, Evidence, Claim, ClaimEvidence, RESEARCH_ENTITIES;
3483
- var init_entities$1 = __esmMin((() => {
3472
+ var init_entities$1 = require_rolldown_runtime.__esmMin((() => {
3484
3473
  init_decorateMetadata();
3485
3474
  init_decorate();
3486
3475
  Project = class Project {
@@ -3802,7 +3791,11 @@ var init_entities$1 = __esmMin((() => {
3802
3791
  type: "text",
3803
3792
  nullable: true
3804
3793
  }), __decorateMetadata("design:type", String)], Claim.prototype, "updated", void 0);
3805
- __decorate([(0, typeorm.JoinColumn)({ name: "project_id" }), __decorateMetadata("design:type", typeof Project === "undefined" ? Object : Project)], Claim.prototype, "project", void 0);
3794
+ __decorate([
3795
+ (0, typeorm.ManyToOne)(() => Project, (p) => p.claims, { createForeignKeyConstraints: false }),
3796
+ (0, typeorm.JoinColumn)({ name: "project_id" }),
3797
+ __decorateMetadata("design:type", typeof Project === "undefined" ? Object : Project)
3798
+ ], Claim.prototype, "project", void 0);
3806
3799
  __decorate([(0, typeorm.OneToMany)(() => ClaimEvidence, (ce) => ce.claim, { createForeignKeyConstraints: false }), __decorateMetadata("design:type", Array)], Claim.prototype, "claimEvidence", void 0);
3807
3800
  Claim = __decorate([(0, typeorm.Entity)({ name: "claims" })], Claim);
3808
3801
  ClaimEvidence = class ClaimEvidence {
@@ -3850,7 +3843,7 @@ var init_entities$1 = __esmMin((() => {
3850
3843
  /** Cross-cutting entities (audit trail). Research-domain entities live in
3851
3844
  * research.ts; both are registered in src/orm.ts. */
3852
3845
  var Event, CORE_ENTITIES;
3853
- var init_entities = __esmMin((() => {
3846
+ var init_entities = require_rolldown_runtime.__esmMin((() => {
3854
3847
  init_decorateMetadata();
3855
3848
  init_decorate();
3856
3849
  Event = class Event {
@@ -3916,7 +3909,7 @@ var init_entities = __esmMin((() => {
3916
3909
  * - CLI commands using the ORM must return a Promise (main() awaits) so
3917
3910
  * the DataSource settles before the wasm DB closes.
3918
3911
  */
3919
- var orm_exports = /* @__PURE__ */ __exportAll({
3912
+ var orm_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
3920
3913
  closeOrm: () => closeOrm,
3921
3914
  getOrm: () => getOrm
3922
3915
  });
@@ -3947,14 +3940,14 @@ async function closeOrm() {
3947
3940
  }
3948
3941
  }
3949
3942
  var cached;
3950
- var init_orm = __esmMin((() => {
3943
+ var init_orm = require_rolldown_runtime.__esmMin((() => {
3951
3944
  init_entities$1();
3952
3945
  init_entities();
3953
3946
  cached = null;
3954
3947
  }));
3955
3948
  //#endregion
3956
3949
  //#region packages/research/pipeline/src/writes.ts
3957
- var writes_exports = /* @__PURE__ */ __exportAll({
3950
+ var writes_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
3958
3951
  artifactAdd: () => artifactAdd,
3959
3952
  claimAdd: () => claimAdd,
3960
3953
  claimLink: () => claimLink,
@@ -4467,10 +4460,14 @@ async function taskSetStatus(ds, taskId, status) {
4467
4460
  meta = rows[0].meta ? JSON.parse(rows[0].meta) : {};
4468
4461
  } catch {}
4469
4462
  const from = meta.status || "todo";
4470
- await mgr.query(`UPDATE artifacts SET meta=? WHERE id=?`, [JSON.stringify({
4471
- ...meta,
4472
- status
4473
- }), taskId]);
4463
+ await mgr.query(`UPDATE artifacts SET meta=?, updated=? WHERE id=?`, [
4464
+ JSON.stringify({
4465
+ ...meta,
4466
+ status
4467
+ }),
4468
+ nowIso(),
4469
+ taskId
4470
+ ]);
4474
4471
  await logEvent$1(mgr, "task.status", "task", taskId, `${from} → ${status}`, status === "done" ? "info" : "info");
4475
4472
  return {
4476
4473
  id: taskId,
@@ -4575,7 +4572,7 @@ async function projectCreate(ds, name, question = "") {
4575
4572
  });
4576
4573
  }
4577
4574
  var TASK_STATUSES;
4578
- var init_writes = __esmMin((() => {
4575
+ var init_writes = require_rolldown_runtime.__esmMin((() => {
4579
4576
  init_entities$1();
4580
4577
  init_entities();
4581
4578
  init_text();
@@ -4587,7 +4584,7 @@ var init_writes = __esmMin((() => {
4587
4584
  }));
4588
4585
  //#endregion
4589
4586
  //#region packages/ops/tools/src/db-cmds.ts
4590
- var db_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$12 });
4587
+ var db_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$12 });
4591
4588
  init_db();
4592
4589
  /**
4593
4590
  * Cold-start: import the built-in skills that ship with this package, so a
@@ -4609,9 +4606,9 @@ async function autoImportBuiltinSkills(env, dbFile) {
4609
4606
  }
4610
4607
  }
4611
4608
  if (!skillsDir) return 0;
4612
- const { getOrm } = (init_orm(), __toCommonJS(orm_exports));
4613
- const writes = (init_writes(), __toCommonJS(writes_exports));
4614
- const { parseFrontmatter } = (init_text(), __toCommonJS(text_exports));
4609
+ const { getOrm } = (init_orm(), require_rolldown_runtime.__toCommonJS(orm_exports));
4610
+ const writes = (init_writes(), require_rolldown_runtime.__toCommonJS(writes_exports));
4611
+ const { parseFrontmatter } = (init_text(), require_rolldown_runtime.__toCommonJS(text_exports));
4615
4612
  const ds = await getOrm(dbFile);
4616
4613
  let count = 0;
4617
4614
  for (const entry of fs2.readdirSync(skillsDir)) {
@@ -4638,16 +4635,16 @@ function run$12(env, action, rest, args) {
4638
4635
  switch (action) {
4639
4636
  case "init": {
4640
4637
  node_fs.mkdirSync(home, { recursive: true });
4641
- const d = new (init_db(), __toCommonJS(db_exports)).DB(file);
4638
+ const d = new (init_db(), require_rolldown_runtime.__toCommonJS(db_exports)).DB(file);
4642
4639
  d.metaSet("created", (/* @__PURE__ */ new Date()).toISOString());
4643
- d.metaSet("schema_version", String((init_db(), __toCommonJS(db_exports)).SCHEMA_VERSION));
4640
+ d.metaSet("schema_version", String((init_db(), require_rolldown_runtime.__toCommonJS(db_exports)).SCHEMA_VERSION));
4644
4641
  d.close();
4645
4642
  ok(ctx, `workspace ready: ${home}`);
4646
4643
  ok(ctx, `database: ${file}`);
4647
4644
  autoImportBuiltinSkills(env, file).then(async (n) => {
4648
4645
  if (n > 0) ok(ctx, `built-in skills: ${n} imported (agent match ready)`);
4649
4646
  try {
4650
- const { closeOrm } = (init_orm(), __toCommonJS(orm_exports));
4647
+ const { closeOrm } = (init_orm(), require_rolldown_runtime.__toCommonJS(orm_exports));
4651
4648
  await closeOrm();
4652
4649
  } catch {}
4653
4650
  });
@@ -4993,7 +4990,7 @@ function configReset(db, key) {
4993
4990
  }
4994
4991
  //#endregion
4995
4992
  //#region packages/ops/tools/src/config-cmds.ts
4996
- var config_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$11 });
4993
+ var config_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$11 });
4997
4994
  function run$11(env, action, rest, args) {
4998
4995
  const { ctx, db } = env;
4999
4996
  switch (action) {
@@ -5079,7 +5076,7 @@ function run$11(env, action, rest, args) {
5079
5076
  //#region packages/ops/tools/src/job-cmds.ts
5080
5077
  /** job group — batch + schedule. `job tick` is what cron/systemctl drives.
5081
5078
  * Writes (add) run on the TypeORM write service (src/writes.ts). */
5082
- var job_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$10 });
5079
+ var job_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$10 });
5083
5080
  init_text();
5084
5081
  init_orm();
5085
5082
  init_writes();
@@ -5283,7 +5280,7 @@ function withTickLock(env, fn) {
5283
5280
  }
5284
5281
  //#endregion
5285
5282
  //#region packages/ops/tools/src/agent-cmds.ts
5286
- var agent_cmds_exports = /* @__PURE__ */ __exportAll({
5283
+ var agent_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
5287
5284
  buildBrief: () => buildBrief,
5288
5285
  run: () => run$9
5289
5286
  });
@@ -5529,7 +5526,7 @@ function validateEnum(ctx, flags, name, allowed, required = false) {
5529
5526
  }
5530
5527
  //#endregion
5531
5528
  //#region packages/ops/tools/src/eval-enhance.ts
5532
- var eval_enhance_exports = /* @__PURE__ */ __exportAll({
5529
+ var eval_enhance_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
5533
5530
  assessEvidenceQuality: () => assessEvidenceQuality,
5534
5531
  evaluateClaimConfidence: () => evaluateClaimConfidence,
5535
5532
  semanticReRank: () => semanticReRank
@@ -5657,7 +5654,7 @@ async function assessEvidenceQuality(ctx, token) {
5657
5654
  usage: r.usage
5658
5655
  };
5659
5656
  }
5660
- var init_eval_enhance = __esmMin((() => {
5657
+ var init_eval_enhance = require_rolldown_runtime.__esmMin((() => {
5661
5658
  init_eval();
5662
5659
  }));
5663
5660
  //#endregion
@@ -5665,7 +5662,7 @@ var init_eval_enhance = __esmMin((() => {
5665
5662
  /** research group — collect → screen → extract → claim.
5666
5663
  * `source fetch` is async (Node 18+ global fetch) and returns a promise.
5667
5664
  * List commands run on TypeORM (src/orm.ts); search stays raw SQL (FTS5). */
5668
- var cmds_exports$2 = /* @__PURE__ */ __exportAll({ run: () => run$8 });
5665
+ var cmds_exports$2 = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$8 });
5669
5666
  init_text();
5670
5667
  init_orm();
5671
5668
  init_writes();
@@ -5992,7 +5989,7 @@ function run$8(env, action, rest, args) {
5992
5989
  bad(ctx, `evidence not found: ${id}`);
5993
5990
  return 1;
5994
5991
  }
5995
- const { assessEvidenceQuality } = (init_eval_enhance(), __toCommonJS(eval_enhance_exports));
5992
+ const { assessEvidenceQuality } = (init_eval_enhance(), require_rolldown_runtime.__toCommonJS(eval_enhance_exports));
5996
5993
  return assessEvidenceQuality({
5997
5994
  quote: ev.quote,
5998
5995
  locator: ev.locator,
@@ -6084,7 +6081,7 @@ function run$8(env, action, rest, args) {
6084
6081
  return getOrm(env.db.path).then((ds) => claimLink(ds, rest[1], rest[2], stance)).then((r) => {
6085
6082
  ok(ctx, `linked; claim status now: ${r.status}`);
6086
6083
  try {
6087
- const { evaluateClaimConfidence } = (init_eval_enhance(), __toCommonJS(eval_enhance_exports));
6084
+ const { evaluateClaimConfidence } = (init_eval_enhance(), require_rolldown_runtime.__toCommonJS(eval_enhance_exports));
6088
6085
  const evRows = store.db.all(`SELECT e.quote, ce.stance, s.title AS source_title
6089
6086
  FROM claim_evidence ce
6090
6087
  JOIN evidence e ON e.id = ce.evidence_id
@@ -6166,7 +6163,7 @@ function run$8(env, action, rest, args) {
6166
6163
  JOIN evidence e ON e.id = ce.evidence_id
6167
6164
  LEFT JOIN sources s ON s.id = e.source_id
6168
6165
  WHERE ce.claim_id = ?`, [id]);
6169
- const { evaluateClaimConfidence } = (init_eval_enhance(), __toCommonJS(eval_enhance_exports));
6166
+ const { evaluateClaimConfidence } = (init_eval_enhance(), require_rolldown_runtime.__toCommonJS(eval_enhance_exports));
6170
6167
  return (async () => {
6171
6168
  const result = await evaluateClaimConfidence({
6172
6169
  claim_text: claim.text,
@@ -6241,7 +6238,7 @@ function run$8(env, action, rest, args) {
6241
6238
  }
6242
6239
  //#endregion
6243
6240
  //#region packages/research/produce/src/project-cmds.ts
6244
- var project_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$7 });
6241
+ var project_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$7 });
6245
6242
  init_orm();
6246
6243
  init_writes();
6247
6244
  init_entities$1();
@@ -6379,7 +6376,7 @@ function run$7(env, action, rest, args) {
6379
6376
  /** produce group — evidence-backed outline → sections → report.
6380
6377
  * Writes run on the TypeORM write service (src/writes.ts); reads stay on
6381
6378
  * Store until their own migration batch. */
6382
- var produce_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$6 });
6379
+ var produce_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$6 });
6383
6380
  init_text();
6384
6381
  init_orm();
6385
6382
  init_writes();
@@ -7196,7 +7193,7 @@ async function importTree(ds, spec, opts = {}) {
7196
7193
  const pid = nodeId.get(String(e.parent));
7197
7194
  const cid = nodeId.get(String(e.child));
7198
7195
  await mgr.query(`INSERT INTO node_edges(id,tree_id,parent_id,child_id,rel,mode,required,min_level,weight,note,created)
7199
- VALUES(?,?,?,?,?,?,?,?,?,?)
7196
+ VALUES(?,?,?,?,?,?,?,?,?,?,?)
7200
7197
  ON CONFLICT(parent_id,child_id,rel) DO UPDATE SET
7201
7198
  mode=excluded.mode, required=excluded.required, min_level=excluded.min_level,
7202
7199
  weight=excluded.weight, note=excluded.note`, [
@@ -7215,7 +7212,8 @@ async function importTree(ds, spec, opts = {}) {
7215
7212
  e.required === false ? 0 : 1,
7216
7213
  Number(e.min_level ?? 1),
7217
7214
  Number(e.weight ?? 1),
7218
- String(e.note || "")
7215
+ String(e.note || ""),
7216
+ nowIso()
7219
7217
  ]);
7220
7218
  }
7221
7219
  for (const c of conds) {
@@ -7268,7 +7266,7 @@ async function importTree(ds, spec, opts = {}) {
7268
7266
  * ygl-trees node validate sanity checks
7269
7267
  * ygl-trees node export [--out file] portable JSON
7270
7268
  */
7271
- var cmds_exports$1 = /* @__PURE__ */ __exportAll({ run: () => run$5 });
7269
+ var cmds_exports$1 = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$5 });
7272
7270
  init_orm();
7273
7271
  init_eval();
7274
7272
  init_text();
@@ -8114,7 +8112,7 @@ function parseState(args) {
8114
8112
  //#region packages/knowledge/skills/src/skill-cmds.ts
8115
8113
  /** skill group — the L1/L2/L3 registry agents query before acting.
8116
8114
  * Writes run on the TypeORM write service (src/writes.ts). */
8117
- var skill_cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$4 });
8115
+ var skill_cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$4 });
8118
8116
  init_text();
8119
8117
  init_orm();
8120
8118
  init_writes();
@@ -8367,7 +8365,7 @@ function wrap(text, indent = 4) {
8367
8365
  //#region packages/knowledge/skills/src/cmds.ts
8368
8366
  /** kb group — long-term knowledge: store, retrieve, connect, promote to skill.
8369
8367
  * Writes (add/ingest) run on the TypeORM write service (src/writes.ts). */
8370
- var cmds_exports = /* @__PURE__ */ __exportAll({ run: () => run$3 });
8368
+ var cmds_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run$3 });
8371
8369
  init_text();
8372
8370
  init_orm();
8373
8371
  init_writes();
@@ -8416,7 +8414,7 @@ function run$3(env, action, rest, args) {
8416
8414
  }
8417
8415
  const raw = store.kbSearch(q, Number(args.flags.limit || configGetNumber(env.db, "search.limit")));
8418
8416
  if (args.flags.eval) {
8419
- const { semanticReRank } = (init_eval_enhance(), __toCommonJS(eval_enhance_exports));
8417
+ const { semanticReRank } = (init_eval_enhance(), require_rolldown_runtime.__toCommonJS(eval_enhance_exports));
8420
8418
  return semanticReRank(q, raw.map((r) => ({
8421
8419
  id: r.id,
8422
8420
  title: r.title,
@@ -8671,7 +8669,7 @@ function run$3(env, action, rest, args) {
8671
8669
  }
8672
8670
  //#endregion
8673
8671
  //#region packages/ops/tools/src/rels.ts
8674
- var rels_exports = /* @__PURE__ */ __exportAll({
8672
+ var rels_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
8675
8673
  REL_TYPES: () => REL_TYPES,
8676
8674
  RelError: () => RelError,
8677
8675
  relAdd: () => relAdd,
@@ -8977,7 +8975,7 @@ function run$2(env, action, rest, args) {
8977
8975
  }
8978
8976
  //#endregion
8979
8977
  //#region packages/ops/tools/src/webui.ts
8980
- var webui_exports = /* @__PURE__ */ __exportAll({
8978
+ var webui_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
8981
8979
  createDashboardServer: () => createDashboardServer,
8982
8980
  gatherData: () => gatherData,
8983
8981
  generateHTML: () => generateHTML,
@@ -9899,7 +9897,7 @@ function serve(env, args) {
9899
9897
  }
9900
9898
  //#endregion
9901
9899
  //#region packages/ops/tools/src/doctor.ts
9902
- var doctor_exports = /* @__PURE__ */ __exportAll({ run: () => run });
9900
+ var doctor_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ run: () => run });
9903
9901
  init_eval();
9904
9902
  init_db();
9905
9903
  init_plugins();
@@ -10005,8 +10003,12 @@ function run(env, action, rest, args) {
10005
10003
  status: "pass",
10006
10004
  detail: configRows.length === 0 ? "no overrides (all defaults)" : `${configRows.length} override(s), all valid`
10007
10005
  });
10008
- const lockPath = `${db.path}.lock`;
10009
- const hasLock = require("node:fs").existsSync(lockPath);
10006
+ const lockPath = `${db.path}.ygllock`;
10007
+ let lockHolder = "";
10008
+ try {
10009
+ lockHolder = require("node:fs").readFileSync(`${lockPath}/pid`, "utf8").trim();
10010
+ } catch {}
10011
+ const hasLock = require("node:fs").existsSync(lockPath) && lockHolder !== String(process.pid);
10010
10012
  checks.push({
10011
10013
  name: "stale_lock",
10012
10014
  status: hasLock ? "warn" : "pass",
@@ -10080,8 +10082,12 @@ function run(env, action, rest, args) {
10080
10082
  db.run("UPDATE meta SET value='0' WHERE key='index_dirty'");
10081
10083
  fixes.push("index dirty flag cleared (run: ygl-trees node index)");
10082
10084
  }
10083
- const lockDir = `${env.db.path}.lock`;
10084
- if (node_fs.existsSync(lockDir)) try {
10085
+ const lockDir = `${env.db.path}.ygllock`;
10086
+ let holder = "";
10087
+ try {
10088
+ holder = node_fs.readFileSync(`${lockDir}/pid`, "utf8").trim();
10089
+ } catch {}
10090
+ if (node_fs.existsSync(lockDir) && holder !== String(process.pid)) try {
10085
10091
  node_fs.rmSync(lockDir, {
10086
10092
  recursive: true,
10087
10093
  force: true
@@ -10309,6 +10315,7 @@ async function main(argv) {
10309
10315
  };
10310
10316
  const group = args._[0];
10311
10317
  const action = args._[1];
10318
+ if (group === "webui" && (action === "serve" || action === "export")) process.env.YGL_SERVE = "1";
10312
10319
  if (args.flags.version === true || group === "version") {
10313
10320
  out(ctx, appVersion());
10314
10321
  return 0;
@@ -10317,6 +10324,11 @@ async function main(argv) {
10317
10324
  out(ctx, generateLlmsManifest());
10318
10325
  return 0;
10319
10326
  }
10327
+ if (group === "mcp") {
10328
+ const { serveMcp } = await Promise.resolve().then(() => require("./mcp-C27lIHd1.cjs"));
10329
+ serveMcp();
10330
+ return new Promise(() => {});
10331
+ }
10320
10332
  if (!group || group === "help" || group === "-h" || group === "--help") {
10321
10333
  if (!ctx.json) out(ctx, usage());
10322
10334
  return 0;
@@ -10351,10 +10363,33 @@ async function main(argv) {
10351
10363
  return 1;
10352
10364
  }
10353
10365
  bad(ctx, `cannot open database ${file}: ${e?.message || e}`);
10354
- const lock = `${file}.lock`;
10355
- if (require("node:fs").existsSync(lock)) {
10356
- out(ctx, ` stale lock dir detected: ${lock}`);
10357
- out(ctx, ` if no other ygl-trees process is running, remove it: rmdir "${lock}"`);
10366
+ const lock = `${file}.ygllock`;
10367
+ if (!ctx.json && require("node:fs").existsSync(lock)) {
10368
+ const pidFile = require("node:path").join(lock, "pid");
10369
+ let holder = "?";
10370
+ try {
10371
+ holder = require("node:fs").readFileSync(pidFile, "utf8").trim();
10372
+ } catch {}
10373
+ let alive = false;
10374
+ try {
10375
+ process.kill(Number(holder), 0);
10376
+ alive = true;
10377
+ } catch (err) {
10378
+ alive = err.code === "EPERM";
10379
+ }
10380
+ if (alive) {
10381
+ out(ctx, ` lock held by live process pid ${holder} (serve? webui dashboard)`);
10382
+ out(ctx, ` to run CLI write commands, stop that process first — or use YGL_TEST=1 to bypass`);
10383
+ } else {
10384
+ out(ctx, ` orphaned lock (pid ${holder} is dead) — removing: ${lock}`);
10385
+ try {
10386
+ require("node:fs").rmSync(lock, {
10387
+ recursive: true,
10388
+ force: true
10389
+ });
10390
+ } catch {}
10391
+ out(ctx, ` retry the command — the lock has been cleaned`);
10392
+ }
10358
10393
  }
10359
10394
  return 1;
10360
10395
  }
@@ -10368,7 +10403,7 @@ async function main(argv) {
10368
10403
  db?.close();
10369
10404
  } catch {}
10370
10405
  try {
10371
- (init_db(), __toCommonJS(db_exports)).DB.releaseLockFor(file);
10406
+ (init_db(), require_rolldown_runtime.__toCommonJS(db_exports)).DB.releaseLockFor(file);
10372
10407
  } catch {}
10373
10408
  });
10374
10409
  process.on("SIGINT", () => shutdown.interrupt(0));