@mean-weasel/lineage 0.1.8 → 0.1.10

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,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/lineageCli.ts
4
- import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
4
+ import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "node:fs";
5
5
  import { homedir, platform } from "node:os";
6
- import { dirname as dirname3, join as join6, resolve as resolve5 } from "node:path";
6
+ import { dirname as dirname3, join as join7, resolve as resolve5 } from "node:path";
7
7
  import { spawn } from "node:child_process";
8
8
  import { fileURLToPath as fileURLToPath2 } from "node:url";
9
9
 
@@ -283,8 +283,8 @@ function isPackageRoot(path) {
283
283
  const packageJson = join3(path, "package.json");
284
284
  if (!existsSync3(packageJson)) return false;
285
285
  try {
286
- const packageInfo = JSON.parse(readFileSync2(packageJson, "utf8"));
287
- return packageInfo.name === "@mean-weasel/lineage";
286
+ const packageInfo2 = JSON.parse(readFileSync2(packageJson, "utf8"));
287
+ return packageInfo2.name === "@mean-weasel/lineage";
288
288
  } catch {
289
289
  return false;
290
290
  }
@@ -3593,6 +3593,74 @@ function getLineageSelectionPacket(project, options = {}) {
3593
3593
  };
3594
3594
  }
3595
3595
 
3596
+ // src/server/runtimeInfo.ts
3597
+ import { spawnSync as spawnSync2 } from "node:child_process";
3598
+ import { createRequire as createRequire2 } from "node:module";
3599
+ import { existsSync as existsSync6, readFileSync as readFileSync3, statSync as statSync5 } from "node:fs";
3600
+ import { join as join6 } from "node:path";
3601
+ var require3 = createRequire2(import.meta.url);
3602
+ function packageInfo() {
3603
+ try {
3604
+ const info = JSON.parse(readFileSync3(join6(repoRoot, "package.json"), "utf8"));
3605
+ return { name: info.name || "@mean-weasel/lineage", version: info.version || "0.0.0" };
3606
+ } catch {
3607
+ return { name: "@mean-weasel/lineage", version: "0.0.0" };
3608
+ }
3609
+ }
3610
+ function normalizeRuntimeChannel(value) {
3611
+ if (value === "stable" || value === "preview" || value === "dev") return value;
3612
+ if (value === "production") return "stable";
3613
+ if (value === "next") return "preview";
3614
+ if (value === "development") return "dev";
3615
+ return process.env.NODE_ENV === "production" ? "stable" : "dev";
3616
+ }
3617
+ function gitSha() {
3618
+ const envSha = process.env.LINEAGE_GIT_SHA || process.env.GITHUB_SHA;
3619
+ if (envSha) return envSha.slice(0, 40);
3620
+ if (!existsSync6(join6(repoRoot, ".git"))) return void 0;
3621
+ const result = spawnSync2("git", ["rev-parse", "--short=12", "HEAD"], { cwd: repoRoot, encoding: "utf8" });
3622
+ return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
3623
+ }
3624
+ function tableExists(database, table) {
3625
+ return Boolean(database.prepare("select name from sqlite_master where type = 'table' and name = ?").get(table));
3626
+ }
3627
+ function tableCount(database, table) {
3628
+ if (!tableExists(database, table)) return void 0;
3629
+ const row = database.prepare(`select count(*) count from ${table}`).get();
3630
+ return typeof row?.count === "number" ? row.count : void 0;
3631
+ }
3632
+ function getLineageRuntimeInfo(options = {}) {
3633
+ const info = packageInfo();
3634
+ const dbPath = options.dbPath || lineageDbPath();
3635
+ const databaseInfo = { exists: existsSync6(dbPath), path: dbPath };
3636
+ if (databaseInfo.exists) {
3637
+ try {
3638
+ const stat = statSync5(dbPath);
3639
+ databaseInfo.modified_at = stat.mtime.toISOString();
3640
+ databaseInfo.size_bytes = stat.size;
3641
+ const { DatabaseSync } = require3("node:sqlite");
3642
+ const database = new DatabaseSync(dbPath, { readOnly: true });
3643
+ try {
3644
+ databaseInfo.projects = tableCount(database, "projects");
3645
+ databaseInfo.workspaces = tableCount(database, "lineage_workspaces");
3646
+ } finally {
3647
+ database.close();
3648
+ }
3649
+ } catch (error) {
3650
+ databaseInfo.error = error instanceof Error ? error.message : String(error);
3651
+ }
3652
+ }
3653
+ return {
3654
+ channel: normalizeRuntimeChannel(options.channel || process.env.LINEAGE_CHANNEL || process.env.LINEAGE_RELEASE_CHANNEL),
3655
+ database: databaseInfo,
3656
+ fetchedAt: nowIso(),
3657
+ git_sha: gitSha(),
3658
+ node_env: process.env.NODE_ENV,
3659
+ package_name: info.name,
3660
+ version: info.version
3661
+ };
3662
+ }
3663
+
3596
3664
  // src/cli/lineageCli.ts
