@diffci.com/diffci 0.3.20 → 0.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/src/client/agent-identity.d.ts +26 -0
- package/dist-client/src/client/agent-identity.js +62 -0
- package/dist-client/src/client/agent-selection.d.ts +55 -0
- package/dist-client/src/client/cli.d.ts +2 -0
- package/dist-client/src/client/cli.js +164 -3
- package/dist-client/src/client/command-batches.d.ts +26 -0
- package/dist-client/src/client/command-batches.js +7 -1
- package/dist-client/src/client/context.d.ts +47 -0
- package/dist-client/src/client/delivery-warning.d.ts +1 -0
- package/dist-client/src/client/economics.d.ts +17 -0
- package/dist-client/src/client/enforce-misses-collect.d.ts +49 -0
- package/dist-client/src/client/enforce-misses.d.ts +124 -0
- package/dist-client/src/client/enforce-policy.d.ts +33 -0
- package/dist-client/src/client/failure-baseline.d.ts +67 -0
- package/dist-client/src/client/failure-baseline.js +43 -19
- package/dist-client/src/client/feedback-prompt.d.ts +6 -0
- package/dist-client/src/client/full-command.d.ts +16 -0
- package/dist-client/src/client/gate-checks.d.ts +54 -0
- package/dist-client/src/client/gate-checks.js +21 -7
- package/dist-client/src/client/gate.d.ts +154 -0
- package/dist-client/src/client/gate.js +221 -0
- package/dist-client/src/client/hook.d.ts +27 -0
- package/dist-client/src/client/install.d.ts +19 -0
- package/dist-client/src/client/mcp.d.ts +2 -0
- package/dist-client/src/client/observe.d.ts +52 -0
- package/dist-client/src/client/observe.js +25 -3
- package/dist-client/src/client/package-identity.d.ts +14 -0
- package/dist-client/src/client/pilot-packet.d.ts +6 -0
- package/dist-client/src/client/report.d.ts +265 -0
- package/dist-client/src/client/selected-coverage.d.ts +19 -0
- package/dist-client/src/client/selected-coverage.js +86 -0
- package/dist-client/src/client/shared-graph-cache.d.ts +113 -0
- package/dist-client/src/client/shared-graph-cache.js +347 -0
- package/dist-client/src/client/spec-conflicts.d.ts +19 -0
- package/dist-client/src/client/submit.d.ts +61 -0
- package/dist-client/src/client/telemetry.d.ts +13 -0
- package/dist-client/src/client/usage-signal.d.ts +19 -0
- package/dist-client/src/client/verify-savings.d.ts +186 -0
- package/dist-client/src/client/verify-savings.js +3 -0
- package/dist-client/src/client/verify.d.ts +113 -0
- package/dist-client/src/client/verify.js +37 -13
- package/dist-client/src/client/workflow-guard.d.ts +59 -0
- package/dist-client/src/client/workflow-guard.js +253 -0
- package/dist-client/src/client/workflow-templates.d.ts +8 -0
- package/dist-client/src/client/working-tree.d.ts +26 -0
- package/dist-client/src/preflight/fingerprint.d.ts +29 -0
- package/dist-client/src/preflight/taxonomy.d.ts +10 -0
- package/node_modules/@diffci.com/core/README.md +4 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +17 -2
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +2 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +46 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +45 -1
- package/package.json +9 -2
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in shared dependency-graph cache, client side (2026-10-31). See docs/shared-graph-cache.md.
|
|
3
|
+
*
|
|
4
|
+
* A read-through/write-back layer around the local graph cache (core's src/cache/graph-cache.ts):
|
|
5
|
+
*
|
|
6
|
+
* load: local disk -> DiffCI Cloud -> (miss: the caller builds the graph as it always has)
|
|
7
|
+
* save: local disk now, remote PUT in the background, awaited by `flush()` with a timeout
|
|
8
|
+
*
|
|
9
|
+
* Three rules, enforced here rather than promised:
|
|
10
|
+
*
|
|
11
|
+
* - OFF UNLESS ASKED. Nothing is constructed unless the caller opted in AND gave an endpoint and a
|
|
12
|
+
* token. The observer's default behaviour - nothing leaves the runner - is unchanged.
|
|
13
|
+
* - A FAILURE IS A MISS. Every remote problem (network, timeout, 4xx/5xx, entitlement, integrity,
|
|
14
|
+
* decryption, an envelope for another key, a shape we do not recognise) degrades to "not cached".
|
|
15
|
+
* Nothing here throws to the caller, and a miss only means the graph is built locally - the analysis
|
|
16
|
+
* result is identical either way.
|
|
17
|
+
* - THE GRAPH, NEVER THE SOURCE. The payload is the derived DependencyGraphResult: repository-relative
|
|
18
|
+
* file paths, import edges, unresolved import specifiers, and repository profile metadata (package.json
|
|
19
|
+
* script strings and dependency names, tsconfig path aliases, test globs). No file contents. Absolute
|
|
20
|
+
* checkout paths are replaced with a placeholder before anything is written, so neither the runner's
|
|
21
|
+
* directory layout nor a username leaves the machine, and a graph built in /home/runner/work/x is valid
|
|
22
|
+
* in C:\src\x. With DIFFCI_GRAPH_CACHE_SECRET set, the payload is AES-256-GCM encrypted client-side and
|
|
23
|
+
* the remote key is an HMAC under the same secret: DiffCI stores bytes it cannot read or correlate.
|
|
24
|
+
*
|
|
25
|
+
* Path hashing (like --redact-paths) was considered and rejected: a graph whose paths are digests cannot
|
|
26
|
+
* be matched against the next change's paths without a reverse map, and a lossy round trip is exactly
|
|
27
|
+
* what must never change a selection. Encryption gives the same privacy with a lossless round trip.
|
|
28
|
+
*/
|
|
29
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "node:crypto";
|
|
30
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
31
|
+
import { join, resolve } from "node:path";
|
|
32
|
+
export const SHARED_GRAPH_CACHE_ENVELOPE_SCHEMA = "diffci.graph-cache.v1";
|
|
33
|
+
export const CONTENT_SHA256_HEADER = "x-diffci-content-sha256";
|
|
34
|
+
/** Bumped whenever the portable payload format or the key inputs below change. */
|
|
35
|
+
export const SHARED_GRAPH_CACHE_KEY_SCHEMA = "shared-1";
|
|
36
|
+
const MAX_ENTRY_BYTES = 32 * 1024 * 1024;
|
|
37
|
+
const REPO_TOKEN = "\u0000diffci:repo\u0000";
|
|
38
|
+
const REPO_POSIX_TOKEN = "\u0000diffci:repo-posix\u0000";
|
|
39
|
+
const LOCKFILES = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"];
|
|
40
|
+
const CONFIG_FILES = ["tsconfig.json", "package.json", "diffci.config.json", "jsconfig.json"];
|
|
41
|
+
function sha256(input) {
|
|
42
|
+
return createHash("sha256").update(input).digest("hex");
|
|
43
|
+
}
|
|
44
|
+
function readHash(path) {
|
|
45
|
+
try {
|
|
46
|
+
return existsSync(path) ? sha256(readFileSync(path)) : "absent";
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return "unreadable";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The cache key for the graph of `repoPath` as it is checked out right now, or undefined when no key
|
|
54
|
+
* can honestly describe it. A dirty working tree has no commit that names it, so it is never cached.
|
|
55
|
+
*
|
|
56
|
+
* Inputs: HEAD, the schema of this format, DiffCI's version and engine commit, hashes of the files that
|
|
57
|
+
* steer resolution (tsconfig/package/DiffCI config, lockfiles), whether node_modules is installed, the
|
|
58
|
+
* platform, and the excluded directories. The output is a SHA-256 digest; the commit is not readable from it.
|
|
59
|
+
*/
|
|
60
|
+
export function deriveSharedGraphCacheKey(input) {
|
|
61
|
+
try {
|
|
62
|
+
const head = input.git(["rev-parse", "HEAD"]);
|
|
63
|
+
const status = input.git(["status", "--porcelain", "--untracked-files=all"]);
|
|
64
|
+
if (!head.ok || !status.ok)
|
|
65
|
+
return undefined;
|
|
66
|
+
const commitSha = head.stdout.trim();
|
|
67
|
+
if (!/^[0-9a-f]{40,64}$/.test(commitSha) || status.stdout.trim() !== "")
|
|
68
|
+
return undefined;
|
|
69
|
+
const repoPath = resolve(input.repoPath);
|
|
70
|
+
const payload = JSON.stringify({
|
|
71
|
+
schema: SHARED_GRAPH_CACHE_KEY_SCHEMA,
|
|
72
|
+
commit: commitSha,
|
|
73
|
+
diffci: `${input.version}:${input.engineSha ?? ""}`,
|
|
74
|
+
config: Object.fromEntries(CONFIG_FILES.map((file) => [file, readHash(join(repoPath, file))])),
|
|
75
|
+
lockfiles: Object.fromEntries(LOCKFILES.map((file) => [file, readHash(join(repoPath, file))])),
|
|
76
|
+
nodeModules: existsSync(join(repoPath, "node_modules")),
|
|
77
|
+
platform: input.platform ?? process.platform,
|
|
78
|
+
exclude: [...input.excludeDirs].sort(),
|
|
79
|
+
});
|
|
80
|
+
return sha256(payload);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** True for graphs that must not be shared: Go metadata depends on the local toolchain. */
|
|
87
|
+
function isUncacheable(result) {
|
|
88
|
+
return result.profile?.adapters?.some((adapter) => adapter.id === "go") === true || result.graph.nodes.length === 0;
|
|
89
|
+
}
|
|
90
|
+
function mapStrings(value, transform) {
|
|
91
|
+
if (typeof value === "string")
|
|
92
|
+
return transform(value);
|
|
93
|
+
if (Array.isArray(value))
|
|
94
|
+
return value.map((item) => mapStrings(item, transform));
|
|
95
|
+
if (value && typeof value === "object") {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [key, item] of Object.entries(value))
|
|
98
|
+
out[transform(key)] = mapStrings(item, transform);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
/** Plain, machine-independent JSON: the graph reduced to nodes and edges, the checkout path tokenised. */
|
|
104
|
+
export function toPortableGraph(result, repoPath) {
|
|
105
|
+
const native = resolve(repoPath);
|
|
106
|
+
const posix = native.replace(/\\/g, "/");
|
|
107
|
+
const projected = { ...result, graph: { nodes: result.graph.nodes, edges: result.graph.edges } };
|
|
108
|
+
const plain = JSON.parse(JSON.stringify(projected));
|
|
109
|
+
return mapStrings(plain, (text) => {
|
|
110
|
+
if (text === native || text.startsWith(native + "/") || text.startsWith(native + "\\"))
|
|
111
|
+
return REPO_TOKEN + text.slice(native.length);
|
|
112
|
+
if (posix !== native && (text === posix || text.startsWith(posix + "/")))
|
|
113
|
+
return REPO_POSIX_TOKEN + text.slice(posix.length);
|
|
114
|
+
return text;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** The inverse of toPortableGraph, against this machine's checkout. Undefined for an unrecognised shape. */
|
|
118
|
+
export function fromPortableGraph(portable, repoPath) {
|
|
119
|
+
const native = resolve(repoPath);
|
|
120
|
+
const posix = native.replace(/\\/g, "/");
|
|
121
|
+
const restored = mapStrings(portable, (text) => text.startsWith(REPO_TOKEN) ? native + text.slice(REPO_TOKEN.length)
|
|
122
|
+
: text.startsWith(REPO_POSIX_TOKEN) ? posix + text.slice(REPO_POSIX_TOKEN.length)
|
|
123
|
+
: text);
|
|
124
|
+
if (!restored || typeof restored !== "object")
|
|
125
|
+
return undefined;
|
|
126
|
+
const graph = restored.graph;
|
|
127
|
+
if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges) || !restored.profile || typeof restored.profile !== "object")
|
|
128
|
+
return undefined;
|
|
129
|
+
return restored;
|
|
130
|
+
}
|
|
131
|
+
function encryptionKey(secret) {
|
|
132
|
+
return createHash("sha256").update(`diffci-graph-cache-v1:${secret}`).digest();
|
|
133
|
+
}
|
|
134
|
+
/** With a team secret, the server sees an HMAC of the key, not the key. Different secrets never collide. */
|
|
135
|
+
export function remoteCacheKey(localKey, secret) {
|
|
136
|
+
return secret ? createHmac("sha256", encryptionKey(secret)).update(localKey).digest("hex") : localKey;
|
|
137
|
+
}
|
|
138
|
+
export function encodeEnvelope(remoteKey, portable, options = {}) {
|
|
139
|
+
const producer = { diffci: options.version ?? "unknown" };
|
|
140
|
+
if (!options.secret) {
|
|
141
|
+
return JSON.stringify({ schema: SHARED_GRAPH_CACHE_ENVELOPE_SCHEMA, key: remoteKey, encoding: "json", producer, payload: portable });
|
|
142
|
+
}
|
|
143
|
+
const iv = randomBytes(12);
|
|
144
|
+
const cipher = createCipheriv("aes-256-gcm", encryptionKey(options.secret), iv);
|
|
145
|
+
cipher.setAAD(Buffer.from(remoteKey));
|
|
146
|
+
const data = Buffer.concat([cipher.update(JSON.stringify(portable), "utf8"), cipher.final()]);
|
|
147
|
+
return JSON.stringify({
|
|
148
|
+
schema: SHARED_GRAPH_CACHE_ENVELOPE_SCHEMA, key: remoteKey, encoding: "aes-256-gcm", producer,
|
|
149
|
+
payload: { iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), data: data.toString("base64") },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** Undefined for anything that is not exactly an envelope for `remoteKey` that we can read. */
|
|
153
|
+
export function decodeEnvelope(remoteKey, body, secret) {
|
|
154
|
+
try {
|
|
155
|
+
const envelope = JSON.parse(body);
|
|
156
|
+
if (envelope.schema !== SHARED_GRAPH_CACHE_ENVELOPE_SCHEMA || envelope.key !== remoteKey)
|
|
157
|
+
return undefined;
|
|
158
|
+
if (envelope.encoding === "json")
|
|
159
|
+
return secret ? undefined : envelope.payload;
|
|
160
|
+
if (envelope.encoding !== "aes-256-gcm" || !secret)
|
|
161
|
+
return undefined;
|
|
162
|
+
const payload = envelope.payload;
|
|
163
|
+
const decipher = createDecipheriv("aes-256-gcm", encryptionKey(secret), Buffer.from(payload.iv, "base64"));
|
|
164
|
+
decipher.setAAD(Buffer.from(remoteKey));
|
|
165
|
+
decipher.setAuthTag(Buffer.from(payload.tag, "base64"));
|
|
166
|
+
const plain = Buffer.concat([decipher.update(Buffer.from(payload.data, "base64")), decipher.final()]).toString("utf8");
|
|
167
|
+
return JSON.parse(plain);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function isLoopback(url) {
|
|
174
|
+
return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Where the cache lives, from an explicit URL or the configured ingest URL's origin. Undefined (cache
|
|
178
|
+
* off) for anything unparseable or plaintext to a non-loopback host - a token is never sent over http.
|
|
179
|
+
*/
|
|
180
|
+
export function resolveSharedGraphCacheBaseUrl(input) {
|
|
181
|
+
try {
|
|
182
|
+
if (input.cacheUrl) {
|
|
183
|
+
const url = new URL(input.cacheUrl);
|
|
184
|
+
if (url.protocol !== "https:" && !isLoopback(url))
|
|
185
|
+
return undefined;
|
|
186
|
+
return url.toString().replace(/\/+$/, "");
|
|
187
|
+
}
|
|
188
|
+
if (!input.apiUrl)
|
|
189
|
+
return undefined;
|
|
190
|
+
const url = new URL(input.apiUrl);
|
|
191
|
+
if (url.protocol !== "https:" && !isLoopback(url))
|
|
192
|
+
return undefined;
|
|
193
|
+
return `${url.origin}/v1/cache/graph`;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** The DiffCI Cloud tier. Every method resolves; none throws. */
|
|
200
|
+
export class RemoteGraphCache {
|
|
201
|
+
options;
|
|
202
|
+
constructor(options) {
|
|
203
|
+
this.options = options;
|
|
204
|
+
}
|
|
205
|
+
async request(method, remoteKey, init = {}) {
|
|
206
|
+
const controller = new AbortController();
|
|
207
|
+
const timer = setTimeout(() => controller.abort(), this.options.timeoutMs ?? (method === "GET" ? 5_000 : 15_000));
|
|
208
|
+
try {
|
|
209
|
+
return await (this.options.fetchImpl ?? fetch)(`${this.options.baseUrl}/${remoteKey}`, {
|
|
210
|
+
method,
|
|
211
|
+
body: init.body,
|
|
212
|
+
headers: { authorization: `Bearer ${this.options.token}`, ...init.headers },
|
|
213
|
+
signal: controller.signal,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Portable payload for `localKey`, or undefined on any miss or failure. */
|
|
224
|
+
async get(localKey) {
|
|
225
|
+
const remoteKey = remoteCacheKey(localKey, this.options.secret);
|
|
226
|
+
const response = await this.request("GET", remoteKey);
|
|
227
|
+
if (!response || response.status !== 200)
|
|
228
|
+
return undefined;
|
|
229
|
+
try {
|
|
230
|
+
const body = await response.text();
|
|
231
|
+
if (body.length > MAX_ENTRY_BYTES)
|
|
232
|
+
return undefined;
|
|
233
|
+
// End-to-end integrity: what arrived must be what the server says it stored.
|
|
234
|
+
const declared = response.headers.get(CONTENT_SHA256_HEADER);
|
|
235
|
+
if (!declared || declared.toLowerCase() !== sha256(body))
|
|
236
|
+
return undefined;
|
|
237
|
+
return decodeEnvelope(remoteKey, body, this.options.secret);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async put(localKey, portable) {
|
|
244
|
+
try {
|
|
245
|
+
const remoteKey = remoteCacheKey(localKey, this.options.secret);
|
|
246
|
+
const body = encodeEnvelope(remoteKey, portable, { secret: this.options.secret, version: this.options.version });
|
|
247
|
+
if (Buffer.byteLength(body, "utf8") > MAX_ENTRY_BYTES)
|
|
248
|
+
return false;
|
|
249
|
+
const response = await this.request("PUT", remoteKey, {
|
|
250
|
+
body,
|
|
251
|
+
headers: { "content-type": "application/json", [CONTENT_SHA256_HEADER]: sha256(body) },
|
|
252
|
+
});
|
|
253
|
+
return response !== undefined && (response.status === 200 || response.status === 201);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
export class LayeredGraphCache {
|
|
261
|
+
options;
|
|
262
|
+
pending = [];
|
|
263
|
+
/** What the last load did, for a one-line summary. */
|
|
264
|
+
lastOutcome;
|
|
265
|
+
constructor(options) {
|
|
266
|
+
this.options = options;
|
|
267
|
+
}
|
|
268
|
+
async load(key) {
|
|
269
|
+
const { repoPath, local, remote } = this.options;
|
|
270
|
+
try {
|
|
271
|
+
const fromDisk = local?.load(key);
|
|
272
|
+
const restored = fromDisk ? fromPortableGraph(fromDisk, repoPath) : undefined;
|
|
273
|
+
if (restored && !isUncacheable(restored)) {
|
|
274
|
+
this.lastOutcome = "local-hit";
|
|
275
|
+
return { result: restored, source: "local" };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch { /* unreadable local entry: fall through */ }
|
|
279
|
+
if (remote) {
|
|
280
|
+
const portable = await remote.get(key);
|
|
281
|
+
const restored = portable === undefined ? undefined : fromPortableGraph(portable, repoPath);
|
|
282
|
+
if (restored && !isUncacheable(restored)) {
|
|
283
|
+
// Read-through: the next run on this machine does not need the network.
|
|
284
|
+
try {
|
|
285
|
+
local?.save(key, portable);
|
|
286
|
+
}
|
|
287
|
+
catch { /* local is an optimisation */ }
|
|
288
|
+
this.lastOutcome = "remote-hit";
|
|
289
|
+
return { result: restored, source: "remote" };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
this.lastOutcome = "miss";
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
/** Synchronous to the caller; the remote write runs in the background until flush(). */
|
|
296
|
+
save(key, result) {
|
|
297
|
+
try {
|
|
298
|
+
if (isUncacheable(result))
|
|
299
|
+
return;
|
|
300
|
+
const portable = toPortableGraph(result, this.options.repoPath);
|
|
301
|
+
try {
|
|
302
|
+
this.options.local?.save(key, portable);
|
|
303
|
+
}
|
|
304
|
+
catch { /* ignore */ }
|
|
305
|
+
if (this.options.remote)
|
|
306
|
+
this.pending.push(this.options.remote.put(key, portable).catch(() => false));
|
|
307
|
+
}
|
|
308
|
+
catch { /* never fail the analysis */ }
|
|
309
|
+
}
|
|
310
|
+
/** Waits for background uploads, bounded by their own request timeouts. */
|
|
311
|
+
async flush() {
|
|
312
|
+
await Promise.allSettled(this.pending.splice(0));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The opt-in decision, in one place. No `cache` means no caching at all - the observer's default. Notes say
|
|
317
|
+
* why a requested tier was left off, without ever repeating the token or secret.
|
|
318
|
+
*/
|
|
319
|
+
export function configureGraphCache(input) {
|
|
320
|
+
const notes = [];
|
|
321
|
+
let localDir = input.localDir ?? (input.shared ? join(input.defaultLocalRoot, "diffci-graph-cache") : undefined);
|
|
322
|
+
if (localDir && input.isInsideRepository(input.repoPath, localDir)) {
|
|
323
|
+
notes.push("local graph cache disabled: the directory is inside the checkout");
|
|
324
|
+
localDir = undefined;
|
|
325
|
+
}
|
|
326
|
+
let remote;
|
|
327
|
+
if (input.shared) {
|
|
328
|
+
const baseUrl = resolveSharedGraphCacheBaseUrl({ cacheUrl: input.cacheUrl, apiUrl: input.apiUrl });
|
|
329
|
+
const secret = input.secret && input.secret.length >= 16 ? input.secret : undefined;
|
|
330
|
+
if (input.secret && !secret)
|
|
331
|
+
notes.push("DIFFCI_GRAPH_CACHE_SECRET ignored: it must be at least 16 characters");
|
|
332
|
+
if (input.noSend)
|
|
333
|
+
notes.push("shared graph cache off: --no-send");
|
|
334
|
+
else if (!baseUrl)
|
|
335
|
+
notes.push("shared graph cache off: no https api-url or graph-cache-url");
|
|
336
|
+
else if (!input.token)
|
|
337
|
+
notes.push("shared graph cache off: no api-token");
|
|
338
|
+
else if (input.redactPaths && !secret)
|
|
339
|
+
notes.push("shared graph cache off: --redact-paths needs DIFFCI_GRAPH_CACHE_SECRET, because the graph carries file paths");
|
|
340
|
+
else
|
|
341
|
+
remote = new RemoteGraphCache({ baseUrl, token: input.token, secret, version: input.version, fetchImpl: input.fetchImpl });
|
|
342
|
+
}
|
|
343
|
+
if (!localDir && !remote)
|
|
344
|
+
return { cache: undefined, notes };
|
|
345
|
+
const local = localDir && input.local ? input.local(localDir) : undefined;
|
|
346
|
+
return { cache: new LayeredGraphCache({ repoPath: input.repoPath, local, remote }), notes };
|
|
347
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ChangeSpecification {
|
|
2
|
+
id: string;
|
|
3
|
+
logicalTarget: string | string[];
|
|
4
|
+
description?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SpecificationConflict {
|
|
7
|
+
logicalTarget: string;
|
|
8
|
+
specificationIds: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface SpecificationConflictReport {
|
|
11
|
+
schema: "diffci.specConflicts.v1";
|
|
12
|
+
valid: boolean;
|
|
13
|
+
specificationsChecked: number;
|
|
14
|
+
logicalTargetsChecked: number;
|
|
15
|
+
conflicts: SpecificationConflict[];
|
|
16
|
+
blockers: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function detectSpecificationConflicts(specifications: readonly ChangeSpecification[]): SpecificationConflictReport;
|
|
19
|
+
export declare function readSpecificationFile(path: string): ChangeSpecification[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sending an observation report (Phase 03, 2026-08-26).
|
|
3
|
+
*
|
|
4
|
+
* The observer runs on someone else's runner, so this is the one place DiffCI's client makes an
|
|
5
|
+
* outbound request from inside their infrastructure. Three rules follow from that, and all three are
|
|
6
|
+
* enforced here rather than documented:
|
|
7
|
+
*
|
|
8
|
+
* - PLAINTEXT IS REFUSED. A credential sent over http:// is a credential published to every hop in
|
|
9
|
+
* between. Only https is allowed, with an explicit exception for localhost so the flow can be
|
|
10
|
+
* developed and tested without weakening the rule for everyone else.
|
|
11
|
+
* - THE TOKEN IS NEVER RETURNED, LOGGED, OR PUT IN A MESSAGE. Not in the error path either - which is
|
|
12
|
+
* exactly where secrets usually escape.
|
|
13
|
+
* - A FAILED SEND IS NOT A FAILED BUILD. The report is already on disk and already an artifact. A
|
|
14
|
+
* network problem between their runner and DiffCI is DiffCI's problem, and the caller is told
|
|
15
|
+
* plainly, but nothing about it is allowed to turn their CI red.
|
|
16
|
+
*
|
|
17
|
+
* One retry, for a network error or a 5xx. A 4xx is the server saying the request itself is wrong -
|
|
18
|
+
* repeating it verbatim would only produce the same answer, more slowly.
|
|
19
|
+
*/
|
|
20
|
+
import type { ObservationReport } from "./report.js";
|
|
21
|
+
export interface SubmitOptions {
|
|
22
|
+
/** Full ingest endpoint, e.g. https://api.diffci.com/v1/ingest/observations */
|
|
23
|
+
apiUrl: string;
|
|
24
|
+
/** The raw ingest token. Never logged, never echoed, never included in any returned value. */
|
|
25
|
+
token: string;
|
|
26
|
+
report: ObservationReport;
|
|
27
|
+
fetchImpl?: typeof fetch;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
/** Retries after the first attempt. Default 1. */
|
|
30
|
+
retries?: number;
|
|
31
|
+
/** Delay between attempts. Injected so tests do not sleep. */
|
|
32
|
+
delayMs?: number;
|
|
33
|
+
sleep?: (ms: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export type SubmitOutcome = {
|
|
36
|
+
ok: true;
|
|
37
|
+
duplicate: boolean;
|
|
38
|
+
status: number;
|
|
39
|
+
}
|
|
40
|
+
/** The server understood the request and refused it. `rejection` is its machine-readable reason. */
|
|
41
|
+
| {
|
|
42
|
+
ok: false;
|
|
43
|
+
kind: "rejected";
|
|
44
|
+
status: number;
|
|
45
|
+
rejection?: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
/** Never reached the server, or the server failed. Worth retrying later; the report is still on disk. */
|
|
49
|
+
| {
|
|
50
|
+
ok: false;
|
|
51
|
+
kind: "unreachable";
|
|
52
|
+
status?: number;
|
|
53
|
+
message: string;
|
|
54
|
+
}
|
|
55
|
+
/** The call itself was misconfigured - a bad URL, a missing token, plaintext http. */
|
|
56
|
+
| {
|
|
57
|
+
ok: false;
|
|
58
|
+
kind: "misconfigured";
|
|
59
|
+
message: string;
|
|
60
|
+
};
|
|
61
|
+
export declare function submitObservation(options: SubmitOptions): Promise<SubmitOutcome>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type UsageCommand, type UsageOutcome } from "./usage-signal.js";
|
|
2
|
+
export type TelemetryMode = "off" | "anonymous" | "installations";
|
|
3
|
+
interface Preference {
|
|
4
|
+
mode: TelemetryMode;
|
|
5
|
+
installationId?: string;
|
|
6
|
+
internal: boolean;
|
|
7
|
+
}
|
|
8
|
+
type Flags = Record<string, string | boolean>;
|
|
9
|
+
export declare function preferencePath(env: NodeJS.ProcessEnv): string;
|
|
10
|
+
export declare function readTelemetryPreference(env: NodeJS.ProcessEnv): Preference;
|
|
11
|
+
export declare function configureTelemetry(mode: string, internal: boolean, env: NodeJS.ProcessEnv): Preference;
|
|
12
|
+
export declare function recordUsage(command: UsageCommand, outcome: UsageOutcome, version: string, flags: Flags, env: NodeJS.ProcessEnv): Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Explicit, best-effort usage signal. Never includes repository or machine details. */
|
|
2
|
+
export type UsageCommand = "check" | "observe" | "verify";
|
|
3
|
+
export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked";
|
|
4
|
+
export interface UsageSignal {
|
|
5
|
+
command: UsageCommand;
|
|
6
|
+
outcome: UsageOutcome;
|
|
7
|
+
version: string;
|
|
8
|
+
surface?: "cli" | "local-mcp";
|
|
9
|
+
activity?: "internal" | "external";
|
|
10
|
+
installationId?: string;
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
fetchImpl?: typeof fetch;
|
|
13
|
+
}
|
|
14
|
+
export interface DeliveryResult {
|
|
15
|
+
status: "delivered" | "accepted" | "failed" | "timed-out";
|
|
16
|
+
httpStatus?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function deliverUsageSignal(input: UsageSignal): Promise<DeliveryResult>;
|
|
19
|
+
export declare function sendUsageSignal(input: UsageSignal): Promise<boolean>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { FailureClass } from "../preflight/taxonomy.js";
|
|
2
|
+
export type CacheState = "cold" | "warm" | "unknown" | "potentially-warmed";
|
|
3
|
+
export type FailureAssessmentKind = "none" | "selection_miss" | "likely_flaky" | "pre_existing" | "infrastructure" | "inconclusive";
|
|
4
|
+
export interface CommandMeasurement {
|
|
5
|
+
command: string;
|
|
6
|
+
exitCode: number | null;
|
|
7
|
+
signal: string | null;
|
|
8
|
+
timedOut: boolean;
|
|
9
|
+
startedAt: string;
|
|
10
|
+
finishedAt: string;
|
|
11
|
+
wallMs: number;
|
|
12
|
+
stdoutTail: string;
|
|
13
|
+
stderrTail: string;
|
|
14
|
+
/** Test names the runner reported as failing, from the complete output (not the tails). */
|
|
15
|
+
failingTests?: string[];
|
|
16
|
+
/** node:test's reported test count, or vitest's or jest's test-file total, from the complete output.
|
|
17
|
+
* Each file contributes at least one, so fewer than the selected files means some never ran. */
|
|
18
|
+
runnerTestCount?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface VerifySavingsReport {
|
|
21
|
+
schema: "diffci.verifySavings.v3";
|
|
22
|
+
producedAt: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
cwd: string;
|
|
25
|
+
timeoutMs: number;
|
|
26
|
+
analysisOverheadMs?: number;
|
|
27
|
+
selectionSource: "manual" | "diffci-observation";
|
|
28
|
+
observationReportPath?: string;
|
|
29
|
+
selectedTestCount?: number;
|
|
30
|
+
totalTestCount?: number;
|
|
31
|
+
provenance: SavingsProvenance;
|
|
32
|
+
runnerIdentity: RunnerIdentity;
|
|
33
|
+
protocol: SavingsProtocol;
|
|
34
|
+
trials: SavingsTrial[];
|
|
35
|
+
failureAssessment: FailureAssessment;
|
|
36
|
+
full: CommandMeasurement;
|
|
37
|
+
selected: CommandMeasurement;
|
|
38
|
+
comparison: {
|
|
39
|
+
fullWallMs: number;
|
|
40
|
+
selectedWallMs: number;
|
|
41
|
+
netSelectedMs: number;
|
|
42
|
+
deltaMs: number;
|
|
43
|
+
grossPercentChange: number;
|
|
44
|
+
percentChange: number;
|
|
45
|
+
selectedCommandSucceeded: boolean;
|
|
46
|
+
fullCommandSucceeded: boolean;
|
|
47
|
+
missedFailureSignal: boolean;
|
|
48
|
+
evidenceValid: boolean;
|
|
49
|
+
performanceEvidence: "CONTROLLED" | "PRELIMINARY" | "INVALID";
|
|
50
|
+
repetitions: number;
|
|
51
|
+
fullWallMsRange: {
|
|
52
|
+
min: number;
|
|
53
|
+
median: number;
|
|
54
|
+
max: number;
|
|
55
|
+
};
|
|
56
|
+
selectedWallMsRange: {
|
|
57
|
+
min: number;
|
|
58
|
+
median: number;
|
|
59
|
+
max: number;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
notes: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface CheckoutSnapshot {
|
|
65
|
+
capturedAt: string;
|
|
66
|
+
headSha?: string;
|
|
67
|
+
worktreeDigest?: string;
|
|
68
|
+
dependencyInputsSha256?: string;
|
|
69
|
+
dependencyInputFiles?: string[];
|
|
70
|
+
resolvedDependencySha256?: string;
|
|
71
|
+
resolvedDependencyFiles?: string[];
|
|
72
|
+
}
|
|
73
|
+
export interface RunnerIdentity {
|
|
74
|
+
platform: string;
|
|
75
|
+
architecture: string;
|
|
76
|
+
osRelease: string;
|
|
77
|
+
nodeVersion: string;
|
|
78
|
+
cpuModel?: string;
|
|
79
|
+
cpuCount: number;
|
|
80
|
+
totalMemoryBytes: number;
|
|
81
|
+
ci?: string;
|
|
82
|
+
runnerName?: string;
|
|
83
|
+
runnerOs?: string;
|
|
84
|
+
runnerArch?: string;
|
|
85
|
+
runnerEnvironment?: string;
|
|
86
|
+
imageOs?: string;
|
|
87
|
+
imageVersion?: string;
|
|
88
|
+
fingerprintSha256: string;
|
|
89
|
+
}
|
|
90
|
+
export interface SavingsProtocol {
|
|
91
|
+
repetitions: number;
|
|
92
|
+
alternatingOrder: boolean;
|
|
93
|
+
declaredCacheState: Exclude<CacheState, "potentially-warmed">;
|
|
94
|
+
cachePreparationCommand?: string;
|
|
95
|
+
cacheStateControlled: boolean;
|
|
96
|
+
}
|
|
97
|
+
export interface SavingsTrial {
|
|
98
|
+
index: number;
|
|
99
|
+
order: ["full" | "selected", "full" | "selected"];
|
|
100
|
+
cacheState: {
|
|
101
|
+
full: CacheState;
|
|
102
|
+
selected: CacheState;
|
|
103
|
+
};
|
|
104
|
+
preparations: CommandMeasurement[];
|
|
105
|
+
full: CommandMeasurement;
|
|
106
|
+
selected: CommandMeasurement;
|
|
107
|
+
provenance: SavingsProvenance;
|
|
108
|
+
}
|
|
109
|
+
export interface FailureEvidenceSummary {
|
|
110
|
+
arm: "full" | "selected";
|
|
111
|
+
trial: number;
|
|
112
|
+
failureClass: FailureClass;
|
|
113
|
+
fingerprint: string;
|
|
114
|
+
}
|
|
115
|
+
export interface FailureAssessment {
|
|
116
|
+
kind: FailureAssessmentKind;
|
|
117
|
+
confidence: "high" | "medium" | "low" | "not-applicable";
|
|
118
|
+
explanation: string;
|
|
119
|
+
evidence: FailureEvidenceSummary[];
|
|
120
|
+
}
|
|
121
|
+
export interface SavingsProvenance {
|
|
122
|
+
baseSha?: string;
|
|
123
|
+
headSha?: string;
|
|
124
|
+
observationSha256?: string;
|
|
125
|
+
observerVersion?: string;
|
|
126
|
+
beforeFull: CheckoutSnapshot;
|
|
127
|
+
afterFull: CheckoutSnapshot;
|
|
128
|
+
afterSelected: CheckoutSnapshot;
|
|
129
|
+
snapshots?: CheckoutSnapshot[];
|
|
130
|
+
checkoutStable: boolean;
|
|
131
|
+
invalidReasons: string[];
|
|
132
|
+
}
|
|
133
|
+
export interface VerifySavingsOptions {
|
|
134
|
+
full: string;
|
|
135
|
+
selected?: string;
|
|
136
|
+
selectedFromReport?: string;
|
|
137
|
+
selectedCommandOverride?: string;
|
|
138
|
+
out: string;
|
|
139
|
+
markdown?: string;
|
|
140
|
+
label?: string;
|
|
141
|
+
cwd: string;
|
|
142
|
+
timeoutMs: number;
|
|
143
|
+
analysisOverheadMs?: number;
|
|
144
|
+
tailBytes: number;
|
|
145
|
+
repetitions?: number;
|
|
146
|
+
cacheState?: Exclude<CacheState, "potentially-warmed">;
|
|
147
|
+
cachePreparationCommand?: string;
|
|
148
|
+
alternateOrder?: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface ResolvedSelection {
|
|
151
|
+
command: string;
|
|
152
|
+
source: "manual" | "diffci-observation";
|
|
153
|
+
observationReportPath?: string;
|
|
154
|
+
selectedTestCount?: number;
|
|
155
|
+
totalTestCount?: number;
|
|
156
|
+
analysisOverheadMs?: number;
|
|
157
|
+
baseSha?: string;
|
|
158
|
+
headSha?: string;
|
|
159
|
+
observationSha256?: string;
|
|
160
|
+
observerVersion?: string;
|
|
161
|
+
}
|
|
162
|
+
export declare function measureCommand(command: string, options: Pick<VerifySavingsOptions, "cwd" | "timeoutMs" | "tailBytes">): CommandMeasurement;
|
|
163
|
+
export declare function buildVerifySavingsReport(input: {
|
|
164
|
+
producedAt?: string;
|
|
165
|
+
label?: string;
|
|
166
|
+
cwd: string;
|
|
167
|
+
timeoutMs: number;
|
|
168
|
+
analysisOverheadMs?: number;
|
|
169
|
+
selection: Omit<ResolvedSelection, "command" | "analysisOverheadMs">;
|
|
170
|
+
full: CommandMeasurement;
|
|
171
|
+
selected: CommandMeasurement;
|
|
172
|
+
provenance?: SavingsProvenance;
|
|
173
|
+
runnerIdentity?: RunnerIdentity;
|
|
174
|
+
protocol?: SavingsProtocol;
|
|
175
|
+
trials?: SavingsTrial[];
|
|
176
|
+
failureAssessment?: FailureAssessment;
|
|
177
|
+
}): VerifySavingsReport;
|
|
178
|
+
export declare function formatGrowthPrompt(report: VerifySavingsReport): string;
|
|
179
|
+
export declare function renderVerifySavingsMarkdown(report: VerifySavingsReport): string;
|
|
180
|
+
export declare function runVerifySavings(options: VerifySavingsOptions): VerifySavingsReport;
|
|
181
|
+
export declare function writeVerifySavingsReport(report: VerifySavingsReport, paths: {
|
|
182
|
+
out: string;
|
|
183
|
+
markdown?: string;
|
|
184
|
+
}): void;
|
|
185
|
+
export declare function formatVerifySavingsSummary(report: VerifySavingsReport): string;
|
|
186
|
+
export {};
|
|
@@ -4,6 +4,7 @@ import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from "n
|
|
|
4
4
|
import { arch, cpus, platform, release, totalmem } from "node:os";
|
|
5
5
|
import { basename, dirname, resolve } from "node:path";
|
|
6
6
|
import { failingTestNames } from "./failure-baseline.js";
|
|
7
|
+
import { runnerTestCount } from "./selected-coverage.js";
|
|
7
8
|
import { classifyFailureFromEvidence, computeFailureFingerprint } from "../preflight/fingerprint.js";
|
|
8
9
|
function tail(value, bytes) {
|
|
9
10
|
if (Buffer.byteLength(value, "utf8") <= bytes)
|
|
@@ -270,6 +271,7 @@ export function measureCommand(command, options) {
|
|
|
270
271
|
const finishedAt = new Date().toISOString();
|
|
271
272
|
const failingTests = result.status === 0 ? [] : failingTestNames(`${result.stdout ?? ""}
|
|
272
273
|
${result.stderr ?? ""}`);
|
|
274
|
+
const testCount = runnerTestCount(result.stdout ?? "");
|
|
273
275
|
return {
|
|
274
276
|
command,
|
|
275
277
|
exitCode: result.status,
|
|
@@ -281,6 +283,7 @@ ${result.stderr ?? ""}`);
|
|
|
281
283
|
stdoutTail: tail(result.stdout ?? "", options.tailBytes),
|
|
282
284
|
stderrTail: tail(result.stderr ?? "", options.tailBytes),
|
|
283
285
|
...(failingTests.length ? { failingTests } : {}),
|
|
286
|
+
...(testCount !== undefined ? { runnerTestCount: testCount } : {}),
|
|
284
287
|
};
|
|
285
288
|
}
|
|
286
289
|
export function buildVerifySavingsReport(input) {
|