chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
12
third_party/pi/packages/codemode/src/identifier.ts
vendored
Normal file
12
third_party/pi/packages/codemode/src/identifier.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* The identifier a script uses for a tool: characters that are not valid in a JavaScript
|
||||
* identifier become `_`. `mcp__docs__search` stays as is, `my-tool` becomes `my_tool`.
|
||||
*/
|
||||
export function toCodemodeIdentifier(name: string): string {
|
||||
let identifier = "";
|
||||
for (const char of name) {
|
||||
const valid = identifier === "" ? /^[A-Za-z_$]$/.test(char) : /^[A-Za-z0-9_$]$/.test(char);
|
||||
identifier += valid ? char : "_";
|
||||
}
|
||||
return identifier === "" ? "_" : identifier;
|
||||
}
|
||||
Reference in New Issue
Block a user