dsh-github-copilot 0.1.0-alpha.1.dsh.0.2.1.alpha.5
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/AGENTS.md +439 -0
- package/CHANGELOG.md +875 -0
- package/CONTRIBUTING.md +55 -0
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/README.zh.md +341 -0
- package/SECURITY.md +29 -0
- package/cordis.patch.yml +16 -0
- package/deployment-baseline.json +1580 -0
- package/docs/account-management-experience.md +143 -0
- package/docs/agent-readiness.md +110 -0
- package/docs/auto-high-cost.md +255 -0
- package/docs/auto-iteration-review.json +22 -0
- package/docs/auto-review-sampling.md +60 -0
- package/docs/auto-task-routing.md +341 -0
- package/docs/automatic-model-routing.md +236 -0
- package/docs/copilot-accounts.md +424 -0
- package/docs/copilot-compaction.md +148 -0
- package/docs/copilot-usage.md +133 -0
- package/docs/dual-model.md +66 -0
- package/docs/evidence-driven-iteration.md +86 -0
- package/docs/image-input-compatibility.md +64 -0
- package/docs/images/copilot-accounts-credits.png +0 -0
- package/docs/images/copilot-accounts.png +0 -0
- package/docs/images/copilot-current-provenance.json +39 -0
- package/docs/images/copilot-model-preferences.png +0 -0
- package/docs/images/copilot-search-routing.png +0 -0
- package/docs/images/copilot-session-continuation.png +0 -0
- package/docs/images/dual-model-desktop.png +0 -0
- package/docs/images/dual-model-mobile.png +0 -0
- package/docs/images/dual-model-provenance.json +35 -0
- package/docs/images/parent-model-follow.png +0 -0
- package/docs/manual-compaction-recovery.md +109 -0
- package/docs/mockups/copilot-account-dropdown.html +71 -0
- package/docs/mockups/copilot-account-management.html +393 -0
- package/docs/model-compatibility-acceptance.md +182 -0
- package/docs/npm-distribution.md +202 -0
- package/docs/official-first-016-alpha2.md +66 -0
- package/docs/official-first-020-rc1.md +32 -0
- package/docs/official-first-020-rc2.md +17 -0
- package/docs/official-first-021-alpha4.md +157 -0
- package/docs/official-first-021-alpha5.md +83 -0
- package/docs/plugin-diagnostics.md +605 -0
- package/docs/session-continuation.md +141 -0
- package/docs/session-search-routing.md +133 -0
- package/docs/single-route-migration.md +131 -0
- package/docs/web-lifecycle-rc2.md +55 -0
- package/lib/client.js +13236 -0
- package/lib/client.js.map +1 -0
- package/lib/copilot-identity-DRZY_d2X.js +15 -0
- package/lib/diagnostics-analysis-io.js +78 -0
- package/lib/diagnostics-analysis.js +427 -0
- package/lib/diagnostics-types-CF-qg8Do.js +708 -0
- package/lib/index.js +15661 -0
- package/lib/manual-compaction-recovery.js +485 -0
- package/lib/remote.js +1507 -0
- package/lib/request-budget-DLY_aRq0.js +87 -0
- package/lib/routed-web.js +120 -0
- package/lib/search-routing-CV2hs8as.js +792 -0
- package/lib/types/account-dropdown.d.ts +22 -0
- package/lib/types/account-model-auth.d.ts +15 -0
- package/lib/types/account-model-catalog.d.ts +70 -0
- package/lib/types/account-model-source.d.ts +85 -0
- package/lib/types/agent-compaction.d.ts +4 -0
- package/lib/types/authorization-code-clipboard.d.ts +4 -0
- package/lib/types/authorization-controller.d.ts +121 -0
- package/lib/types/auto-allocation-card.d.ts +9 -0
- package/lib/types/auto-allocation-diagnostics.d.ts +126 -0
- package/lib/types/auto-allocation-evidence.d.ts +44 -0
- package/lib/types/auto-allocation.d.ts +47 -0
- package/lib/types/auto-assessment-evidence.d.ts +111 -0
- package/lib/types/auto-model-host.d.ts +30 -0
- package/lib/types/auto-model-intent.d.ts +36 -0
- package/lib/types/auto-model-presentation.d.ts +57 -0
- package/lib/types/auto-model-routing.d.ts +64 -0
- package/lib/types/auto-review-sampling.d.ts +6 -0
- package/lib/types/auto-selection-explanation.d.ts +9 -0
- package/lib/types/auto-task-assessment.d.ts +49 -0
- package/lib/types/auto-task-classifier.d.ts +10 -0
- package/lib/types/background-compaction.d.ts +30 -0
- package/lib/types/client.d.ts +129 -0
- package/lib/types/compact-account.d.ts +42 -0
- package/lib/types/compaction-continuation-ui.d.ts +29 -0
- package/lib/types/compaction-continuation.d.ts +48 -0
- package/lib/types/compaction-input-estimate.d.ts +28 -0
- package/lib/types/compaction-pressure.d.ts +23 -0
- package/lib/types/compaction-replay.d.ts +18 -0
- package/lib/types/compatibility.d.ts +17 -0
- package/lib/types/composer-notice-style.d.ts +7 -0
- package/lib/types/config.d.ts +141 -0
- package/lib/types/content-file.d.ts +10 -0
- package/lib/types/context-evidence-ui.d.ts +28 -0
- package/lib/types/context-evidence.d.ts +256 -0
- package/lib/types/context-usage.d.ts +4 -0
- package/lib/types/copilot-account-presentation.d.ts +7 -0
- package/lib/types/copilot-accounts-card.d.ts +43 -0
- package/lib/types/copilot-accounts-host.d.ts +93 -0
- package/lib/types/copilot-accounts-remote.d.ts +85 -0
- package/lib/types/copilot-accounts-types.d.ts +43 -0
- package/lib/types/copilot-auth.d.ts +31 -0
- package/lib/types/copilot-grant.d.ts +11 -0
- package/lib/types/copilot-identity.d.ts +11 -0
- package/lib/types/copilot-request.d.ts +11 -0
- package/lib/types/copilot-stream-liveness.d.ts +23 -0
- package/lib/types/copilot-usage-card.d.ts +51 -0
- package/lib/types/copilot-usage-host.d.ts +61 -0
- package/lib/types/copilot-usage-normalize.d.ts +9 -0
- package/lib/types/copilot-usage-remote.d.ts +63 -0
- package/lib/types/copilot-usage-types.d.ts +20 -0
- package/lib/types/copilot-usage-ui.d.ts +4 -0
- package/lib/types/current-provider.d.ts +59 -0
- package/lib/types/deepseek-search-fallback.d.ts +11 -0
- package/lib/types/diagnostics-analysis-io.d.ts +23 -0
- package/lib/types/diagnostics-analysis.d.ts +298 -0
- package/lib/types/diagnostics-card.d.ts +12 -0
- package/lib/types/diagnostics-client.d.ts +13 -0
- package/lib/types/diagnostics-collector.d.ts +50 -0
- package/lib/types/diagnostics-host.d.ts +183 -0
- package/lib/types/diagnostics-remote.d.ts +113 -0
- package/lib/types/diagnostics-types.d.ts +893 -0
- package/lib/types/dual-model-host.d.ts +119 -0
- package/lib/types/dual-model-remote.d.ts +63 -0
- package/lib/types/dual-model-types.d.ts +34 -0
- package/lib/types/external-link.d.ts +3 -0
- package/lib/types/failure.d.ts +38 -0
- package/lib/types/http.d.ts +48 -0
- package/lib/types/image-input-admission.d.ts +5 -0
- package/lib/types/index.d.ts +39 -0
- package/lib/types/manual-compaction-recovery.d.ts +67 -0
- package/lib/types/migration-status.d.ts +50 -0
- package/lib/types/model-exclusions.d.ts +15 -0
- package/lib/types/model-preferences-card.d.ts +9 -0
- package/lib/types/model-protocol.d.ts +31 -0
- package/lib/types/native-select-style.d.ts +4 -0
- package/lib/types/native-settings-style.d.ts +10 -0
- package/lib/types/parent-model-follow-card.d.ts +32 -0
- package/lib/types/parent-model-follow.d.ts +44 -0
- package/lib/types/pi-provider-bridge.d.ts +22 -0
- package/lib/types/plan.d.ts +148 -0
- package/lib/types/pre-step-pressure.d.ts +8 -0
- package/lib/types/preview-provider.d.ts +77 -0
- package/lib/types/preview-route.d.ts +76 -0
- package/lib/types/probe.d.ts +39 -0
- package/lib/types/remote-codec.d.ts +10 -0
- package/lib/types/remote.d.ts +202 -0
- package/lib/types/replay-recovery-host.d.ts +28 -0
- package/lib/types/replay-recovery-remote.d.ts +14 -0
- package/lib/types/replay-recovery-types.d.ts +24 -0
- package/lib/types/replay-recovery-ui.d.ts +28 -0
- package/lib/types/replay-recovery.d.ts +17 -0
- package/lib/types/request-body-composition.d.ts +17 -0
- package/lib/types/request-body-evidence.d.ts +37 -0
- package/lib/types/request-body-timeout-marker.d.ts +2 -0
- package/lib/types/request-body-timeout.d.ts +4 -0
- package/lib/types/request-budget.d.ts +58 -0
- package/lib/types/request-diagnostics.d.ts +278 -0
- package/lib/types/request-upload-evidence.d.ts +23 -0
- package/lib/types/response-error-body.d.ts +3 -0
- package/lib/types/responses-reasoning-text.d.ts +24 -0
- package/lib/types/responses-reasoning.d.ts +7 -0
- package/lib/types/responses-replay-compat.d.ts +31 -0
- package/lib/types/responses-request-compression.d.ts +33 -0
- package/lib/types/route-ownership.d.ts +70 -0
- package/lib/types/routed-web.d.ts +50 -0
- package/lib/types/search-backend.d.ts +16 -0
- package/lib/types/search-routing-host.d.ts +19 -0
- package/lib/types/search-routing-policy.d.ts +18 -0
- package/lib/types/search-routing-remote.d.ts +20 -0
- package/lib/types/search-routing.d.ts +43 -0
- package/lib/types/search-tool-routing.d.ts +22 -0
- package/lib/types/serialize.d.ts +106 -0
- package/lib/types/session-accounts-controller.d.ts +20 -0
- package/lib/types/session-accounts-host.d.ts +33 -0
- package/lib/types/session-accounts-remote.d.ts +114 -0
- package/lib/types/session-accounts.d.ts +38 -0
- package/lib/types/session-continuation-host.d.ts +45 -0
- package/lib/types/session-continuation-remote.d.ts +22 -0
- package/lib/types/session-continuation-types.d.ts +62 -0
- package/lib/types/session-continuation-ui.d.ts +49 -0
- package/lib/types/session-continuation.d.ts +14 -0
- package/lib/types/settings-reader.d.ts +16 -0
- package/lib/types/sse.d.ts +28 -0
- package/lib/types/temporary-models.d.ts +25 -0
- package/lib/types/tool-schema-compat.d.ts +17 -0
- package/lib/types/traditional-search.d.ts +17 -0
- package/lib/types/turn-model-provenance.d.ts +45 -0
- package/lib/types/turn-request-models.d.ts +55 -0
- package/lib/types/turn-selection-card.d.ts +24 -0
- package/lib/types/turn-selection-host.d.ts +35 -0
- package/lib/types/turn-selection-remote.d.ts +17 -0
- package/lib/types/turn-selection.d.ts +186 -0
- package/lib/types/turn-usage-evidence.d.ts +66 -0
- package/lib/types/turn-usage-notice.d.ts +7 -0
- package/lib/types/types.d.ts +69 -0
- package/lib/types/usage.d.ts +26 -0
- package/lib/types/watchdog.d.ts +22 -0
- package/lib/types/web-delegate.d.ts +12 -0
- package/lib/types/web-search-routing-card.d.ts +16 -0
- package/lib/types/web-search-routing-config.d.ts +12 -0
- package/lib/types/wire-anthropic.d.ts +37 -0
- package/lib/types/wire.d.ts +56 -0
- package/lib/web-delegate.js +9 -0
- package/output/auto-model-mockup/index.html +207 -0
- package/package.json +261 -0
- package/scripts/analyze-diagnostics.mjs +91 -0
- package/scripts/check-search-composition.mjs +191 -0
- package/scripts/iteration-review.mjs +53 -0
- package/scripts/release-policy.mjs +353 -0
- package/scripts/select-core-release.mjs +11 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region lib/types/copilot-identity.js
|
|
2
|
+
/** Native OAuth ownership and the sole plugin-owned, account-discovered route. */
|
|
3
|
+
const GITHUB_COPILOT_CREDENTIAL_KEY = "llm-pi-ai/github-copilot";
|
|
4
|
+
const GITHUB_COPILOT_PROVIDER_ID = "github-copilot";
|
|
5
|
+
const GITHUB_COPILOT_PREVIEW_PROVIDER_ID = "github-copilot-preview";
|
|
6
|
+
const GITHUB_COPILOT_AUTO_MODEL_ID = "auto";
|
|
7
|
+
const GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID = "auto-efficiency";
|
|
8
|
+
const GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID = "auto-intelligence";
|
|
9
|
+
function autoModelPreference(model) {
|
|
10
|
+
if (model === "auto") return "balance";
|
|
11
|
+
if (model === "auto-efficiency") return "efficiency";
|
|
12
|
+
if (model === "auto-intelligence") return "intelligence";
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { GITHUB_COPILOT_PREVIEW_PROVIDER_ID as a, GITHUB_COPILOT_CREDENTIAL_KEY as i, GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID as n, GITHUB_COPILOT_PROVIDER_ID as o, GITHUB_COPILOT_AUTO_MODEL_ID as r, autoModelPreference as s, GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID as t };
|
|
@@ -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,427 @@
|
|
|
1
|
+
import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-CF-qg8Do.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
|
+
"request-observations-not-analyzed"
|
|
47
|
+
];
|
|
48
|
+
const intervals = [
|
|
49
|
+
{
|
|
50
|
+
lowerMs: 0,
|
|
51
|
+
upperExclusiveMs: 100
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
lowerMs: 100,
|
|
55
|
+
upperExclusiveMs: 500
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
lowerMs: 500,
|
|
59
|
+
upperExclusiveMs: 1e3
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
lowerMs: 1e3,
|
|
63
|
+
upperExclusiveMs: 5e3
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
lowerMs: 5e3,
|
|
67
|
+
upperExclusiveMs: 15e3
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
lowerMs: 15e3,
|
|
71
|
+
upperExclusiveMs: 6e4
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
lowerMs: 6e4,
|
|
75
|
+
upperExclusiveMs: 3e5
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
lowerMs: 3e5,
|
|
79
|
+
upperExclusiveMs: null
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
const CountSchema = z.object({
|
|
83
|
+
value: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
84
|
+
overflow: z.boolean()
|
|
85
|
+
}).strict().refine((value) => value.overflow === (value.value === null));
|
|
86
|
+
const outcomeSchema = z.object({
|
|
87
|
+
success: CountSchema,
|
|
88
|
+
"no-op": CountSchema,
|
|
89
|
+
cancelled: CountSchema,
|
|
90
|
+
"policy-rejected": CountSchema,
|
|
91
|
+
revoked: CountSchema,
|
|
92
|
+
"environment-fault": CountSchema,
|
|
93
|
+
failed: CountSchema,
|
|
94
|
+
unknown: CountSchema,
|
|
95
|
+
interrupted: CountSchema
|
|
96
|
+
}).strict();
|
|
97
|
+
const intervalSchema = z.object({
|
|
98
|
+
lowerMs: z.number().int().nonnegative(),
|
|
99
|
+
upperExclusiveMs: z.number().int().positive().nullable(),
|
|
100
|
+
count: CountSchema
|
|
101
|
+
}).strict().refine((value) => value.upperExclusiveMs === null || value.lowerMs < value.upperExclusiveMs);
|
|
102
|
+
const populationSchema = z.object({
|
|
103
|
+
version: z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/),
|
|
104
|
+
layer: z.enum(["client", "host"]),
|
|
105
|
+
operation: z.enum(DIAGNOSTICS_OPERATIONS),
|
|
106
|
+
successMeaning: z.enum([
|
|
107
|
+
"owner-terminal-observation-only",
|
|
108
|
+
"matching-checkpoint-and-end-observed",
|
|
109
|
+
"summary-call-fulfilled-not-checkpoint-commit"
|
|
110
|
+
]),
|
|
111
|
+
firstHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
112
|
+
lastHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
113
|
+
started: CountSchema,
|
|
114
|
+
terminalObservations: CountSchema,
|
|
115
|
+
outcomes: outcomeSchema,
|
|
116
|
+
terminalLatency: z.array(intervalSchema).length(8),
|
|
117
|
+
stageAgeObservations: z.array(intervalSchema).length(8),
|
|
118
|
+
pendingSamples: CountSchema,
|
|
119
|
+
pendingSampleAges: z.array(intervalSchema).length(8),
|
|
120
|
+
stageObservations: CountSchema,
|
|
121
|
+
startsMinusTerminals: z.null(),
|
|
122
|
+
exactOperationFailureRate: z.null()
|
|
123
|
+
}).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"));
|
|
124
|
+
const candidateSchema = z.object({
|
|
125
|
+
fingerprint: z.string().max(256).regex(/^coverage-1\|(?:client|host)\|[a-z-]+\|(?:failed|environment-fault|unknown)\|[A-Za-z0-9_-]+$/),
|
|
126
|
+
category: z.enum(["recorded-failure", "unknown-outcome"]),
|
|
127
|
+
layer: z.enum(["client", "host"]),
|
|
128
|
+
operation: z.enum(DIAGNOSTICS_OPERATIONS),
|
|
129
|
+
metric: z.enum([
|
|
130
|
+
"failed",
|
|
131
|
+
"environment-fault",
|
|
132
|
+
"unknown"
|
|
133
|
+
]),
|
|
134
|
+
reason: z.enum(DIAGNOSTICS_REASONS),
|
|
135
|
+
versions: z.array(z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/)).max(4096),
|
|
136
|
+
firstHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
137
|
+
lastHour: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
138
|
+
observations: CountSchema,
|
|
139
|
+
regressionProven: z.literal(false),
|
|
140
|
+
persistentFaultProven: z.literal(false),
|
|
141
|
+
rootCause: z.literal("unknown")
|
|
142
|
+
}).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"));
|
|
143
|
+
const collectionSchema = z.object({
|
|
144
|
+
enabled: z.boolean().nullable(),
|
|
145
|
+
state: z.enum([
|
|
146
|
+
"loading",
|
|
147
|
+
"ready",
|
|
148
|
+
"unavailable",
|
|
149
|
+
"error"
|
|
150
|
+
]).nullable(),
|
|
151
|
+
diagnostic: z.enum([
|
|
152
|
+
"none",
|
|
153
|
+
"storage-unavailable",
|
|
154
|
+
"storage-invalid",
|
|
155
|
+
"storage-write-failed",
|
|
156
|
+
"profile-unavailable",
|
|
157
|
+
"settings-unavailable",
|
|
158
|
+
"settings-conflict",
|
|
159
|
+
"client-report-failed",
|
|
160
|
+
"client-report-revoked",
|
|
161
|
+
"closed"
|
|
162
|
+
]).nullable(),
|
|
163
|
+
dirty: z.boolean().nullable(),
|
|
164
|
+
persistedAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable()
|
|
165
|
+
}).strict();
|
|
166
|
+
const DiagnosticsAnalysisReportSchema = z.object({
|
|
167
|
+
reportVersion: z.literal(1),
|
|
168
|
+
coverageVersion: z.literal(1),
|
|
169
|
+
interpretation: z.literal("descriptive-observations-only"),
|
|
170
|
+
source: z.enum(["reviewed-view", "persisted-snapshot"]),
|
|
171
|
+
observedAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
172
|
+
snapshotAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
173
|
+
ageMs: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
174
|
+
epoch: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
175
|
+
coverageComplete: z.literal(false),
|
|
176
|
+
effectivenessVerified: z.literal(false),
|
|
177
|
+
gaps: z.array(z.enum(gaps)).max(gaps.length),
|
|
178
|
+
collection: collectionSchema,
|
|
179
|
+
counters: z.object({
|
|
180
|
+
dropped: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
181
|
+
clientDropped: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
182
|
+
clientUnconfirmed: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
183
|
+
evicted: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
184
|
+
saturated: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
185
|
+
interrupted: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
|
|
186
|
+
}).strict(),
|
|
187
|
+
populations: z.array(populationSchema).max(4096),
|
|
188
|
+
pendingAtSnapshot: z.array(DiagnosticsPendingSchema).max(128),
|
|
189
|
+
investigationCandidates: z.array(candidateSchema).max(4096)
|
|
190
|
+
}).strict().refine((value) => new Set(value.gaps).size === value.gaps.length);
|
|
191
|
+
function sum(values) {
|
|
192
|
+
const total = values.reduce((value, next) => value + BigInt(next), 0n);
|
|
193
|
+
return total > BigInt(Number.MAX_SAFE_INTEGER) ? {
|
|
194
|
+
value: null,
|
|
195
|
+
overflow: true
|
|
196
|
+
} : {
|
|
197
|
+
value: Number(total),
|
|
198
|
+
overflow: false
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function parseSnapshot(input) {
|
|
202
|
+
const parsed = DiagnosticsSnapshotSchema.safeParse(input);
|
|
203
|
+
if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_SNAPSHOT");
|
|
204
|
+
const tuples = /* @__PURE__ */ new Set();
|
|
205
|
+
for (const row of parsed.data.rows) {
|
|
206
|
+
const tuple = [
|
|
207
|
+
row.hour,
|
|
208
|
+
row.version,
|
|
209
|
+
row.layer,
|
|
210
|
+
row.operation,
|
|
211
|
+
row.stage,
|
|
212
|
+
row.metric,
|
|
213
|
+
row.reason,
|
|
214
|
+
row.bucket
|
|
215
|
+
].join("|");
|
|
216
|
+
if (tuples.has(tuple)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_DUPLICATE_AGGREGATE");
|
|
217
|
+
tuples.add(tuple);
|
|
218
|
+
}
|
|
219
|
+
return parsed.data;
|
|
220
|
+
}
|
|
221
|
+
function parseJsonText(text) {
|
|
222
|
+
if (Buffer.byteLength(text, "utf8") > 8388608) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INPUT_LIMIT");
|
|
223
|
+
try {
|
|
224
|
+
return JSON.parse(text);
|
|
225
|
+
} catch {
|
|
226
|
+
throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_JSON");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function order(left, right) {
|
|
230
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
231
|
+
}
|
|
232
|
+
function diagnosticsUnitName(profileName) {
|
|
233
|
+
if (!/^[a-zA-Z0-9_-]{1,48}$/.test(profileName)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_PROFILE");
|
|
234
|
+
return `github_copilot_diagnostics_${Buffer.from(profileName, "ascii").toString("hex")}`;
|
|
235
|
+
}
|
|
236
|
+
function parseReviewedView(text) {
|
|
237
|
+
const parsed = DiagnosticsViewSchema.safeParse(parseJsonText(text));
|
|
238
|
+
if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_VIEW");
|
|
239
|
+
return parsed.data;
|
|
240
|
+
}
|
|
241
|
+
function parsePersistedUnit(text, expectedUnit) {
|
|
242
|
+
if (!/^github_copilot_diagnostics_(?:[a-f0-9]{2}){1,48}$/.test(expectedUnit)) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_UNIT");
|
|
243
|
+
const input = parseJsonText(text);
|
|
244
|
+
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");
|
|
245
|
+
return parseSnapshot(input.global);
|
|
246
|
+
}
|
|
247
|
+
function analyzeSnapshot(input, options) {
|
|
248
|
+
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");
|
|
249
|
+
const snapshot = parseSnapshot(input);
|
|
250
|
+
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);
|
|
251
|
+
const groups = /* @__PURE__ */ new Map();
|
|
252
|
+
for (const row of rows) {
|
|
253
|
+
if (row.operation === "collection") continue;
|
|
254
|
+
const key = `${row.version}|${row.layer}|${row.operation}`;
|
|
255
|
+
const population = groups.get(key) ?? [];
|
|
256
|
+
population.push(row);
|
|
257
|
+
groups.set(key, population);
|
|
258
|
+
}
|
|
259
|
+
const populations = [...groups.values()].map((population) => {
|
|
260
|
+
const first = population[0];
|
|
261
|
+
const terminalRows = population.filter((row) => terminals.some((metric) => metric === row.metric));
|
|
262
|
+
const outcomes = Object.fromEntries(terminals.map((metric) => [metric, sum(population.filter((row) => row.metric === metric).map((row) => row.count))]));
|
|
263
|
+
return {
|
|
264
|
+
version: first.version,
|
|
265
|
+
layer: first.layer,
|
|
266
|
+
operation: first.operation,
|
|
267
|
+
successMeaning: first.operation === "compaction" ? "matching-checkpoint-and-end-observed" : first.operation === "compaction-summary" ? "summary-call-fulfilled-not-checkpoint-commit" : "owner-terminal-observation-only",
|
|
268
|
+
firstHour: Math.min(...population.map((row) => row.hour)),
|
|
269
|
+
lastHour: Math.max(...population.map((row) => row.hour)),
|
|
270
|
+
started: sum(population.filter((row) => row.metric === "started").map((row) => row.count)),
|
|
271
|
+
terminalObservations: sum(terminalRows.map((row) => row.count)),
|
|
272
|
+
outcomes,
|
|
273
|
+
terminalLatency: intervals.map((interval, bucket) => ({
|
|
274
|
+
...interval,
|
|
275
|
+
count: sum(terminalRows.filter((row) => row.bucket === bucket).map((row) => row.count))
|
|
276
|
+
})),
|
|
277
|
+
stageAgeObservations: intervals.map((interval, bucket) => ({
|
|
278
|
+
...interval,
|
|
279
|
+
count: sum(population.filter((row) => row.metric === "stage" && row.bucket === bucket).map((row) => row.count))
|
|
280
|
+
})),
|
|
281
|
+
pendingSamples: sum(population.filter((row) => row.metric === "pending-sample").map((row) => row.count)),
|
|
282
|
+
pendingSampleAges: intervals.map((interval, bucket) => ({
|
|
283
|
+
...interval,
|
|
284
|
+
count: sum(population.filter((row) => row.metric === "pending-sample" && row.bucket === bucket).map((row) => row.count))
|
|
285
|
+
})),
|
|
286
|
+
stageObservations: sum(population.filter((row) => row.metric === "stage").map((row) => row.count)),
|
|
287
|
+
startsMinusTerminals: null,
|
|
288
|
+
exactOperationFailureRate: null
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
292
|
+
for (const row of rows) {
|
|
293
|
+
if (row.metric !== "failed" && row.metric !== "environment-fault" && row.metric !== "unknown" || row.operation === "collection") continue;
|
|
294
|
+
const metric = row.metric;
|
|
295
|
+
const fingerprint = `coverage-1|${row.layer}|${row.operation}|${metric}|${row.reason}`;
|
|
296
|
+
const candidate = candidates.get(fingerprint) ?? {
|
|
297
|
+
fingerprint,
|
|
298
|
+
category: metric === "unknown" ? "unknown-outcome" : "recorded-failure",
|
|
299
|
+
layer: row.layer,
|
|
300
|
+
operation: row.operation,
|
|
301
|
+
metric,
|
|
302
|
+
reason: row.reason,
|
|
303
|
+
versions: [],
|
|
304
|
+
hours: [],
|
|
305
|
+
counts: []
|
|
306
|
+
};
|
|
307
|
+
candidate.versions.push(row.version);
|
|
308
|
+
candidate.hours.push(row.hour);
|
|
309
|
+
candidate.counts.push(row.count);
|
|
310
|
+
candidates.set(fingerprint, candidate);
|
|
311
|
+
}
|
|
312
|
+
const gapSet = /* @__PURE__ */ new Set([
|
|
313
|
+
"no-cross-layer-correlation",
|
|
314
|
+
"no-unique-impact",
|
|
315
|
+
"hour-boundary-censoring",
|
|
316
|
+
"no-collection-coverage-clock",
|
|
317
|
+
"no-calibrated-alert-thresholds",
|
|
318
|
+
"no-baseline-trend",
|
|
319
|
+
"no-root-cause-proof"
|
|
320
|
+
]);
|
|
321
|
+
const view = options.view;
|
|
322
|
+
if (options.source === "persisted-snapshot") {
|
|
323
|
+
gapSet.add("persisted-only");
|
|
324
|
+
gapSet.add("live-enabled-state-unknown");
|
|
325
|
+
gapSet.add("live-pending-state-unknown");
|
|
326
|
+
gapSet.add("unflushed-tail-unknown");
|
|
327
|
+
if (snapshot.pending.length) gapSet.add("stored-pending-is-not-live");
|
|
328
|
+
}
|
|
329
|
+
if (!populations.length) gapSet.add("no-retained-operation-observations");
|
|
330
|
+
if (snapshot.requests !== void 0) gapSet.add("request-observations-not-analyzed");
|
|
331
|
+
if (!populations.some((row) => [
|
|
332
|
+
"account-global-switch",
|
|
333
|
+
"account-session-select",
|
|
334
|
+
"account-session-inherit"
|
|
335
|
+
].includes(row.operation))) gapSet.add("account-switch-not-observed");
|
|
336
|
+
if (!populations.some((row) => row.operation === "compaction" || row.operation === "compaction-summary")) gapSet.add("compaction-not-observed");
|
|
337
|
+
if (snapshot.updatedAt <= options.observedAt - RETENTION_MS) gapSet.add("stale-snapshot");
|
|
338
|
+
if (snapshot.rows.some((row) => row.hour <= options.observedAt - RETENTION_MS)) gapSet.add("expired-in-stored-snapshot");
|
|
339
|
+
if (snapshot.dropped) gapSet.add("host-dropped");
|
|
340
|
+
if (snapshot.clientDropped) gapSet.add("client-dropped");
|
|
341
|
+
if (snapshot.clientUnconfirmed) gapSet.add("client-unconfirmed");
|
|
342
|
+
if (snapshot.evicted) gapSet.add("retention-or-capacity-eviction");
|
|
343
|
+
if (snapshot.saturated) gapSet.add("collector-saturated");
|
|
344
|
+
if (snapshot.interrupted || snapshot.rows.some((row) => row.metric === "interrupted")) gapSet.add("interrupted-observations");
|
|
345
|
+
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");
|
|
346
|
+
if (snapshot.rows.some((row) => row.metric === "paused")) gapSet.add("recorded-pause");
|
|
347
|
+
if (view?.dirty) gapSet.add("unpersisted-observations");
|
|
348
|
+
if (view && !view.enabled) gapSet.add("collection-paused");
|
|
349
|
+
if (view && view.state !== "ready") gapSet.add("storage-not-ready");
|
|
350
|
+
const report = {
|
|
351
|
+
reportVersion: 1,
|
|
352
|
+
coverageVersion: 1,
|
|
353
|
+
interpretation: "descriptive-observations-only",
|
|
354
|
+
source: options.source,
|
|
355
|
+
observedAt: options.observedAt,
|
|
356
|
+
snapshotAt: snapshot.updatedAt,
|
|
357
|
+
ageMs: snapshot.updatedAt <= options.observedAt ? options.observedAt - snapshot.updatedAt : null,
|
|
358
|
+
epoch: snapshot.epoch,
|
|
359
|
+
coverageComplete: false,
|
|
360
|
+
effectivenessVerified: false,
|
|
361
|
+
gaps: [...gapSet],
|
|
362
|
+
collection: {
|
|
363
|
+
enabled: view?.enabled ?? null,
|
|
364
|
+
state: view?.state ?? null,
|
|
365
|
+
diagnostic: view?.diagnostic ?? null,
|
|
366
|
+
dirty: view?.dirty ?? null,
|
|
367
|
+
persistedAt: view?.persistedAt ?? null
|
|
368
|
+
},
|
|
369
|
+
counters: {
|
|
370
|
+
dropped: snapshot.dropped,
|
|
371
|
+
clientDropped: snapshot.clientDropped,
|
|
372
|
+
clientUnconfirmed: snapshot.clientUnconfirmed,
|
|
373
|
+
evicted: snapshot.evicted,
|
|
374
|
+
saturated: snapshot.saturated,
|
|
375
|
+
interrupted: snapshot.interrupted
|
|
376
|
+
},
|
|
377
|
+
populations,
|
|
378
|
+
pendingAtSnapshot: snapshot.pending,
|
|
379
|
+
investigationCandidates: [...candidates.values()].map((candidate) => ({
|
|
380
|
+
fingerprint: candidate.fingerprint,
|
|
381
|
+
category: candidate.category,
|
|
382
|
+
layer: candidate.layer,
|
|
383
|
+
operation: candidate.operation,
|
|
384
|
+
metric: candidate.metric,
|
|
385
|
+
reason: candidate.reason,
|
|
386
|
+
versions: [...new Set(candidate.versions)].sort(order),
|
|
387
|
+
firstHour: Math.min(...candidate.hours),
|
|
388
|
+
lastHour: Math.max(...candidate.hours),
|
|
389
|
+
observations: sum(candidate.counts),
|
|
390
|
+
regressionProven: false,
|
|
391
|
+
persistentFaultProven: false,
|
|
392
|
+
rootCause: "unknown"
|
|
393
|
+
}))
|
|
394
|
+
};
|
|
395
|
+
const parsed = DiagnosticsAnalysisReportSchema.safeParse(report);
|
|
396
|
+
if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_REPORT");
|
|
397
|
+
if (populations.some((population) => [
|
|
398
|
+
population.started,
|
|
399
|
+
population.terminalObservations,
|
|
400
|
+
population.stageObservations,
|
|
401
|
+
population.pendingSamples,
|
|
402
|
+
...Object.values(population.outcomes),
|
|
403
|
+
...population.terminalLatency.map((bin) => bin.count),
|
|
404
|
+
...population.stageAgeObservations.map((bin) => bin.count),
|
|
405
|
+
...population.pendingSampleAges.map((bin) => bin.count)
|
|
406
|
+
].some((count) => count.overflow)) || report.investigationCandidates.some((candidate) => candidate.observations.overflow)) gapSet.add("analysis-count-overflow");
|
|
407
|
+
if (gapSet.has("analysis-count-overflow")) {
|
|
408
|
+
const corrected = DiagnosticsAnalysisReportSchema.safeParse({
|
|
409
|
+
...parsed.data,
|
|
410
|
+
gaps: [...gapSet]
|
|
411
|
+
});
|
|
412
|
+
if (!corrected.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_REPORT");
|
|
413
|
+
return corrected.data;
|
|
414
|
+
}
|
|
415
|
+
return parsed.data;
|
|
416
|
+
}
|
|
417
|
+
function analyzeReviewedView(view, observedAt) {
|
|
418
|
+
const parsed = DiagnosticsViewSchema.safeParse(view);
|
|
419
|
+
if (!parsed.success) throw new Error("COPILOT_DIAGNOSTICS_ANALYSIS_INVALID_VIEW");
|
|
420
|
+
return analyzeSnapshot(parsed.data.snapshot, {
|
|
421
|
+
source: "reviewed-view",
|
|
422
|
+
observedAt,
|
|
423
|
+
view: parsed.data
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
//#endregion
|
|
427
|
+
export { DiagnosticsAnalysisReportSchema, analyzeReviewedView, analyzeSnapshot, diagnosticsUnitName, parsePersistedUnit, parseReviewedView };
|