Files
LLeMbas-CLI/src/doctor.ts
T
HomerandClaude Fable 5.1 837f38c744 Harness spec 1.1.0: one plan, prototypes and the library shared; the CLI implements it
The spec: plan_write and plan_update (new, shared, offered in every mode) and
plan_submit (now shared) keep one structured plan — findings, objectives,
phases of tasks — in place of the todo list, which lives on as a former name
of plan_write. The shared system text is one text for both projects, with
variables for what differs; the mode texts, a prototypes block and a library
block are shared. acp.md: the client hands the device what only it knows
(context, library, prototypes), the plan travels as a structure (plan_state),
library calls carry the chat's scope, and a client may rewind a session.
loop.json says its numbers as numbers. Four conformance areas: plan,
prototype, library_scope, toolcall_index.

The CLI: the plan is kept per session in the store and drawn above the prompt
and on the approval card; the prompt is assembled from the spec's texts with
their variables filled; the link reads the instance's instructions,
personalization, knowledge scope and prototype offer, sends the plan as a
structure and answers rewind; library calls to the instance carry the session
as scope; a prototype written in the terminal is saved as a file and named in
the transcript; a tool-call fragment without an index continues the last call;
the default theme is Moria; dead exports and Hermes leftovers removed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-18 04:02:12 +02:00

53 lines
2.5 KiB
TypeScript

// Checks of this machine that `lembas config check` reports.
//
// A LLeMbas server installed with pip may bring a console script called `lembas` too (the server
// itself runs as `lembas-server`). Installed into a directory
// that comes first on PATH, it is what `lembas` runs — and the person typing it gets a Python
// traceback or a web server instead of this program. install.sh says so when it installs; this says
// so whenever the configuration is checked.
import { accessSync, constants, openSync, readSync, closeSync, statSync } from "node:fs"
import { delimiter, dirname, join } from "node:path"
import { realPath } from "./permission/evaluate.ts"
/** The first `lembas` on `path`, the way a shell finds it. */
export function firstOnPath(name: string, path = process.env.PATH ?? ""): string | undefined {
for (const dir of path.split(delimiter)) {
if (!dir) continue
const f = join(dir, name)
try {
if (!statSync(f).isFile()) continue
accessSync(f, constants.X_OK)
return f
} catch {}
}
return undefined
}
/** Whether a file is a Python script (its first line a `#!` naming python). */
export function isPythonScript(file: string): boolean {
try {
const fd = openSync(realPath(file), "r")
const buf = Buffer.alloc(300)
const n = readSync(fd, buf, 0, 300, 0)
closeSync(fd)
const first = buf.subarray(0, n).toString("utf8").split("\n")[0] ?? ""
return first.startsWith("#!") && /python/.test(first)
} catch {
return false
}
}
/** Why `lembas` typed in a shell would not run this program, or undefined when it would (or this
* cannot tell: run from source, nothing on PATH). `self`: this binary — undefined from source, where
* only a Python script is recognised as the wrong one. */
export function lembasShadowed(o: { path?: string; self?: string } = {}): string | undefined {
const self = "self" in o ? o.self : /(^|\/)bun$/.test(process.execPath) ? undefined : process.execPath
const found = firstOnPath("lembas", o.path)
if (!found) return undefined
if (self && realPath(found) === realPath(self)) return undefined
const python = isPythonScript(found)
if (!python && !self) return undefined
const what = python ? "a Python console script — most likely the LLeMbas server's own `lembas`" : "another program"
return `\`lembas\` runs ${found}, ${what}, not this LLeMbas CLI${self ? ` (${self})` : ""}. Put ${self ? dirname(self) : "the directory LLeMbas CLI is installed in"} before ${dirname(found)} in PATH, or remove that one — the server itself runs as lembas-server.`
}