mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:59:11 +01:00
feat/parallel-implement
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
6ee4cbb858 |
feat(widget): Chat mode — a chat the Cat and Loki both live in (#879)
The widget's Chat tab ships. A visitor on an embedding site asks; whichever of the Cat (earning, getting paid) and Loki (getting things built) the question belongs to answers as itself — both when both have something useful — from the public fleet map, and is sent to the project that fits. - POST /api/widget/chat: fcw_* token + origin allowlist + per-IP/per-token limits, charged to the token owner's fair share of the free AI pool. Links are attached from the map, never typed by the model. When the budget or every vendor refuses it still routes by keyword match (degraded: true). - src/lib/widget-chat/concierge.ts: pure facts/prompt/links/fallback. Retired projects, throwaway names (same pattern as the litter gate, pinned equal) and unwritten not-running projects are not offered; stage words say beta/pilot, never live/client; facts are budgeted to survive free-tier limits. - Chat is OPT-IN per embed (data-fc-modes="chat,report"); the default is now Report alone, because the same bundle runs on pilot sites. The first listed mode opens first. window.Loki.ask(question) lets a host page hand a question over (bitbaum's homepage does). Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> |
||
|
|
d14796ca4a |
fix(widget): the mode chips were unstyled on every customer site (#796)
#734 pasted the .modes / .mode rules into the middle of the .dot rule's declaration block, and left .dot's `background` unterminated. CSS error recovery swallows everything from that declaration to the matching brace, so two things were broken on every site embedding /widget.js: - .dot lost its own `flex: none` and `box-shadow` halo, - .modes, .mode, .mode.on, .mode:disabled and .mode-hint never applied at all, so Report / Chat / Watch rendered as naked 16px text instead of chips. Neither is catchable by tsc — the CSS is a template string. The same rules also carried literal hex fallbacks (#333, #aaa, #f60, #fff, #888) behind var() lookups. The widget's Shadow DOM sets `all: initial` and defines no custom properties, so those var()s could only ever resolve to their fallback: a hardcoded colour wearing a token's clothes. Every colour now interpolates from the boot theme, which is generated from @bitbaum/design-tokens, like the rest of the file. Ratchet, so this class ends here: widget-theme-from-tokens now parses both emitted stylesheets and fails on a nested block inside a plain rule, an unterminated declaration, any var(), and any hex that is not a colour the generated theme supplied. All three faults were proven by mutation. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> |
||
|
|
5d9a942cd7 |
refactor: split the five unreadable functions, then lint against the next one (#733)
* refactor(orchestration): split the 733-line dispatch POST into named steps The POST handler in /api/orchestration/run carried every dispatch path inline: registry resolution, the cloud queue branch, the prompt-queue pop, run tracking, the queued-behind and parallel branches, and the claude / codex+gemini / openclaw executors. Reading it meant holding all of them at once. Each step is now its own named function, and POST reads as the sequence it always was. No behaviour change: same responses, same status codes, same sentinel writes in the same order, same log lines. Two genuine duplicates folded while passing: the project-state description block (claude and codex/gemini derived it identically) and the lifecycle sentinel writes. POST 733 -> 164 lines. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(inject): split injectPrompt into named dispatch steps injectPrompt was one 627-line function carrying the whole dispatch: target resolution, local and remote prompt assembly, run opening, /tmp side effects, the hosted-builder route, the executor call, and the failure and success ledgers. Each is now a named function and injectPrompt reads as the sequence. This path is autopilot-critical, so nothing moved across a boundary: same statuses, same response bodies, same event/audit rows in the same order, same log strings. injectPrompt 627 -> 163 lines (executeAndReport, the post-executor half, is 122). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(control): split the 492-line control GET into named steps The /api/control GET built the whole panel inline: project collection and dedupe, the agent-availability override, ten parallel DB slices, a 256-line per-project map callback, and the response. The card builder alone carried session persistence, run closing, runtime resolution and run serialization. Each is now named: collectControlProjects, resolveRunnerAvailability, loadControlSlices, buildProjectState (with persistSessionHandoff, maybeCloseRunFromHandoff, resolveAgentRuntime, serializeLatestRun) and resolveRunnerLastPushedAt. Same payload, same headers, same log lines, same write ordering. GET 492 -> 128 lines; the per-project builder 256 -> 133. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(widget): split the 1,329-line embed into modules widget/main.ts was one file with a 776-line mount() closure and no exports — the launcher, the element picker, the screenshot strip, the voice control, the stylesheets and the DOM helpers all lived inside it. This is the only surface strangers on other people's sites load, and it earns the same care as src/. It stays a self-contained esbuild bundle (nothing imports from src/), split into siblings: dom, theme, visitor-placement, launcher, picker, attachments, voice-control. main.ts now owns the panel, submit and boot. Same DOM, same order of construction, same copy, same listeners — verified by diffing the string literals of the old and new unbundled builds. Two pins added while the code was moving: - scripts/test/widget-self-contained.ts — every widget module imports only its siblings, every sibling import resolves, and the only document-level CSS is the fcw-* pick highlight. Proven by mutation (an "@/config/brand" import makes it fail). - widget-server-caps-mirror now reads every widget module, not just main.ts, so moving a clamp cannot silently defeat the check. main.ts 1,329 -> 528 lines; mount 776 -> 386. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(control): thin the 665-line ControlPanel into named pieces ControlPanel held the deep-link effect, the runner-presence derivation, the empty state, the Workspaces panel, the launch defaults, four modals and the toast — all inline, between the four-tier comments that explain the page's ordering. Extracted, behaviour unchanged (same DOM, same copy, same props): - useControlDeepLink — /control?focus=&switchTo= navigation handling - deriveRunnerPresence — offline / never-seen / stale, now in the presenter - latestRunSignals — the fleet-pulse outcome pairing - ControlEmptyState, WorkspacesSection, LaunchDefaultsSection, ControlNotices - ControlPanelModals — every overlay in one sibling deriveRunnerPresence is the one piece with real logic in it (the ADDITIVE rollout rule where connected===false is not yet authoritative on its own), so it is now pinned by five cases in the presenter suite — it had none. ControlPanel 665 -> 520 lines; the component function 665 -> 396 (most of which is JSX and the ordering comments that explain it). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(control): split the 412-line useControlData hook The hook did four jobs in one function: snapshot fetching + refresh triggers, the SSE patch fold, the /api/control/stream EventSource, and the five dispatch actions. - applyProjectPatches (lib/control-project-patch.ts) — the fold, now pure - useControlProjectStream — the EventSource and its reconnect - buildControlActions — inject / launch / runWithBrain / runCustomPrompt / saveAgent applyProjectPatches carries three rules a later edit could silently break (match by live tab, leave omitted fields alone, maintain liveTabs case-insensitively) and was untestable inside a useCallback. It now has six cases pinning exactly those. useControlData 412 -> 290 lines; the hook function 412 -> 180. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(shell,system): split the palette and Fleet Doctor CommandPalette (442-line component): the entry list and the filter were two useMemos nobody could test, and the NL composer's two fetch hops were inline. Both moved out — palette-entries.ts (pure) and useCommandComposer — with eight cases pinning the decisions that look arbitrary and get tidied away: projects outrank navigation, recents lead and are not repeated, free text offers Run FIRST, a pending command turns the list into a project picker, and a project with no checkout offers no agent switch. /api/system/doctor GET (328 lines): a flat run of independent probes appending to one array. Each is now a named probe returning its own checks, and GET is the list of them plus summarize(). Same checks, same order, same ids and copy. CommandPalette 442 -> 245; doctor GET 328 -> 33. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * refactor(loki): split the 450-line conversation POST into named turns The Loki chat route answered a turn with eight deterministic fast paths and a classifier path, all inline inside the SSE job — a 450-line closure whose control flow was a column of early `return send(...)`. Each fast path is now a named TurnHandler over one TurnContext, returning a message or null to pass. The classifier half splits into dispatchResolvedCommand / needsProjectReply / chatReply. The chain and its ordering are now a list you can read, and the two "add this project to the thread" patterns collapse into linkProject/linkProjects. Same replies, same meta `source` tags, same ordering, same SSE frames. POST 450 -> 63 lines; the longest piece is chatReply at 84. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 * chore(lint): hold the line on function length Nothing was watching functions grow. Today's rule is a ratchet set just above the worst case that survives the split work above, so the next 700-line handler is an error on the author's machine instead of a surprise in review. Two thresholds, because the halves fail differently. Logic — routes, lib, queries, home/ — is where length hides branching, so 300. A component's length is mostly JSX depth: real, far less dangerous, so 510. Error, not warn: a warning on a repo this size is a number nobody reads. Blank lines and comments are skipped — this codebase comments heavily on purpose and a rule that punished that would push the WHY out of the code. Proven by mutation: a 324-line function under src/lib fails the rule. Also removes fnlen-all.mjs, a measurement scratch file that rode along in the previous commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8 --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> |