@causyne/agent 1.20.62 → 1.20.65
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/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/agentLoop.js +181 -11
- package/src/agentLoop.ts +184 -11
- package/src/approvalPolicy.js +19 -0
- package/src/approvalPolicy.ts +18 -0
- package/src/browser/causyneBrowser.js +34 -4
- package/src/browser/causyneBrowser.ts +32 -4
- package/src/cliMode.js +12 -28
- package/src/commands.js +33 -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/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- 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 +56 -7
- 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/composerControls.js +2 -0
- package/src/tui/composerControls.ts +2 -0
- package/src/tui/dialogs.js +41 -6
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- 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 +4 -8
- package/src/tui/observerPicker.ts +4 -8
- package/src/tui/prompt.js +80 -43
- 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 +21 -14
- 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/agentLoop.ts
CHANGED
|
@@ -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.
|
|
@@ -1660,8 +1697,10 @@ export class AgentLoop {
|
|
|
1660
1697
|
this.gameGuardFired = false;
|
|
1661
1698
|
this.webGuardFired = false;
|
|
1662
1699
|
this.webVerificationScheduled = false;
|
|
1700
|
+
this._verificationPlanFired = false;
|
|
1663
1701
|
this.webVerificationState = { screenshotTaken: false, browserActUsed: false, htmlInspected: false };
|
|
1664
1702
|
this.webArtifacts = new Set();
|
|
1703
|
+
this.claimedLocalUrls = new Set();
|
|
1665
1704
|
this.slopReviewAttempts = 0;
|
|
1666
1705
|
this.slopLastAuditHash = '';
|
|
1667
1706
|
this.staticContext = null;
|
|
@@ -2744,11 +2783,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2744
2783
|
break;
|
|
2745
2784
|
}
|
|
2746
2785
|
|
|
2786
|
+
if (!response.toolCalls?.length && !response.toolRoutingError) {
|
|
2787
|
+
this.recordClaimedLocalUrls(response.content);
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2747
2790
|
// The host owns verification policy. A model cannot substitute repeated
|
|
2748
2791
|
// HTTP checks for rendering, and adapters must not contradict this gate.
|
|
2749
2792
|
if (!response.toolCalls?.length && !response.toolRoutingError && !this.webVerificationScheduled
|
|
2750
2793
|
&& !this.webVerificationState.browserActUsed && !this.webVerificationState.screenshotTaken
|
|
2751
|
-
&& isWebIntent(this.currentTaskPrompt || this.userPrompt || '')
|
|
2794
|
+
&& (isWebIntent(this.currentTaskPrompt || this.userPrompt || '') || this.hasWebSurfaceArtifacts())
|
|
2752
2795
|
&& !isLaunchOnlyPrompt(this.currentTaskPrompt || this.userPrompt || '')
|
|
2753
2796
|
&& !isPlanningOnlyRequest(this.currentTaskPrompt || this.userPrompt || '')) {
|
|
2754
2797
|
const files: Array<{ path: string; content: string }> = [];
|
|
@@ -2759,7 +2802,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2759
2802
|
if (stat.isFile() && stat.size <= 512_000) files.push({ path: candidate, content: fsSync.readFileSync(candidate, 'utf8') });
|
|
2760
2803
|
} catch { /* Deleted artifacts cannot be verified. */ }
|
|
2761
2804
|
}
|
|
2762
|
-
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
|
+
});
|
|
2763
2810
|
if (entry && analyzeFiles(files).verdict !== 'slop') {
|
|
2764
2811
|
const { groupStatus } = await import('./provisioning/capabilityProvisioner.js');
|
|
2765
2812
|
const { isBrowserRuntimeInstalled } = await import('./browser/browserRuntime.js');
|
|
@@ -3073,7 +3120,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3073
3120
|
continue;
|
|
3074
3121
|
}
|
|
3075
3122
|
|
|
3076
|
-
|
|
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)) {
|
|
3077
3127
|
const cleanSubstantive = (text: unknown): string => {
|
|
3078
3128
|
if (typeof text !== 'string') return '';
|
|
3079
3129
|
return text
|
|
@@ -3169,7 +3219,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3169
3219
|
}
|
|
3170
3220
|
}
|
|
3171
3221
|
|
|
3172
|
-
|
|
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) {
|
|
3173
3226
|
this.messages.pop();
|
|
3174
3227
|
this.emitEvent({ type: 'error', message: 'The selected model returned text without taking any action. No work was completed.' });
|
|
3175
3228
|
this.memoryManager.saveHistory(this.messages);
|
|
@@ -3177,6 +3230,50 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3177
3230
|
}
|
|
3178
3231
|
|
|
3179
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
|
+
|
|
3180
3277
|
if (!contentText.trim()) {
|
|
3181
3278
|
this.messages.pop();
|
|
3182
3279
|
}
|
|
@@ -3224,7 +3321,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3224
3321
|
// This reads the HTML/CSS actually written and scores it. Weighted and
|
|
3225
3322
|
// threshold-based, never a single tripwire: a guard with false
|
|
3226
3323
|
// positives gets switched off (the ZM-09 lesson).
|
|
3227
|
-
if (!isLaunchOnlyPrompt(taskPrompt) && isWebIntent(taskPrompt) && this.webArtifacts.size > 0) {
|
|
3324
|
+
if (!isLaunchOnlyPrompt(taskPrompt) && (isWebIntent(taskPrompt) || this.hasWebSurfaceArtifacts()) && this.webArtifacts.size > 0) {
|
|
3228
3325
|
try {
|
|
3229
3326
|
const files: Array<{ path: string; content: string }> = [];
|
|
3230
3327
|
for (const artifactPath of this.webArtifacts) {
|
|
@@ -3287,7 +3384,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3287
3384
|
const hasWebOrCodeMutation = this.webArtifacts.size > 0 || outcomes.some((o) =>
|
|
3288
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 || ''))
|
|
3289
3386
|
);
|
|
3290
|
-
const isWebTask = !isLaunchOnlyPrompt(taskPrompt) && !isPlanningOnlyRequest(taskPrompt) && isWebIntent(taskPrompt) && hasWebOrCodeMutation;
|
|
3387
|
+
const isWebTask = !isLaunchOnlyPrompt(taskPrompt) && !isPlanningOnlyRequest(taskPrompt) && (isWebIntent(taskPrompt) || this.hasWebSurfaceArtifacts()) && hasWebOrCodeMutation;
|
|
3291
3388
|
let browserReady = false;
|
|
3292
3389
|
let browserDeclined = false;
|
|
3293
3390
|
let browserRuntimeError = '';
|
|
@@ -3394,8 +3491,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3394
3491
|
if (this.stepsCompleted > 0 && !isWebTask) {
|
|
3395
3492
|
const assessment = assessVerification({
|
|
3396
3493
|
archetype: this.taskShape?.archetype,
|
|
3397
|
-
outcomes: coldObserver.getToolOutcomes(this.taskId)
|
|
3398
|
-
skip: ['web']
|
|
3494
|
+
outcomes: coldObserver.getToolOutcomes(this.taskId)
|
|
3399
3495
|
});
|
|
3400
3496
|
if (assessment.gaps.length > 0) {
|
|
3401
3497
|
const domain = assessment.gaps[0]!.domain;
|
|
@@ -3454,6 +3550,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3454
3550
|
});
|
|
3455
3551
|
|
|
3456
3552
|
if (observation.status === 'ready-to-verify' && !this._verificationPlanFired) {
|
|
3553
|
+
this._verificationPlanFired = true;
|
|
3457
3554
|
this.emitEvent({ type: 'status', message: `Observer: ${observation.message || 'Deliverables require verification check.'}` });
|
|
3458
3555
|
this.messages.push({
|
|
3459
3556
|
role: 'system',
|
|
@@ -3467,6 +3564,48 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3467
3564
|
}
|
|
3468
3565
|
}
|
|
3469
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
|
+
|
|
3470
3609
|
if (process.platform === 'darwin' && isDesktopWallpaperChangePrompt(taskPrompt)) {
|
|
3471
3610
|
const currentDesktopPictures = readMacDesktopPictures();
|
|
3472
3611
|
if (!this.initialDesktopPictures || !currentDesktopPictures || currentDesktopPictures === this.initialDesktopPictures) {
|
|
@@ -3476,8 +3615,42 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3476
3615
|
}
|
|
3477
3616
|
}
|
|
3478
3617
|
|
|
3479
|
-
|
|
3480
|
-
|
|
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
|
+
}
|
|
3481
3654
|
}
|
|
3482
3655
|
if (this.stepsCompleted > 0) {
|
|
3483
3656
|
this.advanceImplementationPlanProgress('complete');
|
package/src/approvalPolicy.js
CHANGED
|
@@ -38,6 +38,22 @@ export function isWholeFileDeletion(tool, args) {
|
|
|
38
38
|
return command.length > 0
|
|
39
39
|
&& (WHOLE_FILE_DELETE.test(command) || DELETE_API_CALL.test(command) || NESTED_SHELL_DELETE.test(command));
|
|
40
40
|
}
|
|
41
|
+
/** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Mode B or C unless uploading or downloading files. */
|
|
42
|
+
export function isRoutineBrowserVerification(tool, args) {
|
|
43
|
+
if (tool !== 'browser_act')
|
|
44
|
+
return false;
|
|
45
|
+
const actions = Array.isArray(args?.actions) ? args.actions : [];
|
|
46
|
+
if (actions.length === 0) {
|
|
47
|
+
const singleType = typeof args?.action === 'string' ? args.action : typeof args?.type === 'string' ? args.type : '';
|
|
48
|
+
return singleType !== 'download' && singleType !== 'upload';
|
|
49
|
+
}
|
|
50
|
+
return !actions.some(item => {
|
|
51
|
+
if (!item || typeof item !== 'object')
|
|
52
|
+
return false;
|
|
53
|
+
const type = String(item.type ?? item.action ?? '');
|
|
54
|
+
return type === 'download' || type === 'upload';
|
|
55
|
+
});
|
|
56
|
+
}
|
|
41
57
|
/** Prompt policy only. Sandbox denial, workspace checks, and observer veto run separately. */
|
|
42
58
|
export function requiresToolApproval(input) {
|
|
43
59
|
if (input.mode === 'C') {
|
|
@@ -48,6 +64,9 @@ export function requiresToolApproval(input) {
|
|
|
48
64
|
}
|
|
49
65
|
if (input.standingApproval)
|
|
50
66
|
return false;
|
|
67
|
+
if (input.mode !== 'A' && isRoutineBrowserVerification(input.tool, input.args)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
51
70
|
return input.risk === 'extreme'
|
|
52
71
|
|| input.heavyDownload
|
|
53
72
|
|| input.risk === 'dangerous'
|
package/src/approvalPolicy.ts
CHANGED
|
@@ -51,6 +51,21 @@ export function isWholeFileDeletion(tool: string, args: Record<string, unknown>)
|
|
|
51
51
|
&& (WHOLE_FILE_DELETE.test(command) || DELETE_API_CALL.test(command) || NESTED_SHELL_DELETE.test(command));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Mode B or C unless uploading or downloading files. */
|
|
55
|
+
export function isRoutineBrowserVerification(tool: string, args: Record<string, unknown>): boolean {
|
|
56
|
+
if (tool !== 'browser_act') return false;
|
|
57
|
+
const actions = Array.isArray(args?.actions) ? args.actions : [];
|
|
58
|
+
if (actions.length === 0) {
|
|
59
|
+
const singleType = typeof args?.action === 'string' ? args.action : typeof args?.type === 'string' ? args.type : '';
|
|
60
|
+
return singleType !== 'download' && singleType !== 'upload';
|
|
61
|
+
}
|
|
62
|
+
return !actions.some(item => {
|
|
63
|
+
if (!item || typeof item !== 'object') return false;
|
|
64
|
+
const type = String((item as { type?: unknown; action?: unknown }).type ?? (item as { action?: unknown }).action ?? '');
|
|
65
|
+
return type === 'download' || type === 'upload';
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
/** Prompt policy only. Sandbox denial, workspace checks, and observer veto run separately. */
|
|
55
70
|
export function requiresToolApproval(input: ToolApprovalInput): boolean {
|
|
56
71
|
if (input.mode === 'C') {
|
|
@@ -59,6 +74,9 @@ export function requiresToolApproval(input: ToolApprovalInput): boolean {
|
|
|
59
74
|
return input.tool !== 'fs_delete' || !input.standingApproval;
|
|
60
75
|
}
|
|
61
76
|
if (input.standingApproval) return false;
|
|
77
|
+
if (input.mode !== 'A' && isRoutineBrowserVerification(input.tool, input.args)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
62
80
|
return input.risk === 'extreme'
|
|
63
81
|
|| input.heavyDownload
|
|
64
82
|
|| input.risk === 'dangerous'
|
|
@@ -10,7 +10,7 @@ import { windowSnapshot } from './snapshotWindow.js';
|
|
|
10
10
|
const NAVIGATION_TIMEOUT_MS = 30_000;
|
|
11
11
|
const ACTION_TIMEOUT_MS = 12_000;
|
|
12
12
|
const IFRAME_SNAPSHOT_TIMEOUT_MS = 3_000;
|
|
13
|
-
const IDLE_CLOSE_MS =
|
|
13
|
+
const IDLE_CLOSE_MS = 30 * 60_000;
|
|
14
14
|
const MAX_SEARCH_RESULTS = 10;
|
|
15
15
|
const MAX_EXTRACT_CHARS = 80_000;
|
|
16
16
|
const MAX_DOWNLOAD_BYTES = 250 * 1024 * 1024;
|
|
@@ -670,6 +670,7 @@ export class CausyneBrowser {
|
|
|
670
670
|
securedPages = new WeakSet();
|
|
671
671
|
pageStates = new WeakMap();
|
|
672
672
|
contextRouteInstalled = false;
|
|
673
|
+
lastTarget = null;
|
|
673
674
|
constructor(options = {}) {
|
|
674
675
|
this.workspace = path.resolve(options.workspace ?? process.cwd());
|
|
675
676
|
this.ensureBrowserCapability = options.ensureBrowserCapability ?? (() => ensureCapability('browser'));
|
|
@@ -681,8 +682,10 @@ export class CausyneBrowser {
|
|
|
681
682
|
}
|
|
682
683
|
setWorkspace(workspace) {
|
|
683
684
|
if (workspace && typeof workspace === 'string') {
|
|
684
|
-
if (this.workspace !== path.resolve(workspace))
|
|
685
|
+
if (this.workspace !== path.resolve(workspace)) {
|
|
685
686
|
this.workspacePreview.clear();
|
|
687
|
+
this.lastTarget = null;
|
|
688
|
+
}
|
|
686
689
|
this.workspace = path.resolve(workspace);
|
|
687
690
|
}
|
|
688
691
|
}
|
|
@@ -745,6 +748,7 @@ export class CausyneBrowser {
|
|
|
745
748
|
async snapshot(offset = 0) {
|
|
746
749
|
await this.start();
|
|
747
750
|
const state = await this.activeTab();
|
|
751
|
+
await this.restoreLastTargetIfBlank(state);
|
|
748
752
|
await this.captureSnapshotState(state);
|
|
749
753
|
return {
|
|
750
754
|
...windowSnapshot(state.lastSnapshot, offset),
|
|
@@ -1102,6 +1106,7 @@ export class CausyneBrowser {
|
|
|
1102
1106
|
state.refs.clear();
|
|
1103
1107
|
state.lastSnapshot = '';
|
|
1104
1108
|
state.lastStructure = null;
|
|
1109
|
+
this.lastTarget = { kind: 'url', url: state.page.url() };
|
|
1105
1110
|
}
|
|
1106
1111
|
async preview(state, filePath, workspace) {
|
|
1107
1112
|
state.runtimeErrors = [];
|
|
@@ -1113,6 +1118,28 @@ export class CausyneBrowser {
|
|
|
1113
1118
|
state.refs.clear();
|
|
1114
1119
|
state.lastSnapshot = '';
|
|
1115
1120
|
state.lastStructure = null;
|
|
1121
|
+
this.lastTarget = { kind: 'preview', workspace, filePath };
|
|
1122
|
+
}
|
|
1123
|
+
async restoreLastTargetIfBlank(state) {
|
|
1124
|
+
if (!this.lastTarget)
|
|
1125
|
+
return false;
|
|
1126
|
+
const currentUrl = state.page.url();
|
|
1127
|
+
if (currentUrl && currentUrl !== 'about:blank')
|
|
1128
|
+
return false;
|
|
1129
|
+
const target = this.lastTarget;
|
|
1130
|
+
try {
|
|
1131
|
+
if (target.kind === 'preview') {
|
|
1132
|
+
await this.preview(state, target.filePath, target.workspace);
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
await this.navigate(state, target.url);
|
|
1136
|
+
}
|
|
1137
|
+
await this.captureSnapshotState(state);
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
catch {
|
|
1141
|
+
return false;
|
|
1142
|
+
}
|
|
1116
1143
|
}
|
|
1117
1144
|
async navigateWithMacroFallback(state, action) {
|
|
1118
1145
|
const { targetUrl, macroName, macroQuery } = this.resolveTargetUrl(action);
|
|
@@ -1178,8 +1205,11 @@ export class CausyneBrowser {
|
|
|
1178
1205
|
const refId = action.ref ?? (action.index !== undefined ? `e${action.index}` : undefined);
|
|
1179
1206
|
if (refId) {
|
|
1180
1207
|
let ref = state.refs.get(refId);
|
|
1181
|
-
if (!ref
|
|
1182
|
-
await this.
|
|
1208
|
+
if (!ref) {
|
|
1209
|
+
await this.restoreLastTargetIfBlank(state);
|
|
1210
|
+
if (!state.refs.has(refId)) {
|
|
1211
|
+
await this.captureSnapshotState(state).catch(() => { });
|
|
1212
|
+
}
|
|
1183
1213
|
ref = state.refs.get(refId);
|
|
1184
1214
|
}
|
|
1185
1215
|
if (!ref)
|
|
@@ -16,7 +16,7 @@ import { windowSnapshot, type SnapshotWindow } from './snapshotWindow.js';
|
|
|
16
16
|
const NAVIGATION_TIMEOUT_MS = 30_000;
|
|
17
17
|
const ACTION_TIMEOUT_MS = 12_000;
|
|
18
18
|
const IFRAME_SNAPSHOT_TIMEOUT_MS = 3_000;
|
|
19
|
-
const IDLE_CLOSE_MS =
|
|
19
|
+
const IDLE_CLOSE_MS = 30 * 60_000;
|
|
20
20
|
const MAX_SEARCH_RESULTS = 10;
|
|
21
21
|
const MAX_EXTRACT_CHARS = 80_000;
|
|
22
22
|
const MAX_DOWNLOAD_BYTES = 250 * 1024 * 1024;
|
|
@@ -936,6 +936,7 @@ export class CausyneBrowser {
|
|
|
936
936
|
private securedPages = new WeakSet<object>();
|
|
937
937
|
private pageStates = new WeakMap<object, TabState>();
|
|
938
938
|
private contextRouteInstalled = false;
|
|
939
|
+
private lastTarget: { kind: 'preview'; workspace: string; filePath: string } | { kind: 'url'; url: string } | null = null;
|
|
939
940
|
|
|
940
941
|
constructor(options: RuntimeOptions = {}) {
|
|
941
942
|
this.workspace = path.resolve(options.workspace ?? process.cwd());
|
|
@@ -949,7 +950,10 @@ export class CausyneBrowser {
|
|
|
949
950
|
|
|
950
951
|
setWorkspace(workspace: string): void {
|
|
951
952
|
if (workspace && typeof workspace === 'string') {
|
|
952
|
-
if (this.workspace !== path.resolve(workspace))
|
|
953
|
+
if (this.workspace !== path.resolve(workspace)) {
|
|
954
|
+
this.workspacePreview.clear();
|
|
955
|
+
this.lastTarget = null;
|
|
956
|
+
}
|
|
953
957
|
this.workspace = path.resolve(workspace);
|
|
954
958
|
}
|
|
955
959
|
}
|
|
@@ -1012,6 +1016,7 @@ export class CausyneBrowser {
|
|
|
1012
1016
|
async snapshot(offset = 0): Promise<SnapshotWindow & { tabId: string; url: string; title: string; refsCount: number; structure?: PageStructure | null }> {
|
|
1013
1017
|
await this.start();
|
|
1014
1018
|
const state = await this.activeTab();
|
|
1019
|
+
await this.restoreLastTargetIfBlank(state);
|
|
1015
1020
|
await this.captureSnapshotState(state);
|
|
1016
1021
|
return {
|
|
1017
1022
|
...windowSnapshot(state.lastSnapshot, offset),
|
|
@@ -1342,6 +1347,7 @@ export class CausyneBrowser {
|
|
|
1342
1347
|
state.refs.clear();
|
|
1343
1348
|
state.lastSnapshot = '';
|
|
1344
1349
|
state.lastStructure = null;
|
|
1350
|
+
this.lastTarget = { kind: 'url', url: state.page.url() };
|
|
1345
1351
|
}
|
|
1346
1352
|
|
|
1347
1353
|
private async preview(state: TabState, filePath: string, workspace: string): Promise<void> {
|
|
@@ -1353,6 +1359,25 @@ export class CausyneBrowser {
|
|
|
1353
1359
|
state.refs.clear();
|
|
1354
1360
|
state.lastSnapshot = '';
|
|
1355
1361
|
state.lastStructure = null;
|
|
1362
|
+
this.lastTarget = { kind: 'preview', workspace, filePath };
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
private async restoreLastTargetIfBlank(state: TabState): Promise<boolean> {
|
|
1366
|
+
if (!this.lastTarget) return false;
|
|
1367
|
+
const currentUrl = state.page.url();
|
|
1368
|
+
if (currentUrl && currentUrl !== 'about:blank') return false;
|
|
1369
|
+
const target = this.lastTarget;
|
|
1370
|
+
try {
|
|
1371
|
+
if (target.kind === 'preview') {
|
|
1372
|
+
await this.preview(state, target.filePath, target.workspace);
|
|
1373
|
+
} else {
|
|
1374
|
+
await this.navigate(state, target.url);
|
|
1375
|
+
}
|
|
1376
|
+
await this.captureSnapshotState(state);
|
|
1377
|
+
return true;
|
|
1378
|
+
} catch {
|
|
1379
|
+
return false;
|
|
1380
|
+
}
|
|
1356
1381
|
}
|
|
1357
1382
|
|
|
1358
1383
|
private async navigateWithMacroFallback(state: TabState, action: BrowserAction): Promise<void> {
|
|
@@ -1414,8 +1439,11 @@ export class CausyneBrowser {
|
|
|
1414
1439
|
const refId = action.ref ?? (action.index !== undefined ? `e${action.index}` : undefined);
|
|
1415
1440
|
if (refId) {
|
|
1416
1441
|
let ref = state.refs.get(refId);
|
|
1417
|
-
if (!ref
|
|
1418
|
-
await this.
|
|
1442
|
+
if (!ref) {
|
|
1443
|
+
await this.restoreLastTargetIfBlank(state);
|
|
1444
|
+
if (!state.refs.has(refId)) {
|
|
1445
|
+
await this.captureSnapshotState(state).catch(() => {});
|
|
1446
|
+
}
|
|
1419
1447
|
ref = state.refs.get(refId);
|
|
1420
1448
|
}
|
|
1421
1449
|
if (!ref) throw new Error(`Unknown element ref ${refId}. Take a new snapshot before interacting.`);
|
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
|
//
|
|
@@ -89,34 +90,9 @@ function makeApprovalHandler(conn, dialogs = null) {
|
|
|
89
90
|
// and a scrollable diff in one frame. The plain fallback asks the same
|
|
90
91
|
// question in the scrollback, which is all a non-TTY session can do.
|
|
91
92
|
if (dialogs && detail) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let approved = false;
|
|
96
|
-
let scope = 'reject';
|
|
97
|
-
|
|
98
|
-
for (;;) {
|
|
99
|
-
const answer = await dialogs.approve(detail);
|
|
100
|
-
approved = Boolean(answer && answer.approved);
|
|
101
|
-
scope = (answer && answer.scope) || 'reject';
|
|
102
|
-
|
|
103
|
-
if (scope !== 'always') break;
|
|
104
|
-
|
|
105
|
-
// A SECOND, EXPLICIT CONFIRMATION — the same shape opencode uses, and
|
|
106
|
-
// for the same reason: a standing grant is a much larger thing than
|
|
107
|
-
// approving one call, so it must not be reachable by one keystroke.
|
|
108
|
-
// The text says exactly what is being given up and for how long.
|
|
109
|
-
const confirmed = await dialogs.confirm(
|
|
110
|
-
`Allow ${bold(detail.tool)} to run WITHOUT asking, for the rest of this session?\n`
|
|
111
|
-
+ ` This lasts until Causyne restarts. Undo it any time with /approvals clear.`,
|
|
112
|
-
// Reaching this question already required moving onto Allow always
|
|
113
|
-
// and pressing Enter. A second Enter is therefore an explicit second
|
|
114
|
-
// confirmation, rather than a reflex approval on the first dialog.
|
|
115
|
-
{ defaultAnswer: true }
|
|
116
|
-
);
|
|
117
|
-
if (confirmed) break;
|
|
118
|
-
// Cancelled: ask again rather than denying something they never rejected.
|
|
119
|
-
}
|
|
93
|
+
const answer = await dialogs.approve(detail);
|
|
94
|
+
const approved = Boolean(answer && answer.approved);
|
|
95
|
+
const scope = (answer && answer.scope) || 'reject';
|
|
120
96
|
|
|
121
97
|
if (approved && scope === 'always') {
|
|
122
98
|
grantAlways(detail.tool);
|
|
@@ -588,6 +564,14 @@ export async function chatMode({ home = false } = {}) {
|
|
|
588
564
|
// never did.
|
|
589
565
|
loop.taskId = `cli_chat_${Date.now()}`;
|
|
590
566
|
|
|
567
|
+
// Transfer any multimodal image attachments (e.g. pasted screenshots from clipboard or /image)
|
|
568
|
+
if (prompt && typeof prompt.consumeAttachments === 'function') {
|
|
569
|
+
const atts = prompt.consumeAttachments();
|
|
570
|
+
if (atts && atts.length > 0) {
|
|
571
|
+
loop.attachments = atts;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
591
575
|
conn.renderer.resetTurn();
|
|
592
576
|
const startedAt = Date.now();
|
|
593
577
|
if (prompt) prompt.setBusy(true);
|
package/src/commands.js
CHANGED
|
@@ -47,6 +47,7 @@ import os from 'os';
|
|
|
47
47
|
import path from 'path';
|
|
48
48
|
import { execSync } from 'child_process';
|
|
49
49
|
import { runCopyCommand, runPasteCommand } from './tui/chatboxClipboard.js';
|
|
50
|
+
import { loadLocalImageAttachment, formatByteSize } from './tui/clipboardImage.js';
|
|
50
51
|
import { getPackageVersion } from './version.js';
|
|
51
52
|
import { listGroups } from './checkpoints.js';
|
|
52
53
|
import { renameSession, getSession } from './sessionStore.js';
|
|
@@ -1153,6 +1154,36 @@ export const COMMANDS = [
|
|
|
1153
1154
|
}
|
|
1154
1155
|
},
|
|
1155
1156
|
|
|
1157
|
+
{
|
|
1158
|
+
name: 'image',
|
|
1159
|
+
aliases: ['attach', 'screenshot'],
|
|
1160
|
+
scope: 'local',
|
|
1161
|
+
usage: '/image [path]',
|
|
1162
|
+
description: 'Attach a screenshot from clipboard or a local image file to the chat prompt',
|
|
1163
|
+
run: (argv, ctx) => {
|
|
1164
|
+
if (!ctx.prompt) {
|
|
1165
|
+
return fail('The /image command is only available in interactive chat mode.');
|
|
1166
|
+
}
|
|
1167
|
+
if (argv.length === 0) {
|
|
1168
|
+
const res = runPasteCommand([], ctx);
|
|
1169
|
+
return res.ok ? ok(res.output, { effect: 'silent' }) : fail(res.output);
|
|
1170
|
+
}
|
|
1171
|
+
const rawPath = argv.join(' ');
|
|
1172
|
+
const img = loadLocalImageAttachment(rawPath);
|
|
1173
|
+
if (!img) {
|
|
1174
|
+
return fail(`Could not load image at "${rawPath}". Ensure file exists and is a valid image (PNG, JPEG, WebP, GIF).`);
|
|
1175
|
+
}
|
|
1176
|
+
if (!Array.isArray(ctx.prompt.pendingAttachments)) {
|
|
1177
|
+
ctx.prompt.pendingAttachments = [];
|
|
1178
|
+
}
|
|
1179
|
+
ctx.prompt.pendingAttachments.push(img);
|
|
1180
|
+
ctx.prompt.editor.insert(`[Image: ${img.name}] `);
|
|
1181
|
+
ctx.prompt.notice = `attached image ${img.name} (${formatByteSize(img.size)})`;
|
|
1182
|
+
ctx.prompt.scheduleDraw();
|
|
1183
|
+
return ok(`Attached image ${img.name} (${formatByteSize(img.size)}) to chat prompt.`, { effect: 'silent' });
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
|
|
1156
1187
|
{
|
|
1157
1188
|
name: 'stop',
|
|
1158
1189
|
aliases: ['abort'],
|
|
@@ -2203,6 +2234,8 @@ export const COMMANDS = [
|
|
|
2203
2234
|
ctx.loop.setAutonomyMode(target);
|
|
2204
2235
|
}
|
|
2205
2236
|
if (ctx.prompt) {
|
|
2237
|
+
ctx.prompt.renderer?.status?.setSession?.({ autonomyMode: target });
|
|
2238
|
+
ctx.prompt.surface?.setSessionInfo?.({ autonomyMode: target });
|
|
2206
2239
|
ctx.prompt.notice = `Mode ${target} active`;
|
|
2207
2240
|
if (ctx.prompt.scheduleDraw) ctx.prompt.scheduleDraw();
|
|
2208
2241
|
return ok(`Autonomy mode switched to ${target}.`, { effect: 'inline' });
|