@weave-tools/weave-it 0.1.0 → 0.1.2

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.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
 
3
+ declare function readPackageVersion(moduleUrl?: string): string;
3
4
  declare function createProgram(): Command;
5
+ declare function isDirectCliInvocation(scriptPath?: string, moduleUrl?: string): boolean;
4
6
 
5
- export { createProgram };
7
+ export { createProgram, isDirectCliInvocation, readPackageVersion };
package/dist/cli.js CHANGED
@@ -18,60 +18,60 @@ import { realpath } from "fs/promises";
18
18
  import { constants } from "fs";
19
19
  import { access, mkdir, readFile, readdir, rename, stat, writeFile } from "fs/promises";
20
20
  import { dirname } from "path";
21
- async function pathExists(path14) {
21
+ async function pathExists(path15) {
22
22
  try {
23
- await access(path14, constants.F_OK);
23
+ await access(path15, constants.F_OK);
24
24
  return true;
25
25
  } catch {
26
26
  return false;
27
27
  }
28
28
  }
29
- async function writeNewFile(path14, contents) {
30
- await writeFile(path14, contents, { flag: "wx" });
29
+ async function writeNewFile(path15, contents) {
30
+ await writeFile(path15, contents, { flag: "wx" });
31
31
  }
32
- async function writeFileIfMissing(path14, contents) {
33
- if (await pathExists(path14)) {
32
+ async function writeFileIfMissing(path15, contents) {
33
+ if (await pathExists(path15)) {
34
34
  return false;
35
35
  }
36
- await writeNewFile(path14, contents);
36
+ await writeNewFile(path15, contents);
37
37
  return true;
38
38
  }
39
- async function writeFileAtomic(path14, contents) {
40
- const tempPath = `${path14}.${process.pid}.tmp`;
39
+ async function writeFileAtomic(path15, contents) {
40
+ const tempPath = `${path15}.${process.pid}.tmp`;
41
41
  await writeFile(tempPath, contents);
42
- await rename(tempPath, path14);
42
+ await rename(tempPath, path15);
43
43
  }
44
- async function ensureDir(path14) {
45
- await mkdir(path14, { recursive: true });
44
+ async function ensureDir(path15) {
45
+ await mkdir(path15, { recursive: true });
46
46
  }
47
- async function createDirExclusive(path14) {
48
- await mkdir(path14, { recursive: false });
47
+ async function createDirExclusive(path15) {
48
+ await mkdir(path15, { recursive: false });
49
49
  }
50
- async function ensureDirectory(path14) {
51
- const value = await stat(path14);
50
+ async function ensureDirectory(path15) {
51
+ const value = await stat(path15);
52
52
  if (!value.isDirectory()) {
53
- throw new Error(`Expected a directory: ${path14}`);
53
+ throw new Error(`Expected a directory: ${path15}`);
54
54
  }
55
55
  }
56
- async function isDirectoryEmpty(path14) {
57
- const entries = await readdir(path14);
56
+ async function isDirectoryEmpty(path15) {
57
+ const entries = await readdir(path15);
58
58
  return entries.length === 0;
59
59
  }
60
60
  async function movePath(source, target) {
61
61
  await rename(source, target);
62
62
  }
63
- async function readJsonCache(path14) {
63
+ async function readJsonCache(path15) {
64
64
  try {
65
- const contents = await readFile(path14, "utf8");
65
+ const contents = await readFile(path15, "utf8");
66
66
  return JSON.parse(contents);
67
67
  } catch {
68
68
  return null;
69
69
  }
70
70
  }
71
- async function writeJsonCache(path14, data) {
71
+ async function writeJsonCache(path15, data) {
72
72
  try {
73
- await mkdir(dirname(path14), { recursive: true });
74
- await writeFileAtomic(path14, JSON.stringify(data, null, 2));
73
+ await mkdir(dirname(path15), { recursive: true });
74
+ await writeFileAtomic(path15, JSON.stringify(data, null, 2));
75
75
  return true;
76
76
  } catch {
77
77
  return false;
@@ -1274,8 +1274,8 @@ function formatFullFileDiff(installedPath, defaultName, installed, currentDefaul
1274
1274
  function splitLines(value) {
1275
1275
  return value.endsWith("\n") ? value.slice(0, -1).split("\n") : value.split("\n");
1276
1276
  }
1277
- function result(agent, artifact, path14, status, message) {
1278
- return { agent, kind: artifact.kind, skill: artifact.name, path: path14, status, message };
1277
+ function result(agent, artifact, path15, status, message) {
1278
+ return { agent, kind: artifact.kind, skill: artifact.name, path: path15, status, message };
1279
1279
  }
1280
1280
  function summarize(results) {
1281
1281
  return {
@@ -2991,9 +2991,9 @@ async function safeListDefaultSkills(templatesDir) {
2991
2991
  return [];
2992
2992
  }
2993
2993
  }
2994
- async function safeHashFile(path14) {
2994
+ async function safeHashFile(path15) {
2995
2995
  try {
2996
- const content = await readFile8(path14, "utf8");
2996
+ const content = await readFile8(path15, "utf8");
2997
2997
  return `sha256:${createHash3("sha256").update(content).digest("hex")}`;
2998
2998
  } catch {
2999
2999
  return null;
@@ -4513,10 +4513,20 @@ function workspaceCommand() {
4513
4513
  }
4514
4514
 
4515
4515
  // src/cli.ts
4516
- import { pathToFileURL } from "url";
4516
+ import { readFileSync, realpathSync } from "fs";
4517
+ import path14 from "path";
4518
+ import { fileURLToPath as fileURLToPath4 } from "url";
4519
+ function readPackageVersion3(moduleUrl = import.meta.url) {
4520
+ const packageJsonPath = path14.join(path14.dirname(fileURLToPath4(moduleUrl)), "..", "package.json");
4521
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
4522
+ if (typeof packageJson.version !== "string") {
4523
+ throw new Error(`Missing version in ${packageJsonPath}`);
4524
+ }
4525
+ return packageJson.version;
4526
+ }
4517
4527
  function createProgram() {
4518
4528
  const program = new Command10();
4519
- program.name("weave").description("Repo-local LLM wiki and temporary multi-folder AI session tooling.").version("0.1.0");
4529
+ program.name("weave").description("Repo-local LLM wiki and temporary multi-folder AI session tooling.").version(readPackageVersion3());
4520
4530
  program.addCommand(initCommand());
4521
4531
  program.addCommand(addCommand());
4522
4532
  program.addCommand(workspaceCommand());
@@ -4529,10 +4539,22 @@ function createProgram() {
4529
4539
  program.addCommand(taskCommand());
4530
4540
  return program;
4531
4541
  }
4532
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
4542
+ function isDirectCliInvocation(scriptPath = process.argv[1], moduleUrl = import.meta.url) {
4543
+ if (!scriptPath) {
4544
+ return false;
4545
+ }
4546
+ try {
4547
+ return realpathSync(scriptPath) === realpathSync(fileURLToPath4(moduleUrl));
4548
+ } catch {
4549
+ return false;
4550
+ }
4551
+ }
4552
+ if (isDirectCliInvocation()) {
4533
4553
  await createProgram().parseAsync(process.argv);
4534
4554
  }
4535
4555
  export {
4536
- createProgram
4556
+ createProgram,
4557
+ isDirectCliInvocation,
4558
+ readPackageVersion3 as readPackageVersion
4537
4559
  };
4538
4560
  //# sourceMappingURL=cli.js.map