UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

28 lines (27 loc) • 2.29 kB
/** * A sourced file this very command WROTE is the text it sources (#3400). * * `. ./lib.sh` / `source lib.sh` run a file's text in THIS shell: the functions it defines stand after it, and a call * to one later runs its body where the call stands. The station cannot read a file — but where the same command wrote * the file first, with a literal printer and a `>` redirection (`printf 'f(){ …; }\n' > lib.sh; . ./lib.sh`, or `cat` * fed a here-document the shell expands nothing in), the text it sources IS the literal the printer spells: the * segments of that literal are spliced in place of the `source` * segment, before anything is projected, so every later reader (definitions, bodies, callers, bindings, the * working-directory thread) reads them as the shell runs them — no reader of its own. * * Fail-closed where the claim does not hold: a file the command did not write before the source with nothing between but * statements that certainly leave it be (a listed reader on literal words; another segment between — a second write, a move, a * pipe, a group — is a claim the station does not make), a write reached * through `&&` / `||` that the source is not chained to (it may not have run), a write with `>>`, through a pipe, with * a word the shell rewrites, a format that converts or a here-document the shell expands, a printer with a launcher or a prefix assignment, a `source` * carrying a redirection of its own, or a literal the lexer cannot read, splices nothing — the `source` segment stays what it was (text run in this shell that the * station does not hold: an unsettled start, the #3358 law). Bash's `sourcepath` PATH search of a bare name is not * read: the file the command wrote at that spelling is taken as the text (docs/KNOWN-LIMITS.md KL-3400-a). */ import { type LexedCommand } from "../../shell/lex.js"; /** * THE splice ({@link module}): each `source` / `.` of a file this text wrote with a literal printer earlier, no base move * between, is replaced by the segments of the written literal (the first taking the `source` segment's connector). * Returns the command unchanged where nothing splices. */ export declare function inlineSourcedLiterals(lexed: LexedCommand, readers?: ReadonlySet<string>): LexedCommand;