## Что это
## Резюме (RU)
G2.2.1.B — Lifecycle-хуки для фреймворка интеграции
*Полный перевод тела — в работе. Английский оригинал ниже.*
---
# Original (EN)
## Summary
Implements Goal 2 sub-objective **2.1.B — Lifecycle hooks** for the integration framework (spec `docs/superpowers/specs/2026-05-20-rox-integration-vision-design.md` § 2.1.B). Adds the runtime in-code lifecycle hook surface that complements the JSON-serialisable lifecycle handler names already declared on `IntegrationManifest`.
## What changed
* `packages/shared/src/integrations/lifecycle.ts` (new) exports:
* `IntegrationLifecycleHooks` — interface with optional `beforeStart`, `onReady`, `onError`, `beforeStop` (each `Promise | void`).
* `IntegrationLifecycleContext` — `{ manifestId: string; phase: IntegrationLifecyclePhase }` (readonly).
* `IntegrationLifecyclePhase` — `'beforeStart' | 'onReady' | 'onError' | 'beforeStop'`.
* `runLifecycleHook(hook, context, error?, onErrorHook?)` — try/catch wrapper that emits a structured `[integration.lifecycle]` log entry `{ manifestId, phase, error }` on failure, fans out to `onErrorHook` (unless the failing phase IS `onError`), and returns `'ok' | 'error'`. Missing hooks are no-ops. A throwing `onError` is logged but never re-thrown.
* `runLifecycle(manifestId, hooks, body)` — orchestrator that fires phases in canonical order (`beforeStart → onReady → body → beforeStop`); on failure routes through `onError` and STILL runs `beforeStop` so resources are released.
* `packages/shared/src/integrations/manifest.ts` — adds optional `lifecycleHooks?: IntegrationLifecycleHooks` to both the `in-process` and `web-contents-view` variants. Zod treats the field as `unknown` (function shapes are not JSON-validatable); the TS type intersects in the strongly-typed hook bag.
* `packages/shared/src/integrations/index.ts` — re-exports the new public surface alongside the existing manifest/registry exports.
* `packages/shared/src/integrations/__tests__/lifecycle.test.ts` (new) — 14 tests across 5 groups: hook ordering, failure semantics (throw in any phase fires onError once + still runs beforeStop, throwing onError is swallowed), optionality (missing hooks/empty bag/undefined bag are all no-ops), async awaiting, direct `runLifecycleHook` invocation.
## Verification evidence
```
$ cd packages/shared && bun run tsc --noEmit
→ EXIT 0 (clean)
$ bun test packages/shared/src/integrations/__tests__/lifecycle.test.ts
bun test v1.3.13 (bf2e2cec...
## Статус
Это задача из текущего backlog'а ROX.ONE (Linear). Текущий статус в Linear: `На ревью — In Review`. Метки: —.
## 🔗 Linear
- [PZD-109](https://linear.app/kuhjie/issue/PZD-109/g221b-lifecycle-huki-dlya-frejmvorka-integracii-g221b-lifecycle-hooks) — backing ticket
- Parent epic: [PZD-116](https://linear.app/kuhjie/issue/PZD-116)