Skip to content

refactor(toplevel): flatten five nested ternaries, drop a shadow import - #13141

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-toplevel
Sep 24, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-toplevel

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Five places in the top-level src/kiro_crew/ modules pick one value out of
three or five choices, and all five spell that as a ternary nested inside a
ternary. A reader has to hold the whole expression in their head to answer
"which arm runs when wait is false?". context_blocks.py is the worst: five
outcomes, four levels deep, indented sixteen columns inside a dict comprehension.

src/kiro_crew/agent_discovery.py spells one decision — "reopen this agent's
spec from the project dir, the passed agents dir, or the kiro home" — three
different ways in one file.

platform_compat.file_lock asks the same question twice. It computes the Windows
lock ceiling with a ternary, then one line later runs an if/elif/else
over the same two conditions to pick which _win_acquire_blocking call to
make. Two spellings of one decision can drift.

src/kiro_crew/history_projection.py has an in-function import os in a method
of a module that already imports os at line 16.

Why it matters

Every one of these sites is on a path someone debugs under pressure — a lock
that will not open, a subagent spawn refused for memory, an agent whose skills
did not load. A nested ternary is where a reader mis-reads the branch order and
fixes the wrong arm. The duplicated condition pair in file_lock is the shape
that ships a bug later: change one chain, forget the other, and the error
message reports a ceiling the code never waited for.

A ternary also hides its arms from the coverage gate. The whole ladder is one
measured statement, so an arm no test ever runs still reads as covered.

What changed (motivation → approach → change)

File Site Was Is
src/kiro_crew/agent_discovery.py agent_skill_globs 3-way nested ternary if/elif/else
src/kiro_crew/agent_discovery.py agent_welcome_message the same choice, still a ternary the same if/elif/else
src/kiro_crew/context_blocks.py measure_prompt 5-way, 4-deep ternary in a dict comprehension a _block_domain(label) helper beside it
src/kiro_crew/platform_compat.py file_lock ceiling ternary plus an identical chain below it one chain that sets ceiling and picks the call
src/kiro_crew/subagent.py check_memory_available 3-way nested ternary if/elif/else
src/kiro_crew/history_projection.py metadata write in-function import os deleted

Every rewrite keeps the same conditions in the same order, so first-match-wins
precedence and short-circuiting are unchanged and no call the original skipped is
now evaluated.

agent_discovery's third spelling, agents_dir or _kiro_agents_dir() in
_all_agent_specs, is left exactly as it is. It is a falsiness test, not an
is not None test, so folding it into the other two would change what a falsy
non-None agents_dir resolves to. Two of three now match; the third differs
for a reason.

The context_blocks site sits inside a dict comprehension, where a statement
chain cannot be written, so it moves into a small module-level helper.
measure_prompt returns the same object it did before, key for key.

The deleted import os re-bound the module-scope os to the same
sys.modules object, so removing it is a no-op for behavior. It is a plain
import X, not a from X import Y. One property does change: the method's
os.write / os.close / os.unlink now read the module global, so
setattr(history_projection, "os", …) would reach them where before it could
not. Nothing in the suite patches that name on this module. The sibling
import tempfile has no module-scope binding and stays.

No keystone security file is reshaped. safety_override.py carries three
ternaries in this module and all three are deliberately left alone.

Backwards compatibility

Compatible: no signature, return type, return value, config key or error message
changes. measure_prompt's dict and check_memory_available's tuple are
identical on every input, verified by running the same probe against
origin/main and this head.

Tests

Flattening turns one measured statement into three to ten, and five of the new
arms turned out to have no test at all — the ternary had been hiding that. Six
tests close the gap, each pinning a real contract rather than a line number:

Test Locks in
TestDomainGrouping (3 tests) in test/metrics/test_context_blocks.py all five domain values from one realistic prompt, and that a recognised block like memory is background because it is none of the four named cases — not because its label went unrecognised
test_a_global_agent_is_reopened_from_the_passed_agents_dir a global-scope winner is reopened from an explicit agents_dir, not the machine's real kiro home; differential, since the spec exists only there
test_file_lock_not_waiting_reports_a_held_lock_as_blocking wait=False raises BlockingIOError, not the stuck-holder OSError — only the first is safe to retry
test_file_lock_names_the_callers_own_timeout_in_the_refusal the refusal names the caller's own ceiling, not the 300s default
test_startup_memory_guard_admits_a_host_with_no_native_reader a host that is neither Linux, macOS nor Windows ADMITS; back-pressure that cannot measure must not refuse every spawn forever

