aspectcode 0.4.0 → 1.0.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 (242) hide show
  1. package/README.md +13 -0
  2. package/dist/agentsMdRenderer.d.ts +16 -0
  3. package/dist/agentsMdRenderer.d.ts.map +1 -0
  4. package/dist/agentsMdRenderer.js +137 -0
  5. package/dist/agentsMdRenderer.js.map +1 -0
  6. package/dist/auth.d.ts +31 -0
  7. package/dist/auth.d.ts.map +1 -0
  8. package/dist/auth.js +385 -0
  9. package/dist/auth.js.map +1 -0
  10. package/dist/autoResolve.d.ts +41 -0
  11. package/dist/autoResolve.d.ts.map +1 -0
  12. package/dist/autoResolve.js +196 -0
  13. package/dist/autoResolve.js.map +1 -0
  14. package/dist/changeEvaluator.d.ts +56 -0
  15. package/dist/changeEvaluator.d.ts.map +1 -0
  16. package/dist/changeEvaluator.js +674 -0
  17. package/dist/changeEvaluator.js.map +1 -0
  18. package/dist/cli.d.ts +12 -1
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/cli.js +1 -1
  21. package/dist/cli.js.map +1 -1
  22. package/dist/config.d.ts +37 -17
  23. package/dist/config.d.ts.map +1 -1
  24. package/dist/config.js +50 -2
  25. package/dist/config.js.map +1 -1
  26. package/dist/dreamCycle.d.ts +57 -0
  27. package/dist/dreamCycle.d.ts.map +1 -0
  28. package/dist/dreamCycle.js +334 -0
  29. package/dist/dreamCycle.js.map +1 -0
  30. package/dist/kbBuilder.d.ts +1 -2
  31. package/dist/kbBuilder.d.ts.map +1 -1
  32. package/dist/kbBuilder.js +1 -2
  33. package/dist/kbBuilder.js.map +1 -1
  34. package/dist/main.d.ts +2 -1
  35. package/dist/main.d.ts.map +1 -1
  36. package/dist/main.js +149 -8
  37. package/dist/main.js.map +1 -1
  38. package/dist/optimize.d.ts +13 -6
  39. package/dist/optimize.d.ts.map +1 -1
  40. package/dist/optimize.js +433 -142
  41. package/dist/optimize.js.map +1 -1
  42. package/dist/pipeline.d.ts +21 -18
  43. package/dist/pipeline.d.ts.map +1 -1
  44. package/dist/pipeline.js +1139 -162
  45. package/dist/pipeline.js.map +1 -1
  46. package/dist/preferences.d.ts +80 -0
  47. package/dist/preferences.d.ts.map +1 -0
  48. package/dist/preferences.js +238 -0
  49. package/dist/preferences.js.map +1 -0
  50. package/dist/runtimeState.d.ts +30 -0
  51. package/dist/runtimeState.d.ts.map +1 -0
  52. package/dist/runtimeState.js +39 -0
  53. package/dist/runtimeState.js.map +1 -0
  54. package/dist/scopedRules.d.ts +84 -0
  55. package/dist/scopedRules.d.ts.map +1 -0
  56. package/dist/scopedRules.js +449 -0
  57. package/dist/scopedRules.js.map +1 -0
  58. package/dist/ui/Dashboard.d.ts +4 -16
  59. package/dist/ui/Dashboard.d.ts.map +1 -1
  60. package/dist/ui/Dashboard.js +339 -141
  61. package/dist/ui/Dashboard.js.map +1 -1
  62. package/dist/ui/MemoryMap.d.ts +16 -0
  63. package/dist/ui/MemoryMap.d.ts.map +1 -0
  64. package/dist/ui/MemoryMap.js +266 -0
  65. package/dist/ui/MemoryMap.js.map +1 -0
  66. package/dist/ui/SettingsPanel.d.ts +18 -0
  67. package/dist/ui/SettingsPanel.d.ts.map +1 -0
  68. package/dist/ui/SettingsPanel.js +241 -0
  69. package/dist/ui/SettingsPanel.js.map +1 -0
  70. package/dist/ui/prompts.d.ts +7 -0
  71. package/dist/ui/prompts.d.ts.map +1 -1
  72. package/dist/ui/prompts.js +63 -0
  73. package/dist/ui/prompts.js.map +1 -1
  74. package/dist/ui/store.d.ts +154 -18
  75. package/dist/ui/store.d.ts.map +1 -1
  76. package/dist/ui/store.js +154 -24
  77. package/dist/ui/store.js.map +1 -1
  78. package/dist/ui/theme.d.ts +1 -8
  79. package/dist/ui/theme.d.ts.map +1 -1
  80. package/dist/ui/theme.js +2 -20
  81. package/dist/ui/theme.js.map +1 -1
  82. package/dist/updateChecker.d.ts +13 -0
  83. package/dist/updateChecker.d.ts.map +1 -0
  84. package/dist/updateChecker.js +66 -0
  85. package/dist/updateChecker.js.map +1 -0
  86. package/dist/usageTracker.d.ts +12 -0
  87. package/dist/usageTracker.d.ts.map +1 -0
  88. package/dist/usageTracker.js +89 -0
  89. package/dist/usageTracker.js.map +1 -0
  90. package/dist/writer.d.ts +1 -7
  91. package/dist/writer.d.ts.map +1 -1
  92. package/dist/writer.js +1 -11
  93. package/dist/writer.js.map +1 -1
  94. package/node_modules/@aspectcode/core/dist/analysis/repo.d.ts.map +1 -1
  95. package/node_modules/@aspectcode/core/dist/analysis/repo.js +13 -2
  96. package/node_modules/@aspectcode/core/dist/analysis/repo.js.map +1 -1
  97. package/node_modules/@aspectcode/core/dist/index.d.ts +1 -3
  98. package/node_modules/@aspectcode/core/dist/index.d.ts.map +1 -1
  99. package/node_modules/@aspectcode/core/dist/index.js +1 -3
  100. package/node_modules/@aspectcode/core/dist/index.js.map +1 -1
  101. package/node_modules/@aspectcode/core/dist/parsers/genericExtractors.d.ts +14 -0
  102. package/node_modules/@aspectcode/core/dist/parsers/genericExtractors.d.ts.map +1 -0
  103. package/node_modules/@aspectcode/core/dist/parsers/genericExtractors.js +191 -0
  104. package/node_modules/@aspectcode/core/dist/parsers/genericExtractors.js.map +1 -0
  105. package/node_modules/@aspectcode/core/dist/parsers/index.d.ts +1 -0
  106. package/node_modules/@aspectcode/core/dist/parsers/index.d.ts.map +1 -1
  107. package/node_modules/@aspectcode/core/dist/parsers/index.js +6 -1
  108. package/node_modules/@aspectcode/core/dist/parsers/index.js.map +1 -1
  109. package/node_modules/@aspectcode/core/dist/parsers/languages.d.ts +20 -0
  110. package/node_modules/@aspectcode/core/dist/parsers/languages.d.ts.map +1 -1
  111. package/node_modules/@aspectcode/core/dist/parsers/languages.js +25 -0
  112. package/node_modules/@aspectcode/core/dist/parsers/languages.js.map +1 -1
  113. package/node_modules/@aspectcode/core/dist/parsers/tsJsExtractors.d.ts.map +1 -1
  114. package/node_modules/@aspectcode/core/dist/parsers/tsJsExtractors.js +4 -1
  115. package/node_modules/@aspectcode/core/dist/parsers/tsJsExtractors.js.map +1 -1
  116. package/node_modules/@aspectcode/core/package.json +2 -2
  117. package/node_modules/@aspectcode/core/parsers/cpp.wasm +0 -0
  118. package/node_modules/@aspectcode/core/parsers/go.wasm +0 -0
  119. package/node_modules/@aspectcode/core/parsers/php.wasm +0 -0
  120. package/node_modules/@aspectcode/core/parsers/ruby.wasm +0 -0
  121. package/node_modules/@aspectcode/core/parsers/rust.wasm +0 -0
  122. package/node_modules/@aspectcode/emitters/dist/index.d.ts +1 -17
  123. package/node_modules/@aspectcode/emitters/dist/index.d.ts.map +1 -1
  124. package/node_modules/@aspectcode/emitters/dist/index.js +2 -89
  125. package/node_modules/@aspectcode/emitters/dist/index.js.map +1 -1
  126. package/node_modules/@aspectcode/emitters/dist/instructions/index.d.ts +0 -2
  127. package/node_modules/@aspectcode/emitters/dist/instructions/index.d.ts.map +1 -1
  128. package/node_modules/@aspectcode/emitters/dist/instructions/index.js +1 -7
  129. package/node_modules/@aspectcode/emitters/dist/instructions/index.js.map +1 -1
  130. package/node_modules/@aspectcode/emitters/dist/kb/analyzers.d.ts +0 -18
  131. package/node_modules/@aspectcode/emitters/dist/kb/analyzers.d.ts.map +1 -1
  132. package/node_modules/@aspectcode/emitters/dist/kb/analyzers.js +0 -57
  133. package/node_modules/@aspectcode/emitters/dist/kb/analyzers.js.map +1 -1
  134. package/node_modules/@aspectcode/emitters/dist/kb/conventions.d.ts +0 -18
  135. package/node_modules/@aspectcode/emitters/dist/kb/conventions.d.ts.map +1 -1
  136. package/node_modules/@aspectcode/emitters/dist/kb/conventions.js +0 -130
  137. package/node_modules/@aspectcode/emitters/dist/kb/conventions.js.map +1 -1
  138. package/node_modules/@aspectcode/emitters/dist/kb/index.d.ts +2 -4
  139. package/node_modules/@aspectcode/emitters/dist/kb/index.d.ts.map +1 -1
  140. package/node_modules/@aspectcode/emitters/dist/kb/index.js +1 -11
  141. package/node_modules/@aspectcode/emitters/dist/kb/index.js.map +1 -1
  142. package/node_modules/@aspectcode/emitters/package.json +3 -3
  143. package/node_modules/@aspectcode/evaluator/dist/apply.d.ts +55 -0
  144. package/node_modules/@aspectcode/evaluator/dist/apply.d.ts.map +1 -0
  145. package/node_modules/@aspectcode/evaluator/dist/apply.js +368 -0
  146. package/node_modules/@aspectcode/evaluator/dist/apply.js.map +1 -0
  147. package/node_modules/@aspectcode/evaluator/dist/diagnosis.d.ts +16 -25
  148. package/node_modules/@aspectcode/evaluator/dist/diagnosis.d.ts.map +1 -1
  149. package/node_modules/@aspectcode/evaluator/dist/diagnosis.js +115 -138
  150. package/node_modules/@aspectcode/evaluator/dist/diagnosis.js.map +1 -1
  151. package/node_modules/@aspectcode/evaluator/dist/index.d.ts +8 -43
  152. package/node_modules/@aspectcode/evaluator/dist/index.d.ts.map +1 -1
  153. package/node_modules/@aspectcode/evaluator/dist/index.js +15 -61
  154. package/node_modules/@aspectcode/evaluator/dist/index.js.map +1 -1
  155. package/node_modules/@aspectcode/evaluator/dist/judge.d.ts +32 -0
  156. package/node_modules/@aspectcode/evaluator/dist/judge.d.ts.map +1 -0
  157. package/node_modules/@aspectcode/evaluator/dist/judge.js +165 -0
  158. package/node_modules/@aspectcode/evaluator/dist/judge.js.map +1 -0
  159. package/node_modules/@aspectcode/evaluator/dist/llmUtil.d.ts +15 -0
  160. package/node_modules/@aspectcode/evaluator/dist/llmUtil.d.ts.map +1 -0
  161. package/node_modules/@aspectcode/evaluator/dist/llmUtil.js +41 -0
  162. package/node_modules/@aspectcode/evaluator/dist/llmUtil.js.map +1 -0
  163. package/node_modules/@aspectcode/evaluator/dist/probes.d.ts +20 -29
  164. package/node_modules/@aspectcode/evaluator/dist/probes.d.ts.map +1 -1
  165. package/node_modules/@aspectcode/evaluator/dist/probes.js +188 -204
  166. package/node_modules/@aspectcode/evaluator/dist/probes.js.map +1 -1
  167. package/node_modules/@aspectcode/evaluator/dist/runner.d.ts +7 -32
  168. package/node_modules/@aspectcode/evaluator/dist/runner.d.ts.map +1 -1
  169. package/node_modules/@aspectcode/evaluator/dist/runner.js +21 -146
  170. package/node_modules/@aspectcode/evaluator/dist/runner.js.map +1 -1
  171. package/node_modules/@aspectcode/evaluator/dist/types.d.ts +141 -99
  172. package/node_modules/@aspectcode/evaluator/dist/types.d.ts.map +1 -1
  173. package/node_modules/@aspectcode/evaluator/dist/types.js +10 -2
  174. package/node_modules/@aspectcode/evaluator/dist/types.js.map +1 -1
  175. package/node_modules/@aspectcode/evaluator/package.json +4 -4
  176. package/node_modules/@aspectcode/optimizer/dist/index.d.ts +3 -10
  177. package/node_modules/@aspectcode/optimizer/dist/index.d.ts.map +1 -1
  178. package/node_modules/@aspectcode/optimizer/dist/index.js +1 -19
  179. package/node_modules/@aspectcode/optimizer/dist/index.js.map +1 -1
  180. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.d.ts.map +1 -1
  181. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.js +40 -0
  182. package/node_modules/@aspectcode/optimizer/dist/providers/anthropic.js.map +1 -1
  183. package/node_modules/@aspectcode/optimizer/dist/providers/aspectcode.d.ts +9 -0
  184. package/node_modules/@aspectcode/optimizer/dist/providers/aspectcode.d.ts.map +1 -0
  185. package/node_modules/@aspectcode/optimizer/dist/providers/aspectcode.js +83 -0
  186. package/node_modules/@aspectcode/optimizer/dist/providers/aspectcode.js.map +1 -0
  187. package/node_modules/@aspectcode/optimizer/dist/providers/index.d.ts +4 -3
  188. package/node_modules/@aspectcode/optimizer/dist/providers/index.d.ts.map +1 -1
  189. package/node_modules/@aspectcode/optimizer/dist/providers/index.js +24 -10
  190. package/node_modules/@aspectcode/optimizer/dist/providers/index.js.map +1 -1
  191. package/node_modules/@aspectcode/optimizer/dist/providers/openai.d.ts.map +1 -1
  192. package/node_modules/@aspectcode/optimizer/dist/providers/openai.js +22 -0
  193. package/node_modules/@aspectcode/optimizer/dist/providers/openai.js.map +1 -1
  194. package/node_modules/@aspectcode/optimizer/dist/providers/retry.d.ts +14 -0
  195. package/node_modules/@aspectcode/optimizer/dist/providers/retry.d.ts.map +1 -1
  196. package/node_modules/@aspectcode/optimizer/dist/providers/retry.js +1 -0
  197. package/node_modules/@aspectcode/optimizer/dist/providers/retry.js.map +1 -1
  198. package/node_modules/@aspectcode/optimizer/dist/types.d.ts +14 -0
  199. package/node_modules/@aspectcode/optimizer/dist/types.d.ts.map +1 -1
  200. package/node_modules/@aspectcode/optimizer/dist/types.js.map +1 -1
  201. package/node_modules/@aspectcode/optimizer/package.json +2 -2
  202. package/package.json +6 -7
  203. package/dist/complaintProcessor.d.ts +0 -16
  204. package/dist/complaintProcessor.d.ts.map +0 -1
  205. package/dist/complaintProcessor.js +0 -134
  206. package/dist/complaintProcessor.js.map +0 -1
  207. package/node_modules/@aspectcode/emitters/dist/emitter.d.ts +0 -72
  208. package/node_modules/@aspectcode/emitters/dist/emitter.d.ts.map +0 -1
  209. package/node_modules/@aspectcode/emitters/dist/emitter.js +0 -10
  210. package/node_modules/@aspectcode/emitters/dist/emitter.js.map +0 -1
  211. package/node_modules/@aspectcode/emitters/dist/instructions/content.d.ts +0 -15
  212. package/node_modules/@aspectcode/emitters/dist/instructions/content.d.ts.map +0 -1
  213. package/node_modules/@aspectcode/emitters/dist/instructions/content.js +0 -289
  214. package/node_modules/@aspectcode/emitters/dist/instructions/content.js.map +0 -1
  215. package/node_modules/@aspectcode/emitters/dist/instructions/detection.d.ts +0 -13
  216. package/node_modules/@aspectcode/emitters/dist/instructions/detection.d.ts.map +0 -1
  217. package/node_modules/@aspectcode/emitters/dist/instructions/detection.js +0 -55
  218. package/node_modules/@aspectcode/emitters/dist/instructions/detection.js.map +0 -1
  219. package/node_modules/@aspectcode/emitters/dist/instructions/instructionsEmitter.d.ts +0 -9
  220. package/node_modules/@aspectcode/emitters/dist/instructions/instructionsEmitter.d.ts.map +0 -1
  221. package/node_modules/@aspectcode/emitters/dist/instructions/instructionsEmitter.js +0 -30
  222. package/node_modules/@aspectcode/emitters/dist/instructions/instructionsEmitter.js.map +0 -1
  223. package/node_modules/@aspectcode/emitters/dist/kb/kbEmitter.d.ts +0 -21
  224. package/node_modules/@aspectcode/emitters/dist/kb/kbEmitter.d.ts.map +0 -1
  225. package/node_modules/@aspectcode/emitters/dist/kb/kbEmitter.js +0 -125
  226. package/node_modules/@aspectcode/emitters/dist/kb/kbEmitter.js.map +0 -1
  227. package/node_modules/@aspectcode/emitters/dist/manifest.d.ts +0 -37
  228. package/node_modules/@aspectcode/emitters/dist/manifest.d.ts.map +0 -1
  229. package/node_modules/@aspectcode/emitters/dist/manifest.js +0 -50
  230. package/node_modules/@aspectcode/emitters/dist/manifest.js.map +0 -1
  231. package/node_modules/@aspectcode/emitters/dist/report.d.ts +0 -22
  232. package/node_modules/@aspectcode/emitters/dist/report.d.ts.map +0 -1
  233. package/node_modules/@aspectcode/emitters/dist/report.js +0 -3
  234. package/node_modules/@aspectcode/emitters/dist/report.js.map +0 -1
  235. package/node_modules/@aspectcode/emitters/dist/stableJson.d.ts +0 -14
  236. package/node_modules/@aspectcode/emitters/dist/stableJson.d.ts.map +0 -1
  237. package/node_modules/@aspectcode/emitters/dist/stableJson.js +0 -40
  238. package/node_modules/@aspectcode/emitters/dist/stableJson.js.map +0 -1
  239. package/node_modules/@aspectcode/emitters/dist/transaction.d.ts +0 -29
  240. package/node_modules/@aspectcode/emitters/dist/transaction.d.ts.map +0 -1
  241. package/node_modules/@aspectcode/emitters/dist/transaction.js +0 -104
  242. package/node_modules/@aspectcode/emitters/dist/transaction.js.map +0 -1
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Deterministic edit application for AGENTS.md.
3
+ *
4
+ * Applies structured edits (add/modify/strengthen/remove) to AGENTS.md
5
+ * using pure markdown manipulation — no LLM calls.
6
+ * Enforces a character budget with priority-based trimming.
7
+ *
8
+ * Ported from sweagent_bench oracle/apply.py.
9
+ */
10
+ import type { AgentsEdit, ApplyResult } from './types';
11
+ /** Default character budget for AGENTS.md. */
12
+ export declare const AGENTS_MD_CHAR_BUDGET = 8000;
13
+ /** Canonical section names allowed in AGENTS.md. */
14
+ declare const CANONICAL_SECTIONS: readonly ["Operating Mode", "Procedural Standards", "High-Impact Hubs", "Entry Points", "Import Chains", "Validation", "Integration Risk", "Conventions", "Guardrails"];
15
+ type CanonicalSection = typeof CANONICAL_SECTIONS[number];
16
+ export declare function isBoilerplate(content: string): boolean;
17
+ export interface ParsedSection {
18
+ title: string;
19
+ level: number;
20
+ lines: string[];
21
+ raw: string;
22
+ }
23
+ /**
24
+ * Parse AGENTS.md into sections by heading.
25
+ * Each section captures all content until the next heading of same or higher level.
26
+ */
27
+ export declare function parseSections(md: string): ParsedSection[];
28
+ /** Canonicalize a section name to its canonical form. */
29
+ export declare function canonicalize(sectionName: string): CanonicalSection | undefined;
30
+ /**
31
+ * Apply a list of edits to AGENTS.md content deterministically.
32
+ *
33
+ * - add/modify/strengthen: append bullet to section
34
+ * - remove: fuzzy-match and remove matching lines
35
+ * - Enforces character budget with priority-based trimming
36
+ */
37
+ export declare function applyEdits(agentsMd: string, edits: AgentsEdit[], charBudget?: number): ApplyResult;
38
+ /**
39
+ * Trim bullets from lowest-priority sections to fit within the character budget.
40
+ * Within a priority tier, longest bullets are shed first.
41
+ */
42
+ export declare function trimToBudget(sections: ParsedSection[], budget: number): {
43
+ content: string;
44
+ trimmed: number;
45
+ };
46
+ import type { LlmProvider } from '@aspectcode/optimizer';
47
+ /**
48
+ * Apply edits with LLM assistance when content exceeds budget or
49
+ * multiple edits target the same section.
50
+ *
51
+ * Falls back to deterministic apply if LLM fails.
52
+ */
53
+ export declare function applyEditsWithLlm(agentsMd: string, edits: AgentsEdit[], charBudget: number, provider: LlmProvider, signal?: AbortSignal): Promise<ApplyResult>;
54
+ export {};
55
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../src/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,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/**
3
+ * Deterministic edit application for AGENTS.md.
4
+ *
5
+ * Applies structured edits (add/modify/strengthen/remove) to AGENTS.md
6
+ * using pure markdown manipulation — no LLM calls.
7
+ * Enforces a character budget with priority-based trimming.
8
+ *
9
+ * Ported from sweagent_bench oracle/apply.py.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AGENTS_MD_CHAR_BUDGET = void 0;
13
+ exports.isBoilerplate = isBoilerplate;
14
+ exports.parseSections = parseSections;
15
+ exports.canonicalize = canonicalize;
16
+ exports.applyEdits = applyEdits;
17
+ exports.trimToBudget = trimToBudget;
18
+ exports.applyEditsWithLlm = applyEditsWithLlm;
19
+ /** Default character budget for AGENTS.md. */
20
+ exports.AGENTS_MD_CHAR_BUDGET = 8000;
21
+ // ── Canonical sections ──────────────────────────────────────
22
+ /** Canonical section names allowed in AGENTS.md. */
23
+ const CANONICAL_SECTIONS = [
24
+ 'Operating Mode',
25
+ 'Procedural Standards',
26
+ 'High-Impact Hubs',
27
+ 'Entry Points',
28
+ 'Import Chains',
29
+ 'Validation',
30
+ 'Integration Risk',
31
+ 'Conventions',
32
+ 'Guardrails',
33
+ ];
34
+ /** Map common LLM-invented aliases to canonical section names. */
35
+ const SECTION_ALIASES = {
36
+ // Operating Mode
37
+ 'operating mode': 'Operating Mode',
38
+ 'workflow': 'Operating Mode',
39
+ 'operating': 'Operating Mode',
40
+ 'mode': 'Operating Mode',
41
+ // Procedural Standards
42
+ 'procedural standards': 'Procedural Standards',
43
+ 'procedural': 'Procedural Standards',
44
+ 'standards': 'Procedural Standards',
45
+ 'procedures': 'Procedural Standards',
46
+ 'process': 'Procedural Standards',
47
+ // High-Impact Hubs
48
+ 'high-impact hubs': 'High-Impact Hubs',
49
+ 'hubs': 'High-Impact Hubs',
50
+ 'high impact hubs': 'High-Impact Hubs',
51
+ 'hub': 'High-Impact Hubs',
52
+ 'high-risk hubs': 'High-Impact Hubs',
53
+ 'architectural hubs': 'High-Impact Hubs',
54
+ // Entry Points
55
+ 'entry points': 'Entry Points',
56
+ 'entry point': 'Entry Points',
57
+ 'endpoints': 'Entry Points',
58
+ // Import Chains
59
+ 'import chains': 'Import Chains',
60
+ 'import chain': 'Import Chains',
61
+ 'imports': 'Import Chains',
62
+ 'dependencies': 'Import Chains',
63
+ // Validation
64
+ 'validation': 'Validation',
65
+ 'testing': 'Validation',
66
+ 'tests': 'Validation',
67
+ 'test': 'Validation',
68
+ // Integration Risk
69
+ 'integration risk': 'Integration Risk',
70
+ 'integration': 'Integration Risk',
71
+ 'risk': 'Integration Risk',
72
+ // Conventions
73
+ 'conventions': 'Conventions',
74
+ 'convention': 'Conventions',
75
+ 'style': 'Conventions',
76
+ 'naming': 'Conventions',
77
+ 'patterns': 'Conventions',
78
+ // Guardrails
79
+ 'guardrails': 'Guardrails',
80
+ 'guardrail': 'Guardrails',
81
+ 'safety': 'Guardrails',
82
+ 'constraints': 'Guardrails',
83
+ // Parent-level aliases
84
+ 'repo priors': 'High-Impact Hubs',
85
+ 'repo-specific': 'High-Impact Hubs',
86
+ };
87
+ /**
88
+ * Trimming priority — higher numbers are shed first.
89
+ * Generic sections shed before repo-specific ones.
90
+ */
91
+ const SECTION_PRIORITY = {
92
+ 'Operating Mode': 2,
93
+ 'Procedural Standards': 2,
94
+ 'Guardrails': 2,
95
+ 'Validation': 1,
96
+ 'High-Impact Hubs': 0,
97
+ 'Entry Points': 0,
98
+ 'Import Chains': 0,
99
+ 'Integration Risk': 0,
100
+ 'Conventions': 0,
101
+ };
102
+ // ── Boilerplate filter ──────────────────────────────────────
103
+ /** Patterns that indicate runner metadata, not real guidance. */
104
+ const BOILERPLATE_PATTERNS = [
105
+ /runner_status/i,
106
+ /patch_len/i,
107
+ /elapsed_s/i,
108
+ /token_usage/i,
109
+ /probe_id/i,
110
+ /iteration_\d/i,
111
+ /version_\d/i,
112
+ /^\s*```/,
113
+ ];
114
+ function isBoilerplate(content) {
115
+ return BOILERPLATE_PATTERNS.some((p) => p.test(content));
116
+ }
117
+ /**
118
+ * Parse AGENTS.md into sections by heading.
119
+ * Each section captures all content until the next heading of same or higher level.
120
+ */
121
+ function parseSections(md) {
122
+ const sections = [];
123
+ const headingRegex = /^(#{1,3})\s+(.+)$/gm;
124
+ const matches = [];
125
+ let match;
126
+ while ((match = headingRegex.exec(md)) !== null) {
127
+ matches.push({
128
+ level: match[1].length,
129
+ title: match[2].trim(),
130
+ index: match.index,
131
+ });
132
+ }
133
+ for (let i = 0; i < matches.length; i++) {
134
+ const start = matches[i].index + md.slice(matches[i].index).indexOf('\n') + 1;
135
+ const end = i + 1 < matches.length ? matches[i + 1].index : md.length;
136
+ const body = md.slice(start, end).trim();
137
+ const lines = body ? body.split('\n').filter((l) => l.trim().length > 0) : [];
138
+ sections.push({
139
+ title: matches[i].title,
140
+ level: matches[i].level,
141
+ lines,
142
+ raw: md.slice(matches[i].index, end),
143
+ });
144
+ }
145
+ return sections;
146
+ }
147
+ /** Canonicalize a section name to its canonical form. */
148
+ function canonicalize(sectionName) {
149
+ const lower = sectionName.toLowerCase().trim();
150
+ // Direct match
151
+ if (SECTION_ALIASES[lower])
152
+ return SECTION_ALIASES[lower];
153
+ // Check if any canonical section name matches (case-insensitive)
154
+ for (const canonical of CANONICAL_SECTIONS) {
155
+ if (canonical.toLowerCase() === lower)
156
+ return canonical;
157
+ }
158
+ // Substring match
159
+ for (const [alias, canonical] of Object.entries(SECTION_ALIASES)) {
160
+ if (lower.includes(alias) || alias.includes(lower))
161
+ return canonical;
162
+ }
163
+ return undefined;
164
+ }
165
+ // ── Edit application ────────────────────────────────────────
166
+ /**
167
+ * Apply a list of edits to AGENTS.md content deterministically.
168
+ *
169
+ * - add/modify/strengthen: append bullet to section
170
+ * - remove: fuzzy-match and remove matching lines
171
+ * - Enforces character budget with priority-based trimming
172
+ */
173
+ function applyEdits(agentsMd, edits, charBudget = exports.AGENTS_MD_CHAR_BUDGET) {
174
+ const sections = parseSections(agentsMd);
175
+ let applied = 0;
176
+ for (const edit of edits) {
177
+ // Skip boilerplate
178
+ if (isBoilerplate(edit.content))
179
+ continue;
180
+ // Canonicalize section name
181
+ const canonical = canonicalize(edit.section);
182
+ if (!canonical)
183
+ continue;
184
+ // Find or create the target section
185
+ let section = sections.find((s) => canonicalize(s.title) === canonical);
186
+ if (!section && (edit.action === 'add' || edit.action === 'strengthen')) {
187
+ // Create the section if it doesn't exist
188
+ section = { title: canonical, level: 2, lines: [], raw: '' };
189
+ // Insert before Guardrails (always last)
190
+ const guardrailIdx = sections.findIndex((s) => canonicalize(s.title) === 'Guardrails');
191
+ if (guardrailIdx >= 0) {
192
+ sections.splice(guardrailIdx, 0, section);
193
+ }
194
+ else {
195
+ sections.push(section);
196
+ }
197
+ }
198
+ if (!section)
199
+ continue;
200
+ if (edit.action === 'remove') {
201
+ // Fuzzy-match: remove lines containing the edit content
202
+ const needle = edit.content.toLowerCase();
203
+ const before = section.lines.length;
204
+ section.lines = section.lines.filter((line) => !line.toLowerCase().includes(needle));
205
+ if (section.lines.length < before)
206
+ applied++;
207
+ }
208
+ else {
209
+ // add / modify / strengthen: append as a bullet
210
+ const bullet = `- ${edit.content}`;
211
+ // Don't add duplicate bullets
212
+ const exists = section.lines.some((line) => line.trim().toLowerCase() === bullet.trim().toLowerCase());
213
+ if (!exists) {
214
+ section.lines.push(bullet);
215
+ applied++;
216
+ }
217
+ }
218
+ }
219
+ // Reconstruct the document
220
+ let result = reconstructDocument(sections, agentsMd);
221
+ // Enforce budget
222
+ let trimmed = 0;
223
+ if (result.length > charBudget) {
224
+ const trimResult = trimToBudget(sections, charBudget);
225
+ result = trimResult.content;
226
+ trimmed = trimResult.trimmed;
227
+ }
228
+ return { content: result, applied, trimmed };
229
+ }
230
+ /**
231
+ * Reconstruct the AGENTS.md document from parsed sections.
232
+ * Preserves the document title (# heading) if present.
233
+ */
234
+ function reconstructDocument(sections, originalMd) {
235
+ const parts = [];
236
+ // Preserve any content before the first section heading (e.g., # title)
237
+ const firstHeadingMatch = /^#{1,3}\s+/m.exec(originalMd);
238
+ if (firstHeadingMatch && firstHeadingMatch.index > 0) {
239
+ const preamble = originalMd.slice(0, firstHeadingMatch.index).trim();
240
+ if (preamble)
241
+ parts.push(preamble);
242
+ }
243
+ else {
244
+ // Check if the document starts with a # title
245
+ const titleMatch = /^#\s+(.+)$/m.exec(originalMd);
246
+ if (titleMatch && !sections.some((s) => s.level === 1 && s.title === titleMatch[1].trim())) {
247
+ parts.push(titleMatch[0]);
248
+ }
249
+ }
250
+ for (const section of sections) {
251
+ const heading = '#'.repeat(section.level) + ' ' + section.title;
252
+ if (section.lines.length > 0) {
253
+ parts.push(heading + '\n' + section.lines.join('\n'));
254
+ }
255
+ else {
256
+ parts.push(heading);
257
+ }
258
+ }
259
+ return parts.join('\n\n') + '\n';
260
+ }
261
+ /**
262
+ * Trim bullets from lowest-priority sections to fit within the character budget.
263
+ * Within a priority tier, longest bullets are shed first.
264
+ */
265
+ function trimToBudget(sections, budget) {
266
+ let trimmed = 0;
267
+ // Build a list of (section index, line index, priority, length) for all bullets
268
+ const candidates = [];
269
+ for (let si = 0; si < sections.length; si++) {
270
+ const canonical = canonicalize(sections[si].title);
271
+ const priority = canonical ? (SECTION_PRIORITY[canonical] ?? 1) : 1;
272
+ for (let li = 0; li < sections[si].lines.length; li++) {
273
+ candidates.push({
274
+ sectionIdx: si,
275
+ lineIdx: li,
276
+ priority,
277
+ length: sections[si].lines[li].length,
278
+ });
279
+ }
280
+ }
281
+ // Sort: highest priority first (shed first), then longest first
282
+ candidates.sort((a, b) => {
283
+ if (a.priority !== b.priority)
284
+ return b.priority - a.priority;
285
+ return b.length - a.length;
286
+ });
287
+ // Remove candidates one at a time until we're under budget
288
+ const removed = new Set();
289
+ for (const candidate of candidates) {
290
+ const result = reconstructDocument(sections, '');
291
+ if (result.length <= budget)
292
+ break;
293
+ const key = `${candidate.sectionIdx}:${candidate.lineIdx}`;
294
+ if (removed.has(key))
295
+ continue;
296
+ removed.add(key);
297
+ // Keep at least one bullet per section
298
+ const section = sections[candidate.sectionIdx];
299
+ const remainingLines = section.lines.filter((_, i) => {
300
+ const k = `${candidate.sectionIdx}:${i}`;
301
+ return !removed.has(k);
302
+ });
303
+ if (remainingLines.length === 0) {
304
+ removed.delete(key);
305
+ continue;
306
+ }
307
+ trimmed++;
308
+ }
309
+ // Apply removals
310
+ for (let si = sections.length - 1; si >= 0; si--) {
311
+ sections[si].lines = sections[si].lines.filter((_, li) => {
312
+ return !removed.has(`${si}:${li}`);
313
+ });
314
+ }
315
+ return { content: reconstructDocument(sections, ''), trimmed };
316
+ }
317
+ const llmUtil_1 = require("./llmUtil");
318
+ /**
319
+ * Apply edits with LLM assistance when content exceeds budget or
320
+ * multiple edits target the same section.
321
+ *
322
+ * Falls back to deterministic apply if LLM fails.
323
+ */
324
+ async function applyEditsWithLlm(agentsMd, edits, charBudget, provider, signal) {
325
+ // First try deterministic apply
326
+ const deterministicResult = applyEdits(agentsMd, edits, charBudget);
327
+ // Check if LLM assistance would help:
328
+ // 1. Content was trimmed (lost information)
329
+ // 2. Multiple edits to the same section (consolidation opportunity)
330
+ const sectionCounts = new Map();
331
+ for (const edit of edits) {
332
+ const s = edit.section;
333
+ sectionCounts.set(s, (sectionCounts.get(s) ?? 0) + 1);
334
+ }
335
+ const hasConsolidationOpportunity = [...sectionCounts.values()].some((c) => c > 3);
336
+ const needsLlm = deterministicResult.trimmed > 0 || hasConsolidationOpportunity;
337
+ if (!needsLlm)
338
+ return deterministicResult;
339
+ // LLM-assisted apply
340
+ try {
341
+ const editDescriptions = edits.map((e) => `- ${e.action} in "${e.section}": ${e.content}`).join('\n');
342
+ const messages = [
343
+ {
344
+ role: 'system',
345
+ content: `You apply edits to AGENTS.md. Given the current content and proposed edits, produce an updated AGENTS.md that:
346
+ - Integrates all edits intelligently (merge related bullets, consolidate redundant content)
347
+ - Stays under ${charBudget} characters
348
+ - Preserves the most important guidance when trimming
349
+ - Maintains section structure and markdown formatting
350
+ Output ONLY the updated AGENTS.md content, no code fences.`,
351
+ },
352
+ {
353
+ role: 'user',
354
+ content: `CURRENT AGENTS.MD (${agentsMd.length} chars, budget ${charBudget}):\n---\n${agentsMd}\n---\n\nPROPOSED EDITS:\n${editDescriptions}\n\nApply these edits and produce the updated AGENTS.md.`,
355
+ },
356
+ ];
357
+ const response = await (0, llmUtil_1.chatWithTemp)(provider, messages, 0.0, signal);
358
+ const cleaned = response.replace(/^```(?:markdown)?\s*\n?/m, '').replace(/\n?```\s*$/m, '').trim();
359
+ if (cleaned.length > 0 && cleaned.length <= charBudget * 1.1) {
360
+ return { content: cleaned + '\n', applied: edits.length, trimmed: 0 };
361
+ }
362
+ }
363
+ catch {
364
+ // Fall back to deterministic result
365
+ }
366
+ return deterministicResult;
367
+ }
368
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../src/apply.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAqHH,sCAEC;AAeD,sCA6BC;AAGD,oCAiBC;AAWD,gCAqEC;AAsCD,oCAiEC;AAaD,8CAwDC;AA/aD,8CAA8C;AACjC,QAAA,qBAAqB,GAAG,IAAI,CAAC;AAE1C,+DAA+D;AAE/D,oDAAoD;AACpD,MAAM,kBAAkB,GAAG;IACzB,gBAAgB;IAChB,sBAAsB;IACtB,kBAAkB;IAClB,cAAc;IACd,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,aAAa;IACb,YAAY;CACJ,CAAC;AAIX,kEAAkE;AAClE,MAAM,eAAe,GAAqC;IACxD,iBAAiB;IACjB,gBAAgB,EAAE,gBAAgB;IAClC,UAAU,EAAE,gBAAgB;IAC5B,WAAW,EAAE,gBAAgB;IAC7B,MAAM,EAAE,gBAAgB;IAExB,uBAAuB;IACvB,sBAAsB,EAAE,sBAAsB;IAC9C,YAAY,EAAE,sBAAsB;IACpC,WAAW,EAAE,sBAAsB;IACnC,YAAY,EAAE,sBAAsB;IACpC,SAAS,EAAE,sBAAsB;I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MAAM,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACvC,KAAK,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,EAAE,CAChD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,QAAQ,GAAkB;YAC9B;gBACE,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE;;gBAED,UAAU;;;2DAGiC;aACpD;YACD;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,sBAAsB,QAAQ,CAAC,MAAM,kBAAkB,UAAU,YAAY,QAAQ,6BAA6B,gBAAgB,0DAA0D;aACtM;SACF,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAY,EAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAEnG,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;YAC7D,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACxE,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,oCAAoC;IACtC,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -1,33 +1,24 @@
1
1
  /**
2
- * Diagnosis engine — analyzes probe failures and proposes AGENTS.md edits.
2
+ * Aggregate diagnosis — analyzes judged probe results and proposes AGENTS.md edits.
3
3
  *
4
- * Takes failed probe results + current AGENTS.md, asks the LLM to identify
5
- * which rules are missing/weak/wrong, and returns targeted edits.
6
- */
7
- import type { LlmProvider, OptLogger } from '@aspectcode/optimizer';
8
- import type { ProbeResult, Diagnosis } from './types';
9
- /**
10
- * Build the diagnosis prompt from failed probe results.
11
- */
12
- declare function buildDiagnosisPrompt(failures: ProbeResult[], agentsContent: string): string;
13
- /** Parse the structured diagnosis response. */
14
- declare function parseDiagnosisResponse(response: string, failureCount: number): Diagnosis;
15
- /**
16
- * Diagnose AGENTS.md shortcomings from failed probe results.
4
+ * Takes all judged probe results (including behaviour reviews and per-probe edits),
5
+ * aggregates the failures, and proposes up to 6 targeted AGENTS.md edits.
17
6
  *
18
- * Sends the failures + current AGENTS.md to the LLM and asks it to
19
- * identify what needs to change and propose specific edits.
7
+ * Ported from sweagent_bench oracle/diagnose.py.
20
8
  */
21
- export declare function diagnose(failures: ProbeResult[], agentsContent: string, provider: LlmProvider, log?: OptLogger, signal?: AbortSignal): Promise<Diagnosis>;
9
+ import type { AgentsEdit, DiagnosisOptions } from './types';
10
+ interface RawEdit {
11
+ section: string;
12
+ action: string;
13
+ content: string;
14
+ }
15
+ export declare function parseDiagnoseResponse(raw: string): RawEdit[];
22
16
  /**
23
- * Apply diagnosis edits to AGENTS.md content.
17
+ * Diagnose AGENTS.md shortcomings from judged probe results.
24
18
  *
25
- * Uses the LLM to intelligently merge the proposed edits into the
26
- * existing content, since edits reference sections by name (not line number).
19
+ * Aggregates all probe behavior reviews and per-probe edits,
20
+ * then proposes up to 6 aggregate edits via a single LLM call.
27
21
  */
28
- export declare function applyDiagnosisEdits(agentsContent: string, diagnosis: Diagnosis, provider: LlmProvider, log?: OptLogger, signal?: AbortSignal): Promise<{
29
- content: string;
30
- appliedEdits: string[];
31
- }>;
32
- export { buildDiagnosisPrompt, parseDiagnosisResponse };
22
+ export declare function diagnose(options: DiagnosisOptions): Promise<AgentsEdit[]>;
23
+ export {};
33
24
  //# sourceMappingURL=diagnosis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnosis.d.ts","sourceRoot":"","sources":["../src/di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