Files
archived-orca/src/cli/handlers/plugin-dev-emit.ts
T
NeilandClaude 60d262ebee feat(plugins): hooks for agent launches and prompts, plus plugin dev hook (#37295)
* plugins: agent.launch.before and agent.prompt.before hooks; orca plugin dev hook

agent.launch.before runs at the PTY spawn every agent terminal goes through
(window tabs, runtime/CLI agent launch, automations, orchestration), before
dispatch to its host: change the command line, add env (Orca's own ORCA_*
variables and the agent's environment stay hidden), or deny. Restores and
resumes are not hooked. agent.prompt.before runs in sendTerminalAgentPrompt
(launch prompts, orchestration dispatch, terminal send to an agent) with the
agent named: rewrite or deny. The terminal hooks move into one runtime layer.
orca plugin dev hook runs a hook through one dev plugin and prints the decision.

Co-Authored-By: Claude <noreply@anthropic.com>

* plugins: recheck rewritten launch commands, forward hook env to WSL, keep prompt delivery outside the hook order

- A command agent.launch.before rewrote passes the AI Vault resume check again
  on both spawn paths.
- Variables a hook adds are named in WSLENV on Windows so WSL agents get them.
- agent.prompt.before holds the terminal's order only while it decides; a
  delivery waiting on a permission answer no longer blocks later input.

Co-Authored-By: Claude <noreply@anthropic.com>

* plugins: plugin dev hook honours onError: deny

Co-Authored-By: Claude <noreply@anthropic.com>

* plugins: regenerate the testing bundle and skill guides on the rebased hooks

Generated files only (lint-staged's oxlint refuses a commit with no lintable files).

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 21:20:29 -08:00

67 lines
2.1 KiB
TypeScript

import type { CommandHandler, HandlerContext } from '../dispatch'
import { printPluginResult, requirePluginPathArg } from '../plugin-authoring/plugin-cli-output'
import { RuntimeClientError } from '../runtime/types'
import { callPlugins, devTargetParams, stringFlag } from './plugin-runtime'
export type PluginDevEmitReply = {
pluginKey: string
event: string
delivered: { worker: boolean; panels: number }
}
export type PluginDevHookReply = {
pluginKey: string
event: string
decision: { kind: 'continue'; event: unknown } | { kind: 'deny'; reason: string }
}
/** `--data` as JSON; shared by `dev emit` and `dev request`. */
export function parseDataFlag(ctx: HandlerContext): unknown {
const raw = stringFlag(ctx, 'data')
if (raw === undefined) {
return undefined
}
try {
return JSON.parse(raw)
} catch (error) {
throw new RuntimeClientError(
'invalid_argument',
`--data is not JSON: ${error instanceof Error ? error.message : String(error)}`
)
}
}
export const PLUGIN_DEV_EMIT_HANDLERS: Record<string, CommandHandler> = {
'plugin dev hook': async (ctx) => {
const target = devTargetParams(ctx, requirePluginPathArg(ctx, 'target'))
const event = requirePluginPathArg(ctx, 'event')
const result = await callPlugins<PluginDevHookReply>(ctx, 'plugins.devHook', {
...target,
event,
payload: parseDataFlag(ctx)
})
const decision = result.decision
printPluginResult(
ctx,
result,
decision.kind === 'deny'
? `${result.event}: denied by ${result.pluginKey}: ${decision.reason}`
: `${result.event}: continue with ${JSON.stringify(decision.event)}`
)
},
'plugin dev emit': async (ctx) => {
const target = devTargetParams(ctx, requirePluginPathArg(ctx, 'target'))
const event = requirePluginPathArg(ctx, 'event')
const result = await callPlugins<PluginDevEmitReply>(ctx, 'plugins.devEmit', {
...target,
event,
payload: parseDataFlag(ctx)
})
printPluginResult(
ctx,
result,
`Sent ${result.event} to ${result.pluginKey}'s worker; handler errors show in \`orca plugin logs ${result.pluginKey}\`.`
)
}
}