@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
58 lines • 2.88 kB
JavaScript
import { basename } from "node:path";
import { resolveToCwd } from "../../../core/tools/path-utils.js";
import { findRenderers, grepRenderers, lsRenderers, readRenderers } from "../../../core/tools/renderers/index.js";
import { getCompactReadClassification } from "../../../core/tools/renderers/read.js";
import { getSkillReadPath } from "../../../core/tools/renderers/skill-read-path.js";
import { formatPathRelativeToCwdOrAbsolute } from "../../../utils/paths.js";
const BUILT_IN_RENDERERS = { read: readRenderers, grep: grepRenderers, find: findRenderers, ls: lsRenderers };
function stringArg(args, ...keys) {
if (args === null || typeof args !== "object")
return undefined;
for (const key of keys) {
const value = Reflect.get(args, key);
if (typeof value === "string" && value)
return value;
}
return undefined;
}
function isReadRenderArgs(args) {
return args !== null && typeof args === "object";
}
/** A skill load or a memory recall is a semantic card, not file exploration; it keeps its own line. */
function isSemanticRead(args, cwd) {
const kind = getCompactReadClassification(isReadRenderArgs(args) ? args : undefined, cwd)?.kind;
return kind === "skill" || kind === "memory";
}
/**
* Group only the built-in read/grep/find/ls presentation; custom renderers, semantic reads, and other
* tools stay cards.
*/
export function explorationCall(component) {
const { identity, state, presentation } = component.presentationSnapshot;
if (presentation !== "classic")
return undefined;
const toolName = identity.toolName;
if (toolName !== "read" && toolName !== "grep" && toolName !== "find" && toolName !== "ls")
return undefined;
const expected = BUILT_IN_RENDERERS[toolName];
const actual = identity.toolDefinition;
if (actual && (actual.renderCall !== expected.renderCall || actual.renderResult !== expected.renderResult)) {
return undefined;
}
const pending = state.isPartial;
const failed = state.result?.isError ?? false;
const path = stringArg(state.args, "file_path", "path");
if (toolName === "read") {
if (isSemanticRead(state.args, identity.cwd))
return undefined;
const label = path ? (getSkillReadPath(resolveToCwd(path, identity.cwd), identity.cwd) ?? basename(path)) : "";
return { action: "Read", label, pending, failed };
}
if (toolName === "grep") {
const pattern = stringArg(state.args, "pattern") ?? "";
const dir = path ? formatPathRelativeToCwdOrAbsolute(resolveToCwd(path, identity.cwd), identity.cwd) : "";
return { action: "Search", label: dir ? `${pattern} in ${dir}` : pattern, pending, failed };
}
return { action: "List", label: (path && basename(path)) || path || ".", pending, failed };
}
//# sourceMappingURL=exploration-call.js.map