Loading page
One script tag and one element. It asks questions, climbs a hint ladder, checks your code against catalogued practices, and keeps a skill and alignment record. Hosts can add renderers, actions and event listeners.
<script type="module" src="https://YOUR-HOST/buddy.js"></script>
<learning-buddy endpoint="https://YOUR-HOST/api/buddy"></learning-buddy>No framework, no dependencies, styles isolated in Shadow DOM. The round button in the corner of this page is the floating buddy; the panel below is the same element with mode="inline".
LearningBuddy.use({
name: "my-ide",
actions: [{ id: "copy", label: "Copy question", run: (api) => navigator.clipboard.writeText(api.state.q?.question ?? "") }],
on: (type, detail) => console.log("buddy", type, detail),
})
// from an editor: document.querySelector("learning-buddy").askAboutCode({ path, code })This page registers that plugin. Events it has seen:
The floating buddy on this page has select-to-ask. Select any part of this code and an "Ask buddy" pill appears; it sends the selection to the code check.
export function total(items: any[], tax, discount, currency, round, log) {
let sum = 0
for (const i of items) { if (i) { if (i.price) { sum += i.price } } }
console.log("total", sum)
return sum
}