创造模式实战
mayfly-cordis preset 可以用动态 Cordis tool 在当前进程热挂载原型。原型仍是 普通 Cordis plugin,直接访问当前 service graph。
流程:
cordis_inspect_list列出当前 service/event/tool provider。- 查询计划使用的精确 method schema。
cordis_define定义带name / inject / apply(ctx)的 host package。cordis_run激活;修改时定义新 immutable package 并update。cordis_stop暂停,cordis_undefine删除。- 用户接受后,再询问 local/GitHub/npm/ephemeral,不能擅自持久化。
js
return {
name: 'health-probe',
inject: ['commands', 'mayflyOverlays'],
apply(ctx) {
ctx.commands.register({
name: 'health-probe',
description: 'Open health',
handler() {
ctx.mayflyOverlays.open({
id: 'probe.health',
capturing: true,
}, { kind: 'text', content: 'healthy' })
return { kind: 'success', text: 'opened health' }
},
})
},
}Dynamic code.host 是普通 JavaScript function body,不能 import/require 或 写 TypeScript。原型在 restart 后消失。持久化时使用普通 package.json、 compiled entry 与 cordis.patch.yml。