Skip to content

Ask: AI formula button on the edit line (c0mpute) - #3

Merged
ralyodio merged 4 commits into
mainfrom
ask
Nov 30, 2026
Merged

ralyodio merged 4 commits into
mainfrom
ask

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Depends on #2 (cloud). This branch is based on cloud, so until #2 merges GitHub shows #2's commits here too. The Ask work is the last commit (db4bd48).

What it does

Ask for a formula in plain language; models on the c0mpute network write it and the engine checks it before the user sees it. Nothing is written to a cell without the user's Enter.

TUI

  • [Ask] button at the right end of the edit/formula line, plus a Ctrl+K ask hint while editing.
  • Ctrl+K on a selected cell opens the edit line with ? ready for the question.
  • While editing, Ctrl+K or a mouse click on [Ask] asks with the edit buffer (hqtui delivers mouse press events, so the button is clickable).
  • Edit line input starting with ? (e.g. ?sum of B2:B9 plus 8% tax) + Enter (or Tab/arrow commit) asks instead of storing. ? alone in READY still opens help, so you type the question after Enter/F2 or Ctrl+K.
  • Non-blocking: the HTTP call runs on a background thread; the result arrives on a channel polled once per frame. The status line shows asking c0mpute… Ns (Esc cancels) and the button shows [ … ]. Esc cancels and restores the buffer.
  • The answer goes into the edit buffer (uncommitted); the status line shows the explanation and → preview. Enter keeps it, Esc drops it. Errors (402 daily limit with the key/upgrade URL, 422, unreachable server) go to the status line.
  • Added to the ? help screen and the bottom hint (^K ask).

Context sent: sheet name, active cell, used range, the edit buffer, and up to 30 rows x 12 columns of display values around the cell as TSV with column letters and row numbers (plus row 1 as header when the window starts lower). Capped at 8 KB; nothing else from the file.

CLI

sk33p ask "QUESTION" [FILE] [--cell C4] [--sheet S] prints the formula, explanation, preview and model. With FILE it uses the same context builder.

