Agents/TUI: align with current pi APIs

This commit is contained in:
Gustavo Madeira Santana
2026-03-27 19:03:35 -04:00
parent c7fbd51890
commit 1fc4d7259f
12 changed files with 96 additions and 48 deletions

View File

@@ -56,7 +56,7 @@ describe("compaction retry integration", () => {
} as unknown as NonNullable<ExtensionContext["model"]>;
const invokeGenerateSummary = (signal = new AbortController().signal) =>
mockGenerateSummary(testMessages, testModel, 1000, "test-api-key", undefined, signal);
mockGenerateSummary(testMessages, testModel, 1000, "test-api-key", signal);
const runSummaryRetry = (options: Parameters<typeof retryAsync>[1]) =>
retryAsync(() => invokeGenerateSummary(), options);

View File

@@ -257,7 +257,6 @@ async function summarizeChunks(params: {
model,
params.reserveTokens,
params.apiKey,
undefined,
params.signal,
effectiveInstructions,
summary,

View File

@@ -1,7 +1,6 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { createSyntheticSourceInfo } from "@mariozechner/pi-coding-agent";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { installDownloadSpec } from "./skills-install-download.js";
import { setTempStateDir } from "./skills-install.download-test-utils.js";
@@ -61,11 +60,7 @@ function buildEntry(name: string): SkillEntry {
description: `${name} test skill`,
filePath: path.join(skillDir, "SKILL.md"),
baseDir: skillDir,
sourceInfo: createSyntheticSourceInfo(path.join(skillDir, "SKILL.md"), {
source: "openclaw-workspace",
scope: "project",
baseDir: skillDir,
}),
source: "openclaw-workspace",
disableModelInvocation: false,
},
frontmatter: {},

View File

@@ -1,4 +1,3 @@
import { createSyntheticSourceInfo } from "@mariozechner/pi-coding-agent";
import { describe, expect, it } from "vitest";
import { buildWorkspaceSkillStatus } from "./skills-status.js";
import type { SkillEntry } from "./skills/types.js";
@@ -18,10 +17,7 @@ describe("buildWorkspaceSkillStatus", () => {
description: "test",
filePath: "/tmp/os-scoped",
baseDir: "/tmp",
sourceInfo: createSyntheticSourceInfo("/tmp/os-scoped", {
source: "test",
baseDir: "/tmp",
}),
source: "test",
disableModelInvocation: false,
},
frontmatter: {},

View File

@@ -1,4 +1,3 @@
import { createSyntheticSourceInfo } from "@mariozechner/pi-coding-agent";
import { describe, expect, it } from "vitest";
import { withEnv } from "../test-utils/env.js";
import { buildWorkspaceSkillStatus } from "./skills-status.js";
@@ -25,11 +24,7 @@ function makeEntry(params: {
description: `desc:${params.name}`,
filePath: `/tmp/${params.name}/SKILL.md`,
baseDir: `/tmp/${params.name}`,
sourceInfo: createSyntheticSourceInfo(`/tmp/${params.name}/SKILL.md`, {
source: params.source ?? "openclaw-workspace",
scope: "project",
baseDir: `/tmp/${params.name}`,
}),
source: params.source ?? "openclaw-workspace",
disableModelInvocation: false,
},
frontmatter: {},

View File

@@ -1,4 +1,3 @@
import { createSyntheticSourceInfo } from "@mariozechner/pi-coding-agent";
import { describe, expect, it } from "vitest";
import { resolveSkillsPromptForRun } from "./skills.js";
import type { SkillEntry } from "./skills/types.js";
@@ -18,11 +17,7 @@ describe("resolveSkillsPromptForRun", () => {
description: "Demo",
filePath: "/app/skills/demo-skill/SKILL.md",
baseDir: "/app/skills/demo-skill",
sourceInfo: createSyntheticSourceInfo("/app/skills/demo-skill/SKILL.md", {
source: "openclaw-bundled",
scope: "project",
baseDir: "/app/skills/demo-skill",
}),
source: "openclaw-bundled",
disableModelInvocation: false,
},
frontmatter: {},

View File

@@ -1,9 +1,5 @@
import os from "node:os";
import {
createSyntheticSourceInfo,
formatSkillsForPrompt,
type Skill,
} from "@mariozechner/pi-coding-agent";
import { formatSkillsForPrompt, type Skill } from "@mariozechner/pi-coding-agent";
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import type { SkillEntry } from "./types.js";
@@ -19,11 +15,7 @@ function makeSkill(name: string, desc = "A skill", filePath = `/skills/${name}/S
description: desc,
filePath,
baseDir: `/skills/${name}`,
sourceInfo: createSyntheticSourceInfo(filePath, {
source: "workspace",
scope: "project",
baseDir: `/skills/${name}`,
}),
source: "workspace",
disableModelInvocation: false,
};
}

View File

@@ -1,5 +1,5 @@
import type { Skill } from "@mariozechner/pi-coding-agent";
export function resolveSkillSource(skill: Skill): string {
return skill.sourceInfo.source ?? "unknown";
return skill.source ?? "unknown";
}

View File

@@ -1,7 +1,6 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { createSyntheticSourceInfo } from "@mariozechner/pi-coding-agent";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { buildWorkspaceSkillStatus } from "../agents/skills-status.js";
import type { SkillEntry } from "../agents/skills.js";
@@ -39,11 +38,7 @@ describe("skills-cli (e2e)", () => {
description: "Capture UI screenshots",
filePath: path.join(baseDir, "SKILL.md"),
baseDir,
sourceInfo: createSyntheticSourceInfo(path.join(baseDir, "SKILL.md"), {
source: "openclaw-bundled",
scope: "project",
baseDir,
}),
source: "openclaw-bundled",
disableModelInvocation: false,
},
frontmatter: {},

View File

@@ -0,0 +1,81 @@
import { describe, expect, it } from "vitest";
import {
FilterableSelectList,
type FilterableSelectItem,
type FilterableSelectListTheme,
} from "./filterable-select-list.js";
const mockTheme: FilterableSelectListTheme = {
selectedPrefix: (t) => `[${t}]`,
selectedText: (t) => `**${t}**`,
description: (t) => `(${t})`,
scrollInfo: (t) => `~${t}~`,
noMatch: (t) => `!${t}!`,
filterLabel: (t) => `>${t}<`,
};
const testItems: FilterableSelectItem[] = [
{
value: "session-1",
label: "first session",
description: "Oldest",
searchText: "alpha",
},
{
value: "session-2",
label: "second session",
description: "Newest",
searchText: "beta",
},
];
describe("FilterableSelectList", () => {
function typeInput(list: FilterableSelectList, text: string) {
for (const ch of text) {
list.handleInput(ch);
}
}
it("clears the active filter before cancelling", () => {
const list = new FilterableSelectList(testItems, 5, mockTheme);
let cancelled = false;
list.onCancel = () => {
cancelled = true;
};
typeInput(list, "beta");
expect(list.getFilterText()).toBe("beta");
expect(list.getSelectedItem()?.value).toBe("session-2");
list.handleInput("\x1b");
expect(cancelled).toBe(false);
expect(list.getFilterText()).toBe("");
expect(list.render(80).join("\n")).toContain("first session");
expect(list.render(80).join("\n")).toContain("second session");
});
it("calls onCancel when escape is pressed with an empty filter", () => {
const list = new FilterableSelectList(testItems, 5, mockTheme);
let cancelled = false;
list.onCancel = () => {
cancelled = true;
};
list.handleInput("\x1b");
expect(cancelled).toBe(true);
});
it("calls onCancel when ctrl+c is pressed with an empty filter", () => {
const list = new FilterableSelectList(testItems, 5, mockTheme);
let cancelled = false;
list.onCancel = () => {
cancelled = true;
};
list.handleInput("\u0003");
expect(cancelled).toBe(true);
});
});

View File

@@ -1,7 +1,7 @@
import type { Component } from "@mariozechner/pi-tui";
import {
getEditorKeybindings,
Input,
getKeybindings,
matchesKey,
type SelectItem,
SelectList,
@@ -110,8 +110,8 @@ export class FilterableSelectList implements Component {
}
// Escape: clear filter or cancel
const kb = getKeybindings();
if (kb.matches(keyData, "tui.select.cancel")) {
const keybindings = getEditorKeybindings();
if (keybindings.matches(keyData, "selectCancel")) {
if (this.filterText) {
this.filterText = "";
this.input.setValue("");

View File

@@ -1,6 +1,6 @@
import {
type Component,
getKeybindings,
getEditorKeybindings,
Input,
isKeyRelease,
matchesKey,
@@ -362,8 +362,8 @@ export class SearchableSelectList implements Component {
return;
}
const kb = getKeybindings();
if (kb.matches(keyData, "tui.select.cancel")) {
const keybindings = getEditorKeybindings();
if (keybindings.matches(keyData, "selectCancel")) {
if (this.onCancel) {
this.onCancel();
}