tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

build-prefix-lines.sh (3461B)


      1 #!/usr/bin/env bash
      2 # Example selections/data only; the shared CLI owns all phase execution.
      3 #
      4 # Goal: extract payloads from tagged log lines, not just retain unchanged lines.
      5 # PREFIX_FILE supplies exact bytes at configuration time. Its contents are data,
      6 # never pasted into SCP source; quotes/backslashes are not source instructions.
      7 # COMPILER_DIGEST is caller-declared (recipe: docs/consumers.md), STORE is the
      8 # CAS directory, and PHASE_SECONDS bounds each separate child process.
      9 #
     10 # < printf 'ERROR ' > /tmp/log-prefix
     11 # < bash demos/consumers/prefix-lines/build-prefix-lines.sh /tmp/scp-logs "$COMPILER_DIGEST" 240 /tmp/log-prefix
     12 # > code-manifest/code-receipt, worker/invocation/configuration pins, file-manifest
     13 # Use printf rather than echo: an added LF becomes part of the exact prefix.
     14 set -euo pipefail
     15 if [[ $# != 4 ]]; then
     16   printf 'Usage: %s STORE COMPILER_DIGEST PHASE_SECONDS PREFIX_FILE\n' "$0" >&2
     17   exit 2
     18 fi
     19 store="$1"; compiler="$2"; seconds="$3"; prefix_file="$4"
     20 repo="$(cd "$(dirname "$0")/../../.." && pwd)"
     21 bootstrap="${SCP_BOOTSTRAP:-$repo/.bootstrap-run/scp-bootstrap}"
     22 tricu="${TRICU:-$repo/result/bin/tricu}"
     23 # 1. Build a narrow graph: seven base units plus prefix-lines.scp. The code
     24 # does not depend on the chosen prefix. code-manifest pins exported entries;
     25 # code-receipt records source/profile/compiler/dependency provenance.
     26 code="$("$tricu" scp build --bootstrap "$bootstrap" --store "$store" --compiler "$compiler" \
     27   --seconds "$seconds" --directory "$repo" --workspace demos.consumer-prefix-workspace)"
     28 printf '%s\n' "$code"
     29 manifest="$(printf '%s\n' "$code" | sed -n 's/^code-manifest=//p')"
     30 # 2. Execute configurePrefix with prefix bytes as input and explicit leaf state.
     31 # SCP constructs a splitter, a prefix-removing mapper, and mapMaybe collection.
     32 # workers pins descriptors with their initial states; invocations pins callable
     33 # Result-preserving wrappers. configuration-receipt records this selection and
     34 # exact input/state. These are outputs, not recipes to compile recursively.
     35 configured="$("$tricu" scp configure --bootstrap "$bootstrap" --store "$store" --seconds "$seconds" \
     36   --code "$manifest" --entry configurePrefix --input-file "$prefix_file" --state-leaf)"
     37 printf '%s\n' "$configured"
     38 invocations="$(printf '%s\n' "$configured" | sed -n 's/^invocations=//p')"
     39 # 3. Bind prefixLines to the shared file adapter. The shell chooses an export
     40 # and display label; SCP still owns extraction and all application wiring.
     41 "$tricu" scp file --bootstrap "$bootstrap" --store "$store" --seconds "$seconds" \
     42   --invocations "$invocations" --entry prefixLines --label matches
     43 # Deploy with the printed file-manifest; neither prefix/source files nor the
     44 # configuration launcher are needed by this pinned runtime program:
     45 # < result/bin/tricu scp run-file --store /tmp/scp-logs --seconds 60 --manifest FILE_MANIFEST_HASH --input-file demos/consumers/prefix-lines/tagged-log.fixture
     46 # > matches=3
     47 # > first=disk
     48 # > [t t, ["disk", t, "final"]]
     49 # Here t is an empty matched payload, not an absent match: an exact "ERROR "
     50 # line contributes one result. Nonmatching lines contribute none.
     51 # Try prefix "WARN ": first=retry and matches=1. Code stays the same; worker
     52 # state and configuration outputs change. An empty prefix keeps every line.
     53 # To configure another prefix without another build, invoke result/bin/tricu scp configure
     54 # directly with the existing code-manifest, then publish its file adapter.