@gitgov/core 1.6.2 → 1.6.3

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/src/index.js CHANGED
@@ -5,7 +5,9 @@ import { promises, existsSync, constants } from 'fs';
5
5
  import * as yaml from 'js-yaml';
6
6
  import { generateKeyPair, createHash, sign, verify } from 'crypto';
7
7
  import { promisify } from 'util';
8
- import * as path from 'path';
8
+ import * as pathUtils from 'path';
9
+ import { createRequire } from 'module';
10
+ import { fileURLToPath } from 'url';
9
11
  import { EventEmitter } from 'events';
10
12
 
11
13
  var __defProp = Object.defineProperty;
@@ -2993,8 +2995,8 @@ var ConfigManager = class _ConfigManager {
2993
2995
  configPath;
2994
2996
  sessionPath;
2995
2997
  constructor(projectRootPath = _ConfigManager.findProjectRoot() || process.cwd()) {
2996
- this.configPath = path.join(projectRootPath, ".gitgov", "config.json");
2997
- this.sessionPath = path.join(projectRootPath, ".gitgov", ".session.json");
2998
+ this.configPath = pathUtils.join(projectRootPath, ".gitgov", "config.json");
2999
+ this.sessionPath = pathUtils.join(projectRootPath, ".gitgov", ".session.json");
2998
3000
  }
2999
3001
  /**
3000
3002
  * Load GitGovernance configuration
@@ -3084,14 +3086,14 @@ var ConfigManager = class _ConfigManager {
3084
3086
  }
3085
3087
  lastSearchPath = startPath;
3086
3088
  let currentPath = startPath;
3087
- while (currentPath !== path.parse(currentPath).root) {
3088
- if (existsSync(path.join(currentPath, ".git"))) {
3089
+ while (currentPath !== pathUtils.parse(currentPath).root) {
3090
+ if (existsSync(pathUtils.join(currentPath, ".git"))) {
3089
3091
  projectRoot = currentPath;
3090
3092
  return projectRoot;
3091
3093
  }
3092
- currentPath = path.dirname(currentPath);
3094
+ currentPath = pathUtils.dirname(currentPath);
3093
3095
  }
3094
- if (existsSync(path.join(currentPath, ".git"))) {
3096
+ if (existsSync(pathUtils.join(currentPath, ".git"))) {
3095
3097
  projectRoot = currentPath;
3096
3098
  return projectRoot;
3097
3099
  }
@@ -3105,23 +3107,23 @@ var ConfigManager = class _ConfigManager {
3105
3107
  */
3106
3108
  static findGitgovRoot(startPath = process.cwd()) {
3107
3109
  let currentPath = startPath;
3108
- while (currentPath !== path.parse(currentPath).root) {
3109
- if (existsSync(path.join(currentPath, ".gitgov"))) {
3110
+ while (currentPath !== pathUtils.parse(currentPath).root) {
3111
+ if (existsSync(pathUtils.join(currentPath, ".gitgov"))) {
3110
3112
  return currentPath;
3111
3113
  }
3112
- currentPath = path.dirname(currentPath);
3114
+ currentPath = pathUtils.dirname(currentPath);
3113
3115
  }
3114
- if (existsSync(path.join(currentPath, ".gitgov"))) {
3116
+ if (existsSync(pathUtils.join(currentPath, ".gitgov"))) {
3115
3117
  return currentPath;
3116
3118
  }
3117
3119
  currentPath = startPath;
3118
- while (currentPath !== path.parse(currentPath).root) {
3119
- if (existsSync(path.join(currentPath, ".git"))) {
3120
+ while (currentPath !== pathUtils.parse(currentPath).root) {
3121
+ if (existsSync(pathUtils.join(currentPath, ".git"))) {
3120
3122
  return currentPath;
3121
3123
  }
3122
- currentPath = path.dirname(currentPath);
3124
+ currentPath = pathUtils.dirname(currentPath);
3123
3125
  }
3124
- if (existsSync(path.join(currentPath, ".git"))) {
3126
+ if (existsSync(pathUtils.join(currentPath, ".git"))) {
3125
3127
  return currentPath;
3126
3128
  }
3127
3129
  return null;
@@ -3134,7 +3136,7 @@ var ConfigManager = class _ConfigManager {
3134
3136
  if (!root) {
3135
3137
  throw new Error("Could not find project root. Make sure you are inside a GitGovernance repository.");
3136
3138
  }
3137
- return path.join(root, ".gitgov");
3139
+ return pathUtils.join(root, ".gitgov");
3138
3140
  }
3139
3141
  /**
3140
3142
  * Checks if current directory is a GitGovernance project
@@ -3163,12 +3165,12 @@ var RecordStore = class {
3163
3165
  throw new Error("Could not find project root. RecordStore requires a valid project root.");
3164
3166
  }
3165
3167
  this.recordType = recordType;
3166
- this.recordsDir = path.join(foundRoot, ".gitgov", this.recordType);
3168
+ this.recordsDir = pathUtils.join(foundRoot, ".gitgov", this.recordType);
3167
3169
  this.fs = fsDeps;
3168
3170
  }
3169
3171
  getRecordPath(recordId) {
3170
3172
  const safeId = recordId.replace(/:/g, "_");
3171
- return path.join(this.recordsDir, `${safeId}.json`);
3173
+ return pathUtils.join(this.recordsDir, `${safeId}.json`);
3172
3174
  }
3173
3175
  async ensureDirExists() {
3174
3176
  await this.fs.mkdir(this.recordsDir, { recursive: true });
@@ -6269,7 +6271,7 @@ var FileIndexerAdapter = class {
6269
6271
  * Writes cache data to file (Phase 1: JSON)
6270
6272
  */
6271
6273
  async writeCacheFile(indexData) {
6272
- const cacheDir = path.dirname(this.cachePath);
6274
+ const cacheDir = pathUtils.dirname(this.cachePath);
6273
6275
  await promises.mkdir(cacheDir, { recursive: true });
6274
6276
  const jsonContent = JSON.stringify(indexData, null, 2);
6275
6277
  await promises.writeFile(this.cachePath, jsonContent, "utf-8");
@@ -6423,10 +6425,10 @@ var FileIndexerAdapter = class {
6423
6425
  let recentActivity = "Task created";
6424
6426
  try {
6425
6427
  let projectRoot2 = process.cwd();
6426
- while (!fs.existsSync(path.join(projectRoot2, ".gitgov")) && projectRoot2 !== "/") {
6427
- projectRoot2 = path.dirname(projectRoot2);
6428
+ while (!fs.existsSync(pathUtils.join(projectRoot2, ".gitgov")) && projectRoot2 !== "/") {
6429
+ projectRoot2 = pathUtils.dirname(projectRoot2);
6428
6430
  }
6429
- const taskFilePath = path.join(projectRoot2, ".gitgov", "tasks", `${task.id}.json`);
6431
+ const taskFilePath = pathUtils.join(projectRoot2, ".gitgov", "tasks", `${task.id}.json`);
6430
6432
  const stats = await promises.stat(taskFilePath);
6431
6433
  const fileModTime = stats.mtime.getTime();
6432
6434
  const creationTime = this.getTimestampFromId(task.id) * 1e3;
@@ -6550,7 +6552,7 @@ var ProjectAdapter = class {
6550
6552
  throw new Error(`Environment validation failed: ${envValidation.warnings.join(", ")}`);
6551
6553
  }
6552
6554
  const projectRoot2 = process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
6553
- const gitgovPath = path.join(projectRoot2, ".gitgov");
6555
+ const gitgovPath = pathUtils.join(projectRoot2, ".gitgov");
6554
6556
  await this.createDirectoryStructure(gitgovPath);
6555
6557
  await this.copyAgentPrompt(gitgovPath);
6556
6558
  const actor = await this.identityAdapter.createActor(
@@ -6614,7 +6616,7 @@ var ProjectAdapter = class {
6614
6616
  actor: {
6615
6617
  id: actor.id,
6616
6618
  displayName: actor.displayName,
6617
- publicKeyPath: path.join(gitgovPath, "actors", `${actor.id}.json`)
6619
+ publicKeyPath: pathUtils.join(gitgovPath, "actors", `${actor.id}.json`)
6618
6620
  },
6619
6621
  template: templateResult ? {
6620
6622
  processed: true,
@@ -6641,7 +6643,7 @@ var ProjectAdapter = class {
6641
6643
  const warnings = [];
6642
6644
  const suggestions = [];
6643
6645
  try {
6644
- const gitPath = path.join(targetPath, ".git");
6646
+ const gitPath = pathUtils.join(targetPath, ".git");
6645
6647
  const isGitRepo = existsSync(gitPath);
6646
6648
  if (!isGitRepo) {
6647
6649
  warnings.push(`Not a Git repository in directory: ${targetPath}`);
@@ -6649,7 +6651,7 @@ var ProjectAdapter = class {
6649
6651
  }
6650
6652
  let hasWritePermissions = false;
6651
6653
  try {
6652
- const testFile = path.join(targetPath, ".gitgov-test");
6654
+ const testFile = pathUtils.join(targetPath, ".gitgov-test");
6653
6655
  await promises.writeFile(testFile, "test");
6654
6656
  await promises.unlink(testFile);
6655
6657
  hasWritePermissions = true;
@@ -6657,7 +6659,7 @@ var ProjectAdapter = class {
6657
6659
  warnings.push("No write permissions in target directory");
6658
6660
  suggestions.push("Ensure you have write permissions in the target directory");
6659
6661
  }
6660
- const gitgovPath = path.join(targetPath, ".gitgov");
6662
+ const gitgovPath = pathUtils.join(targetPath, ".gitgov");
6661
6663
  let isAlreadyInitialized = false;
6662
6664
  try {
6663
6665
  await promises.access(gitgovPath);
@@ -6752,7 +6754,7 @@ var ProjectAdapter = class {
6752
6754
  async rollbackPartialSetup(setupId) {
6753
6755
  try {
6754
6756
  const projectRoot2 = process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
6755
- const gitgovPath = path.join(projectRoot2, ".gitgov");
6757
+ const gitgovPath = pathUtils.join(projectRoot2, ".gitgov");
6756
6758
  try {
6757
6759
  await promises.access(gitgovPath);
6758
6760
  await promises.rm(gitgovPath, { recursive: true, force: true });
@@ -6816,24 +6818,50 @@ var ProjectAdapter = class {
6816
6818
  ];
6817
6819
  await promises.mkdir(gitgovPath, { recursive: true });
6818
6820
  for (const dir of directories) {
6819
- await promises.mkdir(path.join(gitgovPath, dir), { recursive: true });
6821
+ await promises.mkdir(pathUtils.join(gitgovPath, dir), { recursive: true });
6820
6822
  }
6821
6823
  }
6822
6824
  async copyAgentPrompt(gitgovPath) {
6823
- const targetPrompt = path.join(gitgovPath, "gitgov");
6824
- const potentialSources = [
6825
- path.join(ConfigManager.findProjectRoot() || process.cwd(), "docs/gitgov_agent_prompt.md")
6826
- ];
6825
+ function getImportMetaUrl() {
6826
+ try {
6827
+ const getUrl = new Function("return import.meta.url");
6828
+ return getUrl();
6829
+ } catch {
6830
+ return null;
6831
+ }
6832
+ }
6833
+ const targetPrompt = pathUtils.join(gitgovPath, "gitgov");
6834
+ const potentialSources = [];
6835
+ potentialSources.push(
6836
+ pathUtils.join(process.cwd(), "prompts/gitgov_agent_prompt.md")
6837
+ );
6827
6838
  try {
6828
- if (typeof __dirname !== "undefined") {
6829
- potentialSources.push(path.join(__dirname, "../../prompts/gitgov_agent_prompt.md"));
6839
+ const metaUrl = getImportMetaUrl();
6840
+ if (metaUrl) {
6841
+ const require2 = createRequire(metaUrl);
6842
+ const pkgJsonPath = require2.resolve("@gitgov/core/package.json");
6843
+ const pkgRoot = pathUtils.dirname(pkgJsonPath);
6844
+ potentialSources.push(
6845
+ pathUtils.join(pkgRoot, "prompts/gitgov_agent_prompt.md")
6846
+ );
6847
+ }
6848
+ } catch {
6849
+ }
6850
+ try {
6851
+ const metaUrl = getImportMetaUrl();
6852
+ if (metaUrl) {
6853
+ const __filename = fileURLToPath(metaUrl);
6854
+ const __dirname = pathUtils.dirname(__filename);
6855
+ potentialSources.push(
6856
+ pathUtils.resolve(__dirname, "../../prompts/gitgov_agent_prompt.md")
6857
+ );
6830
6858
  }
6831
6859
  } catch {
6832
6860
  }
6833
- for (const sourcePrompt of potentialSources) {
6861
+ for (const source of potentialSources) {
6834
6862
  try {
6835
- await promises.access(sourcePrompt);
6836
- await promises.copyFile(sourcePrompt, targetPrompt);
6863
+ await promises.access(source);
6864
+ await promises.copyFile(source, targetPrompt);
6837
6865
  console.log(`\u{1F4CB} @gitgov agent prompt copied to .gitgov/gitgov`);
6838
6866
  return;
6839
6867
  } catch {
@@ -6846,11 +6874,11 @@ var ProjectAdapter = class {
6846
6874
  return name.toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-");
6847
6875
  }
6848
6876
  async persistConfiguration(config, gitgovPath) {
6849
- const configPath = path.join(gitgovPath, "config.json");
6877
+ const configPath = pathUtils.join(gitgovPath, "config.json");
6850
6878
  await promises.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
6851
6879
  }
6852
6880
  async initializeSession(actorId, gitgovPath) {
6853
- const sessionPath = path.join(gitgovPath, ".session.json");
6881
+ const sessionPath = pathUtils.join(gitgovPath, ".session.json");
6854
6882
  const session = {
6855
6883
  lastSession: {
6856
6884
  actorId,
@@ -6865,7 +6893,7 @@ var ProjectAdapter = class {
6865
6893
  await promises.writeFile(sessionPath, JSON.stringify(session, null, 2), "utf-8");
6866
6894
  }
6867
6895
  async setupGitIntegration(projectRoot2) {
6868
- const gitignorePath = path.join(projectRoot2, ".gitignore");
6896
+ const gitignorePath = pathUtils.join(projectRoot2, ".gitignore");
6869
6897
  const gitignoreContent = `
6870
6898
  # GitGovernance
6871
6899
  .gitgov/.session.json
@@ -8089,7 +8117,7 @@ var EventBus = class {
8089
8117
  if (this.pendingHandlers.size > 0) {
8090
8118
  await Promise.race([
8091
8119
  Promise.all(Array.from(this.pendingHandlers)),
8092
- new Promise((resolve) => setTimeout(resolve, 10))
8120
+ new Promise((resolve2) => setTimeout(resolve2, 10))
8093
8121
  // Re-check every 10ms
8094
8122
  ]);
8095
8123
  }
@@ -8978,14 +9006,14 @@ var DiagramGenerator = class {
8978
9006
  * Loads all cycle records from the filesystem
8979
9007
  */
8980
9008
  async loadCycleRecords(gitgovPath) {
8981
- const cyclesDir = path.join(gitgovPath, "cycles");
9009
+ const cyclesDir = pathUtils.join(gitgovPath, "cycles");
8982
9010
  try {
8983
9011
  const files = await promises.readdir(cyclesDir);
8984
9012
  const jsonFiles = files.filter((file) => file.endsWith(".json"));
8985
9013
  const cycles = [];
8986
9014
  for (const file of jsonFiles) {
8987
9015
  try {
8988
- const filePath = path.join(cyclesDir, file);
9016
+ const filePath = pathUtils.join(cyclesDir, file);
8989
9017
  const content = await promises.readFile(filePath, "utf-8");
8990
9018
  const record = JSON.parse(content);
8991
9019
  if (record.payload && record.payload.id) {
@@ -9014,14 +9042,14 @@ var DiagramGenerator = class {
9014
9042
  * Loads all task records from the filesystem
9015
9043
  */
9016
9044
  async loadTaskRecords(gitgovPath) {
9017
- const tasksDir = path.join(gitgovPath, "tasks");
9045
+ const tasksDir = pathUtils.join(gitgovPath, "tasks");
9018
9046
  try {
9019
9047
  const files = await promises.readdir(tasksDir);
9020
9048
  const jsonFiles = files.filter((file) => file.endsWith(".json"));
9021
9049
  const tasks = [];
9022
9050
  for (const file of jsonFiles) {
9023
9051
  try {
9024
- const filePath = path.join(tasksDir, file);
9052
+ const filePath = pathUtils.join(tasksDir, file);
9025
9053
  const content = await promises.readFile(filePath, "utf-8");
9026
9054
  const record = JSON.parse(content);
9027
9055
  if (record.payload && record.payload.id) {