@hamp10/agentforge 0.2.49 → 0.2.51
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/package.json +1 -1
- package/scripts/check-task-semantics.js +11 -2
- package/src/OpenClawCLI.js +16 -4
- package/src/worker.js +67 -12
package/package.json
CHANGED
|
@@ -291,9 +291,18 @@ try {
|
|
|
291
291
|
);
|
|
292
292
|
git(fixture.repo, ['restore', '--', nestedAlphaRel]);
|
|
293
293
|
const untrackedGammaRel = 'public_html/domains/gamma.html';
|
|
294
|
+
writeFileSync(path.join(fixture.repo, untrackedGammaRel), '');
|
|
295
|
+
assert.match(
|
|
296
|
+
worker._buildIncompleteScopedUiTargetsNudge(
|
|
297
|
+
[{ root: fixture.repo, head: fixture.head, initialDirtyPaths: [] }],
|
|
298
|
+
'Work on the Example.com listing pages for Alpha.ai, Beta.ai, and Gamma.ai. Make all three pages visually polished.'
|
|
299
|
+
),
|
|
300
|
+
/gamma-ai[\s\S]*blank or too little page source/i,
|
|
301
|
+
'blank scoped page files should not count as meaningfully addressed targets'
|
|
302
|
+
);
|
|
294
303
|
writeFileSync(
|
|
295
304
|
path.join(fixture.repo, untrackedGammaRel),
|
|
296
|
-
'<!doctype html><html><body><main><section><h1>Gamma</h1><p>New scoped page.</p></section></main></body></html>'
|
|
305
|
+
'<!doctype html><html><body><main><section><h1>Gamma</h1><p>New scoped page with enough visible product copy to prove the target was actually rebuilt rather than created as an empty placeholder file.</p></section></main></body></html>'
|
|
297
306
|
);
|
|
298
307
|
assert.equal(
|
|
299
308
|
worker._buildIncompleteScopedUiTargetsNudge(
|
|
@@ -536,7 +545,7 @@ try {
|
|
|
536
545
|
worker._findIncompleteScopedUiTargets = originalFindIncompleteScopedUiTargets;
|
|
537
546
|
assert.match(
|
|
538
547
|
incompleteRepairLead,
|
|
539
|
-
/missing-target pass for target page\(s\) not yet changed in the current diff: beta-ai/i,
|
|
548
|
+
/missing-target pass for target page\(s\) not yet changed with meaningful page content in the current diff: beta-ai/i,
|
|
540
549
|
'missing-target retries should name only the targets not yet addressed'
|
|
541
550
|
);
|
|
542
551
|
assert.match(
|
package/src/OpenClawCLI.js
CHANGED
|
@@ -917,7 +917,7 @@ export class OpenClawCLI extends EventEmitter {
|
|
|
917
917
|
_directFocusedRetryAllowedSlugs(task) {
|
|
918
918
|
const text = String(task || '');
|
|
919
919
|
const patterns = [
|
|
920
|
-
/missing-target pass for target page\(s\) not yet changed in the current diff:\s*([^\n.]+)/i,
|
|
920
|
+
/missing-target pass for target page\(s\) not yet changed(?: with meaningful page content)? in the current diff:\s*([^\n.]+)/i,
|
|
921
921
|
/visual repair pass for currently failing target page\(s\):\s*([^\n.]+)/i,
|
|
922
922
|
];
|
|
923
923
|
for (const pattern of patterns) {
|
|
@@ -1820,7 +1820,7 @@ export class OpenClawCLI extends EventEmitter {
|
|
|
1820
1820
|
if (!sessionFilePath || !existsSync(sessionFilePath)) return null;
|
|
1821
1821
|
try {
|
|
1822
1822
|
const lines = readFileSync(sessionFilePath, 'utf8').split('\n');
|
|
1823
|
-
let input = 0, output = 0, costUsd = 0;
|
|
1823
|
+
let input = 0, output = 0, costUsd = 0, hasCost = false;
|
|
1824
1824
|
for (const line of lines) {
|
|
1825
1825
|
if (!line.trim()) continue;
|
|
1826
1826
|
try {
|
|
@@ -1830,14 +1830,26 @@ export class OpenClawCLI extends EventEmitter {
|
|
|
1830
1830
|
output += entry.message.usage.output || 0;
|
|
1831
1831
|
// openclaw writes exact cost.total — use it directly instead of re-calculating
|
|
1832
1832
|
if (entry.message.usage.cost?.total != null) {
|
|
1833
|
-
|
|
1833
|
+
const costTotal = Number(entry.message.usage.cost.total);
|
|
1834
|
+
if (Number.isFinite(costTotal) && costTotal >= 0) {
|
|
1835
|
+
costUsd += costTotal;
|
|
1836
|
+
hasCost = true;
|
|
1837
|
+
}
|
|
1834
1838
|
}
|
|
1835
1839
|
}
|
|
1836
1840
|
} catch { /* skip malformed lines */ }
|
|
1837
1841
|
}
|
|
1838
1842
|
if (input > 0 || output > 0) {
|
|
1839
1843
|
console.log(`[session-usage] Read from JSONL: input=${input} output=${output} cost=$${costUsd.toFixed(6)}`);
|
|
1840
|
-
return {
|
|
1844
|
+
return {
|
|
1845
|
+
input_tokens: input,
|
|
1846
|
+
output_tokens: output,
|
|
1847
|
+
...(hasCost ? {
|
|
1848
|
+
cost_usd: costUsd,
|
|
1849
|
+
cost_source: 'provider_reported',
|
|
1850
|
+
cost_accuracy: 'exact',
|
|
1851
|
+
} : {}),
|
|
1852
|
+
};
|
|
1841
1853
|
}
|
|
1842
1854
|
return null;
|
|
1843
1855
|
} catch (e) {
|
package/src/worker.js
CHANGED
|
@@ -775,6 +775,24 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
775
775
|
return [...names].sort();
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
+
_pageSourceContentIssue(repo, rel) {
|
|
779
|
+
if (!repo || !/\.html?$/i.test(String(rel || ''))) return null;
|
|
780
|
+
const fullPath = path.join(repo, rel);
|
|
781
|
+
if (!existsSync(fullPath)) return 'missing page source file';
|
|
782
|
+
let content = '';
|
|
783
|
+
try {
|
|
784
|
+
content = readFileSync(fullPath, 'utf-8');
|
|
785
|
+
} catch {
|
|
786
|
+
return 'unreadable page source file';
|
|
787
|
+
}
|
|
788
|
+
const trimmed = content.trim();
|
|
789
|
+
if (trimmed.length < 200) return 'blank or too little page source';
|
|
790
|
+
if (!/<(?:html|body|main|section|article|h1)\b/i.test(trimmed)) {
|
|
791
|
+
return 'does not look like a rendered page source';
|
|
792
|
+
}
|
|
793
|
+
return null;
|
|
794
|
+
}
|
|
795
|
+
|
|
778
796
|
_isNewScopedPageOwnedAsset(baseline, rel, allowedSlugs, pageOnly) {
|
|
779
797
|
if (!baseline?.root || !pageOnly || !Array.isArray(allowedSlugs) || allowedSlugs.length === 0) return false;
|
|
780
798
|
if (!this._isPageAssetPath(rel)) return false;
|
|
@@ -1696,20 +1714,40 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
1696
1714
|
if (changedFiles.length === 0) continue;
|
|
1697
1715
|
|
|
1698
1716
|
const touchedSlugs = new Set();
|
|
1717
|
+
const touchedFilesBySlug = new Map();
|
|
1699
1718
|
for (const filePath of changedFiles) {
|
|
1700
1719
|
const lower = String(filePath || '').toLowerCase();
|
|
1701
1720
|
for (const slug of allowedSlugs) {
|
|
1702
|
-
if (this._scopeSlugsMatchingText(lower, [slug]).length > 0)
|
|
1721
|
+
if (this._scopeSlugsMatchingText(lower, [slug]).length > 0) {
|
|
1722
|
+
touchedSlugs.add(slug);
|
|
1723
|
+
if (!touchedFilesBySlug.has(slug)) touchedFilesBySlug.set(slug, []);
|
|
1724
|
+
touchedFilesBySlug.get(slug).push(filePath);
|
|
1725
|
+
}
|
|
1703
1726
|
}
|
|
1704
1727
|
}
|
|
1705
1728
|
|
|
1706
1729
|
const missingSlugs = allowedSlugs.filter(slug => !touchedSlugs.has(slug));
|
|
1707
|
-
|
|
1730
|
+
const contentIssues = [];
|
|
1731
|
+
for (const slug of allowedSlugs.filter(slug => touchedSlugs.has(slug))) {
|
|
1732
|
+
const pageFiles = (touchedFilesBySlug.get(slug) || [])
|
|
1733
|
+
.filter(rel => /\.html?$/i.test(rel));
|
|
1734
|
+
if (pageFiles.length === 0) continue;
|
|
1735
|
+
const issues = pageFiles
|
|
1736
|
+
.map(rel => ({ rel, issue: this._pageSourceContentIssue(baseline.root, rel) }))
|
|
1737
|
+
.filter(item => item.issue);
|
|
1738
|
+
if (issues.length > 0 && issues.length === pageFiles.length) {
|
|
1739
|
+
missingSlugs.push(slug);
|
|
1740
|
+
contentIssues.push(`${slug}: ${issues.map(item => `${item.rel} (${item.issue})`).join(', ')}`);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
const uniqueMissingSlugs = [...new Set(missingSlugs)];
|
|
1744
|
+
if (uniqueMissingSlugs.length === 0) continue;
|
|
1708
1745
|
warnings.push({
|
|
1709
1746
|
repo: baseline.root,
|
|
1710
|
-
missingSlugs,
|
|
1747
|
+
missingSlugs: uniqueMissingSlugs,
|
|
1711
1748
|
touchedSlugs: [...touchedSlugs],
|
|
1712
1749
|
changedFiles: [...new Set(changedFiles)].slice(0, 8),
|
|
1750
|
+
contentIssues,
|
|
1713
1751
|
});
|
|
1714
1752
|
}
|
|
1715
1753
|
|
|
@@ -1718,12 +1756,12 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
1718
1756
|
|
|
1719
1757
|
_formatIncompleteScopedUiTargetsNudge(warnings) {
|
|
1720
1758
|
const lines = warnings.slice(0, 5).map(w =>
|
|
1721
|
-
`- ${w.repo}: missing target(s) ${w.missingSlugs.join(', ')}; changed ${w.changedFiles.join(', ') || 'no UI files'}`
|
|
1759
|
+
`- ${w.repo}: missing or incomplete target(s) ${w.missingSlugs.join(', ')}; changed ${w.changedFiles.join(', ') || 'no UI files'}${w.contentIssues?.length ? `; content issue(s): ${w.contentIssues.join('; ')}` : ''}`
|
|
1722
1760
|
);
|
|
1723
1761
|
return [
|
|
1724
|
-
'The task names multiple scoped UI targets, but the current diff does not
|
|
1762
|
+
'The task names multiple scoped UI targets, but the current diff does not meaningfully address every named target.',
|
|
1725
1763
|
...lines,
|
|
1726
|
-
'For scoped page/listing work, each requested target page must be addressed directly unless the final response clearly reports a blocker for that specific target. Continue from the current files and update the missing target page(s), then visually verify all edited target screens.',
|
|
1764
|
+
'For scoped page/listing work, each requested target page must be addressed directly with non-empty, rendered page content unless the final response clearly reports a blocker for that specific target. Continue from the current files and update the missing or incomplete target page(s), then visually verify all edited target screens.',
|
|
1727
1765
|
].join('\n');
|
|
1728
1766
|
}
|
|
1729
1767
|
|
|
@@ -1741,7 +1779,7 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
1741
1779
|
const alreadyTouchedSlugs = allSlugs.filter(slug => !missingSlugs.includes(slug));
|
|
1742
1780
|
return [
|
|
1743
1781
|
`Original scoped UI target set: ${allSlugs.join(', ')}.`,
|
|
1744
|
-
`This retry is a missing-target pass for target page(s) not yet changed in the current diff: ${missingSlugs.join(', ')}.`,
|
|
1782
|
+
`This retry is a missing-target pass for target page(s) not yet changed with meaningful page content in the current diff: ${missingSlugs.join(', ')}.`,
|
|
1745
1783
|
alreadyTouchedSlugs.length > 0
|
|
1746
1784
|
? `Do not delete, rewrite, or restart target page(s) already changed in this diff just to repeat earlier work: ${alreadyTouchedSlugs.join(', ')}.`
|
|
1747
1785
|
: '',
|
|
@@ -3890,7 +3928,10 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
3890
3928
|
let uiRepairNudgeCount = 0;
|
|
3891
3929
|
let taskResult;
|
|
3892
3930
|
let iterationMessage = finalMessage;
|
|
3893
|
-
let totalUsage = { input_tokens: 0, output_tokens: 0
|
|
3931
|
+
let totalUsage = { input_tokens: 0, output_tokens: 0 };
|
|
3932
|
+
let totalUsageCostUsd = 0;
|
|
3933
|
+
let usageSegments = 0;
|
|
3934
|
+
let usageCostSegments = 0;
|
|
3894
3935
|
// Fallback tracking: used at most once per task
|
|
3895
3936
|
let usedFallback = false;
|
|
3896
3937
|
let toolFailureRetryCount = 0;
|
|
@@ -4175,10 +4216,19 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
4175
4216
|
break;
|
|
4176
4217
|
}
|
|
4177
4218
|
if (taskResult?.usage) {
|
|
4178
|
-
|
|
4179
|
-
|
|
4219
|
+
const inputTokens = Number(taskResult.usage.input_tokens || 0);
|
|
4220
|
+
const outputTokens = Number(taskResult.usage.output_tokens || 0);
|
|
4221
|
+
totalUsage.input_tokens += Number.isFinite(inputTokens) ? inputTokens : 0;
|
|
4222
|
+
totalUsage.output_tokens += Number.isFinite(outputTokens) ? outputTokens : 0;
|
|
4223
|
+
if ((inputTokens > 0 || outputTokens > 0) || taskResult.usage.cost_usd != null) {
|
|
4224
|
+
usageSegments += 1;
|
|
4225
|
+
}
|
|
4180
4226
|
if (taskResult.usage.cost_usd != null) {
|
|
4181
|
-
|
|
4227
|
+
const costUsd = Number(taskResult.usage.cost_usd);
|
|
4228
|
+
if (Number.isFinite(costUsd) && costUsd >= 0) {
|
|
4229
|
+
totalUsageCostUsd += costUsd;
|
|
4230
|
+
usageCostSegments += 1;
|
|
4231
|
+
}
|
|
4182
4232
|
}
|
|
4183
4233
|
}
|
|
4184
4234
|
|
|
@@ -5065,7 +5115,12 @@ export class AgentForgeWorker extends EventEmitter {
|
|
|
5065
5115
|
console.log(`[${taskId}] ℹ️ Task succeeded with no text output — using default completion message`);
|
|
5066
5116
|
}
|
|
5067
5117
|
console.log(`[${taskId}] 📤 finalOutput="${finalOutput.slice(0,100)}" response=${finalOutput ? `"${finalOutput.slice(0,80)}"` : 'undefined'}`);
|
|
5068
|
-
|
|
5118
|
+
if (usageSegments > 0 && usageCostSegments === usageSegments) {
|
|
5119
|
+
totalUsage.cost_usd = totalUsageCostUsd;
|
|
5120
|
+
totalUsage.cost_source = 'provider_reported';
|
|
5121
|
+
totalUsage.cost_accuracy = 'exact';
|
|
5122
|
+
}
|
|
5123
|
+
const hasUsage = totalUsage.input_tokens > 0 || totalUsage.output_tokens > 0 || totalUsage.cost_usd != null;
|
|
5069
5124
|
const completionMessage = {
|
|
5070
5125
|
type: 'task_complete',
|
|
5071
5126
|
taskId,
|