aspectcode 0.3.5 → 0.4.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.
Files changed (65) hide show
  1. package/dist/cli.d.ts +1 -2
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +1 -2
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +0 -2
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js.map +1 -1
  8. package/dist/diffSummary.d.ts +17 -0
  9. package/dist/diffSummary.d.ts.map +1 -0
  10. package/dist/diffSummary.js +49 -0
  11. package/dist/diffSummary.js.map +1 -0
  12. package/dist/main.d.ts.map +1 -1
  13. package/dist/main.js +13 -16
  14. package/dist/main.js.map +1 -1
  15. package/dist/optimize.d.ts +6 -3
  16. package/dist/optimize.d.ts.map +1 -1
  17. package/dist/optimize.js +85 -102
  18. package/dist/optimize.js.map +1 -1
  19. package/dist/pipeline.d.ts +5 -4
  20. package/dist/pipeline.d.ts.map +1 -1
  21. package/dist/pipeline.js +45 -10
  22. package/dist/pipeline.js.map +1 -1
  23. package/dist/summary.d.ts +15 -0
  24. package/dist/summary.d.ts.map +1 -0
  25. package/dist/summary.js +51 -0
  26. package/dist/summary.js.map +1 -0
  27. package/dist/ui/Dashboard.d.ts +15 -7
  28. package/dist/ui/Dashboard.d.ts.map +1 -1
  29. package/dist/ui/Dashboard.js +55 -24
  30. package/dist/ui/Dashboard.js.map +1 -1
  31. package/dist/ui/store.d.ts +33 -0
  32. package/dist/ui/store.d.ts.map +1 -1
  33. package/dist/ui/store.js +24 -1
  34. package/dist/ui/store.js.map +1 -1
  35. package/node_modules/@aspectcode/evaluator/dist/index.d.ts +1 -0
  36. package/node_modules/@aspectcode/evaluator/dist/index.d.ts.map +1 -1
  37. package/node_modules/@aspectcode/evaluator/dist/index.js.map +1 -1
  38. package/node_modules/@aspectcode/evaluator/dist/runner.d.ts +11 -1
  39. package/node_modules/@aspectcode/evaluator/dist/runner.d.ts.map +1 -1
  40. package/node_modules/@aspectcode/evaluator/dist/runner.js +5 -2
  41. package/node_modules/@aspectcode/evaluator/dist/runner.js.map +1 -1
  42. package/node_modules/@aspectcode/evaluator/package.json +2 -2
  43. package/node_modules/@aspectcode/optimizer/dist/agent.d.ts +12 -13
  44. package/node_modules/@aspectcode/optimizer/dist/agent.d.ts.map +1 -1
  45. package/node_modules/@aspectcode/optimizer/dist/agent.js +52 -110
  46. package/node_modules/@aspectcode/optimizer/dist/agent.js.map +1 -1
  47. package/node_modules/@aspectcode/optimizer/dist/index.d.ts +3 -3
  48. package/node_modules/@aspectcode/optimizer/dist/index.d.ts.map +1 -1
  49. package/node_modules/@aspectcode/optimizer/dist/index.js +3 -5
  50. package/node_modules/@aspectcode/optimizer/dist/index.js.map +1 -1
  51. package/node_modules/@aspectcode/optimizer/dist/prompts.d.ts +8 -21
  52. package/node_modules/@aspectcode/optimizer/dist/prompts.d.ts.map +1 -1
  53. package/node_modules/@aspectcode/optimizer/dist/prompts.js +36 -94
  54. package/node_modules/@aspectcode/optimizer/dist/prompts.js.map +1 -1
  55. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.d.ts.map +1 -1
  56. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.js +10 -1
  57. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.js.map +1 -1
  58. package/node_modules/@aspectcode/optimizer/dist/providers/openai.d.ts.map +1 -1
  59. package/node_modules/@aspectcode/optimizer/dist/providers/openai.js +10 -1
  60. package/node_modules/@aspectcode/optimizer/dist/providers/openai.js.map +1 -1
  61. package/node_modules/@aspectcode/optimizer/dist/types.d.ts +33 -24
  62. package/node_modules/@aspectcode/optimizer/dist/types.d.ts.map +1 -1
  63. package/node_modules/@aspectcode/optimizer/dist/types.js.map +1 -1
  64. package/node_modules/@aspectcode/optimizer/package.json +2 -2
  65. package/package.json +3 -3
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
2
  /**
3
- * Prompt templates for the optimization agent.
3
+ * Prompt templates for the generation agent.
4
4
  *
5
- * Three prompts:
5
+ * Two prompts:
6
6
  * 1. System prompt — sets context with KB content.
7
- * 2. Optimize prompt — asks the LLM to refine instructions.
8
- * 3. Eval prompt — asks the LLM to score and critique a candidate.
7
+ * 2. Generate prompt — asks the LLM to generate AGENTS.md from scratch using KB.
9
8
  */
