@coderot-ai/cli 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,95 @@
1
+ Copyright 2026 coderot
2
+
3
+ Elastic License 2.0
4
+
5
+ URL: https://www.elastic.co/licensing/elastic-license
6
+
7
+ ## Acceptance
8
+
9
+ By using the software, you agree to all of the terms and conditions below.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
14
+ non-sublicensable, non-transferable license to use, copy, distribute, make
15
+ available, and prepare derivative works of the software, in each case subject to
16
+ the limitations and conditions below.
17
+
18
+ ## Limitations
19
+
20
+ You may not provide the software to third parties as a hosted or managed
21
+ service, where the service provides users with access to any substantial set of
22
+ the features or functionality of the software.
23
+
24
+ You may not move, change, disable, or circumvent the license key functionality
25
+ in the software, and you may not remove or obscure any functionality in the
26
+ software that is protected by the license key.
27
+
28
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
29
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
30
+ to applicable law.
31
+
32
+ ## Patents
33
+
34
+ The licensor grants you a license, under any patent claims the licensor can
35
+ license, or becomes able to license, to make, have made, use, sell, offer for
36
+ sale, import and have imported the software, in each case subject to the
37
+ limitations and conditions in this license. This license does not cover any
38
+ patent claims that you cause to be infringed by modifications or additions to
39
+ the software. If you or your company make any written claim that the software
40
+ infringes or contributes to infringement of any patent, your patent license for
41
+ the software granted under these terms ends immediately. If your company makes
42
+ such a claim, your patent license ends immediately for work on behalf of your
43
+ company.
44
+
45
+ ## Notices
46
+
47
+ You must ensure that anyone who gets a copy of any part of the software from you
48
+ also gets a copy of these terms.
49
+
50
+ If you modify the software, you must include in any modified copies of the
51
+ software prominent notices stating that you have modified the software.
52
+
53
+ ## No Other Rights
54
+
55
+ These terms do not imply any licenses other than those expressly granted in
56
+ these terms.
57
+
58
+ ## Termination
59
+
60
+ If you use the software in violation of these terms, such use is not licensed,
61
+ and your licenses will automatically terminate. If the licensor provides you
62
+ with a notice of your violation, and you cease all violation of this license no
63
+ later than 30 days after you receive that notice, your licenses will be
64
+ reinstated retroactively. However, if you violate these terms after such
65
+ reinstatement, any additional violation of these terms will cause your licenses
66
+ to terminate automatically and permanently.
67
+
68
+ ## No Liability
69
+
70
+ *As far as the law allows, the software comes as is, without any warranty or
71
+ condition, and the licensor will not be liable to you for any damages arising
72
+ out of these terms or the use or nature of the software, under any kind of
73
+ legal claim.*
74
+
75
+ ## Definitions
76
+
77
+ The **licensor** is the entity offering these terms, and the **software** is the
78
+ software the licensor makes available under these terms, including any portion
79
+ of it.
80
+
81
+ **you** refers to the individual or entity agreeing to these terms.
82
+
83
+ **your company** is any legal entity, sole proprietorship, or other kind of
84
+ organization that you work for, plus all organizations that have control over,
85
+ are under the control of, or are under common control with that
86
+ organization. **control** means ownership of substantially all the assets of an
87
+ entity, or the power to direct its management and policies by vote, contract, or
88
+ otherwise. Control can be direct or indirect.
89
+
90
+ **your licenses** are all the licenses granted to you for the software under
91
+ these terms.
92
+
93
+ **use** means anything you do with the software requiring one of your licenses.
94
+
95
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @coderot-ai/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The [coderot](https://coderot.ai) CLI: code health and AI attribution from a repo's git history. Run it at the root of a full clone
4
+ (`fetch-depth: 0` in GitHub Actions). C# repos also need the .NET runtime 8 or newer.
5
+
6
+ ```sh
7
+ npx @coderot-ai/cli analyze # writes the report to ./report, sends nothing
8
+ npx @coderot-ai/cli ci # analyze, then upload to coderot
9
+ ```
10
+
11
+ In GitHub Actions, use the `coderot-ai/action@v1` Action instead: it runs `ci` with no secret to configure.
12
+
13
+ ## What `ci` sends
14
+
15
+ Per file: its path, its functions' names, line ranges and metrics (complexity, lines, parameters, nesting), and where its comments and
16
+ duplicated code are, as line numbers. Per commit: its SHA, date, lines added and deleted per path, which AI agents it has signals of,
17
+ a SHA-256 of each human author's email, and its PR's number, size and review counts. Never source code, comment text, commit
18
+ messages, names or email addresses. PR titles only with `--titles`.
19
+
20
+ ## License
21
+
22
+ [Elastic License 2.0](LICENSE). `dist/roslyn` holds MIT-licensed .NET components: [THIRD-PARTY-NOTICES.txt](THIRD-PARTY-NOTICES.txt).
@@ -0,0 +1,28 @@
1
+ dist/roslyn holds these components, each under the MIT License below:
2
+
3
+ - Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.CSharp (Roslyn, https://github.com/dotnet/roslyn)
4
+ - System.Collections.Immutable and System.Reflection.Metadata (.NET, https://github.com/dotnet/runtime)
5
+
6
+ The MIT License (MIT)
7
+
8
+ Copyright (c) .NET Foundation and Contributors
9
+
10
+ All rights reserved.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import{existsSync as Fn,mkdirSync as An,readFileSync as kn,rmSync as Mn}from"node:fs";import{join as D}from"node:path";import{parseArgs as Tn}from"node:util";import{z as t}from"zod";var _=1,pe=t.strictObject({name:t.string(),kind:t.string(),start:t.int().positive(),end:t.int().positive(),depth:t.int().nonnegative(),lambda:t.boolean(),cyclomatic:t.int().positive(),cognitive:t.int().nonnegative(),sloc:t.int().nonnegative(),parameters:t.int().nonnegative(),nesting:t.int().nonnegative()}),me=t.strictObject({kind:t.enum(["line","block","doc"]),start:t.int().positive(),end:t.int().positive()}),ue=t.strictObject({parsed:t.boolean(),functions:t.array(pe),unmeasuredFunctions:t.int().nonnegative(),errorLines:t.array(t.int().positive()),inactiveLines:t.int().nonnegative(),sloc:t.int().nonnegative(),comments:t.array(me)}),fe=t.strictObject({path:t.string(),start:t.int().positive(),end:t.int().positive()}),de=t.strictObject({locations:t.array(fe).min(2)}),ge=t.strictObject({commit:t.string(),committedAt:t.iso.datetime(),files:t.array(t.strictObject({path:t.string(),blob:t.string(),test:t.boolean()})),skipped:t.strictObject({generated:t.int().nonnegative(),vendored:t.int().nonnegative(),excluded:t.int().nonnegative()}),markup:t.record(t.string(),t.strictObject({files:t.int().nonnegative(),lines:t.int().nonnegative()})),agentFiles:t.array(t.string()),clones:t.array(de).optional()}),Ct=t.strictObject({reviewers:t.int().nonnegative(),approved:t.boolean(),inline:t.int().nonnegative(),conversation:t.int().nonnegative(),botInline:t.int().nonnegative()}),he=t.strictObject({commit:t.string(),committedAt:t.iso.datetime(),files:t.array(t.strictObject({path:t.string(),added:t.int().nonnegative(),deleted:t.int().nonnegative(),ai:t.record(t.string(),t.int().positive()).optional()})),ai:t.array(t.strictObject({source:t.enum(["git-ai","trailer","bot","branch"]),agent:t.string()})),authors:t.array(t.string()),agentFiles:t.boolean(),lineLevel:t.boolean(),title:t.string().optional(),fix:t.boolean(),reverts:t.string().optional(),fixed:t.array(t.string()).optional(),pr:t.strictObject({number:t.int().positive(),files:t.int().nonnegative(),added:t.int().nonnegative(),deleted:t.int().nonnegative(),commits:t.int().nonnegative().optional(),review:Ct.optional()}).optional()}),Nn=t.strictObject({schemaVersion:t.literal(_),...ge.shape,blobs:t.record(t.string(),ue)}),Et=t.strictObject({schemaVersion:t.literal(_),commits:t.array(he)}),rt=e=>e.reduce((n,s)=>n+s,0);var st=t.strictObject({commit:t.string(),committedAt:t.iso.datetime(),title:t.string(),pr:t.int().positive().optional(),size:t.int().nonnegative().optional(),review:Ct.optional(),agents:t.array(t.string()),fix:t.boolean(),added:t.int().nonnegative(),deleted:t.int().nonnegative()}),it=t.strictObject({count:t.int().nonnegative(),medianSize:t.int().nonnegative(),large:t.int().nonnegative(),fixes:t.int().nonnegative(),settled:t.int().nonnegative(),fixedLater:t.int().nonnegative(),reviewKnown:t.int().nonnegative(),noHumanReview:t.int().nonnegative(),approvedNoComment:t.int().nonnegative(),growth:t.int(),growthLines:t.int().nonnegative(),growthTrimmed:t.int(),growthLinesTrimmed:t.int().nonnegative()}),$t=t.record(t.enum(["ai","other"]),it),Ln=t.strictObject({schemaVersion:t.literal(_),repo:t.string(),snapshots:t.array(t.strictObject({commit:t.string(),committedAt:t.iso.datetime(),sloc:t.int().nonnegative(),testSloc:t.int().nonnegative(),cognitive:t.int().nonnegative(),duplicated:t.int().nonnegative().optional()})),months:t.array(t.strictObject({month:t.string(),commits:t.int().nonnegative(),aiCommits:t.int().nonnegative(),added:t.int().nonnegative(),aiAdded:t.int().nonnegative(),agents:t.record(t.string(),t.int().positive()),attributed:t.int().nonnegative(),prs:$t})),jumps:t.array(t.strictObject({metric:t.enum(["complexity","duplication"]),from:t.int().nonnegative(),to:t.int().nonnegative(),files:t.array(t.strictObject({path:t.string(),delta:t.int()})),commits:t.array(st)})),folders:t.array(t.strictObject({path:t.string(),sloc:t.array(t.int().nonnegative()),cognitive:t.array(t.int().nonnegative()),commits:t.int().nonnegative(),aiCommits:t.int().nonnegative()})),hotspots:t.array(t.strictObject({path:t.string(),commits:t.int().positive(),aiCommits:t.int().nonnegative(),cognitive:t.int().nonnegative()})),prs:$t,prsBy:t.record(t.enum(["large","small","fixed","unfixed","recent","human","unknown"]),it),prsByAgent:t.record(t.string(),it),biggest:t.array(st),worstSince:t.iso.datetime(),worst:t.array(t.strictObject({path:t.string(),before:t.int().nonnegative().optional(),after:t.int().nonnegative(),from:t.strictObject({path:t.string(),how:t.enum(["renamed","copied","moved"])}).optional(),commits:t.array(st)})),lookSince:t.int().nonnegative(),look:t.array(t.strictObject({folder:t.string(),rise:t.int().positive(),commits:t.int().nonnegative(),aiCommits:t.int().nonnegative(),file:t.strictObject({path:t.string(),before:t.int().nonnegative().optional(),after:t.int().nonnegative()}).optional()}))});import{readFile as Xe}from"node:fs/promises";import{join as Ze,posix as tn}from"node:path";import{parse as en}from"yaml";import{z as N}from"zod";import{execFile as ye,execFileSync as be,spawn as we}from"node:child_process";import{mkdirSync as ve,mkdtempSync as xe,readFileSync as Se,rmSync as $e,writeFileSync as Ce}from"node:fs";import{tmpdir as Ee}from"node:os";import{dirname as Oe,extname as J,join as X}from"node:path";import{createInterface as je}from"node:readline";import{fileURLToPath as Pt}from"node:url";import{promisify as Pe}from"node:util";import{parseSync as Fe,visitorKeys as Ft}from"oxc-parser";var At=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]),kt=e=>J(e)===".cs"||At.has(J(e)),Ae=/(^|\/)(node_modules|bower_components|vendor|third[-_]?party|wwwroot\/lib(_npm)?)\//i,ke=/(^|\/)(obj|dist)\/|\.(designer|generated|g|g\.i)\.cs$|(^|\/)TemporaryGeneratedFile_[^/]*$|\.min\.[cm]?js$/i,Me=/^\uFEFF?(\s|\/\/.*|\/\*[\s\S]*?\*\/|#.*)*/,Te=/<auto-?generated|@generated|(file|content) (is|was) (auto-?|automatically )?generated|^\W*generated (by|from)|^(?=.*do not (edit|modify))(?=.*(generated|copied|from )).*/im,Re=/^\/\/[#@] sourceMappingURL=|^\/\*! For license information please see \S+ \*\//m,Ne=new Set([".razor",".cshtml",".vue",".svelte",".astro"]),Le=/(^|\/)((\w+[-_])?(tests?|__tests__|e2e)|(tests?|e2e)[-_]\w+)\/|\.(test|spec)[.-][^/]*$|Tests?(\.cs$|\/)/;function Z(e,n,s={}){return s.vendored??Ae.test(e)?"vendored":s.generated??ke.test(e)?"generated":Ne.has(J(e))?"markup":kt(e)?s.generated===void 0&&(Te.test(n.match(Me)[0])||At.has(J(e))&&Re.test(n))?"generated":Le.test(e)?"test":"code":"other"}async function Mt(e,n,s={}){if(!kt(e))throw new Error(`Unsupported file type: ${e}`);let o=J(e)===".cs"?await Ge(n,s.csharpSymbols??[]):Je(e,n),l=o.functions.filter(r=>!o.errorLines.some(p=>r.start<=p&&p<=r.end));return{...o,functions:l,unmeasuredFunctions:o.functions.length-l.length}}function Tt(){G?.stdin.end(),G=void 0}var Ie=Pt(import.meta.resolve("jscpd/run-jscpd.js"));async function Rt(e){if(!e.length)return[];let n=xe(X(Ee(),"coderot-dup-"));try{for(let c of e)ve(Oe(X(n,"src",c.path)),{recursive:!0}),Ce(X(n,"src",c.path),c.source);await Pe(ye)(process.execPath,[Ie,"src","-f","csharp,typescript,tsx,javascript,jsx","--cross-formats","typescript,tsx;javascript,jsx","-k","50","-l","5","--mode","weak","--ignore-pattern","using\\s+(static\\s+)?[\\w.]+(\\s*=\\s*[\\w.<>]+)?;,\\[assembly:[^\\]]*\\]","--no-gitignore","-r","json","-o","out","-s"],{cwd:n});let{duplicates:s}=JSON.parse(Se(X(n,"out","jscpd-report.json"),"utf8")),o=c=>({path:c.name.replaceAll("\\","/"),start:c.start,end:c.end}),l=c=>`${c.path}:${c.start}-${c.end}`,r=new Map;for(let c of s){let[a,h]=[o(c.firstFile),o(c.secondFile)],[m,u]=[r.get(l(a))??[a],r.get(l(h))??[h]];if(m===u)continue;let b=[...m,...u];for(let g of b)r.set(l(g),b)}let p=(c,a)=>c.path<a.path?-1:c.path>a.path?1:c.start-a.start;return[...new Set(r.values())].map(c=>({locations:c.sort(p)})).sort((c,a)=>p(c.locations[0],a.locations[0]))}finally{$e(n,{recursive:!0,force:!0})}}var _e=Pt(new URL("./roslyn/bin/Release/net8.0/Coderot.Roslyn.dll",import.meta.url)),K=new Map,G,De=0,at;function ze(){if(at??=[...He().matchAll(/^Microsoft\.NETCore\.App (\S+)/gm)].map(s=>s[1]),!at.some(s=>Number(s.split(".")[0])>=8))throw new Error(`C# files need the .NET runtime 8 or newer (found: ${at.join(", ")||"none"}). In GitHub Actions: actions/setup-dotnet`);let e=s=>{G===n&&(G=void 0);for(let o of K.values())o.reject(s);K.clear()},n=we("dotnet",[_e],{stdio:["pipe","pipe","inherit"]});return n.on("error",e),n.on("exit",s=>e(new Error(`C# sidecar exited with code ${s}`))),je({input:n.stdout}).on("line",s=>{let{id:o,...l}=JSON.parse(s);K.get(o)?.resolve(l),K.delete(o)}),n}function He(){try{return be("dotnet",["--list-runtimes"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]})}catch{return""}}function Ge(e,n){G??=ze();let s=De++;return new Promise((o,l)=>{K.set(s,{resolve:o,reject:l}),G.stdin.write(JSON.stringify({id:s,source:e,symbols:n})+`
3
+ `)})}var ct=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]),Ot=new Set(["MethodDefinition","TSAbstractMethodDefinition","Property","PropertyDefinition"]),lt=new Set(["IfStatement","ConditionalExpression","SwitchStatement","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","CatchClause"]),Be=new Set(["IfStatement","ConditionalExpression","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","CatchClause","LogicalExpression"]),We=new Set(["IfStatement","SwitchStatement","TryStatement","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","WithStatement"]),qe=e=>Be.has(e.type)||e.type==="SwitchCase"&&e.test||e.type==="AssignmentExpression"&&["&&=","||=","??="].includes(e.operator),Ue=(e,n,s)=>e.type==="IfStatement"?n==="consequent"||n==="alternate"&&s?.type!=="IfStatement":e.type==="ConditionalExpression"?n!=="test":e.type==="SwitchStatement"?n==="cases":lt.has(e.type)&&n==="body",jt=e=>e.type==="LogicalExpression"&&e.operator!=="??",Ke=(e,n)=>n?e.type==="MemberExpression"&&e.object.type==="ThisExpression"&&!e.computed?(e.property.type==="PrivateIdentifier"?"#":"")+e.property.name:void 0:e.type==="Identifier"?e.name:void 0;function Nt(e){return lt.has(e.type)?!0:ct.has(e.type)?!1:(Ft[e.type]??[]).some(n=>[e[n]].flat().some(s=>s&&Nt(s)))}function Je(e,n){let{program:s,errors:o,comments:l}=Fe(e,n,/\.[mc]?js$/.test(e)?{lang:"jsx"}:{}),r=[0];for(let i=0;i<n.length;i++)n[i]===`
4
+ `&&r.push(i+1);let p=i=>{let d=0,y=r.length-1;for(;d<y;){let $=d+y+1>>1;r[$]<=i?d=$:y=$-1}return d+1},c=i=>n.slice(i.start,i.end),a=[],h=0;for(let i of l)a.push(n.slice(h,i.start),n.slice(i.start,i.end).replace(/[^\n]/g,"")),h=i.end;let m=[0];for(let i of[...a,n.slice(h)].join("").split(`
5
+ `))m.push(m.at(-1)+(/\S/.test(i)?1:0));let u=[],b=new Set,g=new Set,f=i=>i.type==="ParenthesizedExpression"?f(i.expression):jt(i)?(b.add(i),[...f(i.left),i.operator,...f(i.right)]):[],v=(i,d,y,$,F,w,C=0,L=0)=>{(i.type==="ClassDeclaration"||i.type==="ClassExpression")&&($=i.id?.name??"<anonymous>"),(i.type==="StaticBlock"||(d.type==="PropertyDefinition"||d.type==="AccessorProperty")&&d.value===i)&&([F,w]=[!1,void 0]);let T=!1;if(ct.has(i.type)&&i.body){let j=Ot.has(d.type)?d:null,A=j?.kind==="get"||j?.kind==="set",R=i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression"&&!A&&!j?.method&&j?.type!=="MethodDefinition";if(!(R&&F)){let x=j?.kind==="constructor"?$:A?`${c(j.key)}.${j.kind}`:i.id?.name??(j&&c(j.key))??(d.type==="VariableDeclarator"?d.id.name??c(d.id):d.type==="AssignmentExpression"?c(d.left):"<anonymous>"),O=j??i,[E,k]=[p(O.start),p(O.end)],H=i.params.filter(U=>U.type!=="Identifier"||U.name!=="this").length;w={name:x,kind:j?.type??i.type,start:E,end:k,depth:y,lambda:R,cyclomatic:1,cognitive:0,sloc:m[k]-m[E-1],parameters:H,nesting:0},u.push(w),T=!0,F=Nt(i.body)}}let q=i.type==="IfStatement"&&d.type==="IfStatement"&&d.alternate===i,z=T?0:L+(We.has(i.type)&&!q?1:0);w&&(w.nesting=Math.max(w.nesting,z),qe(i)&&w.cyclomatic++,i.type==="IfStatement"?w.cognitive+=(q?1:1+C)+(i.alternate&&i.alternate.type!=="IfStatement"?1:0):lt.has(i.type)?w.cognitive+=1+C:(i.type==="BreakStatement"||i.type==="ContinueStatement")&&i.label?w.cognitive++:jt(i)&&!b.has(i)?w.cognitive+=f(i).filter((j,A,R)=>j!==R[A-1]).length:i.type==="CallExpression"&&Ke(i.callee,Ot.has(w.kind))===w.name&&!g.has(w)&&(g.add(w),w.cognitive++));let Y=T?0:ct.has(i.type)?C+1:C;for(let j of Ft[i.type]??[]){let A=i[j],R=Y+(Ue(i,j,A)?1:0);if(Array.isArray(A))for(let x of A)x&&v(x,i,y+(T?1:0),$,F,w,R,z);else A&&v(A,i,y+(T?1:0),$,F,w,R,z)}};v(s,s,0,"",!1);let S=!(o.length&&!s.body.length);return{parsed:S,functions:u,errorLines:o.map(i=>p(i.labels[0]?.start??0)),inactiveLines:0,sloc:S?m.at(-1):0,comments:S?l.map(i=>({kind:i.type==="Line"?"line":/^\*[^*/]/.test(i.value)?"doc":"block",start:p(i.start),end:p(i.end)})):[]}}import{execFile as Ve,spawn as Qe}from"node:child_process";import{promisify as Ye}from"node:util";var P=(e,...n)=>pt(e,"",...n);async function pt(e,n,...s){let o=Ye(Ve)("git",s,{cwd:e,encoding:"utf8",maxBuffer:1073741824});return o.child.stdin.on("error",()=>{}).end(n),(await o).stdout}function Lt(e){let n=Qe("git",["cat-file","--batch"],{cwd:e,stdio:["pipe","pipe","inherit"]}),s=[],o=p=>s.splice(0).forEach(c=>c.reject(p));n.on("error",o),n.on("exit",p=>o(new Error(`git cat-file exited with code ${p}`)));let l=new Promise(p=>n.on("close",p)),r=Buffer.alloc(0);return n.stdout.on("data",p=>{r=Buffer.concat([r,p]);for(let c;(c=r.indexOf(10))>=0;){let a=r.subarray(0,c).toString();if(a.endsWith(" missing")){s.shift()?.reject(new Error(`git object ${a}`)),r=r.subarray(c+1);continue}let h=Number(a.split(" ")[2]);if(r.length<c+h+2)return;s.shift()?.resolve(r.subarray(c+1,c+1+h)),r=r.subarray(c+h+2)}}),{read:p=>new Promise((c,a)=>{s.push({resolve:c,reject:a}),n.stdin.write(p+`
6
+ `)}),close:()=>(n.stdin.end(),l)}}var V=N.array(N.string()).default([]),tt=N.strictObject({include:V,exclude:V,tests:V,ai:N.record(N.string(),N.strictObject({emails:V,branches:V})).default({}),since:N.string().optional(),interval:N.string().optional()});async function It(e){let n=Ze((await P(e,"rev-parse","--show-toplevel")).trim(),".coderot.yml"),s=await Xe(n,"utf8").catch(l=>l.code==="ENOENT"?"":Promise.reject(l)),o=tt.safeParse(en(s)??{});if(!o.success)throw new Error(`${n}:
7
+ ${N.prettifyError(o.error)}`);return o.data}async function mt(e,n,s){let o=(await pt(e,s.join("\0"),"check-attr","--stdin","-z",`--source=${n}`,"linguist-generated","linguist-vendored")).split("\0"),l=new Map;for(let r=0;r+2<o.length;r+=3){if(o[r+2]==="unspecified")continue;let p=l.get(o[r])??{};p[o[r+1]==="linguist-generated"?"generated":"vendored"]=!["unset","false"].includes(o[r+2]),l.set(o[r],p)}return l}function et(e,n,s,o){let l=Z(n,s,o),r=p=>p.some(c=>tn.matchesGlob(n,c));return l==="generated"||l==="vendored"?l:r(e.exclude)||e.include.length&&!r(e.include)?"excluded":l==="code"&&r(e.tests)?"test":l}var ut="author { __typename login }",Dt=`reviews(first: 50, after: $after) { pageInfo { hasNextPage endCursor } nodes { ${ut} state comments { totalCount } } }`,nn=`commits { totalCount } ${ut} ${Dt} comments(first: 100) { nodes { ${ut} } }`,_t=e=>!e||e.__typename==="Bot"||/(bot|\[bot\])$/i.test(e.login);function zt(e,n){let s=new Map(n.flatMap(o=>o.pr?.review?[[o.pr.number,o.pr]]:[]));for(let o of e){let l=o.pr&&s.get(o.pr.number);l&&Object.assign(o.pr,{review:l.review,commits:o.pr.commits??l.commits})}}async function Ht(e,n,s,o="https://api.github.com/graphql"){let[l,r]=n.split("/"),p=async(u,b=null,g=0)=>{let f=await fetch(o,{method:"POST",headers:{authorization:`bearer ${s}`,"content-type":"application/json"},body:JSON.stringify({query:`query($owner: String!, $name: String!, $after: String) { repository(owner: $owner, name: $name) { ${u} } }`,variables:{owner:l,name:r,after:b}})});if((f.status===403||f.status===429)&&g<4&&/rate limit/i.test(await f.text()))return await new Promise(i=>setTimeout(i,Number(f.headers.get("retry-after")??60*2**g)*1e3)),p(u,b,g+1);if(!f.ok)throw new Error(`HTTP ${f.status}`);let v=await f.json(),S=v.errors?.find(i=>i.type!=="NOT_FOUND")?.message??(v.data?.repository?void 0:`no repository ${n}`);if(S)throw new Error(S);return v.data.repository},c=async u=>{let b;try{b=await p(u.map((g,f)=>`p${f}: pullRequest(number: ${g.pr.number}) { ${nn} }`).join(" "))}catch(g){if(u.length===1||!/^HTTP 50[24]$/.test(g.message))throw g;let f=Math.ceil(u.length/2);return await c(u.slice(0,f)),c(u.slice(f))}for(let[g,f]of u.entries()){let v=b[`p${g}`];if(!v)continue;let S=v.reviews.nodes;for(let y=v.reviews.pageInfo;y.hasNextPage;){let $=(await p(`p0: pullRequest(number: ${f.pr.number}) { ${Dt} }`,y.endCursor)).p0.reviews;S.push(...$.nodes),y=$.pageInfo}let i=y=>!_t(y)&&y.login!==v.author?.login,d=S.filter(y=>i(y.author));f.pr.commits??=v.commits.totalCount,f.pr.review={reviewers:new Set(d.map(y=>y.author.login)).size,approved:d.some(y=>y.state==="APPROVED"),inline:rt(d.map(y=>y.comments.totalCount)),conversation:v.comments.nodes.filter(y=>i(y.author)).length,botInline:rt(S.filter(y=>_t(y.author)).map(y=>y.comments.totalCount))}}},a=e.filter(u=>u.pr&&!u.pr.review),h=[];for(let u=0;u<a.length;u+=50)h.push(a.slice(u,u+50));let m;await Promise.all(Array.from({length:4},async()=>{for(let u;!m&&(u=h.shift());)await c(u).catch(b=>{m??=b.message})})),m&&console.warn(`Commits per squash merge and review attention left out for ${a.filter(u=>!u.pr.review).length} of ${a.length} PRs (${m}). In GitHub Actions, give the workflow \`pull-requests: read\``)}import{createHash as hn}from"node:crypto";import{closeSync as yn,openSync as bn,writeSync as B}from"node:fs";import{availableParallelism as wn}from"node:os";import{extname as wt}from"node:path";import{createHash as sn}from"node:crypto";var ft={"claude-code":{emails:["noreply@anthropic.com","claude[bot]@users.noreply.github.com"],branches:["claude/"],tools:["claude","claude-web"]},"copilot-cli":{emails:["223556219+copilot@users.noreply.github.com"],branches:[],tools:["github-copilot-cli"]},"copilot-coding-agent":{emails:["198982749+copilot@users.noreply.github.com"],branches:["copilot/"],tools:[]},"copilot-review":{emails:["175728472+copilot@users.noreply.github.com"],branches:[],tools:[]},copilot:{emails:["copilot@users.noreply.github.com","copilot@github.com"],branches:[],tools:["github-copilot","copilot"]},cursor:{emails:["cursoragent@cursor.com","cursor[bot]@users.noreply.github.com"],branches:["cursor/"],tools:["cursor","cursor-agent"]},codex:{emails:["noreply@openai.com","codex@openai.com","chatgpt-codex-connector[bot]@users.noreply.github.com"],branches:["codex/"],tools:["codex","codex-cloud"]},gemini:{emails:["noreply@google.com","gemini-code-assist[bot]@users.noreply.github.com"],branches:[],tools:["gemini"]},aider:{emails:["aider@aider.chat","noreply@aider.chat"],branches:[],tools:[]},openhands:{emails:["openhands@all-hands.dev"],branches:[],tools:[]},devin:{emails:["devin-ai-integration[bot]@users.noreply.github.com"],branches:["devin/"],tools:["devin"]},charlie:{emails:["charlie@charlielabs.ai","charliecreates[bot]@users.noreply.github.com"],branches:[],tools:[]},grok:{emails:["noreply@x.ai"],branches:[],tools:[]},"muse-spark":{emails:["noreply@meta.com"],branches:[],tools:[]},jules:{emails:["google-labs-jules[bot]@users.noreply.github.com"],branches:[],tools:[]},"amazon-q":{emails:["amazon-q-developer[bot]@users.noreply.github.com"],branches:[],tools:[]},"factory-droid":{emails:["factory-droid[bot]@users.noreply.github.com","droid@factory.ai"],branches:[],tools:["droid"]}};var dt=(e,n)=>e.get(n.toLowerCase())??e.get(n.toLowerCase().replace(/^\d+\+/,"")),rn=(e,n)=>e.toLowerCase()==="copilot@github.com"&&n>=Date.UTC(2026,3,15)/1e3&&n<Date.UTC(2026,4,20)/1e3,an=[["AGENTS.md",/(^|\/)AGENTS?\.md$/],["Claude Code",/(^|\/)CLAUDE(\.local)?\.md$|^\.claude\//],["GitHub Copilot",/^\.github\/(copilot-instructions\.md$|instructions\/|prompts\/|chatmodes\/|agents\/|workflows\/copilot-setup-steps\.ya?ml$)/],["Gemini",/(^|\/)GEMINI\.md$|^\.gemini\//],["Cursor",/^\.cursorrules$|^\.cursor\/rules\//],["Windsurf",/^\.windsurfrules$|^\.windsurf\/rules\//],["Cline",/^\.clinerules(\/|$)/],["Roo Code",/^\.roorules$|^\.roo\/rules/],["Kiro",/^\.kiro\/steering\//],["Junie",/^\.junie\/guidelines\.md$/],["Aider",/^\.aider\.conf\.ya?ml$/],["Continue",/^\.continue\/rules\//],["Amazon Q",/^\.amazonq\/rules\//],["Augment",/^\.augment-guidelines$|^\.augment\/rules\//],["Warp",/(^|\/)WARP\.md$/],["MCP servers",/^\.mcp\.json$/]],gt=e=>an.some(([,n])=>n.test(e)),cn=e=>sn("sha256").update(e.toLowerCase().replace(/^\d+\+/,"")).digest("hex"),ln=new Map(Object.entries(ft).flatMap(([e,n])=>n.tools.map(s=>[s,e])));function pn(e){let[n="",s=""]=e.split(/^---$/m),o;try{o=JSON.parse(s)}catch{return}if(!String(o?.schema_version).startsWith("authorship/3."))return;let l={...o.prompts,...o.sessions},r={},p="";for(let c of n.split(`
8
+ `)){let[,a="",h=""]=/^ (\S+) ([\d,-]+)$/.exec(c)??[];if(!a){c&&c[0]!==" "&&(p=c.replace(/^"(.*)"$/,"$1"));continue}let m=l[a.split("::")[0]]?.agent_id?.tool;if(typeof m!="string")continue;let u=ln.get(m)??m,b=r[p]??={};for(let g of h.split(",")){let[f=0,v=f]=g.split("-").map(Number);b[u]=(b[u]??0)+v-f+1}}return r}function mn(e){return/^(?:Merge pull request #\d+ from [^\s/]+\/(\S+)|Merged in (\S+) \(pull request|Merge branch '([^']+)'|Merge remote-tracking branch '[^/']+\/([^']+)')/.exec(e)?.slice(1).find(Boolean)}function Gt(e){let n=/^Merge pull request #(\d+) from |\(#(\d+)\)$/.exec(e);return n?Number(n.slice(1).find(Boolean)):void 0}var ht=(e,n)=>(/^Merge pull request #\d+ from /.test(e)?n.split(`
9
+ `)[0]:e).replace(/ \(#\d+\)$/,"").trim(),Bt=(e,n)=>ht(e,n).replace(/^(\[[^\]]*\]\s*)*/,""),Wt=(e,n)=>/^((bug|hot)?fix(es|ed|ing)?|bugs?|revert(s|ed)?)\b/i.test(Bt(e,n)),qt=(e,n)=>/^revert\b/i.test(Bt(e,n))?/This reverts commit ([0-9a-f]{40,64})/.exec(n)?.[1]:void 0;async function Ut(e,n,s={}){if(!n.length)return;let o=[...Object.entries(ft),...Object.entries(s)],l=new Map(o.flatMap(([a,h])=>h.emails.map(m=>[m.toLowerCase(),a])));await P(e,"rev-parse","-q","--verify","refs/notes/ai").catch(()=>"")||await P(e,"fetch","-q","origin","refs/notes/ai:refs/notes/ai").catch(()=>{});let r=(await P(e,"log","-1","--format=%P",n.at(-1).commit)).trim().split(" ")[0],p=new Map;for(let a of(await P(e,"log","--notes=ai","--format=%x01%H %P%x02%at%x02%ae%x02%ce%x02%N%x02%B","HEAD",...r?[`^${r}`]:[])).split("").slice(1)){let[h="",m="",u="",b="",g="",f=""]=a.split(""),[v="",...S]=h.trim().split(" "),i=g.trim()?pn(g):void 0;g.trim()&&!i&&console.warn(`The Git AI note on ${v} isn't authorship/3.x, so it's left out`);let d=[];for(let w of[u,b]){let C=dt(l,w);C&&d.push({source:"bot",agent:C})}let y=[...f.matchAll(/^co-authored-by:.*<([^>]+)>/gim)].map(([,w=""])=>w);for(let w of y){let C=dt(l,w);C&&!rn(w,Number(m))&&d.push({source:"trailer",agent:C})}let $=[u,...y].filter(w=>w&&!dt(l,w)&&!w.includes("[bot]")).map(cn),F=mn(f);for(let[w,C]of o)F&&C.branches.some(L=>F.startsWith(L))&&d.push({source:"branch",agent:w});p.set(v,{parents:S,signals:d,people:$,lines:i})}let c=new Set(n.map(a=>a.commit));for(let a of n.toReversed()){let{parents:h,signals:m,people:u}=p.get(a.commit),b=[...m],g=new Set(u),f=[],v=!0,S=d=>{d.lines?f.push(d.lines):d.parents.length<2&&(v=!1)};S(p.get(a.commit));let i=0;for(let d=h.slice(1),y;y=d.pop();)c.has(y)||!p.has(y)||(c.add(y),i++,b.push(...p.get(y).signals),p.get(y).people.forEach($=>g.add($)),S(p.get(y)),d.push(...p.get(y).parents));a.lineLevel=v&&f.length>0;for(let d of a.files){let y={};for(let w of f)for(let[C,L]of Object.entries(w[d.path]??{}))y[C]=(y[C]??0)+L;let $=Math.min(1,d.added/Object.values(y).reduce((w,C)=>w+C,0)),F=Object.entries(y).map(([w,C])=>[w,Math.floor(C*$)]).filter(([,w])=>w>0);F.length&&(d.ai=Object.fromEntries(F)),b.push(...F.map(([w])=>({source:"git-ai",agent:w})))}a.ai=b.filter((d,y)=>b.findIndex($=>$.source===d.source&&$.agent===d.agent)===y),a.authors=[...g].sort(),a.pr&&h.length>1&&(a.pr.commits=i)}}import{posix as un}from"node:path";var Kt=[[/^net(\d{2,3})$/,"NETFRAMEWORK","NET",["20","35","40","45","451","452","46","461","462","47","471","472","48","481"]],[/^netstandard(\d\.\d)$/,"NETSTANDARD","NETSTANDARD",["1.0","1.1","1.2","1.3","1.4","1.5","1.6","2.0","2.1"]],[/^netcoreapp(\d\.\d)$/,"NETCOREAPP","NETCOREAPP",["1.0","1.1","2.0","2.1","2.2","3.0","3.1"]]],Jt=(e,n)=>n.map(s=>`${e}${s.replace(".","_")}_OR_GREATER`);function fn(e){let n=e.trim().toLowerCase(),s=/^net(\d+)\.(\d+)(?:-([a-z]+))?/.exec(n);if(s&&Number(s[1])>=5){let o=Number(s[1]);return{rank:1e3+o,symbols:["NET",`NET${o}_${s[2]}`,"NETCOREAPP",...Array.from({length:o-4},(l,r)=>`NET${r+5}_0_OR_GREATER`),...Jt("NETCOREAPP",Kt[2][3]),...s[3]?[s[3].toUpperCase()]:[]]}}for(let[o,[l,r,p,c]]of Kt.entries()){let a=c.indexOf(l.exec(n)?.[1]??"");if(a>=0)return{rank:o*100+a,symbols:[r,p+c[a].replace(".","_"),...Jt(p,c.slice(0,a+1))]}}}function dn(e){e=e.replace(/<!--[\s\S]*?-->/g,"");let n=o=>/\bCondition\s*=\s*"([^"]*)"/.exec(o)?.[1],s=[];for(let[,o,l]of e.matchAll(/<PropertyGroup\b([^>]*?)(?<!\/)>([\s\S]*?)<\/PropertyGroup>/g))for(let[,r,p,c]of l.matchAll(/<(\w+)\b([^>]*?)>([^<]*)<\/\1>/g))s.push({name:r.toLowerCase(),value:c.trim(),conditions:[n(o),n(p)].filter(a=>a!==void 0)});return{assignments:s,imports:[...e.matchAll(/<Import\b[^>]*?\bProject\s*=\s*"([^"]*)"/g)].map(o=>o[1])}}var yt=new Map,bt=(e,n,s,o=0)=>e.replace(/\$\((\w+)\)/g,(l,r)=>n.get(r.toLowerCase())??(o<8?bt(s.get(r.toLowerCase())??"",n,s,o+1):"")),gn=e=>e.split(/\s+or\s+/i).some(n=>n.split(/\s+and\s+/i).every(s=>{let o=/^[\s(]*'([^']*)'\s*(==|!=)\s*'([^']*)'[\s)]*$/.exec(s);return!!o&&o[1].trim().toLowerCase()===o[3].trim().toLowerCase()==(o[2]==="==")}));function Vt(e,n,s){let o=new Map(n);for(let{assignments:l}of e)for(let r of l)!n.has(r.name)&&r.conditions.every(p=>gn(bt(p,o,s)))&&o.set(r.name,bt(r.value,o,s));return o}var I=e=>e.slice(0,Math.max(e.lastIndexOf("/"),0)),Qt=(e,n)=>e?`${e}/${n}`:n;function*Yt(e){for(;;){if(yield e,!e)return;e=I(e)}}var Xt=new Map([["configuration","Release"],["platform","AnyCPU"]]);async function Zt(e,n){let s=new Map;await Promise.all([...e].filter(([a])=>/\.(csproj|props|targets)$/.test(a)).map(async([a,h])=>{yt.has(h)||yt.set(h,dn(await n(h))),s.set(a,yt.get(h))}));let o=new Map,l=new Map;for(let a of e.keys())if(a.endsWith(".csproj")&&!l.has(I(a))&&l.set(I(a),a),!!a.endsWith(".props"))for(let h of s.get(a).assignments)!h.conditions.length&&!o.has(h.name)&&o.set(h.name,h.value);let r=(a,h)=>[...Yt(a)].map(m=>Qt(m,h)).find(m=>s.has(m)),p=(a,h)=>{if(!a||h.has(a)||!s.has(a))return[];h.add(a);let m=I(a);return[...s.get(a).imports.flatMap(u=>{let b=/Directory\.Build\.(props|targets)/i.exec(u);if(b&&u.includes("$("))return m?p(r(I(m),b[0]),h):[];let g=u.replace(/\$\(MSBuildThisFileDirectory\)/gi,"").replaceAll("\\","/");return g.includes("$(")?[]:p(un.normalize(Qt(m,g)),h)}),s.get(a)]},c=new Map;return a=>{let h=[...Yt(I(a))].map(d=>l.get(d)).find(d=>d),m=I(h||a);if(c.has(m))return c.get(m);let u=new Set,b=[...p(r(m,"Directory.Build.props"),u),...p(h,u),...p(r(m,"Directory.Build.targets"),u)],g=Vt(b,Xt,o),[f]=(g.get("targetframeworks")||g.get("targetframework")||"").split(";").map(d=>({t:d.trim(),f:fn(d)})).filter(d=>d.f).sort((d,y)=>y.f.rank-d.f.rank),S=((f?Vt(b,new Map([...Xt,["targetframework",f.t]]),o):g).get("defineconstants")??"").split(/[;,]/).map(d=>d.trim()).filter(d=>/^\w+$/.test(d)),i=[...new Set(["RELEASE","TRACE",...f?.f.symbols??[],...S])].sort();return c.set(m,i),i}}var vn={d:86400,w:7*86400,m:365/12*86400,y:365*86400};function W(e){let n=/^(\d+)([dwmy])$/.exec(e);if(!n)throw new Error(`Expected a duration like 90d, 1w, 12m or 1y, got "${e}"`);return Number(n[1])*vn[n[2]]}async function xn(e,n,s){let o=(await P(e,"log","--first-parent","--format=%H %ct","HEAD")).trim().split(`
10
+ `).map(p=>({commit:p.slice(0,p.indexOf(" ")),time:Number(p.slice(p.indexOf(" ")+1))})),l=o[0].time,r=new Map;for(let p=l;p>=l-n;p-=s){let c=o.find(a=>a.time<=p);c&&r.set(c.commit,c)}return[...r.values()]}var Sn=/(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|packages\.lock\.json)$/;async function $n(e,n,s,o=tt.parse({}),l=0,r=!1){let p=/^0{40}$|^0{64}$/.test(s??""),c;s&&!p&&(c=(await P(e,"rev-parse","--verify",`${s}^{commit}`).catch(()=>"")).trim(),(await P(e,"log","--first-parent","--format=%H","HEAD")).trim().split(`
11
+ `).includes(c)||(console.warn(`--since-commit ${s} isn't on HEAD's first-parent history (a force push?), so churn covers the time window`),c=void 0));let a=[],h=[],m=(await P(e,"log","--first-parent","--diff-merges=first-parent","--numstat","-z",...c?[`^${c}`]:p?[]:[`--since=${n}`],"--format=%x01%H %ct %B","HEAD")).split("\0");for(let g=0;g<m.length;g++){let f=/^\x01(\w+) (\d+) ([^\n]*?)\s*(?:\n|$)(.*)$/s.exec(m[g]);if(f){let y=Gt(f[3]);a.push({commit:f[1],committedAt:new Date(Number(f[2])*1e3).toISOString(),files:[],ai:[],lineLevel:!1,authors:[],agentFiles:!1,fix:Wt(f[3],f[4]),reverts:qt(f[3],f[4]),...r&&{title:ht(f[3],f[4])}}),y&&(a.at(-1).pr={number:y,files:0,added:0,deleted:0});continue}let[,v,S,i]=/^\n?(\d+|-)\t(\d+|-)\t(.*)$/s.exec(m[g])??[];if(!v||!S)continue;let d=i||m[g+=2];gt(d)&&(a.at(-1).agentFiles=!0),!(v==="-"||Number(v)+Number(S)===0)&&h.push({c:a.at(-1),path:d,added:Number(v),deleted:Number(S)})}let u=h.length?await mt(e,"HEAD",[...new Set(h.map(g=>g.path))]):new Map;for(let{c:g,path:f,added:v,deleted:S}of h){let i=et(o,f,"",u.get(f));(i==="code"||i==="test")&&g.files.push({path:f,added:v,deleted:S}),g.pr&&i!=="generated"&&i!=="vendored"&&i!=="excluded"&&!Sn.test(f)&&(g.pr.files++,g.pr.added+=v,g.pr.deleted+=S)}let b=a.filter(g=>g.fix&&Date.parse(g.committedAt)/1e3>=l);return await Promise.all(Array.from({length:wn()},async()=>{for(let g;g=b.pop();)g.fixed=await Cn(e,g,new Set(g.files.filter(f=>et(o,f.path,"",u.get(f.path))==="code").map(f=>f.path)))})),a}async function Cn(e,n,s){let o=new Map,l="",r="",p=!1;if(s.size){for(let m of(await P(e,"-c","core.quotePath=false","diff-tree","-p","-U0","-M","--no-prefix","--diff-merges=first-parent","--root",n.commit)).split(`
12
+ `))if(m.startsWith("diff --git "))[p,l,r]=[!0,"",""];else if(p&&m.startsWith("--- "))l=m.slice(4).replace(/\t$/,"");else if(p&&m.startsWith("+++ "))r=m.slice(4).replace(/\t$/,"");else if(m.startsWith("@@ ")){p=!1;let[,u,b="1"]=/^@@ -(\d+)(?:,(\d+))? /.exec(m)??[];l!=="/dev/null"&&s.has(r==="/dev/null"?l:r)&&b!=="0"&&(o.get(l)??o.set(l,[]).get(l)).push(`${u},+${b}`)}}let c=Date.parse(n.committedAt)/1e3-30*86400,a=new Set,h=new Set;for(let[m,u]of o)for(let b=0;b<u.length;b+=1e3){let g="";for(let f of(await P(e,"blame","--first-parent","--porcelain",`--since=${c}`,...u.slice(b,b+1e3).flatMap(v=>["-L",v]),`${n.commit}^`,"--",m)).split(`
13
+ `)){let v=/^([0-9a-f]{40,64}) \d+ \d+/.exec(f);v?a.add(g=v[1]):f==="boundary"&&h.add(g)}}return[...a].filter(m=>!h.has(m))}var En=e=>e.split(`
14
+ `).length-(e.endsWith(`
15
+ `)?1:0);function vt(e,n){let s=bn(e,"w");try{let o=(r,p)=>JSON.stringify(r,null,2).replaceAll(`
16
+ `,`
17
+ `+" ".repeat(p)),l=Object.keys(n).filter(r=>n[r]!==void 0);B(s,`{
18
+ `),l.forEach((r,p)=>{let c=n[r],a=p<l.length-1?`,
19
+ `:`
20
+ `,h=typeof c!="object"||c===null?[]:Array.isArray(c)?c.map(m=>["",m]):Object.entries(c).map(([m,u])=>[`${JSON.stringify(m)}: `,u]);if(!h.length)return B(s,` ${JSON.stringify(r)}: ${o(c,1)}${a}`);B(s,` ${JSON.stringify(r)}: ${Array.isArray(c)?"[":"{"}
21
+ `),h.forEach(([m,u],b)=>B(s,` ${m}${o(u,2)}${b<h.length-1?",":""}
22
+ `)),B(s,` ${Array.isArray(c)?"]":"}"}${a}`)}),B(s,`}
23
+ `)}finally{yn(s)}}async function te(e,n,s,o,l,r=tt.parse({}),p=!1){if(l==="")throw new Error("--since-commit requires a commit SHA");if((await P(e,"rev-parse","--is-shallow-repository")).trim()==="true")throw new Error("This is a shallow clone, so its history is missing. Fetch all of it: in GitHub Actions, set `fetch-depth: 0` on actions/checkout");let c=new Map,a=new Map,h=Lt(e),m=async u=>(await h.read(u)).toString("utf8");try{let u=await xn(e,l?0:n,s),b=-1;for(let{commit:v,time:S}of u){let i=new Map,d=[];for(let x of(await P(e,"ls-tree","-r","-z","--full-tree",v)).split("\0")){let[,O,E,k]=/^(\d+) blob (\w+)\t(.*)$/s.exec(x)??[];k&&gt(k)&&d.push(k),E&&k&&O!=="120000"&&i.set(k,E)}let y=[...i].filter(([x])=>/(^|\/)\.gitattributes$/.test(x)),$=(await Promise.all(y.map(([,x])=>m(x)))).some(x=>x.includes("linguist-"))?await mt(e,v,[...i.keys()]):new Map,F=await Zt(i,m),w=[],C=new Map,L=[],T={generated:0,vendored:0,excluded:0};for(let[x,O]of i){let E=et(r,x,"",$.get(x));if((E==="generated"||E==="vendored"||E==="excluded")&&T[E]++,E==="markup"&&(a.has(O)||a.set(O,m(O).then(En)),L.push({ext:wt(x),lines:a.get(O)})),E!=="code"&&E!=="test")continue;let k=wt(x)===".cs"?F(x):void 0,H=O+wt(x)+(k?":"+hn("sha256").update(k.join(";")).digest("hex").slice(0,8):"");!c.has(H)&&!C.has(H)&&C.set(H,m(O).then(U=>Z(x,U,$.get(x))==="generated"?void 0:Mt(x,U,{csharpSymbols:k}))),w.push({path:x,blob:H,test:E==="test",sha:O})}let q={};for(let[x,O]of C){let E=await O;E&&(q[x]=E),c.set(x,!!E)}let z=[],Y=[];for(let{sha:x,...O}of w){if(!c.get(O.blob)){T.generated++;continue}z.push(O),Y.push({path:O.path,sha:x})}let j={};for(let{ext:x,lines:O}of L){let E=j[x]??={files:0,lines:0};E.files++,E.lines+=await O}let A=Math.floor((u[0].time-S)/W("1m")),R=A===b?void 0:await Rt(await Promise.all(Y.map(async x=>({path:x.path,source:await m(x.sha)}))));b=A,await o({schemaVersion:_,commit:v,committedAt:new Date(S*1e3).toISOString(),files:z,skipped:T,markup:j,agentFiles:d,clones:R,blobs:q})}let g=u.at(-1).time,f=await $n(e,g-W("90d"),l,r,l?0:g-W("31d"),p);return await Ut(e,f,r.ai),f}finally{Tt(),await h.close()}}import{readFileSync as On}from"node:fs";import{gzipSync as jn}from"node:zlib";var ee=(e=process.env)=>e.CODEROT_API??"https://api.coderot.ai";async function Pn(e=process.env){if(e.CODEROT_TOKEN)return e.CODEROT_TOKEN;if(!e.ACTIONS_ID_TOKEN_REQUEST_URL)throw new Error("No credentials for coderot: in GitHub Actions, add `id-token: write` to the workflow's permissions; in other CIs, set CODEROT_TOKEN to the repo's upload token");let n=await fetch(`${e.ACTIONS_ID_TOKEN_REQUEST_URL}&audience=coderot`,{headers:{authorization:`bearer ${e.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`}});if(!n.ok)throw new Error(`GitHub's OIDC token: HTTP ${n.status} ${await n.text()}`);return(await n.json()).value}async function ne(e,n={},s=5e3){for(let o=1;;o++){let l=await Pn().then(r=>fetch(e,{...n,headers:{...n.headers,authorization:`Bearer ${r}`}})).catch(r=>r);if(o===3||l instanceof Response&&l.status<500){if(l instanceof Error)throw l;if(!l.ok)throw new Error(`${e}: HTTP ${l.status} ${await l.text()}`);return l}await new Promise(r=>setTimeout(r,s*o))}}async function oe(e=ee(),n){return(await(await ne(`${e}/v1/reports/head`,{},n)).json()).commit}async function se(e,n=ee(),s){for(let o of e){let l=jn(On(o)),r={"content-encoding":"gzip","content-type":"application/json"};await ne(`${n}/v1/reports`,{method:"POST",body:l,headers:r},s),console.log(`sent ${o} (${Math.round(l.length/1024)} kB)`)}}var{positionals:re,values:M}=Tn({allowPositionals:!0,options:{since:{type:"string"},interval:{type:"string"},"since-commit":{type:"string"},out:{type:"string",default:"report"},titles:{type:"boolean",default:!1}}}),ot=re[0]==="ci";if(re[0]!=="analyze"&&!ot)throw new Error(`Usage: coderot analyze [--since 12m] [--interval 1w] [--since-commit <sha>] [--out report] [--titles]
24
+ coderot ci [--since 12m] [--interval 1w] [--out report] [--titles]`);var nt=ot?await oe()??void 0:M["since-commit"];ot&&console.log(nt?`coderot has commits up to ${nt}: analyzing the ones after it`:"First run: backfilling");var xt=await It(process.cwd());Mn(D(M.out,"snapshots"),{recursive:!0,force:!0});An(D(M.out,"snapshots"),{recursive:!0});var St=[],ae=0,ce=0,le=0,Q=await te(process.cwd(),W(M.since??xt.since??"12m"),W(M.interval??xt.interval??"1w"),e=>{St.push(D(M.out,"snapshots",`${e.committedAt.slice(0,10)}-${e.commit.slice(0,7)}.json`)),vt(St.at(-1),e),ae++||(ce=e.files.length),le+=Object.keys(e.blobs).length},nt,xt,M.titles),ie=Et.safeParse(JSON.parse(Fn(D(M.out,"commits.json"))?kn(D(M.out,"commits.json"),"utf8"):"{}"));ie.success&&zt(Q,ie.data.commits);process.env.GITHUB_TOKEN&&process.env.GITHUB_REPOSITORY&&await Ht(Q,process.env.GITHUB_REPOSITORY,process.env.GITHUB_TOKEN);vt(D(M.out,"commits.json"),{schemaVersion:_,commits:Q});console.log(`${ae} snapshots, ${ce} files at HEAD, ${le} file versions analyzed, ${Q.filter(e=>e.ai.length).length} of ${Q.length} commits with AI signals${nt?" (incremental)":""} \u2192 ${M.out}`);ot&&await se([...St,D(M.out,"commits.json")]);
@@ -0,0 +1,98 @@
1
+ {
2
+ "runtimeTarget": {
3
+ "name": ".NETCoreApp,Version=v8.0",
4
+ "signature": ""
5
+ },
6
+ "compilationOptions": {},
7
+ "targets": {
8
+ ".NETCoreApp,Version=v8.0": {
9
+ "Coderot.Roslyn/1.0.0": {
10
+ "dependencies": {
11
+ "Microsoft.CodeAnalysis.CSharp": "5.9.0"
12
+ },
13
+ "runtime": {
14
+ "Coderot.Roslyn.dll": {}
15
+ }
16
+ },
17
+ "Microsoft.CodeAnalysis.Common/5.9.0": {
18
+ "dependencies": {
19
+ "System.Collections.Immutable": "10.0.1",
20
+ "System.Reflection.Metadata": "10.0.1"
21
+ },
22
+ "runtime": {
23
+ "lib/netstandard2.0/Microsoft.CodeAnalysis.dll": {
24
+ "assemblyVersion": "5.9.0.0",
25
+ "fileVersion": "5.900.26.35703"
26
+ }
27
+ }
28
+ },
29
+ "Microsoft.CodeAnalysis.CSharp/5.9.0": {
30
+ "dependencies": {
31
+ "Microsoft.CodeAnalysis.Common": "5.9.0",
32
+ "System.Collections.Immutable": "10.0.1",
33
+ "System.Reflection.Metadata": "10.0.1"
34
+ },
35
+ "runtime": {
36
+ "lib/netstandard2.0/Microsoft.CodeAnalysis.CSharp.dll": {
37
+ "assemblyVersion": "5.9.0.0",
38
+ "fileVersion": "5.900.26.35703"
39
+ }
40
+ }
41
+ },
42
+ "System.Collections.Immutable/10.0.1": {
43
+ "runtime": {
44
+ "lib/net8.0/System.Collections.Immutable.dll": {
45
+ "assemblyVersion": "10.0.0.0",
46
+ "fileVersion": "10.0.125.57005"
47
+ }
48
+ }
49
+ },
50
+ "System.Reflection.Metadata/10.0.1": {
51
+ "dependencies": {
52
+ "System.Collections.Immutable": "10.0.1"
53
+ },
54
+ "runtime": {
55
+ "lib/net8.0/System.Reflection.Metadata.dll": {
56
+ "assemblyVersion": "10.0.0.0",
57
+ "fileVersion": "10.0.125.57005"
58
+ }
59
+ }
60
+ }
61
+ }
62
+ },
63
+ "libraries": {
64
+ "Coderot.Roslyn/1.0.0": {
65
+ "type": "project",
66
+ "serviceable": false,
67
+ "sha512": ""
68
+ },
69
+ "Microsoft.CodeAnalysis.Common/5.9.0": {
70
+ "type": "package",
71
+ "serviceable": true,
72
+ "sha512": "sha512-IYaIaUWdIx539AReKZOBEqTskFusZfCh/wFSPilDvCn5Say8MegLw2LONcSIcVy+v3Gzv53qYBspgvBGSErfbQ==",
73
+ "path": "microsoft.codeanalysis.common/5.9.0",
74
+ "hashPath": "microsoft.codeanalysis.common.5.9.0.nupkg.sha512"
75
+ },
76
+ "Microsoft.CodeAnalysis.CSharp/5.9.0": {
77
+ "type": "package",
78
+ "serviceable": true,
79
+ "sha512": "sha512-7JGDA0UT1+h7k9ZcA3rF4eFC8+QPq1xyYaXxag4p8r/zzPurEJxvdi7aM+MRL/SfP7XADXpWF/pl/eUYXOq/ww==",
80
+ "path": "microsoft.codeanalysis.csharp/5.9.0",
81
+ "hashPath": "microsoft.codeanalysis.csharp.5.9.0.nupkg.sha512"
82
+ },
83
+ "System.Collections.Immutable/10.0.1": {
84
+ "type": "package",
85
+ "serviceable": true,
86
+ "sha512": "sha512-kdTe61B8P7i2M1pODC3MLbZ/CfFGjpC6c6jzxjQoB5DHZNewayCRqgFUmx3JKB6vLQtozpMQEiw+R5fO32Jv4g==",
87
+ "path": "system.collections.immutable/10.0.1",
88
+ "hashPath": "system.collections.immutable.10.0.1.nupkg.sha512"
89
+ },
90
+ "System.Reflection.Metadata/10.0.1": {
91
+ "type": "package",
92
+ "serviceable": true,
93
+ "sha512": "sha512-zpcfT/wacPPhE17zcudozlxQtWN/84qyiMyZNGLnK4cj2IMBtLsZYwYjVnALUhPliwyUVj/P7kaZvBWYBCnf2Q==",
94
+ "path": "system.reflection.metadata/10.0.1",
95
+ "hashPath": "system.reflection.metadata.10.0.1.nupkg.sha512"
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "runtimeOptions": {
3
+ "tfm": "net8.0",
4
+ "rollForward": "Major",
5
+ "framework": {
6
+ "name": "Microsoft.NETCore.App",
7
+ "version": "8.0.0"
8
+ },
9
+ "configProperties": {
10
+ "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
11
+ "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
12
+ "System.Runtime.TieredCompilation": false
13
+ }
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@coderot-ai/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Code health and AI attribution from a repo's git history, for coderot.ai",
5
+ "license": "Elastic-2.0",
6
+ "homepage": "https://coderot.ai",
7
+ "type": "module",
8
+ "bin": {
9
+ "coderot": "dist/coderot.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "THIRD-PARTY-NOTICES.txt"
14
+ ],
15
+ "dependencies": {
16
+ "jscpd": "5.4.2",
17
+ "oxc-parser": "0.153.0",
18
+ "yaml": "2.9.1",
19
+ "zod": "4.6.7"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "24.10.1",
23
+ "esbuild": "0.28.2",
24
+ "vitest": "5.0.3",
25
+ "@coderot-ai/analyzer": "0.0.0",
26
+ "@coderot-ai/schema": "0.0.0"
27
+ },
28
+ "scripts": {
29
+ "test": "vitest run"
30
+ }
6
31
  }