klui-code 0.1.6 → 0.1.7
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/README.md +14 -7
- package/dist/cli.js +3 -1
- package/dist/extension/agents.js +35 -1
- package/dist/extension/events.js +13 -0
- package/dist/extension/todos.js +11 -0
- package/dist/fallback.js +22 -8
- package/dist/pi-patches.js +34 -3
- package/dist/update.js +7 -1
- package/dist/usage.js +2 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Klui Code
|
|
2
2
|
|
|
3
3
|
Klui in your terminal: a pixel-cute coding agent for the Klui hackathon. It reads, edits and runs
|
|
4
|
-
code in your project, and it's free for attendees: inference runs on
|
|
4
|
+
code in your project, and it's free for attendees: inference runs on
|
|
5
|
+
[Surplus](https://www.surplusintelligence.ai), with [AntSeed](https://antseed.com) as the backup,
|
|
5
6
|
and Klui covers the bill.
|
|
6
7
|
|
|
7
8
|
```
|
|
@@ -81,15 +82,21 @@ in `~/.klui` and never touches an existing pi setup.
|
|
|
81
82
|
```
|
|
82
83
|
klui ──(1) device id──▶ Klui Pass ──▶ key from a pre-made pool
|
|
83
84
|
│
|
|
84
|
-
└──(2) chat + tools, Bearer <key>──▶
|
|
85
|
+
└──(2) chat + tools, Bearer <key>──▶ Klui router ──▶ Surplus (Klui's key)
|
|
86
|
+
│ after two failures
|
|
87
|
+
└──▶ AntSeed gateway ──▶ AntSeed buyer (event wallet) ──▶ sellers
|
|
85
88
|
```
|
|
86
89
|
|
|
87
|
-
- **
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
- **Klui's router** (`server/router.mjs`) is the only way in. It serves just the event's models, from
|
|
91
|
+
Surplus with Klui's one key (which never leaves the server), and moves a request to AntSeed when
|
|
92
|
+
Surplus fails it twice. A conversation AntSeed took over stays there while its prompt is cached
|
|
93
|
+
on that seller.
|
|
94
|
+
- **One funded account per provider.** Klui runs a single AntSeed buyer holding the event wallet,
|
|
95
|
+
behind AntSeed's own API-key gateway. Every attendee key is paid by that one wallet, and each
|
|
96
|
+
key's spend cap covers what it spends on Surplus and AntSeed together.
|
|
90
97
|
- **Klui Pass** (`server/`) hands each device a key from a pool and serves the event's model list,
|
|
91
98
|
so models can change mid-event without a new release. It never sees prompts or code: klui talks to
|
|
92
|
-
the
|
|
99
|
+
the router directly.
|
|
93
100
|
- **The CLI** is pi with one extension (`src/extension/`): the `klui` provider, the pixel header,
|
|
94
101
|
the working line (a shimmering phrase, the time and tokens in one small box), the footer, labeled tool
|
|
95
102
|
rows, the `subagent` tool (each subagent is a child `klui --mode json` process), `/klui`,
|
|
@@ -119,7 +126,7 @@ it for global installs, so transitive packages can still move within their own s
|
|
|
119
126
|
|---|---|
|
|
120
127
|
| `KLUI_PASS_URL` | Klui Pass to use (default `https://klui.ai/code/pass`) |
|
|
121
128
|
| `KLUI_HOME` | where klui keeps its state (default `~/.klui`) |
|
|
122
|
-
| `KLUI_API_KEY`, `KLUI_BASE_URL` | skip Pass and use this AntSeed gateway
|
|
129
|
+
| `KLUI_API_KEY`, `KLUI_BASE_URL` | skip Pass and use this key and router (or AntSeed gateway) directly |
|
|
123
130
|
| `KLUI_REDUCED_MOTION=1` | no animations |
|
|
124
131
|
|
|
125
132
|
To try the whole flow locally against free AntSeed sellers, run an AntSeed buyer and gateway, make
|
package/dist/cli.js
CHANGED
|
@@ -113,7 +113,9 @@ async function run() {
|
|
|
113
113
|
const loaded = loadConfig();
|
|
114
114
|
seedSettings(loaded.config, pi.VERSION);
|
|
115
115
|
seedKeybindings();
|
|
116
|
-
|
|
116
|
+
// Pi's own parser, so a repeated --mode counts the way Pi counts it (the last one wins).
|
|
117
|
+
const { mode } = pi.parseArgs(args);
|
|
118
|
+
await patchPi(loaded.config, mode === "json" || mode === "rpc");
|
|
117
119
|
const { createKluiExtension } = await import("./extension/index.js");
|
|
118
120
|
await pi.main([...args, "--theme", THEMES_DIR], {
|
|
119
121
|
extensionFactories: [{ name: "klui", factory: createKluiExtension(loaded), hidden: true }],
|
package/dist/extension/agents.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// an IPC channel, and the dialog shows here. Its chat is saved in KLUI_HOME/subagents (only the
|
|
15
15
|
// newest few, for a week), and the result names the file, so `klui --session <file>` opens it.
|
|
16
16
|
import { spawn } from "node:child_process";
|
|
17
|
+
import { randomUUID } from "node:crypto";
|
|
17
18
|
import { mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
18
19
|
import { join } from "node:path";
|
|
19
20
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
@@ -23,6 +24,7 @@ import { Type } from "typebox";
|
|
|
23
24
|
import { KLUI_HOME, PACKAGE_DIR, PROVIDER } from "../paths.js";
|
|
24
25
|
import { PARENT_SESSION_ENV } from "../usage.js";
|
|
25
26
|
import { ASK_PARENT, decide, PERMISSIONS_ENV } from "./permissions.js";
|
|
27
|
+
import { emitEvent, eventsWanted } from "./events.js";
|
|
26
28
|
import { state } from "./state.js";
|
|
27
29
|
import { preparingLabel, shortPath } from "./voice.js";
|
|
28
30
|
/** Set in a subagent's environment: subagents don't start subagents of their own. */
|
|
@@ -90,6 +92,7 @@ export function registerAgents(pi) {
|
|
|
90
92
|
],
|
|
91
93
|
parameters: Type.Object({
|
|
92
94
|
task: Type.String({ description: "Everything the subagent needs: the goal, relevant paths and what to report back" }),
|
|
95
|
+
title: Type.Optional(Type.String({ description: "3 to 6 words naming the task for the user, like \"Find ModelManifest usages\"" })),
|
|
93
96
|
kind: Type.Optional(StringEnum(["explore", "general"], { description: "explore (read-only files and web, default) or general (can edit and run commands)" })),
|
|
94
97
|
model: Type.Optional(Type.String({ description: "Only when the user asks for a different model: its id or name. Leave it out to use your own model" })),
|
|
95
98
|
background: Type.Optional(Type.Boolean({ description: "Return right away and deliver the report as a message later" })),
|
|
@@ -102,16 +105,30 @@ export function registerAgents(pi) {
|
|
|
102
105
|
const model = params.model ? resolveModel(params.model) : (own ?? resolveModel(state.config.defaultModel));
|
|
103
106
|
const run = { model: `${PROVIDER}/${model.id}`, thinking: pi.getThinkingLevel() };
|
|
104
107
|
const startedAt = Date.now();
|
|
105
|
-
const
|
|
108
|
+
const title = params.title?.trim() || undefined;
|
|
109
|
+
const details = { kind, task: params.task, ...(title ? { title } : {}), model: model.name, tools: 0, tokens: 0, steps: [], progress: "starting up", startedAt, elapsedMs: 0 };
|
|
106
110
|
if (params.background) {
|
|
107
111
|
ui = ctx.hasUI ? ctx.ui : undefined;
|
|
112
|
+
// An app running Klui over RPC can't see background agents otherwise: no tool call follows them.
|
|
113
|
+
const app = eventsWanted(ctx) ? ctx.ui : undefined;
|
|
108
114
|
const id = nextId++;
|
|
109
115
|
const controller = new AbortController();
|
|
110
116
|
details.background = id;
|
|
117
|
+
details.run = randomUUID();
|
|
111
118
|
running.set(id, { controller, details });
|
|
112
119
|
showRunning();
|
|
120
|
+
let reportedAt = 0;
|
|
121
|
+
const report = (status, error) => {
|
|
122
|
+
reportedAt = Date.now();
|
|
123
|
+
if (app)
|
|
124
|
+
emitEvent(app, { type: "agent", id, run: details.run, kind, task: params.task, status, progress: status === "running" ? details.progress : undefined, error, transcript: details.transcript });
|
|
125
|
+
};
|
|
113
126
|
let shownAt = 0;
|
|
127
|
+
// After runAgent has named the transcript, so the app can follow it from the start.
|
|
128
|
+
queueMicrotask(() => report("running"));
|
|
114
129
|
void runAgent(ctx, kind, run, params.task, controller.signal, details, () => {
|
|
130
|
+
if (Date.now() - reportedAt >= 1000)
|
|
131
|
+
report("running");
|
|
115
132
|
if (Date.now() - shownAt < 250)
|
|
116
133
|
return;
|
|
117
134
|
shownAt = Date.now();
|
|
@@ -119,6 +136,7 @@ export function registerAgents(pi) {
|
|
|
119
136
|
}).then((outcome) => {
|
|
120
137
|
running.delete(id);
|
|
121
138
|
showRunning();
|
|
139
|
+
report(controller.signal.aborted ? "canceled" : outcome.error ? "failed" : "completed", outcome.error);
|
|
122
140
|
if (controller.signal.aborted)
|
|
123
141
|
return;
|
|
124
142
|
const done = { ...details, progress: undefined, error: outcome.error, elapsedMs: Date.now() - startedAt };
|
|
@@ -203,6 +221,22 @@ export function registerAgents(pi) {
|
|
|
203
221
|
}
|
|
204
222
|
return row;
|
|
205
223
|
});
|
|
224
|
+
pi.registerCommand("stop-agents", {
|
|
225
|
+
description: "Stop the background agents, or just the one numbered (/stop-agents 2)",
|
|
226
|
+
handler: async (args, ctx) => {
|
|
227
|
+
const wanted = args.trim();
|
|
228
|
+
const stopping = [...running].filter(([id]) => wanted === "" || String(id) === wanted.replace(/^#/, ""));
|
|
229
|
+
for (const [, { controller }] of stopping)
|
|
230
|
+
controller.abort();
|
|
231
|
+
// The app follows them through their events, which report each one as canceled.
|
|
232
|
+
if (eventsWanted(ctx))
|
|
233
|
+
return;
|
|
234
|
+
if (stopping.length === 0)
|
|
235
|
+
ctx.ui.notify(wanted === "" ? "No background agents are running." : `No background agent #${wanted.replace(/^#/, "")} is running.`, "info");
|
|
236
|
+
else
|
|
237
|
+
ctx.ui.notify(`Stopped ${stopping.length === 1 ? `background agent #${stopping[0][0]}` : `${stopping.length} background agents`}.`, "info");
|
|
238
|
+
},
|
|
239
|
+
});
|
|
206
240
|
pi.on("session_shutdown", async () => {
|
|
207
241
|
for (const { controller } of running.values())
|
|
208
242
|
controller.abort();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Klui's state for a desktop or mobile app that runs Klui over RPC (`klui --mode rpc`). Pi's RPC
|
|
2
|
+
// stream carries chat, tools and dialogs, but not what Klui draws in the terminal (the task list,
|
|
3
|
+
// background agents), so those go out as notify messages: one line, `klui:v1 ` then JSON.
|
|
4
|
+
// Only when the host asks with KLUI_EVENTS=1, so other RPC hosts never see them as notices.
|
|
5
|
+
export const EVENTS_ENV = "KLUI_EVENTS";
|
|
6
|
+
export const EVENT_PREFIX = "klui:v1 ";
|
|
7
|
+
/** Whether this session reports its state to an app. */
|
|
8
|
+
export function eventsWanted(ctx) {
|
|
9
|
+
return process.env[EVENTS_ENV] === "1" && ctx.mode === "rpc" && ctx.hasUI;
|
|
10
|
+
}
|
|
11
|
+
export function emitEvent(ui, event) {
|
|
12
|
+
ui.notify(`${EVENT_PREFIX}${JSON.stringify(event)}`, "info");
|
|
13
|
+
}
|
package/dist/extension/todos.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
6
6
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
|
+
import { emitEvent, eventsWanted } from "./events.js";
|
|
8
9
|
const ENTRY = "klui-todos";
|
|
9
10
|
const WIDGET = "klui-todos";
|
|
10
11
|
/** Task rows the panel shows before "+N more". */
|
|
@@ -13,15 +14,23 @@ export function registerTodos(pi) {
|
|
|
13
14
|
let todos = [];
|
|
14
15
|
let changedThisRun = false;
|
|
15
16
|
let ui;
|
|
17
|
+
/** An app running Klui over RPC (see events.ts), which draws the list itself. */
|
|
18
|
+
let app;
|
|
16
19
|
const show = () => {
|
|
17
20
|
if (!ui)
|
|
18
21
|
return;
|
|
19
22
|
const visible = todos.length > 0 && (changedThisRun || todos.some((t) => t.status !== "completed"));
|
|
20
23
|
ui.setWidget(WIDGET, visible ? (_tui, theme) => ({ render: (width) => todoPanel(todos, theme, width), invalidate() { } }) : undefined);
|
|
21
24
|
};
|
|
25
|
+
/** Tell the app the list changed: a call from a codemode script has no `todo` result to read. */
|
|
26
|
+
const report = () => {
|
|
27
|
+
if (app)
|
|
28
|
+
emitEvent(app, { type: "todos", todos });
|
|
29
|
+
};
|
|
22
30
|
const restore = (ctx) => {
|
|
23
31
|
todos = lastTodos(ctx.sessionManager.getBranch());
|
|
24
32
|
show();
|
|
33
|
+
report();
|
|
25
34
|
};
|
|
26
35
|
pi.registerTool({
|
|
27
36
|
name: "todo",
|
|
@@ -48,11 +57,13 @@ export function registerTodos(pi) {
|
|
|
48
57
|
// session as a tool result.
|
|
49
58
|
pi.appendEntry(ENTRY, { todos });
|
|
50
59
|
show();
|
|
60
|
+
report();
|
|
51
61
|
return { content: [{ type: "text", text: summary(todos) }], details: { todos } };
|
|
52
62
|
},
|
|
53
63
|
});
|
|
54
64
|
pi.on("session_start", async (_event, ctx) => {
|
|
55
65
|
ui = ctx.mode === "tui" ? ctx.ui : undefined;
|
|
66
|
+
app = eventsWanted(ctx) ? ctx.ui : undefined;
|
|
56
67
|
changedThisRun = false;
|
|
57
68
|
restore(ctx);
|
|
58
69
|
});
|
package/dist/fallback.js
CHANGED
|
@@ -39,12 +39,13 @@ export const PROVIDER_ISSUE = "Klui had a model provider issue. Please retry.";
|
|
|
39
39
|
/**
|
|
40
40
|
* A peer that hasn't started answering by now is treated as gone (some hang without a word, others
|
|
41
41
|
* send headers and then nothing). Long prompts get longer: reading an uncached 900K-token
|
|
42
|
-
* conversation alone takes a peer 20-30 s.
|
|
42
|
+
* conversation alone takes a peer 20-30 s. Klui's router spends the first part of this on Surplus
|
|
43
|
+
* before it moves the request to AntSeed (see server/router.mjs), which gets the rest.
|
|
43
44
|
*/
|
|
44
45
|
export function answerTimeoutMs(context) {
|
|
45
46
|
// About 4 characters a token; image data is left out, since a picture costs far fewer tokens than its base64.
|
|
46
47
|
const tokens = JSON.stringify(context, (key, value) => (key === "data" ? undefined : value)).length / 4;
|
|
47
|
-
return
|
|
48
|
+
return 45_000 + Math.round((tokens / 100_000) * 10_000);
|
|
48
49
|
}
|
|
49
50
|
/** The service name in a gateway model id: "<peerId>@deepseek-v4.1-flash" → "deepseek-v4.1-flash". */
|
|
50
51
|
export function serviceOf(id) {
|
|
@@ -52,13 +53,20 @@ export function serviceOf(id) {
|
|
|
52
53
|
return at === -1 ? id : id.slice(at + 1);
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
56
|
-
* that
|
|
56
|
+
* Klui's router names a reply Surplus wrote `surplus@<service>` (see server/router.mjs). Pi keeps
|
|
57
|
+
* that as the reply's response model, since it isn't the id klui asked for.
|
|
58
|
+
*/
|
|
59
|
+
const SURPLUS = "surplus@";
|
|
60
|
+
/**
|
|
61
|
+
* The reply keeps the event model's id, so a resumed chat finds its model again, and names who
|
|
62
|
+
* answered as the response model, for the usage log: Surplus, or the peer klui picked
|
|
63
|
+
* (`<peer>@<service>`).
|
|
57
64
|
*/
|
|
58
65
|
function sellerAside(event, id) {
|
|
59
66
|
const reply = event.type === "done" ? event.message : event.type === "error" ? event.error : "partial" in event ? event.partial : undefined;
|
|
60
67
|
if (reply && reply.model !== id) {
|
|
61
|
-
reply.responseModel
|
|
68
|
+
if (!reply.responseModel?.startsWith(SURPLUS))
|
|
69
|
+
reply.responseModel = reply.model;
|
|
62
70
|
reply.model = id;
|
|
63
71
|
}
|
|
64
72
|
return event;
|
|
@@ -66,12 +74,15 @@ function sellerAside(event, id) {
|
|
|
66
74
|
/**
|
|
67
75
|
* Pi replays a reply's reasoning only to the model that wrote it, by id. Replies keep the event
|
|
68
76
|
* model's id (see sellerAside), so a copy of the chat names the seller again on the replies that
|
|
69
|
-
* seller wrote, as it did when replies kept the seller's id.
|
|
77
|
+
* seller wrote, as it did when replies kept the seller's id. Surplus's replies count as this
|
|
78
|
+
* seller's too: the router sends klui's requests to Surplus whichever seller klui picked, and it's
|
|
79
|
+
* the same model either way.
|
|
70
80
|
*/
|
|
71
81
|
function asSeller(context, attempt) {
|
|
72
|
-
|
|
82
|
+
const mine = (m) => m.role === "assistant" && (m.responseModel === attempt || (!!m.responseModel?.startsWith(SURPLUS) && serviceOf(m.responseModel) === serviceOf(attempt)));
|
|
83
|
+
if (!context.messages.some(mine))
|
|
73
84
|
return context;
|
|
74
|
-
return { ...context, messages: context.messages.map((m) => (m
|
|
85
|
+
return { ...context, messages: context.messages.map((m) => (mine(m) ? { ...m, model: attempt } : m)) };
|
|
75
86
|
}
|
|
76
87
|
/** A failure whose own message is for the user (Klui can't connect, say), not a provider's. */
|
|
77
88
|
class ForTheUser extends Error {
|
|
@@ -149,6 +160,9 @@ function rank(all) {
|
|
|
149
160
|
export function worthAnotherPeer(message) {
|
|
150
161
|
if (!message)
|
|
151
162
|
return false;
|
|
163
|
+
// AntSeed preserves a seller's 403 even when the gateway key is valid.
|
|
164
|
+
if (/^\s*403\b/.test(message) && /"antseed_fault"\s*:\s*"peer"/.test(message) && /"code"\s*:\s*"upstream_unavailable"/.test(message))
|
|
165
|
+
return true;
|
|
152
166
|
if (/^\s*(400|401|403)\b/.test(message) || /invalid_api_key|abort/i.test(message))
|
|
153
167
|
return false;
|
|
154
168
|
return /^\s*(402|404|408|409|429|5\d\d)\b/.test(message) || /insufficient_deposits|not reachable|does not support|no peer|timed? ?out|ECONN|fetch failed/i.test(message);
|
package/dist/pi-patches.js
CHANGED
|
@@ -7,11 +7,13 @@ import { chipFor, isClipboardImageFile } from "./images.js";
|
|
|
7
7
|
import { PROVIDER } from "./paths.js";
|
|
8
8
|
import { scrollFrame } from "./scroll.js";
|
|
9
9
|
export const piModule = async (path) => (await import(new URL(path, import.meta.resolve("@earendil-works/pi-coding-agent")).href));
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** `machineOutput`: `--mode json` or `rpc`, where every stdout line is JSON for another program to parse. */
|
|
11
|
+
export async function patchPi(config, machineOutput = false) {
|
|
12
|
+
if (!machineOutput)
|
|
13
|
+
brandOutput();
|
|
12
14
|
scrollWithTerminal();
|
|
13
15
|
clearAfterCopy();
|
|
14
|
-
for (const patch of [() => sellerModelIds(config), retryProviderIssues, removeLlama, hidePiFooter, hoverJumpToLatest, queuedMessages, trimSlashMenu, slashAliases, simpleThinkingMenu, thinkingAfterModel, () => tidyModelPicker(), () => quietPiHints(config), pasteImageChips])
|
|
16
|
+
for (const patch of [() => sellerModelIds(config), retryProviderIssues, removeLlama, hidePiFooter, hoverJumpToLatest, queuedMessages, trimSlashMenu, slashAliases, simpleThinkingMenu, thinkingAfterModel, () => tidyModelPicker(), () => quietPiHints(config), pasteImageChips, quietImageNotes])
|
|
15
17
|
await patch().catch(() => { });
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -48,6 +50,18 @@ async function retryProviderIssues() {
|
|
|
48
50
|
proto._isRetryableError = function (message) {
|
|
49
51
|
return message.errorMessage === PROVIDER_ISSUE || isRetryable.call(this, message);
|
|
50
52
|
};
|
|
53
|
+
const { InteractiveMode } = await piModule("./modes/interactive/interactive-mode.js");
|
|
54
|
+
const handle = InteractiveMode.prototype.handleEvent;
|
|
55
|
+
if (typeof handle !== "function")
|
|
56
|
+
return;
|
|
57
|
+
InteractiveMode.prototype.handleEvent = function (event) {
|
|
58
|
+
const retry = this.settingsManager.getRetrySettings();
|
|
59
|
+
if (event.type === "message_end" && event.message?.role === "assistant" && event.message.errorMessage === PROVIDER_ISSUE && retry.enabled && this.session.retryAttempt < retry.maxRetries) {
|
|
60
|
+
// Change only the display copy: Pi still recognises the original error for retries.
|
|
61
|
+
event = { ...event, message: { ...event.message, errorMessage: "Klui had a model provider issue. Retrying…" } };
|
|
62
|
+
}
|
|
63
|
+
return handle.call(this, event);
|
|
64
|
+
};
|
|
51
65
|
}
|
|
52
66
|
/** Klui uses event models, so don't load Pi's local llama.cpp manager or its /llama command. */
|
|
53
67
|
async function removeLlama() {
|
|
@@ -329,6 +343,23 @@ async function quietPiHints(config) {
|
|
|
329
343
|
showStatus.call(this, name ? `${match[1] === "Model" ? "Using" : "Default is now"} ${name}` : message);
|
|
330
344
|
};
|
|
331
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Pi shrinks a large pasted image and adds a note to the prompt's text ("[Image: original 2086x1416,
|
|
348
|
+
* displayed at 2000x1358. Multiply coordinates by…]", or "[Image converted from…]"), which is then
|
|
349
|
+
* saved and shown as part of what the person typed. Klui never maps pixel coordinates, so drop
|
|
350
|
+
* those notes. Keep "[Image omitted…]": the model should know an image didn't reach it.
|
|
351
|
+
*/
|
|
352
|
+
async function quietImageNotes() {
|
|
353
|
+
const { AgentSession } = await piModule("./core/agent-session.js");
|
|
354
|
+
const proto = AgentSession.prototype;
|
|
355
|
+
const normalize = proto._normalizePromptImages;
|
|
356
|
+
if (typeof normalize !== "function")
|
|
357
|
+
return;
|
|
358
|
+
proto._normalizePromptImages = async function (images) {
|
|
359
|
+
const normalized = await normalize.call(this, images);
|
|
360
|
+
return { ...normalized, hints: normalized.hints.filter((hint) => hint.startsWith("[Image omitted")) };
|
|
361
|
+
};
|
|
362
|
+
}
|
|
332
363
|
/** ctrl+v with an image on the clipboard puts an "[Image #1]" chip in the composer, not a temp path. */
|
|
333
364
|
async function pasteImageChips() {
|
|
334
365
|
const { InteractiveMode } = await piModule("./modes/interactive/interactive-mode.js");
|
package/dist/update.js
CHANGED
|
@@ -16,6 +16,9 @@ export function installKind(dir = PACKAGE_DIR) {
|
|
|
16
16
|
// npm folder has none.
|
|
17
17
|
try {
|
|
18
18
|
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
19
|
+
// The copy bundled inside Klui Code desktop, which updates with the app.
|
|
20
|
+
if (pkg?.kluiDesktop === true)
|
|
21
|
+
return { kind: "desktop" };
|
|
19
22
|
if (pkg?.dependencies?.[PACKAGE])
|
|
20
23
|
return { kind: "prefix", root };
|
|
21
24
|
}
|
|
@@ -56,6 +59,8 @@ export async function update(onStart = () => { }) {
|
|
|
56
59
|
const install = installKind();
|
|
57
60
|
if (install.kind === "source")
|
|
58
61
|
return { status: "failed", message: "This klui runs from a source checkout. Update it with git pull && npm install." };
|
|
62
|
+
if (install.kind === "desktop")
|
|
63
|
+
return { status: "failed", message: "This klui comes with the Klui Code desktop app. Update it with the update button in the app's sidebar." };
|
|
59
64
|
const latest = await latestVersion(10_000);
|
|
60
65
|
if (!latest)
|
|
61
66
|
return { status: "failed", message: "Couldn't reach the npm registry. Check your connection and try again." };
|
|
@@ -77,7 +82,8 @@ export async function update(onStart = () => { }) {
|
|
|
77
82
|
* ~/.klui). Undefined when up to date, offline, or running from source.
|
|
78
83
|
*/
|
|
79
84
|
export async function availableUpdate() {
|
|
80
|
-
|
|
85
|
+
const kind = installKind().kind;
|
|
86
|
+
if (kind === "source" || kind === "desktop")
|
|
81
87
|
return undefined;
|
|
82
88
|
let latest;
|
|
83
89
|
try {
|
package/dist/usage.js
CHANGED
|
@@ -20,6 +20,7 @@ export const PARENT_SESSION_ENV = "KLUI_PARENT_SESSION";
|
|
|
20
20
|
export function recordUsage(streamSimple, agent = "main", paths = PATHS) {
|
|
21
21
|
return ((...args) => {
|
|
22
22
|
const start = Date.now();
|
|
23
|
+
const requested = args[0];
|
|
23
24
|
const options = args[2];
|
|
24
25
|
const session = process.env[PARENT_SESSION_ENV] || options?.sessionId;
|
|
25
26
|
const stream = streamSimple(...args);
|
|
@@ -39,7 +40,7 @@ export function recordUsage(streamSimple, agent = "main", paths = PATHS) {
|
|
|
39
40
|
const end = Date.now();
|
|
40
41
|
const error = reply?.providerError || reply?.errorMessage;
|
|
41
42
|
const timing = { start, ttft: firstAt === undefined ? undefined : firstAt - start, ms: end - start };
|
|
42
|
-
appendEntry({ t: end, ...tokens(reply?.usage), model: reply?.responseModel ?? reply?.model, agent, ...timing, session, error: error?.slice(0, 1000) }, paths);
|
|
43
|
+
appendEntry({ t: end, ...tokens(reply?.usage), model: reply?.responseModel ?? reply?.model ?? requested?.id, requestedModel: requested?.id ?? reply?.model ?? reply?.responseModel, agent, ...timing, session, error: error?.slice(0, 1000) }, paths);
|
|
43
44
|
};
|
|
44
45
|
stream.result().then(log, () => log(undefined));
|
|
45
46
|
return stream;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "klui-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "klui-code",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.7",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@earendil-works/chord": "1.1.0",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "klui-code",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Klui Code: a pixel-cute coding agent for your terminal, built on Pi and running on AntSeed.",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "Klui Code: a pixel-cute coding agent for your terminal, built on Pi and running on Surplus and AntSeed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"klui",
|
|
7
7
|
"coding-agent",
|