@yuaone/core 0.4.7 → 0.4.9
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-loop.d.ts +10 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +190 -0
- package/dist/agent-loop.js.map +1 -1
- package/dist/ast-analyzer.d.ts +147 -0
- package/dist/ast-analyzer.d.ts.map +1 -0
- package/dist/ast-analyzer.js +344 -0
- package/dist/ast-analyzer.js.map +1 -0
- package/dist/codebase-context.d.ts +24 -4
- package/dist/codebase-context.d.ts.map +1 -1
- package/dist/codebase-context.js +100 -10
- package/dist/codebase-context.js.map +1 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -1
- package/dist/cross-file-refactor.d.ts +12 -3
- package/dist/cross-file-refactor.d.ts.map +1 -1
- package/dist/cross-file-refactor.js +35 -3
- package/dist/cross-file-refactor.js.map +1 -1
- package/dist/execution-engine.d.ts +9 -0
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/execution-engine.js +59 -10
- package/dist/execution-engine.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/vector-store.d.ts +148 -0
- package/dist/vector-store.d.ts.map +1 -0
- package/dist/vector-store.js +328 -0
- package/dist/vector-store.js.map +1 -0
- package/package.json +1 -1
package/dist/agent-loop.d.ts
CHANGED
|
@@ -171,6 +171,16 @@ export declare class AgentLoop extends EventEmitter {
|
|
|
171
171
|
private static readonly MAX_ACTIVE_SKILLS;
|
|
172
172
|
/** Context Budget: track injected system messages per iteration to cap at 5 */
|
|
173
173
|
private iterationSystemMsgCount;
|
|
174
|
+
/** Task 1: ContextBudgetManager for LLM-based summarization at 60-70% context usage */
|
|
175
|
+
private contextBudgetManager;
|
|
176
|
+
/** Task 2: Track whether write tools ran this iteration for QA triggering */
|
|
177
|
+
private iterationWriteToolPaths;
|
|
178
|
+
/** Task 2: Last QA result (surfaced to LLM on issues) */
|
|
179
|
+
private lastQAResult;
|
|
180
|
+
/** Task 3: Track TS files modified this run for auto-tsc */
|
|
181
|
+
private iterationTsFilesModified;
|
|
182
|
+
/** Task 3: Whether tsc was run in the previous iteration (skip cooldown) */
|
|
183
|
+
private tscRanLastIteration;
|
|
174
184
|
private tokenUsage;
|
|
175
185
|
private readonly reasoningAggregator;
|
|
176
186
|
private readonly reasoningTree;
|
package/dist/agent-loop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EACV,WAAW,EAEX,gBAAgB,EAChB,OAAO,EAGP,YAAY,EACZ,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAEL,KAAK,WAAW,EAGjB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EAEpB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAEnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,kBAAkB,EAAmB,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S;IAIjB,oCAAoC;YACtB,cAAc;IAI5B;;;;OAIG;YACW,yBAAyB;IAevC,gCAAgC;IAC1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9B,OAAO,CAAC,SAAS;IAGjB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,gBAAgB;CAazB"}
|
package/dist/agent-loop.js
CHANGED
|
@@ -48,6 +48,8 @@ import { ReasoningTree } from "./reasoning-tree.js";
|
|
|
48
48
|
import { ContextCompressor } from "./context-compressor.js";
|
|
49
49
|
import { DependencyAnalyzer } from "./dependency-analyzer.js";
|
|
50
50
|
import { CrossFileRefactor } from "./cross-file-refactor.js";
|
|
51
|
+
import { ContextBudgetManager } from "./context-budget.js";
|
|
52
|
+
import { QAPipeline } from "./qa-pipeline.js";
|
|
51
53
|
/**
|
|
52
54
|
* AgentLoop — YUAN 에이전트의 핵심 실행 루프.
|
|
53
55
|
*
|
|
@@ -144,6 +146,16 @@ export class AgentLoop extends EventEmitter {
|
|
|
144
146
|
static MAX_ACTIVE_SKILLS = 3;
|
|
145
147
|
/** Context Budget: track injected system messages per iteration to cap at 5 */
|
|
146
148
|
iterationSystemMsgCount = 0;
|
|
149
|
+
/** Task 1: ContextBudgetManager for LLM-based summarization at 60-70% context usage */
|
|
150
|
+
contextBudgetManager = null;
|
|
151
|
+
/** Task 2: Track whether write tools ran this iteration for QA triggering */
|
|
152
|
+
iterationWriteToolPaths = [];
|
|
153
|
+
/** Task 2: Last QA result (surfaced to LLM on issues) */
|
|
154
|
+
lastQAResult = null;
|
|
155
|
+
/** Task 3: Track TS files modified this run for auto-tsc */
|
|
156
|
+
iterationTsFilesModified = [];
|
|
157
|
+
/** Task 3: Whether tsc was run in the previous iteration (skip cooldown) */
|
|
158
|
+
tscRanLastIteration = false;
|
|
147
159
|
tokenUsage = {
|
|
148
160
|
input: 0,
|
|
149
161
|
output: 0,
|
|
@@ -278,6 +290,12 @@ export class AgentLoop extends EventEmitter {
|
|
|
278
290
|
if (this.initialized)
|
|
279
291
|
return;
|
|
280
292
|
this.initialized = true;
|
|
293
|
+
// Task 1: Initialize ContextBudgetManager with the total token budget
|
|
294
|
+
this.contextBudgetManager = new ContextBudgetManager({
|
|
295
|
+
totalBudget: this.config.loop.totalTokenBudget,
|
|
296
|
+
enableSummarization: true,
|
|
297
|
+
summarizationThreshold: 0.60, // trigger summarize() at 60% (before ContextCompressor at 70%)
|
|
298
|
+
});
|
|
281
299
|
const projectPath = this.config.loop.projectPath;
|
|
282
300
|
if (!projectPath)
|
|
283
301
|
return;
|
|
@@ -645,6 +663,9 @@ export class AgentLoop extends EventEmitter {
|
|
|
645
663
|
total: 0,
|
|
646
664
|
};
|
|
647
665
|
this.impactHintInjected = false;
|
|
666
|
+
// Task 3: reset tsc tracking per run
|
|
667
|
+
this.iterationTsFilesModified = [];
|
|
668
|
+
this.tscRanLastIteration = false;
|
|
648
669
|
}
|
|
649
670
|
this.checkpointSaved = false;
|
|
650
671
|
this.failureRecovery.reset();
|
|
@@ -1392,6 +1413,30 @@ export class AgentLoop extends EventEmitter {
|
|
|
1392
1413
|
// Soft context rollover:
|
|
1393
1414
|
// checkpoint first, then let ContextManager compact instead of aborting/throwing.
|
|
1394
1415
|
const contextUsageRatio = this.contextManager.getUsageRatio();
|
|
1416
|
+
// Task 1: ContextBudgetManager LLM summarization at 60-70% — runs BEFORE ContextCompressor
|
|
1417
|
+
// Summarizes old "medium" priority conversation turns into a compact summary message,
|
|
1418
|
+
// freeing tokens before the heavier ContextCompressor kicks in at 70%.
|
|
1419
|
+
if (contextUsageRatio >= 0.60 && contextUsageRatio < 0.70 && this.contextBudgetManager) {
|
|
1420
|
+
try {
|
|
1421
|
+
// Sync current messages into the budget manager so it knows what to summarize
|
|
1422
|
+
this.contextBudgetManager.importMessages(this.contextManager.getMessages());
|
|
1423
|
+
if (this.contextBudgetManager.needsSummarization()) {
|
|
1424
|
+
const summary = await this.contextBudgetManager.summarize(async (prompt) => {
|
|
1425
|
+
const resp = await this.llmClient.chat([{ role: "user", content: prompt }], []);
|
|
1426
|
+
return typeof resp.content === "string" ? resp.content : "";
|
|
1427
|
+
});
|
|
1428
|
+
if (summary) {
|
|
1429
|
+
this.emitEvent({
|
|
1430
|
+
kind: "agent:thinking",
|
|
1431
|
+
content: `Context at ${Math.round(contextUsageRatio * 100)}%: summarized ${summary.originalIds.length} old messages (${summary.originalTokens} → ${summary.summarizedTokens} tokens, ${Math.round(summary.compressionRatio * 100)}% ratio).`,
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
catch {
|
|
1437
|
+
// ContextBudgetManager summarization failure is non-fatal
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1395
1440
|
// Bug 5 fix: use ContextCompressor as an alternative when context pressure is high (>70%)
|
|
1396
1441
|
// At 70-84% we apply intelligent priority-based compression before falling back to truncation.
|
|
1397
1442
|
if (contextUsageRatio >= 0.70 && contextUsageRatio < 0.85) {
|
|
@@ -1625,6 +1670,44 @@ export class AgentLoop extends EventEmitter {
|
|
|
1625
1670
|
content: finalSummary,
|
|
1626
1671
|
});
|
|
1627
1672
|
}
|
|
1673
|
+
// Task 2: QAPipeline "thorough" mode at final task completion (LLM review included)
|
|
1674
|
+
if (this.changedFiles.length > 0 && this.config.loop.projectPath) {
|
|
1675
|
+
try {
|
|
1676
|
+
const thoroughQA = new QAPipeline({
|
|
1677
|
+
projectPath: this.config.loop.projectPath,
|
|
1678
|
+
level: "thorough",
|
|
1679
|
+
enableStructural: true,
|
|
1680
|
+
enableSemantic: false, // skip tests for speed — structural + quality + review
|
|
1681
|
+
enableQuality: true,
|
|
1682
|
+
enableReview: true,
|
|
1683
|
+
enableDecision: true,
|
|
1684
|
+
autoFix: false,
|
|
1685
|
+
});
|
|
1686
|
+
const thoroughResult = await thoroughQA.run(this.changedFiles, async (prompt) => {
|
|
1687
|
+
try {
|
|
1688
|
+
const reviewResp = await this.llmClient.chat([
|
|
1689
|
+
{ role: "system", content: "You are a code reviewer. Review the code changes concisely." },
|
|
1690
|
+
{ role: "user", content: prompt },
|
|
1691
|
+
], []);
|
|
1692
|
+
return typeof reviewResp.content === "string" ? reviewResp.content : "";
|
|
1693
|
+
}
|
|
1694
|
+
catch {
|
|
1695
|
+
return "";
|
|
1696
|
+
}
|
|
1697
|
+
});
|
|
1698
|
+
const thoroughFailures = thoroughResult.stages
|
|
1699
|
+
.flatMap((s) => s.checks)
|
|
1700
|
+
.filter((c) => c.status === "fail");
|
|
1701
|
+
this.emitEvent({
|
|
1702
|
+
kind: "agent:thinking",
|
|
1703
|
+
content: `QA thorough check at completion: ${thoroughResult.overall} (${thoroughFailures.length} failure(s) across ${this.changedFiles.length} file(s)).`,
|
|
1704
|
+
});
|
|
1705
|
+
this.lastQAResult = thoroughResult;
|
|
1706
|
+
}
|
|
1707
|
+
catch {
|
|
1708
|
+
// Thorough QA failure is non-fatal — proceed with completion
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1628
1711
|
this.emitEvent({
|
|
1629
1712
|
kind: "agent:completed",
|
|
1630
1713
|
summary: finalSummary,
|
|
@@ -1688,6 +1771,105 @@ export class AgentLoop extends EventEmitter {
|
|
|
1688
1771
|
content: fixPrompt,
|
|
1689
1772
|
});
|
|
1690
1773
|
}
|
|
1774
|
+
// Task 2: QAPipeline — run "quick" (structural only) after any WRITE tool call this iteration
|
|
1775
|
+
const projectPath = this.config.loop.projectPath;
|
|
1776
|
+
if (this.iterationWriteToolPaths.length > 0 && projectPath) {
|
|
1777
|
+
try {
|
|
1778
|
+
const qaPipeline = new QAPipeline({
|
|
1779
|
+
projectPath,
|
|
1780
|
+
level: "quick",
|
|
1781
|
+
enableStructural: true,
|
|
1782
|
+
enableSemantic: false,
|
|
1783
|
+
enableQuality: false,
|
|
1784
|
+
enableReview: false,
|
|
1785
|
+
enableDecision: true,
|
|
1786
|
+
autoFix: false,
|
|
1787
|
+
});
|
|
1788
|
+
const qaResult = await qaPipeline.run(this.iterationWriteToolPaths);
|
|
1789
|
+
this.lastQAResult = qaResult;
|
|
1790
|
+
// Surface QA issues as a system message so LLM sees them next iteration
|
|
1791
|
+
const failedChecks = qaResult.stages
|
|
1792
|
+
.flatMap((s) => s.checks)
|
|
1793
|
+
.filter((c) => c.status === "fail" || c.status === "warn");
|
|
1794
|
+
if (failedChecks.length > 0 && this.iterationSystemMsgCount < 5) {
|
|
1795
|
+
const checkSummary = failedChecks
|
|
1796
|
+
.slice(0, 5)
|
|
1797
|
+
.map((c) => ` - [${c.severity}] ${c.name}: ${c.message}`)
|
|
1798
|
+
.join("\n");
|
|
1799
|
+
this.contextManager.addMessage({
|
|
1800
|
+
role: "system",
|
|
1801
|
+
content: `[QA Quick Check] ${failedChecks.length} issue(s) detected in modified files:\n${checkSummary}`,
|
|
1802
|
+
});
|
|
1803
|
+
this.iterationSystemMsgCount++;
|
|
1804
|
+
this.emitEvent({
|
|
1805
|
+
kind: "agent:thinking",
|
|
1806
|
+
content: `QA quick check: ${failedChecks.length} issue(s) in ${this.iterationWriteToolPaths.length} file(s).`,
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
else if (failedChecks.length === 0) {
|
|
1810
|
+
this.emitEvent({
|
|
1811
|
+
kind: "agent:thinking",
|
|
1812
|
+
content: `QA quick check passed for ${this.iterationWriteToolPaths.length} file(s).`,
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
catch {
|
|
1817
|
+
// QAPipeline failure is non-fatal
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
// Reset per-iteration write tool tracking
|
|
1821
|
+
this.iterationWriteToolPaths = [];
|
|
1822
|
+
// Task 3: Auto-run tsc --noEmit after 2+ TS files modified in this iteration
|
|
1823
|
+
// Skip if tsc was already run in the previous iteration (cooldown)
|
|
1824
|
+
const tscFilesThisIteration = [...this.iterationTsFilesModified];
|
|
1825
|
+
this.iterationTsFilesModified = []; // reset for next iteration
|
|
1826
|
+
const tscRanPrev = this.tscRanLastIteration;
|
|
1827
|
+
this.tscRanLastIteration = false; // will set to true below if we run it
|
|
1828
|
+
if (tscFilesThisIteration.length >= 2 && projectPath && !tscRanPrev) {
|
|
1829
|
+
try {
|
|
1830
|
+
const tscResult = await this.toolExecutor.execute({
|
|
1831
|
+
id: `auto-tsc-${Date.now()}`,
|
|
1832
|
+
name: "shell_exec",
|
|
1833
|
+
arguments: JSON.stringify({
|
|
1834
|
+
command: "npx tsc --noEmit 2>&1 || true",
|
|
1835
|
+
cwd: projectPath,
|
|
1836
|
+
timeout: 60000,
|
|
1837
|
+
}),
|
|
1838
|
+
});
|
|
1839
|
+
this.tscRanLastIteration = true;
|
|
1840
|
+
// Inject TypeScript errors into context so LLM sees them next iteration
|
|
1841
|
+
if (tscResult.success && tscResult.output && tscResult.output.trim().length > 0) {
|
|
1842
|
+
const tscOutput = tscResult.output.trim();
|
|
1843
|
+
// Only inject if there are actual TS errors (output is non-empty)
|
|
1844
|
+
const hasErrors = tscOutput.includes(": error TS") || tscOutput.includes("error TS");
|
|
1845
|
+
if (hasErrors && this.iterationSystemMsgCount < 5) {
|
|
1846
|
+
// Truncate long tsc output to avoid context bloat
|
|
1847
|
+
const truncated = tscOutput.length > 2000
|
|
1848
|
+
? tscOutput.slice(0, 2000) + "\n[...tsc output truncated]"
|
|
1849
|
+
: tscOutput;
|
|
1850
|
+
this.contextManager.addMessage({
|
|
1851
|
+
role: "system",
|
|
1852
|
+
content: `[Auto-TSC] TypeScript errors detected after modifying ${tscFilesThisIteration.length} files:\n\`\`\`\n${truncated}\n\`\`\`\nPlease fix these type errors.`,
|
|
1853
|
+
});
|
|
1854
|
+
this.iterationSystemMsgCount++;
|
|
1855
|
+
this.emitEvent({
|
|
1856
|
+
kind: "agent:thinking",
|
|
1857
|
+
content: `Auto-TSC: TypeScript errors found after editing ${tscFilesThisIteration.join(", ")}.`,
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
else if (!hasErrors) {
|
|
1861
|
+
this.emitEvent({
|
|
1862
|
+
kind: "agent:thinking",
|
|
1863
|
+
content: `Auto-TSC: No type errors after editing ${tscFilesThisIteration.length} file(s).`,
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
catch {
|
|
1869
|
+
// Auto-tsc failure is non-fatal
|
|
1870
|
+
this.tscRanLastIteration = false;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1691
1873
|
// iteration 이벤트
|
|
1692
1874
|
this.emitEvent({
|
|
1693
1875
|
kind: "agent:iteration",
|
|
@@ -2241,6 +2423,14 @@ export class AgentLoop extends EventEmitter {
|
|
|
2241
2423
|
if (!this.changedFiles.includes(filePathStr)) {
|
|
2242
2424
|
this.changedFiles.push(filePathStr);
|
|
2243
2425
|
}
|
|
2426
|
+
// Task 2: track write tool paths per-iteration for QA triggering
|
|
2427
|
+
if (!this.iterationWriteToolPaths.includes(filePathStr)) {
|
|
2428
|
+
this.iterationWriteToolPaths.push(filePathStr);
|
|
2429
|
+
}
|
|
2430
|
+
// Task 3: track TS/TSX files modified this iteration for auto-tsc
|
|
2431
|
+
if (filePathStr.match(/\.[cm]?tsx?$/) && !this.iterationTsFilesModified.includes(filePathStr)) {
|
|
2432
|
+
this.iterationTsFilesModified.push(filePathStr);
|
|
2433
|
+
}
|
|
2244
2434
|
this.emitEvent({ kind: "agent:file_change", path: filePathStr, diff: result.output });
|
|
2245
2435
|
if (this.impactAnalyzer) {
|
|
2246
2436
|
this.analyzeFileImpact(filePathStr).catch(() => { });
|