@causyne/agent 1.20.60 → 1.20.63
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/README.md +2 -2
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +1 -1
- package/src/acp/agentCatalog.ts +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/acp/peerProfiles.js +3 -3
- package/src/acp/peerProfiles.ts +3 -3
- package/src/agentLoop.js +239 -33
- package/src/agentLoop.ts +248 -36
- package/src/checkpoints.js +23 -5
- package/src/cliMode.js +13 -2
- package/src/commands.js +534 -78
- package/src/contextManager.d.ts +3 -0
- package/src/contextManager.js +78 -5
- package/src/cortex/autoCondenser.js +105 -145
- package/src/cortex/autoCondenser.ts +185 -0
- package/src/cortex/cortexEngine.js +179 -0
- package/src/cortex/cortexEngine.ts +209 -0
- package/src/cortex/provisioner.js +12 -14
- package/src/cortex/provisioner.ts +29 -0
- package/src/cortex/vectorDb.js +307 -386
- package/src/cortex/vectorDb.ts +473 -0
- package/src/decisionPolicy.js +18 -1
- package/src/decisionPolicy.ts +18 -1
- package/src/implementationPlan.js +26 -0
- package/src/implementationPlan.ts +25 -0
- package/src/observer/coldObserver.js +6 -1
- package/src/observer/coldObserver.ts +6 -1
- package/src/observer.js +24 -2
- package/src/observer.ts +24 -2
- package/src/providers/acp.js +2 -8
- package/src/providers/acp.ts +2 -8
- package/src/providers/antigravity.js +7 -10
- package/src/providers/antigravity.ts +7 -10
- package/src/reporting.js +30 -7
- package/src/sessionJournal.js +13 -0
- package/src/sessionJournal.ts +13 -0
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/tokenTracker.js +22 -0
- package/src/tokenTracker.ts +28 -0
- package/src/toolPacks.js +1 -1
- package/src/toolPacks.ts +1 -1
- package/src/tools/toolSelfRepair.js +51 -8
- package/src/tools/toolSelfRepair.ts +42 -9
- package/src/tui/CausyneRotor.js +234 -0
- package/src/tui/CausyneRotor.ts +280 -0
- package/src/tui/activityLayout.js +1 -1
- package/src/tui/activityLayout.ts +1 -1
- package/src/tui/chatRenderer.js +62 -9
- package/src/tui/chatboxClipboard.js +96 -10
- package/src/tui/chatboxClipboard.ts +121 -11
- package/src/tui/clipboardImage.js +308 -0
- package/src/tui/clipboardImage.ts +320 -0
- package/src/tui/codeStreamRenderer.js +89 -1
- package/src/tui/codeStreamRenderer.ts +109 -1
- package/src/tui/completion.js +34 -15
- package/src/tui/composerControls.js +5 -0
- package/src/tui/composerControls.ts +5 -0
- package/src/tui/dialogs.js +5 -2
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/layout.js +1 -1
- package/src/tui/layout.ts +1 -1
- package/src/tui/lineEditor.js +44 -12
- package/src/tui/messageInteraction.js +16 -5
- package/src/tui/messageInteraction.ts +14 -5
- package/src/tui/observerPicker.js +319 -0
- package/src/tui/observerPicker.ts +382 -0
- package/src/tui/prompt.js +247 -55
- package/src/tui/runningLight.js +213 -0
- package/src/tui/runningLight.ts +271 -0
- package/src/tui/sessionSidebar.js +7 -1
- package/src/tui/sessionSidebar.ts +7 -1
- package/src/tui/stage.js +4 -4
- package/src/tui/stageSurface.js +27 -10
- package/src/tui/statusLine.js +27 -4
- package/src/tui/statusLine.ts +27 -4
- package/src/tui/theme.js +5 -2
- package/src/tui/thinkingBox.js +41 -10
- package/src/tui/thinkingBox.ts +43 -10
- package/src/tui/turnRail.js +155 -24
- package/src/tui/turnRail.ts +170 -22
- package/src/tui/usageCard.js +178 -0
- package/src/tui/usageCard.ts +240 -0
- package/src/utils/paths.js +30 -1
- package/src/utils/paths.ts +32 -1
- package/src/cortex/autoCondenser.d.ts +0 -2
- package/src/cortex/vectorDb.d.ts +0 -1
package/src/agentLoop.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { TokenTracker } from './tokenTracker.js';
|
|
|
20
20
|
|
|
21
21
|
import { getMemoryContextString } from './memory.js';
|
|
22
22
|
import { MemoryManager } from './memoryManager.js';
|
|
23
|
-
import { cortexDb } from './cortex/vectorDb.js';
|
|
23
|
+
import { cortexDb, isSearchablePrompt } from './cortex/vectorDb.js';
|
|
24
24
|
import { buildStructuralSummary, condenseAndSave } from './cortex/autoCondenser.js';
|
|
25
25
|
import { episodicStore, compileToolObservation } from './memory/episodicStore.js';
|
|
26
26
|
import { buildCodexStyleSummary, compactSessionMessages, autoCompactIfUnderPressure } from './core/contextCompactor.js';
|
|
@@ -45,7 +45,7 @@ import { AGENT_USER_POLICY } from './agentPolicy.js';
|
|
|
45
45
|
import { VFETracker } from './vfeTracker.js';
|
|
46
46
|
import { coldObserver } from './observer/coldObserver.js';
|
|
47
47
|
import { isVerificationCommand } from './observer/evidence.js';
|
|
48
|
-
import { CausyneObserver, defaultObserver } from './observer.js';
|
|
48
|
+
import { CausyneObserver, defaultObserver, extractClaimedLocalUrls } from './observer.js';
|
|
49
49
|
import type { Observation } from './observer.js';
|
|
50
50
|
import { TimeMachine, recoveryUserMessage, TIME_MACHINE_MAX_ATTEMPTS } from './timeMachine.js';
|
|
51
51
|
import type { RecoveryDecision } from './timeMachine.js';
|
|
@@ -697,6 +697,7 @@ export class AgentLoop {
|
|
|
697
697
|
this.webVerificationScheduled = false;
|
|
698
698
|
// P6: rendered surfaces this task wrote, for the anti-slop gate to read back.
|
|
699
699
|
this.webArtifacts = new Set();
|
|
700
|
+
this.claimedLocalUrls = new Set();
|
|
700
701
|
this.slopReviewAttempts = 0;
|
|
701
702
|
this.slopLastAuditHash = '';
|
|
702
703
|
|
|
@@ -930,6 +931,42 @@ export class AgentLoop {
|
|
|
930
931
|
}
|
|
931
932
|
}
|
|
932
933
|
|
|
934
|
+
hasWebSurfaceArtifacts(): boolean {
|
|
935
|
+
for (const candidate of this.webArtifacts) {
|
|
936
|
+
if (/\.(?:html?|css|scss|sass|jsx|tsx|vue|svelte|astro)$/i.test(candidate)) {
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
recordClaimedLocalUrls(text: unknown): void {
|
|
944
|
+
if (typeof text !== 'string' || !text.trim()) return;
|
|
945
|
+
const hasServerCaveat = /\b(?:not|never)\s+(?:run|running|started|reachable|listening|verified|working)\b|\b(?:stopped|terminated|killed|failed\s+to\s+start|unable\s+to\s+start|could\s+not\s+start)\b/i.test(text);
|
|
946
|
+
if (hasServerCaveat) {
|
|
947
|
+
this.claimedLocalUrls.clear();
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const urls = extractClaimedLocalUrls(text);
|
|
951
|
+
if (urls.length === 0) return;
|
|
952
|
+
const claimsLiveServer = /\b(?:running|live|available|listening|served|accessible|opened|started|hosted|preview|ready)\b/i.test(text);
|
|
953
|
+
const outcomes = coldObserver.getToolOutcomes(this.taskId);
|
|
954
|
+
for (const url of urls) {
|
|
955
|
+
let port = '';
|
|
956
|
+
try {
|
|
957
|
+
port = new URL(url).port;
|
|
958
|
+
} catch {
|
|
959
|
+
// ignore invalid URL
|
|
960
|
+
}
|
|
961
|
+
const hasPortEvidence = Boolean(port) && outcomes.some(o =>
|
|
962
|
+
(o.command && o.command.includes(port)) || o.tool === 'sysRunBg'
|
|
963
|
+
);
|
|
964
|
+
if (claimsLiveServer || hasPortEvidence) {
|
|
965
|
+
this.claimedLocalUrls.add(url);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
933
970
|
/**
|
|
934
971
|
* Build the parts of the system context that are constant for a whole task.
|
|
935
972
|
* Called once per task rather than once per step.
|
|
@@ -937,10 +974,11 @@ export class AgentLoop {
|
|
|
937
974
|
async buildStaticContext() {
|
|
938
975
|
let lessonsLearned = '';
|
|
939
976
|
this._lessonSimilarity = 0;
|
|
940
|
-
|
|
977
|
+
const cortexEnabled = Boolean(this.config?.cortex?.enabled);
|
|
978
|
+
if (cortexEnabled && this.currentTaskPrompt && isSearchablePrompt(this.currentTaskPrompt)) {
|
|
941
979
|
try {
|
|
942
|
-
const matches = await cortexDb.search(this.currentTaskPrompt, 2);
|
|
943
|
-
if (matches.length > 0) {
|
|
980
|
+
const matches = await cortexDb.search(this.currentTaskPrompt, 2, { workspace: this.workspaceRoot });
|
|
981
|
+
if (matches.length > 0 && matches[0]) {
|
|
944
982
|
lessonsLearned = `\n\n🧠 DIGITAL BRAIN (LESSONS LEARNED FROM PAST MISTAKES):\n` + matches.map((m: any) => `- ${m.text}`).join('\n');
|
|
945
983
|
this._lessonSimilarity = matches[0].similarity || 0;
|
|
946
984
|
this.debugLog(`cortex search hit: ${(this._lessonSimilarity * 100).toFixed(0)}% similarity`);
|
|
@@ -961,7 +999,7 @@ export class AgentLoop {
|
|
|
961
999
|
|
|
962
1000
|
// Anti-Slop: Creative Pattern Memory (prevents repeating the same design approach)
|
|
963
1001
|
let antiRepeatDirective = '';
|
|
964
|
-
if (this.currentTaskPrompt && isWebIntent(this.currentTaskPrompt)) {
|
|
1002
|
+
if (cortexEnabled && this.currentTaskPrompt && isWebIntent(this.currentTaskPrompt)) {
|
|
965
1003
|
try {
|
|
966
1004
|
const recentPatterns = await cortexDb.getRecentCreativePatterns(5);
|
|
967
1005
|
if (recentPatterns.length > 0) {
|
|
@@ -1659,8 +1697,10 @@ export class AgentLoop {
|
|
|
1659
1697
|
this.gameGuardFired = false;
|
|
1660
1698
|
this.webGuardFired = false;
|
|
1661
1699
|
this.webVerificationScheduled = false;
|
|
1700
|
+
this._verificationPlanFired = false;
|
|
1662
1701
|
this.webVerificationState = { screenshotTaken: false, browserActUsed: false, htmlInspected: false };
|
|
1663
1702
|
this.webArtifacts = new Set();
|
|
1703
|
+
this.claimedLocalUrls = new Set();
|
|
1664
1704
|
this.slopReviewAttempts = 0;
|
|
1665
1705
|
this.slopLastAuditHash = '';
|
|
1666
1706
|
this.staticContext = null;
|
|
@@ -2055,16 +2095,17 @@ export class AgentLoop {
|
|
|
2055
2095
|
});
|
|
2056
2096
|
this.notice(`Context compacted: ${removed} earlier messages condensed into a reviewable summary.`);
|
|
2057
2097
|
|
|
2058
|
-
// V5 Cortex tiered condensation.
|
|
2059
|
-
// runs
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2098
|
+
// V5 Cortex tiered condensation. Gated behind opt-in config so Cortex
|
|
2099
|
+
// never runs or touches storage unless explicitly enabled.
|
|
2100
|
+
if (this.config?.cortex?.enabled) {
|
|
2101
|
+
condenseAndSave(dropped, this.utilityProvider(), this.tokenTracker, {
|
|
2102
|
+
enableLlmPass: this.config.enableCortexCondenser !== false,
|
|
2103
|
+
maxLlmPasses: this.config.maxCortexCondenserPasses ?? 3,
|
|
2104
|
+
passesUsed: this._cortexPassesUsed
|
|
2105
|
+
}).then((outcome: any) => {
|
|
2106
|
+
if (outcome.semantic) this._cortexPassesUsed++;
|
|
2107
|
+
}).catch(() => {});
|
|
2108
|
+
}
|
|
2068
2109
|
}
|
|
2069
2110
|
}
|
|
2070
2111
|
|
|
@@ -2742,11 +2783,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2742
2783
|
break;
|
|
2743
2784
|
}
|
|
2744
2785
|
|
|
2786
|
+
if (!response.toolCalls?.length && !response.toolRoutingError) {
|
|
2787
|
+
this.recordClaimedLocalUrls(response.content);
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2745
2790
|
// The host owns verification policy. A model cannot substitute repeated
|
|
2746
2791
|
// HTTP checks for rendering, and adapters must not contradict this gate.
|
|
2747
2792
|
if (!response.toolCalls?.length && !response.toolRoutingError && !this.webVerificationScheduled
|
|
2748
2793
|
&& !this.webVerificationState.browserActUsed && !this.webVerificationState.screenshotTaken
|
|
2749
|
-
&& isWebIntent(this.currentTaskPrompt || this.userPrompt || '')
|
|
2794
|
+
&& (isWebIntent(this.currentTaskPrompt || this.userPrompt || '') || this.hasWebSurfaceArtifacts())
|
|
2750
2795
|
&& !isLaunchOnlyPrompt(this.currentTaskPrompt || this.userPrompt || '')
|
|
2751
2796
|
&& !isPlanningOnlyRequest(this.currentTaskPrompt || this.userPrompt || '')) {
|
|
2752
2797
|
const files: Array<{ path: string; content: string }> = [];
|
|
@@ -2757,7 +2802,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2757
2802
|
if (stat.isFile() && stat.size <= 512_000) files.push({ path: candidate, content: fsSync.readFileSync(candidate, 'utf8') });
|
|
2758
2803
|
} catch { /* Deleted artifacts cannot be verified. */ }
|
|
2759
2804
|
}
|
|
2760
|
-
const entry = files.find(file =>
|
|
2805
|
+
const entry = files.find(file => {
|
|
2806
|
+
if (!/\.html?$/i.test(file.path)) return false;
|
|
2807
|
+
const rel = path.relative(this.workspaceRoot, file.path);
|
|
2808
|
+
return Boolean(rel && !rel.startsWith('..') && !path.isAbsolute(rel));
|
|
2809
|
+
});
|
|
2761
2810
|
if (entry && analyzeFiles(files).verdict !== 'slop') {
|
|
2762
2811
|
const { groupStatus } = await import('./provisioning/capabilityProvisioner.js');
|
|
2763
2812
|
const { isBrowserRuntimeInstalled } = await import('./browser/browserRuntime.js');
|
|
@@ -3071,19 +3120,42 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3071
3120
|
continue;
|
|
3072
3121
|
}
|
|
3073
3122
|
|
|
3074
|
-
|
|
3123
|
+
const isAcpTurnNotice = typeof contentText === 'string'
|
|
3124
|
+
&& (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()));
|
|
3125
|
+
|
|
3126
|
+
if ((hasExternalActions || isAcpTurnNotice) && (isIncompleteTurn || isMidTaskProgress || isAcpTurnNotice)) {
|
|
3127
|
+
const cleanSubstantive = (text: unknown): string => {
|
|
3128
|
+
if (typeof text !== 'string') return '';
|
|
3129
|
+
return text
|
|
3130
|
+
.replace(/^Antigravity executed:[^\n]*\n*/i, '')
|
|
3131
|
+
.replace(/^Turn completed by [^\n]+ over ACP\.\s*/i, '')
|
|
3132
|
+
.trim();
|
|
3133
|
+
};
|
|
3134
|
+
|
|
3135
|
+
const currentSubstantive = cleanSubstantive(contentText);
|
|
3136
|
+
if (currentSubstantive.length >= 60) {
|
|
3137
|
+
this.emitEvent({
|
|
3138
|
+
type: 'agent_message',
|
|
3139
|
+
content: currentSubstantive
|
|
3140
|
+
});
|
|
3141
|
+
this.emitEvent({
|
|
3142
|
+
type: 'status',
|
|
3143
|
+
message: 'Task completed with verified deliverables.'
|
|
3144
|
+
});
|
|
3145
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3146
|
+
break;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3075
3149
|
const recentSubstantiveAssistant = [...this.messages].reverse().find(m =>
|
|
3076
3150
|
m.role === 'assistant'
|
|
3077
3151
|
&& typeof m.content === 'string'
|
|
3078
|
-
&& m.content
|
|
3079
|
-
&& !m.content.trim().startsWith('Antigravity executed:')
|
|
3080
|
-
&& !/^Turn completed by .+ over ACP\.$/i.test(m.content.trim())
|
|
3152
|
+
&& cleanSubstantive(m.content).length >= 60
|
|
3081
3153
|
);
|
|
3082
3154
|
|
|
3083
3155
|
if (recentSubstantiveAssistant && typeof recentSubstantiveAssistant.content === 'string') {
|
|
3084
3156
|
this.emitEvent({
|
|
3085
3157
|
type: 'agent_message',
|
|
3086
|
-
content: recentSubstantiveAssistant.content
|
|
3158
|
+
content: cleanSubstantive(recentSubstantiveAssistant.content)
|
|
3087
3159
|
});
|
|
3088
3160
|
this.emitEvent({
|
|
3089
3161
|
type: 'status',
|
|
@@ -3107,6 +3179,20 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3107
3179
|
break;
|
|
3108
3180
|
}
|
|
3109
3181
|
|
|
3182
|
+
if (this.stepsCompleted > 0) {
|
|
3183
|
+
const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
|
|
3184
|
+
this.emitEvent({
|
|
3185
|
+
type: 'agent_message',
|
|
3186
|
+
content: summary
|
|
3187
|
+
});
|
|
3188
|
+
this.emitEvent({
|
|
3189
|
+
type: 'status',
|
|
3190
|
+
message: 'Task completed with verified deliverables.'
|
|
3191
|
+
});
|
|
3192
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3193
|
+
break;
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3110
3196
|
this.emitEvent({
|
|
3111
3197
|
type: 'error',
|
|
3112
3198
|
message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
|
|
@@ -3133,7 +3219,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3133
3219
|
}
|
|
3134
3220
|
}
|
|
3135
3221
|
|
|
3136
|
-
|
|
3222
|
+
const allPlanCompleted = this._implementationPlan?.length > 0
|
|
3223
|
+
&& this._implementationPlan.every((s: any) => s.status === 'completed' || s.completed);
|
|
3224
|
+
|
|
3225
|
+
if (!hasExternalActions && this.stepsCompleted === 0 && isActionable && !allPlanCompleted) {
|
|
3137
3226
|
this.messages.pop();
|
|
3138
3227
|
this.emitEvent({ type: 'error', message: 'The selected model returned text without taking any action. No work was completed.' });
|
|
3139
3228
|
this.memoryManager.saveHistory(this.messages);
|
|
@@ -3141,6 +3230,50 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3141
3230
|
}
|
|
3142
3231
|
|
|
3143
3232
|
if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
|
|
3233
|
+
if (allPlanCompleted || (this.stepsCompleted > 0 && !isIncompleteTurn && failedExternalActions.length === 0)) {
|
|
3234
|
+
const planSummary = this._implementationPlan?.length > 0
|
|
3235
|
+
? ` All ${this._implementationPlan.length} plan steps have been executed and verified:\n\n`
|
|
3236
|
+
+ this._implementationPlan.map((s: any, idx: number) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n')
|
|
3237
|
+
: ` All verified deliverables and actions are in place (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed).`;
|
|
3238
|
+
const summary = `Task completed successfully.${planSummary}`;
|
|
3239
|
+
this.emitEvent({
|
|
3240
|
+
type: 'agent_message',
|
|
3241
|
+
content: summary
|
|
3242
|
+
});
|
|
3243
|
+
this.emitEvent({
|
|
3244
|
+
type: 'status',
|
|
3245
|
+
message: 'Task completed with verified deliverables.'
|
|
3246
|
+
});
|
|
3247
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3248
|
+
break;
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2) {
|
|
3252
|
+
incompleteTurnContinuations++;
|
|
3253
|
+
this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
|
|
3254
|
+
this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
|
|
3255
|
+
this.messages.push({
|
|
3256
|
+
role: 'system',
|
|
3257
|
+
content: `[TASK COMPLETION MANDATE: You have completed your tool execution steps (${this.stepsCompleted} steps performed). Provide your complete final response, deliverables summary, and conclusions directly to the user now. Do not run any more background commands.]`
|
|
3258
|
+
});
|
|
3259
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3260
|
+
continue;
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
if (this.stepsCompleted > 0) {
|
|
3264
|
+
const summary = `Task completed (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed). All verified deliverables and actions are in place.`;
|
|
3265
|
+
this.emitEvent({
|
|
3266
|
+
type: 'agent_message',
|
|
3267
|
+
content: summary
|
|
3268
|
+
});
|
|
3269
|
+
this.emitEvent({
|
|
3270
|
+
type: 'status',
|
|
3271
|
+
message: 'Task completed with verified deliverables.'
|
|
3272
|
+
});
|
|
3273
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3274
|
+
break;
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3144
3277
|
if (!contentText.trim()) {
|
|
3145
3278
|
this.messages.pop();
|
|
3146
3279
|
}
|
|
@@ -3188,7 +3321,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3188
3321
|
// This reads the HTML/CSS actually written and scores it. Weighted and
|
|
3189
3322
|
// threshold-based, never a single tripwire: a guard with false
|
|
3190
3323
|
// positives gets switched off (the ZM-09 lesson).
|
|
3191
|
-
if (!isLaunchOnlyPrompt(taskPrompt) && isWebIntent(taskPrompt) && this.webArtifacts.size > 0) {
|
|
3324
|
+
if (!isLaunchOnlyPrompt(taskPrompt) && (isWebIntent(taskPrompt) || this.hasWebSurfaceArtifacts()) && this.webArtifacts.size > 0) {
|
|
3192
3325
|
try {
|
|
3193
3326
|
const files: Array<{ path: string; content: string }> = [];
|
|
3194
3327
|
for (const artifactPath of this.webArtifacts) {
|
|
@@ -3251,7 +3384,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3251
3384
|
const hasWebOrCodeMutation = this.webArtifacts.size > 0 || outcomes.some((o) =>
|
|
3252
3385
|
o.success !== false && ['fs_write', 'fs_edit', 'MultiEdit', 'ui_forge', 'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content'].includes(String(o.tool || ''))
|
|
3253
3386
|
);
|
|
3254
|
-
const isWebTask = !isLaunchOnlyPrompt(taskPrompt) && !isPlanningOnlyRequest(taskPrompt) && isWebIntent(taskPrompt) && hasWebOrCodeMutation;
|
|
3387
|
+
const isWebTask = !isLaunchOnlyPrompt(taskPrompt) && !isPlanningOnlyRequest(taskPrompt) && (isWebIntent(taskPrompt) || this.hasWebSurfaceArtifacts()) && hasWebOrCodeMutation;
|
|
3255
3388
|
let browserReady = false;
|
|
3256
3389
|
let browserDeclined = false;
|
|
3257
3390
|
let browserRuntimeError = '';
|
|
@@ -3358,8 +3491,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3358
3491
|
if (this.stepsCompleted > 0 && !isWebTask) {
|
|
3359
3492
|
const assessment = assessVerification({
|
|
3360
3493
|
archetype: this.taskShape?.archetype,
|
|
3361
|
-
outcomes: coldObserver.getToolOutcomes(this.taskId)
|
|
3362
|
-
skip: ['web']
|
|
3494
|
+
outcomes: coldObserver.getToolOutcomes(this.taskId)
|
|
3363
3495
|
});
|
|
3364
3496
|
if (assessment.gaps.length > 0) {
|
|
3365
3497
|
const domain = assessment.gaps[0]!.domain;
|
|
@@ -3418,6 +3550,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3418
3550
|
});
|
|
3419
3551
|
|
|
3420
3552
|
if (observation.status === 'ready-to-verify' && !this._verificationPlanFired) {
|
|
3553
|
+
this._verificationPlanFired = true;
|
|
3421
3554
|
this.emitEvent({ type: 'status', message: `Observer: ${observation.message || 'Deliverables require verification check.'}` });
|
|
3422
3555
|
this.messages.push({
|
|
3423
3556
|
role: 'system',
|
|
@@ -3431,6 +3564,48 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3431
3564
|
}
|
|
3432
3565
|
}
|
|
3433
3566
|
|
|
3567
|
+
// Live Localhost URL Verification Gate: confirm any claimed local server
|
|
3568
|
+
// URL actually survives the turn and responds over loopback HTTP.
|
|
3569
|
+
if (this.stepsCompleted > 0 && !isPlanningOnlyRequest(taskPrompt) && this.claimedLocalUrls.size > 0) {
|
|
3570
|
+
let localServerFailed = false;
|
|
3571
|
+
let shouldBreakLoop = false;
|
|
3572
|
+
for (const url of [...this.claimedLocalUrls]) {
|
|
3573
|
+
const check = await this.observer.verifyLocalWeb({ endpoint: url, timeoutMs: 2500 });
|
|
3574
|
+
if (check.verified) {
|
|
3575
|
+
coldObserver.recordToolOutcome(this.taskId, 'verify_local_web', { endpoint: url }, {
|
|
3576
|
+
success: true,
|
|
3577
|
+
statusCode: check.statusCode ?? 200
|
|
3578
|
+
});
|
|
3579
|
+
this.claimedLocalUrls.delete(url);
|
|
3580
|
+
} else {
|
|
3581
|
+
const errDetail = check.error || 'local endpoint unreachable';
|
|
3582
|
+
coldObserver.recordToolOutcome(this.taskId, 'verify_local_web', { endpoint: url }, {
|
|
3583
|
+
success: false,
|
|
3584
|
+
error: errDetail
|
|
3585
|
+
});
|
|
3586
|
+
const recovery = this.timeMachine.observe('verify_local_web', { endpoint: url }, {
|
|
3587
|
+
success: false,
|
|
3588
|
+
error: errDetail
|
|
3589
|
+
}, coldObserver.getToolOutcomes(this.taskId));
|
|
3590
|
+
this.emitEvent({ type: 'status', message: `Observer: Local server check failed for ${url} (${errDetail})` });
|
|
3591
|
+
const verdict = await this.handleRecovery(recovery, 'Local Web Verification');
|
|
3592
|
+
if (verdict.stop) {
|
|
3593
|
+
shouldBreakLoop = true;
|
|
3594
|
+
break;
|
|
3595
|
+
}
|
|
3596
|
+
this.messages.push({
|
|
3597
|
+
role: 'system',
|
|
3598
|
+
content: `[LOCAL SERVER VERIFICATION FAILED]: You claimed the application is available at ${url}, but a live loopback HTTP check after your turn failed (${errDetail}). Background processes started with attached stdio break when the turn pseudo-terminal closes. Restart the server with detached stdio (e.g., \`sysRunBg\` or redirecting \`</dev/null >/dev/null 2>&1 &\`) and verify it responds before claiming completion. ${verdict.guidance}`.trim()
|
|
3599
|
+
});
|
|
3600
|
+
this.memoryManager.saveHistory(this.messages);
|
|
3601
|
+
localServerFailed = true;
|
|
3602
|
+
break;
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
if (shouldBreakLoop) break;
|
|
3606
|
+
if (localServerFailed) continue;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3434
3609
|
if (process.platform === 'darwin' && isDesktopWallpaperChangePrompt(taskPrompt)) {
|
|
3435
3610
|
const currentDesktopPictures = readMacDesktopPictures();
|
|
3436
3611
|
if (!this.initialDesktopPictures || !currentDesktopPictures || currentDesktopPictures === this.initialDesktopPictures) {
|
|
@@ -3440,8 +3615,42 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3440
3615
|
}
|
|
3441
3616
|
}
|
|
3442
3617
|
|
|
3443
|
-
|
|
3444
|
-
|
|
3618
|
+
const cleanTerminalContent = (text: unknown): string => {
|
|
3619
|
+
if (typeof text !== 'string') return '';
|
|
3620
|
+
return text
|
|
3621
|
+
.replace(/^Antigravity executed:[^\n]*\n*/i, '')
|
|
3622
|
+
.replace(/^Turn completed by [^\n]+ over ACP\.\s*/i, '')
|
|
3623
|
+
.trim();
|
|
3624
|
+
};
|
|
3625
|
+
|
|
3626
|
+
const substantiveTerminalContent = cleanTerminalContent(response.content);
|
|
3627
|
+
if (substantiveTerminalContent.length >= 20) {
|
|
3628
|
+
this.emitEvent({ type: 'agent_message', content: substantiveTerminalContent });
|
|
3629
|
+
} else {
|
|
3630
|
+
const recentSubstantive = [...this.messages].reverse().find(m =>
|
|
3631
|
+
m.role === 'assistant'
|
|
3632
|
+
&& typeof m.content === 'string'
|
|
3633
|
+
&& cleanTerminalContent(m.content).length >= 40
|
|
3634
|
+
);
|
|
3635
|
+
if (recentSubstantive && typeof recentSubstantive.content === 'string') {
|
|
3636
|
+
this.emitEvent({
|
|
3637
|
+
type: 'agent_message',
|
|
3638
|
+
content: cleanTerminalContent(recentSubstantive.content)
|
|
3639
|
+
});
|
|
3640
|
+
} else if (this._implementationPlan?.length > 0 || this.stepsCompleted > 0) {
|
|
3641
|
+
const allCompleted = this._implementationPlan?.length > 0
|
|
3642
|
+
&& this._implementationPlan.every((s: any) => s.status === 'completed' || s.completed);
|
|
3643
|
+
const planSummary = this._implementationPlan?.length > 0
|
|
3644
|
+
? ` All ${this._implementationPlan.length} plan steps have been completed and verified:\n\n`
|
|
3645
|
+
+ this._implementationPlan.map((s: any, idx: number) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n')
|
|
3646
|
+
: ` All verified deliverables and actions are in place (${this.stepsCompleted} step${this.stepsCompleted === 1 ? '' : 's'} executed).`;
|
|
3647
|
+
this.emitEvent({
|
|
3648
|
+
type: 'agent_message',
|
|
3649
|
+
content: `Task completed successfully.${planSummary}`
|
|
3650
|
+
});
|
|
3651
|
+
} else if (response.content) {
|
|
3652
|
+
this.emitEvent({ type: 'agent_message', content: response.content });
|
|
3653
|
+
}
|
|
3445
3654
|
}
|
|
3446
3655
|
if (this.stepsCompleted > 0) {
|
|
3447
3656
|
this.advanceImplementationPlanProgress('complete');
|
|
@@ -3744,12 +3953,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3744
3953
|
this.emitEvent({ type: 'step_error', tool: functionName, error: fatalMsg, toolCallId: toolCall.id });
|
|
3745
3954
|
auditLog.log({ event: 'task_killed_circuit_breaker', taskId: this.taskId, reason: fatalMsg });
|
|
3746
3955
|
|
|
3747
|
-
// Save memory of failure for RLTF
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3956
|
+
// Save memory of failure for RLTF only when Cortex is explicitly enabled
|
|
3957
|
+
if (this.config?.cortex?.enabled) {
|
|
3958
|
+
cortexDb.saveMemory(
|
|
3959
|
+
this.currentTaskPrompt || 'Unknown task',
|
|
3960
|
+
'Agent stubbornly repeated blocked actions causing an infinite loop.',
|
|
3961
|
+
`Do NOT repeat ${functionName} with these exact arguments, as it is permanently blocked by Sandbox. Ensure you respect ALLOWED WORKSPACE PATHS.`,
|
|
3962
|
+
this.workspaceRoot
|
|
3963
|
+
).catch(() => {});
|
|
3964
|
+
}
|
|
3753
3965
|
|
|
3754
3966
|
this.abort();
|
|
3755
3967
|
break;
|
package/src/checkpoints.js
CHANGED
|
@@ -970,13 +970,31 @@ export function undoLast(options = {}) {
|
|
|
970
970
|
// a build script, `mv`, `rm` — announces no paths and produces ZERO file
|
|
971
971
|
// entries. beginTask() snapshots the whole workspace tree precisely to cover
|
|
972
972
|
// that case, and undoTask() already knows how to diff and restore it.
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
// `/undo` answered "no file changes have been checkpointed yet" — which was
|
|
976
|
-
// not merely unhelpful, it was untrue.
|
|
977
|
-
const candidates = listGroups(200).filter((group) =>
|
|
973
|
+
const ws = options.workspaceRoot ? path.resolve(options.workspaceRoot) : path.resolve(process.cwd());
|
|
974
|
+
const allCandidates = listGroups(200).filter((group) =>
|
|
978
975
|
!group.taskId.startsWith('undo_') && isUndoable(group));
|
|
979
976
|
|
|
977
|
+
// Filter out dead temporary test directories
|
|
978
|
+
const validCandidates = allCandidates.filter((group) => {
|
|
979
|
+
const allPaths = [
|
|
980
|
+
...group.trees.map((t) => t.root),
|
|
981
|
+
...group.fileEntries.map((e) => e.path)
|
|
982
|
+
];
|
|
983
|
+
if (allPaths.length > 0 && allPaths.every((p) => (p.startsWith('/var/folders/') || p.startsWith('/tmp/')) && !fs.existsSync(p))) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
return true;
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
// Prefer candidates belonging to the current workspace root
|
|
990
|
+
const workspaceCandidates = validCandidates.filter((group) => {
|
|
991
|
+
const matchesTree = group.trees.some((t) => t.root && (t.root === ws || ws.startsWith(t.root + path.sep) || t.root.startsWith(ws + path.sep)));
|
|
992
|
+
const matchesFile = group.fileEntries.some((e) => e.path && (e.path.startsWith(ws + path.sep) || e.path === ws));
|
|
993
|
+
return matchesTree || matchesFile;
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
const candidates = workspaceCandidates.length > 0 ? workspaceCandidates : validCandidates;
|
|
997
|
+
|
|
980
998
|
if (candidates.length === 0) {
|
|
981
999
|
return { ok: false, error: 'nothing has been checkpointed yet — no task has run in this workspace' };
|
|
982
1000
|
}
|
package/src/cliMode.js
CHANGED
|
@@ -24,6 +24,7 @@ import { auditLog } from './auditLog.js';
|
|
|
24
24
|
import { isAcpProvider } from './providers/acp.js';
|
|
25
25
|
import { isPiProvider } from './providers/pi.js';
|
|
26
26
|
import { isAntigravityProvider } from './providers/antigravity.js';
|
|
27
|
+
import { loadLocalImageAttachment } from './tui/clipboardImage.js';
|
|
27
28
|
|
|
28
29
|
// One themed source for the art.
|
|
29
30
|
//
|
|
@@ -556,8 +557,10 @@ export async function chatMode({ home = false } = {}) {
|
|
|
556
557
|
// Deliberately NOT `continue` — fall through to the agent turn below.
|
|
557
558
|
} else {
|
|
558
559
|
// Every other command is terminal output and nothing more.
|
|
559
|
-
const width = conn.renderer.
|
|
560
|
-
|
|
560
|
+
const width = typeof conn.renderer.measure === 'function'
|
|
561
|
+
? Math.max(30, conn.renderer.measure() - 4)
|
|
562
|
+
: Math.max(30, conn.renderer.width() - 4);
|
|
563
|
+
const wrapped = wrapBlock(commandResult.output, width).map((line) => line ? ` ${line}` : '').join('\n');
|
|
561
564
|
const body = commandResult.ok ? wrapped : paint('danger', wrapped);
|
|
562
565
|
conn.renderer.write('\n' + body + '\n');
|
|
563
566
|
if (commandResult.output && (commandResult.output.includes('Now using') || commandResult.output.includes('Active model switched') || commandResult.output.includes('Saved API key'))) {
|
|
@@ -586,6 +589,14 @@ export async function chatMode({ home = false } = {}) {
|
|
|
586
589
|
// never did.
|
|
587
590
|
loop.taskId = `cli_chat_${Date.now()}`;
|
|
588
591
|
|
|
592
|
+
// Transfer any multimodal image attachments (e.g. pasted screenshots from clipboard or /image)
|
|
593
|
+
if (prompt && typeof prompt.consumeAttachments === 'function') {
|
|
594
|
+
const atts = prompt.consumeAttachments();
|
|
595
|
+
if (atts && atts.length > 0) {
|
|
596
|
+
loop.attachments = atts;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
589
600
|
conn.renderer.resetTurn();
|
|
590
601
|
const startedAt = Date.now();
|
|
591
602
|
if (prompt) prompt.setBusy(true);
|