Measured per-file coverage, origin/main versus this head on an identical test
selection, shows no file regressing and three improving:

File main this head
src/kiro_crew/context_blocks.py 104 stmts / 9 missed / 89% 114 / 9 / 90%
src/kiro_crew/agent_discovery.py 544 / 124 / 76% 550 / 120 / 77%
src/kiro_crew/platform_compat.py 3995 / 1206 / 68% 3997 / 1203 / 68%
src/kiro_crew/history_projection.py 837 / 534 / 33% 836 / 534 / 33%

context_blocks.py gains ten measured statements and misses none of them.

The existing tests over the rewritten paths also pass unchanged:
test_context_management_doc.py, test_default_context_admission.py,
test_agent_discovery.py, test_agent_discovery_pathres.py,
test_history_projection_row_shape.py, test_history.py,
test_platform_compat.py, test_flock_compat.py,
test_host_available_memory.py, test_subagent.py, test_subagent_sizing.py
and test_subagent_macos_probe.py — 1750 passed, 26 skipped, 0 failures.

Manual verification

N/A — unit coverage sufficient: the change is behavior-preserving, and
equivalence was checked by running the same probe against a pristine
origin/main worktree and this head and comparing output.

Gates run on the Python 3.12 CI-parity venv, all exit 0:
check_black_formatting, isort --check-only, flake8, mypy (1706 files),
check_subprocess_encoding, check_brand_name, check_harness_parity,
check_comment_history (with a base ref), check_sync_io_in_async,
docs_lint --test, docs-lint.sh, check_per_file_coverage --test,
verify_vendor_manifest.

Seven read-only review agents ran against the diff before this PR opened: one
each on AUTOSDE blocking rules, behavior equivalence, import semantics, the
security keystone and boot path, and comment accuracy, then two adversarial
passes told to refute the clean verdicts. Those last two found the two real
problems this diff now fixes — the newly-measurable uncovered arms, and the
agent_discovery sibling left in ternary form.

Screenshots / video

Why no screenshot: backend-only diff — no file under website/ is touched,
and measure_prompt, which feeds the dashboard's context breakdown, returns the
same object it did before, so nothing rendered changes.

Related Issues

no linked issue: this is a scheduled readability sweep of one module, not a
reported defect.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — no doc change needed: the specs
    that point at this code name measure_prompt, agent_skill_globs and
    project_agents_dir, and all three keep their names and behavior
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and iamwhatever September 23, 2026 18:07
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Make five nested-ternary sites in the top-level src/kiro_crew/ modules read as the first-match-wins chains they are, and spell agent_discovery's repeated directory choice one way where the semantics allow it — so the arms are individually readable and individually measurable.
Not a goal: Changing any behavior, reshaping a keystone security file, unifying the one falsiness-based spelling (agents_dir or _kiro_agents_dir()), touching the safety_override.py ternaries, or sweeping any module other than toplevel.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of e11e8c7c4112b6b6803cda5ce0224a41d7c381cd — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] e11e8c7

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of e11e8c7c4112b6b6803cda5ce0224a41d7c381cd and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e11e8c7

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e11e8c7c4112b6b6803cda5ce0224a41d7c381cd: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of e11e8c7c4112b6b6803cda5ce0224a41d7c381cd — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (10 items) — 10 justified

