2026-11-30 20:08:23 -08:00
// Fails when a built prompt names an agent product's tool by its product name,
// or bakes --web into a skill command.
2026-11-08 13:48:28 -08:00
//
// Prompts are read by many agents, and each one calls the same tool something
// else. Prompt text says what to do ("ask with the question tool", "list the
2026-11-30 20:08:23 -08:00
// folder") and never what one product's tool is called. Skill commands are
// printed bare so the person's saved terminal or web console default decides;
// a baked --web overrides it. This reads every Markdown file in the built
// skills/ tree, so run it after `node install.js --build-skills`.
2026-11-08 13:48:28 -08:00
// Usage: node scripts/check-prompt-wording.mjs [skillsDir] (defaults to ./skills)
import fs from "node:fs" ;
import path from "node:path" ;
import { fileURLToPath } from "node:url" ;
// Case-sensitive on purpose: "glob" and "grep" in lower case are ordinary words
// and command names, "Glob" and "Grep" as tool names are what this catches.
export const BANNED = [
"AskUserQuestion" ,
"Glob" ,
"Grep" ,
"TodoWrite" ,
"WebFetch" ,
"WebSearch" ,
"NotebookEdit" ,
"Read tool" ,
"Write tool" ,
"Edit tool" ,
"Bash tool" ,
"ask_user_question" ,
];
const PATTERN = new RegExp ( `(?<![A-Za-z0-9_])( ${ BANNED . join ( "|" ) } )(?![A-Za-z0-9_])` );
2026-11-30 20:08:23 -08:00
const BAKED_WEB_PATTERN = /`[^`\n]*\/plan2code[\w-]*[^`\n]*--web\b[^`\n]*`/g ;
2026-11-08 13:48:28 -08:00
function * markdownFiles ( dir ) {
for ( const entry of fs . readdirSync ( dir , { withFileTypes : true })) {
const full = path . join ( dir , entry . name );
if ( entry . isDirectory ()) yield * markdownFiles ( full );
else if ( entry . name . endsWith ( ".md" )) yield full ;
}
}
// Returns [{ file, line, name }] for every banned name found under dir.
export function findBanned ( dir ) {
const hits = [];
for ( const file of markdownFiles ( dir )) {
fs . readFileSync ( file , "utf8" )
. split ( "\n" )
. forEach (( text , i ) => {
const m = PATTERN . exec ( text );
if ( m ) hits . push ({ file : path . relative ( dir , file ). split ( path . sep ). join ( "/" ), line : i + 1 , name : m [ 1 ] });
});
}
return hits ;
}
2026-11-30 20:08:23 -08:00
// Returns [{ file, line, text }] for every skill command with --web baked in.
export function findBakedWeb ( dir ) {
const hits = [];
for ( const file of markdownFiles ( dir )) {
fs . readFileSync ( file , "utf8" )
. split ( "\n" )
. forEach (( lineText , i ) => {
for ( const m of lineText . matchAll ( BAKED_WEB_PATTERN )) {
hits . push ({ file : path . relative ( dir , file ). split ( path . sep ). join ( "/" ), line : i + 1 , text : m [ 0 ] });
}
});
}
return hits ;
}
2026-11-08 13:48:28 -08:00
if ( process . argv [ 1 ] && path . resolve ( process . argv [ 1 ]) === fileURLToPath ( import . meta . url )) {
const root = path . dirname ( path . dirname ( fileURLToPath ( import . meta . url )));
const dir = process . argv [ 2 ] ? path . resolve ( process . argv [ 2 ]) : path . join ( root , "skills" );
if ( ! fs . existsSync ( dir )) {
console . error ( ` FAIL ${ dir } does not exist. Run: node install.js --build-skills` );
process . exit ( 1 );
}
const hits = findBanned ( dir );
2026-11-30 20:08:23 -08:00
const baked = findBakedWeb ( dir );
2026-11-08 13:48:28 -08:00
if ( hits . length ) {
for ( const h of hits ) console . error ( ` FAIL ${ h . file } : ${ h . line } names a product tool: ${ h . name } ` );
console . error ( " Say what to do in neutral words (\"the question tool\", \"list the folder\")." );
2026-11-30 20:08:23 -08:00
} else {
console . log ( "Built prompts name no product tool." );
2026-11-08 13:48:28 -08:00
}
2026-11-30 20:08:23 -08:00
if ( baked . length ) {
for ( const h of baked ) console . error ( ` FAIL ${ h . file } : ${ h . line } bakes --web into a skill command: ${ h . text } ` );
console . error ( " Write the command bare and add \"(add `--web` for the web console)\" after it: a baked flag overrides the person's saved terminal or web console default." );
} else {
console . log ( "Built prompts bake no --web into skill commands." );
}
if ( hits . length || baked . length ) process . exit ( 1 );
2026-11-08 13:48:28 -08:00
}