@dsh-enhanced/coding-subscription-provider 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/adapter.js ADDED
@@ -0,0 +1,404 @@
1
+ import { resolve } from 'node:path';
2
+ import { LlmAdapter, LlmError, ReasoningEffortId, } from '@deepseek-ai/dsh-llm';
3
+ import { verifySubscriptionAuth } from './auth.js';
4
+ import { discoverCodexModels, } from './codex-catalog.js';
5
+ import { configForProvider } from './config.js';
6
+ import { buildPrompt } from './prompt.js';
7
+ import { runCliText } from './process.js';
8
+ import { buildInvocation } from './providers.js';
9
+ import { discoverClaudeModels, discoverCursorModels, discoverGrokModels, } from './subscription-catalog.js';
10
+ export const routeDefinitions = [
11
+ { route: 'codex-subscription', cli: 'codex', name: 'Codex Subscription (local CLI)', maturity: 'stable' },
12
+ { route: 'claude-subscription', cli: 'claude', name: 'Claude Subscription (local Claude Code)', maturity: 'experimental' },
13
+ { route: 'cursor-subscription', cli: 'cursor', name: 'Cursor Subscription (local Agent CLI)', maturity: 'beta' },
14
+ { route: 'grok-subscription', cli: 'grok', name: 'Grok Subscription (local Grok Build)', maturity: 'beta' },
15
+ ];
16
+ const CATALOG_TTL_MS = 5 * 60_000;
17
+ const noAutomaticRetry = Object.freeze({
18
+ mode: 'normal',
19
+ maxRetries: 0,
20
+ retryableCodes: Object.freeze([]),
21
+ initialDelayMs: 500,
22
+ maxDelayMs: 10_000,
23
+ jitterRatio: 0.1,
24
+ });
25
+ function definitionFor(route) {
26
+ const definition = routeDefinitions.find(candidate => candidate.route === route);
27
+ if (definition === undefined)
28
+ throw new LlmError(`unknown coding subscription provider: ${route}`, 'INVALID_PROVIDER');
29
+ return definition;
30
+ }
31
+ function abortReason(signal) {
32
+ return signal.reason instanceof Error ? signal.reason : new Error('model resolution aborted');
33
+ }
34
+ function cliFailure(definition, command, error) {
35
+ if (error instanceof Error && error.cause === 'abort')
36
+ return error;
37
+ if (error instanceof Error && error.cause === 'subscription-auth') {
38
+ return new LlmError(`${definition.name} refused the request because a subscription-compatible login could not be verified`, 'SUBSCRIPTION_AUTH_REQUIRED', { cause: error });
39
+ }
40
+ if (error instanceof Error && error.cause === 'protocol') {
41
+ return new LlmError(`${definition.name} returned an unrecognized or incomplete event stream`, 'CLI_PROTOCOL_ERROR', { cause: error });
42
+ }
43
+ const code = error?.code;
44
+ if (code === 'ENOENT') {
45
+ return new LlmError(`${definition.name} executable was not found: ${command}`, 'CLI_NOT_FOUND', { cause: error });
46
+ }
47
+ if (error instanceof Error && error.cause === 'timeout') {
48
+ return new LlmError(`${definition.name} timed out`, 'CLI_TIMEOUT', { cause: error });
49
+ }
50
+ return new LlmError(`${definition.name} failed; verify that the official CLI is installed and logged in with the intended subscription`, 'CLI_FAILED', { cause: error });
51
+ }
52
+ /** Classify the original transport error into a stable, credential-free outcome for diagnostics. */
53
+ function outcomeFor(error) {
54
+ const cause = error instanceof Error ? error.cause : undefined;
55
+ if (cause === 'abort')
56
+ return 'aborted';
57
+ if (cause === 'timeout')
58
+ return 'timeout';
59
+ if (cause === 'subscription-auth')
60
+ return 'auth-required';
61
+ if (cause === 'protocol')
62
+ return 'protocol';
63
+ if (cause === 'process-exit')
64
+ return 'process';
65
+ if (cause === 'output-limit')
66
+ return 'output-limit';
67
+ if (cause === 'line-limit')
68
+ return 'line-limit';
69
+ if (error?.code === 'ENOENT')
70
+ return 'not-found';
71
+ // A bare stream error carries no recognized cause but is a local I/O fault, not a model failure.
72
+ if (error instanceof Error && cause === undefined && !(error instanceof LlmError))
73
+ return 'io';
74
+ return 'failed';
75
+ }
76
+ function reasoningInfo(model) {
77
+ if (model?.reasoning === undefined)
78
+ return {};
79
+ return {
80
+ reasoning: {
81
+ efforts: model.reasoning.efforts.map(effort => ({
82
+ id: ReasoningEffortId(effort.id),
83
+ name: effort.name,
84
+ ...(effort.description === undefined ? {} : { description: effort.description }),
85
+ })),
86
+ ...(model.reasoning.defaultEffort === undefined
87
+ ? {}
88
+ : { defaultEffort: ReasoningEffortId(model.reasoning.defaultEffort) }),
89
+ },
90
+ };
91
+ }
92
+ /** Experimental LLM-compatible facade over local, already-authenticated coding agents. */
93
+ export class CodingSubscriptionAdapter extends LlmAdapter {
94
+ config;
95
+ cwd;
96
+ runText;
97
+ discoverCodexModels;
98
+ discoverClaudeModels;
99
+ discoverCursorModels;
100
+ discoverGrokModels;
101
+ verifyAuth;
102
+ onDiagnostic;
103
+ onSettled;
104
+ lifecycle = new AbortController();
105
+ codexCatalogCache;
106
+ subscriptionCatalogCache = new Map();
107
+ constructor(config, dependencies = {}) {
108
+ super();
109
+ this.config = config;
110
+ this.cwd = resolve(config.cwd);
111
+ this.runText = dependencies.runText ?? runCliText;
112
+ this.discoverCodexModels = dependencies.discoverCodexModels ?? discoverCodexModels;
113
+ this.discoverClaudeModels = dependencies.discoverClaudeModels ?? discoverClaudeModels;
114
+ this.discoverCursorModels = dependencies.discoverCursorModels ?? discoverCursorModels;
115
+ this.discoverGrokModels = dependencies.discoverGrokModels ?? discoverGrokModels;
116
+ this.verifyAuth = dependencies.verifyAuth ?? verifySubscriptionAuth;
117
+ this.onDiagnostic = dependencies.onDiagnostic;
118
+ this.onSettled = dependencies.onSettled;
119
+ }
120
+ reportSettled(context) {
121
+ if (this.onSettled === undefined)
122
+ return;
123
+ try {
124
+ this.onSettled(context);
125
+ }
126
+ catch {
127
+ // A diagnostic sink must never change model-call settlement.
128
+ }
129
+ }
130
+ providerInfo(provider) {
131
+ const definition = definitionFor(provider);
132
+ return { id: provider, name: definition.name };
133
+ }
134
+ providerRetryPolicy(_provider) {
135
+ return noAutomaticRetry;
136
+ }
137
+ async loadCodexCatalog(signal = this.lifecycle.signal) {
138
+ if (signal.aborted)
139
+ throw abortReason(signal);
140
+ const cached = this.codexCatalogCache;
141
+ if (cached !== undefined && cached.expiresAt > Date.now())
142
+ return cached.catalog;
143
+ const definition = definitionFor('codex-subscription');
144
+ const profile = this.config.codex;
145
+ try {
146
+ await this.verifyAuth('codex', {
147
+ command: profile.command,
148
+ cwd: this.cwd,
149
+ timeoutMs: this.config.authProbeTimeoutMs,
150
+ maxOutputBytes: this.config.maxAuthProbeBytes,
151
+ extraEnvNames: this.config.extraEnvNames,
152
+ signal,
153
+ });
154
+ const catalog = await this.discoverCodexModels({ command: profile.command, cwd: this.cwd }, {
155
+ signal,
156
+ timeoutMs: this.config.authProbeTimeoutMs,
157
+ killGraceMs: this.config.killGraceMs,
158
+ maxLineBytes: this.config.maxLineBytes,
159
+ maxOutputBytes: this.config.maxOutputBytes,
160
+ maxStderrBytes: this.config.maxStderrBytes,
161
+ extraEnvNames: this.config.extraEnvNames,
162
+ onDiagnostic: diagnostic => this.onDiagnostic?.(definition.route, diagnostic),
163
+ });
164
+ this.codexCatalogCache = { catalog, expiresAt: Date.now() + CATALOG_TTL_MS };
165
+ return catalog;
166
+ }
167
+ catch (error) {
168
+ this.codexCatalogCache = undefined;
169
+ throw cliFailure(definition, profile.command, error);
170
+ }
171
+ }
172
+ async loadSubscriptionCatalog(provider, signal = this.lifecycle.signal) {
173
+ if (signal.aborted)
174
+ throw abortReason(signal);
175
+ const cached = this.subscriptionCatalogCache.get(provider);
176
+ if (cached !== undefined && cached.expiresAt > Date.now())
177
+ return cached.catalog;
178
+ const definition = routeDefinitions.find(candidate => candidate.cli === provider);
179
+ const profile = configForProvider(this.config, provider);
180
+ const discoverer = provider === 'claude'
181
+ ? this.discoverClaudeModels
182
+ : provider === 'cursor'
183
+ ? this.discoverCursorModels
184
+ : this.discoverGrokModels;
185
+ try {
186
+ await this.verifyAuth(provider, {
187
+ command: profile.command,
188
+ cwd: this.cwd,
189
+ timeoutMs: this.config.authProbeTimeoutMs,
190
+ maxOutputBytes: this.config.maxAuthProbeBytes,
191
+ extraEnvNames: this.config.extraEnvNames,
192
+ signal,
193
+ ...(provider === 'grok'
194
+ ? { userVerifiedSubscription: this.config.grok.userVerifiedSubscription }
195
+ : {}),
196
+ });
197
+ const catalog = await discoverer({ command: profile.command, cwd: this.cwd }, {
198
+ signal,
199
+ timeoutMs: this.config.authProbeTimeoutMs,
200
+ maxOutputBytes: this.config.maxAuthProbeBytes,
201
+ extraEnvNames: this.config.extraEnvNames,
202
+ });
203
+ this.subscriptionCatalogCache.set(provider, { catalog, expiresAt: Date.now() + CATALOG_TTL_MS });
204
+ return catalog;
205
+ }
206
+ catch (error) {
207
+ this.subscriptionCatalogCache.delete(provider);
208
+ throw cliFailure(definition, profile.command, error);
209
+ }
210
+ }
211
+ async listModels(provider) {
212
+ const definition = definitionFor(provider);
213
+ const profile = configForProvider(this.config, definition.cli);
214
+ const catalog = definition.cli === 'codex'
215
+ ? await this.loadCodexCatalog()
216
+ : await this.loadSubscriptionCatalog(definition.cli);
217
+ const defaultModel = catalog.models.find(model => model.id === catalog.defaultModel);
218
+ const entries = new Map();
219
+ for (const model of profile.models) {
220
+ entries.set(model, {
221
+ provider,
222
+ id: model,
223
+ name: model === 'default'
224
+ ? `${definition.name} default${defaultModel === undefined ? '' : ` (${defaultModel.name})`}`
225
+ : model,
226
+ description: `${definition.maturity} local coding-agent delegation; authentication and billing remain in the official CLI`,
227
+ inputModalities: ['text'],
228
+ });
229
+ }
230
+ for (const model of catalog.models) {
231
+ entries.set(model.id, {
232
+ provider,
233
+ id: model.id,
234
+ name: model.name,
235
+ ...(model.description === undefined ? {} : { description: model.description }),
236
+ inputModalities: ['text'],
237
+ });
238
+ }
239
+ return [...entries.values()];
240
+ }
241
+ async resolveModel(provider, model, signal) {
242
+ const effectiveSignal = signal === undefined
243
+ ? this.lifecycle.signal
244
+ : AbortSignal.any([signal, this.lifecycle.signal]);
245
+ if (effectiveSignal.aborted)
246
+ throw abortReason(effectiveSignal);
247
+ const definition = definitionFor(provider);
248
+ const catalog = definition.cli === 'codex'
249
+ ? await this.loadCodexCatalog(effectiveSignal)
250
+ : await this.loadSubscriptionCatalog(definition.cli, effectiveSignal);
251
+ const catalogModel = model === 'default'
252
+ ? catalog.models.find(candidate => candidate.id === catalog.defaultModel)
253
+ : catalog.models.find(candidate => candidate.id === model);
254
+ return {
255
+ provider,
256
+ id: model,
257
+ name: model === 'default'
258
+ ? `${definition.name} default${catalogModel === undefined ? '' : ` (${catalogModel.name})`}`
259
+ : (catalogModel?.name ?? model),
260
+ description: catalogModel?.description ?? `${definition.maturity} local coding-agent delegation`,
261
+ inputModalities: ['text'],
262
+ ...reasoningInfo(catalogModel),
263
+ };
264
+ }
265
+ async *stream(options) {
266
+ const definition = definitionFor(options.provider);
267
+ const profile = configForProvider(this.config, definition.cli);
268
+ const signal = options.signal === undefined
269
+ ? this.lifecycle.signal
270
+ : AbortSignal.any([options.signal, this.lifecycle.signal]);
271
+ let assistantTextForwarded = false;
272
+ let transportContext;
273
+ // Track the best-known lifecycle facts so a single settled report fires on ANY exit,
274
+ // including a consumer that returns early after block-start or a text delta.
275
+ let phase = 'auth';
276
+ let promptSubmissionState = 'not-submitted';
277
+ let outcome = 'aborted';
278
+ let reported = false;
279
+ const settle = () => {
280
+ if (reported)
281
+ return;
282
+ reported = true;
283
+ this.reportSettled({
284
+ route: definition.route,
285
+ phase: transportContext?.phase ?? phase,
286
+ promptSubmissionState: transportContext?.promptSubmissionState ?? promptSubmissionState,
287
+ assistantTextObserved: transportContext?.assistantTextObserved ?? assistantTextForwarded,
288
+ assistantTextForwarded,
289
+ outcome,
290
+ teardownState: transportContext?.teardownState ?? 'not-started',
291
+ ...(transportContext?.terminalReason !== undefined ? { terminalReason: transportContext.terminalReason } : {}),
292
+ ...(transportContext?.exitCode !== undefined ? { exitCode: transportContext.exitCode } : {}),
293
+ ...(transportContext?.signal !== undefined ? { signal: transportContext.signal } : {}),
294
+ ...(transportContext?.metrics !== undefined ? { metrics: transportContext.metrics } : {}),
295
+ });
296
+ };
297
+ try {
298
+ try {
299
+ await this.verifyAuth(definition.cli, {
300
+ command: profile.command,
301
+ cwd: this.cwd,
302
+ timeoutMs: this.config.authProbeTimeoutMs,
303
+ maxOutputBytes: this.config.maxAuthProbeBytes,
304
+ extraEnvNames: this.config.extraEnvNames,
305
+ signal,
306
+ ...(definition.cli === 'grok'
307
+ ? { userVerifiedSubscription: this.config.grok.userVerifiedSubscription }
308
+ : {}),
309
+ });
310
+ }
311
+ catch (error) {
312
+ // Auth precedes spawn, so the prompt argv was never handed to the OS.
313
+ if (definition.cli === 'codex')
314
+ this.codexCatalogCache = undefined;
315
+ else
316
+ this.subscriptionCatalogCache.delete(definition.cli);
317
+ outcome = outcomeFor(error);
318
+ throw cliFailure(definition, profile.command, error);
319
+ }
320
+ // Preflight prompt serialization runs before spawn; a failure here is provably not-submitted.
321
+ phase = 'preflight';
322
+ let invocation;
323
+ try {
324
+ invocation = buildInvocation(definition.cli, {
325
+ cwd: this.cwd,
326
+ prompt: buildPrompt(options, this.config.maxPromptBytes),
327
+ model: options.model,
328
+ ...(definition.cli !== 'cursor' && options.reasoningEffort !== undefined
329
+ ? { reasoningEffort: String(options.reasoningEffort) }
330
+ : {}),
331
+ maxTurns: profile.maxTurns,
332
+ command: profile.command,
333
+ });
334
+ }
335
+ catch (error) {
336
+ outcome = 'preflight';
337
+ throw error;
338
+ }
339
+ const runnerOptions = {
340
+ timeoutMs: this.config.timeoutMs,
341
+ killGraceMs: this.config.killGraceMs,
342
+ maxLineBytes: this.config.maxLineBytes,
343
+ maxOutputBytes: this.config.maxOutputBytes,
344
+ maxStderrBytes: this.config.maxStderrBytes,
345
+ extraEnvNames: this.config.extraEnvNames,
346
+ onDiagnostic: diagnostic => this.onDiagnostic?.(definition.route, diagnostic),
347
+ onSettled: context => { transportContext = context; },
348
+ signal,
349
+ };
350
+ // block-start alone runs nothing: prompt stays provably not-submitted until execution
351
+ // resumes toward the transport. Once iteration begins the transport owns the state and
352
+ // reports it via onSettled; if it never reports (early return mid-stream) we say unknown.
353
+ phase = 'stream';
354
+ let text = '';
355
+ yield { type: 'block-start', index: 0, blockType: 'text' };
356
+ try {
357
+ // Calling an injected runner may itself perform work or throw synchronously, so
358
+ // stop claiming not-submitted immediately before control crosses that boundary.
359
+ promptSubmissionState = 'unknown';
360
+ const deltas = this.runText(invocation, runnerOptions);
361
+ for await (const delta of deltas) {
362
+ if (delta.length === 0)
363
+ continue;
364
+ text += delta;
365
+ assistantTextForwarded = true;
366
+ yield { type: 'text-delta', index: 0, text: delta };
367
+ }
368
+ }
369
+ catch (error) {
370
+ outcome = outcomeFor(error);
371
+ throw cliFailure(definition, profile.command, error);
372
+ }
373
+ outcome = 'ok';
374
+ yield { type: 'block-end', index: 0, block: { type: 'text', text } };
375
+ yield { type: 'finish', reason: { kind: 'stop' } };
376
+ }
377
+ finally {
378
+ settle();
379
+ }
380
+ }
381
+ /** Abort every active/future subprocess when the owning Cordis fiber unloads. */
382
+ shutdown() {
383
+ this.codexCatalogCache = undefined;
384
+ this.subscriptionCatalogCache.clear();
385
+ if (!this.lifecycle.signal.aborted) {
386
+ this.lifecycle.abort(new Error('coding subscription provider unloaded', { cause: 'abort' }));
387
+ }
388
+ }
389
+ }
390
+ export function enabledRoutes(config) {
391
+ return routeDefinitions
392
+ .filter(definition => configForProvider(config, definition.cli).enabled)
393
+ .map(definition => definition.route);
394
+ }
395
+ /** Redact common credential/email shapes before a bounded CLI diagnostic reaches host logs. */
396
+ export function redactDiagnostic(value) {
397
+ return value
398
+ .replace(/(bearer\s+)[^\s]+/gi, '$1[redacted]')
399
+ .replace(/((?:api[_-]?key|auth(?:orization)?|token)\s*[:=]\s*)[^\s]+/gi, '$1[redacted]')
400
+ .replace(/\b(?:sk|xai)-[A-Za-z0-9_-]{8,}\b/g, '[redacted-key]')
401
+ .replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, '[redacted-email]')
402
+ .slice(-2_000);
403
+ }
404
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,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M,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;QACpD,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAA;QACV,CAAC;IACH,CAAC;IAED,iFAAiF;IACjF,QAAQ;QACN,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAA;QAClC,IAAI,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAA;QACrC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,uCAAuC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;QAC9F,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAC,MAAwC;IACpE,OAAO,gBAAgB;SACpB,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;SACvE,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK;SACT,OAAO,CAAC,qBAAqB,EAAE,cAAc,CAAC;SAC9C,OAAO,CAAC,8DAA8D,EAAE,cAAc,CAAC;SACvF,OAAO,CAAC,mCAAmC,EAAE,gBAAgB,CAAC;SAC9D,OAAO,CAAC,yCAAyC,EAAE,kBAAkB,CAAC;SACtE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA;AAClB,CAAC"}
package/lib/auth.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ProviderId } from './providers.js';
2
+ export interface AuthCommandResult {
3
+ readonly exitCode: number;
4
+ readonly signal: NodeJS.Signals | null;
5
+ readonly stdout: string;
6
+ readonly stderr: string;
7
+ }
8
+ export interface AuthCommandOptions {
9
+ readonly cwd: string;
10
+ readonly timeoutMs: number;
11
+ readonly maxOutputBytes: number;
12
+ readonly extraEnvNames: readonly string[];
13
+ readonly signal?: AbortSignal;
14
+ }
15
+ export type AuthCommandRunner = (command: string, args: readonly string[], options: AuthCommandOptions) => Promise<AuthCommandResult>;
16
+ export interface VerifySubscriptionAuthOptions extends AuthCommandOptions {
17
+ readonly command: string;
18
+ readonly userVerifiedSubscription?: boolean;
19
+ }
20
+ export type SubscriptionAuthVerifier = (provider: ProviderId, options: VerifySubscriptionAuthOptions) => Promise<void>;
21
+ export declare class SubscriptionAuthError extends Error {
22
+ readonly provider: ProviderId;
23
+ constructor(provider: ProviderId, message: string);
24
+ }
25
+ /**
26
+ * Fail closed unless the official CLI reports a subscription-compatible login.
27
+ * Grok headless cannot prove its effective credential source, so its MVP route
28
+ * requires an explicit local-user attestation; Phase 2 will keep one ACP
29
+ * `cached_token` connection for authentication and prompting.
30
+ */
31
+ export declare function verifySubscriptionAuth(provider: ProviderId, options: VerifySubscriptionAuthOptions, runCommand?: AuthCommandRunner): Promise<void>;
32
+ export declare const runAuthCommand: AuthCommandRunner;
33
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAA;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE,kBAAkB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAE/B,MAAM,WAAW,6BAA8B,SAAQ,kBAAkB;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;CAC5C;AAED,MAAM,MAAM,wBAAwB,GAAG,CACrC,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,6BAA6B,KACnC,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAA;gBAEjB,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;CAKlD;AAQD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,6BAA6B,EACtC,UAAU,GAAE,iBAAkC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED,eAAO,MAAM,cAAc,EAAE,iBAmC3B,CAAA"}
package/lib/auth.js ADDED
@@ -0,0 +1,101 @@
1
+ import { execFile as nodeExecFile } from 'node:child_process';
2
+ import { buildSubscriptionEnv } from './process.js';
3
+ export class SubscriptionAuthError extends Error {
4
+ provider;
5
+ constructor(provider, message) {
6
+ super(message, { cause: 'subscription-auth' });
7
+ this.name = 'SubscriptionAuthError';
8
+ this.provider = provider;
9
+ }
10
+ }
11
+ const authArgs = {
12
+ codex: ['login', 'status'],
13
+ claude: ['auth', 'status', '--json'],
14
+ cursor: ['status'],
15
+ };
16
+ /**
17
+ * Fail closed unless the official CLI reports a subscription-compatible login.
18
+ * Grok headless cannot prove its effective credential source, so its MVP route
19
+ * requires an explicit local-user attestation; Phase 2 will keep one ACP
20
+ * `cached_token` connection for authentication and prompting.
21
+ */
22
+ export async function verifySubscriptionAuth(provider, options, runCommand = runAuthCommand) {
23
+ if (provider === 'grok') {
24
+ if (!options.userVerifiedSubscription) {
25
+ throw new SubscriptionAuthError(provider, 'Grok subscription use requires explicit local verification');
26
+ }
27
+ return;
28
+ }
29
+ const args = authArgs[provider];
30
+ if (args === undefined)
31
+ throw new SubscriptionAuthError(provider, 'No subscription authentication probe is available');
32
+ const result = await runCommand(options.command, args, options);
33
+ if (result.exitCode !== 0 || result.signal !== null) {
34
+ throw new SubscriptionAuthError(provider, `${provider} subscription authentication probe failed`);
35
+ }
36
+ if (provider === 'codex') {
37
+ const lines = `${result.stdout}\n${result.stderr}`.split(/\r?\n/).map(line => line.trim());
38
+ if (!lines.includes('Logged in using ChatGPT')) {
39
+ throw new SubscriptionAuthError(provider, 'Codex is not logged in with ChatGPT');
40
+ }
41
+ return;
42
+ }
43
+ if (provider === 'claude') {
44
+ const status = jsonObject(result.stdout);
45
+ const method = typeof status?.authMethod === 'string' ? status.authMethod : undefined;
46
+ if (status?.loggedIn !== true || status.apiProvider !== 'firstParty' || (method !== 'claude.ai' && method !== 'oauth_token')) {
47
+ throw new SubscriptionAuthError(provider, 'Claude Code did not report a first-party subscription OAuth login');
48
+ }
49
+ return;
50
+ }
51
+ // Cursor's status command only proves that some authentication exists. The
52
+ // model stream must additionally report system/init apiKeySource="login".
53
+ }
54
+ export const runAuthCommand = (command, args, options) => new Promise((resolve, reject) => {
55
+ nodeExecFile(command, [...args], {
56
+ cwd: options.cwd,
57
+ env: buildSubscriptionEnv(options.extraEnvNames),
58
+ encoding: 'utf8',
59
+ maxBuffer: options.maxOutputBytes,
60
+ timeout: options.timeoutMs,
61
+ signal: options.signal,
62
+ shell: false,
63
+ windowsHide: true,
64
+ }, (error, stdout, stderr) => {
65
+ const output = stdout;
66
+ const diagnostic = stderr;
67
+ if (error === null) {
68
+ resolve({ exitCode: 0, signal: null, stdout: output, stderr: diagnostic });
69
+ return;
70
+ }
71
+ if (options.signal?.aborted) {
72
+ reject(new Error('subscription authentication probe aborted', { cause: 'abort' }));
73
+ return;
74
+ }
75
+ if (error.killed) {
76
+ reject(new Error('subscription authentication probe timed out', { cause: 'timeout' }));
77
+ return;
78
+ }
79
+ if (error.code === 'ENOENT') {
80
+ reject(error);
81
+ return;
82
+ }
83
+ if (typeof error.code === 'number') {
84
+ resolve({ exitCode: error.code, signal: error.signal, stdout: output, stderr: diagnostic });
85
+ return;
86
+ }
87
+ reject(new Error('subscription authentication probe exceeded its safety limit', { cause: 'subscription-auth' }));
88
+ });
89
+ });
90
+ function jsonObject(value) {
91
+ try {
92
+ const parsed = JSON.parse(value);
93
+ return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
94
+ ? parsed
95
+ : undefined;
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ }
101
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAkCnD,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,QAAQ,CAAY;IAE7B,YAAY,QAAoB,EAAE,OAAe;QAC/C,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAED,MAAM,QAAQ,GAA6D;IACzE,KAAK,EAAE,CAAC,O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C,MAAiC;YACnC,CAAC,CAAC,SAAS,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ export interface CodexCatalogInvocation {
3
+ readonly command: string;
4
+ readonly cwd: string;
5
+ }
6
+ export interface CodexCatalogReasoningEffort {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ readonly description?: string;
10
+ }
11
+ export interface CodexCatalogModel {
12
+ readonly id: string;
13
+ readonly name: string;
14
+ readonly description?: string;
15
+ readonly reasoning?: {
16
+ readonly efforts: readonly CodexCatalogReasoningEffort[];
17
+ readonly defaultEffort?: string;
18
+ };
19
+ readonly inputModalities: readonly string[];
20
+ }
21
+ export interface CodexCatalog {
22
+ readonly models: readonly CodexCatalogModel[];
23
+ readonly defaultModel?: string;
24
+ readonly observedAt: number;
25
+ }
26
+ export interface CodexCatalogProcess {
27
+ readonly stdin: Writable;
28
+ readonly stdout: Readable;
29
+ readonly stderr: Readable;
30
+ kill(signal?: NodeJS.Signals | number): boolean;
31
+ once(event: 'error' | 'close' | 'spawn', listener: (...args: any[]) => void): this;
32
+ }
33
+ export type CodexCatalogSpawn = (command: string, args: readonly string[], options: {
34
+ cwd: string;
35
+ shell: false;
36
+ detached: boolean;
37
+ stdio: readonly ['pipe', 'pipe', 'pipe'];
38
+ env: NodeJS.ProcessEnv;
39
+ }) => CodexCatalogProcess;
40
+ export interface DiscoverCodexModelsOptions {
41
+ readonly spawn?: CodexCatalogSpawn;
42
+ readonly signal?: AbortSignal;
43
+ readonly timeoutMs?: number;
44
+ readonly killGraceMs?: number;
45
+ readonly maxLineBytes?: number;
46
+ readonly maxOutputBytes?: number;
47
+ readonly maxStderrBytes?: number;
48
+ readonly extraEnvNames?: readonly string[];
49
+ readonly onDiagnostic?: (diagnostic: string) => void;
50
+ }
51
+ /**
52
+ * Discover Codex's picker-visible subscription models through the stable app-server `model/list`
53
+ * method. The subprocess is forced to the built-in `openai` model provider, creates no thread or
54
+ * turn, and closes immediately after all catalog pages have been validated.
55
+ */
56
+ export declare function discoverCodexModels(invocation: CodexCatalogInvocation, options?: DiscoverCodexModelsOptions): Promise<CodexCatalog>;
57
+ //# sourceMappingURL=codex-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex-catalog.d.ts","sourceRoot":"","sources":["../src/codex-catalog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGrD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,OAAO,EAAE,SAAS,2BAA2B,EAAE,CAAA;QACxD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAChC,CAAA;IACD,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,m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