okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-ui2 baeb4533b (approved UI designs, context fix, workspace default with rename, autotune progress) into f-split-intc5755ed83

main
3.8 KiB53 linesraw
1/** Item 2: an approval card asks in plain words; the exact command stays in the card's Details. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { askFor } from '../server/agent/ask.mjs';
5import { TurnProjector } from '../server/agent/events.mjs';
6
7const sh = command => askFor('pwsh', { command });
8const ev = (type, data, seq = 1, time = 1000) => ({ type: 'event', event: { type, seq, time, data } });
9
10test('opening a folder is asked as opening that folder, with the common ones by name', () => {
11  assert.deepEqual(sh('Start-Process explorer.exe -ArgumentList "C:\\Users\\Ana\\Documents"').id, 'open-known-folder');
12  assert.deepEqual(sh('Start-Process explorer.exe -ArgumentList "C:\\Users\\Ana\\Documents"').params, ['Documents']);
13  assert.deepEqual(sh('explorer.exe C:\\Users\\Ana\\Downloads').params, ['Downloads']);
14  assert.deepEqual(sh('Start-Process explorer.exe C:\\work\\Reports'), { id: 'open-folder', params: ['Reports'], why: 'opens-window', detail: 'C:\\work\\Reports' });
15  assert.equal(sh('Invoke-Item C:\\work\\plan.pdf').id, 'open-file');
16  assert.equal(sh('explorer.exe').id, 'open-explorer');
17});
18
19test('running a program, deleting, creating and copying are named for what they are', () => {
20  assert.deepEqual(sh('Start-Process "C:\\Users\\Ana\\Downloads\\setup.exe" -ArgumentList /S').params, ['setup.exe']);
21  assert.equal(sh('Start-Process "C:\\Users\\Ana\\Downloads\\setup.exe" -ArgumentList /S').id, 'run-program');
22  assert.deepEqual(sh('Remove-Item C:\\tmp\\old.txt -Force'), { id: 'delete', params: ['old.txt'], why: 'delete-why', detail: 'C:\\tmp\\old.txt' });
23  assert.equal(sh('rm -rf build').id, 'delete');
24  assert.equal(sh('New-Item -ItemType File -Path C:\\Users\\Ana\\Desktop\\notes.txt').id, 'create-file');
25  assert.equal(sh('mkdir C:\\work\\out').id, 'create-folder');
26  assert.equal(sh('Copy-Item a.txt b.txt').id, 'copy');
27  assert.equal(sh('Get-Date | Out-File C:\\x\\a.txt').id, 'write-file');
28  assert.equal(sh('echo hi > notes.txt').params[0], 'notes.txt');
29  assert.deepEqual(sh('git push origin main'), { id: 'git', params: ['push'], why: 'changes-repo' });
30  assert.equal(sh('npm install left-pad').id, 'install');
31  assert.equal(sh('python build.py').id, 'run-script');
32});
33
34test('files the agent writes or edits, and the tools that are not commands', () => {
35  assert.deepEqual(askFor('write', { file_path: 'C:/Users/Ana/Desktop/notes.txt' }), { id: 'create-file', params: ['notes.txt'], why: 'replaces-if-exists', detail: 'C:/Users/Ana/Desktop/notes.txt' });
36  assert.equal(askFor('edit', { file_path: 'C:/a/b.md' }).id, 'change-file');
37  assert.equal(askFor('job_kill', {}).id, 'stop-task');
38  assert.deepEqual(askFor('web_fetch', { url: 'https://example.com/a?b=1' }).params, ['example.com']);
39  assert.deepEqual(askFor('mcp__github__create_issue', {}).params, ['github / create_issue']);
40});
41
42test('what it cannot read it does not pretend to: a generic question, with the model\'s own description when there is one', () => {
43  assert.deepEqual(sh('foo --bar'), { id: 'run-command', params: [], why: 'run-command-why' });
44  assert.equal(askFor('pwsh', { command: 'foo --bar' }, 'Rebuild the index').detail, 'Rebuild the index');
45  assert.equal(sh('Get-Date; Remove-Item x.txt').id, 'run-steps', 'two different steps are said to be steps');
46});
47
48test('the card carries the question, and the exact command stays in its arguments for Details', () => {
49  const p = new TurnProjector({ startedAt: 0 });
50  const card = p.consume(ev('tool/call', { callId: 'a1', name: 'pwsh', arguments: JSON.stringify({ command: 'Start-Process explorer.exe -ArgumentList "C:\\Users\\Ana\\Documents"', description: 'Open Documents' }) }))[0].tool;
51  assert.equal(card.ask.id, 'open-known-folder'); assert.deepEqual(card.ask.params, ['Documents']);
52  assert.match(card.preview, /Start-Process explorer\.exe/, 'the command is still sent for the Details disclosure');
53});