@lark-apaas/coding-miaoda-sandbox-skills 0.1.57 → 0.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,8 +9,12 @@ Shadcn Form + React Hook Form + Zod 表单开发。
9
9
 
10
10
  ## Guidelines
11
11
 
12
- - 类型必须用 `z.infer` 推导,禁止手动定义
13
- - 所有字段必须有默认值
12
+ - 表单类型从 schema 推导:`z.input<typeof schema>` 用于 `defaultValues`、`reset`、控件和 `getValues`;`z.output<typeof schema>`(即 `z.infer`)用于默认 `raw: false` 的 resolver 解析后的 `handleSubmit` 回调。coerce、default、transform 不能假设输入输出相同。
13
+ - 输入输出相同时可用单泛型 `useForm<Input>`;不同时,单输入泛型可能通过类型检查,但提交回调的静态类型仍是较宽的输入类型,必须按输入安全处理。需要精确输出时用 `useForm<z.input<typeof schema>, unknown, z.output<typeof schema>>`,回调用 `SubmitHandler<z.output<typeof schema>>`。
14
+ - 初始化每个需要的控件值;schema 有 default 的可选输入可以省略,但 `reset` 仍接收输入类型。外部 `unknown` 不能直接 spread 到 DOM:先适配成控件接受的值。
15
+ - `z.coerce.number<number>()` 只适用于控件实际写入 number;泛型不改变运行时转换。下例将空值写成 NaN 以触发校验,而非让空串 coerce 为 0;只适用于无需保留编辑中间态的非负整数等输入。需要逐键保留小数、符号等中间态时,使用下方字符串兼容路径;旧 Zod 不支持该泛型时也用该路径,不强制升级。
16
+ - 需要 string→number transform 时,先确认实际 `FormField` 是否透传第三泛型;现有包装可能不支持,勿修改托管包装或把三库的支持等同于 UI 支持。可保持 schema、控件、reset 均为字符串,校验后在提交中逐字段转换(见下方兼容路径)。
17
+ - API 合同允许字段可选的查询、筛选、搜索表单,可直接提交与 API 合同匹配的解析输出。
14
18
  - 必须用 Shadcn 组件,禁止原生 input
15
19
  - 同行 FormField 必须等宽
16
20
  - 每个控件都要有能读出来的字段名(读屏和自动化验收都按它找控件):FormField 内用 `FormLabel` + `FormControl`,id 会自动关联;FormField 外的筛选、搜索控件用 `<Label htmlFor="x">` 配控件 `id="x"`,没有可见标签时加 `aria-label`。不要只靠 placeholder 或当前选中值表达字段含义
@@ -27,7 +31,7 @@ Shadcn Form + React Hook Form + Zod 表单开发。
27
31
 
