dsh-github-copilot 0.4.0-alpha.129 → 0.4.0-alpha.132

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.
@@ -118,6 +118,70 @@ factory in its own isolated realm, sharing the actual public Cordis identity.
118
118
  It does not substitute tagged source for published bytes or attach to a live
119
119
  Client module registry; factory qualification is not Desktop activation proof.
120
120
 
121
+ ## Explicit offline analysis (#368)
122
+
123
+ The package provides a separate, read-only analyzer for one explicitly selected
124
+ aggregate file. Build the package first, then provide an absolute input path, an
125
+ input mode, and a new local output path. The output is created exclusively and
126
+ is never printed to stdout or sent over the network:
127
+
128
+ ```sh
129
+ node scripts/analyze-diagnostics.mjs --input "ABSOLUTE_UNIT_FILE.json" --mode persisted-unit --profile-name "PROFILE_NAME" --output "NEW_LOCAL_REPORT.json"
130
+ ```
131
+
132
+ Replace the quoted placeholders before running; the input must be an absolute
133
+ path whose basename matches the profile-qualified unit filename.
134
+
135
+ For an explicitly reviewed Client/Host Remote view export, use
136
+ `--mode reviewed-view` and omit `--profile-name`. The persisted-unit mode
137
+ requires the unit basename and unit envelope to match the supplied 1–48
138
+ character ASCII DSH profile name; the name is mapped using the same public
139
+ profile-qualified storage-domain convention as the collector. The operator
140
+ must identify the file and profile. The tool never searches DSH homes,
141
+ enumerates storage units, opens a storage-domain writer or RPC, reads Settings,
142
+ credentials or history, or falls back between modes.
143
+
144
+ Both modes reuse the collector's strict Zod snapshot/view vocabulary. The
145
+ reader rejects symlinks and non-files, caps input at 8 MiB, opens only for
146
+ reading, decodes fatal UTF-8, and checks file identity, size and modification
147
+ metadata before and after reading. These checks bound and detect ordinary
148
+ concurrent changes; they do not attest the active Host's backend and cannot
149
+ eliminate every filesystem race. Errors expose fixed diagnostic codes, not
150
+ paths, rejected values or raw filesystem details. The strict versioned report
151
+ contains only validated dimensions, bounded counts and explicit gaps. An
152
+ existing output is never overwritten.
153
+
154
+ Populations stay separate by build version, Client/Host layer and operation,
155
+ including logical/physical pairs. Starts and terminal counters are reported
156
+ independently because UTC-hour aggregation and retention can censor either
157
+ side; pending-start subtraction and exact operation failure rates are never
158
+ calculated. Only terminal observations enter duration bins. Stage-age bins are
159
+ cumulative operation ages, not exclusive phase timings. Client pending samples
160
+ are repeated historical observations, not an outstanding-work gauge; persisted
161
+ Host pending rows describe the stored snapshot, not current live work.
162
+
163
+ Outcomes remain separate, including policy rejection, revocation,
164
+ environment-fault, unknown and interrupted. Safe sums that exceed JavaScript's
165
+ exact integer range become `null` with an overflow gap. Fixed semantic candidate
166
+ fingerprints contain only coverage version, layer, operation, metric and
167
+ allowlisted reason—never identity hashes. Candidates do not prove a regression,
168
+ persistent fault, unique impact or root cause. Reports do not claim calibrated
169
+ thresholds, trends, percentiles, effectiveness or live collection status from
170
+ a persisted-only file. Empty, stale, paused, dirty, saturated, dropped,
171
+ evicted, interrupted and clock-discontinuous evidence remains explicit;
172
+ missing account-switch or compaction observations are gaps, not zero failures.
173
+ A physical summary-call success is explicitly not a native checkpoint commit;
174
+ only the logical compaction population can label a matching checkpoint and end
175
+ as observed success.
176
+
177
+ The first locally qualified persisted snapshot produced a private descriptive
178
+ report outside the repository. It is not a release artifact, CI fixture, issue
179
+ attachment or proof that alpha.128 is installed, loaded, collecting now, or
180
+ representative of current behavior. Do not publish that report or its counts
181
+ without separate sharing approval. Synthetic tests never read production
182
+ storage. There is no scheduler, automatic analysis, upload, issue creation,
183
+ repair or live-profile mutation in this milestone.
184
+
121
185
  ## Archived phase-0 qualification and proposals
