Files
deepseek-harness/packages/util/brand
Tianyi Cui 6d1870c8c1 Merge branch 'codex/simp-agent-entry-state' into codex/simp-unify-agent-session-id
# Conflicts:
#	docs/cordis-catalog/events.md
#	docs/cordis-catalog/services.md
#	docs/event-producer-consumer.md
#	docs/module-graph.md
#	packages/bash/tool-bash/src/index.ts
#	packages/ui/stdio-agent/README.md
#	packages/ui/stdio-agent/src/index.ts
#	packages/ui/stdio/src/index.ts
#	packages/workflow/workflow-workerthread/tests/workflow-workerthread.spec.ts
#	packages/workflow/workflow/package.json
#	scripts/gen-doc-graphs.ts
2026-07-15 16:24:43 +08:00
..
2026-07-15 11:28:45 +08:00

dsh-brand

The Branded<B> nominal-typing primitive — a tiny, type-only package (no runtime code, no harness-package dependency) shared by every package that owns a cross-boundary id.

What Branded is

A brand makes structurally-identical strings non-interchangeable at the type level: a SessionId cannot be passed where a CallId is expected, even though both are plain strings at runtime.

import type { Branded } from '@deepseek-ai/dsh-brand'

export type SessionId = Branded<'SessionId'>

/** Brand a string as a SessionId (a plain cast — zero runtime cost). */
export function SessionId(id: string): SessionId {
  return id as SessionId
}

Construction goes through the per-id factory in the OWNING package (a plain cast inside — zero runtime cost). Comparison, logging, JSON serialization, and the wire format all behave exactly as for an ordinary string; the brand is erased at compile time.

Policy: brand ids that cross package boundaries

A package brands the ids it OWNS — CallId in dsh-llm (tool-call correlation), the shared agent/session SessionId in dsh-session, and BashTaskId/OwnerToken in dsh-bash. Branding is for ids that cross package boundaries and could plausibly be confused; not every string needs a brand.

This package owns ONLY the primitive — no concrete id, no runtime code beyond the (erased) type. Keeping the primitive dependency-free is the point: a capability package can brand its ids without depending on an unrelated package. dsh-bash, for example, brands BashTaskId/OwnerToken by depending on dsh-brand alone — it never pulls in dsh-llm (or dsh-session) just to reach Branded.