diffninja 0.1.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 +21 -0
- package/README.md +259 -0
- package/dist/calltree.d.ts +47 -0
- package/dist/calltree.js +296 -0
- package/dist/cli.d.ts +57 -0
- package/dist/cli.js +340 -0
- package/dist/diff.d.ts +7 -0
- package/dist/diff.js +114 -0
- package/dist/extract.d.ts +26 -0
- package/dist/extract.js +152 -0
- package/dist/git.d.ts +40 -0
- package/dist/git.js +288 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/infer.d.ts +21 -0
- package/dist/infer.js +189 -0
- package/dist/languages/bash.d.ts +2 -0
- package/dist/languages/bash.js +208 -0
- package/dist/languages/c.d.ts +2 -0
- package/dist/languages/c.js +218 -0
- package/dist/languages/call-syntax.d.ts +125 -0
- package/dist/languages/call-syntax.js +997 -0
- package/dist/languages/cpp.d.ts +2 -0
- package/dist/languages/cpp.js +321 -0
- package/dist/languages/csharp.d.ts +2 -0
- package/dist/languages/csharp.js +324 -0
- package/dist/languages/elixir.d.ts +2 -0
- package/dist/languages/elixir.js +331 -0
- package/dist/languages/go.d.ts +2 -0
- package/dist/languages/go.js +299 -0
- package/dist/languages/grammars.d.ts +50 -0
- package/dist/languages/grammars.js +351 -0
- package/dist/languages/haskell.d.ts +2 -0
- package/dist/languages/haskell.js +250 -0
- package/dist/languages/java.d.ts +2 -0
- package/dist/languages/java.js +351 -0
- package/dist/languages/javascript.d.ts +4 -0
- package/dist/languages/javascript.js +648 -0
- package/dist/languages/kotlin.d.ts +2 -0
- package/dist/languages/kotlin.js +368 -0
- package/dist/languages/lua.d.ts +2 -0
- package/dist/languages/lua.js +212 -0
- package/dist/languages/ocaml.d.ts +2 -0
- package/dist/languages/ocaml.js +291 -0
- package/dist/languages/perl.d.ts +2 -0
- package/dist/languages/perl.js +418 -0
- package/dist/languages/php.d.ts +2 -0
- package/dist/languages/php.js +397 -0
- package/dist/languages/python.d.ts +2 -0
- package/dist/languages/python.js +376 -0
- package/dist/languages/registry.d.ts +7 -0
- package/dist/languages/registry.js +69 -0
- package/dist/languages/ruby.d.ts +2 -0
- package/dist/languages/ruby.js +391 -0
- package/dist/languages/rust.d.ts +2 -0
- package/dist/languages/rust.js +261 -0
- package/dist/languages/scala.d.ts +2 -0
- package/dist/languages/scala.js +307 -0
- package/dist/languages/solidity.d.ts +2 -0
- package/dist/languages/solidity.js +240 -0
- package/dist/languages/swift.d.ts +2 -0
- package/dist/languages/swift.js +268 -0
- package/dist/languages/types.d.ts +36 -0
- package/dist/languages/types.js +74 -0
- package/dist/languages/typescript-contracts.d.ts +57 -0
- package/dist/languages/typescript-contracts.js +528 -0
- package/dist/languages/typescript-dispatch.d.ts +68 -0
- package/dist/languages/typescript-dispatch.js +710 -0
- package/dist/languages/typescript.d.ts +4 -0
- package/dist/languages/typescript.js +722 -0
- package/dist/languages/zig.d.ts +2 -0
- package/dist/languages/zig.js +243 -0
- package/dist/loc.d.ts +17 -0
- package/dist/loc.js +34 -0
- package/dist/reach.d.ts +17 -0
- package/dist/reach.js +65 -0
- package/dist/render.d.ts +18 -0
- package/dist/render.js +83 -0
- package/dist/review/brand.d.ts +8 -0
- package/dist/review/brand.js +25 -0
- package/dist/review/call-context.d.ts +27 -0
- package/dist/review/call-context.js +446 -0
- package/dist/review/call-flow-html.d.ts +32 -0
- package/dist/review/call-flow-html.js +1870 -0
- package/dist/review/call-flow-nav.d.ts +151 -0
- package/dist/review/call-flow-nav.js +317 -0
- package/dist/review/call-flow.d.ts +47 -0
- package/dist/review/call-flow.js +229 -0
- package/dist/review/change-facts.d.ts +69 -0
- package/dist/review/change-facts.js +729 -0
- package/dist/review/cli.d.ts +2 -0
- package/dist/review/cli.js +50 -0
- package/dist/review/connected-analysis.d.ts +100 -0
- package/dist/review/connected-analysis.js +163 -0
- package/dist/review/connected-html.d.ts +17 -0
- package/dist/review/connected-html.js +2853 -0
- package/dist/review/connected.d.ts +23 -0
- package/dist/review/connected.js +141 -0
- package/dist/review/escape-html.d.ts +2 -0
- package/dist/review/escape-html.js +9 -0
- package/dist/review/evidence-html.d.ts +21 -0
- package/dist/review/evidence-html.js +521 -0
- package/dist/review/evidence-syntax.d.ts +132 -0
- package/dist/review/evidence-syntax.js +478 -0
- package/dist/review/evidence-types.d.ts +62 -0
- package/dist/review/evidence-types.js +1 -0
- package/dist/review/evidence.d.ts +31 -0
- package/dist/review/evidence.js +1603 -0
- package/dist/review/file-role.d.ts +9 -0
- package/dist/review/file-role.js +29 -0
- package/dist/review/github.d.ts +204 -0
- package/dist/review/github.js +1245 -0
- package/dist/review/history.d.ts +101 -0
- package/dist/review/history.js +412 -0
- package/dist/review/html.d.ts +34 -0
- package/dist/review/html.js +1104 -0
- package/dist/review/input.d.ts +10 -0
- package/dist/review/input.js +113 -0
- package/dist/review/intent.d.ts +4 -0
- package/dist/review/intent.js +75 -0
- package/dist/review/mcp-cli.d.ts +2 -0
- package/dist/review/mcp-cli.js +25 -0
- package/dist/review/mcp.d.ts +12 -0
- package/dist/review/mcp.js +414 -0
- package/dist/review/module-resolution.d.ts +2 -0
- package/dist/review/module-resolution.js +86 -0
- package/dist/review/palette.d.ts +7 -0
- package/dist/review/palette.js +104 -0
- package/dist/review/pipeline.d.ts +77 -0
- package/dist/review/pipeline.js +227 -0
- package/dist/review/pr-input.d.ts +19 -0
- package/dist/review/pr-input.js +130 -0
- package/dist/review/questions.d.ts +201 -0
- package/dist/review/questions.js +174 -0
- package/dist/review/reference-check.d.ts +7 -0
- package/dist/review/reference-check.js +733 -0
- package/dist/review/report-pages.d.ts +109 -0
- package/dist/review/report-pages.js +328 -0
- package/dist/review/service.d.ts +23 -0
- package/dist/review/service.js +198 -0
- package/dist/review/setup.d.ts +112 -0
- package/dist/review/setup.js +549 -0
- package/dist/review/source.d.ts +26 -0
- package/dist/review/source.js +276 -0
- package/dist/review/toml.d.ts +38 -0
- package/dist/review/toml.js +565 -0
- package/dist/review/types.d.ts +179 -0
- package/dist/review/types.js +1 -0
- package/dist/run.d.ts +49 -0
- package/dist/run.js +311 -0
- package/dist/types.d.ts +366 -0
- package/dist/types.js +83 -0
- package/package.json +88 -0
- package/scripts/ensure-native-grammar.mjs +188 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-shape classification of test files, shared by the evidence scan and the
|
|
3
|
+
* report order. It is a deterministic fact about the path only: it says nothing
|
|
4
|
+
* about coverage, whether the file runs, or whether its change is harmless.
|
|
5
|
+
* Documentation is deliberately not a role here: prose can carry normative
|
|
6
|
+
* instructions, so it is ranked by its observations like any other source.
|
|
7
|
+
*/
|
|
8
|
+
/** True when the path looks like test code by directory or file-name convention. */
|
|
9
|
+
export declare function testLikeFile(file: string): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-shape classification of test files, shared by the evidence scan and the
|
|
3
|
+
* report order. It is a deterministic fact about the path only: it says nothing
|
|
4
|
+
* about coverage, whether the file runs, or whether its change is harmless.
|
|
5
|
+
* Documentation is deliberately not a role here: prose can carry normative
|
|
6
|
+
* instructions, so it is ranked by its observations like any other source.
|
|
7
|
+
*/
|
|
8
|
+
/** A directory whose name marks test code, at any depth. */
|
|
9
|
+
const TEST_DIRECTORY = /(?:^|\/)(?:tests?|__tests__|specs?)\//;
|
|
10
|
+
/** File names that mark test code by convention, in any directory. */
|
|
11
|
+
const TEST_FILE_NAMES = [
|
|
12
|
+
// foo.test.ts, foo.spec.jsx, and tsd type tests such as index.test-d.ts
|
|
13
|
+
/\.(?:test|spec)(?:-d)?\.[cm]?[jt]sx?$/,
|
|
14
|
+
// a module named test or tests, such as a package's root test.js
|
|
15
|
+
/(?:^|\/)tests?\.[cm]?[jt]sx?$/,
|
|
16
|
+
// pytest discovery: test_*.py and *_test.py
|
|
17
|
+
/(?:^|\/)test_[^/]+\.py$/,
|
|
18
|
+
/_test\.py$/,
|
|
19
|
+
// Go, Ruby
|
|
20
|
+
/_test\.go$/,
|
|
21
|
+
/_(?:spec|test)\.rb$/,
|
|
22
|
+
// JUnit / xUnit / XCTest class naming: FooTest.java, FooTests.cs
|
|
23
|
+
/(?:^|\/)[^/]+Tests?\.(?:java|kt|cs|swift)$/,
|
|
24
|
+
];
|
|
25
|
+
/** True when the path looks like test code by directory or file-name convention. */
|
|
26
|
+
export function testLikeFile(file) {
|
|
27
|
+
const path = file.replace(/\\/g, "/");
|
|
28
|
+
return TEST_DIRECTORY.test(path) || TEST_FILE_NAMES.some((pattern) => pattern.test(path));
|
|
29
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connected GitHub review.
|
|
3
|
+
*
|
|
4
|
+
* One explicit github.com pull request URL in, one canonical diff out, one
|
|
5
|
+
* human-authored review back. `gh` is the only GitHub client: it runs with an
|
|
6
|
+
* explicit argument array, no shell, no prompts, bounded time and output, and
|
|
7
|
+
* the credential the environment already gave it is the identity that is read.
|
|
8
|
+
*
|
|
9
|
+
* Safety invariants:
|
|
10
|
+
* - A snapshot (and therefore every anchor a review may use) is built solely
|
|
11
|
+
* from the canonical pull request diff, and only after that diff was checked
|
|
12
|
+
* against the paginated file list GitHub returns for the same pull request.
|
|
13
|
+
* An added line anchors RIGHT, a deleted line anchors LEFT, a context line
|
|
14
|
+
* anchors either side. Nothing else is commentable.
|
|
15
|
+
* - A review is submitted only for the same snapshot the caller previewed, with
|
|
16
|
+
* the previewed payload byte for byte (including the explicit `commit_id`),
|
|
17
|
+
* after re-reading the metadata and the raw diff and finding them unchanged,
|
|
18
|
+
* and after the effective gh account was re-checked.
|
|
19
|
+
* - One review per session. An ambiguous write marks the session `unknown`,
|
|
20
|
+
* never retried; only an exact match found on GitHub resolves it.
|
|
21
|
+
*/
|
|
22
|
+
export type ReviewEvent = "COMMENT" | "APPROVE" | "REQUEST_CHANGES";
|
|
23
|
+
export type DiffSide = "LEFT" | "RIGHT";
|
|
24
|
+
/** One anchor the reviewer wrote by hand; never generated prose. */
|
|
25
|
+
export interface ReviewComment {
|
|
26
|
+
path: string;
|
|
27
|
+
line: number;
|
|
28
|
+
side: DiffSide;
|
|
29
|
+
body: string;
|
|
30
|
+
}
|
|
31
|
+
/** What the UI sends for preview and submit; it owns all draft text. */
|
|
32
|
+
export interface ReviewInput {
|
|
33
|
+
snapshotId: string;
|
|
34
|
+
event: ReviewEvent;
|
|
35
|
+
body: string;
|
|
36
|
+
comments: ReviewComment[];
|
|
37
|
+
}
|
|
38
|
+
/** Exactly the body POSTed to the GitHub reviews endpoint. */
|
|
39
|
+
export interface ReviewPayload {
|
|
40
|
+
commit_id: string;
|
|
41
|
+
event: ReviewEvent;
|
|
42
|
+
body: string;
|
|
43
|
+
comments: ReviewComment[];
|
|
44
|
+
}
|
|
45
|
+
export interface ConnectedIdentity {
|
|
46
|
+
login: string;
|
|
47
|
+
id: number;
|
|
48
|
+
}
|
|
49
|
+
/** One line of the canonical diff, in new-side order for context and additions. */
|
|
50
|
+
export interface SnapshotLine {
|
|
51
|
+
path: string;
|
|
52
|
+
line: number;
|
|
53
|
+
side: DiffSide;
|
|
54
|
+
text: string;
|
|
55
|
+
kind: "add" | "delete" | "context";
|
|
56
|
+
}
|
|
57
|
+
export interface ConnectedSnapshot {
|
|
58
|
+
id: string;
|
|
59
|
+
url: string;
|
|
60
|
+
owner: string;
|
|
61
|
+
repo: string;
|
|
62
|
+
number: number;
|
|
63
|
+
baseSha: string;
|
|
64
|
+
headSha: string;
|
|
65
|
+
state: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
body?: string;
|
|
68
|
+
lines: SnapshotLine[];
|
|
69
|
+
/** Set when the pull request exists but cannot be reviewed; `lines` may still be empty. */
|
|
70
|
+
unavailableReason?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ConnectedReceipt {
|
|
73
|
+
id: number;
|
|
74
|
+
url: string;
|
|
75
|
+
state: string;
|
|
76
|
+
commitId: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `empty` also covers a loaded pull request that cannot be reviewed
|
|
80
|
+
* (`snapshot.unavailableReason` says why); `ready` means the snapshot is bound
|
|
81
|
+
* and submittable; `unknown` means a write may or may not have landed and only
|
|
82
|
+
* reconciliation may resolve it.
|
|
83
|
+
*/
|
|
84
|
+
export type ConnectedStatus = "empty" | "ready" | "submitting" | "unknown" | "submitted";
|
|
85
|
+
export interface ConnectedState {
|
|
86
|
+
identity?: ConnectedIdentity;
|
|
87
|
+
snapshot?: ConnectedSnapshot;
|
|
88
|
+
status: ConnectedStatus;
|
|
89
|
+
receipt?: ConnectedReceipt;
|
|
90
|
+
message?: string;
|
|
91
|
+
}
|
|
92
|
+
/** Lowest `gh` release whose `pr view --json` fields and `api --input -` this code needs. */
|
|
93
|
+
export declare const MIN_GH_VERSION = "2.45.0";
|
|
94
|
+
export interface GhResult {
|
|
95
|
+
readonly stdout: string;
|
|
96
|
+
readonly stderr: string;
|
|
97
|
+
}
|
|
98
|
+
export interface GhInvocation {
|
|
99
|
+
readonly args: string[];
|
|
100
|
+
readonly stdin?: string;
|
|
101
|
+
readonly timeoutMs: number;
|
|
102
|
+
}
|
|
103
|
+
/** Injectable `gh` transport; tests supply a fake, the app uses {@link ghCliRunner}. */
|
|
104
|
+
export interface GhRunner {
|
|
105
|
+
run(invocation: GhInvocation): Promise<GhResult>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A failed `gh` run. `gh api` prints GitHub's JSON error body to stdout and the
|
|
109
|
+
* HTTP status line to stderr, so both are carried for safe message extraction;
|
|
110
|
+
* neither is ever shown to the user verbatim.
|
|
111
|
+
*/
|
|
112
|
+
export declare class GhCommandError extends Error {
|
|
113
|
+
readonly stdout: string;
|
|
114
|
+
readonly stderr: string;
|
|
115
|
+
constructor(message: string, stdout: string, stderr: string);
|
|
116
|
+
}
|
|
117
|
+
export interface ConnectedReviewDeps {
|
|
118
|
+
runner?: GhRunner;
|
|
119
|
+
timeoutMs?: number;
|
|
120
|
+
}
|
|
121
|
+
/** Runs the real `gh` with an explicit argv (never a shell) and a hard deadline. */
|
|
122
|
+
export declare function ghCliRunner(): GhRunner;
|
|
123
|
+
/** The JSON data model, used to validate each `gh` payload field by field. */
|
|
124
|
+
export type GhJson = string | number | boolean | null | GhJson[] | GhObject;
|
|
125
|
+
export interface GhObject {
|
|
126
|
+
readonly [key: string]: GhJson;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* One connected review session. Every method serializes behind the previous
|
|
130
|
+
* one, so an in-flight submission can never be double-fired.
|
|
131
|
+
*/
|
|
132
|
+
export declare class ConnectedReview {
|
|
133
|
+
private readonly runner;
|
|
134
|
+
private readonly timeoutMs;
|
|
135
|
+
private version;
|
|
136
|
+
private identity;
|
|
137
|
+
private snapshot;
|
|
138
|
+
private diff;
|
|
139
|
+
private anchors;
|
|
140
|
+
private status;
|
|
141
|
+
private receipt;
|
|
142
|
+
private message;
|
|
143
|
+
private previewed;
|
|
144
|
+
/** Review ids that already existed before this session's write attempt. */
|
|
145
|
+
private preexistingReviewIds;
|
|
146
|
+
private queue;
|
|
147
|
+
constructor(deps?: ConnectedReviewDeps);
|
|
148
|
+
getState(): ConnectedState;
|
|
149
|
+
/** Canonical patch from the last successfully bound snapshot, for static export. */
|
|
150
|
+
getDiff(): string;
|
|
151
|
+
load(url: string): Promise<ConnectedState>;
|
|
152
|
+
preview(input: ReviewInput): Promise<ReviewPayload>;
|
|
153
|
+
submit(input: ReviewInput): Promise<ConnectedState>;
|
|
154
|
+
reconcile(): Promise<ConnectedState>;
|
|
155
|
+
/** Run `work` after everything already queued; failures never break the chain. */
|
|
156
|
+
private serialize;
|
|
157
|
+
private call;
|
|
158
|
+
private ensureGhVersion;
|
|
159
|
+
/** The identity of the credential gh actually uses, re-read before each submit. */
|
|
160
|
+
private readIdentity;
|
|
161
|
+
private readMetadata;
|
|
162
|
+
private readCanonicalDiff;
|
|
163
|
+
private readChangedFiles;
|
|
164
|
+
/** Every review row of a pull request, across pages. */
|
|
165
|
+
private readReviews;
|
|
166
|
+
private readReviewIds;
|
|
167
|
+
/**
|
|
168
|
+
* Metadata plus the verified canonical diff; the only source of anchors. The
|
|
169
|
+
* metadata is read again after the diff and the file list, so a pull request
|
|
170
|
+
* that moved mid-read is rejected instead of producing a snapshot that mixes
|
|
171
|
+
* two revisions.
|
|
172
|
+
*/
|
|
173
|
+
private readSnapshot;
|
|
174
|
+
/**
|
|
175
|
+
* One PR and one account per session: the first pull request that loads at all
|
|
176
|
+
* is bound, reviewable or not, because a session is about one pull request and
|
|
177
|
+
* switching targets silently is exactly what this mode refuses to do. Only a
|
|
178
|
+
* refresh of that same pull request is allowed.
|
|
179
|
+
*/
|
|
180
|
+
private assertLoadable;
|
|
181
|
+
private runLoad;
|
|
182
|
+
private runPreview;
|
|
183
|
+
private runSubmit;
|
|
184
|
+
private postReview;
|
|
185
|
+
/**
|
|
186
|
+
* Resolve an ambiguous write. This never retries and never assumes: it looks
|
|
187
|
+
* for a review that matches this session exactly and was not already present
|
|
188
|
+
* before the attempt, so an identical older review cannot pass as proof.
|
|
189
|
+
*/
|
|
190
|
+
private runReconcile;
|
|
191
|
+
private findMatchingReview;
|
|
192
|
+
private readReviewComments;
|
|
193
|
+
/**
|
|
194
|
+
* The only payload a submit can ever send is the previewed one, so both the
|
|
195
|
+
* anchor check and the preview check run before anything is written.
|
|
196
|
+
*/
|
|
197
|
+
private buildPayload;
|
|
198
|
+
/**
|
|
199
|
+
* A comment is accepted only when it names a line of this pull request's diff
|
|
200
|
+
* and carries plain single-line text: the transport casts the request body, so
|
|
201
|
+
* shape is established here rather than assumed.
|
|
202
|
+
*/
|
|
203
|
+
private validateComment;
|
|
204
|
+
}
|