Repository navigation
Polish: README, test suite, pinned CI #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a push or PR changes only a built-in file such as
src/commands/builtin/ship.md,**.mdmatches nested Markdown files too, so the workflow skips CI. These files define runtime commands and are copied intodistby 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**.mdmatches Markdown files throughout the repository.Useful? React with 👍 / 👎.