Skip to content
Closed
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
23 changes: 0 additions & 23 deletions .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,6 @@
}
]
}
],
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
"hooks": [
{
"type": "command",
"command": "node \"$CLAUDE_PROJECT_DIR/scripts/agent/claude.mts\" post-tool",
"timeout": 120
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "node \"$CLAUDE_PROJECT_DIR/scripts/agent/claude.mts\" stop",
"timeout": 300
}
]
}
]
}
}
25 changes: 0 additions & 25 deletions .codex/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
}
]
}
],
"PostToolUse": [
{
"matcher": "^(apply_patch|Edit|Write)$",
"hooks": [
{
"type": "command",
"command": "node \"$(git rev-parse --show-cdup)scripts/agent/codex.mts\" post-tool",
"statusMessage": "Formatting and checking the edited files",
"timeout": 120
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "node \"$(git rev-parse --show-cdup)scripts/agent/codex.mts\" stop",
"statusMessage": "Checking every changed file",
"timeout": 300
}
]
}
]
}
}
12 changes: 0 additions & 12 deletions .githooks/commit-msg

This file was deleted.

12 changes: 0 additions & 12 deletions .githooks/pre-commit

This file was deleted.

12 changes: 0 additions & 12 deletions .githooks/pre-push

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ jobs:
- run: npm ci
- run: npm --prefix studio ci
- run: npm run build
- name: Run Linux release preflight
run: |
sudo chown root:root node_modules/electron/dist/chrome-sandbox
sudo chmod 4755 node_modules/electron/dist/chrome-sandbox
xvfb-run --auto-servernum npm run check:linux
- run: npx electron-builder --linux --publish never
- name: Install and test Debian package
# Refresh the package index first: the runner image's index named archive files that
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: npm
- name: Check pull request commit messages
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/policy/checkCommitRange.mts "$BASE_SHA" "$HEAD_SHA"
- run: npm ci
- run: npm --prefix studio ci
- run: npm run format:check
Expand Down
55 changes: 2 additions & 53 deletions .pi/extensions/stacki-policy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Claude Code and Codex hooks enforce (scripts/agent/hook.mts), from the same
// functions. Pi loads project extensions after the project is trusted.
//
// tool_call refuses gate-skipping commands; asks before gate-file edits
// tool_result formats and checks each file a write or edit touched
// agent_before_settle checks every changed file; a failure continues the run
// with the findings, at most stopContinuationsMax times
// The tool-call guard asks before gate-file edits. GitHub runs the code checks.
//
// Pi's event payloads come from outside this repository, so they are read as
// unknown and parsed field by field (AGENTS.md §2). The Pi package is not a
Expand All @@ -14,15 +11,13 @@
import path from 'node:path';
import { commandVerdict, pathVerdict, repositoryPath, type Verdict } from '../../../scripts/agent/core.mts';
import { field } from '../../../scripts/agent/payload.mts';
import { checkChanged, checkFiles, repositoryRoot } from '../../../scripts/policy/checks.mts';
import { POLICY_LIMITS } from '../../../scripts/policy/limits.mts';
import { repositoryRoot } from '../../../scripts/policy/checks.mts';

interface PiContext {
readonly cwd: string;
readonly hasUI: boolean;
readonly ui: {
confirm(title: string, message: string): Promise<boolean>;
notify(message: string, type?: 'info' | 'warning' | 'error'): void;
};
}

Expand All @@ -37,7 +32,6 @@ const POLICY_EDIT_APPROVAL = 'STACKI_ALLOW_POLICY_EDITS';

