Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

Report a coding agent's use of a repo skill to the workspace

Shrish Dwivedi1a891c18518b
diff --git a/src/claude/hooks.ts b/src/claude/hooks.ts
index 6d3f1f67..a5759e18 100644
--- a/src/claude/hooks.ts
+++ b/src/claude/hooks.ts
@@ -37,6 +37,7 @@ import { everyRepoLearnings } from '../notes/every-repo.js';
import type { Note } from '../notes/notes.js';
import { hostFacts } from '../skills/host-facts.js';
import { trailNow } from '../skills/settings.js';
+import { recordSkillUse, skillOfToolUse } from './skill-use.js';
import { keptContext, keptNotice } from './start-init.js';
export { lastFileScopeHint, promptAskTimeout } from './prompt-hook.js';
@@ -533,6 +534,7 @@ export async function main(event: string): Promise<void> {
if (event === 'tool-savings') {
handleToolUse(input, dir);
+ recordSkillUse(skillOfToolUse(input), input, dir);
// PostToolUse on Bash: the skills mark, and the post-tool offer channel's context (3.4),
// then the learnings about the file the call touched, in the same one answer.
emitHook('PostToolUse', withTouchLearnings(await postBashPart(input, dir, false), input, dir));
diff --git a/src/claude/prompt-hook.ts b/src/claude/prompt-hook.ts
index 54c1dac1..ae44a413 100644
--- a/src/claude/prompt-hook.ts
+++ b/src/claude/prompt-hook.ts
@@ -19,6 +19,7 @@ import { findNotes, listNotes, type NoteHit } from '../notes/notes.js';
import { INJECTED_POINTERS_CAP, notesForPrompt, relevantRetrieval, type AskJson } from './format.js';
import { CHILD_TIMEOUT_MS, emitHook, graftJsonWithin, payloadSessionId, withContextDirArg } from './hook-io.js';
import { promptPart } from './skills-wiring.js';
+import { recordSkillUse, skillOfPrompt } from './skill-use.js';
import { readSession, readStats, writeSession } from './state.js';
import { readWiring } from './stats.js';
import { ownText, PASTE_MARK } from '../trace/claude.js';
@@ -258,6 +259,8 @@ export async function handlePrompt(input: any, dir: string, opts: { budgetMs?: n
// Background completion notices are machine events, not user queries: no skills answer, no ask (#551).
if (String(input?.prompt ?? '').trimStart().startsWith('<task-notification>')) return;
const deadline = Date.now() + (opts.budgetMs ?? PROMPT_BUDGET_MS);
+ // `/name` for one of the repo's skills is a run of it; the name only goes.
+ recordSkillUse(skillOfPrompt(input?.prompt), input, dir);
const skills = await promptPart(input, dir);
if (skills.block) return void emitHook('UserPromptSubmit', { block: skills.block });
const say = (txt: string) => emitHook('UserPromptSubmit', { context: [skills.context, txt].filter(Boolean).join('\n\n'), notice: skills.notice });
diff --git a/src/claude/settings-merge.ts b/src/claude/settings-merge.ts
index 6e47a99e..70a9b9f0 100644
--- a/src/claude/settings-merge.ts
+++ b/src/claude/settings-merge.ts
@@ -75,8 +75,9 @@ function hookBlocks(command: (arg: string) => string): Record<string, Json[]> {
// Read/Grep/Glob as source reads vs graft as graft reads, which is what feeds
// `graft stats` and the `session_summary` graft-vs-grep ratio. Broad matcher,
// but the handler no-ops instantly unless there is something to record, so an
- // unrelated Bash or a plain Read costs only a stdin read.
- { matcher: 'Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob', hooks: [{ type: 'command', command: hookCmd_('tool-savings'), timeout: 8 }] },
+ // unrelated Bash or a plain Read costs only a stdin read. `Skill` is the
+ // agent using a skill: one of the repo's goes to the workspace as a run.
+ { matcher: 'Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob|Skill', hooks: [{ type: 'command', command: hookCmd_('tool-savings'), timeout: 8 }] },
],
// Longer than the other hooks: its `graft ask` is a real query, and a query
// brings the graph up to date first (graph/refresh.ts). The hook itself
diff --git a/src/claude/skill-use.ts b/src/claude/skill-use.ts
new file mode 100644
index 00000000..2cbdaddc
--- /dev/null
+++ b/src/claude/skill-use.ts
@@ -0,0 +1,78 @@
+/**
+ * A coding agent using one of the repo's skills, as a run on the workspace.
+ * Claude Code loads a skill itself (the `Skill` tool, or the person typing
+ * `/name`), so without this the workspace only hears of runs that went
+ * through its own connector, and a skill the team runs every day reads as
+ * "Not used yet". Only the skill's name goes: never the task, the prompt or
+ * the arguments. Only a skill the repo keeps in `.claude/skills/<name>/`
+ * counts (a personal or plugin skill is not the team's), and only once the
+ * workspace has it (flushActivity drops the rest).
+ */
+import { existsSync } from "node:fs";
+import { join } from "node:path";
+import { payloadSessionId } from "./hook-io.js";
+import { readSession, writeSession } from "./state.js";
+import { repoPlace } from "../notes/home.js";
+import { noteAuthor } from "../notes/git-facts.js";
+import { readCloud, type Cloud } from "../cloud/workspace.js";
+import { recordActivity, records } from "../cloud/workspace-sync.js";
+
+/** The same skill again within this long in one session is the same run (the person typed `/name`, then the agent loaded it). */
+export const SAME_RUN_MS = 2 * 60_000;
+
+const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
+
+/** The skill a `Skill` tool call loaded, or "" for any other call. A plugin's (`plugin:name`) is not a repo's. */
+export function skillOfToolUse(input: any): string {
+ if (input?.tool_name !== "Skill") return "";
+ const raw = input?.tool_input?.skill ?? input?.tool_input?.command;
+ const name = typeof raw === "string" ? raw.trim().replace(/^\//, "") : "";
+ return NAME.test(name) ? name : "";
+}
+
+/** The skill a prompt calls by `/name`, or "". */
+export function skillOfPrompt(prompt: unknown): string {
+ const m = typeof prompt === "string" ? /^\s*\/([A-Za-z0-9][A-Za-z0-9._-]{0,63})(?:\s|$)/.exec(prompt) : null;
+ return m ? m[1]! : "";
+}
+
+/**
+ * Queue a run of `name` when it is one of this repo's skills and the machine
+ * records uses for the repo. Never throws.
+ */
+export function recordSkillUse(name: string, input: unknown, dir: string, opts: { cloud?: Cloud | null; now?: number } = {}): boolean {
+ // Most tool calls and prompts aren't a skill: they stop here, before any file is read.
+ if (!name) return false;
+ try {
+ const cloud = opts.cloud === undefined ? readCloud() : opts.cloud;
+ const now = opts.now ?? Date.now();
+ if (!cloud) return false;
+ const place = repoPlace(dir);
+ if (!records(cloud, place.key)) return false;
+ if (!existsSync(join(place.checkout, ".claude", "skills", name, "SKILL.md"))) return false;
+ const session = payloadSessionId(input);
+ const s = readSession(dir, session);
+ const seen = s.skillsUsed ?? {};
+ if (now - (seen[name] ?? 0) < SAME_RUN_MS) return false;
+ writeSession(dir, session, { ...s, skillsUsed: { ...seen, [name]: now } });
+ const me = noteAuthor(place.checkout);
+ recordActivity(
+ {
+ repo: place.key,
+ kind: "skill",
+ skill: name,
+ asker: me,
+ session,
+ file_count: 0,
+ shown_paths: [],
+ shown_authors: [],
+ at: new Date(now).toISOString(),
+ },
+ cloud,
+ );
+ return true;
+ } catch {
+ // A lost run undercounts the skill by one.
+ return false;
+ }
+}
diff --git a/src/claude/state.ts b/src/claude/state.ts
index d1209294..cc822ec5 100644
--- a/src/claude/state.ts
+++ b/src/claude/state.ts
@@ -30,6 +30,8 @@ export interface SessionState {
* nothing the person typed is kept (spec section 6). Optional so files
* written before it still parse. */
promptAsks?: number;
+ /** The repo skills this session used, by name, to when it last went to the workspace as a run (skill-use.ts). */
+ skillsUsed?: Record<string, number>;
graftReads: number; sourceReads: number;
/** Cumulative tokens saved this session via `ask --source` retrieval (est.). */
savedTokens: number;
diff --git a/src/cloud/workspace-sync.ts b/src/cloud/workspace-sync.ts
index d0f9bd1d..c6c8464a 100644
--- a/src/cloud/workspace-sync.ts
+++ b/src/cloud/workspace-sync.ts
@@ -355,8 +355,19 @@ export async function syncRepo(
/* what the workspace has */
/* -------------------------------------------------------------------------- */
-/** Per repo key: the learnings its last upload from this machine carried, by file name, with their authors. */
-type SentLearnings = Record<string, { at: number; learnings: Record<string, string> }>;
+/** Per repo key: the learnings its last upload from this machine carried, by file name, with their authors, and its skills by folder name. */
+type SentLearnings = Record<string, { at: number; learnings: Record<string, string>; skills?: string[] }>;
+
+/** What the workspace got of each repo: learnings by file name to author, and skill folder names. */
+interface Sent {
+ learnings: Map<string, Map<string, string>>;
+ skills: Map<string, Set<string>>;
+}
+
+/** `.claude/skills/<name>/SKILL.md` → `<name>`; "" for any other path. */
+export function repoSkillName(path: string): string {
+ return /^\.claude\/skills\/([^/]+)\/SKILL\.md$/.exec(path)?.[1] ?? "";
+}
function sentPath(env: NodeJS.ProcessEnv = process.env): string {
return join(trailHome(env), "workspace-sent.json");
@@ -370,7 +381,8 @@ function sentPath(env: NodeJS.ProcessEnv = process.env): string {
function rememberSent(key: string, learnings: UploadedLearning[]): void {
try {
const all = readJson<SentLearnings>(sentPath()) ?? {};
- all[key] = { at: Date.now(), learnings: Object.fromEntries(learnings.filter((l) => l.kind !== "skill").map((l) => [learningName(l.path), l.author])) };
+ const skills = learnings.filter((l) => l.kind === "skill").map((l) => repoSkillName(l.path)).filter(Boolean);
+ all[key] = { at: Date.now(), learnings: Object.fromEntries(learnings.filter((l) => l.kind !== "skill").map((l) => [learningName(l.path), l.author])), skills };
ensurePrivateDir(trailHome());
writeJsonAtomic(sentPath(), all, true, PRIVATE_FILE_MODE);
} catch {
@@ -378,15 +390,15 @@ function rememberSent(key: string, learnings: UploadedLearning[]): void {
}
}
-/** File name to author, for every learning the workspace got of each repo. Empty when nothing was sent yet. */
-function readSent(): Map<string, Map<string, string>> {
- const out = new Map<string, Map<string, string>>();
+/** What the workspace got of each repo from this machine. Empty when nothing was sent yet. */
+function readSent(): Sent {
+ const out: Sent = { learnings: new Map(), skills: new Map() };
const all = readJson<SentLearnings>(sentPath());
if (typeof all !== "object" || all === null) return out;
for (const [key, v] of Object.entries(all)) {
const ls = v?.learnings;
- if (typeof ls !== "object" || ls === null) continue;
- out.set(key, new Map(Object.entries(ls).filter((e): e is [string, string] => typeof e[1] === "string")));
+ if (typeof ls === "object" && ls !== null) out.learnings.set(key, new Map(Object.entries(ls).filter((e): e is [string, string] => typeof e[1] === "string")));
+ out.skills.set(key, new Set(asStrings(v?.skills)));
}
return out;
}
@@ -395,10 +407,12 @@ function readSent(): Map<string, Map<string, string>> {
* The use as it may go up: only the learnings the workspace already got of
* its repo, each with the author that upload gave it. A personal learning,
* an uncommitted or untracked one, or one an older trail queued, is dropped
- * from it, name and author both.
+ * from it, name and author both. A skill use goes only for a skill the
+ * workspace got of that repo; any other is dropped whole.
*/
-function onlySent(e: ActivityEvent, sent: Map<string, Map<string, string>>): ActivityEvent {
- const has = sent.get(e.repo);
+function onlySent(e: ActivityEvent, sent: Sent): ActivityEvent | null {
+ if (e.kind === "skill") return e.skill && sent.skills.get(e.repo)?.has(e.skill) ? e : null;
+ const has = sent.learnings.get(e.repo);
const names = [...new Set(e.shown_paths)].filter((n) => has?.has(n));
const authors = names.map((n) => has!.get(n)!);
return { ...e, shown_paths: names, shown_authors: e.kind === "check" ? [...new Set(authors)] : authors };
@@ -437,6 +451,8 @@ export function records(cloud: Cloud | null, repo: string): cloud is Cloud {
return !!cloud && cloud.via !== "connect" && cloud.repos.includes(repo);
}
+/** A skill's folder name, as Claude Code names skills. */
+const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
const asStrings = (x: unknown): string[] => (Array.isArray(x) ? x.filter((s): s is string => typeof s === "string") : []);
const asText = (x: unknown): string => (typeof x === "string" ? x : "");
@@ -449,11 +465,14 @@ const asText = (x: unknown): string => (typeof x === "string" ? x : "");
export function activityEvent(raw: unknown): ActivityEvent | null {
if (typeof raw !== "object" || raw === null) return null;
const r = raw as Record<string, unknown>;
- if (r.kind !== "search" && r.kind !== "check") return null;
+ if (r.kind !== "search" && r.kind !== "check" && r.kind !== "skill") return null;
+ const skill = r.kind === "skill" ? asText(r.skill) : "";
+ if (r.kind === "skill" && !SKILL_NAME.test(skill)) return null;
const count = typeof r.file_count === "number" && Number.isFinite(r.file_count) ? Math.max(0, Math.floor(r.file_count)) : asStrings(r.files).length;
return {
repo: asText(r.repo),
kind: r.kind,
+ ...(skill ? { skill } : {}),
asker: asText(r.asker),
session: asText(r.session),
file_count: count,
@@ -529,7 +548,8 @@ export async function flushActivity(cloud: Cloud, fetchImpl?: typeof fetch): Pro
try {
if (!line.trim()) continue;
const e = activityEvent(JSON.parse(line));
- if (e && sendable(e, cloud)) events.push(onlySent(e, has));
+ const out = e && sendable(e, cloud) ? onlySent(e, has) : null;
+ if (out) events.push(out);
} catch {
/* a torn line */
}
diff --git a/src/cloud/workspace.ts b/src/cloud/workspace.ts
index e7dd31f8..b628a036 100644
--- a/src/cloud/workspace.ts
+++ b/src/cloud/workspace.ts
@@ -355,13 +355,16 @@ export async function uploadLearnings(
}
/**
- * One use of the learnings: a search that showed some, or a check against
- * them. Counts and which learnings, never content: no query (for the prompt
- * hook that is the person's prompt) and no file paths.
+ * One use of the learnings: a search that showed some, a check against them,
+ * or a coding agent using one of the repo's skills. Counts and which
+ * learnings, never content: no query (for the prompt hook that is the
+ * person's prompt), no file paths and no task.
*/
export interface ActivityEvent {
repo: string;
- kind: "search" | "check";
+ kind: "search" | "check" | "skill";
+ /** For a skill use: the skill's folder name under `.claude/skills/`. */
+ skill?: string;
asker: string;
session: string;
/** How many files the answer pointed into, or the check covered. */
diff --git a/test/claude-settings-merge.test.ts b/test/claude-settings-merge.test.ts
index 1e5ebf77..df24a823 100644
--- a/test/claude-settings-merge.test.ts
+++ b/test/claude-settings-merge.test.ts
@@ -17,7 +17,7 @@ test('empty settings gets the full Graft blocks', () => {
// accumulator over the retrieval tools (Bash `graft …`, the graft_* MCP tools)
// and the source-read tools (Read/Grep/Glob) it scores against.
const savings = merged.hooks.PostToolUse[1];
- assert.equal(savings.matcher, 'Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob');
+ assert.equal(savings.matcher, 'Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob|Skill');
assert.ok(savings.hooks[0].command.includes('tool-savings'), 'savings hook wired');
assert.ok(merged.footerLinksRegexes.includes('graft/[\\w./-]+\\.md'));
assert.deepEqual(warnings, []);
diff --git a/test/trail-init-upgrade.test.ts b/test/trail-init-upgrade.test.ts
index 3583894f..c09f2e03 100644
--- a/test/trail-init-upgrade.test.ts
+++ b/test/trail-init-upgrade.test.ts
@@ -64,7 +64,7 @@ function assertWired(repo: string, home: string): void {
assert.deepEqual(shared.SessionStart.at(-1).hooks[0], { type: "command", command: 'node "${CLAUDE_PROJECT_DIR:-.}/.trail/hook.cjs" session-start || exit 0', timeout: 10 });
const user = read(join(home, ".claude", "settings.json")).hooks;
assert.deepEqual(ours(user), {
- PostToolUse: ["Write|Edit|MultiEdit:post-edit", "Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob:tool-savings"],
+ PostToolUse: ["Write|Edit|MultiEdit:post-edit", "Bash|mcp__graft__|mcp__trail__|Read|Grep|Glob|Skill:tool-savings"],
UserPromptSubmit: [":prompt"],
PreToolUse: ["Bash:pre-bash"],
PostToolUseFailure: ["Bash:post-bash-fail"],
diff --git a/test/trail-skill-use.test.ts b/test/trail-skill-use.test.ts
new file mode 100644
index 00000000..c87f80bd
--- /dev/null
+++ b/test/trail-skill-use.test.ts
@@ -0,0 +1,133 @@
+/**
+ * A coding agent using one of the repo's skills goes to the workspace as a
+ * run of it: the skill's name only, never the task or the prompt, and only
+ * for a skill the repo keeps and the workspace already has.
+ */
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { BRAND_ENV } from "../src/brand.js";
+import { recordSkillUse, SAME_RUN_MS, skillOfPrompt, skillOfToolUse } from "../src/claude/skill-use.js";
+import { flushActivity, syncRepo } from "../src/cloud/workspace-sync.js";
+import { isError, type Cloud } from "../src/cloud/workspace.js";
+import { tmpRepo } from "./helpers.js";
+
+process.env.DO_NOT_TRACK = "1";
+process.env[BRAND_ENV] = "trail";
+process.env.TRAIL_NO_FETCH = "1";
+process.env.TRAIL_HOME = mkdtempSync(join(tmpdir(), "skill-use-home-"));
+
+const KEY = "github.com/acme/billing";
+const SKILL = "---\nname: cut-a-release\ndescription: Tag, build and publish a release.\n---\n1. Run the tests.\n2. Tag it.\n";
+
+function git(cwd: string, ...args: string[]): void {
+ const r = spawnSync("git", ["-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf8" });
+ if (r.status !== 0) throw new Error(`git ${args.join(" ")}: ${r.stderr}`);
+}
+
+function repo(tag: string): string {
+ const d = tmpRepo(`skill-use-${tag}`);
+ for (const [p, text] of Object.entries({ "README.md": "billing\n", ".claude/skills/cut-a-release/SKILL.md": SKILL })) {
+ mkdirSync(dirname(join(d, p)), { recursive: true });
+ writeFileSync(join(d, p), text);
+ }
+ git(d, "init", "-q", "-b", "main");
+ git(d, "config", "user.name", "Priya Raman");
+ git(d, "config", "user.email", "[email protected]");
+ git(d, "add", "-A");
+ git(d, "commit", "-qm", "init");
+ git(d, "remote", "add", "origin", `https://${KEY}.git`);
+ return d;
+}
+
+function trail(repos: string[]) {
+ const sent: any[] = [];
+ const fetchImpl = (async (url: string, init: RequestInit) => {
+ const path = new URL(url).pathname;
+ const body = init.body ? JSON.parse(String(init.body)) : undefined;
+ sent.push({ path, body });
+ const json = (b: unknown) => new Response(JSON.stringify(b), { status: 200 });
+ if (path === "/api/cli/learnings") return json({ repo: body.repo.key, learnings: body.learnings.length, added: 0 });
+ if (path === "/api/cli/activity") return json({ stored: body.events.length });
+ return new Response("{}", { status: 404 });
+ }) as typeof fetch;
+ const cloud: Cloud = {
+ url: "http://trail.test",
+ token: "trl_x",
+ user: { name: "Priya", email: "[email protected]" },
+ workspace: { id: "w", name: "Acme", slug: "acme", url: "http://trail.test/w/acme", invite_url: "http://trail.test/join/x" },
+ repos,
+ linkedAt: Date.now() - 60_000,
+ };
+ return { cloud, sent, fetchImpl };
+}
+
+const outbox = () => {
+ const p = join(process.env.TRAIL_HOME!, "outbox.jsonl");
+ return existsSync(p) ? readFileSync(p, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l)) : [];
+};
+const clearOutbox = () => rmSync(join(process.env.TRAIL_HOME!, "outbox.jsonl"), { force: true });
+const use = (skill: string, session = "s1") => ({ session_id: session, tool_name: "Skill", tool_input: { skill, args: "ship 2.4 to customers at acme" } });
+
+test("the skill a Skill call or a /name prompt uses, and nothing else", () => {
+ assert.equal(skillOfToolUse(use("cut-a-release")), "cut-a-release");
+ assert.equal(skillOfToolUse({ tool_name: "Skill", tool_input: { command: "/cut-a-release" } }), "cut-a-release");
+ assert.equal(skillOfToolUse(use("superpowers:brainstorming")), "", "a plugin's skill is not the repo's");
+ assert.equal(skillOfToolUse({ tool_name: "Read", tool_input: { skill: "cut-a-release" } }), "");
+ assert.equal(skillOfPrompt("/cut-a-release 2.4"), "cut-a-release");
+ assert.equal(skillOfPrompt(" /cut-a-release"), "cut-a-release");
+ assert.equal(skillOfPrompt("please /cut-a-release"), "");
+ assert.equal(skillOfPrompt("/../etc"), "");
+});
+
+test("a repo skill's use is queued by name only, once per run", () => {
+ clearOutbox();
+ const d = repo("queue");
+ const { cloud } = trail([KEY]);
+ const now = Date.now();
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud, now }), true);
+ // The person typed /cut-a-release, then the agent loaded it: one run.
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud, now: now + 5_000 }), false);
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud, now: now + SAME_RUN_MS + 1 }), true, "a later run counts");
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release", "s2"), d, { cloud, now: now + 6_000 }), true, "another session counts");
+
+ const queued = outbox();
+ assert.equal(queued.length, 3);
+ assert.deepEqual(Object.keys(queued[0]).sort(), ["asker", "at", "file_count", "kind", "repo", "session", "shown_authors", "shown_paths", "skill"]);
+ assert.equal(queued[0].kind, "skill");
+ assert.equal(queued[0].skill, "cut-a-release");
+ assert.equal(queued[0].repo, KEY);
+ assert.doesNotMatch(JSON.stringify(queued), /acme ship|customers/, "never the task");
+});
+
+test("only the repo's own skills, only for a workspace repo", () => {
+ clearOutbox();
+ const d = repo("only");
+ assert.equal(recordSkillUse("deck", use("deck"), d, { cloud: trail([KEY]).cloud }), false, "not a skill the repo keeps");
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud: trail(["github.com/acme/web"]).cloud }), false, "repo not in the workspace");
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud: null }), false, "not connected");
+ assert.equal(recordSkillUse("", use(""), d, { cloud: trail([KEY]).cloud }), false);
+ assert.equal(outbox().length, 0);
+});
+
+test("a run goes up only once the workspace has the skill", async () => {
+ clearOutbox();
+ const d = repo("flush");
+ const t = trail([KEY]);
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release"), d, { cloud: t.cloud }), true);
+ // Nothing synced from this machine yet: the run names a skill the workspace may not have.
+ assert.equal(await flushActivity(t.cloud, t.fetchImpl), 0);
+ assert.equal(t.sent.filter((s) => s.path === "/api/cli/activity").length, 0);
+
+ const res = await syncRepo(d, t.cloud, { fetch: false, fetchImpl: t.fetchImpl });
+ assert.ok(!isError(res), JSON.stringify(res));
+ assert.equal(recordSkillUse("cut-a-release", use("cut-a-release", "s3"), d, { cloud: t.cloud }), true);
+ assert.equal(await flushActivity(t.cloud, t.fetchImpl), 1);
+ const events = t.sent.find((s) => s.path === "/api/cli/activity").body.events;
+ assert.equal(events.length, 1);
+ assert.equal(events[0].kind, "skill");
+ assert.equal(events[0].skill, "cut-a-release");
+});