@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
75 lines • 2.81 kB
JavaScript
import { COLLAPSE_RULE_NAME, CONTROL_LEAK_RULE_NAME } from "./prompts.js";
import { COLLAPSE_REMEDIATION, CONTROL_LEAK_REMEDIATION, } from "./types.js";
const BUILTIN_RULES = [
{
name: COLLAPSE_RULE_NAME,
detector: "collapse",
remediation: COLLAPSE_REMEDIATION,
summary: "abort the stream, truncate the garbage from history, inject a corrective nudge, then continue",
},
{
name: CONTROL_LEAK_RULE_NAME,
detector: "control-leak",
remediation: CONTROL_LEAK_REMEDIATION,
summary: "abort the stream, replace the generation with an error shell, then resample via bounded provider retry",
},
];
export function registerTtsrCommands(pi, getState) {
pi.registerCommand("ttsr", {
description: "Show TTSR stream-rule status: builtin detectors, user rules, injected rules.",
handler: async (_args, ctx) => {
ctx.ui.notify(formatTtsrStatus(getState()), "info");
},
});
}
function formatTtsrStatus(state) {
const builtinRules = state.rules.filter((rule) => rule.source === "builtin");
const userRules = state.rules.filter((rule) => rule.source !== "builtin");
return [
"TTSR stream rules",
"",
"STATUS",
state.disabled ? "disabled (ttsr-disabled flag set)" : "enabled",
"",
"BUILTIN RULES",
"DETECTORS",
...BUILTIN_RULES.map(formatBuiltinRule),
"STREAM RULES",
...(builtinRules.length === 0 ? ["(none)"] : builtinRules.map(formatBuiltinStreamRule)),
"",
"USER RULES",
...formatUserRules(userRules),
"",
"INJECTED",
state.injectedRuleNames.length === 0 ? "(none)" : state.injectedRuleNames.join(", "),
].join("\n");
}
function formatBuiltinRule(rule) {
return [
`${rule.name} [detector: ${rule.detector}]`,
`remediation: ${rule.summary}`,
`(mode: ${rule.remediation.retryMode}, scope: ${rule.remediation.corruptionScope})`,
].join(" ");
}
function formatBuiltinStreamRule(rule) {
return `${rule.name} [stream rule, scope: ${formatScope(rule.scope)}]`;
}
function formatUserRules(rules) {
if (rules.length === 0)
return ["(none)"];
return rules.map((rule) => `${rule.name} [${rule.source}, scope: ${formatScope(rule.scope)}]`);
}
function formatScope(scope) {
const parts = [];
if (scope.allowText)
parts.push("text");
if (scope.allowThinking)
parts.push("thinking");
for (const toolScope of scope.toolScopes) {
parts.push(toolScope.pathGlob === undefined
? `tool:${toolScope.toolName}`
: `tool:${toolScope.toolName}(${toolScope.pathGlob})`);
}
return parts.length === 0 ? "none" : parts.join("+");
}
//# sourceMappingURL=commands.js.map