openspecui 0.8.0 → 0.9.1

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.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { o as __commonJS, r as OpenSpecAdapter, s as __toESM, t as startServer } from "./src-BtPH0zlP.mjs";
2
+ import { a as __toESM, i as __commonJS, r as OpenSpecAdapter, t as startServer } from "./src-5u2R3Fnr.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { fileURLToPath } from "url";
5
5
  import { basename, dirname, extname, join, normalize, relative, resolve } from "path";
@@ -2647,14 +2647,14 @@ function usage(yargs, shim$2) {
2647
2647
  if (shim$2.process.stdColumns) return Math.min(maxWidth$1, shim$2.process.stdColumns);
2648
2648
  else return maxWidth$1;
2649
2649
  }
2650
- let version = null;
2650
+ let version$1 = null;
2651
2651
  self.version = (ver) => {
2652
- version = ver;
2652
+ version$1 = ver;
2653
2653
  };
2654
2654
  self.showVersion = (level) => {
2655
2655
  const logger = yargs.getInternalMethods().getLoggerInstance();
2656
2656
  if (!level) level = "error";
2657
- (typeof level === "function" ? level : logger[level])(version);
2657
+ (typeof level === "function" ? level : logger[level])(version$1);
2658
2658
  };
2659
2659
  self.reset = function reset(localLookup) {
2660
2660
  failMessage = null;
@@ -4502,10 +4502,13 @@ function isYargsInstance(y) {
4502
4502
  const Yargs = YargsFactory(esm_default);
4503
4503
  var yargs_default = Yargs;
4504
4504
 
4505
+ //#endregion
4506
+ //#region package.json
4507
+ var version = "0.9.1";
4508
+
4505
4509
  //#endregion
4506
4510
  //#region src/export.ts
4507
4511
  const __dirname$1 = dirname$1(fileURLToPath$1(import.meta.url));
4508
- const WEB_PACKAGE_VERSION = "0.8.0";
4509
4512
  /**
4510
4513
  * Generate a complete data snapshot of the OpenSpec project
4511
4514
  * (Kept for backwards compatibility and testing)
@@ -4585,7 +4588,7 @@ async function generateSnapshot(projectDir) {
4585
4588
  return {
4586
4589
  meta: {
4587
4590
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4588
- version: WEB_PACKAGE_VERSION,
4591
+ version,
4589
4592
  projectDir
4590
4593
  },
4591
4594
  dashboard: {
@@ -4601,62 +4604,50 @@ async function generateSnapshot(projectDir) {
4601
4604
  };
4602
4605
  }
4603
4606
  /**
4604
- * Detect the package manager being used
4607
+ * Check if running in local monorepo development mode
4608
+ * Returns the path to web package root if available, null otherwise
4605
4609
  */
4606
- function detectPackageManager() {
4607
- const userAgent = process.env.npm_config_user_agent || "";
4608
- if (userAgent.includes("pnpm")) return "pnpm";
4609
- if (userAgent.includes("yarn")) return "yarn";
4610
- if (userAgent.includes("bun")) return "bun";
4611
- return "npm";
4610
+ function findLocalWebPackage() {
4611
+ if (existsSync(join$1(__dirname$1, "..", "..", "web", "package.json"))) return join$1(__dirname$1, "..", "..", "web");
4612
+ return null;
4612
4613
  }
4613
4614
  /**
4614
- * Get the command to execute a package binary
4615
+ * Run a command and wait for it to complete
4615
4616
  */
4616
- function getExecCommand(pm) {
4617
- const packageSpec = WEB_PACKAGE_VERSION.startsWith("__") ? "@openspecui/web" : `@openspecui/web@${WEB_PACKAGE_VERSION}`;
4618
- switch (pm) {
4619
- case "pnpm": return {
4620
- cmd: "pnpm",
4621
- args: ["dlx", packageSpec]
4622
- };
4623
- case "yarn": return {
4624
- cmd: "yarn",
4625
- args: ["dlx", packageSpec]
4626
- };
4627
- case "bun": return {
4628
- cmd: "bunx",
4629
- args: [packageSpec]
4630
- };
4631
- case "npm":
4632
- default: return {
4633
- cmd: "npx",
4634
- args: [packageSpec]
4635
- };
4636
- }
4617
+ function runCommand(cmd, args, cwd) {
4618
+ return new Promise((resolvePromise, reject) => {
4619
+ const child = spawn(cmd, args, {
4620
+ stdio: "inherit",
4621
+ cwd
4622
+ });
4623
+ child.on("close", (code) => {
4624
+ if (code === 0) resolvePromise();
4625
+ else reject(/* @__PURE__ */ new Error(`Command failed with exit code ${code}`));
4626
+ });
4627
+ child.on("error", (err) => reject(err));
4628
+ });
4637
4629
  }
4638
4630
  /**
4639
- * Check if running in local monorepo development mode
4640
- * Returns the path to local SSG CLI if available, null otherwise
4631
+ * Export as JSON only (data.json)
4641
4632
  */
4642
- function findLocalSSGCli() {
4643
- const localSsgTs = join$1(__dirname$1, "..", "..", "web", "src", "ssg", "cli.ts");
4644
- if (existsSync(localSsgTs)) return localSsgTs;
4645
- return null;
4633
+ async function exportJson(options) {
4634
+ const { projectDir, outputDir, clean } = options;
4635
+ if (clean && existsSync(outputDir)) rmSync(outputDir, { recursive: true });
4636
+ mkdirSync(outputDir, { recursive: true });
4637
+ console.log("Generating data snapshot...");
4638
+ const snapshot = await generateSnapshot(projectDir);
4639
+ const dataJsonPath = join$1(outputDir, "data.json");
4640
+ writeFileSync(dataJsonPath, JSON.stringify(snapshot, null, 2));
4641
+ console.log(`\nExported to ${dataJsonPath}`);
4642
+ console.log(` Specs: ${snapshot.specs.length}`);
4643
+ console.log(` Changes: ${snapshot.changes.length}`);
4644
+ console.log(` Archives: ${snapshot.archives.length}`);
4646
4645
  }
4647
4646
  /**
4648
- * Export the OpenSpec UI as a static website with SSG (pre-rendered HTML)
4649
- *
4650
- * This function:
4651
- * 1. Generates a data snapshot from the openspec/ directory
4652
- * 2. Writes data.json to the output directory
4653
- * 3. Delegates to @openspecui/web's SSG CLI for rendering
4654
- *
4655
- * In development (monorepo), it uses the local web package.
4656
- * In production, it uses npx/pnpm dlx to fetch the published package.
4647
+ * Export as static HTML site
4657
4648
  */
4658
- async function exportStaticSite(options) {
4659
- const { projectDir, outputDir, basePath, clean, open, previewPort, previewHost } = options;
4649
+ async function exportHtml(options) {
4650
+ const { projectDir, outputDir, basePath = "/", clean, open, previewPort, previewHost } = options;
4660
4651
  if (clean && existsSync(outputDir)) rmSync(outputDir, { recursive: true });
4661
4652
  mkdirSync(outputDir, { recursive: true });
4662
4653
  console.log("Generating data snapshot...");
@@ -4664,46 +4655,63 @@ async function exportStaticSite(options) {
4664
4655
  const dataJsonPath = join$1(outputDir, "data.json");
4665
4656
  writeFileSync(dataJsonPath, JSON.stringify(snapshot, null, 2));
4666
4657
  console.log(`Data snapshot written to ${dataJsonPath}`);
4667
- const ssgOnlyArgs = [
4668
- "--data",
4669
- dataJsonPath,
4670
- "--output",
4671
- outputDir
4672
- ];
4673
- if (basePath !== void 0) ssgOnlyArgs.push("--base-path", basePath);
4674
- if (open) {
4675
- ssgOnlyArgs.push("--open");
4676
- if (previewPort !== void 0) ssgOnlyArgs.push("--preview-port", String(previewPort));
4677
- if (previewHost !== void 0) ssgOnlyArgs.push("--host", previewHost);
4678
- }
4679
- const localCli = findLocalSSGCli();
4680
- let cmd;
4681
- let args;
4682
- if (localCli) {
4683
- cmd = "npx";
4684
- args = [
4658
+ const localWebPkg = findLocalWebPackage();
4659
+ if (localWebPkg) {
4660
+ console.log("\n[Local dev mode] Running SSG from local web package...");
4661
+ console.log("\nBuilding client assets...");
4662
+ await runCommand("pnpm", ["build:client"], localWebPkg);
4663
+ console.log("Building SSR bundle...");
4664
+ await runCommand("pnpm", ["build:server"], localWebPkg);
4665
+ console.log("Pre-rendering pages...");
4666
+ const clientDistDir = join$1(localWebPkg, "dist", "client");
4667
+ await runCommand("npx", [
4685
4668
  "tsx",
4686
- localCli,
4687
- ...ssgOnlyArgs
4688
- ];
4669
+ "src/ssg/prerender.ts",
4670
+ "--data",
4671
+ dataJsonPath,
4672
+ "--output",
4673
+ clientDistDir,
4674
+ "--base-path",
4675
+ basePath
4676
+ ], localWebPkg);
4677
+ console.log("\nCopying to output directory...");
4678
+ const { cpSync } = await import("node:fs");
4679
+ cpSync(clientDistDir, outputDir, { recursive: true });
4680
+ writeFileSync(join$1(outputDir, "data.json"), JSON.stringify(snapshot, null, 2));
4681
+ console.log(`\nExport complete: ${outputDir}`);
4689
4682
  } else {
4690
- const execCmd = getExecCommand(detectPackageManager());
4691
- cmd = execCmd.cmd;
4692
- args = [...execCmd.args, ...ssgOnlyArgs];
4683
+ console.log("\nNote: HTML export requires @openspecui/web to be installed locally.");
4684
+ console.log("For production SSG, run these commands:");
4685
+ console.log(" npm install @openspecui/web");
4686
+ console.log(" cd node_modules/@openspecui/web");
4687
+ console.log(" pnpm build:ssg");
4688
+ console.log(` npx tsx src/ssg/prerender.ts --data ${dataJsonPath} --output ${outputDir}`);
4689
+ console.log("\nData exported to data.json. Run the above commands to generate HTML.");
4690
+ return;
4691
+ }
4692
+ if (open) {
4693
+ console.log("\nStarting preview server...");
4694
+ const previewArgs = [
4695
+ "vite",
4696
+ "preview",
4697
+ "--outDir",
4698
+ resolve$1(outputDir)
4699
+ ];
4700
+ if (previewPort) previewArgs.push("--port", String(previewPort));
4701
+ if (previewHost) previewArgs.push("--host", previewHost);
4702
+ previewArgs.push("--open");
4703
+ await runCommand("npx", previewArgs, outputDir);
4693
4704
  }
4694
- return new Promise((resolvePromise, reject) => {
4695
- const child = spawn(cmd, args, {
4696
- stdio: "inherit",
4697
- cwd: projectDir
4698
- });
4699
- child.on("close", (code) => {
4700
- if (code === 0) resolvePromise();
4701
- else reject(/* @__PURE__ */ new Error(`SSG export failed with exit code ${code}`));
4702
- });
4703
- child.on("error", (err) => {
4704
- reject(/* @__PURE__ */ new Error(`Failed to start SSG CLI: ${err.message}`));
4705
- });
4706
- });
4705
+ }
4706
+ /**
4707
+ * Export the OpenSpec project
4708
+ *
4709
+ * @param options Export options
4710
+ * @param options.format 'html' (default) - full static site, 'json' - data only
4711
+ */
4712
+ async function exportStaticSite(options) {
4713
+ if ((options.format || "html") === "json") await exportJson(options);
4714
+ else await exportHtml(options);
4707
4715
  }
4708
4716
 
4709
4717
  //#endregion
@@ -4778,12 +4786,18 @@ async function main() {
4778
4786
  console.error("❌ Failed to start server:", error);
4779
4787
  process.exit(1);
4780
4788
  }
4781
- }).command("export", "Export OpenSpec UI as a static website (alias for @openspecui/web ssg)", (yargs) => {
4789
+ }).command("export", "Export OpenSpec project as static website or JSON data", (yargs) => {
4782
4790
  return yargs.option("output", {
4783
4791
  alias: "o",
4784
- describe: "Output directory for static export",
4792
+ describe: "Output directory for export",
4785
4793
  type: "string",
4786
4794
  demandOption: true
4795
+ }).option("format", {
4796
+ alias: "f",
4797
+ describe: "Export format",
4798
+ type: "string",
4799
+ choices: ["html", "json"],
4800
+ default: "html"
4787
4801
  }).option("dir", {
4788
4802
  alias: "d",
4789
4803
  describe: "Project directory containing openspec/",
@@ -4813,6 +4827,7 @@ async function main() {
4813
4827
  await exportStaticSite({
4814
4828
  projectDir,
4815
4829
  outputDir,
4830
+ format: argv.format,
4816
4831
  basePath: argv["base-path"],
4817
4832
  clean: argv.clean,
4818
4833
  open: argv.open,
@@ -4824,7 +4839,7 @@ async function main() {
4824
4839
  console.error("❌ Export failed:", error);
4825
4840
  process.exit(1);
4826
4841
  }
4827
- }).example("$0", "Start server in current directory").example("$0 ./my-project", "Start server with specific project").example("$0 -p 8080", "Start server on custom port").example("$0 export -o ./dist", "Export to ./dist directory").example("$0 export --output ./public", "Export to ./public directory").example("$0 export -o ./dist --base-path=/docs/", "Export for subdirectory deployment").example("$0 export -o ./dist --clean", "Clean output directory before export").version(getVersion()).alias("v", "version").help().alias("h", "help").parse();
4842
+ }).example("$0", "Start server in current directory").example("$0 ./my-project", "Start server with specific project").example("$0 -p 8080", "Start server on custom port").example("$0 export -o ./dist", "Export HTML to ./dist directory").example("$0 export -o ./dist -f json", "Export JSON data only").example("$0 export -o ./dist --base-path=/docs/", "Export for subdirectory deployment").example("$0 export -o ./dist --clean", "Clean output directory before export").version(getVersion()).alias("v", "version").help().alias("h", "help").parse();
4828
4843
  }
4829
4844
  main();
4830
4845
 
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as ACPAgents, i as ProviderManager, n as createServer, t as startServer } from "./src-BtPH0zlP.mjs";
1
+ import { n as createServer, t as startServer } from "./src-5u2R3Fnr.mjs";
2
2
 
3
- export { ACPAgents, ProviderManager, createServer, startServer };
3
+ export { createServer, startServer };