export default function stackiPolicy(pi: PiApi): void {
const root = repositoryRoot();
let refusals = 0;

pi.on('tool_call', async (event, context) => {
const verdict = toolVerdict(root, event, context.cwd);
Expand All @@ -56,46 +50,6 @@ export default function stackiPolicy(pi: PiApi): void {
}
return { block: true, reason: verdict.reason };
});

pi.on('tool_result', (event, context) => {
const file = editedFile(root, event, context.cwd);
if (file === undefined) {
return undefined;
}
const outcome = checkFiles(root, [file], { format: 'write' });
if (outcome.kind === 'pass') {
return undefined;
}
const existing: unknown = Reflect.get(asObject(event), 'content');
const content: readonly unknown[] = Array.isArray(existing) ? existing : [];
const text = truncate(`The edit left findings:\n\n${outcome.report}`);
return { content: [...content, { type: 'text', text }], isError: true };
});

pi.on('agent_before_settle', (event, context) => {
const outcome = checkChanged(root);
if (outcome.kind === 'pass') {
refusals = 0;
return undefined;
}
refusals += 1;
if (refusals > POLICY_LIMITS.stopContinuationsMax) {
refusals = 0;
context.ui.notify('stacki: stopped with failing checks; run `npm run check:changed`.', 'warning');
return undefined;
}
const existing: unknown = Reflect.get(asObject(event), 'entries');
const entries: readonly unknown[] = Array.isArray(existing) ? existing : [];
const heading =
`The changes do not pass the repository checks yet (attempt ${refusals} of ` + `${POLICY_LIMITS.stopContinuationsMax}). Fix these, then finish:`;
const message = {
type: 'custom_message',
customType: 'stacki-policy',
content: truncate(`${heading}\n\n${outcome.report}`),
display: true,
};
return { entries: [...entries, message], continue: true };
});
}

