diff --git a/CHANGELOG.md b/CHANGELOG.md index 165d99f..938ffcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,12 @@ All notable changes to LLeMbas CLI. The format follows and `/decide` said "/trust creates it", and it did not — and says `/reload` loads the project's config (it said to restart). - A command that could not be started says why instead of "stopped (SIGTERM)". +- **One name for the server.** Texts said "LLeMbas instance" in some places and "LLeMbas server" + in others — one screen used both — and still spoke of 1.x's "connections" and "webui + connections". They now say "LLeMbas server" and "sign-in"; `lembas logout [name]`. "Forge" is + gone from what a person reads. `lembas remote --help` lists `files_that_run_code` in its JSON. +- A folder named like `..cache` in the project is shown relative to the project in the prompt, + in approvals and in the editor, as any other folder. - **In a LLeMbas terminal an answer is bound to the approval it was given for.** What the display asks now carries a short id (`approval yn #k3f9 …`); `/approve #k3f9`, `/always`, `/deny` and `/answer` with an id decide only that approval or question, and an answer meant for one that diff --git a/SECURITY.md b/SECURITY.md index e3b8919..cb37a6e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -54,4 +54,4 @@ ssh-keygen -Y verify -f allowed -I lembas-release -n lembas-release -s SHA256SUM sha256sum -c --ignore-missing SHA256SUMS ``` -Tags and commits are signed too (SSH signatures, shown as verified on the forge). +Tags and commits are signed too (SSH signatures, shown as verified where the repository is hosted). diff --git a/harness/conformance/paths.json b/harness/conformance/paths.json index fe29d48..437a062 100644 --- a/harness/conformance/paths.json +++ b/harness/conformance/paths.json @@ -156,6 +156,16 @@ "path": "/srv/apple", "dir": "/srv/app/", "expect": false + }, + { + "about": "Spec 3.15.0: a directory named ..cache under the root is under it — said relative to the root, like any other (one answer to \"inside\", `within`).", + "op": "env", + "root": "/home/ada/src/app", + "started": "/home/ada/src/app/..cache", + "expect": [ + "Project: app (paths are relative to its root)", + "Started in: ..cache (relative to the project root)" + ] } ] } diff --git a/harness/prompts/blocks/workspace.md b/harness/prompts/blocks/workspace.md index 75f6593..47d64b2 100644 --- a/harness/prompts/blocks/workspace.md +++ b/harness/prompts/blocks/workspace.md @@ -2,8 +2,8 @@ # Files - You work in the user's file system, through the file tools. Relative paths start at {{start}}; absolute paths start at `/`. - What this session can reach, and how: {{view}}. Nothing else exists here. A path below one of these is reached by its full path; a directory above one that is not itself listed cannot be listed, read or written. -- A listing ends a directory with `/`, marks a repository mounted from a forge `[mount]`, and an entry you can read but not change `[read-only]`. -- Read-only means read but not changed. Stage means changes are kept in this session and, in a repository, not committed. Commit means that, in a repository, the changes may also be committed and pushed to the forge. +- A listing ends a directory with `/`, marks a repository mounted from a Git server `[mount]`, and an entry you can read but not change `[read-only]`. +- Read-only means read but not changed. Stage means changes are kept in this session and, in a repository, not committed. Commit means that, in a repository, the changes may also be committed and pushed to its Git server. - {{repositories}} - Deleting moves a file to the trash, from which the user can restore it. Still, delete only what you were asked to, or what you made yourself. - {{show}} diff --git a/schema/config.schema.json b/schema/config.schema.json index 8f33054..9d4040a 100644 --- a/schema/config.schema.json +++ b/schema/config.schema.json @@ -306,7 +306,7 @@ "type": "object", "properties": { "order": { - "description": "Providers to try, in order; the first that answers wins. Default: those configured (webui first), then ddg. webui: the LLeMbas instance's own search.", + "description": "Providers to try, in order; the first that answers wins. Default: those configured (webui first), then ddg. webui: the LLeMbas server's own search.", "type": "array", "items": { "type": "string", @@ -400,18 +400,18 @@ "additionalProperties": false }, "webui": { - "description": "Search through a LLeMbas instance: its provider, its settings, its keys.", + "description": "Search through the LLeMbas server: its provider, its settings, its keys.", "type": "object", "properties": { "connection": { - "description": "Which webui connection (default: the only one there is).", + "description": "Which sign-in (default: the only one there is).", "type": "string" } }, "additionalProperties": false }, "fetch": { - "description": "How web_fetch reads a page: here, through Firecrawl's scrape, or through the LLeMbas instance.", + "description": "How web_fetch reads a page: here, through Firecrawl's scrape, or through the LLeMbas server.", "type": "string", "enum": [ "local", @@ -430,7 +430,7 @@ "type": "object", "properties": { "provider": { - "description": "openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas instance's.", + "description": "openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas server's.", "type": "string", "enum": [ "openai", @@ -464,7 +464,7 @@ "exclusiveMinimum": 0 }, "connection": { - "description": "webui: which webui connection (default: the only one there is).", + "description": "webui: which sign-in (default: the only one there is).", "type": "string" }, "model": { @@ -482,7 +482,7 @@ "type": "object", "properties": { "provider": { - "description": "openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas instance's.", + "description": "openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas server's.", "type": "string", "enum": [ "openai", @@ -516,7 +516,7 @@ "exclusiveMinimum": 0 }, "connection": { - "description": "webui: which webui connection (default: the only one there is).", + "description": "webui: which sign-in (default: the only one there is).", "type": "string" }, "model": { @@ -539,7 +539,7 @@ "type": "object", "properties": { "provider": { - "description": "openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas instance's, in the account's voice.", + "description": "openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas server's, in the account's voice.", "type": "string", "enum": [ "openai", @@ -574,7 +574,7 @@ "exclusiveMinimum": 0 }, "connection": { - "description": "webui: which webui connection (default: the only one there is).", + "description": "webui: which sign-in (default: the only one there is).", "type": "string" }, "model": { @@ -600,7 +600,7 @@ "type": "object", "properties": { "provider": { - "description": "openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas instance's, in the account's voice.", + "description": "openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas server's, in the account's voice.", "type": "string", "enum": [ "openai", @@ -635,7 +635,7 @@ "exclusiveMinimum": 0 }, "connection": { - "description": "webui: which webui connection (default: the only one there is).", + "description": "webui: which sign-in (default: the only one there is).", "type": "string" }, "model": { @@ -1004,7 +1004,7 @@ "description": "github or gitea (Forgejo too): their releases API. static: any web directory with files `stable` and `beta` naming a tag, and the assets under /." }, "url": { - "description": "gitea: the forge (https://git.example.org). github: the API (default https://api.github.com). static: the directory.", + "description": "gitea: the address of the Gitea server (https://git.example.org). github: the API (default https://api.github.com). static: the directory.", "type": "string" }, "repo": { @@ -1071,11 +1071,11 @@ ] }, "remote": { - "description": "Global config only. What a LLeMbas instance may ask of this machine over the link: the device decides, never the server.", + "description": "Global config only. What the LLeMbas server may ask of this machine over the link: the device decides, never the server.", "type": "object", "properties": { "enabled": { - "description": "Accept work from a LLeMbas instance this machine is logged in to (lembas service). Default false.", + "description": "Accept work from the LLeMbas server this machine is signed in to (lembas service). Default false.", "type": "boolean" }, "roots": { @@ -1110,7 +1110,7 @@ "type": "boolean" }, "scheduled": { - "description": "Accept scheduled work (harness acp.md, spec 3.5.0): let your schedules on the LLeMbas instance run here as agent turns, in the folders remote work may use, in the schedule's mode (Edit unless it says Auto) lowered to max_mode. Default false. lembas service scheduled on|off.", + "description": "Accept scheduled work (harness acp.md, spec 3.5.0): let your schedules on the LLeMbas server run here as agent turns, in the folders remote work may use, in the schedule's mode (Edit unless it says Auto) lowered to max_mode. Default false. lembas service scheduled on|off.", "type": "boolean" }, "files_that_run_code": { diff --git a/schema/connections.schema.json b/schema/connections.schema.json index 3a8908d..a351bd1 100644 --- a/schema/connections.schema.json +++ b/schema/connections.schema.json @@ -15,7 +15,7 @@ "type": { "type": "string", "const": "webui", - "description": "A LLeMbas instance: its models, their settings, its voice and its web search." + "description": "A LLeMbas server: its models, their settings, its voice and its web search." }, "url": { "type": "string", diff --git a/src/acp/agent.ts b/src/acp/agent.ts index 0728a3e..e0ec55e 100644 --- a/src/acp/agent.ts +++ b/src/acp/agent.ts @@ -13,6 +13,7 @@ // block: a directory outside `roots` is refused, a mode beyond `max_mode` is lowered to it, an // untrusted project is refused, and an approval nobody answers in time is a denial. The hardline // applies in every mode, as everywhere. +import { clampMode, MODE_RANK } from "../permission/modes.ts" import { within } from "../within.ts" import { closeSync, existsSync, fstatSync, openSync, readdirSync, readSync, statSync } from "node:fs" import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path" @@ -183,10 +184,7 @@ export function effortOf(v: unknown): Level | undefined { return isLevel(v) ? v : undefined } -const MODE_RANK: Record = { auto: 0, edit: 1, manual: 2, plan: 3 } -export function clampMode(wanted: Mode, max: Mode): Mode { - return MODE_RANK[wanted] < MODE_RANK[max] ? max : wanted -} +export { clampMode } export function underRoots(dir: string, roots: string[]): boolean { // Symlinks followed (realPath), so a link inside a root that points out of it is outside. diff --git a/src/acp/complete_context.ts b/src/acp/complete_context.ts index 7dd89e8..d2e6534 100644 --- a/src/acp/complete_context.ts +++ b/src/acp/complete_context.ts @@ -7,6 +7,7 @@ // from cached file summaries (preferring unsaved open buffers sent by the editor), returning // compact declarations/excerpts in a deterministic session order so KV-cache prefill hits // stay warm across keystrokes. +import { relativeWithin } from "../within.ts" import { readFileSync, statSync } from "node:fs" import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path" import type { FileIndex } from "../project/files.ts" @@ -273,8 +274,7 @@ export class CompletionContext { private relOf(root: string, filePath?: string): string { if (!filePath) return "" if (!isAbsolute(filePath)) return filePath.replace(/\\/g, "/") - const rel = relative(root, resolve(filePath)).replace(/\\/g, "/") - return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel : "" + return relativeWithin(resolve(filePath), resolve(root)) ?? "" } private readCached(root: string, rel: string): CachedFile | undefined { diff --git a/src/acp/editor.ts b/src/acp/editor.ts index 70ffae6..c5cfeff 100644 --- a/src/acp/editor.ts +++ b/src/acp/editor.ts @@ -5,6 +5,7 @@ // // Neither autocomplete nor a rewrite runs a tool or reads the disk: they see what the client sent. // What a model answers is text for the client to insert or to show as a diff — never run here. +import { relativeWithin } from "../within.ts" import { isAbsolute, relative, resolve } from "node:path" import { LOOP } from "../harness.ts" import { apiCall, LembasError, type ServedModel } from "../lembas/client.ts" @@ -413,8 +414,7 @@ function saidPath(p: unknown, root: string): string | undefined { const clean = oneLine(p).replace(/[<>]/g, "").trim().slice(0, 1000) if (!clean) return undefined if (!isAbsolute(clean)) return clean - const rel = relative(root, resolve(clean)) - return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel : clean + return relativeWithin(resolve(clean), resolve(root)) || clean } /** Text of a file's or a tool's own inside the block: it cannot close the block or the selection diff --git a/src/acp/link.ts b/src/acp/link.ts index 6127195..8f6efc9 100644 --- a/src/acp/link.ts +++ b/src/acp/link.ts @@ -95,7 +95,7 @@ export function pickInstance(name?: string): Instance { return one } const list = Object.values(all) - if (!list.length) throw new LinkError("not logged in to any LLeMbas instance — lembas login
", "not_logged_in") + if (!list.length) throw new LinkError("not signed in to a LLeMbas server — lembas login
", "not_logged_in") if (list.length > 1) throw new LinkError(`logged in to several instances; name one: ${Object.keys(all).join(", ")}`, "not_logged_in") return list[0]! } @@ -187,7 +187,7 @@ type Outcome = * `roots: []` and can tell a device that allows no folder yet from one that is not running, and a * `lembas remote add` or `enable` makes it serve, without a restart. */ export async function runLink(o: LinkOptions = {}): Promise { - const local = refusedLocally("the link to a LLeMbas instance (lembas service, /remote)") + const local = refusedLocally("the link to the LLeMbas server (lembas service, /remote)") if (local) throw new LinkError(local, "disabled") const limits = limitsFromConfig({ sharedOnly: o.sharedOnly }) const poll = o.pollMs ?? 2000 diff --git a/src/acp/scheduled.ts b/src/acp/scheduled.ts index b44a14d..40a5432 100644 --- a/src/acp/scheduled.ts +++ b/src/acp/scheduled.ts @@ -3,6 +3,7 @@ // device decides whether (Accept scheduled work, `remote.scheduled`) and how far (the schedule's // mode, never wider than Edit unless it says Auto, lowered to remote.max_mode). The pure rules are // here, run by the conformance areas `scheduled`, `silent` and `monitor`; agent.ts wires them in. +import { clampMode } from "../permission/modes.ts" import { trackGroup } from "../shutdown.ts" import { spawn } from "node:child_process" import { createHash } from "node:crypto" @@ -18,9 +19,6 @@ import type { Message } from "../provider/types.ts" export const SCHEDULED = LOOP.scheduled -const RANK: Record = { auto: 0, edit: 1, manual: 2, plan: 3 } -/** A mode lowered to `max` (agent.ts clampMode, kept here so neither imports the other). */ -const clampMode = (wanted: Mode, max: Mode): Mode => (RANK[wanted] < RANK[max] ? max : wanted) /** Why a scheduled request is refused: `data.reason` of the -32602. */ export type Refusal = "scheduled_off" | "plan" | "folder" | "permission" diff --git a/src/acp/share.ts b/src/acp/share.ts index b605f2b..88b9feb 100644 --- a/src/acp/share.ts +++ b/src/acp/share.ts @@ -353,7 +353,7 @@ export class Share { const local = refusedLocally("/remote") if (local) return local const { instances } = await import("../lembas/login.ts") - if (!Object.keys(instances()).length) return "not logged in to a LLeMbas instance — /login first" + if (!Object.keys(instances()).length) return "not signed in to a LLeMbas server — /login first" const hub = new Hub({ service: false, limits: limitsFromConfig() }) if (!(await hub.listen())) return (await this.connect()) ? undefined : "something holds the hub's socket but does not answer" const stop = new AbortController() diff --git a/src/app.ts b/src/app.ts index b6e9610..0d0e122 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,6 @@ // Wiring shared by every front end: load config, find the project, resolve the model, and build // an Engine. The TUI and `run` both start here. +import { stricterMode } from "./permission/modes.ts" import { existsSync, mkdirSync, readFileSync } from "node:fs" import { join, relative } from "node:path" import { capacityRefusal, capacityBeside } from "./session/capacity.ts" @@ -273,10 +274,7 @@ const PENDING_META = "terminal_pending" /** session_meta: the command the agent placed at the person's prompt that was not seen run or dismissed. */ const PLACED_META = "terminal_placed" -const MODE_RANK: Record = { auto: 0, edit: 1, manual: 2, plan: 3 } -export function stricterMode(a: Mode | undefined, b: Mode): Mode { - return a !== undefined && MODE_RANK[a] > MODE_RANK[b] ? a : b -} +export { stricterMode } export function createApp(o: AppOptions): App { const project = findProject(o.cwd) diff --git a/src/cli.ts b/src/cli.ts index b6868cd..3a6781b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -52,27 +52,27 @@ Usage: lembas config schema [--link] write JSON Schemas for editors (--link: point the files at them) lembas login [address] [--ca file] [--default] [--keep-services] [--json] - sign in to a LLeMbas instance: its models, voice and search + sign in to a LLeMbas server: its models, voice and search (again: read them now; --default pins its default model; --json: one JSON object per line, for a program to read) … | lembas login --token-stdin --server [--ca file] [--json] sign in with a token a program already holds (lmb_…, read from stdin only), checked against the server first - lembas logout [connection] sign out of one, and remove what login wrote + lembas logout [name] sign out, and remove what login wrote lembas serve --stdio an ACP agent on stdin/stdout, for an editor that speaks ACP lembas service install | uninstall | status | logs [-f] | run - work from a LLeMbas instance as a background service (remote:) + work from the LLeMbas server as a background service (remote:) lembas service scheduled [on|off] Accept scheduled work: your schedules may run here as agent turns (remote.scheduled, off by default) lembas remote list | add … | remove … | enable | disable | mode | terminal | scheduled | files-that-run-code [--json] - what the instance may do here (remote:): the directories it may + what the server may do here (remote:): the directories it may work in (add turns remote work on), the most permissive mode, terminals; a running service applies a change within seconds (--json: one object, {enabled, roots, max_mode, terminal, - scheduled}) + scheduled, files_that_run_code}) lembas mcp [list] connect the MCP servers and list their tools and prompts lembas mcp auth sign in to a remote MCP server (OAuth) lembas mcp logout forget a server's stored sign-in @@ -170,9 +170,9 @@ async function loginCommand(cmd: "login" | "logout", args: string[]) { } if (cmd === "logout") { const name = positionals[0] ?? (Object.keys(known).length === 1 ? Object.keys(known)[0]! : "") - if (!name) fail(Object.keys(known).length ? `which one? lembas logout <${Object.keys(known).join("|")}>` : "not logged in to any instance", 2) + if (!name) fail(Object.keys(known).length ? `which one? lembas logout <${Object.keys(known).join("|")}>` : "not logged in to a LLeMbas server", 2) const r = await logout(name) - console.log(`Signed out of ${name}${r.revoked ? "" : " here (the instance could not be told — revoke it under User → Security → Devices there)"}; its connection is removed.`) + console.log(`Signed out of ${name}${r.revoked ? "" : " here (the server could not be told — revoke it under User → Security → Devices there)"}; its sign-in is removed here.`) if (r.modelLeft) console.log(`config.yaml still starts on ${r.modelLeft}: choose another with lembas config set model .`) return } @@ -190,7 +190,7 @@ async function loginCommand(cmd: "login" | "logout", args: string[]) { // and "run login again" would send the person straight back here. Sign in afresh instead; // the new login replaces the old one. if (!(e instanceof SignInRejected)) throw e - if (!json) console.error("The instance no longer accepts the sign-in kept here: signing in again.") + if (!json) console.error("The LLeMbas server no longer accepts the sign-in kept here: signing in again.") address = again.base_url } } @@ -198,8 +198,8 @@ async function loginCommand(cmd: "login" | "logout", args: string[]) { // again, at the address it had. if (again && !address) address = again.base_url if (!address) { - if (!process.stdin.isTTY || json) fail("usage: lembas login ", 2) - process.stdout.write("LLeMbas instance address: ") + if (!process.stdin.isTTY || json) fail("usage: lembas login ", 2) + process.stdout.write("LLeMbas server address: ") for await (const line of console) { address = line.trim() break @@ -364,7 +364,7 @@ async function main() { } process.exit(remoteCommand(["scheduled", ...argv.slice(2)])) } - fail("usage: lembas service install | uninstall | status | logs [-f] | run [connection] | scheduled [on|off]", 2) + fail("usage: lembas service install | uninstall | status | logs [-f] | run [name] | scheduled [on|off]", 2) } if (cmd === "run") { diff --git a/src/config/load.ts b/src/config/load.ts index dc5df03..05f4efc 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -1,4 +1,5 @@ import { match as wildcardMatch } from "../permission/wildcard.ts" +import { MODE_RANK } from "../permission/modes.ts" import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs" import { join } from "node:path" import { isScalar, parse, parseDocument } from "yaml" @@ -57,7 +58,6 @@ function validate(schema: S, value: unknown, file: string): /** config.yaml: everything substituted except `mcp` and `voice`, whose parts are substituted one * by one later (a missing variable for one server or endpoint must not break the whole file). */ -const MODE_RANK = { auto: 0, edit: 1, manual: 2, plan: 3 } as const /** A project's change to a global server, kept only where it narrows: off, fewer tools, less in * the prompt, shorter waits. It never turns on what the user turned off. */ @@ -329,10 +329,10 @@ export function loadConfig(opts: { projectConfigDir?: string; trusted?: boolean /** The server a voice half or the search goes through: the login (`connection:` may still name * it). A string says why there is none. */ const webuiFor = (named?: string): { name: string; c: Loaded["connections"][string] } | string => { - if (named) return connections[named]?.webui ? { name: named, c: connections[named]! } : broken[named] ? `${named} is unusable: ${broken[named]}` : `there is no webui connection named ${named}` + if (named) return connections[named]?.webui ? { name: named, c: connections[named]! } : broken[named] ? `${named} is unusable: ${broken[named]}` : `there is no sign-in named ${named}` const all = Object.entries(connections).filter(([, c]) => c.webui) if (all.length === 1) return { name: all[0]![0], c: all[0]![1] } - return all.length ? `there are several webui connections (${all.map(([n]) => n).join(", ")}); name one with connection:` : "there is no webui connection (lembas login)" + return all.length ? `there are several sign-ins (${all.map(([n]) => n).join(", ")}); name one with connection:` : "not signed in to a LLeMbas server (lembas login)" } const mcp: Loaded["mcp"] = {} @@ -480,7 +480,7 @@ function localOnly(config: Config, connections: Loaded["connections"], warnings: const out = { ...config } if (out.search) { const sr = { ...out.search } - if (sr.order?.includes("webui") || sr.webui || sr.fetch === "webui") warnings.push("local mode: web search and fetch do not go through the LLeMbas instance") + if (sr.order?.includes("webui") || sr.webui || sr.fetch === "webui") warnings.push("local mode: web search and fetch do not go through the LLeMbas server") if (sr.order) sr.order = sr.order.filter((p) => p !== "webui") delete sr.webui if (sr.fetch === "webui") sr.fetch = "local" @@ -490,7 +490,7 @@ function localOnly(config: Config, connections: Loaded["connections"], warnings: out.library = "local" const emb = out.embedding?.split("/")[0] if (out.embedding && emb && connections[emb]?.webui) { - warnings.push(`local mode: embedding ${out.embedding} would go through the LLeMbas instance; the library is searched by words only`) + warnings.push(`local mode: embedding ${out.embedding} would go through the LLeMbas server; the library is searched by words only`) delete out.embedding } if (out.hardline_disable?.length) { diff --git a/src/config/schema.ts b/src/config/schema.ts index 9f851ae..61967a6 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -100,7 +100,7 @@ export interface Connection { * their settings, and — where config.yaml says `provider: webui` — the voice and the web search come * from the instance at every start. `lembas login` writes it. */ export const WebuiConnection = z.strictObject({ - type: z.literal("webui").describe("A LLeMbas instance: its models, their settings, its voice and its web search."), + type: z.literal("webui").describe("A LLeMbas server: its models, their settings, its voice and its web search."), url: Url.describe("The instance's address, e.g. https://ai.example.org (no /v1)."), api_key: z.string().optional().describe("This machine's token, as login wrote it: {file:~/.config/lembas/lembas/.key}."), tls: Tls.optional().describe("For an instance behind a private CA: `ca`, the PEM file that signed its certificate."), @@ -139,11 +139,11 @@ const VoiceEndpoint = { /** `provider: webui`: through a LLeMbas instance's own speech servers, with the account's * voice, speed and language. */ const WebuiVoice = { - connection: z.string().optional().describe("webui: which webui connection (default: the only one there is)."), + connection: z.string().optional().describe("webui: which sign-in (default: the only one there is)."), } const SttEndpoint = z.strictObject({ - provider: z.enum(["openai", "whispercpp", "webui"]).optional().describe("openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas instance's."), + provider: z.enum(["openai", "whispercpp", "webui"]).optional().describe("openai: POST {base_url}/audio/transcriptions (OpenAI, whisper.cpp's server with its OpenAI path, faster-whisper servers). whispercpp: POST {base_url}/inference (whisper.cpp's own). webui: the LLeMbas server's."), ...VoiceEndpoint, ...WebuiVoice, model: z.string().optional(), @@ -152,7 +152,7 @@ const SttEndpoint = z.strictObject({ }) const TtsEndpoint = z.strictObject({ - provider: z.enum(["openai", "piper-http", "piper-cli", "webui"]).optional().describe("openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas instance's, in the account's voice."), + provider: z.enum(["openai", "piper-http", "piper-cli", "webui"]).optional().describe("openai: POST {base_url}/audio/speech (OpenAI, Kokoro-FastAPI). piper-http: POST {base_url} with {text} (piper's http_server). piper-cli: the piper program. webui: the LLeMbas server's, in the account's voice."), ...VoiceEndpoint, ...WebuiVoice, model: z.string().optional(), @@ -220,7 +220,7 @@ export const Update = z.strictObject({ source: z .strictObject({ type: z.enum(["github", "gitea", "static"]).describe("github or gitea (Forgejo too): their releases API. static: any web directory with files `stable` and `beta` naming a tag, and the assets under /."), - url: Url.optional().describe("gitea: the forge (https://git.example.org). github: the API (default https://api.github.com). static: the directory."), + url: Url.optional().describe("gitea: the address of the Gitea server (https://git.example.org). github: the API (default https://api.github.com). static: the directory."), repo: z.string().regex(/^(?!\.\.?\/)[\w.-]+\/(?!\.\.?$)[\w.-]+$/).optional().describe("owner/name, for github and gitea."), token: z.string().optional().describe("For a private repository: {env:NAME} or {file:~/path}, never pasted. Or key_cmd."), key_cmd: z.string().optional(), @@ -290,13 +290,13 @@ export const Config = z.strictObject({ instruction_files: z.array(z.string()).optional().describe("More instruction files for the system prompt, besides AGENTS.md / CLAUDE.md."), search: z .strictObject({ - order: z.array(z.enum(["webui", "searxng", "firecrawl", "ddg"])).optional().describe("Providers to try, in order; the first that answers wins. Default: those configured (webui first), then ddg. webui: the LLeMbas instance's own search."), + order: z.array(z.enum(["webui", "searxng", "firecrawl", "ddg"])).optional().describe("Providers to try, in order; the first that answers wins. Default: those configured (webui first), then ddg. webui: the LLeMbas server's own search."), max_results: z.number().int().min(1).max(30).optional().describe("Results per search (default 8)."), searxng: z.strictObject({ base_url: Url, api_key: z.string().optional(), tls: Tls.optional(), categories: z.string().optional(), language: z.string().optional() }).optional(), firecrawl: z.strictObject({ base_url: Url.optional(), api_key: z.string().optional(), tls: Tls.optional() }).optional().describe("API (api.firecrawl.dev, with a key) or self-hosted (its own URL, no key needed)."), ddg: z.strictObject({ region: z.string().optional(), safe: z.enum(["strict", "moderate", "off"]).optional() }).optional(), - webui: z.strictObject({ connection: z.string().optional().describe("Which webui connection (default: the only one there is).") }).optional().describe("Search through a LLeMbas instance: its provider, its settings, its keys."), - fetch: z.enum(["local", "firecrawl", "webui"]).optional().describe("How web_fetch reads a page: here, through Firecrawl's scrape, or through the LLeMbas instance."), + webui: z.strictObject({ connection: z.string().optional().describe("Which sign-in (default: the only one there is).") }).optional().describe("Search through the LLeMbas server: its provider, its settings, its keys."), + fetch: z.enum(["local", "firecrawl", "webui"]).optional().describe("How web_fetch reads a page: here, through Firecrawl's scrape, or through the LLeMbas server."), }) .optional(), voice: Voice.optional().describe("Voice in and out. Global only — it carries endpoints and keys, like a connection."), @@ -318,17 +318,17 @@ export const Config = z.strictObject({ library: z.enum(["local", "lembas"]).optional().describe("Global config only. Where memory lives. lembas (the default when the login may reach it): the account's memory records on the LLeMbas server, through its /mcp — the same records its chats have. local: this machine's memory files. Notes, knowledge bases and skills are this machine's either way."), remote: z .strictObject({ - enabled: z.boolean().optional().describe("Accept work from a LLeMbas instance this machine is logged in to (lembas service). Default false."), + enabled: z.boolean().optional().describe("Accept work from the LLeMbas server this machine is signed in to (lembas service). Default false."), roots: z.array(z.string()).optional().describe("The directories a remote session may be opened in, and anything under them. Empty: none."), max_mode: z.enum(MODES).optional().describe("The most permissive mode a remote session may run in (default edit). auto only when set here."), approval_timeout: z.number().int().positive().optional().describe("Seconds an approval waits for an answer from the web before it counts as a denial (default 600)."), require_trust: z.boolean().optional().describe("Only projects trusted on this machine (default true)."), terminal: z.boolean().optional().describe("Let the web UI open a terminal here (LLeMbas's terminal panel on a chat on this device): a login shell as this user, in a directory remote sessions may use. Default false."), - scheduled: z.boolean().optional().describe("Accept scheduled work (harness acp.md, spec 3.5.0): let your schedules on the LLeMbas instance run here as agent turns, in the folders remote work may use, in the schedule's mode (Edit unless it says Auto) lowered to max_mode. Default false. lembas service scheduled on|off."), + scheduled: z.boolean().optional().describe("Accept scheduled work (harness acp.md, spec 3.5.0): let your schedules on the LLeMbas server run here as agent turns, in the folders remote work may use, in the schedule's mode (Edit unless it says Auto) lowered to max_mode. Default false. lembas service scheduled on|off."), files_that_run_code: z.boolean().optional().describe("Let the file manager of the web UI and the apps change files that run code here (harness acp.md, spec 3.11.0): git's hooks and configuration, a project's agent configuration, your shell's start-up files. Default false: they can be read from there, and are changed only on this machine."), terminal_integration: z.boolean().optional().describe("Shell integration in those terminals (bash, zsh, fish): after your own startup files, the shell marks each prompt, command and exit status (OSC 133) and its directory (OSC 7), so the web UI shows the directory, a mark beside each finished command, and can jump between commands. false: the shell starts as it is. Default true."), }) .optional() - .describe("Global config only. What a LLeMbas instance may ask of this machine over the link: the device decides, never the server."), + .describe("Global config only. What the LLeMbas server may ask of this machine over the link: the device decides, never the server."), }) export type Config = z.infer diff --git a/src/lembas/login.ts b/src/lembas/login.ts index 9bdc5cd..d146771 100644 --- a/src/lembas/login.ts +++ b/src/lembas/login.ts @@ -155,7 +155,7 @@ export function writeConnection(connection: string, d: Discovery, tls: Tls | und doc.setIn(["connections", connection], doc.createNode(entry)) const node = doc.getIn(["connections", connection], true) as { commentBefore?: string } | undefined if (node) - node.commentBefore = ` ${d.name ?? "LLeMbas"} at ${base}, written by \`lembas login\`. Its models and their settings come from the instance at every start; \`lembas logout ${connection}\` removes it.` + node.commentBefore = ` ${d.name ?? "LLeMbas"} at ${base}, written by \`lembas login\`. Its models and their settings come from the server at every start; \`lembas logout ${connection}\` removes it.` writeYamlDoc(connectionsFile(), doc, 0o600) } @@ -185,7 +185,7 @@ function replaceOld(old: string, now: string, instanceDefault: string | undefine if (typeof model === "string" && model.startsWith(`${old}/`)) { if (instanceDefault && model === `${old}/${instanceDefault}`) { cfg.delete("model") - said.push(`config.yaml no longer pins ${model}: sessions start on the instance's default`) + said.push(`config.yaml no longer pins ${model}: sessions start on the server's default`) } else { cfg.set("model", renamed(model, old, now)) said.push(`config.yaml starts on ${renamed(model, old, now)}`) @@ -401,12 +401,12 @@ export function loginSummary(r: LoginResult, fresh: boolean): string[] { const out: string[] = [] const who = r.instance.email ? ` as ${r.instance.email}` : "" const label = r.instance.instance_name ? `${r.instance.instance_name} (${r.instance.base_url})` : r.instance.base_url - out.push(fresh ? `Signed in to ${label}${who}. Connection ${r.connection}: ${r.models.length} model${r.models.length === 1 ? "" : "s"}, read from the instance at every start.` : `${r.connection}: ${r.models.length} model${r.models.length === 1 ? "" : "s"} from ${label} (LLeMbas ${r.version}).`) + out.push(fresh ? `Signed in to ${label}${who} as ${r.connection}: ${r.models.length} model${r.models.length === 1 ? "" : "s"}, read from the server at every start.` : `${r.connection}: ${r.models.length} model${r.models.length === 1 ? "" : "s"} from ${label} (LLeMbas ${r.version}).`) const refOf = (id: string) => r.refs?.[id] ?? `${r.connection}/${id}` - for (const m of r.models) out.push(` ${refOf(m.id)}${m.context ? ` ${Math.round(m.context / 1024)}k` : ""}${m.id === r.instanceDefault ? " (the instance's default)" : ""}`) + for (const m of r.models) out.push(` ${refOf(m.id)}${m.context ? ` ${Math.round(m.context / 1024)}k` : ""}${m.id === r.instanceDefault ? " (the server's default)" : ""}`) const model = currentModel() if (r.defaultSet) out.push(`Sessions start on ${r.defaultSet}.`) - else if (!model && r.instanceDefault) out.push(`Sessions start on the instance's default, ${refOf(r.instanceDefault)}.`) + else if (!model && r.instanceDefault) out.push(`Sessions start on the server's default, ${refOf(r.instanceDefault)}.`) else if (model) out.push(`Sessions start on ${model} (config.yaml).`) for (const c of r.changes) out.push(`· ${c}`) if (r.instance.ca) out.push(`TLS: trusting ${r.instance.ca} for this connection.`) @@ -477,7 +477,7 @@ async function store(discovery: Discovery, tls: Tls | undefined, granted: Grante if (!old?.token || old.token === granted.access_token) return const here = sameServer(old.at, base) const done = here ? await signOut(base, old.token, tls, granted.access_token) : await signOut(old.at, old.token, tls) - if (!done) changes.push("the previous login could not be signed out: revoke it under User → Security → Devices on the instance") + if (!done) changes.push("the previous login could not be signed out: revoke it under User → Security → Devices on the server") } await handOver(replaced) // One server at a time (2.0: the CLI is LLeMbas-server-specific): a login to another one signs diff --git a/src/lembas/personal.ts b/src/lembas/personal.ts index e92eb42..6b8fd19 100644 --- a/src/lembas/personal.ts +++ b/src/lembas/personal.ts @@ -64,7 +64,7 @@ export function withInstancePersonalization(config: Config): { config: Config; c export async function pushPersonalization(key: (typeof PERSONAL_KEYS)[number], value: string): Promise { if (isLocal()) throw new LembasError("local mode (-l) keeps settings in the project, not in the account") const one = soleInstance() - if (!one) throw new LembasError("not logged in to one LLeMbas instance") + if (!one) throw new LembasError("not signed in to a LLeMbas server (/login)") const saved = await savePersonalization(one.instance.base_url, one.token, one.instance.ca ? { ca: one.instance.ca } : undefined, { enabled: true, [key]: value }) const cache = readCache(one.instance.connection) if (cache) writeCache(one.instance.connection, { ...cache, personalization: saved ?? { ...(cache.personalization ?? { personality: "", personality_custom: "", instructions: "", available: true }), [key]: value, enabled: true } }) diff --git a/src/lembas/schedules.ts b/src/lembas/schedules.ts index 3c9b84c..2ec2b4d 100644 --- a/src/lembas/schedules.ts +++ b/src/lembas/schedules.ts @@ -63,7 +63,7 @@ export interface Compiled { /** One call to the schedule (and report) routes; the server's own refusal (`detail`) as the error. */ export async function api(method: string, path: string, body?: unknown, what = "schedules"): Promise { const one = soleInstance() - if (!one) throw new LembasError("not logged in to one LLeMbas server (/login)") + if (!one) throw new LembasError("not signed in to a LLeMbas server (/login)") const r = await apiCall(one.instance.base_url, one.token, one.instance.ca ? { ca: one.instance.ca } : undefined, method, `/api/v2${path}`, body) const detail = typeof r.json?.detail === "string" ? r.json.detail : undefined if (r.status === 401 && !detail) throw new SignInRejected("the server no longer accepts this sign-in — /login again") diff --git a/src/permission/modes.ts b/src/permission/modes.ts new file mode 100644 index 0000000..96a2f54 --- /dev/null +++ b/src/permission/modes.ts @@ -0,0 +1,24 @@ +// The permission modes' order (harness permission/modes.json `order`, loosest first) and the three +// questions asked of it — which is stricter, the stricter of two, a mode lowered to a ceiling. Five +// files had a table of their own; this is the one. +import type { Mode } from "../config/schema.ts" +import MODES_JSON from "../../harness/permission/modes.json" + +/** Loosest first: auto, edit, manual, plan. */ +export const MODE_ORDER = MODES_JSON.order as Mode[] + +/** A mode's place in the order: higher is stricter. */ +export const MODE_RANK = Object.fromEntries(MODE_ORDER.map((m, i) => [m, i])) as Record + +/** a is looser than b. */ +export const looser = (a: Mode, b: Mode) => MODE_RANK[a] < MODE_RANK[b] +/** a is stricter than b. */ +export const stricter = (a: Mode, b: Mode) => MODE_RANK[a] > MODE_RANK[b] + +/** The stricter of the two; `a` may be absent. */ +export function stricterMode(a: Mode | undefined, b: Mode): Mode { + return a !== undefined && stricter(a, b) ? a : b +} + +/** A mode lowered to `max`: never looser than it. */ +export const clampMode = (wanted: Mode, max: Mode): Mode => (looser(wanted, max) ? max : wanted) diff --git a/src/prompt/assemble.ts b/src/prompt/assemble.ts index 3c9c1c8..819fe50 100644 --- a/src/prompt/assemble.ts +++ b/src/prompt/assemble.ts @@ -1,3 +1,4 @@ +import { relativeWithin } from "../within.ts" import { existsSync, readFileSync, realpathSync, statSync } from "node:fs" import { homedir, platform, release } from "node:os" import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path" @@ -291,17 +292,17 @@ export function envLines(root: string, started: string): string[] { const r = resolve(root) const name = basename(r) || r const lines = [fillPrompt(LOOP.context.env.project, { name })] - const rel = relative(r, resolve(started)) - if (rel && !rel.startsWith("..") && !isAbsolute(rel)) lines.push(fillPrompt(LOOP.context.env.started, { path: rel })) + const rel = relativeWithin(resolve(started), r) + if (rel) lines.push(fillPrompt(LOOP.context.env.started, { path: rel })) return lines } /** A path as a prompt names it (context.md §11): relative to the project root inside it, `~/…` * under the person's home, absolute only outside both. */ export function promptPath(root: string, path: string): string { - const rel = relative(resolve(root), path) + const rel = relativeWithin(resolve(path), resolve(root)) if (rel === "") return "." - if (!rel.startsWith("..") && !isAbsolute(rel)) return rel + if (rel !== undefined) return rel const home = homedir() if (home && home !== "/" && (path === home || path.startsWith(home + sep))) return `~${path.slice(home.length)}` return path diff --git a/src/search/webui.ts b/src/search/webui.ts index 6935f51..742c5a4 100644 --- a/src/search/webui.ts +++ b/src/search/webui.ts @@ -13,7 +13,7 @@ export interface WebuiSearch { function target(c: SearchConfig): Required> & WebuiSearch { const w = c.webui as WebuiSearch | undefined - if (!w?.base_url) throw new SearchError("not configured (a webui connection: lembas login)") + if (!w?.base_url) throw new SearchError("not signed in to a LLeMbas server (lembas login)") return w as Required> & WebuiSearch } diff --git a/src/session/commands.ts b/src/session/commands.ts index 0f54a16..0450081 100644 --- a/src/session/commands.ts +++ b/src/session/commands.ts @@ -8,6 +8,7 @@ // The TUI runs the same builders (review, changelog, init) and the same rules (a built-in name wins // over a custom command's, a custom command's over a skill's; @files come from what was typed, never // from a command's own text), so a command does the same thing whichever keyboard typed it. +import { stricterMode } from "../permission/modes.ts" import { existsSync } from "node:fs" import type { App } from "../app.ts" import { MODES, type Mode } from "../config/schema.ts" @@ -325,7 +326,4 @@ export function expandSlash(app: App, text: string, o: { plain?: boolean } = {}) return undefined } -const RANK: Record = { auto: 0, edit: 1, manual: 2, plan: 3 } -function stricter(a: Mode, b: Mode): Mode { - return RANK[a] > RANK[b] ? a : b -} +const stricter = (a: Mode, b: Mode): Mode => stricterMode(a, b) diff --git a/src/team/delegation.ts b/src/team/delegation.ts index 0b9eaba..b7dc3c2 100644 --- a/src/team/delegation.ts +++ b/src/team/delegation.ts @@ -5,21 +5,15 @@ import { LOOP } from "../harness.ts" import { fillPrompt } from "../prompt/fill.ts" import type { Mode } from "../config/schema.ts" import { evaluate, type Context as PermContext, type Decision, type PermissionRequest, type Rule, type ToolClass } from "../permission/evaluate.ts" -import MODES_JSON from "../../harness/permission/modes.json" const TEXTS = LOOP.team.texts const fill = (t: string, v: Record) => fillPrompt(t, v) -/** Loosest first (permission/modes.json `order`). */ -export const MODE_ORDER = MODES_JSON.order as Mode[] -const rank = (m: Mode) => MODE_ORDER.indexOf(m) - -/** a is looser than b. */ -export const looser = (a: Mode, b: Mode) => rank(a) < rank(b) -/** a is stricter than b. */ -export const stricter = (a: Mode, b: Mode) => rank(a) > rank(b) +/** The modes' order and its questions: permission/modes.ts, the one table. */ +export { MODE_ORDER, looser, stricter } from "../permission/modes.ts" +import { looser, stricter, stricterMode } from "../permission/modes.ts" /** The stricter of the two. */ -export const strictest = (a: Mode, b: Mode): Mode => (stricter(a, b) ? a : b) +export const strictest = (a: Mode, b: Mode): Mode => stricterMode(a, b) export const REQUEST_KINDS = LOOP.team.request.kinds as ToolClass[] diff --git a/src/tool/read.ts b/src/tool/read.ts index 4fdb432..c23ac4e 100644 --- a/src/tool/read.ts +++ b/src/tool/read.ts @@ -1,3 +1,4 @@ +import { within } from "../within.ts" import { existsSync, readFileSync, realpathSync } from "node:fs" import { unsafeProjectFile } from "../project/safe.ts" import { readdir, stat } from "node:fs/promises" @@ -74,7 +75,7 @@ export function readBody(text: string, offset?: number, limit?: number): { body: /** OpenCode's "nearby instructions": reading a file under a directory with its own AGENTS.md or * CLAUDE.md hands the model that file, once per session. The root's is already in the prompt. */ function nearbyInstructions(file: string, ctx: import("./tool.ts").ToolContext): string { - if (!ctx.instructionsSeen || !file.startsWith(ctx.root + "/")) return "" + if (!ctx.instructionsSeen || !within(file, ctx.root)) return "" const out: string[] = [] for (let dir = dirname(file); dir.startsWith(ctx.root) && dir !== ctx.root; dir = dirname(dir)) { const hit = ["AGENTS.md", "CLAUDE.md"].map((f) => join(dir, f)).find((f) => existsSync(f)) diff --git a/src/tool/settings.ts b/src/tool/settings.ts index dc6e26e..0a4a8f8 100644 --- a/src/tool/settings.ts +++ b/src/tool/settings.ts @@ -2,13 +2,13 @@ // first" — and it changes the setting, with the user's approval (settings_tool: ask, the default). // Only what config/settings.ts marks for the agent; never permission rules, the hardline, MCP, // connections, updates, or this tool's own gate. A less strict mode is asked about every time. +import { MODE_RANK } from "../permission/modes.ts" import { z } from "zod" import { describe, findSetting, parseValue, show, type Entry } from "../config/settings.ts" import type { Mode } from "../config/schema.ts" import { defineTool, ToolError, type ToolContext } from "./tool.ts" import { described } from "../harness.ts" -const MODE_RANK: Record = { auto: 0, edit: 1, manual: 2, plan: 3 } const line = (e: Entry) => `${e.def.key} = ${show(e.value) || "(unset)"} [${e.source}]${e.def.values ? ` — ${e.def.values.join(" | ")}` : ""}${e.def.agent ? "" : " — user only"}${e.def.reload ? " — after a restart" : ""}` diff --git a/src/tool/tool.ts b/src/tool/tool.ts index 8c7b44a..b90ad46 100644 --- a/src/tool/tool.ts +++ b/src/tool/tool.ts @@ -1,3 +1,4 @@ +import { relativeWithin } from "../within.ts" import { within } from "../within.ts" import { existsSync } from "node:fs" import { isAbsolute, relative, resolve } from "node:path" @@ -285,8 +286,7 @@ export function absPath(p: string, ctx: ToolContext): string { /** For display and rule matching: relative to the root when inside it. */ export function showPath(abs: string, ctx: ToolContext): string { - const rel = relative(ctx.root, abs) - return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel : abs + return relativeWithin(resolve(abs), resolve(ctx.root)) || abs } export class ToolError extends Error {} diff --git a/src/tui/commands.ts b/src/tui/commands.ts index d336eb5..afbf7e6 100644 --- a/src/tui/commands.ts +++ b/src/tui/commands.ts @@ -1078,7 +1078,7 @@ export const COMMANDS: Command[] = [ { name: "login", args: "[address]", - description: "sign in to a LLeMbas instance: its models, voice and search (again: read them now)", + description: "sign in to a LLeMbas server: its models, voice and search (again: read them now)", async run(c, arg) { const { codeInstructions, instances, isWebuiEntry, login, loginSummary, sync } = await import("../lembas/login.ts") const known = instances() @@ -1101,7 +1101,7 @@ export const COMMANDS: Command[] = [ } if (arg.trim()) return go(arg.trim()) c.openDialog({ - title: "Log in to a LLeMbas instance", + title: "Sign in to a LLeMbas server", options: Object.values(known).map((i) => ({ label: i.base_url, value: i.base_url, description: `refresh ${i.connection}${i.email ? ` · ${i.email}` : ""}` })), custom: { label: "Log in to", onSubmit: (text) => void go(text) }, onSelect: (value) => void go(value), @@ -1110,13 +1110,13 @@ export const COMMANDS: Command[] = [ }, { name: "usage", - description: "your account's usage on the LLeMbas instance: this month's tokens and cost, this device's tokens", + description: "your account's usage on the LLeMbas server: this month's tokens and cost, this device's tokens", async run(c) { // /v1/usage of the account this machine is logged in to. const { accountUsage, spendLabel, usageLines } = await import("../lembas/personal.ts") try { const r = await accountUsage() - if (!r) return c.view.info("no usage to show — not logged in to one LLeMbas instance (/login), or it does not keep any") + if (!r) return c.view.info("no usage to show — not signed in to a LLeMbas server (/login), or it does not keep any") c.setSpend?.(spendLabel(r.usage)) c.view.info(usageLines(r.connection, r.usage).join("\n")) } catch (e) { @@ -1219,21 +1219,21 @@ export const COMMANDS: Command[] = [ { name: "logout", args: "[connection]", - description: "sign out of a LLeMbas instance, and remove the connection login wrote", + description: "sign out of the LLeMbas server, and remove what login wrote", async run(c, arg) { const { instances, logout } = await import("../lembas/login.ts") const known = Object.keys(instances()) const go = async (name: string) => { try { const r = await logout(name) - c.view.info(`Signed out of ${name}${r.revoked ? "" : " here — the instance could not be told; revoke it under User → Security → Devices there"}.${r.modelLeft ? ` config.yaml still starts on ${r.modelLeft}; /model picks another.` : ""}`) + c.view.info(`Signed out of ${name}${r.revoked ? "" : " here — the server could not be told; revoke it under User → Security → Devices there"}.${r.modelLeft ? ` config.yaml still starts on ${r.modelLeft}; /model picks another.` : ""}`) c.reload() } catch (e) { c.view.info(`logout: ${(e as Error).message}`, "warn") } } if (arg.trim()) return go(arg.trim()) - if (!known.length) return c.view.info("not logged in to any LLeMbas instance — /login
") + if (!known.length) return c.view.info("not signed in to a LLeMbas server — /login
") if (known.length === 1) return go(known[0]!) c.openDialog({ title: "Sign out of", options: known.map((k) => ({ label: k, value: k })), onSelect: (v) => void go(v) }) }, diff --git a/src/tui/components/setup.tsx b/src/tui/components/setup.tsx index 3e06325..ce3493b 100644 --- a/src/tui/components/setup.tsx +++ b/src/tui/components/setup.tsx @@ -77,7 +77,7 @@ export function Setup(p: { error: Error; onRetry: () => void; onQuit: () => void > - Log in to a LLeMbas instance + Sign in to a LLeMbas server Address: {address()}▏ diff --git a/src/within.ts b/src/within.ts index 10722d7..ea6453d 100644 --- a/src/within.ts +++ b/src/within.ts @@ -8,3 +8,11 @@ export function within(path: string, dir: string): boolean { return path === dir || path.startsWith(dir.endsWith("/") ? dir : dir + "/") } + +/** `path` relative to `dir` when it is `dir` ("") or lies under it; undefined otherwise. The one + * answer for "show it relative to the project": by `within`, so `..cache` under the project is + * `..cache`, not outside. */ +export function relativeWithin(path: string, dir: string): string | undefined { + if (!within(path, dir)) return undefined + return path === dir ? "" : path.slice(dir.endsWith("/") ? dir.length : dir.length + 1) +} diff --git a/tests/lembas-login.test.ts b/tests/lembas-login.test.ts index 690a980..aa19985 100644 --- a/tests/lembas-login.test.ts +++ b/tests/lembas-login.test.ts @@ -346,7 +346,7 @@ test("webui with no webui connection is off, with a warning", () => { const loaded = loadConfig() expect(loaded.config.voice?.tts).toBeUndefined() expect(loaded.config.search?.webui).toBeUndefined() - expect(loaded.warnings.join("\n")).toContain("there is no webui connection (lembas login)") + expect(loaded.warnings.join("\n")).toContain("not signed in to a LLeMbas server (lembas login)") }) test("login again reads the models now", async () => { diff --git a/tests/schedules.test.ts b/tests/schedules.test.ts index 59c4e9e..40b79de 100644 --- a/tests/schedules.test.ts +++ b/tests/schedules.test.ts @@ -116,7 +116,7 @@ test("an older server that lets only an app's token in: said plainly; not logged server({ appOnly: true }) await expect(listSchedules()).rejects.toThrow("does not let a linked computer manage schedules") clean() - await expect(listSchedules()).rejects.toThrow("not logged in") + await expect(listSchedules()).rejects.toThrow("not signed in") }) test("findSchedule: by id, by a title's start when only one fits, else says why", () => { diff --git a/tests/tui/reports.test.tsx b/tests/tui/reports.test.tsx index 3df7858..9de71dc 100644 --- a/tests/tui/reports.test.tsx +++ b/tests/tui/reports.test.tsx @@ -173,7 +173,7 @@ test("/reports with no reports, with a name, and without a server that has them" clean() await t.input.typeText("/reports") t.input.pressEnter() - expect(await t.until("/reports: not logged in to one LLeMbas server")).toBe(true) + expect(await t.until("/reports: not signed in to a LLeMbas server")).toBe(true) }) test("the text where there is no menu: the list unread first, one report with its pages as lines", () => { diff --git a/tests/tui/setup.test.tsx b/tests/tui/setup.test.tsx index 0f390eb..b6ecda8 100644 --- a/tests/tui/setup.test.tsx +++ b/tests/tui/setup.test.tsx @@ -1,4 +1,4 @@ -// The first run with no model: the setup screen opens on "Log in to a LLeMbas instance" +// The first run with no model: the setup screen opens on "Sign in to a LLeMbas server" // with the address field focused — typing goes straight into it — and ctrl+r tries again from there. import { afterEach, expect, test } from "bun:test" import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs" @@ -33,7 +33,7 @@ test("no model yet: the sign-in is first and focused; ctrl+r opens the session o let f = await frame() // 2.0: the server's models or none — the screen is the sign-in, and nothing else to fill in. expect(f).toContain("not logged in to a LLeMbas server") - expect(f).toContain("Log in to a LLeMbas instance") + expect(f).toContain("Sign in to a LLeMbas server") expect(f).not.toContain("connections.yaml") // Focused: what is typed is the address, without pressing l first. await setup.mockInput.typeText("ai.example")