An AI-generated code judgment method and system based on submitted fact anchoring
Patent Information
- Application Number
- CN202610922264.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-25
- Publication Date
- 2026-09-11
AI Technical Summary
该技术方案包括下载git代码工程;用户本地进行代码开发编写;提交代码;触发静态代码检测工具自动代码检测;输出检测结果到文件;用户判断检测结果,若正确跳转到步骤G,否则跳转到步骤H;步骤G、修改检测出的代码错误,跳转到重新执行代码提交;步骤H、上传代码;触发检测结果自动上传到存储服务器;检测结果供在线访问查看;对代码及检测结果进行人工审核,若不通过跳转到步骤G;否则执行代码入库;但是,上述技术方案全程仅做代码质量检测与流程管控,未涉及AI编码行为识别、代码来源追溯,无法区分代码是人工编写还是AI生成,也不能区分不同AI编码工具的贡献;同时,上述技术方案只留存最终代码与静态检测结果,不采集代码编写阶段的行为日志、变更过程数据,没有可追溯的过程证据,无法对代码行的生成来源进行复核、审计;此外,上述技术方案仅关注代码缺陷、审核结果与入库流程,无法支撑AI工具效果评估、研发度量、工作量核算等管理需求
1、本发明构建由AI行为事件证据、Git提交事实证据和核销证明对象组成的三元证据链,使被判定为AI贡献的代码变更行能够追溯至对应的AI行为事件和提交差异行,对具备事件证据支撑的提交差异行进行AI来源判定,区分人工代码、不同AI工具生成代码,便于后续复核和审计;
Smart Images

