Skip to content

Commit 6dec3a1

Browse files
committed
Improve docs, onboarding, and repo signals
1 parent 2003938 commit 6dec3a1

9 files changed

Lines changed: 214 additions & 109 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: Install deps
2323
run: npm install
2424

25+
- name: Run workspace tests
26+
run: npm test
27+
2528
- name: Build core
2629
run: npm run -w authority-layer build
2730

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing to AuthorityLayer
2+
3+
AuthorityLayer is a runtime-safety library. Keep changes explicit, testable, and easy to review.
4+
5+
## Local Workflow
6+
7+
1. Install dependencies with `npm install`.
8+
2. Run `npm test`.
9+
3. Build the package with `npm run -w authority-layer build`.
10+
4. Run `npm run -w authority-layer typecheck`.
11+
5. Use `npm run example` to verify the contributor-facing demo still works.
12+
13+
## Repository Layout
14+
15+
- `packages/core/src/`: published library source
16+
- `docs/`: API and enforcement reference
17+
- `examples/`: runnable examples
18+
- `tests/`: workspace smoke tests
19+
- `src/`: top-level source map for contributors
20+
21+
## Change Expectations
22+
23+
- Keep halt behavior deterministic.
24+
- Document new permissions, approval boundaries, or operator requirements.
25+
- Add or update examples when the public API changes.
26+
- Update docs when enforcement semantics change.

README.md

Lines changed: 83 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,135 @@
11
# AuthorityLayer
22

