diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ead08b..21b7c4fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ""`, 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 diff --git a/package-lock.json b/package-lock.json index 9d4838f9..c630a1dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sandstream-kit", - "version": "1.21.0", + "version": "1.22.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sandstream-kit", - "version": "1.21.0", + "version": "1.22.0", "license": "MIT", "workspaces": [ "packages/*" diff --git a/package.json b/package.json index 06050535..36897743 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli.ts b/src/cli.ts index 96e70e79..fe4e41c2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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"; @@ -4355,14 +4356,18 @@ async function cmdAgentAudit(): Promise { } async function cmdSentinel(): Promise { - 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 [--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"); @@ -4407,6 +4412,16 @@ async function cmdSentinel(): Promise { }, }); + // 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; @@ -4429,6 +4444,48 @@ async function cmdSentinel(): Promise { return true; } +/** `kit sentinel install` — scaffold the L3 scheduler (GitHub Actions) (#53). */ +async function cmdSentinelInstall(): Promise { + 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 { + 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 { const jsonMode = hasFlag(process.argv, "--json"); const { runScanners, suppressBaselined, dedupKey } = await import("./scanners.js"); diff --git a/src/sentinel.test.ts b/src/sentinel.test.ts index 036c9249..e9a30f2a 100644 --- a/src/sentinel.test.ts +++ b/src/sentinel.test.ts @@ -9,6 +9,10 @@ import { applyDedup, parseSuppressions, runSentinel, + proposalSummary, + sentinelStatusLine, + sentinelWorkflow, + SENTINEL_CACHE, type RedFinding, } from "./sentinel.js"; import type { HealthFinding } from "./health.js"; @@ -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"); + }); +}); diff --git a/src/sentinel.ts b/src/sentinel.ts index 89bcae10..9b140b56 100644 --- a/src/sentinel.ts +++ b/src/sentinel.ts @@ -143,3 +143,70 @@ export async function runSentinel(cwd: string, deps: SentinelDeps): Promise; +} + +/** Digest proposals for caching/surfacing (pure). `fresh` = not already open. */ +export function proposalSummary(proposals: Proposal[]): SentinelSummary { + const byClass: Record = { 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 }} +`; +}