@compilr-dev/sdk 0.7.11 → 0.7.13

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/dist/agent.js CHANGED
@@ -86,6 +86,8 @@ class CompilrAgentImpl {
86
86
  agent;
87
87
  abortController;
88
88
  totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
89
+ /** External event listener set during run()/stream() — receives ALL agent events including usage */
90
+ externalEventListener;
89
91
  /** Meta-tools fallback handler (set when capabilities.enabled) */
90
92
  _metaToolsFallback;
91
93
  constructor(config) {
@@ -257,13 +259,16 @@ class CompilrAgentImpl {
257
259
  includeDefaults: guardrailsConfig.includeDefaults,
258
260
  },
259
261
  delegation: config?.delegation,
262
+ usage: { enabled: true },
260
263
  onEvent: (event) => {
261
- // Track usage from events
264
+ // Track usage internally
262
265
  if (event.type === 'usage_recorded') {
263
266
  this.totalUsage.inputTokens += event.tokens.inputTokens;
264
267
  this.totalUsage.outputTokens += event.tokens.outputTokens;
265
268
  this.totalUsage.totalTokens += event.tokens.inputTokens + event.tokens.outputTokens;
266
269
  }
270
+ // Forward ALL events to external listener (if set via run/stream)
271
+ this.externalEventListener?.(event);
267
272
  },
268
273
  });
269
274
  // Register tools
@@ -274,13 +279,20 @@ class CompilrAgentImpl {
274
279
  }
275
280
  }
276
281
  async run(message, options) {
277
- const result = await this.agent.run(message, {
278
- signal: options?.signal ?? this.abortController.signal,
279
- maxIterations: options?.maxIterations,
280
- onEvent: options?.onEvent,
281
- toolFilter: options?.toolFilter,
282
- });
283
- return toRunResult(result);
282
+ // Set external listener so constructor's onEvent can forward events
283
+ this.externalEventListener = options?.onEvent;
284
+ try {
285
+ const result = await this.agent.run(message, {
286
+ signal: options?.signal ?? this.abortController.signal,
287
+ maxIterations: options?.maxIterations,
288
+ onEvent: options?.onEvent,
289
+ toolFilter: options?.toolFilter,
290
+ });
291
+ return toRunResult(result);
292
+ }
293
+ finally {
294
+ this.externalEventListener = undefined;
295
+ }
284
296
  }
