|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/05/2026 |
| 5 | +entityCommandPack.js |
| 6 | +*/ |
| 7 | + |
| 8 | +import { |
| 9 | + requireAtLeastArgs, |
| 10 | + requireNoArgs, |
| 11 | + safeSection, |
| 12 | + standardDetails, |
| 13 | + toLinePair |
| 14 | +} from "./packUtils.js"; |
| 15 | + |
| 16 | +export function createEntityCommandPack() { |
| 17 | + return { |
| 18 | + packId: "entity", |
| 19 | + label: "Entities", |
| 20 | + description: "Entity counts and inspection commands.", |
| 21 | + commands: [ |
| 22 | + { |
| 23 | + name: "entity.count", |
| 24 | + summary: "Show active entity count.", |
| 25 | + usage: "entity.count", |
| 26 | + validate({ args, commandName }) { |
| 27 | + return requireNoArgs({ args, commandName }); |
| 28 | + }, |
| 29 | + handler(context) { |
| 30 | + const entities = safeSection(context, "entities"); |
| 31 | + return { |
| 32 | + title: "Entity Count", |
| 33 | + lines: [ |
| 34 | + toLinePair("count", entities.count ?? 0), |
| 35 | + toLinePair("heroState", entities.heroState ?? "unknown") |
| 36 | + ], |
| 37 | + details: standardDetails({ entities }), |
| 38 | + code: "ENTITY_COUNT" |
| 39 | + }; |
| 40 | + } |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "entity.list", |
| 44 | + summary: "List available entity summary fields.", |
| 45 | + usage: "entity.list", |
| 46 | + validate({ args, commandName }) { |
| 47 | + return requireNoArgs({ args, commandName }); |
| 48 | + }, |
| 49 | + handler(context) { |
| 50 | + const entities = safeSection(context, "entities"); |
| 51 | + const keys = Object.keys(entities).sort((left, right) => left.localeCompare(right)); |
| 52 | + return { |
| 53 | + title: "Entity List", |
| 54 | + lines: keys.length > 0 |
| 55 | + ? keys.map((key) => `${key}: ${String(entities[key])}`) |
| 56 | + : ["No entity summary data available."], |
| 57 | + details: standardDetails({ entities }), |
| 58 | + code: "ENTITY_LIST" |
| 59 | + }; |
| 60 | + } |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "entity.inspect", |
| 64 | + summary: "Inspect a specific entity summary field.", |
| 65 | + usage: "entity.inspect <field>", |
| 66 | + arguments: ["field"], |
| 67 | + validate({ args, commandName }) { |
| 68 | + return requireAtLeastArgs(1, { args, commandName }); |
| 69 | + }, |
| 70 | + handler(context, args) { |
| 71 | + const entities = safeSection(context, "entities"); |
| 72 | + const key = String(args[0] || ""); |
| 73 | + const value = entities[key]; |
| 74 | + if (value === undefined) { |
| 75 | + return { |
| 76 | + status: "failed", |
| 77 | + title: "Entity Inspect", |
| 78 | + lines: [`Field "${key}" not found.`], |
| 79 | + details: standardDetails({ entities, key }), |
| 80 | + code: "ENTITY_FIELD_NOT_FOUND" |
| 81 | + }; |
| 82 | + } |
| 83 | + return { |
| 84 | + title: "Entity Inspect", |
| 85 | + lines: [`${key}: ${String(value)}`], |
| 86 | + details: standardDetails({ key, value }), |
| 87 | + code: "ENTITY_INSPECT" |
| 88 | + }; |
| 89 | + } |
| 90 | + } |
| 91 | + ] |
| 92 | + }; |
| 93 | +} |
0 commit comments