Repository navigation
feat(airc_core): migrate config CRUD to airc_core.config (#152 Phase 1) - #167
Merged
Merged
Conversation
…rc_core.config (#152 Phase 1) Continuing the Python truth-layer migration started in PR #166. Phase 1: convert high-risk bash heredocs to airc_core modules incrementally. ## What - New `lib/airc_core/config.py` with `get(config_path, key, default)` + `get_name(config_path)` + CLI entry point. - Bash `get_name` and `get_config_val` shrink from inline python heredocs (with bash-variable substitution INTO the python source) to one-line `"$AIRC_PYTHON" -m airc_core.config get <key> <default>` calls. ## Why 45+ callsites across airc bash use these two helpers. Pre-migration each was an inline `"$AIRC_PYTHON" -c "import json; ...$1...$2..."` heredoc — bash $1 / $2 substituted INTO the python source. If the key or default contained quotes, special chars, etc., python parsing broke silently and the value fell back via `2>/dev/null || echo $2`. Continuum-b69f 2026-04-27 traced one symptom (host_target reading empty even when config.json had it) to this class. Now: CONFIG env var holds the file path; key + default come from argv. Python source is fixed bytes; bash never touches it. ## Test posture - identity: 19/19 (heaviest config-read scenario — name, identity fields, integrations all read via the migrated path) - whois: 5/5 - part_persists: 8/8 - list: 4/4 - general_sidecar_default: 12/12 - platform_adapters: 11/11 Direct unit-test of the CLI: - valid config → returns name correctly - missing config → returns default - get_name on valid config → name - both subcommands respond as expected ## Next migrations Per the Phase 1 priority queue (high-fragility first): pair handshake JSON build/parse → gist envelope build → gist envelope resolve → monitor_formatter → host_address_set. Each lands as a separate PR; integration tests verify identical bash-side behavior.
There was a problem hiding this comment.
Pull request overview
Migrates airc’s config read helpers (get_name, get_config_val) from inline bash-embedded Python to the airc_core.config Python “truth-layer”, using a stable "$AIRC_PYTHON" -m airc_core.config ... CLI surface and passing inputs via env/argv.
Changes:
- Added
lib/airc_core/config.pyimplementingget/get_nameplus a small CLI (get,get_name) readingCONFIGfrom the environment. - Updated
airc’sget_name()andget_config_val()bash helpers to call the new module via"$AIRC_PYTHON" -m airc_core.config ...rather than inline-csnippets.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/airc_core/config.py | Introduces Python config access functions and CLI entry points for get / get_name. |
| airc | Routes bash config helper functions through airc_core.config to remove bash→Python source substitution fragility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+38
to
+45
| with open(config_path) as f: | ||
| c = json.load(f) | ||
| v = c.get(key) | ||
| if v is None: | ||
| return default | ||
| return str(v) | ||
| except (OSError, ValueError, KeyError): | ||
| return default |
joelteply
added a commit
that referenced
this pull request
Apr 27, 2026
…Phase 1) (#168) Four field-extract sites for the host's handshake response (ssh_pub, airc_home, identity, reminder) were inline `python3 -c "import sys, json; print(json.load(sys.stdin).get('FIELD',''))"` heredocs. Same class as get_config_val pre-PR #167 — bash variable substitution into python source is a per-callsite silent-fail vector if the embedded value drifts. Now: response JSON via stdin; field name + default via argv. Python source is fixed bytes. ## CLI shape ``` echo "$response" | "$AIRC_PYTHON" -m airc_core.handshake get_field <name> [default] ``` Handles dict / list values via json.dumps so callers can re-parse (needed for the identity field, which is a nested object). ## Test posture - identity: 19/19 - whois: 5/5 - part_persists: 8/8 - list: 4/4 - general_sidecar_default: 12/12 - kick: 12/12 Plus direct CLI unit tests (valid response, missing field with default, nested object round-trip, empty stdin → default, garbage input → default). ## What's left in handshake-related code - Host's response BUILDER (line 3236, builds the JSON payload the joiner reads). Bash-substitutes name + airc_home + identity into python source. Same class. Migrate next. - Joiner's payload BUILDER (line 2580, sends payload TO host). Same pattern; same class. Both are smaller migrations following the same shape.
joelteply
added a commit
that referenced
this pull request
Apr 27, 2026
… heredocs (#152 Phase 1 cleanup) (#169) feat(airc_core): collapse _whois_in_scope + resolve_name + cmd_rename heredocs into get_config_val[_in] (#152 Phase 1) Cleanup pass following PR #167/#168. Eight more inline `python -c` heredocs collapsed into one-line calls now that airc_core.config handles the read pattern. ## Sites migrated 1. **resolve_name** (line 1228) — was duplicating the get_config_val logic inline. Now calls get_config_val. 2. **cmd_rename** (line 3369) — same. 3. **_whois_in_scope** (six sites) — host_name, host_identity, host_target (×2), host_airc_home, peer-file's identity, peer-file's host. All collapsed to get_config_val_in or airc_core.handshake get_field. ## New: get_config_val_in Like get_config_val but reads from an arbitrary config.json path. Used by _whois_in_scope's cross-scope walk (#134) which inspects sibling scope state without changing $CONFIG. Same module, same CLI; just different env var per call. ## airc_core.config: dict round-trip Extended `get` to JSON-encode dict/list values (matches handshake.get_field shape). Lets _whois_in_scope read host_identity + peer identity blobs as JSON-encoded strings that callers can re-parse. ## Test posture - whois: 5/5 - whois_cross_scope: 6/6 ← hottest path through _whois_in_scope - identity: 19/19 - kick: 12/12 - part_persists: 8/8 - list: 4/4 - general_sidecar_default: 12/12 ## Code reduction ~70 lines of inline python heredoc → ~10 lines of bash function calls. Each removed heredoc was a separate silent-fail vector (bash-substituted env var into python source code). ## Phase 1 progress - ✓ iso_to_epoch (Phase 0a) - ✓ config CRUD core (PR #167) - ✓ handshake response parse (PR #168) - ✓ _whois_in_scope + resolve_name + cmd_rename cleanup (this PR) - next: handshake/gist envelope BUILD sites, identity show/set, monitor_formatter
joelteply
added a commit
that referenced
this pull request
Apr 27, 2026
… Phase 1) (#170) The pair-handshake send was an inline `python -c` heredoc with FIVE bash-variable substitutions into the python source — name, host, ssh_pub, sign_pub, airc_home — plus the connect target as `('$peer_host_only', $peer_port)`. Any unusual character in any field could silently break python parsing. Specifically host_ssh_pub may contain a trailing newline (depending on how openssh-keygen wrote the .pub file); host_target may contain characters that need quoting; identity is a JSON-encoded blob of arbitrary user-set text. Each was a per-callsite silent-fail. ## Migration `airc_core.handshake.send(host, port)` reads all six fields from env: MY_NAME, MY_HOST, MY_SSH_PUB, MY_SIGN_PUB, MY_AIRC_HOME, MY_IDENTITY. Builds the JSON payload, opens TCP socket, sends, reads response, returns it as a string. Exceptions surface to stderr (matches the never-swallow-errors rule); bash captures stderr via `2>&1`. Bash callsite shrinks from 23 lines (inline python heredoc) to 8 lines (env-var pass + module call): response=$(MY_NAME="$my_name" \ MY_HOST="$(whoami)@$(get_host)" \ MY_SSH_PUB="$my_ssh_pub" \ MY_SIGN_PUB="$my_sign_pub" \ MY_AIRC_HOME="$AIRC_WRITE_DIR" \ MY_IDENTITY="$my_identity_json" \ "$AIRC_PYTHON" -m airc_core.handshake send "$peer_host_only" "$peer_port" 2>&1) || _pair_ok=0 ## Test posture Pair-handshake exercising scenarios all green: - tabs: 19/19 (two-tab pair on localhost — exercises send + receive) - identity: 19/19 (exchange identity at handshake) - whois: 5/5 (read identity from response) - kick: 12/12 (multi-peer pairing) - part_persists: 8/8 (sidecar + primary spawning) ## Phase 1 progress - ✓ iso_to_epoch (Phase 0a, PR #166) - ✓ config CRUD core (PR #167) - ✓ handshake response parse (PR #168) - ✓ _whois_in_scope cleanup (PR #169) - ✓ joiner handshake send (this PR) - next: host's response builder (line ~3236), self-heal/discovery heredocs, monitor_formatter
joelteply
added a commit
that referenced
this pull request
Apr 27, 2026
…-line migration, biggest single heredoc) (#171) feat(airc_core): monitor_formatter → airc_core.monitor_formatter (#152 Phase 1, biggest single migration) The biggest single heredoc in airc bash. ~250 lines of Python embedded in a `"$AIRC_PYTHON" -u -c '...'` block, complete with apostrophe- escape gymnastics like `caller'\''s` and `Joel'\''s` because bash single-quoting required them. Migrated to a proper Python module. ## Impact airc bash file: **5897 → 5647 lines** (−250 lines, ~4.2% reduction of the entire script). The migrated function had: - Inactivity watchdog (cross-platform: SIGALRM on POSIX, threading.Timer on Windows) - [rename] handler with chain-repair via stable host id - Ping/pong control message handling with auto-pong subprocess.Popen - Own-send filtering with mid-session rename support - Inbound mirror-to-local-log for joiners (avoids feedback loop on hosts) - Belt-and-suspenders error handling per line so one bad message doesn't kill the formatter All preserved verbatim — same logic, same stdin/stdout contract. The CLI shape: PEERS_DIR=<peers-dir> "$AIRC_PYTHON" -u -m airc_core.monitor_formatter <my_name> Bash function shrinks to 4 lines (was 268). ## Why a real .py file matters here The bash heredoc had: - `'\''` shell-escape sequences scattered through comments (caller's → caller'\''s) — readable Python source now restores natural apostrophes. - No editor syntax highlighting for python (it was inside a bash string). - No way to unit-test individual functions (_rename_files, _find_peer_by_host) without invoking the whole bash + airc stack. Now the module is a regular Python file: lints, syntax-highlights, unit-testable, importable from other airc_core modules if needed. ## Test posture 84 assertions pass across 8 scenarios touching monitor_formatter (every scenario that pairs + sends/receives): - tabs: 19/19 (two-tab message exchange) - identity: 19/19 (identity round-trip + rename) - whois: 5/5 (host_identity propagation) - part_persists: 8/8 (sidecar + primary monitor active) - list: 4/4 - general_sidecar_default: 12/12 - kick: 12/12 (multi-peer monitor traffic) - events: 5/5 (system-event formatting) ## Phase 1 progress - ✓ iso_to_epoch (Phase 0a, PR #166) - ✓ config CRUD core (PR #167) - ✓ handshake response parse (PR #168) - ✓ _whois_in_scope cleanup (PR #169) - ✓ joiner handshake send (PR #170) - ✓ monitor_formatter (this PR — biggest single migration) - next: host's pair-handshake handler heredocs, smaller cleanups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing the Python truth-layer migration. PR #166 established the foundation; this is the first big-impact migration.
What
`get_name` + `get_config_val` (45+ callsites) now route through `airc_core.config` Python module via `"$AIRC_PYTHON" -m airc_core.config get `.
Why
Pre-migration each was an inline python heredoc with bash variable substitution into the python source. Continuum-b69f 2026-04-27 traced `host_target` reading empty (even with valid config) to this class of silent-fail. Now python source is fixed bytes; CONFIG comes from env var; key/default come from argv.
Test posture
Plus direct CLI unit tests: valid config, missing config, get_name on valid config — all pass.
Pattern
Each migration in Phase 1 follows this shape: bash function shrinks to a 1-line
"$AIRC_PYTHON" -m airc_core.<module>call; logic lives in a Python module with a CLI entry; integration tests verify identical bash-side behavior.Next: pair handshake JSON build/parse → gist envelope build → resolve → monitor_formatter.