@livx.cc/agentx 0.94.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/Agent-1DRfsYaK.d.ts +408 -0
- package/dist/cli.d.ts +293 -0
- package/dist/cli.js +12796 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1319 -0
- package/dist/index.js +5998 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-CnzmQ8JE.d.ts +101 -0
- package/dist/mcp.client.d.ts +228 -0
- package/dist/mcp.client.js +617 -0
- package/dist/mcp.client.js.map +1 -0
- package/dist/tools-DtpN8Agv.d.ts +274 -0
- package/dist/tools.shell.d.ts +115 -0
- package/dist/tools.shell.js +539 -0
- package/dist/tools.shell.js.map +1 -0
- package/package.json +81 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { H as Hooks, h as RunResult, R as ReasoningEffort, A as Agent } from './Agent-1DRfsYaK.js';
|
|
3
|
+
import { IFilesystem } from '@livx.cc/wcli/core';
|
|
4
|
+
import { M as Message, c as ContentPart, e as MessageContent } from './tools-DtpN8Agv.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* On-disk session store for the CLI: each conversation is one JSON file at
|
|
8
|
+
* `<cwd>/.agent/sessions/<id>.json`. Writes are atomic (temp + rename) so a crash
|
|
9
|
+
* mid-write never corrupts a prior session. This is what gives the REPL memory across
|
|
10
|
+
* turns and powers `--continue` / `--resume`.
|
|
11
|
+
*/
|
|
12
|
+
interface SessionMeta {
|
|
13
|
+
id: string;
|
|
14
|
+
created: number;
|
|
15
|
+
updated: number;
|
|
16
|
+
cwd: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
turns: number;
|
|
19
|
+
title: string;
|
|
20
|
+
/** Cumulative tokens across all turns in this session (for `/cost`). */
|
|
21
|
+
tokens?: number;
|
|
22
|
+
/** Cumulative USD cost across all turns (per-turn model pricing; for `/cost`). */
|
|
23
|
+
costUsd?: number;
|
|
24
|
+
/** Sticky: true if any turn's usage was estimated (streamed without provider usage) → cost is approximate. */
|
|
25
|
+
costEstimated?: boolean;
|
|
26
|
+
/** Per-turn forensic log: timing, outcome, usage, and provider error per turn — for investigating a reported issue. */
|
|
27
|
+
events?: TurnEvent[];
|
|
28
|
+
}
|
|
29
|
+
/** One turn's diagnostics, captured for offline forensics (mirrors what the footer prints, but persisted). */
|
|
30
|
+
interface TurnEvent {
|
|
31
|
+
ts: number;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
model: string;
|
|
34
|
+
finishReason: string;
|
|
35
|
+
steps: number;
|
|
36
|
+
tools: number;
|
|
37
|
+
tokens?: number;
|
|
38
|
+
costUsd?: number;
|
|
39
|
+
estimated?: boolean;
|
|
40
|
+
error?: {
|
|
41
|
+
message: string;
|
|
42
|
+
statusCode?: number;
|
|
43
|
+
code?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface SessionData {
|
|
47
|
+
meta: SessionMeta;
|
|
48
|
+
messages: Message[];
|
|
49
|
+
}
|
|
50
|
+
declare class SessionStore {
|
|
51
|
+
readonly dir: string;
|
|
52
|
+
constructor(cwd: string);
|
|
53
|
+
/** Sortable, human-readable id: `YYYYMMDD-HHMMSS-<folder>`. */
|
|
54
|
+
newId(now?: number, cwd?: string): string;
|
|
55
|
+
/** A session id must be one safe path segment — blocks `../`-style traversal via --resume/load/save. */
|
|
56
|
+
private safeId;
|
|
57
|
+
save(data: SessionData): void;
|
|
58
|
+
load(id: string): SessionData | undefined;
|
|
59
|
+
/** All sessions' metadata, most-recently-updated first. */
|
|
60
|
+
list(): SessionMeta[];
|
|
61
|
+
latest(): SessionMeta | undefined;
|
|
62
|
+
/** The most-recently-updated session's full data (single listing pass). */
|
|
63
|
+
latestData(): SessionData | undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Common contract for the CLI's two checkpoint backends: the in-memory {@link CheckpointStack}
|
|
68
|
+
* (sandbox mode) and the durable git-backed `GitCheckpoints` (disk mode). Both expose the same
|
|
69
|
+
* begin/list/rewindTo/size surface consumed by the REPL (`/rewind`, `/undo`, double-Esc rewind).
|
|
70
|
+
*/
|
|
71
|
+
interface Checkpoints {
|
|
72
|
+
/** Open a restore point for the turn about to run (label = the user's message). */
|
|
73
|
+
begin(label: string): void | Promise<void>;
|
|
74
|
+
/** Restore points, newest-first, for an interactive picker. */
|
|
75
|
+
list(): {
|
|
76
|
+
index: number;
|
|
77
|
+
label: string;
|
|
78
|
+
at: number;
|
|
79
|
+
files: number;
|
|
80
|
+
}[];
|
|
81
|
+
/** Restore the working tree to BEFORE restore point `index` (undo it and every later one). */
|
|
82
|
+
rewindTo(index: number): Promise<{
|
|
83
|
+
restored: number;
|
|
84
|
+
deleted: number;
|
|
85
|
+
}>;
|
|
86
|
+
/** Number of restore points currently held. */
|
|
87
|
+
readonly size: number;
|
|
88
|
+
/** Optional pre-mutation hook (in-memory backend only; git captures at the turn boundary). */
|
|
89
|
+
hooks?(): Hooks;
|
|
90
|
+
/** Re-bind to a different conversation (resume/switch); no-op for the in-memory backend. */
|
|
91
|
+
use?(sessionId: string): void;
|
|
92
|
+
/** Sync `list()`/`size` with the durable backend before a read (git backend only). */
|
|
93
|
+
refresh?(): Promise<void>;
|
|
94
|
+
/** Unified diff of everything this session changed (oldest restore point → current tree), for `/diff`. */
|
|
95
|
+
diff?(): Promise<string>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Classify a pasted blob (e.g. a drag-dropped file path) into an attachment: `display` is shown in the
|
|
99
|
+
* in-buffer placeholder, `ref` is what the placeholder expands to on submit (e.g. an `@/abs/path` mention). */
|
|
100
|
+
type PasteClassifier = (text: string) => {
|
|
101
|
+
display: string;
|
|
102
|
+
ref: string;
|
|
103
|
+
} | null;
|
|
104
|
+
|
|
105
|
+
/** Programmatic Esc — abort the in-flight turn (tests; the REPL keymap calls activeTurn directly). */
|
|
106
|
+
declare const abortActiveTurn: () => void;
|
|
107
|
+
interface Args {
|
|
108
|
+
task?: string;
|
|
109
|
+
model?: string;
|
|
110
|
+
cwd?: string;
|
|
111
|
+
stream: boolean;
|
|
112
|
+
plan: boolean;
|
|
113
|
+
ask: boolean;
|
|
114
|
+
yes: boolean;
|
|
115
|
+
vfs: boolean;
|
|
116
|
+
shell: boolean | undefined;
|
|
117
|
+
boddb?: string;
|
|
118
|
+
seed: boolean;
|
|
119
|
+
subagents: boolean;
|
|
120
|
+
maxSteps?: number;
|
|
121
|
+
maxTokens?: number;
|
|
122
|
+
timeoutMs?: number;
|
|
123
|
+
reasoning?: ReasoningEffort;
|
|
124
|
+
help: boolean;
|
|
125
|
+
version: boolean;
|
|
126
|
+
duplex: boolean;
|
|
127
|
+
voiceModel?: string;
|
|
128
|
+
thinkModel?: string | false;
|
|
129
|
+
voice: boolean;
|
|
130
|
+
cont: boolean;
|
|
131
|
+
resume?: string;
|
|
132
|
+
sessionId?: string;
|
|
133
|
+
fork?: boolean;
|
|
134
|
+
outputFormat: 'text' | 'json' | 'stream-json';
|
|
135
|
+
allowedTools?: string[];
|
|
136
|
+
disallowedTools?: string[];
|
|
137
|
+
appendSystemPrompt?: string;
|
|
138
|
+
addDirs?: string[];
|
|
139
|
+
print?: boolean;
|
|
140
|
+
debug?: boolean;
|
|
141
|
+
scratch?: boolean;
|
|
142
|
+
harden?: boolean;
|
|
143
|
+
hardenNet?: boolean;
|
|
144
|
+
}
|
|
145
|
+
declare function parseArgs(argv: string[]): Args;
|
|
146
|
+
/** Hooks that render tool activity to stderr: a preToolUse header, and for edits a colorized diff.
|
|
147
|
+
* `opts.background` marks the agent as a BACKGROUND one (duplex workers): its chrome lands async on
|
|
148
|
+
* top of a live prompt, so it must never drive the foreground spinner (the 'agentx › '/'⠹ thinking…'
|
|
149
|
+
* flicker), clears the prompt line before printing, and repaints via the callback after. `opts.gate`
|
|
150
|
+
* is evaluated per call — false renders nothing (minimal mode: task events only). */
|
|
151
|
+
/** One-line collapsed summary for read-only lookup results (CC parity — `⎿ read 42 lines` instead of the
|
|
152
|
+
* full body flooding the scrollback); null → tool keeps the N-line preview (shell output stays useful). */
|
|
153
|
+
declare function summarizeResult(name: string, text: string): string | null;
|
|
154
|
+
/** Synthetic task-event user messages ("[task t2 completed] <multi-KB worker dump>") aren't real user
|
|
155
|
+
* utterances — replaying the raw payload newline-collapsed + hard-cut at N chars garbles it (slices URLs
|
|
156
|
+
* mid-token). Condense to a one-line marker. Non-task text is returned unchanged. */
|
|
157
|
+
declare function condenseReplay(t: string): string;
|
|
158
|
+
/** Render a resumed conversation (like CC) so the user sees the context they're continuing: user
|
|
159
|
+
* prompts, assistant narration, and a condensed line per tool action. Tool *results* are omitted
|
|
160
|
+
* (verbose) and inlined @-mention blocks are stripped from prompts. Pure → unit-testable. */
|
|
161
|
+
declare function formatHistory(messages: Message[]): string;
|
|
162
|
+
/** Render the FULL transcript — user prompts, assistant text, every tool call AND its complete
|
|
163
|
+
* result body — for `/transcript` (the past-turn equivalent of Ctrl-O live verbose; CC's
|
|
164
|
+
* transcript-viewer parity). `lastTurns` bounds output to the most recent N user turns.
|
|
165
|
+
* Each tool result is capped at `resultLines` lines with an elision marker. Pure → unit-testable. */
|
|
166
|
+
declare function formatTranscriptFull(messages: Message[], opts?: {
|
|
167
|
+
lastTurns?: number;
|
|
168
|
+
resultLines?: number;
|
|
169
|
+
}): string;
|
|
170
|
+
/** Render a transcript to portable Markdown (no ANSI) for `/export`. Same shape as formatHistory —
|
|
171
|
+
* user prompts + assistant narration + one quoted line per tool action; tool results omitted. Pure → unit-testable. */
|
|
172
|
+
declare function exportMarkdown(meta: {
|
|
173
|
+
id: string;
|
|
174
|
+
title?: string;
|
|
175
|
+
model?: string;
|
|
176
|
+
turns?: number;
|
|
177
|
+
created?: number;
|
|
178
|
+
tokens?: number;
|
|
179
|
+
costUsd?: number;
|
|
180
|
+
costEstimated?: boolean;
|
|
181
|
+
}, messages: Message[]): string;
|
|
182
|
+
/** Cache-read/write price multipliers over the input rate, by provider (derived from the model
|
|
183
|
+
* prefix). Anthropic: write 1.25x / read 0.1x. OpenAI & Gemini auto-cache (no write surcharge),
|
|
184
|
+
* reads 0.5x / 0.25x. DeepSeek read 0.1x. Unknown → no discount (1x/1x, safe over-estimate). */
|
|
185
|
+
declare function cacheMultipliers(model?: string): {
|
|
186
|
+
read: number;
|
|
187
|
+
write: number;
|
|
188
|
+
};
|
|
189
|
+
/** USD cost from a model's per-1K pricing (ai.libx.js ModelPricing) + token usage. 0 if unpriced.
|
|
190
|
+
* Cache-aware: promptTokens includes cache reads/writes — priced at the provider's real multipliers
|
|
191
|
+
* (via `model`) so cached runs aren't overstated. Omitting `model` falls back to Anthropic's rates. */
|
|
192
|
+
declare function costOf(pricing: {
|
|
193
|
+
inputCostPer1K: number;
|
|
194
|
+
outputCostPer1K: number;
|
|
195
|
+
} | undefined, promptTokens?: number, completionTokens?: number, cacheCreationTokens?: number, cacheReadTokens?: number, model?: string): number;
|
|
196
|
+
/** Format a USD amount: 2 decimals at $1+, 4 below (agent turns are sub-cent). */
|
|
197
|
+
declare function fmtUsd(n: number): string;
|
|
198
|
+
/** ~4 chars/token estimate over a transcript (matches the Agent's context-budget heuristic). */
|
|
199
|
+
declare function estimateTranscriptTokens(messages: Message[]): number;
|
|
200
|
+
/** One-screen session status (model, dir, fs-mode, tools, permission posture, turns/tokens). Pure. */
|
|
201
|
+
declare function formatStatus(s: {
|
|
202
|
+
model: string;
|
|
203
|
+
cwd: string;
|
|
204
|
+
mode: string;
|
|
205
|
+
tools: string[];
|
|
206
|
+
permissions: string;
|
|
207
|
+
turns: number;
|
|
208
|
+
tokens: number;
|
|
209
|
+
sessionId: string;
|
|
210
|
+
/** Whether the token count is estimated (any turn streamed without provider usage). Defaults to estimated. */
|
|
211
|
+
estimated?: boolean;
|
|
212
|
+
}): string;
|
|
213
|
+
/** Run a `!cmd` line and return its output — no model call. With `realShell` it shells out to a real
|
|
214
|
+
* /bin/sh (same executor as the agent's `Shell` tool, so `!open`/`!docker`/`!git` work); otherwise it
|
|
215
|
+
* runs over the wcli VFS emulator (sandbox/boddb — a real shell would escape the in-memory/db isolation). */
|
|
216
|
+
declare function runShellLine(fs: IFilesystem, cmd: string, opts?: {
|
|
217
|
+
realShell?: boolean;
|
|
218
|
+
cwd?: string;
|
|
219
|
+
}): Promise<string>;
|
|
220
|
+
/** Append a `#note` to the memory index (creating the dir/file if needed). Returns the file path. */
|
|
221
|
+
declare function appendMemoryNote(fs: IFilesystem, dir: string, text: string): Promise<string>;
|
|
222
|
+
interface PermMode {
|
|
223
|
+
gate: 'ask' | 'allow';
|
|
224
|
+
notice?: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Default permission posture — CC-inspired: **ask when a human can answer, allow when unattended.**
|
|
228
|
+
* Pure + exported so the decision is unit-testable without a TTY. Precedence:
|
|
229
|
+
* --yes → allow (explicit trust, no prompts)
|
|
230
|
+
* --ask → ask (explicit gate, even headless)
|
|
231
|
+
* interactive (TTY & not json) → ask (the safe default)
|
|
232
|
+
* else (headless/piped) → allow, with a one-line notice so it's never silent.
|
|
233
|
+
*/
|
|
234
|
+
declare function resolvePermMode(args: {
|
|
235
|
+
yes?: boolean;
|
|
236
|
+
ask?: boolean;
|
|
237
|
+
outputFormat?: string;
|
|
238
|
+
}, interactiveCapable: boolean): PermMode;
|
|
239
|
+
/** Extract `@ref` mentions: bare `@path` (no spaces) or quoted `@"path with spaces"` — the quoted
|
|
240
|
+
* form is what lets a drag-dropped macOS screenshot ("Screenshot 2026-06-11 at ….png") attach at all.
|
|
241
|
+
* Bare refs get trailing sentence punctuation stripped (e.g. "@a.ts." / "@a.ts?"). */
|
|
242
|
+
declare function mentionRefs(line: string): string[];
|
|
243
|
+
/** Read `@image.png` mentions from `line` as base64 image content parts (real files under cwd; binary,
|
|
244
|
+
* so read via node fs — the VFS readFile is utf8). Unreadable/missing images are skipped silently
|
|
245
|
+
* (expandMentions reports the missing @ref separately). */
|
|
246
|
+
declare function readImageParts(cwd: string, line: string): ContentPart[];
|
|
247
|
+
/** Classify a pasted blob as a file attachment when it's a drag-dropped/typed path to an existing file.
|
|
248
|
+
* Returns an `@<abs>` ref the existing mention pipeline attaches (images) or inlines (other files); the
|
|
249
|
+
* in-buffer placeholder shows `[Image #N]` / `[File name #N]`. Returns null for anything not a clear single
|
|
250
|
+
* path (so ordinary text pastes are unaffected). Paths with spaces are skipped — the `@\S+` pipeline can't carry them. */
|
|
251
|
+
declare function pastePathClassifier(cwd: string): PasteClassifier;
|
|
252
|
+
/** Inline `@path` file mentions: append referenced files' contents so the model sees them (missing → warn, leave as-is). */
|
|
253
|
+
/** Resolves an `@server:uri` MCP-resource mention to its text body; null = not an MCP ref (fall through
|
|
254
|
+
* to file resolution). Set by the REPL once servers are mounted; headless runs leave it unset. */
|
|
255
|
+
declare let mcpMentionResolver: ((ref: string) => Promise<string | null>) | undefined;
|
|
256
|
+
declare function setMcpMentionResolver(fn: typeof mcpMentionResolver): void;
|
|
257
|
+
declare function expandMentions(fs: IFilesystem, line: string): Promise<{
|
|
258
|
+
text: string;
|
|
259
|
+
loaded: string[];
|
|
260
|
+
missing: string[];
|
|
261
|
+
}>;
|
|
262
|
+
/** The headless `--output-format json` result object for a turn. */
|
|
263
|
+
declare function jsonResult(res: RunResult, session: SessionData): {
|
|
264
|
+
error?: any;
|
|
265
|
+
ok: boolean;
|
|
266
|
+
finishReason: "error" | "budget" | "stop" | "max_steps" | "timeout" | "loop" | "max_tool_calls" | "aborted";
|
|
267
|
+
text: string;
|
|
268
|
+
steps: number;
|
|
269
|
+
tools: number;
|
|
270
|
+
usage: {
|
|
271
|
+
promptTokens: number;
|
|
272
|
+
completionTokens: number;
|
|
273
|
+
totalTokens: number;
|
|
274
|
+
cacheCreationTokens?: number;
|
|
275
|
+
cacheReadTokens?: number;
|
|
276
|
+
} | undefined;
|
|
277
|
+
sessionId: string;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Read one logical input, supporting `\`-continuation for multi-line prompts: a line ending in
|
|
281
|
+
* a backslash drops the `\` and keeps reading; the parts are joined with newlines. `readLine`
|
|
282
|
+
* is injected (the REPL passes a readline `question`; tests pass a scripted reader).
|
|
283
|
+
*/
|
|
284
|
+
declare function readMultiline(readLine: (continuing: boolean) => Promise<string | null>): Promise<string | null>;
|
|
285
|
+
/** Send one turn (expanding @file mentions), print the footer, persist the session.
|
|
286
|
+
* `sendFn` overrides how the turn is dispatched (duplex routes through dx.send's mutex); `agent`
|
|
287
|
+
* stays the transcript-owning agent (the voice, in duplex) — mentions/fs/signal/cost read off it. */
|
|
288
|
+
declare function runTurn(agent: Agent, store: SessionStore, session: SessionData, task: string, cp?: Checkpoints, cwd?: string, sendFn?: (content: MessageContent) => Promise<RunResult>): Promise<{
|
|
289
|
+
ok: boolean;
|
|
290
|
+
res?: RunResult;
|
|
291
|
+
}>;
|
|
292
|
+
|
|
293
|
+
export { type PermMode, abortActiveTurn, appendMemoryNote, cacheMultipliers, condenseReplay, costOf, estimateTranscriptTokens, expandMentions, exportMarkdown, fmtUsd, formatHistory, formatStatus, formatTranscriptFull, jsonResult, mcpMentionResolver, mentionRefs, parseArgs, pastePathClassifier, readImageParts, readMultiline, resolvePermMode, runShellLine, runTurn, setMcpMentionResolver, summarizeResult };
|