285
297
  async *stream(message, options) {
286
298
  const events = [];
@@ -44,7 +44,7 @@ export interface IDocumentRepository {
44
44
  update(id: number, input: UpdateDocumentInput): Promise<ProjectDocument | null>;
45
45
  delete(id: number): Promise<boolean>;
46
46
  deleteByType(projectId: number, docType: DocumentType): Promise<boolean>;
47
- getTypeCounts(projectId: number): Promise<Record<DocumentType, number>>;
47
+ getTypeCounts(projectId: number): Promise<Record<string, number>>;
48
48
  }
49
49
  export interface IPlanRepository {
50
50
  create(input: CreatePlanInput): Promise<Plan>;
@@ -15,5 +15,5 @@ export declare class SQLiteDocumentRepository implements IDocumentRepository {
15
15
  update(id: number, input: UpdateDocumentInput): Promise<ProjectDocument | null>;
16
16
  delete(id: number): Promise<boolean>;
17
17
  deleteByType(projectId: number, docType: DocumentType): Promise<boolean>;
18
- getTypeCounts(projectId: number): Promise<Record<DocumentType, number>>;
18
+ getTypeCounts(projectId: number): Promise<Record<string, number>>;
19
19
  }
@@ -110,19 +110,7 @@ export class SQLiteDocumentRepository {
110
110
  const results = this.db
111
111
  .prepare('SELECT doc_type, COUNT(*) as count FROM project_documents WHERE project_id = ? GROUP BY doc_type')
112
112
  .all(projectId);
113
- const counts = {
114
- prd: 0,
115
- architecture: 0,
116
- design: 0,
117
- notes: 0,
118
- plan: 0,
119
- 'app-model': 0,
120
- 'research-model': 0,
121
- 'business-model': 0,
122
- 'brand-model': 0,
123
- 'curriculum-model': 0,
124
- 'book-model': 0,
125
- };
113
+ const counts = {};
126
114
  for (const row of results) {
127
115
  counts[row.doc_type] = row.count;
128
116
  }
@@ -7,19 +7,22 @@
7
7
  * Ported from CLI's src/tools/document-db.ts.
8
8
  */
9
9
  import { defineTool, createSuccessResult, createErrorResult } from '@compilr-dev/agents';
10
- /** All valid document types — keep in sync with DocumentType. */
10
+ /** All valid document types — keep in sync with DocumentType in types.ts. */
11
11
  const DOC_TYPE_ENUM = [
12
- 'prd',
13
- 'architecture',
14
- 'design',
15
- 'notes',
16
- 'plan',
17
- 'app-model',
18
- 'research-model',
19
- 'business-model',
20
- 'brand-model',
21
- 'curriculum-model',
22
- 'book-model',
12
+ // Software
13
+ 'prd', 'architecture', 'design', 'notes', 'plan',
14
+ // Structured models
15
+ 'app-model', 'research-model', 'business-model', 'brand-model', 'curriculum-model', 'book-model',
16
+ // Research
17
+ 'outline', 'literature-review', 'abstract', 'methodology', 'bibliography',
18
+ // Business
19
+ 'executive-summary', 'market-analysis', 'financial-model', 'pitch',
20
+ // Content & Marketing
21
+ 'editorial-calendar', 'article',
22
+ // Tech Docs
23
+ 'getting-started', 'api-reference', 'tutorial',
24
+ // General
25
+ 'draft', 'review', 'session-notes', 'chapter',
23
26
  ];
24
27
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
25
28
  export function createDocumentTools(config) {
@@ -19,7 +19,7 @@ export type WorkItemType = 'feature' | 'bug' | 'tech-debt' | 'chore';
19
19
  export type WorkItemStatus = 'backlog' | 'in_progress' | 'completed' | 'skipped';
20
20
  export type WorkItemPriority = 'critical' | 'high' | 'medium' | 'low';
21
21
  export type GuidedStep = 'plan' | 'implement' | 'test' | 'commit' | 'review';
22
- export type DocumentType = 'prd' | 'architecture' | 'design' | 'notes' | 'plan' | 'app-model' | 'research-model' | 'business-model' | 'brand-model' | 'curriculum-model' | 'book-model';
22
+ export type DocumentType = 'prd' | 'architecture' | 'design' | 'notes' | 'plan' | 'app-model' | 'research-model' | 'business-model' | 'brand-model' | 'curriculum-model' | 'book-model' | 'outline' | 'literature-review' | 'abstract' | 'methodology' | 'bibliography' | 'executive-summary' | 'market-analysis' | 'financial-model' | 'pitch' | 'editorial-calendar' | 'article' | 'getting-started' | 'api-reference' | 'tutorial' | 'draft' | 'review' | 'session-notes' | 'chapter';
23
23
  export type PlanStatus = 'draft' | 'approved' | 'in_progress' | 'completed' | 'abandoned';
24
24
  export interface Project {
25
25
  id: number;
@@ -223,11 +223,15 @@ Key categories:
223
223
 
224
224
  ### Document Storage (CRITICAL)
225
225
 
226
- Project documents (PRD, architecture, design, notes) are stored in the **database**, not the filesystem.
227
- - **Read**: \`project_document_get({ doc_type: "prd" })\` or \`project_document_list()\`
228
- - **Write**: \`project_document_add({ doc_type: "prd", title: "...", content: "..." })\`
226
+ Project documents (drafts, outlines, analyses, plans) are stored in the **database**, not the filesystem.
227
+ - **Read**: \`project_document_get({ doc_type: "outline" })\` or \`project_document_list()\`
228
+ - **Write**: \`project_document_add({ doc_type: "outline", title: "...", content: "..." })\`
229
229
  - Do NOT use write_file or edit for project documents — always use these database tools
230
- - Valid doc_types: prd, architecture, design, notes, session-note`,
230
+ - **Software doc_types**: prd, architecture, design, notes, plan
231
+ - **Research doc_types**: outline, literature-review, abstract, methodology, bibliography
232
+ - **Business doc_types**: executive-summary, market-analysis, financial-model, pitch
233
+ - **Content doc_types**: editorial-calendar, article
234
+ - **General doc_types**: draft, review, session-notes, chapter, notes`,
231
235
  };
232
236
  /**
233
237
  * Token delegation module - always included
@@ -389,8 +389,8 @@ export const TOOL_PROFILES = {
389
389
  'search',
390
390
  'dependencies',
391
391
  ],
392
- // Docs - documentation only
393
- docs: ['file_read', 'file_write', 'interaction', 'handoff', 'guide', 'meta', 'project', 'search', 'factory_models'],
392
+ // Docs - documentation + project documents
393
+ docs: ['file_read', 'file_write', 'interaction', 'handoff', 'guide', 'meta', 'project', 'search', 'documents', 'factory_models'],
394
394
  // DevOps - CI/CD tasks
395
395
  devops: [
396
396
  'file_read',
@@ -461,7 +461,7 @@ export const TOOL_PROFILES = {
461
461
  'anchors',
462
462
  'factory_models',
463
463
  ],
464
- // Analyst (BA) - requirements gathering (minimal technical tools)
464
+ // Analyst (BA) - requirements gathering + document access
465
465
  analyst: [
466
466
  'file_read',
467
467
  'tasks',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",