28
32
  ```tsx
29
33
  import { zodResolver } from "@hookform/resolvers/zod";
30
- import { useForm } from "react-hook-form";
34
+ import { useForm, type SubmitHandler } from "react-hook-form";
31
35
  import { z } from "zod";
32
36
  import { Button } from "@/components/ui/button";
33
37
  import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
@@ -37,21 +41,36 @@ import { logger } from "@lark-apaas/client-toolkit/logger";
37
41
 
38
42
  const studentSchema = z.object({
39
43
  name: z.string().min(1, "姓名不能为空"),
40
- age: z.coerce.number().min(0, "年龄不能为负数"),
41
- grade: z.string().min(1, "请选择年级"),
44
+ age: z.coerce.number<number>().int().min(0, "年龄不能为负数").max(150, "年龄不能大于150"),
45
+ grade: z.string().optional().default("grade1"),
42
46
  });
43
47
 
44
- type StudentFormData = z.infer<typeof studentSchema>;
48
+ type StudentInput = z.input<typeof studentSchema>;
49
+ type StudentOutput = z.output<typeof studentSchema>;
50
+
51
+ interface CreateStudentRequest {
52
+ name: string;
53
+ age: number;
54
+ grade: string;
55
+ }
56
+
57
+ async function createStudent(payload: CreateStudentRequest) {
58
+ logger.info(payload);
59
+ }
45
60
 
46
61
  export function StudentForm() {
47
- const form = useForm<StudentFormData>({
62
+ const form = useForm<StudentInput, unknown, StudentOutput>({
48
63
  resolver: zodResolver(studentSchema),
49
- defaultValues: { name: "", age: 0, grade: "" },
64
+ defaultValues: { name: "", age: NaN },
50
65
  });
66
+ const onSubmit: SubmitHandler<StudentOutput> = async (data) => {
67
+ const payload: CreateStudentRequest = { name: data.name, age: data.age, grade: data.grade };
68
+ await createStudent(payload);
69
+ };
51
70
 
52
71
  return (
53
72
  <Form {...form}>
54
- <form onSubmit={form.handleSubmit((data) => logger.info(data))} className="space-y-6">
73
+ <form noValidate onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
55
74
  <div className="flex flex-wrap gap-4">
56
75
  <FormField control={form.control} name="name" render={({ field }) => (
57
76
  <FormItem className="flex-1">
@@ -63,16 +82,18 @@ export function StudentForm() {
63
82
  <FormField control={form.control} name="age" render={({ field }) => (
64
83
  <FormItem className="flex-1">
65
84
  <FormLabel>年龄 <span aria-hidden="true" className="text-destructive">*</span></FormLabel>
66
- <FormControl><Input type="number" {...field} /></FormControl>
85
+ <FormControl><Input {...field} type="number" min={0} max={150} step={1}
86
+ value={Number.isFinite(field.value) ? field.value : ""}
87
+ onChange={(event) => field.onChange(event.target.value === "" ? NaN : event.target.valueAsNumber)} /></FormControl>
67
88
  <FormMessage />
68
89
  </FormItem>
69
90
  )} />
70
91
  </div>
71
92
  <FormField control={form.control} name="grade" render={({ field }) => (
72
93
  <FormItem>
73
- <FormLabel>年级 <span aria-hidden="true" className="text-destructive">*</span></FormLabel>
74
- <Select onValueChange={field.onChange} defaultValue={field.value}>
75
- <FormControl><SelectTrigger><SelectValue placeholder="请选择" /></SelectTrigger></FormControl>
94
+ <FormLabel>年级</FormLabel>
95
+ <Select value={field.value ?? "grade1"} onValueChange={field.onChange}>
96
+ <FormControl><SelectTrigger onBlur={field.onBlur} ref={field.ref}><SelectValue placeholder="默认为一年级" /></SelectTrigger></FormControl>
76
97
  <SelectContent>
77
98
  <SelectItem value="grade1">一年级</SelectItem>
78
99
  <SelectItem value="grade2">二年级</SelectItem>
@@ -82,12 +103,41 @@ export function StudentForm() {
82
103
  </FormItem>
83
104
  )} />
84
105
  <Button type="submit">提交</Button>
106
+ <Button type="button" onClick={() => form.reset({ name: "", age: NaN })}>重置</Button>
85
107
  </form>
86
108
  </Form>
87
109
  );
88
110
  }
89
111
  ```
90
112
 
113
+ ### 字符串兼容路径
114
+
115
+ 按 Guidelines 的字符串兼容路径:用 string/refine 校验非空、有限值和业务范围。范围 0~24、步长 0.5 仅为示例,按业务调整;文本控件保留 `0.` 等中间态,步长在 schema 中校验。
116
+
117
+ ```tsx
118
+ const amountSchema = z.object({
119
+ amount: z.string().refine((text) => {
120
+ const n = Number(text);
121
+ return text.trim() !== "" && Number.isFinite(n) && n >= 0 && n <= 24 && Number.isInteger(n * 2);
122
+ }, "请输入 0~24 内步长为 0.5 的数值"),
123
+ });
124
+ type AmountValues = z.input<typeof amountSchema>;
125
+ const form = useForm<AmountValues>({ resolver: zodResolver(amountSchema), defaultValues: { amount: "" } });
126
+ const submit: SubmitHandler<z.output<typeof amountSchema>> = async (data) => {
127
+ const request: SaveRequest = { amount: Number(data.amount) };
128
+ await api.save(request);
129
+ };
130
+ // 在重置动作中调用 form.reset({ amount: "" });reset 使用输入字符串。
131
+ // 在 <Form {...form}><form onSubmit={form.handleSubmit(submit)}> 中:
132
+ <FormField control={form.control} name="amount" render={({ field }) => (
133
+ <FormItem>
134
+ <FormLabel>数值</FormLabel>
135
+ <FormControl><Input type="text" inputMode="decimal" {...field} /></FormControl>
136
+ <FormMessage />
137
+ </FormItem>
138
+ )} />
139
+ ```
140
+
91
141
  ### 推荐的多步骨架
