office_watch_scheme.rs

office_watch_scheme.rs is a command for Claude Code from NetMindAI-Open/NarraNexus. It costs 0 tokens per session (1,221 once invoked), scanned A, original, Apache-2.0.

Rust code for a custom desktop URL scheme that lets a Tauri app load live Office document previews through a local backend.

In plain words
What is it for?
Use it when maintaining the Office preview proxy, mapping custom URLs to the local backend, serving page resources, polling for document changes, or checking requests for path traversal and server-side request forgery risks.
Why use it?
It works around the browser security rule that can block a web page loaded over HTTPS from requesting active content over plain HTTP. It also handles the limits of long-lived server-sent event connections in Tauri custom protocols.

Command for Claude Code

Written for Claude Code: a Claude Code command (commands/*.md).

Good fit Use it when maintaining the Office preview proxy, mapping custom URLs to the local backend, serving page resources, polling for document changes, or checking requests for path traversal and server-side request forgery risks.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/netmindai-open/narranexus/office_watch_scheme.rs
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.

Clone the repo
git clone --depth 1 https://github.com/NetMindAI-Open/NarraNexus

Made for: Claude Code.

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 office_watch_scheme.rs

README.md
[![agentmods](https://agentmods.dev/badge/commands/netmindai-open/narranexus/office_watch_scheme.rs.svg)](https://agentmods.dev/commands/netmindai-open/narranexus/office_watch_scheme.rs)
Your own site
<a href="https://agentmods.dev/commands/netmindai-open/narranexus/office_watch_scheme.rs"><img src="https://agentmods.dev/badge/commands/netmindai-open/narranexus/office_watch_scheme.rs.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,221 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00000 $0.01221
Opus 5 $0.00000 $0.00611
Sonnet 5 $0.00000 $0.00244
Haiku 4.5 $0.00000 $0.00122

Measured 8d ago against content hash 60d7fa0cf4fe, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

office_watch_scheme.rs 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 8d 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.

.mindflow/mirror/tauri/src-tauri/src/commands/office_watch_scheme.rs.md · 61 lines

How it starts

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

office_watch_scheme.rs — officewatch:// 自定义协议(桌面实时预览)

为什么存在

桌面(dmg)实时 Office 预览要在 iframe 里加载 officecli-watch 页面。webview origin 是 https://tauri.localhost,后端在 http://localhost:8000 → WKWebView 把这个 http iframe 当 active mixed content 静默拦掉(和 artifact 同一个 P0)。

静态 artifact 用 base64 blob 绕过(见 artifact_fetch.rs),但 blob 是静态快照;watch 页面 要拉自己的子资源(assets/字体/katex)还有一个 SSE 端点,blob 一个都带不了。

所以这里换自定义协议:custom scheme 不算混合内容,webview 会加载;页面自己的根相对子请求 经后端注入的 <base> 解析回 officewatch:// 也落到这里,于是每个资源都由 Rust 代理。Rust 自己 发起的 HTTP 不受 WKWebView 约束。

关键设计

  • 不能流式 SSE:Tauri 自定义协议的 responder 只应答一次、respond 消费 self,撑不住 SSE 长连 (实测 Windows 不支持、macOS 实验性)。所以对页面的 /events 请求直接返回空(桌面无 SSE 推送),实时更新改由前端 OfficeWatchViewermtime 轮询 → 重载 iframe 驱动(watch 首页 GET 永远渲染当前文档)。这是"稳妥版"取舍:每次内容变化刷新一次(轮询节奏),非逐帧丝滑。
  • URL 映射:officewatch://localhost/api/public/office-watch-proxy/{token}/{port}/... 1:1 映到 http://localhost:8000/api/public/office-watch-proxy/...。取 uri.path()+query 拼到 BACKEND。
  • SSRF 护栏(两段):path 后面会原样拼进 format!("{BACKEND}{path}"),所以先做两道检查再放行。 ①先拒 .. 点段(path.split('/').any(|seg| seg == ".."))——若某平台 webview 不为自定义 scheme 归一化点段,/api/public/office-watch-proxy/../../secret 可能通过前缀检查却落到任意后端路由;按 段切分只拦 .. 段、不误伤合法含点文件名。②再查前缀:只代理 /api/public/office-watch-proxy/,其它一律 403。token 即鉴权(后端 open 铸,放在路径里),和浏览器 完全一致;只打 loopback :8000。
  • CORS:iframe 用 sandbox="allow-scripts"(不透明源),它对 officewatch:// 的请求是跨源 → 和浏览器代理一样加 Access-Control-Allow-Origin: *(auth 是路径里的 token,不是 cookie)。

上下游

  • 注册在:lib.rs::run().register_asynchronous_uri_scheme_protocol("officewatch", ...) (spawn 到 async runtime 里跑 handle,再 responder.respond)。
  • 被谁用:frontend/.../OfficeWatchViewer.tsx —— isTauri() 时把后端 http open URL 转成 officewatch://localhost 前缀(toDesktopScheme)当 iframe src。
  • 依赖:reqwest 0.12(loopback http,无 TLS,和 artifact_fetch 同款);tauri::http

Gotcha

  • 只 macOS:NarraNexus 桌面只发 macOS(targets: ["dmg","app"],CI 只 build-macos),所以 custom-scheme 的跨平台流式限制不影响我们;但也因此这条路只在 WKWebView 里能验,改完必须 tauri dev / dmg 肉眼确认。
  • 后端端口硬编 8000:和 artifact_fetch.rs / port_preflight.rs 一样。后端若改动态端口,三处 一起改。
  • 桌面无 SSE → OfficeWatchViewerlastContentSseAt 恒为 0 → 每次 mtime 前进都会重载(这正是 桌面期望的行为,不是 bug)。
  • build() 不允许 panic:异步 scheme handler 里若 Response::builder().body() 返回 Err (上游 Content-Type 带非法头字节),旧代码 .expect() 会 panic;tokio 会静默吞掉该 task → responder.respond 永不调用 → webview 无超时地挂起、无可见错误。现在唯一由调用方控制的头 (Content-Type)先用 HeaderValue::from_str 预校验,失败退回 application/octet-stream,其余头是 静态常量、status 恒为合法 u16 → builder 必成功,.expect 永不触发。

Read the full file on GitHub · 61 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. 8d ago First seen · 61 lines · 0 tokens per session scan A 60d7fa0cf4fe

Subscribe to this mod's changes

office_watch_scheme.rs is a command published in the GitHub repository NetMindAI-Open/NarraNexus (86 stars, last pushed today), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,221 tokens. 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.