Intent: make five branch-heavy sites readable and single-spelled so a debugger picks the right arm — a behavior-preserving FIX-shaped refactor, no capability change.

  1. agent_skill_globs spec-dir choice now an if/elif chain, same order — justified
  2. agent_welcome_message same choice, same chain shape — justified
  3. measure_prompt domain grouping moved to private _block_domain, same dict returned — justified
  4. file_lock ceiling and acquire call now picked by one chain instead of two twin chains — justified
  5. check_memory_available host branch flattened, same order — justified
  6. In-function import os deleted; module-global os now patchable there (declared; 0 tests patch it, grepped setattr(.*history_projection) — justified
  7. Three tests pin all five domain values from one prompt — justified
  8. Test pins global-scope agent reopened from the passed agents_dir — justified
  9. Two tests pin file_lock refusal shape: BlockingIOError on wait=False, caller's own timeout in the message — justified
  10. Test pins memory guard admitting a host with no native reader — justified

Checks run: _block_domain has exactly 1 consumer but is a private extraction forced by the dict-comprehension constraint, not generalized surface; grep following_interaction = 2 files (definition + its test), so no second spelling anywhere; remaining nested-ternary siblings (gateway_lock.py:484, cron_history.py:157, cli_commands.py:1634, mcp_core.py:2373, safety_override.py) are outside the declared sweep and the description names the deliberate leave-alones; no test, assertion or comment pinning the opposite behavior is deleted.

[FIRST-PRINCIPLES-REVIEWED] e11e8c7

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed e11e8c7c4112b6b6803cda5ce0224a41d7c381cd — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] e11e8c7

Verdict parsed from the review's SHA-scoped output markers for commit e11e8c7c4112b6b6803cda5ce0224a41d7c381cd.

False positive or not applicable? A repository writer can comment:
/ai-review override fable e11e8c7c4112b6b6803cda5ce0224a41d7c381cd: <one-sentence reason>

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/artifacts.py, src/kiro_crew/dashboard/handlers/artifacts.py, src/kiro_crew/mcp_tools/artifacts.py, src/kiro_crew/validation.py, test/test_artifact_comment_forward_filter.py since this head went green (2672a2a -> a118ae7); CI re-running.

The rebase is what clears the previous head's Backend Lint & Type Check (3.12) red, and no code changed to do it — git patch-id is byte-identical across the rebase (95134db7bc3b).

Attribution of the four reds on 2287c6776b:

