@takboo/dsh-coopanion 0.4.5 → 0.4.6

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/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/notification-broker.ts", "../src/notification-contract.ts", "../src/bridge.ts", "../src/model.ts", "../src/controls.ts"],
4
- "sourcesContent": ["import { randomUUID } from 'node:crypto';\nimport type { Context, Volatile } from '@deepseek-ai/cordis';\nimport type {} from '@deepseek-ai/dsh-client-connection';\nimport type {} from '@deepseek-ai/dsh-settings';\nimport type {} from '@deepseek-ai/dsh-agent';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport type {} from '@deepseek-ai/dsh-user-questions';\nimport type {} from '@deepseek-ai/dsh-api-session-controller';\nimport type {} from '@deepseek-ai/dsh-session-projection';\nimport { SessionId, type Session } from '@deepseek-ai/dsh-session';\nimport { NotificationBroker, type NotificationEvent } from './notification-broker.ts';\nimport { notificationPreferencesSchema, notificationEndpoints, notificationRequests, noticeId } from './notification-contract.ts';\nimport { createUserMessage } from '@deepseek-ai/dsh-llm';\nimport z from '@deepseek-ai/schemastery';\nimport { ElectronBridge, isRecord, type PetBridge, type DesktopOptions } from './bridge.ts';\nimport { PetModel } from './model.ts';\nimport { PetControls } from './controls.ts';\nimport { z as wire } from 'zod';\n\nexport const name = 'dsh-coopanion';\nexport const inject = ['agents'];\nexport interface Config {\n size: Volatile<number>; roam: Volatile<boolean>; notifications: Volatile<boolean>;\n systemNotifications: Volatile<boolean>; reminders: Volatile<boolean>; reminderDelayMs: Volatile<number>;\n bubbleDurationMs: Volatile<number>; autoStart: Volatile<boolean>; electronPath?: string;\n}\nexport const Config = z.object({\n size: z.number().min(90).max(240).default(180).volatile(),\n roam: z.boolean().default(true).volatile(),\n notifications: z.boolean().default(true).volatile(),\n systemNotifications: z.boolean().default(false).volatile(),\n reminders: z.boolean().default(true).volatile(),\n reminderDelayMs: z.number().step(1).min(60000).max(86400000).default(600000).volatile(),\n bubbleDurationMs: z.number().min(2000).max(60000).default(12000).volatile(),\n autoStart: z.boolean().default(true).volatile(),\n electronPath: z.string(),\n});\n\n/** Mounts the pet on public Harness events, delegates approvals, and routes explicit user chat to a selected live agent. */\nexport async function apply(ctx: Context, config: Config): Promise<void> {\n ctx.inject(['settings'], child => { child.effect(() => child.settings.configure({ auto: false }, ctx.fiber)); });\n await mountPet(ctx, config, new ElectronBridge());\n}\n\n/** Shared assembly used by integration tests with an IPC substitute for the native window. */\nexport async function mountPet(ctx: Context, options: Config, bridge: PetBridge): Promise<void> {\n const model = new PetModel();\n const preferences: Partial<Pick<DesktopOptions, 'roam' | 'notifications'>> = {};\n let savePreference: ((field: 'roam' | 'notifications', value: boolean) => Promise<void>) | undefined;\n ctx.inject(['settings'], child => { savePreference = (field, value) => child.settings.mutate('dsh-coopanion', [{ op: 'set', path: [field], value }]); });\n const currentOptions = (): DesktopOptions => ({ size: options.size.get(), roam: options.roam.get(), notifications: options.notifications.get(), bubbleDurationMs: options.bubbleDurationMs.get(), systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get(), electronPath: options.electronPath, locale, ...preferences });\n const controls = new PetControls(bridge, currentOptions);\n let locale = 'zh';\n let navigation: { sessionId: string; expires: number } | undefined;\n ctx.provide('coopanion', controls);\n const update = () => {\n const snapshot = model.snapshot(), live = new Set<string>(ctx.agents.list().map(agent => agent.session.id));\n bridge.update({ ...snapshot, sessions: snapshot.sessions.map(session => ({ ...session, chatAvailable: live.has(session.id) })) });\n };\n let mounted = false;\n const notificationPrefs = () => notificationPreferencesSchema.parse({ notifications: currentOptions().notifications, systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get() });\n const syncNotifications = () => {\n if (!mounted) return;\n const snapshot = broker.snapshot(); model.interactions(snapshot.interactions); bridge.notificationState?.(snapshot); update();\n };\n const broker = new NotificationBroker({ changed: syncNotifications, presentRole: (value, runtime) => bridge.presentRole?.(value, runtime) ?? false });\n broker.preferences(notificationPrefs());\n ctx.effect(() => () => broker.dispose());\n ctx.effect(() => controls.onState(state => broker.runtime(state)));\n let questions: ((session: Session, live?: boolean) => void) | undefined;\n ctx.inject(['sessionProjections', 'userQuestions'], child => {\n const sync = (session: Session, live = true) => {\n try {\n const view = child.sessionProjections.snapshot(session, ['userQuestions']).values.userQuestions;\n if (view) broker.questions(session, view, live);\n } catch (error) { child.logger.warn(`Question projection unavailable: ${String(error).slice(0, 300)}`); }\n };\n questions = sync;\n child.effect(() => () => { if (questions === sync) questions = undefined; });\n // A service is provided before its constructor registers projection units.\n // Fold after that registration turn, including sessions without a live agent.\n queueMicrotask(() => {\n if (!mounted || questions !== sync) return;\n for (const session of child.get('sessions')?.list() ?? ctx.agents.list().map(agent => agent.session)) sync(session, false);\n });\n });\n let testSource: (() => Promise<Session>) | undefined;\n ctx.inject(['sessions', 'sessionController'], child => {\n let source: Promise<Session> | undefined;\n const create = () => source ??= child.sessionController.create({ sessionId: SessionId(`coopanion-notification-test-${randomUUID()}`), cwd: process.cwd() }).then(value => {\n const session = child.sessions.get(value.sessionId); if (!session) throw new Error('Notification test source unavailable'); return session;\n }).catch(error => { source = undefined; throw error; });\n testSource = create; child.effect(() => () => { if (testSource === create) testSource = undefined; });\n });\n let streamUpdate: ReturnType<typeof setTimeout> | undefined;\n ctx.effect(() => () => clearTimeout(streamUpdate));\n ctx.effect(() => () => controls.dispose());\n ctx.effect(() => {\n const timer = setInterval(() => { if (model.settle()) update(); }, 250);\n timer.unref(); return () => clearInterval(timer);\n });\n ctx.on('settings/document-updated', ns => { if (ns === 'dsh-coopanion') { broker.preferences(notificationPrefs()); controls.configure(); } });\n ctx.inject(['connection'], child => {\n const dispatch = async (endpoint: string, payload: unknown, signal: AbortSignal) => {\n try {\n if (signal.aborted) throw new Error('\u8BF7\u6C42\u5DF2\u53D6\u6D88');\n if (endpoint === 'status') {\n wire.object({}).strict().parse(payload);\n return { ok: true, value: controls.status() };\n }\n if (endpoint === 'navigation') {\n wire.object({}).strict().parse(payload);\n const value = navigation && navigation.expires > Date.now() ? { sessionId: navigation.sessionId } : null;\n navigation = undefined;\n return { ok: true, value };\n }\n if (endpoint === 'notification-state') { const input = notificationRequests.state.parse(payload); if (input.locale && input.locale !== locale) { locale = input.locale; controls.configure(); } return { ok: true, value: broker.snapshot() }; }\n if (endpoint === 'notification-claim') { const input = notificationRequests.claim.parse(payload); return { ok: true, value: broker.claim(input.clientId, input.generation) }; }\n if (endpoint === 'notification-receipt') { return { ok: true, value: { accepted: broker.receipt(notificationRequests.receipt.parse(payload)) } }; }\n if (endpoint === 'notification-snooze') { const input = notificationRequests.snooze.parse(payload); if (!broker.snooze(input.interactionId, input.generation)) throw new Error('\u5F85\u5904\u7406\u8BF7\u6C42\u5DF2\u53D8\u5316\u6216\u63D0\u9192\u6682\u4E0D\u53EF\u7528'); return { ok: true, value: { accepted: true } }; }\n if (endpoint === 'notification-test') {\n const input = notificationRequests.test.parse(payload), state = broker.snapshot().runtime, prefs = notificationPrefs();\n if (!testSource || state.phase !== 'running' || state.visible || state.suspended || state.visibilityRevision === 0 || input.generation !== state.generation || !prefs.notifications || !prefs.systemNotifications) throw new Error('\u8BF7\u542F\u52A8\u5E76\u9690\u85CF\u89D2\u8272\uFF0C\u5F00\u542F\u7CFB\u7EDF\u901A\u77E5\u540E\u6D4B\u8BD5');\n const session = await testSource();\n if (signal.aborted) throw new Error('\u8BF7\u6C42\u5DF2\u53D6\u6D88');\n const latest = broker.snapshot().runtime;\n if (latest.generation !== state.generation || latest.visibilityRevision !== state.visibilityRevision || latest.phase !== 'running' || latest.visible || latest.suspended) throw new Error('\u684C\u5BA0\u72B6\u6001\u5DF2\u53D8\u5316');\n const turn = (session.snapshotEvents().findLast(event => event.type === 'turn/start')?.data as { turn?: number } | undefined)?.turn ?? 0;\n session.append('turn/start', { turn: turn + 1 });\n session.append('turn/end', { turn: turn + 1, reason: { kind: 'completed' } });\n const event = session.snapshotEvents().at(-1)!;\n const claim = broker.claim(input.clientId, input.generation, noticeId(session.id, turn + 1, event.seq, 'completed', 'initial'));\n if (!claim) throw new Error('\u6D4B\u8BD5\u901A\u77E5\u672A\u80FD\u9886\u53D6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5');\n return { ok: true, value: claim };\n }\n if (endpoint !== 'control') throw new Error('\u672A\u77E5\u7684\u684C\u5BA0\u64CD\u4F5C');\n const { command } = wire.object({ command: wire.enum(['start', 'show', 'hide', 'restart', 'stop', 'characters']) }).strict().parse(payload);\n return { ok: true, value: await controls.command(command) };\n } catch (error) { return { ok: false, error: { code: 'coopanion/rejected', message: String(error instanceof Error ? error.message : error).slice(0, 600), details: {} } }; }\n };\n // Exact Connection routes coexist with the Gateway's exclusive /api interceptor.\n // The Connection carrier applies its normal Host/Origin and authentication checks.\n for (const endpoint of ['status', 'control', 'navigation', ...notificationEndpoints] as const) {\n child.effect(() => child.connection.fetch.register({\n path: `/api/coopanion/${endpoint}`, methods: ['POST'], requestBody: 'buffered',\n fetch: async request => {\n const parsed = wire.object({ type: wire.literal('client-request'), rpcId: wire.string().min(1).max(128), method: wire.literal(`coopanion/${endpoint}`), payload: wire.unknown() }).strict().safeParse(await request.json().catch(() => undefined));\n if (!parsed.success) return Response.json({ error: 'Invalid desktop pet request' }, { status: 400 });\n return Response.json({ type: 'server-response', rpcId: parsed.data.rpcId, result: await dispatch(endpoint, parsed.data.payload, request.signal) });\n },\n }));\n }\n });\n ctx.inject(['sessions'], child => { for (const session of child.sessions.list()) { model.restore(session); broker.restore(session); questions?.(session, false); } syncNotifications(); update(); });\n for (const agent of ctx.agents.list()) { model.restore(agent.session); broker.restore(agent.session); questions?.(agent.session, false); if (agent.status === 'running') model.running(agent.session); }\n ctx.on('session/created', session => { model.created(session); broker.restore(session); questions?.(session, false); update(); });\n ctx.on('agent/created', ({ agent }) => { model.restore(agent.session); broker.restore(agent.session); questions?.(agent.session, false); if (agent.status === 'running') model.running(agent.session); update(); return undefined; });\n ctx.on('agent/status', ({ agent, status }) => { if (status === 'running') model.running(agent.session); else model.idle(agent.session.id); update(); });\n ctx.on('agent/assistant-stream', ({ agent, frame }) => {\n if (!model.stream(agent.session, frame) || streamUpdate) return;\n // Coalesce high-frequency provider deltas; durable events still publish immediately.\n streamUpdate = setTimeout(() => { streamUpdate = undefined; update(); }, 40);\n });\n ctx.on('agent/disposed', ({ agent }) => { model.idle(agent.session.id); model.detached(agent.session.id); update(); });\n ctx.on('session/event', (session, event) => { broker.consume(session, event); model.consume(session, event); questions?.(session); syncNotifications(); update(); });\n ctx.on('session/disposed', session => { broker.remove(session.id); model.remove(session.id); update(); });\n ctx.inject(['userQuestions'], child => {\n child.on('user-questions/request', async (request, next) => {\n const session = request.agent?.session;\n if (!session || session.header.origin === 'subagent') return next();\n model.observe(session);\n const events: readonly NotificationEvent[] = session.snapshotEvents();\n const callId = request.wait?.callId;\n const origin = callId ? events.findLast(event => (event.type === 'tool/call' && event.data.callId === callId) || (event.type === 'tool/ptc-dispatch' && event.data.subCallId === callId)) : undefined;\n const anchor = origin ?? events.at(-1);\n const turnEvent = events.findLast(event => event.type === 'turn/start');\n const finish = broker.question(session, { nativeId: origin && callId ? callId : randomUUID(), turn: turnEvent?.type === 'turn/start' ? turnEvent.data.turn : 0, seq: anchor?.seq ?? 0, preview: request.questions.map(q => q.question).join('\\n'), signal: request.signal, source: origin ? 'event' : 'runtime' });\n questions?.(session); syncNotifications();\n try { return await next(); }\n finally { questions?.(session); finish(); syncNotifications(); }\n }, { prepend: true });\n });\n const onAction = (action: unknown) => {\n if (!isRecord(action)) return;\n if (action.type === 'notification-snooze') {\n const input = notificationRequests.snooze.safeParse({ interactionId: action.interactionId, generation: action.generation });\n const ok = input.success && broker.snooze(input.data.interactionId, input.data.generation);\n if (typeof action.interactionId === 'string') bridge.snoozeResult?.(action.interactionId, ok, ok ? undefined : '\u5F85\u5904\u7406\u8BF7\u6C42\u5DF2\u53D8\u5316\u6216\u63D0\u9192\u6682\u4E0D\u53EF\u7528');\n syncNotifications(); return;\n }\n if (action.type === 'preference' && (action.field === 'roam' || action.field === 'notifications') && typeof action.value === 'boolean') {\n const field = action.field, value = action.value;\n void (async () => {\n try {\n if (savePreference) await savePreference(field, value); else preferences[field] = value;\n broker.preferences(notificationPrefs()); controls.configure();\n } catch { bridge.notify({ title: '\u8BBE\u7F6E\u672A\u80FD\u4FDD\u5B58', body: '\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u63D2\u4EF6\u8BBE\u7F6E\u3002', sessionId: model.snapshot().sessionId ?? '' }); }\n })(); return;\n }\n if (action.type === 'select' && typeof action.sessionId === 'string') { model.select(action.sessionId); update(); return; }\n if (action.type === 'read' && typeof action.resultId === 'string') { if (model.read(action.resultId)) update(); return; }\n if (action.type === 'open-session' && typeof action.sessionId === 'string') {\n if (!model.select(action.sessionId)) return;\n navigation = { sessionId: action.sessionId, expires: Date.now() + 30000 };\n bridge.focusHarness?.(); update(); return;\n }\n if (action.type !== 'chat' || typeof action.text !== 'string' || typeof action.sessionId !== 'string') return;\n const text = action.text.trim();\n if (!text || text.length > 2000 || !model.select(action.sessionId)) return;\n const id = model.snapshot().sessionId;\n const agent = ctx.agents.list().find(agent => agent.session.id === id);\n if (!agent || agent.session.header.origin === 'subagent') {\n bridge.notify({ title: '\u4F1A\u8BDD\u5C1A\u672A\u5C31\u7EEA', body: '\u8BF7\u5148\u56DE\u5230 Harness \u6253\u5F00\u8FD9\u4E2A\u4F1A\u8BDD\uFF0C\u7136\u540E\u518D\u53D1\u9001\u6D88\u606F\u3002', sessionId: action.sessionId }); update(); return;\n }\n try {\n ctx.agents.withInitiator(agent, () => agent.followup(createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'user' } })));\n update();\n } catch (error) {\n bridge.notify({ title: '\u6D88\u606F\u672A\u80FD\u53D1\u9001', body: '\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u4F1A\u8BDD\u72B6\u6001\u3002', sessionId: action.sessionId });\n ctx.logger.warn(`Desktop pet chat failed: ${String(error)}`);\n }\n };\n ctx.effect(() => { bridge.onAction(onAction); return () => bridge.removeAction(onAction); });\n if (bridge instanceof ElectronBridge) {\n const onFailure = (error: Error) => ctx.logger.warn(error.message);\n ctx.effect(() => { bridge.on('failure', onFailure); return () => bridge.off('failure', onFailure); });\n }\n mounted = true; syncNotifications(); update();\n if (options.autoStart.get()) {\n void controls.command('start').then(status => { if (status.error) ctx.logger.warn(status.error); }, error => ctx.logger.warn(String(error).slice(0, 600)));\n }\n}\n\ndeclare module '@deepseek-ai/cordis' { interface Context { coopanion: PetControls; } }\n", "import { randomUUID } from 'node:crypto';\nimport type { Session, SessionEvent } from '@deepseek-ai/dsh-session';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport {\n NOTIFICATION_PROTOCOL, deliveryReceiptSchema, interactionId, noticeId, noticeSchema,\n notificationPreferencesSchema, runtimeSchema,\n type DeliveryClaim, type DeliveryReceipt, type NotificationPreferences,\n type NotificationRuntime, type NotificationSnapshot, type PendingInteraction, type TaskNotice,\n} from './notification-contract.ts';\n\nexport type NotificationEvent = SessionEvent | { type: 'tool/ptc-dispatch'; data: { name: string; subCallId: string; turn?: number }; seq: number; time: number };\ntype SourceSession = Pick<Session, 'id' | 'header'> & Partial<Pick<Session, 'snapshotEvents'>>;\nexport interface QuestionProjection {\n active: readonly { callId: string; state: 'open' | 'continued'; questions: readonly { question: string }[] }[];\n settled?: readonly { callId: string }[];\n}\nexport interface LiveQuestion {\n nativeId: string; turn: number; seq: number; preview: string; signal?: AbortSignal; source?: 'event' | 'runtime';\n}\nexport interface BrokerClock {\n now(): number;\n setTimeout(callback: () => void, delay: number): unknown;\n clearTimeout(timer: unknown): void;\n}\nexport interface BrokerOptions {\n clock?: BrokerClock;\n /** Must synchronously enqueue into the acknowledged native generation, or return false. */\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n changed?(): void;\n token?(): string;\n claimDurationMs?: number;\n clientLifetimeMs?: number;\n}\ntype SourceKind = 'event' | 'runtime';\ntype SourcedNotice = TaskNotice & { source?: SourceKind };\ninterface RequestState extends PendingInteraction { source?: SourceKind; projected: boolean; snoozes: number; cleanup?: () => void; }\ninterface QuestionOrigin { turn: number; seq: number; time: number; }\ninterface SourceState { seq: number; turn: number; finalText: string; label: string; calls: Map<string, QuestionOrigin>; }\ninterface Delivery {\n notice: TaskNotice; state: 'pending' | 'claimed' | DeliveryReceipt['state'] | 'role' | 'cancelled';\n claim?: DeliveryClaim; requested: boolean; receipts: DeliveryReceipt[];\n}\nconst realClock: BrokerClock = {\n now: Date.now,\n setTimeout: (callback, delay) => { const timer = setTimeout(callback, delay); timer.unref(); return timer; },\n clearTimeout: timer => clearTimeout(timer as ReturnType<typeof setTimeout>),\n};\nconst title: Record<TaskNotice['category'], string> = {\n completed: '\u4EFB\u52A1\u5B8C\u6210', approval: '\u7B49\u4F60\u786E\u8BA4', question: '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60', error: '\u9700\u8981\u5173\u6CE8',\n stopped: '\u5148\u505C\u5728\u8FD9\u91CC', interrupted: '\u4EFB\u52A1\u4E2D\u65AD\u4E86', blocked: '\u4EFB\u52A1\u6682\u65F6\u505C\u4E0B\u4E86', 'max-tokens': '\u8F93\u51FA\u8FBE\u5230\u4E0A\u9650',\n};\nconst body: Record<TaskNotice['category'], string> = {\n completed: '\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002', approval: '\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\u3002', question: '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\u3002', error: '\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002',\n stopped: '\u5148\u505C\u5728\u8FD9\u91CC\uFF0C\u968F\u65F6\u7EE7\u7EED\u3002', interrupted: '\u8FD9\u6BB5\u4EFB\u52A1\u4E2D\u65AD\u4E86\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002', blocked: '\u770B\u770B\u4E0B\u4E00\u6B65\u600E\u4E48\u7EE7\u7EED\u3002', 'max-tokens': '\u770B\u770B\u4E0B\u4E00\u6B65\u600E\u4E48\u7EE7\u7EED\u3002',\n};\n\n/** Event truth, reminder scheduling and delivery ownership stay in the Host. Views never settle requests. */\nexport class NotificationBroker {\n private readonly clock: BrokerClock;\n private prefs = notificationPreferencesSchema.parse({});\n private run: NotificationRuntime = { phase: 'stopped', generation: 0, visibilityRevision: 0, visible: false, suspended: false };\n private readonly sources = new Map<string, SourceState>();\n private readonly requests = new Map<string, RequestState>();\n private readonly deliveries = new Map<string, Delivery>();\n private readonly clients = new Map<string, number>();\n private readonly problems: { code: string; sessionId: string; nativeId: string }[] = [];\n private timer?: unknown;\n private closed = false;\n constructor(private readonly options: BrokerOptions = {}) { this.clock = options.clock ?? realClock; }\n\n snapshot(): NotificationSnapshot {\n return { protocol: NOTIFICATION_PROTOCOL, runtime: { ...this.run }, interactions: [...this.requests.values()].filter(r => r.state !== 'settled').map(r => this.publicRequest(r)) };\n }\n /** Bounded diagnostics; a requested receipt alone never means the OS displayed a notification. */\n diagnostics(): { code: string; sessionId: string; nativeId: string }[] { return this.problems.map(p => ({ ...p })); }\n history(): { notice: TaskNotice; state: Delivery['state']; receipts: DeliveryReceipt[] }[] {\n return [...this.deliveries.values()].map(d => ({ notice: structuredClone(d.notice), state: d.state, receipts: d.receipts.map(r => ({ ...r })) }));\n }\n preferences(value: Partial<NotificationPreferences>): void {\n const delayChanged = value.reminderDelayMs !== undefined && value.reminderDelayMs !== this.prefs.reminderDelayMs;\n this.prefs = notificationPreferencesSchema.parse({ ...this.prefs, ...value });\n if (!this.prefs.reminders) for (const delivery of this.deliveries.values()) if (delivery.notice.stage === 'reminder') this.cancel(delivery);\n if (!this.prefs.notifications) this.cancelDeliveries();\n for (const request of this.requests.values()) {\n if (request.state === 'settled') continue;\n if (!this.prefs.notifications || !this.prefs.reminders) request.dueAt = null;\n else if ((request.dueAt === null || delayChanged) && request.automaticReminders === 0) request.dueAt = this.clock.now() + this.prefs.reminderDelayMs;\n }\n this.refresh();\n }\n runtime(value: NotificationRuntime): boolean {\n const next = runtimeSchema.parse(value);\n if (next.phase === 'running' && this.run.phase === 'running' && next.generation === this.run.generation && next.visibilityRevision === this.run.visibilityRevision && next.visible !== this.run.visible) return false;\n if (this.closed || next.generation < this.run.generation || (next.generation === this.run.generation && next.visibilityRevision < this.run.visibilityRevision)) return false;\n const generationChanged = next.generation !== this.run.generation;\n const changed = next.generation !== this.run.generation || next.visibilityRevision !== this.run.visibilityRevision || next.phase !== this.run.phase || next.suspended !== this.run.suspended;\n if (changed) for (const delivery of this.deliveries.values()) {\n if (next.generation === this.run.generation && next.phase === 'running' && !next.suspended && !delivery.claim && delivery.state === 'pending') { delivery.state = 'pending'; delivery.claim = undefined; }\n else this.cancel(delivery);\n }\n this.run = next;\n if (next.phase !== 'running' || generationChanged) for (const r of this.requests.values()) r.dueAt = null;\n if (next.phase === 'running') for (const r of this.requests.values()) if (r.state !== 'settled' && r.automaticReminders === 0 && r.dueAt === null && this.prefs.reminders && this.prefs.notifications) r.dueAt = this.clock.now() + this.prefs.reminderDelayMs;\n this.refresh(); return true;\n }\n\n /** Baseline history folds pending state; it never replays proactive initial or reminder notices. */\n restore(session: SourceSession, questions?: QuestionProjection): void {\n if (session.header.origin === 'subagent' || this.sources.has(session.id)) return;\n this.source(session);\n for (const event of session.snapshotEvents?.() ?? []) this.event(session, event, false);\n if (questions) this.questions(session, questions, false);\n this.refresh();\n }\n consume(session: SourceSession, event: NotificationEvent): void {\n if (this.closed || session.header.origin === 'subagent') return;\n this.event(session, event, true); this.refresh();\n }\n private source(session: SourceSession): SourceState {\n let state = this.sources.get(session.id);\n if (!state) {\n if (this.sources.size >= 100) this.remove(this.sources.keys().next().value!);\n state = { seq: -1, turn: 0, finalText: '', calls: new Map(), label: session.header.cwd?.split(/[\\\\/]/).filter(Boolean).at(-1) ?? '\u4F1A\u8BDD' };\n this.sources.set(session.id, state);\n }\n return state;\n }\n private event(session: SourceSession, event: NotificationEvent, live: boolean): void {\n const source = this.source(session);\n if (event.seq <= source.seq) return;\n source.seq = event.seq;\n // Request settlements from older turns remain meaningful and use exact native identity.\n if (event.type === 'approval/decided') { this.settle(interactionId(session.id, 'approval', event.data.id)); return; }\n if (event.type === 'user/message') {\n const reply = event.data.source as { kind: string; callId?: string };\n if (reply.kind === 'user-question-reply' && reply.callId) { this.settle(interactionId(session.id, 'question', reply.callId)); return; }\n }\n if ('turn' in event.data && event.data.turn !== undefined && event.data.turn < source.turn) return;\n switch (event.type) {\n case 'turn/start': source.turn = event.data.turn; source.finalText = ''; break;\n case 'tool/call':\n if (event.data.name === 'ask_user_question') this.origin(source, event.data.callId, event.data.turn, event.seq, event.time);\n break;\n case 'tool/ptc-dispatch':\n if (event.data.name === 'ask_user_question') this.origin(source, event.data.subCallId, source.turn, event.seq, event.time);\n break;\n case 'assistant/message':\n source.finalText = event.data.message.content.some(p => p.type === 'tool-call') ? '' : event.data.message.content.filter(p => p.type === 'text').map(p => p.text).join('\\n'); break;\n case 'approval/asked':\n this.open(session.id, 'approval', event.data.id, source.turn, event.seq, event.time, `${event.data.toolName}: ${event.data.reason ?? body.approval}`, false, live); break;\n case 'turn/end': {\n source.turn = event.data.turn;\n if (event.data.reason.kind === 'forked') break;\n const category: TaskNotice['category'] = event.data.reason.kind === 'aborted' ? 'stopped' : event.data.reason.kind;\n if (live) this.enqueue(this.notice(session.id, source.turn, event.seq, event.time, category, source.finalText && category === 'completed' ? source.finalText : body[category]));\n source.finalText = '';\n // Approvals are enclosed by a turn. Durable continued questions are independently projected.\n for (const r of this.requests.values()) if (r.sessionId === session.id && r.kind === 'approval' && r.turn <= source.turn) this.settle(r.id);\n break;\n }\n }\n }\n /** Public projection is authoritative for timed questions, including continued questions after turn/end. */\n questions(session: SourceSession, projection: QuestionProjection, live = true): void {\n if (this.closed || session.header.origin === 'subagent') return;\n const source = this.source(session), active = new Set<string>();\n for (const question of projection.active) {\n const id = interactionId(session.id, 'question', question.callId); active.add(id);\n let origin = source.calls.get(question.callId);\n if (!origin) {\n const events = session.snapshotEvents?.() ?? [];\n const event = events.map(event => event as NotificationEvent).findLast(event => (event.type === 'tool/call' && event.data.callId === question.callId && event.data.name === 'ask_user_question') || (event.type === 'tool/ptc-dispatch' && event.data.subCallId === question.callId && event.data.name === 'ask_user_question'));\n if (event) {\n const start = events.findLast(prior => prior.type === 'turn/start' && prior.seq < event.seq);\n const turn = 'turn' in event.data && event.data.turn !== undefined ? event.data.turn : start?.type === 'turn/start' ? start.data.turn : 0;\n origin = { turn, seq: event.seq, time: event.time };\n }\n }\n const existing = this.requests.get(id);\n if (!origin && existing) origin = { turn: existing.turn, seq: existing.seq, time: existing.createdAt };\n if (!origin) {\n if (!this.problems.some(p => p.sessionId === session.id && p.nativeId === question.callId)) this.problems.push({ code: 'question-source-unavailable', sessionId: session.id, nativeId: question.callId });\n if (this.problems.length > 100) this.problems.shift();\n continue;\n }\n this.open(session.id, 'question', question.callId, origin.turn, origin.seq, origin.time, question.questions.map(q => q.question).join('\\n'), true, live, question.state);\n }\n for (const r of this.requests.values()) if (r.sessionId === session.id && r.projected && !active.has(r.id)) this.settle(r.id);\n for (const q of projection.settled ?? []) this.settle(interactionId(session.id, 'question', q.callId));\n this.refresh();\n }\n private origin(source: SourceState, id: string, turn: number, seq: number, time: number): void {\n source.calls.set(id, { turn, seq, time });\n if (source.calls.size > 200) source.calls.delete(source.calls.keys().next().value!);\n }\n /** Observe a runtime blocking request without claiming the answerer chain. */\n question(session: SourceSession, question: LiveQuestion): () => void {\n if (this.closed || session.header.origin === 'subagent' || question.signal?.aborted) return () => {};\n this.source(session);\n const id = interactionId(session.id, 'question', question.nativeId);\n this.open(session.id, 'question', question.nativeId, question.turn, question.seq, this.clock.now(), question.preview, false, true, 'open', question.source);\n const request = this.requests.get(id);\n if (!request) {\n this.problems.push({ code: 'request-capacity-exceeded', sessionId: session.id, nativeId: question.nativeId });\n if (this.problems.length > 100) this.problems.shift();\n return () => {};\n }\n const finish = () => { if (!request.projected) this.settle(id); this.refresh(); };\n question.signal?.addEventListener('abort', finish, { once: true });\n request.cleanup?.(); request.cleanup = () => question.signal?.removeEventListener('abort', finish);\n this.refresh(); return finish;\n }\n private open(sessionId: string, kind: PendingInteraction['kind'], nativeId: string, turn: number, seq: number, time: number, preview: string, projected: boolean, live: boolean, state: 'open' | 'continued' = 'open', sourceKind?: SourceKind): void {\n const id = interactionId(sessionId, kind, nativeId), existing = this.requests.get(id);\n if (existing) { if (existing.state !== 'settled') { existing.state = state; existing.projected ||= projected; existing.preview = preview.slice(0, 2048); } return; }\n if (this.requests.size >= 500) {\n const old = [...this.requests.values()].find(r => r.state === 'settled');\n if (old) this.requests.delete(old.id); else return;\n }\n // Restored requests keep their entrance, with no repeat automatic reminder on reload.\n const request: RequestState = { id, nativeId, sessionId, kind, turn, seq, createdAt: time, preview: preview.slice(0, 2048), state, dueAt: live && this.prefs.notifications && this.run.phase === 'running' && this.prefs.reminders ? this.clock.now() + this.prefs.reminderDelayMs : null, automaticReminders: live ? 0 : 1, projected, snoozes: 0, ...(sourceKind ? { source: sourceKind } : {}) };\n this.requests.set(id, request);\n if (live) {\n const notice = this.notice(sessionId, turn, seq, time, kind, request.preview, [id]) as SourcedNotice;\n if (sourceKind) notice.source = sourceKind;\n if (sourceKind === 'runtime') notice.id = this.identity(notice, 0, nativeId);\n this.enqueue(notice);\n }\n }\n private settle(id: string): void {\n const request = this.requests.get(id); if (!request || request.state === 'settled') return;\n request.state = 'settled'; request.dueAt = null; request.cleanup?.(); request.cleanup = undefined;\n for (const delivery of this.deliveries.values()) {\n if (!delivery.notice.requestIds.includes(id) || delivery.requested || ['role', 'cancelled'].includes(delivery.state)) continue;\n if (delivery.claim) { this.cancel(delivery); continue; }\n delivery.notice.requestIds = delivery.notice.requestIds.filter(key => key !== id && this.requests.get(key)?.state !== 'settled');\n if (!delivery.notice.requestIds.length) delivery.state = 'cancelled';\n else this.cancel(delivery); // A changed group invalidates any previously claimed payload.\n }\n }\n snooze(id: string, generation: number): boolean {\n const request = this.requests.get(id);\n if (!this.eligible() || generation !== this.run.generation || !this.prefs.reminders || !request || request.state === 'settled') return false;\n for (const delivery of this.deliveries.values()) if (!delivery.requested && delivery.notice.requestIds.includes(id) && ['pending', 'claimed'].includes(delivery.state)) this.cancel(delivery);\n request.dueAt = this.clock.now() + this.prefs.reminderDelayMs; request.snoozes++; this.refresh(); return true;\n }\n\n /** A live client poll refreshes its bounded liveness record and can own one eligible notice. */\n claim(clientId: string, generation: number, noticeId?: string): DeliveryClaim | null {\n if (!clientId || clientId.length > 2048 || this.closed || generation !== this.run.generation) return null;\n this.clients.set(clientId, this.clock.now());\n if (this.clients.size > 100) this.clients.delete(this.clients.keys().next().value!);\n this.tick();\n if (!this.eligible() || this.run.visible || !this.prefs.systemNotifications) return null;\n if ([...this.deliveries.values()].some(d => d.claim?.clientId === clientId && ['claimed', 'requested'].includes(d.state))) return null;\n const delivery = [...this.deliveries.values()].find(d => d.state === 'pending' && this.valid(d.notice) && (noticeId === undefined || d.notice.id === noticeId));\n if (!delivery) return null;\n const claim: DeliveryClaim = { token: this.options.token?.() ?? randomUUID(), clientId, generation, visibilityRevision: this.run.visibilityRevision, expiresAt: this.clock.now() + (this.options.claimDurationMs ?? 15_000), notice: structuredClone(delivery.notice) };\n delivery.state = 'claimed'; delivery.claim = claim;\n this.refresh(); return structuredClone(claim);\n }\n receipt(value: DeliveryReceipt): boolean {\n const parsed = deliveryReceiptSchema.safeParse(value); if (!parsed.success || this.closed) return false;\n const receipt = parsed.data, delivery = this.deliveries.get(receipt.noticeId), claim = delivery?.claim;\n if (!delivery || !claim || claim.token !== receipt.token || claim.clientId !== receipt.clientId || claim.generation !== receipt.generation || delivery.state === 'cancelled') return false;\n if (receipt.state === 'requested') {\n // A claim grants one channel once. Late reports only add evidence; they never authorize another delivery.\n if (!['claimed', 'unknown'].includes(delivery.state) || delivery.requested) return false;\n delivery.requested = true;\n } else if (receipt.state === 'failed') {\n if (!['claimed', 'requested', 'shown', 'unknown'].includes(delivery.state)) return false;\n } else {\n if (!delivery.requested || delivery.state === 'failed' || delivery.state === 'clicked') return false;\n if (receipt.state === 'unknown' && delivery.state !== 'requested') return false;\n if (receipt.state === 'shown' && !['requested', 'unknown'].includes(delivery.state)) return false;\n if (receipt.state === 'clicked' && !['requested', 'shown', 'unknown'].includes(delivery.state)) return false;\n }\n delivery.state = receipt.state;\n if (delivery.receipts.length < 5) delivery.receipts.push({ ...receipt });\n this.refresh(); return true;\n }\n private eligible(): boolean { return !this.closed && this.prefs.notifications && this.run.phase === 'running' && this.run.visibilityRevision > 0 && !this.run.suspended; }\n private valid(notice: TaskNotice): boolean { return !notice.requestIds.length || notice.requestIds.some(id => this.requests.get(id)?.state !== 'settled' && this.requests.has(id)); }\n private notice(sessionId: string, turn: number, seq: number, time: number, category: TaskNotice['category'], preview: string, requestIds: string[] = [], stage: TaskNotice['stage'] = 'initial'): TaskNotice {\n return noticeSchema.parse({ id: noticeId(sessionId, turn, seq, category, stage), sessionId, turn, seq, time, category, stage, title: `${this.sources.get(sessionId)?.label ?? '\u4F1A\u8BDD'} \u00B7 ${title[category]}`.slice(0, 256), body: preview.slice(0, 2048), requestIds });\n }\n private identity(notice: TaskNotice, occurrence = 0, runtimeId?: string): string {\n return noticeId(notice.sessionId, notice.turn, notice.seq, notice.category, notice.stage, occurrence, runtimeId);\n }\n private enqueue(notice: TaskNotice): void {\n if (!this.eligible() || this.deliveries.has(notice.id)) return;\n this.deliveries.set(notice.id, { notice, state: 'pending', requested: false, receipts: [] });\n if (this.deliveries.size > 300) {\n const old = [...this.deliveries.entries()].find(([, d]) => d.state !== 'claimed' && d.state !== 'requested');\n if (old) this.deliveries.delete(old[0]);\n }\n }\n private cancel(delivery: Delivery): void {\n if (delivery.claim && !['shown', 'clicked', 'failed'].includes(delivery.state)) delivery.state = 'unknown';\n else if (!delivery.claim && delivery.state !== 'role') delivery.state = 'cancelled';\n }\n private cancelDeliveries(): void { for (const d of this.deliveries.values()) this.cancel(d); }\n /** Callbacks always recompute request truth immediately before creating or dispatching a notice. */\n tick(): void {\n if (this.closed) return;\n const now = this.clock.now();\n for (const [id, time] of this.clients) if (now - time >= (this.options.clientLifetimeMs ?? 30_000)) this.clients.delete(id);\n for (const delivery of this.deliveries.values()) {\n if (!delivery.claim || !['claimed', 'requested'].includes(delivery.state)) continue;\n if (delivery.claim.expiresAt > now && this.clients.has(delivery.claim.clientId)) continue;\n delivery.state = 'unknown';\n }\n if (this.eligible() && this.prefs.reminders) {\n const groups = new Map<string, RequestState[]>();\n for (const request of this.requests.values()) if (request.state !== 'settled' && request.dueAt !== null && request.dueAt <= now) {\n const group = groups.get(request.sessionId) ?? []; group.push(request); groups.set(request.sessionId, group);\n }\n for (const [sessionId, requests] of groups) for (let start = 0; start < requests.length; start += 100) {\n const group = requests.slice(start, start + 100);\n const origin = group[0], notice = this.notice(sessionId, origin.turn, origin.seq, now, origin.kind, group.length > 1 ? `\u8FD8\u6709 ${group.length} \u4EF6\u4E8B\u7B49\u4F60\u770B\u770B\u3002` : '\u521A\u624D\u90A3\u4EF6\u4E8B\uFF0C\u8FD8\u7B49\u4F60\u770B\u770B\u3002', group.map(r => r.id), 'reminder');\n // Source seq remains literal; a snooze occurrence has its own stable scheduling identity.\n const occurrence = Math.max(...group.map(r => r.snoozes));\n if (origin.source === 'runtime') {\n (notice as SourcedNotice).source = 'runtime'; notice.id = this.identity(notice, occurrence, origin.nativeId);\n } else if (occurrence) notice.id = this.identity(notice, occurrence);\n for (const request of group) { request.dueAt = null; request.automaticReminders = 1; }\n this.enqueue(notice);\n }\n }\n if (this.eligible() && this.run.visible) for (const delivery of this.deliveries.values()) {\n if (delivery.state !== 'pending' || !this.valid(delivery.notice)) continue;\n const state = { ...this.run };\n try { if (this.options.presentRole?.(structuredClone(delivery.notice), state)) delivery.state = 'role'; } catch { delivery.state = 'failed'; }\n }\n }\n private refresh(): void {\n this.tick();\n if (this.timer !== undefined) this.clock.clearTimeout(this.timer);\n this.timer = undefined;\n if (!this.closed) {\n const due = this.eligible() ? [...this.requests.values()].flatMap(r => r.dueAt === null ? [] : [r.dueAt]) : [];\n for (const d of this.deliveries.values()) if (d.claim && ['claimed', 'requested'].includes(d.state)) due.push(Math.min(d.claim.expiresAt, (this.clients.get(d.claim.clientId) ?? this.clock.now()) + (this.options.clientLifetimeMs ?? 30_000)));\n if (due.length) this.timer = this.clock.setTimeout(() => { this.timer = undefined; this.refresh(); }, Math.max(1, Math.min(...due) - this.clock.now()));\n try { this.options.changed?.(); } catch { /* A view failure cannot escape into Harness dispatch. */ }\n }\n }\n private publicRequest(r: RequestState): PendingInteraction {\n const { projected: _projected, snoozes: _snoozes, cleanup: _cleanup, ...value } = r; return { ...value };\n }\n remove(sessionId: string): void {\n this.sources.delete(sessionId);\n for (const [id, r] of this.requests) if (r.sessionId === sessionId) { r.cleanup?.(); this.requests.delete(id); }\n for (const [id, d] of this.deliveries) if (d.notice.sessionId === sessionId) this.deliveries.delete(id);\n this.refresh();\n }\n dispose(): void {\n this.closed = true;\n if (this.timer !== undefined) this.clock.clearTimeout(this.timer);\n this.timer = undefined;\n for (const r of this.requests.values()) r.cleanup?.();\n this.cancelDeliveries(); this.clients.clear(); this.sources.clear(); this.requests.clear(); this.deliveries.clear(); this.problems.length = 0;\n }\n}\n", "import { z } from 'zod';\n\n/** Shared N0 contract. Host owns request truth and delivery claims; views render it. */\nexport const NOTIFICATION_PROTOCOL = 1 as const;\nconst id = z.string().min(1).max(2048);\nconst counter = z.number().int().nonnegative().safe();\nexport const notificationPreferencesSchema = z.object({\n notifications: z.boolean().default(true),\n systemNotifications: z.boolean().default(false),\n reminders: z.boolean().default(true),\n reminderDelayMs: z.number().int().min(60_000).max(86_400_000).default(600_000),\n}).strict();\nexport type NotificationPreferences = z.infer<typeof notificationPreferencesSchema>;\nexport const noticeSchema = z.object({\n id, sessionId: id, turn: counter, seq: counter, time: counter,\n category: z.enum(['completed', 'approval', 'question', 'error', 'stopped', 'interrupted', 'blocked', 'max-tokens']),\n stage: z.enum(['initial', 'reminder']),\n title: z.string().max(256), body: z.string().max(2048),\n requestIds: z.array(id).max(100).default([]), source: z.enum(['event', 'runtime']).optional(),\n}).strict();\nexport type TaskNotice = z.infer<typeof noticeSchema>;\n/** Tuple encoding preserves complete identities even when they contain separators. */\nexport function noticeId(sessionId: string, turn: number, seq: number, category: TaskNotice['category'], stage: TaskNotice['stage'], occurrence = 0, runtimeId?: string): string {\n if (!Number.isSafeInteger(occurrence) || occurrence < 0) throw new Error('Invalid notification occurrence');\n if (runtimeId !== undefined && !runtimeId.length) throw new Error('Invalid runtime request id');\n const tuple: (string | number)[] = [sessionId, turn, seq, category, stage];\n if (runtimeId !== undefined) tuple.push(runtimeId);\n if (occurrence > 0) tuple.push(occurrence);\n return JSON.stringify(tuple);\n}\nexport function interactionId(sessionId: string, kind: 'approval' | 'question', nativeId: string): string {\n return JSON.stringify([sessionId, kind, nativeId]);\n}\nexport const interactionSchema = z.object({\n id, sessionId: id, nativeId: id, kind: z.enum(['approval', 'question']),\n turn: counter, seq: counter, createdAt: counter, preview: z.string().max(2048),\n state: z.enum(['open', 'continued', 'settled']), source: z.enum(['event', 'runtime']).optional(),\n dueAt: counter.nullable(), automaticReminders: z.number().int().min(0).max(1),\n}).strict();\nexport type PendingInteraction = z.infer<typeof interactionSchema>;\nexport const runtimeSchema = z.object({\n phase: z.enum(['stopped', 'starting', 'running', 'stopping', 'error']),\n generation: counter, visibilityRevision: counter, visible: z.boolean(),\n suspended: z.boolean(), error: z.string().max(600).optional(),\n}).strict();\nexport type NotificationRuntime = z.infer<typeof runtimeSchema>;\nexport const deliveryClaimSchema = z.object({\n token: id, clientId: id, generation: counter, visibilityRevision: counter,\n expiresAt: counter, notice: noticeSchema,\n}).strict();\nexport type DeliveryClaim = z.infer<typeof deliveryClaimSchema>;\nexport const deliveryReceiptSchema = z.object({\n token: id, clientId: id, noticeId: id, generation: counter,\n state: z.enum(['requested', 'shown', 'clicked', 'failed', 'unknown']),\n time: counter, detail: z.string().max(600).optional(),\n}).strict();\nexport type DeliveryReceipt = z.infer<typeof deliveryReceiptSchema>;\nexport interface NotificationSnapshot {\n protocol: typeof NOTIFICATION_PROTOCOL;\n runtime: NotificationRuntime;\n interactions: PendingInteraction[];\n}\nexport const notificationRequests = {\n state: z.object({ locale: z.string().min(2).max(64).regex(/^[a-zA-Z0-9-]+$/).optional() }).strict(),\n claim: z.object({ clientId: id, generation: counter }).strict(),\n receipt: deliveryReceiptSchema,\n test: z.object({ clientId: id, generation: counter }).strict(),\n snooze: z.object({ interactionId: id, generation: counter }).strict(),\n} as const;\n/** Paths are carried by authenticated DSH Connection, with server-issued claim tokens. */\nexport const notificationEndpoints = ['notification-state', 'notification-claim', 'notification-receipt', 'notification-snooze', 'notification-test'] as const;\n\nexport interface WebNotificationStatus {\n supported: boolean;\n permission: NotificationPermission | 'unavailable';\n osAuthorization: 'unknown';\n}\n", "import { spawn, type ChildProcess } from 'node:child_process';\nimport { createRequire } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\n\nexport interface StartLifetime { signal: AbortSignal; generation: number; }\nexport interface NativeLifecycle { running: boolean; visible: boolean; error?: string; generation?: number; visibilityRevision?: number; suspended?: boolean; }\n\nexport interface DesktopOptions { size: number; roam: boolean; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n notify(notice: PetNotice | TaskNotice): void;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private resultKey?: string;\n private closing = false;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child) throw new Error('Desktop pet is already running');\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false; this.suspended = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002');\n const executable: string = options.electronPath ?? createRequire(import.meta.url)('electron');\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation) };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '';\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || !isRecord(message)) return;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const error = !this.closing && (code !== 0 || signal) ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code})` : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.send({ type: 'init', options, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: Error) => finish(error);\n const exited = (code: number | null, signal: string | null) => finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n child.on('error', error => { if (this.child === child && !this.closing) this.emit('failure', error); });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice): void { this.send({ type: 'notice', notice }); }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;\n this.send({ type: 'notice', notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision }); return true;\n }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n configure(options: DesktopOptions): void { this.send({ type: 'configure', options }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n if (this.child?.connected) this.child.send(message, error => { if (error && !this.closing) this.emit('failure', error); });\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "import { basename } from 'node:path';\nimport type { Session, SessionEvent } from '@deepseek-ai/dsh-session';\nimport type { AssistantStreamFrame } from '@deepseek-ai/dsh-agent';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport { type PendingInteraction, type TaskNotice } from './notification-contract.ts';\n\nexport type Mood = 'idle' | 'thinking' | 'talking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';\nexport interface PetResult { id: string; sessionId: string; text: string; time: number; read: boolean; }\nexport interface PetSession { id: string; label: string; project: string; cwd: string; prompt: string; createdAt: number; updatedAt: number; mood: Mood; text: string; reply: string; replyId: string; unread: number; revision: number; active: boolean; streaming: boolean; speechId: string; chatAvailable?: boolean; }\nexport interface PetSnapshot { mood: Mood; text: string; sessionId: string | null; revision: number; active: boolean; streaming: boolean; speechId: string; results: PetResult[]; sessions: PetSession[]; }\nexport interface PetNotice extends Partial<Omit<TaskNotice, 'title' | 'body' | 'sessionId'>> { title: string; body: string; sessionId: string; kind?: 'task' | 'message'; }\ninterface TaskState { seq: number; turn: number; active: boolean; finalText?: string; tools: Map<string, string>; approvals: Set<symbol | string>; questions: Set<string>; requests: Set<string>; celebrateUntil: number; stream?: { id: string; revision: number; index: number; text: string; blocks: Map<number, string> }; }\ntype ObservedSession = Pick<Session, 'id' | 'header'> & Partial<Pick<Session, 'snapshotEvents'>>;\nconst ready = '\u51C6\u5907\u597D\u4E86\uFF0C\u968F\u65F6\u53EB\u6211\u3002';\n\n/** Keeps independent task states so background sessions cannot overwrite the selected conversation. */\nexport class PetModel {\n private sessions = new Map<string, PetSession>();\n private selected: string | null = null;\n private tasks = new Map<string, TaskState>();\n private results = new Map<string, PetResult>();\n constructor(private readonly now: () => number = Date.now) {}\n\n observe(session: ObservedSession): PetSession | undefined {\n if (session.header.origin === 'subagent') return;\n let item = this.sessions.get(session.id);\n if (!item) {\n // Bound retained presentation state; live Harness sessions remain owned by the host.\n if (this.sessions.size >= 100) {\n const old = [...this.sessions.keys()].find(id => id !== this.selected);\n if (old) this.remove(old);\n }\n const project = session.header.cwd ? basename(session.header.cwd) : '\u672A\u6307\u5B9A\u9879\u76EE';\n item = { id: session.id, label: project, project, cwd: session.header.cwd ?? '', prompt: '', createdAt: session.header.createdAt, updatedAt: session.header.createdAt, mood: 'idle', text: ready, reply: '', replyId: '', unread: 0, revision: 0, active: false, streaming: false, speechId: '' };\n this.sessions.set(session.id, item);\n this.tasks.set(session.id, { seq: -1, turn: 0, active: false, tools: new Map(), approvals: new Set(), questions: new Set(), requests: new Set(), celebrateUntil: 0 });\n this.selected ??= session.id;\n // Restore identity from public history, without replaying stale task states or notices.\n for (const event of session.snapshotEvents?.() ?? []) this.describe(item, event);\n }\n return item;\n }\n\n /** Explicit initialization fold. A fresh Host restores readable results as unread; existing read state survives. */\n restore(session: ObservedSession): void {\n if (!this.observe(session)) return;\n for (const event of session.snapshotEvents?.() ?? []) this.fold(session, event, false);\n }\n\n private describe(item: PetSession, event: SessionEvent): void {\n if (event.type !== 'user/message' || event.data.source.kind !== 'user') return;\n const text = event.data.content.filter(p => p.type === 'text').map(p => p.text).join(' ').replace(/\\s+/g, ' ').trim();\n if (!text) return;\n if (!item.prompt) item.label = Array.from(text).slice(0, 64).join('');\n item.prompt = Array.from(text).slice(0, 160).join(''); item.updatedAt = event.time;\n }\n\n /** Live chunks are not session events. Keep attempt identity and ordering separate from durable seq. */\n stream(session: ObservedSession, frame: AssistantStreamFrame): boolean {\n const item = this.observe(session);\n if (!item) return false;\n const task = this.tasks.get(item.id)!;\n if (frame.type === 'start') {\n if (frame.turn < task.turn || (frame.turn === task.turn && !task.active && task.seq >= 0) || (task.stream && frame.revision <= task.stream.revision)) return false;\n task.turn = frame.turn; task.active = true;\n task.finalText = undefined;\n task.stream = { id: frame.attemptId, revision: frame.revision, index: -1, text: '', blocks: new Map() };\n item.streaming = true; item.speechId = frame.attemptId;\n if (!task.tools.size && !task.approvals.size) this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026');\n return true;\n }\n const stream = task.stream;\n if (!task.active || !stream || stream.id !== frame.attemptId || stream.revision !== frame.revision || frame.index <= stream.index) return false;\n stream.index = frame.index;\n if (frame.type === 'end') {\n item.streaming = false;\n if (frame.outcome.kind === 'abandoned' && !task.tools.size && !task.approvals.size) this.present(item, 'thinking', '\u6B63\u5728\u91CD\u65B0\u51C6\u5907\u56DE\u590D\u2026');\n return true;\n }\n const chunk = frame.chunk;\n if (chunk.type === 'text-delta' || (chunk.type === 'block-end' && chunk.block.type === 'text')) {\n if (chunk.type === 'text-delta') stream.blocks.set(chunk.index, ((stream.blocks.get(chunk.index) ?? '') + chunk.text).slice(0, 1200));\n else if (chunk.block.type === 'text') stream.blocks.set(chunk.index, chunk.block.text.slice(0, 1200));\n stream.text = [...stream.blocks.entries()].sort(([a], [b]) => a - b).map(([, text]) => text).join('\\n').slice(0, 1200);\n if (stream.text.trim()) {\n // Live text changes the expression, never the reader's confirmed result.\n if (!task.tools.size && !task.approvals.size) this.present(item, 'talking', '\u6B63\u5728\u7EC4\u7EC7\u56DE\u590D\u2026');\n }\n } else if (chunk.type === 'reasoning-delta' && !stream.text && !task.tools.size && !task.approvals.size) {\n // The pet signals reasoning without exposing private reasoning content.\n this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026');\n }\n return true;\n }\n\n detached(id: string): void { const task = this.tasks.get(id); if (task) task.stream = undefined; }\n\n idle(id: string): void {\n const item = this.sessions.get(id), task = this.tasks.get(id);\n if (!item || !task?.active) return;\n task.active = false; task.stream = undefined; task.tools.clear(); task.approvals.clear(); item.streaming = false;\n this.present(item, 'idle', ready);\n }\n\n /** Keep the user's focus stable when other conversations are created. */\n created(session: Pick<Session, 'id' | 'header'>): boolean {\n const item = this.observe(session);\n if (!item) return false;\n return true;\n }\n\n /** Baseline already-running agents without replaying old completion notifications. */\n running(session: Pick<Session, 'id' | 'header'>): void {\n const item = this.observe(session);\n if (!item || this.tasks.get(item.id)!.active) return;\n const task = this.tasks.get(item.id)!; task.active = true;\n if (task.requests.size || task.approvals.size) this.present(item, 'waiting', item.text);\n else this.present(item, 'thinking', '\u6B63\u5728\u5904\u7406\u5F53\u524D\u4F1A\u8BDD\u2026');\n }\n\n private present(item: PetSession, mood: Mood, text: string): void {\n item.active = this.tasks.get(item.id)!.active;\n if (item.mood === mood && item.text === text) return;\n item.mood = mood; item.text = text; item.revision++;\n }\n\n /** Celebration has a deadline independent of UI refreshes or other sessions. */\n settle(): boolean {\n let changed = false;\n for (const [id, task] of this.tasks) {\n if (!task.celebrateUntil || this.now() < task.celebrateUntil) continue;\n task.celebrateUntil = 0;\n const item = this.sessions.get(id)!;\n if (!task.active && item.mood === 'happy') { this.present(item, 'idle', ready); changed = true; }\n }\n return changed;\n }\n\n consume(session: Pick<Session, 'id' | 'header'>, event: SessionEvent): PetNotice | undefined {\n return this.fold(session, event, true);\n }\n\n private fold(session: Pick<Session, 'id' | 'header'>, event: SessionEvent, live: boolean): PetNotice | undefined {\n const item = this.observe(session);\n if (!item) return;\n const task = this.tasks.get(item.id)!;\n if (event.seq <= task.seq) return;\n task.seq = event.seq;\n this.describe(item, event);\n // Late results from a previous turn cannot overwrite a newer turn.\n if ('turn' in event.data && event.data.turn < task.turn) return;\n switch (event.type) {\n case 'turn/start':\n task.turn = event.data.turn; task.active = true; task.tools.clear(); task.approvals.clear(); task.celebrateUntil = 0;\n task.stream = undefined; task.finalText = undefined; item.streaming = false; item.speechId = ''; item.updatedAt = event.time;\n this.present(item, 'thinking', '\u8BA9\u6211\u60F3\u4E00\u60F3\u2026'); break;\n case 'step/start':\n task.active = true; task.finalText = undefined;\n if (!task.approvals.size && !task.tools.size) this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026'); break;\n case 'tool/call':\n if (!task.active) break;\n task.tools.set(event.data.callId, event.data.name);\n if (!task.approvals.size) this.present(item, 'working', toolLabel(event.data.name)); break;\n case 'tool/result':\n if (!task.active) break;\n task.tools.delete(event.data.message.toolCallId);\n if (task.approvals.size) break;\n if (task.tools.size) { this.present(item, 'working', toolLabel(task.tools.values().next().value!)); break; }\n if (event.data.message.isError) {\n this.present(item, 'thinking', '\u8FD9\u4E00\u6B65\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u6B63\u5728\u5904\u7406\u3002');\n } else { this.present(item, 'thinking', '\u8FD9\u4E00\u6B65\u5B8C\u6210\u4E86\uFF0C\u7EE7\u7EED\u60F3\u60F3\u2026'); }\n break;\n case 'assistant/message': {\n const text = event.data.message.content.filter(p => p.type === 'text').map(p => p.text).join('\\n');\n if (!task.active) break;\n item.streaming = false;\n task.finalText = event.data.message.content.some(p => p.type === 'tool-call') ? undefined : text;\n if (text.trim() && !task.tools.size && !task.approvals.size) this.present(item, 'talking', '\u6B63\u5728\u7EC4\u7EC7\u56DE\u590D\u2026');\n break;\n }\n case 'approval/asked': {\n const notice = this.approval(item.id, event.data.toolName, event.data.id);\n return live ? notice : undefined;\n }\n case 'approval/decided':\n this.approvalSettled(item.id, event.data.id); break;\n case 'turn/end': {\n task.turn = event.data.turn; task.active = false; task.tools.clear(); task.approvals.clear(); task.celebrateUntil = 0;\n task.stream = undefined; item.streaming = false;\n switch (event.data.reason.kind) {\n case 'completed': {\n const text = task.finalText?.trim() ? task.finalText : '';\n if (text) {\n const id = `${item.id}:${event.data.turn}:${event.seq}`;\n this.results.set(id, { id, sessionId: item.id, text, time: event.time, read: false });\n item.reply = text; item.replyId = id; item.unread++;\n // Retain complete text for the latest 200 results, preferring unread entries.\n if (this.results.size > 200) {\n const old = [...this.results.values()].find(r => r.read) ?? this.results.values().next().value!;\n this.results.delete(old.id);\n const owner = this.sessions.get(old.sessionId); if (owner && !old.read) owner.unread--;\n }\n }\n task.finalText = undefined;\n this.present(item, live ? 'happy' : 'idle', live ? text || '\u4EFB\u52A1\u5B8C\u6210' : ready); task.celebrateUntil = live ? this.now() + 2500 : 0;\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u5B8C\u6210`, body: text.slice(0, 180) || '\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002', sessionId: item.id, kind: 'task' } : undefined;\n }\n case 'error':\n this.present(item, 'error', '\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u8BF7\u56DE\u5230 Harness \u67E5\u770B\u8BE6\u60C5\u3002');\n return live ? { title: `${item.label} \u00B7 \u9700\u8981\u5173\u6CE8`, body: item.text, sessionId: item.id, kind: 'task' } : undefined;\n case 'blocked':\n case 'max-tokens':\n this.present(item, 'waiting', '\u4EFB\u52A1\u6682\u65F6\u505C\u4E0B\u4E86\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u6682\u505C`, body: item.text, sessionId: item.id, kind: 'task' } : undefined;\n case 'aborted':\n this.present(item, 'idle', '\u5148\u505C\u5728\u8FD9\u91CC\uFF0C\u968F\u65F6\u7EE7\u7EED\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u5DF2\u505C\u6B62`, body: item.text, sessionId: item.id, kind: 'task', category: 'stopped' } : undefined;\n case 'interrupted':\n this.present(item, 'waiting', '\u8FD9\u6BB5\u4EFB\u52A1\u4E2D\u65AD\u4E86\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u4E2D\u65AD`, body: item.text, sessionId: item.id, kind: 'task', category: 'interrupted' } : undefined;\n default:\n this.present(item, 'idle', '\u51C6\u5907\u597D\u4E86\uFF0C\u968F\u65F6\u53EB\u6211\u3002');\n }\n }\n }\n }\n\n approval(id: string, tool: string, token: symbol | string = Symbol()): PetNotice | undefined {\n const item = this.sessions.get(id);\n if (!item) return;\n const task = this.tasks.get(id)!; task.active = true; task.approvals.add(token); task.celebrateUntil = 0;\n this.present(item, 'waiting', `${toolLabel(tool)}\u524D\u9700\u8981\u4F60\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230 Harness\u3002`);\n return { title: `${item.label} \u00B7 \u7B49\u4F60\u786E\u8BA4`, body: item.text, sessionId: id, kind: 'task' };\n }\n\n approvalSettled(id: string, token?: symbol | string): void {\n const item = this.sessions.get(id);\n const task = this.tasks.get(id);\n if (!item || !task?.active) return;\n if (token ? !task.approvals.delete(token) : !task.approvals.size) return;\n if (!token) task.approvals.clear();\n if (!task.approvals.size && item.mood === 'waiting') {\n this.present(item, task.tools.size ? 'working' : 'thinking', task.tools.size ? toolLabel(task.tools.values().next().value!) : '\u786E\u8BA4\u5DF2\u5904\u7406\uFF0C\u7B49\u5F85\u4EFB\u52A1\u7EE7\u7EED\u2026');\n }\n }\n\n /** Public request state can outlive a turn; viewing or reading never removes its waiting entrance. */\n interactions(values: readonly PendingInteraction[]): void {\n for (const [id, task] of this.tasks) {\n const wasPending = task.requests.size > 0;\n const pending = values.filter(value => value.sessionId === id && value.state !== 'settled');\n task.requests = new Set(pending.map(value => value.id));\n task.questions = new Set(pending.filter(value => value.kind === 'question').map(value => value.id));\n const item = this.sessions.get(id)!;\n if (pending.length) {\n task.celebrateUntil = 0;\n this.present(item, 'waiting', pending.some(value => value.kind === 'question') ? '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002' : '\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230 Harness\u3002');\n } else if (wasPending && !task.approvals.size && item.mood === 'waiting') {\n this.present(item, task.active ? task.tools.size ? 'working' : 'thinking' : 'idle', task.active ? task.tools.size ? toolLabel(task.tools.values().next().value!) : '\u7B49\u5F85\u4EFB\u52A1\u7EE7\u7EED\u2026' : ready);\n }\n }\n }\n\n select(id: string): boolean {\n if (!this.sessions.has(id)) return false;\n this.selected = id; return true;\n }\n\n /** Acknowledging an older result cannot clear a newer completion. */\n read(id: string): boolean {\n const result = this.results.get(id);\n if (!result || result.read) return false;\n result.read = true;\n const item = this.sessions.get(result.sessionId); if (item) item.unread = Math.max(0, item.unread - 1);\n return true;\n }\n\n remove(id: string): void {\n this.sessions.delete(id);\n this.tasks.delete(id);\n for (const [key, result] of this.results) if (result.sessionId === id) this.results.delete(key);\n if (this.selected === id) this.selected = this.sessions.keys().next().value ?? null;\n }\n\n snapshot(): PetSnapshot {\n const item = this.selected ? this.sessions.get(this.selected) : undefined;\n this.settle();\n return { mood: item?.mood ?? 'idle', text: item?.text ?? ready, sessionId: item?.id ?? null, revision: item?.revision ?? 0, active: item?.active ?? false, streaming: item?.streaming ?? false, speechId: item?.speechId ?? '', results: [...this.results.values()].map(r => ({ ...r })), sessions: [...this.sessions.values()].map(s => ({ ...s })) };\n }\n}\n\nfunction toolLabel(name: string): string {\n if (/read|cat|view/.test(name)) return '\u6B63\u5728\u770B\u6587\u4EF6';\n if (/search|grep|find/.test(name)) return '\u6B63\u5728\u67E5\u627E';\n if (/write|edit|patch/.test(name)) return '\u6B63\u5728\u5199\u4EE3\u7801';\n if (/bash|shell|exec|terminal/.test(name)) return '\u6B63\u5728\u8FD0\u884C\u547D\u4EE4';\n if (/web|browse|fetch/.test(name)) return '\u6B63\u5728\u6D4F\u89C8';\n return `\u6B63\u5728\u4F7F\u7528 ${name.slice(0, 60)}`;\n}\n", "import type { DesktopOptions, PetBridge } from './bridge.ts';\nimport type { NotificationRuntime } from './notification-contract.ts';\n\nexport type PetCommand = 'start' | 'show' | 'hide' | 'restart' | 'stop' | 'characters';\nexport type PetStatus = NotificationRuntime;\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n}\nexport interface StartLifetime { signal: AbortSignal; generation: number; }\ninterface LifetimeBridge extends PetBridge { start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>; }\nexport interface ControlLimits { startTimeoutMs?: number; cleanupTimeoutMs?: number; }\n\n/** Commands own a cancellable native generation. Lifecycle acknowledgements alone establish visibility. */\nexport class PetControls {\n private state: PetStatus = { phase: 'stopped', visible: false, generation: 0, visibilityRevision: 0, suspended: false };\n private queue: Promise<unknown> = Promise.resolve();\n private disposed = false;\n private startup?: AbortController;\n private readonly listeners = new Set<(status: PetStatus) => void>();\n private readonly changed = (event: NativeLifecycle) => {\n if (this.disposed || event.generation !== this.state.generation || !Number.isSafeInteger(event.visibilityRevision) || event.visibilityRevision! < this.state.visibilityRevision) return;\n if (event.visibilityRevision === this.state.visibilityRevision && event.visible !== this.state.visible) return;\n if (this.state.phase === 'stopping' || ((this.state.phase === 'stopped' || this.state.phase === 'error') && event.running)) return;\n this.set({ ...this.state, phase: event.error ? 'error' : event.running ? this.state.phase === 'starting' ? 'starting' : 'running' : 'stopped', visible: event.running && event.visible, visibilityRevision: event.visibilityRevision!, suspended: event.suspended ?? false, ...(event.error ? { error: event.error.slice(0, 600) } : {}) });\n };\n constructor(private readonly bridge: PetBridge, private readonly options: () => DesktopOptions, private readonly limits: ControlLimits = {}) {\n bridge.onLifecycle?.(this.changed);\n }\n status(): PetStatus { return { ...this.state }; }\n /** Root assembly registers this listener as a context-owned effect. */\n onState(listener: (status: PetStatus) => void): () => void {\n this.listeners.add(listener); try { listener(this.status()); } catch { /* A view is optional. */ } return () => this.listeners.delete(listener);\n }\n configure(): void { this.bridge.configure?.(this.options()); }\n command(command: PetCommand): Promise<PetStatus> {\n // A stop during a pending launch cancels immediately, before entering the command queue.\n if (command === 'stop' || command === 'restart') this.startup?.abort();\n return this.enqueue(async () => {\n if (this.disposed) throw new Error('\u684C\u5BA0\u63D2\u4EF6\u5DF2\u505C\u7528');\n try {\n if (command === 'stop' || command === 'restart') {\n this.set({ ...this.state, phase: 'stopping', visible: false, suspended: false });\n await this.cleanup();\n this.set({ ...this.state, phase: 'stopped', visible: false, suspended: false });\n }\n if (command !== 'stop' && command !== 'hide' && this.state.phase !== 'running') {\n const startup = new AbortController(); this.startup = startup;\n this.set({ phase: 'starting', visible: false, generation: this.state.generation + 1, visibilityRevision: 0, suspended: false });\n await this.withDeadline((this.bridge as LifetimeBridge).start(this.options(), { signal: startup.signal, generation: this.state.generation }), this.limits.startTimeoutMs ?? 25_000, '\u684C\u5BA0\u542F\u52A8\u8D85\u65F6', startup.signal);\n if (startup.signal.aborted || this.disposed) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.startup = undefined;\n this.set({ ...this.state, phase: 'running' });\n }\n if (this.state.phase === 'running') this.bridge.control?.(command === 'characters' ? 'characters' : command === 'hide' ? 'hide' : 'show');\n return this.status();\n } catch (error) {\n this.startup?.abort(); this.startup = undefined;\n const cleanup = await this.cleanup().then(() => '', failure => `\uFF1B\u6E05\u7406\u5931\u8D25\uFF1A${this.message(failure)}`);\n this.set({ ...this.state, phase: 'error', visible: false, suspended: false, error: (this.message(error) + cleanup).slice(0, 600) });\n return this.status();\n }\n });\n }\n async dispose(): Promise<void> {\n this.disposed = true; this.startup?.abort();\n this.set({ ...this.state, phase: 'stopping', visible: false, suspended: false });\n await this.enqueue(async () => {\n this.bridge.removeLifecycle?.(this.changed);\n const failure = await this.cleanup().then(() => undefined, error => this.message(error));\n this.set({ ...this.state, phase: failure ? 'error' : 'stopped', visible: false, ...(failure ? { error: failure } : {}) });\n this.listeners.clear();\n });\n }\n private message(error: unknown): string { return String(error instanceof Error ? error.message : error).slice(0, 600); }\n private cleanup(): Promise<void> { return this.withDeadline(Promise.resolve().then(() => this.bridge.dispose()), this.limits.cleanupTimeoutMs ?? 5_000, '\u684C\u5BA0\u6E05\u7406\u8D85\u65F6'); }\n private withDeadline<T>(task: Promise<T>, delay: number, message: string, signal?: AbortSignal): Promise<T> {\n return new Promise((resolve, reject) => {\n let done = false;\n const finish = (error?: unknown, value?: T) => {\n if (done) return; done = true; clearTimeout(timer); signal?.removeEventListener('abort', aborted);\n if (error) reject(error); else resolve(value as T);\n };\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new Error(message)), delay);\n signal?.addEventListener('abort', aborted, { once: true });\n if (signal?.aborted) aborted();\n task.then(value => finish(undefined, value), error => finish(error));\n });\n }\n private set(state: PetStatus): void {\n this.state = state;\n for (const listener of this.listeners) { try { listener(this.status()); } catch { /* View errors cannot stall native cleanup. */ } }\n }\n private enqueue<T>(operation: () => Promise<T>): Promise<T> {\n const pending = this.queue.then(operation); this.queue = pending.catch(() => undefined); return pending;\n }\n}\n"],
5
- "mappings": ";AAAA,SAAS,cAAAA,mBAAkB;AAS3B,SAAS,iBAA+B;;;ACTxC,SAAS,kBAAkB;;;ACA3B,SAAS,SAAS;AAGX,IAAM,wBAAwB;AACrC,IAAM,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;AACrC,IAAM,UAAU,EAAE,OAAO,EAAE,IAAI,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E,SAAS,CAAC,EAAE,MAAM,QAAQ,KAAK,CAAC,GAAG,QAAQ,EAAE,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC;AACxI,aAAO;AAAA,IACT,SAAS,OAAO;AACd,aAAO,OAAO,EAAE,OAAO,wCAAU,MAAM,yEAAuB,WAAW,OAAO,UAAU,CAAC;AAC3F,UAAI,OAAO,KAAK,4BAA4B,OAAO,KAAK,CAAC,EAAE;AAAA,IAC7D;AAAA,EACF;AACA,MAAI,OAAO,MAAM;AAAE,WAAO,SAAS,QAAQ;AAAG,WAAO,MAAM,OAAO,aAAa,QAAQ;AAAA,EAAG,CAAC;AAC3F,MAAI,kBAAkB,gBAAgB;AACpC,UAAM,YAAY,CAAC,UAAiB,IAAI,OAAO,KAAK,MAAM,OAAO;AACjE,QAAI,OAAO,MAAM;AAAE,aAAO,GAAG,WAAW,SAAS;AAAG,aAAO,MAAM,OAAO,IAAI,WAAW,SAAS;AAAA,IAAG,CAAC;AAAA,EACtG;AACA,YAAU;AAAM,oBAAkB;AAAG,SAAO;AAC5C,MAAI,QAAQ,UAAU,IAAI,GAAG;AAC3B,SAAK,SAAS,QAAQ,OAAO,EAAE,KAAK,YAAU;AAAE,UAAI,OAAO,MAAO,KAAI,OAAO,KAAK,OAAO,KAAK;AAAA,IAAG,GAAG,WAAS,IAAI,OAAO,KAAK,OAAO,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC;AAAA,EAC3J;AACF;",
4
+ "sourcesContent": ["import { randomUUID } from 'node:crypto';\nimport type { Context, Volatile } from '@deepseek-ai/cordis';\nimport type {} from '@deepseek-ai/dsh-client-connection';\nimport type {} from '@deepseek-ai/dsh-settings';\nimport type {} from '@deepseek-ai/dsh-agent';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport type {} from '@deepseek-ai/dsh-user-questions';\nimport type {} from '@deepseek-ai/dsh-api-session-controller';\nimport type {} from '@deepseek-ai/dsh-session-projection';\nimport { SessionId, type Session } from '@deepseek-ai/dsh-session';\nimport { NotificationBroker, type NotificationEvent } from './notification-broker.ts';\nimport { notificationPreferencesSchema, notificationEndpoints, notificationRequests, noticeId } from './notification-contract.ts';\nimport { createUserMessage } from '@deepseek-ai/dsh-llm';\nimport z from '@deepseek-ai/schemastery';\nimport { ElectronBridge, isRecord, type PetBridge, type DesktopOptions } from './bridge.ts';\nimport { PetModel } from './model.ts';\nimport { PetControls } from './controls.ts';\nimport { z as wire } from 'zod';\n\nexport const name = 'dsh-coopanion';\nexport const inject = ['agents'];\nexport interface Config {\n size: Volatile<number>; roam: Volatile<boolean>; notifications: Volatile<boolean>;\n systemNotifications: Volatile<boolean>; reminders: Volatile<boolean>; reminderDelayMs: Volatile<number>;\n bubbleDurationMs: Volatile<number>; autoStart: Volatile<boolean>; electronPath?: string;\n}\nexport const Config = z.object({\n size: z.number().min(90).max(240).default(180).volatile(),\n roam: z.boolean().default(true).volatile(),\n notifications: z.boolean().default(true).volatile(),\n systemNotifications: z.boolean().default(false).volatile(),\n reminders: z.boolean().default(true).volatile(),\n reminderDelayMs: z.number().step(1).min(60000).max(86400000).default(600000).volatile(),\n bubbleDurationMs: z.number().min(2000).max(60000).default(12000).volatile(),\n autoStart: z.boolean().default(true).volatile(),\n electronPath: z.string(),\n});\n\n/** Mounts the pet on public Harness events, delegates approvals, and routes explicit user chat to a selected live agent. */\nexport async function apply(ctx: Context, config: Config): Promise<void> {\n ctx.inject(['settings'], child => { child.effect(() => child.settings.configure({ auto: false }, ctx.fiber)); });\n await mountPet(ctx, config, new ElectronBridge());\n}\n\n/** Shared assembly used by integration tests with an IPC substitute for the native window. */\nexport async function mountPet(ctx: Context, options: Config, bridge: PetBridge): Promise<void> {\n const model = new PetModel();\n const preferences: Partial<Pick<DesktopOptions, 'roam' | 'notifications'>> = {};\n let savePreference: ((field: 'roam' | 'notifications', value: boolean) => Promise<void>) | undefined;\n ctx.inject(['settings'], child => { savePreference = (field, value) => child.settings.mutate('dsh-coopanion', [{ op: 'set', path: [field], value }]); });\n const currentOptions = (): DesktopOptions => ({ size: options.size.get(), roam: options.roam.get(), notifications: options.notifications.get(), bubbleDurationMs: options.bubbleDurationMs.get(), systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get(), electronPath: options.electronPath, locale, ...preferences });\n const controls = new PetControls(bridge, currentOptions);\n let locale = 'zh';\n let navigation: { sessionId: string; expires: number } | undefined;\n ctx.provide('coopanion', controls);\n const update = () => {\n const snapshot = model.snapshot(), live = new Set<string>(ctx.agents.list().map(agent => agent.session.id));\n bridge.update({ ...snapshot, sessions: snapshot.sessions.map(session => ({ ...session, chatAvailable: live.has(session.id) })) });\n };\n let mounted = false;\n const notificationPrefs = () => notificationPreferencesSchema.parse({ notifications: currentOptions().notifications, systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get() });\n const syncNotifications = () => {\n if (!mounted) return;\n const snapshot = broker.snapshot(); model.interactions(snapshot.interactions); bridge.notificationState?.(snapshot); update();\n };\n const broker = new NotificationBroker({ changed: syncNotifications, presentRole: (value, runtime) => bridge.presentRole?.(value, runtime) ?? false });\n broker.preferences(notificationPrefs());\n ctx.effect(() => () => broker.dispose());\n ctx.effect(() => controls.onState(state => broker.runtime(state)));\n let questions: ((session: Session, live?: boolean) => void) | undefined;\n ctx.inject(['sessionProjections', 'userQuestions'], child => {\n const sync = (session: Session, live = true) => {\n try {\n const view = child.sessionProjections.snapshot(session, ['userQuestions']).values.userQuestions;\n if (view) broker.questions(session, view, live);\n } catch (error) { child.logger.warn(`Question projection unavailable: ${String(error).slice(0, 300)}`); }\n };\n questions = sync;\n child.effect(() => () => { if (questions === sync) questions = undefined; });\n // A service is provided before its constructor registers projection units.\n // Fold after that registration turn, including sessions without a live agent.\n queueMicrotask(() => {\n if (!mounted || questions !== sync) return;\n for (const session of child.get('sessions')?.list() ?? ctx.agents.list().map(agent => agent.session)) sync(session, false);\n });\n });\n let testSource: (() => Promise<Session>) | undefined;\n ctx.inject(['sessions', 'sessionController'], child => {\n let source: Promise<Session> | undefined;\n const create = () => source ??= child.sessionController.create({ sessionId: SessionId(`coopanion-notification-test-${randomUUID()}`), cwd: process.cwd() }).then(value => {\n const session = child.sessions.get(value.sessionId); if (!session) throw new Error('Notification test source unavailable'); return session;\n }).catch(error => { source = undefined; throw error; });\n testSource = create; child.effect(() => () => { if (testSource === create) testSource = undefined; });\n });\n let streamUpdate: ReturnType<typeof setTimeout> | undefined;\n ctx.effect(() => () => clearTimeout(streamUpdate));\n ctx.effect(() => () => controls.dispose());\n ctx.effect(() => {\n const timer = setInterval(() => { if (model.settle()) update(); }, 250);\n timer.unref(); return () => clearInterval(timer);\n });\n ctx.on('settings/document-updated', ns => { if (ns === 'dsh-coopanion') { broker.preferences(notificationPrefs()); controls.configure(); } });\n ctx.inject(['connection'], child => {\n const dispatch = async (endpoint: string, payload: unknown, signal: AbortSignal) => {\n try {\n if (signal.aborted) throw new Error('\u8BF7\u6C42\u5DF2\u53D6\u6D88');\n if (endpoint === 'status') {\n wire.object({}).strict().parse(payload);\n return { ok: true, value: controls.status() };\n }\n if (endpoint === 'navigation') {\n wire.object({}).strict().parse(payload);\n const value = navigation && navigation.expires > Date.now() ? { sessionId: navigation.sessionId } : null;\n navigation = undefined;\n return { ok: true, value };\n }\n if (endpoint === 'notification-state') { const input = notificationRequests.state.parse(payload); if (input.locale && input.locale !== locale) { locale = input.locale; controls.configure(); } return { ok: true, value: broker.snapshot() }; }\n if (endpoint === 'notification-claim') { const input = notificationRequests.claim.parse(payload); return { ok: true, value: broker.claim(input.clientId, input.generation) }; }\n if (endpoint === 'notification-receipt') { return { ok: true, value: { accepted: broker.receipt(notificationRequests.receipt.parse(payload)) } }; }\n if (endpoint === 'notification-snooze') { const input = notificationRequests.snooze.parse(payload); if (!broker.snooze(input.interactionId, input.generation)) throw new Error('\u5F85\u5904\u7406\u8BF7\u6C42\u5DF2\u53D8\u5316\u6216\u63D0\u9192\u6682\u4E0D\u53EF\u7528'); return { ok: true, value: { accepted: true } }; }\n if (endpoint === 'notification-test') {\n const input = notificationRequests.test.parse(payload), state = broker.snapshot().runtime, prefs = notificationPrefs();\n if (!testSource || state.phase !== 'running' || state.visible || state.suspended || state.visibilityRevision === 0 || input.generation !== state.generation || !prefs.notifications || !prefs.systemNotifications) throw new Error('\u8BF7\u542F\u52A8\u5E76\u9690\u85CF\u89D2\u8272\uFF0C\u5F00\u542F\u7CFB\u7EDF\u901A\u77E5\u540E\u6D4B\u8BD5');\n const session = await testSource();\n if (signal.aborted) throw new Error('\u8BF7\u6C42\u5DF2\u53D6\u6D88');\n const latest = broker.snapshot().runtime;\n if (latest.generation !== state.generation || latest.visibilityRevision !== state.visibilityRevision || latest.phase !== 'running' || latest.visible || latest.suspended) throw new Error('\u684C\u5BA0\u72B6\u6001\u5DF2\u53D8\u5316');\n const turn = (session.snapshotEvents().findLast(event => event.type === 'turn/start')?.data as { turn?: number } | undefined)?.turn ?? 0;\n session.append('turn/start', { turn: turn + 1 });\n session.append('turn/end', { turn: turn + 1, reason: { kind: 'completed' } });\n const event = session.snapshotEvents().at(-1)!;\n const claim = broker.claim(input.clientId, input.generation, noticeId(session.id, turn + 1, event.seq, 'completed', 'initial'));\n if (!claim) throw new Error('\u6D4B\u8BD5\u901A\u77E5\u672A\u80FD\u9886\u53D6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5');\n return { ok: true, value: claim };\n }\n if (endpoint !== 'control') throw new Error('\u672A\u77E5\u7684\u684C\u5BA0\u64CD\u4F5C');\n const { command } = wire.object({ command: wire.enum(['start', 'show', 'hide', 'restart', 'stop', 'characters']) }).strict().parse(payload);\n return { ok: true, value: await controls.command(command) };\n } catch (error) { return { ok: false, error: { code: 'coopanion/rejected', message: String(error instanceof Error ? error.message : error).slice(0, 600), details: {} } }; }\n };\n // Exact Connection routes coexist with the Gateway's exclusive /api interceptor.\n // The Connection carrier applies its normal Host/Origin and authentication checks.\n for (const endpoint of ['status', 'control', 'navigation', ...notificationEndpoints] as const) {\n child.effect(() => child.connection.fetch.register({\n path: `/api/coopanion/${endpoint}`, methods: ['POST'], requestBody: 'buffered',\n fetch: async request => {\n const parsed = wire.object({ type: wire.literal('client-request'), rpcId: wire.string().min(1).max(128), method: wire.literal(`coopanion/${endpoint}`), payload: wire.unknown() }).strict().safeParse(await request.json().catch(() => undefined));\n if (!parsed.success) return Response.json({ error: 'Invalid desktop pet request' }, { status: 400 });\n return Response.json({ type: 'server-response', rpcId: parsed.data.rpcId, result: await dispatch(endpoint, parsed.data.payload, request.signal) });\n },\n }));\n }\n });\n const restoreSession = (session: Session, running = ctx.agents.list().some(agent => agent.session.id === session.id && agent.status === 'running')) => {\n model.restore(session);\n // A stored open turn is history, not evidence of an Agent running in this Host.\n if (running) model.running(session); else model.idle(session.id);\n broker.restore(session); questions?.(session, false);\n };\n ctx.inject(['sessions'], child => { for (const session of child.sessions.list()) restoreSession(session); syncNotifications(); update(); });\n for (const agent of ctx.agents.list()) restoreSession(agent.session, agent.status === 'running');\n ctx.on('session/created', session => { restoreSession(session); syncNotifications(); update(); });\n ctx.on('agent/created', ({ agent }) => { restoreSession(agent.session, agent.status === 'running'); syncNotifications(); update(); return undefined; });\n ctx.on('agent/status', ({ agent, status }) => { if (status === 'running') model.running(agent.session); else model.idle(agent.session.id); update(); });\n ctx.on('agent/assistant-stream', ({ agent, frame }) => {\n if (!model.stream(agent.session, frame) || streamUpdate) return;\n // Coalesce high-frequency provider deltas; durable events still publish immediately.\n streamUpdate = setTimeout(() => { streamUpdate = undefined; update(); }, 40);\n });\n ctx.on('agent/disposed', ({ agent }) => { model.idle(agent.session.id); model.detached(agent.session.id); update(); });\n ctx.on('session/event', (session, event) => { broker.consume(session, event); model.consume(session, event); questions?.(session); syncNotifications(); update(); });\n ctx.on('session/disposed', session => { broker.remove(session.id); model.remove(session.id); update(); });\n ctx.inject(['userQuestions'], child => {\n child.on('user-questions/request', async (request, next) => {\n const session = request.agent?.session;\n if (!session || session.header.origin === 'subagent') return next();\n model.observe(session);\n const events: readonly NotificationEvent[] = session.snapshotEvents();\n const callId = request.wait?.callId;\n const origin = callId ? events.findLast(event => (event.type === 'tool/call' && event.data.callId === callId) || (event.type === 'tool/ptc-dispatch' && event.data.subCallId === callId)) : undefined;\n const anchor = origin ?? events.at(-1);\n const turnEvent = events.findLast(event => event.type === 'turn/start');\n const finish = broker.question(session, { nativeId: origin && callId ? callId : randomUUID(), turn: turnEvent?.type === 'turn/start' ? turnEvent.data.turn : 0, seq: anchor?.seq ?? 0, preview: request.questions.map(q => q.question).join('\\n'), signal: request.signal, source: origin ? 'event' : 'runtime' });\n questions?.(session); syncNotifications();\n try { return await next(); }\n finally { questions?.(session); finish(); syncNotifications(); }\n }, { prepend: true });\n });\n const onAction = (action: unknown) => {\n if (!isRecord(action)) return;\n if (action.type === 'notification-snooze') {\n const input = notificationRequests.snooze.safeParse({ interactionId: action.interactionId, generation: action.generation });\n const ok = input.success && broker.snooze(input.data.interactionId, input.data.generation);\n if (typeof action.interactionId === 'string') bridge.snoozeResult?.(action.interactionId, ok, ok ? undefined : '\u5F85\u5904\u7406\u8BF7\u6C42\u5DF2\u53D8\u5316\u6216\u63D0\u9192\u6682\u4E0D\u53EF\u7528');\n syncNotifications(); return;\n }\n if (action.type === 'preference' && (action.field === 'roam' || action.field === 'notifications') && typeof action.value === 'boolean') {\n const field = action.field, value = action.value;\n void (async () => {\n try {\n if (savePreference) await savePreference(field, value); else preferences[field] = value;\n broker.preferences(notificationPrefs()); controls.configure();\n } catch { bridge.notify({ title: '\u8BBE\u7F6E\u672A\u80FD\u4FDD\u5B58', body: '\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u63D2\u4EF6\u8BBE\u7F6E\u3002', sessionId: model.snapshot().sessionId ?? '' }); }\n })(); return;\n }\n if (action.type === 'select' && typeof action.sessionId === 'string') { model.select(action.sessionId); update(); return; }\n if (action.type === 'read' && typeof action.resultId === 'string') { if (model.read(action.resultId)) update(); return; }\n if (action.type === 'open-session' && typeof action.sessionId === 'string') {\n if (!model.select(action.sessionId)) return;\n navigation = { sessionId: action.sessionId, expires: Date.now() + 30000 };\n bridge.focusHarness?.(); update(); return;\n }\n if (action.type !== 'chat' || typeof action.text !== 'string' || typeof action.sessionId !== 'string') return;\n const text = action.text.trim();\n if (!text || text.length > 2000 || !model.select(action.sessionId)) return;\n const id = model.snapshot().sessionId;\n const agent = ctx.agents.list().find(agent => agent.session.id === id);\n if (!agent || agent.session.header.origin === 'subagent') {\n bridge.notify({ title: '\u4F1A\u8BDD\u5C1A\u672A\u5C31\u7EEA', body: '\u8BF7\u5148\u56DE\u5230 Harness \u6253\u5F00\u8FD9\u4E2A\u4F1A\u8BDD\uFF0C\u7136\u540E\u518D\u53D1\u9001\u6D88\u606F\u3002', sessionId: action.sessionId }); update(); return;\n }\n try {\n ctx.agents.withInitiator(agent, () => agent.followup(createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'user' } })));\n update();\n } catch (error) {\n bridge.notify({ title: '\u6D88\u606F\u672A\u80FD\u53D1\u9001', body: '\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u4F1A\u8BDD\u72B6\u6001\u3002', sessionId: action.sessionId });\n ctx.logger.warn(`Desktop pet chat failed: ${String(error)}`);\n }\n };\n ctx.effect(() => { bridge.onAction(onAction); return () => bridge.removeAction(onAction); });\n if (bridge instanceof ElectronBridge) {\n const onFailure = (error: Error) => ctx.logger.warn(error.message);\n ctx.effect(() => { bridge.on('failure', onFailure); return () => bridge.off('failure', onFailure); });\n }\n mounted = true; syncNotifications(); update();\n if (options.autoStart.get()) {\n void controls.command('start').then(status => { if (status.error) ctx.logger.warn(status.error); }, error => ctx.logger.warn(String(error).slice(0, 600)));\n }\n}\n\ndeclare module '@deepseek-ai/cordis' { interface Context { coopanion: PetControls; } }\n", "import { randomUUID } from 'node:crypto';\nimport type { Session, SessionEvent } from '@deepseek-ai/dsh-session';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport {\n NOTIFICATION_PROTOCOL, deliveryReceiptSchema, interactionId, noticeId, noticeSchema,\n notificationPreferencesSchema, runtimeSchema,\n type DeliveryClaim, type DeliveryReceipt, type NotificationPreferences,\n type NotificationRuntime, type NotificationSnapshot, type PendingInteraction, type TaskNotice,\n} from './notification-contract.ts';\n\nexport type NotificationEvent = SessionEvent | { type: 'tool/ptc-dispatch'; data: { name: string; subCallId: string; turn?: number }; seq: number; time: number };\ntype SourceSession = Pick<Session, 'id' | 'header'> & Partial<Pick<Session, 'snapshotEvents'>>;\nexport interface QuestionProjection {\n active: readonly { callId: string; state: 'open' | 'continued'; questions: readonly { question: string }[] }[];\n settled?: readonly { callId: string }[];\n}\nexport interface LiveQuestion {\n nativeId: string; turn: number; seq: number; preview: string; signal?: AbortSignal; source?: 'event' | 'runtime';\n}\nexport interface BrokerClock {\n now(): number;\n setTimeout(callback: () => void, delay: number): unknown;\n clearTimeout(timer: unknown): void;\n}\nexport interface BrokerOptions {\n clock?: BrokerClock;\n /** Must synchronously enqueue into the acknowledged native generation, or return false. */\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n changed?(): void;\n token?(): string;\n claimDurationMs?: number;\n clientLifetimeMs?: number;\n}\ntype SourceKind = 'event' | 'runtime';\ntype SourcedNotice = TaskNotice & { source?: SourceKind };\ninterface RequestState extends PendingInteraction { source?: SourceKind; projected: boolean; snoozes: number; cleanup?: () => void; }\ninterface QuestionOrigin { turn: number; seq: number; time: number; }\ninterface SourceState { seq: number; turn: number; finalText: string; label: string; calls: Map<string, QuestionOrigin>; }\ninterface Delivery {\n notice: TaskNotice; state: 'pending' | 'claimed' | DeliveryReceipt['state'] | 'role' | 'cancelled';\n claim?: DeliveryClaim; requested: boolean; receipts: DeliveryReceipt[];\n}\nconst realClock: BrokerClock = {\n now: Date.now,\n setTimeout: (callback, delay) => { const timer = setTimeout(callback, delay); timer.unref(); return timer; },\n clearTimeout: timer => clearTimeout(timer as ReturnType<typeof setTimeout>),\n};\nconst title: Record<TaskNotice['category'], string> = {\n completed: '\u4EFB\u52A1\u5B8C\u6210', approval: '\u7B49\u4F60\u786E\u8BA4', question: '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60', error: '\u9700\u8981\u5173\u6CE8',\n stopped: '\u5148\u505C\u5728\u8FD9\u91CC', interrupted: '\u4EFB\u52A1\u4E2D\u65AD\u4E86', blocked: '\u4EFB\u52A1\u6682\u65F6\u505C\u4E0B\u4E86', 'max-tokens': '\u8F93\u51FA\u8FBE\u5230\u4E0A\u9650',\n};\nconst body: Record<TaskNotice['category'], string> = {\n completed: '\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002', approval: '\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\u3002', question: '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\u3002', error: '\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002',\n stopped: '\u5148\u505C\u5728\u8FD9\u91CC\uFF0C\u968F\u65F6\u7EE7\u7EED\u3002', interrupted: '\u8FD9\u6BB5\u4EFB\u52A1\u4E2D\u65AD\u4E86\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002', blocked: '\u770B\u770B\u4E0B\u4E00\u6B65\u600E\u4E48\u7EE7\u7EED\u3002', 'max-tokens': '\u770B\u770B\u4E0B\u4E00\u6B65\u600E\u4E48\u7EE7\u7EED\u3002',\n};\n\n/** Event truth, reminder scheduling and delivery ownership stay in the Host. Views never settle requests. */\nexport class NotificationBroker {\n private readonly clock: BrokerClock;\n private prefs = notificationPreferencesSchema.parse({});\n private run: NotificationRuntime = { phase: 'stopped', generation: 0, visibilityRevision: 0, visible: false, suspended: false };\n private readonly sources = new Map<string, SourceState>();\n private readonly requests = new Map<string, RequestState>();\n private readonly deliveries = new Map<string, Delivery>();\n private readonly clients = new Map<string, number>();\n private readonly problems: { code: string; sessionId: string; nativeId: string }[] = [];\n private timer?: unknown;\n private closed = false;\n constructor(private readonly options: BrokerOptions = {}) { this.clock = options.clock ?? realClock; }\n\n snapshot(): NotificationSnapshot {\n return { protocol: NOTIFICATION_PROTOCOL, runtime: { ...this.run }, interactions: [...this.requests.values()].filter(r => r.state !== 'settled').map(r => this.publicRequest(r)) };\n }\n /** Bounded diagnostics; a requested receipt alone never means the OS displayed a notification. */\n diagnostics(): { code: string; sessionId: string; nativeId: string }[] { return this.problems.map(p => ({ ...p })); }\n history(): { notice: TaskNotice; state: Delivery['state']; receipts: DeliveryReceipt[] }[] {\n return [...this.deliveries.values()].map(d => ({ notice: structuredClone(d.notice), state: d.state, receipts: d.receipts.map(r => ({ ...r })) }));\n }\n preferences(value: Partial<NotificationPreferences>): void {\n const delayChanged = value.reminderDelayMs !== undefined && value.reminderDelayMs !== this.prefs.reminderDelayMs;\n this.prefs = notificationPreferencesSchema.parse({ ...this.prefs, ...value });\n if (!this.prefs.reminders) for (const delivery of this.deliveries.values()) if (delivery.notice.stage === 'reminder') this.cancel(delivery);\n if (!this.prefs.notifications) this.cancelDeliveries();\n for (const request of this.requests.values()) {\n if (request.state === 'settled') continue;\n if (!this.prefs.notifications || !this.prefs.reminders) request.dueAt = null;\n else if ((request.dueAt === null || delayChanged) && request.automaticReminders === 0) request.dueAt = this.clock.now() + this.prefs.reminderDelayMs;\n }\n this.refresh();\n }\n runtime(value: NotificationRuntime): boolean {\n const next = runtimeSchema.parse(value);\n if (next.phase === 'running' && this.run.phase === 'running' && next.generation === this.run.generation && next.visibilityRevision === this.run.visibilityRevision && next.visible !== this.run.visible) return false;\n if (this.closed || next.generation < this.run.generation || (next.generation === this.run.generation && next.visibilityRevision < this.run.visibilityRevision)) return false;\n const generationChanged = next.generation !== this.run.generation;\n const changed = next.generation !== this.run.generation || next.visibilityRevision !== this.run.visibilityRevision || next.phase !== this.run.phase || next.suspended !== this.run.suspended;\n if (changed) for (const delivery of this.deliveries.values()) {\n if (next.generation === this.run.generation && next.phase === 'running' && !next.suspended && !delivery.claim && delivery.state === 'pending') { delivery.state = 'pending'; delivery.claim = undefined; }\n else this.cancel(delivery);\n }\n this.run = next;\n if (next.phase !== 'running' || generationChanged) for (const r of this.requests.values()) r.dueAt = null;\n if (next.phase === 'running') for (const r of this.requests.values()) if (r.state !== 'settled' && r.automaticReminders === 0 && r.dueAt === null && this.prefs.reminders && this.prefs.notifications) r.dueAt = this.clock.now() + this.prefs.reminderDelayMs;\n this.refresh(); return true;\n }\n\n /** Baseline history folds pending state; it never replays proactive initial or reminder notices. */\n restore(session: SourceSession, questions?: QuestionProjection): void {\n if (session.header.origin === 'subagent' || this.sources.has(session.id)) return;\n this.source(session);\n for (const event of session.snapshotEvents?.() ?? []) this.event(session, event, false);\n if (questions) this.questions(session, questions, false);\n this.refresh();\n }\n consume(session: SourceSession, event: NotificationEvent): void {\n if (this.closed || session.header.origin === 'subagent') return;\n this.event(session, event, true); this.refresh();\n }\n private source(session: SourceSession): SourceState {\n let state = this.sources.get(session.id);\n if (!state) {\n if (this.sources.size >= 100) this.remove(this.sources.keys().next().value!);\n state = { seq: -1, turn: 0, finalText: '', calls: new Map(), label: session.header.cwd?.split(/[\\\\/]/).filter(Boolean).at(-1) ?? '\u4F1A\u8BDD' };\n this.sources.set(session.id, state);\n }\n return state;\n }\n private event(session: SourceSession, event: NotificationEvent, live: boolean): void {\n const source = this.source(session);\n if (event.seq <= source.seq) return;\n source.seq = event.seq;\n // Request settlements from older turns remain meaningful and use exact native identity.\n if (event.type === 'approval/decided') { this.settle(interactionId(session.id, 'approval', event.data.id)); return; }\n if (event.type === 'user/message') {\n const reply = event.data.source as { kind: string; callId?: string };\n if (reply.kind === 'user-question-reply' && reply.callId) { this.settle(interactionId(session.id, 'question', reply.callId)); return; }\n }\n if ('turn' in event.data && event.data.turn !== undefined && event.data.turn < source.turn) return;\n switch (event.type) {\n case 'turn/start': source.turn = event.data.turn; source.finalText = ''; break;\n case 'tool/call':\n if (event.data.name === 'ask_user_question') this.origin(source, event.data.callId, event.data.turn, event.seq, event.time);\n break;\n case 'tool/ptc-dispatch':\n if (event.data.name === 'ask_user_question') this.origin(source, event.data.subCallId, source.turn, event.seq, event.time);\n break;\n case 'assistant/message':\n source.finalText = event.data.message.content.some(p => p.type === 'tool-call') ? '' : event.data.message.content.filter(p => p.type === 'text').map(p => p.text).join('\\n'); break;\n case 'approval/asked':\n this.open(session.id, 'approval', event.data.id, source.turn, event.seq, event.time, `${event.data.toolName}: ${event.data.reason ?? body.approval}`, false, live); break;\n case 'turn/end': {\n source.turn = event.data.turn;\n if (event.data.reason.kind === 'forked') break;\n const category: TaskNotice['category'] = event.data.reason.kind === 'aborted' ? 'stopped' : event.data.reason.kind;\n if (live) this.enqueue(this.notice(session.id, source.turn, event.seq, event.time, category, source.finalText && category === 'completed' ? source.finalText : body[category]));\n source.finalText = '';\n // Approvals are enclosed by a turn. Durable continued questions are independently projected.\n for (const r of this.requests.values()) if (r.sessionId === session.id && r.kind === 'approval' && r.turn <= source.turn) this.settle(r.id);\n break;\n }\n }\n }\n /** Public projection is authoritative for timed questions, including continued questions after turn/end. */\n questions(session: SourceSession, projection: QuestionProjection, live = true): void {\n if (this.closed || session.header.origin === 'subagent') return;\n const source = this.source(session), active = new Set<string>();\n for (const question of projection.active) {\n const id = interactionId(session.id, 'question', question.callId); active.add(id);\n let origin = source.calls.get(question.callId);\n if (!origin) {\n const events = session.snapshotEvents?.() ?? [];\n const event = events.map(event => event as NotificationEvent).findLast(event => (event.type === 'tool/call' && event.data.callId === question.callId && event.data.name === 'ask_user_question') || (event.type === 'tool/ptc-dispatch' && event.data.subCallId === question.callId && event.data.name === 'ask_user_question'));\n if (event) {\n const start = events.findLast(prior => prior.type === 'turn/start' && prior.seq < event.seq);\n const turn = 'turn' in event.data && event.data.turn !== undefined ? event.data.turn : start?.type === 'turn/start' ? start.data.turn : 0;\n origin = { turn, seq: event.seq, time: event.time };\n }\n }\n const existing = this.requests.get(id);\n if (!origin && existing) origin = { turn: existing.turn, seq: existing.seq, time: existing.createdAt };\n if (!origin) {\n if (!this.problems.some(p => p.sessionId === session.id && p.nativeId === question.callId)) this.problems.push({ code: 'question-source-unavailable', sessionId: session.id, nativeId: question.callId });\n if (this.problems.length > 100) this.problems.shift();\n continue;\n }\n this.open(session.id, 'question', question.callId, origin.turn, origin.seq, origin.time, question.questions.map(q => q.question).join('\\n'), true, live, question.state);\n }\n for (const r of this.requests.values()) if (r.sessionId === session.id && r.projected && !active.has(r.id)) this.settle(r.id);\n for (const q of projection.settled ?? []) this.settle(interactionId(session.id, 'question', q.callId));\n this.refresh();\n }\n private origin(source: SourceState, id: string, turn: number, seq: number, time: number): void {\n source.calls.set(id, { turn, seq, time });\n if (source.calls.size > 200) source.calls.delete(source.calls.keys().next().value!);\n }\n /** Observe a runtime blocking request without claiming the answerer chain. */\n question(session: SourceSession, question: LiveQuestion): () => void {\n if (this.closed || session.header.origin === 'subagent' || question.signal?.aborted) return () => {};\n this.source(session);\n const id = interactionId(session.id, 'question', question.nativeId);\n this.open(session.id, 'question', question.nativeId, question.turn, question.seq, this.clock.now(), question.preview, false, true, 'open', question.source);\n const request = this.requests.get(id);\n if (!request) {\n this.problems.push({ code: 'request-capacity-exceeded', sessionId: session.id, nativeId: question.nativeId });\n if (this.problems.length > 100) this.problems.shift();\n return () => {};\n }\n const finish = () => { if (!request.projected) this.settle(id); this.refresh(); };\n question.signal?.addEventListener('abort', finish, { once: true });\n request.cleanup?.(); request.cleanup = () => question.signal?.removeEventListener('abort', finish);\n this.refresh(); return finish;\n }\n private open(sessionId: string, kind: PendingInteraction['kind'], nativeId: string, turn: number, seq: number, time: number, preview: string, projected: boolean, live: boolean, state: 'open' | 'continued' = 'open', sourceKind?: SourceKind): void {\n const id = interactionId(sessionId, kind, nativeId), existing = this.requests.get(id);\n if (existing) { if (existing.state !== 'settled') { existing.state = state; existing.projected ||= projected; existing.preview = preview.slice(0, 2048); } return; }\n if (this.requests.size >= 500) {\n const old = [...this.requests.values()].find(r => r.state === 'settled');\n if (old) this.requests.delete(old.id); else return;\n }\n // Restored requests keep their entrance, with no repeat automatic reminder on reload.\n const request: RequestState = { id, nativeId, sessionId, kind, turn, seq, createdAt: time, preview: preview.slice(0, 2048), state, dueAt: live && this.prefs.notifications && this.run.phase === 'running' && this.prefs.reminders ? this.clock.now() + this.prefs.reminderDelayMs : null, automaticReminders: live ? 0 : 1, projected, snoozes: 0, ...(sourceKind ? { source: sourceKind } : {}) };\n this.requests.set(id, request);\n if (live) {\n const notice = this.notice(sessionId, turn, seq, time, kind, request.preview, [id]) as SourcedNotice;\n if (sourceKind) notice.source = sourceKind;\n if (sourceKind === 'runtime') notice.id = this.identity(notice, 0, nativeId);\n this.enqueue(notice);\n }\n }\n private settle(id: string): void {\n const request = this.requests.get(id); if (!request || request.state === 'settled') return;\n request.state = 'settled'; request.dueAt = null; request.cleanup?.(); request.cleanup = undefined;\n for (const delivery of this.deliveries.values()) {\n if (!delivery.notice.requestIds.includes(id) || delivery.requested || ['role', 'cancelled'].includes(delivery.state)) continue;\n if (delivery.claim) { this.cancel(delivery); continue; }\n delivery.notice.requestIds = delivery.notice.requestIds.filter(key => key !== id && this.requests.get(key)?.state !== 'settled');\n if (!delivery.notice.requestIds.length) delivery.state = 'cancelled';\n else this.cancel(delivery); // A changed group invalidates any previously claimed payload.\n }\n }\n snooze(id: string, generation: number): boolean {\n const request = this.requests.get(id);\n if (!this.eligible() || generation !== this.run.generation || !this.prefs.reminders || !request || request.state === 'settled') return false;\n for (const delivery of this.deliveries.values()) if (!delivery.requested && delivery.notice.requestIds.includes(id) && ['pending', 'claimed'].includes(delivery.state)) this.cancel(delivery);\n request.dueAt = this.clock.now() + this.prefs.reminderDelayMs; request.snoozes++; this.refresh(); return true;\n }\n\n /** A live client poll refreshes its bounded liveness record and can own one eligible notice. */\n claim(clientId: string, generation: number, noticeId?: string): DeliveryClaim | null {\n if (!clientId || clientId.length > 2048 || this.closed || generation !== this.run.generation) return null;\n this.clients.set(clientId, this.clock.now());\n if (this.clients.size > 100) this.clients.delete(this.clients.keys().next().value!);\n this.tick();\n if (!this.eligible() || this.run.visible || !this.prefs.systemNotifications) return null;\n if ([...this.deliveries.values()].some(d => d.claim?.clientId === clientId && ['claimed', 'requested'].includes(d.state))) return null;\n const delivery = [...this.deliveries.values()].find(d => d.state === 'pending' && this.valid(d.notice) && (noticeId === undefined || d.notice.id === noticeId));\n if (!delivery) return null;\n const claim: DeliveryClaim = { token: this.options.token?.() ?? randomUUID(), clientId, generation, visibilityRevision: this.run.visibilityRevision, expiresAt: this.clock.now() + (this.options.claimDurationMs ?? 15_000), notice: structuredClone(delivery.notice) };\n delivery.state = 'claimed'; delivery.claim = claim;\n this.refresh(); return structuredClone(claim);\n }\n receipt(value: DeliveryReceipt): boolean {\n const parsed = deliveryReceiptSchema.safeParse(value); if (!parsed.success || this.closed) return false;\n const receipt = parsed.data, delivery = this.deliveries.get(receipt.noticeId), claim = delivery?.claim;\n if (!delivery || !claim || claim.token !== receipt.token || claim.clientId !== receipt.clientId || claim.generation !== receipt.generation || delivery.state === 'cancelled') return false;\n if (receipt.state === 'requested') {\n // A claim grants one channel once. Late reports only add evidence; they never authorize another delivery.\n if (!['claimed', 'unknown'].includes(delivery.state) || delivery.requested) return false;\n delivery.requested = true;\n } else if (receipt.state === 'failed') {\n if (!['claimed', 'requested', 'shown', 'unknown'].includes(delivery.state)) return false;\n } else {\n if (!delivery.requested || delivery.state === 'failed' || delivery.state === 'clicked') return false;\n if (receipt.state === 'unknown' && delivery.state !== 'requested') return false;\n if (receipt.state === 'shown' && !['requested', 'unknown'].includes(delivery.state)) return false;\n if (receipt.state === 'clicked' && !['requested', 'shown', 'unknown'].includes(delivery.state)) return false;\n }\n delivery.state = receipt.state;\n if (delivery.receipts.length < 5) delivery.receipts.push({ ...receipt });\n this.refresh(); return true;\n }\n private eligible(): boolean { return !this.closed && this.prefs.notifications && this.run.phase === 'running' && this.run.visibilityRevision > 0 && !this.run.suspended; }\n private valid(notice: TaskNotice): boolean { return !notice.requestIds.length || notice.requestIds.some(id => this.requests.get(id)?.state !== 'settled' && this.requests.has(id)); }\n private notice(sessionId: string, turn: number, seq: number, time: number, category: TaskNotice['category'], preview: string, requestIds: string[] = [], stage: TaskNotice['stage'] = 'initial'): TaskNotice {\n return noticeSchema.parse({ id: noticeId(sessionId, turn, seq, category, stage), sessionId, turn, seq, time, category, stage, title: `${this.sources.get(sessionId)?.label ?? '\u4F1A\u8BDD'} \u00B7 ${title[category]}`.slice(0, 256), body: preview.slice(0, 2048), requestIds });\n }\n private identity(notice: TaskNotice, occurrence = 0, runtimeId?: string): string {\n return noticeId(notice.sessionId, notice.turn, notice.seq, notice.category, notice.stage, occurrence, runtimeId);\n }\n private enqueue(notice: TaskNotice): void {\n if (!this.eligible() || this.deliveries.has(notice.id)) return;\n this.deliveries.set(notice.id, { notice, state: 'pending', requested: false, receipts: [] });\n if (this.deliveries.size > 300) {\n const old = [...this.deliveries.entries()].find(([, d]) => d.state !== 'claimed' && d.state !== 'requested');\n if (old) this.deliveries.delete(old[0]);\n }\n }\n private cancel(delivery: Delivery): void {\n if (delivery.claim && !['shown', 'clicked', 'failed'].includes(delivery.state)) delivery.state = 'unknown';\n else if (!delivery.claim && delivery.state !== 'role') delivery.state = 'cancelled';\n }\n private cancelDeliveries(): void { for (const d of this.deliveries.values()) this.cancel(d); }\n /** Callbacks always recompute request truth immediately before creating or dispatching a notice. */\n tick(): void {\n if (this.closed) return;\n const now = this.clock.now();\n for (const [id, time] of this.clients) if (now - time >= (this.options.clientLifetimeMs ?? 30_000)) this.clients.delete(id);\n for (const delivery of this.deliveries.values()) {\n if (!delivery.claim || !['claimed', 'requested'].includes(delivery.state)) continue;\n if (delivery.claim.expiresAt > now && this.clients.has(delivery.claim.clientId)) continue;\n delivery.state = 'unknown';\n }\n if (this.eligible() && this.prefs.reminders) {\n const groups = new Map<string, RequestState[]>();\n for (const request of this.requests.values()) if (request.state !== 'settled' && request.dueAt !== null && request.dueAt <= now) {\n const group = groups.get(request.sessionId) ?? []; group.push(request); groups.set(request.sessionId, group);\n }\n for (const [sessionId, requests] of groups) for (let start = 0; start < requests.length; start += 100) {\n const group = requests.slice(start, start + 100);\n const origin = group[0], notice = this.notice(sessionId, origin.turn, origin.seq, now, origin.kind, group.length > 1 ? `\u8FD8\u6709 ${group.length} \u4EF6\u4E8B\u7B49\u4F60\u770B\u770B\u3002` : '\u521A\u624D\u90A3\u4EF6\u4E8B\uFF0C\u8FD8\u7B49\u4F60\u770B\u770B\u3002', group.map(r => r.id), 'reminder');\n // Source seq remains literal; a snooze occurrence has its own stable scheduling identity.\n const occurrence = Math.max(...group.map(r => r.snoozes));\n if (origin.source === 'runtime') {\n (notice as SourcedNotice).source = 'runtime'; notice.id = this.identity(notice, occurrence, origin.nativeId);\n } else if (occurrence) notice.id = this.identity(notice, occurrence);\n for (const request of group) { request.dueAt = null; request.automaticReminders = 1; }\n this.enqueue(notice);\n }\n }\n if (this.eligible() && this.run.visible) for (const delivery of this.deliveries.values()) {\n if (delivery.state !== 'pending' || !this.valid(delivery.notice)) continue;\n const state = { ...this.run };\n try { if (this.options.presentRole?.(structuredClone(delivery.notice), state)) delivery.state = 'role'; } catch { delivery.state = 'failed'; }\n }\n }\n private refresh(): void {\n this.tick();\n if (this.timer !== undefined) this.clock.clearTimeout(this.timer);\n this.timer = undefined;\n if (!this.closed) {\n const due = this.eligible() ? [...this.requests.values()].flatMap(r => r.dueAt === null ? [] : [r.dueAt]) : [];\n for (const d of this.deliveries.values()) if (d.claim && ['claimed', 'requested'].includes(d.state)) due.push(Math.min(d.claim.expiresAt, (this.clients.get(d.claim.clientId) ?? this.clock.now()) + (this.options.clientLifetimeMs ?? 30_000)));\n if (due.length) this.timer = this.clock.setTimeout(() => { this.timer = undefined; this.refresh(); }, Math.max(1, Math.min(...due) - this.clock.now()));\n try { this.options.changed?.(); } catch { /* A view failure cannot escape into Harness dispatch. */ }\n }\n }\n private publicRequest(r: RequestState): PendingInteraction {\n const { projected: _projected, snoozes: _snoozes, cleanup: _cleanup, ...value } = r; return { ...value };\n }\n remove(sessionId: string): void {\n this.sources.delete(sessionId);\n for (const [id, r] of this.requests) if (r.sessionId === sessionId) { r.cleanup?.(); this.requests.delete(id); }\n for (const [id, d] of this.deliveries) if (d.notice.sessionId === sessionId) this.deliveries.delete(id);\n this.refresh();\n }\n dispose(): void {\n this.closed = true;\n if (this.timer !== undefined) this.clock.clearTimeout(this.timer);\n this.timer = undefined;\n for (const r of this.requests.values()) r.cleanup?.();\n this.cancelDeliveries(); this.clients.clear(); this.sources.clear(); this.requests.clear(); this.deliveries.clear(); this.problems.length = 0;\n }\n}\n", "import { z } from 'zod';\n\n/** Shared N0 contract. Host owns request truth and delivery claims; views render it. */\nexport const NOTIFICATION_PROTOCOL = 1 as const;\nconst id = z.string().min(1).max(2048);\nconst counter = z.number().int().nonnegative().safe();\nexport const notificationPreferencesSchema = z.object({\n notifications: z.boolean().default(true),\n systemNotifications: z.boolean().default(false),\n reminders: z.boolean().default(true),\n reminderDelayMs: z.number().int().min(60_000).max(86_400_000).default(600_000),\n}).strict();\nexport type NotificationPreferences = z.infer<typeof notificationPreferencesSchema>;\nexport const noticeSchema = z.object({\n id, sessionId: id, turn: counter, seq: counter, time: counter,\n category: z.enum(['completed', 'approval', 'question', 'error', 'stopped', 'interrupted', 'blocked', 'max-tokens']),\n stage: z.enum(['initial', 'reminder']),\n title: z.string().max(256), body: z.string().max(2048),\n requestIds: z.array(id).max(100).default([]), source: z.enum(['event', 'runtime']).optional(),\n}).strict();\nexport type TaskNotice = z.infer<typeof noticeSchema>;\n/** Tuple encoding preserves complete identities even when they contain separators. */\nexport function noticeId(sessionId: string, turn: number, seq: number, category: TaskNotice['category'], stage: TaskNotice['stage'], occurrence = 0, runtimeId?: string): string {\n if (!Number.isSafeInteger(occurrence) || occurrence < 0) throw new Error('Invalid notification occurrence');\n if (runtimeId !== undefined && !runtimeId.length) throw new Error('Invalid runtime request id');\n const tuple: (string | number)[] = [sessionId, turn, seq, category, stage];\n if (runtimeId !== undefined) tuple.push(runtimeId);\n if (occurrence > 0) tuple.push(occurrence);\n return JSON.stringify(tuple);\n}\nexport function interactionId(sessionId: string, kind: 'approval' | 'question', nativeId: string): string {\n return JSON.stringify([sessionId, kind, nativeId]);\n}\nexport const interactionSchema = z.object({\n id, sessionId: id, nativeId: id, kind: z.enum(['approval', 'question']),\n turn: counter, seq: counter, createdAt: counter, preview: z.string().max(2048),\n state: z.enum(['open', 'continued', 'settled']), source: z.enum(['event', 'runtime']).optional(),\n dueAt: counter.nullable(), automaticReminders: z.number().int().min(0).max(1),\n}).strict();\nexport type PendingInteraction = z.infer<typeof interactionSchema>;\nexport const runtimeSchema = z.object({\n phase: z.enum(['stopped', 'starting', 'running', 'stopping', 'error']),\n generation: counter, visibilityRevision: counter, visible: z.boolean(),\n suspended: z.boolean(), error: z.string().max(600).optional(),\n}).strict();\nexport type NotificationRuntime = z.infer<typeof runtimeSchema>;\nexport const deliveryClaimSchema = z.object({\n token: id, clientId: id, generation: counter, visibilityRevision: counter,\n expiresAt: counter, notice: noticeSchema,\n}).strict();\nexport type DeliveryClaim = z.infer<typeof deliveryClaimSchema>;\nexport const deliveryReceiptSchema = z.object({\n token: id, clientId: id, noticeId: id, generation: counter,\n state: z.enum(['requested', 'shown', 'clicked', 'failed', 'unknown']),\n time: counter, detail: z.string().max(600).optional(),\n}).strict();\nexport type DeliveryReceipt = z.infer<typeof deliveryReceiptSchema>;\nexport interface NotificationSnapshot {\n protocol: typeof NOTIFICATION_PROTOCOL;\n runtime: NotificationRuntime;\n interactions: PendingInteraction[];\n}\nexport const notificationRequests = {\n state: z.object({ locale: z.string().min(2).max(64).regex(/^[a-zA-Z0-9-]+$/).optional() }).strict(),\n claim: z.object({ clientId: id, generation: counter }).strict(),\n receipt: deliveryReceiptSchema,\n test: z.object({ clientId: id, generation: counter }).strict(),\n snooze: z.object({ interactionId: id, generation: counter }).strict(),\n} as const;\n/** Paths are carried by authenticated DSH Connection, with server-issued claim tokens. */\nexport const notificationEndpoints = ['notification-state', 'notification-claim', 'notification-receipt', 'notification-snooze', 'notification-test'] as const;\n\nexport interface WebNotificationStatus {\n supported: boolean;\n permission: NotificationPermission | 'unavailable';\n osAuthorization: 'unknown';\n}\n", "import { spawn, type ChildProcess } from 'node:child_process';\nimport { createRequire } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\n\nexport interface StartLifetime { signal: AbortSignal; generation: number; }\nexport interface NativeLifecycle { running: boolean; visible: boolean; error?: string; generation?: number; visibilityRevision?: number; suspended?: boolean; }\n\nexport interface DesktopOptions { size: number; roam: boolean; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n notify(notice: PetNotice | TaskNotice): void;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private resultKey?: string;\n private closing = false;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child) throw new Error('Desktop pet is already running');\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false; this.suspended = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002');\n const executable: string = options.electronPath ?? createRequire(import.meta.url)('electron');\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation) };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '';\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || !isRecord(message)) return;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const error = !this.closing && (code !== 0 || signal) ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code})` : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.send({ type: 'init', options, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: Error) => finish(error);\n const exited = (code: number | null, signal: string | null) => finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n child.on('error', error => { if (this.child === child && !this.closing) this.emit('failure', error); });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice): void { this.send({ type: 'notice', notice }); }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;\n this.send({ type: 'notice', notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision }); return true;\n }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n configure(options: DesktopOptions): void { this.send({ type: 'configure', options }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n if (this.child?.connected) this.child.send(message, error => { if (error && !this.closing) this.emit('failure', error); });\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "import { basename } from 'node:path';\nimport type { Session, SessionEvent } from '@deepseek-ai/dsh-session';\nimport type { AssistantStreamFrame } from '@deepseek-ai/dsh-agent';\nimport type {} from '@deepseek-ai/dsh-user-approval';\nimport { type PendingInteraction, type TaskNotice } from './notification-contract.ts';\n\nexport type Mood = 'idle' | 'thinking' | 'talking' | 'working' | 'waiting' | 'happy' | 'error' | 'sleeping';\nexport interface PetResult { id: string; sessionId: string; text: string; time: number; read: boolean; }\nexport interface PetSession { id: string; label: string; project: string; cwd: string; prompt: string; createdAt: number; updatedAt: number; mood: Mood; text: string; reply: string; replyId: string; unread: number; revision: number; active: boolean; streaming: boolean; speechId: string; chatAvailable?: boolean; }\nexport interface PetSnapshot { mood: Mood; text: string; sessionId: string | null; revision: number; active: boolean; streaming: boolean; speechId: string; results: PetResult[]; sessions: PetSession[]; }\nexport interface PetNotice extends Partial<Omit<TaskNotice, 'title' | 'body' | 'sessionId'>> { title: string; body: string; sessionId: string; kind?: 'task' | 'message'; }\ninterface TaskState { seq: number; turn: number; active: boolean; finalText?: string; tools: Map<string, string>; approvals: Set<symbol | string>; questions: Set<string>; requests: Set<string>; celebrateUntil: number; stream?: { id: string; revision: number; index: number; text: string; blocks: Map<number, string> }; }\ntype ObservedSession = Pick<Session, 'id' | 'header'> & Partial<Pick<Session, 'snapshotEvents'>>;\nconst ready = '\u51C6\u5907\u597D\u4E86\uFF0C\u968F\u65F6\u53EB\u6211\u3002';\n\n/** Keeps independent task states so background sessions cannot overwrite the selected conversation. */\nexport class PetModel {\n private sessions = new Map<string, PetSession>();\n private selected: string | null = null;\n private tasks = new Map<string, TaskState>();\n private results = new Map<string, PetResult>();\n constructor(private readonly now: () => number = Date.now) {}\n\n observe(session: ObservedSession): PetSession | undefined {\n if (session.header.origin === 'subagent') return;\n let item = this.sessions.get(session.id);\n if (!item) {\n // Bound retained presentation state; live Harness sessions remain owned by the host.\n if (this.sessions.size >= 100) {\n const old = [...this.sessions.keys()].find(id => id !== this.selected);\n if (old) this.remove(old);\n }\n const project = session.header.cwd ? basename(session.header.cwd) : '\u672A\u6307\u5B9A\u9879\u76EE';\n item = { id: session.id, label: project, project, cwd: session.header.cwd ?? '', prompt: '', createdAt: session.header.createdAt, updatedAt: session.header.createdAt, mood: 'idle', text: ready, reply: '', replyId: '', unread: 0, revision: 0, active: false, streaming: false, speechId: '' };\n this.sessions.set(session.id, item);\n this.tasks.set(session.id, { seq: -1, turn: 0, active: false, tools: new Map(), approvals: new Set(), questions: new Set(), requests: new Set(), celebrateUntil: 0 });\n this.selected ??= session.id;\n // Restore identity from public history, without replaying stale task states or notices.\n for (const event of session.snapshotEvents?.() ?? []) this.describe(item, event);\n }\n return item;\n }\n\n /** Fold history as a read baseline; callers reconcile activity with the live Agent status. */\n restore(session: ObservedSession): void {\n if (!this.observe(session)) return;\n for (const event of session.snapshotEvents?.() ?? []) this.fold(session, event, false);\n }\n\n private describe(item: PetSession, event: SessionEvent): void {\n if (event.type !== 'user/message' || event.data.source.kind !== 'user') return;\n const text = event.data.content.filter(p => p.type === 'text').map(p => p.text).join(' ').replace(/\\s+/g, ' ').trim();\n if (!text) return;\n if (!item.prompt) item.label = Array.from(text).slice(0, 64).join('');\n item.prompt = Array.from(text).slice(0, 160).join(''); item.updatedAt = event.time;\n }\n\n /** Live chunks are not session events. Keep attempt identity and ordering separate from durable seq. */\n stream(session: ObservedSession, frame: AssistantStreamFrame): boolean {\n const item = this.observe(session);\n if (!item) return false;\n const task = this.tasks.get(item.id)!;\n if (frame.type === 'start') {\n if (frame.turn < task.turn || (frame.turn === task.turn && !task.active && task.seq >= 0) || (task.stream && frame.revision <= task.stream.revision)) return false;\n task.turn = frame.turn; task.active = true;\n task.finalText = undefined;\n task.stream = { id: frame.attemptId, revision: frame.revision, index: -1, text: '', blocks: new Map() };\n item.streaming = true; item.speechId = frame.attemptId;\n if (!task.tools.size && !task.approvals.size) this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026');\n return true;\n }\n const stream = task.stream;\n if (!task.active || !stream || stream.id !== frame.attemptId || stream.revision !== frame.revision || frame.index <= stream.index) return false;\n stream.index = frame.index;\n if (frame.type === 'end') {\n item.streaming = false;\n if (frame.outcome.kind === 'abandoned' && !task.tools.size && !task.approvals.size) this.present(item, 'thinking', '\u6B63\u5728\u91CD\u65B0\u51C6\u5907\u56DE\u590D\u2026');\n return true;\n }\n const chunk = frame.chunk;\n if (chunk.type === 'text-delta' || (chunk.type === 'block-end' && chunk.block.type === 'text')) {\n if (chunk.type === 'text-delta') stream.blocks.set(chunk.index, ((stream.blocks.get(chunk.index) ?? '') + chunk.text).slice(0, 1200));\n else if (chunk.block.type === 'text') stream.blocks.set(chunk.index, chunk.block.text.slice(0, 1200));\n stream.text = [...stream.blocks.entries()].sort(([a], [b]) => a - b).map(([, text]) => text).join('\\n').slice(0, 1200);\n if (stream.text.trim()) {\n // Live text changes the expression, never the reader's confirmed result.\n if (!task.tools.size && !task.approvals.size) this.present(item, 'talking', '\u6B63\u5728\u7EC4\u7EC7\u56DE\u590D\u2026');\n }\n } else if (chunk.type === 'reasoning-delta' && !stream.text && !task.tools.size && !task.approvals.size) {\n // The pet signals reasoning without exposing private reasoning content.\n this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026');\n }\n return true;\n }\n\n detached(id: string): void { const task = this.tasks.get(id); if (task) task.stream = undefined; }\n\n idle(id: string): void {\n const item = this.sessions.get(id), task = this.tasks.get(id);\n if (!item || !task?.active) return;\n task.active = false; task.stream = undefined; task.tools.clear(); task.approvals.clear(); item.streaming = false;\n this.present(item, 'idle', ready);\n }\n\n /** Keep the user's focus stable when other conversations are created. */\n created(session: Pick<Session, 'id' | 'header'>): boolean {\n const item = this.observe(session);\n if (!item) return false;\n return true;\n }\n\n /** Baseline already-running agents without replaying old completion notifications. */\n running(session: Pick<Session, 'id' | 'header'>): void {\n const item = this.observe(session);\n if (!item || this.tasks.get(item.id)!.active) return;\n const task = this.tasks.get(item.id)!; task.active = true;\n if (task.requests.size || task.approvals.size) this.present(item, 'waiting', item.text);\n else this.present(item, 'thinking', '\u6B63\u5728\u5904\u7406\u5F53\u524D\u4F1A\u8BDD\u2026');\n }\n\n private present(item: PetSession, mood: Mood, text: string): void {\n item.active = this.tasks.get(item.id)!.active;\n if (item.mood === mood && item.text === text) return;\n item.mood = mood; item.text = text; item.revision++;\n }\n\n /** Celebration has a deadline independent of UI refreshes or other sessions. */\n settle(): boolean {\n let changed = false;\n for (const [id, task] of this.tasks) {\n if (!task.celebrateUntil || this.now() < task.celebrateUntil) continue;\n task.celebrateUntil = 0;\n const item = this.sessions.get(id)!;\n if (!task.active && item.mood === 'happy') { this.present(item, 'idle', ready); changed = true; }\n }\n return changed;\n }\n\n consume(session: Pick<Session, 'id' | 'header'>, event: SessionEvent): PetNotice | undefined {\n return this.fold(session, event, true);\n }\n\n private fold(session: Pick<Session, 'id' | 'header'>, event: SessionEvent, live: boolean): PetNotice | undefined {\n const item = this.observe(session);\n if (!item) return;\n const task = this.tasks.get(item.id)!;\n if (event.seq <= task.seq) return;\n task.seq = event.seq;\n this.describe(item, event);\n // Late results from a previous turn cannot overwrite a newer turn.\n if ('turn' in event.data && event.data.turn < task.turn) return;\n switch (event.type) {\n case 'turn/start':\n task.turn = event.data.turn; task.active = true; task.tools.clear(); task.approvals.clear(); task.celebrateUntil = 0;\n task.stream = undefined; task.finalText = undefined; item.streaming = false; item.speechId = ''; item.updatedAt = event.time;\n this.present(item, 'thinking', '\u8BA9\u6211\u60F3\u4E00\u60F3\u2026'); break;\n case 'step/start':\n task.active = true; task.finalText = undefined;\n if (!task.approvals.size && !task.tools.size) this.present(item, 'thinking', '\u6B63\u5728\u601D\u8003\u2026'); break;\n case 'tool/call':\n if (!task.active) break;\n task.tools.set(event.data.callId, event.data.name);\n if (!task.approvals.size) this.present(item, 'working', toolLabel(event.data.name)); break;\n case 'tool/result':\n if (!task.active) break;\n task.tools.delete(event.data.message.toolCallId);\n if (task.approvals.size) break;\n if (task.tools.size) { this.present(item, 'working', toolLabel(task.tools.values().next().value!)); break; }\n if (event.data.message.isError) {\n this.present(item, 'thinking', '\u8FD9\u4E00\u6B65\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u6B63\u5728\u5904\u7406\u3002');\n } else { this.present(item, 'thinking', '\u8FD9\u4E00\u6B65\u5B8C\u6210\u4E86\uFF0C\u7EE7\u7EED\u60F3\u60F3\u2026'); }\n break;\n case 'assistant/message': {\n const text = event.data.message.content.filter(p => p.type === 'text').map(p => p.text).join('\\n');\n if (!task.active) break;\n item.streaming = false;\n task.finalText = event.data.message.content.some(p => p.type === 'tool-call') ? undefined : text;\n if (text.trim() && !task.tools.size && !task.approvals.size) this.present(item, 'talking', '\u6B63\u5728\u7EC4\u7EC7\u56DE\u590D\u2026');\n break;\n }\n case 'approval/asked': {\n const notice = this.approval(item.id, event.data.toolName, event.data.id);\n return live ? notice : undefined;\n }\n case 'approval/decided':\n this.approvalSettled(item.id, event.data.id); break;\n case 'turn/end': {\n task.turn = event.data.turn; task.active = false; task.tools.clear(); task.approvals.clear(); task.celebrateUntil = 0;\n task.stream = undefined; item.streaming = false;\n switch (event.data.reason.kind) {\n case 'completed': {\n const text = task.finalText?.trim() ? task.finalText : '';\n if (text) {\n const id = `${item.id}:${event.data.turn}:${event.seq}`;\n this.results.set(id, { id, sessionId: item.id, text, time: event.time, read: !live });\n item.reply = text; item.replyId = id; if (live) item.unread++;\n // Retain complete text for the latest 200 results, preferring unread entries.\n if (this.results.size > 200) {\n const old = [...this.results.values()].find(r => r.read) ?? this.results.values().next().value!;\n this.results.delete(old.id);\n const owner = this.sessions.get(old.sessionId); if (owner && !old.read) owner.unread--;\n }\n }\n task.finalText = undefined;\n this.present(item, live ? 'happy' : 'idle', live ? text || '\u4EFB\u52A1\u5B8C\u6210' : ready); task.celebrateUntil = live ? this.now() + 2500 : 0;\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u5B8C\u6210`, body: text.slice(0, 180) || '\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002', sessionId: item.id, kind: 'task' } : undefined;\n }\n case 'error':\n this.present(item, 'error', '\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u8BF7\u56DE\u5230 Harness \u67E5\u770B\u8BE6\u60C5\u3002');\n return live ? { title: `${item.label} \u00B7 \u9700\u8981\u5173\u6CE8`, body: item.text, sessionId: item.id, kind: 'task' } : undefined;\n case 'blocked':\n case 'max-tokens':\n this.present(item, 'waiting', '\u4EFB\u52A1\u6682\u65F6\u505C\u4E0B\u4E86\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u6682\u505C`, body: item.text, sessionId: item.id, kind: 'task' } : undefined;\n case 'aborted':\n this.present(item, 'idle', '\u5148\u505C\u5728\u8FD9\u91CC\uFF0C\u968F\u65F6\u7EE7\u7EED\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u5DF2\u505C\u6B62`, body: item.text, sessionId: item.id, kind: 'task', category: 'stopped' } : undefined;\n case 'interrupted':\n this.present(item, 'waiting', '\u8FD9\u6BB5\u4EFB\u52A1\u4E2D\u65AD\u4E86\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002');\n return live ? { title: `${item.label} \u00B7 \u4EFB\u52A1\u4E2D\u65AD`, body: item.text, sessionId: item.id, kind: 'task', category: 'interrupted' } : undefined;\n default:\n this.present(item, 'idle', '\u51C6\u5907\u597D\u4E86\uFF0C\u968F\u65F6\u53EB\u6211\u3002');\n }\n }\n }\n }\n\n approval(id: string, tool: string, token: symbol | string = Symbol()): PetNotice | undefined {\n const item = this.sessions.get(id);\n if (!item) return;\n const task = this.tasks.get(id)!; task.active = true; task.approvals.add(token); task.celebrateUntil = 0;\n this.present(item, 'waiting', `${toolLabel(tool)}\u524D\u9700\u8981\u4F60\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230 Harness\u3002`);\n return { title: `${item.label} \u00B7 \u7B49\u4F60\u786E\u8BA4`, body: item.text, sessionId: id, kind: 'task' };\n }\n\n approvalSettled(id: string, token?: symbol | string): void {\n const item = this.sessions.get(id);\n const task = this.tasks.get(id);\n if (!item || !task?.active) return;\n if (token ? !task.approvals.delete(token) : !task.approvals.size) return;\n if (!token) task.approvals.clear();\n if (!task.approvals.size && item.mood === 'waiting') {\n this.present(item, task.tools.size ? 'working' : 'thinking', task.tools.size ? toolLabel(task.tools.values().next().value!) : '\u786E\u8BA4\u5DF2\u5904\u7406\uFF0C\u7B49\u5F85\u4EFB\u52A1\u7EE7\u7EED\u2026');\n }\n }\n\n /** Public request state can outlive a turn; viewing or reading never removes its waiting entrance. */\n interactions(values: readonly PendingInteraction[]): void {\n for (const [id, task] of this.tasks) {\n const wasPending = task.requests.size > 0;\n const pending = values.filter(value => value.sessionId === id && value.state !== 'settled');\n task.requests = new Set(pending.map(value => value.id));\n task.questions = new Set(pending.filter(value => value.kind === 'question').map(value => value.id));\n const item = this.sessions.get(id)!;\n if (pending.length) {\n task.celebrateUntil = 0;\n this.present(item, 'waiting', pending.some(value => value.kind === 'question') ? '\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002' : '\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230 Harness\u3002');\n } else if (wasPending && !task.approvals.size && item.mood === 'waiting') {\n this.present(item, task.active ? task.tools.size ? 'working' : 'thinking' : 'idle', task.active ? task.tools.size ? toolLabel(task.tools.values().next().value!) : '\u7B49\u5F85\u4EFB\u52A1\u7EE7\u7EED\u2026' : ready);\n }\n }\n }\n\n select(id: string): boolean {\n if (!this.sessions.has(id)) return false;\n this.selected = id; return true;\n }\n\n /** Acknowledging an older result cannot clear a newer completion. */\n read(id: string): boolean {\n const result = this.results.get(id);\n if (!result || result.read) return false;\n result.read = true;\n const item = this.sessions.get(result.sessionId); if (item) item.unread = Math.max(0, item.unread - 1);\n return true;\n }\n\n remove(id: string): void {\n this.sessions.delete(id);\n this.tasks.delete(id);\n for (const [key, result] of this.results) if (result.sessionId === id) this.results.delete(key);\n if (this.selected === id) this.selected = this.sessions.keys().next().value ?? null;\n }\n\n snapshot(): PetSnapshot {\n const item = this.selected ? this.sessions.get(this.selected) : undefined;\n this.settle();\n return { mood: item?.mood ?? 'idle', text: item?.text ?? ready, sessionId: item?.id ?? null, revision: item?.revision ?? 0, active: item?.active ?? false, streaming: item?.streaming ?? false, speechId: item?.speechId ?? '', results: [...this.results.values()].map(r => ({ ...r })), sessions: [...this.sessions.values()].map(s => ({ ...s })) };\n }\n}\n\nfunction toolLabel(name: string): string {\n if (/read|cat|view/.test(name)) return '\u6B63\u5728\u770B\u6587\u4EF6';\n if (/search|grep|find/.test(name)) return '\u6B63\u5728\u67E5\u627E';\n if (/write|edit|patch/.test(name)) return '\u6B63\u5728\u5199\u4EE3\u7801';\n if (/bash|shell|exec|terminal/.test(name)) return '\u6B63\u5728\u8FD0\u884C\u547D\u4EE4';\n if (/web|browse|fetch/.test(name)) return '\u6B63\u5728\u6D4F\u89C8';\n return `\u6B63\u5728\u4F7F\u7528 ${name.slice(0, 60)}`;\n}\n", "import type { DesktopOptions, PetBridge } from './bridge.ts';\nimport type { NotificationRuntime } from './notification-contract.ts';\n\nexport type PetCommand = 'start' | 'show' | 'hide' | 'restart' | 'stop' | 'characters';\nexport type PetStatus = NotificationRuntime;\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n}\nexport interface StartLifetime { signal: AbortSignal; generation: number; }\ninterface LifetimeBridge extends PetBridge { start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>; }\nexport interface ControlLimits { startTimeoutMs?: number; cleanupTimeoutMs?: number; }\n\n/** Commands own a cancellable native generation. Lifecycle acknowledgements alone establish visibility. */\nexport class PetControls {\n private state: PetStatus = { phase: 'stopped', visible: false, generation: 0, visibilityRevision: 0, suspended: false };\n private queue: Promise<unknown> = Promise.resolve();\n private disposed = false;\n private startup?: AbortController;\n private readonly listeners = new Set<(status: PetStatus) => void>();\n private readonly changed = (event: NativeLifecycle) => {\n if (this.disposed || event.generation !== this.state.generation || !Number.isSafeInteger(event.visibilityRevision) || event.visibilityRevision! < this.state.visibilityRevision) return;\n if (event.visibilityRevision === this.state.visibilityRevision && event.visible !== this.state.visible) return;\n if (this.state.phase === 'stopping' || ((this.state.phase === 'stopped' || this.state.phase === 'error') && event.running)) return;\n this.set({ ...this.state, phase: event.error ? 'error' : event.running ? this.state.phase === 'starting' ? 'starting' : 'running' : 'stopped', visible: event.running && event.visible, visibilityRevision: event.visibilityRevision!, suspended: event.suspended ?? false, ...(event.error ? { error: event.error.slice(0, 600) } : {}) });\n };\n constructor(private readonly bridge: PetBridge, private readonly options: () => DesktopOptions, private readonly limits: ControlLimits = {}) {\n bridge.onLifecycle?.(this.changed);\n }\n status(): PetStatus { return { ...this.state }; }\n /** Root assembly registers this listener as a context-owned effect. */\n onState(listener: (status: PetStatus) => void): () => void {\n this.listeners.add(listener); try { listener(this.status()); } catch { /* A view is optional. */ } return () => this.listeners.delete(listener);\n }\n configure(): void { this.bridge.configure?.(this.options()); }\n command(command: PetCommand): Promise<PetStatus> {\n // A stop during a pending launch cancels immediately, before entering the command queue.\n if (command === 'stop' || command === 'restart') this.startup?.abort();\n return this.enqueue(async () => {\n if (this.disposed) throw new Error('\u684C\u5BA0\u63D2\u4EF6\u5DF2\u505C\u7528');\n try {\n if (command === 'stop' || command === 'restart') {\n this.set({ ...this.state, phase: 'stopping', visible: false, suspended: false });\n await this.cleanup();\n this.set({ ...this.state, phase: 'stopped', visible: false, suspended: false });\n }\n if (command !== 'stop' && command !== 'hide' && this.state.phase !== 'running') {\n const startup = new AbortController(); this.startup = startup;\n this.set({ phase: 'starting', visible: false, generation: this.state.generation + 1, visibilityRevision: 0, suspended: false });\n await this.withDeadline((this.bridge as LifetimeBridge).start(this.options(), { signal: startup.signal, generation: this.state.generation }), this.limits.startTimeoutMs ?? 25_000, '\u684C\u5BA0\u542F\u52A8\u8D85\u65F6', startup.signal);\n if (startup.signal.aborted || this.disposed) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.startup = undefined;\n this.set({ ...this.state, phase: 'running' });\n }\n if (this.state.phase === 'running') this.bridge.control?.(command === 'characters' ? 'characters' : command === 'hide' ? 'hide' : 'show');\n return this.status();\n } catch (error) {\n this.startup?.abort(); this.startup = undefined;\n const cleanup = await this.cleanup().then(() => '', failure => `\uFF1B\u6E05\u7406\u5931\u8D25\uFF1A${this.message(failure)}`);\n this.set({ ...this.state, phase: 'error', visible: false, suspended: false, error: (this.message(error) + cleanup).slice(0, 600) });\n return this.status();\n }\n });\n }\n async dispose(): Promise<void> {\n this.disposed = true; this.startup?.abort();\n this.set({ ...this.state, phase: 'stopping', visible: false, suspended: false });\n await this.enqueue(async () => {\n this.bridge.removeLifecycle?.(this.changed);\n const failure = await this.cleanup().then(() => undefined, error => this.message(error));\n this.set({ ...this.state, phase: failure ? 'error' : 'stopped', visible: false, ...(failure ? { error: failure } : {}) });\n this.listeners.clear();\n });\n }\n private message(error: unknown): string { return String(error instanceof Error ? error.message : error).slice(0, 600); }\n private cleanup(): Promise<void> { return this.withDeadline(Promise.resolve().then(() => this.bridge.dispose()), this.limits.cleanupTimeoutMs ?? 5_000, '\u684C\u5BA0\u6E05\u7406\u8D85\u65F6'); }\n private withDeadline<T>(task: Promise<T>, delay: number, message: string, signal?: AbortSignal): Promise<T> {\n return new Promise((resolve, reject) => {\n let done = false;\n const finish = (error?: unknown, value?: T) => {\n if (done) return; done = true; clearTimeout(timer); signal?.removeEventListener('abort', aborted);\n if (error) reject(error); else resolve(value as T);\n };\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new Error(message)), delay);\n signal?.addEventListener('abort', aborted, { once: true });\n if (signal?.aborted) aborted();\n task.then(value => finish(undefined, value), error => finish(error));\n });\n }\n private set(state: PetStatus): void {\n this.state = state;\n for (const listener of this.listeners) { try { listener(this.status()); } catch { /* View errors cannot stall native cleanup. */ } }\n }\n private enqueue<T>(operation: () => Promise<T>): Promise<T> {\n const pending = this.queue.then(operation); this.queue = pending.catch(() => undefined); return pending;\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,cAAAA,mBAAkB;AAS3B,SAAS,iBAA+B;;;ACTxC,SAAS,kBAAkB;;;ACA3B,SAAS,SAAS;AAGX,IAAM,wBAAwB;AACrC,IAAM,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;AACrC,IAAM,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK;AAC7C,IAAM,gCAAgC,EAAE,OAAO;AAAA,EACpD,eAAe,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACvC,qBAAqB,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA,EAC9C,WAAW,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACnC,iBAAiB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAM,EAAE,IAAI,KAAU,EAAE,QAAQ,GAAO;AAC/E,CAAC,EAAE,OAAO;AAEH,IAAM,eAAe,EAAE,OAAO;AAAA,EACnC;AAAA,EAAI,WAAW;AAAA,EAAI,MAAM;AAAA,EAAS,KAAK;AAAA,EAAS,MAAM;AAAA,EACtD,UAAU,EAAE,KAAK,CAAC,aAAa,YAAY,YAAY,SAAS,WAAW,eAAe,WAAW,YAAY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