Files
archived-orca/src/cli/plugin-dev-watch/plugin-frame-log-dedupe.ts
T
Neil 2666bbddbe Plugin dev loop: dev request, shot --act, worker-panel template, output polish (#37049)
* feat(plugins): orca plugin dev request; --template worker-panel

- orca plugin dev request <dir|key> <name> [--data] [--panel] [--timeout-ms] calls a dev
  plugin's orca.panels.handle handler through the real panel bridge (plugins.devRequest) and
  prints the answer; handler errors become plugin_request_failed with the worker's code.
- orca plugin create --template worker-panel scaffolds a build-less trusted-worker plugin: a
  components panel, src/worker.ts, a shared src/protocol.ts contract, and panel and worker tests
  that pass under orca plugin test and type-check with tsc.

* feat(plugins): shot --act, shots in the plugin folder, quieter logs

- orca plugin shot --act '<json>' presses, types, selects and toggles in the live components
  panel (the test kit's queries and acts, through Orca's own controls and onEvent) before the
  capture, waiting for each to settle. Only that plugin's panel, only with Orca's window hidden
  or minimized; html panels refused; acts are not user gestures. Results in actions[].
- shot run inside a plugin folder defaults to its .orca/shots, like dev watch --shot.
- dev watch prints identical [frame] lines once per reload with a count; logged stacks drop
  <anonymous>/native frames; the floating workspace button hides during a capture.
- Skill: worker-panel template in the decision table, dev request, shot --act, and a gotcha
  that a worker save drops its in-memory state.
2026-11-01 07:31:10 -08:00

64 lines
2.1 KiB
TypeScript

import type { PluginLogLine } from './plugin-log-follower'
/** A log line as dev watch prints it: `count` identical lines, or `repeat`s of one printed earlier. */
export type PluginDevWatchLogLine = PluginLogLine & { count?: number; repeat?: true }
const FRAME_PREFIX = '[frame] '
const keyOf = (line: PluginLogLine): string => `${line.level}\u0000${line.line}`
/**
* Panel console lines repeat per item and per render (a warning inside `items.map`), so within one
* reload each `[frame]` line prints once with how many arrived together; later copies are counted
* and reported once when the plugin reloads or the watch ends. Worker lines pass through as is.
*/
export class PluginFrameLogDedupe {
private readonly repeats = new Map<string, { more: number; last: PluginLogLine }>()
take(lines: readonly PluginLogLine[]): PluginDevWatchLogLine[] {
const batch = new Map<string, number>()
for (const line of lines) {
if (line.line.startsWith(FRAME_PREFIX)) {
batch.set(keyOf(line), (batch.get(keyOf(line)) ?? 0) + 1)
}
}
const out: PluginDevWatchLogLine[] = []
const printed = new Map<string, PluginLogLine>()
for (const line of lines) {
const key = keyOf(line)
const count = batch.get(key)
if (count === undefined) {
out.push(line)
continue
}
const seen = this.repeats.get(key)
if (seen) {
seen.more += 1
seen.last = line
continue
}
if (!printed.has(key)) {
printed.set(key, line)
out.push(count > 1 ? { ...line, count } : line)
}
}
// After the loop, so this batch's own copies count in `count`, not as repeats.
for (const [key, line] of printed) {
this.repeats.set(key, { more: 0, last: line })
}
return out
}
/** A reload (or the end of the watch): what repeated since it printed, then a clean slate. */
flush(): PluginDevWatchLogLine[] {
const out: PluginDevWatchLogLine[] = []
for (const { more, last } of this.repeats.values()) {
if (more > 0) {
out.push({ ...last, count: more, repeat: true })
}
}
this.repeats.clear()
return out
}
}