mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-29 06:13:46 +00:00
merge: hapi upstream main 2026-10-19 (34 commits past v0.30.7)
Bring in the post-0.30.7 upstream work while keeping local team, macaron, requirement, DSH and deployment features: - runner/hub: cross-platform orphan reap on archive and tracking loss, machine-spawn preallocated stubs, keepalive-only sessions reconcile to idle - hub: prepared-statement cache, stale/canceled permission request handling - cli: Codex compaction announcements, dynamic Kimi models, MCP bridge reap - web: session toolbar icon shedding, mark-all-read, unread/active sections, Russian locale, external-link preference, 48px search chrome - ios/android: locale and font-size updates Conflict resolution keeps local-only behavior (agent team spawns, macaron skins, collapsible sidebar, workspace markdown images) layered on the new upstream toolbar and session lifecycle plumbing. Test infrastructure: skip the Docker-only pwsh integration test quickly when Docker is unavailable, and exclude the Bun-only usageScan test from vitest. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,7 @@ const BUILTIN_DESCRIPTORS: Record<AgentFlavor, AgentConfigFieldDescriptor[]> = {
|
||||
{ id: 'effort', section: 'effort', kind: 'select', optionSource: 'model', availability: 'both' },
|
||||
PERMISSION
|
||||
),
|
||||
kimi: fields(MODEL, PERMISSION),
|
||||
kimi: fields({ ...MODEL, optionSource: 'directory' }, PERMISSION),
|
||||
opencode: fields(
|
||||
{ ...MODEL, optionSource: 'directory' },
|
||||
{ id: 'effort', section: 'effort', kind: 'select', optionSource: 'model', availability: 'both' },
|
||||
|
||||
+38
-1
@@ -27,6 +27,11 @@ export type CreateOrLoadMachineRequest = z.infer<typeof CreateOrLoadMachineReque
|
||||
|
||||
export const CreateOrLoadSessionRequestSchema = z.object({
|
||||
id: z.string().uuid().optional(),
|
||||
/**
|
||||
* When true with `id`, bind a hub-preallocated stub (overwrite tag/metadata)
|
||||
* instead of create/getOrCreate. Rejects non-stub rows (#1911 adopt).
|
||||
*/
|
||||
adopt: z.boolean().optional(),
|
||||
tag: z.string().min(1),
|
||||
metadata: z.unknown(),
|
||||
agentState: z.unknown().nullable().optional(),
|
||||
@@ -34,6 +39,14 @@ export const CreateOrLoadSessionRequestSchema = z.object({
|
||||
modelReasoningEffort: z.string().optional(),
|
||||
effort: z.string().optional(),
|
||||
machine: CreateOrLoadMachineRequestSchema.optional()
|
||||
}).superRefine((value, ctx) => {
|
||||
if (value.adopt === true && !value.id) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'adopt requires id',
|
||||
path: ['id'],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export type CreateOrLoadSessionRequest = z.infer<typeof CreateOrLoadSessionRequestSchema>
|
||||
@@ -1142,6 +1155,22 @@ export type CopilotModelsResponse = {
|
||||
|
||||
export type ListCopilotModelsResponse = CopilotModelsResponse
|
||||
|
||||
export type KimiModelSummary = {
|
||||
/** Kimi model alias as used by `--model` / `session/set_model`. */
|
||||
modelId: string
|
||||
name?: string
|
||||
provider?: string
|
||||
}
|
||||
|
||||
export type KimiModelsResponse = {
|
||||
success: boolean
|
||||
availableModels?: KimiModelSummary[]
|
||||
currentModelId?: string | null
|
||||
error?: string
|
||||
}
|
||||
|
||||
export type ListKimiModelsResponse = KimiModelsResponse
|
||||
|
||||
export type GrokReasoningEffortResponse = {
|
||||
success: boolean
|
||||
options?: GrokReasoningEffortOption[]
|
||||
@@ -1181,7 +1210,15 @@ export type ListAgyModelsResponse = AgyModelsResponse
|
||||
|
||||
export type CursorModelSummary = OpencodeModelSummary
|
||||
|
||||
export type CursorModelsResponse = OpencodeModelsResponse
|
||||
export type CursorModelsResponse = OpencodeModelsResponse & {
|
||||
/**
|
||||
* True when ACP advertised Cursor's parameterized model picker: bare model bases
|
||||
* plus separate `fast` / `thought_level` config options. The ACP apply path
|
||||
* expresses variant CLI skus through those options, so variant rows stay valid
|
||||
* even when the catalog itself carries no bracket wire ids.
|
||||
*/
|
||||
parameterized?: boolean
|
||||
}
|
||||
|
||||
export type ListCursorModelsResponse = CursorModelsResponse
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
CURSOR_AUTO_MODEL_ID,
|
||||
cursorCliSkuBaseId,
|
||||
cursorSpawnModelId,
|
||||
cursorModelBaseMatches,
|
||||
findBestCliSkuForAcpWire,
|
||||
isCursorAcpCatalogModelId,
|
||||
isCursorAcpWireModelId,
|
||||
isCursorAutoModelId,
|
||||
isCursorCliSkuVariantId,
|
||||
matchCliSkuToAcpWireId,
|
||||
parseCursorAvailableModelsFromRejection,
|
||||
parseCursorSkuParamHints,
|
||||
remapStaleCursorModelId
|
||||
} from './cursorCliSku';
|
||||
|
||||
@@ -19,6 +24,19 @@ const cursorGrokCatalog = [
|
||||
{ modelId: 'cursor-grok-4.5-high-fast' },
|
||||
];
|
||||
|
||||
describe('cursorSpawnModelId', () => {
|
||||
it('pins Auto as the CLI auto id and omits unset models', () => {
|
||||
expect(isCursorAutoModelId('auto')).toBe(true);
|
||||
expect(isCursorAutoModelId('default[]')).toBe(true);
|
||||
expect(isCursorAutoModelId('composer-2.5')).toBe(false);
|
||||
expect(cursorSpawnModelId('auto')).toBe(CURSOR_AUTO_MODEL_ID);
|
||||
expect(cursorSpawnModelId('default')).toBe(CURSOR_AUTO_MODEL_ID);
|
||||
expect(cursorSpawnModelId('default[]')).toBe(CURSOR_AUTO_MODEL_ID);
|
||||
expect(cursorSpawnModelId(null)).toBeNull();
|
||||
expect(cursorSpawnModelId('composer-2.5[fast=true]')).toBe('composer-2.5[fast=true]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('cursorCliSkuBaseId', () => {
|
||||
it('strips effort/speed suffixes from CLI skus', () => {
|
||||
expect(cursorCliSkuBaseId('gpt-5.5-high-fast')).toBe('gpt-5.5');
|
||||
@@ -273,6 +291,29 @@ describe('round-trip (regression for #883: "selected but no response")', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('cursorModelBaseMatches', () => {
|
||||
it('matches bases across the legacy cursor- CLI family prefix', () => {
|
||||
expect(cursorModelBaseMatches('cursor-grok-4.6', 'grok-4.6')).toBe(true);
|
||||
expect(cursorModelBaseMatches('grok-4.6', 'cursor-grok-4.6')).toBe(true);
|
||||
expect(cursorModelBaseMatches('cursor-grok-4.5', 'cursor-grok-4.5')).toBe(true);
|
||||
expect(cursorModelBaseMatches('composer-2.5', 'composer-2.5')).toBe(true);
|
||||
expect(cursorModelBaseMatches('grok-4.6', 'grok-4.5')).toBe(false);
|
||||
expect(cursorModelBaseMatches('claude-opus-4-8', 'claude-opus-5')).toBe(false);
|
||||
});
|
||||
|
||||
it('parses parameter hints from CLI sku suffixes', () => {
|
||||
expect(parseCursorSkuParamHints('cursor-grok-4.6-low')).toMatchObject({
|
||||
effort: 'low',
|
||||
fast: 'false'
|
||||
});
|
||||
expect(parseCursorSkuParamHints('gpt-5.5-extra-high-fast')).toMatchObject({
|
||||
reasoning: 'extra-high',
|
||||
fast: 'true'
|
||||
});
|
||||
expect(parseCursorSkuParamHints('composer-2.5')).toMatchObject({ fast: 'false' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCursorAcpWireModelId', () => {
|
||||
it('detects parameterized wire ids only', () => {
|
||||
expect(isCursorAcpWireModelId('gpt-5.5[fast=false]')).toBe(true);
|
||||
|
||||
@@ -8,18 +8,54 @@ export function resolveCursorLegacyModelBase(baseId: string): string {
|
||||
return CURSOR_LEGACY_MODEL_BASE_ALIASES[trimmed] ?? trimmed;
|
||||
}
|
||||
|
||||
/** CLI `agent --list-models` id for Cursor Auto (`auto - Auto`). */
|
||||
export const CURSOR_AUTO_MODEL_ID = 'auto';
|
||||
|
||||
/** ACP parameterized wire ids use bracket params; CLI `agent --list-models` slugs do not. */
|
||||
export function isCursorAcpWireModelId(modelId: string): boolean {
|
||||
const trimmed = modelId.trim();
|
||||
return trimmed === 'default[]' || trimmed.includes('[');
|
||||
}
|
||||
|
||||
/** True for CLI Auto and the legacy default aliases that must not stay as a Default option. */
|
||||
export function isCursorAutoModelId(modelId: string | null | undefined): boolean {
|
||||
const normalized = modelId?.trim().toLowerCase();
|
||||
return normalized === 'auto' || normalized === 'default' || normalized === 'default[]';
|
||||
}
|
||||
|
||||
/** Spawn `--model` value: pin Auto as `auto`. Empty/unset omits `--model`. */
|
||||
export function cursorSpawnModelId(model: string | null | undefined): string | null {
|
||||
const trimmed = model?.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
return isCursorAutoModelId(trimmed) ? CURSOR_AUTO_MODEL_ID : trimmed;
|
||||
}
|
||||
|
||||
export function cursorModelBaseId(modelId: string): string {
|
||||
const trimmed = modelId.trim();
|
||||
const bracket = trimmed.indexOf('[');
|
||||
return bracket === -1 ? trimmed : trimmed.slice(0, bracket);
|
||||
}
|
||||
|
||||
function stripCursorFamilyPrefix(base: string): string {
|
||||
return base.startsWith('cursor-') ? base.slice('cursor-'.length) : base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare an ACP wire base with a CLI sku base. Cursor's CLI keeps a legacy `cursor-`
|
||||
* family prefix for some models (`cursor-grok-4.6-high` vs ACP base `grok-4.6`), so a
|
||||
* plain equality check silently drops those variant rows.
|
||||
*/
|
||||
export function cursorModelBaseMatches(a: string, b: string): boolean {
|
||||
const left = a.trim();
|
||||
const right = b.trim();
|
||||
if (left === right) {
|
||||
return true;
|
||||
}
|
||||
return stripCursorFamilyPrefix(left) === stripCursorFamilyPrefix(right);
|
||||
}
|
||||
|
||||
/** Longest-first suffixes from Cursor CLI sku ids (e.g. `gpt-5.5-high-fast` → `gpt-5.5`). */
|
||||
const CLI_SKU_SUFFIXES = [
|
||||
'-extra-high-fast',
|
||||
@@ -116,6 +152,14 @@ export function parseCursorWireParams(modelId: string): Record<string, string> {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter hints carried by a CLI `agent --list-models` sku
|
||||
* (effort/reasoning/thinking/fast suffixes).
|
||||
*/
|
||||
export function parseCursorSkuParamHints(slug: string): Record<string, string> {
|
||||
return inferSkuParamHints(slug);
|
||||
}
|
||||
|
||||
function inferSkuParamHints(slug: string): Record<string, string> {
|
||||
const lower = slug.toLowerCase();
|
||||
const hints: Record<string, string> = {};
|
||||
|
||||
@@ -18,6 +18,7 @@ export * from './historySync'
|
||||
export * from './messageTruncation'
|
||||
export * from './sessionSummary'
|
||||
export * from './sessionCitation'
|
||||
export * from './sessionLifecycle'
|
||||
export * from './sessionExport'
|
||||
export * from './piThinkingLevel'
|
||||
export * from './runnerCapabilities'
|
||||
|
||||
@@ -46,6 +46,8 @@ export const RPC_METHODS = {
|
||||
ListGrokReasoningEffortOptions: 'listGrokReasoningEffortOptions',
|
||||
ListCopilotModelsForCwd: 'listCopilotModelsForCwd',
|
||||
ListCopilotModels: 'listCopilotModels',
|
||||
ListKimiModelsForCwd: 'listKimiModelsForCwd',
|
||||
ListKimiModels: 'listKimiModels',
|
||||
ListOpencodeReasoningEffortOptions: 'listOpencodeReasoningEffortOptions',
|
||||
ListAgyModels: 'listAgyModels',
|
||||
/** Deliver one queued message into the active turn (Pi / Codex / Cursor). */
|
||||
@@ -60,4 +62,14 @@ export const RPC_METHODS = {
|
||||
|
||||
export const RPC_TARGET_MISSING_ERROR_CODE = 'rpc_target_missing' as const
|
||||
|
||||
/**
|
||||
* Thrown by a permission handler's handleMissingPendingResponse when a
|
||||
* Permission RPC response arrives for a request the CLI no longer has
|
||||
* pending (already answered, or canceled on the agent side). Shared so the
|
||||
* hub can match on the specific message rather than treating any error on
|
||||
* this RPC method as "not found" — see RpcGateway.approvePermission/
|
||||
* denyPermission.
|
||||
*/
|
||||
export const PERMISSION_REQUEST_NOT_FOUND_MESSAGE = 'Permission request not found or already resolved' as const
|
||||
|
||||
export type RpcMethod = typeof RPC_METHODS[keyof typeof RPC_METHODS]
|
||||
|
||||
@@ -103,6 +103,14 @@ export const MetadataSchema = z.object({
|
||||
state: z.enum(['resuming', 'quarantined']),
|
||||
machineId: z.string(),
|
||||
startedAt: z.number(),
|
||||
// Same durability as piResumeAttempt: clear-before-spawn +
|
||||
// rollbackSafe:false quarantine must not lose archive fields (#1911).
|
||||
archiveSnapshot: z.object({
|
||||
lifecycleState: z.string().optional(),
|
||||
lifecycleStateSince: z.number().optional(),
|
||||
archivedBy: z.string().optional(),
|
||||
archiveReason: z.string().optional(),
|
||||
}).optional(),
|
||||
}).optional(),
|
||||
tools: z.array(z.string()).optional(),
|
||||
slashCommands: z.array(z.string()).optional(),
|
||||
@@ -116,8 +124,15 @@ export const MetadataSchema = z.object({
|
||||
hostPid: z.number().optional(),
|
||||
hapiMcpUrl: z.string().url().optional(),
|
||||
startedBy: z.enum(['runner', 'terminal']).optional(),
|
||||
// 'running' | 'idle' | 'archived' (see shared/src/sessionLifecycle.ts).
|
||||
// 'idle' is written by the hub's keepalive-idle reconciler (tiann/hapi#1820)
|
||||
// and reverts to 'running' on the next agent progress.
|
||||
lifecycleState: z.string().optional(),
|
||||
lifecycleStateSince: z.number().optional(),
|
||||
// Opt out of keepalive-idle reconciliation for sessions that are meant to
|
||||
// sit quiet indefinitely (operator holding pens, sessions owning work the
|
||||
// hub cannot see). Never reconciled to 'idle' while true.
|
||||
idleReconcileExempt: z.boolean().optional(),
|
||||
archivedBy: z.string().optional(),
|
||||
archiveReason: z.string().optional(),
|
||||
// Set only after a completed fresh-session clear. The source row remains
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* `metadata.lifecycleState` vocabulary.
|
||||
*
|
||||
* Two different liveness signals travel on a Session and they answer
|
||||
* different questions (tiann/hapi#1820):
|
||||
*
|
||||
* - `active` / `activeAt` — **transport** liveness. The CLI socket is
|
||||
* connected and its `session-alive` keepalive is landing. It says nothing
|
||||
* about whether the agent behind that socket is doing, or has recently
|
||||
* done, any work.
|
||||
* - `metadata.lifecycleState` — **agent** liveness. `running` while the
|
||||
* session is a live working session, `idle` once the hub has observed
|
||||
* keepalives with no agent progress for the configured window, `archived`
|
||||
* once the session is closed.
|
||||
*
|
||||
* `idle` is a reversible, non-destructive marker: the session stays `active`
|
||||
* (its CLI really is reachable and a turn would be served immediately), it is
|
||||
* simply flagged as keepalive-only so operators and the session list can tell
|
||||
* a working fleet from a pile of zombies.
|
||||
*/
|
||||
|
||||
export const SESSION_LIFECYCLE_RUNNING = 'running'
|
||||
export const SESSION_LIFECYCLE_IDLE = 'idle'
|
||||
export const SESSION_LIFECYCLE_ARCHIVED = 'archived'
|
||||
|
||||
/**
|
||||
* True for the lifecycle values that mean "a CLI still owns this session".
|
||||
*
|
||||
* Call sites that used to compare against `'running'` literally must use this
|
||||
* instead, otherwise a session that the hub reconciled to `idle` reads as a
|
||||
* dead row and becomes eligible for archive-as-stale / migrate-over paths.
|
||||
*/
|
||||
export function isLiveLifecycleState(value: unknown): boolean {
|
||||
return value === SESSION_LIFECYCLE_RUNNING || value === SESSION_LIFECYCLE_IDLE
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
listConfiguredTranscriptionProviders,
|
||||
listConfiguredVoiceBackends,
|
||||
resolveEffectiveVoiceBackend,
|
||||
resolveVoiceMaxDurationSeconds,
|
||||
resolveHubVoiceBackend
|
||||
} from './voice'
|
||||
|
||||
@@ -91,3 +92,29 @@ describe('resolveEffectiveVoiceBackend', () => {
|
||||
expect(resolveEffectiveVoiceBackend([], null, null)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveVoiceMaxDurationSeconds', () => {
|
||||
test('defaults to 1800s when unset or blank', () => {
|
||||
expect(resolveVoiceMaxDurationSeconds(undefined)).toBe(1800)
|
||||
expect(resolveVoiceMaxDurationSeconds(' ')).toBe(1800)
|
||||
})
|
||||
|
||||
test('accepts the inclusive 60..7200 range', () => {
|
||||
expect(resolveVoiceMaxDurationSeconds('60')).toBe(60)
|
||||
expect(resolveVoiceMaxDurationSeconds(' 7200 ')).toBe(7200)
|
||||
})
|
||||
|
||||
test('rejects out-of-range and non-integer values', () => {
|
||||
for (const bad of ['59', '7201', '0', '-1', 'abc', '1800.5']) {
|
||||
expect(() => resolveVoiceMaxDurationSeconds(bad)).toThrow(/between 60 and 7200/)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildVoiceAgentConfig max duration', () => {
|
||||
test('omits conversation cap unless requested, includes it when given', () => {
|
||||
expect(buildVoiceAgentConfig().conversation_config.conversation).toBeUndefined()
|
||||
expect(buildVoiceAgentConfig({ maxDurationSeconds: 900 }).conversation_config.conversation)
|
||||
.toEqual({ max_duration_seconds: 900 })
|
||||
})
|
||||
})
|
||||
|
||||
+40
-1
@@ -17,6 +17,37 @@ export { VOICE_CHINESE_LANGUAGE_BLOCK } from './voicePromptLayers'
|
||||
export const ELEVENLABS_API_BASE = 'https://api.elevenlabs.io/v1'
|
||||
export const VOICE_AGENT_NAME = 'Hapi Voice Assistant'
|
||||
|
||||
/** ElevenLabs ConvAI accepts conversation caps of 60s..7200s. */
|
||||
export const VOICE_MAX_DURATION_MIN_SECONDS = 60
|
||||
export const VOICE_MAX_DURATION_MAX_SECONDS = 7200
|
||||
/**
|
||||
* Default cap on a single ConvAI conversation. ConvAI bills per minute, so this
|
||||
* also bounds the cost of a dead-but-open conversation; deliberately well below
|
||||
* the 7200s ceiling. ElevenLabs' own default (600s) cuts real conversations off.
|
||||
*/
|
||||
export const VOICE_MAX_DURATION_DEFAULT_SECONDS = 1800
|
||||
|
||||
/**
|
||||
* Resolve the configured conversation cap (env ELEVENLABS_MAX_DURATION_SECONDS).
|
||||
* Unset/blank -> default. Throws a descriptive Error when not an integer in range.
|
||||
*/
|
||||
export function resolveVoiceMaxDurationSeconds(raw: string | undefined): number {
|
||||
const text = raw?.trim()
|
||||
if (!text) return VOICE_MAX_DURATION_DEFAULT_SECONDS
|
||||
const value = Number(text)
|
||||
if (
|
||||
!Number.isInteger(value)
|
||||
|| value < VOICE_MAX_DURATION_MIN_SECONDS
|
||||
|| value > VOICE_MAX_DURATION_MAX_SECONDS
|
||||
) {
|
||||
throw new Error(
|
||||
`ELEVENLABS_MAX_DURATION_SECONDS must be an integer between `
|
||||
+ `${VOICE_MAX_DURATION_MIN_SECONDS} and ${VOICE_MAX_DURATION_MAX_SECONDS} (got "${text}")`
|
||||
)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
const DEFAULT_COMPOSED_LAYERS: VoicePromptLayerInput = {
|
||||
identity: '',
|
||||
character: '',
|
||||
@@ -161,6 +192,9 @@ export interface VoiceAgentConfig {
|
||||
turn_timeout: number
|
||||
silence_end_call_timeout: number
|
||||
}
|
||||
conversation?: {
|
||||
max_duration_seconds: number
|
||||
}
|
||||
tts: {
|
||||
voice_id: string
|
||||
model_id: string
|
||||
@@ -194,7 +228,7 @@ export interface VoiceAgentConfig {
|
||||
* Build the agent configuration for Hapi Voice Assistant.
|
||||
* Used by both server-side auto-creation and client-side configuration.
|
||||
*/
|
||||
export function buildVoiceAgentConfig(): VoiceAgentConfig {
|
||||
export function buildVoiceAgentConfig(options: { maxDurationSeconds?: number } = {}): VoiceAgentConfig {
|
||||
return {
|
||||
name: VOICE_AGENT_NAME,
|
||||
conversation_config: {
|
||||
@@ -213,6 +247,11 @@ export function buildVoiceAgentConfig(): VoiceAgentConfig {
|
||||
turn_timeout: 30.0,
|
||||
silence_end_call_timeout: 600.0
|
||||
},
|
||||
// Omitted unless provided so clients that PATCH an existing agent
|
||||
// without knowing the hub setting do not clobber its cap.
|
||||
...(options.maxDurationSeconds !== undefined
|
||||
? { conversation: { max_duration_seconds: options.maxDurationSeconds } }
|
||||
: {}),
|
||||
tts: {
|
||||
voice_id: 'cgSgspJ2msm6clMCkdW9', // Jessica
|
||||
model_id: 'eleven_flash_v2',
|
||||
|
||||
Reference in New Issue
Block a user