92
142
 
93
143
  ```tsx
@@ -160,7 +210,7 @@ const form = useForm<FormData>({ resolver: zodResolver(schema), defaultValues: {
160
210
  )} />
161
211
 
162
212
  // 必填 Request/DTO 桥接:zodResolver 负责运行时校验,DTO 边界负责静态类型匹配。
163
- // 用 handleSubmit 回调的 data,不要用 getValues(拿到的是 coerce 前的原始值)。
213
+ // 用 handleSubmit 回调的解析输出 data;getValues 返回输入值。
164
214
  import type { SaveRequest } from "@/shared/api";
165
215
  form.handleSubmit(async (data) => {
166
216
  const request: SaveRequest = { field: data.field };
@@ -53,12 +53,14 @@ CLI 提供三种互斥的 scope 表达方式:
53
53
  | flag | 用途 | 备注 |
54
54
  |---|---|---|
55
55
  | `--scope-all` | `allow_all=true`,放开所有路由 | bool flag,显式传 `--scope-all=false` 也算"已设置" |
56
- | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由从应用 `docs/openapi.json` 取 |
56
+ | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由按下述「scope 值来源」取值 |
57
57
  | `--scope '<raw request_scope JSON>'` | 高级逃生口,直传 request_scope JSON(snake_case) | CLI 只校验合法 JSON;`--scope` 与 `--scope-all`/`--scope-api` 互斥 |
58
58
 
59
59
  ### scope 值来源
60
60
 
61
- 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json`(`paths` 下每个 `"/openapi/..."` 条目 + HTTP 方法)。要授权哪些路由,读目标应用自己的 `docs/openapi.json`,取 `(method, path)` 对。CLI 本身不提供 API 路由发现功能(P1 规划中)。
61
+ 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json` 的 `paths`。读目标应用的该文件,选择所需 HTTP 方法和应用内路径(不含 `/app/<appId>` 前缀)。构造 scope 时,将每个完整动态段 `{name}` 转为 `:name`,如 `/openapi/items/{itemId}` → `/openapi/items/:itemId`;多动态段逐段转换,静态段和方法不变,已有冒号动态段不改。create/update 的 `--scope-api` 和 raw JSON 的 `http_infos[].http_path` 使用同一规则。CLI 本身不提供 API 路由发现功能(P1 规划中)。
62
+
63
+ `:name` 匹配一个非空路径段,路径段数须相等;它也覆盖同方法、同层的静态路径,不按 spec 参数约束或 Controller 路由优先级收窄。用户要求排除这些路径时,说明现有 scope 的限制;仅在具体目标已知且用户授权允许时使用精确路径,不静默扩权。`{name}` 和 `*` 不是通配语法(仍可字面量匹配),不能替代动态段或匹配任意后缀。
62
64
 
63
65
  ## 高风险操作(delete / reset)
64
66
 
@@ -73,7 +75,7 @@ CLI 提供三种互斥的 scope 表达方式:
73
75
  | "key 泄露了,先停掉" | `+openapi-key-disable`(不是 delete) |
74
76
  | "key 丢了/忘了,再给我一个" | `+openapi-key-reset`(不是 create 新 key;reset 轮换密钥、保留原 key 配置) |
75
77
  | "我的 key 密钥是什么" | 解释:list/get 不回显原始密钥,只能用 `+openapi-key-reset` 轮换 |
76
- | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由取自应用 `docs/openapi.json`) |
78
+ | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由按「scope 值来源」取值) |
77
79
 
78
80
  ## 不在本 skill 范围
79
81
 
@@ -188,7 +188,7 @@ lark-cli apps +db-sync-get --app-id "$app_id" --task-id streaming_123
188
188
 
189
189
  **多表 Base**:本命令一次只处理一张表。用户要同步整个 Base 时,先把计划说清楚:不是一个“整库同步任务”,而是按表拆成 N 个单表任务。每张表各有一份配置文件、一次 `+db-sync-create --preview`、一次用户确认后的 `+db-sync-create --yes`,并记录各自 `task_id`。配置也必须是单表粒度:每份 JSON 只有一个 `source.table` 和一个 `target.table`,字段名保持 `field_maps`、`option_mappings`、`syncable_source_fields` 这些复数 key。
190
190
 
191
- **修改 streaming 映射**:先用 get 导出当前配置,编辑 `field_maps` 后 update。update 是高危操作,必须经用户确认再加 `--yes`。
191
+ **修改 streaming 映射**:先用 get 导出当前配置。`+db-sync-get` 的 `target.table` 不含更新必填的 `action`;沿用已有目标表时,补 `target.table.action="use_existing"`(不是 update 默认,不能改成 `create`),保持当前 `source`、目标表名及无关 `field_maps`,只改用户要求的映射。update 是高危操作,必须经用户确认再加 `--yes`。
192
192
 
193
193
  `+db-sync-get` 返回的 `source` **不含 `base_url`**(只有 token / tableId,服务端没有 domain 拼不出完整 URL),这是正常的。原表 update 直接省略 `base_url` 即可;只有要换成另一张 Base 表时,才在 config 里显式补一个新的 `base_url`。不要为了"补全" `base_url` 而编造 domain 或拼接 URL——拿不到就省略,让服务端复用原任务的源 URL。
194
194
 
@@ -196,6 +196,8 @@ lark-cli apps +db-sync-get --app-id "$app_id" --task-id streaming_123
196
196
 
197
197
  ```bash
