Skip to content
Merged
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

## [1.22.0] - 2026-06-23

### Added
- **Sentinel layer 3 — scheduling + surfacing (#53).** L2 produces proposals on demand; L3 makes them _recur_ and _visible_, staying zero-LLM + agent-agnostic. `kit sentinel install` scaffolds a GitHub Actions scheduler (`.github/workflows/kit-sentinel.yml`, weekly by default, `--schedule "<cron>"`, refuses to clobber without `--force`) that recurs `kit sentinel run --json` — an agent (or a downstream job step) acts on the JSON. `kit sentinel run` now caches a compact summary to `.kit/sentinel.json` (best-effort; never fails the run), and `kit sentinel status` prints a one-line SessionStart surface (`[sentinel · N fresh, M need you]`) — silent when nothing is fresh, `--json` for the raw digest. Pure `proposalSummary` / `sentinelStatusLine` / `sentinelWorkflow` fixture-tested.

### Changed
- **`kit scan` resolves scanner tokens from a tooling vault — no `infisical run` wrapper (#65).** New optional `[scan.tooling]` config (`project_id`, `env`) points at a shared Infisical project (e.g. `sandstream-common`); `kit scan` resolves each scanner's `needsToken` (e.g. `SNYK_TOKEN`) from there and injects it into the scanner subprocess env. The value flows vault→subprocess and is never logged. New uncached `fetchInfisicalProjectSecrets` (distinct from the cached per-app `fetchInfisicalSecrets`); a token already in `process.env` always wins.

## [1.21.0] - 2026-06-23

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sandstream-kit",
"version": "1.21.0",
"version": "1.22.0",
"description": "developer kit. zero LLM, local-first, multi-vault. one command from git clone to working dev environment.",
"license": "MIT",
"funding": "https://buymeacoffee.com/sandstream",
Expand Down
63 changes: 60 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { checkServices } from "./check-services.js";
import { checkSecrets } from "./check-secrets.js";
import { checkSecurity } from "./check-security.js";
import type { HealthCtx } from "./health.js";
import type { SentinelSummary } from "./sentinel.js";
import { syncSecurityFindings } from "./findings-track.js";
import { checkWebSearch } from "./check-web-search.js";
import { installTools } from "./install.js";
Expand Down Expand Up @@ -4355,14 +4356,18 @@ async function cmdAgentAudit(): Promise<boolean> {
}

async function cmdSentinel(): Promise<boolean> {
if (process.argv[3] !== "run") {
console.error(`${c.red}usage: kit sentinel run [--json]${c.reset}`);
const sub = process.argv[3];
if (sub === "install") return cmdSentinelInstall();
if (sub === "status") return cmdSentinelStatus();
if (sub !== "run") {
console.error(`${c.red}usage: kit sentinel <run|install|status> [--json]${c.reset}`);
process.exitCode = 1;
return false;
}
const jsonMode = hasFlag(process.argv, "--json");
const config = await loadConfig(resolveConfigPath());
const { runSentinel, healthToRedFindings } = await import("./sentinel.js");
const { runSentinel, healthToRedFindings, proposalSummary, SENTINEL_CACHE } =
await import("./sentinel.js");
const { runHealth, selectSensors, defaultHealthDeps } = await import("./health.js");
const { execFileNoThrow } = await import("./utils/execFileNoThrow.js");

Expand Down Expand Up @@ -4407,6 +4412,16 @@ async function cmdSentinel(): Promise<boolean> {
},
});

// L3: cache a compact summary for the SessionStart surface (#53). Best-effort —
// a cache-write failure must never fail the run itself.
try {
const cachePath = resolve(process.cwd(), SENTINEL_CACHE);
await mkdir(dirname(cachePath), { recursive: true });
writeFileSync(cachePath, JSON.stringify(proposalSummary(proposals), null, 2) + "\n");
} catch {
// no cache → status surface simply stays quiet
}

if (jsonMode) {
console.log(JSON.stringify({ proposals }, null, 2));
return true;
Expand All @@ -4429,6 +4444,48 @@ async function cmdSentinel(): Promise<boolean> {
return true;
}

/** `kit sentinel install` — scaffold the L3 scheduler (GitHub Actions) (#53). */
async function cmdSentinelInstall(): Promise<boolean> {
const { sentinelWorkflow } = await import("./sentinel.js");
const dest = resolve(process.cwd(), ".github/workflows/kit-sentinel.yml");
if (existsSync(dest) && !hasFlag(process.argv, "--force")) {
console.error(
`${c.yellow}.github/workflows/kit-sentinel.yml exists — re-run with --force to overwrite${c.reset}`,
);
process.exitCode = 1;
return false;
}
const si = process.argv.indexOf("--schedule");
const schedule = si >= 0 ? process.argv[si + 1] : undefined;
await mkdir(dirname(dest), { recursive: true });
writeFileSync(dest, schedule ? sentinelWorkflow(schedule) : sentinelWorkflow());
console.log(`${c.green}✓${c.reset} wrote .github/workflows/kit-sentinel.yml`);
console.log(
` ${c.dim}recurs \`kit sentinel run --json\`; an agent (or a downstream step) acts on the JSON${c.reset}`,
);
return true;
}

/** `kit sentinel status` — print the cached one-line surface for a SessionStart hook (#53). */
async function cmdSentinelStatus(): Promise<boolean> {
const { SENTINEL_CACHE, sentinelStatusLine } = await import("./sentinel.js");
let summary: SentinelSummary | null = null;
try {
summary = JSON.parse(readFileSync(resolve(process.cwd(), SENTINEL_CACHE), "utf8"));
} catch {
// no cache yet (sentinel never run) → nothing to surface
}
if (hasFlag(process.argv, "--json")) {
console.log(
JSON.stringify(summary ?? { total: 0, fresh: 0, byClass: { code: 0, human: 0, noise: 0 } }),
);
return true;
}
const line = sentinelStatusLine(summary);
if (line) console.log(line); // silent when nothing fresh → clean SessionStart surface
return true;
}

async function cmdScan(): Promise<boolean> {
const jsonMode = hasFlag(process.argv, "--json");
const { runScanners, suppressBaselined, dedupKey } = await import("./scanners.js");
Expand Down
64 changes: 64 additions & 0 deletions src/sentinel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
applyDedup,
parseSuppressions,
runSentinel,
proposalSummary,
sentinelStatusLine,
sentinelWorkflow,
SENTINEL_CACHE,
type RedFinding,
} from "./sentinel.js";
import type { HealthFinding } from "./health.js";
Expand Down Expand Up @@ -119,3 +123,63 @@ describe("runSentinel (gather → build → dedup)", () => {
assert.equal(out[0].alreadyOpen, true);
});
});

describe("proposalSummary (#53 L3)", () => {
const red: RedFinding[] = [
{ id: "health:vercel", class: "code", title: "deploy failed" },
{ id: "health:resend", class: "human", title: "domain unverified" },
{ id: "x:y", class: "noise", title: "benign" },
];
it("counts total, fresh (not already open), and per-class", () => {
// only the code finding already has an open artifact
const proposals = applyDedup(buildProposals(red), new Set(["health:vercel"]));
const s = proposalSummary(proposals);
assert.equal(s.total, 3);
assert.equal(s.fresh, 2); // resend + x:y fresh; vercel already open
assert.deepEqual(s.byClass, { code: 1, human: 1, noise: 1 });
});
it("treats unchecked dedup (null) as fresh", () => {
const s = proposalSummary(applyDedup(buildProposals(red), null));
assert.equal(s.fresh, 3);
});
});

describe("sentinelStatusLine (#53 surface)", () => {
it("is null when nothing fresh (or no cache)", () => {
assert.equal(sentinelStatusLine(null), null);
assert.equal(
sentinelStatusLine({ total: 2, fresh: 0, byClass: { code: 0, human: 0, noise: 0 } }),
null,
);
});
it("renders fresh count, and flags human items needing the user", () => {
assert.equal(
sentinelStatusLine({ total: 3, fresh: 3, byClass: { code: 2, human: 1, noise: 0 } }),
"[sentinel · 3 fresh, 1 need you]",
);
assert.equal(
sentinelStatusLine({ total: 1, fresh: 1, byClass: { code: 1, human: 0, noise: 0 } }),
"[sentinel · 1 fresh]",
);
});
});

describe("sentinelWorkflow (#53 scheduler)", () => {
it("emits a runnable GHA workflow with the default weekly cron", () => {
const wf = sentinelWorkflow();
assert.match(wf, /cron: "0 7 \* \* 1"/);
assert.match(wf, /kit sentinel run --json/);
assert.match(wf, /name: kit-sentinel/);
// GHA expression survived the template literal (not interpolated to empty)
assert.ok(wf.includes("${{ github.token }}"));
});
it("honours a custom schedule", () => {
assert.match(sentinelWorkflow("0 0 * * *"), /cron: "0 0 \* \* \*"/);
});
});

describe("SENTINEL_CACHE", () => {
it("points under the .kit dir", () => {
assert.equal(SENTINEL_CACHE, ".kit/sentinel.json");
});
});
67 changes: 67 additions & 0 deletions src/sentinel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,70 @@ export async function runSentinel(cwd: string, deps: SentinelDeps): Promise<Prop
const proposals = buildProposals(findings, suppressed);
return applyDedup(proposals, await deps.openMarkers());
}

