API usage patterns & frequency stats
KB-001 bucket ③. Generated by
scripts/kbe-api-scan.py(AST-based, stdlib only) on 2026-11-07 over the two script trees in this repository. Scope is honest: these are the in-repo trees — the vendored demo assets fixture (tests/fixtures/kbengine-demo-assets, 50 files) and the project template (templates/assets, 27 files) — 77 files total, 0 parse errors. This is not a real-project survey; widening to official sample projects and real codebases is future work and will be recorded here when done.Regenerate:
python3 scripts/kbe-api-scan.py tests/fixtures/kbengine-demo-assets templates/assets(add--json PATHfor machine-readable output). Counts are attribute-access occurrences (reads + calls), deterministic (sorted by count desc, then name).
What the scan measures
KBEngine.<name>— every attribute access on theKBEnginemodule object (functions and constants alike).- Entity API members —
X.<member>accesses where<member>exists in the C-21 API-docs library (crates/kode-server/assets/api-docs.json, 225 entries). Note the top rows:id/positionare built-in entity properties whose counts include ordinary client-side field reads — the number measures presence in code, not API "call" intensity. - Callbacks defined —
def onXxx(...)declarations, classified into engine-known groups (names verified against the knowledge pages: entity lifecycle, client/proxy lifecycle, timer/trigger, db/archive, global/space data, entry-script SPI) versus project-defined handlers (the engine never calls them; project code does).
KBEngine.<name> module usage (aggregated)
| name | count | name | count | |
|---|---|---|---|---|
Entity | 33 | SERVER_ERR_NAME | 4 | |
entities | 13 | SERVER_ERR_PASSWORD | 4 | |
scriptLogType | 10 | deregisterReadFileDescriptor | 4 | |
Proxy | 8 | publish | 4 | |
SERVER_SUCCESS | 8 | registerReadFileDescriptor | 4 | |
createEntityLocally | 6 | LOG_ON_ACCEPT, LOG_TYPE_* (5) | 2 each | |
EntityComponent | 4 | SERVER_ERR_LOCAL_PROCESSING | 2 | |
accountLoginResponse | 2 | chargeResponse | 2 | |
createAccountResponse | 2 | createEntity | 2 |
Reading: base-class inheritance (Entity/Proxy/EntityComponent) and the global registry entities dominate; the rest is login/interfaces plumbing (server error constants, *Response functions on interfaces faces) and the interfaces-face descriptor polling pair (registerReadFileDescriptor/deregisterReadFileDescriptor).
Entity API member usage (library members, aggregated)
Note: accesses via the module object (KBEngine.scriptLogType, KBEngine.createEntity, ...) count in both this table and the module table above — the scanner counts every X.<member> where <member> is in the library, whatever the receiver. Use this table for relative member popularity, not as an disjoint partition of calls.
| member | count | note |
|---|---|---|
id | 160 | built-in property; includes plain field reads |
position | 130 | built-in property; movement/UI reads dominate |
cell | 24 | base→cell remote handle |
client | 18 | server→client broadcast handle |
entities | 17 | registry lookups |
spaceID | 12 | |
addTimer | 8 | delTimer is never called in these trees — see patterns |
destroy | 8 | |
base | 6 | cell→base remote handle |
destroyCellEntity | 4 | |
moveToPoint | 4 | cell-face movement |
createEntityLocally | 6 | client face |
createCellEntity / createCellEntityInNewSpace | 2 each | cell creation pair |
createSpace / giveClientTo / time | 2 each |
Callbacks defined: engine-known vs project-defined
Engine-known groups (counts = definitions across both trees):
- entity lifecycle:
onDestroy4,onGetCell4,onLoseCell4,onEnterSpace4,onLeaveSpace4,onEnterWorld2 - client/proxy lifecycle:
onClientDeath4,onClientEnabled4,onLogOnAttempt2 - timer/trigger:
onTimer10 (the single most-defined engine callback) - entry script SPI:
onInit6,onTick6,onReadyForShutDown4,onRequestCreateAccount4, plus 25 more at 2 each (ready/shutdown pairs per component, DB callbacks, interfaces request handlers) - global/space data:
onGlobalData/onGlobalDataDel4 each, theon*Data(Del)family andonSpaceData2 each - project-defined:
onMove/onMoveFailure/onMoveOver6 each,onHPChanged,onLevelUp,onLoginOK4 each, and 16 more at 2 each — these are game-logic handlers invoked by project code, not engine callbacks. Roughly a third of alldef onXxxdefinitions in the trees are project-defined — a naming-convention trap worth knowing when reading unfamiliar KBEngine code (see the traps index).
Patterns worth copying (observed combinations)
- Timer discipline:
addTimerat 8 occurrences vsonTimerat 10 definitions — trees consistently implementonTimer(timerID, userArg)and dispatch on the timer identity (if userArg != TIMER_THINK: return,templates/assets/scripts/cell/Monster.py:139-145). NotablydelTimeris never called (0 occurrences) even though 8 timers are added: consistent with the lifecycle article (timers are cancelled wholesale on destroy — thedestroy()macro callsscriptTimers_.cancelAll(),entity_macro.h:1021atkbengine@3082ab5), so explicit cancellation only matters for cancelling early while the entity lives. A repeating timer that should stop on a condition before destroy must calldelTimer— the demo trees never demonstrate this pattern. - Cell creation pair:
createCellEntity/createCellEntityInNewSpacechosen per "entity already has a space?" — always followed by anonGetCellimplementation (4/4 in these trees). - Remote-handle direction:
cell(24) ≫base(6) — business logic drives the cell from the base;client(18) broadcast sits between. - Interfaces face: the polling pair
registerReadFileDescriptor/deregisterReadFileDescriptoralways appears together (4/4), matching the Poller pattern in the interfaces demo.
Feeding the pipeline
This scan is the bucket ③ input of the KB-001 pipeline (scan → curate → hover/MCP). The C-21 hover library priorities already reflect it implicitly; re-run the scan after tree changes and reconcile this page in the same batch (documents-only standing order: never let this page claim trees it did not scan).