198
198
  lark-cli apps +db-sync-get --app-id "$app_id" --task-id streaming_123 -q '.data | {mode, source, target, field_maps}' > sync.json
199
+ jq '.target.table.action = "use_existing"' sync.json > sync.tmp.json && mv sync.tmp.json sync.json
200
+ # 只编辑用户要求的 field_maps,展示改后配置并取得用户确认,再执行 update
199
201
  lark-cli apps +db-sync-update --app-id "$app_id" --task-id streaming_123 --environment dev --config @sync.json --yes
200
202
  ```
201
203
 
@@ -53,12 +53,14 @@ CLI 提供三种互斥的 scope 表达方式:
53
53
  | flag | 用途 | 备注 |
54
54
  |---|---|---|
55
55
  | `--scope-all` | `allow_all=true`,放开所有路由 | bool flag,显式传 `--scope-all=false` 也算"已设置" |
56
- | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由从应用 `docs/openapi.json` 取 |
56
+ | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由按下述「scope 值来源」取值 |
57
57
  | `--scope '<raw request_scope JSON>'` | 高级逃生口,直传 request_scope JSON(snake_case) | CLI 只校验合法 JSON;`--scope` 与 `--scope-all`/`--scope-api` 互斥 |
58
58
 
59
59
  ### scope 值来源
60
60
 
61
- 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json`(`paths` 下每个 `"/openapi/..."` 条目 + HTTP 方法)。要授权哪些路由,读目标应用自己的 `docs/openapi.json`,取 `(method, path)` 对。CLI 本身不提供 API 路由发现功能(P1 规划中)。
61
+ 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json` 的 `paths`。读目标应用的该文件,选择所需 HTTP 方法和应用内路径(不含 `/app/<appId>` 前缀)。构造 scope 时,将每个完整动态段 `{name}` 转为 `:name`,如 `/openapi/items/{itemId}` → `/openapi/items/:itemId`;多动态段逐段转换,静态段和方法不变,已有冒号动态段不改。create/update 的 `--scope-api` 和 raw JSON 的 `http_infos[].http_path` 使用同一规则。CLI 本身不提供 API 路由发现功能(P1 规划中)。
62
+
63
+ `:name` 匹配一个非空路径段,路径段数须相等;它也覆盖同方法、同层的静态路径,不按 spec 参数约束或 Controller 路由优先级收窄。用户要求排除这些路径时,说明现有 scope 的限制;仅在具体目标已知且用户授权允许时使用精确路径,不静默扩权。`{name}` 和 `*` 不是通配语法(仍可字面量匹配),不能替代动态段或匹配任意后缀。
62
64
 
63
65
  ## 高风险操作(delete / reset)
64
66
 
@@ -73,7 +75,7 @@ CLI 提供三种互斥的 scope 表达方式:
73
75
  | "key 泄露了,先停掉" | `+openapi-key-disable`(不是 delete) |
74
76
  | "key 丢了/忘了,再给我一个" | `+openapi-key-reset`(不是 create 新 key;reset 轮换密钥、保留原 key 配置) |
75
77
  | "我的 key 密钥是什么" | 解释:list/get 不回显原始密钥,只能用 `+openapi-key-reset` 轮换 |
76
- | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由取自应用 `docs/openapi.json`) |
78
+ | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由按「scope 值来源」取值) |
77
79
 
78
80
  ## 不在本 skill 范围
79
81
 
@@ -9,10 +9,15 @@ Shadcn Form + React Hook Form + Zod 表单开发。
9
9
 
10
10
  ## Guidelines
11
11
 
12
- - 表单类型由 zod schema 推导;所有字段必须有 `defaultValues`;运行时校验用 `zodResolver`
12
+ - 表单类型从 schema 推导:`z.input<typeof schema>` 用于 `defaultValues`、`reset`、控件和 `getValues`;`z.output<typeof schema>`(即 `z.infer`)用于默认 `raw: false` 的 resolver 解析后的 `handleSubmit` 回调。coerce、default、transform 不能假设输入输出相同。
13
+ - 输入输出相同时可用单泛型 `useForm<Input>`;不同时,单输入泛型可能通过类型检查,但提交回调的静态类型仍是较宽的输入类型,必须按输入安全处理。需要精确输出时用 `useForm<z.input<typeof schema>, unknown, z.output<typeof schema>>`,回调用 `SubmitHandler<z.output<typeof schema>>`。
14
+ - 初始化每个需要的控件值;schema 有 default 的可选输入可以省略,但 `reset` 仍接收输入类型。外部 `unknown` 不能直接 spread 到 DOM:先适配成控件接受的值。
15
+ - `z.coerce.number<number>()` 只适用于控件实际写入 number;泛型不改变运行时转换。下例将空值写成 NaN 以触发校验,而非让空串 coerce 为 0;只适用于无需保留编辑中间态的非负整数等输入。需要逐键保留小数、符号等中间态时,使用下方字符串兼容路径;旧 Zod 不支持该泛型时也用该路径,不强制升级。
16
+ - 需要 string→number transform 时,先确认实际 `FormField` 是否透传第三泛型;现有包装可能不支持,勿修改托管包装或把三库的支持等同于 UI 支持。可保持 schema、控件、reset 均为字符串,校验后在提交中逐字段转换(见下方兼容路径)。
17
+ - 运行时校验使用 `zodResolver`。
13
18
  - 提交到必填 API/service Request 时,submit 的类型边界用业务 Request:Request 类型可读就 `const payload: XxxRequest = { ... }` 逐字段补齐;不可读但函数签名可读用 `Parameters<typeof submit>[0]` 派生
14
- - 补 `useForm<TFieldValues, TContext, TTransformedValues>` 的泛型参数解决不了这个问题
15
- - API 合同允许字段可选的查询、筛选、搜索表单,继续提交 `z.infer` 值
19
+ - 三泛型可表达 resolver 的输入输出,但不会自动补齐必填 Request/DTO 字段。
20
+ - API 合同允许字段可选的查询、筛选、搜索表单,可直接提交与 API 合同匹配的解析输出。
16
21
  - 必须用 Shadcn 组件,禁止原生 input
17
22
  - 同行 FormField 必须等宽
18
23
  - 每个控件都要有能读出来的字段名(读屏和自动化验收都按它找控件):FormField 内用 `FormLabel` + `FormControl`,id 会自动关联;FormField 外的筛选、搜索控件用 `<Label htmlFor="x">` 配控件 `id="x"`,没有可见标签时加 `aria-label`。不要只靠 placeholder 或当前选中值表达字段含义
@@ -28,7 +33,7 @@ Shadcn Form + React Hook Form + Zod 表单开发。
28
33
 
29
34
  ```tsx
