| 1 | /** Owner/scope registration only. Rust owns command review, scheduling, processes and steering. */ |
| 2 | import { Service } from '@deepseek-ai/cordis' |
| 3 | import type { OwnerBase, OwnedEntry, OwnedRegistrations } from './owned.ts' |
| 4 | export interface ShellDefinition {dialect:'claude-code'|'codex';point:string;matcher?:string;hook:{event:string;command:string;timeout_secs:number;background:boolean;continue_on_error:boolean;name:string}} |
| 5 | export interface LocalShellHook<O extends OwnerBase> extends OwnedEntry<O> {} |
| 6 | export function defineShellHooksService<O extends OwnerBase>(options:{ownerOf:(ctx:any)=>O|undefined;registrations:OwnedRegistrations<O,LocalShellHook<O>>}) { |
| 7 | class ShellHooks extends Service { |
| 8 | constructor(ctx:any){super(ctx,'shellHooks')} |
| 9 | register(definition:ShellDefinition):()=>void { |
| 10 | const ctx:any=this.ctx;const owner=options.ownerOf(ctx) |
| 11 | if(!owner || owner.ref.plugin_id.startsWith('host:'))throw new Error('shell hooks require a reviewed Native owner') |
| 12 | const text=JSON.stringify(definition) |
| 13 | if(Buffer.byteLength(text)>64*1024)throw new Error('shell hook definition exceeds 64 KiB') |
| 14 | return ctx.effect(()=>options.registrations.add({owner,name:definition.hook.name,disposed:false},{name:definition.hook.name,description:text}),'shellHooks.register') |
| 15 | } |
| 16 | } |
| 17 | Object.freeze(ShellHooks.prototype);return ShellHooks |
| 18 | } |
| 19 |