Repository navigation
T3code/copilot cli subscription #11423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
cjrutherford
wants to merge
3
commits into
pingdotgg:main
from
cjrutherford:t3code/copilot-cli-subscription
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,15 @@ type Driver = ServerProvider["driver"]; | |
| function useBarColor(driver: Driver): string | null { | ||
| const colors = useProviderColors(); | ||
| const kind: UsageProviderKind | null = | ||
| driver === "codex" ? "codex" : driver === "claudeAgent" ? "claude" : null; | ||
| driver === "codex" | ||
| ? "codex" | ||
| : driver === "claudeAgent" | ||
| ? "claude" | ||
| : driver === "copilot" | ||
| ? "copilot" | ||
| : driver === "antigravity" | ||
| ? "antigravity" | ||
| : null; | ||
|
Comment on lines
+37
to
+45
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should also use the shared helper as described in the usage limits pooled file. |
||
| return kind ? colors[kind] : null; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { CopilotSettings, ProviderDriverKind, type ServerProvider } from "@t3tools/contracts"; | ||
| import * as Crypto from "effect/Crypto"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { HttpClient } from "effect/unstable/http"; | ||
| import { ChildProcessSpawner } from "effect/unstable/process"; | ||
|
|
||
| import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; | ||
| import { ServerConfig } from "../../config.ts"; | ||
| import { ServerSettingsService } from "../../serverSettings.ts"; | ||
| import { makeCopilotTextGeneration } from "../../textGeneration/CopilotTextGeneration.ts"; | ||
| import { ProviderDriverError } from "../Errors.ts"; | ||
| import { makeCopilotAdapter } from "../Layers/CopilotAdapter.ts"; | ||
| import { | ||
| buildInitialCopilotProviderSnapshot, | ||
| checkCopilotProviderStatus, | ||
| enrichCopilotSnapshot, | ||
| } from "../Layers/CopilotProvider.ts"; | ||
| import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts"; | ||
| import { makeManagedServerProvider } from "../makeManagedServerProvider.ts"; | ||
| import { | ||
| defaultProviderContinuationIdentity, | ||
| type ProviderDriver, | ||
| type ProviderInstance, | ||
| } from "../ProviderDriver.ts"; | ||
| import type { ServerProviderDraft } from "../providerSnapshot.ts"; | ||
| import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts"; | ||
| import { makeManualOnlyProviderMaintenanceCapabilities } from "../providerMaintenance.ts"; | ||
| import { | ||
| haveProviderSnapshotSettingsChanged, | ||
| makeProviderSnapshotSettingsSource, | ||
| type ProviderSnapshotSettings, | ||
| } from "../providerUpdateSettings.ts"; | ||
|
|
||
| const decodeCopilotSettings = Schema.decodeSync(CopilotSettings); | ||
|
|
||
| const DRIVER_KIND = ProviderDriverKind.make("copilot"); | ||
| const MAINTENANCE_CAPABILITIES = makeManualOnlyProviderMaintenanceCapabilities({ | ||
| provider: DRIVER_KIND, | ||
| packageName: null, | ||
| }); | ||
|
|
||
| export type CopilotDriverEnv = | ||
| | BackgroundPolicy.BackgroundPolicy | ||
| | ChildProcessSpawner.ChildProcessSpawner | ||
| | Crypto.Crypto | ||
| | FileSystem.FileSystem | ||
| | HttpClient.HttpClient | ||
| | Path.Path | ||
| | ProviderEventLoggers | ||
| | ServerConfig | ||
| | ServerSettingsService; | ||
|
|
||
| const withInstanceIdentity = | ||
| (input: { | ||
| readonly instanceId: ProviderInstance["instanceId"]; | ||
| readonly displayName: string | undefined; | ||
| readonly accentColor: string | undefined; | ||
| readonly continuationGroupKey: string; | ||
| }) => | ||
| (snapshot: ServerProviderDraft): ServerProvider => ({ | ||
| ...snapshot, | ||
| instanceId: input.instanceId, | ||
| driver: DRIVER_KIND, | ||
| ...(input.displayName ? { displayName: input.displayName } : {}), | ||
| ...(input.accentColor ? { accentColor: input.accentColor } : {}), | ||
| continuation: { groupKey: input.continuationGroupKey }, | ||
| }); | ||
|
|
||
| export const CopilotDriver: ProviderDriver<CopilotSettings, CopilotDriverEnv> = { | ||
| driverKind: DRIVER_KIND, | ||
| metadata: { | ||
| displayName: "GitHub Copilot", | ||
| supportsMultipleInstances: true, | ||
| }, | ||
| configSchema: CopilotSettings, | ||
| defaultConfig: (): CopilotSettings => decodeCopilotSettings({}), | ||
| create: ({ instanceId, displayName, accentColor, environment, enabled, config }) => | ||
| Effect.gen(function* () { | ||
| const crypto = yield* Crypto.Crypto; | ||
| const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; | ||
| const httpClient = yield* HttpClient.HttpClient; | ||
| const serverSettings = yield* ServerSettingsService; | ||
| const eventLoggers = yield* ProviderEventLoggers; | ||
| const processEnv = mergeProviderInstanceEnvironment(environment); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const continuationIdentity = defaultProviderContinuationIdentity({ | ||
| driverKind: DRIVER_KIND, | ||
| instanceId, | ||
| }); | ||
| const stampIdentity = withInstanceIdentity({ | ||
| instanceId, | ||
| displayName, | ||
| accentColor, | ||
| continuationGroupKey: continuationIdentity.continuationKey, | ||
| }); | ||
| const effectiveConfig = { ...config, enabled } satisfies CopilotSettings; | ||
|
|
||
| const adapter = yield* makeCopilotAdapter(effectiveConfig, { | ||
| environment: processEnv, | ||
| ...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}), | ||
| instanceId, | ||
| }); | ||
| const textGeneration = yield* makeCopilotTextGeneration(effectiveConfig, processEnv); | ||
|
|
||
| const checkProvider = checkCopilotProviderStatus(effectiveConfig, processEnv).pipe( | ||
| Effect.map(stampIdentity), | ||
| Effect.provideService(Crypto.Crypto, crypto), | ||
| Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), | ||
| ); | ||
|
|
||
| const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, serverSettings); | ||
| const snapshot = yield* makeManagedServerProvider<ProviderSnapshotSettings<CopilotSettings>>({ | ||
| resolveMaintenance: () => Effect.succeed(MAINTENANCE_CAPABILITIES), | ||
| getSettings: snapshotSettings.getSettings, | ||
| streamSettings: snapshotSettings.streamSettings, | ||
| haveSettingsChanged: haveProviderSnapshotSettingsChanged, | ||
| initialSnapshot: (settings) => | ||
| buildInitialCopilotProviderSnapshot(settings.provider).pipe(Effect.map(stampIdentity)), | ||
| checkProvider, | ||
| enrichSnapshot: ({ settings, snapshot: currentSnapshot, publishSnapshot }) => | ||
| enrichCopilotSnapshot({ | ||
| snapshot: currentSnapshot, | ||
| maintenanceCapabilities: MAINTENANCE_CAPABILITIES, | ||
| enableProviderUpdateChecks: settings.enableProviderUpdateChecks, | ||
| publishSnapshot, | ||
| httpClient, | ||
| }), | ||
| }).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new ProviderDriverError({ | ||
| driver: DRIVER_KIND, | ||
| instanceId, | ||
| detail: `Failed to build GitHub Copilot snapshot: ${cause.message ?? String(cause)}`, | ||
| cause, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| return { | ||
| instanceId, | ||
| driverKind: DRIVER_KIND, | ||
| continuationIdentity, | ||
| displayName, | ||
| accentColor, | ||
| enabled, | ||
| snapshot, | ||
| adapter, | ||
| textGeneration, | ||
| } satisfies ProviderInstance; | ||
| }), | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { TurnId } from "@t3tools/contracts"; | ||
| import { assert, it } from "@effect/vitest"; | ||
|
|
||
| import { copilotPromptSettlementBelongsToContext } from "./CopilotAdapter.ts"; | ||
|
|
||
| it("requires a settlement to match the live Copilot turn", () => { | ||
| const staleTurnId = TurnId.make("stale-turn"); | ||
| const replacementTurnId = TurnId.make("replacement-turn"); | ||
|
|
||
| assert.isFalse( | ||
| copilotPromptSettlementBelongsToContext({ | ||
| liveAcpSessionId: "session-1", | ||
| expectedAcpSessionId: "session-1", | ||
| liveActiveTurnId: replacementTurnId, | ||
| liveSessionActiveTurnId: replacementTurnId, | ||
| turnId: staleTurnId, | ||
| }), | ||
| ); | ||
| assert.isFalse( | ||
| copilotPromptSettlementBelongsToContext({ | ||
| liveAcpSessionId: "replacement-session", | ||
| expectedAcpSessionId: "stale-session", | ||
| liveActiveTurnId: staleTurnId, | ||
| liveSessionActiveTurnId: staleTurnId, | ||
| turnId: staleTurnId, | ||
| }), | ||
| ); | ||
| assert.isTrue( | ||
| copilotPromptSettlementBelongsToContext({ | ||
| liveAcpSessionId: "session-1", | ||
| expectedAcpSessionId: "session-1", | ||
| liveActiveTurnId: staleTurnId, | ||
| liveSessionActiveTurnId: staleTurnId, | ||
| turnId: staleTurnId, | ||
| }), | ||
| ); | ||
| assert.isTrue( | ||
| copilotPromptSettlementBelongsToContext({ | ||
| liveAcpSessionId: "session-1", | ||
| expectedAcpSessionId: "session-1", | ||
| liveActiveTurnId: undefined, | ||
| liveSessionActiveTurnId: staleTurnId, | ||
| turnId: staleTurnId, | ||
| }), | ||
| ); | ||
| assert.isTrue( | ||
| copilotPromptSettlementBelongsToContext({ | ||
| liveAcpSessionId: "session-1", | ||
| expectedAcpSessionId: "session-1", | ||
| liveActiveTurnId: staleTurnId, | ||
| liveSessionActiveTurnId: undefined, | ||
| turnId: staleTurnId, | ||
| }), | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a switch statement in a shared helper. not a nested ternary.