@preapexis/honeycomb 0.0.0-stage → 1.1.0
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 +15 -0
- package/README.md +443 -2
- package/bin/bee.js +18 -0
- package/package.json +66 -4
- package/plan/tools/tool-parity.md +61 -0
- package/src/commands/btw.ts +95 -0
- package/src/commands/claude-migrate.ts +63 -0
- package/src/commands/diff.ts +119 -0
- package/src/commands/discovery.ts +112 -0
- package/src/commands/doctor.ts +80 -0
- package/src/commands/goal/index.ts +254 -0
- package/src/commands/goal/report.ts +66 -0
- package/src/commands/goal/state.ts +74 -0
- package/src/commands/hooks.ts +38 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/init.ts +66 -0
- package/src/commands/memory.ts +70 -0
- package/src/commands/plan.ts +36 -0
- package/src/commands/review-report.ts +23 -0
- package/src/commands/review.ts +21 -0
- package/src/commands/rewind-history.ts +40 -0
- package/src/commands/security-review.ts +138 -0
- package/src/commands/simplify.ts +21 -0
- package/src/commands/stats.ts +125 -0
- package/src/commands/tasks.ts +87 -0
- package/src/commands/verify.ts +21 -0
- package/src/commands/worktree.ts +138 -0
- package/src/config/bi.config.json +77 -0
- package/src/config/index.ts +47 -0
- package/src/config/limits.ts +12 -0
- package/src/config/path-rules.ts +19 -0
- package/src/config/project.ts +133 -0
- package/src/extension/ask-user.ts +52 -0
- package/src/extension/index.ts +4 -0
- package/src/extension/lsp-install.ts +95 -0
- package/src/extension/lsp-menu.ts +90 -0
- package/src/extension/permission-modes/index.ts +337 -0
- package/src/extension/permission-modes/mcp-resources.ts +21 -0
- package/src/extension/permission-modes/metadata.ts +18 -0
- package/src/extension/permission-modes/paths.ts +44 -0
- package/src/extension/permission-modes/plan-note.ts +58 -0
- package/src/extension/permission-modes/policy.ts +236 -0
- package/src/extension/permission-modes/preview.ts +104 -0
- package/src/extension/permission-modes/rules.ts +67 -0
- package/src/extension/permission-modes/shell.ts +183 -0
- package/src/extension/permission-modes/state.ts +6 -0
- package/src/extension/quiet-startup.ts +25 -0
- package/src/extension/register-tools.ts +312 -0
- package/src/extension/scoped-rules.ts +91 -0
- package/src/extension/system-instruction.ts +74 -0
- package/src/index.ts +71 -0
- package/src/tools/advanced.ts +133 -0
- package/src/tools/agent.ts +379 -0
- package/src/tools/dispatcher.ts +80 -0
- package/src/tools/executable.ts +15 -0
- package/src/tools/execution.ts +289 -0
- package/src/tools/filesystem.ts +662 -0
- package/src/tools/git.ts +196 -0
- package/src/tools/glob.ts +81 -0
- package/src/tools/grep.ts +203 -0
- package/src/tools/image-read.ts +71 -0
- package/src/tools/index.ts +52 -0
- package/src/tools/lsp-client.ts +104 -0
- package/src/tools/lsp.ts +172 -0
- package/src/tools/memory-store.ts +77 -0
- package/src/tools/notebook.ts +169 -0
- package/src/tools/registry.ts +31 -0
- package/src/tools/shells.ts +63 -0
- package/src/tools/todo.ts +119 -0
- package/src/tools/undo-journal.ts +46 -0
- package/src/tools/web-fetch.ts +119 -0
- package/src/tools/web-search.ts +76 -0
- package/src/tools/write-file.ts +14 -0
- package/src/tui/editor.ts +65 -0
- package/src/tui/footer-stats.ts +35 -0
- package/src/tui/header.ts +81 -0
- package/src/tui/index.ts +124 -0
- package/src/tui/mascot.ts +59 -0
- package/src/tui/permission-dialog.ts +94 -0
- package/src/tui/permission-rules.ts +64 -0
- package/src/tui/tasks-panel.ts +84 -0
- package/src/tui/text.ts +55 -0
- package/src/tui/tool-renderer.ts +42 -0
- package/src/tui/working-feedback.ts +220 -0
- package/src/types/agent.ts +54 -0
- package/src/types/common.ts +1 -0
- package/src/types/execution.ts +24 -0
- package/src/types/index.ts +4 -0
- package/src/types/tools.ts +61 -0
- package/themes/catppuccin-mocha.json +80 -0
- package/themes/github-dark.json +80 -0
- package/themes/honeycomb-dark.json +81 -0
- package/themes/honeycomb-light.json +81 -0
- package/themes/tokyo-day.json +80 -0
- package/themes/tokyo-night.json +80 -0
- package/themes/vercel-black.json +80 -0
- package/themes/vercel-light.json +80 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
const MAX_HEADER = 4096;
|
|
4
|
+
const MAX_BODY = 1024 * 1024;
|
|
5
|
+
const MAX_TRAFFIC = 4 * MAX_BODY;
|
|
6
|
+
|
|
7
|
+
export function object(value: unknown): Record<string, unknown> | undefined {
|
|
8
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** One private stdio connection per query. Never services server-initiated requests. */
|
|
12
|
+
export async function withLspClient<T>(server: string, cwd: string, signal: AbortSignal, query: (client: {
|
|
13
|
+
request(method: string, params?: unknown): Promise<unknown>;
|
|
14
|
+
notify(method: string, params?: unknown): void;
|
|
15
|
+
onNotification(handler: (message: Record<string, unknown>) => void): void;
|
|
16
|
+
}) => Promise<T>): Promise<T> {
|
|
17
|
+
signal.throwIfAborted();
|
|
18
|
+
const env = Object.fromEntries(['PATH', 'HOME', 'USERPROFILE', 'SYSTEMROOT', 'TMPDIR', 'TEMP', 'TMP', 'LANG', 'LC_ALL']
|
|
19
|
+
.map(key => [key, process.env[key]]).filter(([, value]) => value !== undefined));
|
|
20
|
+
const child = spawn(server, ['--stdio'], { cwd, env, detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'ignore'] });
|
|
21
|
+
let buffer = Buffer.alloc(0), length = 0, traffic = 0, id = 0;
|
|
22
|
+
let error: Error | undefined;
|
|
23
|
+
let notify: ((message: Record<string, unknown>) => void) | undefined;
|
|
24
|
+
const pending = new Map<number, { resolve(value: unknown): void; reject(error: Error): void }>();
|
|
25
|
+
let rejectConnection!: (error: Error) => void;
|
|
26
|
+
const connectionFailure = new Promise<never>((_, reject) => { rejectConnection = reject; });
|
|
27
|
+
const fail = (reason: string) => {
|
|
28
|
+
if (error) return;
|
|
29
|
+
error = new Error(reason);
|
|
30
|
+
for (const waiter of pending.values()) waiter.reject(error);
|
|
31
|
+
pending.clear();
|
|
32
|
+
rejectConnection(error);
|
|
33
|
+
};
|
|
34
|
+
const abort = () => fail('LSP query cancelled or timed out');
|
|
35
|
+
const send = (value: object) => {
|
|
36
|
+
if (error) throw error;
|
|
37
|
+
const body = Buffer.from(JSON.stringify(value));
|
|
38
|
+
child.stdin.write(Buffer.concat([Buffer.from(`Content-Length: ${body.length}\r\n\r\n`), body]));
|
|
39
|
+
};
|
|
40
|
+
child.on('error', () => fail('Could not start the LSP server'));
|
|
41
|
+
child.once('close', () => fail('LSP server closed its connection'));
|
|
42
|
+
child.stdin.on('error', () => fail('LSP server input closed'));
|
|
43
|
+
child.stdout.on('error', () => fail('LSP server output closed'));
|
|
44
|
+
child.stdout.on('data', (data: Buffer) => {
|
|
45
|
+
if (error) return;
|
|
46
|
+
traffic += data.length;
|
|
47
|
+
if (traffic > MAX_TRAFFIC) return fail('LSP server output limit exceeded');
|
|
48
|
+
buffer = Buffer.concat([buffer, data]);
|
|
49
|
+
try {
|
|
50
|
+
for (;;) {
|
|
51
|
+
if (!length) {
|
|
52
|
+
const end = buffer.indexOf('\r\n\r\n');
|
|
53
|
+
if (end === -1 && buffer.length <= MAX_HEADER) return;
|
|
54
|
+
if (end === -1 || end > MAX_HEADER) throw new Error();
|
|
55
|
+
const headers = [...buffer.subarray(0, end).toString('ascii').matchAll(/^Content-Length:[ \t]*(\d+)[ \t]*\r?$/gim)];
|
|
56
|
+
length = headers.length === 1 ? Number(headers[0]![1]) : 0;
|
|
57
|
+
if (!length || length > MAX_BODY) throw new Error();
|
|
58
|
+
buffer = buffer.subarray(end + 4);
|
|
59
|
+
}
|
|
60
|
+
if (buffer.length < length) return;
|
|
61
|
+
const message = object(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(0, length))));
|
|
62
|
+
buffer = buffer.subarray(length);
|
|
63
|
+
length = 0;
|
|
64
|
+
if (message?.jsonrpc !== '2.0') throw new Error();
|
|
65
|
+
if (typeof message.method === 'string') {
|
|
66
|
+
if (typeof message.id === 'number' || typeof message.id === 'string') {
|
|
67
|
+
send({ jsonrpc: '2.0', id: message.id, error: { code: -32601, message: 'Client requests are not supported' } });
|
|
68
|
+
} else if (!Object.hasOwn(message, 'id')) notify?.(message);
|
|
69
|
+
} else if (typeof message.id === 'number') {
|
|
70
|
+
const waiter = pending.get(message.id);
|
|
71
|
+
if (!waiter) continue;
|
|
72
|
+
pending.delete(message.id);
|
|
73
|
+
if (Object.hasOwn(message, 'error') || !Object.hasOwn(message, 'result')) waiter.reject(new Error('LSP server rejected the request'));
|
|
74
|
+
else waiter.resolve(message.result);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch { fail('Invalid or oversized LSP message'); }
|
|
78
|
+
});
|
|
79
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
80
|
+
if (signal.aborted) abort();
|
|
81
|
+
try {
|
|
82
|
+
return await Promise.race([connectionFailure, query({
|
|
83
|
+
request(method, params) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const next = ++id;
|
|
86
|
+
send({ jsonrpc: '2.0', id: next, method, params });
|
|
87
|
+
pending.set(next, { resolve, reject });
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
notify(method, params) { send({ jsonrpc: '2.0', method, params }); },
|
|
91
|
+
onNotification(handler) { notify = handler; },
|
|
92
|
+
})]);
|
|
93
|
+
} finally {
|
|
94
|
+
signal.removeEventListener('abort', abort);
|
|
95
|
+
if (child.pid && child.exitCode === null && child.signalCode === null) {
|
|
96
|
+
try {
|
|
97
|
+
if (process.platform === 'win32') child.kill('SIGKILL');
|
|
98
|
+
else process.kill(-child.pid, 'SIGKILL');
|
|
99
|
+
} catch { /* The process group may already have exited. */ }
|
|
100
|
+
}
|
|
101
|
+
child.stdin.destroy();
|
|
102
|
+
child.stdout.destroy();
|
|
103
|
+
}
|
|
104
|
+
}
|
package/src/tools/lsp.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { constants, promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { isProtectedWrite, isWithin } from '../extension/permission-modes/paths.ts';
|
|
5
|
+
import type { Args, Tool } from '../types/index.ts';
|
|
6
|
+
import { object, withLspClient } from './lsp-client.ts';
|
|
7
|
+
import { resolveExternalExecutable as resolveLspServer } from './executable.ts';
|
|
8
|
+
export { resolveLspServer };
|
|
9
|
+
|
|
10
|
+
export const LSP_FLAG = 'bi-lsp-server';
|
|
11
|
+
const MAX_FILE = 128 * 1024;
|
|
12
|
+
const MAX_RESULTS = 40;
|
|
13
|
+
const actions = ['definition', 'references', 'hover', 'diagnostics', 'document_symbols', 'implementation'] as const;
|
|
14
|
+
type Action = typeof actions[number];
|
|
15
|
+
type LspArgs = Args & { path: string; language_id: string; action: Action; line?: number; character?: number };
|
|
16
|
+
const needsPosition = (action: Action) => action !== 'diagnostics' && action !== 'document_symbols';
|
|
17
|
+
|
|
18
|
+
const coordinate = (n: unknown): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 0 && n <= 0x7fffffff;
|
|
19
|
+
export const validLspArgs = (input: unknown): input is LspArgs => {
|
|
20
|
+
const args = object(input);
|
|
21
|
+
return !!args && Object.keys(args).every(key => ['path', 'language_id', 'action', 'line', 'character'].includes(key)) &&
|
|
22
|
+
typeof args.path === 'string' && !!args.path && args.path.length <= 4096 && !args.path.includes('\0') &&
|
|
23
|
+
typeof args.language_id === 'string' && /^[a-zA-Z0-9_+.-]{1,40}$/.test(args.language_id) && actions.includes(args.action as Action) &&
|
|
24
|
+
(needsPosition(args.action as Action) ? coordinate(args.line) && coordinate(args.character) : args.line === undefined && args.character === undefined);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function allowedPath(root: string, file: string): boolean {
|
|
28
|
+
return isWithin(root, file) && !isProtectedWrite(file) && !path.relative(root, file).split(path.sep)
|
|
29
|
+
.some(part => ['.pi', '.bi'].includes(part.toLowerCase()));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function readSource(file: string): Promise<string> {
|
|
33
|
+
const handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
34
|
+
try {
|
|
35
|
+
const stat = await handle.stat();
|
|
36
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_FILE) throw new Error('LSP requires a regular workspace file of at most 128 KiB');
|
|
37
|
+
const bytes = Buffer.alloc(stat.size + 1);
|
|
38
|
+
let length = 0;
|
|
39
|
+
while (length < bytes.length) {
|
|
40
|
+
const { bytesRead } = await handle.read(bytes, length, bytes.length - length, length);
|
|
41
|
+
if (!bytesRead) break;
|
|
42
|
+
length += bytesRead;
|
|
43
|
+
}
|
|
44
|
+
if (length !== stat.size || bytes.subarray(0, length).includes(0)) throw new Error('LSP input changed while reading or is not text');
|
|
45
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, length));
|
|
46
|
+
} finally { await handle.close(); }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function createLspTool(connect = withLspClient): Tool<LspArgs> {
|
|
50
|
+
return {
|
|
51
|
+
name: 'lsp', description: 'Query an approved local LSP server for definition, implementation, references, hover, diagnostics, or document_symbols. Positions are zero-based UTF-16; omit them for diagnostics and document_symbols.',
|
|
52
|
+
parameters: { type: 'object', additionalProperties: false, required: ['path', 'language_id', 'action'], properties: {
|
|
53
|
+
path: { type: 'string', maxLength: 4096 }, language_id: { type: 'string', maxLength: 40 }, action: { enum: actions },
|
|
54
|
+
line: { type: 'integer', minimum: 0 }, character: { type: 'integer', minimum: 0 },
|
|
55
|
+
} },
|
|
56
|
+
validate: validLspArgs,
|
|
57
|
+
async execute(args, ctx) {
|
|
58
|
+
if (!ctx.authorizeLsp) return { success: false, error: 'LSP requires a trusted project and an explicitly configured server' };
|
|
59
|
+
const cwd = path.resolve(ctx.workingDirectory);
|
|
60
|
+
const root = await fs.realpath(cwd);
|
|
61
|
+
const requested = path.resolve(cwd, args.path);
|
|
62
|
+
if (!allowedPath(cwd, requested)) return { success: false, error: 'Invalid LSP workspace path' };
|
|
63
|
+
const file = path.join(root, path.relative(cwd, requested));
|
|
64
|
+
if (!allowedPath(root, file) || await fs.realpath(file) !== file) return { success: false, error: 'LSP refuses unsafe or symlinked paths' };
|
|
65
|
+
const server = await ctx.authorizeLsp(file);
|
|
66
|
+
if (!server || await resolveLspServer(server, root) !== server) return { success: false, error: 'LSP query was not approved or server is unavailable' };
|
|
67
|
+
if (await fs.realpath(file) !== file) return { success: false, error: 'LSP path changed after approval' };
|
|
68
|
+
const text = await readSource(file);
|
|
69
|
+
const position = needsPosition(args.action) ? { line: args.line!, character: args.character! } : undefined;
|
|
70
|
+
if (position) {
|
|
71
|
+
const line = text.split(/\r\n|\n|\r/)[position.line];
|
|
72
|
+
if (line === undefined || position.character > line.length) return { success: false, error: 'LSP position is outside the document' };
|
|
73
|
+
}
|
|
74
|
+
const timeout = AbortSignal.timeout(8_000);
|
|
75
|
+
const signal = ctx.signal ? AbortSignal.any([ctx.signal, timeout]) : timeout;
|
|
76
|
+
const uri = pathToFileURL(file).href;
|
|
77
|
+
const rootUri = pathToFileURL(root).href;
|
|
78
|
+
const result = await connect(server, root, signal, async client => {
|
|
79
|
+
const initialized = object(await client.request('initialize', {
|
|
80
|
+
processId: process.pid, rootUri, workspaceFolders: [{ uri: rootUri, name: path.basename(root) }],
|
|
81
|
+
// Some push servers (including typescript-language-server) opt in only when advertised.
|
|
82
|
+
capabilities: { general: { positionEncodings: ['utf-16'] }, textDocument: {
|
|
83
|
+
diagnostic: { dynamicRegistration: false }, publishDiagnostics: { versionSupport: true },
|
|
84
|
+
documentSymbol: { hierarchicalDocumentSymbolSupport: true }, implementation: { linkSupport: true },
|
|
85
|
+
} },
|
|
86
|
+
}));
|
|
87
|
+
const capabilities = object(initialized?.capabilities);
|
|
88
|
+
if (!capabilities || (capabilities.positionEncoding !== undefined && capabilities.positionEncoding !== 'utf-16')) throw new Error('LSP server did not initialize with UTF-16 positions');
|
|
89
|
+
client.notify('initialized', {});
|
|
90
|
+
let published: Promise<unknown> | undefined;
|
|
91
|
+
if (args.action === 'diagnostics' && !capabilities.diagnosticProvider) {
|
|
92
|
+
published = new Promise(resolve => client.onNotification(message => {
|
|
93
|
+
const params = object(message.params);
|
|
94
|
+
if (message.method === 'textDocument/publishDiagnostics' && params?.uri === uri &&
|
|
95
|
+
(params.version === undefined || params.version === 1) && Array.isArray(params.diagnostics)) resolve(params.diagnostics);
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
client.notify('textDocument/didOpen', { textDocument: { uri, languageId: args.language_id, version: 1, text } });
|
|
99
|
+
if (args.action === 'diagnostics') return published ?? object(await client.request('textDocument/diagnostic', { textDocument: { uri } }))?.items;
|
|
100
|
+
const method = args.action === 'document_symbols' ? 'documentSymbol' : args.action;
|
|
101
|
+
return client.request(`textDocument/${method}`, { textDocument: { uri }, ...(position ? { position } : {}),
|
|
102
|
+
...(args.action === 'references' ? { context: { includeDeclaration: true } } : {}) });
|
|
103
|
+
});
|
|
104
|
+
signal.throwIfAborted();
|
|
105
|
+
const output = args.action === 'hover' ? hover(result) : args.action === 'diagnostics' ? diagnostics(result) :
|
|
106
|
+
args.action === 'document_symbols' ? documentSymbols(result, uri) : await locations(root, result, ctx.canReadLspLocation);
|
|
107
|
+
signal.throwIfAborted();
|
|
108
|
+
return { success: true, output: JSON.stringify(output, null, 2) };
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function position(value: unknown) {
|
|
114
|
+
const p = object(value);
|
|
115
|
+
return coordinate(p?.line) && coordinate(p.character) ? { line: p.line, character: p.character } : undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function range(value: unknown) {
|
|
119
|
+
const r = object(value), start = position(r?.start), end = position(r?.end);
|
|
120
|
+
return start && end ? { start, end } : undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function locations(root: string, result: unknown, canRead?: (file: string) => boolean) {
|
|
124
|
+
const output = [];
|
|
125
|
+
for (const item of (Array.isArray(result) ? result : [result]).slice(0, 200)) {
|
|
126
|
+
const row = object(item);
|
|
127
|
+
const uri = row?.targetUri ?? row?.uri, span = range(row?.targetSelectionRange ?? row?.range);
|
|
128
|
+
if (typeof uri !== 'string' || !uri.startsWith('file:') || !span) continue;
|
|
129
|
+
try {
|
|
130
|
+
const file = fileURLToPath(uri);
|
|
131
|
+
if (!allowedPath(root, file) || await fs.realpath(file) !== file || !(await fs.stat(file)).isFile() || canRead?.(file) === false) continue;
|
|
132
|
+
output.push({ path: path.relative(root, file), range: span });
|
|
133
|
+
if (output.length >= MAX_RESULTS) break;
|
|
134
|
+
} catch { /* Ignore nonlocal, missing, and invalid targets. */ }
|
|
135
|
+
}
|
|
136
|
+
return output;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function documentSymbols(result: unknown, uri: string) {
|
|
140
|
+
const output = [];
|
|
141
|
+
const pending = (Array.isArray(result) ? result : []).slice(0, 200).reverse().map(item => ({ item, depth: 0 }));
|
|
142
|
+
for (let visited = 0; pending.length && visited < 200 && output.length < MAX_RESULTS; visited++) {
|
|
143
|
+
const { item, depth } = pending.pop()!;
|
|
144
|
+
const row = object(item);
|
|
145
|
+
const location = object(row?.location);
|
|
146
|
+
if (!row || typeof row.name !== 'string' || !row.name || (row.location !== undefined && location?.uri !== uri)) continue;
|
|
147
|
+
const span = range(location?.range ?? row.selectionRange ?? row.range);
|
|
148
|
+
if (!span) continue;
|
|
149
|
+
output.push({ name: row.name.slice(0, 160), depth, range: span,
|
|
150
|
+
...(coordinate(row.kind) && row.kind >= 1 && row.kind <= 26 ? { kind: row.kind } : {}) });
|
|
151
|
+
if (depth < 8 && Array.isArray(row.children)) {
|
|
152
|
+
pending.push(...row.children.slice(0, 200).reverse().map(item => ({ item, depth: depth + 1 })));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return output;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function diagnostics(result: unknown) {
|
|
159
|
+
return (Array.isArray(result) ? result : []).slice(0, MAX_RESULTS).flatMap(item => {
|
|
160
|
+
const row = object(item), span = range(row?.range);
|
|
161
|
+
if (!span || typeof row?.message !== 'string') return [];
|
|
162
|
+
return [{ range: span, message: row.message.slice(0, 500), ...(coordinate(row.severity) ? { severity: row.severity } : {}) }];
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function hover(result: unknown): string {
|
|
167
|
+
const contents = object(result)?.contents;
|
|
168
|
+
return (Array.isArray(contents) ? contents : [contents]).slice(0, 10).map(item => {
|
|
169
|
+
const text = typeof item === 'string' ? item : object(item)?.value;
|
|
170
|
+
return typeof text === 'string' ? text.slice(0, 4000) : '';
|
|
171
|
+
}).filter(Boolean).join('\n').slice(0, 8000);
|
|
172
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { constants, promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isProtectedWrite, resolvePermissionPath } from '../extension/permission-modes/paths.ts';
|
|
4
|
+
import { atomicReplace } from './filesystem.ts';
|
|
5
|
+
|
|
6
|
+
export const memoryRelativePath = '.pi/memory.json';
|
|
7
|
+
export const MAX_MEMORY_NOTE = 4000;
|
|
8
|
+
const MAX_MEMORY_BYTES = 128 * 1024;
|
|
9
|
+
const MAX_ENTRIES = 100;
|
|
10
|
+
|
|
11
|
+
export function memoryPath(cwd: string): string {
|
|
12
|
+
const root = resolvePermissionPath(cwd, '.');
|
|
13
|
+
const file = path.join(root, memoryRelativePath);
|
|
14
|
+
if (isProtectedWrite(file) || resolvePermissionPath(root, file) !== file) throw new Error('Unsafe project memory path');
|
|
15
|
+
return file;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface MemorySnapshot {
|
|
19
|
+
file: string;
|
|
20
|
+
entries: string[];
|
|
21
|
+
existing?: { bytes: Buffer; dev: number; ino: number; mode: number };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function readMemory(cwd: string, file = memoryPath(cwd)): Promise<MemorySnapshot> {
|
|
25
|
+
if (memoryPath(cwd) !== file) throw new Error('Project memory path changed');
|
|
26
|
+
let handle;
|
|
27
|
+
try { handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK); }
|
|
28
|
+
catch (error) {
|
|
29
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT' && memoryPath(cwd) === file) return { file, entries: [] };
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const stat = await handle.stat();
|
|
34
|
+
const { size, dev, ino, mode, nlink } = stat;
|
|
35
|
+
if (!stat.isFile() || nlink !== 1 || size > MAX_MEMORY_BYTES) throw new Error('Memory requires a regular file with one link and at most 128 KiB');
|
|
36
|
+
const buffer = Buffer.alloc(size + 1);
|
|
37
|
+
let length = 0;
|
|
38
|
+
while (length < buffer.length) {
|
|
39
|
+
const { bytesRead } = await handle.read(buffer, length, buffer.length - length, length);
|
|
40
|
+
if (!bytesRead) break;
|
|
41
|
+
length += bytesRead;
|
|
42
|
+
}
|
|
43
|
+
if (length !== size || memoryPath(cwd) !== file) throw new Error('Project memory changed while reading');
|
|
44
|
+
const bytes = buffer.subarray(0, length);
|
|
45
|
+
let value: unknown;
|
|
46
|
+
try { value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); }
|
|
47
|
+
catch { throw new Error('Invalid project memory format'); }
|
|
48
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some(key => key !== 'entries')) {
|
|
49
|
+
throw new Error('Invalid project memory format');
|
|
50
|
+
}
|
|
51
|
+
const entries = (value as { entries?: unknown }).entries;
|
|
52
|
+
if (!Array.isArray(entries) || entries.length > MAX_ENTRIES || entries.some(item => typeof item !== 'string')) throw new Error('Invalid project memory entries');
|
|
53
|
+
return { file, entries, existing: { bytes, dev, ino, mode } };
|
|
54
|
+
} finally { await handle.close(); }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function writeMemory(cwd: string, previous: MemorySnapshot, entries: string[], permitted = () => true): Promise<void> {
|
|
58
|
+
const saved = Buffer.from(`${JSON.stringify({ entries }, null, 2)}\n`);
|
|
59
|
+
if (entries.length > MAX_ENTRIES || saved.length > MAX_MEMORY_BYTES) throw new Error('Project memory limit exceeded');
|
|
60
|
+
const { file, existing } = previous;
|
|
61
|
+
const recheck = async () => {
|
|
62
|
+
if (!permitted()) throw new Error('Memory write is no longer permitted');
|
|
63
|
+
const current = (await readMemory(cwd, file)).existing;
|
|
64
|
+
if ((existing && (!current || current.dev !== existing.dev || current.ino !== existing.ino || current.mode !== existing.mode ||
|
|
65
|
+
!current.bytes.equals(existing.bytes))) || (!existing && current)) throw new Error('Project memory changed before saving');
|
|
66
|
+
if (!permitted() || memoryPath(cwd) !== file) throw new Error('Memory write is no longer permitted');
|
|
67
|
+
};
|
|
68
|
+
await recheck();
|
|
69
|
+
if (existing) {
|
|
70
|
+
await atomicReplace(file, saved, existing.mode, recheck);
|
|
71
|
+
} else {
|
|
72
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
73
|
+
await recheck();
|
|
74
|
+
const handle = await fs.open(file, 'wx', 0o600);
|
|
75
|
+
try { await handle.writeFile(saved); } finally { await handle.close(); }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { constants, promises as fs } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { isProtectedWrite, isWithin } from '../extension/permission-modes/paths.ts';
|
|
5
|
+
import type { Args, Tool, ToolContext } from '../types/index.ts';
|
|
6
|
+
import { MAX_UNDO_FILE_BYTES, type UndoJournal } from './undo-journal.ts';
|
|
7
|
+
|
|
8
|
+
const MAX_SOURCE = 12_000;
|
|
9
|
+
const MAX_SOURCE_LINES = 80;
|
|
10
|
+
const fields = ['path', 'cell_index', 'old_source', 'new_source'] as const;
|
|
11
|
+
type NotebookArgs = Args & { path: string; cell_index: number; old_source: string; new_source: string };
|
|
12
|
+
|
|
13
|
+
export function validNotebookEdit(value: unknown): value is NotebookArgs {
|
|
14
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
15
|
+
const args = value as NotebookArgs;
|
|
16
|
+
const keys = Object.keys(args);
|
|
17
|
+
return keys.length === fields.length && fields.every(key => Object.hasOwn(args, key)) &&
|
|
18
|
+
typeof args.path === 'string' && args.path.endsWith('.ipynb') && !args.path.includes('\0') &&
|
|
19
|
+
Number.isSafeInteger(args.cell_index) && args.cell_index >= 0 &&
|
|
20
|
+
[args.old_source, args.new_source].every(s => typeof s === 'string' && s.length <= MAX_SOURCE && s.split('\n').length <= MAX_SOURCE_LINES) &&
|
|
21
|
+
args.old_source !== args.new_source;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createNotebookTool(options: {
|
|
25
|
+
journal: UndoJournal;
|
|
26
|
+
readHash: (ctx: ToolContext, file: string) => string | undefined;
|
|
27
|
+
atomicReplace: (file: string, bytes: Buffer, mode: number, validate: () => Promise<void>) => Promise<void>;
|
|
28
|
+
}): Tool<NotebookArgs> {
|
|
29
|
+
return {
|
|
30
|
+
name: 'notebook_edit',
|
|
31
|
+
description: 'Replace an existing .ipynb cell source only. Read the notebook first and supply the exact full old source (join source arrays without separators) and a zero-based cell index. Does not run cells.',
|
|
32
|
+
parameters: {
|
|
33
|
+
type: 'object', additionalProperties: false, required: [...fields],
|
|
34
|
+
properties: {
|
|
35
|
+
path: { type: 'string', pattern: '\\.ipynb$' },
|
|
36
|
+
cell_index: { type: 'integer', minimum: 0 },
|
|
37
|
+
old_source: { type: 'string', maxLength: MAX_SOURCE }, new_source: { type: 'string', maxLength: MAX_SOURCE },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
validate: validNotebookEdit,
|
|
41
|
+
async execute(args, ctx) {
|
|
42
|
+
const resolve = async () => {
|
|
43
|
+
const cwd = path.resolve(ctx.workingDirectory);
|
|
44
|
+
const requested = path.resolve(cwd, args.path);
|
|
45
|
+
if (!isWithin(cwd, requested) || isProtectedWrite(requested)) throw new Error('Unsafe notebook path');
|
|
46
|
+
const root = await fs.realpath(cwd);
|
|
47
|
+
const file = path.join(root, path.relative(cwd, requested));
|
|
48
|
+
if (isProtectedWrite(file) || await fs.realpath(file) !== file) throw new Error('Unsafe or symlinked notebook path');
|
|
49
|
+
return file;
|
|
50
|
+
};
|
|
51
|
+
const file = await resolve();
|
|
52
|
+
const expected = options.readHash(ctx, file);
|
|
53
|
+
if (!expected) return { success: false, error: 'Read the notebook in this session before editing it' };
|
|
54
|
+
const before = await readNotebook(file);
|
|
55
|
+
if (hash(before.bytes) !== expected) return { success: false, error: 'Notebook has changed since it was read' };
|
|
56
|
+
const original = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(before.bytes);
|
|
57
|
+
const offset = original.startsWith('\uFEFF') ? 1 : 0;
|
|
58
|
+
const text = original.slice(offset);
|
|
59
|
+
const updated = editSource(text, args);
|
|
60
|
+
const bytes = Buffer.from(original.slice(0, offset) + updated);
|
|
61
|
+
if (bytes.length > MAX_UNDO_FILE_BYTES) return { success: false, error: 'Updated notebook exceeds the 1 MiB edit limit' };
|
|
62
|
+
if (!ctx.confirmDestructive || !await ctx.confirmDestructive('edit notebook cell', file)) {
|
|
63
|
+
return { success: false, error: 'Notebook edit was not approved' };
|
|
64
|
+
}
|
|
65
|
+
ctx.signal?.throwIfAborted();
|
|
66
|
+
await options.atomicReplace(file, bytes, before.mode, async () => {
|
|
67
|
+
if (await resolve() !== file) throw new Error('Notebook path changed');
|
|
68
|
+
const current = await readNotebook(file);
|
|
69
|
+
if (!current.bytes.equals(before.bytes) || current.dev !== before.dev || current.ino !== before.ino || current.mode !== before.mode) {
|
|
70
|
+
throw new Error('Notebook changed before the edit could be saved');
|
|
71
|
+
}
|
|
72
|
+
ctx.signal?.throwIfAborted();
|
|
73
|
+
if (ctx.checkNotebookEdit?.() === false) throw new Error('Notebook edit permission changed before saving');
|
|
74
|
+
});
|
|
75
|
+
options.journal.record(ctx, [{ id: randomUUID(), file, before: before.bytes, afterHash: hash(bytes) }]);
|
|
76
|
+
options.journal.invalidateSnapshots?.(ctx, [file]);
|
|
77
|
+
return { success: true, output: `Updated source of cell ${args.cell_index}. No cells were executed.` };
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function hash(bytes: Buffer): string {
|
|
83
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function readNotebook(file: string) {
|
|
87
|
+
const handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
88
|
+
try {
|
|
89
|
+
const stat = await handle.stat();
|
|
90
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_UNDO_FILE_BYTES) throw new Error('Expected a regular unlinked notebook of at most 1 MiB');
|
|
91
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
92
|
+
let length = 0;
|
|
93
|
+
while (length < buffer.length) {
|
|
94
|
+
const { bytesRead } = await handle.read(buffer, length, buffer.length - length, length);
|
|
95
|
+
if (!bytesRead) break;
|
|
96
|
+
length += bytesRead;
|
|
97
|
+
}
|
|
98
|
+
if (length !== stat.size) throw new Error('Notebook changed while reading');
|
|
99
|
+
return { bytes: buffer.subarray(0, length), mode: stat.mode, dev: stat.dev, ino: stat.ino };
|
|
100
|
+
} finally {
|
|
101
|
+
await handle.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
106
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function source(value: unknown): value is string | string[] {
|
|
110
|
+
return typeof value === 'string' || (Array.isArray(value) && value.every(part => typeof part === 'string'));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function editSource(text: string, args: NotebookArgs): string {
|
|
114
|
+
let book: unknown;
|
|
115
|
+
try { book = JSON.parse(text); } catch { throw new Error('Notebook is not valid JSON'); }
|
|
116
|
+
if (!record(book) || book.nbformat !== 4 || typeof book.nbformat_minor !== 'number' || !Number.isInteger(book.nbformat_minor) || book.nbformat_minor < 0 || !record(book.metadata) || !Array.isArray(book.cells) ||
|
|
117
|
+
!book.cells.every(cell => record(cell) && record(cell.metadata) && source(cell.source) &&
|
|
118
|
+
(cell.cell_type === 'markdown' || cell.cell_type === 'raw' || (cell.cell_type === 'code' && Array.isArray(cell.outputs) &&
|
|
119
|
+
(cell.execution_count === null || Number.isInteger(cell.execution_count)))))) throw new Error('Expected a valid nbformat 4 notebook');
|
|
120
|
+
const cell = book.cells[args.cell_index];
|
|
121
|
+
if (!cell) throw new Error('Notebook cell index is out of range');
|
|
122
|
+
if ((Array.isArray(cell.source) ? cell.source.join('') : cell.source) !== args.old_source) throw new Error('Cell source does not match old_source');
|
|
123
|
+
|
|
124
|
+
// Walk tokens of already-validated JSON to locate just the source value.
|
|
125
|
+
// Re-serializing the document could change unrelated formatting or numbers.
|
|
126
|
+
const tokens = /"(?:[^"\\]|\\[\s\S])*"|[{}[\],:]|[^\s{}[\],:]+/gy;
|
|
127
|
+
let cursor = 0;
|
|
128
|
+
const next = () => {
|
|
129
|
+
while (cursor < text.length && /[\t\n\r ]/.test(text[cursor]!)) cursor++;
|
|
130
|
+
const start = cursor;
|
|
131
|
+
tokens.lastIndex = start;
|
|
132
|
+
const match = tokens.exec(text);
|
|
133
|
+
if (!match) throw new Error('Unexpected notebook token');
|
|
134
|
+
cursor = tokens.lastIndex;
|
|
135
|
+
return { start, value: match[0] };
|
|
136
|
+
};
|
|
137
|
+
const skip = (first: string) => {
|
|
138
|
+
let depth = first === '[' || first === '{' ? 1 : 0;
|
|
139
|
+
while (depth) {
|
|
140
|
+
const { value } = next();
|
|
141
|
+
if (value === '[' || value === '{') depth++;
|
|
142
|
+
if (value === ']' || value === '}') depth--;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const member = (key: string) => {
|
|
146
|
+
let span: { start: number; end: number } | undefined;
|
|
147
|
+
for (let name = next(); name.value !== '}'; name = next()) {
|
|
148
|
+
next(); // colon
|
|
149
|
+
const first = next();
|
|
150
|
+
skip(first.value);
|
|
151
|
+
if (JSON.parse(name.value) === key) {
|
|
152
|
+
if (span) throw new Error(`Notebook contains duplicate ${key} fields`);
|
|
153
|
+
span = { start: first.start, end: cursor };
|
|
154
|
+
}
|
|
155
|
+
if (next().value === '}') break;
|
|
156
|
+
}
|
|
157
|
+
if (!span) throw new Error(`Notebook is missing ${key}`);
|
|
158
|
+
return span;
|
|
159
|
+
};
|
|
160
|
+
next(); // root object
|
|
161
|
+
const cells = member('cells');
|
|
162
|
+
cursor = cells.start;
|
|
163
|
+
next(); // cells array
|
|
164
|
+
for (let index = 0; index < args.cell_index; index++) { skip(next().value); next(); }
|
|
165
|
+
next(); // selected cell object
|
|
166
|
+
const span = member('source');
|
|
167
|
+
const replacement = Array.isArray(cell.source) ? args.new_source.match(/[^\n]*\n|[^\n]+$/g) ?? [] : args.new_source;
|
|
168
|
+
return text.slice(0, span.start) + JSON.stringify(replacement) + text.slice(span.end);
|
|
169
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Tool } from '../types/index.ts';
|
|
2
|
+
|
|
3
|
+
export class ToolRegistry {
|
|
4
|
+
private readonly tools = new Map<string, Tool<any>>();
|
|
5
|
+
|
|
6
|
+
register(tool: Tool<any>): void {
|
|
7
|
+
if (!tool.name.trim()) throw new Error('Tool name must not be empty');
|
|
8
|
+
if (this.tools.has(tool.name)) throw new Error(`Tool already registered: ${tool.name}`);
|
|
9
|
+
this.tools.set(tool.name, tool);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
unregister(name: string): boolean {
|
|
13
|
+
return this.tools.delete(name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get(name: string): Tool<any> | undefined {
|
|
17
|
+
return this.tools.get(name);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
has(name: string): boolean {
|
|
21
|
+
return this.tools.has(name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
list(): Tool<any>[] {
|
|
25
|
+
return [...this.tools.values()];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
definitions(): Array<{ name: string; description: string; parameters: Record<string, unknown> }> {
|
|
29
|
+
return this.list().map(({ name, description, parameters }) => ({ name, description, parameters }));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { getPowerShellConfig, getShellConfig } from '@earendil-works/pi-coding-agent';
|
|
5
|
+
import { isWithin } from '../extension/permission-modes/paths.ts';
|
|
6
|
+
|
|
7
|
+
type ShellConfig = ReturnType<typeof getShellConfig>;
|
|
8
|
+
export type ShellName = 'bash' | 'powershell';
|
|
9
|
+
export type Shells = Partial<Record<ShellName, ShellConfig>>;
|
|
10
|
+
let detected: Shells | undefined;
|
|
11
|
+
|
|
12
|
+
function windowsShell(resolve: () => ShellConfig, posix: boolean): ShellConfig | undefined {
|
|
13
|
+
try {
|
|
14
|
+
const config = resolve();
|
|
15
|
+
const shell = realpathSync(config.shell);
|
|
16
|
+
if (isWithin(realpathSync(process.cwd()), shell)) return;
|
|
17
|
+
if (posix) {
|
|
18
|
+
// A legacy WSL launcher can exist even without a working distribution.
|
|
19
|
+
const stdin = config.commandTransport === 'stdin';
|
|
20
|
+
const probe = 'printf honeycomb';
|
|
21
|
+
const result = spawnSync(shell, stdin ? config.args : [...config.args, probe], {
|
|
22
|
+
cwd: path.dirname(shell), input: stdin ? probe + '\n' : undefined,
|
|
23
|
+
encoding: 'utf8', timeout: 4000, windowsHide: true,
|
|
24
|
+
env: { ...process.env, BASH_ENV: '', ENV: '' },
|
|
25
|
+
});
|
|
26
|
+
if (result.status !== 0 || result.stdout !== 'honeycomb') return;
|
|
27
|
+
}
|
|
28
|
+
return { ...config, shell };
|
|
29
|
+
} catch { return; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function executionShells(): Shells {
|
|
33
|
+
return detected ??= process.platform === 'win32'
|
|
34
|
+
? { powershell: windowsShell(getPowerShellConfig, false), bash: windowsShell(getShellConfig, true) }
|
|
35
|
+
: { bash: { shell: '/bin/sh', args: ['-c'] } };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function shellForTool(tool: string, shells: Shells = executionShells()): ShellName | undefined {
|
|
39
|
+
if (tool === 'powershell' || tool === 'bash') return shells[tool] ? tool : undefined;
|
|
40
|
+
if (tool === 'background' || tool === 'terminal') return shells.powershell ? 'powershell' : shells.bash ? 'bash' : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function availableShellTool(tool: string, shells: Shells = executionShells()) {
|
|
44
|
+
return !['bash', 'powershell', 'background', 'terminal'].includes(tool) || !!shellForTool(tool, shells);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface LaunchCommand { executable: string; args: string[]; stdinScript?: string }
|
|
48
|
+
|
|
49
|
+
export function shellCommand(command: string, name: ShellName | undefined, shells: Shells): LaunchCommand {
|
|
50
|
+
const config = name && shells[name];
|
|
51
|
+
if (!config) throw new Error('No compatible shell is available');
|
|
52
|
+
if (name === 'powershell') {
|
|
53
|
+
// Pass source intact through Win32 argv, including embedded quotes and newlines.
|
|
54
|
+
const script = '[Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)\n' + command;
|
|
55
|
+
return { executable: config.shell, args: ['-NoLogo', '-NoProfile', '-NonInteractive', '-OutputFormat', 'Text',
|
|
56
|
+
'-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')] };
|
|
57
|
+
}
|
|
58
|
+
if (config.commandTransport === 'stdin') {
|
|
59
|
+
// exec hands the existing stdin pipe to the command for later terminal input.
|
|
60
|
+
return { executable: config.shell, args: config.args, stdinScript: `exec sh -c '${command.replaceAll("'", "'\\''")}'\n` };
|
|
61
|
+
}
|
|
62
|
+
return { executable: config.shell, args: [...config.args, command] };
|
|
63
|
+
}
|