Skip to content

Commit ef63468

Browse files
committed
agent: integrates with agent SKILLs , open-source some internal use cases
1 parent 656924c commit ef63468

File tree

19 files changed

+835
-7
lines changed

19 files changed

+835
-7
lines changed

SKILL.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: ezorm-skills
3+
description: Entry point for ezorm repo skills. Use to pick the right skill based on task (write YAML vs generate code, and mongo vs mysql/mysqlr).
4+
---
5+
6+
# Ezorm Skills Index
7+
8+
## Choose a Skill
9+
10+
- Write YAML schema (mongo): `ezorm-write-yaml-mongo`
11+
- Write YAML schema (mysql/mysqlr): `ezorm-write-yaml-mysql` (prefer mysqlr unless explicitly asked for mysql)
12+
- Generate Go from YAML (mongo): `ezorm-gen-yaml-mongo`
13+
- Generate Go from YAML (mysql/mysqlr): `ezorm-gen-yaml-mysql` (prefer mysqlr unless explicitly asked for mysql)
14+
15+
## Notes
16+
17+
- YAML is the source of truth. Generate code with `ezorm gen` using the gen-yaml skills.
18+
- Use db-specific docs and examples referenced inside each skill folder.

doc/schema/yaml.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# YAML Schema
22

3+
EZORM schemas are defined in YAML; generated code is derived from YAML.
4+
Do not infer extra fields or constraints not requested by the user.
5+
6+
## Required vs Optional
7+
8+
Required:
9+
- `db`
10+
- `fields`
11+
12+
Recommended:
13+
- `dbname`
14+
- `table` (mysql) or `dbtable` (mysqlr)
15+
16+
Optional:
17+
- `comment`
18+
- `indexes`
19+
- `uniques`
20+
- `primary`
21+
322
## Example
423

