spec-check
Checks a module against its spec. Produces: a pass or fail table.
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 344
- Forks
- 7
01 前言 Front Matter
- name
- scaffold-client-extension
- description
- Generate the directory structure and client-extension.yaml for any Liferay client extension type. Use when the user asks to create a client extension, scaffold a custom element, add an object action microservice, create a site initializer, or build any other CET. After scaffolding, calls deploy-and-verify to confirm startup.
03 SKILL.md 正文
Scaffold Client Extension
Generate a ready to deploy client extension under client-extensions/<name>. The CET type drives the file layout and the companion OAuth entry requirement.
When to Invoke
- "Create a client extension", "scaffold a custom element", "build a React widget"
- "Add an object action microservice"
- "Create a site initializer"
- "I need a global CSS override" or "inject a JS library on every page"
Workflow
Identify the CET Type
If the user did not specify a type, ask. Refer to rules/client-extension-types.md for the full list of types grouped by classification:
- Frontend:
customElement,globalCSS,globalJS,iframe,themeCSS,themeFavicon,themeSpritemap,staticContent,jsImportMapsEntry,editorConfigContributor,fdsCellRenderer,fdsFilter,commerceCheckoutStep - Microservice:
objectAction,objectValidationRule,objectEntryManager,workflowAction,notificationType,captcha,commercePaymentIntegration,commerceShippingEngine,commerceTaxEngine - Configuration:
oAuthApplicationHeadlessServer,oAuthApplicationUserAgent,instanceSettings - Batch:
batch,siteInitializer
Collect Inputs
| Input | How to Obtain |
|---|---|
| Extension name | From user; convert to kebab-case for the directory |
| Workspace ID | Read from the id field at the root of client-extension.yaml in the workspace root |
| Microservice port | For microservice types; default 8081, or next unused port |
| OAuth scopes | Look up in rules/oauth-scopes.md for the CET type |
Create the Directory
client-extensions/<extension-name>/
client-extension.yaml
Additional source files depend on type (see templates below).
Type Specific Templates
customElement (React example)
<workspace-id>-<name>:
cssURLs:
- "css/main.css"
friendlyURLMapping: <name>
htmlElementName: <name>-element
name: <Display Name>
portletCategoryName: category.client-extensions
type: customElement
urls:
- "js/main.js"
useESM: true
Source layout:
client-extensions/<name>/
client-extension.yaml
package.json
src/
index.jsx # React entry, exports a web component
build.gradle # optional; Blade transpiles via Liferay's frontend Gradle tooling
Minimal src/index.jsx:
import React from 'react';
import {createRoot} from 'react-dom/client';
class MyElement extends HTMLElement {
connectedCallback() {
const root = createRoot(this);
root.render(<App />);
}
}
customElements.define('<name>-element', MyElement);
function App() {
return <div className="<name>">Hello from <Display Name></div>;
}
globalCSS
<workspace-id>-global-css:
name: <Display Name> Global CSS
type: globalCSS
url: "css/main.css"
client-extensions/<name>/
client-extension.yaml
css/
main.css
globalJS
<workspace-id>-global-js:
name: <Display Name> Global JS
scriptElementAttributes:
async: true
type: globalJS
url: "js/main.js"
objectAction (Spring Boot example)
<workspace-id>-oauth:
.serviceAddress: localhost:8081
.serviceScheme: http
name: <WorkspaceId> OAuth
scopes:
- c_<name>.everything
type: oAuthApplicationUserAgent
<workspace-id>-<name>:
name: <Display Name> Action
oAuth2ApplicationExternalReferenceCode: <workspace-id>-oauth
resourcePath: /object/action/<name>
type: objectAction
client-extensions/<name>/
client-extension.yaml
src/main/java/<package>/
Application.java
ObjectActionRestController.java
src/main/resources/
application.properties
ObjectActionRestController.java minimal shape:
@RestController
public class ObjectActionRestController {
@PostMapping("/")
public ResponseEntity<String> post(@RequestBody Map<String, Object> body) {
// Body contains the object entry fields
return ResponseEntity.ok("{}");
}
}
application.properties:
server.port=8081
liferay.oauth.application.external.reference.code=<workspace-id>-oauth
Every Microservice Project Needs a Dockerfile and LCP.json
The project templates above list only source files, but createClientExtensionConfig refuses a microservice project without both, even for a purely local deploy:
Required file "Dockerfile" not found in project "<name>"
Required file "LCP.json" not found in project "<name>"
Copy them from the matching sample on GitHub — liferay-sample-etc-node or liferay-sample-etc-spring-boot — and change the port in LCP.json to the one in .serviceAddress. Verified on 2026.Q1 with a Node project.
Run a Microservice Locally
Deploying registers the CET with Liferay; it does not start the service. The deploy writes the service's configuration into bundles/routes/default/<project> and the portal's into bundles/routes/default/dxp. Point the service's config loader at both, as the samples do.
Start the service detached from the agent's session. It has to keep running after the agent finishes or goes down — object actions keep firing at it, and anything that fires while it is down fails and is not retried. An agent's own background execution ties the process to the session, so it dies with it. Start it in a new session with setsid nohup, logging to the bundle's log directory (for Node, after npm install in the project):
WORKSPACE=$(pwd)
setsid \
nohup \
env \
LIFERAY_ROUTES_CLIENT_EXTENSION="${WORKSPACE}/bundles/routes/default/<project>" \
LIFERAY_ROUTES_DXP="${WORKSPACE}/bundles/routes/default/dxp" \
node \
"${WORKSPACE}/client-extensions/<project>/app.js" \
> "${WORKSPACE}/bundles/logs/<project>.log" 2>&1 < /dev/null &
Run it from the workspace root. Stop an earlier copy first — a second one fails to bind the port and exits, leaving the old code serving:
WORKSPACE=$(pwd)
pkill -f "[n]ode ${WORKSPACE}/client-extensions/<project>/app.js"
The [n] keeps the pattern from matching the shell that runs the command. Without it, pkill also kills that shell, because its own command line contains the pattern.
Then confirm both that it answers and that it no longer belongs to the agent. Run this from the workspace root too:
WORKSPACE=$(pwd)
curl \
--silent \
--url "http://localhost:<port>/ready"
ps -o pid=,ppid=,sid=,args= -p "$(pgrep -d , -f "[n]ode ${WORKSPACE}/client-extensions/<project>/app.js")"
READY means it is up. ps prints one line per copy; more than one line means an earlier copy is still running. The process must be its own session leader — its pid equals its sid — and its parent must not be the agent's process. If either check fails, the service stops when the session does. It does not survive a reboot; restart it the same way after one.
siteInitializer
<workspace-id>-site-init:
name: <Site Name> Initializer
oAuthApplicationHeadlessServer: <workspace-id>-site-oauth
siteExternalReferenceCode: <site-erc>
siteName: <Site Name>
type: siteInitializer
<workspace-id>-site-oauth:
name: <Site Name> OAuth
scopes:
- Liferay.Headless.Site.everything
type: oAuthApplicationHeadlessServer
Populate site-initializer per rules/site-initializer-format.md.
siteExternalReferenceCode uniquely identifies the site so rerunning the initializer updates it rather than creating a duplicate. Derive it from the site name in kebab-case.
batch
Copy liferay-sample-batch from GitHub into client-extensions/<name>. Rename the top level keys and each name in client-extension.yaml, and replace the files in batch/ with your own.
Keep the sample's assemble block. Without it, the batch/ directory is left out of the zip. The build succeeds, the bundle reaches STARTED, and nothing is imported. The signal is assembleClientExtension NO-SOURCE in the build output, or no Started batch engine import task line in the log after STARTED. Confirm the files made it in with unzip -l dist/<name>.zip. Verified on 2026.Q1.
Files import in filename order, so number them so that dependencies come first. Each file is one envelope, in the shape of the sample's files. On a local bundle, the import runs inside the portal, and Liferay.Headless.Batch.Engine.everything alone was enough for ObjectField and ObjectAction items. Verified on 2026.Q1. Liferay Cloud was not tested.
A batch project needs no Dockerfile or LCP.json; the build and import succeed without them, as in the sample. Only microservice projects require them. Verified on 2026.Q1.
Wire OAuth When Required
If rules/client-extension-types.md shows "Yes" in the OAuth column, call setup-oauth to add the companion OAuth entry: oAuthApplicationUserAgent for a microservice CET, or oAuthApplicationHeadlessServer for a batch or siteInitializer CET (see rules/oauth-scopes.md). The OAuth entry must appear in the same client-extension.yaml file.
Deploy and Verify
Call deploy-and-verify. For microservice CETs, also start the microservice process on the declared port before the smoke check.
Troubleshoot
| Symptom | Check |
|---|---|
| Bundle not STARTED | Read bundles/logs/liferay.<date>.log for the error; run diag <id> in Gogo shell |
| Custom element not in Fragments panel | htmlElementName must be a valid custom element name (contains a hyphen) |
| 401 from microservice CET | OAuth companion not deployed or scopes insufficient |
| Site initializer not in template list | CET not ACTIVE; redeploy and recheck log |
CSS Architecture for Custom Elements
CSS rules in Custom Element CETs run alongside theme styles and other CETs. A few rules keep the cascade predictable:
global.cssis additive only. Never redefine a class that already exists in the theme SCSS — the later stylesheet wins at equal specificity, producing silent cascade conflicts. Only add new classes.- Each component's
style.cssmust be selfcontained. TheglobalCSSclient extension is not injected on every site; never rely on it from inside a Custom Element. Every rule the component needs has to be present in its own stylesheet. - Prefix scoped selectors with the custom element tag name. E.g.
my-widget .btn { ... }. This raises specificity above theme defaults regardless of stylesheet load order. - Include all required properties on each scoped rule. A scoped rule does not inherit sibling properties from a lower specificity theme rule — declare every property the component depends on.
Asset URLs
After deploy, CET assets are served at /o/<webContextPath>/<filename>.<hash>.<ext>. The exact URL — including the content hash — is regenerated on each build, so read the deployed *.client-extension-config.json (under bundles/osgi/client-extensions) to resolve it at runtime. Never hardcode asset paths.
Runtime Patterns When Calling Liferay APIs From a Custom Element
Always Use Liferay.Util.fetch
Use Liferay.Util.fetch for every API call inside a Custom Element — including GET requests:
Liferay.Util.fetch(endpoint, options)
Native fetch() fails in two distinct ways:
- For write calls (
POST,PUT,DELETE), nativefetch()omits the CSRF token and the request is rejected. - For GET calls on nonpublic Object APIs, native
fetch()sends an anonymous request — Liferay responds200 OKwithitems: []rather than a 401, silently hiding every record the Guest role cannot see.
Liferay.Util.fetch propagates the user's session context for both cases.
Resolve the Current User via my-user-account, Not ThemeDisplay
Never use Liferay.ThemeDisplay.getUserId() in client side Custom Element code. It can return 0 or a stale ID when the page is partially cached.
Resolve the current user via the session fresh API instead:
GET /o/headless-admin-user/v1.0/my-user-account
Call this through Liferay.Util.fetch so the CSRF token is attached automatically.
Never Use roleBriefs for Access Control
my-user-account.roleBriefs is not invalidated immediately after a role is assigned via API — the permission cache may not reflect the new role until the session is refreshed or the cache expires.
Do not gate Custom Element UI on roleBriefs. Use a functional data check against your own object model instead — to confirm a user has a role, check whether they have records that prove it (a direct report, an account membership, an assignment). This is authoritative, always current, and degrades gracefully if the data model changes.
Success Signal
TODO / inferred — verify against a running bundle. Confirm the deployed CET manifests for its type via deploy-and-verify's Smoke Check on a live bundle.
04 同仓库更多 Skills
PromptScript 脚本编写与排查
promptscript
PromptScript 语言专家,用于读取、编写、修改和排查 .prs 文件。适用于处理 PromptScript 语法、创建或编辑 .prs 文件、添加 @identity、@standards、@restrictions、@shortcuts、@skills 或 @agents 等块、配置 promptscript.yaml、解决编译错误、理解继承(@inherit)、组合(@use、@extend、@override)、上下文 @header 元数据,或将 AI 指令迁移到 PromptScript。当用户询问 50 个内置编码智能体编译目标(包括 GitHub Copilot、Claude Code、Cursor、Antigravity、Factory AI 以及基于 AGENTS.md 的平台),或询问用于应用提示词的 bundle 和 prompt-text 目标时,也适用此技能。
基础专家技能
expert
基础专家技能。
测试驱动开发工作流
tdd-workflow
测试驱动开发(TDD)工作流。
Alpha 技能
alpha
Alpha 技能
PDF 文件处理
pdf-processing
提取 PDF 文本、填写表单、合并文件。用于处理 PDF 时。
React 组件编写规范
react-component-patterns
在此代码库中编写 React 组件的约定。