@getmikk/ai-context 1.2.0 → 1.3.1

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.
@@ -1,137 +1,137 @@
1
- import { describe, test, expect } from 'bun:test'
2
- import { ClaudeMdGenerator } from '../src/claude-md-generator'
3
- import type { MikkContract, MikkLock } from '@getmikk/core'
4
-
5
- const mockContract: MikkContract = {
6
- version: '1.0.0',
7
- project: {
8
- name: 'TestProject',
9
- description: 'A test project for validating claude.md generation',
10
- language: 'TypeScript',
11
- entryPoints: ['src/index.ts'],
12
- },
13
- declared: {
14
- modules: [
15
- { id: 'auth', name: 'Authentication', description: 'Handles user authentication', intent: 'JWT-based auth flow', paths: ['src/auth/**'] },
16
- { id: 'api', name: 'API', description: 'REST API layer', paths: ['src/api/**'] },
17
- ],
18
- constraints: [
19
- 'No direct DB access outside db/',
20
- 'All auth must go through auth.middleware',
21
- ],
22
- decisions: [
23
- { id: 'd1', title: 'Use JWT', reason: 'Stateless auth for scalability', date: '2024-01-01' },
24
- ],
25
- },
26
- overwrite: { mode: 'never', requireConfirmation: true },
27
- }
28
-
29
- const mockLock: MikkLock = {
30
- version: '1.0.0',
31
- generatedAt: new Date().toISOString(),
32
- generatorVersion: '1.1.0',
33
- projectRoot: '/test',
34
- syncState: { status: 'clean', lastSyncAt: new Date().toISOString(), lockHash: 'a', contractHash: 'b' },
35
- modules: {
36
- auth: { id: 'auth', files: ['src/auth/verify.ts'], hash: 'h1', fragmentPath: '.mikk/fragments/auth.json' },
37
- api: { id: 'api', files: ['src/api/login.ts'], hash: 'h2', fragmentPath: '.mikk/fragments/api.json' },
38
- },
39
- functions: {
40
- 'fn:auth:verifyToken': {
41
- id: 'fn:auth:verifyToken', name: 'verifyToken', file: 'src/auth/verify.ts',
42
- startLine: 1, endLine: 10, hash: 'h1', calls: [], calledBy: ['fn:api:handleLogin'],
43
- moduleId: 'auth', purpose: 'Verify JWT tokens',
44
- },
45
- 'fn:auth:refreshToken': {
46
- id: 'fn:auth:refreshToken', name: 'refreshToken', file: 'src/auth/refresh.ts',
47
- startLine: 1, endLine: 15, hash: 'h2', calls: [], calledBy: [],
48
- moduleId: 'auth',
49
- },
50
- 'fn:api:handleLogin': {
51
- id: 'fn:api:handleLogin', name: 'handleLogin', file: 'src/api/login.ts',
52
- startLine: 1, endLine: 20, hash: 'h3', calls: ['fn:auth:verifyToken'], calledBy: [],
53
- moduleId: 'api',
54
- },
55
- },
56
- files: {
57
- 'src/auth/verify.ts': { path: 'src/auth/verify.ts', hash: 'fh1', moduleId: 'auth', lastModified: new Date().toISOString() },
58
- 'src/api/login.ts': { path: 'src/api/login.ts', hash: 'fh2', moduleId: 'api', lastModified: new Date().toISOString() },
59
- },
60
- graph: { nodes: 3, edges: 1, rootHash: 'root' },
61
- }
62
-
63
- describe('ClaudeMdGenerator', () => {
64
- test('generates valid markdown', () => {
65
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
66
- const md = gen.generate()
67
- expect(md).toContain('# TestProject')
68
- expect(md).toContain('Architecture Overview')
69
- })
70
-
71
- test('includes project description', () => {
72
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
73
- const md = gen.generate()
74
- expect(md).toContain('A test project for validating claude.md generation')
75
- })
76
-
77
- test('includes module sections', () => {
78
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
79
- const md = gen.generate()
80
- expect(md).toContain('Authentication module')
81
- expect(md).toContain('API module')
82
- })
83
-
84
- test('includes function names', () => {
85
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
86
- const md = gen.generate()
87
- expect(md).toContain('verifyToken')
88
- expect(md).toContain('handleLogin')
89
- })
90
-
91
- test('includes constraints', () => {
92
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
93
- const md = gen.generate()
94
- expect(md).toContain('No direct DB access outside db/')
95
- })
96
-
97
- test('includes decisions', () => {
98
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
99
- const md = gen.generate()
100
- expect(md).toContain('Use JWT')
101
- expect(md).toContain('Stateless auth for scalability')
102
- })
103
-
104
- test('includes dependency info', () => {
105
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
106
- const md = gen.generate()
107
- // API depends on Auth (handleLogin calls verifyToken)
108
- expect(md).toContain('Depends on')
109
- })
110
-
111
- test('respects token budget', () => {
112
- // Use a very small budget — should truncate
113
- const gen = new ClaudeMdGenerator(mockContract, mockLock, 200)
114
- const md = gen.generate()
115
- // Should have the summary but may be truncated
116
- expect(md).toContain('TestProject')
117
- })
118
-
119
- test('includes stats', () => {
120
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
121
- const md = gen.generate()
122
- expect(md).toContain('3 functions')
123
- expect(md).toContain('2 modules')
124
- })
125
-
126
- test('shows purpose when available', () => {
127
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
128
- const md = gen.generate()
129
- expect(md).toContain('Verify JWT tokens')
130
- })
131
-
132
- test('shows calledBy count for key functions', () => {
133
- const gen = new ClaudeMdGenerator(mockContract, mockLock)
134
- const md = gen.generate()
135
- expect(md).toContain('called by 1')
136
- })
137
- })
1
+ import { describe, test, expect } from 'bun:test'
2
+ import { ClaudeMdGenerator } from '../src/claude-md-generator'
3
+ import type { MikkContract, MikkLock } from '@getmikk/core'
4
+
5
+ const mockContract: MikkContract = {
6
+ version: '1.0.0',
7
+ project: {
8
+ name: 'TestProject',
9
+ description: 'A test project for validating claude.md generation',
10
+ language: 'TypeScript',
11
+ entryPoints: ['src/index.ts'],
12
+ },
13
+ declared: {
14
+ modules: [
15
+ { id: 'auth', name: 'Authentication', description: 'Handles user authentication', intent: 'JWT-based auth flow', paths: ['src/auth/**'] },
16
+ { id: 'api', name: 'API', description: 'REST API layer', paths: ['src/api/**'] },
17
+ ],
18
+ constraints: [
19
+ 'No direct DB access outside db/',
20
+ 'All auth must go through auth.middleware',
21
+ ],
22
+ decisions: [
23
+ { id: 'd1', title: 'Use JWT', reason: 'Stateless auth for scalability', date: '2024-01-01' },
24
+ ],
25
+ },
26
+ overwrite: { mode: 'never', requireConfirmation: true },
27
+ }
28
+
29
+ const mockLock: MikkLock = {
30
+ version: '1.0.0',
31
+ generatedAt: new Date().toISOString(),
32
+ generatorVersion: '1.1.0',
33
+ projectRoot: '/test',
34
+ syncState: { status: 'clean', lastSyncAt: new Date().toISOString(), lockHash: 'a', contractHash: 'b' },
35
+ modules: {
36
+ auth: { id: 'auth', files: ['src/auth/verify.ts'], hash: 'h1', fragmentPath: '.mikk/fragments/auth.json' },
37
+ api: { id: 'api', files: ['src/api/login.ts'], hash: 'h2', fragmentPath: '.mikk/fragments/api.json' },
38
+ },
39
+ functions: {
40
+ 'fn:auth:verifyToken': {
41
+ id: 'fn:auth:verifyToken', name: 'verifyToken', file: 'src/auth/verify.ts',
42
+ startLine: 1, endLine: 10, hash: 'h1', calls: [], calledBy: ['fn:api:handleLogin'],
43
+ moduleId: 'auth', purpose: 'Verify JWT tokens',
44
+ },
45
+ 'fn:auth:refreshToken': {
46
+ id: 'fn:auth:refreshToken', name: 'refreshToken', file: 'src/auth/refresh.ts',
47
+ startLine: 1, endLine: 15, hash: 'h2', calls: [], calledBy: [],
48
+ moduleId: 'auth',
49
+ },
50
+ 'fn:api:handleLogin': {
51
+ id: 'fn:api:handleLogin', name: 'handleLogin', file: 'src/api/login.ts',
52
+ startLine: 1, endLine: 20, hash: 'h3', calls: ['fn:auth:verifyToken'], calledBy: [],
53
+ moduleId: 'api',
54
+ },
55
+ },
56
+ files: {
57
+ 'src/auth/verify.ts': { path: 'src/auth/verify.ts', hash: 'fh1', moduleId: 'auth', lastModified: new Date().toISOString() },
58
+ 'src/api/login.ts': { path: 'src/api/login.ts', hash: 'fh2', moduleId: 'api', lastModified: new Date().toISOString() },
59
+ },
60
+ graph: { nodes: 3, edges: 1, rootHash: 'root' },
61
+ }
62
+
63
+ describe('ClaudeMdGenerator', () => {
64
+ test('generates valid markdown', () => {
65
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
66
+ const md = gen.generate()
67
+ expect(md).toContain('# TestProject')
68
+ expect(md).toContain('Architecture Overview')
69
+ })
70
+
71
+ test('includes project description', () => {
72
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
73
+ const md = gen.generate()
74
+ expect(md).toContain('A test project for validating claude.md generation')
75
+ })
76
+
77
+ test('includes module sections', () => {
78
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
79
+ const md = gen.generate()
80
+ expect(md).toContain('Authentication module')
81
+ expect(md).toContain('API module')
82
+ })
83
+
84
+ test('includes function names', () => {
85
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
86
+ const md = gen.generate()
87
+ expect(md).toContain('verifyToken')
88
+ expect(md).toContain('handleLogin')
89
+ })
90
+
91
+ test('includes constraints', () => {
92
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
93
+ const md = gen.generate()
94
+ expect(md).toContain('No direct DB access outside db/')
95
+ })
96
+
97
+ test('includes decisions', () => {
98
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
99
+ const md = gen.generate()
100
+ expect(md).toContain('Use JWT')
101
+ expect(md).toContain('Stateless auth for scalability')
102
+ })
103
+
104
+ test('includes dependency info', () => {
105
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
106
+ const md = gen.generate()
107
+ // API depends on Auth (handleLogin calls verifyToken)
108
+ expect(md).toContain('Depends on')
109
+ })
110
+
111
+ test('respects token budget', () => {
112
+ // Use a very small budget — should truncate
113
+ const gen = new ClaudeMdGenerator(mockContract, mockLock, 200)
114
+ const md = gen.generate()
115
+ // Should have the summary but may be truncated
116
+ expect(md).toContain('TestProject')
117
+ })
118
+
119
+ test('includes stats', () => {
120
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
121
+ const md = gen.generate()
122
+ expect(md).toContain('3 functions')
123
+ expect(md).toContain('2 modules')
124
+ })
125
+
126
+ test('shows purpose when available', () => {
127
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
128
+ const md = gen.generate()
129
+ expect(md).toContain('Verify JWT tokens')
130
+ })
131
+
132
+ test('shows calledBy count for key functions', () => {
133
+ const gen = new ClaudeMdGenerator(mockContract, mockLock)
134
+ const md = gen.generate()
135
+ expect(md).toContain('called by 1')
136
+ })
137
+ })
@@ -1,5 +1,5 @@
1
- import { expect, test } from "bun:test";
2
-
3
- test("smoke test - ai-context", () => {
4
- expect(true).toBe(true);
5
- });
1
+ import { expect, test } from "bun:test";
2
+
3
+ test("smoke test - ai-context", () => {
4
+ expect(true).toBe(true);
5
+ });
package/tsconfig.json CHANGED
@@ -1,15 +1,15 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": [
8
- "src/**/*"
9
- ],
10
- "exclude": [
11
- "node_modules",
12
- "dist",
13
- "tests"
14
- ]
15
- }
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": [
8
+ "src/**/*"
9
+ ],
10
+ "exclude": [
11
+ "node_modules",
12
+ "dist",
13
+ "tests"
14
+ ]
15
+ }