Client: ureq 2 (rustls), SK33P_API (default https://sk33p.pwa.pit.world), key from SK33P_KEY or ~/.config/sk33p/key (none = anonymous quota), 120 s timeout.

Cloud

  • POST /api/v1/ask {question, context?, sheet?, cell?} → {formula, explanation, preview, model, provider}. It is metered like the other tools (one call; 402 with the offer when over the limit).
  • MCP ask tool on /mcp with the same behaviour.
  • @profullstack/ai-providers router built from the C0MPUTE_* variables only, with paidFallback: false, AI_PAID_FALLBACK=off and only: ['c0mpute']. OpenAI and Anthropic are never constructed, even if their keys are in the environment (there is a test for this). There are no openai or Anthropic SDK imports.
  • Validation: each formula is run through the engine (write_cells with the context's cells filled in, or eval when there is no context). If it throws or evaluates to an error value, the error goes back to the model for one retry; if that also fails the endpoint returns 422 with the reason. <think> blocks are stripped, including unclosed ones.
  • The AI call is injectable through Config.ai (tests never touch the network). ASK_DISABLED=1 turns Ask off (503).
  • Docs section, homepage line, llms.txt, pricing card list.
  • Bun.serve idleTimeout goes from 60 to 255 s (Bun's max). Without this, c0mpute answers longer than 60 s would be cut off.

Version bumped to 0.2.0 (release is separate). README documents Ask (keys, CLI, env).

Tests

  • Rust: cargo test --release: 6 passed. New: context builder (small sheet, 30x12 window keeps the header, 8 KB cap), ? prefix parsing, reply parsing (200/402/401/422/non-JSON). There is also a headless TUI flow against a stand-in HTTP server: ?question + Enter, pending state, answer in the buffer and not written, Enter commits; Ctrl+K from READY; Esc cancel; [Ask] click; 402 shown. SK33P_SKIP_NATIVE=1 cargo clippy --all-targets is clean.
  • Cloud: bun test: 18 passed (9 new). They cover the success path with preview from context cells, eval without context, invalid formula → retry → success, error value twice → 422, 402 quota with no model call, no key = anon quota vs keyed free plan, bad input / model down 502 / Ask off 503, MCP ask, answer and context parsing, and the production router being c0mpute-only. Passes with and without the prlimit sandbox.
  • Manual: ran a local cloud server with a mocked AI, then ran sk33p ask ... demo.xlsx --cell D12 and the TUI in tmux (Ctrl+K, question, Enter → asking c0mpute… → =SUM(D2:D6)*1.08 in the edit line with → 3806.9352, Enter commits). The retry path was exercised with a deliberately bad first answer (SUMM → engine error fed back).

Deploy notes

  • Cloud env: C0MPUTE_API_KEY (Infernet account key; without one c0mpute's free tier of 10 queries/day applies). Optional: C0MPUTE_MODELS (default huihui_ai/qwen3.5-abliterated:4b,qwen3:4b), C0MPUTE_TIMEOUT_MS (default 120000), ASK_DISABLED=1.
  • The edge proxy in front of the container must allow ~130 s responses on /api/v1/ask and /mcp.

🤖 Generated with Claude Code

ralyodio and others added 4 commits November 30, 2026 14:40
sk33p.pwa.pit.world. Bun + Hono in front of the release binary: every
call runs a fresh 'sk33p mcp' under prlimit in a scratch dir.

- /api/v1/{eval,read,write,sheets,convert} (JSON base64 files, or raw
  upload for convert), /api/v1/{keys,me,upgrade}, remote MCP at /mcp.
- Plans per UTC day: no key 10 calls, free key 100 (2 MB), Pro 10,000
  (25 MB) at $9 per 30 days; over the limit is a 402 with the next step.
- Pro = CoinPay hosted checkout (any coin or PayPal); signed webhook at
  /hooks/coinpay settles once and extends Pro.
- Pages: home with live formula demo + pricing, /docs (+ /docs.md),
  /key, /upgrade, llms.txt, webring descriptor, webmcp embed, footers.
- Docker: ubuntu 24.04 (release glibc), non-root, read-only, HEALTHCHECK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cache)

Error: could not load cache on every platform when the cache hit: target/
carries ExternalProject stamps but each sub-build's CMakeCache lives in the
engine submodule tree. Cache only the cargo registry and git checkouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TUI: an [Ask] button and "Ctrl+K ask" hint on the edit line. Ctrl+K on a
cell opens the edit line with "?"; Ctrl+K, a click on [Ask], or Enter on a
"?question" asks. The call runs on a background thread (status line shows
"asking c0mpute... Ns", Esc cancels); the answer lands in the edit line,
uncommitted, with its explanation and preview. Enter keeps, Esc drops.
Errors (402 with the upgrade link, 422, transport) go to the status line.

Context sent: sheet, active cell, used range, edit buffer and up to
30x12 display values around the cell (plus the header row), < 8 KB.

CLI: sk33p ask "QUESTION" [FILE] [--cell C4] [--sheet S]. ureq (rustls)
client; SK33P_API (default https://sk33p.pwa.pit.world), SK33P_KEY or
~/.config/sk33p/key, 120 s timeout.

Cloud: POST /api/v1/ask and an MCP ask tool, metered like every tool.
@profullstack/ai-providers built from C0MPUTE_* only with the paid
fallback off, so OpenAI/Anthropic are never constructed. Each formula is
evaluated by the engine (with the context's cells filled in); an error or
error value is fed back for one retry, then 422. <think> blocks stripped.
AI call injectable via Config.ai. Docs, homepage line, llms.txt.
Bun idleTimeout raised to 255 s so long asks are not cut off.

Version 0.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit 266ea73 into main Nov 30, 2026
3 checks passed
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