Skip to content

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 PATH for machine-readable output). Counts are attribute-access occurrences (reads + calls), deterministic (sorted by count desc, then name).

What the scan measures ​

  1. KBEngine.<name> — every attribute access on the KBEngine module object (functions and constants alike).
  2. 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/position are built-in entity properties whose counts include ordinary client-side field reads — the number measures presence in code, not API "call" intensity.
  3. 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) ​

namecountnamecount
Entity33SERVER_ERR_NAME4
entities13SERVER_ERR_PASSWORD4
scriptLogType10deregisterReadFileDescriptor4
Proxy8publish4
SERVER_SUCCESS8registerReadFileDescriptor4
createEntityLocally6LOG_ON_ACCEPT, LOG_TYPE_* (5)2 each
EntityComponent4SERVER_ERR_LOCAL_PROCESSING2
accountLoginResponse2chargeResponse2
createAccountResponse2createEntity2

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.

membercountnote
id160built-in property; includes plain field reads
position130built-in property; movement/UI reads dominate
cell24base→cell remote handle
client18server→client broadcast handle
entities17registry lookups
spaceID12
addTimer8delTimer is never called in these trees — see patterns
destroy8
base6cell→base remote handle
destroyCellEntity4
moveToPoint4cell-face movement
createEntityLocally6client face
createCellEntity / createCellEntityInNewSpace2 eachcell creation pair
createSpace / giveClientTo / time2 each

Callbacks defined: engine-known vs project-defined ​

Engine-known groups (counts = definitions across both trees):

  • entity lifecycle: onDestroy 4, onGetCell 4, onLoseCell 4, onEnterSpace 4, onLeaveSpace 4, onEnterWorld 2
  • client/proxy lifecycle: onClientDeath 4, onClientEnabled 4, onLogOnAttempt 2
  • timer/trigger: onTimer 10 (the single most-defined engine callback)
  • entry script SPI: onInit 6, onTick 6, onReadyForShutDown 4, onRequestCreateAccount 4, plus 25 more at 2 each (ready/shutdown pairs per component, DB callbacks, interfaces request handlers)
  • global/space data: onGlobalData/onGlobalDataDel 4 each, the on*Data(Del) family and onSpaceData 2 each
  • project-defined: onMove/onMoveFailure/onMoveOver 6 each, onHPChanged, onLevelUp, onLoginOK 4 each, and 16 more at 2 each — these are game-logic handlers invoked by project code, not engine callbacks. Roughly a third of all def onXxx definitions 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: addTimer at 8 occurrences vs onTimer at 10 definitions — trees consistently implement onTimer(timerID, userArg) and dispatch on the timer identity (if userArg != TIMER_THINK: return, templates/assets/scripts/cell/Monster.py:139-145). Notably delTimer is never called (0 occurrences) even though 8 timers are added: consistent with the lifecycle article (timers are cancelled wholesale on destroy — the destroy() macro calls scriptTimers_.cancelAll(), entity_macro.h:1021 at kbengine@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 call delTimer — the demo trees never demonstrate this pattern.
  • Cell creation pair: createCellEntity/createCellEntityInNewSpace chosen per "entity already has a space?" — always followed by an onGetCell implementation (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/deregisterReadFileDescriptor always 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).

Kode documentation