122
186
 
123
187
  The remaining sections preserve the reviewed phase-0 inventory. Their proposed
@@ -21,7 +21,7 @@ Reload sees newly registered IDs.
21
21
 
22
22
  ![Actual parent-following and search controls with synthetic settings](images/copilot-search-routing.png)
23
23
 
24
- The picture uses actual published Client components in an isolated browser.
24
+ The picture uses current built Client components in an isolated synthetic browser fixture.
25
25
  It does not demonstrate a live search or loaded Desktop runtime.
26
26
 
27
27
  ## Routing and fallback
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Result and boundaries
6
6
 
7
- One Host-owned OAuth account supplies many account models. The stable managed
7
+ The selected Host-owned OAuth account supplies many account models. The stable managed
8
8
  route ID is `github-copilot-preview`, displayed as **GitHub Copilot**.
9
9
  Fresh installations need no native provider definition. Upgrades preserve
10
10
  existing `llm-pi-ai.providers.github-copilot`; two real groups can remain until
@@ -15,8 +15,9 @@ single-route enforcement; Core Edit/Delete remains. Model discovery/UI lifecycle
15
15
  is described in the [current README](../README.md#install-and-sign-in), not a
16
16
  prerequisite to removing a route.
17
17
 
18
- Keep `llm-pi-ai` and authorization mounted and preserve the sole credential
19
- record `llm-pi-ai/github-copilot`. Do not sign out, delete credentials or remove
18
+ Keep `llm-pi-ai` and authorization mounted and preserve the canonical credential
19
+ record `llm-pi-ai/github-copilot` and any independently authorized saved accounts.
20
+ Do not sign out, delete credentials or remove
20
21
  authorization to hide a group. `models: []` can mean the default catalog, not
21
22
  disabled models.
22
23
 
@@ -111,7 +112,7 @@ may recreate canonical, not a second account.
111
112
 
112
113
  新安装无需原生 provider;升级保留已有 canonical 配置,两组都是真实路由,
113
114
  不是两个账号。迁移只在明确批准后移除审核过的
114
- `llm-pi-ai.providers.github-copilot`;唯一凭据、`llm-pi-ai`、授权服务及其它配置保留。
115
+ `llm-pi-ai.providers.github-copilot`;canonical 凭据、独立授权的已保存账号、`llm-pi-ai`、授权服务及其它配置保留。
115
116
  不要退出登录、删除凭据或使用 `models: []` 来隐藏分组。
116
117
 
117
118
  先验证发布版本已实际加载,再调用无参数 `githubCopilot.migrationStatus()`。
package/lib/client.js CHANGED
@@ -6988,7 +6988,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
6988
6988
  };
6989
6989
  //#endregion
6990
6990
  //#region package.json
6991
- var version = "0.4.0-alpha.129";
6991
+ var version = "0.4.0-alpha.132";
6992
6992
  //#endregion
6993
6993
  //#region lib/types/diagnostics-client.js
6994
6994
  let owner;
