gitnexushub 0.7.1 → 0.7.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/hooks/gitnexus-enterprise-hook.cjs +102 -44
- package/package.json +1 -1
|
@@ -592,10 +592,16 @@ async function handlePostToolUse(input, config, entry, agentName) {
|
|
|
592
592
|
const exitCode = readExitCode(out);
|
|
593
593
|
if (exitCode !== null && exitCode !== 0) return;
|
|
594
594
|
|
|
595
|
+
// Use the resolved registered repo path (entry.localPath) rather
|
|
596
|
+
// than input.cwd. Cursor 3.x passes input.cwd: "" and spawns hooks
|
|
597
|
+
// from ~/.cursor, which is not a git repo — `git rev-parse HEAD`
|
|
598
|
+
// there returns empty, localHead becomes "", and the staleness
|
|
599
|
+
// check bails before even hitting /meta. The registry entry already
|
|
600
|
+
// has the canonical absolute path; use it.
|
|
595
601
|
let localHead = '';
|
|
596
602
|
try {
|
|
597
603
|
const r = spawnSync('git', ['rev-parse', 'HEAD'], {
|
|
598
|
-
cwd:
|
|
604
|
+
cwd: entry.localPath,
|
|
599
605
|
encoding: 'utf-8',
|
|
600
606
|
timeout: 2000,
|
|
601
607
|
});
|
|
@@ -729,52 +735,104 @@ async function runKiroEditCapture(agentName) {
|
|
|
729
735
|
|
|
730
736
|
const entries = readRegistry();
|
|
731
737
|
const cwd = process.cwd();
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
//
|
|
736
|
-
//
|
|
737
|
-
//
|
|
738
|
-
//
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
//
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
738
|
+
|
|
739
|
+
// Pick which repos to scan. Two cases:
|
|
740
|
+
//
|
|
741
|
+
// A. cwd is INSIDE a registered repo (e.g. Kiro opened directly
|
|
742
|
+
// on the project root, or any child path). Standard
|
|
743
|
+
// resolveCwdToRepo path — scan that single repo.
|
|
744
|
+
//
|
|
745
|
+
// B. cwd is the PARENT of one or more registered repos (e.g.
|
|
746
|
+
// Kiro opened on `~/AkonLabs/` with multiple sub-repos
|
|
747
|
+
// inside). resolveCwdToRepo returns null in this case
|
|
748
|
+
// because the cwd↔localPath direction is reversed. Find all
|
|
749
|
+
// registered repos whose localPath is inside cwd and scan
|
|
750
|
+
// each. The single-repo case (A) takes precedence so we
|
|
751
|
+
// don't double-scan when both relations match.
|
|
752
|
+
let resolvedCwd;
|
|
753
|
+
try {
|
|
754
|
+
resolvedCwd = fs.realpathSync(path.resolve(cwd));
|
|
755
|
+
} catch {
|
|
756
|
+
resolvedCwd = path.resolve(cwd);
|
|
757
|
+
}
|
|
758
|
+
const isWin = process.platform === 'win32';
|
|
759
|
+
const normCwd = isWin ? resolvedCwd.toLowerCase() : resolvedCwd;
|
|
760
|
+
const sep = path.sep;
|
|
761
|
+
|
|
762
|
+
/** @type {Array<{ hubRepoId: string, localPath: string }>} */
|
|
763
|
+
const targets = [];
|
|
764
|
+
const inside = resolveCwdToRepo(cwd, entries);
|
|
765
|
+
if (inside) {
|
|
766
|
+
targets.push({ hubRepoId: inside.hubRepoId, localPath: inside.localPath });
|
|
767
|
+
} else {
|
|
768
|
+
for (const entry of entries) {
|
|
769
|
+
if (!entry || !entry.localPath || !entry.hubRepoId) continue;
|
|
770
|
+
let ep;
|
|
771
|
+
try {
|
|
772
|
+
ep = fs.realpathSync(path.resolve(entry.localPath));
|
|
773
|
+
} catch {
|
|
774
|
+
ep = path.resolve(entry.localPath);
|
|
775
|
+
}
|
|
776
|
+
const nep = isWin ? ep.toLowerCase() : ep;
|
|
777
|
+
if (nep === normCwd || nep.startsWith(normCwd + sep)) {
|
|
778
|
+
targets.push({ hubRepoId: entry.hubRepoId, localPath: ep });
|
|
754
779
|
}
|
|
755
|
-
} catch {
|
|
756
|
-
// Best effort — proceed with whatever we got from prior args.
|
|
757
780
|
}
|
|
758
781
|
}
|
|
759
|
-
if (
|
|
760
|
-
|
|
761
|
-
//
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
//
|
|
765
|
-
let
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
782
|
+
if (targets.length === 0) return;
|
|
783
|
+
|
|
784
|
+
// Run git diff + ls-files inside each target repo. Cap at 5 repos
|
|
785
|
+
// per fire so a `~/code/` workspace with 50 sibling repos doesn't
|
|
786
|
+
// spawn 100 git processes on every postToolUse. The 20-file cap
|
|
787
|
+
// is applied per-repo.
|
|
788
|
+
let postedTotal = 0;
|
|
789
|
+
const MAX_REPOS = 5;
|
|
790
|
+
const MAX_FILES_PER_REPO = 20;
|
|
791
|
+
for (const target of targets.slice(0, MAX_REPOS)) {
|
|
792
|
+
const collected = new Set();
|
|
793
|
+
for (const args of [
|
|
794
|
+
['diff', '--name-only', 'HEAD'],
|
|
795
|
+
['ls-files', '--others', '--exclude-standard'],
|
|
796
|
+
]) {
|
|
797
|
+
try {
|
|
798
|
+
const r = spawnSync('git', args, {
|
|
799
|
+
cwd: target.localPath,
|
|
800
|
+
encoding: 'utf-8',
|
|
801
|
+
timeout: 2000,
|
|
802
|
+
});
|
|
803
|
+
const out = (r.stdout || '').trim();
|
|
804
|
+
if (!out) continue;
|
|
805
|
+
for (const line of out.split('\n')) {
|
|
806
|
+
const trimmed = line.trim();
|
|
807
|
+
if (trimmed) collected.add(trimmed);
|
|
808
|
+
}
|
|
809
|
+
} catch {
|
|
810
|
+
// Best effort
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (collected.size === 0) continue;
|
|
814
|
+
|
|
815
|
+
let perRepo = 0;
|
|
816
|
+
for (const filePath of collected) {
|
|
817
|
+
if (perRepo >= MAX_FILES_PER_REPO) break;
|
|
818
|
+
const absPath = path.isAbsolute(filePath) ? filePath : path.join(target.localPath, filePath);
|
|
819
|
+
await httpPostJson(`${config.hubUrl}/api/activity/edit-observed`, authHeaders(config), {
|
|
820
|
+
sessionId: null,
|
|
821
|
+
repoId: target.hubRepoId,
|
|
822
|
+
filePath: absPath,
|
|
823
|
+
line: null,
|
|
824
|
+
tool: 'Write',
|
|
825
|
+
agentName,
|
|
826
|
+
});
|
|
827
|
+
perRepo++;
|
|
828
|
+
postedTotal++;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
if (process.env.GITNEXUS_DEBUG) {
|
|
833
|
+
process.stderr.write(
|
|
834
|
+
`kiro-edit-capture: targets=${targets.length} posted=${postedTotal}\n`,
|
|
835
|
+
);
|
|
778
836
|
}
|
|
779
837
|
}
|
|
780
838
|
|
package/package.json
CHANGED