@causyne/agent 1.20.117 → 1.20.118
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 +7 -2
- package/src/cliMode.js +19 -3
- package/src/commands.js +7 -1
- package/src/plugins/pluginManager.js +74 -0
- package/src/reporting.js +12 -4
- package/src/skillsManager.js +3 -2
- package/src/skillsManager.ts +3 -2
- package/src/tools/pluginManager.js +17 -2
- package/src/tui/composerControls.js +16 -3
- package/src/tui/composerControls.ts +14 -3
- package/src/tui/prompt.js +122 -16
- package/src/tui/usageCard.js +119 -47
- package/src/tui/usageCard.ts +133 -49
- package/src/tui/workspaceSwitch.js +2 -0
- package/src/tui/workspaceSwitch.ts +1 -0
- package/src/verification/boundedExplorer.js +119 -0
- package/src/verification/cliProbe.js +116 -0
- package/src/verification/featureMap.js +78 -0
- package/src/verification/interactivePty.js +188 -0
- package/src/verification/propertyProbe.js +121 -0
- package/src/verification/ptyProbe.js +125 -0
- package/src/verification/skillCatalog.d.ts +1 -0
- package/src/verification/skillCatalog.js +60 -0
- package/src/verification/statechart.js +143 -0
- package/src/verification/uiRuntime.js +57 -0
- package/src/verificationPlan.js +1 -1
- package/src/verificationPlan.ts +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const FEATURE_MAP = Object.freeze({
|
|
2
|
+
'tui-usage': {
|
|
3
|
+
surface: 'terminal',
|
|
4
|
+
entry: '/usage and /status',
|
|
5
|
+
action: 'Open the panel, submit a message, switch busy state, close with Escape',
|
|
6
|
+
assertion: 'The panel stays visible until explicitly dismissed',
|
|
7
|
+
automated: ['tests/tuiPinnedUsageStatus.test.ts', 'tests/usageCard.test.ts'],
|
|
8
|
+
liveDriver: 'posix-pty-chat',
|
|
9
|
+
liveRequired: 'Drive ChatPrompt, StageSurface, and chatMode in isolated PTYs; packaged launcher and host mouse pixels remain separate'
|
|
10
|
+
},
|
|
11
|
+
'tui-turn-rail': {
|
|
12
|
+
surface: 'terminal',
|
|
13
|
+
entry: 'Left conversation navigation rail',
|
|
14
|
+
action: 'Hover grouped dots, choose a turn, scroll its timeline preview',
|
|
15
|
+
assertion: 'The selected turn opens without scrolling terminal scrollback',
|
|
16
|
+
automated: ['tests/tuiTurnTimelineVideoParity.test.ts', 'tests/tuiTurnTimelineWheel.test.ts'],
|
|
17
|
+
liveRequired: 'Inspect pointer movement, popup geometry and wheel handling in a real terminal'
|
|
18
|
+
},
|
|
19
|
+
'agent-loop': {
|
|
20
|
+
surface: 'agent',
|
|
21
|
+
entry: 'Submit a task with tool calls and retry conditions',
|
|
22
|
+
action: 'Execute, interrupt, resume, and inspect evidence-gated completion',
|
|
23
|
+
assertion: 'No fabricated completion or unhandled failed tool response',
|
|
24
|
+
automated: ['tests/agentLoopFixes.test.ts', 'tests/agentLoopHookSeams.test.js'],
|
|
25
|
+
liveRequired: 'Run a real task in the selected workspace with explicitly permitted tools'
|
|
26
|
+
},
|
|
27
|
+
'web-preview': {
|
|
28
|
+
surface: 'browser',
|
|
29
|
+
entry: 'browser_act preview, snapshot and screenshot',
|
|
30
|
+
action: 'Open the built page and inspect the DOM and rendered pixels',
|
|
31
|
+
assertion: 'The page is reachable and its actual visual state matches the request',
|
|
32
|
+
automated: ['tests/webVerificationState.test.ts'],
|
|
33
|
+
liveRequired: 'Use the Causyne Browser to capture a fresh screenshot after the latest edit'
|
|
34
|
+
},
|
|
35
|
+
'plugin-safety': {
|
|
36
|
+
surface: 'plugin',
|
|
37
|
+
entry: 'Enabled plugin skills via the plugin manager',
|
|
38
|
+
action: 'Read a permitted skill and reject an unapproved or invalid plugin',
|
|
39
|
+
assertion: 'Digest-pinned plugin permissions remain mandatory',
|
|
40
|
+
automated: ['tests/plugins.test.js', 'tests/skillsReliability.test.js'],
|
|
41
|
+
liveRequired: 'Check a separately approved plugin against the current permission record'
|
|
42
|
+
},
|
|
43
|
+
'terminal-pty': {
|
|
44
|
+
surface: 'terminal',
|
|
45
|
+
entry: 'An explicitly selected interactive program and input sequence',
|
|
46
|
+
action: 'Launch the real program in a pseudo-terminal and capture exit, input and output evidence',
|
|
47
|
+
assertion: 'A PTY pass requires observed terminal output and the expected process exit',
|
|
48
|
+
automated: ['tests/verificationPtyProbe.test.ts'],
|
|
49
|
+
liveRequired: 'The smoke fixture only tests the PTY driver; user-app behavior needs a separate real app session'
|
|
50
|
+
},
|
|
51
|
+
'ui-properties': {
|
|
52
|
+
surface: 'terminal',
|
|
53
|
+
entry: 'Seeded UI interaction and runtime state handlers',
|
|
54
|
+
action: 'Generate bounded action sequences, shrink counterexamples and replay real prompt transitions',
|
|
55
|
+
assertion: 'Panels persist until explicit close; counterexamples retain their original failure identity',
|
|
56
|
+
automated: ['tests/verificationPropertyProbe.test.ts'],
|
|
57
|
+
liveRequired: 'Seeded handler checks do not establish terminal rendering or cross-process races'
|
|
58
|
+
},
|
|
59
|
+
'formal-state': {
|
|
60
|
+
surface: 'model',
|
|
61
|
+
entry: 'verification/formal-verification',
|
|
62
|
+
action: 'Explore bounded state transitions and inject a deliberately broken variant',
|
|
63
|
+
assertion: 'Counterexamples are reproducible and a bounded pass is not claimed as a proof',
|
|
64
|
+
automated: ['tests/boundedExplorer.test.ts', 'tests/cliProbe.test.ts'],
|
|
65
|
+
liveRequired: 'For unbounded guarantees, run a real external model checker or proof assistant'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export function selectFeatures(names) {
|
|
70
|
+
if (!Array.isArray(names) || names.length === 0) throw new Error('At least one feature is required');
|
|
71
|
+
const selected = [...new Set(names)];
|
|
72
|
+
for (const name of selected) {
|
|
73
|
+
if (!Object.hasOwn(FEATURE_MAP, name)) {
|
|
74
|
+
throw new Error('Unknown feature: ' + String(name));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return selected.map(name => ({ id: name, ...FEATURE_MAP[name] }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
const DRIVER = String.raw`import base64, fcntl, json, os, pty, select, signal, struct, sys, termios, time
|
|
7
|
+
cfg=json.loads(sys.argv[1])
|
|
8
|
+
pid,fd=pty.fork()
|
|
9
|
+
if pid==0:
|
|
10
|
+
os.chdir(cfg["cwd"])
|
|
11
|
+
os.environ["TERM"]="xterm-256color"
|
|
12
|
+
os.environ["COLUMNS"]=str(cfg["cols"])
|
|
13
|
+
os.environ["LINES"]=str(cfg["rows"])
|
|
14
|
+
os.execv(cfg["exec"],cfg["argv"])
|
|
15
|
+
fcntl.ioctl(fd,termios.TIOCSWINSZ,struct.pack("HHHH",cfg["rows"],cfg["cols"],0,0))
|
|
16
|
+
started=time.monotonic()
|
|
17
|
+
out=bytearray()
|
|
18
|
+
observations=[]
|
|
19
|
+
cursor=0
|
|
20
|
+
since=0
|
|
21
|
+
pending_enter=None
|
|
22
|
+
done=False
|
|
23
|
+
closed=False
|
|
24
|
+
timeout=False
|
|
25
|
+
overflow=False
|
|
26
|
+
exit_code=None
|
|
27
|
+
while True:
|
|
28
|
+
elapsed=(time.monotonic()-started)*1000
|
|
29
|
+
if pending_enter is not None and elapsed>=pending_enter[0]:
|
|
30
|
+
try: os.write(fd,pending_enter[1])
|
|
31
|
+
except OSError: pass
|
|
32
|
+
pending_enter=None
|
|
33
|
+
readable,_,_=select.select([fd],[],[],0.025)
|
|
34
|
+
if readable and not closed:
|
|
35
|
+
try: chunk=os.read(fd,16384)
|
|
36
|
+
except OSError: chunk=b""
|
|
37
|
+
if not chunk: closed=True
|
|
38
|
+
else:
|
|
39
|
+
room=max(0,cfg["limit"]-len(out))
|
|
40
|
+
if len(chunk)>room: overflow=True
|
|
41
|
+
out.extend(chunk[:room])
|
|
42
|
+
if cursor<len(cfg["steps"]) and not done and pending_enter is None:
|
|
43
|
+
step=cfg["steps"][cursor]
|
|
44
|
+
match=step["waitFor"]
|
|
45
|
+
segment=bytes(out[since:]).decode("utf-8",errors="replace")
|
|
46
|
+
if match in segment:
|
|
47
|
+
observation={"name":step["name"],"offset":len(out),"expected":step["contains"]}
|
|
48
|
+
observations.append(observation)
|
|
49
|
+
payload=base64.b64decode(step["input"])
|
|
50
|
+
# A real keyboard sends text then Enter. Combining both in one
|
|
51
|
+
# PTY write makes Causyne correctly classify it as a bulk paste.
|
|
52
|
+
if payload.endswith(b"\r") and len(payload)>1:
|
|
53
|
+
try: os.write(fd,payload[:-1])
|
|
54
|
+
except OSError: pass
|
|
55
|
+
pending_enter=((time.monotonic()-started)*1000+65,b"\r")
|
|
56
|
+
else:
|
|
57
|
+
try: os.write(fd,payload)
|
|
58
|
+
except OSError: pass
|
|
59
|
+
since=len(out)
|
|
60
|
+
cursor+=1
|
|
61
|
+
if not done:
|
|
62
|
+
got,status=os.waitpid(pid,os.WNOHANG)
|
|
63
|
+
if got:
|
|
64
|
+
done=True
|
|
65
|
+
exit_code=os.waitstatus_to_exitcode(status)
|
|
66
|
+
if done and closed: break
|
|
67
|
+
if elapsed>cfg["timeout"]:
|
|
68
|
+
timeout=True
|
|
69
|
+
if not done:
|
|
70
|
+
try: os.killpg(pid,signal.SIGKILL)
|
|
71
|
+
except ProcessLookupError: pass
|
|
72
|
+
try:
|
|
73
|
+
got,status=os.waitpid(pid,0)
|
|
74
|
+
exit_code=os.waitstatus_to_exitcode(status)
|
|
75
|
+
except ChildProcessError: pass
|
|
76
|
+
break
|
|
77
|
+
for n,item in enumerate(observations):
|
|
78
|
+
end=observations[n+1]["offset"] if n+1<len(observations) else len(out)
|
|
79
|
+
segment=bytes(out[item["offset"]:end]).decode("utf-8",errors="replace")
|
|
80
|
+
item["matched"]=item["expected"] in segment
|
|
81
|
+
item["bytes"]=end-item["offset"]
|
|
82
|
+
result={"exit":exit_code,"timeout":timeout,"truncated":overflow,
|
|
83
|
+
"completed":cursor==len(cfg["steps"]),"steps":observations,
|
|
84
|
+
"requested":len(cfg["steps"])}
|
|
85
|
+
os.write(1,bytes(out))
|
|
86
|
+
os.write(2,("CAUSYNE_UI_PTY_RESULT:"+json.dumps(result)+"\n").encode("utf-8"))`;
|
|
87
|
+
|
|
88
|
+
function bounded(value, min, max, label) {
|
|
89
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
90
|
+
throw new RangeError('Invalid ' + label);
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function runInteractivePty(options = {}) {
|
|
96
|
+
const {
|
|
97
|
+
workspace, script, steps, timeoutMs = 15000,
|
|
98
|
+
outputLimit = 1048576, rows = 42, columns = 126, env = {}
|
|
99
|
+
} = options;
|
|
100
|
+
if (typeof workspace !== 'string' || typeof script !== 'string'
|
|
101
|
+
|| !Array.isArray(steps) || steps.length < 1 || steps.length > 12) {
|
|
102
|
+
throw new TypeError('workspace, script, and 1..12 interaction steps are required');
|
|
103
|
+
}
|
|
104
|
+
bounded(timeoutMs, 1000, 60000, 'timeoutMs');
|
|
105
|
+
bounded(outputLimit, 1024, 2097152, 'outputLimit');
|
|
106
|
+
bounded(rows, 20, 100, 'rows');
|
|
107
|
+
bounded(columns, 48, 240, 'columns');
|
|
108
|
+
for (const step of steps) {
|
|
109
|
+
if (!step || typeof step.name !== 'string' || !/^[\w-]{1,50}$/.test(step.name)
|
|
110
|
+
|| typeof step.input !== 'string' || step.input.length > 2048
|
|
111
|
+
|| typeof step.waitFor !== 'string' || !step.waitFor
|
|
112
|
+
|| step.waitFor.length > 200 || typeof step.contains !== 'string'
|
|
113
|
+
|| step.contains.length > 200) {
|
|
114
|
+
throw new TypeError('Each step requires bounded name, input, waitFor and contains strings');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!env || typeof env !== 'object' || Array.isArray(env)
|
|
118
|
+
|| Object.keys(env).some(key => !['CAUSYNE_HOME'].includes(key))) {
|
|
119
|
+
throw new TypeError('Only an isolated CAUSYNE_HOME environment override is permitted');
|
|
120
|
+
}
|
|
121
|
+
if (typeof env.CAUSYNE_HOME !== 'string' || !path.isAbsolute(env.CAUSYNE_HOME)) {
|
|
122
|
+
throw new TypeError('An explicit isolated CAUSYNE_HOME path is required');
|
|
123
|
+
}
|
|
124
|
+
const tempRoot = realpathSync(os.tmpdir());
|
|
125
|
+
const isolatedHome = realpathSync(env.CAUSYNE_HOME);
|
|
126
|
+
const relativeHome = path.relative(tempRoot, isolatedHome);
|
|
127
|
+
if (!relativeHome || relativeHome === '..' || relativeHome.startsWith('..' + path.sep)
|
|
128
|
+
|| path.isAbsolute(relativeHome)) {
|
|
129
|
+
throw new Error('Verification CAUSYNE_HOME must be an isolated temporary directory');
|
|
130
|
+
}
|
|
131
|
+
const cwd = realpathSync(workspace);
|
|
132
|
+
const target = realpathSync(path.resolve(cwd, script));
|
|
133
|
+
const relative = path.relative(cwd, target);
|
|
134
|
+
if (!relative || relative === '..' || relative.startsWith('..' + path.sep)
|
|
135
|
+
|| path.isAbsolute(relative) || !/\.[cm]?js$/.test(target)) {
|
|
136
|
+
throw new Error('Interactive verification target must be a workspace JavaScript file');
|
|
137
|
+
}
|
|
138
|
+
if (process.platform === 'win32') {
|
|
139
|
+
return { status: 'unavailable', success: false, surface: 'none',
|
|
140
|
+
reason: 'A Windows ConPTY adapter has not been implemented' };
|
|
141
|
+
}
|
|
142
|
+
const cfg = {
|
|
143
|
+
cwd, exec: process.execPath, argv: [process.execPath, target],
|
|
144
|
+
rows, cols: columns, timeout: timeoutMs, limit: outputLimit,
|
|
145
|
+
steps: steps.map(step => ({
|
|
146
|
+
name: step.name, input: Buffer.from(step.input, 'utf8').toString('base64'),
|
|
147
|
+
waitFor: step.waitFor, contains: step.contains
|
|
148
|
+
}))
|
|
149
|
+
};
|
|
150
|
+
return new Promise(resolve => {
|
|
151
|
+
let stdout = '';
|
|
152
|
+
let stderr = '';
|
|
153
|
+
let spawnError = null;
|
|
154
|
+
const child = spawn('python3', ['-c', DRIVER, JSON.stringify(cfg)], {
|
|
155
|
+
cwd, shell: false, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'],
|
|
156
|
+
env: { ...process.env, ...env, TERM: 'xterm-256color',
|
|
157
|
+
COLUMNS: String(columns), LINES: String(rows), CAUSYNE_VERIFY_PROBE: '1' }
|
|
158
|
+
});
|
|
159
|
+
child.stdout.on('data', data => { stdout += data.toString('utf8'); });
|
|
160
|
+
child.stderr.on('data', data => { stderr += data.toString('utf8'); });
|
|
161
|
+
child.on('error', e => { spawnError = e; });
|
|
162
|
+
child.on('close', () => {
|
|
163
|
+
if (spawnError?.code === 'ENOENT') {
|
|
164
|
+
resolve({ status: 'unavailable', success: false, surface: 'none',
|
|
165
|
+
reason: 'python3 is required for POSIX terminal verification' });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const marker = stderr.match(/CAUSYNE_UI_PTY_RESULT:(\{[^\r\n]+\})/);
|
|
169
|
+
let detail = null;
|
|
170
|
+
try { if (marker) detail = JSON.parse(marker[1]); } catch {}
|
|
171
|
+
const observations = Array.isArray(detail?.steps) ? detail.steps : [];
|
|
172
|
+
const success = Boolean(detail && !detail.timeout && !detail.truncated
|
|
173
|
+
&& detail.completed && detail.exit === 0
|
|
174
|
+
&& observations.length === steps.length
|
|
175
|
+
&& observations.every(item => item.matched));
|
|
176
|
+
resolve({
|
|
177
|
+
status: success ? 'observed-pass' : 'observed-fail', success,
|
|
178
|
+
surface: detail ? 'posix-pty' : 'unverified',
|
|
179
|
+
exitCode: detail?.exit ?? null, timedOut: detail?.timeout ?? null,
|
|
180
|
+
truncated: detail?.truncated ?? null,
|
|
181
|
+
completed: detail?.completed ?? false, observations,
|
|
182
|
+
stdout, stderr: stderr.replace(/CAUSYNE_UI_PTY_RESULT:\{[^\r\n]+\}\r?\n?/, ''),
|
|
183
|
+
reason: detail ? null : (spawnError?.message || 'No valid PTY evidence'),
|
|
184
|
+
limitation: 'Actual TUI components run in a PTY; host screenshots, mouse forwarding, and the full CLI launch are separate checks'
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const LIMITS = Object.freeze({ trials: 500, steps: 500, actions: 1000, replay: 20000 });
|
|
2
|
+
|
|
3
|
+
function integer(name, value, maximum) {
|
|
4
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) {
|
|
5
|
+
throw new RangeError(name + ' must be an integer between 0 and ' + maximum);
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function failure(value) {
|
|
11
|
+
if (value && typeof value.then === 'function') throw new TypeError('Async invariants are not supported');
|
|
12
|
+
return value === true ? null : (typeof value === 'string' ? value : 'Invariant returned false');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function nextRandom(state) {
|
|
16
|
+
let value = state.value >>> 0;
|
|
17
|
+
value ^= value << 13;
|
|
18
|
+
value ^= value >>> 17;
|
|
19
|
+
value ^= value << 5;
|
|
20
|
+
state.value = value >>> 0;
|
|
21
|
+
return state.value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function runPath(initial, transition, invariant, path) {
|
|
25
|
+
let state;
|
|
26
|
+
try {
|
|
27
|
+
state = initial();
|
|
28
|
+
if (state && typeof state.then === 'function') {
|
|
29
|
+
throw new TypeError('Async initial state is not supported');
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return { failed: true, reason: String(error?.message || error), step: -1 };
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const error = failure(invariant(state));
|
|
36
|
+
if (error) return { failed: true, reason: error, step: -1 };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return { failed: true, reason: String(error?.message || error), step: -1 };
|
|
39
|
+
}
|
|
40
|
+
for (let i = 0; i < path.length; i++) {
|
|
41
|
+
try {
|
|
42
|
+
const action = structuredClone(path[i]);
|
|
43
|
+
const next = transition(state, action);
|
|
44
|
+
if (next && typeof next.then === 'function') throw new TypeError('Async transitions are not supported');
|
|
45
|
+
if (next !== undefined) state = next;
|
|
46
|
+
const error = failure(invariant(state));
|
|
47
|
+
if (error) return { failed: true, reason: error, step: i };
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return { failed: true, reason: String(error?.message || error), step: i };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { failed: false, reason: null, step: path.length };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function shrinkPath(path, fails, budget) {
|
|
56
|
+
let current = path.slice();
|
|
57
|
+
let chunk = Math.ceil(current.length / 2);
|
|
58
|
+
while (chunk > 0 && budget.left > 0) {
|
|
59
|
+
let changed = false;
|
|
60
|
+
for (let offset = 0; offset < current.length && budget.left > 0; offset += chunk) {
|
|
61
|
+
const candidate = current.slice(0, offset).concat(current.slice(offset + chunk));
|
|
62
|
+
budget.left--;
|
|
63
|
+
if (fails(candidate)) {
|
|
64
|
+
current = candidate;
|
|
65
|
+
changed = true;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!changed) chunk = Math.floor(chunk / 2);
|
|
70
|
+
}
|
|
71
|
+
return current;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Deterministic bounded property exploration for real transition handlers.
|
|
76
|
+
* Pass a fresh initial() per replay; never report a bounded pass as a proof.
|
|
77
|
+
*/
|
|
78
|
+
export function verifyActionSequences(options = {}) {
|
|
79
|
+
const { initial, transition, invariant, actions } = options;
|
|
80
|
+
if (typeof initial !== 'function' || typeof transition !== 'function'
|
|
81
|
+
|| typeof invariant !== 'function') {
|
|
82
|
+
throw new TypeError('initial, transition, and invariant must be functions');
|
|
83
|
+
}
|
|
84
|
+
if (!Array.isArray(actions) || actions.length === 0 || actions.length > LIMITS.actions) {
|
|
85
|
+
throw new RangeError('actions must be a nonempty bounded array');
|
|
86
|
+
}
|
|
87
|
+
const seed = integer('seed', options.seed ?? 1, 0xffffffff);
|
|
88
|
+
const trials = integer('trials', options.trials ?? 100, LIMITS.trials);
|
|
89
|
+
const maxSteps = integer('maxSteps', options.maxSteps ?? 32, LIMITS.steps);
|
|
90
|
+
if (trials === 0) throw new RangeError('trials must be positive');
|
|
91
|
+
const random = { value: seed === 0 ? 0x6d2b79f5 : seed };
|
|
92
|
+
let executed = 0;
|
|
93
|
+
|
|
94
|
+
for (let trial = 0; trial < trials; trial++) {
|
|
95
|
+
const path = [];
|
|
96
|
+
for (let step = 0; step < maxSteps; step++) {
|
|
97
|
+
path.push(actions[nextRandom(random) % actions.length]);
|
|
98
|
+
}
|
|
99
|
+
executed += path.length;
|
|
100
|
+
const observed = runPath(initial, transition, invariant, path);
|
|
101
|
+
if (!observed.failed) continue;
|
|
102
|
+
const originalTrace = path.slice(0, Math.max(0, observed.step + 1));
|
|
103
|
+
const budget = { left: LIMITS.replay };
|
|
104
|
+
const trace = shrinkPath(originalTrace, candidate => {
|
|
105
|
+
const result = runPath(initial, transition, invariant, candidate);
|
|
106
|
+
return result.failed && result.reason === observed.reason;
|
|
107
|
+
}, budget);
|
|
108
|
+
const minimized = runPath(initial, transition, invariant, trace);
|
|
109
|
+
return {
|
|
110
|
+
status: 'counterexample', seed, trial, maxSteps, trialsRun: trial + 1,
|
|
111
|
+
transitionsGenerated: executed, trace, originalTrace,
|
|
112
|
+
reason: minimized.reason, shrinkReplays: LIMITS.replay - budget.left,
|
|
113
|
+
evidence: 'replayable transition-handler counterexample, not a formal proof'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
status: 'bounded-pass', seed, trialsRun: trials, maxSteps,
|
|
118
|
+
transitionsGenerated: executed,
|
|
119
|
+
evidence: 'deterministic seeded action-sequence sampling only; not exhaustive or a formal proof'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const DRIVER = String.raw`
|
|
6
|
+
import base64, json, os, pty, select, signal, sys, time
|
|
7
|
+
cfg=json.loads(sys.argv[1])
|
|
8
|
+
pid,fd=pty.fork()
|
|
9
|
+
if pid==0:
|
|
10
|
+
os.chdir(cfg["cwd"])
|
|
11
|
+
os.execvpe(cfg["argv"][0],cfg["argv"],os.environ)
|
|
12
|
+
start=time.monotonic()
|
|
13
|
+
sent=not bool(cfg["input"])
|
|
14
|
+
closed=False
|
|
15
|
+
done=False
|
|
16
|
+
status=None
|
|
17
|
+
overflow=False
|
|
18
|
+
out=bytearray()
|
|
19
|
+
while True:
|
|
20
|
+
elapsed=time.monotonic()-start
|
|
21
|
+
if not sent and elapsed>=cfg["delay"]/1000:
|
|
22
|
+
if cfg["input"]:
|
|
23
|
+
try: os.write(fd,base64.b64decode(cfg["input"]))
|
|
24
|
+
except OSError: pass
|
|
25
|
+
sent=True
|
|
26
|
+
readable,_,_=select.select([fd],[],[],0.04)
|
|
27
|
+
if readable and not closed:
|
|
28
|
+
try: chunk=os.read(fd,8192)
|
|
29
|
+
except OSError: chunk=b""
|
|
30
|
+
if not chunk: closed=True
|
|
31
|
+
else:
|
|
32
|
+
remaining=cfg["limit"]-len(out)
|
|
33
|
+
if len(chunk)>remaining: overflow=True
|
|
34
|
+
out.extend(chunk[:max(0,remaining)])
|
|
35
|
+
if not done:
|
|
36
|
+
got,info=os.waitpid(pid,os.WNOHANG)
|
|
37
|
+
if got:
|
|
38
|
+
done=True
|
|
39
|
+
status=os.waitstatus_to_exitcode(info)
|
|
40
|
+
if done and closed: break
|
|
41
|
+
if elapsed>cfg["timeout"]/1000:
|
|
42
|
+
if not done:
|
|
43
|
+
try: os.killpg(pid,signal.SIGKILL)
|
|
44
|
+
except ProcessLookupError: pass
|
|
45
|
+
got,info=os.waitpid(pid,0)
|
|
46
|
+
status=os.waitstatus_to_exitcode(info)
|
|
47
|
+
done=True
|
|
48
|
+
break
|
|
49
|
+
os.write(1,bytes(out))
|
|
50
|
+
os.write(2,("PTY_RESULT:"+json.dumps({"exit":status,"timeout":elapsed>cfg["timeout"]/1000,"truncated":overflow,"inputSent":sent})+"\n").encode())
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
function resolveCommand(workspace, program) {
|
|
54
|
+
const base = realpathSync(workspace);
|
|
55
|
+
if (program === 'node') return process.execPath;
|
|
56
|
+
if (typeof program !== 'string' || !path.isAbsolute(program)) {
|
|
57
|
+
throw new Error('Only node or an absolute workspace executable is permitted');
|
|
58
|
+
}
|
|
59
|
+
const resolved = realpathSync(program);
|
|
60
|
+
const relative = path.relative(base, resolved);
|
|
61
|
+
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
62
|
+
throw new Error('Executable must be inside workspace');
|
|
63
|
+
}
|
|
64
|
+
return resolved;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function runPtyProbe(options = {}) {
|
|
68
|
+
const { workspace, program = 'node', args = [], input = '', contains = null,
|
|
69
|
+
timeoutMs = 5000, inputDelayMs = 100, outputLimit = 65536,
|
|
70
|
+
expectedExitCode = 0 } = options;
|
|
71
|
+
if (typeof workspace !== 'string' || !Array.isArray(args)
|
|
72
|
+
|| !args.every(a => typeof a === 'string') || typeof input !== 'string') {
|
|
73
|
+
throw new TypeError('workspace, argv, and input must be valid strings');
|
|
74
|
+
}
|
|
75
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 60000
|
|
76
|
+
|| !Number.isSafeInteger(inputDelayMs) || inputDelayMs < 0 || inputDelayMs >= timeoutMs
|
|
77
|
+
|| !Number.isSafeInteger(outputLimit) || outputLimit < 128 || outputLimit > 1048576) {
|
|
78
|
+
throw new RangeError('Invalid PTY probe limits');
|
|
79
|
+
}
|
|
80
|
+
if (!Number.isInteger(expectedExitCode) || expectedExitCode < 0 || expectedExitCode > 255
|
|
81
|
+
|| (contains !== null && (typeof contains !== 'string' || contains.length > 1024))) {
|
|
82
|
+
throw new TypeError('Invalid PTY probe assertion');
|
|
83
|
+
}
|
|
84
|
+
const cwd = realpathSync(workspace);
|
|
85
|
+
const executable = resolveCommand(workspace, program);
|
|
86
|
+
if (process.platform === 'win32') {
|
|
87
|
+
return { status: 'unavailable', success: false,
|
|
88
|
+
reason: 'Windows ConPTY adapter is not installed', surface: 'none' };
|
|
89
|
+
}
|
|
90
|
+
const config = { cwd, argv: [executable, ...args],
|
|
91
|
+
input: Buffer.from(input).toString('base64'), delay: inputDelayMs,
|
|
92
|
+
timeout: timeoutMs, limit: outputLimit };
|
|
93
|
+
return new Promise(resolve => {
|
|
94
|
+
let stdout = '';
|
|
95
|
+
let stderr = '';
|
|
96
|
+
let spawnedError = null;
|
|
97
|
+
const child = spawn('python3', ['-c', DRIVER, JSON.stringify(config)], {
|
|
98
|
+
cwd, shell: false, windowsHide: true,
|
|
99
|
+
stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, CAUSYNE_VERIFY_PROBE: '1' }
|
|
100
|
+
});
|
|
101
|
+
child.stdout.on('data', bytes => { stdout += bytes.toString('utf8'); });
|
|
102
|
+
child.stderr.on('data', bytes => { stderr += bytes.toString('utf8'); });
|
|
103
|
+
child.on('error', error => { spawnedError = String(error.message || error); });
|
|
104
|
+
child.on('close', () => {
|
|
105
|
+
if (spawnedError && /ENOENT/.test(spawnedError)) {
|
|
106
|
+
resolve({ status: 'unavailable', success: false, surface: 'none',
|
|
107
|
+
reason: 'python3 is required for POSIX PTY verification' });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const marker = stderr.match(/PTY_RESULT:(\{[^\n]+\})/);
|
|
111
|
+
let detail;
|
|
112
|
+
try { detail = marker ? JSON.parse(marker[1]) : null; } catch { detail = null; }
|
|
113
|
+
const success = Boolean(detail && !detail.timeout && !detail.truncated
|
|
114
|
+
&& detail.exit === expectedExitCode && detail.inputSent
|
|
115
|
+
&& (contains === null || stdout.includes(contains)));
|
|
116
|
+
resolve({ status: success ? 'observed-pass' : 'observed-fail', success,
|
|
117
|
+
surface: detail ? 'posix-pty' : 'unverified', stdout,
|
|
118
|
+
stderr: stderr.replace(/PTY_RESULT:\{[^\n]+\}\n?/, ''),
|
|
119
|
+
exitCode: detail?.exit ?? null, timedOut: detail?.timeout ?? null,
|
|
120
|
+
truncated: detail?.truncated ?? null, inputSent: detail?.inputSent ?? false,
|
|
121
|
+
reason: detail ? null : (spawnedError || 'PTY driver produced no valid exit evidence'),
|
|
122
|
+
limitation: 'PTY verifies terminal input/output, not desktop pixels or host mouse settings' });
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERIFICATION_SKILLS: Readonly<Record<string, { name: string; description: string; content: string }>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const VERIFICATION_SKILLS = Object.freeze({
|
|
2
|
+
'runtime-verification': {
|
|
3
|
+
name: 'runtime-verification',
|
|
4
|
+
description: 'Drive a real app or CLI and collect repeatable evidence. Use after UI, CLI, browser, or desktop changes before claiming completion.',
|
|
5
|
+
content: `# Runtime verification
|
|
6
|
+
1. Identify one user-visible behavior and the actual launch command in the active workspace. Do not assume the Causyne repository is the workspace.
|
|
7
|
+
2. Run the build and existing tests first. Launch the real binary or local app using sysRun and the current workspace scope.
|
|
8
|
+
3. For a CLI, supply a real input and inspect the exit status and output. For a TUI, call runPtyProbe from src/verification/ptyProbe.js on POSIX when python3 is available. Treat unavailable as unverified; pipes do not establish terminal mouse or rendering behavior.
|
|
9
|
+
4. For a web app, use browser_act for navigation, snapshot, and screenshot. For a desktop app, use computer_use and explicit screenshot/inspection tools. Do not invent an "app aria-click" command.
|
|
10
|
+
5. Record the action, observed result, expected result, and artifact location. A screenshot alone does not prove the action took place. If an adapter or approval is unavailable, report unverified.
|
|
11
|
+
6. Close the launched process, and ensure transient resources are released.
|
|
12
|
+
## Verification
|
|
13
|
+
- Done when: the real user path was exercised, the assertion matched observed evidence, and cleanup succeeded. Build-only passes must be labeled build-only.`
|
|
14
|
+
},
|
|
15
|
+
'formal-verification': {
|
|
16
|
+
name: 'formal-verification',
|
|
17
|
+
description: 'Check state-machine invariants, retries, and asynchronous races. Use when tests do not cover all important event orders.',
|
|
18
|
+
content: `# Formal verification
|
|
19
|
+
1. Choose a concrete safety property from code and identify the production transition functions. Model only states and actions supported by the implementation.
|
|
20
|
+
2. For small finite state spaces, run exhaustive bounded exploration on the production transition function. Record the depth, explored states, and assumptions.
|
|
21
|
+
3. For cross-process interleavings, use an installed TLA+ TLC checker with a version-pinned model. For unbounded data properties, consider an installed Lean verifier. Never silently download a binary or assume Lean is installed.
|
|
22
|
+
4. Run a deliberately broken variant in a scratch workspace to prove the invariant detects the bug. Restore the original and rerun.
|
|
23
|
+
5. Present the shortest counterexample as real actions. Never call bounded model exploration an unbounded proof or imply a TLA+ model proves the TypeScript implementation.
|
|
24
|
+
## Verification
|
|
25
|
+
- Done when: the check was actually executed, catches a deliberately failing case, and passes or reports a reproducible counterexample on unchanged production code.`
|
|
26
|
+
},
|
|
27
|
+
'ui-property-testing': {
|
|
28
|
+
name: 'ui-property-testing',
|
|
29
|
+
description: 'Explore UI state and input sequences including long random-looking text, resize, and session changes. Use for regressions in chat or navigation.',
|
|
30
|
+
content: `# UI property testing
|
|
31
|
+
1. Define user-observable invariants for the current interface: text stays within viewport width, hover cannot mutate messages, Escape closes only the intended layer, and scrolling never escapes the active surface.
|
|
32
|
+
2. Use verifyActionSequences from src/verification/propertyProbe.js with a fresh state factory, seeded actions and real event handlers. Report the finite trials and shortened counterexample; a bounded pass is not a proof.
|
|
33
|
+
3. Execute the real UI reducer or input handler for each sequence; use a PTY for claims about terminal behavior and browser_act for browser visuals.
|
|
34
|
+
4. Save the shortest failing sequence and seed. Rerun the original sequence after a fix; do not lower the assertion to make it pass.
|
|
35
|
+
## Verification
|
|
36
|
+
- Done when: the failing path was reproduced and is now a regression test, or the bounded sequence count and unverified host dependencies were reported.`
|
|
37
|
+
},
|
|
38
|
+
'statechart-verification': {
|
|
39
|
+
name: 'statechart-verification',
|
|
40
|
+
description: 'Explain and validate reachable states for queues, approvals, retries, and UI overlays. Use for state-dependent behavior with invalid transitions.',
|
|
41
|
+
content: `# Statechart verification
|
|
42
|
+
1. Locate the real reducer or transition map. List states, events, guards, and actions from code.
|
|
43
|
+
2. Define forbidden states and transitions. Use bounded breadth-first exploration to reach every modeled state within the chosen bounds.
|
|
44
|
+
3. Run npm run verify:statechart to render the bounded JavaScript panel model, and npm run verify:statechart -- --broken to confirm a counterexample can be found. This graph is not a TLC proof. Where a pinned TLA+ checker exists, separately run npm run verify:tla and report its status explicitly.
|
|
45
|
+
4. Report shortest paths to violations; do not invent events or conflate a diagram with an executable verification result.
|
|
46
|
+
## Verification
|
|
47
|
+
- Done when: each displayed transition has a code mapping and all reported counterexamples reproduce under the stated conditions.`
|
|
48
|
+
},
|
|
49
|
+
'verification-maintenance': {
|
|
50
|
+
name: 'verification-maintenance',
|
|
51
|
+
description: 'Update runtime and formal checks after touched code changes. Use when prior passing evidence may no longer describe the current implementation.',
|
|
52
|
+
content: `# Verification maintenance
|
|
53
|
+
1. Compare changed source files against tests, runtime evidence and model-covered functions.
|
|
54
|
+
2. Invalidate prior evidence after behavior-changing edits. Reproduce the user path again, rather than reusing old screenshots, status flags, or test output.
|
|
55
|
+
3. Execute affected tests, build, and the appropriate runtime or bounded formal checks; distinguish missing tools from successful checks.
|
|
56
|
+
4. Preserve user scope, existing permissions, and unrelated files. Do not generate public documentation or commit private run reports.
|
|
57
|
+
## Verification
|
|
58
|
+
- Done when: all relevant checks were rerun against the present commit and missing validation is clearly marked, not silently treated as success.`
|
|
59
|
+
}
|
|
60
|
+
});
|