Figure CN122733346A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information processing technology, and mainly to an AI-generated code judgment method and system based on submitted fact anchoring. Background Technology
[0002] AI-assisted coding tools have been widely applied in enterprise software development processes, significantly improving coding efficiency. Against this backdrop, identifying the source of AI-generated code, tracing its line-level origins, tracking usage, and evaluating its effectiveness have become core requirements for enterprise R&D efficiency management, quality auditing, cost accounting, and tool selection. Currently, the industry has developed various technical solutions for AI coding behavior statistics and code contribution attribution, but all solutions have significant shortcomings and cannot meet the demands of enterprises using multiple AI coding tools in combination for accurate, verifiable, and line-level code assessment.
[0003] Current traditional Git code statistics tools rely on data from the Git repository itself to track basic information such as the number of lines added or deleted in each commit and pull request, the scope of file changes, and the commit author. However, these tools rely solely on the final code commit as the only data source, completely lacking process evidence of AI coding behavior. They cannot distinguish whether the code was written manually or generated by AI, nor can they accurately classify the code contributions of different tools such as Cursor and Codex. Consequently, they are ill-suited to the refined attribution requirements of AI-assisted coding scenarios.
[0004] Chinese invention patent application CN 117130908 A discloses a method for automatic code detection based on Git. The technical solution includes downloading the Git code project; the user developing and writing code locally; committing the code; triggering an automatic code analysis tool to perform code analysis; outputting the analysis results to a file; the user judging the analysis results, if correct, proceeding to step G, otherwise proceeding to step H; step G: correcting the detected code errors, then proceeding to re-committing the code; step H: uploading the code; triggering the automatic upload of the analysis results to the storage server; the analysis results are available for online viewing; the code and analysis results undergo manual review, if they fail, proceeding to step G; otherwise, the code is added to the repository. However, the above technical solution only performs code quality detection and process control throughout the entire process, without involving AI coding behavior recognition or code source tracing. It cannot distinguish whether the code is manually written or AI-generated, nor can it distinguish the contributions of different AI coding tools. At the same time, the above technical solution only retains the final code and static analysis results, without collecting behavior logs or change process data during the code writing stage, lacking traceable process evidence, and unable to review or audit the source of code lines. In addition, the above technical solution only focuses on code defects, review results, and the repository process, and cannot support management needs such as AI tool effectiveness evaluation, R&D measurement, and workload accounting.
[0005] Therefore, there is an urgent need for a method that can enable AI-generated code to achieve accurate traceability, source differentiation, and quantitative statistics. Summary of the Invention
[0006] To address the problems existing in the prior art, this invention proposes an AI-generated code judgment method and system based on submitted fact anchoring.
[0007] The technical solution of the present invention is as follows: On the one hand, this invention proposes an AI-generated code judgment method based on submitted fact anchoring, the method comprising: Collect AI behavior events generated by AI coding tools and convert them into unified event objects as event evidence; Retrieve the difference data of the parent commit corresponding to the current commit of the target code, as a Git commit fact; Based on event evidence and Git commit facts, a one-to-one verification is performed to determine whether the code corresponding to the current commit fact was generated by the AI coding tool. When the verification is successful, an AI code contribution proof object is generated. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. Generate AI code contribution statistics reports based on AI code contribution proof objects.
[0008] Preferably, the AI encoding tool includes a first type of tool and a second type of tool, specifically: The first type of tool listens for code editing completion events and extracts the code text before and after the code editing changes to construct AI behavior events; The second type of tool captures difference snapshots of the workspace before and after the call; it extracts the text lines added or deleted during the current tool call by comparing the count differences of the difference snapshots, in order to construct AI behavioral events.
[0009] Preferably, the difference data specifically refers to the uniformly formatted difference text, digitized statistics of added and deleted lines, and the set of changed files obtained when executing the git diff HEAD^1..HEAD command; Preprocess the differential data, including excluding rows with pure blank lines and low signal signs; The preprocessed difference data is used as the Git commit fact.
[0010] Preferably, before performing consumer-based matching, path normalization and text normalization are performed on AI behavioral events and differential data, wherein: The path normalization includes at least standardizing path separators, converting absolute paths to repository relative paths, normalizing Windows drive letter case, fixing path character encoding anomalies, and handling path prefix differences in single-repository multi-project code repository scenarios. The text normalization specifically includes at least removing whitespace characters from code lines to obtain a normalized text key, and filtering out pure blank lines or lines with low signal symbols.
[0011] Preferably, the reconciliation step includes reconciliation of the ordinary event queue, reconciliation of the fragment event queue, and reconciliation of the global fallback queue, wherein: The ordinary event queue reversal specifically involves establishing an ordinary event queue for each changed file or each normalized file path, including a new line queue and a deleted line queue; matching the new lines in the difference data with the new lines in the AI behavior events, and matching the deleted lines in the difference data with the deleted lines in the AI behavior events; if the match is successful, an AI code contribution proof object is generated, and the corresponding event line is removed from the corresponding queue. The specific process of the fragment event queue verification involves text normalization of code fragments generated based on AI coding tool completion or fragment generation events to obtain normalized code fragments. The length of the code fragment is the number of characters in the string of the normalized code fragment. When the number of characters is not less than a preset threshold, the normalized code fragment is added to the fragment event queue. The process involves traversing the difference rows in the difference data, performing text normalization on the difference rows, and determining whether the normalized difference rows contain the normalized code fragment. If they do, the matching is considered successful, a corresponding AI code contribution proof object is generated, and the current code fragment is removed from the fragment event queue. Specifically, the global fallback queue verification process involves searching for an event that matches the normalized text key in the AI behavior event queue if the difference line in the current difference data is not found in either the normal event queue or the fragment event queue of the corresponding file, and the normalized character length of the difference line in the current difference data reaches the minimum valid length. If a match is found, an AI code contribution proof object is generated, and the matched global event line or event fragment is removed from the global AI behavior event queue.
[0012] Preferably, the AI code contribution proof object includes source event identifier, file path, source identifier, AI contribution score, line number, normalized code line content hash, and change direction.
[0013] Preferably, the AI code contribution statistics report includes file-level metrics and metrics by source, wherein: The file-level metrics describe the total number of lines added or deleted, AI-generated lines added or deleted, and deletion attribution for each file. The statistics by source are calculated at least based on the source of the AI editing tool, showing the proportion of AI-added or deleted lines in all modified code text.
[0014] On the other hand, the present invention also provides an AI-generated code judgment system based on submitted fact anchoring, the system comprising: The behavior acquisition module collects AI behavior events generated by the AI coding tool and converts them into unified event objects as event evidence. The commit fact anchoring module retrieves the difference data of the parent commit corresponding to the current commit of the target code, and uses it as the Git commit fact. The reconciliation module performs one-to-one reconciliation based on event evidence and Git commit facts, and determines whether the code corresponding to the current commit fact was generated by the AI coding tool. When the reconciliation is successful, an AI code contribution proof object is generated. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. The report generation module generates AI code contribution statistics reports based on AI code contribution proof objects.
[0015] Furthermore, the present invention also provides a performance management method based on AI code contribution statistical reports, which generates AI code contribution statistical reports using the method described in any embodiment, the method comprising: Obtain the AI code contribution statistics report, and extract the number of AI lines added or deleted and the code contribution ratio of AI coding tools from the AI code contribution statistics report; Map the number of lines added or deleted by AI and the code contribution ratio of AI coding tools to preset performance mapping rules to obtain corresponding performance management operations; Perform the performance management operations on the target code repository.
[0016] In another aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the method described in the present invention.
[0017] The present invention has the following beneficial effects: 1. This invention constructs a ternary evidence chain consisting of AI behavior event evidence, Git commit fact evidence, and reversal proof objects, enabling code change lines judged as AI contributions to be traced back to the corresponding AI behavior events and commit difference lines. For commit difference lines supported by event evidence, the source of AI is determined, distinguishing between manual code and code generated by different AI tools, which facilitates subsequent review and auditing. 2. This invention uses the difference between the current commit and the first parent commit as the fact boundary. Only code changes that enter the final commit are considered for AI contribution, thus avoiding inflated statistics caused by content generated by the AI tool but not committed. 3. The present invention adopts a verification mechanism, which removes a line of code or code segment from the corresponding queue after a certain AI behavior event is successfully matched, thus avoiding the repeated counting of the same line of code due to duplicate hooks, duplicate events or historical residual configurations. 4. This invention employs a hierarchical verification mechanism consisting of a regular event queue, a fragment event queue, and a global fallback queue to handle regular code editing, fragment completion, and path anomaly scenarios respectively. Furthermore, it combines fragment length thresholds, minimum effective length, and low-signal line filtering rules to reduce false matching caused by short fragments or path anomalies. 5. This invention converts heterogeneous AI behavior events, such as Cursor editor events and Codex tool call difference events, into unified event objects and distinguishes them by source identifiers, supporting unified statistics and source-specific statistics of contributions from different AI coding tools; 6. The AI code contribution proof object generated by this invention includes source event identifier, file path, change direction, line number, source identifier, and line content hash, which can support subsequent recalculation and verification based on the event ledger and Git commit differences. Attached Figure Description
[0018] Figure 1 This is a detailed flowchart of an embodiment of the present invention. Detailed Implementation
[0019] 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.
[0020] It should be understood that the step numbers used in the text are for ease of description only and are not intended to limit the order in which the steps are performed.
[0021] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0022] The terms “comprising” and “including” indicate the presence of the described feature, whole, step, operation, element and / or component, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or collections thereof.
[0023] The term “and / or” refers to any combination of one or more of the associated listed items, as well as all possible combinations, and includes these combinations.
[0024] Example 1: See Figure 1 This invention provides an AI-generated code judgment method based on submitted fact anchoring, the method comprising: S1. Collect AI behavior events generated by AI coding tools and convert them into unified event objects as event evidence; The unified event object includes the file path, the text before the change, the text after the change, the source identifier, and the source event identifier; The AI encoding tools include a first type of tool and a second type of tool, specifically: The first type of tool listens for code editing completion events and extracts the code text before and after the code editing changes to construct AI behavior events; The second type of tool captures difference snapshots of the workspace before and after the call; it extracts the text lines added or deleted during the current tool call by comparing the count differences of the difference snapshots, in order to construct AI behavioral events; AI coding tools generate raw behaviors and hook payloads during code generation or editing; AI tool hooks capture these payloads and extract fields such as file path, text before change, text after change, and source identifier to construct a unified AI behavior event; The AI behavior events are jointly executed by an integrated development environment (IDE) plugin, a command-line processing module, AI tool hooks, and Git hooks. The AI tool hooks are used to collect AI behavior events, the IDE plugins are used to configure the AI tool hooks and workspace parameters, the command-line processing module is used to record AI behavior events, parse submission differences, and generate AI code contribution statistics reports, and the Git hooks are used to trigger reversal processing after code submission and to trigger the reporting of AI code contribution statistics reports before code push. In this embodiment, the first type of tool is the Cursor tool. The record-hook reads the payloads of afterFileEdit and afterTabFileEdit, normalizes fields such as filePath, oldString (text before change), newString (text after change), and hookEventName (hookEventName), marks the AI source identifier agentSource as cursor (for Cursor events, mark the AI source identifier agentSource as cursor; for Codex events, mark the agentSource as codex), and appends it to .cursor / animus / events / events_YYYY-MM-DD.jsonl under the top level of the Git repository. Among them, record-hook is a hook script used to record Cursor editing events; afterFileEdit indicates the file editing completion event; afterTabFileEdit indicates the editing event after Tab completion or fragment completion; In this embodiment, for example, the repository path is / Users / tang / Documents / Project / demo; after an event is generated, it will be appended to / Users / tang / Documents / Project / demo / .cursor / animus / events / events_YYYY-MM-DD.jsonl; where the file content is one JSON per line, for example {"recordedAt":1781433600000,"sourceEventId":"cursor:chat001:gen001","agentSource":"cursor","filePath":"src / utils / math.ts","hookEventName":"afterFileEdit","oldString":"","newString":"export function sum(a,b) { return a + b;}","conversationId":"chat001","generationId":"gen001"}; The second type of tool is the Codex tool. The codex-hook saves a snapshot of the difference data (diff) between the working area and HEAD in PreToolUse, and obtains the diff again in PostToolUse. By comparing the difference in diff counts before and after, it extracts the text lines added or deleted in this tool call and constructs an event with agentSource as codex. Both types of events can be written to the same event ledger, uniformly including fields such as filePath, oldString / newString, agentSource, sourceEventId, hookEventName, and recordedAt; sourceEventId can be prefixed with cursor: or codex: to avoid source confusion from the data structure perspective; S2. Obtain the difference data of the parent commit corresponding to the current commit of the target code as a Git commit fact. The difference data includes changes to file paths, added lines, deleted lines and corresponding line numbers. The specific difference data refers to the uniformly formatted difference text, numerical statistics of added and deleted lines, and the set of changed files obtained when executing the `git diff HEAD^1..HEAD` command. The uniformly formatted difference text is used to show the specific lines of code added and deleted in each file. The numerical statistics of added and deleted lines are used to typically indicate how many lines were added and how many lines were deleted in each file. The set of changed files includes a list of file paths that changed in this commit. Preprocess the differential data, including excluding rows with pure blank lines and low signal signs; Use the preprocessed difference data as the Git commit fact; S3. Based on event evidence and Git commit facts, perform one-to-one verification to determine whether the code corresponding to the current commit fact was generated by the AI coding tool. When the verification is successful, generate an AI code contribution proof object. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. S31. Before performing consumer-based matching, perform path normalization and text normalization on AI behavioral events and differential data, where: The path normalization includes at least standardizing path separators, converting absolute paths to repository relative paths, normalizing Windows drive letter case, fixing path character encoding anomalies, and handling path prefix differences in single-repository multi-project code repository scenarios. The text normalization specifically includes at least removing whitespace characters such as spaces, tabs, and newlines from code lines to obtain a normalized text key, and filtering out pure blank lines or lines with low signal symbols; In this embodiment, exportconstrole = normalizeRole(inputRole) is normalized to exportconstrole = normalizeRole(inputRole); S32, the reconciliation step includes ordinary event queue reconciliation, fragment event queue reconciliation, and global fallback queue reconciliation, wherein: S321. The ordinary event queue verification specifically involves establishing an ordinary event queue for each changed file or each normalized file path, including a new line queue and a deleted line queue; matching the new lines in the difference data with the new lines in the AI behavior events, and matching the deleted lines in the difference data with the deleted lines in the AI behavior events; if the match is successful, generating an AI code contribution proof object and removing the corresponding event line from the corresponding queue. S322. The specific process of the fragment event queue verification is as follows: Text normalization is performed on code fragments generated based on AI coding tool completion or fragment generation events to obtain normalized code fragments; the length of the code fragment is the number of characters in the string of the normalized code fragment; when the number of characters is not less than a preset threshold, the normalized code fragment is added to the fragment event queue; the difference rows in the difference data are traversed, text normalization is performed on the difference rows, and it is determined whether the normalized difference rows contain the normalized code fragment; if they do, the match is successful, a corresponding AI code contribution proof object is generated, and the current code fragment is removed from the fragment event queue. S323. Specifically, the global fallback queue verification is as follows: if the difference line in the current difference data is not found in either the ordinary event queue or the fragment event queue of the corresponding file, and the normalized character length of the difference line in the current difference data reaches the minimum valid length, then the event matching the normalized text key is searched in the AI behavior event queue; if a match is found, an AI code contribution proof object is generated, and the matched global event line or event fragment is removed from the global AI behavior event queue. S33. The AI code contribution proof object includes source event identifier sourceEventId, file path filePath, source identifier agentSource, AI contribution score aiScore, line number newStart, normalized code line content hash lineContentHashes, and change direction kind (such as added or deleted). The AI code contribution proof object is specifically an object used to record this matching relationship, for example: { "sourceEventId": "cursor:chat123:gen456", "filePath": "src / utils / math.ts", "kind": "added", "agentSource": "cursor", "aiScore": 1, "newStart": 12, "lineContentHashes": ["..."] }; In this embodiment, the AI contribution score is a binary score; if a submission difference row successfully matches an AI behavior event, the AI contribution score of that row is 1; if it does not match successfully, no attribution proof object is generated, or it is regarded as 0. It can also be extended to a continuous score calculated based on text similarity, fragment coverage, etc. S4. Generate an AI code contribution statistics report based on the AI code contribution proof object; The AI code contribution statistics report includes file-level metrics and metrics by source, wherein: The file-level metrics describe the total number of lines added or deleted, AI-generated lines added or deleted, and deletion attribution for each file. The source-based statistical indicators should at least calculate the proportion of AI-added / deleted lines in all modified code text based on the source of the AI editing tool. After the report is generated, the system writes the commit hash value (commitSha) to be reported into the pending commit list (.git / animus / pending-shas.json) in the Git metadata directory; the pre-push reads pending-shas, uploaded-shas, and commit-history.json, filters uploaded items, and reports them after splitting them into chunks based on the number of items and UTF-8 bytes; after the server returns successShas / failed, the client only writes successShas to .git / animus / uploaded-shas.txt and removes it from pending-shas. Here, `pre-push` is the Git hook triggered before code is pushed; `.git / animus / pending-shas.json` is the file containing the list of commits yet to be uploaded, which contains a set of commit hashes that have not yet been successfully uploaded; `commit-history.json` is the commit history file, with one JSON per line; `.git / animus / uploaded-shas.txt` is the file recording the hashes of successfully uploaded commits; `successShas / failed` are the lists of successful commit hashes and failed commits returned by the server; and `commitSha` is the commit hash. In a specific embodiment, assuming the Git repository root directory is / Project / demo, the developer only opens the subdirectory / Project / demo / packages / app in Cursor; the commit number is 9f8e7d6c5b4a3210, and the commit content includes TypeScript code, a README document, and a binary image file; before the commit, the developer used Cursor's normal editing, Cursor Tab completion, and Codex tool calls, which also included duplicate hooks, path anomalies, and manually written code; this embodiment sets 10 representative processing scenarios, as shown in Table 1; where E1 to E8 are AI behavior events collected and converted, E9 is binary resource events that should be excluded, and E10 is manual code changes for which there is no corresponding AI behavior event; Table 1 AI Behavioral Events
[0025] Retrieve the difference data of the parent commit corresponding to the current commit of the target code, as a Git commit fact; The event evidence and submitted facts are verified against the general event queue, specifically as follows: The path and text of the `formatName` line in the `diff` function are aligned with `E1`, thus generating a contribution proof object; after generation, the line corresponding to `E1` is removed from the queue; for example: diff line: packages / app / src / user.ts+export function formatName(name) {return name.trim();}; Event hit: E1 cursor:conv-001:gen-001; Generate an AI code contribution proof object: {"sourceEventId":"cursor:conv-001:gen-001","filePath":"packages / app / src / user.ts","kind":"added","agentSource":"cursor","newStart":1,"newCount":1,"aiScore":1}; The event evidence and submitted facts are verified in the fragment event queue, specifically as follows: The complete line in the `diff` function is `export const PI = 3.14159`, but E3 only records 3.14159. Because E3 is an `afterTabFileEdit` and the fragment length meets the threshold, it determines that the complete line contains this fragment, thus the match is successful. For example: Normalized text keys for different rows: exportconstPI=3.14159; Fragment text key: 3.14159; Determine if the diff line text keys contain fragment text keys; Result: Matching successful, generating an AI code contribution proof object from the Cursor source, and removing the fragment instance corresponding to E3 from the fragment event queue of this file and the global fragment event queue; The evidence of the incident and the facts submitted will be verified and cleared through a global backstop queue, specifically as follows: The `timeoutMs` line in `packages / app / src / config.ts` corresponds to E7, but the file path recorded by E7 is `session-cache / config-copy.ts`. This path cannot be uniquely aligned with the set of changed files in this commit, so it is not entered into any single-file event queue. First, the normal queue and fragment queue for this file are tried, both failing. Then, the `diff` line is checked: it is not a blank line, not a low-signal line, and its normalized length is greater than 16, so it is entered into the global catch-all queue. An E7 with the same text key exists in the global queue, so the match is successful. For example: diff line: exportconsttimeoutMs=30000; Normalized text key: export const timeout Ms=30000; This file queue: No hit; Global queue: Hits E7; Result: Generates an AI code contribution proof object, with the filePath using packages / app / src / config.ts from the commit facts; The final generated AI code contribution proof object is written as an element of the aiBlocks array to the local commit report .cursor / animus / state / commit-report.final.json; at the same time, the commit report containing the proof object is appended to the history report file .cursor / animus / state / commit-history.json as a JSON object on a line, instead of saving each proof object as a separate file; Current commit report: .cursor / animus / state / commit-report.final.json; Historical report: .cursor / animus / state / commit-history.jsonl; List of pending reports: .git / animus / pending-shas.json; The reported list is located at: .git / animus / uploaded-shas.txt.
[0026] Example 2: This embodiment provides an AI-generated code judgment system based on submitted fact anchoring, the system comprising: The behavior acquisition module collects AI behavior events generated by the AI coding tool and converts them into unified event objects. The unified event objects include file path, text before change, text after change, source identifier, and source event identifier. The commit fact anchoring module retrieves the difference data of the parent commit corresponding to the current commit of the target code, and uses it as the Git commit fact. The reconciliation module performs one-to-one reconciliation based on event evidence and Git commit facts, and determines whether the code corresponding to the current commit fact was generated by the AI coding tool. When the reconciliation is successful, an AI code contribution proof object is generated. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. The report generation module generates AI code contribution statistics reports based on AI code contribution proof objects.
[0027] Example 3: This embodiment provides a performance management method based on AI code contribution statistics reports, using AI code contribution statistics reports generated by the method described in any embodiment, the method including: Obtain the AI code contribution statistics report, and extract the number of AI lines added or deleted and the code contribution ratio of AI coding tools from the AI code contribution statistics report; Map the number of lines added or deleted by AI and the code contribution ratio of AI coding tools to preset performance mapping rules to obtain corresponding performance management operations; Perform the performance management operations on the target code repository.
[0028] Preferably, the mapping of the number of lines added / deleted by AI and the code contribution ratio of AI coding tools to a preset performance mapping rule is specifically as follows: If the proportion of AI-added / deleted lines in any file to the total number of changed lines exceeds a preset first threshold, the file will be automatically marked as "high AI dependency" and included in the mandatory manual review queue, triggering the code review pipeline and generating a review task sheet with the file path and AI contribution label. If the code contribution percentage of any AI coding tool is lower than the preset second threshold, the tool will be automatically removed from the current list of recommended tools, and the tool call permission configuration in the continuous integration environment will be adjusted. If the overall proportion of AI-generated code exceeds the preset third threshold, the strictness level of the static code analysis rules will be automatically increased, and incremental compilation and building will be re-executed to output a joint report containing the distribution of AI contributions and quality gate results.
[0029] Example 4: This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements an AI-generated code judgment method based on submission fact anchoring as described in any one of Embodiment 1.
[0030] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent the existence of A alone, A and B simultaneously, or B alone. A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of singular or plural items. For example, at least one of a, b, and c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, and c can be single or multiple.
[0031] Those skilled in the art will recognize that the units and algorithm steps described in the embodiments disclosed herein can be implemented using electronic hardware, computer software, or a combination of electronic hardware and software. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0032] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0033] In the several embodiments provided in this application, any function, if implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0034] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for judging AI-generated code based on submitted fact anchoring, characterized in that, The method includes: Collect AI behavior events generated by AI coding tools and convert them into unified event objects as event evidence; Retrieve the difference data of the parent commit corresponding to the current commit of the target code, as a Git commit fact; Based on event evidence and Git commit facts, a one-to-one verification is performed to determine whether the code corresponding to the current commit fact was generated by the AI coding tool. When the verification is successful, an AI code contribution proof object is generated. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. Generate AI code contribution statistics reports based on AI code contribution proof objects.
2. The AI-generated code judgment method based on submission fact anchoring according to claim 1, characterized in that, The AI encoding tools include a first type of tool and a second type of tool, specifically: The first type of tool listens for code editing completion events and extracts the code text before and after the code editing changes to construct AI behavior events; The second type of tool captures difference snapshots of the workspace before and after the call; it extracts the text lines added or deleted during the current tool call by comparing the count differences of the difference snapshots, in order to construct AI behavioral events.
3. The AI-generated code judgment method based on submission fact anchoring according to claim 1, characterized in that, The difference data specifically refers to the uniformly formatted difference text, digitized statistics of added and deleted lines, and the set of changed files obtained when the submit command is executed; Preprocess the differential data, including excluding rows with pure blank lines and low signal signs; The preprocessed difference data is used as the Git commit fact.
4. The AI-generated code judgment method based on submission fact anchoring according to claim 1, characterized in that, Before performing consumer-based matching, path normalization and text normalization are performed on AI behavioral events and differential data, including: The path normalization includes at least standardizing path separators, converting absolute paths to repository relative paths, normalizing Windows drive letter case, fixing path character encoding anomalies, and handling path prefix differences in single-repository multi-project code repository scenarios. The text normalization specifically includes at least removing whitespace characters from code lines to obtain a normalized text key, and filtering out pure blank lines or lines with low signal symbols.
5. The AI-generated code judgment method based on submission fact anchoring according to claim 4, characterized in that, The reconciliation steps include reconciliation of the normal event queue, reconciliation of the fragment event queue, and reconciliation of the global fallback queue, wherein: The ordinary event queue reversal specifically involves establishing an ordinary event queue for each changed file or each normalized file path, including a new line queue and a deleted line queue; matching the new lines in the difference data with the new lines in the AI behavior events, and matching the deleted lines in the difference data with the deleted lines in the AI behavior events; if the match is successful, an AI code contribution proof object is generated, and the corresponding event line is removed from the corresponding queue. The specific process of the fragment event queue verification involves text normalization of code fragments generated based on AI coding tool completion or fragment generation events to obtain normalized code fragments. The length of the code fragment is the number of characters in the string of the normalized code fragment. When the number of characters is not less than a preset threshold, the normalized code fragment is added to the fragment event queue. The process involves traversing the difference rows in the difference data, performing text normalization on the difference rows, and determining whether the normalized difference rows contain the normalized code fragment. If they do, the matching is considered successful, a corresponding AI code contribution proof object is generated, and the current code fragment is removed from the fragment event queue. Specifically, the global fallback queue verification process involves searching for an event that matches the normalized text key in the AI behavior event queue if the difference line in the current difference data is not found in either the normal event queue or the fragment event queue of the corresponding file, and the normalized character length of the difference line in the current difference data reaches the minimum valid length. If a match is found, an AI code contribution proof object is generated, and the matched global event line or event fragment is removed from the global AI behavior event queue.
6. The AI-generated code judgment method based on submission fact anchoring according to claim 1, characterized in that, The AI code contribution proof object includes the source event identifier, file path, source identifier, AI contribution score, line number, normalized code line content hash, and change direction.
7. The AI-generated code judgment method based on submission fact anchoring according to claim 1, characterized in that, The AI code contribution statistics report includes file-level metrics and metrics by source, wherein: The file-level metrics describe the total number of lines added or deleted, AI-generated lines added or deleted, and deletion attribution for each file. The statistics by source are calculated at least based on the source of the AI editing tool, showing the proportion of AI-added or deleted lines in all modified code text.
8. An AI-generated code judgment system based on submitted fact anchoring, characterized in that, The system includes: The behavior acquisition module collects AI behavior events generated by the AI coding tool and converts them into unified event objects as event evidence. The commit fact anchoring module retrieves the difference data of the parent commit corresponding to the current commit of the target code, and uses it as the Git commit fact. The reconciliation module performs one-to-one reconciliation based on event evidence and Git commit facts, and determines whether the code corresponding to the current commit fact was generated by the AI coding tool. When the reconciliation is successful, an AI code contribution proof object is generated. The AI code contribution proof object is used to record the correspondence between the difference data and the AI behavior event. The report generation module generates AI code contribution statistics reports based on AI code contribution proof objects.
9. A performance management method based on AI code contribution statistics reports, using AI code contribution statistics reports generated by the methods described in claims 1-7, characterized in that, The method includes: Obtain the AI code contribution statistics report, and extract the number of AI lines added or deleted and the code contribution ratio of AI coding tools from the AI code contribution statistics report; Map the number of lines added or deleted by AI and the code contribution ratio of AI coding tools to preset performance mapping rules to obtain corresponding performance management operations; Perform the performance management operations on the target code repository.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Automatic code detection method based on git
CN117130908A