nexus-agents 2.167.0 → 2.168.0
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/{child-mcp-config-X4YLQKGK.js → child-mcp-config-FAWSJFMQ.js} +2 -2
- package/dist/{chunk-KM3YEIEN.js → chunk-2ANAH2UU.js} +4 -4
- package/dist/{chunk-7USEQLMS.js → chunk-2Z4QECP7.js} +2 -2
- package/dist/{chunk-7K5LSUEU.js → chunk-3KID7AIF.js} +3 -3
- package/dist/{chunk-ZTWKSN5K.js → chunk-52T2MJDS.js} +34 -34
- package/dist/{chunk-PC4Y4VPX.js → chunk-5LPPJIZ4.js} +2 -2
- package/dist/{chunk-XUMLVCFL.js → chunk-6ERIC5NJ.js} +2 -2
- package/dist/{chunk-S6HCREYY.js → chunk-7IUVW67T.js} +7 -7
- package/dist/{chunk-ZIC6ZZFU.js → chunk-CJLMB7MO.js} +3 -3
- package/dist/{chunk-O6VL6LA4.js → chunk-CPS2HN4T.js} +2 -2
- package/dist/{chunk-TGAVZ2ZL.js → chunk-ELWMGKVP.js} +8 -8
- package/dist/{chunk-JKUX73VD.js → chunk-EQLJYWLP.js} +3 -3
- package/dist/{chunk-GGYQTV2Y.js → chunk-ETFCT2CH.js} +4 -4
- package/dist/{chunk-BB7KSLNA.js → chunk-F5JDQXHJ.js} +2 -2
- package/dist/{chunk-STMW5BSR.js → chunk-G7NDNFIE.js} +3 -3
- package/dist/{chunk-GRWHPG72.js → chunk-GNCUZDQI.js} +7 -7
- package/dist/{chunk-ZSUN7BHE.js → chunk-HJA3Z56H.js} +696 -14
- package/dist/chunk-HJA3Z56H.js.map +1 -0
- package/dist/{chunk-COIZLMGV.js → chunk-HZNOSJOO.js} +3 -3
- package/dist/{chunk-USBKBGT3.js → chunk-I3LGUSZ3.js} +5 -5
- package/dist/{chunk-UNIDAVVR.js → chunk-IAGLVGHN.js} +2 -2
- package/dist/{chunk-7YD3TRDX.js → chunk-LNPKBBPG.js} +4 -4
- package/dist/{chunk-IFSIKGHI.js → chunk-MSBYVBPX.js} +2 -2
- package/dist/{chunk-QPSYBHK6.js → chunk-MX3XD2ML.js} +2 -2
- package/dist/{chunk-VNVGGM73.js → chunk-N56C2MWI.js} +2 -2
- package/dist/{chunk-CURHM4TH.js → chunk-OKAHIWG4.js} +3 -3
- package/dist/{chunk-DFCC7FN4.js → chunk-OLCDGMEO.js} +190 -4
- package/dist/chunk-OLCDGMEO.js.map +1 -0
- package/dist/{chunk-QLZDOEO4.js → chunk-P7RBQUAG.js} +30 -7
- package/dist/chunk-P7RBQUAG.js.map +1 -0
- package/dist/{chunk-QV52AXTF.js → chunk-RJHLNI37.js} +2 -2
- package/dist/{chunk-GVNY4ZB6.js → chunk-RQNBJ7AS.js} +2 -2
- package/dist/{chunk-ZAPCPHGZ.js → chunk-TORS5V2C.js} +2 -2
- package/dist/{chunk-RKIPSMCN.js → chunk-TZK7VQAW.js} +5 -5
- package/dist/{chunk-ZTTUXPBQ.js → chunk-UGJRDFMN.js} +2 -2
- package/dist/{chunk-SRNAXDOT.js → chunk-UN7PYUJB.js} +2 -2
- package/dist/{chunk-2NU774CB.js → chunk-VQE3OSUW.js} +2 -2
- package/dist/{cli-circuit-breaker-2AAHSCHR.js → cli-circuit-breaker-JDGZ25MD.js} +4 -4
- package/dist/cli.js +409 -897
- package/dist/cli.js.map +1 -1
- package/dist/{composite-router-WOVGICBS.js → composite-router-EZPPVCMD.js} +2 -2
- package/dist/{consensus-vote-322S65GQ.js → consensus-vote-YKKJHLOD.js} +15 -15
- package/dist/{context-retriever-YMJY6YBJ.js → context-retriever-EGMARBAC.js} +8 -8
- package/dist/{doctor-deep-DALT3OXC.js → doctor-deep-QTBDR3VV.js} +3 -3
- package/dist/{expert-bridge-WNV3ST2T.js → expert-bridge-FZYJ3XAL.js} +4 -4
- package/dist/{factory-TLSTFONW.js → factory-NDMPXPYE.js} +5 -5
- package/dist/{factory-33HQYVCK.js → factory-SABHBAHC.js} +8 -8
- package/dist/{improvement-review-2W6LKP74.js → improvement-review-WYFGNEVP.js} +5 -5
- package/dist/index.js +35 -35
- package/dist/{init-opencode-I4FY4OGP.js → init-opencode-CMGJ3TXZ.js} +5 -6
- package/dist/{init-opencode-I4FY4OGP.js.map → init-opencode-CMGJ3TXZ.js.map} +1 -1
- package/dist/{issue-triage-CVMVZ3IV.js → issue-triage-NHRZGMKC.js} +6 -6
- package/dist/{pr-reviewer-helpers-SAMOVLNJ.js → pr-reviewer-helpers-HJRFRUZX.js} +4 -4
- package/dist/{registry-command-5D2DJT53.js → registry-command-JCOZA7TM.js} +2 -2
- package/dist/{repo-security-plan-F7V5SHAQ.js → repo-security-plan-OMY33VHA.js} +3 -3
- package/dist/{research-helpers-synthesize-F4PV4B4B.js → research-helpers-synthesize-DFINP3KN.js} +4 -4
- package/dist/{routing-memory-G6YBK4WI.js → routing-memory-KK4GPB64.js} +2 -2
- package/dist/{session-memory-DAJHLPOY.js → session-memory-QTHGU2XM.js} +3 -3
- package/dist/{setup-command-S4AOTSY5.js → setup-command-CURZCHSQ.js} +13 -11
- package/dist/{setup-config-HKUWFV5N.js → setup-config-FX6SJXGQ.js} +3 -3
- package/dist/{setup-custom-api-XRUPWEPF.js → setup-custom-api-MYN4EVT2.js} +3 -3
- package/dist/{tool-memory-XJ5VRMNQ.js → tool-memory-3W5NXR4P.js} +5 -5
- package/dist/{unified-registry-ETKPTZBU.js → unified-registry-PKPNJ3G7.js} +9 -9
- package/dist/{weather-report-TWBLIHPZ.js → weather-report-46ZY3X2Z.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-DFCC7FN4.js.map +0 -1
- package/dist/chunk-QLZDOEO4.js.map +0 -1
- package/dist/chunk-VGEVDF44.js +0 -197
- package/dist/chunk-VGEVDF44.js.map +0 -1
- package/dist/chunk-ZSUN7BHE.js.map +0 -1
- /package/dist/{child-mcp-config-X4YLQKGK.js.map → child-mcp-config-FAWSJFMQ.js.map} +0 -0
- /package/dist/{chunk-KM3YEIEN.js.map → chunk-2ANAH2UU.js.map} +0 -0
- /package/dist/{chunk-7USEQLMS.js.map → chunk-2Z4QECP7.js.map} +0 -0
- /package/dist/{chunk-7K5LSUEU.js.map → chunk-3KID7AIF.js.map} +0 -0
- /package/dist/{chunk-ZTWKSN5K.js.map → chunk-52T2MJDS.js.map} +0 -0
- /package/dist/{chunk-PC4Y4VPX.js.map → chunk-5LPPJIZ4.js.map} +0 -0
- /package/dist/{chunk-XUMLVCFL.js.map → chunk-6ERIC5NJ.js.map} +0 -0
- /package/dist/{chunk-S6HCREYY.js.map → chunk-7IUVW67T.js.map} +0 -0
- /package/dist/{chunk-ZIC6ZZFU.js.map → chunk-CJLMB7MO.js.map} +0 -0
- /package/dist/{chunk-O6VL6LA4.js.map → chunk-CPS2HN4T.js.map} +0 -0
- /package/dist/{chunk-TGAVZ2ZL.js.map → chunk-ELWMGKVP.js.map} +0 -0
- /package/dist/{chunk-JKUX73VD.js.map → chunk-EQLJYWLP.js.map} +0 -0
- /package/dist/{chunk-GGYQTV2Y.js.map → chunk-ETFCT2CH.js.map} +0 -0
- /package/dist/{chunk-BB7KSLNA.js.map → chunk-F5JDQXHJ.js.map} +0 -0
- /package/dist/{chunk-STMW5BSR.js.map → chunk-G7NDNFIE.js.map} +0 -0
- /package/dist/{chunk-GRWHPG72.js.map → chunk-GNCUZDQI.js.map} +0 -0
- /package/dist/{chunk-COIZLMGV.js.map → chunk-HZNOSJOO.js.map} +0 -0
- /package/dist/{chunk-USBKBGT3.js.map → chunk-I3LGUSZ3.js.map} +0 -0
- /package/dist/{chunk-UNIDAVVR.js.map → chunk-IAGLVGHN.js.map} +0 -0
- /package/dist/{chunk-7YD3TRDX.js.map → chunk-LNPKBBPG.js.map} +0 -0
- /package/dist/{chunk-IFSIKGHI.js.map → chunk-MSBYVBPX.js.map} +0 -0
- /package/dist/{chunk-QPSYBHK6.js.map → chunk-MX3XD2ML.js.map} +0 -0
- /package/dist/{chunk-VNVGGM73.js.map → chunk-N56C2MWI.js.map} +0 -0
- /package/dist/{chunk-CURHM4TH.js.map → chunk-OKAHIWG4.js.map} +0 -0
- /package/dist/{chunk-QV52AXTF.js.map → chunk-RJHLNI37.js.map} +0 -0
- /package/dist/{chunk-GVNY4ZB6.js.map → chunk-RQNBJ7AS.js.map} +0 -0
- /package/dist/{chunk-ZAPCPHGZ.js.map → chunk-TORS5V2C.js.map} +0 -0
- /package/dist/{chunk-RKIPSMCN.js.map → chunk-TZK7VQAW.js.map} +0 -0
- /package/dist/{chunk-ZTTUXPBQ.js.map → chunk-UGJRDFMN.js.map} +0 -0
- /package/dist/{chunk-SRNAXDOT.js.map → chunk-UN7PYUJB.js.map} +0 -0
- /package/dist/{chunk-2NU774CB.js.map → chunk-VQE3OSUW.js.map} +0 -0
- /package/dist/{cli-circuit-breaker-2AAHSCHR.js.map → cli-circuit-breaker-JDGZ25MD.js.map} +0 -0
- /package/dist/{composite-router-WOVGICBS.js.map → composite-router-EZPPVCMD.js.map} +0 -0
- /package/dist/{consensus-vote-322S65GQ.js.map → consensus-vote-YKKJHLOD.js.map} +0 -0
- /package/dist/{context-retriever-YMJY6YBJ.js.map → context-retriever-EGMARBAC.js.map} +0 -0
- /package/dist/{doctor-deep-DALT3OXC.js.map → doctor-deep-QTBDR3VV.js.map} +0 -0
- /package/dist/{expert-bridge-WNV3ST2T.js.map → expert-bridge-FZYJ3XAL.js.map} +0 -0
- /package/dist/{factory-33HQYVCK.js.map → factory-NDMPXPYE.js.map} +0 -0
- /package/dist/{factory-TLSTFONW.js.map → factory-SABHBAHC.js.map} +0 -0
- /package/dist/{improvement-review-2W6LKP74.js.map → improvement-review-WYFGNEVP.js.map} +0 -0
- /package/dist/{issue-triage-CVMVZ3IV.js.map → issue-triage-NHRZGMKC.js.map} +0 -0
- /package/dist/{pr-reviewer-helpers-SAMOVLNJ.js.map → pr-reviewer-helpers-HJRFRUZX.js.map} +0 -0
- /package/dist/{registry-command-5D2DJT53.js.map → registry-command-JCOZA7TM.js.map} +0 -0
- /package/dist/{repo-security-plan-F7V5SHAQ.js.map → repo-security-plan-OMY33VHA.js.map} +0 -0
- /package/dist/{research-helpers-synthesize-F4PV4B4B.js.map → research-helpers-synthesize-DFINP3KN.js.map} +0 -0
- /package/dist/{routing-memory-G6YBK4WI.js.map → routing-memory-KK4GPB64.js.map} +0 -0
- /package/dist/{session-memory-DAJHLPOY.js.map → session-memory-QTHGU2XM.js.map} +0 -0
- /package/dist/{setup-command-S4AOTSY5.js.map → setup-command-CURZCHSQ.js.map} +0 -0
- /package/dist/{setup-config-HKUWFV5N.js.map → setup-config-FX6SJXGQ.js.map} +0 -0
- /package/dist/{setup-custom-api-XRUPWEPF.js.map → setup-custom-api-MYN4EVT2.js.map} +0 -0
- /package/dist/{tool-memory-XJ5VRMNQ.js.map → tool-memory-3W5NXR4P.js.map} +0 -0
- /package/dist/{unified-registry-ETKPTZBU.js.map → unified-registry-PKPNJ3G7.js.map} +0 -0
- /package/dist/{weather-report-TWBLIHPZ.js.map → weather-report-46ZY3X2Z.js.map} +0 -0
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveToken
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IAGLVGHN.js";
|
|
4
4
|
import {
|
|
5
5
|
REGISTRY_PATH,
|
|
6
6
|
getProjectRoot,
|
|
7
7
|
loadPapersRegistry,
|
|
8
8
|
loadTechniquesRegistry,
|
|
9
9
|
savePapersRegistry
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5LPPJIZ4.js";
|
|
11
11
|
import {
|
|
12
12
|
resolveInsideRoot
|
|
13
13
|
} from "./chunk-NUBSJGQZ.js";
|
|
14
14
|
import {
|
|
15
15
|
getToolMemory
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-2ANAH2UU.js";
|
|
17
17
|
import {
|
|
18
|
-
capitalizeWords
|
|
18
|
+
capitalizeWords,
|
|
19
|
+
truncateSentence
|
|
19
20
|
} from "./chunk-6T3EPABN.js";
|
|
20
21
|
import {
|
|
21
22
|
extractSystemPrompt,
|
|
@@ -37,7 +38,7 @@ import {
|
|
|
37
38
|
getTimeProvider,
|
|
38
39
|
ok,
|
|
39
40
|
registerPersistentDistillerFactory
|
|
40
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-OKAHIWG4.js";
|
|
41
42
|
import {
|
|
42
43
|
ensureLearningDir,
|
|
43
44
|
getRulesFile
|
|
@@ -2831,6 +2832,662 @@ function getTokenLedger() {
|
|
|
2831
2832
|
return singleton;
|
|
2832
2833
|
}
|
|
2833
2834
|
|
|
2835
|
+
// src/indexer/category-detection.ts
|
|
2836
|
+
import * as path4 from "path";
|
|
2837
|
+
var FILE_SUFFIX_PATTERNS = [
|
|
2838
|
+
[".test.ts", "test"],
|
|
2839
|
+
[".spec.ts", "test"],
|
|
2840
|
+
["-types.ts", "types"],
|
|
2841
|
+
[".types.ts", "types"],
|
|
2842
|
+
["-command.ts", "cli"]
|
|
2843
|
+
];
|
|
2844
|
+
var FILE_PATH_PATTERNS = [
|
|
2845
|
+
{ test: (f) => f === "index.ts", category: "index" },
|
|
2846
|
+
{ test: (_, d) => d.includes("/cli"), category: "cli" },
|
|
2847
|
+
{ test: (f, d) => d.includes("config") || f.includes("config"), category: "config" },
|
|
2848
|
+
{ test: (f) => f.includes("helper") || f.includes("util"), category: "util" }
|
|
2849
|
+
];
|
|
2850
|
+
function detectCategoryFromPath(fileName, dirName) {
|
|
2851
|
+
for (const [suffix, category] of FILE_SUFFIX_PATTERNS) {
|
|
2852
|
+
if (fileName.endsWith(suffix)) return category;
|
|
2853
|
+
}
|
|
2854
|
+
for (const { test, category } of FILE_PATH_PATTERNS) {
|
|
2855
|
+
if (test(fileName, dirName)) return category;
|
|
2856
|
+
}
|
|
2857
|
+
return void 0;
|
|
2858
|
+
}
|
|
2859
|
+
function isTypesOnlyFile(sourceFile) {
|
|
2860
|
+
const typeCount = sourceFile.getTypeAliases().length + sourceFile.getInterfaces().length;
|
|
2861
|
+
const implCount = sourceFile.getFunctions().length + sourceFile.getClasses().length + sourceFile.getVariableDeclarations().length;
|
|
2862
|
+
return typeCount > 0 && implCount === 0;
|
|
2863
|
+
}
|
|
2864
|
+
function detectFileCategory(filePath, sourceFile) {
|
|
2865
|
+
const pathCategory = detectCategoryFromPath(path4.basename(filePath), path4.dirname(filePath));
|
|
2866
|
+
if (pathCategory !== void 0) return pathCategory;
|
|
2867
|
+
if (isTypesOnlyFile(sourceFile)) return "types";
|
|
2868
|
+
return "implementation";
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
// src/indexer/export-extraction.ts
|
|
2872
|
+
function addExport(state, name, kind, reExportInfo) {
|
|
2873
|
+
if (state.seenNames.has(name)) return;
|
|
2874
|
+
state.seenNames.add(name);
|
|
2875
|
+
const entry = { name, kind, isReExport: reExportInfo !== void 0 };
|
|
2876
|
+
if (reExportInfo !== void 0)
|
|
2877
|
+
entry.sourceModule = reExportInfo.sourceModule;
|
|
2878
|
+
state.exports.push(entry);
|
|
2879
|
+
}
|
|
2880
|
+
function extractFunctionClassExports(sourceFile, state) {
|
|
2881
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
2882
|
+
if (fn.isExported()) {
|
|
2883
|
+
const name = fn.getName();
|
|
2884
|
+
if (name !== void 0) addExport(state, name, "function");
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
for (const cls of sourceFile.getClasses()) {
|
|
2888
|
+
if (cls.isExported()) {
|
|
2889
|
+
const name = cls.getName();
|
|
2890
|
+
if (name !== void 0) addExport(state, name, "class");
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
function extractTypeExports(sourceFile, state) {
|
|
2895
|
+
for (const iface of sourceFile.getInterfaces()) {
|
|
2896
|
+
if (iface.isExported()) addExport(state, iface.getName(), "interface");
|
|
2897
|
+
}
|
|
2898
|
+
for (const typeAlias of sourceFile.getTypeAliases()) {
|
|
2899
|
+
if (typeAlias.isExported()) addExport(state, typeAlias.getName(), "type");
|
|
2900
|
+
}
|
|
2901
|
+
for (const enumDecl of sourceFile.getEnums()) {
|
|
2902
|
+
if (enumDecl.isExported()) addExport(state, enumDecl.getName(), "enum");
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
function extractVariableExports(sourceFile, state) {
|
|
2906
|
+
for (const varStmt of sourceFile.getVariableStatements()) {
|
|
2907
|
+
if (varStmt.isExported()) {
|
|
2908
|
+
for (const decl of varStmt.getDeclarations()) addExport(state, decl.getName(), "const");
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
function extractReExports(sourceFile, state) {
|
|
2913
|
+
for (const exportDecl of sourceFile.getExportDeclarations()) {
|
|
2914
|
+
const moduleSpecifier = exportDecl.getModuleSpecifierValue();
|
|
2915
|
+
const namedExports = exportDecl.getNamedExports();
|
|
2916
|
+
const reExportInfo = moduleSpecifier !== void 0 ? { sourceModule: moduleSpecifier } : void 0;
|
|
2917
|
+
for (const namedExport of namedExports) {
|
|
2918
|
+
const name = namedExport.getAliasNode()?.getText() ?? namedExport.getName();
|
|
2919
|
+
addExport(state, name, "unknown", reExportInfo);
|
|
2920
|
+
}
|
|
2921
|
+
if (namedExports.length === 0 && reExportInfo !== void 0) {
|
|
2922
|
+
addExport(state, "*", "unknown", reExportInfo);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
function extractExports(sourceFile) {
|
|
2927
|
+
const state = { exports: [], seenNames: /* @__PURE__ */ new Set() };
|
|
2928
|
+
extractFunctionClassExports(sourceFile, state);
|
|
2929
|
+
extractTypeExports(sourceFile, state);
|
|
2930
|
+
extractVariableExports(sourceFile, state);
|
|
2931
|
+
extractReExports(sourceFile, state);
|
|
2932
|
+
return state.exports;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
// src/indexer/dependency-extraction.ts
|
|
2936
|
+
function isExternalImport(specifier) {
|
|
2937
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) {
|
|
2938
|
+
return false;
|
|
2939
|
+
}
|
|
2940
|
+
if (specifier.startsWith("node:")) {
|
|
2941
|
+
return true;
|
|
2942
|
+
}
|
|
2943
|
+
return true;
|
|
2944
|
+
}
|
|
2945
|
+
function extractDependencies(sourceFile) {
|
|
2946
|
+
const deps = [];
|
|
2947
|
+
const seenSpecifiers = /* @__PURE__ */ new Set();
|
|
2948
|
+
for (const importDecl of sourceFile.getImportDeclarations()) {
|
|
2949
|
+
const specifier = importDecl.getModuleSpecifierValue();
|
|
2950
|
+
if (seenSpecifiers.has(specifier)) continue;
|
|
2951
|
+
seenSpecifiers.add(specifier);
|
|
2952
|
+
const imports = [];
|
|
2953
|
+
const namedImports = importDecl.getNamedImports();
|
|
2954
|
+
for (const namedImport of namedImports) {
|
|
2955
|
+
imports.push(namedImport.getName());
|
|
2956
|
+
}
|
|
2957
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
2958
|
+
if (defaultImport !== void 0) {
|
|
2959
|
+
imports.push(defaultImport.getText());
|
|
2960
|
+
}
|
|
2961
|
+
const namespaceImport = importDecl.getNamespaceImport();
|
|
2962
|
+
if (namespaceImport !== void 0) {
|
|
2963
|
+
imports.push(`* as ${namespaceImport.getText()}`);
|
|
2964
|
+
}
|
|
2965
|
+
deps.push({
|
|
2966
|
+
specifier,
|
|
2967
|
+
isExternal: isExternalImport(specifier),
|
|
2968
|
+
imports
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
return deps;
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
// src/indexer/description-extraction.ts
|
|
2975
|
+
function isPlainBlockComment(trimmed) {
|
|
2976
|
+
return trimmed.startsWith("/*") && trimmed.endsWith("*/");
|
|
2977
|
+
}
|
|
2978
|
+
function classifyOutsideComment(trimmed) {
|
|
2979
|
+
if (isPlainBlockComment(trimmed)) return "skip";
|
|
2980
|
+
if (trimmed.length > 0 && !trimmed.startsWith("//")) return "stop";
|
|
2981
|
+
return "skip";
|
|
2982
|
+
}
|
|
2983
|
+
function classifyInsideComment(trimmed) {
|
|
2984
|
+
if (trimmed.endsWith("*/")) return "end";
|
|
2985
|
+
if (trimmed.startsWith("* @") || trimmed.startsWith("@")) return "skip";
|
|
2986
|
+
return "content";
|
|
2987
|
+
}
|
|
2988
|
+
function classifyJsDocLine(trimmed, inComment) {
|
|
2989
|
+
if (trimmed.startsWith("/**")) {
|
|
2990
|
+
return trimmed.endsWith("*/") ? "startEnd" : "start";
|
|
2991
|
+
}
|
|
2992
|
+
return inComment ? classifyInsideComment(trimmed) : classifyOutsideComment(trimmed);
|
|
2993
|
+
}
|
|
2994
|
+
function extractJsDocLineContent(trimmed) {
|
|
2995
|
+
return trimmed.startsWith("*") ? trimmed.slice(1).trim() : trimmed;
|
|
2996
|
+
}
|
|
2997
|
+
function extractInlineJsDocContent(trimmed) {
|
|
2998
|
+
return trimmed.slice(3, -2).trim();
|
|
2999
|
+
}
|
|
3000
|
+
function truncateDescription(full) {
|
|
3001
|
+
return truncateSentence(full, 150);
|
|
3002
|
+
}
|
|
3003
|
+
function extractDescription(sourceFile) {
|
|
3004
|
+
const lines = sourceFile.getFullText().split("\n");
|
|
3005
|
+
let inComment = false;
|
|
3006
|
+
const description = [];
|
|
3007
|
+
for (const line of lines) {
|
|
3008
|
+
const trimmed = line.trim();
|
|
3009
|
+
const result = classifyJsDocLine(trimmed, inComment);
|
|
3010
|
+
if (result === "start") {
|
|
3011
|
+
inComment = true;
|
|
3012
|
+
continue;
|
|
3013
|
+
}
|
|
3014
|
+
if (result === "startEnd") {
|
|
3015
|
+
const inline = extractInlineJsDocContent(trimmed);
|
|
3016
|
+
if (inline.length > 0) description.push(inline);
|
|
3017
|
+
break;
|
|
3018
|
+
}
|
|
3019
|
+
if (result === "end" || result === "stop") break;
|
|
3020
|
+
if (result === "skip") continue;
|
|
3021
|
+
const content = extractJsDocLineContent(trimmed);
|
|
3022
|
+
if (content.length > 0) description.push(content);
|
|
3023
|
+
}
|
|
3024
|
+
if (description.length === 0) return void 0;
|
|
3025
|
+
return truncateDescription(description.join(" "));
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
// src/indexer/project-extraction.ts
|
|
3029
|
+
import { Project } from "ts-morph";
|
|
3030
|
+
import * as path5 from "path";
|
|
3031
|
+
|
|
3032
|
+
// src/indexer/types.ts
|
|
3033
|
+
import { z as z6 } from "zod";
|
|
3034
|
+
var SCHEMA_VERSION = "1.0";
|
|
3035
|
+
var ExportEntrySchema = z6.object({
|
|
3036
|
+
name: z6.string(),
|
|
3037
|
+
kind: z6.enum(["type", "interface", "class", "function", "const", "enum", "unknown"]),
|
|
3038
|
+
isReExport: z6.boolean(),
|
|
3039
|
+
sourceModule: z6.string().optional()
|
|
3040
|
+
});
|
|
3041
|
+
var DependencyEntrySchema = z6.object({
|
|
3042
|
+
specifier: z6.string(),
|
|
3043
|
+
isExternal: z6.boolean(),
|
|
3044
|
+
imports: z6.array(z6.string()).readonly()
|
|
3045
|
+
});
|
|
3046
|
+
var FileEntrySchema = z6.object({
|
|
3047
|
+
path: z6.string(),
|
|
3048
|
+
lines: z6.number().int().nonnegative(),
|
|
3049
|
+
category: z6.enum(["types", "implementation", "test", "config", "cli", "util", "index"]),
|
|
3050
|
+
exports: z6.array(ExportEntrySchema).readonly(),
|
|
3051
|
+
dependencies: z6.array(DependencyEntrySchema).readonly(),
|
|
3052
|
+
description: z6.string().optional()
|
|
3053
|
+
});
|
|
3054
|
+
var ModuleStatsSchema = z6.object({
|
|
3055
|
+
fileCount: z6.number().int().nonnegative(),
|
|
3056
|
+
totalLines: z6.number().int().nonnegative(),
|
|
3057
|
+
exportCount: z6.number().int().nonnegative(),
|
|
3058
|
+
internalDeps: z6.number().int().nonnegative(),
|
|
3059
|
+
externalDeps: z6.number().int().nonnegative()
|
|
3060
|
+
});
|
|
3061
|
+
var ModuleEntrySchema = z6.object({
|
|
3062
|
+
name: z6.string(),
|
|
3063
|
+
path: z6.string(),
|
|
3064
|
+
purpose: z6.string(),
|
|
3065
|
+
files: z6.array(FileEntrySchema).readonly(),
|
|
3066
|
+
stats: ModuleStatsSchema,
|
|
3067
|
+
dependsOn: z6.array(z6.string()).readonly()
|
|
3068
|
+
});
|
|
3069
|
+
var IndexStatsSchema = z6.object({
|
|
3070
|
+
totalFiles: z6.number().int().nonnegative(),
|
|
3071
|
+
totalLines: z6.number().int().nonnegative(),
|
|
3072
|
+
totalExports: z6.number().int().nonnegative(),
|
|
3073
|
+
moduleCount: z6.number().int().nonnegative(),
|
|
3074
|
+
externalPackages: z6.array(z6.string()).readonly()
|
|
3075
|
+
});
|
|
3076
|
+
var CodebaseIndexSchema = z6.object({
|
|
3077
|
+
schemaVersion: z6.literal(SCHEMA_VERSION),
|
|
3078
|
+
generatedAt: z6.string(),
|
|
3079
|
+
stats: IndexStatsSchema,
|
|
3080
|
+
modules: z6.record(z6.string(), ModuleEntrySchema)
|
|
3081
|
+
});
|
|
3082
|
+
var DEFAULT_EXTRACTOR_OPTIONS = {
|
|
3083
|
+
rootDir: "src",
|
|
3084
|
+
include: ["**/*.ts"],
|
|
3085
|
+
exclude: ["**/*.test.ts", "**/*.d.ts", "**/node_modules/**"],
|
|
3086
|
+
extractDescriptions: true
|
|
3087
|
+
};
|
|
3088
|
+
|
|
3089
|
+
// src/indexer/project-extraction.ts
|
|
3090
|
+
function extractFileEntry(sourceFile, rootDir, extractDescriptions) {
|
|
3091
|
+
const absolutePath = sourceFile.getFilePath();
|
|
3092
|
+
const relativePath = path5.relative(rootDir, absolutePath);
|
|
3093
|
+
const lineCount = sourceFile.getEndLineNumber();
|
|
3094
|
+
const entry = {
|
|
3095
|
+
path: relativePath,
|
|
3096
|
+
lines: lineCount,
|
|
3097
|
+
category: detectFileCategory(relativePath, sourceFile),
|
|
3098
|
+
exports: extractExports(sourceFile),
|
|
3099
|
+
dependencies: extractDependencies(sourceFile)
|
|
3100
|
+
};
|
|
3101
|
+
if (extractDescriptions) {
|
|
3102
|
+
const desc = extractDescription(sourceFile);
|
|
3103
|
+
if (desc !== void 0) {
|
|
3104
|
+
entry.description = desc;
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
return entry;
|
|
3108
|
+
}
|
|
3109
|
+
function processSourceFiles(project, rootDir, extractDescriptions) {
|
|
3110
|
+
const files = [];
|
|
3111
|
+
const errors = [];
|
|
3112
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
3113
|
+
const filePath = sourceFile.getFilePath();
|
|
3114
|
+
try {
|
|
3115
|
+
files.push(extractFileEntry(sourceFile, rootDir, extractDescriptions));
|
|
3116
|
+
} catch (err2) {
|
|
3117
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
3118
|
+
errors.push(`Error extracting ${filePath}: ${message}`);
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
return { files, errors };
|
|
3122
|
+
}
|
|
3123
|
+
function extractProject(options = {}) {
|
|
3124
|
+
const opts = { ...DEFAULT_EXTRACTOR_OPTIONS, ...options };
|
|
3125
|
+
const startTime = getTimeProvider().now();
|
|
3126
|
+
const project = new Project({
|
|
3127
|
+
skipAddingFilesFromTsConfig: true,
|
|
3128
|
+
skipFileDependencyResolution: true
|
|
3129
|
+
});
|
|
3130
|
+
const rootDir = path5.resolve(process.cwd(), opts.rootDir);
|
|
3131
|
+
const includePatterns = opts.include.map((p) => path5.join(rootDir, p));
|
|
3132
|
+
const excludePatterns = opts.exclude.map((p) => `!${path5.join(rootDir, p)}`);
|
|
3133
|
+
try {
|
|
3134
|
+
project.addSourceFilesAtPaths([...includePatterns, ...excludePatterns]);
|
|
3135
|
+
const { files, errors } = processSourceFiles(project, rootDir, opts.extractDescriptions);
|
|
3136
|
+
return { files, errors, durationMs: getTimeProvider().now() - startTime };
|
|
3137
|
+
} catch (err2) {
|
|
3138
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
3139
|
+
return {
|
|
3140
|
+
files: [],
|
|
3141
|
+
errors: [`Error loading project: ${message}`],
|
|
3142
|
+
durationMs: getTimeProvider().now() - startTime
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
// src/indexer/analyzer.ts
|
|
3148
|
+
import * as path6 from "path";
|
|
3149
|
+
var MODULE_PURPOSES = {
|
|
3150
|
+
core: "Types, Result<T,E>, errors, logger",
|
|
3151
|
+
config: "Configuration loading, validation, Zod schemas",
|
|
3152
|
+
adapters: "Model adapters (Claude, OpenAI, Gemini, Ollama)",
|
|
3153
|
+
agents: "Agent framework, Orchestrator, Experts, collaboration",
|
|
3154
|
+
workflows: "Workflow engine, templates, execution",
|
|
3155
|
+
mcp: "MCP server, tool definitions",
|
|
3156
|
+
cli: "CLI interface, mode detection, commands",
|
|
3157
|
+
"cli-adapters": "External CLI integrations (Claude, Gemini, Codex)",
|
|
3158
|
+
context: "Context management, token counting, memory",
|
|
3159
|
+
consensus: "Multi-agent consensus, voting strategies",
|
|
3160
|
+
learning: "Feedback collection, outcome tracking",
|
|
3161
|
+
indexer: "Codebase indexing and documentation",
|
|
3162
|
+
security: "Sandbox execution, secrets management"
|
|
3163
|
+
};
|
|
3164
|
+
function detectModulePurpose(moduleName, files) {
|
|
3165
|
+
const known = MODULE_PURPOSES[moduleName];
|
|
3166
|
+
if (known !== void 0) {
|
|
3167
|
+
return known;
|
|
3168
|
+
}
|
|
3169
|
+
const descriptions = files.filter((f) => f.description !== void 0).map((f) => f.description).slice(0, 3);
|
|
3170
|
+
if (descriptions.length > 0) {
|
|
3171
|
+
return descriptions.join("; ");
|
|
3172
|
+
}
|
|
3173
|
+
return `${moduleName} module`;
|
|
3174
|
+
}
|
|
3175
|
+
function extractPackageName(specifier) {
|
|
3176
|
+
if (specifier.startsWith("@")) {
|
|
3177
|
+
const parts2 = specifier.split("/");
|
|
3178
|
+
const scope = parts2[0];
|
|
3179
|
+
const name = parts2[1];
|
|
3180
|
+
if (scope !== void 0 && name !== void 0) {
|
|
3181
|
+
return `${scope}/${name}`;
|
|
3182
|
+
}
|
|
3183
|
+
return void 0;
|
|
3184
|
+
}
|
|
3185
|
+
if (specifier.startsWith("node:")) {
|
|
3186
|
+
return specifier;
|
|
3187
|
+
}
|
|
3188
|
+
const parts = specifier.split("/");
|
|
3189
|
+
return parts[0];
|
|
3190
|
+
}
|
|
3191
|
+
function groupFilesByModule(files) {
|
|
3192
|
+
const modules = /* @__PURE__ */ new Map();
|
|
3193
|
+
for (const file of files) {
|
|
3194
|
+
const parts = file.path.split("/");
|
|
3195
|
+
const moduleName = parts.length > 1 ? parts[0] ?? "root" : "root";
|
|
3196
|
+
const existing = modules.get(moduleName);
|
|
3197
|
+
if (existing !== void 0) {
|
|
3198
|
+
existing.push(file);
|
|
3199
|
+
} else {
|
|
3200
|
+
modules.set(moduleName, [file]);
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
return modules;
|
|
3204
|
+
}
|
|
3205
|
+
function collectExternalPackages(file, packages) {
|
|
3206
|
+
for (const dep of file.dependencies) {
|
|
3207
|
+
if (dep.isExternal) {
|
|
3208
|
+
const pkgName = extractPackageName(dep.specifier);
|
|
3209
|
+
if (pkgName !== void 0) {
|
|
3210
|
+
packages.add(pkgName);
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
function computeModuleStats(files) {
|
|
3216
|
+
let totalLines = 0;
|
|
3217
|
+
let exportCount = 0;
|
|
3218
|
+
let internalDeps = 0;
|
|
3219
|
+
let externalDeps = 0;
|
|
3220
|
+
for (const file of files) {
|
|
3221
|
+
totalLines += file.lines;
|
|
3222
|
+
exportCount += file.exports.length;
|
|
3223
|
+
for (const dep of file.dependencies) {
|
|
3224
|
+
if (dep.isExternal) {
|
|
3225
|
+
externalDeps++;
|
|
3226
|
+
} else {
|
|
3227
|
+
internalDeps++;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return {
|
|
3232
|
+
fileCount: files.length,
|
|
3233
|
+
totalLines,
|
|
3234
|
+
exportCount,
|
|
3235
|
+
internalDeps,
|
|
3236
|
+
externalDeps
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
function resolveTargetModule(filePath, specifier) {
|
|
3240
|
+
if (!specifier.startsWith(".")) return void 0;
|
|
3241
|
+
const resolved = path6.join(path6.dirname(filePath), specifier);
|
|
3242
|
+
const parts = resolved.split("/");
|
|
3243
|
+
return parts[0];
|
|
3244
|
+
}
|
|
3245
|
+
function isValidModuleDep(targetModule, moduleName, allModules) {
|
|
3246
|
+
return targetModule !== void 0 && targetModule !== moduleName && allModules.has(targetModule);
|
|
3247
|
+
}
|
|
3248
|
+
function detectModuleDependencies(moduleName, files, allModules) {
|
|
3249
|
+
const deps = /* @__PURE__ */ new Set();
|
|
3250
|
+
for (const file of files) {
|
|
3251
|
+
for (const dep of file.dependencies) {
|
|
3252
|
+
if (dep.isExternal) continue;
|
|
3253
|
+
const targetModule = resolveTargetModule(file.path, dep.specifier);
|
|
3254
|
+
if (isValidModuleDep(targetModule, moduleName, allModules)) {
|
|
3255
|
+
deps.add(targetModule);
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
return Array.from(deps).sort();
|
|
3260
|
+
}
|
|
3261
|
+
function analyzeModules(files) {
|
|
3262
|
+
const filesByModule = groupFilesByModule(files);
|
|
3263
|
+
const moduleNames = new Set(filesByModule.keys());
|
|
3264
|
+
const modules = /* @__PURE__ */ new Map();
|
|
3265
|
+
for (const [moduleName, moduleFiles] of filesByModule) {
|
|
3266
|
+
modules.set(moduleName, {
|
|
3267
|
+
name: moduleName,
|
|
3268
|
+
path: moduleName === "root" ? "." : moduleName,
|
|
3269
|
+
purpose: detectModulePurpose(moduleName, moduleFiles),
|
|
3270
|
+
files: moduleFiles,
|
|
3271
|
+
stats: computeModuleStats(moduleFiles),
|
|
3272
|
+
dependsOn: detectModuleDependencies(moduleName, moduleFiles, moduleNames)
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
return modules;
|
|
3276
|
+
}
|
|
3277
|
+
function computeIndexStats(modules) {
|
|
3278
|
+
let totalFiles = 0;
|
|
3279
|
+
let totalLines = 0;
|
|
3280
|
+
let totalExports = 0;
|
|
3281
|
+
const externalPackages = /* @__PURE__ */ new Set();
|
|
3282
|
+
for (const module of modules.values()) {
|
|
3283
|
+
totalFiles += module.stats.fileCount;
|
|
3284
|
+
totalLines += module.stats.totalLines;
|
|
3285
|
+
totalExports += module.stats.exportCount;
|
|
3286
|
+
for (const file of module.files) {
|
|
3287
|
+
collectExternalPackages(file, externalPackages);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
return {
|
|
3291
|
+
totalFiles,
|
|
3292
|
+
totalLines,
|
|
3293
|
+
totalExports,
|
|
3294
|
+
moduleCount: modules.size,
|
|
3295
|
+
externalPackages: Array.from(externalPackages).sort()
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
function buildIndex(files) {
|
|
3299
|
+
const modules = analyzeModules(files);
|
|
3300
|
+
const stats = computeIndexStats(modules);
|
|
3301
|
+
const now = new Date(getTimeProvider().now());
|
|
3302
|
+
const etFormatter = new Intl.DateTimeFormat("en-US", {
|
|
3303
|
+
timeZone: "America/New_York",
|
|
3304
|
+
year: "numeric",
|
|
3305
|
+
month: "2-digit",
|
|
3306
|
+
day: "2-digit",
|
|
3307
|
+
hour: "2-digit",
|
|
3308
|
+
minute: "2-digit",
|
|
3309
|
+
second: "2-digit",
|
|
3310
|
+
hour12: false
|
|
3311
|
+
});
|
|
3312
|
+
const parts = etFormatter.formatToParts(now);
|
|
3313
|
+
const getPart = (type) => parts.find((p) => p.type === type)?.value ?? "00";
|
|
3314
|
+
const utcFormatter = new Intl.DateTimeFormat("en-US", {
|
|
3315
|
+
timeZone: "UTC",
|
|
3316
|
+
hour: "numeric",
|
|
3317
|
+
hour12: false
|
|
3318
|
+
});
|
|
3319
|
+
const utcHour = Number(
|
|
3320
|
+
utcFormatter.formatToParts(now).find((p) => p.type === "hour")?.value ?? "0"
|
|
3321
|
+
);
|
|
3322
|
+
const etHour = Number(getPart("hour"));
|
|
3323
|
+
const rawDiff = etHour - utcHour;
|
|
3324
|
+
const offsetHours = rawDiff > 12 ? rawDiff - 24 : rawDiff < -12 ? rawDiff + 24 : rawDiff;
|
|
3325
|
+
const offsetSign = offsetHours <= 0 ? "-" : "+";
|
|
3326
|
+
const absOffset = String(Math.abs(offsetHours)).padStart(2, "0");
|
|
3327
|
+
const timestamp = `${getPart("year")}-${getPart("month")}-${getPart("day")}T${getPart("hour")}:${getPart("minute")}:${getPart("second")}${offsetSign}${absOffset}:00`;
|
|
3328
|
+
const modulesRecord = {};
|
|
3329
|
+
for (const [name, entry] of modules) {
|
|
3330
|
+
modulesRecord[name] = entry;
|
|
3331
|
+
}
|
|
3332
|
+
return {
|
|
3333
|
+
schemaVersion: SCHEMA_VERSION,
|
|
3334
|
+
generatedAt: timestamp,
|
|
3335
|
+
stats,
|
|
3336
|
+
modules: modulesRecord
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
|
|
3340
|
+
// src/context/repo-map.ts
|
|
3341
|
+
var REPO_MAP_FLAG = "NEXUS_REPO_MAP";
|
|
3342
|
+
var DEFAULT_REPO_MAP_TOKEN_BUDGET = 400;
|
|
3343
|
+
var REPO_MAP_CAVEAT = "Import-graph only: edges are module import dependencies + declaration names, NOT call-site/usage data. Centrality reflects import structure, not runtime call frequency \u2014 do not treat this as a call graph (call-site edges tracked in #4249-A).";
|
|
3344
|
+
var REPO_MAP_HEADER = "## Repo Map (module import graph \u2014 PageRank-ranked)";
|
|
3345
|
+
var PAGERANK_DAMPING = 0.85;
|
|
3346
|
+
var PAGERANK_MAX_ITERATIONS = 100;
|
|
3347
|
+
var PAGERANK_EPSILON = 1e-6;
|
|
3348
|
+
function computeModulePageRank(modules) {
|
|
3349
|
+
const names = Object.keys(modules);
|
|
3350
|
+
const n = names.length;
|
|
3351
|
+
if (n === 0) return /* @__PURE__ */ new Map();
|
|
3352
|
+
const outEdges = buildOutEdges(modules, names);
|
|
3353
|
+
let ranks = new Map(names.map((name) => [name, 1 / n]));
|
|
3354
|
+
for (let iter = 0; iter < PAGERANK_MAX_ITERATIONS; iter++) {
|
|
3355
|
+
const next = pageRankStep(names, outEdges, ranks, n);
|
|
3356
|
+
if (l1Delta(ranks, next) < PAGERANK_EPSILON) return next;
|
|
3357
|
+
ranks = next;
|
|
3358
|
+
}
|
|
3359
|
+
return ranks;
|
|
3360
|
+
}
|
|
3361
|
+
function buildOutEdges(modules, names) {
|
|
3362
|
+
const known = new Set(names);
|
|
3363
|
+
const out = /* @__PURE__ */ new Map();
|
|
3364
|
+
for (const name of names) {
|
|
3365
|
+
const deps = modules[name]?.dependsOn ?? [];
|
|
3366
|
+
out.set(
|
|
3367
|
+
name,
|
|
3368
|
+
deps.filter((d) => known.has(d) && d !== name)
|
|
3369
|
+
);
|
|
3370
|
+
}
|
|
3371
|
+
return out;
|
|
3372
|
+
}
|
|
3373
|
+
function pageRankStep(names, outEdges, ranks, n) {
|
|
3374
|
+
const danglingShare = PAGERANK_DAMPING * sumDanglingRank(names, outEdges, ranks) / n;
|
|
3375
|
+
const base = (1 - PAGERANK_DAMPING) / n + danglingShare;
|
|
3376
|
+
const next = new Map(names.map((name) => [name, base]));
|
|
3377
|
+
for (const src of names) {
|
|
3378
|
+
const targets = outEdges.get(src) ?? [];
|
|
3379
|
+
if (targets.length === 0) continue;
|
|
3380
|
+
const share = PAGERANK_DAMPING * (ranks.get(src) ?? 0) / targets.length;
|
|
3381
|
+
for (const t of targets) {
|
|
3382
|
+
next.set(t, (next.get(t) ?? 0) + share);
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
return next;
|
|
3386
|
+
}
|
|
3387
|
+
function sumDanglingRank(names, outEdges, ranks) {
|
|
3388
|
+
let sum = 0;
|
|
3389
|
+
for (const name of names) {
|
|
3390
|
+
if ((outEdges.get(name) ?? []).length === 0) sum += ranks.get(name) ?? 0;
|
|
3391
|
+
}
|
|
3392
|
+
return sum;
|
|
3393
|
+
}
|
|
3394
|
+
function l1Delta(a, b) {
|
|
3395
|
+
let d = 0;
|
|
3396
|
+
for (const [k, v] of a) d += Math.abs(v - (b.get(k) ?? 0));
|
|
3397
|
+
return d;
|
|
3398
|
+
}
|
|
3399
|
+
function rankRepoMapEntries(index) {
|
|
3400
|
+
const ranks = computeModulePageRank(index.modules);
|
|
3401
|
+
const entries = Object.entries(index.modules).map(([name, mod]) => ({
|
|
3402
|
+
module: name,
|
|
3403
|
+
centrality: ranks.get(name) ?? 0,
|
|
3404
|
+
purpose: mod.purpose,
|
|
3405
|
+
dependsOn: mod.dependsOn,
|
|
3406
|
+
fileCount: mod.stats.fileCount
|
|
3407
|
+
}));
|
|
3408
|
+
return entries.sort(
|
|
3409
|
+
(a, b) => b.centrality !== a.centrality ? b.centrality - a.centrality : a.module.localeCompare(b.module)
|
|
3410
|
+
);
|
|
3411
|
+
}
|
|
3412
|
+
var CHARS_PER_TOKEN3 = 4;
|
|
3413
|
+
var MAX_DEPS_PER_LINE = 6;
|
|
3414
|
+
var MAX_LINE_CHARS = 200;
|
|
3415
|
+
function buildRepoMap(index, options = {}) {
|
|
3416
|
+
const entries = rankRepoMapEntries(index);
|
|
3417
|
+
if (entries.length === 0) return "";
|
|
3418
|
+
const budget = options.budgetTokens ?? DEFAULT_REPO_MAP_TOKEN_BUDGET;
|
|
3419
|
+
return renderRepoMap(entries, budget);
|
|
3420
|
+
}
|
|
3421
|
+
function renderRepoMap(entries, budgetTokens) {
|
|
3422
|
+
const preamble = `${REPO_MAP_HEADER}
|
|
3423
|
+
> ${REPO_MAP_CAVEAT}`;
|
|
3424
|
+
const lines = entries.map(formatEntryLine);
|
|
3425
|
+
const { kept, omitted } = fitLinesWithinBudget(lines, budgetTokens);
|
|
3426
|
+
const bodyText = kept.length > 0 ? clampToTokenBudget(kept.join("\n"), budgetTokens).text : "";
|
|
3427
|
+
const body = bodyText === "" ? "" : `
|
|
3428
|
+
${bodyText}`;
|
|
3429
|
+
const notice = omitted > 0 ? `
|
|
3430
|
+
_(+${String(omitted)} lower-centrality modules omitted for the ~${String(budgetTokens)}-token module budget \u2014 #4254)_` : "";
|
|
3431
|
+
return `${preamble}${body}${notice}`;
|
|
3432
|
+
}
|
|
3433
|
+
function formatEntryLine(e) {
|
|
3434
|
+
const shownDeps = e.dependsOn.slice(0, MAX_DEPS_PER_LINE);
|
|
3435
|
+
const more = e.dependsOn.length > MAX_DEPS_PER_LINE ? ", \u2026" : "";
|
|
3436
|
+
const deps = shownDeps.length > 0 ? ` \u2192 ${shownDeps.join(", ")}${more}` : "";
|
|
3437
|
+
const line = `- ${e.module} (centrality ${e.centrality.toFixed(3)}, ${String(e.fileCount)} files): ${oneLine2(e.purpose)}${deps}`;
|
|
3438
|
+
return line.slice(0, MAX_LINE_CHARS);
|
|
3439
|
+
}
|
|
3440
|
+
function fitLinesWithinBudget(lines, budgetTokens) {
|
|
3441
|
+
let used = 0;
|
|
3442
|
+
const kept = [];
|
|
3443
|
+
for (const line of lines) {
|
|
3444
|
+
const cost = estimateTokens2(line) + 1;
|
|
3445
|
+
if (used + cost > budgetTokens) break;
|
|
3446
|
+
used += cost;
|
|
3447
|
+
kept.push(line);
|
|
3448
|
+
}
|
|
3449
|
+
return { kept, omitted: lines.length - kept.length };
|
|
3450
|
+
}
|
|
3451
|
+
function estimateTokens2(text) {
|
|
3452
|
+
return Math.ceil(text.length / CHARS_PER_TOKEN3);
|
|
3453
|
+
}
|
|
3454
|
+
function oneLine2(value) {
|
|
3455
|
+
return value.replace(/\s+/g, " ").trim();
|
|
3456
|
+
}
|
|
3457
|
+
var STRUCTURAL_CATEGORIES = /* @__PURE__ */ new Set([
|
|
3458
|
+
"architecture",
|
|
3459
|
+
"planning",
|
|
3460
|
+
"code_generation",
|
|
3461
|
+
"code_review",
|
|
3462
|
+
"security_review"
|
|
3463
|
+
]);
|
|
3464
|
+
var STRUCTURAL_TASK_PATTERN = /architect|refactor|depend|module|cross[- ]file|structure|integrat|migrat|coupl|call ?graph|import ?graph|repo.?map|entry ?point|wiring|data ?flow/i;
|
|
3465
|
+
function taskNeedsRepoMap(task, category) {
|
|
3466
|
+
if (STRUCTURAL_CATEGORIES.has(category)) return true;
|
|
3467
|
+
return STRUCTURAL_TASK_PATTERN.test(task);
|
|
3468
|
+
}
|
|
3469
|
+
function getRepoMapForTask(options) {
|
|
3470
|
+
if (process.env[REPO_MAP_FLAG] !== "1") return void 0;
|
|
3471
|
+
if (!taskNeedsRepoMap(options.task, options.category)) return void 0;
|
|
3472
|
+
const log = options.logger ?? createLogger({ component: "RepoMap" });
|
|
3473
|
+
try {
|
|
3474
|
+
const index = (options.indexProvider ?? buildLiveIndex)();
|
|
3475
|
+
const map = buildRepoMap(index, {
|
|
3476
|
+
budgetTokens: options.budgetTokens ?? DEFAULT_REPO_MAP_TOKEN_BUDGET
|
|
3477
|
+
});
|
|
3478
|
+
return map === "" ? void 0 : map;
|
|
3479
|
+
} catch (error) {
|
|
3480
|
+
log.debug("repo-map build failed", {
|
|
3481
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3482
|
+
});
|
|
3483
|
+
return void 0;
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
function buildLiveIndex() {
|
|
3487
|
+
const extraction = extractProject({ extractDescriptions: false });
|
|
3488
|
+
return buildIndex(extraction.files);
|
|
3489
|
+
}
|
|
3490
|
+
|
|
2834
3491
|
// src/context/context-retriever.ts
|
|
2835
3492
|
var DEFAULT_LIMIT = 5;
|
|
2836
3493
|
async function getContextForTask(options) {
|
|
@@ -2862,7 +3519,12 @@ async function getContextForTask(options) {
|
|
|
2862
3519
|
priorStrategies,
|
|
2863
3520
|
researchInsights
|
|
2864
3521
|
};
|
|
2865
|
-
|
|
3522
|
+
const result = {
|
|
3523
|
+
...base,
|
|
3524
|
+
rankedMemories: rankMemories({ ...base, rankedMemories: [] }, options.task)
|
|
3525
|
+
};
|
|
3526
|
+
const repoMap = getRepoMapForTask({ task: options.task, category: options.category, logger });
|
|
3527
|
+
return repoMap === void 0 ? result : { ...result, repoMap };
|
|
2866
3528
|
}
|
|
2867
3529
|
var MIN_RELEVANCE_TOKEN = 4;
|
|
2868
3530
|
function selectRelevantResearch(techniques, task, limit) {
|
|
@@ -2986,7 +3648,7 @@ function inferTaskCategory(task) {
|
|
|
2986
3648
|
return "exploration";
|
|
2987
3649
|
}
|
|
2988
3650
|
var MAX_SUMMARY_FIELD = 200;
|
|
2989
|
-
function
|
|
3651
|
+
function oneLine3(value) {
|
|
2990
3652
|
return value.replace(/\s+/g, " ").trim().slice(0, MAX_SUMMARY_FIELD);
|
|
2991
3653
|
}
|
|
2992
3654
|
function summarizeContextForPrompt(ctx, budgetTokens = DEFAULT_CONTEXT_BUDGET_TOKENS) {
|
|
@@ -2994,7 +3656,24 @@ function summarizeContextForPrompt(ctx, budgetTokens = DEFAULT_CONTEXT_BUDGET_TO
|
|
|
2994
3656
|
const rendered = ranked ? summarizeRankedContext(ctx) : summarizeLegacyContext(ctx);
|
|
2995
3657
|
const clamped = clampRenderedContext(rendered, budgetTokens);
|
|
2996
3658
|
recordAssembledContextTokens(clamped, ranked);
|
|
2997
|
-
return clamped;
|
|
3659
|
+
return appendRepoMapSection(clamped, ctx);
|
|
3660
|
+
}
|
|
3661
|
+
function appendRepoMapSection(memoryBlock, ctx) {
|
|
3662
|
+
const map = ctx.repoMap;
|
|
3663
|
+
if (map === void 0 || map === "") return memoryBlock;
|
|
3664
|
+
recordRepoMapTokens(map);
|
|
3665
|
+
return memoryBlock === "" ? map : `${memoryBlock}
|
|
3666
|
+
|
|
3667
|
+
${map}`;
|
|
3668
|
+
}
|
|
3669
|
+
var REPO_MAP_LEDGER_VARIANT = `${REPO_MAP_FLAG}=1`;
|
|
3670
|
+
function recordRepoMapTokens(rendered) {
|
|
3671
|
+
getTokenLedger().record({
|
|
3672
|
+
tool: "context-retriever.summarizeContextForPrompt",
|
|
3673
|
+
contextSource: "repo-map",
|
|
3674
|
+
inputTokens: contextTokenCounter.estimate(rendered),
|
|
3675
|
+
variant: REPO_MAP_LEDGER_VARIANT
|
|
3676
|
+
});
|
|
2998
3677
|
}
|
|
2999
3678
|
var contextTokenCounter = createTokenCounter();
|
|
3000
3679
|
function recordAssembledContextTokens(rendered, ranked) {
|
|
@@ -3021,19 +3700,19 @@ function summarizeLegacyContext(ctx) {
|
|
|
3021
3700
|
const sections = [];
|
|
3022
3701
|
if (ctx.beliefs.length > 0) {
|
|
3023
3702
|
const lines = ctx.beliefs.slice(0, 5).map(
|
|
3024
|
-
(b) => `- ${
|
|
3703
|
+
(b) => `- ${oneLine3(b.subject)} ${oneLine3(b.predicate)} ${oneLine3(b.object)} (confidence: ${b.confidence})`
|
|
3025
3704
|
);
|
|
3026
3705
|
sections.push(`### Beliefs
|
|
3027
3706
|
${lines.join("\n")}`);
|
|
3028
3707
|
}
|
|
3029
3708
|
if (ctx.similarMemories.length > 0) {
|
|
3030
|
-
const lines = ctx.similarMemories.slice(0, 3).map((m) => `- ${
|
|
3709
|
+
const lines = ctx.similarMemories.slice(0, 3).map((m) => `- ${oneLine3(m.attributes.contextDescription)}`);
|
|
3031
3710
|
sections.push(`### Similar prior work
|
|
3032
3711
|
${lines.join("\n")}`);
|
|
3033
3712
|
}
|
|
3034
3713
|
if (ctx.experiencePatterns.length > 0) {
|
|
3035
3714
|
const lines = ctx.experiencePatterns.slice(0, 3).map(
|
|
3036
|
-
(p) => `- ${
|
|
3715
|
+
(p) => `- ${oneLine3(p.taskType)}: ${(p.successRate * 100).toFixed(0)}% success over ${String(p.attemptCount)} attempts`
|
|
3037
3716
|
);
|
|
3038
3717
|
sections.push(`### Observed patterns
|
|
3039
3718
|
${lines.join("\n")}`);
|
|
@@ -3045,7 +3724,7 @@ ${lines.join("\n")}`);
|
|
|
3045
3724
|
);
|
|
3046
3725
|
}
|
|
3047
3726
|
if (ctx.researchInsights.length > 0) {
|
|
3048
|
-
const lines = ctx.researchInsights.slice(0, 5).map((r) => `- ${
|
|
3727
|
+
const lines = ctx.researchInsights.slice(0, 5).map((r) => `- ${oneLine3(r.name)} (${oneLine3(r.status)}) \u2014 ${oneLine3(r.topic)}`);
|
|
3049
3728
|
sections.push(`### Prior research on this topic
|
|
3050
3729
|
${lines.join("\n")}`);
|
|
3051
3730
|
}
|
|
@@ -3067,7 +3746,7 @@ function summarizeRankedContext(ctx) {
|
|
|
3067
3746
|
const top = topRankedWithinBudget(ranked, RANKED_PREFIX_TOKEN_BUDGET);
|
|
3068
3747
|
if (top.length === 0) return "";
|
|
3069
3748
|
const lines = top.map(
|
|
3070
|
-
(r) => `- [${RANKED_SOURCE_LABEL[r.source]}] ${
|
|
3749
|
+
(r) => `- [${RANKED_SOURCE_LABEL[r.source]}] ${oneLine3(r.text)} (relevance: ${r.relevanceScore.toFixed(2)})`
|
|
3071
3750
|
);
|
|
3072
3751
|
return `## Prior Context (Nexus Memory)
|
|
3073
3752
|
### Most relevant prior context
|
|
@@ -3129,6 +3808,9 @@ export {
|
|
|
3129
3808
|
TokenCountError,
|
|
3130
3809
|
TokenCounter,
|
|
3131
3810
|
createTokenCounter,
|
|
3811
|
+
CodebaseIndexSchema,
|
|
3812
|
+
extractProject,
|
|
3813
|
+
buildIndex,
|
|
3132
3814
|
getContextForTask,
|
|
3133
3815
|
selectRelevantResearch,
|
|
3134
3816
|
getResearchInsightsForTask,
|
|
@@ -3137,4 +3819,4 @@ export {
|
|
|
3137
3819
|
DEFAULT_CONTEXT_BUDGET_TOKENS,
|
|
3138
3820
|
getContextPromptPrefix
|
|
3139
3821
|
};
|
|
3140
|
-
//# sourceMappingURL=chunk-
|
|
3822
|
+
//# sourceMappingURL=chunk-HJA3Z56H.js.map
|