8000 refactor: untangle the codebase and refresh its dependencies by aorumbayev · Pull Request #108 · kagan-sh/kagan · GitHub
[go: up one dir, main page]

Skip to content

refactor: untangle the codebase and refresh its dependencies - #108

Merged
aorumbayev merged 261 commits into
mainfrom
refactor/untangle
Nov 9, 2026
Merged

aorumbayev merged 261 commits into
mainfrom
refactor/untangle

Conversation

@aorumbayev
Copy link
Copy Markdown
Member

Untangles the workspace so pieces that change together sit together, refreshes the forks and dependencies, and reworks four parts of the window that confused people.

What changed

Untangle (no behaviour change except the fixes below)

  • One owner per shared fact: thread status rules, preference keys, the 1 MiB text cap, screen limits, the git: source prefix, the typing quiet, preview image caps, agent program names.
  • Core: one run record and one pending-question map per workspace; one git runner; each ThreadOp matched once.
  • Plugins: one typed way to ask a plugin; thread calls built as typed ThreadOp values; host modules registered from tables; the plugin folder layout owned by core.
  • UI: the main Kagan struct split into feature groups; one thread menu for the title bar and the row; one dispatch-then-report helper; one front-window shell.
  • Spec changes (decisions 183 to 192): the Start screen reads its setup script through core; kg_process owns the Unix tree kill; socket-only rules live in dispatch_for; the socket is a Workspace::open parameter; interaction options say which one is safe and which destructive; the keychain belongs to plugins; kg ui shows the web panel hint; plugins own the facts core used to parse.
  • Product Rust: 70,092 → 69,448 lines.

Bugs fixed (each with a test that failed before)

  • A plugin theme id was not checked as a plugin id.
  • A running plugin could stay paused after an early return.
  • A plugin command's error text could show plugin secrets.
  • A notice click did nothing before the plugin host started.
  • A sidebar row's menu acted on the shown thread, not its own row.
  • Nested thread rows pushed their actions past the sidebar edge.
  • The review panicked when a file changed under its diff.
  • The New thread screen could start a program scrolled out of sight.
  • An empty KG_DATA_DIR or HOME was treated as set.
  • Kimi skill folders ignored the Kimi folder override.

Window

  • Thread marks: each state has its own shape and a tooltip, not color alone (decision 195).
  • Bottom strip: each part is a real button; the log sits behind one labeled "Activity log" button (kg window toggle-activity-log); plugin status items can run their own command (decisions 196, 197).
  • New thread screen: pinned form, 8 rows with "N more", one-line folder sentence, keyboard focus rings, Enter starts (decisions 198 to 200).
  • An ended thread offers "New thread here…" to start any program in the same folder (decision 199).

New: a child tells its parent (decision 201). A child started with --parent-thread-id types one line into the parent's program when its turn ends, it asks the person, exits or fails. It waits while the parent is busy or the person has an unsent draft. kg thread run --quiet turns it off.

Rules and docs

  • AGENTS.md order of truth: code and tests, then enforced rules, then docs/. Per-crate AGENTS.md for store, domain, ui, plugins and kg.
  • New checks in CI and pre-push: scripts/decisions-check.sh, scripts/test-env-check.sh.
  • Lints: allow_attributes_without_reason, undocumented_unsafe_blocks. assert_is_empty (new in clippy 1.99) is allowed: its fix reads worse.

Performance and safety

  • The 1 s sweep deletes saved screens only when it releases one; saved screens restore off the main thread; the login-shell PATH is read off the main thread; the diff cache is bounded; detached ops log their failure.
  • The flaky socket test is fixed (pid-keyed temp folders); tests no longer read KG_* or the person's agent folders.

Dependencies

  • Rust 1.99.1.
  • gpui-kit fork: 95 upstream commits merged (52e47a4). gpui-fast fork: 74 upstream commits (v0.1.14) merged, our four Windows crash fixes carried onto upstream's device recovery (9501036). wry already current.
  • rusqlite 0.41 (RUSTSEC-2026-0459); latest patch releases; plain cargo update.

Checked

fmt, clippy -D warnings, 1779 tests, size budget, crate boundaries, glossary, view colors, decisions and test-env checks, pre-push hook test; CI on Linux, macOS and Windows; macOS smoke test.

Needs a person

  • Windows, strip see-through: unproven cause. Open a thread running seq 1 5000 with the VSCodium panel open, open the activity log, screenshot; repeat with GPUI_VIEW_RETENTION=0, then GPUI_SCROLL_LAYERS=0. If either clears it, the bug is in gpui-fast.
  • Windows, gpui-fast: the lost-device and window-procedure-panic paths compile and pass CI but never ran on real hardware. After 5 failed recoveries the window now stays up and stops drawing (upstream crashed).
  • Minimize and Zoom from the menu have no test.
  • Recovery keep-block (workspace/recovery.rs, resume_programs): kept because a killed resume can leave a thread Idle; its mutant stays alive until a test-only Workspace::open hook exists.
  • The Windows GDI leak fix (ui_driver.rs) was checked by reading only.

Paste and browser fill each had a 1 MiB constant, a CLI reader and their
own checks, and the fill rule let a path through over the socket. Domain
now owns TEXT_MAX and one check for both, and the CLI reads --file through
one helper.
valid_theme_choice accepted -a.b-/x, whose plugin half is no valid plugin
id. It now uses PluginId::valid, and the two empty-or-control checks in
check() share one helper.
Three callers had to call before_connect, build the name, then connect, in
that order. Client::open does all three.
String building in the CLI uses write! instead of spelled-out write_fmt,
the path warm-up spawns user_path directly, and the two sends and kills
that may find their peer gone say so.
install now sends UiJob::Op and UiJob::Surface to their own paths, so the
driver functions take UiOp directly and no longer re-check the job kind.
… each

