07-event-system

07-event-system is a cursor rule for coding agents from loonghao/auroraview. It costs 787 tokens per session, scanned A, original, MIT.

A project rule defining how AuroraView sends events from Python and Rust to JavaScript. Events are emitted through the AuroraView bridge and received by JavaScript handlers registered in that same system.

In plain words
What is it for?
It is for implementing or reviewing Python-to-JavaScript event flows in AuroraView applications. It covers the standard emit, trigger, and on pattern and notes how frontend code should handle the current bridge behavior.
Why use it?
It prevents different event-delivery methods from being mixed together. Following one path makes the bridge easier to understand and provides a clear error when the frontend is not ready.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/loonghao/auroraview/07-event-system
Clone the repo
git clone --depth 1 https://github.com/loonghao/auroraview

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 07-event-system

README.md
[![agentmods](https://agentmods.dev/badge/rules/loonghao/auroraview/07-event-system.svg)](https://agentmods.dev/rules/loonghao/auroraview/07-event-system)
Your own site
<a href="https://agentmods.dev/rules/loonghao/auroraview/07-event-system"><img src="https://agentmods.dev/badge/rules/loonghao/auroraview/07-event-system.svg" alt="Measured on agentmods" height="20"></a>
Per session 787 This file is loaded in full into every session.
When invoked 787 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00787 $0.00787
Opus 5 $0.00394 $0.00394
Sonnet 5 $0.00157 $0.00157
Haiku 4.5 $0.00079 $0.00079

Measured 5d ago against content hash 3344b1d483db, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

07-event-system scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.codebuddy/rules/07-event-system.mdc · 77 lines

How it starts

The opening of the file, as written. The whole thing — 77 lines — stays where its author put it; the contents beside it link to each section on GitHub.

事件分发机制(Python → JavaScript)

关键设计决策(2025-01):统一使用 window.auroraview.trigger() 进行事件分发

  • Rust 层实现

    • 所有 WebViewMessage::EmitEvent 处理统一使用 window.auroraview.trigger(event, data)
    • 替代原有的 window.dispatchEvent(new CustomEvent(...))
    • 涉及文件:
      • src/webview/backend/native.rs
      • src/webview/event_loop.rs(两处)
      • src/webview/webview_inner.rs
      • src/webview/backend/mod.rs
      • src/webview/backend/custom.rs
  • 标准模式

    (function() {
        if (window.auroraview && window.auroraview.trigger) {
            window.auroraview.trigger('event_name', data);
        } else {
            console.error('[AuroraView] Event bridge not ready, cannot emit event: event_name');
        }
    })();
    
  • 前端接收

    • 使用 window.auroraview.on(event, handler) 订阅事件
    • 与 Rust 层的 trigger() 完全匹配
    • 形成完整的事件流:Python emit()Rust trigger()JS on()
  • 架构优势

    • API 一致性:统一使用 AuroraView 事件系统,不混用浏览器原生 API
    • 错误处理:事件桥接未就绪时有明确错误提示
    • 可维护性:所有事件分发逻辑集中在 window.auroraview 命名空间

最小端到端示例(当前实现)

注意:当前实现中,auroraview.call() 在桥接层还是 fire-and-forget,Promise 会立即 resolve 为 undefined; 最推荐的模式是:前端通过 auroraview.api.* 触发 Python 逻辑,Python 再通过 emit 向前端推事件。

  • 前端(JS):

    // 等待 bridge 就绪
    window.addEventListener('auroraviewready', () => {
      // 订阅来自 Python 的 echo 结果
      auroraview.on('echo_result', (payload) => {
        console.log('[AuroraView] echo_result from Python:', payload);
      });
    
      // 通过 api 调用 Python 方法(fire-and-forget)
      auroraview.api.echo({ message: 'hello from JS' });
    });
    
  • Python(概念示例,基于 AuroraView 基类):

    from auroraview import AuroraView
    
    class MyTool(AuroraView):
        def __init__(self, **kwargs):
            super().__init__(api=self, **kwargs)
    
        # JS 侧调用:auroraview.api.echo({ message: "..." })
        def echo(self, message: str) -> None:
            # 当前实现:通过事件把结果推回前端
            self.emit("echo_result", {"message": message})
    

后续在 call 的 request/response 协议补全后,可以把 echo 设计为真正返回值的函数, 前端直接使用 await auroraview.api.echo("hello") 获取结果。

Read the full file on GitHub · 77 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 77 lines · 787 tokens per session scan A 3344b1d483db

Subscribe to this mod's changes

07-event-system is a cursor rule published in the GitHub repository loonghao/auroraview (44 stars, last pushed 1mo ago), licensed MIT. It adds 787 tokens to every session, about $0.0039 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.