astrocook.gaps module#

The gaps of the collection of recipes (phase 6-ter, PR 5b, decision 6).

A gap is something the analysis needed and no recipe provided. The gaps are recorded where they are met (by the MCP server today, by any caller that wants to) in a local file of the user, one JSON object per line, and summarized by summarize() (the command astrocook-gaps, the tool gaps_summary of the server) as the input of the plan of a phase.

Privacy: the file is local and never sent anywhere. A line holds only date, version, kind, text and session (the name of the session), nothing else of the user: no paths, no parameter values, no data of the spectrum. The text is what the agent wrote (kind declared) or a fixed sentence of the server naming a tool, a prerequisite or an exception type (never its message, which may hold a path).

Where the file is (ASTROCOOK_GAPS_FILE overrides it; off disables the record):

macOS

~/Library/Application Support/Astrocook/gaps.jsonl

Linux

$XDG_DATA_HOME/astrocook/gaps.jsonl, else ~/.local/share/astrocook/gaps.jsonl

Windows

%APPDATA%\Astrocook\gaps.jsonl

astrocook.gaps.KINDS = ('declared', 'prerequisite', 'failed', 'undone')#

written by the agent (what was needed and what it did instead); prerequisite: a prerequisite that no recipe estimates from the data; failed: a recipe that failed with an unexpected error on a valid request; undone: the result of a recipe that the agent undid.

Type:

The kinds of gap. declared

astrocook.gaps.ENV_VAR = 'ASTROCOOK_GAPS_FILE'#

The environment variable that moves the file, or turns the record off

astrocook.gaps.MAX_TEXT = 2000#

The longest text recorded; the rest is cut

astrocook.gaps.gaps_path() → Path | None[source]#

The file of the gaps, or None if the record is off.

astrocook.gaps.record_gap(kind: str, text: str, session: str) → bool[source]#

Append a gap to the file of the user.

Never raises: a record that cannot be written must not break the caller (one warning is logged). Returns True if the line was written.

Parameters:
  • kind (str) – One of KINDS.

  • text (str) – What was needed and what was done instead, or the sentence of the server; cut to MAX_TEXT characters.

  • session (str) – The name of the session.

astrocook.gaps.read_gaps(path: Path | None = None) → Tuple[List[Dict[str, Any]], int][source]#

The gaps recorded, and the number of lines skipped (not JSON, or without the fields). A file that does not exist holds no gaps.

astrocook.gaps.summarize(records: Iterable[Dict[str, Any]], since: str | None = None, kind: str | None = None, limit: int | None = None) → List[Dict[str, Any]][source]#

Group the gaps by kind and text (without the numbers).

The texts of the kind declared are free, so their groups are only those of equal wording: the reader joins the similar ones.

Parameters:
  • records (iterable of dict) – The output of read_gaps().

  • since (str, optional) – Only the gaps from this date on (YYYY-MM-DD).

  • kind (str, optional) – Only this kind.

  • limit (int, optional) – At most this number of groups, the most frequent first.

Returns:

Each with kind, text (the first one met), count, sessions (how many different), versions, first, last (dates) and examples (up to three different texts), the most frequent first.

Return type:

list of dict

astrocook.gaps.format_summary(groups: List[Dict[str, Any]], skipped: int = 0) → str[source]#

The groups of summarize() as text, by kind.

astrocook.gaps.main(argv: List[str] | None = None) → int[source]#

Entry point of astrocook-gaps: summarize the gaps recorded.