Adds tests for each browser call, scroll and ref checks, the status tones and a
state constructor called without a receiver.
Kimi skills now follow the same folder override as Kimi sessions.
Ids that must match in two places (answer and header focus, body ids,
sidebar row prefixes, the thread and project key contexts, the archived
list test, the quit sentence) now come from one function or constant.
The Dock badge, the next-thread jump and the event refresh filter each
had their own copy of the rule. Attention now owns needs_you and refreshes.
The click sent the thread through the plugin host, so a click made before
the host started did nothing. The window now selects the thread itself.
PluginHostEvent had one variant, so the plugin host no longer emits it and
the type is gone.
# Conflicts:
#	crates/ui/src/kagan/settings/installed.rs
# Conflicts:
#	AGENTS.md
#	Cargo.toml
#	assets/THIRD-PARTY-NOTICES.txt
#	docs/decisions.md
Upstream gpui-kit needs 1.99. Clippy 1.99 adds assert_is_empty, allowed: its fix reads worse than assert!(x.is_empty()).
gpui-kit 52e47a4 (95 upstream commits), gpui-fast 9501036 (74 upstream commits, our 4 Windows crash fixes carried onto upstream's device recovery), wry already current. The ui registry keys a window by its id, since gpui 0.3.12 changed what its text system pointer can tell apart.
The authorizer denies BEGIN, COMMIT, ROLLBACK, SAVEPOINT and their variants in plugin statements. Only COMMIT was tested, so removing the guard left the rest unpinned. The new tests fail when the guard is removed: a plugin ROLLBACK then leaves later statements committed, and a migration can commit its own COMMIT.
The line waited 1.5 seconds after the last key, so a message the person paused in the middle of could be sent with the line stuck to it. Text that does not end in Enter now holds lines for 30 seconds after the last key. Enter drops the hold back to the typing quiet, so a sent message does not delay lines. The test fails on the old 1.5 second hold.
A parent that waited on its child was then typed the child's end again once its own turn ended. A wait or wait-event that returns the child's end now drops the line queued for that end. The cost: the request does not name the waiting thread, so a wait from any thread drops the parent's line for that child. Tests fail when the drop is removed.
The window and core each held a copy of the 1.5 second typing quiet, and only a sentence in decision 201 linked them. Core now owns TYPING_QUIET and the window uses it.
The line put the child's title between quotes into a shell parent as typed input, so a title with quotes or $(...) changed what the parent ran. The line now names the child by id and says where to read it. The test fails on the old line.
Every sweep ran a delete of archived screens once any thread was archived past the grace, and archived threads stay archived, so the delete ran every second in a normal workspace. The sweep now deletes only when it released an ended screen, and app start runs one delete for rows no screen in memory owns. The test fails when the delete runs on every sweep.
The layout save dispatched its preference write and detached the result, so a failure left no trace. It now goes through the logged dispatch that the other controls use. No test: the logged line goes to stderr, and a test would have to capture it.
The rule said tests use an in-memory database, but the schema and reopen tests use a file in a temp folder, and they must.
… names its limit

test-env-check only read files named as tests, so a #[cfg(test)] module inside a product file was not checked. It now scans from that line to the end of the file. The rule also says a read through clap env or a product helper is checked in review, not by the script.
…ows its limit

Three private items had doc comments, which the rule bans. The cache test copied the limit as 64; it now uses MAX_ENTRIES, so the two cannot drift.
The help text said the parent is not told when the child waits. The line is sent when the child asks a question, so the help now says that, and the CLI reference is regenerated to match.
tell() created an empty run for a parent that had none, and kept the entry after the line was dropped. Now a line is queued only for a parent whose program is running. The test removes the parent's run and fails on the old code.
Entries 193, 194 and 198 to 201 had the number alone in bold, so a reader could not scan the titles. Each heading is now **N. Title.** with the entry's first sentence as the title.
The startup delete sat at the end of refresh, which every changed sweep and every thread start also calls, so it ran again after the first load. It now runs once in resume, after the first refresh. The test starts another thread, which refreshes, and fails when the delete runs there.
… Enter

The comment said child lines wait for the typing quiet. Since the draft hold, that is only true after Enter.
@aorumbayev
aorumbayev merged commit 85d2826 into main Nov 9, 2026
19 checks passed
@aorumbayev
aorumbayev deleted the refactor/untangle branch November 9, 2026 18:42
aorumbayev added a commit that referenced this pull request Nov 10, 2026
…109)

Three loose ends from the untangle (#108).

- **Resume test:** a test-only `Workspace::open_with` runs setup before
resume, so a killed resume pass is now tested
(`a_killed_resume_pass_brings_back_a_thread_that_exited_cleanly`, shown
to fail without the keep block). The four restart tests use the homes
map instead of process-wide env vars, and a resume-order flake (equal
`created_at` under the test clock) is fixed.
- **Screenshots off the main thread:** `kg ui screenshot` reads the
window id on the window's thread and runs the capture on the background
executor, on macOS and Windows.
- **One "empty counts as unset" helper** in `kg`.

Skipped: "sidebar rows built twice per frame" was wrong; the second
build runs only on keyboard navigation, not in render.

Checked: fmt, clippy, 1780 tests, all repo checks, macOS smoke.
**Windows** capture compiles only in CI.
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.

1 participant

0