Add strict custom field registry

This commit is contained in:
2026-05-07 11:04:11 +08:00
parent 27e71d8c51
commit c1cc9132a4
20 changed files with 582 additions and 20 deletions

View File

@@ -13,6 +13,7 @@ README 面向准备使用 GSP 语言的人类和 AI。它说明 GSP 的用途、
| `README.md` | GSP 语言使用前说明。给人类和 AI 阅读。 |
| `gsp.schema.json` | GSP 第一版核心字段规范。使用 JSON Schema 表达,便于 AI、工具、编译器和实现模块识别。 |
| `gsp.manifest.schema.json` | GSP 工程 manifest 字段规范。 |
| `gsp.fields.schema.json` | GSP 工程自定义字段注册规范。 |
| `gsp.message.schema.json` | GSP agent 通信消息字段规范。 |
| `commands.md` | GSP Toolkit 命令规范。 |
| `ai-usage.md` | GSP 项目 AI 使用规则。 |
@@ -38,6 +39,46 @@ GSP 是一种游戏规格协议,不是具体游戏引擎、代码框架或资
GSP 不预设抽象和实体的硬边界。所有对象都先被视为 GSP再由 `title``context``resolution``with``refines` 和当前任务共同解释。
## 自定义字段
GSP 项目默认使用严格自定义字段策略。
```yaml
customFieldPolicy: strict
fieldRegistry: gsp.fields
```
非内置字段必须在 `gsp.fields` 中声明。
```yaml
gspFieldsVersion: 0.1
fields:
rewardTier:
type: string
allowed:
- common
- rare
- epic
scope:
type:
- mechanic
- feedback
```
支持类型:
```text
string
number
integer
boolean
array
object
```
未声明字段在 `strict` 模式下是 error。
## GSP 用来做什么
GSP 的核心作用是高效传递设计信息。

View File

@@ -8,6 +8,8 @@
- `title` is display text; use `id` when `title` is missing.
- `links` associates a GSP with paths, folders, URLs, or external addresses.
- Use only fields valid for the declared GSP version.
- Do not add non-built-in fields unless they are declared in `gsp.fields`.
- Run `gsp fields list` before using project custom fields.
- `with` means related design context.
- `refines` means single-source refinement.
- Empty `context` means placeholder.

View File

@@ -79,6 +79,17 @@ Build a stable GSP index.
gsp index [--root .] [--out index.json]
```
## fields
List or validate the project custom field registry.
```bash
gsp fields list [--root .] [--out fields.json]
gsp fields validate [--root .] [--out fields-report.json]
```
`gsp validate` also validates custom fields by default.
## trace
Inspect relation chains from one GSP id.

View File

@@ -0,0 +1,57 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://gsp.local/schema/gsp.fields.schema.json",
"title": "GSP Fields",
"description": "Game Specification Protocol custom field registry schema.",
"type": "object",
"additionalProperties": true,
"required": ["gspFieldsVersion", "fields"],
"properties": {
"gspFieldsVersion": {
"type": "string",
"enum": ["0.1"]
},
"fields": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": true,
"required": ["type"],
"properties": {
"type": {
"type": "string",
"enum": ["string", "number", "integer", "boolean", "array", "object"]
},
"description": {
"type": "string"
},
"allowed": {
"type": "array"
},
"required": {
"type": "boolean"
},
"default": {},
"scope": {
"type": "object",
"additionalProperties": true,
"properties": {
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"idPrefix": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}
}
}

View File

@@ -34,6 +34,15 @@
},
"description": "Directories or files scanned by the Toolkit. Defaults to design."
},
"customFieldPolicy": {
"type": "string",
"enum": ["strict", "warn", "loose"],
"description": "Policy for custom fields that are not built in. Defaults to strict."
},
"fieldRegistry": {
"type": "string",
"description": "Path to the project custom field registry. Defaults to gsp.fields."
},
"stageRules": {
"type": "object",
"additionalProperties": {