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
43 changes: 26 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,39 @@ name: CI

on:
push:
branches: [main, master]
branches: [main]
paths-ignore: ['**.md', 'docs/**', 'assets/**', 'LICENSE', 'NOTICE', 'TRADEMARK.md', '.gitignore']
pull_request:
branches: [main, master]
paths-ignore: ['**.md', 'docs/**', 'assets/**', 'LICENSE', 'NOTICE', 'TRADEMARK.md', '.gitignore']
Comment on lines +6 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep CI enabled for functional Markdown changes

When a push or PR changes only a built-in file such as src/commands/builtin/ship.md, **.md matches nested Markdown files too, so the workflow skips CI. These files define runtime commands and are copied into dist by the build, so changes to commands, agents, or skills receive no test or build check. Limit the exclusion to documentation paths; GitHub’s path-pattern docs confirm that **.md matches Markdown files throughout the repository.

Useful? React with 👍 / 👎.


jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [20]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
# CI never drives a real browser; skip the ~150 MB Chromium download.
PUPPETEER_SKIP_DOWNLOAD: '1'

jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
node-version: 22
cache: npm
cache-dependency-path: |
package-lock.json
gui/package-lock.json

- name: Install dependencies
run: npm install
- name: Install (engine)
run: npm ci

- name: Lint (tsc --noEmit)
run: npm run lint
Expand All @@ -36,8 +45,8 @@ jobs:
- name: Build engine (tsup)
run: npm run build

- name: Build GUI (vite)
- name: Install + build GUI (vite)
working-directory: gui
run: |
npm install
npm ci
npm run build
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<img src="assets/banner.svg" alt="sentinel-cli — one AI coding engine, four faces, any model">
</p>

<p align="center">
<strong>One AI coding engine. Four faces. Any model.</strong><br>
A streaming agentic loop with real tools — terminal UI, desktop GUI, headless CLI, and MCP server — that runs against any cloud or local provider.
</p>
# sentinel-cli

**One AI coding engine, four faces (TUI, desktop GUI, headless CLI, MCP server), any cloud or local model.**

<p align="center">
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-22D3EE?style=flat-square&labelColor=0A0A0F" alt="MIT license"></a>
<img src="https://img.shields.io/badge/version-3.2.0-22D3EE?style=flat-square&labelColor=0A0A0F" alt="v3.2.0">
<img src="https://img.shields.io/badge/tests-849%20passing-22C55E?style=flat-square&labelColor=0A0A0F" alt="849 tests passing">
<a href="https://github.com/dirtysouthalpha/sentinel-code/actions/workflows/ci.yml"><img src="https://github.com/dirtysouthalpha/sentinel-code/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<img src="https://img.shields.io/badge/version-3.3.0-22D3EE?style=flat-square&labelColor=0A0A0F" alt="v3.3.0">
<img src="https://img.shields.io/badge/tests-866%20passing-22C55E?style=flat-square&labelColor=0A0A0F" alt="866 tests passing">
<img src="https://img.shields.io/badge/TypeScript-ESM-22D3EE?style=flat-square&labelColor=0A0A0F" alt="TypeScript ESM">
<img src="https://img.shields.io/badge/built%20with-MCP-8B5CF6?style=flat-square&labelColor=0A0A0F" alt="MCP client + server">
</p>
Expand Down Expand Up @@ -53,7 +53,8 @@ Most "AI CLIs" are a thin wrapper around one provider's chat endpoint. **Sentine
## 📑 Table of Contents