Red Cause Action
Backend Lint & Type Check (3.12) — black gate FAILED: 0 new offender(s), 1 graduated entr(y/ies) on test/test_knowledge.py Stale base. #13151 pruned that entry from .github/black-baseline.txt after this head's run; graduated = baseline - unformatted is baseline-wide, not diff-scoped, so a branch behind that prune reds on a file it never touches. Fixed by the rebase. Gate now exits 0 locally.
Backend Tests (macOS) (1) — test_a_failed_sidecar_staging_leaks_no_descriptor FileNotFoundError: '/proc/self/fd' Main bug, not this diff. The test is guarded skipif(not platform_compat.IS_POSIX) but its body reads the Linux-only /proc/self/fd; darwin is POSIX, so the guard admits it and the body fails. Its sibling two tests above uses the correct skipif(not os.path.isdir("/proc/self/fd")). Landed today in b4238b2 (#12797); test/test_chat_threads.py is untouched here. Filed separately.
Backend Tests (macOS) (2) — test_pdf_extract.py::TestBound::test_the_child_itself_exits_with_the_memory_report_under_the_profile Known main red, already tracked: #13095. Tracked.
Backend Tests (Windows) (4) — test_diag_procs.py::test_an_unchanged_process_still_gets_its_rate, assert 47.478871902002815 == 50.0 ± 1 Wall-clock CPU-rate sampling under runner load. Nothing in this diff reaches diag/procs sampling. Re-run only; no assertion touched.

Gates re-run green on the rebased head (eaf43fcdd8): flake8, isort --check-only, mypy, check_black_formatting.py, check_brand_name.py, check_harness_parity.py, docs_lint.py --test, docs-lint.sh, check_per_file_coverage.py --test, verify_vendor_manifest.py — all exit 0. Scoped tests: 410 passed.

The simplification detector re-scan after the rebase reports 0 actionable sites in toplevel and 3 correctly excluded as keystone (safety_override.py), so the rebase introduced no new sites.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 23, 2026
@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from eaf43fc to 33da02f Compare September 23, 2026 23:53
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved 13 commits since the last head went green (a118ae76 -> f1f891bf), one of which — c7596c8, perf(agents): share the agents-dir revision memo with the KAS session start (#13067) — touches src/kiro_crew/agent_discovery.py, a file this diff also edits. A same-file move is the case where a stale green can hide a real conflict, so this re-sync is a measurement, not a formality. CI re-running on 33da02fb83.

Still no code change: git patch-id is identical across both rebases (95134db7bc3b). The two flattened sites in agent_discovery.py sit in agent_skill_globs and agent_welcome_message; #13067 changed neither, and both rewrites still preserve is not None rather than truthiness, so an agents_dir of Path("") resolves the same way it did before.

Gates on 33da02fb83 — all exit 0: flake8, isort --check-only, mypy, check_black_formatting.py, check_brand_name.py, check_harness_parity.py, docs_lint.py --test, docs-lint.sh, check_per_file_coverage.py --test, verify_vendor_manifest.py.

Tests. The scoped runner selects 681 files here, because platform_compat.py is a hub: 48287 passed, 8 failed. All 8 attributed to this host, none to this diff, by running the same set in isolation against pristine origin/main (f1f891bf) and comparing failure sets rather than counts:

Tests Branch, in isolation Pristine main, in isolation Verdict
test_cli.py::TestDoctorStt (2) fail fail host is missing the optional amazon-transcribe dependency
test_pdf_extract.py (4), test_file_grep.py::TestDocumentPass (2) pass pass load-induced under the 681-file run; they pass on both trees in isolation

The two remaining CI reds on the previous head were the same two deterministic macOS failures, reproduced identically on two independent heads, both tracked and neither reachable from this diff:

Fixing either would mean editing a file outside the toplevel module this PR sweeps, which is the "while I'm here" widening the campaign forbids; both are recorded against their own issues instead.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Sep 23, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 3) on 33da02fb83 is a runner flake, re-run rather than patched.

FAILED test/test_dashboard_server_startup_coverage.py::TestReserveDashboardPort::test_bind_once_matches_kernel_listener_posture
  OSError: [Errno 99] Cannot assign requested address

EADDRNOTAVAIL on a bind() is the runner declining an address, not a wrong answer from the code under test. Three things place it outside this diff:

  • Shard 3 passed on both earlier heads of this same patch (2287c6776b, eaf43fcdd8); git patch-id is identical across all three (95134db7bc3b), so the code the shard ran is byte-for-byte what it passed on twice.
  • This diff touches no socket, port-reservation or dashboard path. Its five files are agent_discovery.py, context_blocks.py, history_projection.py, platform_compat.py and subagent.py; the only platform_compat.py hunk is inside the Windows file_lock branch, which does not execute on a Linux shard.
  • Coverage Gate is downstream of the shard — one failure reported twice, not two.

Re-ran that one job only (gh run rerun 35935827900 --failed), no assertion touched and no rerun added to the suite. The macOS Tests run is a separate workflow run that was still in flight, so the targeted rerun left it alone rather than cancelling it.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 3) failed twice on 33da02fb83, so it is not a coin-flip flake — but it is not this diff either. It is a main break this PR's second rebase landed on top of.

FAILED test/test_dashboard_server_startup_coverage.py::TestReserveDashboardPort::test_bind_once_matches_kernel_listener_posture
  OSError: [Errno 99] Cannot assign requested address

