Skip to content

Desktop app that records your on-screen work session and uses the GitHub Copilot SDK to reconstruct it as an intent + ordered steps, then builds a reusable Skill or Automation for Microsoft Autopilots like Scout, Microsoft Copilot Cowork, or Copilot Studio.

Add Scout automation builder alongside skills (#10)

adilei67186ba6dfa6
diff --git a/common/automation.ts b/common/automation.ts
new file mode 100644
index 0000000..9c163da
--- /dev/null
+++ b/common/automation.ts
@@ -0,0 +1,262 @@
+import { z } from "zod";
+
+import { SkillArchitecture, SkillInputSchema, slugifySkillName } from "./skill";
+
+/**
+ * The Automation Builder's contract — the automation-flavoured sibling of
+ * `skill.ts`. From an *approved* {@link Analysis} the multi-turn Copilot agent
+ * first proposes a **plan** ({@link AutomationPlan}) — a **trigger** (a schedule
+ * it proposes, refinable in natural language) plus the generalized, ordered
+ * **steps** (each a natural-language prompt to the target agent) — which the user
+ * refines. On confirmation the agent submits the final **built automation**
+ * ({@link BuiltAutomation}), which is rendered to Scout's import JSON and written
+ * into an importable bundle folder (Scout imports it; it is not auto-loaded like a
+ * skill). Kept separate from `analysis.ts` (the builder's *input*); this is the
+ * builder's *output*.
+ *
+ * The recorder-side schedule mirrors Scout's three kinds but omits the redundant
+ * top-level `hour`/`minute` mirror Scout's import schema also carries — the
+ * renderer fills that in {@link renderAutomationJson} so the emitted JSON validates
+ * against Scout's strict `AutomationScheduleSchema` without relying on its
+ * import-time schedule migration.
+ */
+
+/** A wall-clock time of day, 24-hour. */
+export const TimeOfDaySchema = z.object({
+ hour: z.number().int().min(0).max(23),
+ minute: z.number().int().min(0).max(59),
+});
+export type TimeOfDay = z.infer<typeof TimeOfDaySchema>;
+
+/** Days of the week the schedule fires on (0 = Sunday … 6 = Saturday). */
+export const DaysSchema = z.array(z.number().int().min(0).max(6));
+
+/** The generated schedule. One of Scout's three kinds; `naturalLanguage` is the
+ * human phrasing shown in the plan and refined by the user. */
+export const AutomationScheduleSchema = z.discriminatedUnion("kind", [
+ z.object({
+ kind: z.literal("single"),
+ naturalLanguage: z.string().default(""),
+ days: DaysSchema.default([]),
+ /** The single time of day it runs. */
+ time: TimeOfDaySchema,
+ }),
+ z.object({
+ kind: z.literal("interval"),
+ naturalLanguage: z.string().default(""),
+ days: DaysSchema.default([]),
+ /** Minutes between runs; must divide a day (1440) evenly. */
+ intervalMinutes: z
+ .number()
+ .int()
+ .positive()
+ .refine((m) => m <= 1440 && 1440 % m === 0, {
+ message: "intervalMinutes must divide 1440 evenly",
+ }),
+ /** The first run of the day (the interval anchor). */
+ anchor: TimeOfDaySchema,
+ }),
+ z.object({
+ kind: z.literal("multi"),
+ naturalLanguage: z.string().default(""),
+ days: DaysSchema.default([]),
+ /** Two or more times of day it runs. */
+ times: z.array(TimeOfDaySchema).min(1),
+ }),
+]);
+export type AutomationSchedule = z.infer<typeof AutomationScheduleSchema>;
+
+/** How an automation is triggered. `schedule` is always present (for condition
+ * triggers it is the check cadence); `condition` gates a run when set. */
+export const AutomationTriggerType = z.enum(["schedule", "condition"]);
+export type AutomationTriggerType = z.infer<typeof AutomationTriggerType>;
+
+export const AutomationTriggerSchema = z.object({
+ type: AutomationTriggerType.default("schedule"),
+ schedule: AutomationScheduleSchema,
+ /** Natural-language condition to check before running (condition triggers only). */
+ condition: z.string().default(""),
+ /** How often (minutes) to re-check the condition. */
+ conditionCheckInterval: z.number().int().positive().optional(),
+});
+export type AutomationTrigger = z.infer<typeof AutomationTriggerSchema>;
+
+/** One generalized step of the automation: a short label + the NL prompt the agent runs. */
+export const AutomationStepDraftSchema = z.object({
+ /** Short label for the step, e.g. "Collect new leads". */
+ label: z.string().default(""),
+ /** The natural-language instruction to the target agent for this step. */
+ prompt: z.string(),
+});
+export type AutomationStepDraft = z.infer<typeof AutomationStepDraftSchema>;
+
+/**
+ * The agent's proposed plan, shown to the user before any automation is written.
+ * This is what `propose_automation_plan` submits and what the user refines in NL.
+ */
+export const AutomationPlanSchema = z.object({
+ /** Target architecture this plan is written for. */
+ architecture: SkillArchitecture,
+ /** kebab-case automation id, e.g. "daily-lead-digest". */
+ name: z.string().transform(slugifySkillName),
+ /** Human-friendly title, e.g. "Daily lead digest". */
+ title: z.string(),
+ /** What the automation does (becomes the automation `description`). */
+ description: z.string(),
+ /** Plain-language summary of what it does. */
+ summary: z.string().default(""),
+ /** How the recorded specifics are generalized into a repeatable procedure. */
+ generalization: z.string().default(""),
+ /** The proposed trigger (schedule + optional condition). */
+ trigger: AutomationTriggerSchema,
+ /** Inputs the automation needs and where each comes from (informational; the
+ * automation resolves them inside its step prompts). */
+ inputs: z.array(SkillInputSchema).default([]),
+ /** The generalized procedure, as ordered label + prompt steps. */
+ steps: z.array(AutomationStepDraftSchema).default([]),
+ /** Optional per-automation model override. */
+ model: z.string().default(""),
+ /** Built-in Scout skills the steps rely on (for the user's awareness). */
+ skillNames: z.array(z.string()).default([]),
+});
+export type AutomationPlan = z.infer<typeof AutomationPlanSchema>;
+
+/**
+ * The payload the agent submits via `submit_automation` once the plan is approved.
+ * The engine renders this into Scout's import JSON and wraps it into a
+ * {@link BuiltAutomation}.
+ */
+export const AutomationSubmissionSchema = z.object({
+ /** kebab-case automation id. */
+ name: z.string().transform(slugifySkillName),
+ /** The automation `description`. */
+ description: z.string().default(""),
+ triggerType: AutomationTriggerType.default("schedule"),
+ schedule: AutomationScheduleSchema,
+ condition: z.string().default(""),
+ conditionCheckInterval: z.number().int().positive().optional(),
+ model: z.string().default(""),
+ /** The generalized, ordered steps (each an NL prompt). */
+ steps: z.array(AutomationStepDraftSchema).min(1),
+});
+export type AutomationSubmission = z.infer<typeof AutomationSubmissionSchema>;
+
+/** The full, persisted result of an automation build for a session. */
+export const BuiltAutomationSchema = z.object({
+ version: z.literal(1),
+ sessionId: z.string(),
+ kind: z.literal("automation"),
+ architecture: SkillArchitecture,
+ name: z.string(),
+ description: z.string().default(""),
+ triggerType: AutomationTriggerType,
+ schedule: AutomationScheduleSchema,
+ condition: z.string().default(""),
+ conditionCheckInterval: z.number().int().positive().optional(),
+ model: z.string().default(""),
+ steps: z.array(AutomationStepDraftSchema),
+ /** The plan the automation was built from (for the UI / re-export). */
+ plan: AutomationPlanSchema.nullable().default(null),
+ createdAt: z.number(),
+ /** Absolute path of the exported automation.json, once exported. */
+ exportedPath: z.string().optional(),
+ exportedAt: z.number().optional(),
+});
+export type BuiltAutomation = z.infer<typeof BuiltAutomationSchema>;
+
+/** Build a full BuiltAutomation from an agent submission + engine-managed fields. */
+export function toBuiltAutomation(
+ sessionId: string,
+ architecture: SkillArchitecture,
+ submission: AutomationSubmission,
+ plan: AutomationPlan | null,
+): BuiltAutomation {
+ return BuiltAutomationSchema.parse({
+ version: 1,
+ sessionId,
+ kind: "automation",
+ architecture,
+ name: slugifySkillName(submission.name),
+ description: submission.description,
+ triggerType: submission.triggerType,
+ schedule: submission.schedule,
+ condition: submission.condition,
+ conditionCheckInterval: submission.conditionCheckInterval,
+ model: submission.model,
+ steps: submission.steps,
+ plan,
+ createdAt: Date.now(),
+ });
+}
+
+/** The primary time of day for a schedule — the value Scout mirrors into the
+ * schedule's top-level `hour`/`minute`. */
+function primaryTime(schedule: AutomationSchedule): TimeOfDay {
+ switch (schedule.kind) {
+ case "single":
+ return schedule.time;
+ case "interval":
+ return schedule.anchor;
+ case "multi":
+ return schedule.times[0];
+ }
+}
+
+/** Convert a recorder schedule into Scout's strict import schedule shape (adds the
+ * redundant top-level `hour`/`minute` mirror Scout's schema requires). */
+function scheduleToScout(schedule: AutomationSchedule): Record<string, unknown> {
+ const t = primaryTime(schedule);
+ const base = {
+ naturalLanguage: schedule.naturalLanguage,
+ days: schedule.days,
+ hour: t.hour,
+ minute: t.minute,
+ };
+ switch (schedule.kind) {
+ case "single":
+ return { kind: "single", ...base, time: schedule.time };
+ case "interval":
+ return { kind: "interval", ...base, intervalMinutes: schedule.intervalMinutes, anchor: schedule.anchor };
+ case "multi":
+ return { kind: "multi", ...base, times: schedule.times };
+ }
+}
+
+/**
+ * Shape a {@link BuiltAutomation} into the plain object Scout's `AutomationImportSchema`
+ * accepts (`workingDir`/`skillNames` are injected by Scout at import time from the
+ * bundle context, so they are intentionally omitted here).
+ */
+export function toAutomationImport(a: BuiltAutomation): Record<string, unknown> {
+ const obj: Record<string, unknown> = {
+ name: slugifySkillName(a.name),
+ description: a.description,
+ triggerType: a.triggerType,
+ schedule: scheduleToScout(a.schedule),
+ steps: a.steps.map((s) => ({ label: s.label, prompt: s.prompt })),
+ };
+ if (a.triggerType === "condition" && a.condition) obj.condition = a.condition;
+ if (a.conditionCheckInterval) obj.conditionCheckInterval = a.conditionCheckInterval;
+ if (a.model) obj.model = a.model;
+ return obj;
+}
+
+/** Render a {@link BuiltAutomation} to the `automation.json` text Scout imports. */
+export function renderAutomationJson(a: BuiltAutomation): string {
+ return JSON.stringify(toAutomationImport(a), null, 2) + "\n";
+}
+
+/** A human one-liner describing a schedule, for the plan/done UI. */
+export function describeSchedule(schedule: AutomationSchedule): string {
+ if (schedule.naturalLanguage.trim()) return schedule.naturalLanguage.trim();
+ const t = primaryTime(schedule);
+ const time = `${String(t.hour).padStart(2, "0")}:${String(t.minute).padStart(2, "0")}`;
+ switch (schedule.kind) {
+ case "single":
+ return `Once a day at ${time}`;
+ case "interval":
+ return `Every ${schedule.intervalMinutes} min from ${time}`;
+ case "multi":
+ return `${schedule.times.length}× a day`;
+ }
+}
diff --git a/common/ipc.ts b/common/ipc.ts
index 0a9df8a..d351acc 100644
--- a/common/ipc.ts
+++ b/common/ipc.ts
@@ -1,4 +1,5 @@
import type { Analysis, AnalysisFeedback, Confidence } from "./analysis";
+import type { AutomationPlan, BuiltAutomation } from "./automation";
import type { BuiltSkill, SkillArchitecture, SkillPlan } from "./skill";
import type { RecorderState } from "./types";
@@ -20,6 +21,8 @@ export interface SessionSummary {
hasVideo: boolean;
/** True once a skill has been built and persisted for this session. */
hasSkill: boolean;
+ /** True once an automation has been built and persisted for this session. */
+ hasAutomation: boolean;
/** Present once the describer has produced an analysis for this session. */
analysis: {
revision: number;
@@ -101,6 +104,40 @@ export interface SkillCreateResult {
error?: string;
}
+/* --- Automation Builder --------------------------------------------------- */
+
+/** Streamed to the renderer while the automation-builder agent works. */
+export interface AutomationBuildProgress {
+ sessionId: string;
+ phase: "start" | "working" | "drafting" | "done" | "error";
+ message: string;
+}
+
+/** Start an automation build (or refine one) for a session's analysis. */
+export interface AutomationBuildInput {
+ sessionId: string;
+ /** Target architecture (only "scout" is enabled today). */
+ architecture: SkillArchitecture;
+ /** Natural-language refinement for the current plan; omit for the first pass. */
+ feedback?: string;
+}
+
+/** Result of a propose/refine round: the automation plan to show the user. */
+export interface AutomationPlanResult {
+ ok: boolean;
+ plan?: AutomationPlan;
+ error?: string;
+}
+
+/** Result of finalizing + exporting an automation bundle. */
+export interface AutomationCreateResult {
+ ok: boolean;
+ automation?: BuiltAutomation;
+ /** Absolute path of the exported automation.json. */
+ path?: string;
+ error?: string;
+}
+
export interface StartResult {
ok: boolean;
sessionId?: string;
@@ -193,6 +230,12 @@ export const IPC = {
cancelSkill: "skill:cancel",
revealSkill: "skill:reveal",
skillProgress: "skill:progress",
+ buildAutomation: "automation:build",
+ createAutomation: "automation:create",
+ getAutomation: "automation:get",
+ cancelAutomation: "automation:cancel",
+ revealAutomation: "automation:reveal",
+ automationProgress: "automation:progress",
openLibrary: "ui:open-library",
closeLibrary: "ui:close-library",
} as const;
@@ -235,6 +278,20 @@ export interface SkillRecorderApi {
/** Reveal a session's exported SKILL.md in the OS file manager. */
revealSkill(sessionId: string): Promise<{ ok: boolean }>;
onSkillProgress(cb: (progress: SkillBuildProgress) => void): () => void;
+ /**
+ * Propose (or refine) an automation from a recording's analysis. Pass `feedback`
+ * to revise the current plan in the same multi-turn conversation.
+ */
+ buildAutomation(input: AutomationBuildInput): Promise<AutomationPlanResult>;
+ /** Finalize the proposed automation and export its importable bundle. */
+ createAutomation(sessionId: string): Promise<AutomationCreateResult>;
+ /** Load a previously built automation for a session, if any. */
+ getAutomation(sessionId: string): Promise<BuiltAutomation | null>;
+ /** Abort an in-flight automation build. */
+ cancelAutomation(sessionId: string): Promise<{ ok: boolean }>;
+ /** Reveal a session's exported automation bundle in the OS file manager. */
+ revealAutomation(sessionId: string): Promise<{ ok: boolean }>;
+ onAutomationProgress(cb: (progress: AutomationBuildProgress) => void): () => void;
/** Open (and focus) the Sessions library window, docked to the recorder. */
openLibrary(): Promise<void>;
/** Close the Sessions library window from within it. */
diff --git a/common/skill.ts b/common/skill.ts
index 79125e4..aa47984 100644
--- a/common/skill.ts
+++ b/common/skill.ts
@@ -31,6 +31,59 @@ export const ARCHITECTURES: readonly ArchitectureOption[] = [
{ id: "copilot-studio", label: "Copilot Studio", enabled: false, note: "Coming soon." },
] as const;
+/**
+ * The kind of artifact the builder produces from an approved analysis. A **skill**
+ * is an on-demand, description-triggered `SKILL.md`; an **automation** is a
+ * scheduled/condition-triggered, multi-step procedure. The two are built by
+ * separate final-stage agents because their plans have different shapes.
+ */
+export const BuildKind = z.enum(["skill", "automation"]);
+export type BuildKind = z.infer<typeof BuildKind>;
+
+/** One selectable option in the "What do you want to build?" target picker. */
+export interface BuildTarget {
+ kind: BuildKind;
+ architecture: SkillArchitecture;
+ /** Card label, e.g. "Scout automation". */
+ label: string;
+ /** Enabled targets can be built today; the rest are shown greyed out. */
+ enabled: boolean;
+ /** One-line note shown under the option. */
+ note: string;
+}
+
+/**
+ * The build targets shown up front, in order. Only Scout is wired today, so its
+ * skill and automation targets are enabled; the other architectures are shown as
+ * a single greyed "coming soon" card each (their `kind` is nominal — they can't be
+ * selected). Automations are deeply platform-specific, so the target — not just the
+ * architecture — is chosen before the builder plans.
+ */
+export const TARGETS: readonly BuildTarget[] = [
+ {
+ kind: "skill",
+ architecture: "scout",
+ label: "Scout skill",
+ enabled: true,
+ note: "An on-demand skill Scout runs when its description matches the task.",
+ },
+ {
+ kind: "automation",
+ architecture: "scout",
+ label: "Scout automation",
+ enabled: true,
+ note: "A scheduled, multi-step automation Scout runs on a trigger.",
+ },
+ { kind: "skill", architecture: "cowork", label: "Cowork", enabled: false, note: "Coming soon." },
+ {
+ kind: "skill",
+ architecture: "copilot-studio",
+ label: "Copilot Studio",
+ enabled: false,
+ note: "Coming soon.",
+ },
+] as const;
+
/**
* Where a skill's input comes from at run time. Kept deliberately small:
* - **ask** — the skill asks the user for it when it runs (a path, URL, value).
diff --git a/electron/automationbuilder/builder.ts b/electron/automationbuilder/builder.ts
new file mode 100644
index 0000000..88d3d75
--- /dev/null
+++ b/electron/automationbuilder/builder.ts
@@ -0,0 +1,261 @@
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import os from "node:os";
+import path from "node:path";
+
+import { approveAll, type CopilotSession } from "@github/copilot-sdk";
+
+import {
+ BuiltAutomationSchema,
+ renderAutomationJson,
+ toBuiltAutomation,
+ type AutomationPlan,
+ type AutomationSubmission,
+ type BuiltAutomation,
+} from "../../common/automation";
+import type { AutomationBuildInput, AutomationBuildProgress } from "../../common/ipc";
+import { slugifySkillName, type SkillArchitecture } from "../../common/skill";
+import { AgentBuilder, type BaseLive } from "../builders/agent-builder";
+import { createReadTools } from "../builders/read-tools";
+import { loadPersistedAnalysis } from "../describer/describer";
+import { createLogger } from "../logger";
+import { isValidSessionId, sessionDir } from "../recorder/session-store";
+import { AUTOMATION_BUILDER_INSTRUCTIONS } from "./instructions";
+import { automationCatalogueFor } from "./scout-automation-catalog";
+import { createAutomationBuilderTools } from "./tools";
+
+const log = createLogger("AutomationBuilder");
+
+const TURN_TIMEOUT_MS = 180_000;
+
+const KICKOFF_PROMPT =
+ "Read get_analysis (and get_timeline where the tool mapping or schedule needs evidence), then call " +
+ "propose_automation_plan with how you'll generalize this task, a sensible default schedule, and the " +
+ "generalized prompt-steps. Stop after propose_automation_plan so the user can review it.";
+
+const CREATE_PROMPT =
+ "The user approved the plan. Now call submit_automation with the final name, description, trigger " +
+ "(triggerType + schedule), and the generalized ordered prompt-steps.";
+
+const msg = (err: unknown) => (err instanceof Error ? err.message : String(err));
+
+/** Root folder automation bundles are exported into (overridable for dev/tests). */
+function automationsRoot(): string {
+ const override = process.env.SKILL_RECORDER_AUTOMATIONS_DIR;
+ if (override) return path.resolve(override);
+ return path.join(os.homedir(), ".copilot", "automations");
+}
+
+interface LiveBuild extends BaseLive {
+ sessionDir: string;
+ architecture: SkillArchitecture;
+ copilot: CopilotSession;
+ holder: { plan: AutomationPlan | undefined; submission: AutomationSubmission | undefined };
+ /** Last plan proposed this build (kept so submit can reference it). */
+ lastPlan: AutomationPlan | null;
+}
+
+function readJson<T>(file: string): T | null {
+ if (!existsSync(file)) return null;
+ try {
+ return JSON.parse(readFileSync(file, "utf8")) as T;
+ } catch {
+ return null;
+ }
+}
+
+/** Load a previously built + persisted automation for a session, if any. */
+export function loadPersistedAutomation(sessionId: string): BuiltAutomation | null {
+ if (!isValidSessionId(sessionId)) return null;
+ const raw = readJson<unknown>(path.join(sessionDir(sessionId), "built-automation.json"));
+ if (!raw) return null;
+ const parsed = BuiltAutomationSchema.safeParse(raw);
+ return parsed.success ? parsed.data : null;
+}
+
+/**
+ * Drives the multi-turn GitHub Copilot CLI agent that turns a recording's analysis
+ * into a generalized Scout **automation** (a trigger + ordered prompt-steps). Shares
+ * the {@link AgentBuilder} pool (one live conversation per recording) so the plan →
+ * refine → create flow stays in a single session. Streams progress out via a callback
+ * and writes an importable bundle (automation.json) the user imports into Scout.
+ */
+export class AutomationBuilder extends AgentBuilder<LiveBuild> {
+ constructor(private readonly emitProgress: (p: AutomationBuildProgress) => void) {
+ super("AutomationBuilder");
+ }
+
+ /** Propose a plan (first pass) or refine the current one with NL feedback. */
+ async build(input: AutomationBuildInput): Promise<AutomationPlan> {
+ const { sessionId, architecture, feedback } = input;
+ if (this.active.has(sessionId)) throw new Error("A build is already running for this session.");
+ if (!automationCatalogueFor(architecture)) {
+ throw new Error("That target architecture isn't available yet. Choose Scout.");
+ }
+ const analysis = loadPersistedAnalysis(sessionId);
+ if (!analysis) throw new Error("There is no analysis for this recording yet.");
+
+ this.active.add(sessionId);
+ try {
+ const refining = Boolean(feedback && feedback.trim());
+ this.emit(sessionId, "start", refining ? "Refining the plan…" : "Planning the automation…");
+ let live = this.live.get(sessionId);
+ if (!refining || !live) {
+ await this.disposeLive(sessionId); // fresh conversation for a fresh plan
+ live = await this.createLive(sessionId, architecture);
+ }
+ const prompt = refining ? renderRefinePrompt(feedback!.trim(), live.lastPlan) : KICKOFF_PROMPT;
+ return await this.runProposeTurn(live, prompt);
+ } finally {
+ this.active.delete(sessionId);
+ }
+ }
+
+ /** Finalize the proposed plan into an automation bundle and export it. */
+ async create(sessionId: string): Promise<{ automation: BuiltAutomation; path: string }> {
+ if (this.active.has(sessionId)) throw new Error("Wait for the current step to finish.");
+ const live = this.live.get(sessionId);
+ if (!live) throw new Error("Propose a plan first, then create the automation.");
+ if (!live.lastPlan) throw new Error("There is no proposed plan to build from yet.");
+
+ this.active.add(sessionId);
+ try {
+ this.emit(sessionId, "drafting", "Writing the automation…");
+ live.holder.submission = undefined;
+ try {
+ await live.copilot.sendAndWait(CREATE_PROMPT, TURN_TIMEOUT_MS);
+ } catch (err) {
+ await live.copilot.abort().catch(() => undefined);
+ throw new Error(`Automation build failed: ${msg(err)}`);
+ }
+ const submission = live.holder.submission;
+ if (!submission) throw new Error("The agent finished without submitting an automation.");
+ const built = toBuiltAutomation(sessionId, live.architecture, submission, live.lastPlan);
+ const exportPath = this.exportAutomation(built);
+ const finalAutomation: BuiltAutomation = { ...built, exportedPath: exportPath, exportedAt: Date.now() };
+ this.persist(live.sessionDir, finalAutomation);
+ this.emit(sessionId, "done", `Automation exported to ${exportPath}`);
+ return { automation: finalAutomation, path: exportPath };
+ } finally {
+ this.active.delete(sessionId);
+ }
+ }
+
+ // --- internals -----------------------------------------------------------
+
+ private emit(sessionId: string, phase: AutomationBuildProgress["phase"], message: string): void {
+ this.emitProgress({ sessionId, phase, message });
+ }
+
+ private async createLive(sessionId: string, architecture: SkillArchitecture): Promise<LiveBuild> {
+ const dir = sessionDir(sessionId);
+ const analysis = loadPersistedAnalysis(sessionId);
+ if (!analysis) throw new Error("There is no analysis for this recording yet.");
+
+ const holder: LiveBuild["holder"] = { plan: undefined, submission: undefined };
+ const tools = [
+ ...createReadTools({
+ sessionDir: dir,
+ analysis,
+ onProgress: (m) => this.emit(sessionId, "working", m),
+ }),
+ ...createAutomationBuilderTools({
+ architecture,
+ onProgress: (m) => this.emit(sessionId, "working", m),
+ onPlan: (p) => {
+ holder.plan = p;
+ },
+ onSubmit: (s) => {
+ holder.submission = s;
+ },
+ }),
+ ];
+
+ const catalogue = automationCatalogueFor(architecture) ?? "";
+ const systemContent = `${AUTOMATION_BUILDER_INSTRUCTIONS}\n\n${catalogue}`.trim();
+
+ const client = await this.ensureClient();
+ const copilot = await client.createSession({
+ systemMessage: { mode: "append", content: systemContent },
+ tools,
+ onPermissionRequest: approveAll,
+ workingDirectory: dir,
+ enableHostGitOperations: false,
+ infiniteSessions: { enabled: false },
+ availableTools: tools.map((t) => t.name),
+ ...(this.model ? { model: this.model } : {}),
+ });
+
+ const live: LiveBuild = {
+ sessionId,
+ sessionDir: dir,
+ architecture,
+ copilot,
+ holder,
+ lastPlan: null,
+ };
+ this.registerLive(live);
+ return live;
+ }
+
+ private async runProposeTurn(live: LiveBuild, prompt: string): Promise<AutomationPlan> {
+ live.holder.plan = undefined;
+ this.emit(live.sessionId, "working", "Thinking…");
+ try {
+ await live.copilot.sendAndWait(prompt, TURN_TIMEOUT_MS);
+ } catch (err) {
+ await live.copilot.abort().catch(() => undefined);
+ throw new Error(`Planning failed: ${msg(err)}`);
+ }
+ const plan = live.holder.plan;
+ if (!plan) throw new Error("The agent finished without proposing a plan.");
+ live.lastPlan = plan;
+ this.emit(live.sessionId, "done", "Plan ready for your review.");
+ return plan;
+ }
+
+ /** Write the importable bundle (automation.json) to disk; returns its path. */
+ private exportAutomation(automation: BuiltAutomation): string {
+ const root = automationsRoot();
+ const name = slugifySkillName(automation.name);
+ const prior = loadPersistedAutomation(automation.sessionId);
+ // Re-export to the same folder if this session already exported one; otherwise pick
+ // a fresh, non-colliding directory so we never clobber an unrelated automation.
+ let dir = prior?.exportedPath ? path.dirname(prior.exportedPath) : path.join(root, name);
+ if (!prior?.exportedPath && existsSync(dir)) {
+ let n = 2;
+ while (existsSync(path.join(root, `${name}-${n}`))) n++;
+ dir = path.join(root, `${name}-${n}`);
+ }
+ mkdirSync(dir, { recursive: true });
+ const file = path.join(dir, "automation.json");
+ writeFileSync(file, renderAutomationJson(automation));
+ return file;
+ }
+
+ private persist(dir: string, automation: BuiltAutomation): void {
+ try {
+ writeFileSync(path.join(dir, "built-automation.json"), JSON.stringify(automation, null, 2));
+ } catch (err) {
+ log.warn("failed to persist automation:", msg(err));
+ }
+ }
+}
+
+function renderRefinePrompt(feedback: string, prior: AutomationPlan | null): string {
+ const lines = [
+ "The user reviewed your proposed plan and wants changes. Revise the plan and call",
+ "propose_automation_plan again (do not submit the automation yet).",
+ "",
+ ];
+ if (prior) {
+ lines.push(`Current plan: ${prior.title} (${prior.name})`);
+ lines.push(`- generalization: ${prior.generalization || "(none)"}`);
+ lines.push(`- trigger: ${prior.trigger.type}, schedule "${prior.trigger.schedule.naturalLanguage || "(unset)"}"`);
+ if (prior.steps.length) {
+ lines.push(`- steps: ${prior.steps.map((s) => s.label || s.prompt.slice(0, 32)).join("; ")}`);
+ }
+ lines.push("");
+ }
+ lines.push(`Their feedback: ${feedback}`);
+ return lines.join("\n");
+}
diff --git a/electron/automationbuilder/instructions.ts b/electron/automationbuilder/instructions.ts
new file mode 100644
index 0000000..de68dfa
--- /dev/null
+++ b/electron/automationbuilder/instructions.ts
@@ -0,0 +1,98 @@
+/**
+ * The Automation Builder **brief** — the agent's system message (appended to the SDK
+ * foundation, then followed by the target architecture's automation catalogue). It
+ * turns an *approved* recording analysis into a runnable, GENERALIZED **automation**
+ * for the chosen agent: a **trigger** (a schedule the builder proposes) plus ordered
+ * **steps**, each a natural-language prompt that prefers the agent's native tools.
+ *
+ * Two-phase, so the user stays in control:
+ * 1. **propose_automation_plan** — infer the generalization, a default schedule, and
+ * the native-tool-first steps, then show it. The user refines it in natural
+ * language (more turns).
+ * 2. **submit_automation** — only after the user approves, emit the final automation.
+ */
+export const AUTOMATION_BUILDER_INSTRUCTIONS = `
+# Role: Automation Builder
+
+You turn a recording of one task the user did into a reusable **automation** for an AI
+agent. The recording was already reconstructed into an approved **intent** and an
+ordered list of **steps** (call get_analysis to read it). Your job is to generalize
+that one run into an automation that runs on a **trigger** and carries ordered
+**steps** — each a natural-language prompt to the agent — targeting the architecture
+whose native capabilities are described in the **catalogue below**.
+
+## Two phases — never skip the plan
+
+1. **Propose a plan first.** Call **propose_automation_plan** with how you'll generalize
+ the task, the trigger (propose a sensible default **schedule**), and the ordered
+ prompt-steps. STOP after this — the user reviews it and may reply with natural-language
+ changes (especially to the schedule). If they do, call **propose_automation_plan**
+ again with the revision. Only ONE proposal per turn.
+2. **Build only when told.** When the user's message says the plan is approved (e.g.
+ "approved", "create it", "looks good"), call **submit_automation** with the final
+ name, description, trigger, and steps.
+
+## Propose the trigger (you must infer it)
+
+A recording captures ONE run and has NO "when to run" signal. So you must PROPOSE a
+sensible default **schedule** and state your assumption in the plan — the user corrects
+it in plain language.
+
+- Default to a **schedule**. Pick the shape that fits the task:
+ - **single** — one time of day (e.g. a morning digest at 9am on weekdays).
+ - **interval** — every N minutes, N dividing 1440 evenly (e.g. a poller every 30 min).
+ - **multi** — a few fixed times a day.
+- Always set the schedule's \`naturalLanguage\` to the human phrasing (e.g. "every weekday
+ at 9am") AND the structured fields (\`kind\`, \`days\`, \`time\`/\`anchor\`/\`times\`).
+- Only choose a **condition** trigger when the recording clearly implies an event
+ ("when a new file appears…"); then give the condition and a check interval.
+
+## Generalize from the intent (the core job)
+
+- The recording is ONE example. Use the intent to separate the essential procedure from
+ the incidental specifics.
+- If the user acted on a specific set (e.g. processed **3** rows of a sheet), the steps
+ must handle **every** item (N) — they iterate over the whole collection; they do NOT
+ hardcode the 3 examples.
+- Keep what's essential ("email a digest of today's new leads"); drop what's incidental
+ (the 3 particular leads, exact window positions, timing).
+
+## Steps are prompts (write them well)
+
+Each step has a short **label** and a **prompt** — an imperative instruction to the agent:
+
+- **Generalize, don't overfit.** The prompt describes the repeatable action over the whole
+ collection and the SHAPE of the data, never the specific values from the recording.
+- **Prefer native tools, and say why.** Map each recorded action to the target's native
+ capability (see the catalogue): searching Teams becomes a WorkIQ call, reading a local
+ file becomes the file tools, editing a spreadsheet becomes the built-in skill. Only fall
+ back to the browser for genuine UI-only steps, and the shell as a last resort.
+- **Resolve inputs inside the prompt.** An automation runs unattended and can't stop to ask
+ a human, so tell the agent to DISCOVER inputs on the local OS / read them from M365, or
+ bake in a genuinely fixed value. Avoid "ask the user" inputs.
+- **No surprises.** Keep destructive or send/create actions explicit in their step so the
+ user sees them in the plan. The automation must do exactly what its description says.
+- Keep it to a few ordered steps (roughly 2–6); each prompt tight and imperative.
+
+## Inputs (informational)
+
+List the things the task needs from outside in the plan's \`inputs\` with a likely source
+(discover / constant / — avoid ask). These are for the user's awareness; the automation
+resolves them inside the step prompts.
+
+## Your tools
+
+- **get_analysis** — the approved intent + ordered steps you're generalizing. Read first.
+- **get_timeline** — the deterministic timeline (apps, URLs, hosts, commands, clipboard
+ counts) behind those steps. Use it to ground the native-tool mapping and the schedule
+ in real evidence.
+- **propose_automation_plan({ name, title, description, summary, generalization, trigger,
+ inputs, steps, model, skillNames })** — your reviewable plan. Call once per turn, then stop.
+- **submit_automation({ name, description, triggerType, schedule, condition?,
+ conditionCheckInterval?, model?, steps })** — the final automation. Call only after the
+ user approves the plan.
+
+Start by reading get_analysis (and get_timeline where the mapping or schedule needs
+evidence), then call propose_automation_plan. Do not submit the automation until the plan
+is approved.
+`.trim();
diff --git a/electron/automationbuilder/scout-automation-catalog.ts b/electron/automationbuilder/scout-automation-catalog.ts
new file mode 100644
index 0000000..ae30770
--- /dev/null
+++ b/electron/automationbuilder/scout-automation-catalog.ts
@@ -0,0 +1,62 @@
+import type { SkillArchitecture } from "../../common/skill";
+import { SCOUT_NATIVE_CAPABILITIES } from "../skillbuilder/scout-catalog";
+
+/**
+ * The Automation Builder's Scout catalogue. Reuses the shared native-capability
+ * snapshot ({@link SCOUT_NATIVE_CAPABILITIES}) but frames it for **automations** —
+ * a scheduled/condition trigger plus ordered steps, where each step is a
+ * natural-language **prompt** to the Scout agent (not a `SKILL.md` procedure).
+ * Authored by inspecting `~/projects/m` (electron/automations/*). Refresh when
+ * Scout's automation model or native tools change.
+ */
+export const SCOUT_AUTOMATION_CATALOGUE_VERSION = "2026-07-25";
+
+const SCOUT_AUTOMATION_CATALOGUE = `
+# Target: Microsoft Scout — automation catalogue (built-ins only)
+
+A Scout **automation** is a **trigger** plus an ordered list of **steps**. Scout runs
+the steps in order on the trigger; each step is a natural-language **prompt** the Scout
+agent executes with its native tools (below). Automations are imported into Scout from a
+bundle folder — they are NOT auto-loaded like skills.
+
+## Trigger
+
+- **schedule** (default) — the automation runs on a clock. Express it as natural language
+ such as: "every weekday at 9am", "daily at 8:30am", "every day at 9am, 2pm, and 6pm",
+ "every 30 minutes", or "every hour at :15". The three shapes are:
+ - **single** — one time of day (optionally only on some weekdays).
+ - **interval** — every N minutes (N must divide 1440 evenly), from an anchor time.
+ - **multi** — several fixed times of day.
+- **condition** — the automation checks a natural-language condition on a cadence and only
+ runs when it's true (e.g. "when a new CSV appears in ~/Downloads"). Use this only when the
+ recording clearly implies an event trigger; otherwise prefer a schedule.
+
+A recording captures ONE run of the task and usually has NO "when to run" signal — so you
+must PROPOSE a sensible default schedule (state your assumption) and let the user correct it
+in plain language.
+
+## Steps — each is a prompt
+
+- Break the generalized task into a few ordered steps. Each step has a short **label** and a
+ **prompt** — an imperative instruction to the Scout agent for that part of the task.
+- Write prompts that GENERALIZE: if the recording acted on N specific items, the prompt tells
+ the agent to handle every item of that kind, not the specific examples recorded.
+- Prompts should prefer Scout's native tools (below) over UI replay, and say briefly why.
+- Resolve inputs inside the prompts: tell the agent to discover them on the local OS, read
+ them from M365, or (only if unavoidable) that they're fixed values. An unattended automation
+ can't stop to ask a human, so avoid "ask the user" inputs — discover or fix them instead.
+- Keep destructive or send/create actions explicit so the user sees them in the plan.
+
+${SCOUT_NATIVE_CAPABILITIES}
+
+## Writing the automation
+
+- Propose a trigger (a schedule by default) and 2–6 generalized, native-tool-first steps.
+- Prefer the native tools above; only use the browser for genuine UI-only steps.
+- Give the automation a clear \`description\` of what it does and when it runs.
+`.trim();
+
+/** The automation catalogue for a target architecture, or null if unavailable. */
+export function automationCatalogueFor(architecture: SkillArchitecture): string | null {
+ return architecture === "scout" ? SCOUT_AUTOMATION_CATALOGUE : null;
+}
diff --git a/electron/automationbuilder/tools.ts b/electron/automationbuilder/tools.ts
new file mode 100644
index 0000000..dcd0951
--- /dev/null
+++ b/electron/automationbuilder/tools.ts
@@ -0,0 +1,244 @@
+import type { Tool } from "@github/copilot-sdk";
+
+import {
+ AutomationPlanSchema,
+ AutomationSubmissionSchema,
+ type AutomationPlan,
+ type AutomationSubmission,
+} from "../../common/automation";
+import type { SkillArchitecture } from "../../common/skill";
+
+/** Everything the builder's automation-specific tools are bound to for one session. */
+export interface AutomationToolContext {
+ architecture: SkillArchitecture;
+ /** Streamed to the UI as the agent works. */
+ onProgress?: (message: string) => void;
+ /** Called when the agent proposes a (validated) plan for review. */
+ onPlan: (plan: AutomationPlan) => void;
+ /** Called when the agent submits the final (validated) automation. */
+ onSubmit: (submission: AutomationSubmission) => void;
+}
+
+/** A wall-clock time-of-day object, reused across the schedule fields. */
+const timeOfDay = (description: string) => ({
+ type: "object" as const,
+ description,
+ properties: {
+ hour: { type: "integer" as const, minimum: 0, maximum: 23 },
+ minute: { type: "integer" as const, minimum: 0, maximum: 59 },
+ },
+ required: ["hour", "minute"],
+ additionalProperties: false,
+});
+
+/**
+ * A schedule object. Modelled loosely for the tool call (all kind-specific fields are
+ * optional here); the zod discriminated union enforces the right combination per `kind`
+ * server-side. `single` → `time`; `interval` → `intervalMinutes` + `anchor`;
+ * `multi` → `times[]`.
+ */
+const scheduleSchema = {
+ type: "object" as const,
+ description:
+ "The run schedule. Set `kind` and the matching fields, plus `naturalLanguage` (human phrasing) and optional `days` (0=Sun…6=Sat; empty = every day).",
+ properties: {
+ kind: {
+ type: "string" as const,
+ enum: ["single", "interval", "multi"],
+ description: "single = one time/day; interval = every N minutes; multi = several fixed times/day.",
+ },
+ naturalLanguage: {
+ type: "string" as const,
+ description: 'Human phrasing of the schedule, e.g. "every weekday at 9am".',
+ },
+ days: {
+ type: "array" as const,
+ items: { type: "integer" as const, minimum: 0, maximum: 6 },
+ description: "Weekdays it runs (0=Sun…6=Sat). Empty/omitted = every day.",
+ },
+ time: timeOfDay("For kind=single: the single time of day it runs."),
+ intervalMinutes: {
+ type: "integer" as const,
+ minimum: 1,
+ maximum: 1440,
+ description: "For kind=interval: minutes between runs; must divide 1440 evenly (e.g. 15, 30, 60, 120).",
+ },
+ anchor: timeOfDay("For kind=interval: the first run of the day (the interval anchor)."),
+ times: {
+ type: "array" as const,
+ items: timeOfDay("A time of day it runs."),
+ description: "For kind=multi: the fixed times of day it runs.",
+ },
+ },
+ required: ["kind"],
+ additionalProperties: false,
+};
+
+const stepsSchema = {
+ type: "array" as const,
+ description: "The generalized procedure as ordered steps; each step is a label + an NL prompt to the agent.",
+ items: {
+ type: "object" as const,
+ properties: {
+ label: { type: "string" as const, description: 'Short label for the step, e.g. "Collect new leads".' },
+ prompt: {
+ type: "string" as const,
+ description:
+ "The natural-language instruction to the agent for this step: generalized over the whole collection, native-tool-first, resolving inputs itself (an automation runs unattended).",
+ },
+ },
+ required: ["prompt"],
+ additionalProperties: false,
+ },
+};
+
+/**
+ * Build the automation-specific tools exposed to one Automation Builder session. The
+ * agent reads the recording via the shared read-tools (get_analysis / get_timeline),
+ * proposes a reviewable plan (propose_automation_plan) with a default schedule, then —
+ * once the user approves — submits the final automation (submit_automation). Both
+ * submissions are zod-validated; the architecture is injected server-side.
+ */
+export function createAutomationBuilderTools(ctx: AutomationToolContext): Tool[] {
+ const { architecture, onPlan, onSubmit } = ctx;
+ const progress = (m: string) => ctx.onProgress?.(m);
+
+ const proposePlan: Tool = {
+ name: "propose_automation_plan",
+ description:
+ "Propose your reviewable plan for the automation: how you'll generalize the task, the trigger (propose a sensible default schedule), the inputs it needs, and the generalized ordered prompt-steps. Call this once per turn, then STOP so the user can review or refine it (especially the schedule). Do NOT submit the automation yet.",
+ parameters: {
+ type: "object",
+ properties: {
+ name: { type: "string", description: 'kebab-case automation id, e.g. "daily-lead-digest".' },
+ title: { type: "string", description: 'Human-friendly title, e.g. "Daily lead digest".' },
+ description: {
+ type: "string",
+ description: "What the automation does and when it runs (becomes the automation description).",
+ },
+ summary: { type: "string", description: "Plain-language summary of what the automation does." },
+ generalization: {
+ type: "string",
+ description: "How the recorded specifics become a repeatable procedure (the loop/collection insight).",
+ },
+ trigger: {
+ type: "object",
+ description: "The trigger. Default to a schedule; use a condition only when the recording implies an event.",
+ properties: {
+ type: {
+ type: "string",
+ enum: ["schedule", "condition"],
+ description: "schedule (default) or condition.",
+ },
+ schedule: scheduleSchema,
+ condition: {
+ type: "string",
+ description: "For type=condition: the NL condition to check before running.",
+ },
+ conditionCheckInterval: {
+ type: "integer",
+ minimum: 1,
+ description: "For type=condition: minutes between condition checks.",
+ },
+ },
+ required: ["schedule"],
+ additionalProperties: false,
+ },
+ inputs: {
+ type: "array",
+ description: "Inputs the automation needs (informational; resolved inside the step prompts).",
+ items: {
+ type: "object",
+ properties: {
+ name: { type: "string" },
+ description: { type: "string" },
+ source: {
+ type: "string",
+ enum: ["ask", "discover", "constant"],
+ description: "Prefer discover/constant — an automation runs unattended and can't ask.",
+ },
+ detail: {
+ type: "string",
+ description: "For discover: how to find it. For constant: the value.",
+ },
+ },
+ required: ["name", "source"],
+ additionalProperties: false,
+ },
+ },
+ steps: stepsSchema,
+ model: { type: "string", description: "Optional per-automation model override." },
+ skillNames: {
+ type: "array",
+ items: { type: "string" },
+ description: "Built-in Scout skills the steps rely on (for the user's awareness).",
+ },
+ },
+ required: ["name", "title", "description", "trigger"],
+ additionalProperties: false,
+ },
+ handler: (raw) => {
+ const merged = { ...(raw as Record<string, unknown>), architecture };
+ const parsed = AutomationPlanSchema.safeParse(merged);
+ if (!parsed.success) {
+ return {
+ textResultForLlm:
+ "propose_automation_plan rejected — the payload did not match the schema. Fix these and call again:\n" +
+ parsed.error.issues.map((i) => `- ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n"),
+ resultType: "failure",
+ };
+ }
+ progress("Proposed an automation plan for your review.");
+ onPlan(parsed.data);
+ return "Plan recorded and shown to the user. Stop now and wait for their review or refinement.";
+ },
+ };
+
+ const submitAutomation: Tool = {
+ name: "submit_automation",
+ description:
+ "Submit the final automation AFTER the user approves the plan: name, description, the trigger (triggerType + schedule, plus condition for condition triggers), and the generalized ordered prompt-steps.",
+ parameters: {
+ type: "object",
+ properties: {
+ name: { type: "string", description: "kebab-case automation id (matches the approved plan)." },
+ description: { type: "string", description: "What the automation does and when it runs." },
+ triggerType: {
+ type: "string",
+ enum: ["schedule", "condition"],
+ description: "schedule (default) or condition.",
+ },
+ schedule: scheduleSchema,
+ condition: {
+ type: "string",
+ description: "For triggerType=condition: the NL condition to check before running.",
+ },
+ conditionCheckInterval: {
+ type: "integer",
+ minimum: 1,
+ description: "For triggerType=condition: minutes between condition checks.",
+ },
+ model: { type: "string", description: "Optional per-automation model override." },
+ steps: stepsSchema,
+ },
+ required: ["name", "schedule", "steps"],
+ additionalProperties: false,
+ },
+ handler: (raw) => {
+ const parsed = AutomationSubmissionSchema.safeParse(raw);
+ if (!parsed.success) {
+ return {
+ textResultForLlm:
+ "submit_automation rejected — the payload did not match the schema. Fix these and call again:\n" +
+ parsed.error.issues.map((i) => `- ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n"),
+ resultType: "failure",
+ };
+ }
+ progress("Received the finished automation.");
+ onSubmit(parsed.data);
+ return "Automation recorded. You may stop now.";
+ },
+ };
+
+ return [proposePlan, submitAutomation];
+}
diff --git a/electron/builders/agent-builder.ts b/electron/builders/agent-builder.ts
new file mode 100644
index 0000000..1613886
--- /dev/null
+++ b/electron/builders/agent-builder.ts
@@ -0,0 +1,108 @@
+import { CopilotClient, type CopilotSession } from "@github/copilot-sdk";
+
+import { copilotConnectionOption, withStartupTimeout } from "../copilot-cli-path";
+import { createLogger } from "../logger";
+
+/**
+ * Shared plumbing for the final-stage, multi-turn Copilot builders (Skill Builder
+ * and Automation Builder). Owns one lazily-started {@link CopilotClient} and a small
+ * pool of live conversations — one per recording — so each build's plan → refine →
+ * create flow stays in a single session. Subclasses add the build-specific tools,
+ * system prompt, and `build`/`create` turns; everything below is common.
+ */
+
+/** The minimum every live build carries so the pool can manage it. */
+export interface BaseLive {
+ sessionId: string;
+ copilot: CopilotSession;
+}
+
+const MAX_LIVE_SESSIONS = 4;
+
+export abstract class AgentBuilder<TLive extends BaseLive> {
+ private client: CopilotClient | null = null;
+ private clientStart: Promise<CopilotClient> | null = null;
+ protected model: string | undefined;
+ protected readonly live = new Map<string, TLive>();
+ protected readonly active = new Set<string>();
+ protected readonly log;
+
+ /** @param name Used for logs and the "not signed in" / startup-timeout messages. */
+ constructor(private readonly name: string) {
+ this.log = createLogger(name);
+ }
+
+ isBuilding(sessionId: string): boolean {
+ return this.active.has(sessionId);
+ }
+
+ async cancel(sessionId: string): Promise<void> {
+ const live = this.live.get(sessionId);
+ if (live) await live.copilot.abort().catch(() => undefined);
+ }
+
+ async forget(sessionId: string): Promise<void> {
+ await this.disposeLive(sessionId);
+ }
+
+ async evictIdle(): Promise<void> {
+ for (const [id, live] of this.live) {
+ if (this.active.has(id)) continue;
+ this.live.delete(id);
+ await live.copilot.disconnect().catch(() => undefined);
+ }
+ }
+
+ async dispose(): Promise<void> {
+ for (const [id] of this.live) await this.disposeLive(id);
+ if (this.client) await this.client.stop().catch(() => undefined);
+ this.client = null;
+ this.clientStart = null;
+ }
+
+ /** Start (once) and return the shared Copilot client, verifying it's signed in. */
+ protected async ensureClient(): Promise<CopilotClient> {
+ if (this.client) return this.client;
+ if (this.clientStart) return this.clientStart;
+ this.clientStart = (async () => {
+ const client = new CopilotClient(copilotConnectionOption());
+ await withStartupTimeout(client.start(), `Copilot CLI (${this.name})`);
+ const auth = await client.getAuthStatus();
+ if (!auth.isAuthenticated) {
+ await client.stop().catch(() => undefined);
+ throw new Error(
+ "GitHub Copilot CLI is not signed in. Open a terminal, run `copilot`, sign in, then try again.",
+ );
+ }
+ this.model = process.env.SKILL_RECORDER_MODEL || undefined;
+ this.log.info("Copilot ready", auth.login ? `as ${auth.login}` : "");
+ this.client = client;
+ return client;
+ })();
+ try {
+ return await this.clientStart;
+ } catch (err) {
+ this.clientStart = null;
+ throw err;
+ }
+ }
+
+ /** Add a freshly created live session to the pool, evicting the oldest idle one
+ * when the pool is over budget. */
+ protected registerLive(live: TLive): void {
+ this.live.set(live.sessionId, live);
+ for (const [id, l] of this.live) {
+ if (this.live.size <= MAX_LIVE_SESSIONS) break;
+ if (id === live.sessionId || this.active.has(id)) continue;
+ this.live.delete(id);
+ void l.copilot.disconnect().catch(() => undefined);
+ }
+ }
+
+ protected async disposeLive(sessionId: string): Promise<void> {
+ const live = this.live.get(sessionId);
+ if (!live) return;
+ this.live.delete(sessionId);
+ await live.copilot.disconnect().catch(() => undefined);
+ }
+}
diff --git a/electron/builders/read-tools.ts b/electron/builders/read-tools.ts
new file mode 100644
index 0000000..dbab662
--- /dev/null
+++ b/electron/builders/read-tools.ts
@@ -0,0 +1,93 @@
+import { existsSync, readFileSync } from "node:fs";
+import path from "node:path";
+
+import type { Tool } from "@github/copilot-sdk";
+
+import type { Analysis } from "../../common/analysis";
+import type { SessionBundle } from "../../common/bundle";
+
+/**
+ * The two read-only tools every final-stage builder exposes: `get_analysis`
+ * (the approved intent + steps the builder generalizes) and `get_timeline` (the
+ * deterministic evidence behind those steps). Shared by the Skill Builder and the
+ * Automation Builder so both ground their plans in the same recording data.
+ */
+
+export function readBundle(sessionDir: string): SessionBundle | null {
+ const p = path.join(sessionDir, "bundle.json");
+ if (!existsSync(p)) return null;
+ try {
+ return JSON.parse(readFileSync(p, "utf8")) as SessionBundle;
+ } catch {
+ return null;
+ }
+}
+
+export interface ReadToolsContext {
+ sessionDir: string;
+ /** The approved analysis being generalized (the builder's input). */
+ analysis: Analysis;
+ /** Streamed to the UI as the agent works. */
+ onProgress?: (message: string) => void;
+}
+
+/** Build the shared `get_analysis` + `get_timeline` tools for one builder session. */
+export function createReadTools(ctx: ReadToolsContext): Tool[] {
+ const { sessionDir, analysis } = ctx;
+ const progress = (m: string) => ctx.onProgress?.(m);
+
+ const getAnalysis: Tool = {
+ name: "get_analysis",
+ description:
+ "Return the approved analysis you are generalizing: the overall intent and the ordered list of steps (with each step's title, detail, apps, and evidence). Read this first.",
+ parameters: { type: "object", properties: {}, additionalProperties: false },
+ handler: () => {
+ progress("Reading the approved analysis…");
+ const view = {
+ intent: analysis.intent,
+ intentRationale: analysis.intentRationale,
+ stepCount: analysis.steps.length,
+ steps: analysis.steps.map((s) => ({
+ id: s.id,
+ title: s.title,
+ detail: s.detail,
+ apps: s.apps,
+ evidence: s.evidence,
+ })),
+ };
+ return JSON.stringify(view, null, 2);
+ },
+ };
+
+ const getTimeline: Tool = {
+ name: "get_timeline",
+ description:
+ "Return the deterministic timeline behind the analysis: ordered steps with their app, window titles, hosts, URLs, terminal commands, clipboard counts and markers. Use it to ground your native-tool mapping in real evidence.",
+ parameters: { type: "object", properties: {}, additionalProperties: false },
+ handler: () => {
+ progress("Reading the timeline…");
+ const bundle = readBundle(sessionDir);
+ if (!bundle) {
+ return "No timeline is available (bundle.json missing). Work from get_analysis instead.";
+ }
+ const view = {
+ durationMs: bundle.session.durationMs,
+ platform: bundle.session.platform,
+ steps: bundle.steps.map((s) => ({
+ index: s.index,
+ app: s.app,
+ titles: s.titles,
+ hosts: s.hosts,
+ urls: s.urls,
+ commands: s.commands,
+ clipboardCount: s.clipboardCount,
+ markers: s.markers,
+ summary: s.summary,
+ })),
+ };
+ return JSON.stringify(view, null, 2);
+ },
+ };
+
+ return [getAnalysis, getTimeline];
+}
diff --git a/electron/ipc.ts b/electron/ipc.ts
index 7421f76..e4a333e 100644
--- a/electron/ipc.ts
+++ b/electron/ipc.ts
@@ -5,12 +5,16 @@ import type {
AnalysisEditInput,
AnalysisFeedbackInput,
AnalyzeResult,
+ AutomationBuildInput,
+ AutomationCreateResult,
+ AutomationPlanResult,
DeleteSessionResult,
SkillBuildInput,
SkillCreateResult,
SkillPlanResult,
} from "../common/ipc";
import { IPC } from "../common/ipc";
+import { AutomationBuilder, loadPersistedAutomation } from "./automationbuilder/builder";
import { Describer, loadPersistedAnalysis } from "./describer/describer";
import { runDoctor } from "./doctor";
import { createLogger } from "./logger";
@@ -21,11 +25,12 @@ import { loadPersistedSkill, SkillBuilder } from "./skillbuilder/builder";
const log = createLogger("IPC");
-/** Wire the renderer-facing invoke channels to the recorder, describer, builder + doctor. */
+/** Wire the renderer-facing invoke channels to the recorder, describer, builders + doctor. */
export function registerIpc(
recorder: RecorderController,
describer: Describer,
builder: SkillBuilder,
+ automationBuilder: AutomationBuilder,
): void {
ipcMain.handle(IPC.start, () => recorder.start());
ipcMain.handle(IPC.stop, () => recorder.stop());
@@ -108,9 +113,16 @@ export function registerIpc(
if (builder.isBuilding(sessionId)) {
return { ok: false, error: "This recording is being turned into a skill. Cancel that first, then delete." };
}
+ if (automationBuilder.isBuilding(sessionId)) {
+ return {
+ ok: false,
+ error: "This recording is being turned into an automation. Cancel that first, then delete.",
+ };
+ }
try {
await describer.forget(sessionId); // release any idle agent holding the folder
await builder.forget(sessionId);
+ await automationBuilder.forget(sessionId);
await deleteSession(sessionId);
recorder.forgetSession(sessionId); // clear the "last completed" pointer if it was this one
return { ok: true };
@@ -160,5 +172,48 @@ export function registerIpc(
if (skill?.exportedPath) shell.showItemInFolder(skill.exportedPath);
return { ok: true };
});
+
+ ipcMain.handle(
+ IPC.buildAutomation,
+ async (_event, input: AutomationBuildInput): Promise<AutomationPlanResult> => {
+ if (!isValidSessionId(input?.sessionId)) return { ok: false, error: "Unknown session." };
+ try {
+ const plan = await automationBuilder.build(input);
+ return { ok: true, plan };
+ } catch (err) {
+ const error = err instanceof Error ? err.message : String(err);
+ log.warn("build automation failed:", error);
+ return { ok: false, error };
+ }
+ },
+ );
+
+ ipcMain.handle(IPC.createAutomation, async (_event, sessionId: string): Promise<AutomationCreateResult> => {
+ if (!isValidSessionId(sessionId)) return { ok: false, error: "Unknown session." };
+ try {
+ const { automation, path: file } = await automationBuilder.create(sessionId);
+ return { ok: true, automation, path: file };
+ } catch (err) {
+ const error = err instanceof Error ? err.message : String(err);
+ log.warn("create automation failed:", error);
+ return { ok: false, error };
+ }
+ });
+
+ ipcMain.handle(IPC.getAutomation, (_event, sessionId: string) =>
+ isValidSessionId(sessionId) ? loadPersistedAutomation(sessionId) : null,
+ );
+
+ ipcMain.handle(IPC.cancelAutomation, async (_event, sessionId: string) => {
+ if (isValidSessionId(sessionId)) await automationBuilder.cancel(sessionId);
+ return { ok: true };
+ });
+
+ ipcMain.handle(IPC.revealAutomation, (_event, sessionId: string) => {
+ if (!isValidSessionId(sessionId)) return { ok: false };
+ const automation = loadPersistedAutomation(sessionId);
+ if (automation?.exportedPath) shell.showItemInFolder(automation.exportedPath);
+ return { ok: true };
+ });
}
diff --git a/electron/main.ts b/electron/main.ts
index 8fe22b4..dc06391 100644
--- a/electron/main.ts
+++ b/electron/main.ts
@@ -9,6 +9,7 @@ import { registerIpc } from "./ipc";
import { createLogger } from "./logger";
import { RecorderController } from "./recorder/controller";
import { SkillBuilder } from "./skillbuilder/builder";
+import { AutomationBuilder } from "./automationbuilder/builder";
import { createTray } from "./tray";
import { VideoRecorder } from "./video/recorder";
import { createLibraryWindow, createRecorderWindow, redockLibrary } from "./window";
@@ -34,6 +35,9 @@ function broadcast(channel: string, payload: unknown): void {
const describer = new Describer((progress) => broadcast(IPC.analyzeProgress, progress));
const builder = new SkillBuilder((progress) => broadcast(IPC.skillProgress, progress));
+const automationBuilder = new AutomationBuilder((progress) =>
+ broadcast(IPC.automationProgress, progress),
+);
/** Open, focus, and re-dock the Sessions library window (creating it lazily). */
function openLibrary(): void {
@@ -56,11 +60,12 @@ function openLibrary(): void {
// Drop idle agent conversations now that the library is gone.
void describer.evictIdle();
void builder.evictIdle();
+ void automationBuilder.evictIdle();
});
}
app.whenReady().then(() => {
- registerIpc(recorder, describer, builder);
+ registerIpc(recorder, describer, builder, automationBuilder);
log.info("Capture: recording all sources");
ipcMain.handle(IPC.openLibrary, () => openLibrary());
@@ -104,6 +109,7 @@ app.on("will-quit", () => {
if (recorder.state === "recording") void recorder.stop();
void describer.dispose();
void builder.dispose();
+ void automationBuilder.dispose();
});
diff --git a/electron/preload.cjs b/electron/preload.cjs
index 84df48f..1f1beb5 100644
--- a/electron/preload.cjs
+++ b/electron/preload.cjs
@@ -23,6 +23,12 @@ const IPC = {
cancelSkill: "skill:cancel",
revealSkill: "skill:reveal",
skillProgress: "skill:progress",
+ buildAutomation: "automation:build",
+ createAutomation: "automation:create",
+ getAutomation: "automation:get",
+ cancelAutomation: "automation:cancel",
+ revealAutomation: "automation:reveal",
+ automationProgress: "automation:progress",
openLibrary: "ui:open-library",
closeLibrary: "ui:close-library",
};
@@ -60,6 +66,16 @@ contextBridge.exposeInMainWorld("skillRecorder", {
ipcRenderer.on(IPC.skillProgress, listener);
return () => ipcRenderer.removeListener(IPC.skillProgress, listener);
},
+ buildAutomation: (input) => ipcRenderer.invoke(IPC.buildAutomation, input),
+ createAutomation: (sessionId) => ipcRenderer.invoke(IPC.createAutomation, sessionId),
+ getAutomation: (sessionId) => ipcRenderer.invoke(IPC.getAutomation, sessionId),
+ cancelAutomation: (sessionId) => ipcRenderer.invoke(IPC.cancelAutomation, sessionId),
+ revealAutomation: (sessionId) => ipcRenderer.invoke(IPC.revealAutomation, sessionId),
+ onAutomationProgress: (cb) => {
+ const listener = (_event, progress) => cb(progress);
+ ipcRenderer.on(IPC.automationProgress, listener);
+ return () => ipcRenderer.removeListener(IPC.automationProgress, listener);
+ },
openLibrary: () => ipcRenderer.invoke(IPC.openLibrary),
closeLibrary: () => ipcRenderer.invoke(IPC.closeLibrary),
});
diff --git a/electron/sessions.ts b/electron/sessions.ts
index b90ccd0..c2c4203 100644
--- a/electron/sessions.ts
+++ b/electron/sessions.ts
@@ -44,11 +44,12 @@ async function summarize(root: string, name: string): Promise<SessionSummary | n
}
if (!meta?.id) return null;
- const [analysis, processed, hasVideo, hasSkill] = await Promise.all([
+ const [analysis, processed, hasVideo, hasSkill, hasAutomation] = await Promise.all([
loadAnalysis(dir),
exists(path.join(dir, "bundle.json")),
exists(path.join(dir, "video.json")),
exists(path.join(dir, "skill.json")),
+ exists(path.join(dir, "built-automation.json")),
]);
return {
@@ -59,6 +60,7 @@ async function summarize(root: string, name: string): Promise<SessionSummary | n
processed,
hasVideo,
hasSkill,
+ hasAutomation,
analysis: analysis
? {
revision: analysis.revision,
diff --git a/electron/skillbuilder/builder.ts b/electron/skillbuilder/builder.ts
index a4617fb..f692c9f 100644
--- a/electron/skillbuilder/builder.ts
+++ b/electron/skillbuilder/builder.ts
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
-import { approveAll, CopilotClient, type CopilotSession } from "@github/copilot-sdk";
+import { approveAll, type CopilotSession } from "@github/copilot-sdk";
import {
BuiltSkillSchema,
@@ -15,8 +15,9 @@ import {
type SkillSubmission,
} from "../../common/skill";
import type { SkillBuildInput, SkillBuildProgress } from "../../common/ipc";
+import { AgentBuilder, type BaseLive } from "../builders/agent-builder";
+import { createReadTools } from "../builders/read-tools";
import { loadPersistedAnalysis } from "../describer/describer";
-import { copilotConnectionOption, withStartupTimeout } from "../copilot-cli-path";
import { createLogger } from "../logger";
import { isValidSessionId, sessionDir } from "../recorder/session-store";
import { SKILL_BUILDER_INSTRUCTIONS } from "./instructions";
@@ -26,7 +27,6 @@ import { createSkillBuilderTools } from "./tools";
const log = createLogger("SkillBuilder");
const TURN_TIMEOUT_MS = 180_000;
-const MAX_LIVE_SESSIONS = 4;
const KICKOFF_PROMPT =
"Read get_analysis (and get_timeline where the tool mapping needs evidence), then call " +
@@ -46,8 +46,7 @@ function skillsRoot(): string {
return path.join(os.homedir(), ".copilot", "skills");
}
-interface LiveBuild {
- sessionId: string;
+interface LiveBuild extends BaseLive {
sessionDir: string;
architecture: SkillArchitecture;
copilot: CopilotSession;
@@ -76,19 +75,15 @@ export function loadPersistedSkill(sessionId: string): BuiltSkill | null {
/**
* Drives the multi-turn GitHub Copilot CLI agent that turns a recording's analysis
- * into a generalized, native-tool-first skill for a target architecture. Owns one
- * shared {@link CopilotClient}; keeps one live conversation per recording so the
- * plan → refine → build flow stays in a single session. Streams progress out via a
+ * into a generalized, native-tool-first skill for a target architecture. Shares the
+ * {@link AgentBuilder} pool (one live conversation per recording) so the plan →
+ * refine → build flow stays in a single session. Streams progress out via a
* callback and writes the final SKILL.md into the target agent's skills folder.
*/
-export class SkillBuilder {
- private client: CopilotClient | null = null;
- private clientStart: Promise<CopilotClient> | null = null;
- private model: string | undefined;
- private readonly live = new Map<string, LiveBuild>();
- private readonly active = new Set<string>();
-
- constructor(private readonly emitProgress: (p: SkillBuildProgress) => void) {}
+export class SkillBuilder extends AgentBuilder<LiveBuild> {
+ constructor(private readonly emitProgress: (p: SkillBuildProgress) => void) {
+ super("SkillBuilder");
+ }
/** Propose a plan (first pass) or refine the current one with NL feedback. */
async build(input: SkillBuildInput): Promise<SkillPlan> {
@@ -146,84 +141,35 @@ export class SkillBuilder {
}
}
- async cancel(sessionId: string): Promise<void> {
- const live = this.live.get(sessionId);
- if (live) await live.copilot.abort().catch(() => undefined);
- }
-
- isBuilding(sessionId: string): boolean {
- return this.active.has(sessionId);
- }
-
- async forget(sessionId: string): Promise<void> {
- await this.disposeLive(sessionId);
- }
-
- async evictIdle(): Promise<void> {
- for (const [id, live] of this.live) {
- if (this.active.has(id)) continue;
- this.live.delete(id);
- await live.copilot.disconnect().catch(() => undefined);
- }
- }
-
- async dispose(): Promise<void> {
- for (const [id] of this.live) await this.disposeLive(id);
- if (this.client) await this.client.stop().catch(() => undefined);
- this.client = null;
- this.clientStart = null;
- }
-
// --- internals -----------------------------------------------------------
private emit(sessionId: string, phase: SkillBuildProgress["phase"], message: string): void {
this.emitProgress({ sessionId, phase, message });
}
- private async ensureClient(): Promise<CopilotClient> {
- if (this.client) return this.client;
- if (this.clientStart) return this.clientStart;
- this.clientStart = (async () => {
- const client = new CopilotClient(copilotConnectionOption());
- await withStartupTimeout(client.start(), "Copilot CLI (SkillBuilder)");
- const auth = await client.getAuthStatus();
- if (!auth.isAuthenticated) {
- await client.stop().catch(() => undefined);
- throw new Error(
- "GitHub Copilot CLI is not signed in. Open a terminal, run `copilot`, sign in, then try again.",
- );
- }
- this.model = process.env.SKILL_RECORDER_MODEL || undefined;
- log.info("Copilot ready", auth.login ? `as ${auth.login}` : "");
- this.client = client;
- return client;
- })();
- try {
- return await this.clientStart;
- } catch (err) {
- this.clientStart = null;
- throw err;
- }
- }
-
private async createLive(sessionId: string, architecture: SkillArchitecture): Promise<LiveBuild> {
const dir = sessionDir(sessionId);
const analysis = loadPersistedAnalysis(sessionId);
if (!analysis) throw new Error("There is no analysis for this recording yet.");
const holder: LiveBuild["holder"] = { plan: undefined, submission: undefined };
- const tools = createSkillBuilderTools({
- sessionDir: dir,
- architecture,
- analysis,
- onProgress: (m) => this.emit(sessionId, "working", m),
- onPlan: (p) => {
- holder.plan = p;
- },
- onSubmit: (s) => {
- holder.submission = s;
- },
- });
+ const tools = [
+ ...createReadTools({
+ sessionDir: dir,
+ analysis,
+ onProgress: (m) => this.emit(sessionId, "working", m),
+ }),
+ ...createSkillBuilderTools({
+ architecture,
+ onProgress: (m) => this.emit(sessionId, "working", m),
+ onPlan: (p) => {
+ holder.plan = p;
+ },
+ onSubmit: (s) => {
+ holder.submission = s;
+ },
+ }),
+ ];
const catalogue = catalogueFor(architecture) ?? "";
const systemContent = `${SKILL_BUILDER_INSTRUCTIONS}\n\n${catalogue}`.trim();
@@ -248,27 +194,10 @@ export class SkillBuilder {
holder,
lastPlan: null,
};
- this.live.set(sessionId, live);
- this.evictOverflow(sessionId);
+ this.registerLive(live);
return live;
}
- private evictOverflow(keep: string): void {
- for (const [id, live] of this.live) {
- if (this.live.size <= MAX_LIVE_SESSIONS) break;
- if (id === keep || this.active.has(id)) continue;
- this.live.delete(id);
- void live.copilot.disconnect().catch(() => undefined);
- }
- }
-
- private async disposeLive(sessionId: string): Promise<void> {
- const live = this.live.get(sessionId);
- if (!live) return;
- this.live.delete(sessionId);
- await live.copilot.disconnect().catch(() => undefined);
- }
-
private async runProposeTurn(live: LiveBuild, prompt: string): Promise<SkillPlan> {
live.holder.plan = undefined;
this.emit(live.sessionId, "working", "Thinking…");
diff --git a/electron/skillbuilder/scout-catalog.ts b/electron/skillbuilder/scout-catalog.ts
index dfd935e..c3e4fce 100644
--- a/electron/skillbuilder/scout-catalog.ts
+++ b/electron/skillbuilder/scout-catalog.ts
@@ -12,22 +12,12 @@ import type { SkillArchitecture } from "../../common/skill";
*/
export const SCOUT_CATALOGUE_VERSION = "2026-07-25";
-const SCOUT_CATALOGUE = `
-# Target: Microsoft Scout — native capability catalogue (built-ins only)
-
-A Scout **skill** is a \`SKILL.md\` file: optional YAML frontmatter followed by a
-markdown **instructions body**. Scout auto-loads user skills from
-\`~/.copilot/skills/<name>/SKILL.md\`.
-
-Frontmatter fields:
-- \`name\` — kebab-case, \`^[a-z0-9-]+$\`.
-- \`description\` — one line of trigger keywords (when Scout should reach for this skill).
-- \`allowed-tools\` (optional) — a YAML list of tool patterns the skill may use, e.g.
- \`Bash(git *)\`, \`Read\`, \`Write\`, \`Grep\`, \`Glob\`. Omit it to allow the default set.
-
-The body is plain instructions written TO the Scout agent (imperative voice): when
-to use the skill, the procedure to follow, and how to handle inputs and edge cases.
-
+/**
+ * The reusable core of the Scout catalogue: the native tools, built-in skills, and
+ * recorded-action→capability mapping. Shared by the Skill Builder and the Automation
+ * Builder (their preambles/tails differ, but both prefer these same capabilities).
+ */
+export const SCOUT_NATIVE_CAPABILITIES = `
## Native tools, in the order to PREFER them
Prefer a real native tool/API over replaying UI clicks. Only fall back down this list.
@@ -83,6 +73,25 @@ skill being installed.
| Reading a public web page | \`web_fetch\` |
| Editing a spreadsheet / doc / deck | the \`xlsx\` / \`docx\` / \`pptx\` built-in skill |
| Filling a form on a web app with no API | \`browser_navigate\` + \`browser_snapshot\` + \`browser_fill_form\`/\`browser_type\`/\`browser_click\` |
+`.trim();
+
+const SCOUT_CATALOGUE = `
+# Target: Microsoft Scout — native capability catalogue (built-ins only)
+
+A Scout **skill** is a \`SKILL.md\` file: optional YAML frontmatter followed by a
+markdown **instructions body**. Scout auto-loads user skills from
+\`~/.copilot/skills/<name>/SKILL.md\`.
+
+Frontmatter fields:
+- \`name\` — kebab-case, \`^[a-z0-9-]+$\`.
+- \`description\` — one line of trigger keywords (when Scout should reach for this skill).
+- \`allowed-tools\` (optional) — a YAML list of tool patterns the skill may use, e.g.
+ \`Bash(git *)\`, \`Read\`, \`Write\`, \`Grep\`, \`Glob\`. Omit it to allow the default set.
+
+The body is plain instructions written TO the Scout agent (imperative voice): when
+to use the skill, the procedure to follow, and how to handle inputs and edge cases.
+
+${SCOUT_NATIVE_CAPABILITIES}
## Writing the SKILL.md body
diff --git a/electron/skillbuilder/tools.ts b/electron/skillbuilder/tools.ts
index 11251f7..5b7ea15 100644
--- a/electron/skillbuilder/tools.ts
+++ b/electron/skillbuilder/tools.ts
@@ -1,10 +1,5 @@
-import { existsSync, readFileSync } from "node:fs";
-import path from "node:path";
-
import type { Tool } from "@github/copilot-sdk";
-import type { Analysis } from "../../common/analysis";
-import type { SessionBundle } from "../../common/bundle";
import {
SkillPlanSchema,
SkillSubmissionSchema,
@@ -13,12 +8,9 @@ import {
type SkillSubmission,
} from "../../common/skill";
-/** Everything the builder's tools are bound to for one session. */
+/** Everything the builder's skill-specific tools are bound to for one session. */
export interface SkillToolContext {
- sessionDir: string;
architecture: SkillArchitecture;
- /** The approved analysis being generalized (the builder's input). */
- analysis: Analysis;
/** Streamed to the UI as the agent works. */
onProgress?: (message: string) => void;
/** Called when the agent proposes a (validated) plan for review. */
@@ -27,80 +19,17 @@ export interface SkillToolContext {
onSubmit: (submission: SkillSubmission) => void;
}
-function readBundle(sessionDir: string): SessionBundle | null {
- const p = path.join(sessionDir, "bundle.json");
- if (!existsSync(p)) return null;
- try {
- return JSON.parse(readFileSync(p, "utf8")) as SessionBundle;
- } catch {
- return null;
- }
-}
-
/**
- * Build the custom in-process tools exposed to one Skill Builder session. The
- * agent reads the approved analysis (get_analysis) and its deterministic timeline
- * (get_timeline), then proposes a reviewable plan (propose_plan) and — once the
- * user approves — submits the final skill (submit_skill). Both submissions are
- * zod-validated; the architecture is injected server-side so the agent can't set it.
+ * Build the skill-specific tools exposed to one Skill Builder session. The agent
+ * reads the recording via the shared read-tools (get_analysis / get_timeline), then
+ * proposes a reviewable plan (propose_plan) and — once the user approves — submits
+ * the final skill (submit_skill). Both submissions are zod-validated; the
+ * architecture is injected server-side so the agent can't set it.
*/
export function createSkillBuilderTools(ctx: SkillToolContext): Tool[] {
- const { sessionDir, architecture, analysis, onPlan, onSubmit } = ctx;
+ const { architecture, onPlan, onSubmit } = ctx;
const progress = (m: string) => ctx.onProgress?.(m);
- const getAnalysis: Tool = {
- name: "get_analysis",
- description:
- "Return the approved analysis you are generalizing: the overall intent and the ordered list of steps (with each step's title, detail, apps, and evidence). Read this first.",
- parameters: { type: "object", properties: {}, additionalProperties: false },
- handler: () => {
- progress("Reading the approved analysis…");
- const view = {
- intent: analysis.intent,
- intentRationale: analysis.intentRationale,
- stepCount: analysis.steps.length,
- steps: analysis.steps.map((s) => ({
- id: s.id,
- title: s.title,
- detail: s.detail,
- apps: s.apps,
- evidence: s.evidence,
- })),
- };
- return JSON.stringify(view, null, 2);
- },
- };
-
- const getTimeline: Tool = {
- name: "get_timeline",
- description:
- "Return the deterministic timeline behind the analysis: ordered steps with their app, window titles, hosts, URLs, terminal commands, clipboard counts and markers. Use it to ground your native-tool mapping in real evidence.",
- parameters: { type: "object", properties: {}, additionalProperties: false },
- handler: () => {
- progress("Reading the timeline…");
- const bundle = readBundle(sessionDir);
- if (!bundle) {
- return "No timeline is available (bundle.json missing). Work from get_analysis instead.";
- }
- const view = {
- durationMs: bundle.session.durationMs,
- platform: bundle.session.platform,
- steps: bundle.steps.map((s) => ({
- index: s.index,
- app: s.app,
- titles: s.titles,
- hosts: s.hosts,
- urls: s.urls,
- commands: s.commands,
- clipboardCount: s.clipboardCount,
- markers: s.markers,
- summary: s.summary,
- })),
- };
- return JSON.stringify(view, null, 2);
- },
- };
-
const proposePlan: Tool = {
name: "propose_plan",
description:
@@ -225,5 +154,5 @@ export function createSkillBuilderTools(ctx: SkillToolContext): Tool[] {
},
};
- return [getAnalysis, getTimeline, proposePlan, submitSkill];
+ return [proposePlan, submitSkill];
}
diff --git a/src/App.css b/src/App.css
index 96f266f..a44fe8f 100644
--- a/src/App.css
+++ b/src/App.css
@@ -267,6 +267,22 @@ button:focus-visible,
box-shadow: 0 0 6px rgba(var(--rec-rgb), 0.55);
}
+.tag.auto {
+ color: var(--brand-ink); /* automation — a distinct coral, set apart from the green skill tag */
+}
+
+.tag.auto::before {
+ background: var(--brand-ink);
+}
+
+.sess-tags {
+ display: inline-flex;
+ align-items: center;
+ justify-content: flex-end;
+ flex-wrap: wrap;
+ gap: 6px;
+}
+
/* =========================================================================
Recorder HUD (compact window)
========================================================================= */
@@ -1694,3 +1710,45 @@ button:focus-visible,
border-radius: 8px;
padding: 8px 11px;
}
+
+/* Automation-specific: trigger, prompt-steps, and the import hint */
+.sb-trigger {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ background: var(--surface);
+ border: 1px solid var(--line);
+ border-radius: 9px;
+ padding: 10px 12px;
+}
+
+.trigger-when {
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--text);
+}
+
+.trigger-cond {
+ font-size: 12.5px;
+ color: var(--muted);
+}
+
+.sb-steps li .sb-step-label {
+ display: block;
+ font-weight: 600;
+ color: var(--text);
+}
+
+.sb-steps li .sb-step-prompt {
+ display: block;
+ color: var(--muted);
+ line-height: 1.5;
+}
+
+.sb-import-hint {
+ margin: 4px 0 0;
+ font-size: 12.5px;
+ line-height: 1.5;
+ color: var(--muted) !important;
+ max-width: 460px;
+}
diff --git a/src/Library.tsx b/src/Library.tsx
index 30f9263..5d50619 100644
--- a/src/Library.tsx
+++ b/src/Library.tsx
@@ -1,9 +1,21 @@
import { useCallback, useEffect, useRef, useState } from "react";
import type { Analysis } from "../common/analysis";
-import type { AnalyzeProgress, SessionSummary, SkillBuildProgress } from "../common/ipc";
-import type { BuiltSkill, SkillArchitecture, SkillPlan } from "../common/skill";
-import { ARCHITECTURES } from "../common/skill";
+import type {
+ AnalyzeProgress,
+ AutomationBuildProgress,
+ SessionSummary,
+ SkillBuildProgress,
+} from "../common/ipc";
+import type {
+ BuildTarget,
+ BuiltSkill,
+ SkillArchitecture,
+ SkillPlan,
+} from "../common/skill";
+import { ARCHITECTURES, TARGETS } from "../common/skill";
+import type { AutomationPlan, BuiltAutomation } from "../common/automation";
+import { describeSchedule } from "../common/automation";
import { formatDur, formatMs, formatWhen, shortLabel } from "./format";
export function Library() {
@@ -138,15 +150,19 @@ function SessionsList({
>
<div className="sess-top">
<span className="sess-when">{formatWhen(s.startedAt)}</span>
- {s.hasSkill ? (
- <span className="tag ok">skill</span>
- ) : s.analysis ? (
- <span className="tag an">analyzed</span>
- ) : !s.processed ? (
- <span className="tag warn">processing</span>
- ) : (
- <span className="tag recorded">recorded</span>
- )}
+ <span className="sess-tags">
+ {s.hasSkill && <span className="tag ok">skill</span>}
+ {s.hasAutomation && <span className="tag auto">automation</span>}
+ {!s.hasSkill && !s.hasAutomation && s.analysis && (
+ <span className="tag an">analyzed</span>
+ )}
+ {!s.hasSkill && !s.hasAutomation && !s.analysis && !s.processed && (
+ <span className="tag warn">processing</span>
+ )}
+ {!s.hasSkill && !s.hasAutomation && !s.analysis && s.processed && (
+ <span className="tag recorded">recorded</span>
+ )}
+ </span>
</div>
<div className="sess-intent">
{s.analysis
@@ -210,9 +226,17 @@ function AnalysisWorkspace({
const [editing, setEditing] = useState(false);
const [draftTitle, setDraftTitle] = useState("");
const [draftIntent, setDraftIntent] = useState("");
- // A recording that's already a skill opens straight to the skill; otherwise
- // it opens to the analysis, where "Create skill" starts the builder.
- const [building, setBuilding] = useState(summary.hasSkill);
+ // The final stage: pick a target, then build a skill or an automation. A recording
+ // that is already exactly one kind opens straight to it; otherwise it opens to the
+ // analysis, where "Create…" starts the target picker.
+ const initialLaunch: LaunchTarget =
+ summary.hasSkill && !summary.hasAutomation
+ ? "skill"
+ : summary.hasAutomation && !summary.hasSkill
+ ? "automation"
+ : "none";
+ const [launch, setLaunch] = useState<LaunchTarget>(initialLaunch);
+ const [chosenArch, setChosenArch] = useState<SkillArchitecture>("scout");
// Set while the user is deliberately canceling, so the aborted run's rejection
// doesn't surface as an error toast.
const canceled = useRef(false);
@@ -311,14 +335,43 @@ function AnalysisWorkspace({
setNotes((prev) => ({ ...prev, [stepId]: note }));
}, []);
- if (building) {
+ if (launch === "picker") {
+ return (
+ <TargetPicker
+ startedAt={summary.startedAt}
+ onPick={(t) => {
+ setChosenArch(t.architecture);
+ setLaunch(t.kind);
+ }}
+ onClose={() => setLaunch("none")}
+ />
+ );
+ }
+
+ if (launch === "skill") {
return (
<SkillBuilderView
sessionId={sessionId}
+ architecture={chosenArch}
startedAt={summary.startedAt}
hasSkill={summary.hasSkill}
onClose={() => {
- setBuilding(false);
+ setLaunch("none");
+ void onChanged();
+ }}
+ />
+ );
+ }
+
+ if (launch === "automation") {
+ return (
+ <AutomationBuilderView
+ sessionId={sessionId}
+ architecture={chosenArch}
+ startedAt={summary.startedAt}
+ hasAutomation={summary.hasAutomation}
+ onClose={() => {
+ setLaunch("none");
void onChanged();
}}
/>
@@ -459,26 +512,38 @@ function AnalysisWorkspace({
{analysis && !analyzing && (
<div className="ws-foot">
- <span className="foot-status">{summary.hasSkill ? "Skill created" : ""}</span>
+ <span className="foot-status">{launchFootStatus(summary)}</span>
<div className="ws-foot-actions">
{hasFeedback && (
<button className="secondary" onClick={sendFeedback}>
Send feedback &amp; re-analyze
</button>
)}
+ {summary.hasSkill && (
+ <button className="secondary" onClick={() => setLaunch("skill")} title="Open the skill built from this recording">
+ Open skill →
+ </button>
+ )}
+ {summary.hasAutomation && (
+ <button
+ className="secondary"
+ onClick={() => setLaunch("automation")}
+ title="Open the automation built from this recording"
+ >
+ Open automation →
+ </button>
+ )}
<button
className="record-cta"
- onClick={() => setBuilding(true)}
+ onClick={() => setLaunch("picker")}
disabled={hasFeedback}
title={
hasFeedback
? "Send or clear your feedback first"
- : summary.hasSkill
- ? "Open the skill built from this recording"
- : "Turn this recording into a reusable skill"
+ : "Turn this recording into a skill or an automation"
}
>
- {summary.hasSkill ? "Open skill →" : "Create skill →"}
+ {summary.hasSkill || summary.hasAutomation ? "Create another →" : "Create…"}
</button>
</div>
</div>
@@ -487,9 +552,64 @@ function AnalysisWorkspace({
);
}
+/* --- Final stage: target picker + builders -------------------------------- */
+
+/** Which final-stage surface the analysis workspace is showing. */
+type LaunchTarget = "none" | "picker" | "skill" | "automation";
+
+function launchFootStatus(summary: SessionSummary): string {
+ if (summary.hasSkill && summary.hasAutomation) return "Skill & automation created";
+ if (summary.hasSkill) return "Skill created";
+ if (summary.hasAutomation) return "Automation created";
+ return "";
+}
+
+/** "What do you want to build?" — picks both kind and architecture up front. */
+function TargetPicker({
+ startedAt,
+ onPick,
+ onClose,
+}: {
+ startedAt: number | null;
+ onPick: (target: BuildTarget) => void;
+ onClose: () => void;
+}) {
+ return (
+ <section className="ws">
+ <div className="ws-head">
+ <div className="ws-titles">
+ <span className="eyebrow">Create</span>
+ <span className="ws-when">{formatWhen(startedAt)}</span>
+ </div>
+ <button className="ghost" onClick={onClose} title="Back to the analysis">
+ Close
+ </button>
+ </div>
+ <div className="ws-body">
+ <div className="sb-arch">
+ <p className="sb-lead">What do you want to build from this recording?</p>
+ <div className="arch-grid">
+ {TARGETS.map((t) => (
+ <button
+ key={`${t.kind}:${t.architecture}`}
+ className="arch-card"
+ disabled={!t.enabled}
+ onClick={() => t.enabled && onPick(t)}
+ >
+ <span className="arch-name">{t.label}</span>
+ <span className="arch-note">{t.enabled ? t.note : "Coming soon"}</span>
+ </button>
+ ))}
+ </div>
+ </div>
+ </div>
+ </section>
+ );
+}
+
/* --- Skill builder ------------------------------------------------------- */
-type BuildPhase = "loading" | "arch" | "planning" | "plan" | "creating" | "done";
+type BuildPhase = "loading" | "ready" | "planning" | "plan" | "creating" | "done";
const SOURCE_LABEL: Record<SkillPlan["inputs"][number]["source"], string> = {
ask: "You provide it",
@@ -499,19 +619,21 @@ const SOURCE_LABEL: Record<SkillPlan["inputs"][number]["source"], string> = {
function SkillBuilderView({
sessionId,
+ architecture: initialArch,
startedAt,
hasSkill,
onClose,
}: {
sessionId: string;
+ architecture: SkillArchitecture;
startedAt: number | null;
hasSkill: boolean;
onClose: () => void;
}) {
- // If this recording is already a skill, hold on a spinner until we've loaded
- // it, so we never flash the architecture picker before jumping to the skill.
- const [phase, setPhase] = useState<BuildPhase>(hasSkill ? "loading" : "arch");
- const [architecture, setArchitecture] = useState<SkillArchitecture>("scout");
+ // If this recording is already a skill, hold on a spinner until we've loaded it,
+ // so we never flash the planning state before jumping to the skill.
+ const [phase, setPhase] = useState<BuildPhase>(hasSkill ? "loading" : "ready");
+ const [architecture, setArchitecture] = useState<SkillArchitecture>(initialArch);
const [plan, setPlan] = useState<SkillPlan | null>(null);
const [statusLine, setStatusLine] = useState("");
const [feedback, setFeedback] = useState("");
@@ -541,8 +663,8 @@ function SkillBuilderView({
if (s.plan) setPlan(s.plan);
setPhase("done");
} else if (hasSkill) {
- // We expected a skill but couldn't load it; fall back to the picker.
- setPhase("arch");
+ // We expected a skill but couldn't load it; fall back to the ready screen.
+ setPhase("ready");
}
});
return () => {
@@ -571,7 +693,7 @@ function SkillBuilderView({
setPhase("plan");
} else if (!canceled.current) {
setError(res.error ?? "Planning failed");
- setPhase(note ? "plan" : "arch");
+ setPhase(note ? "plan" : "ready");
}
},
[sessionId, architecture],
@@ -600,7 +722,7 @@ function SkillBuilderView({
inFlight.current = false;
setStatusLine("Stopping…");
await window.skillRecorder.cancelSkill(sessionId);
- setPhase(plan ? "plan" : "arch");
+ setPhase(plan ? "plan" : "ready");
}, [sessionId, plan]);
const busy = phase === "planning" || phase === "creating";
@@ -632,22 +754,9 @@ function SkillBuilderView({
</div>
)}
- {phase === "arch" && (
+ {phase === "ready" && (
<div className="sb-arch">
- <p className="sb-lead">Which agent should run this skill?</p>
- <div className="arch-grid">
- {ARCHITECTURES.map((a) => (
- <button
- key={a.id}
- className={`arch-card ${architecture === a.id ? "on" : ""}`}
- disabled={!a.enabled}
- onClick={() => a.enabled && setArchitecture(a.id)}
- >
- <span className="arch-name">{a.label}</span>
- <span className="arch-note">{a.enabled ? a.note : "Coming soon"}</span>
- </button>
- ))}
- </div>
+ <p className="sb-lead">Build a {archLabel(architecture)} skill from this recording.</p>
<button className="record-cta" onClick={() => void runPlan()}>
Plan the skill →
</button>
@@ -799,6 +908,297 @@ function archLabel(id: SkillArchitecture): string {
return ARCHITECTURES.find((a) => a.id === id)?.label ?? id;
}
+/* --- Automation builder --------------------------------------------------- */
+
+function AutomationBuilderView({
+ sessionId,
+ architecture: initialArch,
+ startedAt,
+ hasAutomation,
+ onClose,
+}: {
+ sessionId: string;
+ architecture: SkillArchitecture;
+ startedAt: number | null;
+ hasAutomation: boolean;
+ onClose: () => void;
+}) {
+ const [phase, setPhase] = useState<BuildPhase>(hasAutomation ? "loading" : "ready");
+ const [architecture, setArchitecture] = useState<SkillArchitecture>(initialArch);
+ const [plan, setPlan] = useState<AutomationPlan | null>(null);
+ const [statusLine, setStatusLine] = useState("");
+ const [feedback, setFeedback] = useState("");
+ const [error, setError] = useState<string | null>(null);
+ const [exportedPath, setExportedPath] = useState("");
+ const [builtName, setBuiltName] = useState("");
+ const canceled = useRef(false);
+ const inFlight = useRef(false);
+
+ useEffect(() => {
+ return () => {
+ if (inFlight.current) void window.skillRecorder.cancelAutomation(sessionId);
+ };
+ }, [sessionId]);
+
+ // Reopen straight to the exported state if this recording already has one.
+ useEffect(() => {
+ let live = true;
+ void window.skillRecorder.getAutomation(sessionId).then((a: BuiltAutomation | null) => {
+ if (!live) return;
+ if (a?.exportedPath) {
+ setBuiltName(a.name);
+ setExportedPath(a.exportedPath);
+ setArchitecture(a.architecture);
+ if (a.plan) setPlan(a.plan);
+ setPhase("done");
+ } else if (hasAutomation) {
+ setPhase("ready");
+ }
+ });
+ return () => {
+ live = false;
+ };
+ }, [sessionId, hasAutomation]);
+
+ useEffect(() => {
+ return window.skillRecorder.onAutomationProgress((p: AutomationBuildProgress) => {
+ if (p.sessionId === sessionId) setStatusLine(p.message);
+ });
+ }, [sessionId]);
+
+ const runPlan = useCallback(
+ async (note?: string) => {
+ canceled.current = false;
+ inFlight.current = true;
+ setError(null);
+ setStatusLine(note ? "Refining the plan…" : "Planning the automation…");
+ setPhase("planning");
+ const res = await window.skillRecorder.buildAutomation({ sessionId, architecture, feedback: note });
+ inFlight.current = false;
+ if (res.ok && res.plan) {
+ setPlan(res.plan);
+ setFeedback("");
+ setPhase("plan");
+ } else if (!canceled.current) {
+ setError(res.error ?? "Planning failed");
+ setPhase(note ? "plan" : "ready");
+ }
+ },
+ [sessionId, architecture],
+ );
+
+ const create = useCallback(async () => {
+ canceled.current = false;
+ inFlight.current = true;
+ setError(null);
+ setStatusLine("Writing the automation…");
+ setPhase("creating");
+ const res = await window.skillRecorder.createAutomation(sessionId);
+ inFlight.current = false;
+ if (res.ok && res.automation) {
+ setBuiltName(res.automation.name);
+ setExportedPath(res.path ?? res.automation.exportedPath ?? "");
+ setPhase("done");
+ } else if (!canceled.current) {
+ setError(res.error ?? "Could not create the automation");
+ setPhase("plan");
+ }
+ }, [sessionId]);
+
+ const cancelRun = useCallback(async () => {
+ canceled.current = true;
+ inFlight.current = false;
+ setStatusLine("Stopping…");
+ await window.skillRecorder.cancelAutomation(sessionId);
+ setPhase(plan ? "plan" : "ready");
+ }, [sessionId, plan]);
+
+ const busy = phase === "planning" || phase === "creating";
+
+ return (
+ <section className="ws">
+ <div className="ws-head">
+ <div className="ws-titles">
+ <span className="eyebrow">{phase === "done" ? "Automation" : "Create automation"}</span>
+ <span className="ws-when">{formatWhen(startedAt)}</span>
+ </div>
+ <button
+ className="ghost"
+ onClick={onClose}
+ disabled={busy}
+ title={phase === "done" ? "View this recording's analysis" : "Back to the analysis"}
+ >
+ {phase === "done" ? "Analysis" : "Close"}
+ </button>
+ </div>
+
+ <div className="ws-body">
+ {error && <div className="analysis-error">{error}</div>}
+
+ {phase === "loading" && (
+ <div className="status-line">
+ <span className="spinner" />
+ <span className="status-text">Opening the automation…</span>
+ </div>
+ )}
+
+ {phase === "ready" && (
+ <div className="sb-arch">
+ <p className="sb-lead">Build a {archLabel(architecture)} automation from this recording.</p>
+ <button className="record-cta" onClick={() => void runPlan()}>
+ Plan the automation →
+ </button>
+ </div>
+ )}
+
+ {busy && (
+ <div className="status-line">
+ <span className="spinner" />
+ <span className="status-text">{statusLine || "Working…"}</span>
+ <button className="linky status-cancel" onClick={cancelRun}>
+ Cancel
+ </button>
+ </div>
+ )}
+
+ {phase === "plan" && plan && (
+ <div className="sb-plan">
+ <div className="sb-planhead">
+ <h2 className="sb-title">{plan.title}</h2>
+ <code className="sb-slug">{plan.name}</code>
+ </div>
+ <p className="sb-desc">{plan.description}</p>
+
+ <div className="sb-sec">
+ <span className="eyebrow">When it runs</span>
+ <div className="sb-trigger">
+ <span className="trigger-when">{describeSchedule(plan.trigger.schedule)}</span>
+ {plan.trigger.type === "condition" && plan.trigger.condition && (
+ <span className="trigger-cond">Only when: {plan.trigger.condition}</span>
+ )}
+ </div>
+ <p className="sb-refine-hint">
+ A recording has no schedule of its own — this is a suggestion. Say e.g. “every
+ weekday at 8am” below to change it.
+ </p>
+ </div>
+
+ {(plan.summary || plan.generalization) && (
+ <div className="sb-sec">
+ <span className="eyebrow">How it generalizes</span>
+ {plan.summary && <p>{plan.summary}</p>}
+ {plan.generalization && <p className="sb-muted">{plan.generalization}</p>}
+ </div>
+ )}
+
+ {plan.inputs.length > 0 && (
+ <div className="sb-sec">
+ <span className="eyebrow">Inputs</span>
+ <ul className="sb-inputs">
+ {plan.inputs.map((inp, i) => (
+ <li key={i} className="input-row">
+ <div className="input-main">
+ <span className="input-name">{inp.name}</span>
+ <span className={`src-badge src-${inp.source}`}>{SOURCE_LABEL[inp.source]}</span>
+ </div>
+ {(inp.detail || inp.description) && (
+ <span className="input-detail">{inp.detail || inp.description}</span>
+ )}
+ </li>
+ ))}
+ </ul>
+ </div>
+ )}
+
+ {plan.steps.length > 0 && (
+ <div className="sb-sec">
+ <span className="eyebrow">What the automation will do</span>
+ <ol className="sb-steps">
+ {plan.steps.map((s, i) => (
+ <li key={i}>
+ {s.label && <span className="sb-step-label">{s.label}</span>}
+ <span className="sb-step-prompt">{s.prompt}</span>
+ </li>
+ ))}
+ </ol>
+ </div>
+ )}
+
+ <div className="sb-sec sb-refine">
+ <span className="eyebrow">Adjust the plan</span>
+ <p className="sb-refine-hint">
+ Describe any change in plain language — the schedule, the steps, anything — then
+ Refine to re-plan before you export.
+ </p>
+ <textarea
+ className="overall-fb"
+ placeholder="e.g. 'run every weekday at 8am', or 'add a step that emails me the summary'…"
+ value={feedback}
+ onChange={(e) => setFeedback(e.target.value)}
+ />
+ </div>
+ </div>
+ )}
+
+ {phase === "done" && (
+ <div className="sb-done">
+ <div className="sb-check" aria-hidden>
+ ✓
+ </div>
+ <h2 className="sb-title">Automation ready</h2>
+ <p>
+ <code className="sb-slug">{builtName}</code> is built for {archLabel(architecture)}.
+ </p>
+ {exportedPath && <p className="sb-path">{exportedPath}</p>}
+ <p className="sb-import-hint">
+ Import it into Scout: open Scout → Automations → Import, and choose this bundle folder.
+ </p>
+ </div>
+ )}
+ </div>
+
+ {phase === "plan" && plan && (
+ <div className="ws-foot">
+ <span className="foot-status" />
+ <div className="ws-foot-actions">
+ <button
+ className="secondary"
+ onClick={() => void runPlan(feedback.trim())}
+ disabled={!feedback.trim()}
+ title={feedback.trim() ? "Apply your changes and re-plan" : "Type a change above to refine"}
+ >
+ Refine plan
+ </button>
+ <button
+ className="record-cta"
+ onClick={() => void create()}
+ title="Create and export the automation bundle"
+ >
+ Create &amp; export automation
+ </button>
+ </div>
+ </div>
+ )}
+
+ {phase === "done" && (
+ <div className="ws-foot">
+ <span className="foot-status">Automation created</span>
+ <div className="ws-foot-actions">
+ {exportedPath && (
+ <button
+ className="record-cta"
+ onClick={() => void window.skillRecorder.revealAutomation(sessionId)}
+ >
+ Reveal bundle
+ </button>
+ )}
+ </div>
+ </div>
+ )}
+ </section>
+ );
+}
+
/* --- One step, told as plain language ------------------------------------- */
function StepCard({