30
35
  import { zodResolver } from "@hookform/resolvers/zod";
31
- import { useForm } from "react-hook-form";
36
+ import { useForm, type SubmitHandler } from "react-hook-form";
32
37
  import { z } from "zod";
33
38
  import { Button } from "@/components/ui/button";
34
39
  import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
@@ -38,11 +43,12 @@ import { logger } from "@lark-apaas/client-toolkit-lite";
38
43
 
39
44
  const studentSchema = z.object({
40
45
  name: z.string().min(1, "姓名不能为空"),
41
- age: z.coerce.number().min(0, "年龄不能为负数"),
42
- grade: z.string().min(1, "请选择年级"),
46
+ age: z.coerce.number<number>().int().min(0, "年龄不能为负数").max(150, "年龄不能大于150"),
47
+ grade: z.string().optional().default("grade1"),
43
48
  });
44
49
 
45
- type StudentFormData = z.infer<typeof studentSchema>;
50
+ type StudentInput = z.input<typeof studentSchema>;
51
+ type StudentOutput = z.output<typeof studentSchema>;
46
52
 
47
53
  interface CreateStudentRequest {
48
54
  name: string;
@@ -55,23 +61,18 @@ async function createStudent(payload: CreateStudentRequest) {
55
61
  }
56
62
 
57
63
  export function StudentForm() {
58
- const form = useForm<StudentFormData>({
64
+ const form = useForm<StudentInput, unknown, StudentOutput>({
59
65
  resolver: zodResolver(studentSchema),
60
- defaultValues: { name: "", age: 0, grade: "" },
66
+ defaultValues: { name: "", age: NaN },
61
67
  });
62
-
63
- const handleSubmit = async (values: StudentFormData) => {
64
- const payload: CreateStudentRequest = {
65
- name: values.name,
66
- age: values.age,
67
- grade: values.grade,
68
- };
68
+ const onSubmit: SubmitHandler<StudentOutput> = async (data) => {
69
+ const payload: CreateStudentRequest = { name: data.name, age: data.age, grade: data.grade };
69
70
  await createStudent(payload);
70
71
  };
71
72
 
72
73
  return (
73
74
  <Form {...form}>
74
- <form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-6">
75
+ <form noValidate onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
75
76
  <div className="flex flex-wrap gap-4">
76
77
  <FormField control={form.control} name="name" render={({ field }) => (
77
78
  <FormItem className="flex-1">
@@ -83,16 +84,18 @@ export function StudentForm() {
83
84
  <FormField control={form.control} name="age" render={({ field }) => (
84
85
  <FormItem className="flex-1">
85
86
  <FormLabel>年龄 <span aria-hidden="true" className="text-destructive">*</span></FormLabel>
86
- <FormControl><Input type="number" {...field} /></FormControl>
87
+ <FormControl><Input {...field} type="number" min={0} max={150} step={1}
88
+ value={Number.isFinite(field.value) ? field.value : ""}
89
+ onChange={(event) => field.onChange(event.target.value === "" ? NaN : event.target.valueAsNumber)} /></FormControl>
87
90
  <FormMessage />
88
91
  </FormItem>
89
92
  )} />
90
93
  </div>
91
94
  <FormField control={form.control} name="grade" render={({ field }) => (
92
95
  <FormItem>
93
- <FormLabel>年级 <span aria-hidden="true" className="text-destructive">*</span></FormLabel>
94
- <Select onValueChange={field.onChange} defaultValue={field.value}>
95
- <FormControl><SelectTrigger><SelectValue placeholder="请选择" /></SelectTrigger></FormControl>
96
+ <FormLabel>年级</FormLabel>
97
+ <Select value={field.value ?? "grade1"} onValueChange={field.onChange}>
98
+ <FormControl><SelectTrigger onBlur={field.onBlur} ref={field.ref}><SelectValue placeholder="默认为一年级" /></SelectTrigger></FormControl>
96
99
  <SelectContent>
97
100
  <SelectItem value="grade1">一年级</SelectItem>
98
101
  <SelectItem value="grade2">二年级</SelectItem>
@@ -102,12 +105,41 @@ export function StudentForm() {
102
105
  </FormItem>
103
106
  )} />
104
107
  <Button type="submit">提交</Button>
108
+ <Button type="button" onClick={() => form.reset({ name: "", age: NaN })}>重置</Button>
105
109
  </form>
106
110
  </Form>
107
111
  );
108
112
  }
109
113
  ```
110
114
 
115
+ ### 字符串兼容路径
116
+
117
+ 按 Guidelines 的字符串兼容路径:用 string/refine 校验非空、有限值和业务范围。范围 0~24、步长 0.5 仅为示例,按业务调整;文本控件保留 `0.` 等中间态,步长在 schema 中校验。
118
+
119
+ ```tsx
120
+ const amountSchema = z.object({
121
+ amount: z.string().refine((text) => {
122
+ const n = Number(text);
123
+ return text.trim() !== "" && Number.isFinite(n) && n >= 0 && n <= 24 && Number.isInteger(n * 2);
124
+ }, "请输入 0~24 内步长为 0.5 的数值"),
125
+ });
126
+ type AmountValues = z.input<typeof amountSchema>;
127
+ const form = useForm<AmountValues>({ resolver: zodResolver(amountSchema), defaultValues: { amount: "" } });
128
+ const submit: SubmitHandler<z.output<typeof amountSchema>> = async (data) => {
129
+ const request: SaveRequest = { amount: Number(data.amount) };
130
+ await api.save(request);
131
+ };
132
+ // 在重置动作中调用 form.reset({ amount: "" });reset 使用输入字符串。
133
+ // 在 <Form {...form}><form onSubmit={form.handleSubmit(submit)}> 中:
134
+ <FormField control={form.control} name="amount" render={({ field }) => (
135
+ <FormItem>
136
+ <FormLabel>数值</FormLabel>
137
+ <FormControl><Input type="text" inputMode="decimal" {...field} /></FormControl>
138
+ <FormMessage />
139
+ </FormItem>
140
+ )} />
141
+ ```
142
+
111
143
  ---
112
144
 
113
145
  ## Patterns
@@ -156,7 +188,7 @@ const form = useForm<FormData>({ resolver: zodResolver(schema), defaultValues: {
156
188
  )} />
157
189
 
158
190
  // 必填 Request/DTO 桥接:zodResolver 负责运行时校验,DTO 边界负责静态类型匹配。
159
- // 用 handleSubmit 回调的 data,不要用 getValues(拿到的是 coerce 前的原始值)。
191
+ // 用 handleSubmit 回调的解析输出 data;getValues 返回输入值。
160
192
  import type { SaveRequest } from "@/shared/api";
161
193
  form.handleSubmit(async (data) => {
162
194
  const request: SaveRequest = { field: data.field };
@@ -53,12 +53,14 @@ CLI 提供三种互斥的 scope 表达方式:
53
53
  | flag | 用途 | 备注 |
54
54
  |---|---|---|
55
55
  | `--scope-all` | `allow_all=true`,放开所有路由 | bool flag,显式传 `--scope-all=false` 也算"已设置" |
56
- | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由从应用 `docs/openapi.json` 取 |
56
+ | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由按下述「scope 值来源」取值 |
57
57
  | `--scope '<raw request_scope JSON>'` | 高级逃生口,直传 request_scope JSON(snake_case) | CLI 只校验合法 JSON;`--scope` 与 `--scope-all`/`--scope-api` 互斥 |
58
58
 
59
59
  ### scope 值来源
60
60
 
61
- 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json`(`paths` 下每个 `"/openapi/..."` 条目 + HTTP 方法)。要授权哪些路由,读目标应用自己的 `docs/openapi.json`,取 `(method, path)` 对。CLI 本身不提供 API 路由发现功能(P1 规划中)。
61
+ 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json` 的 `paths`。读目标应用的该文件,选择所需 HTTP 方法和应用内路径(不含 `/app/<appId>` 前缀)。构造 scope 时,将每个完整动态段 `{name}` 转为 `:name`,如 `/openapi/items/{itemId}` → `/openapi/items/:itemId`;多动态段逐段转换,静态段和方法不变,已有冒号动态段不改。create/update 的 `--scope-api` 和 raw JSON 的 `http_infos[].http_path` 使用同一规则。CLI 本身不提供 API 路由发现功能(P1 规划中)。
62
+
63
+ `:name` 匹配一个非空路径段,路径段数须相等;它也覆盖同方法、同层的静态路径,不按 spec 参数约束或 Controller 路由优先级收窄。用户要求排除这些路径时,说明现有 scope 的限制;仅在具体目标已知且用户授权允许时使用精确路径,不静默扩权。`{name}` 和 `*` 不是通配语法(仍可字面量匹配),不能替代动态段或匹配任意后缀。
62
64
 
63
65
  ## 高风险操作(delete / reset)
64
66
 
@@ -73,7 +75,7 @@ CLI 提供三种互斥的 scope 表达方式:
73
75
  | "key 泄露了,先停掉" | `+openapi-key-disable`(不是 delete) |
74
76
  | "key 丢了/忘了,再给我一个" | `+openapi-key-reset`(不是 create 新 key;reset 轮换密钥、保留原 key 配置) |
75
77
  | "我的 key 密钥是什么" | 解释:list/get 不回显原始密钥,只能用 `+openapi-key-reset` 轮换 |
76
- | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由取自应用 `docs/openapi.json`) |
78
+ | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由按「scope 值来源」取值) |
77
79
 
78
80
  ## 不在本 skill 范围
79
81
 
@@ -53,12 +53,14 @@ CLI 提供三种互斥的 scope 表达方式:
53
53
  | flag | 用途 | 备注 |
54
54
  |---|---|---|
55
55
  | `--scope-all` | `allow_all=true`,放开所有路由 | bool flag,显式传 `--scope-all=false` 也算"已设置" |
56
- | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由从应用 `docs/openapi.json` 取 |
56
+ | `--scope-api 'METHOD /openapi/path'` | 逐条授权一个路由,可重复 | 路由按下述「scope 值来源」取值 |
57
57
  | `--scope '<raw request_scope JSON>'` | 高级逃生口,直传 request_scope JSON(snake_case) | CLI 只校验合法 JSON;`--scope` 与 `--scope-all`/`--scope-api` 互斥 |
58
58
 
59
59
  ### scope 值来源
60
60
 
61
- 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json`(`paths` 下每个 `"/openapi/..."` 条目 + HTTP 方法)。要授权哪些路由,读目标应用自己的 `docs/openapi.json`,取 `(method, path)` 对。CLI 本身不提供 API 路由发现功能(P1 规划中)。
61
+ 妙搭应用的 `/openapi/**` 路由定义在应用仓库,并同步维护在 `docs/openapi.json` 的 `paths`。读目标应用的该文件,选择所需 HTTP 方法和应用内路径(不含 `/app/<appId>` 前缀)。构造 scope 时,将每个完整动态段 `{name}` 转为 `:name`,如 `/openapi/items/{itemId}` → `/openapi/items/:itemId`;多动态段逐段转换,静态段和方法不变,已有冒号动态段不改。create/update 的 `--scope-api` 和 raw JSON 的 `http_infos[].http_path` 使用同一规则。CLI 本身不提供 API 路由发现功能(P1 规划中)。
62
+
63
+ `:name` 匹配一个非空路径段,路径段数须相等;它也覆盖同方法、同层的静态路径,不按 spec 参数约束或 Controller 路由优先级收窄。用户要求排除这些路径时,说明现有 scope 的限制;仅在具体目标已知且用户授权允许时使用精确路径,不静默扩权。`{name}` 和 `*` 不是通配语法(仍可字面量匹配),不能替代动态段或匹配任意后缀。
62
64
 
63
65
  ## 高风险操作(delete / reset)
64
66
 
@@ -73,7 +75,7 @@ CLI 提供三种互斥的 scope 表达方式:
73
75
  | "key 泄露了,先停掉" | `+openapi-key-disable`(不是 delete) |
74
76
  | "key 丢了/忘了,再给我一个" | `+openapi-key-reset`(不是 create 新 key;reset 轮换密钥、保留原 key 配置) |
75
77
  | "我的 key 密钥是什么" | 解释:list/get 不回显原始密钥,只能用 `+openapi-key-reset` 轮换 |
76
- | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由取自应用 `docs/openapi.json`) |
78
+ | "给应用创建一个有权限限制的 key" | `+openapi-key-create --name ... --scope-api 'GET /openapi/...'`(路由按「scope 值来源」取值) |
77
79
 
78
80
  ## 不在本 skill 范围
79
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-miaoda-sandbox-skills",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "Miaoda 合并沙箱 skills 包(包含原 miaoda-skills 的 miaoda / miaoda-modern / miaoda-design / shared 四条业务线);发布公网 npm,随沙箱运行时经 update-skills 同步到 .agent/skills/",
5
5
  "type": "module",
6
6
  "files": [