function toolVerdict(root: string, event: unknown, cwd: string): Verdict {
Expand Down Expand Up @@ -124,8 +78,3 @@ function editedFile(root: string, event: unknown, cwd: string): string | undefin
function asObject(value: unknown): object {
return typeof value === 'object' && value !== null ? value : {};
}

function truncate(text: string): string {
const limit = POLICY_LIMITS.feedbackCharsMax;
return text.length <= limit ? text : `${text.slice(0, limit)}\n… (truncated)`;
}
28 changes: 11 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ the same checks run for people and for every coding agent (Claude Code, Codex,
Pi). `docs/enforcement.md` maps each rule to the check that holds it and lists
the rules that remain for review.

- Agent hooks format and check each file you edit, and check every changed
file before you finish. Fix what they report; do not work around them.
- `npm run check:changed` runs the finish check by hand. Run it before you
say you are done.
- `npm run check:local` runs fast repository-wide checks before `npm run dev`.
All Desktop compiler targets and test source paths also run at agent finish,
because config changes and deleted files can break unchanged callers.
- Git hooks check staged files, commit messages, and pushes. Never skip them
(`--no-verify`); the agent hooks refuse it, and CI runs the same checks.
- Pushes run the full clean-build and regression gate locally so passing
TypeScript alone cannot send a known test failure to GitHub.
- GitHub Actions runs required checks for pull requests and pushes to
`main`. Wait for the checks on the current commit and fix failures before
merging. This keeps builds and tests off the contributor's machine and
checks every supported operating system.
- Run local checks only when the user asks. Commits, pushes, development
launches, and agent sessions can proceed without starting the test suite.
- The files that define the gates (this file, lint and compiler configs,
`scripts/{eslintPlugin,policy,agent}/`, hook configs, `shared/core/limits.ts`)
change only with a human's approval.
Expand Down Expand Up @@ -538,7 +533,7 @@ installs; their cost is amplified through everything built on them.
`docs/contracts.md` before changing page trees, scans, preload methods, IPC
channels, or renderer bridge modules. Values from IPC, disk, browser messages,
drag data, and `JSON.parse` stay `unknown` until the matching shared or feature
boundary parser accepts them. Generated or edited code must pass
boundary parser accepts them. GitHub Actions runs the equivalent of
`env -u ELECTRON_RUN_AS_NODE npm test`, which includes strict TypeScript,
ESLint, production builds, contract tests, and the complete regression suite.

Expand All @@ -554,10 +549,9 @@ ESLint, production builds, contract tests, and the complete regression suite.
- Where a state machine exists, property-based tests (e.g. fast-check) hunt the
transitions you didn't think of. A fuzzer proves the presence of bugs, never
their absence — the mental model and its assertions come first.
- When a GitHub release or publishing workflow fails, reproduce the cause locally and add or
improve a regression test whenever possible before pushing again. This prevents the same
failure from recurring only in GitHub. Follow [publishing failure handling](docs/releases.md).
If local reproduction is impractical, document why and the verification that remains remote.
- When a GitHub release or publishing workflow fails, use the GitHub logs to
identify the cause and add or improve a regression test where possible.
Verify the fix on GitHub. Follow [publishing failure handling](docs/releases.md).

## Definition of done (checklist)

Expand All @@ -579,7 +573,7 @@ ESLint, production builds, contract tests, and the complete regression suite.
- [ ] Comments are sentences that say why; test files open with goal and
methodology
- [ ] New dependencies carry a written justification
- [ ] `npm run check:changed` passes (`tsc`, ESLint, Prettier, policy scan)
- [ ] GitHub Actions passes for the current pull request commit

## Code display

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MIT licensed — fork it, build on it, ship your own version.
- **Git & GitHub** — the branch chip in the title bar shows the current branch and dirty state. From its dropdown you can switch branches, create branches, commit, push, or publish a brand-new repo to GitHub (via the `gh` CLI).
- **Tell an AI what's selected** — **⇧⌘C** copies whatever the canvas has selected as the trail of `file:line-range` pointers that leads to it: the page, each component drilled into on the way down, then the node itself. Paste that into Claude Code or any AI chat that can read the project and it knows exactly which markup you mean.
- **Code fallback** — pages with markup too complex for the visual model open in a code editor instead, still with live preview.
- **New project** — "Start from Lumos" or "Start from Astro" creates a named site with the framework's own scaffolder and installs its dependencies for you.
- **New project.** Choose "Start from Lumos", "Start from shadcn", or "Start from Astro". Stacki creates the site and installs its dependencies. A new shadcn site opens on Style Gallery and includes a Component Gallery page. Set Astro’s `site` option to your public URL before deploying so the sitemap, canonical links, and social image URLs use that domain.

## Running in development

Expand Down
33 changes: 11 additions & 22 deletions docs/enforcement.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
# Enforcement

AGENTS.md states the rules; this page says which machine holds each one, so a reader can tell a
rule that cannot be broken from one that relies on review. Everything below runs the same way for
a person, for Claude Code, for Codex, and for Pi, because every gate calls the same code.
rule that cannot be broken from one that relies on review. GitHub Actions verifies the
same repository rules for people and coding agents.

## Gates

| Gate | When | What runs | Can it be skipped? |
|---|---|---|---|
| Agent pre-tool | Before an agent runs a command or edits a file | `scripts/agent/core.mts` verdicts | No: refusals come from the harness |
| Agent post-tool | After an agent edits a file | Prettier (writes), policy scan, ESLint on the file | No |
| Agent stop | When an agent tries to finish | Changed-file formatting, scan and lint; all Desktop compiler targets and test source paths | After 3 refusals for the same findings the session may end, and the human is told; new findings start a new round |
| `pre-commit` | `git commit` | Prettier check, scan, ESLint on staged files | `--no-verify`, which agent hooks refuse |
| `commit-msg` | `git commit` | Typed subject ≤ 72 characters, blank line, body | As above |
| Local development | `npm run dev` or `npm run check:local` | All Desktop compiler targets, full lint, formatting, policy, test source paths, Studio static checks | Run directly at any time |
| `pre-push` | `git push` | Full CI gate: clean builds, Desktop and Studio static checks and tests; a pushed version tag (`refs/tags/v<digit>…`) then runs the Linux preflight. Skipped only when every pushed tree already passed the full gate here (a marker keyed by tree hash and gate version, `scripts/gate/gateMarker.ts`) or a tag names a commit on `origin/main` that `Check` passed; `npm run check:local` (and the static Linux preflight for a tag) still runs | As above |
| Release (`npm run release:ship`) | Every release | The bump is a GitHub commit made from origin's files (version lines only, read back; subject fixed at 37 characters), so no local hook runs on it; the tag is created only when `Check` and `Candidate` are green on that exact SHA (`promote.mts` proves it again before publishing). The pre-push gate's job moves to CI on the exact commit | None: `release.yml` refuses to publish without both proofs |
| Commit messages | Every pull request | Typed subject ≤ 72 characters, blank line, body | GitHub Actions reports failures in the policy job |
| Local development checks | On request with `npm run check:local` | Desktop compiler targets, lint, formatting, policy, test source paths, Studio static checks | Optional |
| Release (`npm run release:ship`) | Every release | GitHub creates the version bump. The release tag requires green `Check` and `Candidate` runs on the exact commit | None: `release.yml` refuses to publish without both proofs |
| Quarantine (`scripts/gate/quarantine.json`) | Every gate run | A listed suite's failure is reported and tolerated only with an owner, a reason, two red run URLs and an expiry at most 7 days after it was added; an expired, invalid or protected (correctness, safety, data-write) entry fails the gate (`scripts/gate/quarantine.ts`) | Renewing an entry needs a new commit with a new reason |
| CI (`npm test -- --shard=k/4`) | Every pull request and push to `main` | Builds, `tsc` (app and scripts), ESLint, Prettier, scan, every test: a desktop static-checks job (`npm test -- --checks=desktop`), a Studio verify job (`--checks=studio`, 25-minute limit) and four test shards per platform, together exactly `npm test` (`scripts/gate/testShard.ts`); `test (<os>)` passes only when all six did | **No**, once `main` requires the `Check` workflow |

The adapters are thin: `.claude/settings.json` and `.codex/hooks.json` call
`scripts/agent/{claude,codex}.mts`; `.pi/extensions/stacki-policy/` imports the same modules. Git
hooks live in `.githooks/` and are installed by `npm install` (`scripts/policy/installGitHooks.mts`).
Claude Code, Codex, and Pi use a pre-tool guard for changes to protected files.
Commits, pushes, and development launches proceed without running repository checks.
GitHub Actions runs the required checks on the pull request.

Commands for people and agents:

- `npm run check:changed` — what the stop hook runs. Use it before you finish.
- `npm run check:local` — fast, repository-wide checks before starting development.
`npm run dev` runs these automatically before building and launching the app.
- `npm run check:changed` — optional checks for changed files.
- `npm run check:local` — optional repository-wide checks.
- `npm run typecheck` — checks the root, scripts, contracts, Electron, preload and preview
compiler configurations with separate incremental caches. The broad root program alone
cannot catch differences in the build targets' library and module settings.
Expand All @@ -45,12 +40,6 @@ Commands for people and agents:
whole-tree static checks, so it is no substitute for `check:changed` or the full gate
(`scripts/gate/gatePlan.ts`).

The push hook compiles the test runner and runs the full gate (unless the marker or green-tag proof above holds), with live output and a 30-minute
limit per command. It clears `ELECTRON_RUN_AS_NODE` for its children so agent terminals do not
silently run browser probes as Node programs. A failed build or test stops the push. This costs
several minutes, but catches local regressions before GitHub starts a release. CI still checks
clean dependency installation and all three operating systems; local checks cover the host OS.

### The gate files

Some files define the gates themselves: `AGENTS.md`, `CLAUDE.md`, `eslint.config.mjs`, the
Expand Down Expand Up @@ -134,7 +123,7 @@ an allow (`withRootAsDot` in `scripts/agent/core.mts`; issue #78).
| 17 | Dependencies justified | scan: `dependency-record` (`docs/dependencies.md` ↔ `package.json`) |
| 17 | One lockfile | scan: `one-lockfile` |
| 17 | Scripts are TypeScript | scan: `no-shell-script` |
| 17 | Descriptive commit messages | hook: `commit-msg` |
| 17 | Descriptive commit messages | CI: pull request commit message check |
| — | No `@ts-nocheck`; `@ts-expect-error` says why | scan: `no-ts-nocheck`; lint: `ban-ts-comment` |
| — | Code display: code in the UI is syntax highlighted | test: `test/renderer/ui/codeDisplayRule.test.js` (source scan with named allowlists); `test/renderer/ui/codeBlock.test.js` for each site; review for code that looks like a label |
| — | Dropdowns: the custom dropdown, never a native `<select>` | lint: `stacki/no-native-select` (JSX `<select>` and `createElement('select')`) in `src/` via `eslint.config.mjs`, and in `studio/src/` and `studio/demo/` via `studio/eslint.config.ts`, which loads the vendored rule file |
Expand Down
Loading