@@ -0,0 +1,78 @@
1
+ import { lstat, open } from "node:fs/promises";
2
+ import { isAbsolute } from "node:path";
3
+ import { TextDecoder } from "node:util";
4
+ //#region lib/types/diagnostics-analysis-io.js
5
+ const DIAGNOSTICS_ANALYSIS_MAX_INPUT_BYTES = 8388608;
6
+ const fileSystem = {
7
+ lstat,
8
+ open
9
+ };
10
+ function failure(code) {
11
+ throw new Error(`COPILOT_DIAGNOSTICS_ANALYSIS_${code}`);
12
+ }
13
+ function sameFile(left, right) {
14
+ return left.dev === right.dev && left.ino === right.ino;
15
+ }
16
+ function sameContentState(left, right) {
17
+ return sameFile(left, right) && left.size === right.size && left.mtimeMs === right.mtimeMs;
18
+ }
19
+ async function readBoundedDiagnosticsFile(filePath, io = fileSystem) {
20
+ if (!isAbsolute(filePath)) failure("INVALID_PATH");
21
+ let pathBefore;
22
+ try {
23
+ pathBefore = await io.lstat(filePath);
24
+ } catch {
25
+ failure("FILE_READ_FAILED");
26
+ }
27
+ if (pathBefore.isSymbolicLink()) failure("SYMLINK_REJECTED");
28
+ if (!pathBefore.isFile()) failure("NOT_REGULAR_FILE");
29
+ if (pathBefore.size > 8388608) failure("INPUT_LIMIT");
30
+ let handle;
31
+ try {
32
+ handle = await io.open(filePath, "r");
33
+ } catch {
34
+ failure("FILE_READ_FAILED");
35
+ }
36
+ let text;
37
+ try {
38
+ const before = await handle.stat();
39
+ if (!before.isFile()) failure("NOT_REGULAR_FILE");
40
+ if (before.size > 8388608) failure("INPUT_LIMIT");
41
+ if (!sameContentState(pathBefore, before)) failure("FILE_CHANGED");
42
+ const bytes = Buffer.alloc(8388609);
43
+ let offset = 0;
44
+ while (offset < bytes.length) {
45
+ const { bytesRead } = await handle.read(bytes, offset, bytes.length - offset, offset);
46
+ if (bytesRead === 0) break;
47
+ offset += bytesRead;
48
+ }
49
+ const after = await handle.stat();
50
+ let pathAfter;
51
+ try {
52
+ pathAfter = await io.lstat(filePath);
53
+ } catch {
54
+ failure("FILE_CHANGED");
55
+ }
56
+ if (pathAfter.isSymbolicLink()) failure("SYMLINK_REJECTED");
57
+ if (!pathAfter.isFile() || !after.isFile()) failure("NOT_REGULAR_FILE");
58
+ if (offset > 8388608 || before.size > 8388608 || after.size > 8388608) failure("INPUT_LIMIT");
59
+ if (offset !== before.size || !sameContentState(before, after) || !sameContentState(pathBefore, pathAfter) || !sameFile(pathAfter, after)) failure("FILE_CHANGED");
60
+ try {
61
+ text = new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(0, offset));
62
+ } catch {
63
+ failure("INVALID_UTF8");
64
+ }
65
+ } catch (error) {
66
+ if (error instanceof Error && error.message.startsWith("COPILOT_DIAGNOSTICS_ANALYSIS_")) throw error;
67
+ failure("FILE_READ_FAILED");
68
+ } finally {
69
+ try {
70
+ await handle.close();
71
+ } catch {
72
+ failure("FILE_READ_FAILED");
73
+ }
74
+ }
75
+ return text;
76
+ }
77
+ //#endregion
78
+ export { DIAGNOSTICS_ANALYSIS_MAX_INPUT_BYTES, readBoundedDiagnosticsFile };
@@ -0,0 +1,425 @@
1
+ import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-FVf6zjob.js";
2
+ import { z } from "zod";
3
+ //#region lib/types/diagnostics-analysis.js
4
+ const RETENTION_MS = 12096e5;
5
+ const terminals = [
6
+ "success",
7
+ "no-op",
8
+ "cancelled",
9
+ "policy-rejected",
10
+ "revoked",
11
+ "environment-fault",
12
+ "failed",
13
+ "unknown",
14
+ "interrupted"
15
+ ];
16
+ const gaps = [
17
+ "persisted-only",
18
+ "live-enabled-state-unknown",
19
+ "live-pending-state-unknown",
20
+ "unflushed-tail-unknown",
21
+ "stored-pending-is-not-live",
22
+ "no-retained-operation-observations",
23
+ "account-switch-not-observed",
24
+ "compaction-not-observed",
25
+ "stale-snapshot",
26
+ "expired-in-stored-snapshot",
27
+ "host-dropped",
28
+ "client-dropped",
29
+ "client-unconfirmed",
30
+ "retention-or-capacity-eviction",
31
+ "collector-saturated",
32
+ "interrupted-observations",
33
+ "clock-discontinuity",
34
+ "recorded-pause",
35
+ "unpersisted-observations",
36
+ "collection-paused",
37
+ "storage-not-ready",
38
+ "analysis-count-overflow",
39
+ "no-cross-layer-correlation",
40
+ "no-unique-impact",
41
+ "hour-boundary-censoring",
42
+ "no-collection-coverage-clock",
43
+ "no-calibrated-alert-thresholds",
44
+ "no-baseline-trend",
45
+ "no-root-cause-proof"
46
+ ];
47
+ const intervals = [
48
+ {
49
+ lowerMs: 0,
50
+ upperExclusiveMs: 100
51
+ },
52
+ {
53
+ lowerMs: 100,
54
+ upperExclusiveMs: 500
55
+ },
56
+ {
57
+ lowerMs: 500,
58
+ upperExclusiveMs: 1e3
59
+ },
60
+ {
61
+ lowerMs: 1e3,
62
+ upperExclusiveMs: 5e3
63
+ },
64
+ {
65
+ lowerMs: 5e3,
66
+ upperExclusiveMs: 15e3
67
+ },
68
+ {
69
+ lowerMs: 15e3,
70
+ upperExclusiveMs: 6e4
71
+ },
72
+ {
73
+ lowerMs: 6e4,
74
+ upperExclusiveMs: 3e5
75
+ },
76
+ {
77
+ lowerMs: 3e5,
78
+ upperExclusiveMs: null
79
+ }
80
+ ];
81
+ const CountSchema = z.object({
82
+ value: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable(),
83
+ overflow: z.boolean()
84
+ }).strict().refine((value) => value.overflow === (value.value === null));
85
+ const outcomeSchema = z.object({
86
+ success: CountSchema,
87
+ "no-op": CountSchema,
88
+ cancelled: CountSchema,
89
+ "policy-rejected": CountSchema,
90
+ revoked: CountSchema,
91
+ "environment-fault": CountSchema,
92
+ failed: CountSchema,
93
+ unknown: CountSchema,
94
+ interrupted: CountSchema
95
+ }).strict();
96
+ const intervalSchema = z.object({
97
+ lowerMs: z.number().int().nonnegative(),
98
+ upperExclusiveMs: z.number().int().positive().nullable(),
99
+ count: CountSchema
100
+ }).strict().refine((value) => value.upperExclusiveMs === null || value.lowerMs < value.upperExclusiveMs);
101
+ const populationSchema = z.object({
102
+ version: z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/),
103
+ layer: z.enum(["client", "host"]),
104
+ operation: z.enum(DIAGNOSTICS_OPERATIONS),
105
+ successMeaning: z.enum([
106
+ "owner-terminal-observation-only",
107
+ "matching-checkpoint-and-end-observed",
108
+ "summary-call-fulfilled-not-checkpoint-commit"
109
+ ]),
110
+ firstHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
111
+ lastHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
112
+ started: CountSchema,
113
+ terminalObservations: CountSchema,
114
+ outcomes: outcomeSchema,
115
+ terminalLatency: z.array(intervalSchema).length(8),
116
+ stageAgeObservations: z.array(intervalSchema).length(8),
117
+ pendingSamples: CountSchema,
118
+ pendingSampleAges: z.array(intervalSchema).length(8),
119
+ stageObservations: CountSchema,
120
+ startsMinusTerminals: z.null(),
121
+ exactOperationFailureRate: z.null()
122
+ }).strict().refine((value) => value.firstHour <= value.lastHour).refine((value) => value.successMeaning === (value.operation === "compaction" ? "matching-checkpoint-and-end-observed" : value.operation === "compaction-summary" ? "summary-call-fulfilled-not-checkpoint-commit" : "owner-terminal-observation-only"));
123
+ const candidateSchema = z.object({
124
+ fingerprint: z.string().max(256).regex(/^coverage-1\|(?:client|host)\|[a-z-]+\|(?:failed|environment-fault|unknown)\|[A-Za-z0-9_-]+$/),
125
+ category: z.enum(["recorded-failure", "unknown-outcome"]),
126
+ layer: z.enum(["client", "host"]),
127
+ operation: z.enum(DIAGNOSTICS_OPERATIONS),
128
+ metric: z.enum([
129
+ "failed",
130
+ "environment-fault",
131
+ "unknown"
132
+ ]),
133
+ reason: z.enum(DIAGNOSTICS_REASONS),
134
+ versions: z.array(z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/)).max(4096),
135
+ firstHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
136
+ lastHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
137
+ observations: CountSchema,
138
+ regressionProven: z.literal(false),
139
+ persistentFaultProven: z.literal(false),
140
+ rootCause: z.literal("unknown")
141
+ }).strict().refine((value) => value.firstHour <= value.lastHour).refine((value) => value.fingerprint === `coverage-1|${value.layer}|${value.operation}|${value.metric}|${value.reason}`).refine((value) => value.category === (value.metric === "unknown" ? "unknown-outcome" : "recorded-failure"));
142
+ const collectionSchema = z.object({
143
+ enabled: z.boolean().nullable(),
144
+ state: z.enum([
145
+ "loading",
146
+ "ready",
147
+ "unavailable",
148
+ "error"
149
+ ]).nullable(),
150
+ diagnostic: z.enum([
151
+ "none",
152
+ "storage-unavailable",
153
+ "storage-invalid",
154
+ "storage-write-failed",
155
+ "profile-unavailable",
156
+ "settings-unavailable",
157
+ "settings-conflict",
158
+ "client-report-failed",
159
+ "client-report-revoked",
160
+ "closed"
161
+ ]).nullable(),
162
+ dirty: z.boolean().nullable(),
163
+ persistedAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable()
164
+ }).strict();
165
+ const DiagnosticsAnalysisReportSchema = z.object({
166
+ reportVersion: z.literal(1),
167
+ coverageVersion: z.literal(1),
168
+ interpretation: z.literal("descriptive-observations-only"),
169
+ source: z.enum(["reviewed-view", "persisted-snapshot"]),
170
+ observedAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
171
+ snapshotAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
172
+ ageMs: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable(),
173
+ epoch: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
174
+ coverageComplete: z.literal(false),
175
+ effectivenessVerified: z.literal(false),
176
+ gaps: z.array(z.enum(gaps)).max(gaps.length),
177
+ collection: collectionSchema,
178
+ counters: z.object({
179
+ dropped: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
180
+ clientDropped: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
181
+ clientUnconfirmed: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
182
+ evicted: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
183
+ saturated: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
184
+ interrupted: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
185
+ }).strict(),
186
+ populations: z.array(populationSchema).max(4096),
187
+ pendingAtSnapshot: z.array(DiagnosticsPendingSchema).max(128),
188
+ investigationCandidates: z.array(candidateSchema).max(4096)
189
+ }).strict().refine((value) => new Set(value.gaps).size === value.gaps.length);
190
+ function sum(values) {
191
+ const total = values.reduce((value, next) => value + BigInt(next), 0n);
192
+ return total > BigInt(Number.MAX_SAFE_INTEGER) ? {
193
+ value: null,
194
+ overflow: true
195
+ } : {
196
+ value: Number(total),
197
+ overflow: false
198
+ };
199
+ }
200
+ function parseSnapshot(input) {
201
+ const parsed = DiagnosticsSnapshotSchema.safeParse(input);
202
+ if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_SNAPSHOT");
203
+ const tuples = /* @__PURE__ */ new Set();
204
+ for (const row of parsed.data.rows) {
205
+ const tuple = [
206
+ row.hour,
207
+ row.version,
208
+ row.layer,
209
+ row.operation,
210
+ row.stage,
211
+ row.metric,
212
+ row.reason,
213
+ row.bucket
214
+ ].join("|");
215
+ if (tuples.has(tuple)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_DUPLICATE_AGGREGATE");
216
+ tuples.add(tuple);
217
+ }
218
+ return parsed.data;
219
+ }
220
+ function parseJsonText(text) {
221
+ if (Buffer.byteLength(text, "utf8") > 8388608) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INPUT_LIMIT");
222
+ try {
223
+ return JSON.parse(text);
224
+ } catch {
225
+ throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_JSON");
226
+ }
227
+ }
228
+ function order(left, right) {
229
+ return left < right ? -1 : left > right ? 1 : 0;
230
+ }
231
+ function diagnosticsUnitName(profileName) {
232
+ if (!/^[a-zA-Z0-9_-]{1,48}$/.test(profileName)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_PROFILE");
233
+ return `github_copilot_diagnostics_${Buffer.from(profileName, "ascii").toString("hex")}`;
234
+ }
235
+ function parseReviewedView(text) {
236
+ const parsed = DiagnosticsViewSchema.safeParse(parseJsonText(text));
237
+ if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_VIEW");
238
+ return parsed.data;
239
+ }
240
+ function parsePersistedUnit(text, expectedUnit) {
241
+ if (!/^github_copilot_diagnostics_(?:[a-f0-9]{2}){1,48}$/.test(expectedUnit)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_UNIT");
242
+ const input = parseJsonText(text);
243
+ if (typeof input !== "object" || input === null || Array.isArray(input) || Object.keys(input).sort().join(",") !== "global,tables,unit" || !("unit" in input) || typeof input.unit !== "object" || input.unit === null || Array.isArray(input.unit) || Object.keys(input.unit).sort().join(",") !== "name,version" || !("name" in input.unit) || input.unit.name !== expectedUnit || !("version" in input.unit) || input.unit.version !== 1 || !("tables" in input) || typeof input.tables !== "object" || input.tables === null || Array.isArray(input.tables) || Object.keys(input.tables).length !== 0 || !("global" in input)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_UNIT");
244
+ return parseSnapshot(input.global);
245
+ }
246
+ function analyzeSnapshot(input, options) {
247
+ if (!Number.isSafeInteger(options.observedAt) || options.observedAt < 0 || !["reviewed-view", "persisted-snapshot"].includes(options.source) || options.source === "reviewed-view" !== (options.view !== void 0)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_OPTIONS");
248
+ const snapshot = parseSnapshot(input);
249
+ const rows = [...snapshot.rows].sort((a, b) => order(a.version, b.version) || order(a.layer, b.layer) || order(a.operation, b.operation) || a.hour - b.hour || order(a.stage, b.stage) || order(a.metric, b.metric) || order(a.reason, b.reason) || a.bucket - b.bucket);
250
+ const groups = /* @__PURE__ */ new Map();
251
+ for (const row of rows) {
252
+ if (row.operation === "collection") continue;
253
+ const key = `${row.version}|${row.layer}|${row.operation}`;
254
+ const population = groups.get(key) ?? [];
255
+ population.push(row);
256
+ groups.set(key, population);
257
+ }
258
+ const populations = [...groups.values()].map((population) => {
259
+ const first = population[0];
260
+ const terminalRows = population.filter((row) => terminals.some((metric) => metric === row.metric));
261
+ const outcomes = Object.fromEntries(terminals.map((metric) => [metric, sum(population.filter((row) => row.metric === metric).map((row) => row.count))]));
262
+ return {
263
+ version: first.version,
264
+ layer: first.layer,
265
+ operation: first.operation,
266
+ successMeaning: first.operation === "compaction" ? "matching-checkpoint-and-end-observed" : first.operation === "compaction-summary" ? "summary-call-fulfilled-not-checkpoint-commit" : "owner-terminal-observation-only",
267
+ firstHour: Math.min(...population.map((row) => row.hour)),
268
+ lastHour: Math.max(...population.map((row) => row.hour)),
269
+ started: sum(population.filter((row) => row.metric === "started").map((row) => row.count)),
270
+ terminalObservations: sum(terminalRows.map((row) => row.count)),
271
+ outcomes,
272
+ terminalLatency: intervals.map((interval, bucket) => ({
273
+ ...interval,
274
+ count: sum(terminalRows.filter((row) => row.bucket === bucket).map((row) => row.count))
275
+ })),
276
+ stageAgeObservations: intervals.map((interval, bucket) => ({
277
+ ...interval,
278
+ count: sum(population.filter((row) => row.metric === "stage" && row.bucket === bucket).map((row) => row.count))
279
+ })),
280
+ pendingSamples: sum(population.filter((row) => row.metric === "pending-sample").map((row) => row.count)),
281
+ pendingSampleAges: intervals.map((interval, bucket) => ({
282
+ ...interval,
283
+ count: sum(population.filter((row) => row.metric === "pending-sample" && row.bucket === bucket).map((row) => row.count))
284
+ })),
285
+ stageObservations: sum(population.filter((row) => row.metric === "stage").map((row) => row.count)),
286
+ startsMinusTerminals: null,
287
+ exactOperationFailureRate: null
288
+ };
289
+ });
290
+ const candidates = /* @__PURE__ */ new Map();
291
+ for (const row of rows) {
292
+ if (row.metric !== "failed" && row.metric !== "environment-fault" && row.metric !== "unknown" || row.operation === "collection") continue;
293
+ const metric = row.metric;
294
+ const fingerprint = `coverage-1|${row.layer}|${row.operation}|${metric}|${row.reason}`;
295
+ const candidate = candidates.get(fingerprint) ?? {
296
+ fingerprint,
297
+ category: metric === "unknown" ? "unknown-outcome" : "recorded-failure",
298
+ layer: row.layer,
299
+ operation: row.operation,
300
+ metric,
301
+ reason: row.reason,
302
+ versions: [],
303
+ hours: [],
304
+ counts: []
305
+ };
306
+ candidate.versions.push(row.version);
307
+ candidate.hours.push(row.hour);
308
+ candidate.counts.push(row.count);
309
+ candidates.set(fingerprint, candidate);
310
+ }
311
+ const gapSet = /* @__PURE__ */ new Set([
312
+ "no-cross-layer-correlation",
313
+ "no-unique-impact",
314
+ "hour-boundary-censoring",
315
+ "no-collection-coverage-clock",
316
+ "no-calibrated-alert-thresholds",
317
+ "no-baseline-trend",
318
+ "no-root-cause-proof"
319
+ ]);
320
+ const view = options.view;
321
+ if (options.source === "persisted-snapshot") {
322
+ gapSet.add("persisted-only");
323
+ gapSet.add("live-enabled-state-unknown");
324
+ gapSet.add("live-pending-state-unknown");
325
+ gapSet.add("unflushed-tail-unknown");
326
+ if (snapshot.pending.length) gapSet.add("stored-pending-is-not-live");
327
+ }
328
+ if (!populations.length) gapSet.add("no-retained-operation-observations");
329
+ if (!populations.some((row) => [
330
+ "account-global-switch",
331
+ "account-session-select",
332
+ "account-session-inherit"
333
+ ].includes(row.operation))) gapSet.add("account-switch-not-observed");
334
+ if (!populations.some((row) => row.operation === "compaction" || row.operation === "compaction-summary")) gapSet.add("compaction-not-observed");
335
+ if (snapshot.updatedAt <= options.observedAt - RETENTION_MS) gapSet.add("stale-snapshot");
336
+ if (snapshot.rows.some((row) => row.hour <= options.observedAt - RETENTION_MS)) gapSet.add("expired-in-stored-snapshot");
337
+ if (snapshot.dropped) gapSet.add("host-dropped");
338
+ if (snapshot.clientDropped) gapSet.add("client-dropped");
339
+ if (snapshot.clientUnconfirmed) gapSet.add("client-unconfirmed");
340
+ if (snapshot.evicted) gapSet.add("retention-or-capacity-eviction");
341
+ if (snapshot.saturated) gapSet.add("collector-saturated");
342
+ if (snapshot.interrupted || snapshot.rows.some((row) => row.metric === "interrupted")) gapSet.add("interrupted-observations");
343
+ if (snapshot.rows.some((row) => row.metric === "clock-discontinuity") || snapshot.updatedAt > options.observedAt || snapshot.rows.some((row) => row.hour > options.observedAt)) gapSet.add("clock-discontinuity");
344
+ if (snapshot.rows.some((row) => row.metric === "paused")) gapSet.add("recorded-pause");
345
+ if (view?.dirty) gapSet.add("unpersisted-observations");
346
+ if (view && !view.enabled) gapSet.add("collection-paused");
347
+ if (view && view.state !== "ready") gapSet.add("storage-not-ready");
348
+ const report = {
349
+ reportVersion: 1,
350
+ coverageVersion: 1,
351
+ interpretation: "descriptive-observations-only",
352
+ source: options.source,
353
+ observedAt: options.observedAt,
354
+ snapshotAt: snapshot.updatedAt,
355
+ ageMs: snapshot.updatedAt <= options.observedAt ? options.observedAt - snapshot.updatedAt : null,
356
+ epoch: snapshot.epoch,
357
+ coverageComplete: false,
358
+ effectivenessVerified: false,
359
+ gaps: [...gapSet],
360
+ collection: {
361
+ enabled: view?.enabled ?? null,
362
+ state: view?.state ?? null,
363
+ diagnostic: view?.diagnostic ?? null,
364
+ dirty: view?.dirty ?? null,
365
+ persistedAt: view?.persistedAt ?? null
366
+ },
367
+ counters: {
368
+ dropped: snapshot.dropped,
369
+ clientDropped: snapshot.clientDropped,
370
+ clientUnconfirmed: snapshot.clientUnconfirmed,
371
+ evicted: snapshot.evicted,
372
+ saturated: snapshot.saturated,
373
+ interrupted: snapshot.interrupted
374
+ },
375
+ populations,
376
+ pendingAtSnapshot: snapshot.pending,
377
+ investigationCandidates: [...candidates.values()].map((candidate) => ({
378
+ fingerprint: candidate.fingerprint,
379
+ category: candidate.category,
380
+ layer: candidate.layer,
381
+ operation: candidate.operation,
382
+ metric: candidate.metric,
383
+ reason: candidate.reason,
384
+ versions: [...new Set(candidate.versions)].sort(order),
385
+ firstHour: Math.min(...candidate.hours),
386
+ lastHour: Math.max(...candidate.hours),
387
+ observations: sum(candidate.counts),
388
+ regressionProven: false,
389
+ persistentFaultProven: false,
390
+ rootCause: "unknown"
391
+ }))
392
+ };
393
+ const parsed = DiagnosticsAnalysisReportSchema.safeParse(report);
394
+ if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_REPORT");
395
+ if (populations.some((population) => [
396
+ population.started,
397
+ population.terminalObservations,
398
+ population.stageObservations,
399
+ population.pendingSamples,
400
+ ...Object.values(population.outcomes),
401
+ ...population.terminalLatency.map((bin) => bin.count),
402
+ ...population.stageAgeObservations.map((bin) => bin.count),
403
+ ...population.pendingSampleAges.map((bin) => bin.count)
404
+ ].some((count) => count.overflow)) || report.investigationCandidates.some((candidate) => candidate.observations.overflow)) gapSet.add("analysis-count-overflow");
405
+ if (gapSet.has("analysis-count-overflow")) {
406
+ const corrected = DiagnosticsAnalysisReportSchema.safeParse({
407
+ ...parsed.data,
408
+ gaps: [...gapSet]
409
+ });
410
+ if (!corrected.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_REPORT");
411
+ return corrected.data;
412
+ }
413
+ return parsed.data;
414
+ }
415
+ function analyzeReviewedView(view, observedAt) {
416
+ const parsed = DiagnosticsViewSchema.safeParse(view);
417
+ if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_VIEW");
418
+ return analyzeSnapshot(parsed.data.snapshot, {
419
+ source: "reviewed-view",
420
+ observedAt,
421
+ view: parsed.data
422
+ });
423
+ }
424
+ //#endregion
425
+ export { DiagnosticsAnalysisReportSchema, analyzeReviewedView, analyzeSnapshot, diagnosticsUnitName, parsePersistedUnit, parseReviewedView };