@causyne/agent 1.20.103 → 1.20.105
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/src/agentLoop.js +20 -20
- package/src/agentLoop.ts +18 -21
- package/src/launchIntent.js +76 -16
- package/src/launchIntent.ts +75 -16
- package/src/observer/evidence.js +2 -1
- package/src/observer/evidence.ts +2 -1
- package/src/observer.js +39 -4
- package/src/observer.ts +35 -5
- package/src/timeMachine.js +20 -8
- package/src/timeMachine.ts +20 -8
- package/src/tools/gitExec.js +64 -24
- package/src/tui/chatRenderer.js +14 -6
- package/src/tui/sessionSidebar.js +30 -17
- package/src/tui/sessionSidebar.ts +27 -16
- package/src/tui/stageSurface.js +66 -12
package/package.json
CHANGED
package/src/agentLoop.js
CHANGED
|
@@ -270,7 +270,7 @@ export function isMidTaskProgressText(text) {
|
|
|
270
270
|
"i'm going to ",
|
|
271
271
|
'going to '
|
|
272
272
|
];
|
|
273
|
-
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || lower.startsWith(prefix))) {
|
|
273
|
+
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
|
|
274
274
|
if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
|
|
275
275
|
return true;
|
|
276
276
|
}
|
|
@@ -576,6 +576,7 @@ export class AgentLoop {
|
|
|
576
576
|
static MAX_CONSECUTIVE_FAILURES = 3;
|
|
577
577
|
constructor(eventSink, taskId, userPrompt, options = {}) {
|
|
578
578
|
this.eventSink = eventSink;
|
|
579
|
+
this._deliveredAgentMessages = new Set();
|
|
579
580
|
this.taskId = taskId;
|
|
580
581
|
this.userPrompt = userPrompt;
|
|
581
582
|
// User intent must remain independent of injected @-file contents.
|
|
@@ -1354,6 +1355,22 @@ export class AgentLoop {
|
|
|
1354
1355
|
return typeof result.output === 'string' ? result.output : '';
|
|
1355
1356
|
}
|
|
1356
1357
|
emitEvent(messageObj) {
|
|
1358
|
+
if (messageObj.type === 'agent_message' && typeof messageObj.content === 'string') {
|
|
1359
|
+
const content = messageObj.content.trim().replace(/\s+/g, ' ');
|
|
1360
|
+
if (content) {
|
|
1361
|
+
const streaming = messageObj.streaming === true;
|
|
1362
|
+
if ([...this._deliveredAgentMessages].some((prior) => prior === content || (streaming && prior.startsWith(content))))
|
|
1363
|
+
return;
|
|
1364
|
+
if (!streaming) {
|
|
1365
|
+
if (this._deliveredAgentMessages.size >= 32) {
|
|
1366
|
+
const oldest = this._deliveredAgentMessages.values().next().value;
|
|
1367
|
+
if (typeof oldest === 'string')
|
|
1368
|
+
this._deliveredAgentMessages.delete(oldest);
|
|
1369
|
+
}
|
|
1370
|
+
this._deliveredAgentMessages.add(content);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1357
1374
|
if (this.eventSink && this.eventSink.readyState === 1) {
|
|
1358
1375
|
this.eventSink.send(JSON.stringify({ taskId: this.taskId, ...messageObj }));
|
|
1359
1376
|
}
|
|
@@ -2058,6 +2075,7 @@ export class AgentLoop {
|
|
|
2058
2075
|
}
|
|
2059
2076
|
}
|
|
2060
2077
|
this.stepsCompleted = 0;
|
|
2078
|
+
this._deliveredAgentMessages.clear();
|
|
2061
2079
|
// Fresh per task. A digest from a previous task would point at a step
|
|
2062
2080
|
// number the model can no longer see, which is worse than paying twice.
|
|
2063
2081
|
this._observationDigests = new Map();
|
|
@@ -3303,31 +3321,13 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3303
3321
|
continue;
|
|
3304
3322
|
}
|
|
3305
3323
|
}
|
|
3306
|
-
|
|
3307
|
-
&& this._implementationPlan.every((s) => s.status === 'completed' || s.completed);
|
|
3308
|
-
if (!hasExternalActions && this.stepsCompleted === 0 && isActionable && !allPlanCompleted) {
|
|
3324
|
+
if (!hasExternalActions && this.stepsCompleted === 0 && isActionable) {
|
|
3309
3325
|
this.messages.pop();
|
|
3310
3326
|
this.emitEvent({ type: 'error', message: 'The selected model returned text without taking any action. No work was completed.' });
|
|
3311
3327
|
this.memoryManager.saveHistory(this.messages);
|
|
3312
3328
|
break;
|
|
3313
3329
|
}
|
|
3314
3330
|
if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
|
|
3315
|
-
if (allPlanCompleted) {
|
|
3316
|
-
const planSummary = ` All ${this._implementationPlan.length} plan steps have been completed and verified:\n\n`
|
|
3317
|
-
+ this._implementationPlan.map((s, idx) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n');
|
|
3318
|
-
const summary = `Task completed successfully.${planSummary}`;
|
|
3319
|
-
this.emitEvent({
|
|
3320
|
-
type: 'agent_message',
|
|
3321
|
-
content: summary
|
|
3322
|
-
});
|
|
3323
|
-
this.emitEvent({
|
|
3324
|
-
type: 'status',
|
|
3325
|
-
message: 'Task completed with verified deliverables.'
|
|
3326
|
-
});
|
|
3327
|
-
this._causyneTaskOutcome = 'completed';
|
|
3328
|
-
this.memoryManager.saveHistory(this.messages);
|
|
3329
|
-
break;
|
|
3330
|
-
}
|
|
3331
3331
|
if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2 && failedExternalActions.length === 0) {
|
|
3332
3332
|
incompleteTurnContinuations++;
|
|
3333
3333
|
this.emitEvent({ type: 'status', message: 'Requesting the missing final response…' });
|
package/src/agentLoop.ts
CHANGED
|
@@ -345,7 +345,7 @@ export function isMidTaskProgressText(text: string): boolean {
|
|
|
345
345
|
"i'm going to ",
|
|
346
346
|
'going to '
|
|
347
347
|
];
|
|
348
|
-
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || lower.startsWith(prefix))) {
|
|
348
|
+
if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
|
|
349
349
|
if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
|
|
350
350
|
return true;
|
|
351
351
|
}
|
|
@@ -678,6 +678,7 @@ export class AgentLoop {
|
|
|
678
678
|
static MAX_CONSECUTIVE_FAILURES = 3;
|
|
679
679
|
constructor(eventSink: AgentLoopEventSink | null, taskId: string, userPrompt: string | null, options: AgentLoopOptions = {}) {
|
|
680
680
|
this.eventSink = eventSink;
|
|
681
|
+
this._deliveredAgentMessages = new Set<string>();
|
|
681
682
|
this.taskId = taskId;
|
|
682
683
|
this.userPrompt = userPrompt;
|
|
683
684
|
// User intent must remain independent of injected @-file contents.
|
|
@@ -1434,6 +1435,20 @@ export class AgentLoop {
|
|
|
1434
1435
|
}
|
|
1435
1436
|
|
|
1436
1437
|
emitEvent(messageObj: AgentLoopEvent) {
|
|
1438
|
+
if (messageObj.type === 'agent_message' && typeof (messageObj as any).content === 'string') {
|
|
1439
|
+
const content = (messageObj as any).content.trim().replace(/\s+/g, ' ');
|
|
1440
|
+
if (content) {
|
|
1441
|
+
const streaming = (messageObj as any).streaming === true;
|
|
1442
|
+
if ([...this._deliveredAgentMessages].some((prior: string) => prior === content || (streaming && prior.startsWith(content)))) return;
|
|
1443
|
+
if (!streaming) {
|
|
1444
|
+
if (this._deliveredAgentMessages.size >= 32) {
|
|
1445
|
+
const oldest = this._deliveredAgentMessages.values().next().value;
|
|
1446
|
+
if (typeof oldest === 'string') this._deliveredAgentMessages.delete(oldest);
|
|
1447
|
+
}
|
|
1448
|
+
this._deliveredAgentMessages.add(content);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1437
1452
|
if (this.eventSink && this.eventSink.readyState === 1) {
|
|
1438
1453
|
this.eventSink.send(JSON.stringify({ taskId: this.taskId, ...messageObj }));
|
|
1439
1454
|
}
|
|
@@ -2133,6 +2148,7 @@ export class AgentLoop {
|
|
|
2133
2148
|
}
|
|
2134
2149
|
|
|
2135
2150
|
this.stepsCompleted = 0;
|
|
2151
|
+
this._deliveredAgentMessages.clear();
|
|
2136
2152
|
// Fresh per task. A digest from a previous task would point at a step
|
|
2137
2153
|
// number the model can no longer see, which is worse than paying twice.
|
|
2138
2154
|
this._observationDigests = new Map();
|
|
@@ -3443,10 +3459,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3443
3459
|
}
|
|
3444
3460
|
}
|
|
3445
3461
|
|
|
3446
|
-
|
|
3447
|
-
&& this._implementationPlan.every((s: any) => s.status === 'completed' || s.completed);
|
|
3448
|
-
|
|
3449
|
-
if (!hasExternalActions && this.stepsCompleted === 0 && isActionable && !allPlanCompleted) {
|
|
3462
|
+
if (!hasExternalActions && this.stepsCompleted === 0 && isActionable) {
|
|
3450
3463
|
this.messages.pop();
|
|
3451
3464
|
this.emitEvent({ type: 'error', message: 'The selected model returned text without taking any action. No work was completed.' });
|
|
3452
3465
|
this.memoryManager.saveHistory(this.messages);
|
|
@@ -3454,22 +3467,6 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
3454
3467
|
}
|
|
3455
3468
|
|
|
3456
3469
|
if (!hasExternalActions && (isIncompleteTurn || failedExternalActions.length > 0 || !contentText.trim())) {
|
|
3457
|
-
if (allPlanCompleted) {
|
|
3458
|
-
const planSummary = ` All ${this._implementationPlan.length} plan steps have been completed and verified:\n\n`
|
|
3459
|
-
+ this._implementationPlan.map((s: any, idx: number) => ` ✓ ${s.step || s.text || s.content || `Step ${idx + 1}`}`).join('\n');
|
|
3460
|
-
const summary = `Task completed successfully.${planSummary}`;
|
|
3461
|
-
this.emitEvent({
|
|
3462
|
-
type: 'agent_message',
|
|
3463
|
-
content: summary
|
|
3464
|
-
});
|
|
3465
|
-
this.emitEvent({
|
|
3466
|
-
type: 'status',
|
|
3467
|
-
message: 'Task completed with verified deliverables.'
|
|
3468
|
-
});
|
|
3469
|
-
this._causyneTaskOutcome = 'completed';
|
|
3470
|
-
this.memoryManager.saveHistory(this.messages);
|
|
3471
|
-
break;
|
|
3472
|
-
}
|
|
3473
3470
|
if (this.stepsCompleted > 0 && incompleteTurnContinuations < 2 && failedExternalActions.length === 0) {
|
|
3474
3471
|
incompleteTurnContinuations++;
|
|
3475
3472
|
this.emitEvent({ type: 'status', message: 'Requesting the missing final response…' });
|
package/src/launchIntent.js
CHANGED
|
@@ -8,19 +8,22 @@ const URL_OR_FILE_LAUNCH = /^\s*(?:open|preview)\s+(?:https?:\/\/|\/|~\/|\.\/|[a
|
|
|
8
8
|
const BROWSER_LAUNCH = /\b(?:open|view)\s+(?:in\s+)?(?:browser|chrome|safari)\b/i;
|
|
9
9
|
const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
|
|
10
10
|
const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
|
|
11
|
+
// Some inspection executables have flags that write files or execute commands.
|
|
12
|
+
const MUTATING_INSPECTION_OPTIONS = /(?:^|\s)(?:-delete|-exec(?:dir)?|-ok(?:dir)?|-fprint(?:f|0)?|-fprintf|-fls)(?=\s|$)|(?:^|\s)--(?:output|pre)(?==|\s|$|-)/i;
|
|
11
13
|
const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
|
|
12
14
|
const LOCAL_HEALTH_CHECK = /^\s*curl\b[^;&|><`$()]*https?:\/\/(?:localhost|127\.0\.0\.1):\d+(?:\/\S*)?\s*$/i;
|
|
13
|
-
const PORT_CLEANUP_COMMAND = /^\s*(?:pkill|kill|fuser)\b/i;
|
|
14
15
|
export const MUTATION_TOOLS = new Set([
|
|
15
16
|
'fs_write', 'fs_edit', 'fs_delete', 'fs_move',
|
|
16
17
|
'multi_edit', 'MultiEdit', 'edit_file', 'write_to_file', 'delete_file',
|
|
17
|
-
'create_skill', 'manage_local_dependencies'
|
|
18
|
+
'create_skill', 'manage_local_dependencies', 'skill_create', 'memory_write', 'archive', 'tool.forge', 'proc.term'
|
|
18
19
|
]);
|
|
19
20
|
const NO_EXECUTION_PHRASES = /\b(?:don'?t|do\s+not|never|without)\s+(?:execute|run|modify|mutate|apply|touch|write|change|edit|delete)\b|\b(?:no|without)\s+(?:execution|tools?|actions?)\b|\bjust\s+explain\b|\bread[\s-]only\b/i;
|
|
21
|
+
// 'Do not run tests' is a scoped restriction, not a prohibition on editing code.
|
|
22
|
+
const SCOPED_TEST_PROHIBITION = /\b(?:don'?t|do\s+not|never|without)\s+(?:run|execute)\s+(?:the\s+)?(?:unit\s+|integration\s+|e2e\s+)?(?:tests?|checks?|lint(?:ing|ers?)?|benchmarks?|test\s+suite)\b/gi;
|
|
20
23
|
export function isNoExecutionPrompt(prompt) {
|
|
21
24
|
if (!prompt || typeof prompt !== 'string')
|
|
22
25
|
return false;
|
|
23
|
-
return NO_EXECUTION_PHRASES.test(prompt);
|
|
26
|
+
return NO_EXECUTION_PHRASES.test(prompt.replace(SCOPED_TEST_PROHIBITION, ''));
|
|
24
27
|
}
|
|
25
28
|
export function isReadOnlyOrExplanatoryPrompt(prompt) {
|
|
26
29
|
if (!prompt || typeof prompt !== 'string')
|
|
@@ -32,11 +35,28 @@ export function isReadOnlyOrExplanatoryPrompt(prompt) {
|
|
|
32
35
|
return true;
|
|
33
36
|
if (!INQUIRY_WORDS.test(trimmed))
|
|
34
37
|
return false;
|
|
35
|
-
//
|
|
38
|
+
// Questions about *how to modify* are still requests for information.
|
|
39
|
+
if (/^(?:please\s+)?(?:how|why|what|where|when|who)\b/i.test(trimmed))
|
|
40
|
+
return true;
|
|
41
|
+
if (/^(?:please\s+)?(?:explain|describe|summarize|analy[sz]e|review|tell\s+me)\b/i.test(trimmed)) {
|
|
42
|
+
const followUp = /\b(?:and|then|also|afterwards)\s+(?:please\s+)?(.+)/i.exec(trimmed)?.[1] ?? '';
|
|
43
|
+
if (!CHANGE_VERBS.test(followUp) && !/^(?:run|execute|test|launch|open|start)\b/i.test(followUp))
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// An inquiry that also commands implementation must not be forced read-only.
|
|
36
47
|
if (CHANGE_VERBS.test(trimmed))
|
|
37
48
|
return false;
|
|
38
49
|
return true;
|
|
39
50
|
}
|
|
51
|
+
const READ_ONLY_GIT_COMMAND = /^(?:status|diff|log|show|rev-parse|ls-files)(?=\s|$)/i;
|
|
52
|
+
const RISKY_GIT_INSPECTION_OPTIONS = /(?:^|\s)--(?:ext-diff|textconv|config-env)(?=\s|$|=)/i;
|
|
53
|
+
function isGitInspectionCommand(rawCommand) {
|
|
54
|
+
const command = String(rawCommand ?? '').trim();
|
|
55
|
+
return READ_ONLY_GIT_COMMAND.test(command)
|
|
56
|
+
&& !hasShellControlOperators(command)
|
|
57
|
+
&& !MUTATING_INSPECTION_OPTIONS.test(command)
|
|
58
|
+
&& !RISKY_GIT_INSPECTION_OPTIONS.test(command);
|
|
59
|
+
}
|
|
40
60
|
/** Enforces scope boundaries when the user's intent is explanatory or forbids execution. */
|
|
41
61
|
export function readOnlyScopeError(tool, args, prompt) {
|
|
42
62
|
const p = prompt || '';
|
|
@@ -50,16 +70,20 @@ export function readOnlyScopeError(tool, args, prompt) {
|
|
|
50
70
|
if (MUTATION_TOOLS.has(tool) || tool === 'desktop_act' || tool === 'computer_use') {
|
|
51
71
|
return 'The user requested an explanation/read-only inquiry, not workspace modifications or desktop actions.';
|
|
52
72
|
}
|
|
73
|
+
if (tool === 'creative_apps' && !['status', 'verify_bridge'].includes(String(args.action ?? '').toLowerCase())) {
|
|
74
|
+
return 'A read-only inquiry does not authorize creative application mutations.';
|
|
75
|
+
}
|
|
76
|
+
if (tool === 'plugin.manager' && String(args.action ?? '').toLowerCase() !== 'list') {
|
|
77
|
+
return 'A read-only inquiry does not authorize modifying installed plugins.';
|
|
78
|
+
}
|
|
53
79
|
if (tool === 'gitOp') {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
80
|
+
return isGitInspectionCommand(args.command)
|
|
81
|
+
? null
|
|
82
|
+
: 'A read-only inquiry authorizes inspection of Git status and history, not repository mutations.';
|
|
59
83
|
}
|
|
60
84
|
if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
|
|
61
85
|
const command = String(args.command ?? args.input ?? '').trim();
|
|
62
|
-
if (READ_ONLY_COMMAND.test(command) && !/[;&|><`$()]/.test(command)) {
|
|
86
|
+
if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !/[;&|><`$()]/.test(command)) {
|
|
63
87
|
return null;
|
|
64
88
|
}
|
|
65
89
|
return 'A read-only inquiry authorizes only non-mutating status inspection commands (e.g. pwd, git status, cat), not arbitrary execution.';
|
|
@@ -95,23 +119,59 @@ export function isLaunchOnlyPrompt(prompt) {
|
|
|
95
119
|
export function isServerLaunchCommand(command) {
|
|
96
120
|
return SERVER_COMMAND.test(command.trim());
|
|
97
121
|
}
|
|
122
|
+
function hasShellControlOperators(command) {
|
|
123
|
+
let quote = null;
|
|
124
|
+
for (let i = 0; i < command.length; i++) {
|
|
125
|
+
const ch = command.charAt(i);
|
|
126
|
+
if (ch === '\\') {
|
|
127
|
+
if (i === command.length - 1)
|
|
128
|
+
return true;
|
|
129
|
+
i++;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (ch === '"' || ch === "'") {
|
|
133
|
+
if (quote === null)
|
|
134
|
+
quote = ch;
|
|
135
|
+
else if (quote === ch)
|
|
136
|
+
quote = null;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// Shell substitution is active inside double quotes.
|
|
140
|
+
if (ch === '`' || ch === '$' || ch === '\n' || ch === '\r')
|
|
141
|
+
return true;
|
|
142
|
+
if (quote === null && /[;&|><()]/.test(ch))
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return quote !== null;
|
|
146
|
+
}
|
|
98
147
|
/** A launch-only request authorizes inspection, starting the app, and opening it. */
|
|
99
148
|
export function launchScopeError(tool, args) {
|
|
100
149
|
if (MUTATION_TOOLS.has(tool)) {
|
|
101
150
|
return 'The user asked to open the existing project, not change its files or configuration.';
|
|
102
151
|
}
|
|
152
|
+
if (tool === 'creative_apps' && !['status', 'verify_bridge'].includes(String(args.action ?? '').toLowerCase())) {
|
|
153
|
+
return 'A launch-only request does not authorize creative application mutations.';
|
|
154
|
+
}
|
|
155
|
+
if (tool === 'plugin.manager' && String(args.action ?? '').toLowerCase() !== 'list') {
|
|
156
|
+
return 'A launch-only request does not authorize modifying installed plugins.';
|
|
157
|
+
}
|
|
158
|
+
if (tool === 'gitOp') {
|
|
159
|
+
return isGitInspectionCommand(args.command)
|
|
160
|
+
? null
|
|
161
|
+
: 'A launch-only request allows Git inspection, not working-tree or history changes.';
|
|
162
|
+
}
|
|
103
163
|
if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
|
|
104
164
|
const command = String(args.command ?? args.input ?? '').trim();
|
|
105
|
-
if (
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
if (/[;&|><`$()]/.test(command)) {
|
|
165
|
+
if (hasShellControlOperators(command)) {
|
|
109
166
|
return 'A launch-only request does not authorize chained shell commands. Use one scoped command per tool call.';
|
|
110
167
|
}
|
|
111
|
-
if (
|
|
168
|
+
if (OPEN_COMMAND.test(command) || isServerLaunchCommand(command) || LOCAL_HEALTH_CHECK.test(command)) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command)) {
|
|
112
172
|
return null;
|
|
113
173
|
}
|
|
114
|
-
return '
|
|
174
|
+
return 'A launch-only request does not authorize unrelated commands. Use read-only inspection, a background server, or desktop.open; do not run unrelated commands.';
|
|
115
175
|
}
|
|
116
176
|
return null;
|
|
117
177
|
}
|
package/src/launchIntent.ts
CHANGED
|
@@ -9,21 +9,24 @@ const URL_OR_FILE_LAUNCH = /^\s*(?:open|preview)\s+(?:https?:\/\/|\/|~\/|\.\/|[a
|
|
|
9
9
|
const BROWSER_LAUNCH = /\b(?:open|view)\s+(?:in\s+)?(?:browser|chrome|safari)\b/i;
|
|
10
10
|
const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
|
|
11
11
|
const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
|
|
12
|
+
// Some inspection executables have flags that write files or execute commands.
|
|
13
|
+
const MUTATING_INSPECTION_OPTIONS = /(?:^|\s)(?:-delete|-exec(?:dir)?|-ok(?:dir)?|-fprint(?:f|0)?|-fprintf|-fls)(?=\s|$)|(?:^|\s)--(?:output|pre)(?==|\s|$|-)/i;
|
|
12
14
|
const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
|
|
13
15
|
const LOCAL_HEALTH_CHECK = /^\s*curl\b[^;&|><`$()]*https?:\/\/(?:localhost|127\.0\.0\.1):\d+(?:\/\S*)?\s*$/i;
|
|
14
|
-
const PORT_CLEANUP_COMMAND = /^\s*(?:pkill|kill|fuser)\b/i;
|
|
15
16
|
|
|
16
17
|
export const MUTATION_TOOLS = new Set([
|
|
17
18
|
'fs_write', 'fs_edit', 'fs_delete', 'fs_move',
|
|
18
19
|
'multi_edit', 'MultiEdit', 'edit_file', 'write_to_file', 'delete_file',
|
|
19
|
-
'create_skill', 'manage_local_dependencies'
|
|
20
|
+
'create_skill', 'manage_local_dependencies', 'skill_create', 'memory_write', 'archive', 'tool.forge', 'proc.term'
|
|
20
21
|
]);
|
|
21
22
|
|
|
22
23
|
const NO_EXECUTION_PHRASES = /\b(?:don'?t|do\s+not|never|without)\s+(?:execute|run|modify|mutate|apply|touch|write|change|edit|delete)\b|\b(?:no|without)\s+(?:execution|tools?|actions?)\b|\bjust\s+explain\b|\bread[\s-]only\b/i;
|
|
24
|
+
// 'Do not run tests' is a scoped restriction, not a prohibition on editing code.
|
|
25
|
+
const SCOPED_TEST_PROHIBITION = /\b(?:don'?t|do\s+not|never|without)\s+(?:run|execute)\s+(?:the\s+)?(?:unit\s+|integration\s+|e2e\s+)?(?:tests?|checks?|lint(?:ing|ers?)?|benchmarks?|test\s+suite)\b/gi;
|
|
23
26
|
|
|
24
27
|
export function isNoExecutionPrompt(prompt?: string | null): boolean {
|
|
25
28
|
if (!prompt || typeof prompt !== 'string') return false;
|
|
26
|
-
return NO_EXECUTION_PHRASES.test(prompt);
|
|
29
|
+
return NO_EXECUTION_PHRASES.test(prompt.replace(SCOPED_TEST_PROHIBITION, ''));
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export function isReadOnlyOrExplanatoryPrompt(prompt?: string | null): boolean {
|
|
@@ -32,11 +35,28 @@ export function isReadOnlyOrExplanatoryPrompt(prompt?: string | null): boolean {
|
|
|
32
35
|
if (trimmed.length === 0) return false;
|
|
33
36
|
if (isNoExecutionPrompt(trimmed)) return true;
|
|
34
37
|
if (!INQUIRY_WORDS.test(trimmed)) return false;
|
|
35
|
-
//
|
|
38
|
+
// Questions about *how to modify* are still requests for information.
|
|
39
|
+
if (/^(?:please\s+)?(?:how|why|what|where|when|who)\b/i.test(trimmed)) return true;
|
|
40
|
+
if (/^(?:please\s+)?(?:explain|describe|summarize|analy[sz]e|review|tell\s+me)\b/i.test(trimmed)) {
|
|
41
|
+
const followUp = /\b(?:and|then|also|afterwards)\s+(?:please\s+)?(.+)/i.exec(trimmed)?.[1] ?? '';
|
|
42
|
+
if (!CHANGE_VERBS.test(followUp) && !/^(?:run|execute|test|launch|open|start)\b/i.test(followUp)) return true;
|
|
43
|
+
}
|
|
44
|
+
// An inquiry that also commands implementation must not be forced read-only.
|
|
36
45
|
if (CHANGE_VERBS.test(trimmed)) return false;
|
|
37
46
|
return true;
|
|
38
47
|
}
|
|
39
48
|
|
|
49
|
+
const READ_ONLY_GIT_COMMAND = /^(?:status|diff|log|show|rev-parse|ls-files)(?=\s|$)/i;
|
|
50
|
+
const RISKY_GIT_INSPECTION_OPTIONS = /(?:^|\s)--(?:ext-diff|textconv|config-env)(?=\s|$|=)/i;
|
|
51
|
+
|
|
52
|
+
function isGitInspectionCommand(rawCommand: unknown): boolean {
|
|
53
|
+
const command = String(rawCommand ?? '').trim();
|
|
54
|
+
return READ_ONLY_GIT_COMMAND.test(command)
|
|
55
|
+
&& !hasShellControlOperators(command)
|
|
56
|
+
&& !MUTATING_INSPECTION_OPTIONS.test(command)
|
|
57
|
+
&& !RISKY_GIT_INSPECTION_OPTIONS.test(command);
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
/** Enforces scope boundaries when the user's intent is explanatory or forbids execution. */
|
|
41
61
|
export function readOnlyScopeError(
|
|
42
62
|
tool: string,
|
|
@@ -55,16 +75,20 @@ export function readOnlyScopeError(
|
|
|
55
75
|
if (MUTATION_TOOLS.has(tool) || tool === 'desktop_act' || tool === 'computer_use') {
|
|
56
76
|
return 'The user requested an explanation/read-only inquiry, not workspace modifications or desktop actions.';
|
|
57
77
|
}
|
|
78
|
+
if (tool === 'creative_apps' && !['status', 'verify_bridge'].includes(String(args.action ?? '').toLowerCase())) {
|
|
79
|
+
return 'A read-only inquiry does not authorize creative application mutations.';
|
|
80
|
+
}
|
|
81
|
+
if (tool === 'plugin.manager' && String(args.action ?? '').toLowerCase() !== 'list') {
|
|
82
|
+
return 'A read-only inquiry does not authorize modifying installed plugins.';
|
|
83
|
+
}
|
|
58
84
|
if (tool === 'gitOp') {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
85
|
+
return isGitInspectionCommand(args.command)
|
|
86
|
+
? null
|
|
87
|
+
: 'A read-only inquiry authorizes inspection of Git status and history, not repository mutations.';
|
|
64
88
|
}
|
|
65
89
|
if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
|
|
66
90
|
const command = String(args.command ?? args.input ?? '').trim();
|
|
67
|
-
if (READ_ONLY_COMMAND.test(command) && !/[;&|><`$()]/.test(command)) {
|
|
91
|
+
if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command) && !/[;&|><`$()]/.test(command)) {
|
|
68
92
|
return null;
|
|
69
93
|
}
|
|
70
94
|
return 'A read-only inquiry authorizes only non-mutating status inspection commands (e.g. pwd, git status, cat), not arbitrary execution.';
|
|
@@ -98,28 +122,63 @@ export function isServerLaunchCommand(command: string): boolean {
|
|
|
98
122
|
return SERVER_COMMAND.test(command.trim());
|
|
99
123
|
}
|
|
100
124
|
|
|
125
|
+
function hasShellControlOperators(command: string): boolean {
|
|
126
|
+
let quote: '"' | "'" | null = null;
|
|
127
|
+
for (let i = 0; i < command.length; i++) {
|
|
128
|
+
const ch = command.charAt(i);
|
|
129
|
+
if (ch === '\\') {
|
|
130
|
+
if (i === command.length - 1) return true;
|
|
131
|
+
i++;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (ch === '"' || ch === "'") {
|
|
135
|
+
if (quote === null) quote = ch;
|
|
136
|
+
else if (quote === ch) quote = null;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
// Shell substitution is active inside double quotes.
|
|
140
|
+
if (ch === '`' || ch === '$' || ch === '\n' || ch === '\r') return true;
|
|
141
|
+
if (quote === null && /[;&|><()]/.test(ch)) return true;
|
|
142
|
+
}
|
|
143
|
+
return quote !== null;
|
|
144
|
+
}
|
|
145
|
+
|
|
101
146
|
/** A launch-only request authorizes inspection, starting the app, and opening it. */
|
|
102
147
|
export function launchScopeError(tool: string, args: Record<string, unknown>): string | null {
|
|
103
148
|
if (MUTATION_TOOLS.has(tool)) {
|
|
104
149
|
return 'The user asked to open the existing project, not change its files or configuration.';
|
|
105
150
|
}
|
|
106
151
|
|
|
152
|
+
if (tool === 'creative_apps' && !['status', 'verify_bridge'].includes(String(args.action ?? '').toLowerCase())) {
|
|
153
|
+
return 'A launch-only request does not authorize creative application mutations.';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (tool === 'plugin.manager' && String(args.action ?? '').toLowerCase() !== 'list') {
|
|
157
|
+
return 'A launch-only request does not authorize modifying installed plugins.';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (tool === 'gitOp') {
|
|
161
|
+
return isGitInspectionCommand(args.command)
|
|
162
|
+
? null
|
|
163
|
+
: 'A launch-only request allows Git inspection, not working-tree or history changes.';
|
|
164
|
+
}
|
|
165
|
+
|
|
107
166
|
if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
|
|
108
167
|
const command = String(args.command ?? args.input ?? '').trim();
|
|
109
168
|
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
169
|
+
if (hasShellControlOperators(command)) {
|
|
170
|
+
return 'A launch-only request does not authorize chained shell commands. Use one scoped command per tool call.';
|
|
112
171
|
}
|
|
113
172
|
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
173
|
+
if (OPEN_COMMAND.test(command) || isServerLaunchCommand(command) || LOCAL_HEALTH_CHECK.test(command)) {
|
|
174
|
+
return null;
|
|
116
175
|
}
|
|
117
176
|
|
|
118
|
-
if (READ_ONLY_COMMAND.test(command)) {
|
|
177
|
+
if (READ_ONLY_COMMAND.test(command) && !MUTATING_INSPECTION_OPTIONS.test(command)) {
|
|
119
178
|
return null;
|
|
120
179
|
}
|
|
121
180
|
|
|
122
|
-
return '
|
|
181
|
+
return 'A launch-only request does not authorize unrelated commands. Use read-only inspection, a background server, or desktop.open; do not run unrelated commands.';
|
|
123
182
|
}
|
|
124
183
|
|
|
125
184
|
return null;
|
package/src/observer/evidence.js
CHANGED
|
@@ -422,7 +422,8 @@ export function outcomeFromResult(tool, args, result, at) {
|
|
|
422
422
|
const record = result !== null && typeof result === 'object' && !Array.isArray(result)
|
|
423
423
|
? result
|
|
424
424
|
: {};
|
|
425
|
-
const success = record.success !== false && typeof record.error
|
|
425
|
+
const success = record.success !== false && !(typeof record.error === 'string' && record.error.trim().length > 0)
|
|
426
|
+
&& !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
|
|
426
427
|
const rawError = typeof record.error === 'string' ? record.error : '';
|
|
427
428
|
const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
|
|
428
429
|
const rawCommand = typeof args.command === 'string' ? args.command
|
package/src/observer/evidence.ts
CHANGED
|
@@ -486,7 +486,8 @@ export function outcomeFromResult(tool: string, args: Record<string, unknown>, r
|
|
|
486
486
|
const record = result !== null && typeof result === 'object' && !Array.isArray(result)
|
|
487
487
|
? result as Record<string, unknown>
|
|
488
488
|
: {};
|
|
489
|
-
const success = record.success !== false && typeof record.error
|
|
489
|
+
const success = record.success !== false && !(typeof record.error === 'string' && record.error.trim().length > 0)
|
|
490
|
+
&& !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
|
|
490
491
|
const rawError = typeof record.error === 'string' ? record.error : '';
|
|
491
492
|
const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
|
|
492
493
|
const rawCommand = typeof args.command === 'string' ? args.command
|
package/src/observer.js
CHANGED
|
@@ -19,6 +19,17 @@ export function extractClaimedLocalUrls(text) {
|
|
|
19
19
|
}
|
|
20
20
|
return [...unique];
|
|
21
21
|
}
|
|
22
|
+
function isWorkspaceArtifact(workspaceRoot, targetPath) {
|
|
23
|
+
try {
|
|
24
|
+
const root = fs.realpathSync(workspaceRoot);
|
|
25
|
+
const target = fs.realpathSync(targetPath);
|
|
26
|
+
const relative = path.relative(root, target);
|
|
27
|
+
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
export class CausyneObserver {
|
|
23
34
|
/**
|
|
24
35
|
* Evaluates the current state of a task after a tool outcome or at a step boundary.
|
|
@@ -79,13 +90,13 @@ export class CausyneObserver {
|
|
|
79
90
|
}
|
|
80
91
|
// Check if the agent claims completion
|
|
81
92
|
if (context.agentClaim && context.agentClaim.trim()) {
|
|
82
|
-
|
|
93
|
+
// Negative completion statements must not be promoted to verified outcomes.
|
|
94
|
+
const claim = context.agentClaim.toLowerCase().replace(/\b(?:not|never|isn't|wasn't|haven't|hasn't)\s+(?:(?:yet|fully|actually|successfully)\s+)?(?:done|complete|completed|finished|implemented|fixed|verified)\b/gi, '');
|
|
83
95
|
const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b|\b(?:is\s+(?:running|live|available|listening|served)\s+(?:at|on)|application\s+is\s+running)\b/i.test(claim);
|
|
84
96
|
if (claimsCompletion) {
|
|
85
97
|
// Run deterministic verification checks based on domain
|
|
86
98
|
const hasMutations = outcomes.some(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool));
|
|
87
|
-
const hasPassingVerification = outcomes.some(o => o.success && (o.rendered === true ||
|
|
88
|
-
o.tool === 'browser_act' ||
|
|
99
|
+
const hasPassingVerification = outcomes.slice(outcomes.findLastIndex(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)) + 1).some(o => o.success && (o.exitCode == null || o.exitCode === 0) && (o.rendered === true ||
|
|
89
100
|
o.tool === 'verify_local_web' ||
|
|
90
101
|
(o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))));
|
|
91
102
|
if (hasMutations && !hasPassingVerification) {
|
|
@@ -119,6 +130,8 @@ export class CausyneObserver {
|
|
|
119
130
|
* Deterministically verifies code deliverables (targeted test, build, syntax).
|
|
120
131
|
*/
|
|
121
132
|
verifyCode(req) {
|
|
133
|
+
if (!req.changedFiles?.length)
|
|
134
|
+
return { verified: false, error: 'No code deliverables supplied.', evidence: 'no_files' };
|
|
122
135
|
if (req.changedFiles && req.changedFiles.length > 0) {
|
|
123
136
|
for (const file of req.changedFiles) {
|
|
124
137
|
const fullPath = path.isAbsolute(file) ? file : path.join(req.workspaceRoot, file);
|
|
@@ -129,6 +142,12 @@ export class CausyneObserver {
|
|
|
129
142
|
evidence: 'file_missing'
|
|
130
143
|
};
|
|
131
144
|
}
|
|
145
|
+
if (!isWorkspaceArtifact(req.workspaceRoot, fullPath)) {
|
|
146
|
+
return { verified: false, error: `Target deliverable ${file} is outside the workspace.`, evidence: 'outside_workspace' };
|
|
147
|
+
}
|
|
148
|
+
if (!fs.statSync(fullPath).isFile() || fs.statSync(fullPath).size === 0) {
|
|
149
|
+
return { verified: false, error: `Target deliverable ${file} is not a non-empty file.`, evidence: 'invalid_file' };
|
|
150
|
+
}
|
|
132
151
|
}
|
|
133
152
|
}
|
|
134
153
|
return {
|
|
@@ -144,6 +163,10 @@ export class CausyneObserver {
|
|
|
144
163
|
if (!fs.existsSync(fullPath)) {
|
|
145
164
|
return { verified: false, missingHeadings: req.requiredHeadings || [] };
|
|
146
165
|
}
|
|
166
|
+
if (!isWorkspaceArtifact(req.workspaceRoot, fullPath))
|
|
167
|
+
return { verified: false, missingHeadings: req.requiredHeadings || [] };
|
|
168
|
+
if (!fs.statSync(fullPath).isFile())
|
|
169
|
+
return { verified: false, missingHeadings: req.requiredHeadings || [] };
|
|
147
170
|
const content = fs.readFileSync(fullPath, 'utf8');
|
|
148
171
|
const missing = [];
|
|
149
172
|
for (const heading of req.requiredHeadings || []) {
|
|
@@ -165,8 +188,14 @@ export class CausyneObserver {
|
|
|
165
188
|
if (!fs.existsSync(fullPath)) {
|
|
166
189
|
return { verified: false, bytes: 0, error: `Media asset not found: ${req.artifactPath}` };
|
|
167
190
|
}
|
|
191
|
+
if (!isWorkspaceArtifact(req.workspaceRoot, fullPath))
|
|
192
|
+
return { verified: false, bytes: 0, error: 'Media artifact is outside the workspace.' };
|
|
168
193
|
const stat = fs.statSync(fullPath);
|
|
194
|
+
if (!stat.isFile())
|
|
195
|
+
return { verified: false, bytes: 0, error: 'Media artifact must be a regular file.' };
|
|
169
196
|
const minBytes = req.minBytes ?? 100;
|
|
197
|
+
if (!Number.isSafeInteger(minBytes) || minBytes < 0)
|
|
198
|
+
return { verified: false, bytes: stat.size, error: 'Invalid minimum artifact size.' };
|
|
170
199
|
if (stat.size < minBytes) {
|
|
171
200
|
return { verified: false, bytes: stat.size, error: `Media asset too small (${stat.size} bytes < ${minBytes} bytes)` };
|
|
172
201
|
}
|
|
@@ -184,10 +213,16 @@ export class CausyneObserver {
|
|
|
184
213
|
resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
|
|
185
214
|
return;
|
|
186
215
|
}
|
|
216
|
+
if (url.username || url.password) {
|
|
217
|
+
resolve({ verified: false, error: 'Local verification URL must not contain credentials.' });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
187
220
|
const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
|
|
188
221
|
res.resume();
|
|
189
222
|
const expected = req.expectedStatus ?? 200;
|
|
190
|
-
const ok =
|
|
223
|
+
const ok = req.expectedStatus === undefined
|
|
224
|
+
? (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 300)
|
|
225
|
+
: res.statusCode === expected;
|
|
191
226
|
const result = { verified: Boolean(ok) };
|
|
192
227
|
if (typeof res.statusCode === 'number')
|
|
193
228
|
result.statusCode = res.statusCode;
|