// ── Layer 3: scheduling + surfacing (#53) ──────────────────────────────────
// L2 produces proposals on demand; L3 makes them RECUR (a scheduler) and makes
// the result VISIBLE between runs (a cached summary a SessionStart hook reads).
// Both halves stay zero-LLM + agent-agnostic: `kit sentinel install` scaffolds a
// scheduler that runs `kit sentinel run --json`; any agent (or the job itself)
// acts on that JSON. Nothing here opens an artifact or needs creds.

/** Repo-relative path to the cached summary the SessionStart surface reads. */
export const SENTINEL_CACHE = ".kit/sentinel.json";

/** A compact, serialisable digest of a proposal set — what L3 caches + surfaces. */
export interface SentinelSummary {
total: number;
fresh: number;
byClass: Record<FindingClass, number>;
}

/** Digest proposals for caching/surfacing (pure). `fresh` = not already open. */
export function proposalSummary(proposals: Proposal[]): SentinelSummary {
const byClass: Record<FindingClass, number> = { code: 0, human: 0, noise: 0 };
let fresh = 0;
for (const p of proposals) {
byClass[p.class]++;
if (p.alreadyOpen !== true) fresh++;
}
return { total: proposals.length, fresh, byClass };
}

/** One-line SessionStart surface, e.g. `[sentinel · 3 fresh, 1 need you]`. null = stay quiet. */
export function sentinelStatusLine(s: SentinelSummary | null | undefined): string | null {
if (!s || s.fresh === 0) return null;
const human = s.byClass.human > 0 ? `, ${s.byClass.human} need you` : "";
return `[sentinel · ${s.fresh} fresh${human}]`;
}

/**
* GitHub Actions workflow that recurs `kit sentinel run` (#53 L3 scheduler).
* Read-only by default: it emits the proposal JSON; an agent step acts on it.
* GHA expression syntax is backslash-escaped so it survives the template literal.
*/
export function sentinelWorkflow(schedule = "0 7 * * 1"): string {
return `# Generated by \`kit sentinel install\` — layer-3 scheduler (#53).
# Recurs the agent-agnostic responder; an agent (or a downstream step) acts on the JSON.
name: kit-sentinel
on:
schedule:
- cron: "${schedule}"
workflow_dispatch: {}
permissions:
contents: read
issues: write
pull-requests: write
jobs:
sentinel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: kit sentinel run
run: npx --yes sandstream-kit sentinel run --json | tee sentinel.json
env:
GH_TOKEN: \${{ github.token }}
`;
}
Loading