3-
[![CI](https://github.com/032383justin/authority-layer/actions/workflows/ci.yml/badge.svg)](https://github.com/032383justin/authority-layer/actions/workflows/ci.yml)
4-
[![npm version](https://img.shields.io/npm/v/authority-layer?color=blue)](https://www.npmjs.com/package/authority-layer)
5-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6-
[![Node.js >= 18](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
3+
![RepoScore](https://repoforge.dev/badge/repoforge-dev/authority-layer)
74

8-
Hard execution and budget limits for autonomous agents — enforced locally.
5+
AuthorityLayer enforces hard runtime limits for AI agents so budgets, loop counts, and tool-call rates fail closed instead of drifting until after damage is done.
96

10-
✔ No telemetry
11-
✔ Works fully offline
12-
✔ Fail-closed by default
13-
✔ Zero runtime dependencies
7+
## What This Project Does
148

15-
---
9+
AuthorityLayer gives developers a minimal runtime control layer for autonomous or tool-using agents. It wraps an execution loop, tracks spend, limits tool-call volume, and throws a typed halt when an agent crosses a configured boundary. The goal is not observability after the fact. The goal is deterministic enforcement during execution.
1610

17-
## Why AuthorityLayer Exists
11+
The library is aimed at developers building agent runtimes, internal automation, LLM-backed services, and safety-sensitive tools that need explicit operational limits. If a workflow should stop after a dollar budget, after a certain number of tool calls, or after a rate cap is reached, AuthorityLayer provides those controls directly in code.
1812

19-
Autonomous AI agents can fail in expensive, hard-to-detect ways:
13+
## Why It Exists
2014

21-
- **Runaway token spend** — a looping agent burns thousands of dollars before anyone notices
22-
- **Infinite tool loops** — agents retry the same failing call indefinitely
23-
- **Retry storms** — cascading failures hammer external APIs with no ceiling
24-
- **Cascading tool call explosions** — one agent spawns sub-calls that spawn more
15+
Many agent systems fail in ordinary ways long before they fail in exotic ones. A loop retries a tool forever. A model call path consumes more tokens than expected. A badly bounded automation script keeps hitting an external API because nothing in the runtime says stop. Post-run dashboards can describe the incident, but they do not prevent it.
2516

26-
Most tooling detects these problems after they happen — in dashboards, alerts, or post-run analytics.
17+
AuthorityLayer was created to make those boundaries local, explicit, and enforceable. It treats spend caps, loop limits, and rate limits as runtime invariants rather than optional monitoring. That keeps the implementation small, easy to audit, and practical for teams that want guardrails without adopting a full platform.
2718

28-
AuthorityLayer prevents them inside the runtime, before cost or damage accumulates.
19+
## Quickstart
2920

30-
It helps developers:
31-
32-
- prevent runaway LLM costs
33-
- stop infinite agent loops
34-
- limit AI agent tool calls per run and per minute
35-
- enforce runtime safety for autonomous agents
36-
37-
---
38-
39-
## Live Enforcement Demo (10-second example)
40-
41-
![AuthorityLayer enforcement demo](https://raw.githubusercontent.com/032383justin/authority-layer/main/docs/assets/enforcement-demo.svg)
42-
43-
---
44-
45-
## Quick Start
21+
Install the package and run the environment check:
4622

4723
```bash
4824
npm install authority-layer
49-
```
50-
51-
Verify the install:
52-
53-
```bash
5425
npx authority-layer doctor
5526
```
5627

57-
```
58-
AuthorityLayer Doctor authority-layer@0.1.2
59-
60-
✔ Node.js version >= 18 pass
61-
✔ crypto module (sha256) pass
62-
✔ AUTHORITY_LAYER_DISABLE not set pass
63-
✔ core module loads offline pass
64-
✔ AuthorityLayer instantiates pass
65-
66-
All checks passed. AuthorityLayer is ready.
67-
```
68-
69-
## CLI Tools
28+
If the doctor command passes, you can create an `AuthorityLayer` instance and wrap the part of your agent loop that must stay within budget and call limits.
7029

71-
| Command | What it does |
72-
|---------|-------------|
73-
| `npx authority-layer doctor` | Verify your installation passes all environment checks |
74-
| `npx authority-layer simulate` | Run a live enforcement simulation — see a halt in action without writing any code |
30+
## Example
7531

76-
---
77-
78-
## Minimal Integration
32+
Minimal example:
7933

8034
```typescript
8135
import { AuthorityLayer, EnforcementHalt } from "authority-layer";
8236

8337
const authority = new AuthorityLayer({
84-
budget: { dailyUSD: 50 }, // Hard USD spend cap
85-
loopGuard: { maxToolCallsPerRun: 25 }, // Max tool calls per run
86-
toolThrottle: { maxCallsPerMinute: 60 }, // Sliding-window rate cap
38+
budget: { dailyUSD: 25 },
39+
loopGuard: { maxToolCallsPerRun: 12 },
40+
toolThrottle: { maxCallsPerMinute: 30 },
8741
});
8842

8943
try {
9044
await authority.wrap(async () => {
91-
const result = await authority.tool("llm.chat", () =>
92-
callYourModel(prompt)
93-
);
45+
const result = await authority.tool("llm.chat", () => callModel(prompt));
9446
authority.recordSpend(calculateCostUSD(result));
9547
});
96-
} catch (err) {
97-
if (err instanceof EnforcementHalt) {
98-
console.error(err.enforcement);
99-
// { status: "halted", reason: "budget_exceeded", limit: 50, spent: 52.14, event_id: "evt_..." }
48+
} catch (error) {
49+
if (error instanceof EnforcementHalt) {
50+
console.error(error.enforcement);
10051
}
10152
}
10253
```
10354

104-
---
55+
For a runnable project example, use the bundled demo in `examples/` and the workspace script:
10556

106-
## Enforcement Primitives
57+
```bash
58+
npm run example
59+
```
10760

108-
AuthorityLayer V1 provides three composable enforcement primitives. Each is opt-in — omit a config key to disable it.
61+
That flow exercises the same enforcement surface used by the package: `wrap()` defines the run boundary, `tool()` tracks tool usage and rate limits, and `recordSpend()` reports explicit provider cost data.
10962

110-
These primitives enforce boundaries directly inside the execution loop — not in dashboards or external monitoring.
63+
## How It Works
11164

112-
| Primitive | Config key | What it enforces |
113-
|-----------|------------|------------------|
114-
| **Budget cap** | `budget.dailyUSD` | Cumulative USD spend across the process lifetime. Halts when spend exceeds the cap. → [docs](./docs/enforcement.md#1-budget-cap) |
115-
| **Loop guard** | `loopGuard.maxToolCallsPerRun` | Total tool calls per `wrap()` invocation. Counter resets each run. → [docs](./docs/enforcement.md#2-loop-guard) |
116-
| **Tool throttle** | `toolThrottle.maxCallsPerMinute` | Rate of tool calls using a sliding 60-second window — no fixed buckets. → [docs](./docs/enforcement.md#3-tool-throttle) |
65+
AuthorityLayer is organized as a small workspace with the package implementation, runnable examples, and reference docs kept close together.
11766

118-
When a primitive breaches, AuthorityLayer throws a typed `EnforcementHalt` error with a structured `.enforcement` object. Execution never crashes silently.
67+
- `packages/core/src/` contains the runtime implementation, CLI entrypoint, enforcement primitives, integrity helpers, and exported types.
68+
- `examples/` contains runnable examples for quick integration checks and demos.
69+
- `docs/` contains concept notes, API reference, enforcement details, and integrity-chain documentation.
70+
- `tests/` contains workspace-level smoke tests that keep the top-level layout and package metadata honest.
71+
- `src/` documents the workspace source map so contributors can find the package entrypoints quickly.
11972

120-
---
73+
There are exactly three enforcement primitives: a budget cap, a loop guard, and a tool throttle. Each primitive is opt-in. If you omit a config block, that guard is not instantiated. When a configured limit is breached, AuthorityLayer throws `EnforcementHalt` with structured data instead of forcing callers to parse log output.
12174

122-
## How AuthorityLayer Is Different
75+
Operational boundaries are explicit. AuthorityLayer does not claim to sandbox arbitrary code, but it does define clear permission and approval boundaries inside an agent runtime: only wrapped runs are counted, only calls made through `authority.tool()` are throttled, and spend is recorded only when the host reports it. Evaluation should happen before release using repeatable tests and demos so halt behavior is visible under controlled conditions.
12376

124-
Most AI guardrail tools focus on moderation or observability. AuthorityLayer focuses on **runtime enforcement**.
77+
## Use Cases
12578

126-
| Tool type | What it does |
127-
|-----------|-------------|
128-
| Prompt guardrails | Filter or rewrite prompts and outputs |
129-
| Observability platforms | Analyze agent behavior after execution |
130-
| Cost analytics | Track and report token usage |
131-
| **AuthorityLayer** | Enforces hard limits **during** execution — halts immediately when a boundary is crossed |
79+
- Stop an internal agent after a daily spend budget is exhausted.
80+
- Prevent a tool-using workflow from entering an unbounded retry loop.
81+
- Enforce a maximum number of external tool calls per run.
82+
- Rate-limit calls to a provider or internal service from an autonomous workflow.
83+
- Add fail-closed controls to a prototype agent before exposing it to users.
84+
- Demonstrate runtime guardrail behavior in a reproducible example or CI pipeline.
13285

133-
---
86+
## Installation
13487

135-
## Documentation
88+
For package consumers:
13689

137-
| Topic | File |
138-
|------|------|
139-
| Concepts & philosophy | [docs/concepts.md](./docs/concepts.md) |
140-
| Enforcement primitives | [docs/enforcement.md](./docs/enforcement.md) |
141-
| API reference | [docs/api.md](./docs/api.md) |
142-
| Integrity chain | [docs/integrity.md](./docs/integrity.md) |
143-
| Example run | `npm run example` |
90+
```bash
91+
npm install authority-layer
92+
```
14493

145-
---
94+
For contributors working on the repository:
14695

147-
AuthorityLayer is designed as a minimal enforcement primitive — not a platform, dashboard, or governance system.
96+
```bash
97+
git clone https://github.com/repoforge-dev/authority-layer.git
98+
cd authority-layer
99+
npm install
100+
npm test
101+
npm run -w authority-layer build
102+
npm run -w authority-layer typecheck
103+
```
148104

149-
---
105+
The workspace keeps contributor commands small. The root package coordinates examples and tests, while `packages/core` contains the published package source and build scripts.
150106

151-
## License
107+
## Why RepoScore Matters
108+
109+
Many GitHub repositories have thousands of stars but still lack strong documentation, onboarding clarity, or discoverability.
110+
111+
RepoScore automatically analyzes repositories and identifies practical improvements that make projects easier for developers and AI agents to use.
112+
113+
## RepoScore
114+
115+
Badge:
152116

153-
MIT © 2025 AuthorityLayer Contributors
117+
```md
118+
![RepoScore](https://repoforge.dev/badge/repoforge-dev/authority-layer)
119+
```
120+
121+
Analysis page:
122+
123+
- `https://repoforge.dev/repos/repoforge-dev/authority-layer`
124+
125+
The RepoScore page is useful here because AuthorityLayer is a runtime-safety package. A public analysis page makes it easy to inspect documentation quality, discoverability, and onboarding clarity from the perspective of a developer evaluating whether to trust the project in a real workflow.
126+
127+
## Contributing
128+
129+
Contributions should keep the runtime surface explicit and easy to audit. Favor small changes, typed interfaces, and examples that demonstrate enforcement behavior clearly. When you change runtime semantics, update the docs and example flows in the same pull request so contributors can evaluate the impact without reverse-engineering the source.
130+
131+
Start with [CONTRIBUTING.md](./CONTRIBUTING.md). It documents the workspace layout, test commands, and expectations for changes that affect halt behavior, permissions, or approval boundaries.
132+
133+
## License
154134

155-
[GitHub](https://github.com/032383justin/authority-layer) · [npm](https://www.npmjs.com/package/authority-layer) · [Issues](https://github.com/032383justin/authority-layer/issues)
135+
MIT. See [LICENSE](./LICENSE).

SECURITY.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Security Notes
2+
3+
AuthorityLayer is a local runtime-enforcement library. It helps callers define and enforce operational boundaries for AI agents, but it does not replace broader application security review.
4+
5+
## Scope
6+
7+
- AuthorityLayer enforces configured budget, loop, and tool-throttle limits.
8+
- AuthorityLayer does not sandbox arbitrary code execution.
9+
- AuthorityLayer depends on the host application to decide what tools are exposed and when approvals are required.
10+
11+
## Evaluation Guidance
12+
13+
Before release, verify halt behavior with repeatable tests or example runs that cover:
14+
15+
- budget exhaustion
16+
- loop-limit enforcement
17+
- tool-throttle enforcement
18+
- error handling around `EnforcementHalt`
19+
20+
## Reporting Issues
21+
22+
If you discover a security issue in the library, report it privately to the maintainers before opening a public issue.

docs/architecture.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# AuthorityLayer Architecture
2+
3+
AuthorityLayer is organized as a small npm workspace around a single published core package.
4+
5+
## Layout
6+
7+
- `packages/core/src/`: core runtime, CLI, enforcement primitives, integrity helpers, and types
8+
- `examples/`: runnable examples and minimal integration flows
9+
- `docs/`: concepts, enforcement, API, integrity, and contributor notes
10+
- `tests/`: workspace smoke tests
11+
- `src/`: contributor-facing source map for the top-level workspace
12+
13+
## Runtime Model
14+
15+
The package exposes three main integration points:
16+
17+
- `AuthorityLayer`: runtime controller configured with enforcement primitives
18+
- `authority.wrap(fn)`: run boundary that resets per-run state
19+
- `authority.tool(name, fn)`: tool-call boundary used by loop guard and rate limiting
20+
- `authority.recordSpend(usd)`: explicit cost-reporting hook for budget enforcement
21+
22+
The design keeps limits explicit and local. Callers decide what tools are available, when human approval is required, and how spend is calculated.

package.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
{
22
"name": "authority-layer-repo",
33
"private": true,
4+
"description": "Repository workspace for AuthorityLayer, a runtime guardrail package for AI agents.",
45
"workspaces": [
56
"packages/core"
67
],
78
"scripts": {
8-
"example": "npm run -w authority-layer build && node examples/run.js"
9+
"example": "npm run -w authority-layer build && node examples/run.js",
10+
"test": "node tests/workspace-smoke.test.js"
11+
},
12+
"keywords": [
13+
"ai-guardrails",
14+
"ai-agents",
15+
"agent-runtime",
16+
"ai-safety",
17+
"llm-security",
18+
"autonomous-agents"
19+
],
20+
"homepage": "https://github.com/repoforge-dev/authority-layer",
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/repoforge-dev/authority-layer.git"
24+
},
25+
"bugs": {
26+
"url": "https://github.com/repoforge-dev/authority-layer/issues"
927
}
10-
}
28+
}

packages/core/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
"prepublishOnly": "node -e \"require('fs').copyFileSync('../../README.md','README.md')\" && npm run build && npm run typecheck"
2222
},
2323
"keywords": [
24+
"ai-guardrails",
2425
"ai-agents",
2526
"agent-runtime",
27+
"ai-safety",
28+
"llm-security",
2629
"runtime-guardrails",
2730
"llm-guardrails",
2831
"token-cost-control",
@@ -37,11 +40,11 @@
3740
],
3841
"repository": {
3942
"type": "git",
40-
"url": "git+https://github.com/032383justin/authority-layer.git"
43+
"url": "git+https://github.com/repoforge-dev/authority-layer.git"
4144
},
42-
"homepage": "https://github.com/032383justin/authority-layer",
45+
"homepage": "https://github.com/repoforge-dev/authority-layer",
4346
"bugs": {
44-
"url": "https://github.com/032383justin/authority-layer/issues"
47+
"url": "https://github.com/repoforge-dev/authority-layer/issues"
4548
},
4649
"license": "MIT",
4750
"engines": {
@@ -51,4 +54,4 @@
5154
"typescript": "^5.4.0",
5255
"@types/node": "^20.0.0"
5356
}
54-
}
57+
}

0 commit comments

Comments
 (0)