Code warehouse management method and device, and electronic equipment
By generating module dependency graphs and analyzing homology groups, redundancy in AI-generated code repositories is identified and addressed, solving the problem of low code repository operating efficiency and achieving automated governance and resource saving.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILE INTERNET CO LTD
- Filing Date
- 2025-12-12
- Publication Date
- 2026-04-21
Smart Images

Figure CN121900805A_ABST
Abstract
Description
Technical Field
[0001] This application relates to electronic technology, including but not limited to a code repository governance method, apparatus, and electronic device. Background Technology
[0002] With the development of the times and the progress of society, the widespread application of large AI models (such as GPT-4 and Copilot) in the field of code generation has significantly increased the proportion of AI-generated code in enterprise code repositories. While the emerging AI models' ability to automatically generate code can instantly produce large amounts of code, users' lack of basic coding skills and repetitive input of commands can easily lead to a large amount of redundant code in the code repository, resulting in low operational efficiency.
[0003] Traditional methods rely heavily on human resources, using human experience to make judgments and optimize processes. This long-term reliance on manual labor leads to a waste of human resources. Summary of the Invention
[0004] In view of this, embodiments of this application provide a code repository governance method, apparatus, and electronic device.
[0005] The technical solution of this application embodiment is implemented as follows: This application provides a code repository governance method, the method including: obtaining the original code repository; A full scan of the original code repository is performed to obtain a module dependency graph. Based on the module dependency graph, homology group analysis of algebraic topology is performed to obtain isolated code modules, circular dependency chains, and cross-redundant blocks. The isolated code modules, circular dependency chains, and cross-redundant blocks are integrated and extracted to obtain a governance candidate set. The original code repository is then governed based on the governance candidate set.
[0006] Optionally, governing the original code repository based on the governance candidate set includes: calculating a variant Lyapunov index for each module in the governance candidate set; and prioritizing each module based on the variant Lyapunov index to obtain a candidate code governance queue.
[0007] Optionally, after obtaining the candidate code governance queue, the process includes: calculating the topological degrees of freedom of each module based on the candidate code governance queue and the variant Lyapunov index of each module; governing the original code repository based on the topological degrees of freedom of each module and a first preset strategy; the first preset strategy includes at least: a first preset method, a second preset method, and a third preset method.
[0008] Optionally, the governance of the original code repository based on the topological degrees of freedom of each module and the first preset strategy includes: if the topological degrees of freedom are not less than the first preset value, then processing is performed using the first preset method; if the topological degrees of freedom are less than the second preset value, then processing is performed using the second preset method; if the topological degrees of freedom are not greater than the first preset value and not less than the second preset value, then processing is performed using the third preset method; wherein, the first preset value is greater than the second preset value.
[0009] Optionally, the processing via the first preset method includes: obtaining the original module based on the original code repository; obtaining the replacement module and the adaptation format based on the original module; and migrating the data corresponding to the original module to the replacement module.
[0010] Optionally, the processing via the second preset method includes: obtaining the original module based on the original code repository; obtaining the upstream calling module based on the original module; obtaining the default return value based on the upstream calling module; and performing a deletion operation based on the default return value and the module dependency graph.
[0011] Optionally, the processing via a third preset method includes: obtaining the original module based on the original code repository; obtaining the target module based on the original module; constructing a bidirectional proxy route; and merging the original module and the target module based on the bidirectional proxy route.
[0012] Optionally, the step of governing the original code repository based on the topological degrees of freedom of each module and the first preset strategy includes: obtaining the governed code repository; monitoring the governed code repository through the second preset strategy to obtain monitoring results; calculating a quality retention factor based on the monitoring results to obtain an evaluation result; wherein the second preset strategy includes at least: a first monitoring method, a second monitoring method, and a third monitoring method; the first monitoring method corresponds to the first preset method, the second monitoring method corresponds to the second preset method, and the third monitoring method corresponds to the third preset method.
[0013] Optionally, the first monitoring method includes: topology mirroring; intelligent traffic injection; and dynamic route adjustment.
[0014] Optionally, the second monitoring method includes: topological surgery simulation; fracture impact assessment; and progressive deletion control.
[0015] Optionally, the third monitoring method includes: intelligent agent container; entropy monitoring; and automatic merging decision.
[0016] Optionally, after calculating the quality retention factor based on the monitoring results and obtaining the evaluation results, the process includes: if the evaluation results are unsuccessful, triggering a cross-policy dynamic switch; if the evaluation results are still unsuccessful after the switch, implementing a downgrade retry mechanism, executed through the first preset method; if the evaluation results are still unsuccessful, implementing a downgrade retry mechanism, executed through the second preset method; and if the evaluation results are still unsuccessful, implementing a downgrade retry mechanism, executed through the third preset method.
[0017] Optionally, after calculating the quality retention factor based on the monitoring results and obtaining the evaluation results, the following steps are taken: if the evaluation results meet the cycle termination conditions, then the treatment is stopped.
[0018] Optionally, a full scan of the original code repository is performed to obtain a module dependency graph, including: obtaining the vertex set, edge set, and weight matrix of each module; and obtaining the module dependency graph based on the vertex set, edge set, and weight matrix of each module.
[0019] A governance apparatus, comprising: an acquisition unit, an analysis unit, and a processing unit; the acquisition unit being used to acquire an original code repository; the analysis unit being used to perform a full scan of the original code repository to obtain a module dependency graph; and to perform homology group analysis of algebraic topology based on the module dependency graph to obtain isolated code modules, circular dependency chains, and cross-redundant blocks; the processing unit being used to integrate and extract the isolated code modules, the circular dependency chains, and the cross-redundant blocks to obtain a governance candidate set, and to govern the original code repository based on the governance candidate set.
[0020] An electronic device includes: a memory for storing at least one set of instructions; a processor for acquiring a raw code repository; performing a full scan of the raw code repository to obtain a module dependency graph; performing homology group analysis of algebraic topology based on the module dependency graph to obtain isolated code modules, circular dependency chains, and cross-redundant blocks; integrating and extracting the isolated code modules, circular dependency chains, and cross-redundant blocks to obtain a governance candidate set; and governing the raw code repository based on the governance candidate set.
[0021] This invention provides a code repository governance method, apparatus, and electronic device. The method involves acquiring the original code repository, performing a full scan of the original code repository to obtain a module dependency graph, determining the dependencies between modules in the code repository based on the module dependency graph, performing homology group analysis of algebraic topology based on the module dependency graph to obtain isolated code modules, circular dependency chains, and cross-redundant blocks, merging and extracting the isolated code modules, circular dependency chains, and cross-redundant blocks to obtain a governance candidate set, and automatically governing the original code repository based on the governance candidate set, thereby saving human resources. Attached Figure Description
[0022] Figure 1 A flowchart illustrating the code repository governance method provided in this embodiment of the invention; Figure 2 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 3 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 4 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 5 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 6 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 7 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 8 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 9 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 10 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 11 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 12 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 13 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 14 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 15 Another flowchart of the code repository governance method provided in this embodiment of the invention; Figure 16 A schematic diagram of the treatment device provided in an embodiment of the present invention; Figure 17 This is a schematic diagram of the structural composition of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0023] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0024] Please refer to Figure 1 , Figure 2 ,in, Figure 1 A flowchart illustrating an implementation of the code repository governance method provided in this application embodiment may include: Step S101: Obtain the original code repository; Step S102: Perform a full scan of the original code repository to obtain the module dependency graph; Step S103: Perform homology group analysis of algebraic topology based on the module dependency graph to obtain isolated code modules, circular dependency chains, and cross-redundant blocks; Step S104: Integrate and extract isolated code modules, circular dependency chains, and cross-redundant blocks to obtain a governance candidate set, and govern the original code repository based on the governance candidate set.
[0025] The original code repository is the code repository that needs to be governed. The chief engineer performs a full scan of the code repository that needs to be governed, models the call dependencies between code modules as a directed graph structure, and generates an AI-free compilation module dependency graph. Then, based on the AI-driven free compilation module dependency graph... Redundancy patterns in the code are identified through homology group analysis of algebraic topology, including: isolated code blocks (H0 group dimension), circular dependency chains (H1 group dimension), and cross-redundant modules (H2 group dimension). Then, isolated code blocks... Circular dependency chain and cross-redundant blocks The data is integrated to extract a set of governance candidates that includes isolated code, circular dependencies, and cross-redundancy. This generates a governance candidate set. By automating code repository governance through this candidate set, human resources are saved. Furthermore, compared to traditional code deduplication techniques based on syntax tree matching or simple dependency analysis, this innovation achieves a qualitative breakthrough through multi-dimensional topological invariants. Existing technologies typically only detect text-level repetition or simple call relationships, failing to identify cross-module semantic redundancy unique to AI-generated code (such as similar functional modules generated by different prompts) and interface drift caused by version iterations. This solution introduces generation count filtering when quantizing isolated code using the H0 group (…). Effectively distinguishes temporary test code from real redundancy; a model version alignment matrix is added to the H1 group calculation. It can accurately capture circular dependencies caused by mixing multiple versions of AI; while the H2 group forces the construction The 2-single form solves the problem that traditional methods are insensitive to "instruction-level repetition".
[0026] Specifically, the module dependency graph generation method is as follows: Vertex set : Each vertex This represents an AI-generated code module with attribute tuples. ,in: For module static features (number of lines of code, number of interfaces, comment density), especially including AI-generated features. Triplet; To track module change frequency, record the number of times the AI regenerates the module (as opposed to manual commits). As module domain labels, consistency scores are obtained by comparing the prompt intent during LLM generation with the code implementation. Generate metadata for the module (generate timestamps, AI model version used, temperature parameters, etc.).
[0027] - Edge set : Directed edge Representation module Call The dependency relationship, especially the identification of two types of AI-specific edges, "illusion edges": when and of The difference is greater than the threshold. When marked as a potential erroneous dependency, "copy edge": and code similarity Furthermore, it avoids unnecessary redundant dependencies in the call relationships.
[0028] -Weight matrix for: ; in: - Special weights based on AI call chain characteristics are set by the business based on the following conditions: Cross-model generation module call penalty ; Inter-module call reward items generated by the same prompt ; - Module The number of times the interface is regenerated by AI reflects its stability. - Shared execution time (the combined execution time of the two modules in the call chain); - Total execution time of the called module.
[0029] Specifically, the methods for identifying isolated code blocks (H0 group dimension), circular dependency chains (H1 group dimension), and cross-redundant modules (H2 group dimension) are as follows: H0 group computation (AI isolated module detection): ; Through the improved boundary operator matrix Calculate the number of connected components, which includes three types of correction terms: topological connectivity of regular dependent edges (weights above a threshold). (edge), AI-generated stub code markers Additive compensation (to avoid misjudging temporary test modules as isolated code), and low Prompt consistency modules ( Subtraction elimination, finally The value directly reflects the number of invalid orphaned modules in the system that need to be addressed. For example, when there are 5 modules that are not called and are not stubs... This provides quantitative targets for subsequent cleanup.
[0030] Boundary operators for: ; in: Identify the stub codes generated by AI. Excluding AI and user intentions Figure 1 Modules with low consistency It is a dynamic call relationship determination threshold used to distinguish between real and effective module calls (with weights higher than the threshold) and noise dependencies (with weights lower than the threshold) in AI-generated code. Its value is dynamically calculated based on the median and standard deviation of the call weights between modules.
[0031] -H1 group computation (AI circular dependency detection): ; Starting from the difference in the number of edges and vertices in the AI-generated subgraph, divide by the Prompt coherence coefficient. To mitigate the false loops caused by ambiguous instructions, the number of loops formed by AI modules of the same version is further reduced. (through the power trace of the adjacency matrix) (Calculation), final The value precisely quantifies the complexity of AI-specific circular dependencies, for example, when , And if 10 identical loops are detected, if but This indicates the presence of a high-density malfunctioning circulation structure.
[0032] in: ; in: Measuring the consistency of the prompts generated by AI for these modules. Matrix penalty for circular dependencies between different versions of AI generation modules, when Timely triggering of alarms, This indicates the number of edges generated by AI (excluding edges modified manually). Indicates the number of modules generated by AI (including stub code and temporary modules). Indicates a reasonable number of connected branches (including stub code filtering). This indicates the number of rings aligned to the same version, counting only rings formed by AI generation modules of the same version. This indicates the maximum loop length limit (usually set to K=5). The adjacency matrix is raised to the power of k, and the number of paths of length k from node v to itself is also expressed. Represents matrix trace operations, counting the number of closed loops, This represents the AI model version number of the generation module v_i.
[0033] -H2 group computation (AI cross-redundancy detection): Constructing the dependency complex of AI perception : Will satisfy The modules are forced to form a 2-simulacra; Computing boundary operators with entropy values : ; Calculation using temperature-weighted persistent cohomology : ; By analyzing higher-order topologies using persistent homology theory, we first construct a forced-association 2-similarity complex ( (Module group), and then calculate the boundary operator with entropy correction. The difference in dimensionality between the kernel space and the image space is then multiplied by the temperature decay factor. Suppressing highly random structural noise, such as detecting three sets of cross-module redundancies but with average generation temperature hour, This reflects the substantial amount of architectural redundancy that needs to be addressed.
[0034] in, This indicates the similarity of the Prompt instructions between two modules, used to identify redundant module groups generated by AI due to repeated / similar instructions. Represents code module nodes, Representing the traditional two-dimensional boundary operator matrix, This represents the uncertainty in generating the Prompt for a given module v. This represents the maximum possible entropy value (determined by the size of the Prompt vocabulary). The kernel space representing a reasonable boundary operator, Represents the image space of the current boundary operator, This represents the average temperature of the generated modules.
[0035] Specifically, the governance candidate set is generated as follows: Generate a candidate set for AI code repository governance : A governance candidate set is constructed through a four-layer filtering mechanism: first, the three redundant patterns obtained from homology group analysis are merged into an isolated module set. (Modules with zero in-degree and more than 50% of the modules have been regenerated), circular dependency sets (Strongly connected components with a high-temperature generation module accounting for over 30%), cross-redundant sets (Persistence score exceeds dynamic threshold) (topological void structure); then exclude the core module set. (The betweenness centrality exceeds the model version aging correction) (Key node).
[0036] - AI isolated module set: ; -AI circular dependency set: ; -AI Cross Redundancy Set: ; -AI Core Module Set: ; in: · This indicates that the in-degree of module v_i is 0 (no other module calls it); · This indicates the number of times the module has been regenerated by AI; · This indicates the maximum number of times all modules in the system can be regenerated. · This represents the set of modules that generate at temperatures > 0.7. · This represents the probability of iterative persistence. Considering the iteration interval of the AI model, redundancy generated in the old session may have been resolved in the new session. · This represents a dynamic threshold that decays over time as the model version is released. · This indicates the betweenness centrality of a module (the number of shortest paths through the module). · This indicates the age of the AI model version that generated this module (e.g., GPT-3=3, GPT-4=1). It represents the mean plus standard deviation of the betweenness centrality of all modules in the system.
[0037] Please refer to Figure 3 The method in this embodiment may include: governing the original code repository based on a governance candidate set, including: Step S201: Calculate the variant Lyapunov index for each module in the governance candidate set based on the governance candidate set; Step S202: Prioritize each module in the governance candidate set based on its variant Lyapunov index to obtain the candidate code governance queue.
[0038] Among them, based on the generated governance candidate set The evolution of the code repository automatically generated by the AI model is modeled as a discrete dynamical system. Governance actions (deletion, splitting, and downgrading) are defined as input parameters for system state transitions, and a variant Lyapunov index is calculated for each module in the governance candidate set. Based on the variant Lyapunov index, the long-term impact of deletion or modification on system stability is predicted. (For example, core modules that may lead to the breakage of multi-level call chains after deletion) are marked as restricted operation objects, and the remaining modules are sorted according to risk level to form a priority governance queue.
[0039] Specifically, the evolution of the code repository automatically generated by the AI model is modeled as a discrete dynamical system. Code governance (deletion, splitting, and degradation) is defined as the input parameter for the system state transition, where the system state changes are as follows: Through deterministic transfer functions And AI uncertainty Together driving the evolution of code repositories: Based on the current topology state and governance actions (Delete / Split / Degrade) Calculate the ideal next state, while The intent drift effect of the quantification high-temperature generation module, for example, when batch deletion... When using the module, It will amplify the state deviation caused by the randomness of generation, and an additional 10% of the disturbance path needs to be simulated in the sandbox.
[0040] in:- : The system state vector at time t; The spectral embedding of the module dependency graph in step one (the first d eigenvalues of the Laplacian matrix). Step 1 generates the Betty number of the homology group of the cluster. This represents the entropy value of historical governance actions. A set of governance actions; (Delete / Split / Downgrade), each action is accompanied by AI-generated features: Delete module Record its time and , The splitting operation must meet the following requirements: , Downgrade operations must meet the following requirements: and , AI uncertainty term, reflecting the intention of the high-temperature generation module. Figure 1 Consistency gradient, , Representation module The meaning of generation Figure 1 Consistency score, Temperature coefficient generated by AI.
[0041] Specifically, based on the governance candidate set generated in step one Calculate the variant Lyapunov index for each module in the governance candidate set. For each candidate module calculate: ; Governance module based on time-averaged sensitivity prediction Long-term impact: Computing the Jacobian matrix of a system With module sensitivity vector (Including topological influence) and the contribution of the harmonic group The logarithmic norm of the product of ) in an infinite time window Lower convergence. For example, a certain module. This indicates that deletion can reduce system entropy by 40%, while This warning could trigger a chain reaction of crashes. Specifically: The sensitivity vector of module v is calculated as follows: T: Observation time window : System state transition Jacobian matrix, Topological influence of a module in the dependency graph Changes in the contribution of homology group structure Entropy change in historical governance actions.
[0042] Specifically, regarding the calculated index The result exceeded The module with the threshold is marked as a restricted operation object (the core module whose deletion may cause a break in a multi-level call chain). The remaining modules are sorted according to risk level to form a priority governance queue. The governance queue is generated as follows: Input: , System status
[0043] Output: Priority queue
[0044] 1. First, the restricted operation set is filtered based on the variant Lyapunov index:
[0045] in, The threshold is dynamic (default 0.2). To generate the age of the AI model version of v, Use lifecycle length for AI model versions 2. Then, the candidate governance queues within the unrestricted operation set are prioritized based on conditions such as cross-redundancy, obvious redundancy, and high-temperature verification: - Identify emergency governance queues (high persistence and stable improvement of system cross redundancy): ; - Identify high-priority governance lists (significant redundancy generated at low temperatures): ; - Identify the low-priority governance list (high-temperature generation module requiring manual review): ; in: , , : Calculated from step one.
[0046] Redundancy mode persistence score indicates that the redundancy persists through multiple AI model iterations (non-temporary compatibility layer).
[0047] Module generates temperature.
[0048] 3. Finally, the three priority governance queues are sorted according to iterative persistence probability, variant Lyapunov exponent, etc., to generate the final candidate code governance queue: -Targeting the emergency management queue according to Descending order; -For high priority lists according to Ascending order (most stable items are processed first); -For low priority lists according to The queues are sorted in ascending order (the one with the most ambiguous intent is reviewed first), and then the three queues are merged into a single candidate governance queue.
[0049] Please refer to Figure 4 The method in this embodiment may include: after obtaining the candidate code governance queue, including: Step S301: Calculate the topological degrees of freedom of each module based on the candidate code governance queue and the variant Lyapunov index of each module; Step S302: Govern the original code repository based on the topological degrees of freedom of each module and the first preset strategy; the first preset strategy includes at least: a first preset method, a second preset method, and a third preset method.
[0050] Among them, the chief index is based on a variant of the Lyapunov index for each module. The topological degrees of freedom of each module are calculated, including the gravitational relationships between modules and the redundancy relationships between module groups. Then, governance is performed based on the topological degrees of freedom of each module and a first preset strategy. The first preset strategy includes three preset methods: a first preset method, a second preset method, and a third preset method. The first preset method is a three-three fixed-form module replacement method; the second preset method is a center-point isolated deletion method; and the third preset method is a cross-shaped diagonal module interchange method.
[0051] Please refer to Figure 5 , Figure 6 The method in this embodiment may include: governing the original code repository based on the topological degrees of freedom of each module and a first preset strategy, including: Step S401: If the topological degrees of freedom are not less than the first preset value, then process it according to the first preset method; Step S402: If the topological degrees of freedom are less than the second preset value, then process it according to the second preset method; Step S403: If the topological degrees of freedom are not greater than the first preset value and not less than the second preset value, then process them using the third preset method; wherein the first preset value is greater than the second preset value.
[0052] Among them, when the topological degrees of freedom When the conditions are met, the three-three fixed-form module substitution method is applied: ; Among them, topological degrees of freedom Representation module It has sufficient calling flexibility and low circular dependencies (similar to having ample "liberties" in Go); it also has modules. satisfy Requires finding the matching Alternative modules with highly similar generation instructions (Prompt semantic similarity > 70%); and temperature-corrected variant Lyapunov index. Ensure governance It can stabilize the system (exponent < -0.2) and generate at high temperatures ( The randomness of the process has been compensated for. Together, these three factors ensure that the replacement operation safely eliminates redundant modules repeatedly generated by the AI while maintaining interface compatibility.
[0053] Among them, topological degrees of freedom When the conditions are met, the center point isolation deletion method is performed: Among them, topological degrees of freedom Representation module The invocation is inflexible and carries the risk of circular dependencies (similar to the situation in Go where "liberties" are about to run out); at the same time This indicates that the module does not call any other modules (isolated and without dependencies); and the original variant Lyapunov index This ensures that directly deleting the module significantly improves system stability (index < -0.3). These three criteria collectively identify low-value AI generation modules that neither affect the system call chain nor prevent stable gains from deletion, aligning with the governance logic of "capturing dead stones" in Go.
[0054] Among them, topological degrees of freedom When the conditions are met, the method of swapping the diagonal modules of the cross shape is performed: Among them, topological degrees of freedom Representation module It is in a state of moderate flexibility (similar to the moderate "liberties" in Go, neither completely isolated nor highly coupled); and it also contains modules. satisfy The code structures must be more than 60% similar, and the call complexities of the two codes must be similar (degree difference not exceeding 2); moreover, the rate of change of their contribution to the system's circular dependencies must also be considered. and Approximate equality indicates that they play similar roles in the topology. These three conditions together identify AI generation module pairs with similar functions but moderate redundancy, providing a basis for implementing the "cross-shaped diagonal swap" strategy. By establishing proxy routing, the feasibility of module merging is gradually evaluated, optimizing architectural complexity while maintaining system stability.
[0055] Specifically, based on the variant Lyapunov index for each module And the gravitational relationships between modules, the redundancy relationships between module groups, and the calculation of topological degrees of freedom. : Direct degrees of freedom term The necessity of quantifying the calling relationships between modules, and the loop penalty term. Suppressing modules involved in complex dependencies, AI generates quality items. Reduce the score of modules with high randomness. For example, a certain module. (Direct degrees of freedom 0.9 × cycle penalty 0.8 + AI quality 0.48) is suitable for three-three substitution patterns, while Modules should be handled with care.
[0056] in, For module The set of directly adjacent nodes Edge weights (including call frequency and shared execution time) For Prompt Figure 1 Consistency score (0~1) Generate temperature parameters for The set of AI circular dependency edges involved.
[0057] Please refer to Figure 7 The method in this embodiment may include: processing through a first preset mode, including: Step S501: Obtain the original module based on the original code repository; Step S502: Based on the original module, obtain the replacement module and the adapted format; Step S503: Migrate the data corresponding to the original module to the replacement module.
[0058] Specifically, the method for replacing the three-three fixed-form module: a) Finding alternative modules: based on Prompt semantic similarity ( ) and version compatibility filtering target modules ; ; b) Interface adaptation: In the original module The outer wrapper is a version adaptation layer that automatically converts the old and new parameter formats (such as the input differences between GPT-3 and GPT-4). c) Traffic migration: by The proportion will gradually increase from Switch to Simultaneously monitor the error rate to ultimately achieve seamless replacement.
[0059] Please refer to Figure 8 The method in this embodiment may include: processing through a second preset method, including: Step S601: Obtain the original module based on the original code repository; Step S602: Based on the original module, obtain the upstream calling module; Step S603: Obtain the default return value based on the upstream calling module; Step S604: Perform the deletion operation based on the default return value and the module dependency graph.
[0060] Specifically, the core idea of the isolated deletion method is as follows: a) Confirmation Module No downstream caller ( ), and obtain the set of all upstream calling modules. ; ; b) For each caller Based on version differences, inject adaptation logic; if the caller module version is earlier than the generated version of v, downgrade the output format of v to be compatible; if the caller module version is later than v, generate the default return value according to the latest interface specification. c) Retain the v node in the dependency graph but mark it as obsolete, remove all associated edges, and continuously monitor the error rate of the upstream calling module. When the error rate is below the 1% threshold, perform physical deletion.
[0061] Please refer to Figure 9 The method in this embodiment may include: processing through a third preset method, including: Step S701: Obtain the original module based on the original code repository; Step S702: Obtain the target module based on the original module; Step S703: Construct bidirectional proxy routes; Step S704: Merge the original module and the target module based on bidirectional proxy routing.
[0062] Specifically, the method for swapping the diagonal modules of the cross shape: Based on code structure similarity from code modules ) and topological role consistency ( ), Target Filtering Module : Create a proxy module to receive unified data. and The call request is dynamically routed based on input characteristics (if the input matches...). The historical pattern was then forwarded to Otherwise forward to Inject version arbitration logic; when the difference between the caller's version and the target module's version is ≥2, automatically perform parameter conversion; monitor the decision entropy of the proxy module. When the entropy value is below 0.1 (routing decisions tend to stabilize); and They were merged into a unified module, and the original proxy layer was degraded into a compatibility wrapper.
[0063] Please refer to Figure 10 , Figure 11 The method in this embodiment may include: after governing the original code repository based on the topological degrees of freedom of each module and a first preset strategy, including: Step S801: Obtain the reorganized code repository; Step S802: Monitor the remediated code repository using the second preset strategy and obtain the monitoring results; Step S803: Calculate the quality retention factor based on the monitoring results to obtain the evaluation results; wherein, the second preset strategy includes at least: a first monitoring method, a second monitoring method, and a third monitoring method; the first monitoring method corresponds to the first preset method, the second monitoring method corresponds to the second preset method, and the third monitoring method corresponds to the third preset method.
[0064] After obtaining the remediated code repository, the repository is monitored using a second preset strategy. This second preset strategy includes three monitoring methods: a first monitoring method, a second monitoring method, and a third monitoring method. The first monitoring method involves constructing a 3x3 substitution honeypot sandbox for the 3x3 fixed module substitution method; the second monitoring method involves constructing a central point deletion honeypot sandbox for the central point isolated deletion method; and the third monitoring method involves constructing a cross-shaped swap honeypot sandbox for the cross-shaped diagonal module swap method.
[0065] Please refer to Figure 12 The method in this embodiment may include: a first monitoring method, including: Step S901: Topology mirror construction; Step S902: Intelligent flow injection; Step S903: Dynamic routing adjustment.
[0066] Specifically, a 3x3 alternative to a honeypot sandbox: 1) First, completely clone the target module. It also includes its three-layer call chain neighbors, preserving the original interface signature and version tag, while embedding semantic similarity. Replacement module A dual-version parallel environment is constructed. Traffic distribution is controlled via a routing switch to ensure that the old and new modules can be compared in real time.
[0067] 2) Next, combining historical log playback (retaining 7 days of real request sequences) with 20% of abnormal inputs generated by AI (including cross-version parameters and malformed requests), the high-temperature generation is particularly improved. The test weight is set to 30% to simulate extreme scenarios.
[0068] 3) Then initialize and allocate 10% of the traffic to Hourly based on semantic differences The error rate is automatically adjusted to adjust the traffic ratio, where the adjustment formula is: This enables incremental verification, in which This is a similarity adjustment factor, preset by the business.
[0069] 4) Calculate the quality retention factor: Among them, with 1 as the baseline, the interface conflict rate and semantic deviation rate (normalized output vector distance) are subtracted. Finally, increasing the topological degrees of freedom improves the ratio. For example, a certain replacement operation resulted in an interface conflict rate of 2%. ), semantic bias rate 10% And the degree of freedom is increased by 50%. ),but This indicates that the replacement significantly optimizes the system. Three indicators respectively constrain API compatibility, functional equivalence, and architectural health to ensure the safety and reliability of AI-generated code replacement.
[0070] Please refer to Figure 13 The method in this embodiment may include: a second monitoring method, including: Step S1001: Topological surgery simulation; Step S1002: Fracture impact assessment; Step S1003: Progressive deletion control.
[0071] Specifically, construct a central point to delete the honeypot sandbox: 1) First, ghost node technology is used to retain But marked as The call is redirected to the default value generator (older version module) or the nearest neighbor function module ( ), and freeze newly added dependency edges to isolate the impact of deletion operations.
[0072] 2) Next, quantify the change in critical path length. and execution traffic reallocation By monitoring traffic in real time Identify the risk of topological faults.
[0073] 3) Then, the built-in degradation adapter automatically trims the parameters specific to the new version, and the protocol conversion gateway handles cross-protocol calls such as gRPC / REST, adapting to and covering scenarios where multiple versions coexist.
[0074] 4) The deletion operation is performed in three phases according to time, and the situation is monitored while the operation is performed: a 24-hour observation period (marking only), a 72-hour downgrade period, and a final cleanup period (physical deletion when the error rate is <0.1%), to ensure a smooth transition.
[0075] 5) Calculate the quality retention factor: ; Among them, fracture depth The exponential decay function is used to evaluate topological integrity (the score decreases by 63% for every 1 increase in depth), and the version adaptation effect is reflected by the degradation failure rate. Finally, the Lyapunov index is used. High-risk modules are penalized with a penalty of 0.1. For example, deleting a module results in a call chain break depth of 2 ( ), downgrade failure rate 5% And without risk compensation, This triggers an automatic rollback.
[0076] Please refer to Figure 14 The method in this embodiment may include: a third monitoring method, including: Step S1101: Smart Agent Container; Step S1102: Entropy monitoring; Step S1103: Automatic merging of decisions.
[0077] Specifically, construct a cross-shaped honeypot swapping sandbox: 1) Construct a dynamic routing hub with an XGBoost decision engine. The hub analyzes the 20-dimensional features (structure / version / timing pattern) of the input parameters and selects the target module from them. or When the version difference is ≥2, the protocol conversion will be automatically triggered.
[0078] 2) Calculate the route distribution entropy every minute. It also uses the CUSUM control chart to detect abnormal fluctuations in distribution entropy, and triggers a circuit breaker when the entropy value exceeds 1.5.
[0079] 3) When the distribution entropy lasts for 6 hours Merge when compression ratio > 15% and no version conflicts. and To unify the modules, the agent layer degenerates into a compatible wrapper, retaining complete decision logs for auditing.
[0080] 4) Calculate the quality retention factor: ; Among them, through routing decision entropy The scheduling stability of the quantification proxy module (lower entropy indicates more deterministic routing) is combined with protocol conversion latency. With optimal delay The ratio of these three metrics is used to assess performance loss, and finally, the reduction ratio of circular dependencies is used to measure the effectiveness of architectural optimization. These three metrics are weighted and summed. The swap operation is considered successful at this time—for example, if (Route highly stable), conversion latency only increased by 10% ( And if circular dependencies are reduced by 30%, then It far exceeds the threshold.
[0081] Specifically, a unified quality maintenance assessment will be conducted on all honeypot sandboxes:
[0082] Among them, the unified quality retention assessment achieves automated decision-making through three dynamic thresholds: when the quality retention factor of the honeypot sandbox... And the recent 3-hour fluctuations When governance is deemed successful (operation executed), the system is in a steady-state optimization range, indicating that governance has not introduced significant risks; when A rollback is triggered when the number of errors exceeds 5 per hour. This combination of thresholds can capture sudden architectural degradation (such as circular dependency regeneration or critical path breakage). In other cases, the system enters observation mode and is continuously monitored for no more than 24 hours. If the execution criteria are not met, the process is automatically terminated.
[0083] Please refer to Figure 15 The method in this embodiment may include: calculating a quality retention factor based on monitoring results, and after obtaining the evaluation results, including: Step S1201: If the evaluation result is failure, trigger cross-policy dynamic switching; Step S1202: If the evaluation result still fails after switching, a downgrade retry mechanism is implemented, and the first preset method is used. Step S1203: If the evaluation result is still a failure, a downgrade retry mechanism is implemented, and the second preset method is used. Step S1204: If the evaluation result is still a failure, a downgrade retry mechanism is implemented, which is carried out through the third preset method.
[0084] Specifically, (1) Failure mode analysis and strategy switching conditions: when the honeypot sandbox quality retention factor When the threshold is not met (i.e.) ), triggering the cross-policy dynamic switching algorithm: Among them, the optimal governance strategy is dynamically selected through a two-stage weighted decision-making process. First, the calculation module... Stability-degrees of freedom ratio The potential benefits of quantifying this module are calculated (the numerator reflects the system stability gain, and the denominator suppresses risky operations by highly coupled modules); then multiplied by the policy compatibility score. After ruling out technically infeasible solutions (such as attempting to delete non-isolated modules), the strategy with the highest overall score is ultimately selected for governance.
[0085] (2) If the switch still fails, a downgrade retry mechanism is implemented. The retry mechanism for the three-three fixed-form module replacement method is as follows: when the original strategy fails due to semantic output deviation ( When a failure occurs, the system automatically triggers a two-stage correction: first, candidate set expansion, relaxing the Prompt similarity threshold to... Incorporate more potential alternative modules and use version-weighted scoring. The first step involves reordering candidates; the second is semantic adaptation enhancement, which involves embedding a lightweight MLP model in the proxy layer to dynamically align the output vector spaces of the old and new modules. If the correction is successful... If so, continue execution; otherwise, switch to the cross-star exchange strategy.
[0086] (3) If the switch still fails, a downgraded retry mechanism will be implemented. The retry mechanism for the isolated deletion method of the central point is as follows: for the retry mechanism due to the broken call chain ( For failures caused by [unspecified event], the system performs a three-level compensation: the first level is virtual stub injection, which automatically selects a default value generator based on the module's version and preserves the original interface signature; the second level is an elastic retry mechanism, which automatically redirects failed call requests to the nearest compatible module in the topology. If there are 3 failures, the system will revert to the original module; Level 3 is a secondary evaluation, monitoring for 72 hours. If the percentage drops below 0.5%, confirm the deletion; otherwise, roll back and mark it as a "multi-version dependency hotspot".
[0087] (4) If the switch still fails, a downgrade retry mechanism will be implemented. The retry mechanism for the cross-shaped diagonal module swapping method is as follows: if the failure is due to routing uncertainty ( If the trigger fails, the system initiates a dynamic optimization process. First, feature enhancement is performed by adding five-dimensional contextual features, such as caller version and time pattern, to the routing model to improve decision accuracy. Second, redundancy verification is performed in parallel. and The logic involves comparing output consistency; if the difference exceeds a threshold, a historically successful path is automatically selected. Finally, a degradation decision is made when there are 12 consecutive hours of... At that time, according to the module's degrees of freedom The decision was made to downgrade to a three-three fixed pattern ( Or delete directly. ).
[0088] The method in this embodiment may include: calculating a quality retention factor based on monitoring results, and after obtaining the evaluation results, stopping the treatment if the evaluation results meet the cycle termination conditions.
[0089] Specifically, regarding termination conditions and closed-loop control, the loop termination condition is: ; The termination condition is implemented through a dual-threshold circuit breaker mechanism to achieve closed-loop control, immediately stopping the governance process when either condition is met. (1) Success conditions ( If the quality retention factor exceeds the optimization threshold, it indicates that the system has reached a steady state after treatment, and the operation can take effect. (2) Failure to trigger circuit breaker ( The system will forcibly terminate the process when the maximum number of retries is reached, preventing infinite retries due to inherent defects in AI-generated code (such as ambiguity in the Prompt and high randomness). It will also mark the module as a special case requiring manual intervention. Updates will be synchronized after each retry. A value and retry counter are used to monitor termination conditions in real time. For example, the first time a module is processed... (Try again), second time (Still not up to standard), the third time if If the error rate does not exceed 0.8 or a surge in errors occurs, a circuit breaker will be triggered and the system will roll back to the pre-remediation state, generating a diagnostic report containing information such as version differences and temperature parameters for subsequent optimization reference.
[0090] Specifically, the governance solution, verified for quality retention, will be deployed to the production environment of the AI large-scale model's code repository. This involves physical removal of redundant code, microservice transformation of circular dependencies, and migration of redundant modules. After governance, changes in the code repository's quality retention will be continuously tracked. If abnormal topology features are detected to reappear (such as the formation of new circular dependencies), the process will return to step two, automatically triggering an incremental governance process to form a closed-loop governance mechanism.
[0091] Specifically, based on the variant Lyapunov index for each module And the gravitational relationships between modules, the redundancy relationships between module groups, and the calculation of topological degrees of freedom. The system determines the governance operations that modules can perform, including the three-three fixed module replacement method, the centroid isolation deletion method, and the cross-shaped diagonal module swapping method. Different types of honeypot sandboxes are constructed to correspond to different governance operations through topology mirroring, intelligent traffic injection, and dynamic route adjustment. The quality retention factors of different types of honeypot sandboxes are calculated, and a unified quality retention assessment is formed through triple dynamic thresholds. If the unified quality retention assessment of the honeypot sandbox does not meet the conditions for executing governance, a variant Lyapunov index is used to perform a strategy compatibility judgment operation with the topological degrees of freedom. Then, a self-stability-degree-of-freedom dynamic switching strategy is used to switch to one of the other two of the three governance methods for execution.
[0092] The method in this embodiment may include: performing a full scan of the original code repository to obtain a module dependency graph, including: obtaining the vertex set, edge set, and weight matrix of each module; and obtaining the module dependency graph based on the vertex set, edge set, and weight matrix of each module.
[0093] Specifically, vertex set : Each vertex This represents an AI-generated code module with attribute tuples. ,in: For module static features (number of lines of code, number of interfaces, comment density), especially including AI-generated features. Triplet; To track module change frequency, record the number of times the AI regenerates the module (as opposed to manual commits). As module domain labels, consistency scores are obtained by comparing the prompt intent during LLM generation with the code implementation. Generate metadata for the module (generate timestamps, AI model version used, temperature parameters, etc.).
[0094] - Edge set : Directed edge Representation module Call The dependency relationship, especially the identification of two types of AI-specific edges, "illusion edges": when and of The difference is greater than the threshold. When marked as a potential erroneous dependency, "copy edge": and code similarity Furthermore, it avoids unnecessary redundant dependencies in the call relationships.
[0095] -Weight matrix for: ; in: - Special weights based on AI call chain characteristics are set by the business based on the following conditions: Cross-model generation module call penalty ; Inter-module call reward items generated by the same prompt ; - Module The number of times the interface is regenerated by AI reflects its stability. - Shared execution time (the combined execution time of the two modules in the call chain); - Total execution time of the called module.
[0096] Please refer to Figure 16 The apparatus of this embodiment may include the following structure: Unit 1301 is used to retrieve the original code repository; Analysis unit 1302 is used to perform a full scan of the original code repository to obtain the module dependency graph; based on the module dependency graph, it performs homology group analysis of algebraic topology to obtain isolated code modules, circular dependency chains, and cross-redundant blocks; Processing unit 1303 is used to integrate and extract isolated code modules, circular dependency chains, and cross-redundant blocks to obtain a governance candidate set, and to govern the original code repository based on the governance candidate set.
[0097] Please refer to Figure 17 This embodiment of the present application also discloses an electronic device, which includes at least one processor 701, and at least one memory 702 and a bus 703 connected to the processor 701; wherein the processor 701 and the memory 702 communicate with each other through the bus 703; the processor 701 is used to call program instructions in the memory 702 to execute the above-mentioned code repository governance method.
[0098] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A code repository governance method, characterized in that, The method includes: Obtain the original code repository; A full scan of the original code repository was performed to obtain the module dependency graph; Based on the module dependency graph, homology group analysis of algebraic topology is performed to obtain isolated code modules, circular dependency chains, and cross-redundant blocks. The isolated code modules, circular dependency chains, and cross-redundant blocks are integrated and extracted to obtain a governance candidate set, and the original code repository is governed based on the governance candidate set.
2. The method according to claim 1, characterized in that, Governing the original code repository based on the governance candidate set includes: Based on the governance candidate set, a variant Lyapunov index is obtained for each module in the governance candidate set. Priority is assigned to each module in the governance candidate set based on its variant Lyapunov index to obtain a candidate code governance queue.
3. The method according to claim 2, characterized in that, After obtaining the candidate code governance queue, the process includes: The topological degrees of freedom of each module are obtained by calculating based on the candidate code governance queue and the variant Lyapunov index of each module. The original code repository is governed based on the topological degrees of freedom of each module and the first preset strategy. The first preset strategy includes at least: a first preset method, a second preset method, and a third preset method.
4. The method according to claim 3, characterized in that, The governance of the original code repository based on the topological degrees of freedom of each module and the first preset strategy includes: If the topological degrees of freedom are not less than the first preset value, then the processing is performed in the first preset manner; If the topological degree of freedom is less than the second preset value, then it is processed in the second preset manner; If the topological degrees of freedom are not greater than the first preset value and not less than the second preset value, then the processing is carried out in the third preset manner; The first preset value is greater than the second preset value.
5. The method according to claim 4, characterized in that, The processing via the first preset method includes: Based on the original code repository, the original module is obtained; Based on the original module, a replacement module and an adapted format are obtained; The data corresponding to the original module is migrated to the replacement module.
6. The method according to claim 5, characterized in that, The processing via the second preset method includes: Based on the original code repository, the original module is obtained; Based on the original module, the upstream calling module is obtained; Based on the upstream calling module, obtain the default return value; The deletion operation is performed based on the default return value and the module dependency graph.
7. The method according to claim 6, characterized in that, The processing via the third preset method includes: Based on the original code repository, the original module is obtained; Based on the original module, the target module is obtained; Build bidirectional proxy routing; The original module and the target module are merged based on the bidirectional proxy routing.
8. The method according to claim 7, characterized in that, The process of governing the original code repository based on the topological degrees of freedom of each module and the first preset strategy includes: Obtain the restructured code repository; The reorganized code repository is monitored using a second preset strategy to obtain monitoring results; Based on the monitoring results, a quality retention factor is calculated to obtain the evaluation results; The second preset strategy includes at least: a first monitoring method, a second monitoring method, and a third monitoring method; The first monitoring method corresponds to the first preset method, the second monitoring method corresponds to the second preset method, and the third monitoring method corresponds to the third preset method.
9. The method according to claim 8, characterized in that, The first monitoring method includes: Topology mirroring; Intelligent traffic injection; Dynamic routing adjustment.
10. The method according to claim 8, characterized in that, The second monitoring method includes: Topological surgical simulation; Fracture impact assessment; Gradual deletion control.
11. The method according to claim 8, characterized in that, The third monitoring method includes: Smart agent container; Entropy monitoring; Automatic decision merging.
12. The method according to claim 8, characterized in that, Based on the monitoring results, a quality retention factor is calculated, and the evaluation results are obtained, including: If the evaluation result is failure, a cross-policy dynamic switch is triggered; If the evaluation result still fails after switching, a downgrade retry mechanism will be implemented, and the first preset method will be used. If the evaluation result is still a failure, a downgrade retry mechanism will be implemented, and the second preset method will be used. If the evaluation result is still a failure, a downgrade retry mechanism will be implemented, which will be executed through the third preset method.
13. The method according to claim 12, characterized in that, Based on the monitoring results, a quality retention factor is calculated, and the evaluation results are obtained, including: If the evaluation results meet the cycle termination condition, then the treatment will stop.
14. The method according to claim 1, characterized in that, A full scan of the original code repository was performed to obtain a module dependency graph, including: Obtain the vertex set, edge set, and weight matrix for each module; Based on the vertex set, edge set, and weight matrix of each module, the module dependency graph is obtained.
15. A treatment device, characterized in that, The device includes: an acquisition unit, an analysis unit, and a processing unit. The acquisition unit is used to acquire the original code repository; The analysis unit is used to perform a full scan of the original code repository to obtain a module dependency graph; and to perform homology group analysis of algebraic topology based on the module dependency graph to obtain isolated code modules, circular dependency chains, and cross-redundant blocks. The processing unit is used to integrate and extract the isolated code modules, the circular dependency chains, and the cross-redundant blocks to obtain a governance candidate set, and to govern the original code repository based on the governance candidate set.
16. An electronic device, characterized in that, include: Memory, used to store at least one set of instructions; A processor used to retrieve the original code repository; A full scan of the original code repository was performed to obtain the module dependency graph; Based on the module dependency graph, homology group analysis of algebraic topology is performed to obtain isolated code modules, circular dependency chains, and cross-redundant blocks. The isolated code modules, circular dependency chains, and cross-redundant blocks are integrated and extracted to obtain a governance candidate set, and the original code repository is governed based on the governance candidate set.