Make the skill runbook limits a general setting

The longest runbook a skill may save and how much of it load_skill hands
back are now set on Settings > General (skill_body_max_chars,
skill_body_shown_chars), defaulting to AppData.SkillBodyMaxChars and
SkillBodyShownChars. Saving, confirming and proposing a skill check the
install's limit; a skill saved before it was lowered can still be toggled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 09:43:00 +01:00
co-authored by Claude Opus 5.5
parent 2408185a65
commit 373210c2a5
22 changed files with 421 additions and 28 deletions
@@ -6,6 +6,7 @@ import grabUserPasswordHash from "@/src/functions/backend/auth/grab-user-passwor
import type { PagePropsType } from "@/src/types";
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
import grabRunLimitsOverview from "@/src/functions/backend/db/app-settings/grab-run-limits";
import grabSkillLimitsOverview from "@/src/functions/backend/db/app-settings/grab-skill-limits";
import grabStorageQuotaOverview from "@/src/functions/backend/db/app-settings/grab-storage-quota-overview";
import { grabSystemPromptAppendOverview } from "@/src/functions/backend/db/app-settings/grab-system-prompt-append";
import runningVersion from "@/src/utils/running-version";
@@ -47,6 +48,7 @@ export default async function grabSettingsServerProps({ req }: Params) {
storage_quota: await grabStorageQuotaOverview().catch(() => null),
system_prompt_append: await grabSystemPromptAppendOverview().catch(() => null),
run_limits: await grabRunLimitsOverview().catch(() => null),
skill_limits: await grabSkillLimitsOverview().catch(() => null),
running_version: runningVersion({ env: process.env }),
},
};
@@ -0,0 +1,137 @@
import { useState } from "react";
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import Form from "@moduletrace/twui/form/Form";
import Input from "@moduletrace/twui/form/Input";
import Stack from "@moduletrace/twui/layout/Stack";
import type { SkillLimitsOverview } from "@/src/types";
import SettingsSaveBar from "../../(partials)/settings-save-bar";
type Props = {
limits?: SkillLimitsOverview | null;
};
/**
* The longest runbook a skill may save and how much of it a bot reads at
* once, saved on its own without a reload. Zero puts the code's default
* back for that one.
*/
export default function SkillLimitsForm({ limits }: Props) {
const [overview, setOverview] = useState(limits || undefined);
const [dirty, setDirty] = useState(false);
const [body_max_chars, setBodyMaxChars] = useState(String(limits?.body_max_chars ?? ""));
const [body_shown_chars, setBodyShownChars] = useState(String(limits?.body_shown_chars ?? ""));
/**
* The inputs only read `defaultValue` when they mount, so discarding or
* saving remounts them with the saved numbers.
*/
const [form_key, setFormKey] = useState(0);
const [loading, setLoading] = useState(false);
const [status, setStatus] = useState<{
msg?: string;
error?: boolean;
success?: boolean;
}>();
const save = async () => {
if (!window.confirm("Save the skill limits?")) return;
setLoading(true);
setStatus(undefined);
const res = await fetchApi<{}, APIResponseObject<SkillLimitsOverview>>(
"/api/admin/settings/skill-limits",
{
method: "POST",
body: {
body_max_chars: Number(body_max_chars) || 0,
body_shown_chars: Number(body_shown_chars) || 0,
},
},
).catch(() => null);
setLoading(false);
if (!res?.success || !res.singleRes) {
setStatus({
error: true,
msg: res?.msg || `Couldn't save the limits.`,
});
return;
}
setOverview(res.singleRes);
setBodyMaxChars(String(res.singleRes.body_max_chars));
setBodyShownChars(String(res.singleRes.body_shown_chars));
setFormKey((key) => key + 1);
setDirty(false);
setStatus({
success: true,
msg: `Saved: runbooks up to ${res.singleRes.body_max_chars} characters, ${res.singleRes.body_shown_chars} read at once.`,
});
};
const discard = () => {
setBodyMaxChars(String(overview?.body_max_chars ?? ""));
setBodyShownChars(String(overview?.body_shown_chars ?? ""));
setFormKey((key) => key + 1);
setDirty(false);
setStatus(undefined);
};
return (
<Form
onSubmit={(event) => {
event.preventDefault();
save().catch(() => {});
}}
className="w-full gap-3! items-stretch"
>
<Stack className="w-full gap-3! items-stretch">
<Input
key={`max-${form_key}`}
label="Longest runbook"
type="number"
min={0}
max={overview?.max}
step={1}
numberText
rawNumber
defaultValue={body_max_chars}
onChange={(event) => {
setBodyMaxChars(event.target.value);
setDirty(true);
setStatus(undefined);
}}
suffix={`characters`}
info={`How long a skill's runbook may be when it's saved or proposed. A skill already longer keeps working until its runbook is edited. 0 uses the default (${overview?.body_max_default ?? ""}).`}
/>
<Input
key={`shown-${form_key}`}
label="Runbook a bot reads at once"
type="number"
min={0}
max={overview?.max}
step={1}
numberText
rawNumber
defaultValue={body_shown_chars}
onChange={(event) => {
setBodyShownChars(event.target.value);
setDirty(true);
setStatus(undefined);
}}
suffix={`characters`}
info={`How much of a runbook a bot gets when it loads the skill; past that it's cut and the bot is told so. All of it goes into the model's context. 0 uses the default (${overview?.body_shown_default ?? ""}).`}
/>
</Stack>
<SettingsSaveBar
dirty={dirty}
loading={loading}
status={status}
save_label="Save limits"
onDiscard={discard}
/>
</Form>
);
}
@@ -0,0 +1,25 @@
import { useContext } from "react";
import { AppContext } from "@/src/pages/__root";
import isPassThroughUser from "@/src/utils/rbac/is-pass-through-user";
import SettingsGroup from "../../(partials)/settings-group";
import SkillLimitsForm from "../(partials)/skill-limits-form";
/**
* How long a skill's runbook may be, and how much of it a bot reads at
* once. Only the super admin sees it, since it changes every skill.
*/
export default function SkillLimitsSection() {
const { pageProps } = useContext(AppContext);
if (!isPassThroughUser({ user_types: pageProps?.user_types })) return null;
return (
<SettingsGroup
title="Skill limits"
description="How long a skill's runbook may be, and how much of it a bot reads when it loads the skill. A longer read costs more context on every load."
id="skill-limits"
>
<SkillLimitsForm limits={pageProps?.skill_limits} />
</SettingsGroup>
);
}
@@ -2,6 +2,7 @@ import AppearanceSection from "./(sections)/appearance-section";
import NotificationsSection from "./(sections)/notifications-section";
import PromptSection from "./(sections)/prompt-section";
import RunLimitsSection from "./(sections)/run-limits-section";
import SkillLimitsSection from "./(sections)/skill-limits-section";
import StorageSection from "./(sections)/storage-section";
import VersionSection from "./(sections)/version-section";
import SettingsShell from "../(partials)/settings-shell";
@@ -17,6 +18,7 @@ export default function AdminSettingsGeneralPage() {
<NotificationsSection />
<PromptSection />
<RunLimitsSection />
<SkillLimitsSection />
<StorageSection />
<VersionSection />
</SettingsShell>
@@ -6,15 +6,18 @@ import Form from "@moduletrace/twui/form/Form";
import Input from "@moduletrace/twui/form/Input";
import Textarea from "@moduletrace/twui/form/Textarea";
import CodeEditor from "@/src/components/general/code-editor";
import { AppData } from "@/src/data/app-data";
import postAdminApi from "@/src/layouts/bots/(functions)/post-admin-api";
import type { PublicSkill, SkillsOverviewPayload } from "@/src/types";
import type { PublicSkill, SkillLimitsOverview, SkillsOverviewPayload } from "@/src/types";
type Props = {
/**
* Edits this skill; adds one when not given.
*/
skill?: PublicSkill;
/**
* The install's runbook limits, for the hint.
*/
limits: SkillLimitsOverview;
onSaved: (overview: SkillsOverviewPayload, msg: string) => void;
onCancel: () => void;
};
@@ -24,7 +27,7 @@ type Props = {
* loads it by, the one line that tells the bot when it applies, and the
* runbook itself in markdown.
*/
export default function SkillModal({ skill, onSaved, onCancel }: Props) {
export default function SkillModal({ skill, limits, onSaved, onCancel }: Props) {
const [name, setName] = useState(skill?.name || "");
const [slug, setSlug] = useState(skill?.slug || "");
const [description, setDescription] = useState(skill?.description || "");
@@ -103,7 +106,7 @@ export default function SkillModal({ skill, onSaved, onCancel }: Props) {
className="h-80"
title="Runbook"
content={body}
info={`Markdown. The steps, the checks, and what good looks like. A bot reads it only when it loads the skill, up to ${AppData.SkillBodyShownChars} characters of it at a time.`}
info={`Markdown. The steps, the checks, and what good looks like. Up to ${limits.body_max_chars} characters. A bot reads it only when it loads the skill, up to ${limits.body_shown_chars} characters of it at a time.`}
onChange={(value) => setBody(value)}
/>
<Checkbox title="On" label="On: bots get it" checked={enabled} changeHandler={setEnabled} />
@@ -3,7 +3,7 @@ import Stack from "@moduletrace/twui/layout/Stack";
import { BookOpen } from "lucide-react";
import IconTile from "@/src/components/general/icon-tile";
import postAdminApi from "@/src/layouts/bots/(functions)/post-admin-api";
import type { ExtensionTargets, PublicSkill, SkillsOverviewPayload } from "@/src/types";
import type { ExtensionTargets, PublicSkill, SkillLimitsOverview, SkillsOverviewPayload } from "@/src/types";
import ExtensionAccessModal from "../../(partials)/extension-access-modal";
import SettingsListRow from "../../(partials)/settings-list-row";
import SettingsRowAction from "../../(partials)/settings-row-action";
@@ -13,6 +13,7 @@ import SkillModal from "./skill-modal";
type Props = {
skill: PublicSkill;
targets: ExtensionTargets;
limits: SkillLimitsOverview;
onChanged: (overview: SkillsOverviewPayload, msg: string) => void;
onError: (msg: string) => void;
};
@@ -21,7 +22,7 @@ type Props = {
* One skill: its slug and when it applies, and who gets it. Edit and Access
* open in a modal.
*/
export default function SkillRow({ skill, targets, onChanged, onError }: Props) {
export default function SkillRow({ skill, targets, limits, onChanged, onError }: Props) {
const [open, setOpen] = useState<"edit" | "access">();
const [busy, setBusy] = useState(false);
@@ -73,7 +74,7 @@ export default function SkillRow({ skill, targets, onChanged, onError }: Props)
) : null}
</SettingsListRow>
{open == "edit" ? (
<SkillModal skill={skill} onSaved={saved} onCancel={() => setOpen(undefined)} />
<SkillModal skill={skill} limits={limits} onSaved={saved} onCancel={() => setOpen(undefined)} />
) : null}
{open == "access" ? (
<ExtensionAccessModal<SkillsOverviewPayload>
@@ -41,6 +41,7 @@ export default function SkillsSettingsSection() {
>
{adding ? (
<SkillModal
limits={overview.limits}
onSaved={(next, msg) => {
setAdding(false);
changed(next, msg);
@@ -54,6 +55,7 @@ export default function SkillsSettingsSection() {
key={`${skill.id}-${version}`}
skill={skill}
targets={overview}
limits={overview.limits}
onChanged={changed}
onError={failed}
/>