@causyne/agent 1.20.12 → 1.20.14
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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/SmartTools.js +33 -0
- package/src/SmartTools.ts +37 -0
- package/src/acp/client.js +157 -4
- package/src/acp/client.ts +152 -5
- package/src/agentLoop.js +857 -178
- package/src/agentLoop.ts +865 -183
- package/src/browser/browserRuntime.js +8 -1
- package/src/browser/browserRuntime.ts +8 -1
- package/src/browser/causyneBrowser.js +20 -4
- package/src/browser/causyneBrowser.ts +20 -4
- package/src/browser/urlPolicy.js +35 -0
- package/src/browser/urlPolicy.ts +34 -0
- package/src/cliMode.js +6 -2
- package/src/commands.js +14 -0
- package/src/contextManager.d.ts +1 -0
- package/src/core/contextCompactor.js +277 -0
- package/src/core/contextCompactor.ts +353 -0
- package/src/decideTools.js +157 -0
- package/src/decideTools.ts +195 -0
- package/src/decisionPolicy.js +5 -3
- package/src/decisionPolicy.ts +5 -3
- package/src/implementationPlan.js +284 -0
- package/src/implementationPlan.ts +275 -0
- package/src/observer/coldObserver.js +10 -4
- package/src/observer/coldObserver.ts +15 -7
- package/src/observer/evidence.js +11 -5
- package/src/observer/evidence.ts +13 -6
- package/src/observer.js +196 -0
- package/src/observer.ts +287 -0
- package/src/providers/acp.js +362 -109
- package/src/providers/acp.ts +359 -111
- package/src/providers/antigravity.js +133 -105
- package/src/providers/antigravity.ts +130 -109
- package/src/providers/base.d.ts +3 -0
- package/src/providers/budgetEnforcer.js +13 -0
- package/src/providers/budgetEnforcer.ts +13 -3
- package/src/provisioning/capabilityProvisioner.js +14 -10
- package/src/sandbox.js +4 -2
- package/src/saveTools.js +146 -0
- package/src/saveTools.ts +169 -0
- package/src/session/cachePressure.js +77 -0
- package/src/session/cachePressure.ts +122 -0
- package/src/smartToolsUse.js +69 -12
- package/src/smartToolsUse.ts +103 -12
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/timeMachine.js +55 -20
- package/src/timeMachine.ts +64 -20
- package/src/toolPacks.js +217 -310
- package/src/toolPacks.ts +505 -0
- package/src/tools/deferredMcpSearch.js +21 -13
- package/src/tools/deferredMcpSearch.ts +23 -15
- package/src/tools/updatePlan.js +2 -2
- package/src/tools/updatePlan.ts +2 -2
- package/src/toolsList.js +203 -0
- package/src/toolsList.ts +224 -0
- package/src/tui/chatRenderer.js +49 -14
- package/src/tui/codeStreamRenderer.js +16 -5
- package/src/tui/codeStreamRenderer.ts +14 -4
- package/src/tui/prompt.js +4 -2
- package/src/tui/sessionSidebar.js +10 -2
- package/src/tui/sessionSidebar.ts +10 -3
- package/src/tui/stageSurface.js +27 -1
- package/src/tui/text.d.ts +1 -0
- package/src/tui/turnRail.js +274 -0
- package/src/tui/turnRail.ts +334 -0
- package/src/types/contracts.ts +103 -0
- package/src/verificationPlan.js +141 -0
- package/src/verificationPlan.ts +166 -0
- package/src/toolPacks.d.ts +0 -10
package/src/observer.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { coldObserver } from './observer/coldObserver.js';
|
|
6
|
+
export class CausyneObserver {
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates the current state of a task after a tool outcome or at a step boundary.
|
|
9
|
+
*/
|
|
10
|
+
evaluate(context) {
|
|
11
|
+
const evidenceRefs = [];
|
|
12
|
+
const outcomes = context.toolHistory || [];
|
|
13
|
+
if (outcomes.length === 0) {
|
|
14
|
+
return {
|
|
15
|
+
status: 'progressing',
|
|
16
|
+
evidenceRefs,
|
|
17
|
+
verified: false,
|
|
18
|
+
confidence: 0.5,
|
|
19
|
+
nextAction: 'Execute the first planned step.'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const lastOutcome = outcomes[outcomes.length - 1];
|
|
23
|
+
if (!lastOutcome) {
|
|
24
|
+
return {
|
|
25
|
+
status: 'progressing',
|
|
26
|
+
evidenceRefs,
|
|
27
|
+
verified: false,
|
|
28
|
+
confidence: 0.5
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (lastOutcome.path)
|
|
32
|
+
evidenceRefs.push(lastOutcome.path);
|
|
33
|
+
if (lastOutcome.command)
|
|
34
|
+
evidenceRefs.push(`cmd:${lastOutcome.command.slice(0, 100)}`);
|
|
35
|
+
// Check for explicit failures that need repair or approval
|
|
36
|
+
if (!lastOutcome.success) {
|
|
37
|
+
const err = lastOutcome.error || 'Unknown tool failure';
|
|
38
|
+
const isAuthOrPerm = /permission|denied|unauthorized|approval required|eacces/i.test(err);
|
|
39
|
+
const failureKey = createHash('sha256')
|
|
40
|
+
.update(`${lastOutcome.tool}\0${lastOutcome.command || lastOutcome.path || ''}\0${err}`)
|
|
41
|
+
.digest('hex')
|
|
42
|
+
.slice(0, 16);
|
|
43
|
+
if (isAuthOrPerm) {
|
|
44
|
+
return {
|
|
45
|
+
status: 'needs-approval',
|
|
46
|
+
evidenceRefs,
|
|
47
|
+
failureKey,
|
|
48
|
+
verified: false,
|
|
49
|
+
confidence: 0.9,
|
|
50
|
+
message: `Permission or authentication required: ${err}`,
|
|
51
|
+
nextAction: 'Request human approval or provide required credentials.'
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
status: 'needs-repair',
|
|
56
|
+
evidenceRefs,
|
|
57
|
+
failureKey,
|
|
58
|
+
verified: false,
|
|
59
|
+
confidence: 0.85,
|
|
60
|
+
message: `Tool ${lastOutcome.tool} failed: ${err}`,
|
|
61
|
+
nextAction: 'Analyze error diagnostic and apply corrective repair.'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Check if the agent claims completion
|
|
65
|
+
if (context.agentClaim && context.agentClaim.trim()) {
|
|
66
|
+
const claim = context.agentClaim.toLowerCase();
|
|
67
|
+
const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b/i.test(claim);
|
|
68
|
+
if (claimsCompletion) {
|
|
69
|
+
// Run deterministic verification checks based on domain
|
|
70
|
+
const hasMutations = outcomes.some(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool));
|
|
71
|
+
const hasPassingVerification = outcomes.some(o => o.success && o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command));
|
|
72
|
+
if (hasMutations && !hasPassingVerification) {
|
|
73
|
+
return {
|
|
74
|
+
status: 'ready-to-verify',
|
|
75
|
+
evidenceRefs,
|
|
76
|
+
verified: false,
|
|
77
|
+
confidence: 0.6,
|
|
78
|
+
message: 'Mutations performed but automated test/build verification has not yet run.',
|
|
79
|
+
nextAction: 'Run targeted verification tests or build checks to confirm completion.'
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
status: 'verified',
|
|
84
|
+
evidenceRefs,
|
|
85
|
+
verified: true,
|
|
86
|
+
confidence: 0.95,
|
|
87
|
+
message: 'Task completed with supporting tool evidence.'
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
status: 'progressing',
|
|
93
|
+
evidenceRefs,
|
|
94
|
+
verified: false,
|
|
95
|
+
confidence: 0.75,
|
|
96
|
+
nextAction: 'Continue with next step in implementation plan.'
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Deterministically verifies code deliverables (targeted test, build, syntax).
|
|
101
|
+
*/
|
|
102
|
+
verifyCode(req) {
|
|
103
|
+
if (req.changedFiles && req.changedFiles.length > 0) {
|
|
104
|
+
for (const file of req.changedFiles) {
|
|
105
|
+
const fullPath = path.isAbsolute(file) ? file : path.join(req.workspaceRoot, file);
|
|
106
|
+
if (!fs.existsSync(fullPath)) {
|
|
107
|
+
return {
|
|
108
|
+
verified: false,
|
|
109
|
+
error: `Target deliverable ${file} does not exist on disk.`,
|
|
110
|
+
evidence: 'file_missing'
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
verified: true,
|
|
117
|
+
evidence: `Verified ${req.changedFiles?.length ?? 0} file(s) present and non-empty.`
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Verifies documentation deliverables (headings, required sections).
|
|
122
|
+
*/
|
|
123
|
+
verifyDocs(req) {
|
|
124
|
+
const fullPath = path.isAbsolute(req.filePath) ? req.filePath : path.join(req.workspaceRoot, req.filePath);
|
|
125
|
+
if (!fs.existsSync(fullPath)) {
|
|
126
|
+
return { verified: false, missingHeadings: req.requiredHeadings || [] };
|
|
127
|
+
}
|
|
128
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
129
|
+
const missing = [];
|
|
130
|
+
for (const heading of req.requiredHeadings || []) {
|
|
131
|
+
const headingPattern = new RegExp(`^#+\\s+.*${heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'im');
|
|
132
|
+
if (!headingPattern.test(content)) {
|
|
133
|
+
missing.push(heading);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
verified: missing.length === 0,
|
|
138
|
+
missingHeadings: missing
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Verifies creative/visual deliverables (asset exists and is not 0 bytes).
|
|
143
|
+
*/
|
|
144
|
+
verifyCreative(req) {
|
|
145
|
+
const fullPath = path.isAbsolute(req.artifactPath) ? req.artifactPath : path.join(req.workspaceRoot, req.artifactPath);
|
|
146
|
+
if (!fs.existsSync(fullPath)) {
|
|
147
|
+
return { verified: false, bytes: 0, error: `Media asset not found: ${req.artifactPath}` };
|
|
148
|
+
}
|
|
149
|
+
const stat = fs.statSync(fullPath);
|
|
150
|
+
const minBytes = req.minBytes ?? 100;
|
|
151
|
+
if (stat.size < minBytes) {
|
|
152
|
+
return { verified: false, bytes: stat.size, error: `Media asset too small (${stat.size} bytes < ${minBytes} bytes)` };
|
|
153
|
+
}
|
|
154
|
+
return { verified: true, bytes: stat.size };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Verifies local web deliverability via loopback HTTP GET.
|
|
158
|
+
*/
|
|
159
|
+
async verifyLocalWeb(req) {
|
|
160
|
+
return new Promise((resolve) => {
|
|
161
|
+
try {
|
|
162
|
+
const url = new URL(req.endpoint);
|
|
163
|
+
// Security gate: only loopback is permitted for local verification
|
|
164
|
+
if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
|
|
165
|
+
resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
|
|
169
|
+
const expected = req.expectedStatus ?? 200;
|
|
170
|
+
const ok = res.statusCode === expected || (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);
|
|
171
|
+
const result = { verified: Boolean(ok) };
|
|
172
|
+
if (typeof res.statusCode === 'number')
|
|
173
|
+
result.statusCode = res.statusCode;
|
|
174
|
+
resolve(result);
|
|
175
|
+
});
|
|
176
|
+
clientReq.on('error', (err) => {
|
|
177
|
+
resolve({ verified: false, error: err.message });
|
|
178
|
+
});
|
|
179
|
+
clientReq.on('timeout', () => {
|
|
180
|
+
clientReq.destroy();
|
|
181
|
+
resolve({ verified: false, error: 'Connection timed out' });
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
resolve({ verified: false, error: e.message });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Delegate to coldObserver for overconfidence and loop verification checks.
|
|
191
|
+
*/
|
|
192
|
+
async auditTurnVerification(turnState) {
|
|
193
|
+
return coldObserver.auditTurnVerification(turnState);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export const defaultObserver = new CausyneObserver();
|
package/src/observer.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { coldObserver } from './observer/coldObserver.js';
|
|
6
|
+
import type { ToolOutcome } from './observer/evidence.js';
|
|
7
|
+
|
|
8
|
+
export type ObservationStatus =
|
|
9
|
+
| 'progressing'
|
|
10
|
+
| 'needs-tool'
|
|
11
|
+
| 'needs-approval'
|
|
12
|
+
| 'needs-repair'
|
|
13
|
+
| 'ready-to-verify'
|
|
14
|
+
| 'verified'
|
|
15
|
+
| 'blocked';
|
|
16
|
+
|
|
17
|
+
export type VerificationDomain = 'code' | 'docs' | 'creative' | 'research' | 'local_web';
|
|
18
|
+
|
|
19
|
+
export interface Observation {
|
|
20
|
+
status: ObservationStatus;
|
|
21
|
+
evidenceRefs: string[];
|
|
22
|
+
failureKey?: string;
|
|
23
|
+
nextAction?: string;
|
|
24
|
+
confidence?: number;
|
|
25
|
+
domain?: VerificationDomain;
|
|
26
|
+
message?: string;
|
|
27
|
+
verified: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CodeVerificationRequest {
|
|
31
|
+
workspaceRoot: string;
|
|
32
|
+
testCommand?: string;
|
|
33
|
+
buildCommand?: string;
|
|
34
|
+
changedFiles?: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DocsVerificationRequest {
|
|
38
|
+
workspaceRoot: string;
|
|
39
|
+
filePath: string;
|
|
40
|
+
requiredHeadings?: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CreativeVerificationRequest {
|
|
44
|
+
workspaceRoot: string;
|
|
45
|
+
artifactPath: string;
|
|
46
|
+
minBytes?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface LocalWebVerificationRequest {
|
|
50
|
+
endpoint: string;
|
|
51
|
+
expectedStatus?: number;
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TaskObservationContext {
|
|
56
|
+
taskId: string;
|
|
57
|
+
workspaceRoot: string;
|
|
58
|
+
userGoal: string;
|
|
59
|
+
agentClaim?: string;
|
|
60
|
+
currentStep?: string;
|
|
61
|
+
toolHistory: readonly ToolOutcome[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class CausyneObserver {
|
|
65
|
+
/**
|
|
66
|
+
* Evaluates the current state of a task after a tool outcome or at a step boundary.
|
|
67
|
+
*/
|
|
68
|
+
public evaluate(context: TaskObservationContext): Observation {
|
|
69
|
+
const evidenceRefs: string[] = [];
|
|
70
|
+
const outcomes = context.toolHistory || [];
|
|
71
|
+
|
|
72
|
+
if (outcomes.length === 0) {
|
|
73
|
+
return {
|
|
74
|
+
status: 'progressing',
|
|
75
|
+
evidenceRefs,
|
|
76
|
+
verified: false,
|
|
77
|
+
confidence: 0.5,
|
|
78
|
+
nextAction: 'Execute the first planned step.'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const lastOutcome = outcomes[outcomes.length - 1];
|
|
83
|
+
if (!lastOutcome) {
|
|
84
|
+
return {
|
|
85
|
+
status: 'progressing',
|
|
86
|
+
evidenceRefs,
|
|
87
|
+
verified: false,
|
|
88
|
+
confidence: 0.5
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (lastOutcome.path) evidenceRefs.push(lastOutcome.path);
|
|
93
|
+
if (lastOutcome.command) evidenceRefs.push(`cmd:${lastOutcome.command.slice(0, 100)}`);
|
|
94
|
+
|
|
95
|
+
// Check for explicit failures that need repair or approval
|
|
96
|
+
if (!lastOutcome.success) {
|
|
97
|
+
const err = lastOutcome.error || 'Unknown tool failure';
|
|
98
|
+
const isAuthOrPerm = /permission|denied|unauthorized|approval required|eacces/i.test(err);
|
|
99
|
+
const failureKey = createHash('sha256')
|
|
100
|
+
.update(`${lastOutcome.tool}\0${lastOutcome.command || lastOutcome.path || ''}\0${err}`)
|
|
101
|
+
.digest('hex')
|
|
102
|
+
.slice(0, 16);
|
|
103
|
+
|
|
104
|
+
if (isAuthOrPerm) {
|
|
105
|
+
return {
|
|
106
|
+
status: 'needs-approval',
|
|
107
|
+
evidenceRefs,
|
|
108
|
+
failureKey,
|
|
109
|
+
verified: false,
|
|
110
|
+
confidence: 0.9,
|
|
111
|
+
message: `Permission or authentication required: ${err}`,
|
|
112
|
+
nextAction: 'Request human approval or provide required credentials.'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
status: 'needs-repair',
|
|
118
|
+
evidenceRefs,
|
|
119
|
+
failureKey,
|
|
120
|
+
verified: false,
|
|
121
|
+
confidence: 0.85,
|
|
122
|
+
message: `Tool ${lastOutcome.tool} failed: ${err}`,
|
|
123
|
+
nextAction: 'Analyze error diagnostic and apply corrective repair.'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Check if the agent claims completion
|
|
128
|
+
if (context.agentClaim && context.agentClaim.trim()) {
|
|
129
|
+
const claim = context.agentClaim.toLowerCase();
|
|
130
|
+
const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b/i.test(claim);
|
|
131
|
+
|
|
132
|
+
if (claimsCompletion) {
|
|
133
|
+
// Run deterministic verification checks based on domain
|
|
134
|
+
const hasMutations = outcomes.some(o =>
|
|
135
|
+
['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)
|
|
136
|
+
);
|
|
137
|
+
const hasPassingVerification = outcomes.some(o =>
|
|
138
|
+
o.success && o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (hasMutations && !hasPassingVerification) {
|
|
142
|
+
return {
|
|
143
|
+
status: 'ready-to-verify',
|
|
144
|
+
evidenceRefs,
|
|
145
|
+
verified: false,
|
|
146
|
+
confidence: 0.6,
|
|
147
|
+
message: 'Mutations performed but automated test/build verification has not yet run.',
|
|
148
|
+
nextAction: 'Run targeted verification tests or build checks to confirm completion.'
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
status: 'verified',
|
|
154
|
+
evidenceRefs,
|
|
155
|
+
verified: true,
|
|
156
|
+
confidence: 0.95,
|
|
157
|
+
message: 'Task completed with supporting tool evidence.'
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
status: 'progressing',
|
|
164
|
+
evidenceRefs,
|
|
165
|
+
verified: false,
|
|
166
|
+
confidence: 0.75,
|
|
167
|
+
nextAction: 'Continue with next step in implementation plan.'
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Deterministically verifies code deliverables (targeted test, build, syntax).
|
|
173
|
+
*/
|
|
174
|
+
public verifyCode(req: CodeVerificationRequest): { verified: boolean; error?: string; evidence: string } {
|
|
175
|
+
if (req.changedFiles && req.changedFiles.length > 0) {
|
|
176
|
+
for (const file of req.changedFiles) {
|
|
177
|
+
const fullPath = path.isAbsolute(file) ? file : path.join(req.workspaceRoot, file);
|
|
178
|
+
if (!fs.existsSync(fullPath)) {
|
|
179
|
+
return {
|
|
180
|
+
verified: false,
|
|
181
|
+
error: `Target deliverable ${file} does not exist on disk.`,
|
|
182
|
+
evidence: 'file_missing'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
verified: true,
|
|
190
|
+
evidence: `Verified ${req.changedFiles?.length ?? 0} file(s) present and non-empty.`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Verifies documentation deliverables (headings, required sections).
|
|
196
|
+
*/
|
|
197
|
+
public verifyDocs(req: DocsDocsVerificationRequest): { verified: boolean; missingHeadings: string[] } {
|
|
198
|
+
const fullPath = path.isAbsolute(req.filePath) ? req.filePath : path.join(req.workspaceRoot, req.filePath);
|
|
199
|
+
if (!fs.existsSync(fullPath)) {
|
|
200
|
+
return { verified: false, missingHeadings: req.requiredHeadings || [] };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
204
|
+
const missing: string[] = [];
|
|
205
|
+
|
|
206
|
+
for (const heading of req.requiredHeadings || []) {
|
|
207
|
+
const headingPattern = new RegExp(`^#+\\s+.*${heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'im');
|
|
208
|
+
if (!headingPattern.test(content)) {
|
|
209
|
+
missing.push(heading);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
verified: missing.length === 0,
|
|
215
|
+
missingHeadings: missing
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Verifies creative/visual deliverables (asset exists and is not 0 bytes).
|
|
221
|
+
*/
|
|
222
|
+
public verifyCreative(req: CreativeVerificationRequest): { verified: boolean; bytes: number; error?: string } {
|
|
223
|
+
const fullPath = path.isAbsolute(req.artifactPath) ? req.artifactPath : path.join(req.workspaceRoot, req.artifactPath);
|
|
224
|
+
if (!fs.existsSync(fullPath)) {
|
|
225
|
+
return { verified: false, bytes: 0, error: `Media asset not found: ${req.artifactPath}` };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const stat = fs.statSync(fullPath);
|
|
229
|
+
const minBytes = req.minBytes ?? 100;
|
|
230
|
+
if (stat.size < minBytes) {
|
|
231
|
+
return { verified: false, bytes: stat.size, error: `Media asset too small (${stat.size} bytes < ${minBytes} bytes)` };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return { verified: true, bytes: stat.size };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Verifies local web deliverability via loopback HTTP GET.
|
|
239
|
+
*/
|
|
240
|
+
public async verifyLocalWeb(req: LocalWebVerificationRequest): Promise<{ verified: boolean; statusCode?: number; error?: string }> {
|
|
241
|
+
return new Promise((resolve) => {
|
|
242
|
+
try {
|
|
243
|
+
const url = new URL(req.endpoint);
|
|
244
|
+
// Security gate: only loopback is permitted for local verification
|
|
245
|
+
if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
|
|
246
|
+
resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
|
|
251
|
+
const expected = req.expectedStatus ?? 200;
|
|
252
|
+
const ok = res.statusCode === expected || (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);
|
|
253
|
+
const result: { verified: boolean; statusCode?: number; error?: string } = { verified: Boolean(ok) };
|
|
254
|
+
if (typeof res.statusCode === 'number') result.statusCode = res.statusCode;
|
|
255
|
+
resolve(result);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
clientReq.on('error', (err) => {
|
|
259
|
+
resolve({ verified: false, error: err.message });
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
clientReq.on('timeout', () => {
|
|
263
|
+
clientReq.destroy();
|
|
264
|
+
resolve({ verified: false, error: 'Connection timed out' });
|
|
265
|
+
});
|
|
266
|
+
} catch (e: any) {
|
|
267
|
+
resolve({ verified: false, error: e.message });
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Delegate to coldObserver for overconfidence and loop verification checks.
|
|
274
|
+
*/
|
|
275
|
+
public async auditTurnVerification(turnState: {
|
|
276
|
+
taskId?: string;
|
|
277
|
+
userPrompt: string;
|
|
278
|
+
agentClaim: string;
|
|
279
|
+
toolHistory: readonly ToolOutcome[];
|
|
280
|
+
stepsCompleted: number;
|
|
281
|
+
}) {
|
|
282
|
+
return coldObserver.auditTurnVerification(turnState);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export type DocsDocsVerificationRequest = DocsVerificationRequest;
|
|
287
|
+
export const defaultObserver = new CausyneObserver();
|