skills/publish-nats-message/SKILL.md
Publish a NATS message conforming to a cross-team contract, using NATS MCP tools. Authors the contract on first use if missing. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting basics across sessions.
npx skillsauth add nesnilnehc/ai-cortex publish-nats-messageInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
让相互协作的项目能"正确生产消息"——按跨团队契约通过 NATS MCP 工具发布一条消息,确保 subject / headers / payload / QoS 严格对齐 specs/nats-messaging.md。首次某事件无契约时,引导生成契约并落盘 producer repo。
首要目标:通过 NATS MCP 工具发布一条符合 contract 的消息;契约不存在时先生成契约再发送。
成功标准:
.cortex/nats.yaml 已读取(不存在则引导生成)<event>-contract.md 已就位(存在则读取;不存在则起草并提示 commit)Nats-Msg-Id 为本次生成的 UUID v7(或同消息重试复用原 ID)验收测试:consumer 侧用 consume-nats-message 订阅同一 subject,能正确解码 headers + payload 且无校验失败。
本技能负责:
本技能不负责:
mcp__nats__publish / mcp__nats__jetstream_publish / mcp__nats__request 等工具;具体工具名以连接的 server 为准).cortex/nats.yaml 与契约文件)"我正在使用 publish-nats-message 技能发送一条 NATS 消息。"
.cortex/nats.yaml(producer repo 根目录)broker_url / service_source / default_stream / contract_dir / iac_owner.cortex/nats.yaml,提示用户 review 并 commit;后续步骤复用此次填的值<contract_dir>/**/<event>-contract.md询问最少必要信息(其他从缓存得到):
X-Correlation-Id 标条件必填,subject 内规划 sessionId 位置)<subject>.dlq、max_deliver=5、exponential backoff base 1s max 30s)生成契约文件:
<contract_dir>/<consumer>/<event>-contract.md(按 cross-team-contract.md §3 扁平布局)contract_version: 1.0.0 + CHANGELOG 首条 ### 1.0.0 — YYYY-MM-DD Initial Release完成后:
按契约填字段:
| 项 | 取值 |
|---|---|
| subject | 契约「契约范围」节定义的 subject |
| Nats-Msg-Id | 现场生成 UUID v7(重试时复用原 ID) |
| X-Source | 缓存 service_source |
| X-Type | 契约定义的事件类型字符串 |
| Traceparent | 若运行环境有 OTel context,注入;否则跳过 |
| X-Correlation-Id | 多轮会话场景必填,由调用方提供原 ID |
| X-Schema-Url | 契约定义 schema URL 时填 |
| payload | 用户提供的业务数据,按契约字段表逐字段校验(必填齐全、类型对、枚举值合法) |
校验失败 → 报错指出违规字段,不发送。
按 QoS 选用工具:
| 场景 | MCP 工具 | 备注 |
|---|---|---|
| at-most-once(telemetry / 心跳) | mcp__nats__publish | 无 ack,fire-and-forget |
| at-least-once(跨团队默认) | mcp__nats__jetstream_publish | 必须等 ack;触发 duplicate_window 去重 |
| 同步请求-响应(< 5s) | mcp__nats__request | 含 reply subject + X-Correlation-Id |
具体工具名以连接的 NATS MCP server 提供为准;如工具签名不一致,Skill 自适应映射(headers 参数 / subject 参数)。
Nats-Msg-Id(broker 端去重);达 max_deliver 仍失败 → 上报用户| 情况 | 处理 |
|---|---|
| MCP NATS server 未连接 | 提示用户检查 MCP 配置,列出期望工具名 |
| .cortex/nats.yaml 不存在 | 进入缓存初始化子流程(阶段 1) |
| 契约不存在 | 进入契约起草子流程(阶段 3) |
| Payload 字段校验失败 | 列出违规字段,要求修正后重发 |
| JetStream ack 超时 | 按契约 backoff 重试;最终失败上报用户 |
| Stream 不存在(Subject 域未 IaC 化) | 报错指出违反 specs/nats-messaging.md §5.5.2;提示联系 IaC 责任方 |
Nats-Msg-Id —— 必须复用,否则 broker 去重失效id / source / time 等)—— 必须走 Headersbroker_url / service_source 等基础信息development
Generate an LLM agent test suite (golden cases, mock-LLM unit tests, evaluator harness) from an agent implementation and its agent-test contract. Use when an agent has no tests, or a contract exists but the test code is missing.
development
After code changes, auto-detect the project's build system and local deployment method for a given directory, then build the project and restart its locally-deployed environment (Docker Compose / systemd / process manager). Never assumes — asks only when detection is ambiguous. Caches detected commands per project in .cortex/redeploy-local.yaml; re-invocations on the same project skip re-scanning until signal files change, the cache expires (30 days), or the skill version bumps.
tools
Drain pending NATS messages from a producer contract via NATS MCP tools (default batch / drain-style). Applies Tolerant Reader semantics and per-message ack/nak/term, returning aggregated stats. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting.
testing
Iteratively review changes, run automated tests, and apply targeted fixes until issues are resolved (or a stop condition is reached).