InferHaven/agent-skills / codetrain
codetrain
FlaggedCodeTrain is an open-source Socratic coding tutor with a local lesson page where the learner writes every line while the agent sets small steps, gives hints and reviews the work without putting the solution into the lesson. Use when the user wants to be taught/walked through code one tiny step at a time — triggers like "teach me this code", "walk me through this", "hold my hand", "explain step by step", "tutor me", "guide me through", "I want to learn this", or asks for a safe practice exercise to learn a concept.
app/static/editor.js
View on GitHub/* CodeTrain — editor.
A reliable syntax-highlighting editor with NO runtime CDN: a transparent
<textarea> (rock-solid editing) layered over a Prism-highlighted <pre> that
scroll-syncs with it. Prism is vendored locally (prism.js), so there is nothing
to time out and it works offline. If Prism somehow isn't present, falls back to
a plain textarea. Same tiny API either way:
createEditor(mount, {doc, lang, onChange}) ->
{ getValue, setValue(doc), setLanguage(lang), focus(), kind }
*/
const LANG = { python: "python", py: "python", javascript: "javascript", js: "javascript", node: "javascript", bash: "bash", sh: "bash", shell: "bash" };
function grammar(l) { return LANG[(l || "").toLowerCase()] || "none"; }
function makePrism(mount, opts) {
mount.classList.add("cwrap");
mount.innerHTML = `
<div class="gutter" data-gutter aria-hidden="true">1</div>
<div class="celayers">
<pre class="chl" aria-hidden="true"><code></code></pre>
<textarea class="cinput" spellcheck="false" autocapitalize="off" autocomplete="off" autocorrect="off" wrap="off" aria-label="Code editor"></textarea>
</div>`;
const ta = mount.querySelector(".cinput");
const code = mount.querySelector(".chl code");
const pre = mount.querySelector(".chl");
const gutter = mount.querySelector("[data-gutter]");
let lang = opts.lang || "python";
function highlight() {
const v = ta.value;
const g = grammar(lang);
code.className = "language-" + g;
code.textContent = v + (v.endsWith("\n") ? " " : ""); // keep last line tall
const P = window.Prism;
if (P && P.languages[g]) P.highlightElement(code);
}
function gut() {
const n = Math.max(ta.value.split("\n").length, 1);
gutter.textContent = Array.from({ length: n }, (_, i) => i + 1).join("\n");
}
function syncScroll() { pre.scrollTop = ta.scrollTop; pre.scrollLeft = ta.scrollLeft; gutter.scrollTop = ta.scrollTop; }
ta.addEventListener("input", () => { highlight(); gut(); if (opts.onChange) opts.onChange(); });
ta.addEventListener("scroll", syncScroll);
ta.addEventListener("keydown", (e) => {
if (e.key === "Tab") {
e.preventDefault();
const s = ta.selectionStart, en = ta.selectionEnd;
ta.value = ta.value.slice(0, s) + " " + ta.value.slice(en);
ta.selectionStart = ta.selectionEnd = s + 4;
highlight(); gut(); if (opts.onChange) opts.onChange();
}
});
ta.value = opts.doc || "";
highlight(); gut();
return {
kind: "prism",
getValue: () => ta.value,
setValue: (d) => { ta.value = d || ""; highlight(); gut(); syncScroll(); },
setLanguage: (l) => { lang = l || lang; highlight(); },
focus: () => ta.focus(),
// Re-align the highlight <pre> + gutter to the textarea after a layout change
// (e.g. the full-page pop-out toggle), which fires no scroll/input event.
resync: () => { highlight(); gut(); syncScroll(); },
};
}
function makeTextarea(mount, opts) {
mount.innerHTML = '<div class="ta-wrap"><div class="gutter" data-gutter aria-hidden="true">1</div><textarea spellcheck="false" aria-label="Code editor"></textarea></div>';
const ta = mount.querySelector("textarea");
const gutter = mount.querySelector("[data-gutter]");
ta.value = opts.doc || "";
const sync = () => {
const n = Math.max(ta.value.split("\n").length, 1);
gutter.textContent = Array.from({ length: n }, (_, i) => i + 1).join("\n");
};
ta.addEventListener("input", () => { sync(); if (opts.onChange) opts.onChange(); });
ta.addEventListener("scroll", () => { gutter.scrollTop = ta.scrollTop; });
ta.addEventListener("keydown", (e) => {
if (e.key === "Tab") {
e.preventDefault();
const s = ta.selectionStart, en = ta.selectionEnd;
ta.value = ta.value.slice(0, s) + " " + ta.value.slice(en);
ta.selectionStart = ta.selectionEnd = s + 4;
sync();
}
});
sync();
return {
kind: "textarea",
getValue: () => ta.value,
setValue: (d) => { ta.value = d || ""; sync(); },
setLanguage: () => {},
focus: () => ta.focus(),
resync: () => { sync(); gutter.scrollTop = ta.scrollTop; },
};
}
export async function createEditor(mount, opts = {}) {
try {
if (window.Prism) return makePrism(mount, opts);
throw new Error("Prism not loaded");
} catch (e) {
console.warn("Prism overlay unavailable, using plain textarea:", e.message);
return makeTextarea(mount, opts);
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |