bianhaifeng789-hue/openclaw-config/branded-ids

Claude Code and agent skill by bianhaifeng789-hue/openclaw-config

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install bianhaifeng789-hue/openclaw-config/branded-ids

SKILL.md

The same SKILL.md was published earlier as bianhaifeng789-hue/openclaw-config/branded-ids.

Branded IDs Skill

品牌化ID类型 - Branded type + Compile-time safety + Pattern validation + Cast functions。

功能概述

从Claude Code的Branded ID系统提取的类型安全模式,用于OpenClaw的ID管理。

核心机制

Branded Type Pattern
typescript
export type SessionId = string & { readonly __brand: 'SessionId' }
export type AgentId = string & { readonly __brand: 'AgentId' }
// Nominal typing via brand
// Compile-time safety
// 防止ID混用
Cast Functions
typescript
export function asSessionId(id: string): SessionId {
return id as SessionId
}
export function asAgentId(id: string): AgentId {
return id as AgentId
}
// Use sparingly
// Prefer getSessionId()/createAgentId()
Pattern Validation
typescript
const AGENT_ID_PATTERN = /^a(?:.+-)?[0-9a-f]{16}$/
export function toAgentId(s: string): AgentId | null {
return AGENT_ID_PATTERN.test(s) ? (s as AgentId) : null
}
// a + optional label- + 16 hex chars
// null if doesn't match
Discriminator Usage
typescript
// AgentId presence indicates subagent context (not main session)
// When present, indicates the context is a subagent
// Compile-time type narrowing

实现建议

OpenClaw适配
  1. brandedType: Branded type pattern
  2. castFunctions: Cast functions
  3. patternValidation: Pattern validation
  4. compileTimeSafety: Compile-time safety
状态文件示例
json
{
"sessionId": "sess-123",
"agentId": "a-researcher-abc123def456",
"branded": true,
"patternValid": true
}

关键模式

Nominal Typing via Brand
string & { readonly __brand: 'SessionId' }
// 编译时区分
// 不混淆不同ID类型
Pattern-based Validation
toAgentId(s) → AgentId | null
// 验证格式
// 返回null而不是throw
Cast Sparingly
asAgentId(id) → prefer createAgentId()
// 少用cast
// 优先用factory

借用价值

  • ⭐⭐⭐⭐⭐ Branded type pattern
  • ⭐⭐⭐⭐ Pattern validation (return null)
  • ⭐⭐⭐⭐ Cast sparingly principle

来源

  • Claude Code: types/ids.ts
  • 分析报告: P39-2

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/bianhaifeng789-hue/openclaw-config/branded-ids/badge)](https://verified-skill.com/skills/bianhaifeng789-hue/openclaw-config/branded-ids)

Something wrong with this skill or its page? Tell us.