- [The four faces](#-the-four-faces)
- [Quick start](#-quick-start)
- [Quickstart](#-quickstart)
- [Tested on](#%EF%B8%8F-tested-on)
- [Providers](#-providers)
- [Features](#-features)
- [Commands](#-commands)
Expand Down Expand Up @@ -84,7 +85,7 @@ Build once; pick how you use it — all share the same engine, tools, and config

---

## 🚀 Quick start
## 🚀 Quickstart

```bash
git clone https://github.com/dirtysouthalpha/sentinel-code.git
Expand Down Expand Up @@ -133,6 +134,20 @@ Full install / update / uninstall details in [`INSTALL.md`](INSTALL.md).

---

## 🖥️ Tested on

Facts only — everything below is taken from what the repo already documents ([`INSTALL.md`](INSTALL.md), [`package.json`](package.json) `engines`, [`.github/workflows/ci.yml`](.github/workflows/ci.yml)).

| Platform | Node.js | How it's exercised |
|----------|---------|--------------------|
| Ubuntu 24.04 (GitHub Actions) | 22 | CI on every push/PR: `npm ci` → `npm run lint` → `npm test` → `npm run build` → GUI `vite build` |
| Windows (PowerShell) | ≥ 20 | `install.bat` / `install.ps1` one-click install; the bash tool runs PowerShell natively |
| macOS / Linux | ≥ 20 | `npm install && npm run build`, then `npm link` for a global `sentinel` |

Minimum supported runtime is **Node.js 20** (`engines.node >= 20.0.0`). The native desktop window additionally needs a Rust toolchain for Tauri v2. Add your machine via PR if you've run it somewhere else.

---

## 🔌 Providers

Everywhere a model is referenced it's `provider/model` (split on the first `/`). The default is `zai/glm-4.6`.
Expand Down Expand Up @@ -295,7 +310,7 @@ See [`CLAUDE.md`](CLAUDE.md) for the full code map and conventions.
```bash
npm run build # tsup -> dist/ (+ copies builtins into dist/builtin)
npm run lint # tsc --noEmit (type-check only — there is no ESLint)
npm test # vitest (347 tests)
npm test # vitest (866 tests)
npm run dev # tsup --watch

# Single test file / single test
Expand Down
90 changes: 90 additions & 0 deletions tests/compression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { describe, it, expect, beforeEach, beforeAll } from "vitest";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

// Point Headroom at an empty config dir so isHeadroomAvailable() is false and
// every call takes the deterministic local fallback path (no network).
process.env.HEADROOM_CONFIG_DIR = join(mkdtempSync(join(tmpdir(), "sentinel-headroom-")), "missing");

import { state } from "../src/core/state.js";
import {
compressToolOutput,
compressMessages,
clearCompressionCache,
getCompressionStats,
} from "../src/ai/compression.js";

describe("compression (local fallback)", () => {
beforeAll(() => {
state.reset();
});

beforeEach(() => {
state.reset();
clearCompressionCache();
});

it("returns input unchanged for an empty message list", async () => {
const result = await compressMessages([]);
expect(result).toEqual([]);
expect(getCompressionStats().originalTokens).toBe(0);
});

it("merges consecutive same-role messages and truncates content", async () => {
const a = "a".repeat(100);
const b = "b".repeat(100);
const c = "c".repeat(100);
const result = await compressMessages([
{ role: "user", content: a },
{ role: "user", content: b },
{ role: "assistant", content: c },
]);

expect(result).toHaveLength(2);
expect(result[0].role).toBe("user");
expect(result[1].role).toBe("assistant");
// first message of a run keeps 70%, subsequent same-role messages keep 60%
expect(result[0].content).toBe("a".repeat(70) + " " + "b".repeat(60));
expect(result[1].content).toBe("c".repeat(70));
});

it("never grows the content and records savings in state", async () => {
const input = [{ role: "system", content: "x".repeat(350) }];
const result = await compressMessages(input);

expect(result[0].content.length).toBeLessThanOrEqual(input[0].content.length);

const stats = getCompressionStats();
expect(stats.originalTokens).toBeGreaterThan(0);
expect(stats.compressedTokens).toBeLessThan(stats.originalTokens);
expect(stats.savingsPercent).toBeGreaterThan(0);
expect(stats.savingsPercent).toBeLessThanOrEqual(100);
expect(stats.lastCompressed).toBeGreaterThan(0);
});

it("compressToolOutput prefixes the tool name and caches by content", async () => {
const output = "line\n".repeat(50);
const first = await compressToolOutput(output, "bash");
expect(first.startsWith("[bash output]")).toBe(true);

const statsAfterFirst = getCompressionStats();

// Same content -> cache hit -> stats must not change.
const second = await compressToolOutput(output, "bash");
expect(second).toBe(first);
expect(getCompressionStats()).toEqual(statsAfterFirst);

// Clearing the cache makes the next call recompute (and re-count).
clearCompressionCache();
await compressToolOutput(output, "bash");
expect(getCompressionStats().originalTokens).toBeGreaterThan(statsAfterFirst.originalTokens);
});

it("accumulates stats across multiple compressions", async () => {
await compressMessages([{ role: "user", content: "y".repeat(70) }]);
const once = getCompressionStats().originalTokens;
await compressMessages([{ role: "user", content: "z".repeat(70) }]);
expect(getCompressionStats().originalTokens).toBe(once * 2);
});
});
65 changes: 65 additions & 0 deletions tests/project-detector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { mkdtempSync, writeFileSync, rmSync, mkdirSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { detectProject, getProjectIcon } from "../src/core/project-detector.js";

let root: string;

beforeEach(() => {
root = mkdtempSync(join(tmpdir(), "sentinel-detect-"));
});

afterEach(() => {
rmSync(root, { recursive: true, force: true });
});

describe("detectProject", () => {
it("returns null when no known project file exists", () => {
expect(detectProject(root)).toBeNull();
});

it("detects a Node project and reads the package name", () => {
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "@scope/my-app" }));
const info = detectProject(root);
expect(info).toMatchObject({ type: "node", name: "@scope/my-app", language: "TypeScript/JavaScript" });
});

it("falls back to the directory name when package.json is unparsable", () => {
const dir = join(root, "fallback-name");
mkdirSync(dir);
writeFileSync(join(dir, "package.json"), "{ not json");
expect(detectProject(dir)?.name).toBe("fallback-name");
});

it("detects Rust, Python and Go projects with their names", () => {
const rust = join(root, "rs");
mkdirSync(rust);
writeFileSync(join(rust, "Cargo.toml"), '[package]\nname = "crabby"\nversion = "0.1.0"\n');
expect(detectProject(rust)).toMatchObject({ type: "rust", name: "crabby", language: "Rust" });

const py = join(root, "py");
mkdirSync(py);
writeFileSync(join(py, "pyproject.toml"), '[project]\nname = "snek"\n');
expect(detectProject(py)).toMatchObject({ type: "python", name: "snek", language: "Python" });

const go = join(root, "go");
mkdirSync(go);
writeFileSync(join(go, "go.mod"), "module example.com/gopher\n\ngo 1.22\n");
expect(detectProject(go)).toMatchObject({ type: "go", name: "example.com/gopher", language: "Go" });
});

it("prefers package.json when several project files are present", () => {
writeFileSync(join(root, "Cargo.toml"), 'name = "crabby"\n');
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "node-wins" }));
expect(detectProject(root)?.type).toBe("node");
});
});

describe("getProjectIcon", () => {
it("returns the folder icon for unknown projects and the project icon otherwise", () => {
expect(getProjectIcon(root)).toBe("\u{1F4C1}");
writeFileSync(join(root, "go.mod"), "module x\n");
expect(getProjectIcon(root)).toBe("\u{1F408}");
});
});
Loading