Skip to content

feat(frontend): add admin UI for Lua MRF policies#36

Merged
PrivateGER merged 3 commits into
developfrom
feat/mrf-admin-ui
Jul 3, 2026
Merged

feat(frontend): add admin UI for Lua MRF policies#36
PrivateGER merged 3 commits into
developfrom
feat/mrf-admin-ui

Conversation

@PrivateGER

@PrivateGER PrivateGER commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added a new admin area for managing MRF policies, including viewing, creating, editing, testing, and deleting policies.
    • Added moderation log labels for MRF policy actions and several additional content/account lifecycle events.
    • Expanded English and Japanese interface text for the new policy management screens.
  • Bug Fixes
    • Improved policy testing so incompatible parameters are handled more gracefully and test results show clearer decision details.

Adds an admin page (/admin/mrf-policies) to manage DB-backed Lua MRF
policies: list with enable/priority/built-in status, per-policy editor
with a Lua code editor (MkCodeEditor), dynamic params form driven by the
policy's paramsSchema, scope editing, warnings, and a dry-run test panel
wired to admin/mrf-policies/test.

Built-in policies restrict edits to enabled/priority/params (matching the
update endpoint guard). On source change the client omits stale params and
reseeds from the returned policy; the dry-run test endpoint now filters
incompatible params instead of hard-failing so live editing converges.

Also describes the test endpoint's decision in its response schema and
regenerates misskey-js types and locale typings.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PrivateGER, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5adabf3a-0527-4642-98c4-3830acd72864

📥 Commits

Reviewing files that changed from the base of the PR and between 0292eb6 and be67124.

📒 Files selected for processing (3)
  • packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts
  • packages/frontend/src/pages/admin/mrf-policies.policy.vue
  • packages/frontend/src/pages/admin/mrf-policies.vue

Walkthrough

Adds an MRF (Message Rewrite Facility) policy management feature: new admin frontend pages for listing/editing/testing/creating/deleting policies, router and menu entries, a backend endpoint change replacing strict param validation with param filtering, generated misskey-js API types for new endpoints, and corresponding locale strings.

Changes

MRF Policies feature

