1+ import type {
2+ ProjectFilePage ,
3+ HistoryReader ,
4+ HistoryWindow ,
5+ SearchPage ,
6+ SearchRequest ,
7+ } from "./workspace-search.ts" ;
18import type { EntryPlacement } from "../entry-placement.ts" ;
29import type { ReplTesting , ReplTestReport } from "./testing.ts" ;
310/**
@@ -29,8 +36,8 @@ import type { ReplTesting, ReplTestReport } from "./testing.ts";
2936 * ## Reads, writes, and which returns become feedback
3037 *
3138 * The read class observes and returns: bindings, the entry vocabulary, the six
32- * guide chapters, the environment, and the four bounded reads of one entry's
33- * saved evidence. The write class is
39+ * guide chapters, the environment, entry inspection and Workspace Search.
40+ * The write class is
3441 * what changes something a person can see or asks them something: filling the
3542 * shared draft, submitting it, and canonical `<Elicit>`. Keeping them in
3643 * separate classes is what lets the captured ceiling say, exactly, that a reply
@@ -128,6 +135,9 @@ export type GuideChapter = (typeof GUIDE_CHAPTERS)[number];
128135 * unavailable may well ask for something else next.
129136 */
130137export interface SidekickRequests {
138+ search ( request : SearchRequest ) : Operation < Result < SearchPage > > ;
139+ projectFile ( request : Json ) : Operation < Result < ProjectFilePage > > ;
140+ historyWindow ( reader : HistoryReader , request : Json ) : Operation < Result < HistoryWindow > > ;
131141 readonly test ?: ReplTesting ;
132142 inspectImage ?( path : string ) : Operation < Result < string > > ;
133143 importAsset ( source : string , destination : string ) : Operation < Result < string > > ;
@@ -286,6 +296,8 @@ export const DESIGNATED: ReadonlySet<string> = new Set([
286296 "REPL.InspectImage" ,
287297 "REPL.EntryOutput" ,
288298 ...ENTRY_INSPECTIONS ,
299+ "REPL.Search" ,
300+ "REPL.File.Read" ,
289301 ELICIT_CONTROL ,
290302 ...GUIDE_CHAPTERS . map ( ( chapter ) => `Guide.${ chapter } ` ) ,
291303] ) ;
@@ -581,7 +593,58 @@ export function sidekickObservations(
581593 } ) ,
582594 ) ;
583595 }
584- observations . push ( ...entryInspections ( requests , journal ) ) ;
596+ observations . push (
597+ ...entryInspections ( requests , journal ) ,
598+ reading ( "REPL.Search" , "Search project files and REPL history" , {
599+ kind : "function" ,
600+ name : "REPL.Search" ,
601+ description :
602+ 'Find literal text with `<REPL.Search query="error message" />`. Pass the returned reference as request to its named reader.' ,
603+ props : {
604+ type : "object" ,
605+ properties : {
606+ query : { type : "string" , minLength : 1 , maxLength : 160 } ,
607+ scope : { type : "string" , enum : [ "files" , "history" , "both" ] } ,
608+ after : { type : "object" } ,
609+ } ,
610+ required : [ "query" ] ,
611+ additionalProperties : false ,
612+ } ,
613+ * fn ( props : Record < string , Json > ) : Operation < SearchPage | string > {
614+ const { query, scope, after } = props ;
615+ if (
616+ typeof query !== "string" ||
617+ ( scope !== undefined && scope !== "files" && scope !== "history" && scope !== "both" )
618+ ) {
619+ throw new Error ( "Invalid Workspace Search arguments." ) ;
620+ }
621+ return yield * inspected (
622+ journal ,
623+ { component : "REPL.Search" , arguments : { ...props } } ,
624+ ( ) => requests . search ( { query, scope, after } ) ,
625+ ) ;
626+ } ,
627+ } ) ,
628+ reading ( "REPL.File.Read" , "Read a bounded project file window" , {
629+ kind : "function" ,
630+ name : "REPL.File.Read" ,
631+ description :
632+ 'Read project context with `<REPL.File.Read request={{"path":"note.txt","lines":"2:4"}} />`.' ,
633+ props : {
634+ type : "object" ,
635+ properties : { request : { type : "object" } } ,
636+ required : [ "request" ] ,
637+ additionalProperties : false ,
638+ } ,
639+ * fn ( props : Record < string , Json > ) : Operation < ProjectFilePage | string > {
640+ return yield * inspected (
641+ journal ,
642+ { component : "REPL.File.Read" , arguments : { ...props } } ,
643+ ( ) => requests . projectFile ( props . request ) ,
644+ ) ;
645+ } ,
646+ } ) ,
647+ ) ;
585648 for ( const chapter of GUIDE_CHAPTERS ) {
586649 const name = `Guide.${ chapter } ` ;
587650 observations . push (
@@ -629,18 +692,27 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
629692 name : "REPL.Entry.Source" ,
630693 props : {
631694 type : "object" ,
632- properties : { ...ENTRY_SELECTION } ,
695+ properties : { ...ENTRY_SELECTION , request : { type : "object" } } ,
633696 additionalProperties : false ,
634697 } ,
635698 description :
636699 "Read the exact source one entry was admitted with. " +
637700 "`<REPL.Entry.Source entry={22} />` answers with a window of that source, counted in " +
638701 "Unicode code points, and the arguments of the windows either side of it." ,
639- * fn ( props : EntryReadRequest ) : Operation < EntryTextPage | string > {
640- return yield * inspected (
702+ * fn (
703+ props : EntryReadRequest & { request ?: Json } ,
704+ ) : Operation < EntryTextPage | HistoryWindow | string > {
705+ return yield * inspected < EntryTextPage | HistoryWindow > (
641706 journal ,
642707 { component : "REPL.Entry.Source" , arguments : { ...props } } ,
643- ( ) => requests . inspectSource ( props ) ,
708+ ( ) =>
709+ props . request === undefined
710+ ? requests . inspectSource ( props )
711+ : Object . keys ( props ) . length === 1
712+ ? requests . historyWindow ( "REPL.Entry.Source" , props . request )
713+ : ( function * ( ) {
714+ return Err ( new Error ( "Pass a history request by itself." ) ) ;
715+ } ) ( ) ,
644716 ) ;
645717 } ,
646718 } ) ,
@@ -650,6 +722,7 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
650722 props : {
651723 type : "object" ,
652724 properties : {
725+ request : { type : "object" } ,
653726 ...ENTRY_SELECTION ,
654727 prompt : { type : "number" } ,
655728 field : { type : "string" } ,
@@ -661,11 +734,20 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
661734 '`<REPL.Entry.Prompt entry={22} prompt={9} field="error" />` answers with that turn\'s ' +
662735 "reply, request or complete failure message, its own status and where it was written. " +
663736 "A turn that recorded no failure answers with null text rather than an empty one." ,
664- * fn ( props : EntryPromptRequest ) : Operation < EntryPromptPage | string > {
665- return yield * inspected (
737+ * fn (
738+ props : EntryPromptRequest & { request ?: Json } ,
739+ ) : Operation < EntryPromptPage | HistoryWindow | string > {
740+ return yield * inspected < EntryPromptPage | HistoryWindow > (
666741 journal ,
667742 { component : "REPL.Entry.Prompt" , arguments : { ...props } } ,
668- ( ) => requests . inspectPrompt ( props ) ,
743+ ( ) =>
744+ props . request === undefined
745+ ? requests . inspectPrompt ( props )
746+ : Object . keys ( props ) . length === 1
747+ ? requests . historyWindow ( "REPL.Entry.Prompt" , props . request )
748+ : ( function * ( ) {
749+ return Err ( new Error ( "Pass a history request by itself." ) ) ;
750+ } ) ( ) ,
669751 ) ;
670752 } ,
671753 } ) ,
@@ -674,18 +756,27 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
674756 name : "REPL.Entry.Output" ,
675757 props : {
676758 type : "object" ,
677- properties : { ...ENTRY_SELECTION } ,
759+ properties : { ...ENTRY_SELECTION , request : { type : "object" } } ,
678760 additionalProperties : false ,
679761 } ,
680762 description :
681763 "Read what one entry printed. `<REPL.Entry.Output entry={22} />` answers with the last " +
682764 "window of that entry's output; `offset={0}` reads from the beginning. An entry that " +
683765 "retained none answers with an empty window." ,
684- * fn ( props : EntryReadRequest ) : Operation < EntryTextPage | string > {
685- return yield * inspected (
766+ * fn (
767+ props : EntryReadRequest & { request ?: Json } ,
768+ ) : Operation < EntryTextPage | HistoryWindow | string > {
769+ return yield * inspected < EntryTextPage | HistoryWindow > (
686770 journal ,
687771 { component : "REPL.Entry.Output" , arguments : { ...props } } ,
688- ( ) => requests . inspectOutput ( props ) ,
772+ ( ) =>
773+ props . request === undefined
774+ ? requests . inspectOutput ( props )
775+ : Object . keys ( props ) . length === 1
776+ ? requests . historyWindow ( "REPL.Entry.Output" , props . request )
777+ : ( function * ( ) {
778+ return Err ( new Error ( "Pass a history request by itself." ) ) ;
779+ } ) ( ) ,
689780 ) ;
690781 } ,
691782 } ) ,
@@ -695,6 +786,7 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
695786 props : {
696787 type : "object" ,
697788 properties : {
789+ request : { type : "object" } ,
698790 entry : { type : "number" } ,
699791 yq : { type : "string" , minLength : 1 } ,
700792 maxBytes : { type : "integer" , minimum : 1 , maximum : Number . MAX_SAFE_INTEGER } ,
@@ -709,11 +801,20 @@ function entryInspections(requests: SidekickRequests, journal: ControlJournal):
709801 "Read .exec.exitCode, .exec.stdout and .exec.stderr on a command record; " +
710802 "reuse next, prev or last as yq with the same positive entry. " +
711803 "Use maxBytes={8388608} for an 8 MiB compact UTF-8 JSON response budget; navigation carries it, and a later explicit budget overrides it." ,
712- * fn ( props : EntryJournalRequest ) : Operation < EntryJournalPage | string > {
713- return yield * inspected (
804+ * fn (
805+ props : EntryJournalRequest & { request ?: Json } ,
806+ ) : Operation < EntryJournalPage | HistoryWindow | string > {
807+ return yield * inspected < EntryJournalPage | HistoryWindow > (
714808 journal ,
715809 { component : "REPL.Entry.Journal" , arguments : { ...props } } ,
716- ( ) => requests . inspectJournal ( props ) ,
810+ ( ) =>
811+ props . request === undefined
812+ ? requests . inspectJournal ( props )
813+ : Object . keys ( props ) . length === 1
814+ ? requests . historyWindow ( "REPL.Entry.Journal" , props . request )
815+ : ( function * ( ) {
816+ return Err ( new Error ( "Pass a history request by itself." ) ) ;
817+ } ) ( ) ,
717818 ) ;
718819 } ,
719820 } ) ,
0 commit comments