Coverage for sources/mimeogram/prompt.py: 31%
25 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-05 19:46 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-05 19:46 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Mimeogram prompt text for LLMs. '''
22# TODO? Use BSD sysexits.
25from . import __
26from . import interfaces as _interfaces
29_scribe = __.produce_scribe( __name__ )
32class Command(
33 _interfaces.CliCommand,
34 decorators = ( __.standard_tyro_class, ),
35):
36 ''' Provides LLM prompt text for mimeogram format. '''
38 clip: __.typx.Annotated[
39 __.typx.Optional[ bool ],
40 __.typx.Doc( ''' Copy prompt to clipboard. ''' ),
41 __.tyro.conf.arg( aliases = ( '--clipboard', '--to-clipboard' ) ),
42 ] = None
44 async def __call__( self, auxdata: __.Globals ) -> None:
45 ''' Executes command to provide prompt text. '''
46 await provide_prompt( auxdata )
48 def provide_configuration_edits( self ) -> __.DictionaryEdits:
49 ''' Provides edits against configuration from options. '''
50 edits: list[ __.DictionaryEdit ] = [ ]
51 if None is not self.clip:
52 edits.append( __.SimpleDictionaryEdit( # pyright: ignore
53 address = ( 'prompt', 'to-clipboard' ), value = self.clip ) )
54 return tuple( edits )
57async def acquire_prompt( auxdata: __.Globals ) -> str:
58 ''' Acquires prompt text from package data. '''
59 location = (
60 auxdata.distribution.provide_data_location(
61 'prompts', 'mimeogram.md' ) )
62 return await __.acquire_text_file_async( location )
65async def provide_prompt( auxdata: __.Globals ) -> None:
66 ''' Provides mimeogram prompt text. '''
67 with __.report_exceptions( _scribe, "Could not acquire prompt text." ):
68 prompt = await acquire_prompt( auxdata )
69 options = auxdata.configuration.get( 'prompt', { } )
70 if options.get( 'to-clipboard', False ):
71 from pyperclip import copy
72 with __.report_exceptions(
73 _scribe, "Could not copy prompt to clipboard."
74 ): copy( prompt )
75 _scribe.info( "Copied prompt to clipboard." )
76 else: print( prompt ) # TODO? Use output stream from configuration.
77 raise SystemExit( 0 )