10
9
  Object.defineProperty(exports, "__esModule", { value: true });
11
10
  exports.truncateKb = truncateKb;
12
11
  exports.buildSystemPrompt = buildSystemPrompt;
13
- exports.buildOptimizePrompt = buildOptimizePrompt;
14
- exports.buildEvalPrompt = buildEvalPrompt;
15
- exports.parseEvalResponse = parseEvalResponse;
12
+ exports.buildGeneratePrompt = buildGeneratePrompt;
16
13
  exports.buildComplaintPrompt = buildComplaintPrompt;
17
14
  exports.parseComplaintResponse = parseComplaintResponse;
18
15
  /** Default maximum KB characters to include before truncation. */
@@ -40,18 +37,19 @@ function truncateKb(kb, charBudget = DEFAULT_KB_CHAR_BUDGET) {
40
37
  */
41
38
  function buildSystemPrompt(kb, kbCharBudget, toolInstructions) {
42
39
  const trimmedKb = truncateKb(kb, kbCharBudget);
43
- let prompt = `You are an expert AI coding assistant instruction optimizer.
40
+ let prompt = `You are an expert AI coding assistant instruction author.
44
41
 
45
- Your job is to improve AGENTS.md instructions — the guidelines that AI coding
46
- assistants follow when working in a codebase. You optimize these instructions
42
+ Your job is to generate AGENTS.md — the guidelines that AI coding assistants
43
+ follow when working in a codebase. You author these instructions from scratch
47
44
  so they are maximally useful, precise, and aligned with the actual codebase.
48
45
 
49
- Below is the project's internal knowledge base. Use it as YOUR private
50
- reference to understand the codebase — but NEVER reference it in the output.
51
- The AI assistant reading AGENTS.md will NOT have access to the knowledge base,
52
- Map section, symbol index, or any other external document. All codebase-specific
53
- guidance (file paths, naming conventions, key modules, architectural patterns)
54
- must be written directly as self-contained rules inside AGENTS.md.
46
+ Below is the project's internal knowledge base generated by static analysis.
47
+ Use it as YOUR private reference to understand the codebase — but NEVER
48
+ reference it in the output. The AI assistant reading AGENTS.md will NOT have
49
+ access to the knowledge base, Map section, symbol index, or any other external
50
+ document. All codebase-specific guidance (file paths, naming conventions, key
51
+ modules, architectural patterns) must be written directly as self-contained
52
+ rules inside AGENTS.md.
55
53
 
56
54
  Forbidden in output:
57
55
  - References to "the Map", "the KB", "the knowledge base", "the Context section"
@@ -75,94 +73,38 @@ ${toolInstructions}`;
75
73
  return prompt;
76
74
  }
77
75
  /**
78
- * Build the user prompt for instruction optimization.
76
+ * Build the user prompt for AGENTS.md generation.
79
77
  *
80
- * Includes the current instructions and optionally a KB diff showing
81
- * what changed in the codebase since the last generation.
78
+ * Asks the LLM to generate AGENTS.md from scratch using the KB
79
+ * (static analysis) provided in the system prompt as context.
80
+ * Optionally includes a KB diff for incremental regeneration.
82
81
  */
83
- function buildOptimizePrompt(currentInstructions, kbDiff, priorFeedback) {
84
- let prompt = `Optimize the following AGENTS.md instructions. Make them more specific,
85
- actionable, and self-contained.
86
-
87
- ## Rules
88
- - Keep the same overall structure (sections, headers) unless restructuring improves clarity.
89
- - Remove generic advice that any developer already knows.
90
- - Inline project-specific guidance (file paths, naming conventions, key modules, architectural
91
- patterns) directly as rules. Derive these from the knowledge base in the system prompt,
92
- but NEVER reference the knowledge base, Map, or any external document in the output.
93
- - AGENTS.md must be fully self-contained the AI reading it will have no other reference.
94
- - Be concise every line should earn its place.
95
- - Output ONLY the optimized instruction content (no explanations or markdown fences).
96
-
97
- ## Current Instructions
98
- ${currentInstructions}`;
82
+ function buildGeneratePrompt(kbDiff) {
83
+ let prompt = `Generate AGENTS.md instructions from scratch for this codebase.
84
+ Use the knowledge base in the system prompt to understand the project, then
85
+ produce specific, actionable coding guidelines tailored to THIS codebase.
86
+
87
+ ## Requirements
88
+ - Structure the output with clear sections: a brief project overview, golden rules,
89
+ a recommended workflow, code-change guidelines, and troubleshooting tips.
90
+ - Make every rule specific to THIS codebase. Inline actual file paths, naming conventions,
91
+ key modules, architecture patterns, entry points, and high-risk hubs.
92
+ - Derive all project-specific details from the knowledge base but NEVER reference the
93
+ knowledge base, Map, KB, or any external document in the output.
94
+ - AGENTS.md must be fully self-contained — the AI reading it has no other reference.
95
+ - Remove generic advice that any developer already knows. Every line should earn its place.
96
+ - Be concise but comprehensive — cover architecture, conventions, risk zones, and workflows.
97
+ - Output ONLY the instruction content (no explanations, preamble, or markdown fences).`;
99
98
  if (kbDiff) {
100
99
  prompt += `
101
100
 
102
101
  ## Recent KB Changes (diff)
103
- The following diff shows what changed in the knowledge base since the last generation.
104
- Focus your optimization on areas affected by these changes:
102
+ The following diff shows what changed in the codebase since the last generation.
103
+ Focus on areas affected by these changes:
105
104
  ${kbDiff}`;
106
- }
107
- if (priorFeedback) {
108
- prompt += `
109
-
110
- ## Prior Evaluation Feedback
111
- A previous iteration received this feedback. Address these points:
112
- ${priorFeedback}`;
113
105
  }
114
106
  return prompt;
115
107
  }
116
- /**
117
- * Build the evaluation prompt that asks the LLM to score and critique
118
- * a candidate set of instructions.
119
- */
120
- function buildEvalPrompt(candidateInstructions, kb, kbCharBudget) {
121
- const trimmedKb = truncateKb(kb, kbCharBudget);
122
- return `You are evaluating AI coding assistant instructions (AGENTS.md) for quality.
123
-
124
- Score the following candidate instructions on a scale of 1–10 based on:
125
- 1. **Specificity** — Are rules grounded in the actual codebase (real file paths, real patterns), not generic?
126
- 2. **Actionability** — Can an AI assistant follow each rule unambiguously?
127
- 3. **Completeness** — Are key architectural patterns and conventions covered?
128
- 4. **Conciseness** — Is every line valuable, with no filler?
129
- 5. **Self-contained** — Are ALL rules fully inline? The AI reading AGENTS.md will NOT have
130
- access to any external document. Penalize any reference to "the Map", "the KB",
131
- "the knowledge base", "kb.md", "the symbol index", or similar external documents.
132
-
133
- Respond in EXACTLY this format (no other text):
134
- SCORE: <number 1-10>
135
- FEEDBACK: <one paragraph of overall assessment>
136
- SUGGESTIONS:
137
- - <specific improvement 1>
138
- - <specific improvement 2>
139
- - <specific improvement 3>
140
-
141
- ## Knowledge Base (private reference — do not expect in output)
142
- ${trimmedKb}
143
-
144
- ## Candidate Instructions
145
- ${candidateInstructions}`;
146
- }
147
- /**
148
- * Parse the structured evaluation response into an EvalResult.
149
- */
150
- function parseEvalResponse(response) {
151
- const scoreMatch = response.match(/SCORE:\s*(\d+)/i);
152
- const score = scoreMatch ? Math.min(10, Math.max(1, parseInt(scoreMatch[1], 10))) : 5;
153
- const feedbackMatch = response.match(/FEEDBACK:\s*(.+?)(?=SUGGESTIONS:|$)/is);
154
- const feedback = feedbackMatch ? feedbackMatch[1].trim() : 'No feedback provided.';
155
- const suggestionsMatch = response.match(/SUGGESTIONS:\s*([\s\S]*)/i);
156
- const suggestions = [];
157
- if (suggestionsMatch) {
158
- for (const line of suggestionsMatch[1].split('\n')) {
159
- const trimmed = line.replace(/^[-*]\s*/, '').trim();
160
- if (trimmed)
161
- suggestions.push(trimmed);
162
- }
163
- }
164
- return { score, feedback, suggestions };
165
- }
166
108
  // ── Complaint-driven prompts ─────────────────────────────────
167
109
  /**
168
110
  * Build a prompt that instructs the LLM to address specific user complaints
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AASH,gCAeC;AAMD,8CAsCC;AAQD,kDAuCC;AAMD,0CA+BC;AAKD,8CAqBC;AAQD,oDAmCC;AAKD,wDAoBC;AApPD,kEAAkE;AAClE,MAAM,sBAAsB,GAAG,KAAM,CAAC;AAEtC;;;GAGG;AACH,SAAgB,UAAU,CAAC,EAAU,EAAE,aAAqB,sBAAsB;IAChF,IAAI,EAAE,CAAC,MAAM,IAAI,UAAU;QAAE,OAAO,EAAE,CAAC;IAEvC,8CAA8C;IAC9C,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,UAAU,GAAG,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ic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAA2B,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAOtF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,WAAW,CA+F9F"}
@@ -71,6 +71,10 @@ function createAnthropicProvider(apiKey, options) {
71
71
  return {
72
72
  name: 'anthropic',
73
73
  async chat(messages) {
74
+ const result = await this.chatWithUsage(messages);
75
+ return result.content;
76
+ },
77
+ async chatWithUsage(messages) {
74
78
  return (0, retry_1.withRetry)(async () => {
75
79
  const client = await getClient();
76
80
  // Anthropic handles system prompts as a separate field,
@@ -118,7 +122,12 @@ function createAnthropicProvider(apiKey, options) {
118
122
  console.warn(`[optimizer] Anthropic response truncated (stop_reason=max_tokens). ` +
119
123
  `Consider increasing maxTokens (currently ${maxTokens}).`);
120
124
  }
121
- return content;
125
+ return {
126
+ content,
127
+ usage: response.usage
128
+ ? { inputTokens: response.usage.input_tokens, outputTokens: response.usage.output_tokens }
129
+ : undefined,
130
+ };
122
131
  });
123
132
  },
124
133
  };
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBH,0DAqFC;AAlGD,mCAAoC;AAEpC,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,MAAc,EAAE,OAAyB;IAC/E,MAAM,OAAO,GAAG,OAAO,EAAE,KAAK,IAAI,aAAa,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,EAAE,WAA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CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,OAAO;oBACP,KAAK,EAAE,QAAQ,CAAC,KAAK;wBACnB,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE;wBAC1F,CAAC,CAAC,SAAS;iBACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO1E;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,WAAW,CAkD3F"}
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAA2B,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAOtF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,WAAW,CA4D3F"}
@@ -69,6 +69,10 @@ function createOpenAiProvider(apiKey, options) {
69
69
  return {
70
70
  name: 'openai',
71
71
  async chat(messages) {
72
+ const result = await this.chatWithUsage(messages);
73
+ return result.content;
74
+ },
75
+ async chatWithUsage(messages) {
72
76
  return (0, retry_1.withRetry)(async () => {
73
77
  const client = await getClient();
74
78
  const response = await client.chat.completions.create({
@@ -90,7 +94,12 @@ function createOpenAiProvider(apiKey, options) {
90
94
  console.warn(`[optimizer] OpenAI response truncated (finish_reason=length). ` +
91
95
  `Consider increasing maxTokens (currently ${maxTokens}).`);
92
96
  }
93
- return content;
97
+ return {
98
+ content,
99
+ usage: response.usage
100
+ ? { inputTokens: response.usage.prompt_tokens, outputTokens: response.usage.completion_tokens }
101
+ : undefined,
102
+ };
94
103
  });
95
104
  },
96
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBH,oDAkDC;AA/DD,mCAAoC;AAEpC,MAAM,aAAa,GAAG,aAAa,CAAC;AACpC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,MAAc,EAAE,OAAyB;IAC5E,MAAM,OAAO,GAAG,OAAO,EAAE,KAAK,IAAI,aAAa,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,mBAAmB,CAAC;IAChE,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,kBAAkB,CAAC;IAE3D,oCAAoC;IACpC,IAAI,aAAiF,CAAC;IAEtF,KAAK,UAAU,SAAS;QACtB,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,aAAa,GAAG,kDAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QAEd,KAAK,CAAC,IAAI,CAAC,QAAuB;YAChC,OAAO,IAAA,iBAAS,EAAC,KAAK,IAAI,EAAE;gBAC1B,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;gBAEjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAA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gBACvD,CAAC;gBAED,2BAA2B;gBAC3B,IAAI,MAAM,CAAC,aAAa,KAAK,QAAQ,EAAE,CAAC;oBACtC,OAAO,CAAC,IAAI,CACV,gEAAgE;wBAChE,4CAA4C,SAAS,IAAI,CAC1D,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,OAAO;oBACP,KAAK,EAAE,QAAQ,CAAC,KAAK;wBACnB,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,iBAAiB,EAAE;wBAC/F,CAAC,CAAC,SAAS;iBACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -9,6 +9,16 @@ export interface ChatMessage {
9
9
  role: 'system' | 'user' | 'assistant';
10
10
  content: string;
11
11
  }
12
+ /** Token usage from a single LLM call. */
13
+ export interface ChatUsage {
14
+ inputTokens: number;
15
+ outputTokens: number;
16
+ }
17
+ /** Result from an LLM call that includes optional token usage. */
18
+ export interface ChatResult {
19
+ content: string;
20
+ usage?: ChatUsage;
21
+ }
12
22
  /**
13
23
  * Provider-agnostic LLM interface.
14
24
  *
@@ -20,6 +30,11 @@ export interface LlmProvider {
20
30
  readonly name: string;
21
31
  /** Send a chat completion request and return the assistant reply. */
22
32
  chat(messages: ChatMessage[]): Promise<string>;
33
+ /**
34
+ * Send a chat completion request and return the reply with token usage.
35
+ * Optional — providers that don't implement this fall back to `chat()`.
36
+ */
37
+ chatWithUsage?(messages: ChatMessage[]): Promise<ChatResult>;
23
38
  }
24
39
  /** Options passed to provider factory functions. */
25
40
  export interface ProviderOptions {
@@ -37,54 +52,48 @@ export interface OptLogger {
37
52
  error(msg: string): void;
38
53
  debug(msg: string): void;
39
54
  }
40
- /** Options for a single optimization run. */
55
+ /** Options for a single generation run. */
41
56
  export interface OptimizeOptions {
42
- /** Current AGENTS.md content. */
43
- currentInstructions: string;
57
+ /**
58
+ * Fallback content returned when the LLM call fails or is cancelled.
59
+ * When omitted, an empty string is used as the fallback.
60
+ */
61
+ currentInstructions?: string;
44
62
  /** Full KB content (architecture + map + context). */
45
63
  kb: string;
46
64
  /** Line-level diff of KB changes (undefined on first run). */
47
65
  kbDiff?: string;
48
66
  /** Concatenated content from other AI tool instruction files (read-only context). */
49
67
  toolInstructions?: string;
50
- /** Maximum agent iterations (optimize → eval → refine). */
51
- maxIterations: number;
52
68
  /** LLM provider to use. */
53
69
  provider: LlmProvider;
54
70
  /** Optional logger for progress reporting. */
55
71
  log?: OptLogger;
56
- /** Minimum eval score (1–10) to accept a candidate without further iteration. Default: 8. */
57
- acceptThreshold?: number;
58
72
  /** AbortSignal for cooperative cancellation. */
59
73
  signal?: AbortSignal;
60
- /** Delay in ms between iterations to avoid rate limiting. Default: 0. */
61
- iterationDelayMs?: number;
62
74
  /** Character budget for KB content in prompts. Default: 60000. */
63
75
  kbCharBudget?: number;
64
76
  /**
65
- * Feedback from the evaluator package (probe test results).
66
- * When provided, this replaces or supplements the self-eval loop.
67
- * Formatted as a human-readable summary of probe failures and diagnosis.
77
+ * Progress callback invoked at each meaningful step inside the agent.
78
+ * Useful for updating a CLI dashboard or progress bar.
68
79
  */
69
- evaluatorFeedback?: string;
80
+ onProgress?: (step: OptimizeStep) => void;
70
81
  }
71
- /** Self-evaluation result from one iteration. */
72
- export interface EvalResult {
73
- /** Quality score 1–10. */
74
- score: number;
75
- /** Free-text feedback on the candidate. */
76
- feedback: string;
77
- /** Concrete improvement suggestions. */
78
- suggestions: string[];
82
+ /** Progress step emitted by the optimization agent via `onProgress`. */
83
+ export interface OptimizeStep {
84
+ /** Which sub-step is running. */
85
+ kind: 'generating' | 'done';
86
+ /** Optional human-readable detail. */
87
+ detail?: string;
79
88
  }
80
89
  /** Final result of the optimization agent. */
81
90
  export interface OptimizeResult {
82
91
  /** The optimized instructions content (to be placed between markers). */
83
92
  optimizedInstructions: string;
84
- /** Number of iterations actually executed. */
85
- iterations: number;
86
- /** Per-iteration reasoning / eval feedback. */
93
+ /** Human-readable reasoning / status messages. */
87
94
  reasoning: string[];
95
+ /** Aggregate token usage across all LLM calls in this run. */
96
+ usage?: ChatUsage;
88
97
  }
89
98
  /** Supported provider keys looked up in the environment. */
90
99
  export declare const PROVIDER_ENV_KEYS: {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,qEAAqE;IACrE,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChD;AAED,oDAAoD;AACpD,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,sDAAsD;AACtD,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAE5B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IAEX,8DAA8D;IAC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AAE,SAAS,CAAC;CACnB;AAID,4DAA4D;AAC5D,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAI1D,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAE5B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IAEX,+DAA+D;IAC/D,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB,2BAA2B;IAC3B,QAAQ,EAAE,WAAW,CAAC;IAEtB,uBAAuB;IACvB,GAAG,CAAC,EAAE,SAAS,CAAC;IAEhB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,gDAAgD;IAChD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,+CAA+C;AAC/C,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAE9B,kEAAkE;IAClE,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qDAAqD;AACrD,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,sDAAsD;AACtD,eAAO,MAAM,aAAa,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA+GH,+DAA+D;AAE/D,4DAA4D;AAC/C,QAAA,iBAAiB,GAAG;IAC/B,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;CACtB,CAAC;AAuCX,qDAAqD;AACxC,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAE/C,sDAAsD;AACzC,QAAA,aAAa,GAAG,WAAW,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAsHH,+DAA+D;AAE/D,4DAA4D;AAC/C,QAAA,iBAAiB,GAAG;IAC/B,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;CACtB,CAAC;AAuCX,qDAAqD;AACxC,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAE/C,sDAAsD;AACzC,QAAA,aAAa,GAAG,WAAW,CAAC"}
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@aspectcode/optimizer",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "private": true,
5
- "description": "LLM-powered instruction optimizer for Aspect Code",
5
+ "description": "LLM-powered instruction generator for Aspect Code",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aspectcode",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "CLI for Aspect Code — generate knowledge-base artifacts from the command line",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",
@@ -51,8 +51,8 @@
51
51
  "@anthropic-ai/sdk": "^0.39.0",
52
52
  "@aspectcode/core": "0.3.1",
53
53
  "@aspectcode/emitters": "0.3.4",
54
- "@aspectcode/evaluator": "0.3.4",
55
- "@aspectcode/optimizer": "0.3.4",
54
+ "@aspectcode/evaluator": "0.4.0",
55
+ "@aspectcode/optimizer": "0.4.0",
56
56
  "chokidar": "^4.0.3",
57
57
  "dotenv": "^16.4.0",
58
58
  "ink": "3.2.0",