mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-01 06:31:27 +00:00
feat(cli): add GitHub Copilot CLI agent support via ACP (#1245)
* feat(cli): add GitHub Copilot CLI agent support via ACP Wrap `copilot --acp --stdio` for remote sessions and spawn the native TUI locally, with full hub/web integration for spawn, resume, and permissions. Fixes tiann/hapi#362 Co-Authored-By: HAPI <noreply@hapi.run> Co-authored-by: Cursor <cursoragent@cursor.com> * feat(copilot): agent modes, models, slash/file UX, local session sync Add Interactive/Plan/Autopilot (fleet is slash-only), subscription-aware model discovery, web StatusBar/permission UX, @ file mentions, and fix local Safe Yolo plus session-id locator for handoff/resume. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: re-trigger Codex PR review after auth outage Co-authored-by: Cursor <cursoragent@cursor.com> * chore: retry Codex PR review Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): preserve agent mode on resume and apply via ACP set_mode Resume was dropping copilotAgentMode so Plan/Autopilot reset to interactive. Also switch local/remote mode application to --mode / session set_mode instead of slash prompts. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): wake remote loop when agent mode changes Empty isolated queue tick lets setMode apply without inventing a user prompt. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): confirm mode changes before persisting Await Copilot mode changes and expose discovered models so session state reflects backend acceptance. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): guard mode discovery and slash updates Keep model probes within runner roots and preserve active sessions when mode switching is unavailable or rejected. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): preserve resume and auto semantics Deduplicate Copilot resume rows, apply Auto explicitly, and fail closed on denied permissions. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): close permission and model discovery gaps Keep write-capable commands pending in read-only mode, extend model probe RPCs, and preserve explicit model validation before session creation. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): persist runtime model and agent mode Fallback to ACP model options when direct model switching is unavailable and retain Copilot agent mode across hub restarts. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): normalize composer auto selection Use the null session sentinel for Copilot Auto so the composer selects and resets default models consistently. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(copilot): reject local permission mode changes * style(copilot): remove trailing blank line * fix(copilot): secure local config handoffs * fix(copilot): reject local agent mode slashes * fix(copilot): reject mode changes during turns * fix(copilot): consume rejected slash updates * fix(copilot): preserve thinking across slash handling * fix(copilot): stabilize async config changes * fix(copilot): roll back rejected startup model * fix(copilot): preserve cancellation and file mentions * fix(copilot): hide local permission controls * fix(deps): support clean workspace installs * test(copilot): account for spawn mode argument * fix(copilot): attribute usage to active model --------- Co-authored-by: HAPI <noreply@hapi.run> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
HAPI
parent
b67f4e56e5
commit
f10fbc7496
+23
-1
@@ -2,6 +2,7 @@ import { z } from 'zod'
|
||||
import {
|
||||
AttachmentMetadataSchema,
|
||||
CodexCollaborationModeSchema,
|
||||
CopilotAgentModeSchema,
|
||||
DecryptedMessageSchema,
|
||||
MachineSchema,
|
||||
PermissionModeSchema,
|
||||
@@ -202,6 +203,12 @@ export const SessionCollaborationModeRequestSchema = z.object({
|
||||
|
||||
export type SessionCollaborationModeRequest = z.infer<typeof SessionCollaborationModeRequestSchema>
|
||||
|
||||
export const SessionCopilotAgentModeRequestSchema = z.object({
|
||||
mode: CopilotAgentModeSchema
|
||||
})
|
||||
|
||||
export type SessionCopilotAgentModeRequest = z.infer<typeof SessionCopilotAgentModeRequestSchema>
|
||||
|
||||
export const SessionModelRequestSchema = z.object({
|
||||
model: z.union([
|
||||
z.string().trim().min(1),
|
||||
@@ -502,7 +509,8 @@ export const SpawnSessionRequestSchema = z.object({
|
||||
sessionType: z.enum(['simple', 'worktree']).optional(),
|
||||
worktreeName: z.string().optional(),
|
||||
serviceTier: z.enum(['fast', 'standard']).optional(),
|
||||
collaborationMode: CodexCollaborationModeSchema.optional()
|
||||
collaborationMode: CodexCollaborationModeSchema.optional(),
|
||||
copilotAgentMode: CopilotAgentModeSchema.optional()
|
||||
})
|
||||
|
||||
export type SpawnSessionRequest = z.infer<typeof SpawnSessionRequestSchema>
|
||||
@@ -661,6 +669,20 @@ export type GrokModelsResponse = {
|
||||
}
|
||||
export type ListGrokModelsResponse = GrokModelsResponse
|
||||
|
||||
export type CopilotModelSummary = {
|
||||
modelId: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
export type CopilotModelsResponse = {
|
||||
success: boolean
|
||||
availableModels?: CopilotModelSummary[]
|
||||
currentModelId?: string | null
|
||||
error?: string
|
||||
}
|
||||
|
||||
export type ListCopilotModelsResponse = CopilotModelsResponse
|
||||
|
||||
export type GrokReasoningEffortResponse = {
|
||||
success: boolean
|
||||
options?: GrokReasoningEffortOption[]
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
export const COPILOT_AGENT_MODES = [
|
||||
'interactive',
|
||||
'plan',
|
||||
'autopilot',
|
||||
] as const
|
||||
|
||||
export type CopilotAgentMode = typeof COPILOT_AGENT_MODES[number]
|
||||
|
||||
export const COPILOT_AGENT_MODE_LABELS: Record<CopilotAgentMode, string> = {
|
||||
interactive: 'Interactive',
|
||||
plan: 'Plan',
|
||||
autopilot: 'Autopilot',
|
||||
}
|
||||
|
||||
export type CopilotAgentModeOption = {
|
||||
mode: CopilotAgentMode
|
||||
label: string
|
||||
}
|
||||
|
||||
export function getCopilotAgentModeLabel(mode: CopilotAgentMode): string {
|
||||
return COPILOT_AGENT_MODE_LABELS[mode]
|
||||
}
|
||||
|
||||
export function getCopilotAgentModeOptions(): CopilotAgentModeOption[] {
|
||||
return COPILOT_AGENT_MODES.map((mode) => ({
|
||||
mode,
|
||||
label: getCopilotAgentModeLabel(mode)
|
||||
}))
|
||||
}
|
||||
|
||||
export function isCopilotAgentMode(value: unknown): value is CopilotAgentMode {
|
||||
return typeof value === 'string'
|
||||
&& (COPILOT_AGENT_MODES as readonly string[]).includes(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce legacy / invalid values. `fleet` was briefly treated as an agent mode;
|
||||
* it is a slash command (`/fleet`) orthogonal to interactive/plan/autopilot.
|
||||
*/
|
||||
export function normalizeCopilotAgentMode(value: unknown): CopilotAgentMode {
|
||||
if (value === 'fleet') {
|
||||
return 'interactive'
|
||||
}
|
||||
return isCopilotAgentMode(value) ? value : 'interactive'
|
||||
}
|
||||
@@ -48,6 +48,11 @@ describe('hasCapability', () => {
|
||||
expect(hasCapability('kimi', Capabilities.Effort)).toBe(false)
|
||||
})
|
||||
|
||||
test('copilot supports model-change but not effort', () => {
|
||||
expect(hasCapability('copilot', Capabilities.ModelChange)).toBe(true)
|
||||
expect(hasCapability('copilot', Capabilities.Effort)).toBe(false)
|
||||
})
|
||||
|
||||
test('grok supports runtime model and effort switching through ACP', () => {
|
||||
expect(hasCapability('grok', Capabilities.ModelChange)).toBe(true)
|
||||
expect(hasCapability('grok', Capabilities.Effort)).toBe(true)
|
||||
@@ -72,6 +77,7 @@ describe('getFlavorLabel', () => {
|
||||
expect(getFlavorLabel('opencode')).toBe('OpenCode')
|
||||
expect(getFlavorLabel('pi')).toBe('Pi')
|
||||
expect(getFlavorLabel('kimi')).toBe('Kimi')
|
||||
expect(getFlavorLabel('copilot')).toBe('Copilot')
|
||||
expect(getFlavorLabel('grok')).toBe('Grok Build')
|
||||
})
|
||||
|
||||
@@ -94,6 +100,7 @@ describe('isKnownFlavor', () => {
|
||||
expect(isKnownFlavor('opencode')).toBe(true)
|
||||
expect(isKnownFlavor('pi')).toBe(true)
|
||||
expect(isKnownFlavor('kimi')).toBe(true)
|
||||
expect(isKnownFlavor('copilot')).toBe(true)
|
||||
expect(isKnownFlavor('grok')).toBe(true)
|
||||
})
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const FLAVOR_CAPS: Record<AgentFlavor, ReadonlySet<Capability>> = {
|
||||
claude: new Set([Capabilities.ModelChange, Capabilities.Effort]),
|
||||
gemini: new Set([Capabilities.ModelChange]),
|
||||
kimi: new Set([Capabilities.ModelChange]),
|
||||
copilot: new Set([Capabilities.ModelChange]),
|
||||
grok: new Set([Capabilities.ModelChange, Capabilities.Effort]),
|
||||
codex: new Set([Capabilities.ModelChange]),
|
||||
cursor: new Set([Capabilities.ModelChange]),
|
||||
@@ -25,6 +26,7 @@ const FLAVOR_LABELS: Record<AgentFlavor, string> = {
|
||||
claude: 'Claude',
|
||||
gemini: 'Gemini',
|
||||
kimi: 'Kimi',
|
||||
copilot: 'Copilot',
|
||||
grok: 'Grok Build',
|
||||
codex: 'Codex',
|
||||
cursor: 'Cursor',
|
||||
@@ -61,5 +63,6 @@ export function isCodexFamilyFlavor(flavor: string | null | undefined): boolean
|
||||
|| flavor === 'gemini'
|
||||
|| flavor === 'grok'
|
||||
|| flavor === 'kimi'
|
||||
|| flavor === 'copilot'
|
||||
|| flavor === 'opencode'
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ export * from './socket'
|
||||
export * from './sessionSummary'
|
||||
export * from './sessionExport'
|
||||
export * from './piThinkingLevel'
|
||||
export * from './copilotModes'
|
||||
export * from './slashCommands'
|
||||
export * from './utils'
|
||||
export * from './version'
|
||||
|
||||
+7
-1
@@ -7,7 +7,7 @@ import { z } from 'zod'
|
||||
*/
|
||||
export const AGENT_MESSAGE_PAYLOAD_TYPE = 'codex' as const
|
||||
|
||||
export const AGENT_FLAVORS = ['claude', 'codex', 'cursor', 'gemini', 'grok', 'kimi', 'opencode', 'pi'] as const
|
||||
export const AGENT_FLAVORS = ['claude', 'codex', 'copilot', 'cursor', 'gemini', 'grok', 'kimi', 'opencode', 'pi'] as const
|
||||
export type AgentFlavor = typeof AGENT_FLAVORS[number]
|
||||
export const AgentFlavorSchema = z.enum(AGENT_FLAVORS)
|
||||
|
||||
@@ -34,6 +34,9 @@ export type GeminiPermissionMode = typeof GEMINI_PERMISSION_MODES[number]
|
||||
export const KIMI_PERMISSION_MODES = ['default', 'read-only', 'safe-yolo', 'yolo'] as const
|
||||
export type KimiPermissionMode = typeof KIMI_PERMISSION_MODES[number]
|
||||
|
||||
export const COPILOT_PERMISSION_MODES = ['default', 'read-only', 'safe-yolo', 'yolo'] as const
|
||||
export type CopilotPermissionMode = typeof COPILOT_PERMISSION_MODES[number]
|
||||
|
||||
export const GROK_PERMISSION_MODES = ['default', 'auto', 'plan', 'bypassPermissions'] as const
|
||||
export type GrokPermissionMode = typeof GROK_PERMISSION_MODES[number]
|
||||
|
||||
@@ -127,6 +130,9 @@ export function getPermissionModesForFlavor(flavor?: string | null): readonly Pe
|
||||
if (flavor === 'kimi') {
|
||||
return KIMI_PERMISSION_MODES
|
||||
}
|
||||
if (flavor === 'copilot') {
|
||||
return COPILOT_PERMISSION_MODES
|
||||
}
|
||||
if (flavor === 'grok') {
|
||||
return GROK_PERMISSION_MODES
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import { CodexCollaborationModeSchema, PermissionModeSchema } from './schemas'
|
||||
import { CodexCollaborationModeSchema, CopilotAgentModeSchema, PermissionModeSchema } from './schemas'
|
||||
import { AgentFlavorSchema } from './modes'
|
||||
|
||||
export const LocalResumeTargetSchema = z.object({
|
||||
@@ -17,7 +17,8 @@ export const LocalResumeTargetSchema = z.object({
|
||||
modelReasoningEffort: z.string().nullable().optional(),
|
||||
serviceTier: z.string().nullable().optional(),
|
||||
permissionMode: PermissionModeSchema.optional(),
|
||||
collaborationMode: CodexCollaborationModeSchema.optional()
|
||||
collaborationMode: CodexCollaborationModeSchema.optional(),
|
||||
copilotAgentMode: CopilotAgentModeSchema.optional()
|
||||
})
|
||||
|
||||
export type LocalResumeTarget = z.infer<typeof LocalResumeTargetSchema>
|
||||
|
||||
@@ -37,6 +37,8 @@ export const RPC_METHODS = {
|
||||
ListGrokModelsForCwd: 'listGrokModelsForCwd',
|
||||
ListGrokModels: 'listGrokModels',
|
||||
ListGrokReasoningEffortOptions: 'listGrokReasoningEffortOptions',
|
||||
ListCopilotModelsForCwd: 'listCopilotModelsForCwd',
|
||||
ListCopilotModels: 'listCopilotModels',
|
||||
ListOpencodeReasoningEffortOptions: 'listOpencodeReasoningEffortOptions',
|
||||
ForkConversation: 'fork-conversation',
|
||||
RewindConversation: 'rewind-conversation',
|
||||
|
||||
+11
-1
@@ -1,8 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { COPILOT_AGENT_MODES, type CopilotAgentMode } from './copilotModes'
|
||||
import { CODEX_COLLABORATION_MODES, PERMISSION_MODES } from './modes'
|
||||
|
||||
export const PermissionModeSchema = z.enum(PERMISSION_MODES)
|
||||
export const CodexCollaborationModeSchema = z.enum(CODEX_COLLABORATION_MODES)
|
||||
/** Accept legacy `fleet` (was briefly a peer mode) and coerce to interactive. */
|
||||
export const CopilotAgentModeSchema = z.union([
|
||||
z.enum(COPILOT_AGENT_MODES),
|
||||
z.literal('fleet').transform((): CopilotAgentMode => 'interactive'),
|
||||
])
|
||||
export const SessionEndReasonSchema = z.enum(['completed', 'terminated', 'error', 'handoff', 'cleared'])
|
||||
export type SessionEndReason = z.infer<typeof SessionEndReasonSchema>
|
||||
|
||||
@@ -74,6 +80,7 @@ export const MetadataSchema = z.object({
|
||||
// tiann/hapi#873.
|
||||
cursorMigrationState: z.enum(['in_progress', 'ambiguous']).optional(),
|
||||
kimiSessionId: z.string().optional(),
|
||||
copilotSessionId: z.string().optional(),
|
||||
piSessionId: z.string().optional(),
|
||||
piResumeAttempt: z.object({
|
||||
state: z.enum(['resuming', 'terminating', 'quarantined']),
|
||||
@@ -107,6 +114,7 @@ export const MetadataSchema = z.object({
|
||||
// Durable in-progress state for runner-backed OpenCode /clear.
|
||||
opencodeClearOperation: OpencodeClearOperationSchema.optional(),
|
||||
preferredPermissionMode: PermissionModeSchema.optional(),
|
||||
preferredCopilotAgentMode: CopilotAgentModeSchema.optional(),
|
||||
flavor: z.string().nullish(),
|
||||
capabilities: SessionCapabilitiesSchema.optional(),
|
||||
conversationHistoryPoints: z.record(z.string(), z.literal(true)).optional(),
|
||||
@@ -279,7 +287,8 @@ export const SessionSchema = z.object({
|
||||
effort: z.string().nullable().optional().default(null),
|
||||
serviceTier: z.string().nullable().optional().default(null),
|
||||
permissionMode: PermissionModeSchema.optional(),
|
||||
collaborationMode: CodexCollaborationModeSchema.optional()
|
||||
collaborationMode: CodexCollaborationModeSchema.optional(),
|
||||
copilotAgentMode: CopilotAgentModeSchema.optional()
|
||||
})
|
||||
|
||||
export type Session = z.infer<typeof SessionSchema>
|
||||
@@ -295,6 +304,7 @@ export const SessionPatchSchema = z.object({
|
||||
serviceTier: z.string().nullable().optional(),
|
||||
permissionMode: PermissionModeSchema.optional(),
|
||||
collaborationMode: CodexCollaborationModeSchema.optional(),
|
||||
copilotAgentMode: CopilotAgentModeSchema.optional(),
|
||||
backgroundTaskCount: z.number().optional(),
|
||||
// tiann/hapi#893 (scratchlist v2). Bumped whenever any entry on the
|
||||
// session_scratchlist table mutates. Web client uses the change as a
|
||||
|
||||
@@ -116,6 +116,7 @@ const AGENT_SESSION_ID_FIELD_BY_FLAVOR = {
|
||||
grok: 'grokSessionId',
|
||||
cursor: 'cursorSessionId',
|
||||
kimi: 'kimiSessionId',
|
||||
copilot: 'copilotSessionId',
|
||||
pi: 'piSessionId'
|
||||
} as const satisfies Record<AgentFlavor, keyof Metadata>
|
||||
|
||||
@@ -137,6 +138,7 @@ function getSummaryAgentSessionId(metadata: Metadata): string | undefined {
|
||||
?? metadata.grokSessionId
|
||||
?? metadata.cursorSessionId
|
||||
?? metadata.kimiSessionId
|
||||
?? metadata.copilotSessionId
|
||||
?? undefined
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,28 @@ export const BUILTIN_SLASH_COMMANDS = {
|
||||
cursor: [
|
||||
{ name: 'compress', description: 'Compress conversation context to free window space (pass-through to Cursor agent)', source: 'builtin' },
|
||||
],
|
||||
copilot: [
|
||||
{ name: 'help', description: 'Show supported Copilot slash commands', source: 'builtin' },
|
||||
{ name: 'status', description: 'Show current Copilot session config', source: 'builtin' },
|
||||
{ name: 'plan', description: 'Start plan mode for structured implementation planning', source: 'builtin' },
|
||||
{ name: 'autopilot', description: 'Start autopilot mode for autonomous multi-step work', source: 'builtin' },
|
||||
{ name: 'fleet', description: 'Run parallel subagents for a task (combine with Interactive/Plan/Autopilot)', source: 'builtin' },
|
||||
{ name: 'tasks', description: 'List or manage fleet tasks', source: 'builtin' },
|
||||
{ name: 'subagents', description: 'Manage Copilot subagents', source: 'builtin' },
|
||||
{ name: 'agents', description: 'Alias for /subagents', source: 'builtin' },
|
||||
{ name: 'delegate', description: 'Delegate work to a subagent', source: 'builtin' },
|
||||
{ name: 'agent', description: 'Select or configure a custom agent', source: 'builtin' },
|
||||
{ name: 'rubber-duck', description: 'Consult the rubber-duck agent for a second opinion on plans, code, and tests', source: 'builtin' },
|
||||
{ name: 'security-review', description: 'Run a focused security review of active local code changes', source: 'builtin' },
|
||||
{ name: 'research', description: 'Run a deep research investigation across the codebase and web', source: 'builtin' },
|
||||
{ name: 'review', description: 'Run the code-review agent on current changes', source: 'builtin' },
|
||||
{ name: 'skills', description: 'List, inspect, add, or remove Copilot skills', source: 'builtin' },
|
||||
{ name: 'context', description: 'Show current context usage', source: 'builtin' },
|
||||
{ name: 'model', description: 'Show or switch the active model', source: 'builtin' },
|
||||
{ name: 'permissions', description: 'Show or set permission mode', source: 'builtin' },
|
||||
{ name: 'permission', description: 'Alias for /permissions', source: 'builtin' },
|
||||
{ name: 'usage', description: 'Show session usage metrics', source: 'builtin' },
|
||||
],
|
||||
kimi: [],
|
||||
pi: [],
|
||||
} as const satisfies Record<string, readonly SlashCommand[]>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from 'zod'
|
||||
import type { CodexCollaborationMode, PermissionMode } from './modes'
|
||||
import type { CopilotAgentMode } from './copilotModes'
|
||||
import type { SessionEndReason } from './schemas'
|
||||
export { SessionEndReasonSchema, type SessionEndReason } from './schemas'
|
||||
|
||||
@@ -212,6 +213,7 @@ export interface ClientToServerEvents {
|
||||
effort?: string | null
|
||||
serviceTier?: string | null
|
||||
collaborationMode?: CodexCollaborationMode
|
||||
copilotAgentMode?: CopilotAgentMode
|
||||
}) => void
|
||||
/** CLI agent finished session/load (or equivalent) and can accept prompts. */
|
||||
'session-ready': (data: { sid: string; time: number }) => void
|
||||
|
||||
@@ -39,6 +39,7 @@ export type {
|
||||
GeminiPermissionMode,
|
||||
GrokPermissionMode,
|
||||
KimiPermissionMode,
|
||||
CopilotPermissionMode,
|
||||
OpencodePermissionMode,
|
||||
PermissionMode,
|
||||
PermissionModeOption,
|
||||
@@ -46,3 +47,4 @@ export type {
|
||||
} from './modes'
|
||||
|
||||
export type { ClaudeModelPreset, GeminiModelPreset } from './models'
|
||||
export type { CopilotAgentMode } from './copilotModes'
|
||||
|
||||
Reference in New Issue
Block a user