feat: vendor permission system source

This commit is contained in:
云服务部-叶林立
2026-08-19 14:35:19 +08:00
parent 198584daf8
commit 410c50a3e5
809 changed files with 157793 additions and 139 deletions
@@ -0,0 +1,47 @@
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
import type { RegisteredChildDetector } from "./authority/subagent-detection";
import { emitReadyEvent, type PermissionEventBus } from "./permission-events";
import {
type PermissionsService,
publishPermissionsService,
unpublishPermissionsService,
} from "./service";
/** The session-scoped service lifecycle that the lifecycle handler drives. */
export interface ServiceLifecycle {
activate(ctx: ExtensionContext): void;
teardown(): void;
}
/**
* Owns the process-global service publication lifecycle for one extension
* instance.
*
* - `activate` publishes the service (skipped for registered subagent children
* so they never clobber the parent's slot — see #302), then emits the ready
* event.
* - `teardown` runs all session-scoped subscription cleanups in order, then
* unpublishes the service.
*/
export class PermissionServiceLifecycle implements ServiceLifecycle {
constructor(
private readonly service: PermissionsService,
private readonly detection: RegisteredChildDetector,
private readonly events: PermissionEventBus,
private readonly subscriptions: readonly (() => void)[],
) {}
activate(ctx: ExtensionContext): void {
if (!this.detection.isRegisteredChild(ctx)) {
publishPermissionsService(this.service);
}
emitReadyEvent(this.events);
}
teardown(): void {
for (const unsubscribe of this.subscriptions) {
unsubscribe();
}
unpublishPermissionsService(this.service);
}
}