Coverage for sources / mimeogram / prompt.py: 33%
26 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-18 17:27 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-18 17:27 +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 exceptions as _exceptions
27from . import interfaces as _interfaces
30_scribe = __.produce_scribe( __name__ )
33class Command(
34 _interfaces.CliCommand,
35 decorators = ( __.standard_tyro_class, ),
36):
37 ''' Provides LLM prompt text for mimeogram format. '''
39 clip: __.typx.Annotated[
40 __.tyro.conf.DisallowNone[ bool | None ],
41 __.typx.Doc( ''' Copy prompt to clipboard. ''' ),
42 __.tyro.conf.arg( aliases = ( '--clipboard', '--to-clipboard' ) ),
43 ] = None
45 async def __call__(
46 self, auxdata: __.appcore.state.Globals
47 ) -> None:
48 ''' Executes command to provide prompt text. '''
49 await provide_prompt( auxdata )
51 def provide_configuration_edits(
52 self,
53 ) -> __.appcore.dictedits.Edits:
54 ''' Provides edits against configuration from options. '''
55 edits: list[ __.appcore.dictedits.Edit ] = [ ]
56 if None is not self.clip:
57 edits.append( __.appcore.dictedits.SimpleEdit( # pyright: ignore
58 address = ( 'prompt', 'to-clipboard' ), value = self.clip ) )
59 return tuple( edits )
62async def acquire_prompt(
63 auxdata: __.appcore.state.Globals,
64) -> str:
65 ''' Acquires prompt text from package data. '''
66 location = (
67 auxdata.distribution.provide_data_location(
68 'prompts', 'mimeogram.md' ) )
69 return await __.appcore.io.acquire_text_file_async( location )
72async def provide_prompt(
73 auxdata: __.appcore.state.Globals,
74) -> None:
75 ''' Provides mimeogram prompt text. '''
76 with _exceptions.report_exceptions(
77 _scribe, "Could not acquire prompt text."
78 ):
79 prompt = await acquire_prompt( auxdata )
80 options = auxdata.configuration.get( 'prompt', { } )
81 if options.get( 'to-clipboard', False ):
82 from . import clipboard
83 with _exceptions.report_exceptions(
84 _scribe, "Could not copy prompt to clipboard."
85 ): clipboard.copy_to_clipboard( prompt )
86 _scribe.info( "Copied prompt to clipboard." )
87 else: print( prompt ) # TODO? Use output stream from configuration.
88 raise SystemExit( 0 )