kata-context 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,409 @@
1
+ # Research Summary: Kata Context v0.1.0 Core Setup
2
+
3
+ **Project:** Kata Context - Standalone context policy engine for AI agents
4
+ **Milestone:** v0.1.0 Core Setup
5
+ **Synthesized:** 2026-01-29
6
+ **Overall Confidence:** HIGH
7
+
8
+ ---
9
+
10
+ ## Executive Summary
11
+
12
+ Kata Context is a REST API-first context policy engine that will be deployed on Vercel's serverless platform with TypeScript and Python SDKs. Based on comprehensive research across stack choices, feature requirements, architecture patterns, and common pitfalls, the recommended approach is:
13
+
14
+ **Use modern, fast, TypeScript-native tooling**: Node.js 24.x (Vercel's current LTS), pnpm 10.x for packages, Biome for linting/formatting (20-35x faster than ESLint+Prettier), and Vitest for testing (10-20x faster than Jest). These tools are production-ready, well-documented, and designed for the serverless environment.
15
+
16
+ **Adopt a monorepo structure with pure Vercel Functions**: Use Turborepo + pnpm workspaces to co-locate the API, TypeScript SDK, and Python SDK. Deploy the API using Vercel's `/api` directory pattern (not Next.js) to avoid unnecessary React/frontend overhead. Organize code feature-first (`domain/policy/`, `domain/context/`) rather than layer-first to keep related code together and support future extraction.
17
+
18
+ **The biggest risks are configuration missteps in Phase 1**: The critical pitfalls all occur during initial setup: wrong module resolution settings (causes deployment failures), path aliases not resolved in production, ESM/CJS format mismatches, and environment variable confusion. These are preventable with correct TypeScript and Vercel configuration from day one, strict mode enabled immediately, and local testing with `vercel build` before first deployment. The research provides specific configuration templates to avoid these issues.
19
+
20
+ ---
21
+
22
+ ## Key Findings
23
+
24
+ ### From STACK.md: Modern TypeScript Serverless Tooling
25
+
26
+ **Core Stack:**
27
+ - **Node.js 24.x** - Current Vercel default LTS (active through April 2028), native TypeScript type stripping
28
+ - **pnpm 10.x** - 70% disk savings vs npm, strict dependency isolation, Vercel auto-detects via lockfile
29
+ - **Biome 2.3.x** - Single tool for linting + formatting, 20-35x faster than ESLint+Prettier, 97% Prettier compatible
30
+ - **Vitest 4.x** - 10-20x faster than Jest, native ESM/TypeScript, Jest-compatible API
31
+ - **tsx 4.x** - Development TypeScript execution, 20-30x faster than ts-node
32
+
33
+ **TypeScript Configuration:**
34
+ - Target: ES2024 (Node.js 24 supports fully)
35
+ - Module: NodeNext (Node.js ESM with package.json type field support)
36
+ - Enable `strict: true`, `verbatimModuleSyntax: true`, `isolatedModules: true`
37
+ - Use `noEmit: true` - Vercel handles compilation
38
+
39
+ **What NOT to include:**
40
+ - Jest, ESLint+Prettier (slower alternatives)
41
+ - Webpack/Rollup/esbuild (Vercel handles bundling)
42
+ - Babel, nodemon, husky+lint-staged (unnecessary for v0.1.0)
43
+
44
+ **Confidence:** HIGH - Based on official Vercel documentation and verified benchmarks
45
+
46
+ ### From FEATURES.md: Essential vs Deferred Features
47
+
48
+ **Table Stakes (Must Include):**
49
+ - TypeScript configuration (tsconfig.json) with strict mode
50
+ - Biome configuration (biome.json) for linting + formatting
51
+ - .gitignore with Node + Vercel-specific entries
52
+ - package.json scripts: dev, build, test, lint
53
+ - /api directory structure for Vercel Functions
54
+ - Environment variable handling (.env.example)
55
+ - Node.js version specification (.nvmrc or engines)
56
+ - README with setup instructions
57
+
58
+ **Differentiators (Recommended):**
59
+ - Vitest test configuration (modern, fast testing)
60
+ - Strict TypeScript settings (noUncheckedIndexedAccess, noImplicitReturns)
61
+ - vercel.json configuration (explicit function limits)
62
+ - GitHub Actions CI workflow (lint + test only, not full CD)
63
+ - EditorConfig and VS Code workspace settings
64
+
65
+ **Anti-Features (Explicitly Avoid):**
66
+ - Full GitHub Actions CD pipeline (use Vercel's Git integration)
67
+ - Database configuration (defer to storage layer milestone)
68
+ - API routes with business logic (single health check only)
69
+ - Authentication/authorization (defer to security milestone)
70
+ - Logging infrastructure, error monitoring (add during production hardening)
71
+ - Complex folder structure (minimal: /api, /src, /tests)
72
+ - Monorepo setup (single package until proven need for SDK phase)
73
+ - Custom build tooling (trust Vercel's build system)
74
+ - API versioning, rate limiting (add when API stabilizes)
75
+
76
+ **Confidence:** HIGH - Based on Vercel's zero-config philosophy and verified best practices
77
+
78
+ ### From ARCHITECTURE.md: Monorepo with Pure Serverless
79
+
80
+ **Critical Architectural Decisions:**
81
+
82
+ 1. **Monorepo (not Polyrepo)**: Use Turborepo + pnpm workspaces
83
+ - Enables coordinated releases between API and SDKs
84
+ - Shared TypeScript types between API and TypeScript SDK
85
+ - AI tooling benefits from full context visibility
86
+ - Accepted trade-off: Python SDK needs its own tooling within monorepo
87
+
88
+ 2. **Pure Vercel Functions (not Next.js)**: Use `/api` directory pattern
89
+ - Kata Context is a REST API, not a web application
90
+ - No need for React, SSR, or frontend routing
91
+ - Zero-configuration deployment, lower complexity, smaller bundles
92
+
93
+ **Directory Structure (Simplified for v0.1.0):**
94
+ ```
95
+ kata-context/
96
+ ├── .planning/ # Kata planning artifacts
97
+ ├── api/ # Vercel Functions
98
+ │ └── health.ts # GET /api/health
99
+ ├── src/ # Shared code (placeholder for v0.1.0)
100
+ ├── tests/ # Tests
101
+ │ └── health.test.ts # Smoke test
102
+ ├── package.json
103
+ ├── tsconfig.json
104
+ ├── biome.json
105
+ └── vercel.json
106
+ ```
107
+
108
+ **Note:** Full monorepo structure with `apps/api/`, `packages/typescript-sdk/`, `packages/python-sdk/` deferred to SDK phase. Start simple for v0.1.0.
109
+
110
+ **Patterns to Follow:**
111
+ - **Vercel Function Handler**: Standard typed request/response pattern
112
+ - **Feature-First Organization**: When adding domain code, organize by business domain (`domain/policy/`, `domain/context/`) not by layer
113
+ - **Shared Types**: Single source of truth for TypeScript types (implement when SDK phase begins)
114
+
115
+ **Anti-Patterns to Avoid:**
116
+ - Fat route handlers (keep business logic in services)
117
+ - Layer-first organization (controllers/, services/, models/)
118
+ - Next.js for pure APIs
119
+ - Polyrepo for tightly coupled components
120
+
121
+ **Confidence:** HIGH for Vercel patterns, MEDIUM for full monorepo structure (implement incrementally)
122
+
123
+ ### From PITFALLS.md: Configuration Mistakes to Avoid
124
+
125
+ **Critical Pitfalls (Phase 1 - Cause Rewrites):**
126
+
127
+ 1. **Path Aliases Not Resolved in Compiled Output**
128
+ - TypeScript paths are type-checking only; `tsc` doesn't rewrite imports
129
+ - Prevention: Either configure bundler to match tsconfig OR avoid path aliases entirely
130
+ - For Vercel serverless: Consider avoiding aliases since functions may bundle differently
131
+
132
+ 2. **Wrong Module Resolution Strategy**
133
+ - `moduleResolution: "bundler"` vs `moduleResolution: "node16"` are incompatible
134
+ - Prevention: For Vercel Functions with bundling use `moduleResolution: "bundler"` + `module: "ESNext"`
135
+ - Must match module and moduleResolution values
136
+
137
+ 3. **Environment Variables Baked at Build Time vs Runtime**
138
+ - Next.js replaces `process.env.VARIABLE` at build time for client code
139
+ - Prevention: Use Vercel's environment variable scoping per environment
140
+ - For Kata Context: Pure API means all env vars are runtime (simpler)
141
+
142
+ 4. **ESM/CJS Module Format Mismatch**
143
+ - `"type": "module"` in package.json makes all .js files ESM
144
+ - Prevention: Pick ESM for new projects, add `"type": "module"`, set `module: "ESNext"` in tsconfig
145
+
146
+ **Moderate Pitfalls (Phase 1 - Cause Delays):**
147
+
148
+ 5. **Biome/Prettier Configuration** (Less applicable with Biome-only approach)
149
+ - Prevention: Use Biome exclusively to eliminate conflicts
150
+
151
+ 6. **Testing Setup Not Matching Runtime**
152
+ - Prevention: Pin Node.js version with .nvmrc, enable strict async TypeScript rules
153
+
154
+ 7. **Choosing Edge Functions When Serverless Required**
155
+ - Prevention: Default to Serverless Functions (use Edge only for auth checks, redirects)
156
+
157
+ 8. **Large Bundle Sizes Causing Cold Starts**
158
+ - Prevention: Choose lightweight dependencies from start, analyze bundles before adding dependencies
159
+
160
+ 9. **Not Enabling TypeScript Strict Mode**
161
+ - Prevention: Enable `strict: true` on day one, add `noUncheckedIndexedAccess: true`
162
+
163
+ **Minor Pitfalls (Quick Fixes):**
164
+
165
+ 10. **Utility Files in /api Directory**: Prefix with underscore or place outside /api
166
+ 11. **vercel.json Overrides Build Settings**: Pick one source of truth
167
+ 12. **Forgetting to Pin Dependency Versions**: Use lockfile and commit it
168
+
169
+ **Confidence:** HIGH - Based on official documentation and verified community issues
170
+
171
+ ---
172
+
173
+ ## Implications for Roadmap
174
+
175
+ ### Suggested Phase Structure
176
+
177
+ Based on combined research, v0.1.0 Core Setup should be broken into focused phases:
178
+
179
+ #### Phase 1: Project Initialization (Foundation)
180
+ **Rationale:** Get configuration right before writing any code. All critical pitfalls occur here.
181
+
182
+ **Delivers:**
183
+ - Project structure (single package, not monorepo yet)
184
+ - TypeScript configuration with strict mode
185
+ - pnpm workspace initialization
186
+ - Node.js version pinning
187
+
188
+ **Features from FEATURES.md:**
189
+ - tsconfig.json (strict: true, moduleResolution: bundler, module: ESNext)
190
+ - package.json with engines field
191
+ - .nvmrc file
192
+ - .gitignore
193
+
194
+ **Pitfalls to avoid:**
195
+ - Wrong module resolution (Pitfall 2)
196
+ - ESM/CJS mismatch (Pitfall 4)
197
+ - Not enabling strict mode (Pitfall 9)
198
+
199
+ **Research needed:** None - well-documented patterns
200
+
201
+ ---
202
+
203
+ #### Phase 2: Developer Tooling
204
+ **Rationale:** Set up quality and testing tools while codebase is small and easy to configure.
205
+
206
+ **Delivers:**
207
+ - Linting and formatting with Biome
208
+ - Testing framework with Vitest
209
+ - Basic CI workflow
210
+
211
+ **Features from FEATURES.md:**
212
+ - biome.json configuration
213
+ - vitest.config.ts
214
+ - package.json scripts (dev, build, test, lint)
215
+ - .github/workflows/ci.yml (lint + test only)
216
+ - .vscode/settings.json (optional but recommended)
217
+
218
+ **Pitfalls to avoid:**
219
+ - Biome misconfiguration (minimal risk, single tool)
220
+ - Testing environment mismatch (Pitfall 6)
221
+
222
+ **Research needed:** None - straightforward setup
223
+
224
+ ---
225
+
226
+ #### Phase 3: Vercel Functions Setup
227
+ **Rationale:** Deploy simplest possible serverless function to verify configuration works end-to-end.
228
+
229
+ **Delivers:**
230
+ - /api directory structure
231
+ - Health check endpoint
232
+ - Vercel configuration
233
+ - Local development workflow
234
+ - First deployment
235
+
236
+ **Features from FEATURES.md:**
237
+ - /api/health.ts (GET /api/health returns {status: "ok"})
238
+ - vercel.json configuration
239
+ - .env.example
240
+ - tests/health.test.ts (smoke test)
241
+ - README with setup instructions
242
+
243
+ **Pitfalls to avoid:**
244
+ - Path aliases not resolved (Pitfall 1)
245
+ - Utility files becoming functions (Pitfall 10)
246
+ - vercel.json overrides (Pitfall 11)
247
+ - Not testing `vercel build` locally (Pitfall 3)
248
+
249
+ **Research needed:** None - pure Vercel Functions pattern is well-documented
250
+
251
+ ---
252
+
253
+ ### Architecture Evolution
254
+
255
+ **v0.1.0 (Current Milestone):** Single package, minimal structure
256
+ - Simple `/api`, `/src`, `/tests` directories
257
+ - No monorepo complexity
258
+ - Focus on getting configuration right
259
+
260
+ **v0.2.0 (Storage Layer):** Add database integration
261
+ - Still single package
262
+ - Add database client configuration
263
+ - Watch out for cold start timeouts (Pitfall 8)
264
+
265
+ **v0.3.0 (SDK Phase):** Migrate to monorepo
266
+ - Introduce Turborepo + pnpm workspaces
267
+ - Refactor to `apps/api/`, `packages/typescript-sdk/`, `packages/python-sdk/`
268
+ - Implement shared types package
269
+
270
+ **v1.0.0 (Production):** Harden and optimize
271
+ - Add logging infrastructure
272
+ - Add error monitoring
273
+ - Implement rate limiting
274
+ - Multi-region deployment considerations
275
+
276
+ ---
277
+
278
+ ## Research Flags
279
+
280
+ ### Phases Needing Deeper Research
281
+
282
+ **Phase 2.5 (Database Integration - future milestone):**
283
+ - Needs `/kata:research-phase` for database choice and connection pooling patterns
284
+ - Serverless-specific database considerations
285
+ - Cold start mitigation strategies
286
+
287
+ **Phase 3.5 (SDK Architecture - future milestone):**
288
+ - Needs `/kata:research-phase` for Python SDK packaging and distribution
289
+ - Type generation from API schema
290
+ - Multi-language error handling patterns
291
+
292
+ ### Phases with Standard Patterns (Skip Research)
293
+
294
+ **Phase 1-3 (v0.1.0):** Well-documented, no additional research needed
295
+ - TypeScript + Vercel serverless patterns are mature
296
+ - Biome and Vitest have straightforward setup
297
+ - Pure API deployment is Vercel's core use case
298
+
299
+ ---
300
+
301
+ ## Confidence Assessment
302
+
303
+ | Area | Confidence | Notes |
304
+ | ------------ | ---------- | ----------------------------------------------------------------------------------------- |
305
+ | Stack | HIGH | Official Vercel docs, verified benchmarks, current LTS versions identified |
306
+ | Features | HIGH | Clear table stakes vs differentiators, anti-features well-justified from Vercel patterns |
307
+ | Architecture | HIGH | Pure Vercel Functions pattern is officially documented; monorepo deferred to later phase |
308
+ | Pitfalls | HIGH | Based on official docs, community issues, and verified incidents; specific to TypeScript + Vercel |
309
+
310
+ ### Gaps to Address
311
+
312
+ **Identified gaps that need attention during planning:**
313
+
314
+ 1. **Database selection deferred**: Not researched yet, intentionally deferred to v0.2.0 Storage milestone
315
+ - Will need research on serverless-optimized databases (Neon, Turso, etc.)
316
+ - Connection pooling and cold start strategies
317
+
318
+ 2. **Python SDK tooling**: Mentioned but not deeply researched
319
+ - Defer to SDK phase when implementing packages/python-sdk/
320
+ - Will need research on Poetry vs pip, PyPI publishing, type stubs
321
+
322
+ 3. **Production hardening details**: Logging, monitoring, rate limiting mentioned as anti-features for v0.1.0
323
+ - Correctly deferred, but will need research when implementing
324
+ - Consider Vercel Observability, Sentry integration, Upstash rate limiting
325
+
326
+ 4. **Monorepo migration path**: Architecture research focused on final state
327
+ - Need to document migration steps from single package to monorepo
328
+ - When to introduce Turborepo (likely during SDK phase)
329
+
330
+ **These gaps are acceptable for v0.1.0** because they're explicitly deferred to later milestones.
331
+
332
+ ---
333
+
334
+ ## Ready for Requirements
335
+
336
+ ### What We Know with Confidence
337
+
338
+ 1. **Stack is locked in**: Node.js 24.x, pnpm 10.x, Biome 2.3.x, Vitest 4.x, tsx 4.x, TypeScript 5.9.x
339
+ 2. **Architecture is clear**: Start simple (single package), pure Vercel Functions, feature-first organization
340
+ 3. **Critical risks identified**: All Phase 1 configuration pitfalls documented with prevention strategies
341
+ 4. **Feature scope is bounded**: Table stakes defined, anti-features identified, defer database/auth/monitoring
342
+
343
+ ### Specific Recommendations for Roadmapper
344
+
345
+ **Phase 1 duration estimate:** 1-2 hours (mostly configuration files)
346
+ - High confidence because patterns are well-documented
347
+ - No complex decisions, just following Vercel best practices
348
+
349
+ **Phase 2 duration estimate:** 2-3 hours (Biome + Vitest + CI)
350
+ - Straightforward tool setup
351
+ - CI workflow is minimal (lint + test)
352
+
353
+ **Phase 3 duration estimate:** 2-3 hours (health check + deployment)
354
+ - Simple endpoint implementation
355
+ - First Vercel deployment verification
356
+ - Documentation of setup process
357
+
358
+ **Total v0.1.0 estimate:** 5-8 hours of focused work
359
+
360
+ **Risk factors:**
361
+ - LOW: Configuration is well-specified
362
+ - MEDIUM: First Vercel deployment might reveal environment-specific issues
363
+ - Mitigation: Test `vercel build` locally before deploying
364
+
365
+ **Validation checkpoints:**
366
+ - Phase 1: `pnpm install` and `tsc --noEmit` pass
367
+ - Phase 2: `pnpm test` and `pnpm lint` pass in CI
368
+ - Phase 3: Health check returns 200 OK in production deployment
369
+
370
+ ---
371
+
372
+ ## Sources
373
+
374
+ ### STACK.md Sources
375
+ - [pnpm vs npm vs yarn vs Bun: The 2026 Package Manager Showdown](https://dev.to/pockit_tools/pnpm-vs-npm-vs-yarn-vs-bun-the-2026-package-manager-showdown-51dc)
376
+ - [Biome Official Site](https://biomejs.dev/) (v2.3.13)
377
+ - [Biome: Complete Migration Guide for 2026](https://dev.to/pockit_tools/biome-the-eslint-and-prettier-killer-complete-migration-guide-for-2026-27m)
378
+ - [Vitest Official Site](https://vitest.dev/) (v4.0.18)
379
+ - [Vitest vs Jest 30: 2026 Browser-Native Testing](https://dev.to/dataformathub/vitest-vs-jest-30-why-2026-is-the-year-of-browser-native-testing-2fgb)
380
+ - [TypeScript 5.9 Documentation](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-9.html)
381
+ - [Vercel Functions Documentation](https://vercel.com/docs/functions)
382
+ - [Vercel Node.js Runtime](https://vercel.com/docs/functions/runtimes/node-js)
383
+
384
+ ### FEATURES.md Sources
385
+ - [Vercel Functions Documentation](https://vercel.com/docs/functions)
386
+ - [Vercel Project Configuration](https://vercel.com/docs/project-configuration)
387
+ - [TypeScript TSConfig Reference](https://www.typescriptlang.org/tsconfig/)
388
+ - [Vitest Configuration Guide](https://vitest.dev/config/)
389
+ - [ESLint + Prettier Configuration (2026)](https://medium.com/@osmion/prettier-eslint-configuration-that-actually-works-without-the-headaches-a8506b710d21)
390
+
391
+ ### ARCHITECTURE.md Sources
392
+ - [Vercel Functions](https://vercel.com/docs/functions)
393
+ - [Vercel vercel.ts Configuration](https://vercel.com/docs/project-configuration/vercel-ts)
394
+ - [Turborepo Repository Structure](https://turborepo.dev/docs/crafting-your-repository/structuring-a-repository)
395
+ - [Hosting Backend APIs on Vercel](https://vercel.com/kb/guide/hosting-backend-apis)
396
+ - [Monorepo Tools Comparison](https://monorepo.tools/)
397
+
398
+ ### PITFALLS.md Sources
399
+ - [Vercel Environment Variables](https://vercel.com/docs/projects/environment-variables)
400
+ - [TypeScript moduleResolution docs](https://www.typescriptlang.org/tsconfig/moduleResolution.html)
401
+ - [Next.js Discussion #41189](https://github.com/vercel/next.js/discussions/41189)
402
+ - [Vercel Community: TypeScript serverless functions](https://community.vercel.com/t/deploying-typescript-serverless-functions/4029)
403
+ - [eslint-config-prettier GitHub](https://github.com/prettier/eslint-config-prettier)
404
+ - [Vercel Cold Start Performance guide](https://vercel.com/kb/guide/how-can-i-improve-serverless-function-lambda-cold-start-performance-on-vercel)
405
+ - [Why strict: true isn't enough](https://itnext.io/why-typescripts-strict-true-isn-t-enough-missing-compiler-flags-for-production-code-a3877b81142c)
406
+
407
+ ---
408
+
409
+ **Synthesis Complete:** All research files synthesized. Ready for roadmap creation.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Kata Context
2
+
3
+ > **Status: Pre-alpha** — Building in public. Not ready for use.
4
+
5
+ ## What This Is
6
+
7
+ Kata Context is a standalone context policy engine for AI agents. It manages what goes in and out of the LLM context window — handling compaction, summarization, retrieval, and budget-aware windowing. Framework-agnostic: works with any agent system, or none.
8
+
9
+ Part of the Kata ecosystem, alongside [Kata Orchestrator](https://github.com/gannonh/kata) and [Kata TUI](https://github.com/gannonh/kata-tui).
10
+
11
+ ## Core Value
12
+
13
+ **Policy, not storage.** Given messages and a context budget, determine the optimal window to send to the model. The value isn't persisting conversations — it's intelligently managing finite context.
14
+
15
+ ## The Key Insight
16
+
17
+ Kata Context answers ONE question: **"Given this conversation history and this token budget, what's the optimal context window to send?"**
18
+
19
+ It doesn't care about:
20
+ - Which LLM you're using
21
+ - How your agent is structured
22
+ - What tools you have
23
+ - How you handle responses
24
+
25
+ ```
26
+ ┌─────────────────────────────────────┐
27
+ │ Your Agent Code │
28
+ │ (LangChain, custom, Kata, etc.) │
29
+ └─────────────────┬───────────────────┘
30
+ │ "What should I send?"
31
+
32
+ ┌─────────────────────────────────────┐
33
+ │ Kata Context │
34
+ │ - Stores full history │
35
+ │ - Applies policy │
36
+ │ - Returns optimal window │
37
+ └─────────────────┬───────────────────┘
38
+ │ Optimized context
39
+
40
+ ┌─────────────────────────────────────┐
41
+ │ Any LLM │
42
+ │ (OpenAI, Anthropic, local, etc.) │
43
+ └─────────────────────────────────────┘
44
+ ```
45
+
46
+ ## Infrastructure, Not Framework
47
+
48
+ | Aspect | Framework (Letta, LangChain) | Infrastructure (Kata Context) |
49
+ | ---------------- | ---------------------------- | ----------------------------- |
50
+ | **Relationship** | You build *inside* it | You *call* it from outside |
51
+ | **Control** | Framework controls lifecycle | You control lifecycle |
52
+ | **Opinions** | Dictates agent patterns | No opinion on agent design |
53
+ | **Coupling** | Tight — hard to leave | Loose — easy to swap |
54
+ | **Analogy** | Rails | Postgres |
55
+
56
+ ## Usage
57
+
58
+ ```python
59
+ from kata_context import Context
60
+
61
+ # Use with any agent framework, or none
62
+ ctx = Context(context_id="my-agent-session")
63
+
64
+ # Store whatever you want
65
+ ctx.append([
66
+ {"role": "user", "content": "Hello"},
67
+ {"role": "assistant", "content": "Hi there!"},
68
+ ])
69
+
70
+ # Get optimal window for your model's budget
71
+ window = ctx.get_window(token_budget=8000, policy="balanced")
72
+
73
+ # Send to ANY LLM — we don't care which
74
+ response = openai.chat.completions.create(
75
+ model="gpt-4",
76
+ messages=window,
77
+ )
78
+ ```
79
+
80
+ ## License
81
+
82
+ Apache 2.0 (core engine and SDKs)
package/biome.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true,
7
+ "defaultBranch": "main"
8
+ },
9
+ "files": {
10
+ "ignoreUnknown": true,
11
+ "includes": ["**", "!.claude"]
12
+ },
13
+ "formatter": {
14
+ "enabled": true,
15
+ "indentStyle": "space",
16
+ "indentWidth": 2,
17
+ "lineWidth": 100,
18
+ "lineEnding": "lf"
19
+ },
20
+ "linter": {
21
+ "enabled": true,
22
+ "rules": {
23
+ "recommended": true
24
+ }
25
+ },
26
+ "assist": {
27
+ "actions": {
28
+ "source": {
29
+ "organizeImports": {
30
+ "level": "on"
31
+ }
32
+ }
33
+ }
34
+ },
35
+ "javascript": {
36
+ "formatter": {
37
+ "quoteStyle": "double",
38
+ "semicolons": "always",
39
+ "trailingCommas": "all"
40
+ }
41
+ }
42
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "kata-context",
3
+ "version": "0.1.0",
4
+ "description": "A standalone context policy engine for AI agents",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=24.0.0"
8
+ },
9
+ "scripts": {
10
+ "dev": "tsc --watch",
11
+ "build": "tsc",
12
+ "test": "vitest run",
13
+ "test:watch": "vitest",
14
+ "lint": "biome lint .",
15
+ "format": "biome format --write .",
16
+ "check": "biome check --write ."
17
+ },
18
+ "keywords": [],
19
+ "author": "",
20
+ "license": "Apache-2.0",
21
+ "packageManager": "pnpm@10.15.0",
22
+ "devDependencies": {
23
+ "@biomejs/biome": "2.3.11",
24
+ "@types/node": "24.0.0",
25
+ "typescript": "5.9.3",
26
+ "vitest": "4.0.17"
27
+ }
28
+ }
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+ #
3
+ # rescue-main.sh
4
+ #
5
+ # Rescues commits stuck on a protected main branch by moving them
6
+ # to a new branch and creating a PR.
7
+ #
8
+ # Usage: ./scripts/rescue-main.sh "PR Title" "PR Body"
9
+ #
10
+
11
+ set -e
12
+
13
+ # Check arguments
14
+ if [ -z "$1" ]; then
15
+ echo "Usage: $0 \"PR Title\" [\"PR Body\"]"
16
+ echo ""
17
+ echo "Example: $0 \"Add authentication\" \"Implements JWT-based auth\""
18
+ exit 1
19
+ fi
20
+
21
+ TITLE="$1"
22
+ BODY="${2:-$TITLE}"
23
+
24
+ # Generate branch name from title (lowercase, replace spaces with hyphens)
25
+ BRANCH=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
26
+
27
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
28
+ echo " Rescuing commits from protected main"
29
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
30
+ echo ""
31
+ echo "Branch: $BRANCH"
32
+ echo "Title: $TITLE"
33
+ echo "Body: $BODY"
34
+ echo ""
35
+
36
+ # Check if we're on main
37
+ CURRENT_BRANCH=$(git branch --show-current)
38
+ if [ "$CURRENT_BRANCH" != "main" ]; then
39
+ echo "Error: Not on main branch (currently on '$CURRENT_BRANCH')"
40
+ exit 1
41
+ fi
42
+
43
+ # Check if there are commits ahead of origin/main
44
+ git fetch origin
45
+ AHEAD=$(git rev-list origin/main..HEAD --count)
46
+ if [ "$AHEAD" -eq 0 ]; then
47
+ echo "Error: No local commits ahead of origin/main"
48
+ exit 1
49
+ fi
50
+
51
+ echo "Found $AHEAD commit(s) to rescue"
52
+ echo ""
53
+
54
+ # Create and switch to new branch
55
+ echo "→ Creating branch '$BRANCH'..."
56
+ git checkout -b "$BRANCH"
57
+
58
+ # Push the branch
59
+ echo "→ Pushing branch to origin..."
60
+ git push -u origin "$BRANCH"
61
+
62
+ # Create PR
63
+ echo "→ Creating pull request..."
64
+ PR_URL=$(gh pr create --title "$TITLE" --body "$BODY" --head "$BRANCH" --base main)
65
+
66
+ # Switch back to main and reset
67
+ echo "→ Resetting local main to origin/main..."
68
+ git checkout main
69
+ git reset --hard origin/main
70
+
71
+ echo ""
72
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
73
+ echo " Done!"
74
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
75
+ echo ""
76
+ echo "PR created: $PR_URL"
77
+ echo ""
78
+ echo "Your local main is now in sync with origin/main."
79
+ echo "Merge the PR on GitHub to complete."
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Kata Context - Context policy engine for AI agents
3
+ * @packageDocumentation
4
+ */
5
+
6
+ export const VERSION = "0.1.0";
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2023",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "sourceMap": true,
14
+ "noUncheckedIndexedAccess": true,
15
+ "isolatedModules": true,
16
+ "verbatimModuleSyntax": true
17
+ },
18
+ "include": ["src"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: "node",
7
+ include: ["src/**/*.test.ts"],
8
+ passWithNoTests: true,
9
+ coverage: {
10
+ provider: "v8",
11
+ reporter: ["text", "json", "html"],
12
+ },
13
+ },
14
+ });