@gitgov/core 1.6.2 → 1.6.4

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;
@@ -6528,6 +6530,15 @@ var project_adapter_exports = {};
6528
6530
  __export(project_adapter_exports, {
6529
6531
  ProjectAdapter: () => ProjectAdapter
6530
6532
  });
6533
+
6534
+ // src/utils/esm_helper.ts
6535
+ function getImportMetaUrl() {
6536
+ try {
6537
+ return import.meta.url;
6538
+ } catch {
6539
+ return null;
6540
+ }
6541
+ }
6531
6542
  var ProjectAdapter = class {
6532
6543
  identityAdapter;
6533
6544
  backlogAdapter;
@@ -6550,7 +6561,7 @@ var ProjectAdapter = class {
6550
6561
  throw new Error(`Environment validation failed: ${envValidation.warnings.join(", ")}`);
6551
6562
  }
6552
6563
  const projectRoot2 = process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
6553
- const gitgovPath = path.join(projectRoot2, ".gitgov");
6564
+ const gitgovPath = pathUtils.join(projectRoot2, ".gitgov");
6554
6565
  await this.createDirectoryStructure(gitgovPath);
6555
6566
  await this.copyAgentPrompt(gitgovPath);
6556
6567
  const actor = await this.identityAdapter.createActor(
@@ -6614,7 +6625,7 @@ var ProjectAdapter = class {
6614
6625
  actor: {
6615
6626
  id: actor.id,
6616
6627
  displayName: actor.displayName,
6617
- publicKeyPath: path.join(gitgovPath, "actors", `${actor.id}.json`)
6628
+ publicKeyPath: pathUtils.join(gitgovPath, "actors", `${actor.id}.json`)
6618
6629
  },
6619
6630
  template: templateResult ? {
6620
6631
  processed: true,
@@ -6641,7 +6652,7 @@ var ProjectAdapter = class {
6641
6652
  const warnings = [];
6642
6653
  const suggestions = [];
6643
6654
  try {
6644
- const gitPath = path.join(targetPath, ".git");
6655
+ const gitPath = pathUtils.join(targetPath, ".git");
6645
6656
  const isGitRepo = existsSync(gitPath);
6646
6657
  if (!isGitRepo) {
6647
6658
  warnings.push(`Not a Git repository in directory: ${targetPath}`);
@@ -6649,7 +6660,7 @@ var ProjectAdapter = class {
6649
6660
  }
6650
6661
  let hasWritePermissions = false;
6651
6662
  try {
6652
- const testFile = path.join(targetPath, ".gitgov-test");
6663
+ const testFile = pathUtils.join(targetPath, ".gitgov-test");
6653
6664
  await promises.writeFile(testFile, "test");
6654
6665
  await promises.unlink(testFile);
6655
6666
  hasWritePermissions = true;
@@ -6657,7 +6668,7 @@ var ProjectAdapter = class {
6657
6668
  warnings.push("No write permissions in target directory");
6658
6669
  suggestions.push("Ensure you have write permissions in the target directory");
6659
6670
  }
6660
- const gitgovPath = path.join(targetPath, ".gitgov");
6671
+ const gitgovPath = pathUtils.join(targetPath, ".gitgov");
6661
6672
  let isAlreadyInitialized = false;
6662
6673
  try {
6663
6674
  await promises.access(gitgovPath);
@@ -6752,7 +6763,7 @@ var ProjectAdapter = class {
6752
6763
  async rollbackPartialSetup(setupId) {
6753
6764
  try {
6754
6765
  const projectRoot2 = process.env["GITGOV_ORIGINAL_DIR"] || process.cwd();
6755
- const gitgovPath = path.join(projectRoot2, ".gitgov");
6766
+ const gitgovPath = pathUtils.join(projectRoot2, ".gitgov");
6756
6767
  try {
6757
6768
  await promises.access(gitgovPath);
6758
6769
  await promises.rm(gitgovPath, { recursive: true, force: true });
@@ -6816,24 +6827,40 @@ var ProjectAdapter = class {
6816
6827
  ];
6817
6828
  await promises.mkdir(gitgovPath, { recursive: true });
6818
6829
  for (const dir of directories) {
6819
- await promises.mkdir(path.join(gitgovPath, dir), { recursive: true });
6830
+ await promises.mkdir(pathUtils.join(gitgovPath, dir), { recursive: true });
6820
6831
  }
6821
6832
  }
6822
6833
  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
- ];
6834
+ const targetPrompt = pathUtils.join(gitgovPath, "gitgov");
6835
+ const potentialSources = [];
6836
+ potentialSources.push(
6837
+ pathUtils.join(process.cwd(), "prompts/gitgov_agent_prompt.md")
6838
+ );
6839
+ try {
6840
+ const metaUrl = getImportMetaUrl();
6841
+ if (metaUrl) {
6842
+ const require2 = createRequire(metaUrl);
6843
+ const pkgJsonPath = require2.resolve("@gitgov/core/package.json");
6844
+ const pkgRoot = pathUtils.dirname(pkgJsonPath);
6845
+ const promptPath = pathUtils.join(pkgRoot, "prompts/gitgov_agent_prompt.md");
6846
+ potentialSources.push(promptPath);
6847
+ }
6848
+ } catch {
6849
+ }
6827
6850
  try {
6828
- if (typeof __dirname !== "undefined") {
6829
- potentialSources.push(path.join(__dirname, "../../prompts/gitgov_agent_prompt.md"));
6851
+ const metaUrl = getImportMetaUrl();
6852
+ if (metaUrl) {
6853
+ const __filename = fileURLToPath(metaUrl);
6854
+ const __dirname = pathUtils.dirname(__filename);
6855
+ const promptPath = pathUtils.resolve(__dirname, "../../prompts/gitgov_agent_prompt.md");
6856
+ potentialSources.push(promptPath);
6830
6857
  }
6831
6858
  } catch {
6832
6859
  }
6833
- for (const sourcePrompt of potentialSources) {
6860
+ for (const source of potentialSources) {
6834
6861
  try {
6835
- await promises.access(sourcePrompt);
6836
- await promises.copyFile(sourcePrompt, targetPrompt);
6862
+ await promises.access(source);
6863
+ await promises.copyFile(source, targetPrompt);
6837
6864
  console.log(`\u{1F4CB} @gitgov agent prompt copied to .gitgov/gitgov`);
6838
6865
  return;
6839
6866
  } catch {
@@ -6846,11 +6873,11 @@ var ProjectAdapter = class {
6846
6873
  return name.toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-");
6847
6874
  }
6848
6875
  async persistConfiguration(config, gitgovPath) {
6849
- const configPath = path.join(gitgovPath, "config.json");
6876
+ const configPath = pathUtils.join(gitgovPath, "config.json");
6850
6877
  await promises.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
6851
6878
  }
6852
6879
  async initializeSession(actorId, gitgovPath) {
6853
- const sessionPath = path.join(gitgovPath, ".session.json");
6880
+ const sessionPath = pathUtils.join(gitgovPath, ".session.json");
6854
6881
  const session = {
6855
6882
  lastSession: {
6856
6883
  actorId,
@@ -6865,7 +6892,7 @@ var ProjectAdapter = class {
6865
6892
  await promises.writeFile(sessionPath, JSON.stringify(session, null, 2), "utf-8");
6866
6893
  }
6867
6894
  async setupGitIntegration(projectRoot2) {
6868
- const gitignorePath = path.join(projectRoot2, ".gitignore");
6895
+ const gitignorePath = pathUtils.join(projectRoot2, ".gitignore");
6869
6896
  const gitignoreContent = `
6870
6897
  # GitGovernance
6871
6898
  .gitgov/.session.json
@@ -8089,7 +8116,7 @@ var EventBus = class {
8089
8116
  if (this.pendingHandlers.size > 0) {
8090
8117
  await Promise.race([
8091
8118
  Promise.all(Array.from(this.pendingHandlers)),
8092
- new Promise((resolve) => setTimeout(resolve, 10))
8119
+ new Promise((resolve2) => setTimeout(resolve2, 10))
8093
8120
  // Re-check every 10ms
8094
8121
  ]);
8095
8122
  }
@@ -8978,14 +9005,14 @@ var DiagramGenerator = class {
8978
9005
  * Loads all cycle records from the filesystem
8979
9006
  */
8980
9007
  async loadCycleRecords(gitgovPath) {
8981
- const cyclesDir = path.join(gitgovPath, "cycles");
9008
+ const cyclesDir = pathUtils.join(gitgovPath, "cycles");
8982
9009
  try {
8983
9010
  const files = await promises.readdir(cyclesDir);
8984
9011
  const jsonFiles = files.filter((file) => file.endsWith(".json"));
8985
9012
  const cycles = [];
8986
9013
  for (const file of jsonFiles) {
8987
9014
  try {
8988
- const filePath = path.join(cyclesDir, file);
9015
+ const filePath = pathUtils.join(cyclesDir, file);
8989
9016
  const content = await promises.readFile(filePath, "utf-8");
8990
9017
  const record = JSON.parse(content);
8991
9018
  if (record.payload && record.payload.id) {
@@ -9014,14 +9041,14 @@ var DiagramGenerator = class {
9014
9041
  * Loads all task records from the filesystem
9015
9042
  */
9016
9043
  async loadTaskRecords(gitgovPath) {
9017
- const tasksDir = path.join(gitgovPath, "tasks");
9044
+ const tasksDir = pathUtils.join(gitgovPath, "tasks");
9018
9045
  try {
9019
9046
  const files = await promises.readdir(tasksDir);
9020
9047
  const jsonFiles = files.filter((file) => file.endsWith(".json"));
9021
9048
  const tasks = [];
9022
9049
  for (const file of jsonFiles) {
9023
9050
  try {
9024
- const filePath = path.join(tasksDir, file);
9051
+ const filePath = pathUtils.join(tasksDir, file);
9025
9052
  const content = await promises.readFile(filePath, "utf-8");
9026
9053
  const record = JSON.parse(content);
9027
9054
  if (record.payload && record.payload.id) {