Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions desktop/main/agent-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,8 @@ export async function skillList(cwd?: string): Promise<{ ok: boolean; rows?: Ski
}
return { ok: false, error: `could not parse skill list line: ${line.slice(0, 120)}` };
}
// ATO-67: a learned draft pending review is not a disabled skill; Pending review lists it (skill-drafts-ipc.ts).
if (cells[3] === "pending") continue;
rows.push({
name: cells[0]!,
version: (cells[1] ?? "").replace(/^v/, ""),
Expand Down
7 changes: 6 additions & 1 deletion desktop/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { AgentClient, APPROVAL_DECISIONS, commandOf, probeRemoteAgent, type Proj
import { wireAgentLiveIpc } from "./agent-live.js";
import { wirePluginsIpc } from "./plugins-ipc.js";
import { wireSkillEvalIpc } from "./skill-eval-ipc.js";
import { wireSkillDraftsIpc } from "./skill-drafts-ipc.js";
import { pushTurnNote, wirePushIpc } from "./push-ipc.js";
import { wireAttachmentIpc } from "./attachments-ipc.js";
import { wireWindowSnapshotIpc } from "./window-snapshot-ipc.js";
Expand Down Expand Up @@ -3091,6 +3092,8 @@ function wireIpc(client: AgentClient): void {
wirePluginsIpc();
// ATO-1102: "Test skill" on a skill card, through `atag skill eval` (skill-eval-ipc.ts).
wireSkillEvalIpc({ cwd: () => client.status.workingDir });
// ATO-67: Settings › Skills › Pending review, through `atag skill learned` (skill-drafts-ipc.ts).
wireSkillDraftsIpc({ cwd: () => client.status.workingDir, isRemote: () => client.isRemote });
// ATO-1129: Settings › Connections › Phone push, through `atag push` (push-ipc.ts).
wirePushIpc();
// ATO-404/405: the composer's attachments, saved into <stateDir>/inbox/desktop.
Expand Down Expand Up @@ -3195,7 +3198,9 @@ function wireIpc(client: AgentClient): void {
requiresBins?: string[]; installHints?: Record<string, string> }>;
};
if (!data.workingDir) return skillList(client.status.workingDir);
const rows = data.skills.map(row => ({ ...row, version: row.version || "—", enabled: !row.disabled }));
// ATO-67: a learned draft pending review is not an installed skill (the Pending review group shows it).
const rows = data.skills.filter(row => (row as { status?: string }).status !== "pending")
.map(row => ({ ...row, version: row.version || "—", enabled: !row.disabled }));
return { ok: true, workingDir: data.workingDir, projectSkillsEnabled: data.projectSkillsEnabled,
errors: data.errors, rows: client.isRemote ? rows : skillRowsWithBins(rows) };
} catch (err) { return { ok: false, error: err instanceof Error ? err.message : String(err) }; }
Expand Down
110 changes: 110 additions & 0 deletions desktop/main/skill-drafts-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* ATO-67: skills the agent learned from a turn that read outside content
* (a web page, a file, a tool's output) are not saved straight away. The
* agent keeps them as drafts until the person looks at them; Settings ›
* Skills shows them under "Pending review" with Show / Approve / Discard.
*
* This file is pure: the id check, the argv and the output parsing.
* skill-drafts-ipc.ts runs the commands.
*
* The agent's side (src/cli/skill.ts, src/skills/learning/pending-drafts.ts):
* - `atag skill list --json` → an array of rows; a draft is a row with
* `status: "pending"`, `draftId`, `draftKind` ("create" | "patch"), its
* `name`, and `description` = the model's reason for the skill;
* - `atag skill learned show <id> --json` → the draft: its SKILL.md, the
* current SKILL.md and a diff for a patch, the sources it came from;
* - `atag skill learned approve <id>` / `discard <id>` → exit 0 when done.
* An agent older than that answers `skill list --json` with its plain
* tab-separated listing (or an error): no drafts, and no error on screen.
*/

/** Draft ids are short hex today (PENDING_ID_PATTERN); this is a little wider, and never a leading `-` (argv flag). */
export const SKILL_DRAFT_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;

export interface SkillDraftRow {
id: string;
name: string;
kind: "create" | "patch";
/** The model's reason for the skill, as it wrote it. Plain text: the window escapes it. */
reason: string;
}

export interface SkillDraftDetail {
id: string;
kind: "create" | "patch";
skill: string;
path: string;
origin: string;
sources: string[];
reason: string;
createdAt: number | string | null;
skillMd: string;
currentSkillMd: string | null;
diff: string | null;
}

export function skillDraftListArgs(): string[] {
return ["skill", "list", "--json"];
}
export function skillDraftShowArgs(id: string): string[] {
return ["skill", "learned", "show", id, "--json"];
}
export function skillDraftActionArgs(action: "approve" | "discard", id: string): string[] {
return ["skill", "learned", action, id];
}

const str = (v: unknown): string => (typeof v === "string" ? v : "");

/**
* The pending rows of `skill list --json`. Anything that is not a JSON array
* (an older agent's tab-separated listing, an empty answer) is no drafts.
*/
export function parseSkillDrafts(stdout: string): SkillDraftRow[] {
let parsed: unknown;
try {
parsed = JSON.parse(stdout);
} catch {
return [];
}
if (!Array.isArray(parsed)) return [];
const out: SkillDraftRow[] = [];
const seen = new Set<string>();
for (const row of parsed) {
if (!row || typeof row !== "object") continue;
const r = row as Record<string, unknown>;
if (r.status !== "pending") continue;
const id = str(r.draftId);
if (!SKILL_DRAFT_ID_RE.test(id) || seen.has(id)) continue;
seen.add(id);
out.push({ id, name: str(r.name) || id, kind: r.draftKind === "patch" ? "patch" : "create", reason: str(r.description) });
}
return out;
}

/** `skill learned show <id> --json`, or null when it is not the document. */
export function parseSkillDraftShow(stdout: string): SkillDraftDetail | null {
let parsed: unknown;
try {
parsed = JSON.parse(stdout);
} catch {
return null;
}
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
const d = parsed as Record<string, unknown>;
const id = str(d.id);
const skillMd = d.skillMd;
if (!SKILL_DRAFT_ID_RE.test(id) || typeof skillMd !== "string") return null;
return {
id,
kind: d.kind === "patch" ? "patch" : "create",
skill: str(d.skill),
path: str(d.path),
origin: str(d.origin),
sources: Array.isArray(d.sources) ? d.sources.filter((s): s is string => typeof s === "string") : [],
reason: str(d.reason),
createdAt: typeof d.createdAt === "number" || typeof d.createdAt === "string" ? d.createdAt : null,
skillMd,
currentSkillMd: typeof d.currentSkillMd === "string" ? d.currentSkillMd : null,
diff: typeof d.diff === "string" ? d.diff : null,
};
}
82 changes: 82 additions & 0 deletions desktop/main/skill-drafts-ipc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ipcMain } from "electron";

import { atagRun, plainCliError } from "./agent-cli.js";
import {
SKILL_DRAFT_ID_RE,
parseSkillDraftShow,
parseSkillDrafts,
skillDraftActionArgs,
skillDraftListArgs,
skillDraftShowArgs,
type SkillDraftDetail,
type SkillDraftRow,
} from "./skill-drafts-cli.js";

/**
* ATO-67: Settings › Skills › "Pending review" (skill-drafts-cli.ts says what
* the agent prints). Four routes:
*
* cli:skillDrafts → `{ok, rows}`: the drafts waiting for the person (empty on an older agent)
* cli:skillDraftShow → `{ok, draft}`: one draft's SKILL.md, diff and sources
* cli:skillDraftApprove → `atag skill learned approve <id>`
* cli:skillDraftDiscard → `atag skill learned discard <id>`
*
* Drafts live in the agent's state folder on this computer, so while the app
* runs chats on another computer the list is empty here. Nothing throws at the window.
*/

type Deps = { cwd: () => string | undefined; isRemote: () => boolean };

export async function skillDrafts(cwd?: string): Promise<{ ok: true; rows: SkillDraftRow[] }> {
const res = await atagRun(skillDraftListArgs(), 45_000, cwd);
// An older agent: `--json` unknown, or its plain listing. Either way, no drafts and no error.
return { ok: true, rows: res.ok ? parseSkillDrafts(res.stdout) : [] };
}

export async function skillDraftShow(id: string, cwd?: string): Promise<{ ok: boolean; draft?: SkillDraftDetail; error?: string }> {
if (!SKILL_DRAFT_ID_RE.test(id)) return { ok: false, error: `not a draft id: ${id}` };
const res = await atagRun(skillDraftShowArgs(id), 30_000, cwd);
const draft = parseSkillDraftShow(res.stdout);
if (draft) return { ok: true, draft };
return { ok: false, error: plainCliError(res.stderr) || res.error || "The agent did not show this draft." };
}

async function skillDraftAction(action: "approve" | "discard", id: string, cwd?: string): Promise<{ ok: boolean; error?: string }> {
if (!SKILL_DRAFT_ID_RE.test(id)) return { ok: false, error: `not a draft id: ${id}` };
const res = await atagRun(skillDraftActionArgs(action, id), 30_000, cwd);
if (res.ok) return { ok: true };
return { ok: false, error: plainCliError(res.stderr) || res.stdout.trim() || res.error || `Could not ${action} the draft.` };
}
export const skillDraftApprove = (id: string, cwd?: string) => skillDraftAction("approve", id, cwd);
export const skillDraftDiscard = (id: string, cwd?: string) => skillDraftAction("discard", id, cwd);

const REMOTE = "Learned drafts are reviewed on the computer that runs the agent.";

export function wireSkillDraftsIpc(deps: Deps): void {
const guard = async <T>(fn: () => Promise<T>): Promise<T | { ok: false; error: string }> => {
try {
return await fn();
} catch (err) {
return { ok: false, error: err instanceof Error ? err.message : String(err) };
}
};
const idOf = (v: unknown): string | null => (typeof v === "string" && SKILL_DRAFT_ID_RE.test(v) ? v : null);

ipcMain.handle("cli:skillDrafts", () =>
deps.isRemote() ? { ok: true, rows: [] } : guard(() => skillDrafts(deps.cwd())));
ipcMain.handle("cli:skillDraftShow", (_event, id: unknown) => {
const clean = idOf(id);
if (!clean) return { ok: false, error: "draft id required" };
return deps.isRemote() ? { ok: false, error: REMOTE } : guard(() => skillDraftShow(clean, deps.cwd()));
});
ipcMain.handle("cli:skillDraftApprove", (_event, id: unknown) => {
const clean = idOf(id);
if (!clean) return { ok: false, error: "draft id required" };
return deps.isRemote() ? { ok: false, error: REMOTE } : guard(() => skillDraftApprove(clean, deps.cwd()));
});
ipcMain.handle("cli:skillDraftDiscard", (_event, id: unknown) => {
const clean = idOf(id);
if (!clean) return { ok: false, error: "draft id required" };
return deps.isRemote() ? { ok: false, error: REMOTE } : guard(() => skillDraftDiscard(clean, deps.cwd()));
});
}
5 changes: 5 additions & 0 deletions desktop/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ contextBridge.exposeInMainWorld("atomic", {
ipcRenderer.invoke("cli:skillSetDisabled", { name, disabled, scope, sessionId }),
skillProjectEnabled: (enabled: boolean, sessionId?: string | null) =>
ipcRenderer.invoke("cli:skillProjectEnabled", { enabled, sessionId }),
/** ATO-67: learned skills waiting for review (main/skill-drafts-ipc.ts). */
skillDrafts: () => ipcRenderer.invoke("cli:skillDrafts"),
skillDraftShow: (id: string) => ipcRenderer.invoke("cli:skillDraftShow", id),
skillDraftApprove: (id: string) => ipcRenderer.invoke("cli:skillDraftApprove", id),
skillDraftDiscard: (id: string) => ipcRenderer.invoke("cli:skillDraftDiscard", id),
/** ATO-954: Settings › Plugins (main/plugins-ipc.ts). */
pluginList: () => ipcRenderer.invoke("cli:pluginList"),
/** ATO-1129: Settings › Connections › Phone push (main/push-ipc.ts). */
Expand Down
6 changes: 6 additions & 0 deletions desktop/renderer/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ button.set-search:hover{border-color:var(--bd)}
.set-skeval{padding:10px 12px;border-radius:8px;margin:10px 0}
.set-skeval .acts{align-items:center;gap:8px;margin:0}
.set-skeval p{margin:6px 0 0}
/* ATO-67: Pending review, learned skills waiting above the skill rows */
.set-skdrafts{margin-bottom:14px}
.set-skdraft{display:block;padding:10px 12px}
.set-skdraft .d{margin:4px 0 0;white-space:normal}
.set-skdraft .acts{align-items:center;gap:8px;margin:8px 0 0}
.set-skdsrc{margin:4px 0 10px;padding-left:18px}

/* Empty and loading states */
.set-empty{padding:40px 20px 28px}
Expand Down
12 changes: 9 additions & 3 deletions desktop/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,8 @@ const SKP = {
};
/* ATO-1102: "Test skill" on the skill card: the open card's probe, the one run in flight, the last answer per skill. */
const SKE = {probeName:null, probe:null, seq:0, runningName:null, cancelling:false, outcomes:{}};
/* ATO-67: learned skills waiting for review, the "Pending review" group (workspace-skills.js, main/skill-drafts-ipc.ts). */
const SKD = createSkillDraftsController({api: () => BR, paint: () => { if (skillsVisible() && !skpTyping()) render(); }, changed: () => skpReloadRows()});
const SKP_FILTERS = ['all','enabled','disabled']; // skills-filter.ts FILTER_ORDER
const SKP_FILTER_LABELS = {all:'All', enabled:'Enabled', disabled:'Disabled'}; // Д43: the tabs, each with its count
const SKP_MAX_ROWS = 14, SKP_HUB_ROWS = 12, SKP_DETAIL_LINES = 32; // skills-panel.tsx / skills-hub-list.tsx / skills-detail.tsx
Expand Down Expand Up @@ -6472,6 +6474,7 @@ async function webhooksAct(v) {
async function refreshSkillList() {
if (!BR || !BR.skillList) return;
projectTrustCheck();
SKD.refresh(SKP.listRefreshing); // ATO-67: at most every 15 s, at once on Refresh
const key = skillContextKey();
if (SK.for !== key) {
SK.for = key; SK.rows = null; SK.err = null; SK.workingDir = null; SK.errors = []; SKILLS.length = 0;
Expand All @@ -6485,7 +6488,7 @@ async function refreshSkillList() {
const res = answer.result, before = JSON.stringify([SK.rows, SK.err, SK.projectSkillsEnabled]);
const oldDetail = SK.rows && SK.rows.find(row => row.name === SKP.detailName);
if (res && res.ok && Array.isArray(res.rows)) {
SK.rows = res.rows; SK.err = null; SK.at = Date.now();
SK.rows = skillRowsWithoutDrafts(res.rows); SK.err = null; SK.at = Date.now();
SK.workingDir = res.workingDir || null; SK.projectSkillsEnabled = res.projectSkillsEnabled !== false;
SK.errors = res.errors || [];
SKILLS.length = 0;
Expand Down Expand Up @@ -25492,6 +25495,7 @@ function skillsTabEntered() {
// Item 09: the section opens on its skills; Built-in tools is picked (its segment, `/tools`, which enters through here first).
if (SKP.view !== 'skills') { SKP.view = 'skills'; skpListTop(); render(); }
ensureSkillsPoll();
SKD.refresh(true);
if (SK.workingDir) refreshSkillList();
tpSkillsOmittedRefresh();
projectTrustCheck(true); // ATO-1250: the folder-trust row reads the agent's current answer
Expand All @@ -25509,7 +25513,7 @@ function skillsTab() {
ensureSkillsPoll();
// Soft Tactile (ST-08, ST-11): a confirm is a modal over the view it was
// raised from instead of replacing it; the same two states win as before.
const overlay = SKP.installConfirm ? skpInstallConfirmHTML() : SKP.removeConfirm ? skpRemoveConfirmHTML() : '';
const overlay = SKP.installConfirm ? skpInstallConfirmHTML() : SKP.removeConfirm ? skpRemoveConfirmHTML() : SKD.confirmHTML(esc);
let view;
// Д45: a card is drawn from its hub row at once (only its source waits for the detail read), so no view-wide loader here.
if (SKP.hubCard) view = skpHubCardHTML();
Expand Down Expand Up @@ -25551,7 +25555,7 @@ function skillsTab() {
+ (SKP.lastError ? '<div class="tuierr tk-notice tk-notice--red">' + ic('alert') + '<span class="grow">' + esc(SKP.lastError) + '</span></div>' : '')
+ (SK.err && !tools ? '<div class="tuierr tk-notice tk-notice--red">' + ic('alert') + '<span class="grow">' + esc(SK.err) + '</span></div>' : '')
+ skpMessages()
+ (tools ? skpToolsHTML(groups) : SKP.mode === 'detail' ? skpDetailHTML() : tpSkillsOmittedHTML() + skpListHTML(visible));
+ (tools ? skpToolsHTML(groups) : SKP.mode === 'detail' ? skpDetailHTML() : SKD.state.open ? SKD.detailHTML(esc) : tpSkillsOmittedHTML() + SKD.listHTML(esc) + skpListHTML(visible));
}
return '<div class="set-pane set-skills">' + view + overlay + '</div>';
}
Expand Down Expand Up @@ -26143,6 +26147,7 @@ function skillsAct(what) {
if (verb === 'removeCancel') { SKP.removeConfirm = null; render(); return; }
if (verb === 'test') { const name = sel(); if (name) skeRun(name); return; } // ATO-1102
if (verb === 'testCancel') { skeCancel(); return; }
if (verb === 'draft') { SKD.act(arg); return; } // ATO-67: Pending review
if (verb === 'refresh') {
if (SKP.mode === 'list' && SKP.view === 'tools') { skpToolsRefresh(); render(); return; } // Item 09: the list on screen is the agent's tools
if (SKP.mode === 'detail' && SKP.detailName) { refreshSkillList(); skpOpenDetail(SKP.detailName); return; }
Expand Down Expand Up @@ -26196,6 +26201,7 @@ function skillsKey(e, k, inText) {
if (k === 'n' || k === 'Escape') { e.preventDefault(); SKP.removeConfirm = null; render(); return true; }
return true;
}
if (SKP.mode === 'list' && SKP.view === 'skills' && SKD.key(e, k)) return true; // ATO-67: the Discard confirm, a draft's preview
if (SKP.hubCard) {
if (k === 'i' || k === 'y' || k === 'Enter') { e.preventDefault(); if (SKP.hubCard.installId) skpInstall(false); return true; } // handleHubCardKey: i / y / Enter
if (k === 'n' || k === 'Escape') { e.preventDefault(); skillsAct('back'); return true; }
Expand Down
Loading
Loading