524
```yaml
@@ -22,14 +41,23 @@ Blog:
2241
2342
## Schema Definition
2443
44+
Top-level YAML contains one or more entities. Each entity name is the
45+
logical model name used by generated code.
46+
2547
> details: [db: mysql](yaml_mysql.md) | [db: mysqlr](yaml_mysqlr.md) | [db: mongo](yaml_mongo.md)
2648
2749
| Component | Remark | Definition in Example | Other Properties |
2850
|---|---|---|---|
29-
| Database Name | The Name of database Object , the generated code will use this name as Access Manager|`Blog`| / |
30-
| `db` | The name of database driver |[`mongo`](../../e2e/mongo/)| [`mysql`](../../e2e/mysql/) / [`mysqlr`](../../e2e/mysqlr/) |
31-
| `fields` | The definition of fields | `Title`,`Slug`, `Body`, `CreateDate`,`IsPublished`| / |
32-
| Field Type | The type of field | `string`, `int32`, `bool`, `datetime`| / |
33-
| Field `flags` | The properties of fields | `unique`,`sort`,`index` | /|
34-
|Database Constraint | Describe the table constraint | `indexes` | `uniques`/ `primary` |
35-
|Database Comment|Describe the table comment | `comment` | / |
51+
| Entity Name | Logical model name | `Blog` | / |
52+
| `db` | Database driver | `mongo` | `mysql` / `mysqlr` |
53+
| `fields` | Field definitions | `Title`, `Slug`, `Body`, `CreateDate`, `IsPublished` | / |
54+
| Field Type | Field type | `string`, `int32`, `bool`, `datetime` | / |
55+
| Field `flags` | Field properties | `unique`, `sort`, `index` | / |
56+
| Constraints | Table or collection constraints | `indexes` | `uniques` / `primary` |
57+
| `comment` | Entity comment | `comment` | / |
58+
59+
## Driver-specific Pointers
60+
61+
- mongo: [yaml_mongo.md](yaml_mongo.md), examples in `e2e/mongo/`
62+
- mysql: [yaml_mysql.md](yaml_mysql.md), examples in `e2e/mysql/`
63+
- mysqlr: [yaml_mysqlr.md](yaml_mysqlr.md), examples in `e2e/mysqlr/`

doc/schema/yaml_mongo.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
## mongo
22

3+
### Required vs Optional
4+
5+
Required:
6+
- `db`
7+
- `fields`
8+
9+
Recommended:
10+
- `dbname`
11+
- `table`
12+
13+
Optional:
14+
- `comment`
15+
- `indexes`
16+
- `uniques`
17+
- `primary`
18+
319
### Field Properties
420

521
* label

doc/schema/yaml_mysql.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11

22
## mysql
33

4+
### Required vs Optional
5+
6+
Required:
7+
- `db`
8+
- `fields`
9+
10+
Recommended:
11+
- `dbname`
12+
- `table`
13+
14+
Optional:
15+
- `comment`
16+
- `indexes`
17+
- `uniques`
18+
- `primary`
19+
420
### Field Properties
521

622
* label

doc/schema/yaml_mysqlr.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
## mysqlr
22

3+
### Required vs Optional
4+
5+
Required:
6+
- `db`
7+
- `fields`
8+
9+
Recommended:
10+
- `dbname`
11+
- `dbtable`
12+
13+
Optional:
14+
- `comment`
15+
- `indexes`
16+
- `uniques`
17+
- `primary`
18+
319
### Field Properties
420

521
* size
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: ezorm-gen-yaml-mongo
3+
description: Generate Go code from ezorm YAML (mongo). Use when asked to produce Go output from mongo YAML schemas; provide the exact ezorm CLI command(s).
4+
---
5+
6+
# Ezorm Gen Yaml (Mongo)
7+
8+
## Scope
9+
10+
Generate Go code from ezorm YAML schema files for mongo using the `ezorm` CLI.
11+
Read these files when command details or examples are needed:
12+
- `Makefile` (target: `gene2e`)
13+
- `e2e/mongo/`
14+
If the local `references/` or `assets/` directories are missing, run:
15+
`scripts/init.sh` (or `scripts/init.sh --force` to refresh).
16+
Validate with `scripts/validate.sh`.
17+
If `bin/ezorm` is missing, run `scripts/ensure-ezorm.sh` first.
18+
19+
## Workflow
20+
21+
1. Confirm input YAML path(s) and output directory.
22+
2. Choose goPackage and namespace (required for `ezorm gen`).
23+
3. Use the mongo command pattern:
24+
- `bin/ezorm gen -i <yaml-or-dir> -o <out-dir> --goPackage <pkg> --namespace <ns>`
25+
4. Output only the command(s) needed. Do not generate Go code in the response.
26+
27+
## Output Rules
28+
29+
- Emit shell command(s) only.
30+
- Do not invent paths; use the user-provided locations.
31+
- Prefer a single command per directory when input is a folder.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
force=false
5+
if [[ "${1:-}" == "--force" ]]; then
6+
force=true
7+
fi
8+
9+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
repo_root="$(cd "${script_dir}/../../.." && pwd)"
11+
bin_dir="${repo_root}/bin"
12+
target_bin="${bin_dir}/ezorm"
13+
14+
if [[ -x "${target_bin}" && "${force}" == "false" ]]; then
15+
printf 'ezorm already present: %s\n' "${target_bin}"
16+
exit 0
17+
fi
18+
19+
mkdir -p "${bin_dir}"
20+
21+
try_go_install() {
22+
if ! command -v go >/dev/null 2>&1; then
23+
return 1
24+
fi
25+
26+
printf 'installing ezorm via go install...\n'
27+
if ! go install github.com/ezbuy/ezorm/v2@latest; then
28+
return 1
29+
fi
30+
31+
local gopath
32+
gopath="$(go env GOPATH)"
33+
if [[ -z "${gopath}" ]]; then
34+
return 1
35+
fi
36+
37+
local installed_bin="${gopath}/bin/ezorm"
38+
if [[ ! -x "${installed_bin}" ]]; then
39+
return 1
40+
fi
41+
42+
cp "${installed_bin}" "${target_bin}"
43+
chmod +x "${target_bin}"
44+
printf 'installed ezorm to %s\n' "${target_bin}"
45+
return 0
46+
}
47+
48+
try_release_download() {
49+
if ! command -v curl >/dev/null 2>&1; then
50+
printf 'curl is required to download ezorm release\n'
51+
return 1
52+
fi
53+
54+
local os arch
55+
case "$(uname -s)" in
56+
Linux) os="linux" ;;
57+
Darwin) os="darwin" ;;
58+
*)
59+
printf 'unsupported OS: %s\n' "$(uname -s)"
60+
return 1
61+
;;
62+
esac
63+
64+
case "$(uname -m)" in
65+
x86_64) arch="amd64" ;;
66+
arm64|aarch64) arch="arm64" ;;
67+
*)
68+
printf 'unsupported arch: %s\n' "$(uname -m)"
69+
return 1
70+
;;
71+
esac
72+
73+
local py
74+
if command -v python3 >/dev/null 2>&1; then
75+
py="python3"
76+
elif command -v python >/dev/null 2>&1; then
77+
py="python"
78+
else
79+
printf 'python is required to parse release metadata\n'
80+
return 1
81+
fi
82+
83+
printf 'downloading ezorm release for %s/%s...\n' "${os}" "${arch}"
84+
85+
local release_json url
86+
release_json="$(curl -fsSL https://api.github.com/repos/ezbuy/ezorm/releases/latest)"
87+
url="$(${py} - "${os}" "${arch}" <<'PY'
88+
import json
89+
import sys
90+
91+
target_os = sys.argv[1]
92+
target_arch = sys.argv[2]
93+
94+
data = json.load(sys.stdin)
95+
assets = data.get("assets", [])
96+
for asset in assets:
97+
name = asset.get("name", "")
98+
lower = name.lower()
99+
if "ezorm" not in lower:
100+
continue
101+
if target_os in lower and target_arch in lower:
102+
print(asset.get("browser_download_url", ""))
103+
raise SystemExit(0)
104+
print("")
105+
raise SystemExit(1)
106+
PY
107+
)"
108+
109+
if [[ -z "${url}" ]]; then
110+
printf 'no release asset found for %s/%s\n' "${os}" "${arch}"
111+
return 1
112+
fi
113+
114+
local tmpdir tmpfile
115+
tmpdir="$(mktemp -d)"
116+
tmpfile="${tmpdir}/ezorm_download"
117+
curl -fsSL "${url}" -o "${tmpfile}"
118+
119+
case "${url}" in
120+
*.tar.gz)
121+
tar -xzf "${tmpfile}" -C "${tmpdir}"
122+
;;
123+
*.zip)
124+
unzip -q "${tmpfile}" -d "${tmpdir}"
125+
;;
126+
*)
127+
cp "${tmpfile}" "${target_bin}"
128+
chmod +x "${target_bin}"
129+
printf 'installed ezorm to %s\n' "${target_bin}"
130+
rm -rf "${tmpdir}"
131+
return 0
132+
;;
133+
esac
134+
135+
local found
136+
found="$(find "${tmpdir}" -type f -name ezorm -maxdepth 3 | head -n 1)"
137+
if [[ -z "${found}" ]]; then
138+
printf 'ezorm binary not found in release archive\n'
139+
rm -rf "${tmpdir}"
140+
return 1
141+
fi
142+
143+
cp "${found}" "${target_bin}"
144+
chmod +x "${target_bin}"
145+
rm -rf "${tmpdir}"
146+
printf 'installed ezorm to %s\n' "${target_bin}"
147+
return 0
148+
}
149+
150+
if try_go_install; then
151+
exit 0
152+
fi
153+
154+
if try_release_download; then
155+
exit 0
156+
fi
157+
158+
printf 'failed to install ezorm; try go install github.com/ezbuy/ezorm/v2@latest\n'
159+
exit 1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
force=false
5+
if [[ "${1:-}" == "--force" ]]; then
6+
force=true
7+
fi
8+
9+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
assets_dir="${script_dir}/../assets"
11+
refs_dir="${script_dir}/../references"
12+
13+
mkdir -p "${assets_dir}" "${refs_dir}"
14+
15+
download() {
16+
local src_path="$1"
17+
local dst_path="$2"
18+
19+
if [[ -f "${dst_path}" && "${force}" == "false" ]]; then
20+
return 0
21+
fi
22+
23+
curl -fsSL "https://raw.githubusercontent.com/ezbuy/ezorm/main/${src_path}" -o "${dst_path}"
24+
}
25+
26+
# References
27+
28+
download "Makefile" "${refs_dir}/Makefile"
29+
30+
# Assets (examples)
31+
32+
download "e2e/mongo/user/user.yaml" "${assets_dir}/mongo_user.yaml"
33+
download "e2e/mongo/nested/nested.yaml" "${assets_dir}/mongo_nested.yaml"
34+
35+
printf 'init complete (gen mongo)\n'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
assets_dir="${script_dir}/../assets"
6+
refs_dir="${script_dir}/../references"
7+
8+
required_files=(
9+
"${refs_dir}/Makefile"
10+
"${assets_dir}/mongo_user.yaml"
11+
"${assets_dir}/mongo_nested.yaml"
12+
)
13+
14+
missing=0
15+
for f in "${required_files[@]}"; do
16+
if [[ ! -f "${f}" ]]; then
17+
printf 'missing: %s\n' "${f}"
18+
missing=1
19+
fi
20+
done
21+
22+
if [[ "${missing}" -ne 0 ]]; then
23+
printf 'run scripts/init.sh to download missing files\n'
24+
exit 1
25+
fi
26+
27+
printf 'validate ok (gen mongo)\n'

0 commit comments

Comments
 (0)