Flavor Development
MFW is the general engine for running MaaFramework projects. If a project already has an interface.json and you only need to run and configure its tasks in AUTO-MAS, just use the MFW project guide. You only need to build a "flavor" (called flavor in code) when a project really needs its own managed type, wording, or a few pre-run rules.
This page is the how-to guide: follow the steps to build a flavor. For why flavors are designed this way, the full set of hooks and contracts, and the item-by-item notes on M9A and MSS, see the design page Flavor; for the overall MFW design, see MFW Design Overview.
M9A and MSS are the existing examples: they reuse MFW's project import, runtime environment, updates, task execution, notifications, and periodic tasks, and each declares only its project identification rule and project-specific behavior. Before you start, read the main repository's app/task/MaaFW/AGENTS.md and the MaaFWFlavor contract (its module docstring holds the contracts of all optional hooks).
First Decide Whether You Need a Flavor
| Need | Where it goes |
|---|---|
| The project's existing tasks, controllers, resources, and options | The project's interface.json; MFW reads it directly |
| A capability every MaaFramework project needs | The MFW general engine |
| A single project's own identity, hints, pre-run task orchestration, pre-run login, a few unique forms | Flavor config and hooks |
| A native editor session, a dedicated UI organized around game semantics | An adapter, not a flavor |
| How in-game tasks run and how task results are judged | The project itself; AUTO-MAS does not rewrite project logic |
If what you are integrating is not a MaaFramework project but a script tool with its own way of running, see Standalone Adapters.
A flavor is a managed type inside the main program, not a plugin shipped in the project's release package. After an ordinary MFW managed script imports a project claimed by a flavor, it switches in place to that type; it is re-identified when you switch to another project. The managed script ID stays the same, but the project-related task queue needs to be rechecked.
No specific flavor's name may appear in app/task/MaaFW/; all of a flavor's logic enters only through the FLAVOR hook.
Step 1: Backend Config Classes and Registration
The following uses a new flavor X as the example. M9A and MSS both appear in these places; the consequence of missing each one is noted under it.
In
app/models/config/script.py, right next toMSSConfig, createXUserConfig(MaaFWUserConfig)andXConfig(MaaFWConfig). The class attributesDEFAULT_SCRIPT_NAME,USER_CONFIG_CLASS, andFLAVORare required. KeepFLAVORa string so the config model does not load the task module directly at import time. When the account fields have no differences,XUserConfigcan be just a one-line docstring.pythonclass XUserConfig(MaaFWUserConfig): """X 账号配置。""" class XConfig(MaaFWConfig): """X 托管配置:MaaFW 的特调类型。""" DEFAULT_SCRIPT_NAME: ClassVar = "新 X 托管" USER_CONFIG_CLASS: ClassVar = XUserConfig FLAVOR: ClassVar = "app.task.X.flavor:FLAVOR" class InfoFields(MaaFWConfig.InfoFields): Name: str = Field( default_factory=lambda: "新 X 托管", description="MaaFW 托管名称" ) # 独立配置类型有意覆盖分组及集合,保留专项默认值与准确字段类型。 Info: InfoFields = Field( # pyright: ignore[reportIncompatibleVariableOverride] default_factory=InfoFields ) UserData: ConfigCollection[XUserConfig] = collection( # pyright: ignore[reportIncompatibleVariableOverride] XUserConfig )script.pyalready importsClassVar,Field,ConfigCollection, andcollection. The default ofInfo.Namemust be written as the same name asDEFAULT_SCRIPT_NAMEand the frontend descriptor'sdefaultScriptName.To change the default of a generic field, follow
M9AConfig: override that group in the subclass and inherit the other fields:Built-in per-task time limits: write both the class attribute
DEFAULT_TASK_TIME_LIMIT_OVERRIDES(a JSON string, task name → minutes) and thedefault_factoryofRun.TaskTimeLimitOverrides, using the same constant in both places. When a generic MFW managed script is swapped to this flavor by a project import, the class attribute's value is filled in only if the script'sRun.TaskTimeLimitOverridesis still empty. Put only tasks longer than the global default (Run.TaskTimeLimit, 45 minutes) here.python_X_TASK_TIME_LIMIT_OVERRIDES = '{"某个耗时任务": 60}' class XConfig(MaaFWConfig): # 下面这些合进上面的 XConfig,其余成员不变 DEFAULT_TASK_TIME_LIMIT_OVERRIDES: ClassVar = _X_TASK_TIME_LIMIT_OVERRIDES class RunFields(MaaFWConfig.RunFields): TaskTimeLimitOverrides: JsonDictString = Field( default_factory=lambda: _X_TASK_TIME_LIMIT_OVERRIDES, description="按任务名覆盖的单任务时限(分钟),值 0 表示该任务不限。", ) Run: RunFields = Field( # pyright: ignore[reportIncompatibleVariableOverride] default_factory=RunFields )Game startup wait time:
Game.WaitTimedefaults to 120 seconds generically, and M9A changed it to 15. The way: extendMaaFWConfig.GameFields, override onlyWaitTime, then override the group withGame: GameFields = Field(default_factory=GameFields).Config items unique to the flavor (M9A's
Run.LoginMode, MSS'sInfo.PlanModeon the account) are likewise added in the inherited groups.
At the end of the same file two more places need updating: add
"XUserConfig"and"XConfig"to__all__; and add one entry each to the type unionsScriptConfigTypeandUserConfigType.Register
"X": XConfiginCLASS_BOOKinapp/models/config/__init__.py. The key is the type name at creation and must also equal the hook object'stype_key. The engine picks the first flavor that claims a project in the registration order ofCLASS_BOOK, so placing a new type before or after another is meaningful.In
TYPE_BOOKinapp/utils/common/constants.py, add"XConfig": "X"(M9A also registeredM9AUserConfig). The managed script dropdown gets type names from it (get_script_comboxinapp/core/config/manager.py); a missing entry raisesKeyErrorwhen fetching the dropdown.In
app/task/MaaFW/registration.py: importXConfigfromapp.models.configand add it torun_typesofScriptRegistration. The host matches the run index by exact type, and subclasses do not inherit the parent's registration automatically; if missed, the host raisesValueError("adapter capability missing: XConfig") when building the adapter registration. Theisinstance(…, MaaFWConfig)branch inapp/core/config/manager.pyalready covers subclasses; do not add a flavor branch.Fill in the API request and response types. The places to change are the ones below;
app/models/schema.pyneed not be touched:app/api/scripts/management.py:- config payload and input aliases:
XConfig = ConfigPayload[_config_models.XConfig],XConfigInput = ConfigInput[_config_models.XConfig]; - add the class name
"XConfig"to the enum ofScriptIndexItem.type; - add
"X"to the enum ofScriptCreateIn.type, and also complete the type list indescription; - union types: add
XConfigtoScriptCreateOut.dataandScriptGetOut.data, andXConfigInputtoScriptUpdateIn.data.
- config payload and input aliases:
app/api/scripts/users.py(account side):- the aliases
XUserConfigandXUserConfigInput; - add
"XUserConfig"to the enum ofUserIndexItem.type; - union types: add
XUserConfigtoUserGetOut.dataandUserCreateOut.data, andXUserConfigInputtoUserUpdateIn.data.
- the aliases
Optional: add the new class to the return type annotations of
add_scriptandadd_userinapp/core/config/manager.py(annotations only); if the flavor's game has game calendar reminders, add"X": "<game key in the calendar>"toSCRIPT_CALENDAR_GAMESinapp/core/game_calendar.py.After the backend changes, start the dev backend and regenerate the frontend API (see "Wrap-up" below); do not hand-edit
frontend/src/api/.
Step 2: The Backend Hook Object
Export a FLAVOR object from app/task/X/flavor.py. It must at least satisfy the MaaFWFlavor protocol: a type_key, a matches_project(interface_model), and a decorate_selection(...). Minimal example:
from __future__ import annotations
from typing import Any
from app.task.MaaFW.tools.core.interface.models import MaaFWInterface
from app.task.MaaFW.tools.embedded.flavor_support import MaaFWSelectionContext
class XFlavor:
type_key = "X"
def matches_project(self, interface_model: MaaFWInterface) -> bool:
return str(interface_model.mirrorchyan_rid or "").strip().casefold() == "x"
def decorate_selection(
self,
interface_model: MaaFWInterface,
task_ids: list[str],
task_options: dict[str, Any],
*,
context: MaaFWSelectionContext,
) -> tuple[list[str], dict[str, Any]]:
return list(task_ids), dict(task_options)
FLAVOR = XFlavor()matches_projectidentifies the identity only from the project'sinterface.json. Prefer a stable project identifier, such asmirrorchyan_ridor the repository address; the name is suitable as a compatibility criterion. The criterion must not mistake other projects for yours. An exception only warns and does not block the import.decorate_selectionreceives the already-selected task instance IDs and options before the run plan is generated, and returns a new(task_ids, task_options). It can insert, remove, or reorder project-specific tasks, or adjust options according to the account config; do not redo the generic flows such as updates, retries, timeouts, or game start/stop here.It is called once per account when the run plan is built, and not again on retries. The list passed in has already dropped unselectable tasks and instances not on a run day today; an instance the hook adds back itself runs as usual.
The last parameter of the signature is the read-only
context(MaaFWSelectionContext, inflavor_support.py), and there are no other keyword parameters besides it:Field Content context.script_configThe script (managed) config context.user_configThe account config for this run; read account fields such as Info.Accountfrom herecontext.resource_nameThe resource actually in effect at run time. The engine has already fallen back by controller when the script resource is empty; do not work it out again yourself context.excluded_task_idsInstance IDs the engine decided not to run this round ( frozenset): those the user set to red light, and those not on a run day todaycontext.logWrites one line to the account run log; the hook runs in a worker thread, and this callback can be called directly When a hook reads the account config separately to add tasks automatically, do not add back instances in
excluded_task_ids, and do not parse the snapshot yourself to judge red lights or weekdays. When the core builds the plan it also filters the decorated result by red light again, so a red-light instance added back still does not run.A task instance ID does not necessarily equal the task name (when the same task is queued repeatedly it is
<task name>__MAS_DUP__<suffix>). Resolve it withresolve_task_instance_name(app.task.MaaFW.tools.core.interface.models); find tasks by the interface task'sentry, not by task name.task_name_for_entry(interface_model, entry)inflavor_support.pyreturns the name of the first task with the sameentry, orNoneif not found.Return new lists and dicts; do not modify the passed-in objects. When the project lacks an expected task or option, write one readable log line with
context.logand skip.It runs in a worker thread, with no event loop.
Raising an exception means building the run plan for this account fails this time: the account is recorded as "exception", an error notice is sent, it does not run and is not retried, and other accounts proceed as usual; the original exception text is shown to the user after "unable to build the MaaFW run plan" (「无法构建 MaaFW 运行计划」). Do this only when it truly cannot run, and make the message directly presentable to the user.
How to add a project-specific task:
from __future__ import annotations
from typing import Any
from app.task.MaaFW.tools.core.interface.models import MaaFWInterface
from app.task.MaaFW.tools.embedded.flavor_support import (
MaaFWSelectionContext,
task_name_for_entry,
)
DAILY_ENTRY = "X_Daily"
class XFlavor:
type_key = "X"
def matches_project(self, interface_model: MaaFWInterface) -> bool:
return str(interface_model.mirrorchyan_rid or "").strip().casefold() == "x"
def decorate_selection(
self,
interface_model: MaaFWInterface,
task_ids: list[str],
task_options: dict[str, Any],
*,
context: MaaFWSelectionContext,
) -> tuple[list[str], dict[str, Any]]:
ids = list(task_ids)
options = dict(task_options)
daily = task_name_for_entry(interface_model, DAILY_ENTRY)
if daily is None:
context.log(f"[X] interface 里没有 entry 为 {DAILY_ENTRY} 的任务,未自动加入")
elif daily not in ids and daily not in context.excluded_task_ids:
ids.append(daily)
return ids, options
FLAVOR = XFlavor()Optional Hooks and Declarations
Implement them only when needed. They are all probed with getattr, and must not be added to the MaaFWFlavor protocol: the protocol is runtime_checkable, and once they are added, a flavor that does not implement them would fall back to generic MFW entirely.
| Name | Purpose |
|---|---|
sanitize_task_snapshot(...) | Tidies tasks the flavor takes over before the account task snapshot is saved, and can also write account Info fields. Called only when the project can be read and the write includes Task.TaskSnapshot; at run time, old snapshots should still be handled by the same rule. M9A's managed tasks are the reference implementation |
async ensure_game_updated(...) | Implement only when you need to check the game client version. Called only with ADB control and game updates enabled on the managed script, after the emulator starts and before the first task; returns app.utils.common.game_update.GameUpdateResult (fields status, message, resource_version; status is one of Skipped / UpToDate / Updated / NeedManualUpdate). Updating the project's release package is still managed by the generic MFW flow; these two "updates" are not the same thing |
async ensure_logged_in(...) | Pre-run login; see "Pre-run login" below |
abort_round_entries = {entry: explanation} | Critical tasks: if one fails or times out the round ends (retried as usual) |
nonfatal_entries = {entry: explanation} | Wrap-up tasks: if one fails, times out, or is forcibly stopped, it does not count as a round failure and is not retried |
skip_on_retry_entries = frozenset({entry, ...}) | On retry, these tasks that already completed in this run are not rerun. List only tasks where a rerun is pure waste and that do not depend on earlier steps of this round; write them one by one, and new tasks are rerun as before by default |
unselectable_entries = {entry: reason} | Unselectable tasks: the account page does not let them be selected, and at run time they are dropped and one line is logged. For tasks MAS cannot run unattended |
no_default_fallback_inputs = frozenset({(option name, field name), ...}) | When a string input is not filled in, the engine by default falls back to the default in the interface; fields listed here do not fall back and send an empty string if unfilled. Use it for fields whose default is a literal placeholder left by the project that would cause an error if sent (the "占位" of M9A's custom redeem code). /maafw/preview blanks the default of these fields so the account page does not show it as the value for "not filled". Do not list a default that works |
retype_notice_lines(*, entering, has_users) -> list[str] | The explanation lines appended under the system notice "identified by project as …" when a script is swapped to / away from this flavor after a project import. Called once with entering=True for swapping in and once with entering=False for swapping out; has_users is whether the script has accounts right now, and do not return lines that only apply to existing accounts when there are none |
For signatures, call timing, and precedence, see the module docstring of flavor.py; for the design notes, see Flavor.
Pre-run Login: ensure_logged_in
Implement it only when the game must be logged in by MAS before tasks start. It is called with an ADB controller, after MAS starts the emulator (which also brings up the game) and before the first task is dispatched, right after ensure_game_updated, and is awaited in the event loop. Whether to actually do anything is up to the hook, according to config; if it does nothing, return an empty string.
from collections.abc import Awaitable, Callable
from typing import Any
from app.task.MaaFW.tools.embedded.flavor import MaaFWLoginRequired, StartupTask
class XFlavor:
# 其余成员同上
async def ensure_logged_in(
self,
*,
script_config: Any,
user_config: Any,
resource_name: str | None,
package_name: str | None,
adb_path: str | None,
adb_address: str,
progress: Callable[[str], Awaitable[None]] | None,
host_adb: Any = None,
) -> str | StartupTask:
if not adb_address:
raise MaaFWLoginRequired("这种登录方式只支持 ADB 控制器")
# ……截图、识别、点击,完成登录
return "X 登录完成"- Parameters:
user_config.Info.Accountis the account field;package_nameis the package name brought up with the emulator this time (an empty string means it was not brought up, and the hook may start it by package name itself); whenhost_adbis non-empty, screenshots and commands must go through this private channel, otherwise connect withadb_path;progressis an async callback that writes the user run log. A Win32 controller calls it with an emptyadb_address, and the hook uses this to reject unsupported login modes. - Return value: a string is written to the run log, and an empty string is not. Completion is recorded only after a successful login; on failure the next attempt calls it again, and after a retry closes the game / emulator it is verified again too.
- Failure: raise
MaaFWLoginRequired, whose message is shown directly to the user. This account's attempt is judged failed and goes through the normal failure retry; raising any other exception is treated as a failure as well, and the engine wraps it inMaaFWLoginRequiredwith the message "pre-run login error: <original exception text>" (「运行前登录出错:<异常原文>」). - Cancellation: the
CancelledErrorraised when the user stops must propagate as usual and must not be swallowed. - When the project has to start the game after account selection, return
StartupTask(deadline, entry)instead of a string:deadlineis an absolutetime.monotonic()instant (the end of the remaining login time limit), andentryis the entry of the first public startup task (M9A returnsStartupTask(deadline, "StartUp")). Requirements:- The entry of the first task in the run plan must equal it, otherwise this attempt is judged failed (so
decorate_selectionhas to put this task at the front); - The full plan is still executed by one worker, and the first task's per-task time limit is tightened to within the remaining login time limit; if the first task fails the round ends, with no post-start verification;
- When a
StartupTaskis returned, the engine writes no log text and does not yet record "logged in"; it records logged in only when the first startup task appears among the completed tasks reported by the worker.
- The entry of the first task in the run plan must equal it, otherwise this attempt is judged failed (so
Step 3: The Frontend Descriptor Object
The managed page, account page, create flow, and routes all reuse MFW's shared pages. A new flavor writes just one descriptor object. The order below matches the list in the header of frontend/src/composables/useMaaFWFlavor.ts; the item there about the "词表 zh-CN.ts" (string table zh-CN.ts) is out of date, and strings follow the backend's res/i18n (see "Wrap-up").
- After the backend is written and OpenAPI is regenerated,
ScriptTypeautomatically gains'X': it is derived from the generated API's create type (frontend/src/types/script.ts), so there is no separate copy to keep. The icon and display name inscriptLogos.tsare derived fromSCRIPT_METADATAin the next item, and the config class name inuseScriptApi.tscomes from the flavor registry; none of these need manual changes. - Add an
Xentry toSCRIPT_METADATAinfrontend/src/utils/scriptMetadata.ts(that table issatisfies Record<ScriptType, ScriptMetadata>, and typecheck fails if you miss it):logo(put the image infrontend/src/assets/and import it at the top),label,typeTagColor,routeSuffix,routeTitles(script/userAdd/userEdit),createOrder, andcreate(titleKey,descriptionKey,keywordsfor search,group). - Add
'X'toMaaFWFlavorTypeinfrontend/src/composables/maafwFlavorTypes.ts. - Create the directory
frontend/src/views/EditView/MaaFWFlavor/x/, and export the descriptor objectX_FLAVORinindex.tswithdefineMaaFWFlavor. Write only what differs from MFW: identity fields,routes.suffix, andcreate.cardare required; for string keys write only the ones you replace; if there is no unique block, do not writeslots. - Register it in
FLAVOR_REGISTRYinfrontend/src/composables/useMaaFWFlavor.ts(typecheck fails if missed) and import it at the top of the file. - For the help link
docUrl, useMAS_DOC_URLSinfrontend/src/utils/openExternal.ts: the generic one isMAS_DOC_URLS.scripts; for one with a dedicated doc page, add an entry toMAS_DOC_URLS.scriptTypes(M9A does this). - When the flavor has unique fields on the script or account config and frontend components need to read and write them, add the fields as optional items to
MaaFWScriptConfig/MaaFWUserConfiginfrontend/src/types/script.ts(such asRun.LoginMode?,Info.PlanMode?). - Add strings; see "Wrap-up" below.
Minimal example (written like mss/index.ts: first take SCRIPT_METADATA.X, then use metadata.label and so on):
import { MAS_DOC_URLS } from '@/utils/openExternal'
import { SCRIPT_METADATA } from '@/utils/scriptMetadata'
import { defineMaaFWFlavor } from '../defineFlavor'
const metadata = SCRIPT_METADATA.X
export const X_FLAVOR = defineMaaFWFlavor({
type: 'X',
scriptConfigType: 'XConfig',
userConfigType: 'XUserConfig',
defaultScriptName: '新 X 托管',
typeTagLabel: metadata.label,
typeTagColor: metadata.typeTagColor,
logo: metadata.logo,
docUrl: MAS_DOC_URLS.scripts,
routes: { suffix: metadata.routeSuffix, titles: metadata.routeTitles },
create: {
card: {
...metadata.create,
after: null,
},
},
})create.card.after is the type after which this card is placed in the create dialog; null puts it last (M9A uses 'MaaEnd').
Routes need no changes: frontend/src/router/maafwFlavorRoutes.ts generates four routes for each type from the registry (managed-script edit, project onboarding, add account, edit account), and the page host picks the page by the managed script's actual type.
What You Can Write in a Descriptor Object
First, which fields are merged as "differences". scriptPage.text, userPage.text, and userPage.managed are shallow-merged by field onto MFW's defaults: omit to inherit MFW, write null to explicitly turn off (only fields marked nullable can take null). page, sections, slots, and prepare (including create.sections / create.slots) are not inherited, and omitting them means none.
scriptPage.text (all values are string keys):
| Field | Purpose | MFW default |
|---|---|---|
titleKey | The script edit page title; nullable, and when null it is "<project name> project config". The onboarding form is always "<project name> project onboarding" | null |
sourceDirectoryKey | The label of the project directory field | core.edit.localProjectDirectory |
sourceHintKey | The question-mark tooltip on the project directory label (after import the field is locked, and the tooltip changes to the uniform "already imported" line) | core.edit.pickMfwProjectDirectory |
sourcePlaceholderKey | The placeholder of the project directory input | core.edit.pickActualMfwProject |
M9A and MSS change only sourceHintKey, to name the project in the directory tooltip.
userPage.text:
| Field | Purpose | MFW default |
|---|---|---|
accountPlaceholderKey | The placeholder of the account field. If the account has another use, state its purpose | core.edit.localNoteOnly |
accountTooltipKey | The question-mark tooltip on the account label; nullable, and when null no question mark is attached | null |
queueHintKey | The hint at the top of the task queue area, with \n for line breaks, one box per line; nullable, and when null nothing is shown | null |
userPage.managed: write it only when the flavor puts some tasks under the backend's full control (managed tasks); with none, the MFW empty value is inherited. The fields must be the same set of entries as the backend's tidying rules.
| Field | Purpose | MFW default |
|---|---|---|
entries | Tasks users may not add themselves (the interface tasks' entry): they appear neither in the account page's "Add task" nor in preset templates; ones already in the queue are shown as usual (visible and deletable) | [] |
accountTask | The managed account-switch task { entry, resources }: when the resource is in resources and the number of its effective instances in the queue (with a non-empty target account) is ≥ 2, the backend refuses to run the account and asks to split it into several accounts. Nullable | null |
warningKey | The warning string for when accounts need splitting, interpolating count (the number) and accounts (each target account); nullable | null |
noticeKey | The hint string for when other managed tasks remain in the queue, interpolating tasks (task names), and the run proceeds as usual; nullable | null |
For how M9A writes it, see m9a/index.ts: entries: ['StartUp', 'SwitchAccount', 'Close1999'], accountTask: { entry: 'SwitchAccount', resources: ['官服'] }.
prepare (scriptPage.prepare / userPage.prepare): async () => { ... }, called in parallel with other reads while the page loads, used to prefetch data for unique blocks so they do not appear empty and then pop in. Do not throw failures outward; handle them yourself. scriptPage.prepare is called after the script details are read, and called again when the type becomes this flavor after an import; userPage.prepare runs in parallel with reading the interface. The create flow has no prepare. Put the data-fetching logic in an on-demand module; the registry is imported by the script list, routes, and other places, so do not bring in API dependencies. How MSS writes it:
prepare: async () => {
const { loadMSSPlanComboxItems } = await import('./planModeOptions')
await loadMSSPlanComboxItems()
},When You Need a Unique UI
From shallow to deep; use the shallower one when it will do:
Slots: write
defineMaaFWLazyComponent(() => import('./XField.vue'))intoscriptPage.slots/userPage.slots/create.slots; the value is an array of components, rendered in order. A component receives the context as acontextprop, and hands changes back according to the page type: the script page emitschange(category, key, value), the account page emitssave(key, value), and the create flow's slots are read-only. The existing slots:- Managed page:
afterBasicInfo,beforeControl,besidePackageName,afterControl,afterUpdate,afterRun; - Account page:
afterBasicInfo,beforeTaskQueue,afterTaskQueue(none go inside the two columns of the task queue); - Create flow:
afterSourceStep(read-only).
besidePackageNameis special: it is not a place the page puts directly, but a scoped slot of the same name provided by the control method section (control). Under ADB it comes after "game package name" and "wait time" and before the screenshot / input strategy table, one cell per component. The page forwards cell by cell according to the number of registered components. So when you only use slots you need not care; when replacing thecontrolsection, you must keep this slot in the new section yourself (forward once per cell bybesidePackageNameCount, passing{ index }), otherwise these components will not show.An account page slot component example (written like
mss/MSSPlanModeField.vue):vue<!-- eslint-disable vue/no-mutating-props -- Slot components edit the parent-owned reactive draft; persistence stays in the parent. --> <template> <a-form-item label="X 选项"> <a-select v-model:value="context.formData.Info.Notes" :options="options" :disabled="context.loading" @change="emit('save', 'Info.Notes', context.formData.Info.Notes)" /> </a-form-item> </template> <script setup lang="ts"> import type { MaaFWUserSlotContext } from '@/composables/maafwFlavorTypes' defineProps<{ context: MaaFWUserSlotContext }>() const emit = defineEmits<{ save: [key: string, value: unknown] }>() const options = [ { label: '甲', value: 'a' }, { label: '乙', value: 'b' }, ] </script>The example uses
Info.Notesas the field being saved; in real use, swap in the field you added intypes/script.ts. Theeslint-disable vue/no-mutating-propsline at the top of the file cannot be omitted; every existing slot component is written that way: the config draft is owned by the page, the component edits the draft directly, and persistence is done by the page. For example, MSS puts the plan table dropdown and the event-first switch inuserPage.slots.beforeTaskQueue, and M9A puts the "Login mode" and "Game update" dropdowns inscriptPage.slots.besidePackageName(M9ALoginModeField.vue,M9AGameUpdateField.vue).- Managed page:
Section replacement: write
defineMaaFWSection(part, key, load)intosections. The replacement component must accept the props of that section inMaaFWFlavor/sectionContracts.ts(typecheck fails if it cannot) and emit events per that section's…Emits(or pass$attrsthrough to the MFW section it wraps), otherwise changes will not be saved.Whole-page replacement:
scriptPage.page/userPage.page, assembled from the sections and orchestration layer exported byviews/EditView/Script/MaaFWScriptEdit/pageKit.tsandviews/EditView/User/MaaFWUserEdit/pageKit.ts; do not copy the MFW page.
If you need a slot that does not exist yet: add the name to MaaFWFlavorSlotContextMap in maafwFlavorTypes.ts, and place <MaaFWFlavorSlot> at the corresponding spot in the shared page. Do not write type === 'X' branches in shared pages, and do not add boolean switches to the descriptor object; neither has an automated check, and both rely on review.
When You Need a Plan Table (MSS as the Example)
When a flavor needs accounts to reference a plan table that gives a different configuration by weekday or rotation day, beyond the steps above you must do the following extra steps. Each one has matching code in MSS.
Backend:
- Add a reference field to the account config and let it reach the plan table collection. How
MSSUserConfigwrites it (script.py): the class attributerelated_config: ClassVar = {}, andInfo.PlanModeusesref("PlanConfig", default="Fixed", allow_values=("Fixed",), entry_types=(MSSPlanConfig,), display_field="Info.Name"), with default"Fixed".related_configis filled in from a list byapp/core/config/manager.pyat initialization, and account config classes are not inCLASS_BOOK, so you must also addXUserConfigto the tuple there that listsMSSUserConfigandBAAHUserConfig, and import it fromapp.models.configat the top ofmanager.py. - The plan table config class: create
XPlanConfiginapp/models/config/plan.py(MSS extendsWeeklyKeyPlan), with each date slot storing one key model. The key modelXPlanKeyis written inapp/models/schema.py(takeMSSPlanKeyas the example,extra="forbid"), the legacy data normalization function is written inapp/models/config/shared.py(normalize_mss_plan_key), and it is called inXPlanConfig.normalize_payload. Inplan.py, add the new class to__all__and thePlanConfigTypeunion. - Register in
PLAN_BOOKinapp/models/config/__init__.py, with the plan table class name as key:create_type(the type name used at creation, such as"MSSPlan"),config_class,consumer(takePLAN_CONSUMER_VALUES[index]),script_class(the managed classXConfig), andfield_groupandfield_name(the field on the account that references the plan table, such as"Info","PlanMode"). When a plan table is deleted, the manager uses the last three to find the accounts that reference it (first filter managed scripts byscript_class, then compare this field on the accounts) and sets the reference back to"Fixed"(the plan-delete logic inapp/core/config/manager.py), so the reference field on the account must have"Fixed"as a value. - In
PLAN_CONSUMER_VALUESinapp/utils/common/constants.py, only append new consumers at the end:PLAN_BOOKreferences it by index, and inserting in the middle would point existing plan table types at other consumers (the constant's docstring says so;"mss"sits after"baah", which is how the index came about). - Add the same string to
PlanComboxConsumer(aLiteral) inapp/models/schema.py; the plan dropdown endpoint (app/api/info.py) validates against it. - In
app/api/plan.py: add theXPlanConfig/XPlanConfigInputaliases,PlanCreateType(aLiteral), and the union typesPlanConfigDataandPlanConfigDataInput. The type enums of the plan table index and create endpoints are generated fromPLAN_BOOKautomatically and need no hand-writing. - Get the day's slot in the flavor hook:
type(user_config).related_config["PlanConfig"][uuid.UUID(mode)], then call the plan table'sget_current_key()(see_current_plan_keyinapp/task/MSS/flavor.py). When the referenced plan table has been deleted or has the wrong type, treat it as "Fixed" and write a log line.
Frontend:
frontend/src/utils/planTypeRegistry.ts: addX: PlanIndexItem.type.…toPLAN_CONFIG_TYPES(the enum name is generated by OpenAPI), and add a description toPLAN_TYPE_REGISTRY:configType,createType,displayNameKey,defaultName(it is written into the plan name and used to judge "still the default name", so keep it in Chinese),selectorTag,reloadAfterSave,supportsSimpleView,tableComponent.- The plan table component
frontend/src/views/plan/tables/XPlanTable.vue, with propstableData,currentMode,viewMode,planId, andhandlePlanChange; write it likeMSSPlanTable.vue. - The plan table dropdown on the account page: a unique-block slot +
userPage.prepareprefetch. Options come fromService.getPlanComboxApiInfoComboxPlanPost({ consumer: PlanComboxIn.consumer.X })(seemss/planModeOptions.ts), and the first item is always "Fixed" (valueFixed). - The string
core.plan.type.x(see "Wrap-up" below).
Wrap-up
- Add strings. Strings are in the backend resources
res/i18n/zh_CN.json,en.json, andja.json, as flat dotted keys. Chinese is the source language and must be added;en.jsonandja.jsonmay lack keys, and M9A and MSS filled in all three, so do likewise:core.scripts.type.X: the type name;core.scripts.create.typeDesc.X: the type description in the create dialog;- the string keys used in the descriptor object and slot components (such as
core.edit.xFlavorSourceHint); - for those with a plan table, also
core.plan.type.x.
- Regenerate OpenAPI. First start the dev backend of the target worktree (the
openapiscript infrontend/package.jsonfetches the schema fromhttp://127.0.0.1:36164/openapi.json, so the backend must listen on this port), then runcorepack yarn openapifrom that worktree'sfrontenddirectory. After generation this script runsscripts/postprocess-openapi.mjs, which normalizes the generated files' CRLF line endings to LF; do not hand-editfrontend/src/api/.
Checklist
Check each item before committing:
- [ ] Import once with the target project and once with an ordinary MaaFramework project; the type switches correctly and there is no false claim.
- [ ] No flavor name appears in
app/task/MaaFW/; there are no type branches in shared frontend pages; there are no booleans in the descriptor object. - [ ]
decorate_selectionhandles duplicate task instances, an empty queue, missing tasks or options, and a queue saved after user edits; auto-added tasks do not add back instances inexcluded_task_ids; if there is a snapshot-tidying hook, the result after restoring config was also checked. - [ ] The tasks the flavor takes over (if any) are the same set of entries in the backend tidying rules and the frontend descriptor object.
- [ ] Newly added optional hooks were not added to the
MaaFWFlavorprotocol. - [ ] All registration places in Step 1 are filled in:
script.py(including__all__and the type unions),CLASS_BOOK,TYPE_BOOK,run_typesinregistration.py,management.py, andusers.py. - [ ] The flavor-specific run order or options were verified, and it was confirmed that MFW's generic running, project updates, and account config still work.
- [ ] In the target worktree, with its local dependencies,
tests/task/test_maafw_core.pyand the related backend checks were run, along with the frontendtypecheck,lint, and related tests; the commands actually run and their results were recorded. If the schema changed, OpenAPI was regenerated from that worktree's dev backend.
Read-only references: M9A flavor, MSS flavor, frontend flavor directory.