Skip to content

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

TypeScript

mods/telemetry: a Choice member may start with a digit; names and keys still start with a letter

poteat9f306ce9259b
diff --git a/mods/telemetry/hooks/entries/checked-value/checked-value.ts b/mods/telemetry/hooks/entries/checked-value/checked-value.ts
index 6b3da4a8..778b51ff 100644
--- a/mods/telemetry/hooks/entries/checked-value/checked-value.ts
+++ b/mods/telemetry/hooks/entries/checked-value/checked-value.ts
@@ -1,7 +1,7 @@
+import { CHOICE_TOKEN } from '../choice-token'
import { CHOICES_LIMIT } from '../choices-limit'
import { isRecord } from '../is-record'
import { refusal } from '../refusal'
-import { TOKEN } from '../token'
/**
* One property's value as it goes into the metadata: a finite number, a
@@ -49,7 +49,9 @@ export function checkedValue(
const isTokenList =
members.length > 0 &&
members.length <= CHOICES_LIMIT &&
- members.every(member => typeof member === 'string' && TOKEN.test(member))
+ members.every(
+ member => typeof member === 'string' && CHOICE_TOKEN.test(member),
+ )
if (!isTokenList) {
throw refusal(
diff --git a/mods/telemetry/hooks/entries/choice-token/choice-token.ts b/mods/telemetry/hooks/entries/choice-token/choice-token.ts
new file mode 100644
index 00000000..29479224
--- /dev/null
+++ b/mods/telemetry/hooks/entries/choice-token/choice-token.ts
@@ -0,0 +1,6 @@
+/**
+ * The shape of a Choice member: a snake_case token of at most 64 characters,
+ * which may start with a digit (a bucket such as `110_to_143`), unlike a name
+ * or a key (TOKEN).
+ */
+export const CHOICE_TOKEN = /^[a-z0-9][a-z0-9_]{0,63}$/
diff --git a/mods/telemetry/hooks/entries/choice-token/index.ts b/mods/telemetry/hooks/entries/choice-token/index.ts
new file mode 100644
index 00000000..6cccdbd5
--- /dev/null
+++ b/mods/telemetry/hooks/entries/choice-token/index.ts
@@ -0,0 +1,3 @@
+export * from './choice-token.js'
+
+export * as default from '.'
diff --git a/mods/telemetry/hooks/entries/index.ts b/mods/telemetry/hooks/entries/index.ts
index 915ff1fc..13bece5e 100644
--- a/mods/telemetry/hooks/entries/index.ts
+++ b/mods/telemetry/hooks/entries/index.ts
@@ -2,6 +2,7 @@ export * from './batch-of.js'
export * from './checked-fields.js'
export * from './checked-mark.js'
export * from './checked-value'
+export * from './choice-token'
export * from './choices-limit'
export * from './core-event-prefix'
export * from './event-prefix'
diff --git a/mods/telemetry/hooks/entries/token/token.ts b/mods/telemetry/hooks/entries/token/token.ts
index a37c3ea3..8767f4a1 100644
--- a/mods/telemetry/hooks/entries/token/token.ts
+++ b/mods/telemetry/hooks/entries/token/token.ts
@@ -1,5 +1,5 @@
/**
- * The shape of an event name, a property key and a Choice member: a
- * snake_case token of at most 64 characters, starting with a letter.
+ * The shape of an event name and a property key: a snake_case token of at
+ * most 64 characters, starting with a letter (a Choice member: CHOICE_TOKEN).
*/
export const TOKEN = /^[a-z][a-z0-9_]{0,63}$/
diff --git a/mods/telemetry/hooks/telemetry-types/choice/choice.ts b/mods/telemetry/hooks/telemetry-types/choice/choice.ts
index 42ebec36..c6ae243d 100644
--- a/mods/telemetry/hooks/telemetry-types/choice/choice.ts
+++ b/mods/telemetry/hooks/telemetry-types/choice/choice.ts
@@ -2,7 +2,7 @@
* A string property: the value and the list it is chosen from, declared
* beside it, so no free text reaches the row.
*
- * Every member of `of` is a snake_case token, at most CHOICES_LIMIT of
- * them; `value` is one of them.
+ * Every member of `of` is a snake_case token, which may start with a digit,
+ * at most CHOICES_LIMIT of them; `value` is one of them.
*/
export type Choice = { value: string; of: readonly string[] }