3597
3665
  var signalExitCodes = {
3598
3666
  SIGINT: 130,
@@ -3603,17 +3671,17 @@ function packageRoot() {
3603
3671
  }
3604
3672
  function packageVersion() {
3605
3673
  try {
3606
- const packageInfo = JSON.parse(readFileSync3(join6(packageRoot(), "package.json"), "utf8"));
3607
- return packageInfo.version || "0.0.0";
3674
+ const packageInfo2 = JSON.parse(readFileSync4(join7(packageRoot(), "package.json"), "utf8"));
3675
+ return packageInfo2.version || "0.0.0";
3608
3676
  } catch {
3609
3677
  return "0.0.0";
3610
3678
  }
3611
3679
  }
3612
3680
  function dataRoot(displayName) {
3613
3681
  if (process.env.LINEAGE_HOME) return process.env.LINEAGE_HOME;
3614
- if (platform() === "darwin") return join6(homedir(), "Library", "Application Support", displayName);
3615
- if (platform() === "win32") return join6(process.env.APPDATA || join6(homedir(), "AppData", "Roaming"), displayName);
3616
- return join6(process.env.XDG_DATA_HOME || join6(homedir(), ".local", "share"), displayName.toLowerCase().replace(/\s+/g, "-"));
3682
+ if (platform() === "darwin") return join7(homedir(), "Library", "Application Support", displayName);
3683
+ if (platform() === "win32") return join7(process.env.APPDATA || join7(homedir(), "AppData", "Roaming"), displayName);
3684
+ return join7(process.env.XDG_DATA_HOME || join7(homedir(), ".local", "share"), displayName.toLowerCase().replace(/\s+/g, "-"));
3617
3685
  }
3618
3686
  function readOption(args, name) {
3619
3687
  const prefix = `${name}=`;
@@ -3637,20 +3705,22 @@ function readOptions(args, name) {
3637
3705
  return values;
3638
3706
  }
3639
3707
  function resolveStartOptions(config, args) {
3640
- const runtimeDir = dataRoot(config.displayName);
3641
3708
  const rawPort = readOption(args, "--port") || process.env.PORT || String(config.defaultPort);
3642
3709
  const port = Number(rawPort);
3643
3710
  if (!Number.isInteger(port) || port < 1 || port > 65535) {
3644
3711
  throw new Error(`Invalid port: ${rawPort}`);
3645
3712
  }
3646
3713
  return {
3647
- dbPath: readOption(args, "--db") || process.env.LINEAGE_DB || join6(runtimeDir, `${config.binName}.sqlite`),
3714
+ dbPath: resolveCliDbPath(config, args),
3648
3715
  host: readOption(args, "--host") || process.env.HOST || config.defaultHost,
3649
3716
  json: args.includes("--json"),
3650
3717
  open: args.includes("--open"),
3651
3718
  port
3652
3719
  };
3653
3720
  }
3721
+ function resolveCliDbPath(config, args) {
3722
+ return readOption(args, "--db") || process.env.LINEAGE_DB || join7(dataRoot(config.displayName), `${config.binName}.sqlite`);
3723
+ }
3654
3724
  function formatLineageHelp(config) {
3655
3725
  return `${config.binName} ${packageVersion()}
3656
3726
 
@@ -3674,6 +3744,7 @@ Usage:
3674
3744
  ${config.binName} tasks cancel --task <task-id> [--confirm-write] [--override] [--project <project>] [--db <path>] [--json]
3675
3745
  ${config.binName} tasks override --task <task-id> --reason <text> [--instructions <text>] [--project <project>] [--db <path>] [--json]
3676
3746
  ${config.binName} tasks instructions --task <task-id> --instructions <text> [--project <project>] [--db <path>] [--json]
3747
+ ${config.binName} db info [--db <path>] [--json]
3677
3748
  ${config.binName} agent claim --project <project> --scope <scope> --target <target-id> --agent-name <name> [--channel <channel>] [--ttl 20m] [--json]
3678
3749
  ${config.binName} agent graph --root <asset-id> [--project <project>] [--db <path>] [--json]
3679
3750
  ${config.binName} agent status [--project <project>] [--json]
@@ -3958,6 +4029,34 @@ function printDataResult(command, result, json) {
3958
4029
  }
3959
4030
  console.log(String(result));
3960
4031
  }
4032
+ function runLineageDbCommand(config, command, args) {
4033
+ const dbPath = resolveCliDbPath(config, args);
4034
+ process.env.LINEAGE_DB = dbPath;
4035
+ if (command === "info") return getLineageRuntimeInfo({ channel: config.channel, dbPath });
4036
+ throw new Error(`Unknown db command: ${command}`);
4037
+ }
4038
+ function printDbResult(command, result, json) {
4039
+ if (json) {
4040
+ console.log(JSON.stringify(result, null, 2));
4041
+ return;
4042
+ }
4043
+ if (command === "info" && result && typeof result === "object" && "database" in result) {
4044
+ const runtime = result;
4045
+ console.log(`Channel: ${runtime.channel}`);
4046
+ console.log(`Version: ${runtime.version}`);
4047
+ if (runtime.git_sha) console.log(`Git: ${runtime.git_sha}`);
4048
+ if (runtime.node_env) console.log(`Node env: ${runtime.node_env}`);
4049
+ console.log(`SQLite: ${runtime.database.path}`);
4050
+ console.log(`Exists: ${runtime.database.exists ? "yes" : "no"}`);
4051
+ if (runtime.database.size_bytes !== void 0) console.log(`Size: ${runtime.database.size_bytes} bytes`);
4052
+ if (runtime.database.modified_at) console.log(`Modified: ${runtime.database.modified_at}`);
4053
+ if (runtime.database.projects !== void 0) console.log(`Projects: ${runtime.database.projects}`);
4054
+ if (runtime.database.workspaces !== void 0) console.log(`Workspaces: ${runtime.database.workspaces}`);
4055
+ if (runtime.database.error) console.log(`Warning: ${runtime.database.error}`);
4056
+ return;
4057
+ }
4058
+ console.log(String(result));
4059
+ }
3961
4060
  function runLineageAgentCommand(command, args) {
3962
4061
  const dbPath = readOption(args, "--db");
3963
4062
  if (dbPath) process.env.LINEAGE_DB = dbPath;
@@ -4084,8 +4183,8 @@ function start(config, args) {
4084
4183
  else console.error(`${config.binName}: ${message}`);
4085
4184
  process.exit(1);
4086
4185
  }
4087
- const serverPath = join6(packageRoot(), "dist", "server.js");
4088
- if (!existsSync6(serverPath)) {
4186
+ const serverPath = join7(packageRoot(), "dist", "server.js");
4187
+ if (!existsSync7(serverPath)) {
4089
4188
  const message = `Missing bundled server at ${serverPath}. Run npm run build before using ${config.binName} start from a source checkout.`;
4090
4189
  if (options.json) console.error(JSON.stringify({ ok: false, error: message }, null, 2));
4091
4190
  else console.error(`${config.binName}: ${message}`);
@@ -4154,6 +4253,20 @@ function runLineageCli(config, args = process.argv.slice(2)) {
4154
4253
  }
4155
4254
  process.exit(0);
4156
4255
  }
4256
+ if (command === "db") {
4257
+ const commandArgs = normalizedArgs.slice(2);
4258
+ const dbCommand = normalizedArgs[1] || "";
4259
+ const json2 = commandArgs.includes("--json");
4260
+ try {
4261
+ printDbResult(dbCommand, runLineageDbCommand(config, dbCommand, commandArgs), json2);
4262
+ } catch (error) {
4263
+ const message2 = error instanceof Error ? error.message : String(error);
4264
+ if (json2) console.error(JSON.stringify({ ok: false, command: `db ${dbCommand}`, error: message2 }, null, 2));
4265
+ else console.error(`${config.binName}: ${message2}`);
4266
+ process.exit(1);
4267
+ }
4268
+ process.exit(0);
4269
+ }
4157
4270
  if (command === "agent") {
4158
4271
  const commandArgs = normalizedArgs.slice(2);
4159
4272
  const agentCommand = normalizedArgs[1] || "";