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.4.0] - 2026-06-17

### Security
- **PAL verify is now a declarative, typed check instead of a raw shell command.** `palAutoVerify` no longer runs a stored shell string through `execSync`; it runs a typed check natively (`http-status` via fetch, `file-exists` via fs), never through a shell and never by interpolating a stored value into a command. There is no longer an arbitrary-command-execution sink. This removes a persistence/deferred-execution risk that mattered for kit's agent-native use: a prompt-injected agent could previously store a `verify_cmd` in one (low-trust) session that detonated later when a more-trusted session ran `kit memory pal verify`. The typed model is also deliberately autonomy-friendly: auto-verify needs no human gate, yet a planted or injected value is inert (a defensive parser rejects any unknown shape). Closes the residual `memory/pal.js` finding (Socket AI) at the root rather than by adding a human-in-the-loop gate that would break autonomous agent jobs.

### Changed
- **`kit memory pal add` verify flags:** use `--verify-http <url> [--expect <code>]` or `--verify-file <path>` instead of `--verify "<shell>"`. For checks these types do not cover, run the check yourself and close the item manually (pal stays a ledger). Raw shell `verify_cmd` from pre-1.4 stores is retained so `kit memory scan` can still find secrets in old rows, but is never auto-executed.

## [1.3.1] - 2026-06-17

### Security
Expand Down
25 changes: 18 additions & 7 deletions docs/MEMORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,25 @@ source-verifiable: see the table in the repo notes.)
### Pending actions (PAL)

A structured "blocked-on-you" ledger on top of the raw log — items that survive
across sessions and **auto-close when their verify command starts passing**.
across sessions and **auto-close when their declarative verify check starts
passing**. A verify is a typed, native check (no shell), so it is safe to
auto-run unattended and a planted value can never execute code:

```bash
kit memory pal # list open items
kit memory pal add "ship the release" --verify "curl -fsS https://… | grep -q 200"
kit memory pal # list open items
kit memory pal add "ship the release" --verify-http https://example.com --expect 200
kit memory pal add "build artifact exists" --verify-file ./dist/cli.js
kit memory pal done <id> | snooze <id> <days>
kit memory pal verify # run verifies: N=2 consecutive passes closes; a regression reopens
kit memory pal import # migrate a legacy ~/.claude/pal/ledger.jsonl
kit memory pal verify # run checks: N=2 consecutive passes closes; a regression reopens
kit memory pal import # migrate a legacy ~/.claude/pal/ledger.jsonl (verifies become manual)
```

Supported verify checks: `--verify-http <url> [--expect <code>]` (kit makes the
request and compares the status) and `--verify-file <path>` (file exists). kit
never runs a shell verify. For a check these types do not cover, run it yourself
and close the item manually. Raw shell `verify_cmd` from pre-1.4 stores is never
auto-executed.

Open items surface in the `UserPromptSubmit` reminder so handed-off tasks stop
getting forgotten. Verify commands run in your shell — they are **operator-authored
and live in the personal store only**; never put an executable verify on an item
Expand Down Expand Up @@ -183,8 +192,10 @@ Shared memory is **treated like code**:
cell contents. It reports masked findings and exits non-zero if any are found,
so you can use it as a gate.
- Backups are encrypted (AES-256-GCM, scrypt). The passphrase is never stored.
- Shared writes are secret-scanned fail-closed; executable verify commands never
cross the sharing boundary.
- Shared writes are secret-scanned fail-closed. Verify checks are declarative
and typed (no shell), and a verify imported or merged from another store is
demoted to a manual item, so no executable ever crosses a file, DB, or sharing
boundary and auto-runs.

## Where it sits