test_bind_once_matches_kernel_listener_posture was added by f1f891b, feat(apps): inject gateway origin into backends (#6599) — which is exactly the main tip this branch rebased onto. It binds ::1 behind a socket.has_ipv6 guard, and socket.has_ipv6 reports whether Python was built with IPv6, not whether the host has a usable IPv6 loopback; the CodeBuild Linux container has none, so the bind returns EADDRNOTAVAIL. Already filed independently as #13229.

That explains the timeline exactly: shard 3 was green on both earlier heads (2287c6776b, eaf43fcdd8), whose bases predate that commit, and git patch-id is identical across all three heads (95134db7bc3b) — the code this shard ran is byte-for-byte what it passed on twice. Coverage Gate is downstream of the shard, one failure reported twice.

Every red on this head is main's, and all three are tracked:

Check Cause Issue
Backend Tests (3.12, 3) + Coverage Gate ::1 bind guarded on socket.has_ipv6; no IPv6 loopback in the CodeBuild container #13229
macOS Tests (1) test_a_failed_sidecar_staging_leaks_no_descriptor guarded on IS_POSIX but reads the Linux-only /proc/self/fd #13199
macOS Tests (2) test_pdf_extract TestBound memory-report expectation on darwin #13095
PR Readiness aggregate of the above —

Worth recording for whoever picks this up: the previous head eaf43fcdd8 reached aggregate readiness: pass with only the two macOS reds. The re-sync onto f1f891bf was justified — main had touched agent_discovery.py, a file this diff edits — but it traded a passing readiness for a newer main break.

Not fixing any of the three here. Each lives outside the toplevel module this PR sweeps, so patching them would be the "while I'm here" widening the simplification campaign forbids, and #13229's guard fix belongs with the commit that introduced it. No test was weakened, no assertion relaxed, no rerun added.

PR Readiness cannot go green until #13229 is fixed on main. The diff itself is unchanged and gated green locally: flake8, isort, mypy, check_black_formatting.py, check_brand_name.py, check_harness_parity.py, docs_lint.py --test, docs-lint.sh, check_per_file_coverage.py --test, verify_vendor_manifest.py all exit 0, and all four review lanes (Design, First Principles, GPT 5.6, Opus 5) are PASS on this head with zero findings.

@bolichen97
bolichen97 enabled auto-merge (squash) September 24, 2026 08:20
@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from 33da02f to 4971a91 Compare September 24, 2026 12:40
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 24, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in 142 files this PR also touches since this head went green
(f1f891b -> 2077450); CI re-running.

The diff is byte-identical after the rebase — one commit, same five production
files, same hunks. All gates re-run green on the Python 3.12 CI-parity venv:
flake8, isort --check-only, mypy, check_black_formatting,
check_subprocess_encoding, check_brand_name, check_harness_parity,
docs_lint --test, docs-lint.sh, check_per_file_coverage --test,
verify_vendor_manifest, and the 684-file scoped backend related set.

Why the previous head's three test reds needed no code change here. Each is a
tracked main failure in a file this diff does not touch:

Red Cause Tracked as
Backend Tests (3.12, 3) — test_bind_once_matches_kernel_listener_posture binds ::1 on a runner with no IPv6 loopback (Errno 99) #13226 / #13229 — fixed on main, so this rebase carries the fix
Backend Tests (macOS) (1) — test_a_failed_sidecar_staging_leaks_no_descriptor guarded on IS_POSIX but reads the Linux-only /proc/self/fd #13199, open
Backend Tests (macOS) (2) — test_pdf_extract TestBound memory report on darwin the RSS watchdog answers rss before PdfminerException #13095, open

Coverage Gate and PR Readiness were derivative of the shard-3 red, not
separate failures.

Attribution was measured, not assumed: the eight failures in the local scoped run
were re-run in isolation against a pristine origin/main worktree with its own
PYTHONPATH. The failure sets are identical on both sides — two
TestDoctorStt cases that need an optional amazon-transcribe extra this venv
does not carry — and the six pdf_extract / file_grep reds pass in isolation on
both, so they are this host's memory pressure under -n auto. Zero
branch-only failures.

One site is deliberately left out of scope: src/kiro_crew/cli_commands.py:1634
gained a chained ternary from a commit merged while this PR was open. Adding it is
not one of the four reasons to push onto an open PR, and widening a
behavior-preserving sweep mid-review re-arms every lane on a diff nobody asked to
grow. It belongs to the next sweep of this module.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (Windows) (4) red on this head is a wall-clock race in a test
this diff does not touch, so it got that one job re-run rather than a code change.

test/test_session_pool.py::TestFillWarmPool::test_cancelled_error_cleans_up_via_finally
asserts that _sync_kill_provider ran. The production code dispatches that kill
fire-and-forget to the subprocess executor — a cancellation handler can neither
await nor block the loop — so the test polls for it:

for _ in range(100):
    if mock_kill.call_count:
        break
    await asyncio.sleep(0.01)
mock_kill.assert_called_once_with(provider)

That is a 1-second budget for a worker thread to be scheduled. Actual: not called. is the budget expiring, not the kill being skipped. A loaded Windows
runner misses a 1 s thread-scheduling window; the same shard and the other seven
Windows shards passed on this same head.

Nothing in this diff can reach that path. Of the five production files, only
platform_compat.file_lock has a Windows branch, and its change moves the
ceiling assignment into the three branches that already existed — same
conditions, same order, same _win_acquire_blocking calls. ceiling is read on
exactly one line, to format the timeout message in a refusal, so it cannot
influence when an executor thread runs. Re-run only, per the no-rerun-as-a-fix
rule: the assertion is correct and stays as it is.

Worth a tracked issue on its own merits — the budget is wall-clock rather than an
awaited signal, which is the shape that reds a shard at random — but that is a
change to a file outside this PR's module and does not belong in a
behavior-preserving sweep.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
Five chained-ternary expressions in four top-level modules read as nested
expressions where the code is a plain first-match-wins chain. Each becomes
an if/elif/else with the same conditions in the same order, so precedence
and short-circuiting are unchanged and no call the original skipped is now
evaluated.

agent_discovery spelled one directory choice three ways. Both `is not None`
spellings — in agent_skill_globs and agent_welcome_message — now read
identically. The third, `agents_dir or _kiro_agents_dir()` in
_all_agent_specs, is a FALSINESS test and is deliberately left alone:
folding it in would change what a falsy non-None agents_dir resolves to.

context_blocks.measure_prompt's four-deep domain ternary sits inside a dict
comprehension, where a statement chain is not expressible, so it moves to a
_block_domain helper beside it. measure_prompt's output is unchanged.

platform_compat.file_lock computed its Windows timeout ceiling with a
ternary over the same if/elif/else that chose the acquire call one line
later. The two chains merge into one, so the condition is spelled once.

history_projection drops an in-function `import os` that re-binds the
module-scope import from line 16. The sibling `import tempfile` has no
module-scope binding and stays.

Flattening makes each arm its own measured statement, and five arms turned
out to have had no test. Six tests cover them, so no touched file's
coverage regresses: the five domains of measure_prompt, a global-scope
agent reopened from an explicit agents_dir, the Windows not-waiting and
explicit-timeout lock refusals, and a host with no native memory reader.

No behavior change; no keystone file reshaped.
@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from 4971a91 to e11e8c7 Compare September 24, 2026 13:36
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/chat_runner.py,
test/test_chat_agent_selection.py, test/test_chat_runner_coverage.py and
test/test_eager_spawn.py since this head went green
(2077450 -> ad164a7); CI re-running.

The overlap is import-level only — none of the five production files this PR
edits was modified by that commit, and the diff is byte-identical across both
rebases. The four overlapping test files plus this PR's own four run green
(888 passed), and every gate re-ran at exit 0 on the Python 3.12 CI-parity venv,
including mypy over 1708 source files.

This is the second re-sync on this PR. The previous head reached
readiness: passed with all 96 checks green and zero findings from any lane, so
this push is only about measuring that green against today's base.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Sep 24, 2026
@bolichen97
bolichen97 merged commit 2c51c95 into main Sep 24, 2026
96 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-toplevel branch September 24, 2026 16:11
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 24, 2026
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…rt (kirodotdev#13141)

Five chained-ternary expressions in four top-level modules read as nested
expressions where the code is a plain first-match-wins chain. Each becomes
an if/elif/else with the same conditions in the same order, so precedence
and short-circuiting are unchanged and no call the original skipped is now
evaluated.

agent_discovery spelled one directory choice three ways. Both `is not None`
spellings — in agent_skill_globs and agent_welcome_message — now read
identically. The third, `agents_dir or _kiro_agents_dir()` in
_all_agent_specs, is a FALSINESS test and is deliberately left alone:
folding it in would change what a falsy non-None agents_dir resolves to.

context_blocks.measure_prompt's four-deep domain ternary sits inside a dict
comprehension, where a statement chain is not expressible, so it moves to a
_block_domain helper beside it. measure_prompt's output is unchanged.

platform_compat.file_lock computed its Windows timeout ceiling with a
ternary over the same if/elif/else that chose the acquire call one line
later. The two chains merge into one, so the condition is spelled once.

history_projection drops an in-function `import os` that re-binds the
module-scope import from line 16. The sibling `import tempfile` has no
module-scope binding and stays.

Flattening makes each arm its own measured statement, and five arms turned
out to have had no test. Six tests cover them, so no touched file's
coverage regresses: the five domains of measure_prompt, a global-scope
agent reopened from an explicit agents_dir, the Windows not-waiting and
explicit-timeout lock refusals, and a host with no native memory reader.

No behavior change; no keystone file reshaped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants