A client of `lembas serve --stdio`, in vscode/: plain JavaScript, no dependencies, no build. scripts/package-vscode.sh writes the .vsix with Node alone; the version comes from VERSION. - Chat in a side bar view: transcript, mode, the session's model, Stop, new session. Approval cards are answered there; one that carries ACP diff content opens the editor's diff view before the answer. - Ask about a selection, with the editor context as _meta.lembas.editor. - Rewrite a selection through _lembas/edit: proposed changes with Accept / Reject per change and for all, and a diff beside the file. Nothing is written before it is accepted. - Autocomplete as an inline completion provider on _lembas/complete: debounced, the request before cancelled by its own id, a cancelled or stale answer shown as nothing. No model chosen: said once, with a button that opens the picker. - The two model settings through _lembas/editor/settings, and a quick switch for the window that is saved nowhere. - Files the agent shows (_lembas/show, _lembas/show/read): pictures in the chat, anything else a line with Open, under a size limit. - fs/read_text_file answered from the open document. Model output is untrusted: the extension's own Markdown reader makes a tree of plain objects and the page builds elements and text from it, under a Content-Security-Policy with one nonce'd script. Tests (scripts/test-vscode.sh, node --test): the modules in src/ against a stand-in agent, the package's structure, and extension.js against an in-memory stand-in for the editor's API. Nothing was run inside VS Code. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
'use strict';
|
|
// Shared by the tests: the stand-in agent, a place for files, and reading what the agent was sent.
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const { Agent } = require('../src/agent');
|
|
const { Chat } = require('../src/chat');
|
|
|
|
const FAKE = path.join(__dirname, 'fake_agent.py');
|
|
|
|
function tempDir(t) {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'llembas-vscode-test-'));
|
|
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
return dir;
|
|
}
|
|
|
|
/** An Agent on the stand-in. `env` adds to the environment; the log of what it received is `agent.log()`. */
|
|
function fakeAgent(t, dir, env, more) {
|
|
const logFile = path.join(dir, `agent-${Math.random().toString(36).slice(2)}.log`);
|
|
const agent = new Agent({
|
|
command: 'python3',
|
|
args: [FAKE],
|
|
cwd: dir,
|
|
env: { ...process.env, PYTHONDONTWRITEBYTECODE: '1', FAKE_AGENT_LOG: logFile, ...(env || {}) },
|
|
clientInfo: { name: 'test', version: '0' },
|
|
...(more || {}),
|
|
});
|
|
agent.log = () => (fs.existsSync(logFile) ? fs.readFileSync(logFile, 'utf8').split('\n').filter(Boolean).map((l) => JSON.parse(l)) : []);
|
|
t.after(() => agent.stop());
|
|
return agent;
|
|
}
|
|
|
|
/** A Chat on the stand-in. Returns `{ chat, agents, dir }`; `agents` fills as the chat starts them. */
|
|
function fakeChat(t, options) {
|
|
const o = options || {};
|
|
const dir = o.dir || tempDir(t);
|
|
const agents = [];
|
|
const chat = new Chat({
|
|
makeAgent: (m) => {
|
|
const a = fakeAgent(t, dir, o.env, { cwd: m.cwd, onRequest: m.onRequest, ...(o.agent || {}) });
|
|
agents.push(a);
|
|
return a;
|
|
},
|
|
cwd: () => dir,
|
|
options: () => o.options || {},
|
|
hooks: o.hooks || {},
|
|
});
|
|
t.after(() => chat.dispose());
|
|
return { chat, agents, dir };
|
|
}
|
|
|
|
/** Wait until `test()` is true (checked every few milliseconds). */
|
|
async function until(test, ms) {
|
|
const end = Date.now() + (ms || 8000);
|
|
for (;;) {
|
|
if (test()) return true;
|
|
if (Date.now() > end) throw new Error('waited too long for: ' + test);
|
|
await new Promise((r) => setTimeout(r, 10));
|
|
}
|
|
}
|
|
|
|
const text = (chat) =>
|
|
chat.items
|
|
.map((i) => {
|
|
if (i.kind === 'user') return `You: ${i.label ? '[' + i.label + '] ' : ''}${i.text}`;
|
|
if (i.kind === 'agent') return `LLeMbas: ${i.text}`;
|
|
if (i.kind === 'thought') return `Thinking: ${i.text}`;
|
|
if (i.kind === 'note') return `> ${i.text}`;
|
|
if (i.kind === 'tool') return `tool ${i.status}: ${i.title}`;
|
|
if (i.kind === 'card') return `card ${i.state}: ${i.title} (${i.answer})`;
|
|
if (i.kind === 'media') return `media: ${i.name}`;
|
|
return i.kind;
|
|
})
|
|
.join('\n');
|
|
|
|
module.exports = { FAKE, tempDir, fakeAgent, fakeChat, until, text };
|