How to Get Runtime Documentation Using the `help()` Function in Ego‑Lite
The help() function in ego-lite provides dynamic runtime documentation for all public helpers, returning formatted JSDoc signatures and descriptions either for specific helpers, multiple helpers, or the entire API surface when called without arguments.
Ego‑Lite is a specialized browser automation framework that exposes a sandboxed helper API to agent scripts. According to the citrolabs/ego-lite source code, every script executed via the Ego‑Browser binary receives a help() function through its helper context, enabling agents to introspect available methods without leaving the runtime environment.
Where the help() Function Lives in the Source Code
The help routine is attached to the helper façade that every script receives through helperContext() in package/ego-browser/src/helpers.ts. Inside this context, the property help is defined as a wrapper around the runtime implementation located in help-runtime.ts【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/helpers.ts#L36-LL48】.
When an agent script runs via the Ego‑Browser binary (e.g., ego-browser nodejs <<'EOF' … EOF), the helper object—including the help function—is injected directly into the script's scope. This allows agents to call await help() without importing any modules.
How Runtime Documentation Gets Embedded
During the build step, the documentation content is baked into the bundle. The scripts/build.mjs file injects a JSON string containing JSDoc‑generated documentation for all exported helpers. This string replaces the placeholder __EGO_EMBEDDED_HELP_DOCS__ inside package/ego-browser/src/help-runtime.ts【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/help-runtime.ts#L19-LL27】.
If the placeholder was not replaced—such as when loading raw TypeScript source—the parseEmbeddedDocs function returns an empty map. This allows the help() function to degrade gracefully rather than throwing errors【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/help-runtime.ts#L88-LL96】.
Using the help() Function in Agent Scripts
The helpRuntime implementation supports three calling patterns depending on how many arguments you provide.
Listing All Available Helpers
When called with no arguments, help() returns an array of documentation objects for every helper present in the embedded JSON map. Each entry is formatted as a human‑readable markdown‑style string containing parameters, return types, and signatures via the formatHelp utility【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/help-runtime.ts#L57-LL77】.
// List all available helpers with full JSDoc output
const all = await help();
console.log(all.join('\n\n'));
Querying Specific Helper Documentation
Passing a single string returns the documentation for that specific helper. If the name exists in the embedded docs, you receive the formatted HelperDoc object; otherwise, the function returns a friendly "Unknown helper" string.
// Get documentation for the 'click' helper
const clickDoc = await help('click');
console.log(clickDoc);
// Get documentation for the 'goto' helper
console.log(await help('goto'));
When you provide multiple arguments, help() returns an array of docs, inserting minimal placeholder strings for any unknown names.
// Query multiple helpers at once
const docs = await help('click', 'goto', 'snapshot');
console.log(docs.map(d => typeof d === 'string' ? d : d).join('\n\n'));
Getting Shortcut Descriptions for Main Facades
For quick overviews of the primary facades—page, locator, browser, taskSpaces, site, and fetch—the helperContext contains a hard‑coded map called FACADE_HELP. If help() receives exactly one of these keys, it returns the pre‑written description instead of the full JSDoc documentation【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/help-runtime.ts#L108-LL122】.
// Get a short description of the page façade
const pageDesc = await help('page');
console.log(pageDesc);
// Quick overview of taskSpaces
console.log(await help('taskSpaces'));
Understanding the helpRuntime Implementation
At the core of the system, helpRuntime receives the complete helpers object and an optional list of names. It builds a map of HelperDoc objects by parsing the embedded JSON string injected during the build process. The implementation handles three distinct scenarios:
- Empty argument list: Returns all available documentation entries.
- Single name: Returns the specific
HelperDocor an "Unknown helper" string. - Multiple names: Returns an array mixed with valid docs and placeholders for invalid names.
The formatHelp function assembles the final output by extracting parameter names, return types, and descriptions from the parsed JSDoc metadata, presenting them in a consistent markdown‑style format suitable for console output or logging.
Summary
- The
help()function is injected into every ego-lite script viahelperContext()inpackage/ego-browser/src/helpers.ts. - Documentation content originates from JSDoc comments and is embedded into the bundle at build time via
scripts/build.mjs, replacing the__EGO_EMBEDDED_HELP_DOCS__placeholder. - Calling
help()without arguments lists every available helper; passing names retrieves specific documentation or shortcut descriptions. - The system gracefully handles missing documentation by returning empty arrays or "Unknown helper" messages rather than throwing exceptions.
- Special facade keys (
page,locator,browser,taskSpaces,site,fetch) return hard‑coded shortcut descriptions instead of full JSDoc output.
Frequently Asked Questions
How do I call help() from within an ego-lite script?
You can invoke help() directly using await without any imports because the function is injected into your script's scope by the helperContext() mechanism when running inside the Ego‑Browser binary. Simply write await help() or await help('helperName') anywhere in your agent code.
What happens if I call help() when no documentation is embedded?
If the build placeholder __EGO_EMBEDDED_HELP_DOCS__ was not replaced—common when loading raw TypeScript source—the parseEmbeddedDocs function returns an empty map. In this case, help() returns an empty array when called without arguments, or "Unknown helper" strings when queried with specific names, ensuring the script continues running without errors【/cache/repos/github.com/citrolabs/ego-lite/main/package/ego-browser/src/help-runtime.ts#L88-LL96】.
Can I get documentation for multiple helpers at once?
Yes. Pass multiple string arguments to help(): await help('click', 'goto', 'fill'). The function returns an array where each element corresponds to the requested helper. Valid helpers return formatted documentation objects, while unknown names return placeholder strings indicating they were not found in the embedded documentation map.
Where does the documentation content originate?
The content comes from JSDoc comments written above helper function definitions in the TypeScript source. During the build process (scripts/build.mjs), these comments are extracted and serialized into a JSON string that replaces the __EGO_EMBEDDED_HELP_DOCS__ placeholder in help-runtime.ts, making the documentation available at runtime without requiring access to the original source files.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →