@codetelemetry/connect 0.1.1 → 0.1.3

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.
Files changed (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -24
  3. package/dist/agent.d.ts +699 -0
  4. package/dist/agent.js +435 -0
  5. package/dist/assistants.d.ts +4 -0
  6. package/dist/assistants.js +5 -0
  7. package/dist/bin.js +3 -0
  8. package/dist/cli.d.ts +1 -0
  9. package/dist/cli.js +567 -0
  10. package/dist/clients.d.ts +34 -0
  11. package/dist/clients.js +74 -0
  12. package/dist/{src/codexConfig.d.ts → codexConfig.d.ts} +1 -0
  13. package/dist/{src/codexConfig.js → codexConfig.js} +5 -0
  14. package/dist/{src/config.d.ts → config.d.ts} +16 -0
  15. package/dist/{src/config.js → config.js} +16 -0
  16. package/dist/connectivity.d.ts +51 -0
  17. package/dist/connectivity.js +118 -0
  18. package/dist/{src/deviceClient.d.ts → deviceClient.d.ts} +9 -2
  19. package/dist/{src/deviceClient.js → deviceClient.js} +45 -13
  20. package/dist/graderSeed.d.ts +50 -0
  21. package/dist/graderSeed.js +289 -0
  22. package/dist/hostMetrics.d.ts +54 -0
  23. package/dist/hostMetrics.js +425 -0
  24. package/dist/import/browser.d.ts +30 -0
  25. package/dist/import/browser.js +157 -0
  26. package/dist/import/convert.d.ts +20 -0
  27. package/dist/import/convert.js +165 -0
  28. package/dist/import/core.d.ts +143 -0
  29. package/dist/import/core.js +441 -0
  30. package/dist/import/ledger.d.ts +52 -0
  31. package/dist/import/ledger.js +161 -0
  32. package/dist/import/model.d.ts +70 -0
  33. package/dist/import/model.js +42 -0
  34. package/dist/import/options.d.ts +24 -0
  35. package/dist/import/options.js +71 -0
  36. package/dist/import/otlpImport.d.ts +7 -0
  37. package/dist/import/otlpImport.js +81 -0
  38. package/dist/import/protocol.d.ts +35 -0
  39. package/dist/import/protocol.js +51 -0
  40. package/dist/import/run.d.ts +30 -0
  41. package/dist/import/run.js +127 -0
  42. package/dist/import/sources/claudeCodeText.d.ts +19 -0
  43. package/dist/import/sources/claudeCodeText.js +214 -0
  44. package/dist/import/sources/codexText.d.ts +20 -0
  45. package/dist/import/sources/codexText.js +319 -0
  46. package/dist/import/sources/files.d.ts +24 -0
  47. package/dist/import/sources/files.js +129 -0
  48. package/dist/import/transport.d.ts +76 -0
  49. package/dist/import/transport.js +141 -0
  50. package/dist/index.d.ts +19 -0
  51. package/dist/index.js +19 -0
  52. package/dist/kiro/collector.d.ts +88 -0
  53. package/dist/kiro/collector.js +577 -0
  54. package/dist/kiro/command.d.ts +3 -0
  55. package/dist/kiro/command.js +109 -0
  56. package/dist/kiro/config.d.ts +39 -0
  57. package/dist/kiro/config.js +107 -0
  58. package/dist/kiro/records.d.ts +52 -0
  59. package/dist/kiro/records.js +206 -0
  60. package/dist/kiro/service.d.ts +21 -0
  61. package/dist/kiro/service.js +183 -0
  62. package/dist/kiro/state.d.ts +45 -0
  63. package/dist/kiro/state.js +205 -0
  64. package/dist/kiro/transport.d.ts +9 -0
  65. package/dist/kiro/transport.js +90 -0
  66. package/dist/{src/onboard.d.ts → onboard.d.ts} +8 -2
  67. package/dist/onboard.js +116 -0
  68. package/dist/piConfig.d.ts +29 -0
  69. package/dist/piConfig.js +112 -0
  70. package/dist/plan.d.ts +53 -0
  71. package/dist/plan.js +113 -0
  72. package/dist/{src/repositoryHook.d.ts → repositoryHook.d.ts} +0 -1
  73. package/dist/{src/repositoryHook.js → repositoryHook.js} +5 -38
  74. package/dist/{src/settings.d.ts → settings.d.ts} +4 -0
  75. package/dist/{src/settings.js → settings.js} +17 -0
  76. package/dist/yaml.d.ts +5 -0
  77. package/dist/yaml.js +72 -0
  78. package/package.json +27 -18
  79. package/dist/bin/connect.js +0 -6
  80. package/dist/src/cli.d.ts +0 -10
  81. package/dist/src/cli.js +0 -172
  82. package/dist/src/connectivity.d.ts +0 -27
  83. package/dist/src/connectivity.js +0 -54
  84. package/dist/src/index.d.ts +0 -8
  85. package/dist/src/index.js +0 -8
  86. package/dist/src/onboard.js +0 -84
  87. /package/dist/{bin/connect.d.ts → bin.d.ts} +0 -0
  88. /package/dist/{src/keys.d.ts → keys.d.ts} +0 -0
  89. /package/dist/{src/keys.js → keys.js} +0 -0
  90. /package/dist/{src/otlp.d.ts → otlp.d.ts} +0 -0
  91. /package/dist/{src/otlp.js → otlp.js} +0 -0
@@ -263,3 +263,8 @@ export function readCodexSummary(configPath) {
263
263
  .filter((k) => k !== null);
264
264
  return { exists: true, otelKeys, hasKey: /Bearer\s+cot_/.test(exporterKeyText(raw)) };
265
265
  }
266
+ export function readCodexLogUserPrompt(configPath) {
267
+ if (!fs.existsSync(configPath))
268
+ return false;
269
+ return activeOtelLines(fs.readFileSync(configPath, "utf8")).some((l) => keyOf(l) === "log_user_prompt" && /=\s*true$/.test(stripComment(l).trimEnd()));
270
+ }
@@ -2,8 +2,13 @@ export type Endpoints = {
2
2
  apiBase: string;
3
3
  ingestEndpoint: string;
4
4
  deviceCodeUrl: string;
5
+ deviceScopedCodeUrl: string;
6
+ deviceOrganizationCodeUrl: string;
5
7
  deviceApproveUrl: string;
8
+ deviceScopedApproveUrl: string;
9
+ deviceOrganizationApproveUrl: string;
6
10
  deviceTokenUrl: string;
11
+ deviceScopedTokenUrl: string;
7
12
  connectivityUrl: string;
8
13
  verificationUri: string;
9
14
  agentCostUrl: string;
@@ -12,6 +17,17 @@ export type Endpoints = {
12
17
  agentSessionSearchUrl: string;
13
18
  agentTaskSizeUrl: string;
14
19
  agentLinearIssueSizeUrl: string;
20
+ agentInterpretSessionUrl: string;
21
+ agentReadSessionEventsUrl: string;
22
+ agentCompareSessionsUrl: string;
23
+ agentPlanNextSessionUrl: string;
24
+ agentHostHealthUrl: string;
25
+ agentGitHubGateUrl: string;
26
+ agentGitHubGateConfigureUrl: string;
27
+ agentReplyPhrasesUrl: string;
28
+ agentImportStatusUrl: string;
29
+ agentGraderUrl: string;
30
+ agentGraderConfigureUrl: string;
15
31
  };
16
32
  export declare function resolveEndpoints(overrides?: Partial<{
17
33
  apiBase: string;
@@ -9,8 +9,13 @@ export function resolveEndpoints(overrides = {}) {
9
9
  apiBase,
10
10
  ingestEndpoint,
11
11
  deviceCodeUrl: `${apiBase}/api/device/code`,
12
+ deviceScopedCodeUrl: `${apiBase}/api/device/code/scope-v1`,
13
+ deviceOrganizationCodeUrl: `${apiBase}/api/device/code/organization-v1`,
12
14
  deviceApproveUrl: `${apiBase}/api/device/approve`,
15
+ deviceScopedApproveUrl: `${apiBase}/api/device/approve/scope-v1`,
16
+ deviceOrganizationApproveUrl: `${apiBase}/api/device/approve/organization-v1`,
13
17
  deviceTokenUrl: `${apiBase}/api/device/token`,
18
+ deviceScopedTokenUrl: `${apiBase}/api/device/token/scope-v1`,
14
19
  connectivityUrl: `${apiBase}/api/connectivity/check`,
15
20
  verificationUri: `${apiBase}/activate`,
16
21
  agentCostUrl: `${apiBase}/api/agent/cost`,
@@ -19,6 +24,17 @@ export function resolveEndpoints(overrides = {}) {
19
24
  agentSessionSearchUrl: `${apiBase}/api/agent/session-search`,
20
25
  agentTaskSizeUrl: `${apiBase}/api/agent/task-size`,
21
26
  agentLinearIssueSizeUrl: `${apiBase}/api/agent/linear-issue-size`,
27
+ agentInterpretSessionUrl: `${apiBase}/api/agent/interpret-session`,
28
+ agentReadSessionEventsUrl: `${apiBase}/api/agent/read-session-events`,
29
+ agentCompareSessionsUrl: `${apiBase}/api/agent/compare-sessions`,
30
+ agentPlanNextSessionUrl: `${apiBase}/api/agent/plan-next-session`,
31
+ agentHostHealthUrl: `${apiBase}/api/agent/host-health`,
32
+ agentGitHubGateUrl: `${apiBase}/api/agent/github-gate`,
33
+ agentGitHubGateConfigureUrl: `${apiBase}/api/agent/github-gate/configure`,
34
+ agentReplyPhrasesUrl: `${apiBase}/api/agent/reply-phrases`,
35
+ agentImportStatusUrl: `${apiBase}/api/agent/import-status`,
36
+ agentGraderUrl: `${apiBase}/api/agent/grader`,
37
+ agentGraderConfigureUrl: `${apiBase}/api/agent/grader/configure`,
22
38
  };
23
39
  }
24
40
  export function resolveSettingsPath(opts = {}) {
@@ -0,0 +1,51 @@
1
+ import type { FetchLike } from "./otlp.ts";
2
+ export type ConnectivityState = "scope_verified" | "connected" | "ingestion_delay" | "wrong_scope" | "budget_exhausted" | "invalid_key" | "dashboard_read_failure" | "unknown_failure";
3
+ export type KeyScope = {
4
+ tenantId: string;
5
+ teamId: string | null;
6
+ billingAccountId: string;
7
+ };
8
+ export type ExpectedKeyScope = Partial<KeyScope>;
9
+ export type CheckResult = {
10
+ seen: boolean;
11
+ httpStatus: number;
12
+ state: ConnectivityState;
13
+ scope?: KeyScope;
14
+ budget?: {
15
+ creditBalanceUsd: number;
16
+ seats: number;
17
+ remainingIncludedTokens: number;
18
+ } | null;
19
+ mismatches?: (keyof KeyScope)[];
20
+ };
21
+ export declare function checkOnce(opts: {
22
+ key: string;
23
+ connectivityUrl: string;
24
+ probeId: string;
25
+ fetchImpl?: FetchLike;
26
+ timeoutMs?: number;
27
+ expected?: ExpectedKeyScope;
28
+ }): Promise<CheckResult>;
29
+ export declare function verifyScope(opts: {
30
+ key: string;
31
+ connectivityUrl: string;
32
+ fetchImpl?: FetchLike;
33
+ timeoutMs?: number;
34
+ expected: ExpectedKeyScope;
35
+ }): Promise<CheckResult>;
36
+ export type ConfirmResult = CheckResult & {
37
+ landed: boolean;
38
+ elapsedMs: number;
39
+ polls: number;
40
+ };
41
+ export declare function confirmLanded(opts: {
42
+ key: string;
43
+ connectivityUrl: string;
44
+ probeId: string;
45
+ fetchImpl?: FetchLike;
46
+ intervalMs?: number;
47
+ timeoutMs?: number;
48
+ onTick?: (poll: number) => void;
49
+ now?: () => number;
50
+ expected?: ExpectedKeyScope;
51
+ }): Promise<ConfirmResult>;
@@ -0,0 +1,118 @@
1
+ import { assertKey } from "./keys.js";
2
+ export async function checkOnce(opts) {
3
+ const key = assertKey(opts.key);
4
+ const fetchImpl = opts.fetchImpl ?? fetch;
5
+ const ac = new AbortController();
6
+ const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? 8_000);
7
+ try {
8
+ const res = await fetchImpl(opts.connectivityUrl, {
9
+ method: "POST",
10
+ headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
11
+ body: JSON.stringify({ probeId: opts.probeId, ...(opts.expected ? { expected: opts.expected } : {}) }),
12
+ signal: ac.signal,
13
+ });
14
+ let payload = {};
15
+ try {
16
+ payload = ((await res.json()) ?? {});
17
+ }
18
+ catch {
19
+ }
20
+ const seen = payload.seen === true;
21
+ const state = typeof payload.state === "string"
22
+ ? payload.state
23
+ : seen
24
+ ? "connected"
25
+ : res.status === 401
26
+ ? "invalid_key"
27
+ : res.status >= 500
28
+ ? "dashboard_read_failure"
29
+ : "ingestion_delay";
30
+ return {
31
+ seen,
32
+ httpStatus: res.status,
33
+ state,
34
+ ...(payload.scope ? { scope: payload.scope } : {}),
35
+ ...(payload.budget !== undefined ? { budget: payload.budget } : {}),
36
+ ...(payload.mismatches ? { mismatches: payload.mismatches } : {}),
37
+ };
38
+ }
39
+ finally {
40
+ clearTimeout(timer);
41
+ }
42
+ }
43
+ export async function verifyScope(opts) {
44
+ const key = assertKey(opts.key);
45
+ const fetchImpl = opts.fetchImpl ?? fetch;
46
+ const ac = new AbortController();
47
+ const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? 8_000);
48
+ try {
49
+ const res = await fetchImpl(opts.connectivityUrl, {
50
+ method: "POST",
51
+ headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
52
+ body: JSON.stringify({ scopeOnly: true, expected: opts.expected }),
53
+ signal: ac.signal,
54
+ });
55
+ let payload = {};
56
+ try {
57
+ payload = ((await res.json()) ?? {});
58
+ }
59
+ catch {
60
+ }
61
+ const state = typeof payload.state === "string"
62
+ ? payload.state
63
+ : res.status === 401
64
+ ? "invalid_key"
65
+ : res.status >= 500
66
+ ? "dashboard_read_failure"
67
+ : "unknown_failure";
68
+ return {
69
+ seen: false,
70
+ httpStatus: res.status,
71
+ state,
72
+ ...(payload.scope ? { scope: payload.scope } : {}),
73
+ ...(payload.budget !== undefined ? { budget: payload.budget } : {}),
74
+ ...(payload.mismatches ? { mismatches: payload.mismatches } : {}),
75
+ };
76
+ }
77
+ finally {
78
+ clearTimeout(timer);
79
+ }
80
+ }
81
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
82
+ export async function confirmLanded(opts) {
83
+ const interval = opts.intervalMs ?? 2_000;
84
+ const timeout = opts.timeoutMs ?? 30_000;
85
+ const now = opts.now ?? (() => Date.now());
86
+ const start = now();
87
+ let polls = 0;
88
+ let last = null;
89
+ while (true) {
90
+ const remaining = timeout - (now() - start);
91
+ if (remaining <= 0) {
92
+ const fallback = { seen: false, httpStatus: 0, state: "ingestion_delay" };
93
+ return { ...(last ?? fallback), landed: false, elapsedMs: now() - start, polls };
94
+ }
95
+ polls += 1;
96
+ opts.onTick?.(polls);
97
+ const checked = await checkOnce({
98
+ key: opts.key,
99
+ connectivityUrl: opts.connectivityUrl,
100
+ probeId: opts.probeId,
101
+ fetchImpl: opts.fetchImpl,
102
+ expected: opts.expected,
103
+ timeoutMs: Math.min(8_000, remaining),
104
+ });
105
+ last = checked;
106
+ const elapsedMs = now() - start;
107
+ if (checked.seen)
108
+ return { ...checked, landed: true, elapsedMs, polls };
109
+ if (checked.state !== "ingestion_delay"
110
+ && checked.state !== "budget_exhausted"
111
+ && checked.state !== "dashboard_read_failure") {
112
+ return { ...checked, landed: false, elapsedMs, polls };
113
+ }
114
+ if (elapsedMs + interval >= timeout)
115
+ return { ...checked, landed: false, elapsedMs, polls };
116
+ await sleep(interval);
117
+ }
118
+ }
@@ -1,32 +1,39 @@
1
1
  import type { FetchLike } from "./otlp.ts";
2
2
  import type { Endpoints } from "./config.ts";
3
+ import type { ExpectedKeyScope, KeyScope } from "./connectivity.ts";
3
4
  export type DeviceCodeResponse = {
4
5
  deviceCode: string;
5
6
  userCode: string;
6
7
  verificationUri: string;
7
8
  expiresIn: number;
8
9
  interval: number;
10
+ scopeFenced: boolean;
9
11
  };
10
- export declare function requestDeviceCode(endpoints: Endpoints, fetchImpl?: FetchLike, timeoutMs?: number): Promise<DeviceCodeResponse>;
12
+ export declare function requestDeviceCode(endpoints: Endpoints, fetchImpl?: FetchLike, timeoutMs?: number, expected?: ExpectedKeyScope): Promise<DeviceCodeResponse>;
11
13
  export type DeviceKey = {
12
14
  apiKey: string;
13
15
  ingestEndpoint: string;
16
+ scope?: KeyScope;
14
17
  };
15
18
  export type PollOnce = {
16
19
  status: "authorized";
17
20
  apiKey: string;
18
21
  ingestEndpoint: string;
22
+ scope?: KeyScope;
19
23
  } | {
20
24
  status: "pending";
21
25
  } | {
22
26
  status: "error";
23
27
  error: string;
24
28
  };
25
- export declare function pollOnce(endpoints: Endpoints, deviceCode: string, fetchImpl?: FetchLike, timeoutMs?: number): Promise<PollOnce>;
29
+ export declare function pollOnce(endpoints: Endpoints, deviceCode: string, fetchImpl?: FetchLike, timeoutMs?: number, opts?: {
30
+ scopeFenced?: boolean;
31
+ }): Promise<PollOnce>;
26
32
  export declare function pollForKey(endpoints: Endpoints, deviceCode: string, opts?: {
27
33
  intervalMs?: number;
28
34
  timeoutMs?: number;
29
35
  fetchImpl?: FetchLike;
30
36
  now?: () => number;
31
37
  sleepImpl?: (ms: number) => Promise<void>;
38
+ scopeFenced?: boolean;
32
39
  }): Promise<DeviceKey>;
@@ -1,14 +1,22 @@
1
- const TERMINAL_ERRORS = new Set(["expired_token", "invalid_grant", "access_denied"]);
2
- export async function requestDeviceCode(endpoints, fetchImpl = fetch, timeoutMs = 10_000) {
1
+ const TERMINAL_ERRORS = new Set(["expired_token", "invalid_grant", "access_denied", "wrong_scope"]);
2
+ function tokenError(body, fallback) {
3
+ return body.state === "wrong_scope" ? "wrong_scope" : String(body.error ?? fallback);
4
+ }
5
+ function issuedIngestEndpoint(body, endpoints) {
6
+ return typeof body.ingest_endpoint === "string" && body.ingest_endpoint ? body.ingest_endpoint : endpoints.ingestEndpoint;
7
+ }
8
+ export async function requestDeviceCode(endpoints, fetchImpl = fetch, timeoutMs = 10_000, expected) {
9
+ const scopeFenced = !!expected && Object.keys(expected).length > 0;
10
+ const codeUrl = scopeFenced ? endpoints.deviceScopedCodeUrl : endpoints.deviceCodeUrl;
3
11
  const ac = new AbortController();
4
12
  const timer = setTimeout(() => ac.abort(), Math.max(1, timeoutMs));
5
13
  try {
6
14
  let res;
7
15
  try {
8
- res = await fetchImpl(endpoints.deviceCodeUrl, {
16
+ res = await fetchImpl(codeUrl, {
9
17
  method: "POST",
10
18
  headers: { "content-type": "application/json" },
11
- body: JSON.stringify({ client: "codetelemetry-connect" }),
19
+ body: JSON.stringify({ client: "codetelemetry-connect", ...(expected ? { expected } : {}) }),
12
20
  signal: ac.signal,
13
21
  });
14
22
  }
@@ -34,19 +42,32 @@ export async function requestDeviceCode(endpoints, fetchImpl = fetch, timeoutMs
34
42
  verificationUri: String(j.verification_uri ?? endpoints.verificationUri),
35
43
  expiresIn: Number(j.expires_in ?? 600),
36
44
  interval: Number(j.interval ?? 2),
45
+ scopeFenced,
37
46
  };
38
47
  }
39
48
  finally {
40
49
  clearTimeout(timer);
41
50
  }
42
51
  }
43
- async function tokenRequest(endpoints, deviceCode, fetchImpl, timeoutMs) {
52
+ function keyScope(value) {
53
+ if (!value || typeof value !== "object" || Array.isArray(value))
54
+ return undefined;
55
+ const raw = value;
56
+ if (typeof raw.tenantId !== "string" || !raw.tenantId || raw.tenantId.length > 256)
57
+ return undefined;
58
+ if (raw.teamId !== null && (typeof raw.teamId !== "string" || !raw.teamId || raw.teamId.length > 256))
59
+ return undefined;
60
+ if (typeof raw.billingAccountId !== "string" || !raw.billingAccountId || raw.billingAccountId.length > 256)
61
+ return undefined;
62
+ return { tenantId: raw.tenantId, teamId: raw.teamId, billingAccountId: raw.billingAccountId };
63
+ }
64
+ async function tokenRequest(endpoints, deviceCode, fetchImpl, timeoutMs, scopeFenced) {
44
65
  const ac = new AbortController();
45
66
  const timer = setTimeout(() => ac.abort(), Math.max(1, timeoutMs));
46
67
  try {
47
68
  let response;
48
69
  try {
49
- response = await fetchImpl(endpoints.deviceTokenUrl, {
70
+ response = await fetchImpl(scopeFenced ? endpoints.deviceScopedTokenUrl : endpoints.deviceTokenUrl, {
50
71
  method: "POST",
51
72
  headers: { "content-type": "application/json" },
52
73
  body: JSON.stringify({ device_code: deviceCode }),
@@ -65,15 +86,21 @@ async function tokenRequest(endpoints, deviceCode, fetchImpl, timeoutMs) {
65
86
  clearTimeout(timer);
66
87
  }
67
88
  }
68
- export async function pollOnce(endpoints, deviceCode, fetchImpl = fetch, timeoutMs = 8_000) {
69
- const result = await tokenRequest(endpoints, deviceCode, fetchImpl, timeoutMs);
89
+ export async function pollOnce(endpoints, deviceCode, fetchImpl = fetch, timeoutMs = 8_000, opts = {}) {
90
+ const result = await tokenRequest(endpoints, deviceCode, fetchImpl, timeoutMs, opts.scopeFenced === true);
70
91
  if (result === null)
71
92
  return { status: "pending" };
72
93
  const { response: res, body: j } = result;
73
94
  if (res.ok && j.api_key) {
74
- return { status: "authorized", apiKey: String(j.api_key), ingestEndpoint: String(j.ingest_endpoint) };
95
+ const scope = keyScope(j.scope);
96
+ return {
97
+ status: "authorized",
98
+ apiKey: String(j.api_key),
99
+ ingestEndpoint: issuedIngestEndpoint(j, endpoints),
100
+ ...(scope ? { scope } : {}),
101
+ };
75
102
  }
76
- const error = String(j.error ?? "authorization_pending");
103
+ const error = tokenError(j, "authorization_pending");
77
104
  return TERMINAL_ERRORS.has(error) ? { status: "error", error } : { status: "pending" };
78
105
  }
79
106
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -89,15 +116,20 @@ export async function pollForKey(endpoints, deviceCode, opts = {}) {
89
116
  if (remaining <= 0) {
90
117
  throw new Error("device authorization timed out — approval not completed in time");
91
118
  }
92
- const result = await tokenRequest(endpoints, deviceCode, fetchImpl, remaining);
119
+ const result = await tokenRequest(endpoints, deviceCode, fetchImpl, remaining, opts.scopeFenced === true);
93
120
  if (result === null) {
94
121
  throw new Error("device authorization timed out — approval not completed in time");
95
122
  }
96
123
  const { response: res, body: j } = result;
97
124
  if (res.ok && j.api_key) {
98
- return { apiKey: String(j.api_key), ingestEndpoint: String(j.ingest_endpoint) };
125
+ const scope = keyScope(j.scope);
126
+ return {
127
+ apiKey: String(j.api_key),
128
+ ingestEndpoint: issuedIngestEndpoint(j, endpoints),
129
+ ...(scope ? { scope } : {}),
130
+ };
99
131
  }
100
- const error = String(j.error ?? (res.status >= 500 ? "server_error" : "authorization_pending"));
132
+ const error = tokenError(j, res.status >= 500 ? "server_error" : "authorization_pending");
101
133
  if (TERMINAL_ERRORS.has(error)) {
102
134
  throw new Error(`device authorization ${error}`);
103
135
  }
@@ -0,0 +1,50 @@
1
+ export type GraderMatcherNode = {
2
+ field: string;
3
+ operator: string;
4
+ value?: string | string[];
5
+ } | {
6
+ all: GraderMatcherNode[];
7
+ } | {
8
+ any: GraderMatcherNode[];
9
+ } | {
10
+ not: GraderMatcherNode;
11
+ };
12
+ export type GraderCheck = {
13
+ id: string;
14
+ name: string;
15
+ category: string;
16
+ description?: string;
17
+ weight: number;
18
+ satisfactionMode: "observed" | "successful";
19
+ minimumOccurrences: number;
20
+ aggregationMode: "once";
21
+ enabled: boolean;
22
+ repositoryId?: string;
23
+ matcherRule: {
24
+ include: GraderMatcherNode;
25
+ exclude?: GraderMatcherNode;
26
+ };
27
+ };
28
+ export type GraderSeed = {
29
+ features: string;
30
+ sources: Array<{
31
+ path: string;
32
+ kind: "instructions" | "skill";
33
+ text: string;
34
+ truncated: boolean;
35
+ }>;
36
+ candidates: Array<{
37
+ source: string;
38
+ command: string;
39
+ inferred: boolean;
40
+ check: GraderCheck;
41
+ }>;
42
+ warnings: string[];
43
+ truncated: boolean;
44
+ };
45
+ export declare function seedGraderConfig(options: {
46
+ root: string;
47
+ features: string;
48
+ skillPaths?: string[];
49
+ repositoryId?: string;
50
+ }): GraderSeed;