Layer / File(s) Summary
Backend test endpoint param filtering
packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts
Removes invalidParams error, expands the decision response schema, and replaces strict param validation with filterCompatibleParams to drop incompatible params during dry-run tests.
Admin MRF policy list and editor pages
packages/frontend/src/pages/admin/mrf-policies.vue, packages/frontend/src/pages/admin/mrf-policies.policy.vue, packages/frontend/src/pages/admin/index.vue, packages/frontend/src/router.definition.ts
Adds a policy list page and an XPolicy editor component supporting save/delete/run-test flows, adds a router entry at /mrf-policies, and adds an admin menu item.
Generated misskey-js API types
packages/misskey-js/src/autogen/*, packages/misskey-js/etc/misskey-js.api.md
Adds request/response types, Endpoints mappings, APIClient.request overloads, and OpenAPI path/schema typings for admin/mrf-policies/*, admin/antennas/global, drive/files/generate-alt-text, and top-posts, plus minor permission metadata and AchievementName/useGlobalRelay schema additions.
Locale updates
locales/en-US.yml, locales/index.d.ts, sharkey-locales/en-US.yml
Adds mrfPolicies/_mrfPolicies strings and moderation-log labels for MRF policy lifecycle events plus other moderation-log entries.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant XPolicy
  participant API
  participant LuaRuntime
  User->>XPolicy: edit draft, click Run Test
  XPolicy->>API: admin/mrf-policies/test (source, activity, params)
  API->>API: filterCompatibleParams
  API->>LuaRuntime: execute policy
  LuaRuntime-->>API: decision, warnings
  API-->>XPolicy: testResult, paramsSchema
  XPolicy->>XPolicy: pruneParams, refresh currentSchema
  User->>XPolicy: click Save
  XPolicy->>API: admin/mrf-policies/update
  API-->>XPolicy: updated policy
  XPolicy-->>User: emit updated event
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing the required template sections and contains no What, Why, Additional info, or Checklist content. Add the template sections (What, Why, Additional info, Checklist) and fill them with a brief summary, motivation, and testing notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding an admin UI for MRF policies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mrf-admin-ui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts (1)

101-101: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant nullish coalescing.

ps.params already defaults to {} via paramDef.params.default: {}, so ps.params ?? {} is dead defensive code (AJV applies the default before the handler runs).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts` at line
101, The `filterCompatibleParams` call in the admin MRF policy test is doing
redundant fallback logic because `ps.params` is already defaulted by the schema.
Update the `mrfLuaPolicyService.filterCompatibleParams` usage to pass
`ps.params` directly and remove the unnecessary nullish coalescing, keeping the
change localized to the handler/test code where `paramsSchema` and `ps.params`
are used.
packages/frontend/src/pages/admin/mrf-policies.policy.vue (1)

73-76: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No guard against duplicate Save submissions.

runTest() disables its trigger button via testing while in flight (Line 109), but save() has no equivalent saving flag, so rapid double-clicks on Save can fire concurrent admin/mrf-policies/update requests.

♻️ Proposed fix
+const saving = ref(false);
+
 async function save() {
+	if (saving.value) return;
+	saving.value = true;
+	try {
 	const sourceChanged = !props.policy.isBuiltin && draft.source !== props.policy.source;
 	...
 	const updated = await os.apiWithDialog('admin/mrf-policies/update', patch);
 	applyPolicy(updated);
 	emit('updated', updated);
+	} finally {
+		saving.value = false;
+	}
 }
-		<MkButton primary inline `@click`="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
+		<MkButton primary inline :disabled="saving" `@click`="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue` around lines 73 -
76, The Save action in mrf-policies.policy.vue can be triggered multiple times
because save() has no in-flight guard like runTest() does with testing. Add a
saving state in the component, set it while the save request is running, and
bind the Save MkButton to that state so rapid clicks cannot fire concurrent
admin/mrf-policies/update requests. Update the save() method and the button in
the template to use the new saving flag, following the existing
runTest()/testing pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts`:
- Around line 99-101: The dry-run path in the admin MRF policy test flow
silently drops incompatible submitted params via
mrfLuaPolicyService.filterCompatibleParams, so add a warning when params are
removed. Update the logic around the paramsSchema/ps.params handling to detect
dropped keys and append a warning into the response’s warnings collection,
alongside metadata.warnings and result.warnings, so admins can see which
submitted values were ignored.

In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue`:
- Around line 168-176: The dynamic policy params in mrf-policies.policy.vue are
being submitted as raw strings for integer/number fields, unlike other numeric
inputs that are normalized with Number(...). Update the form handling around the
draft.params model so numeric entries are coerced to numbers before submission
in both the patch payload and runTest() test payload. Use the existing symbols
draft, patch.params, runTest(), and the paramsSchema-driven MkInput bindings to
locate the conversion point, and ensure only integer/number param types are
converted while non-numeric params remain unchanged.

In `@packages/frontend/src/pages/admin/mrf-policies.vue`:
- Around line 48-50: The refresh flow in refresh() can overwrite newer local
edits with a stale admin/mrf-policies/list response, so guard it with a request
token or abort/cancel mechanism and ignore outdated results. Make sure the
initial load in refresh() and the create/update/delete paths all consult the
same freshness state, or block mutations until the first load settles, so later
edits are not clobbered by an earlier in-flight request.

---

Nitpick comments:
In `@packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts`:
- Line 101: The `filterCompatibleParams` call in the admin MRF policy test is
doing redundant fallback logic because `ps.params` is already defaulted by the
schema. Update the `mrfLuaPolicyService.filterCompatibleParams` usage to pass
`ps.params` directly and remove the unnecessary nullish coalescing, keeping the
change localized to the handler/test code where `paramsSchema` and `ps.params`
are used.

In `@packages/frontend/src/pages/admin/mrf-policies.policy.vue`:
- Around line 73-76: The Save action in mrf-policies.policy.vue can be triggered
multiple times because save() has no in-flight guard like runTest() does with
testing. Add a saving state in the component, set it while the save request is
running, and bind the Save MkButton to that state so rapid clicks cannot fire
concurrent admin/mrf-policies/update requests. Update the save() method and the
button in the template to use the new saving flag, following the existing
runTest()/testing pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf61100e-7e26-4517-b59a-e5ad7a9ae12f

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed1d03 and 0292eb6.

📒 Files selected for processing (14)
  • locales/en-US.yml
  • locales/index.d.ts
  • packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts
  • packages/frontend/src/pages/admin/index.vue
  • packages/frontend/src/pages/admin/mrf-policies.policy.vue
  • packages/frontend/src/pages/admin/mrf-policies.vue
  • packages/frontend/src/router.definition.ts
  • packages/misskey-js/etc/misskey-js.api.md
  • packages/misskey-js/src/autogen/apiClientJSDoc.ts
  • packages/misskey-js/src/autogen/endpoint.ts
  • packages/misskey-js/src/autogen/entities.ts
  • packages/misskey-js/src/autogen/models.ts
  • packages/misskey-js/src/autogen/types.ts
  • sharkey-locales/en-US.yml
💤 Files with no reviewable changes (1)
  • locales/en-US.yml

Comment thread packages/backend/src/server/api/endpoints/admin/mrf-policies/test.ts Outdated
Comment thread packages/frontend/src/pages/admin/mrf-policies.policy.vue
Comment thread packages/frontend/src/pages/admin/mrf-policies.vue
The dry-run endpoint silently dropped submitted params that no longer
matched the policy's schema. Emit an incompatible_param_ignored warning
per dropped key so admins can tell the test didn't use their values.
Also drop the redundant 'ps.params ?? {}' fallback (the schema default
already applies).

Claude-Session: https://claude.ai/code/session_01NkWAnRDVKZc2Bgq6szruAj
- Coerce dynamic param values by schema type before submitting to
  update/test: numeric params through Number(), matching the explicit
  coercion convention used for priority/timeoutMs, and string_array
  params edited as comma-separated text (previously the raw array was
  bound to a text input and edits produced a string the server rejects).
- Guard save() with a saving flag and disable the Save button while a
  request is in flight, mirroring the runTest()/testing pattern.
- Guard the policy list against a stale in-flight initial load
  clobbering newer local state: refresh() only applies the latest
  request's response, mutations invalidate pending responses, and
  create() re-syncs from the server.

Claude-Session: https://claude.ai/code/session_01NkWAnRDVKZc2Bgq6szruAj
@PrivateGER PrivateGER force-pushed the feat/mrf-admin-ui branch from 7af3387 to be67124 Compare July 3, 2026 09:42
@PrivateGER PrivateGER merged commit c6813c1 into develop Jul 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant