ListArtifacts() / createArtifact() in .md file to compare - side-by-side diff against artifacts
artifacts
description: "Triggers on prompt mention of 'artifacts'."
What it does for you
Keeps your saved charts, tables, and briefs handy so you can reopen them anytime.
What it produces
A recent result, so you can see the kind of work it returns.
loading…
How to get it
These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.
For developers how this skill is built, graded, and how it runs
at a glance- the short version
what's inside - the parts that make up a skill 3/4 present
A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.
state/skills/artifacts/SKILL.md
present
state/lib/artifacts.ts
present
state/bin/artifacts/
not present
state/skills/artifacts/AGENTS.md
present
how it's graded - what counts as a good run 4 criteria · 4 deterministic
Each row is one thing a good run has to get right. deterministic means a quick check decides, pass or fail. judge means the AI reads the result and rates it. Grading each piece on its own (instead of one overall score) shows exactly where a run fell short, so the fix is obvious.
how it runs - the shared frame every skill uses 5/5 present
Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.
State/lint/library-shape.ts (the lib must export the two state/log/evals.ndjson - Atomic write or it never happened. createArtifact must temp+rename.
- state/log/ is gitignored. Artifacts are LOCAL cache. Do not assume
- list returns desc by created_at. Don't change the sort without
- Pure read for listArtifacts. Never write inside it. Even if a
- Refresh / delete are NOT in this version. When they land, separate
- name is required. createArtifact throws on empty name. Cockpit
what it has learned - fixes written back in over time sample
When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.
- Loading feedback rows…
how the work flows- who makes it, who checks it
import { listArtifacts, createArtifact } from "./state/lib/artifacts.ts"
SKILL.md- the skill, written out in plain English
artifacts
The cockpit-is-renderer principle says every cockpit affordance must map to a snappy-os skill. The Live artifacts sidebar destination (cd-22 / cd-23 in dogfood-loop/refs/) is no exception - this skill is the producer.
An artifact is a named, refreshable piece of structured output a user has opted to keep around: a daily revenue chart, a top-pipeline-deals table, a weekly catchup brief. Each is one JSON file in state/log/artifacts/, keyed by uuid. The cockpit lists them via GET /artifacts and creates new ones via POST /artifacts.
The lib at state/lib/artifacts.ts is the action scope. Refresh + delete are deliberately deferred until the cockpit's interaction surface lands - list + create is the minimum viable producer that lets the empty-state vignette ("Create your first artifact") become non-empty.
Pure read for listArtifacts. createArtifact writes one new file atomically (temp + rename) so partial writes are never visible to the listing.
Steps
listArtifacts(): Promise<Artifact[]>- read every*.jsonunder
state/log/artifacts/, parse, validate shape, drop bad rows, return sorted by created_at desc. Creates the directory if missing so the first call on a fresh checkout returns [] cleanly.
createArtifact({ name, description?, pinned_chat_id?, source_connectors? })
- mint a randomUUID(), build the Artifact row, write state/log/artifacts/<id>.json atomically (temp + rename), return the materialized object. name is required; everything else is optional.
- The HTTP endpoints are wired in
state/bin/head-screen/server.ts:
GET /artifacts→ returns the array directly.POST /artifacts(body{ name, description? }) → returns the new
artifact. Both endpoints emit CORS * so the WKWebView (file:// origin) can hit them.
Library API
state/lib/artifacts.ts exports two functions and the Artifact type. Importable from any TS agent code; also runnable as a CLI smoke.
export type ArtifactStatus = "fresh" | "stale" | "error";
export interface Artifact {
id: string;
name: string;
description?: string;
created_at: string;
last_refreshed_at?: string;
status: ArtifactStatus;
pinned_chat_id?: string;
source_connectors?: string[];
last_output_preview?: string;
}
export async function listArtifacts(): Promise<Artifact[]>;
export async function createArtifact(opts: {
name: string;
description?: string;
pinned_chat_id?: string;
source_connectors?: string[];
}): Promise<Artifact>;
CLI:
npx tsx state/lib/artifacts.ts # list (JSON to stdout)
npx tsx state/lib/artifacts.ts create "Revenue brief" "Daily auto-refresh"
Storage shape
state/log/artifacts/
<uuid>.json # one per artifact
state/log/ is gitignored (per-machine ephemeral) - artifacts are local state, not synced across machines. If a future axis needs cross-machine artifacts, add a sync hook here, don't move the storage.
Per-row JSON schema example:
{
"id": "8e1c4a08-…",
"name": "Daily revenue brief",
"description": "Pulled from FreshBooks each morning",
"created_at": "2026-04-29T05:30:00.000Z",
"status": "fresh",
"source_connectors": ["freshbooks"]
}
Eval
Actor: listArtifacts() / createArtifact() in state/lib/artifacts.ts. Auditor: state/lint/library-shape.ts (the lib must export the two functions with the documented signatures) plus the cockpit dogfood loop that proves the sidebar list renders (not error fallback).
Eval kind: shape. Mechanical: import the lib, assert listArtifacts and createArtifact exist as functions, type-check passes, atomic write contract holds (no .tmp files visible to a concurrent list during create).
| Outcome | Score |
|---|---|
| Lib exports correct, atomic write holds, HTTP endpoints respond | 1.0 |
| Lib exports correct but endpoint returns malformed shape | 0.5 |
| Lib import fails or list crashes on a corrupt row | 0.0 |
Pitfalls
state/log/is gitignored. Don't expect artifacts to follow the
agent across machines - they're local cache. If Robert needs portable artifacts, that's a separate axis (sync hook, not storage move).
- Atomic write is non-negotiable. A partial JSON file in the directory
means listArtifacts parse-fails the row and silently drops it - the cockpit will never see it. Always temp+rename.
nameis required, everything else is optional. The cockpit's
"New artifact" sheet should enforce this client-side; the lib also throws if name is empty.
- Refresh / delete are NOT in this version. When they land, they're
separate endpoints (POST /artifacts/<id>/refresh, DELETE /artifacts/<id>) and separate skills. Don't bolt them on here.
Files
state/lib/artifacts.ts- the API (importable + CLI).state/bin/head-screen/server.ts- ownsGET /artifactsand
POST /artifacts.
state/log/artifacts/- per-row JSON storage (gitignored).
Rubric
criteria:
- name: lib_exports_shape
kind: deterministic
check: "state/lib/artifacts.ts exports listArtifacts and createArtifact as async functions with the documented Artifact return shape (id, name, created_at, status all required)."
- name: atomic_write_holds
kind: deterministic
check: "createArtifact writes via temp+rename — no `.tmp` file ever appears in state/log/artifacts/ visible to a concurrent listArtifacts call."
- name: http_endpoints_wired
kind: deterministic
check: "GET /artifacts returns a JSON array; POST /artifacts with {name} returns the new artifact and persists it. CORS `*` set so the WKWebView (file://) can hit them."
- name: corrupt_row_does_not_crash
kind: deterministic
check: "A bad JSON file in state/log/artifacts/ is silently skipped by listArtifacts — the listing returns the valid rows, never throws."AGENTS.md- what the AI loads when this skill comes up
artifacts - loader
Per-turn rules for the artifacts skill. Full reference: state/skills/artifacts/SKILL.md. Storage: state/log/artifacts/<uuid>.json (gitignored, per-machine).
Critical Rules
- Atomic write or it never happened.
createArtifactmust temp+rename.
A partial JSON file in state/log/artifacts/ makes listArtifacts silently drop the row and the cockpit never sees it. Always atomic.
state/log/is gitignored. Artifacts are LOCAL cache. Do not assume
they sync across machines. If Robert needs portable artifacts, that's a separate axis.
- list returns desc by
created_at. Don't change the sort without
updating the cockpit's expectations.
- Pure read for
listArtifacts. Never write inside it. Even if a
corrupt row is found, skip silently - don't try to repair on read.
- Refresh / delete are NOT in this version. When they land, separate
endpoints + separate skills. Don't bolt them on here.
nameis required.createArtifactthrows on empty name. Cockpit
should enforce client-side too.
Commands
| ui dashboard | state/skills/artifacts/resources/ui.openui | |invoke: import { listArtifacts, createArtifact } from "./state/lib/artifacts.ts" |cli list: npx tsx state/lib/artifacts.ts |cli create: npx tsx state/lib/artifacts.ts create "<name>" "<optional desc>" |http list: curl -s http://127.0.0.1:3147/artifacts |http create: curl -s -XPOST http://127.0.0.1:3147/artifacts -H 'content-type: application/json' -d '{"name":"Daily brief"}' |storage: state/log/artifacts/<uuid>.json |eval log: state/log/evals.ndjson (skill: "artifacts")
Endpoints (head-screen owns these)
GET /artifacts- returnsArtifact[], sorted desc bycreated_at.
CORS *.
POST /artifacts- body{ name, description? }→ returns the new
Artifact. CORS *. 400 on missing/empty name.
Working primitives
listArtifacts()- read every*.jsonunderstate/log/artifacts/,
parse, validate, drop bad rows, sort desc by created_at. Creates the directory if missing so the first call on a fresh checkout returns [].
createArtifact({ name, description?, pinned_chat_id?, source_connectors? })
- mint uuid, atomic write, return the materialized row.
Self-Test
An agent reading this should correctly:
- [ ] Use atomic write (temp + rename) in any new write path
- [ ] Treat
state/log/as per-machine ephemeral storage - [ ] Reject empty
nameat the lib level (don't push validation to
the HTTP layer)
- [ ] Skip corrupt rows silently in
listArtifacts- never throw
Self-report
If this loader fell short, append a line:
echo "[$(date -u +%FT%TZ)] artifacts: <what was missing>" >> state/log/loader-feedback.log
<!-- kernel-ok: historical attribution for the PID-loader pattern. -->
Self-correcting loader (PID feedback)
This is the rule that makes loaders learn. Ported from snappy-kernel, where it demonstrably worked: the snappy-dom-cartographer skill mapped Skool admin UI once, every later ship-agent inherited the full map for free.
Before you finish, do two things:
1. Fix gaps (P - proportional). MANDATORY. If this loader didn't cover your case - if you had to read another file, run an undocumented command, work around a wrong selector, or discover a quirk - you MUST attempt an Edit to this AGENTS.md before you log.
- Default action: edit this file. Surgical. Add the missing line, table
row, or code example where it belongs. No restructuring.
- Only
LOGGEDis allowed when: the fix needs >10 lines, spans multiple
files, or requires a structural rewrite. In that case the state/regen/drain.sh queue picks it up asynchronously.
- "I didn't have time" / "it's minor" / "the next agent will figure it out"
are NOT valid reasons. Minor gaps compound - that's the whole point of this loop.
- Concrete example of a valid P-fix: discover
agent-browser screenshot
takes path positionally not as --output <path>. One line in a table. Edit it in. Do not just log it.
- The goal: the next agent never has to leave the loader.
2. Log the result.
echo "[$(date -u +%FT%TZ)] artifacts: <what was missing or fixed> [FIXED|LOGGED] action_kind=<kind>" >> state/log/loader-feedback.log
<slug>MUST be the literal folder name of this loader
(state/skills/<slug>/AGENTS.md). The class token between [ts] and : is the producer slug, the writeback class, AND the grade class - they must be equal so state/lib/controller-tune.ts can pair the brief.
FIXED= you patched this loader inline (P-fix).LOGGED= too large for inline; the PostToolUse enqueue + Stop-hook drain
will rewrite the loader from scratch on next session-end.
action_kindis the SECOND pairing predicate (added 2026-04-27, task #327).
Pick the value that describes what you actually did - same slug, different action_kind means the writeback satisfies a different brief layer:
shape-ok- only frontmatter-shape verification passed (rare from
a human; usually emitted by the lint, not a loader echo)
skill-ran- the skill ran end-to-end and an eval row landed
in state/log/evals.ndjson
loader-rewritten- you EDITED this AGENTS.md inline (the FIXED case),
OR the regen drain rewrote it
pattern-elevated- you promoted a recurring failure to a Critical Rule
(rule fix or new-skill scaffold) If you LOGGED (couldn't fix inline), omit action_kind - the inferrer will pick it up from your body keywords.
Do not skip this. Every agent run must leave the system better than it found it. The loader is the setpoint; you are the sensor; the gap is the error signal; closing the gap is the correction.
OpenUI Resource
- Skill-owned OpenUI Lang resource:
state/skills/artifacts/resources/ui.openui. Read it before rendering or editing this skill's generated component surface. - Treat this resource as a first-class artifact of the skill, not a generic chat response. Improve it when the skill's user-facing output needs to become richer.
- System resources compose OpenUI primitives and inherit SnappyChat tokens. Use
ui_contract: brandedin SKILL.md only for deliberate platform or client visuals.
api.ts- the code it can call
#!/usr/bin/env npx tsx
/**
* state/lib/artifacts.ts -- Live artifacts producer for the snappy-chat
* cockpit's artifacts sidebar destination (cd-22 / cd-23 reference shots).
*
* An artifact is a named, refreshable piece of structured output a user
* has opted to keep around (a chart, a table, a brief). Each lives as one
* JSON file in state/log/artifacts/ keyed by uuid. This module provides
* read + create primitives; refresh / delete are deliberately deferred
* until the cockpit's interaction surface lands.
*
* import { listArtifacts, createArtifact } from "../lib/artifacts.ts";
* const artifacts = await listArtifacts();
* const fresh = await createArtifact({ name: "Daily revenue brief" });
*
* Pure read for listArtifacts. createArtifact writes one new file and
* returns the materialized artifact — atomic via temp+rename so a partial
* write can never be observed by listArtifacts.
*/
import {
existsSync,
mkdirSync,
readFileSync,
readdirSync,
renameSync,
writeFileSync,
} from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { randomUUID } from "crypto";
const HERE = dirname(fileURLToPath(import.meta.url));
const ROOT = join(HERE, "..", "..");
const ARTIFACTS_DIR = join(ROOT, "state", "log", "artifacts");
export type ArtifactStatus = "fresh" | "stale" | "error";
export interface Artifact {
id: string;
name: string;
description?: string;
created_at: string;
last_refreshed_at?: string;
status: ArtifactStatus;
/** Optional pinned chat thread id this artifact draws from. */
pinned_chat_id?: string;
/** Optional source connectors (e.g. ["xano", "gmail"]). */
source_connectors?: string[];
/** Optional preview of the most recent output (truncated). */
last_output_preview?: string;
/** Optional producer slug — which skill produced this artifact (e.g. "artifacts:brain-digest"). */
producer_slug?: string;
/** Optional generative-UI shape name this artifact captured (e.g. "LinkedinPostPreview", "KPIBlock"). */
shape_name?: string;
/** Optional shape args — the JSON the shape was rendered with. Re-used to re-render in the artifacts view. */
shape_args?: unknown;
/** Optional originating user intent string that produced the shape. */
intent?: string;
/** Optional path to fetch fresh data, e.g. "/full-state". Client polls this URL to refresh the artifact. */
refresh_url?: string;
/** Optional seconds between auto-polls; client-side only. */
refresh_interval?: number;
}
export interface CreateArtifactOpts {
name: string;
description?: string;
pinned_chat_id?: string;
source_connectors?: string[];
producer_slug?: string;
shape_name?: string;
shape_args?: unknown;
intent?: string;
/** Optional path to fetch fresh data, e.g. "/full-state". */
refresh_url?: string;
/** Optional seconds between auto-polls; client-side only. */
refresh_interval?: number;
}
function ensureDir(): void {
if (!existsSync(ARTIFACTS_DIR)) {
mkdirSync(ARTIFACTS_DIR, { recursive: true });
}
}
function isArtifact(o: unknown): o is Artifact {
if (!o || typeof o !== "object") return false;
const a = o as Partial<Artifact>;
return typeof a.id === "string"
&& typeof a.name === "string"
&& typeof a.created_at === "string"
&& (a.status === "fresh" || a.status === "stale" || a.status === "error");
}
/**
* List every artifact in state/log/artifacts/, sorted by created_at desc.
* Files that fail to parse or fail the shape check are skipped silently —
* the cockpit should never see a partial row.
*/
export async function listArtifacts(): Promise<Artifact[]> {
ensureDir();
const entries = readdirSync(ARTIFACTS_DIR);
const out: Artifact[] = [];
for (const f of entries) {
if (!f.endsWith(".json")) continue;
const fp = join(ARTIFACTS_DIR, f);
try {
const raw = readFileSync(fp, "utf-8");
const parsed = JSON.parse(raw);
if (isArtifact(parsed)) out.push(parsed);
} catch {
// skip — corrupt rows must not crash the listing
}
}
out.sort((a, b) => (a.created_at < b.created_at ? 1 : a.created_at > b.created_at ? -1 : 0));
return out;
}
/**
* Create a new artifact. Atomic write (temp + rename) so partial files
* are never visible to listArtifacts.
*/
export async function createArtifact(opts: CreateArtifactOpts): Promise<Artifact> {
const name = (opts.name ?? "").trim();
if (!name) {
throw new Error("createArtifact: name is required");
}
ensureDir();
const id = randomUUID();
const artifact: Artifact = {
id,
name,
description: opts.description?.trim() || undefined,
created_at: new Date().toISOString(),
status: "fresh",
pinned_chat_id: opts.pinned_chat_id,
source_connectors: opts.source_connectors,
producer_slug: opts.producer_slug,
shape_name: opts.shape_name,
shape_args: opts.shape_args,
intent: opts.intent,
refresh_url: opts.refresh_url,
refresh_interval: opts.refresh_interval,
};
const finalPath = join(ARTIFACTS_DIR, `${id}.json`);
const tmpPath = join(ARTIFACTS_DIR, `.${id}.tmp`);
writeFileSync(tmpPath, JSON.stringify(artifact, null, 2) + "\n", "utf-8");
renameSync(tmpPath, finalPath);
return artifact;
}
/**
* Get a single artifact by id. Returns null when not found.
*/
export async function getArtifact(id: string): Promise<Artifact | null> {
ensureDir();
const fp = join(ARTIFACTS_DIR, `${id}.json`);
try {
const raw = readFileSync(fp, "utf-8");
const parsed = JSON.parse(raw);
if (isArtifact(parsed)) return parsed;
return null;
} catch {
return null;
}
}
export interface UpdateArtifactOpts {
name?: string;
description?: string;
shape_args?: unknown;
last_output_preview?: string;
status?: ArtifactStatus;
}
/**
* Update a subset of artifact fields. Bumps updatedAt. Atomic write.
* Returns the updated artifact, or null when not found.
*/
export async function updateArtifact(id: string, opts: UpdateArtifactOpts): Promise<Artifact | null> {
ensureDir();
const fp = join(ARTIFACTS_DIR, `${id}.json`);
try {
const raw = readFileSync(fp, "utf-8");
const parsed = JSON.parse(raw);
if (!isArtifact(parsed)) return null;
const updated: Artifact = {
...parsed,
...(typeof opts.name === "string" && opts.name.trim() ? { name: opts.name.trim() } : {}),
...(typeof opts.description === "string" ? { description: opts.description.trim() || undefined } : {}),
...(opts.shape_args !== undefined ? { shape_args: opts.shape_args } : {}),
...(typeof opts.last_output_preview === "string" ? { last_output_preview: opts.last_output_preview } : {}),
...(opts.status !== undefined ? { status: opts.status } : {}),
last_refreshed_at: new Date().toISOString(),
};
const tmpPath = join(ARTIFACTS_DIR, `.${id}.tmp`);
writeFileSync(tmpPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
renameSync(tmpPath, fp);
return updated;
} catch {
return null;
}
}
/**
* Delete an artifact by id. No-op when not found. Returns true when
* a file was actually removed.
*/
export async function deleteArtifact(id: string): Promise<boolean> {
ensureDir();
const fp = join(ARTIFACTS_DIR, `${id}.json`);
try {
const { unlinkSync } = await import("fs");
if (!existsSync(fp)) return false;
unlinkSync(fp);
return true;
} catch {
return false;
}
}
// CLI smoke: `npx tsx state/lib/artifacts.ts` lists; `... create "<name>"` creates.
if (import.meta.url === `file://${process.argv[1]}`) {
(async () => {
const cmd = process.argv[2] ?? "list";
if (cmd === "list") {
const items = await listArtifacts();
console.log(JSON.stringify(items, null, 2));
return;
}
if (cmd === "create") {
const name = process.argv[3];
if (!name) {
console.error("usage: artifacts.ts create <name> [description]");
process.exit(2);
}
const description = process.argv[4];
const a = await createArtifact({ name, description });
console.log(JSON.stringify(a, null, 2));
return;
}
console.error("usage: artifacts.ts [list|create <name> [desc]]");
process.exit(2);
})();
}
scripts- helper scripts it can run
prose-only skill - 5 inline code blocks live in SKILL.md above (no state/bin/ sidecar yet).
how we check it- the checks, plus the last 5 runs
| timestamp | verb | score | primary_issue | artifact |
|---|---|---|---|---|
| 2026-05-02 18:38Z | - | 1.00 | - | - |
| 2026-05-02 15:58Z | - | 1.00 | - | - |
| 2026-04-29 05:08Z | - | 1.00 | - | - |
| 2026-04-29 05:08Z | - | 1.00 | - | - |
| 2026-04-29 05:08Z | - | 1.00 | - | - |