Expand Down
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.3.1",
"version": "1.4.0",
"description": "developer kit. zero LLM, local-first, multi-vault. one command from git clone to working dev environment.",
"license": "MIT",
"type": "module",
Expand Down
17 changes: 14 additions & 3 deletions src/commands/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
palSnooze,
palAutoVerify,
importLegacyLedger,
type VerifyCheck,
} from "../memory/pal.js";
import {
saveThread,
Expand Down Expand Up @@ -109,13 +110,23 @@ async function memPal(): Promise<boolean> {
const title = process.argv.slice(5).filter((a) => !a.startsWith("--")).join(" ").trim();
if (!title) {
console.error(
`${c.red}usage: kit memory pal add <title> [--verify=<cmd>] [--scope=<s>]${c.reset}`,
`${c.red}usage: kit memory pal add <title> [--verify-http <url> [--expect <code>]] [--verify-file <path>] [--scope=<s>]${c.reset}`,
);
return false;
}
// Declarative verify only (no shell). http-status or file-exists.
const httpUrl = flagValue(process.argv, "--verify-http");
const filePath = flagValue(process.argv, "--verify-file");
let check: VerifyCheck | undefined;
if (httpUrl) {
const expect = Number(flagValue(process.argv, "--expect") ?? "200");
check = { type: "http-status", url: httpUrl, expect: Number.isFinite(expect) ? expect : 200 };
} else if (filePath) {
check = { type: "file-exists", path: filePath };
}
const id = palAdd(db, {
title,
verifyCmd: flagValue(process.argv, "--verify"),
check,
scope: flagValue(process.argv, "--scope") ?? basename(getCurrentProjectRoot()),
});
console.log(`${c.green}✓${c.reset} added ${c.bold}${id}${c.reset}`);
Expand Down Expand Up @@ -149,7 +160,7 @@ async function memPal(): Promise<boolean> {
return true;
}
if (action === "verify") {
const r = palAutoVerify(db);
const r = await palAutoVerify(db);
console.log(
`${c.dim}checked ${r.checked} · closed ${r.closed.length} · reopened ${r.reopened.length}${c.reset}`,
);
Expand Down
5 changes: 5 additions & 0 deletions src/memory/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ CREATE TABLE IF NOT EXISTS pending_actions (
scope TEXT,
kind TEXT NOT NULL DEFAULT 'manual',
verify_cmd TEXT,
verify_check TEXT,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
next_check TEXT,
snooze_until TEXT,
Expand Down Expand Up @@ -149,6 +150,10 @@ function migrate(db: DatabaseSync): void {
// v2: pending_actions.verify_passes (N=2 auto-verify confirmation). Add to
// tables created before this column existed.
ensureColumn(db, "pending_actions", "verify_passes", "INTEGER NOT NULL DEFAULT 0");
// v3: pending_actions.verify_check (declarative typed verify replacing raw
// shell verify_cmd). Legacy verify_cmd rows have a NULL verify_check and are
// never auto-executed.
ensureColumn(db, "pending_actions", "verify_check", "TEXT");
const row = db.prepare("SELECT version FROM schema_meta LIMIT 1").get() as
| { version: number }
| undefined;
Expand Down
55 changes: 43 additions & 12 deletions src/memory/pal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import {
describe("PAL — pending actions", () => {
const fresh = () => openMemoryDb(":memory:");

it("adds + lists; kind inferred from verifyCmd", () => {
it("adds + lists; kind inferred from a verify check", () => {
const db = fresh();
const manual = palAdd(db, { title: "ship the harvest branch" });
const auto = palAdd(db, { title: "endpoint returns 200", verifyCmd: "true" });
const auto = palAdd(db, {
title: "endpoint returns 200",
check: { type: "http-status", url: "https://example.com", expect: 200 },
});
assert.match(manual, /^[0-9a-f]{4}$/);
const open = palList(db);
assert.equal(open.length, 2);
Expand Down Expand Up @@ -47,29 +50,39 @@ describe("PAL — pending actions", () => {
db.close();
});

it("auto-verify closes after N=2 passes; a failing verify stays open", () => {
it("auto-verify closes after N=2 passes; a failing check stays open", async () => {
const db = fresh();
const passes = palAdd(db, { title: "passing check", verifyCmd: "true" });
const fails = palAdd(db, { title: "failing check", verifyCmd: "false" });
let r = palAutoVerify(db);
const tmp = mkdtempSync(join(tmpdir(), "kit-pal-"));
const present = join(tmp, "present");
writeFileSync(present, "x");
const missing = join(tmp, "missing");
const passes = palAdd(db, { title: "passing check", check: { type: "file-exists", path: present } });
const fails = palAdd(db, { title: "failing check", check: { type: "file-exists", path: missing } });
let r = await palAutoVerify(db);
assert.deepEqual(r.closed, []); // first pass: streak = 1
assert.equal(palList(db).length, 2);
r = palAutoVerify(db);
r = await palAutoVerify(db);
assert.deepEqual(r.closed, [passes]); // second consecutive pass closes it
const open = palList(db);
assert.equal(open.length, 1);
assert.equal(open[0]?.id, fails);
rmSync(tmp, { recursive: true, force: true });
db.close();
});

it("reopens a closed auto item when its verify regresses", () => {
it("reopens a closed auto item when its check regresses", async () => {
const db = fresh();
const id = palAdd(db, { title: "regressing check", verifyCmd: "false" });
const tmp = mkdtempSync(join(tmpdir(), "kit-pal-"));
const artifact = join(tmp, "artifact");
writeFileSync(artifact, "x");
const id = palAdd(db, { title: "regressing check", check: { type: "file-exists", path: artifact } });
palDone(db, id); // force-close
assert.equal(palList(db, { status: "closed" }).length, 1);
const r = palAutoVerify(db); // verify 'false' on a closed auto item → reopen
rmSync(artifact); // artifact gone -> the check now fails
const r = await palAutoVerify(db); // fail on a closed auto item -> reopen
assert.deepEqual(r.reopened, [id]);
assert.equal(palList(db).length, 1);
rmSync(tmp, { recursive: true, force: true });
db.close();
});

Expand Down Expand Up @@ -113,7 +126,7 @@ describe("PAL — pending actions", () => {
db.close();
});

it("SECURITY: a verify command imported from a legacy ledger is never auto-executed", () => {
it("SECURITY: a verify command imported from a legacy ledger is never auto-executed", async () => {
const db = fresh();
const tmp = mkdtempSync(join(tmpdir(), "kit-pal-sec-"));
const led = join(tmp, "ledger.jsonl");
Expand All @@ -132,12 +145,30 @@ describe("PAL — pending actions", () => {
const item = palList(db).find((p) => p.id === "evil");
assert.equal(item?.kind, "manual"); // demoted: not an auto item
assert.equal(item?.verify_cmd ?? null, null); // executable command dropped on import
palAutoVerify(db); // must NOT run `touch ${marker}`
await palAutoVerify(db); // must NOT run `touch ${marker}`
assert.equal(existsSync(marker), false, "imported verify_cmd must never execute");
rmSync(tmp, { recursive: true, force: true });
db.close();
});

it("SECURITY: an unknown/injected verify_check shape is never executed", async () => {
const db = fresh();
const tmp = mkdtempSync(join(tmpdir(), "kit-pal-sec2-"));
const marker = join(tmp, "PWNED");
// Simulate DB tampering: inject a row with a bogus verify_check that a naive
// executor might run as a command. parseCheck must reject the unknown shape;
// nothing executes.
db.prepare(
`INSERT INTO pending_actions (id, status, title, kind, verify_check)
VALUES ('evil', 'open', 'injected', 'auto', ?)`,
).run(JSON.stringify({ type: "shell", cmd: `touch ${marker}` }));
const r = await palAutoVerify(db);
assert.equal(r.checked, 0); // unknown shape -> not even run
assert.equal(existsSync(marker), false, "injected verify_check must never execute");
rmSync(tmp, { recursive: true, force: true });
db.close();
});

it("scopes the open list to a project (plus globally-scoped items)", () => {
const db = fresh();
palAdd(db, { title: "kit item", scope: "kit" });
Expand Down
Loading
Loading