Snapshot() in state/lib/bundle-snapshot.ts. .md file to compare - side-by-side diff against bundle-snapshot
bundle-snapshot
description: "Triggers on prompt mention of 'bundle-snapshot', 'what is the bundle context', 'what's mounted', 'show me connectors', 'bundle status'."
What it does for you
Shows what's connected and switched on in your setup at a glance.
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/bundle-snapshot/SKILL.md
present
state/lib/bundle-snapshot.ts
present
state/bin/bundle-snapshot/
not present
state/skills/bundle-snapshot/AGENTS.md
present
how it's graded - what counts as a good run 3 criteria · 2 deterministic · 1 judge
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 state/log/evals.ndjson 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 { snapshot } from "../lib/bundle-snapshot.ts"
SKILL.md- the skill, written out in plain English
bundle-snapshot
Producer skill that closes the catalog-to-cockpit drift gap: when the cockpit asks "what is the snappy-os bundle context", the dispatcher used to fall back to plain text because no skill emitted the right TOOL_CALL_ARGS shape. bundle-snapshot reads the head-screen /bundle/status endpoint plus a couple of on-disk signals and shapes them into the ContextPanel contract that snappy-chat/web/src/tool-args.ts:parseContextPanelArgs accepts.
The lib at state/lib/bundle-snapshot.ts is the action scope. The dispatcher at state/bin/head-screen/server.ts wires the intent matcher and emits the TOOL_CALL_START / TOOL_CALL_ARGS / TOOL_CALL_END triple after the assistant text streams.
Pure read. Never writes. Scope-only by snappy-os convention.
Steps
snapshot({ headScreenUrl?, offline? }):
- Probe
${HEAD_SCREEN_BASE}/bundle/status(2s timeout). On any failure
return null and downgrade the head-screen connector to off.
- Read
state/config/dispatch.jsonforchat.backend/chat.model. - Check
.env.cachepresence at the repo root. - Build six connector chips: bundle, head-screen, dispatch, credentials,
web, browser. Each chip carries {id, label, status, icon} per the parseContextPanelArgs shape.
Dispatcher wiring
state/bin/head-screen/server.ts adds a regex matcher to the chat dispatch intent loop. Trigger phrases: "what is the bundle context", "what's mounted", "show me connectors", "bundle status". When matched and llmEmittedNames does not already contain ContextPanel, the dispatcher imports snapshot() from this lib and calls emitTriple("ContextPanel", payload.contextPanel).
Eval
Actor: snapshot() in state/lib/bundle-snapshot.ts. Auditor: state/lint/library-shape.ts (the lib must export snapshot) plus the dogfood loop screenshot that proves the card rendered (not text fallback).
| Outcome | Score |
|---|---|
| Card renders in chat with bundle path + connector states | 1.0 |
| Card renders but a connector status is wrong | 0.5 |
| Plain text fallback (intent didn't match) | 0.0 |
Rubric
criteria:
- name: shape_matches_parser
kind: deterministic
check: "snapshot() returns { contextPanel: { connectors: [...] } } where each connector has id, label, status in {on|off|loading}, optional icon — exactly the shape parseContextPanelArgs in web/src/tool-args.ts accepts."
- name: dispatcher_intent_match
kind: deterministic
check: "Trigger phrases route to a ContextPanel TOOL_CALL emission, not text fallback."
- name: bundle_signal_truth
kind: judge
check: "Bundle connector status reflects the real /bundle/status response: 'on' when mounted and not ejected, 'off' otherwise."AGENTS.md- what the AI loads when this skill comes up
bundle-snapshot - loader
Per-turn rules for the bundle-snapshot skill. Closes the catalog-to-cockpit drift gap: when the cockpit asks "what's mounted?", this producer emits a ContextPanel payload that snappy-chat's generative UI renders inline.
Lib: state/lib/bundle-snapshot.ts. Dispatcher: state/bin/head-screen/server.ts (regex matcher → emitTriple("ContextPanel", payload.contextPanel)).
Critical Rules
- Pure read. NEVER writes. Scope-only by snappy-os convention; no probe is allowed to mutate state.
- Status enum is
on|off|loading- exactly.parseContextPanelArgsvalidates this; any off-enum value kills the card silently. - Single emit per turn. The dispatcher MUST NOT re-emit ContextPanel if
llmEmittedNamesalready contains it. - 2s probe timeout. Slow networks must NOT block the card render. On timeout, downgrade head-screen connector to
offand continue rendering the other five. - Bundle chip reflects real
/bundle/status.ononly when mounted and not ejected;offotherwise. Never fake-green.
Commands
| ui dashboard | state/skills/bundle-snapshot/resources/ui.openui | |invoke: import { snapshot } from "../lib/bundle-snapshot.ts" |cli: npx tsx state/lib/bundle-snapshot.ts (returns JSON to stdout) |dispatcher: state/bin/head-screen/server.ts (regex matcher + emitTriple("ContextPanel", payload.contextPanel)) |trigger phrases: "what is the bundle context" / "what's mounted" / "show me connectors" / "bundle status" |reads: GET ${HEAD_SCREEN_BASE}/bundle/status (2s timeout); state/config/dispatch.json; .env.cache |eval log: state/log/evals.ndjson (skill: "bundle-snapshot", eval_mode: shape)
Six connectors
Hard-coded chip set returned as {id, label, status, icon} per parseContextPanelArgs:
bundle- mount state from/bundle/statushead-screen- cockpit reachability on127.0.0.1:3147(orHEAD_SCREEN_URL)dispatch- chat backend/model fromstate/config/dispatch.jsoncredentials-.env.cachepresence at repo rootweb- outbound web reachability flagbrowser- agent-browser availability
Trigger phrases
- "what is the bundle context"
- "what's mounted"
- "show me connectors"
- "bundle status"
OpenUI Resource
- Skill-owned OpenUI Lang resource:
state/skills/bundle-snapshot/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.
Known Pitfalls
/bundle/statushits127.0.0.1:3147by default. If the head-screen server is dead, that single chip flips tooff- the rest still render. Restart withbash state/bin/head-screen/launch.sh.HEAD_SCREEN_URLenv override is required for non-default cockpit instances. Pass viasnapshot({ headScreenUrl })or env.- Six connectors are hard-coded. Adding a seventh requires changes in BOTH
state/lib/bundle-snapshot.tsAND the snappy-chat ContextPanel renderer - keep them in lockstep.
Self-Test
An agent reading this should correctly:
- [ ] Confirm no chip status returned by
snapshot()falls outsideon|off|loading - [ ] Confirm the dispatcher's regex matcher recognizes all four trigger phrases
- [ ] Confirm the
/bundle/statusprobe is bounded by a 2s timeout (non-blocking on failure) - [ ] Confirm the snapshot path is pure-read - no writes anywhere in the call graph
- [ ] Confirm only one ContextPanel emit per turn (
llmEmittedNamesguard honored)
Self-report
If this loader fell short, append a line:
echo "[$(date -u +%FT%TZ)] bundle-snapshot: <what was missing or fixed> [FIXED|LOGGED] action_kind=<kind>" >> 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)] bundle-snapshot: <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.
api.ts- the code it can call
#!/usr/bin/env npx tsx
/**
* state/lib/bundle-snapshot.ts -- read snappy-os bundle + connector state
* and produce a ContextPanel payload for the snappy-chat generative UI.
*
* Closes the catalog→cockpit drift gap surfaced by the dogfood loop: the
* intent "what is the snappy-os bundle context" used to fall back to plain
* text because no producer skill emitted the right TOOL_CALL shape.
*
* The shape matches web/src/tool-args.ts:parseContextPanelArgs — a flat
* list of connector chips. Each chip carries:
* - id stable slug used as React key
* - label human-readable name
* - status "on" | "off" | "loading"
* - icon? optional glyph hint
*
* import { snapshot } from "../lib/bundle-snapshot.ts";
* const { contextPanel } = await snapshot();
*
* Pure read. Never writes. Scope-only by snappy-os convention.
*/
import { existsSync, readFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const HERE = dirname(fileURLToPath(import.meta.url));
const ROOT = join(HERE, "..", "..");
const HEAD_SCREEN_BASE =
process.env.HEAD_SCREEN_URL ?? "http://127.0.0.1:3147";
export type ContextPanelStatus = "on" | "off" | "loading";
export interface ContextPanelConnector {
id: string;
label: string;
status: ContextPanelStatus;
icon?: string;
}
export interface ContextPanelPayload {
connectors: ContextPanelConnector[];
}
export interface SnapshotOpts {
/** Override head-screen base URL (mostly for tests). */
headScreenUrl?: string;
/** Skip the live HTTP probe and read bundle status from disk only. */
offline?: boolean;
}
interface BundleStatus {
ok?: boolean;
mounted?: boolean;
ejected?: boolean;
root?: string | null;
meta?: { name?: string | null } | null;
default_root?: string | null;
}
async function fetchBundleStatus(base: string): Promise<BundleStatus | null> {
try {
const res = await fetch(`${base}/bundle/status`, {
signal: AbortSignal.timeout(2_000),
});
if (!res.ok) return null;
return (await res.json()) as BundleStatus;
} catch {
return null;
}
}
function readEnvCachePresence(): boolean {
// The .env.cache symlink in the repo root is the canonical credential
// store. If it's missing or broken, the secrets connector is "off".
const p = join(ROOT, ".env.cache");
return existsSync(p);
}
function readDispatchConfigBackend(): { backend: string | null; model: string | null } {
const p = join(ROOT, "state", "config", "dispatch.json");
if (!existsSync(p)) return { backend: null, model: null };
try {
const o = JSON.parse(readFileSync(p, "utf8")) as {
chat?: { backend?: string; model?: string };
};
return {
backend: o.chat?.backend ?? null,
model: o.chat?.model ?? null,
};
} catch {
return { backend: null, model: null };
}
}
/**
* Build a ContextPanel describing the active bundle and the connectors the
* cockpit knows about. Connector status is derived from disk where
* possible; the head-screen HTTP probe is consulted for live mount state
* with a 2s timeout so the function never blocks the dispatcher.
*/
export async function snapshot(
opts: SnapshotOpts = {},
): Promise<{ contextPanel: ContextPanelPayload }> {
const base = opts.headScreenUrl ?? HEAD_SCREEN_BASE;
const status = opts.offline ? null : await fetchBundleStatus(base);
const mounted = status?.mounted === true && status?.ejected !== true;
const bundleName =
(status?.meta && status.meta.name) ||
(status?.root ? status.root.replace(/^.*\//, "") : null);
const bundleLabel = mounted
? `snappy-os bundle (${bundleName ?? "mounted"})`
: "snappy-os bundle";
const bundleStatusToken: ContextPanelStatus = mounted ? "on" : "off";
const dispatch = readDispatchConfigBackend();
const dispatchLabel = dispatch.backend
? `chat backend (${dispatch.backend}${dispatch.model ? " / " + dispatch.model : ""})`
: "chat backend";
const dispatchStatus: ContextPanelStatus = dispatch.backend ? "on" : "off";
const credsStatus: ContextPanelStatus = readEnvCachePresence() ? "on" : "off";
const connectors: ContextPanelConnector[] = [
{
id: "bundle",
label: bundleLabel,
status: bundleStatusToken,
icon: "bundle",
},
{
id: "head-screen",
label: "head-screen server (127.0.0.1:3147)",
status: status === null ? "off" : "on",
icon: "server",
},
{
id: "dispatch",
label: dispatchLabel,
status: dispatchStatus,
icon: "dispatch",
},
{
id: "credentials",
label: "credentials (.env.cache)",
status: credsStatus,
icon: "key",
},
{
id: "web",
label: "Web search",
status: "off",
icon: "web",
},
{
id: "browser",
label: "Claude in Chrome",
status: "off",
icon: "browser",
},
];
return { contextPanel: { connectors } };
}
// CLI smoke-test path: `npx tsx state/lib/bundle-snapshot.ts`
const isMain = (() => {
try {
const argv1 = process.argv[1];
if (!argv1) return false;
return import.meta.url === new URL(`file://${argv1}`).href
|| import.meta.url.endsWith(argv1);
} catch { return false; }
})();
if (isMain) {
snapshot().then(out => {
process.stdout.write(JSON.stringify(out, null, 2) + "\n");
}).catch(err => {
console.error(`bundle-snapshot: ${err}`);
process.exit(1);
});
}
scripts- helper scripts it can run
prose-only skill - 1 inline code block live in SKILL.md above (no state/bin/ sidecar yet).
how we check it- the checks, plus the last 3 runs
| timestamp | verb | score | primary_issue | artifact |
|---|---|---|---|---|
| 2026-04-29 04:31Z | - | 1.00 | - | - |
| 2026-04-29 04:31Z | - | 1.00 | - | - |
| 2026-04-29 04:31Z | - | 1.00 | - | - |