okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c5755ed83
main
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' , () => { 11assert . deepEqual ( sh ( 'Start-Process explorer.exe -ArgumentList "C:\\Users\\Ana\\Documents"' ). id , 'open-known-folder' ); 12assert . deepEqual ( sh ( 'Start-Process explorer.exe -ArgumentList "C:\\Users\\Ana\\Documents"' ). params , [ 'Documents' ]); 13assert . deepEqual ( sh ( 'explorer.exe C:\\Users\\Ana\\Downloads' ). params , [ 'Downloads' ]); 14assert . deepEqual ( sh ( 'Start-Process explorer.exe C:\\work\\Reports' ), { id :'open-folder' , params :[ 'Reports' ], why :'opens-window' , detail :'C:\\work\\Reports' }); 15assert . equal ( sh ( 'Invoke-Item C:\\work\\plan.pdf' ). id , 'open-file' ); 16assert . equal ( sh ( 'explorer.exe' ). id , 'open-explorer' ); 17}); 18 19test ( 'running a program, deleting, creating and copying are named for what they are' , () => { 20assert . deepEqual ( sh ( 'Start-Process "C:\\Users\\Ana\\Downloads\\setup.exe" -ArgumentList /S' ). params , [ 'setup.exe' ]); 21assert . equal ( sh ( 'Start-Process "C:\\Users\\Ana\\Downloads\\setup.exe" -ArgumentList /S' ). id , 'run-program' ); 22assert . deepEqual ( sh ( 'Remove-Item C:\\tmp\\old.txt -Force' ), { id :'delete' , params :[ 'old.txt' ], why :'delete-why' , detail :'C:\\tmp\\old.txt' }); 23assert . equal ( sh ( 'rm -rf build' ). id , 'delete' ); 24assert . equal ( sh ( 'New-Item -ItemType File -Path C:\\Users\\Ana\\Desktop\\notes.txt' ). id , 'create-file' ); 25assert . equal ( sh ( 'mkdir C:\\work\\out' ). id , 'create-folder' ); 26assert . equal ( sh ( 'Copy-Item a.txt b.txt' ). id , 'copy' ); 27assert . equal ( sh ( 'Get-Date | Out-File C:\\x\\a.txt' ). id , 'write-file' ); 28assert . equal ( sh ( 'echo hi > notes.txt' ). params [ 0 ], 'notes.txt' ); 29assert . deepEqual ( sh ( 'git push origin main' ), { id :'git' , params :[ 'push' ], why :'changes-repo' }); 30assert . equal ( sh ( 'npm install left-pad' ). id , 'install' ); 31assert . equal ( sh ( 'python build.py' ). id , 'run-script' ); 32}); 33 34test ( 'files the agent writes or edits, and the tools that are not commands' , () => { 35assert . 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' }); 36assert . equal ( askFor ( 'edit' , { file_path :'C:/a/b.md' }). id , 'change-file' ); 37assert . equal ( askFor ( 'job_kill' , {}). id , 'stop-task' ); 38assert . deepEqual ( askFor ( 'web_fetch' , { url :'https://example.com/a?b=1' }). params , [ 'example.com' ]); 39assert . 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' , () => { 43assert . deepEqual ( sh ( 'foo --bar' ), { id :'run-command' , params :[], why :'run-command-why' }); 44assert . equal ( askFor ( 'pwsh' , { command :'foo --bar' }, 'Rebuild the index' ). detail , 'Rebuild the index' ); 45assert . 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' , () => { 49const p = new TurnProjector ({ startedAt :0 }); 50const 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 ; 51assert . equal ( card . ask . id , 'open-known-folder' ); assert . deepEqual ( card . ask . params , [ 'Documents' ]); 52assert . match ( card . preview , / Start-Process explorer\.exe / , 'the command is still sent for the Details disclosure' ); 53});