repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

feat(ultra): auto-enable workflow tool from settings

9e23201fd8a564e3f2003b2e60367b96cff6d962

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (7)

CHANGELOG.md

Modified
11 11 - Change Tune's fullscreen shortcut to `Ctrl+Alt+T`
12 12 - Generate git-safe's fixed-executable wrapper on first Bash use and reuse it across reloads
13 13 - Defer unused extension implementations, PATH checks, settings reads, prompt loading, and RTK probes beyond startup and reload
14 -- Lazy-load Ultra execution, workflow discovery, settings, validation, and workflow tool registration when Ultra is first used
14 +- Lazy-load Ultra execution, workflow discovery, validation, and workflow tool registration until first use unless `ultra.auto_enable` is enabled
15 +- Let `ultra.auto_enable` activate Ultra's workflow tool when each session starts
15 16 - Retain Ultra sub-agent sessions as named parent-linked children, resume matching interrupted steps, and provide an explicit stateless opt-out
16 17 - Let Ultra load one static extension-name allowlist into every sub-agent while preserving `"all"` as the default
17 18 - Let loaded extensions activate their own Ultra sub-agent tools without extension-specific workflow tool names

extensions/ultra/README.md

Modified
105 105 | Key | Default | Meaning |
106 106 | ----------------------------- | ------- | ---------------------------------------------------------- |
107 107 | `ultra.enabled` | `true` | When false, the tool + command refuse to run. |
108 +| `ultra.auto_enable` | `false` | Enable `run_workflow` when each session starts. |
108 109 | `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. |
109 110 | `ultra.maxRetries` | `2` | Result-submission reminders after a missing output. |
110 111 | `ultra.subagentExtensions` | `"all"` | Load all, none, or a static extension-name list. |

extensions/ultra/__tests__/harness.test.ts

Modified
1 -import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
1 +import {
2 + mkdirSync,
3 + mkdtempSync,
4 + readFileSync,
5 + rmSync,
6 + writeFileSync,
7 +} from "node:fs";
8 +import { tmpdir } from "node:os";
2 9 import { join } from "node:path";
3 10 import { fileURLToPath } from "node:url";
4 11 import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
5 12 import {
6 - createTestSession,
13 + createTestSession as createHarnessSession,
7 14 type TestSession,
8 15 } from "@marcfargas/pi-test-harness";
9 16 import { afterEach, describe, expect, it, vi } from "vitest";
10 17 import { WorkflowSpecSchema } from "../spec.ts";
12 19 let t: TestSession | undefined;
20 +let root: string | undefined;
14 22 afterEach(() => {
15 23 t?.dispose();
24 + if (root) rmSync(root, { recursive: true, force: true });
16 25 t = undefined;
26 + root = undefined;
19 29 function ultraPath(): string {
20 30 return fileURLToPath(new URL("../index.ts", import.meta.url));
33 +async function createTestSession(options: {
34 + extensions: string[];
35 + cwd?: string;
36 +}): Promise<TestSession> {
37 + if (options.cwd) return createHarnessSession(options);
38 + root = mkdtempSync(join(tmpdir(), "ultra-harness-"));
39 + mkdirSync(join(root, ".pi"), { recursive: true });
40 + writeFileSync(
41 + join(root, ".pi", "settings.json"),
42 + JSON.stringify({ ultra: { auto_enable: false } }),
43 + );
44 + return createHarnessSession({ ...options, cwd: root });
23 47 function saveWorkflow(
24 48 session: TestSession,
25 49 name: string,
89 113 expect(extension.commands.has("ultra-runs")).toBe(false);
116 + it("auto-enables the workflow tool when configured", async () => {
117 + root = mkdtempSync(join(tmpdir(), "ultra-auto-enable-"));
118 + mkdirSync(join(root, ".pi"), { recursive: true });
119 + writeFileSync(
120 + join(root, ".pi", "settings.json"),
121 + JSON.stringify({ ultra: { auto_enable: true } }),
122 + );
124 + t = await createTestSession({ cwd: root, extensions: [ultraPath()] });
125 + const [extension] = t.session.extensionRunner.extensions;
127 + expect(extension.tools.has("run_workflow")).toBe(true);
128 + expect(t.session.getActiveToolNames()).toContain("run_workflow");
129 + expect(t.session.systemPrompt).toContain("- run_workflow:");
130 + });
92 132 it("completes subcommands first and saved workflows below run", async () => {
93 133 t = await createTestSession({ extensions: [ultraPath()] });
94 134 const [extension] = t.session.extensionRunner.extensions;

extensions/ultra/__tests__/settings.test.ts

Modified
10 10 it("matches the documented defaults", () => {
11 11 expect(ULTRA_DEFAULTS).toEqual({
12 12 enabled: true,
13 + autoEnable: false,
13 14 concurrency: 5,
14 15 maxRetries: 2,
15 16 subagentExtensions: "all",
25 +describe("auto_enable setting", () => {
26 + it("defaults to false and accepts booleans", () => {
27 + expect(ULTRA_DEFAULTS.autoEnable).toBe(false);
28 + expect(pickUltra({ ultra: { auto_enable: true } })).toEqual({
29 + autoEnable: true,
30 + });
31 + expect(pickUltra({ ultra: { auto_enable: "true" } })).toEqual({});
32 + });
34 + it("merges later valid values and ignores invalid ones", () => {
35 + expect(
36 + mergeUltraSettings({ autoEnable: true }, { autoEnable: false })
37 + .autoEnable,
38 + ).toBe(false);
39 + expect(mergeUltraSettings({ autoEnable: "yes" as never }).autoEnable).toBe(
40 + false,
41 + );
42 + });
43 +});
24 45 describe("subagentExtensions setting", () => {
25 46 it('defaults to "all"', () => {
26 47 expect(ULTRA_DEFAULTS.subagentExtensions).toBe("all");
126 147 concurrency: 8,
127 148 maxRetries: 1,
128 149 enabled: false,
150 + auto_enable: true,
129 151 actionSummarizerModel: " openai/gpt-5-mini ",
130 152 modelTiers: {
131 153 small: "openai/gpt-5-mini:low",
138 160 ).toEqual({
139 161 enabled: false,
162 + autoEnable: true,
140 163 concurrency: 8,
141 164 maxRetries: 1,
142 165 actionSummarizerModel: "openai/gpt-5-mini",
182 205 ).toEqual({
183 206 enabled: true,
207 + autoEnable: false,
184 208 concurrency: 9,
185 209 maxRetries: 4,
186 210 subagentExtensions: "all",
209 233 const merged = loadUltraSettings({
210 234 global: {
211 235 ultra: {
236 + auto_enable: true,
212 237 concurrency: 10,
213 238 actionSummarizerModel: "openai/gpt-5-mini",
214 239 modelTiers: { small: "openai/gpt-5-mini" },
225 250 expect(merged).toEqual({
226 251 enabled: true,
252 + autoEnable: true,
227 253 concurrency: 10,
228 254 maxRetries: 9,
229 255 subagentExtensions: "all",

extensions/ultra/implementation.ts

Modified
347 347 // ── `/ultra [exec | run]` command ──
348 348 return {
349 + activateWorkflowTool,
349 350 getArgumentCompletions: (prefix: string) =>
350 351 completeUltraCommand(discover(process.cwd()), prefix),
351 352 handleCommand: async (argString: string, ctx: ExtensionCommandContext) => {

extensions/ultra/index.ts

Modified
1 -// ultra entry point: keep startup limited to command and historical-result rendering.
1 +// ultra entry point: keep startup limited to command, result rendering, and the auto-enable check.
3 3 import type {
4 4 ExtensionAPI,
5 5 ExtensionCommandContext,
6 6 } from "@earendil-works/pi-coding-agent";
7 -import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
7 +import {
8 + getMarkdownTheme,
9 + SettingsManager,
10 +} from "@earendil-works/pi-coding-agent";
8 11 import { type AutocompleteItem, Markdown } from "@earendil-works/pi-tui";
9 12 import type { WorkflowResult } from "./engine.ts";
10 13 import { formatUltraResultMarkdown } from "./result.ts";
14 +import { loadUltraSettings } from "./settings.ts";
12 16 interface UltraRuntime {
17 + activateWorkflowTool(): void;
13 18 getArgumentCompletions(prefix: string): AutocompleteItem[] | null;
14 19 handleCommand(argString: string, ctx: ExtensionCommandContext): Promise<void>;
41 46 ({ createUltraRuntime }) => createUltraRuntime(pi),
49 + pi.on("session_start", async (_event, ctx) => {
50 + const manager = SettingsManager.create(ctx.cwd);
51 + const settings = loadUltraSettings({
52 + global: manager.getGlobalSettings(),
53 + project: manager.getProjectSettings(),
54 + });
55 + if (settings.enabled && settings.autoEnable)
56 + (await runtime()).activateWorkflowTool();
57 + });
44 59 pi.registerCommand("ultra", {
45 60 description:
46 61 "Enable ultra, execute workflow instructions, or run a saved workflow.",

extensions/ultra/settings.ts

Modified
9 9 export interface UltraSettings {
10 10 /** When false, the tool + command refuse to run. */
11 11 enabled: boolean;
12 + /** Activate `run_workflow` when the session starts. */
13 + autoEnable: boolean;
12 14 /** Max concurrent sub-agents in a `fanout` phase. */
13 15 concurrency: number;
14 16 /** Result-submission reminders after an agent stops without output. */
30 32 /** Documented defaults (design §Settings table). */
31 33 export const ULTRA_DEFAULTS: UltraSettings = {
32 34 enabled: true,
35 + autoEnable: false,
33 36 concurrency: 5,
34 37 maxRetries: 2,
35 38 subagentExtensions: "all",
64 67 if (!isPlainObject(ultra)) return {};
65 68 const out: Partial<UltraSettings> = {};
66 69 if (typeof ultra.enabled === "boolean") out.enabled = ultra.enabled;
70 + if (typeof ultra.auto_enable === "boolean")
71 + out.autoEnable = ultra.auto_enable;
67 72 if (typeof ultra.concurrency === "number")
68 73 out.concurrency = ultra.concurrency;
69 74 if (typeof ultra.maxRetries === "number") out.maxRetries = ultra.maxRetries;
104 109 return partials.reduce<UltraSettings>(
105 110 (into, p) => ({
106 111 enabled: typeof p.enabled === "boolean" ? p.enabled : into.enabled,
112 + autoEnable:
113 + typeof p.autoEnable === "boolean" ? p.autoEnable : into.autoEnable,
107 114 concurrency:
108 115 typeof p.concurrency === "number" ? p.concurrency : into.concurrency,
109 116 maxRetries: