App-Greple-xlate

 view release on metacpan or  search on metacpan

CLAUDE.md  view on Meta::CPAN

- `docs/` - Development documentation (design specs, reference notes)
- Multiple README files in different languages generated by the translation system itself

## Critical File Handling Requirements
- **ALWAYS ensure ALL files end with a newline character** when using Write, Edit, or MultiEdit tools
- This is mandatory for proper file handling and to avoid issues with text processing tools, git, and other utilities
- Before finalizing any file operation, verify the content ends with '\n'

## Coding Style
- **Never use tab characters for indentation** — indent with spaces only
  (the codebase was fully de-tabbed in 2026-07; former tabs were expanded
  at 8-column stops)
- The only exception is Makefiles (`share/XLATE.mk`, `i18n/Makefile`,
  `examples/Makefile`, etc.), where make syntax requires tabs

## Important Behavior Guidelines
- **警告やエラーを無視しない**: git statusの警告、テストの失敗、Dockerのエラーなど、問題が発生したら「外部の問題」「関係ない」と推測で片付けずに、必ず原因を調査する
- **推測で判断しない**: 「〜だろう」「〜のはず」で済ませず、実際に確認してから判断する
- **問題から逃げない**: 面倒そうに見えても、根本原因を特定して適切に修正する

lib/App/Greple/xlate/llm.pm  view on Meta::CPAN

my $json_flat = JSON->new->canonical;

our $CONTEXT_MAX = 8000;          # total rendered context limit
our $CONTEXT_SOURCE_MIN = 500;    # slice floor while truncating

sub _progress {
    print STDERR @_ if opt('progress');
}

##
## Assemble the system prompt: expand %s to the target language name
## and append --xlate-context entries.  Phase 2 (context-aware
## differential translation) extends this function.
##
sub build_system {
    my $param = shift;
    my $prompt = opt('prompt') || $param->{prompt};
    my @vars = do {
        if ($prompt =~ /%s/) {
            $LANGNAME{$param->{lang_to}} // die "$param->{lang_to}: unknown lang.\n";
        } else {

share/XLATE.mk  view on Meta::CPAN

# XLATE_SEED:           Seed cache from another cache file
# XLATE_CONTEXT_WINDOW: Context blocks for re-translation
#
# XOPT single-quotes XLATE_ANONYMIZE/XLATE_MARK/XLATE_TEMPLATE/XLATE_SEED/
# XLATE_CONTEXT_WINDOW (and FILE.ANONYMIZE) so a value such as a custom
# --mark/--template regex containing parentheses survives /bin/sh
# unharmed.  This leaves residual limits:
#   - values must not contain a single quote (') -- there is no escaping
#     for it inside the single-quoted recipe argument;
#   - a literal $ in a value must be written as $$ at the make layer,
#     or make will try to expand it as its own variable reference;
#   - REMOVE_QUOTE (below) strips embedded double quotes from these
#     variables before XOPT ever sees them, so double quotes in a value
#     do not need separate handling here.
#

#
# PARAMETER FILES
#   If the source file is acompanied with parameter files with
#   following extension, they are used to override default parameters.
#

t/07_llm_unit.t  view on Meta::CPAN

    max       => 1000,
    options   => [ [ alpha => 'one' ], [ beta => 'two' ] ],
    prompt    => "Translate the following JSON array into %s.\n",
    lang_from => 'ORIGINAL',
    lang_to   => 'JA',
);

subtest 'build_system' => sub {
    my $system = App::Greple::xlate::llm::build_system(\%param);
    like($system, qr/\ATranslate the following JSON array into Japanese\./,
         '%s expands to language name');

    {
        my @saved = @{$opt{contexts}};
        @{$opt{contexts}} = ('background info');
        my $system = App::Greple::xlate::llm::build_system(\%param);
        like($system, qr/Translation context:\n- background info/,
             '--xlate-context is appended');
        @{$opt{contexts}} = @saved;
    }
    {

t/08_llm_gpt5.t  view on Meta::CPAN

like($argv_str, qr/-o reasoning_effort none/, 'reasoning_effort none');
like($argv_str, qr/-o verbosity low/, 'verbosity low');
like($argv_str, qr/--no-stream/, 'no-stream');
like($argv_str, qr/--no-log/, 'no-log');
unlike($argv_str, qr/temperature/, 'temperature is not sent');
unlike($argv_str, qr/max_tokens/, 'max_tokens is not sent (llm 0.31 Chat API rejects it)');

my($i) = grep { $argv[$_] eq '-s' } 0 .. $#argv;
my $system = $argv[$i + 1];
like($system, qr/\ATranslate the following JSON array into American English\./,
     'system prompt with language expanded');
like($system, qr/XML-style marker tag/, 'mask tag instruction preserved');
like($system, qr/conventions for that kind of element/,
     'element-type convention instruction present');
like($system, qr/<person id=2 \/>/, 'category tag example present');

is_deeply(JSON::PP->new->decode($rec->{stdin}), ["hello world\n"],
          'stdin is JSON array of lines');

done_testing;



( run in 0.530 second using v1.01-cache-2.11-cpan-9169edd2b0e )