@dot-ai/cli 0.5.2
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.
- package/LICENSE +21 -0
- package/dist/__tests__/cli.test.d.ts +2 -0
- package/dist/__tests__/cli.test.d.ts.map +1 -0
- package/dist/__tests__/cli.test.js +276 -0
- package/dist/__tests__/cli.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -0
- package/src/__tests__/cli.test.ts +346 -0
- package/src/index.ts +228 -0
- package/tsconfig.json +23 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { mkdtemp, mkdir, writeFile, readFile, access } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
loadConfig,
|
|
7
|
+
registerDefaults,
|
|
8
|
+
clearProviders,
|
|
9
|
+
createProviders,
|
|
10
|
+
boot,
|
|
11
|
+
enrich,
|
|
12
|
+
} from '@dot-ai/core';
|
|
13
|
+
|
|
14
|
+
// ── init command logic ───────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
async function runInit(root: string): Promise<string> {
|
|
17
|
+
const aiDir = join(root, '.ai');
|
|
18
|
+
const lines: string[] = [];
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await access(join(aiDir, 'dot-ai.yml'));
|
|
22
|
+
lines.push('.ai/dot-ai.yml already exists. Nothing to do.');
|
|
23
|
+
return lines.join('\n');
|
|
24
|
+
} catch {
|
|
25
|
+
// Doesn't exist, create it
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await mkdir(aiDir, { recursive: true });
|
|
29
|
+
|
|
30
|
+
await writeFile(join(aiDir, 'dot-ai.yml'), [
|
|
31
|
+
'# dot-ai configuration',
|
|
32
|
+
'# Uncomment and customize providers as needed.',
|
|
33
|
+
'# Default: file-based providers reading from .ai/ directory.',
|
|
34
|
+
'#',
|
|
35
|
+
'# memory:',
|
|
36
|
+
'# use: "@dot-ai/provider-file-memory"',
|
|
37
|
+
'#',
|
|
38
|
+
'# skills:',
|
|
39
|
+
'# use: "@dot-ai/provider-file-skills"',
|
|
40
|
+
'#',
|
|
41
|
+
'# routing:',
|
|
42
|
+
'# use: "@dot-ai/provider-rules-routing"',
|
|
43
|
+
'',
|
|
44
|
+
].join('\n'));
|
|
45
|
+
|
|
46
|
+
await writeFile(join(aiDir, 'AGENTS.md'), [
|
|
47
|
+
'# AGENTS.md',
|
|
48
|
+
'',
|
|
49
|
+
'> Your workspace rules and conventions go here.',
|
|
50
|
+
'',
|
|
51
|
+
'## Rules',
|
|
52
|
+
'',
|
|
53
|
+
'- ...',
|
|
54
|
+
'',
|
|
55
|
+
].join('\n'));
|
|
56
|
+
|
|
57
|
+
lines.push('Created:');
|
|
58
|
+
lines.push(' .ai/dot-ai.yml (config)');
|
|
59
|
+
lines.push(' .ai/AGENTS.md (template)');
|
|
60
|
+
lines.push('\nNext: add SOUL.md, USER.md, skills/, memory/ as needed.');
|
|
61
|
+
return lines.join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
async function setupAiDir(root: string): Promise<void> {
|
|
67
|
+
const ai = join(root, '.ai');
|
|
68
|
+
await mkdir(ai, { recursive: true });
|
|
69
|
+
await mkdir(join(ai, 'memory'), { recursive: true });
|
|
70
|
+
await mkdir(join(ai, 'skills', 'ts-standards'), { recursive: true });
|
|
71
|
+
await mkdir(join(ai, 'skills', 'code-review'), { recursive: true });
|
|
72
|
+
await mkdir(join(ai, 'tools'), { recursive: true });
|
|
73
|
+
|
|
74
|
+
await writeFile(join(ai, 'AGENTS.md'), '# AGENTS.md\n\nYou are Kiwi.');
|
|
75
|
+
await writeFile(join(ai, 'SOUL.md'), '# SOUL.md\n\nBe genuine.');
|
|
76
|
+
await writeFile(join(ai, 'USER.md'), '# USER.md\n\nJo, developer.');
|
|
77
|
+
await writeFile(join(ai, 'IDENTITY.md'), '# IDENTITY.md\n\nName: Kiwi');
|
|
78
|
+
|
|
79
|
+
await writeFile(join(ai, 'skills', 'ts-standards', 'SKILL.md'), [
|
|
80
|
+
'---',
|
|
81
|
+
'description: TypeScript coding standards',
|
|
82
|
+
'labels: [typescript, code, standards]',
|
|
83
|
+
'triggers: [auto]',
|
|
84
|
+
'---',
|
|
85
|
+
'',
|
|
86
|
+
'## TypeScript Standards',
|
|
87
|
+
'- Use strict mode',
|
|
88
|
+
].join('\n'));
|
|
89
|
+
|
|
90
|
+
await writeFile(join(ai, 'skills', 'code-review', 'SKILL.md'), [
|
|
91
|
+
'---',
|
|
92
|
+
'description: Code review guidelines',
|
|
93
|
+
'labels: [review, code-fix, bug]',
|
|
94
|
+
'triggers: [auto]',
|
|
95
|
+
'---',
|
|
96
|
+
'',
|
|
97
|
+
'## Code Review',
|
|
98
|
+
'- Check for edge cases',
|
|
99
|
+
].join('\n'));
|
|
100
|
+
|
|
101
|
+
await writeFile(join(ai, 'tools', 'eslint.yaml'), [
|
|
102
|
+
'name: eslint',
|
|
103
|
+
'description: TypeScript linter',
|
|
104
|
+
'labels: [typescript, lint, code]',
|
|
105
|
+
].join('\n'));
|
|
106
|
+
|
|
107
|
+
await writeFile(join(ai, 'memory', '2026-03-01.md'), [
|
|
108
|
+
'- Fixed auth middleware N+1 query bug',
|
|
109
|
+
'- Decided to use JWT for auth tokens',
|
|
110
|
+
].join('\n'));
|
|
111
|
+
|
|
112
|
+
await writeFile(join(ai, 'dot-ai.yml'), [
|
|
113
|
+
'# dot-ai config',
|
|
114
|
+
'memory:',
|
|
115
|
+
' use: @dot-ai/provider-file-memory',
|
|
116
|
+
` root: ${root}`,
|
|
117
|
+
'skills:',
|
|
118
|
+
' use: @dot-ai/provider-file-skills',
|
|
119
|
+
` root: ${root}`,
|
|
120
|
+
'identity:',
|
|
121
|
+
' use: @dot-ai/provider-file-identity',
|
|
122
|
+
` root: ${root}`,
|
|
123
|
+
'routing:',
|
|
124
|
+
' use: @dot-ai/provider-rules-routing',
|
|
125
|
+
'tasks:',
|
|
126
|
+
' use: @dot-ai/provider-file-tasks',
|
|
127
|
+
` root: ${root}`,
|
|
128
|
+
'tools:',
|
|
129
|
+
' use: @dot-ai/provider-file-tools',
|
|
130
|
+
` root: ${root}`,
|
|
131
|
+
].join('\n'));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── init tests ───────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
describe('init command', () => {
|
|
137
|
+
let root: string;
|
|
138
|
+
|
|
139
|
+
beforeEach(async () => {
|
|
140
|
+
root = await mkdtemp(join(tmpdir(), 'dot-ai-cli-init-'));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('creates .ai/dot-ai.yml in empty directory', async () => {
|
|
144
|
+
await runInit(root);
|
|
145
|
+
const content = await readFile(join(root, '.ai', 'dot-ai.yml'), 'utf8');
|
|
146
|
+
expect(content).toContain('# dot-ai configuration');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('creates .ai/AGENTS.md in empty directory', async () => {
|
|
150
|
+
await runInit(root);
|
|
151
|
+
const content = await readFile(join(root, '.ai', 'AGENTS.md'), 'utf8');
|
|
152
|
+
expect(content).toContain('# AGENTS.md');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('dot-ai.yml contains commented provider examples', async () => {
|
|
156
|
+
await runInit(root);
|
|
157
|
+
const content = await readFile(join(root, '.ai', 'dot-ai.yml'), 'utf8');
|
|
158
|
+
expect(content).toContain('@dot-ai/provider-file-memory');
|
|
159
|
+
expect(content).toContain('@dot-ai/provider-file-skills');
|
|
160
|
+
expect(content).toContain('@dot-ai/provider-rules-routing');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('AGENTS.md is a template with ## Rules section', async () => {
|
|
164
|
+
await runInit(root);
|
|
165
|
+
const content = await readFile(join(root, '.ai', 'AGENTS.md'), 'utf8');
|
|
166
|
+
expect(content).toContain('## Rules');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('does nothing if dot-ai.yml already exists', async () => {
|
|
170
|
+
await mkdir(join(root, '.ai'), { recursive: true });
|
|
171
|
+
await writeFile(join(root, '.ai', 'dot-ai.yml'), '# existing config\n');
|
|
172
|
+
|
|
173
|
+
const output = await runInit(root);
|
|
174
|
+
|
|
175
|
+
expect(output).toContain('already exists');
|
|
176
|
+
// File should be unchanged
|
|
177
|
+
const content = await readFile(join(root, '.ai', 'dot-ai.yml'), 'utf8');
|
|
178
|
+
expect(content).toBe('# existing config\n');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('works if .ai/ directory already exists without dot-ai.yml', async () => {
|
|
182
|
+
await mkdir(join(root, '.ai'), { recursive: true });
|
|
183
|
+
await writeFile(join(root, '.ai', 'AGENTS.md'), '# existing\n');
|
|
184
|
+
|
|
185
|
+
await runInit(root);
|
|
186
|
+
|
|
187
|
+
// dot-ai.yml should be created
|
|
188
|
+
const content = await readFile(join(root, '.ai', 'dot-ai.yml'), 'utf8');
|
|
189
|
+
expect(content).toContain('# dot-ai configuration');
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// ── boot command logic ────────────────────────────────────────────────────────
|
|
194
|
+
|
|
195
|
+
describe('boot command (core pipeline)', () => {
|
|
196
|
+
let root: string;
|
|
197
|
+
|
|
198
|
+
beforeEach(async () => {
|
|
199
|
+
clearProviders();
|
|
200
|
+
registerDefaults();
|
|
201
|
+
root = await mkdtemp(join(tmpdir(), 'dot-ai-cli-boot-'));
|
|
202
|
+
await setupAiDir(root);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('loads config and creates providers', async () => {
|
|
206
|
+
const config = await loadConfig(root);
|
|
207
|
+
const providers = await createProviders(config);
|
|
208
|
+
expect(providers.memory).toBeDefined();
|
|
209
|
+
expect(providers.skills).toBeDefined();
|
|
210
|
+
expect(providers.identity).toBeDefined();
|
|
211
|
+
expect(providers.routing).toBeDefined();
|
|
212
|
+
expect(providers.tools).toBeDefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('boot returns identities, skills, vocabulary', async () => {
|
|
216
|
+
const config = await loadConfig(root);
|
|
217
|
+
const providers = await createProviders(config);
|
|
218
|
+
const cache = await boot(providers);
|
|
219
|
+
|
|
220
|
+
expect(cache.identities.length).toBe(4); // AGENTS, SOUL, USER, IDENTITY
|
|
221
|
+
expect(cache.skills.length).toBe(2); // ts-standards, code-review
|
|
222
|
+
expect(cache.vocabulary.length).toBeGreaterThan(0);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('vocabulary contains labels from skills and tools', async () => {
|
|
226
|
+
const config = await loadConfig(root);
|
|
227
|
+
const providers = await createProviders(config);
|
|
228
|
+
const cache = await boot(providers);
|
|
229
|
+
|
|
230
|
+
expect(cache.vocabulary).toContain('typescript');
|
|
231
|
+
expect(cache.vocabulary).toContain('code');
|
|
232
|
+
expect(cache.vocabulary).toContain('bug');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('identities have correct types', async () => {
|
|
236
|
+
const config = await loadConfig(root);
|
|
237
|
+
const providers = await createProviders(config);
|
|
238
|
+
const cache = await boot(providers);
|
|
239
|
+
|
|
240
|
+
const types = cache.identities.map(i => i.type);
|
|
241
|
+
expect(types).toContain('agents');
|
|
242
|
+
expect(types).toContain('soul');
|
|
243
|
+
expect(types).toContain('user');
|
|
244
|
+
expect(types).toContain('identity');
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ── trace command logic ───────────────────────────────────────────────────────
|
|
249
|
+
|
|
250
|
+
describe('trace command (enrich pipeline)', () => {
|
|
251
|
+
let root: string;
|
|
252
|
+
|
|
253
|
+
beforeEach(async () => {
|
|
254
|
+
clearProviders();
|
|
255
|
+
registerDefaults();
|
|
256
|
+
root = await mkdtemp(join(tmpdir(), 'dot-ai-cli-trace-'));
|
|
257
|
+
await setupAiDir(root);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('enrich returns labels matching prompt vocabulary', async () => {
|
|
261
|
+
const config = await loadConfig(root);
|
|
262
|
+
const providers = await createProviders(config);
|
|
263
|
+
const cache = await boot(providers);
|
|
264
|
+
|
|
265
|
+
const ctx = await enrich('Fix the TypeScript bug', providers, cache);
|
|
266
|
+
|
|
267
|
+
expect(ctx.labels.some(l => l.name === 'typescript')).toBe(true);
|
|
268
|
+
expect(ctx.labels.some(l => l.name === 'bug')).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('enrich returns matched skills for typescript prompt', async () => {
|
|
272
|
+
const config = await loadConfig(root);
|
|
273
|
+
const providers = await createProviders(config);
|
|
274
|
+
const cache = await boot(providers);
|
|
275
|
+
|
|
276
|
+
const ctx = await enrich('Fix the TypeScript code', providers, cache);
|
|
277
|
+
|
|
278
|
+
expect(ctx.skills.some(s => s.name === 'ts-standards')).toBe(true);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('enrich returns matched tools for typescript prompt', async () => {
|
|
282
|
+
const config = await loadConfig(root);
|
|
283
|
+
const providers = await createProviders(config);
|
|
284
|
+
const cache = await boot(providers);
|
|
285
|
+
|
|
286
|
+
const ctx = await enrich('Fix the TypeScript bug', providers, cache);
|
|
287
|
+
|
|
288
|
+
expect(ctx.tools.some(t => t.name === 'eslint')).toBe(true);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('enrich returns memories related to prompt', async () => {
|
|
292
|
+
const config = await loadConfig(root);
|
|
293
|
+
const providers = await createProviders(config);
|
|
294
|
+
const cache = await boot(providers);
|
|
295
|
+
|
|
296
|
+
const ctx = await enrich('Fix the auth bug', providers, cache);
|
|
297
|
+
|
|
298
|
+
expect(ctx.memories.some(m => m.content.includes('auth'))).toBe(true);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('enrich returns routing result', async () => {
|
|
302
|
+
const config = await loadConfig(root);
|
|
303
|
+
const providers = await createProviders(config);
|
|
304
|
+
const cache = await boot(providers);
|
|
305
|
+
|
|
306
|
+
const ctx = await enrich('Fix the bug', providers, cache);
|
|
307
|
+
|
|
308
|
+
expect(ctx.routing.model).toBeDefined();
|
|
309
|
+
expect(ctx.routing.reason).toBeDefined();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('enrich returns identities from boot cache', async () => {
|
|
313
|
+
const config = await loadConfig(root);
|
|
314
|
+
const providers = await createProviders(config);
|
|
315
|
+
const cache = await boot(providers);
|
|
316
|
+
|
|
317
|
+
const ctx = await enrich('anything', providers, cache);
|
|
318
|
+
|
|
319
|
+
expect(ctx.identities.length).toBe(4);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('enrich with unrelated prompt returns no matched skills', async () => {
|
|
323
|
+
const config = await loadConfig(root);
|
|
324
|
+
const providers = await createProviders(config);
|
|
325
|
+
const cache = await boot(providers);
|
|
326
|
+
|
|
327
|
+
// "hello world" doesn't match any known label
|
|
328
|
+
const ctx = await enrich('hello world', providers, cache);
|
|
329
|
+
|
|
330
|
+
expect(ctx.labels.length).toBe(0);
|
|
331
|
+
expect(ctx.skills.length).toBe(0);
|
|
332
|
+
expect(ctx.tools.length).toBe(0);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('different prompts match different skills', async () => {
|
|
336
|
+
const config = await loadConfig(root);
|
|
337
|
+
const providers = await createProviders(config);
|
|
338
|
+
const cache = await boot(providers);
|
|
339
|
+
|
|
340
|
+
const tsCtx = await enrich('Fix TypeScript code', providers, cache);
|
|
341
|
+
const reviewCtx = await enrich('Review this code for bugs', providers, cache);
|
|
342
|
+
|
|
343
|
+
expect(tsCtx.skills.some(s => s.name === 'ts-standards')).toBe(true);
|
|
344
|
+
expect(reviewCtx.skills.some(s => s.name === 'code-review')).toBe(true);
|
|
345
|
+
});
|
|
346
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { argv, cwd, exit } from 'node:process';
|
|
3
|
+
import { mkdir, writeFile, access } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
loadConfig,
|
|
7
|
+
resolveConfig,
|
|
8
|
+
injectRoot,
|
|
9
|
+
registerDefaults,
|
|
10
|
+
clearProviders,
|
|
11
|
+
createProviders,
|
|
12
|
+
boot,
|
|
13
|
+
enrich,
|
|
14
|
+
formatContext,
|
|
15
|
+
} from '@dot-ai/core';
|
|
16
|
+
|
|
17
|
+
const args = argv.slice(2);
|
|
18
|
+
const command = args[0];
|
|
19
|
+
|
|
20
|
+
async function main(): Promise<void> {
|
|
21
|
+
switch (command) {
|
|
22
|
+
case 'init':
|
|
23
|
+
await cmdInit();
|
|
24
|
+
break;
|
|
25
|
+
case 'boot':
|
|
26
|
+
await cmdBoot();
|
|
27
|
+
break;
|
|
28
|
+
case 'trace':
|
|
29
|
+
await cmdTrace(args.slice(1));
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
console.log('dot-ai v0.4.0\n');
|
|
33
|
+
console.log('Commands:');
|
|
34
|
+
console.log(' init Create .ai/ directory with defaults');
|
|
35
|
+
console.log(' boot Run boot and show workspace info');
|
|
36
|
+
console.log(' trace "<prompt>" Dry-run enrich pipeline with token estimates');
|
|
37
|
+
exit(command ? 1 : 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function cmdInit(): Promise<void> {
|
|
42
|
+
const root = cwd();
|
|
43
|
+
const aiDir = join(root, '.ai');
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await access(join(aiDir, 'dot-ai.yml'));
|
|
47
|
+
console.log('.ai/dot-ai.yml already exists. Nothing to do.');
|
|
48
|
+
return;
|
|
49
|
+
} catch {
|
|
50
|
+
// Doesn't exist, create it
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await mkdir(aiDir, { recursive: true });
|
|
54
|
+
|
|
55
|
+
await writeFile(join(aiDir, 'dot-ai.yml'), [
|
|
56
|
+
'# dot-ai configuration',
|
|
57
|
+
'# Uncomment and customize providers as needed.',
|
|
58
|
+
'# Default: file-based providers reading from .ai/ directory.',
|
|
59
|
+
'#',
|
|
60
|
+
'# memory:',
|
|
61
|
+
'# use: "@dot-ai/provider-file-memory"',
|
|
62
|
+
'#',
|
|
63
|
+
'# skills:',
|
|
64
|
+
'# use: "@dot-ai/provider-file-skills"',
|
|
65
|
+
'#',
|
|
66
|
+
'# routing:',
|
|
67
|
+
'# use: "@dot-ai/provider-rules-routing"',
|
|
68
|
+
'',
|
|
69
|
+
].join('\n'));
|
|
70
|
+
|
|
71
|
+
await writeFile(join(aiDir, 'AGENTS.md'), [
|
|
72
|
+
'# AGENTS.md',
|
|
73
|
+
'',
|
|
74
|
+
'> Your workspace rules and conventions go here.',
|
|
75
|
+
'',
|
|
76
|
+
'## Rules',
|
|
77
|
+
'',
|
|
78
|
+
'- ...',
|
|
79
|
+
'',
|
|
80
|
+
].join('\n'));
|
|
81
|
+
|
|
82
|
+
console.log('Created:');
|
|
83
|
+
console.log(' .ai/dot-ai.yml (config)');
|
|
84
|
+
console.log(' .ai/AGENTS.md (template)');
|
|
85
|
+
console.log('\nNext: add SOUL.md, USER.md, skills/, memory/ as needed.');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function cmdBoot(): Promise<void> {
|
|
89
|
+
const root = cwd();
|
|
90
|
+
const start = performance.now();
|
|
91
|
+
|
|
92
|
+
clearProviders();
|
|
93
|
+
registerDefaults();
|
|
94
|
+
|
|
95
|
+
const rawConfig = await loadConfig(root);
|
|
96
|
+
const config = injectRoot(rawConfig, root);
|
|
97
|
+
const providers = await createProviders(config);
|
|
98
|
+
const cache = await boot(providers);
|
|
99
|
+
|
|
100
|
+
const duration = Math.round(performance.now() - start);
|
|
101
|
+
|
|
102
|
+
console.log(`dot-ai boot — ${root}\n`);
|
|
103
|
+
console.log(`Identities: ${cache.identities.length}${cache.identities.length > 0 ? ` (${cache.identities.map(i => i.type).join(', ')})` : ''}`);
|
|
104
|
+
console.log(`Skills: ${cache.skills.length}${cache.skills.length > 0 ? ` (${cache.skills.map(s => s.name).join(', ')})` : ''}`);
|
|
105
|
+
console.log(`Vocabulary: ${cache.vocabulary.length} labels`);
|
|
106
|
+
console.log(`\nBoot complete in ${duration}ms`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function cmdTrace(rawArgs: string[]): Promise<void> {
|
|
110
|
+
const flags = new Set(rawArgs.filter(a => a.startsWith('--')));
|
|
111
|
+
const prompt = rawArgs.filter(a => !a.startsWith('--')).join(' ');
|
|
112
|
+
const jsonMode = flags.has('--json');
|
|
113
|
+
const verbose = flags.has('--verbose');
|
|
114
|
+
|
|
115
|
+
if (!prompt) {
|
|
116
|
+
console.error('Usage: dot-ai trace "<prompt>" [--json] [--verbose]');
|
|
117
|
+
exit(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const root = cwd();
|
|
121
|
+
const start = performance.now();
|
|
122
|
+
|
|
123
|
+
clearProviders();
|
|
124
|
+
registerDefaults();
|
|
125
|
+
|
|
126
|
+
const rawConfig = await loadConfig(root);
|
|
127
|
+
const config = injectRoot(rawConfig, root);
|
|
128
|
+
const resolved = resolveConfig(rawConfig);
|
|
129
|
+
const providers = await createProviders(config);
|
|
130
|
+
const cache = await boot(providers);
|
|
131
|
+
const ctx = await enrich(prompt, providers, cache);
|
|
132
|
+
|
|
133
|
+
// Load skill content for matched skills
|
|
134
|
+
for (const skill of ctx.skills) {
|
|
135
|
+
if (!skill.content && skill.name) {
|
|
136
|
+
skill.content = await providers.skills.load(skill.name) ?? undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const duration = Math.round(performance.now() - start);
|
|
141
|
+
|
|
142
|
+
// Compute token estimates
|
|
143
|
+
const identityChars = cache.identities.reduce((sum, i) => sum + (i.content?.length ?? 0), 0);
|
|
144
|
+
const skillChars = ctx.skills.reduce((sum, s) => sum + (s.content?.length ?? 0), 0);
|
|
145
|
+
const memoryChars = ctx.memories.reduce((sum, m) => sum + m.content.length, 0);
|
|
146
|
+
const totalChars = skillChars + memoryChars;
|
|
147
|
+
|
|
148
|
+
// Check for disabled skills
|
|
149
|
+
const disabledList = typeof resolved.skills?.with?.disabled === 'string'
|
|
150
|
+
? resolved.skills.with.disabled.split(',').map((s: string) => s.trim()).filter(Boolean)
|
|
151
|
+
: [];
|
|
152
|
+
|
|
153
|
+
if (jsonMode) {
|
|
154
|
+
const output = {
|
|
155
|
+
prompt,
|
|
156
|
+
sessionStart: {
|
|
157
|
+
identityCount: cache.identities.length,
|
|
158
|
+
identityChars,
|
|
159
|
+
estimatedTokens: Math.round(identityChars / 4),
|
|
160
|
+
},
|
|
161
|
+
userPromptSubmit: {
|
|
162
|
+
labels: ctx.labels.map(l => l.name),
|
|
163
|
+
skills: ctx.skills.map(s => ({
|
|
164
|
+
name: s.name,
|
|
165
|
+
chars: s.content?.length ?? 0,
|
|
166
|
+
})),
|
|
167
|
+
memoryCount: ctx.memories.length,
|
|
168
|
+
memoryChars,
|
|
169
|
+
toolCount: ctx.tools.length,
|
|
170
|
+
routing: ctx.routing,
|
|
171
|
+
totalChars,
|
|
172
|
+
estimatedTokens: Math.round(totalChars / 4),
|
|
173
|
+
},
|
|
174
|
+
disabled: disabledList,
|
|
175
|
+
vocabularySize: cache.vocabulary.length,
|
|
176
|
+
durationMs: duration,
|
|
177
|
+
};
|
|
178
|
+
console.log(JSON.stringify(output, null, 2));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Human-readable output
|
|
183
|
+
console.log(`dot-ai trace — "${prompt}"\n`);
|
|
184
|
+
|
|
185
|
+
// SessionStart section
|
|
186
|
+
console.log(`── SessionStart (one-time) ──`);
|
|
187
|
+
console.log(` ${cache.identities.length} identities: ${identityChars.toLocaleString()} chars (~${Math.round(identityChars / 4).toLocaleString()} tokens)`);
|
|
188
|
+
|
|
189
|
+
// UserPromptSubmit section
|
|
190
|
+
console.log(`\n── UserPromptSubmit ──`);
|
|
191
|
+
console.log(` Labels: [${ctx.labels.map(l => l.name).join(', ')}]`);
|
|
192
|
+
|
|
193
|
+
if (ctx.skills.length > 0) {
|
|
194
|
+
const skillDetails = ctx.skills.map(s => `${s.name} (${(s.content?.length ?? 0).toLocaleString()} chars)`);
|
|
195
|
+
console.log(` Skills: ${skillDetails.join(', ')}`);
|
|
196
|
+
} else {
|
|
197
|
+
console.log(` Skills: none matched`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
console.log(` Memory: ${ctx.memories.length} entries (${memoryChars.toLocaleString()} chars)`);
|
|
201
|
+
console.log(` Tools: ${ctx.tools.length} matched`);
|
|
202
|
+
console.log(` Routing: ${ctx.routing.model} (${ctx.routing.reason})`);
|
|
203
|
+
console.log(` Total: ${totalChars.toLocaleString()} chars (~${Math.round(totalChars / 4).toLocaleString()} tokens)`);
|
|
204
|
+
|
|
205
|
+
// Disabled skills
|
|
206
|
+
if (disabledList.length > 0) {
|
|
207
|
+
console.log(`\n── Disabled skills ──`);
|
|
208
|
+
console.log(` ${disabledList.join(', ')} (via config)`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Verbose: show the actual markdown that would be injected
|
|
212
|
+
if (verbose) {
|
|
213
|
+
const formatted = formatContext(ctx, {
|
|
214
|
+
skipIdentities: true,
|
|
215
|
+
maxSkillLength: 3000,
|
|
216
|
+
maxSkills: 5,
|
|
217
|
+
});
|
|
218
|
+
console.log(`\n── Injected markdown (${formatted.length.toLocaleString()} chars) ──`);
|
|
219
|
+
console.log(formatted);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
console.log(`\nTrace complete in ${duration}ms`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
main().catch((err) => {
|
|
226
|
+
console.error(err);
|
|
227
|
+
exit(1);
|
|
228
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2023"],
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"outDir": "./dist",
|
|
15
|
+
"rootDir": "./src",
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"declarationMap": true,
|
|
18
|
+
"sourceMap": true,
|
|
19
|
+
"composite": true
|
|
20
|
+
},
|
|
21
|
+
"include": ["src"],
|
|
22
|
+
"exclude": ["node_modules", "dist"]
|
|
23
|
+
}
|