@datalabrotterdam/nova-ai-cli 1.1.0 → 1.2.0-alpha.1
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 +165 -96
- package/dist/acp-ZYOQ6PON.js +65 -0
- package/dist/chunk-GZZ7PY3S.js +8878 -0
- package/dist/chunk-JAEXUFAS.js +451 -0
- package/dist/chunk-Q7WL3DXP.js +19 -0
- package/dist/chunk-ZKRZIF3S.js +954 -0
- package/dist/headless-ZYUSTZDL.js +567 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +155 -17
- package/dist/login-6U7QS7EA.js +118 -0
- package/dist/tui-XOKXPXN2.js +4801 -0
- package/dist/webui-L4GGMXJ3.js +9 -0
- package/package.json +24 -8
- package/src/acp/web/dist/assets/{index-D2Z0sfLR.js → index-DlCz3fmq.js} +1 -1
- package/src/acp/web/dist/index.html +1 -1
- package/dist/acp/agent.d.ts +0 -13
- package/dist/acp/agent.js +0 -242
- package/dist/acp/auth-server.d.ts +0 -10
- package/dist/acp/auth-server.js +0 -67
- package/dist/acp/credentials.d.ts +0 -11
- package/dist/acp/credentials.js +0 -30
- package/dist/acp/index.d.ts +0 -2
- package/dist/acp/index.js +0 -21
- package/dist/acp/mcp.d.ts +0 -11
- package/dist/acp/mcp.js +0 -90
- package/dist/acp/sessions.d.ts +0 -20
- package/dist/acp/sessions.js +0 -91
- package/dist/acp/tools/index.d.ts +0 -6
- package/dist/acp/tools/index.js +0 -5
- package/dist/acp/tools/marker.d.ts +0 -17
- package/dist/acp/tools/marker.js +0 -43
- package/dist/acp/tools/permission.d.ts +0 -2
- package/dist/acp/tools/permission.js +0 -20
- package/dist/acp/tools/read-file.d.ts +0 -2
- package/dist/acp/tools/read-file.js +0 -20
- package/dist/acp/tools/registry.d.ts +0 -4
- package/dist/acp/tools/registry.js +0 -10
- package/dist/acp/tools/reporting.d.ts +0 -3
- package/dist/acp/tools/reporting.js +0 -26
- package/dist/acp/tools/run-command.d.ts +0 -2
- package/dist/acp/tools/run-command.js +0 -29
- package/dist/acp/tools/system-prompt.d.ts +0 -2
- package/dist/acp/tools/system-prompt.js +0 -23
- package/dist/acp/tools/types.d.ts +0 -18
- package/dist/acp/tools/types.js +0 -1
- package/dist/acp/tools/write-file.d.ts +0 -2
- package/dist/acp/tools/write-file.js +0 -20
- package/dist/tui/index.d.ts +0 -7
- package/dist/tui/index.js +0 -11
- package/dist/webui/index.d.ts +0 -6
- package/dist/webui/index.js +0 -9
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type StoredCredentials = {
|
|
2
|
-
apiKey: string;
|
|
3
|
-
defaultModel?: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Single place that owns "how we get the Nova API key", so swapping this for
|
|
7
|
-
* an OAuth-based Agent Auth flow later only touches this file.
|
|
8
|
-
*/
|
|
9
|
-
export declare function readCredentials(): StoredCredentials | null;
|
|
10
|
-
export declare function writeCredentials(credentials: StoredCredentials): void;
|
|
11
|
-
export declare function credentialsPath(): string;
|
package/dist/acp/credentials.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
const CREDENTIALS_PATH = join(homedir(), ".nova-ai", "credentials.json");
|
|
5
|
-
/**
|
|
6
|
-
* Single place that owns "how we get the Nova API key", so swapping this for
|
|
7
|
-
* an OAuth-based Agent Auth flow later only touches this file.
|
|
8
|
-
*/
|
|
9
|
-
export function readCredentials() {
|
|
10
|
-
const envApiKey = process.env.NOVA_API_KEY;
|
|
11
|
-
if (envApiKey) {
|
|
12
|
-
return { apiKey: envApiKey, defaultModel: process.env.NOVA_MODEL };
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
const raw = readFileSync(CREDENTIALS_PATH, "utf8");
|
|
16
|
-
return JSON.parse(raw);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export function writeCredentials(credentials) {
|
|
23
|
-
mkdirSync(dirname(CREDENTIALS_PATH), { recursive: true });
|
|
24
|
-
writeFileSync(CREDENTIALS_PATH, JSON.stringify(credentials, null, 2), {
|
|
25
|
-
mode: 0o600,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export function credentialsPath() {
|
|
29
|
-
return CREDENTIALS_PATH;
|
|
30
|
-
}
|
package/dist/acp/index.d.ts
DELETED
package/dist/acp/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Readable, Writable } from "node:stream";
|
|
2
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
3
|
-
import { NovaAgent } from "./agent.js";
|
|
4
|
-
async function runAcp(...args) {
|
|
5
|
-
const agentImpl = new NovaAgent();
|
|
6
|
-
const output = Writable.toWeb(process.stdout);
|
|
7
|
-
const input = Readable.toWeb(process.stdin);
|
|
8
|
-
const stream = acp.ndJsonStream(output, input);
|
|
9
|
-
acp
|
|
10
|
-
.agent({ name: "nova-ai-cli" })
|
|
11
|
-
.onRequest("initialize", (ctx) => agentImpl.initialize(ctx.params))
|
|
12
|
-
.onRequest("session/new", (ctx) => agentImpl.newSession(ctx.params))
|
|
13
|
-
.onRequest("session/load", (ctx) => agentImpl.loadSession(ctx.params, ctx.client))
|
|
14
|
-
.onRequest("session/list", (ctx) => agentImpl.listSessions(ctx.params))
|
|
15
|
-
.onRequest("session/close", (ctx) => agentImpl.closeSession(ctx.params))
|
|
16
|
-
.onRequest("authenticate", (ctx) => agentImpl.authenticate(ctx.params))
|
|
17
|
-
.onRequest("session/prompt", (ctx) => agentImpl.prompt(ctx.params, ctx.client))
|
|
18
|
-
.onNotification("session/cancel", (ctx) => agentImpl.cancel(ctx.params))
|
|
19
|
-
.connect(stream);
|
|
20
|
-
}
|
|
21
|
-
export default runAcp;
|
package/dist/acp/mcp.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import type { ToolDefinition } from "./tools/types.js";
|
|
4
|
-
export type McpConnection = {
|
|
5
|
-
serverName: string;
|
|
6
|
-
client: Client;
|
|
7
|
-
close(): Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
export declare function connectMcpServers(servers: acp.McpServer[]): Promise<McpConnection[]>;
|
|
10
|
-
export declare function closeMcpConnections(connections: McpConnection[]): Promise<void>;
|
|
11
|
-
export declare function listMcpTools(connections: McpConnection[]): Promise<ToolDefinition[]>;
|
package/dist/acp/mcp.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
|
-
const TOOL_NAME_PREFIX = "mcp__";
|
|
6
|
-
function sanitize(name) {
|
|
7
|
-
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
8
|
-
}
|
|
9
|
-
function headersToRecord(headers) {
|
|
10
|
-
return Object.fromEntries(headers.map((h) => [h.name, h.value]));
|
|
11
|
-
}
|
|
12
|
-
function buildTransport(server) {
|
|
13
|
-
if ("type" in server && server.type === "http") {
|
|
14
|
-
return new StreamableHTTPClientTransport(new URL(server.url), {
|
|
15
|
-
requestInit: { headers: headersToRecord(server.headers) },
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if ("type" in server && server.type === "sse") {
|
|
19
|
-
return new SSEClientTransport(new URL(server.url), {
|
|
20
|
-
requestInit: { headers: headersToRecord(server.headers) },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
const stdio = server;
|
|
24
|
-
return new StdioClientTransport({
|
|
25
|
-
command: stdio.command,
|
|
26
|
-
args: stdio.args,
|
|
27
|
-
env: Object.fromEntries(stdio.env.map((e) => [e.name, e.value])),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export async function connectMcpServers(servers) {
|
|
31
|
-
const connections = [];
|
|
32
|
-
for (const server of servers) {
|
|
33
|
-
if ("type" in server && server.type === "acp")
|
|
34
|
-
continue; // experimental ACP-transport MCP, not yet supported
|
|
35
|
-
const client = new Client({ name: "nova-ai-cli", version: "1.0.0" });
|
|
36
|
-
const transport = buildTransport(server);
|
|
37
|
-
try {
|
|
38
|
-
await client.connect(transport);
|
|
39
|
-
connections.push({ serverName: server.name, client, close: () => client.close() });
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
console.error(`Failed to connect MCP server "${server.name}": ${err.message}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return connections;
|
|
46
|
-
}
|
|
47
|
-
export async function closeMcpConnections(connections) {
|
|
48
|
-
await Promise.all(connections.map((c) => c.close().catch(() => { })));
|
|
49
|
-
}
|
|
50
|
-
function toToolResult(result) {
|
|
51
|
-
const text = Array.isArray(result.content)
|
|
52
|
-
? result.content
|
|
53
|
-
.map((block) => {
|
|
54
|
-
if (typeof block === "object" && block !== null && "type" in block && block.type === "text") {
|
|
55
|
-
return block.text;
|
|
56
|
-
}
|
|
57
|
-
return "";
|
|
58
|
-
})
|
|
59
|
-
.filter(Boolean)
|
|
60
|
-
.join("\n")
|
|
61
|
-
: "";
|
|
62
|
-
if (result.isError)
|
|
63
|
-
return { error: text || "MCP tool call failed." };
|
|
64
|
-
return { output: text };
|
|
65
|
-
}
|
|
66
|
-
export async function listMcpTools(connections) {
|
|
67
|
-
const tools = [];
|
|
68
|
-
for (const connection of connections) {
|
|
69
|
-
const { tools: serverTools } = await connection.client.listTools();
|
|
70
|
-
for (const tool of serverTools) {
|
|
71
|
-
const qualifiedName = `${TOOL_NAME_PREFIX}${sanitize(connection.serverName)}__${sanitize(tool.name)}`;
|
|
72
|
-
tools.push({
|
|
73
|
-
name: qualifiedName,
|
|
74
|
-
description: `${qualifiedName}: ${tool.description ?? tool.name} (from MCP server "${connection.serverName}")`,
|
|
75
|
-
requiredCapability: () => true,
|
|
76
|
-
mutating: true,
|
|
77
|
-
async execute(_ctx, args) {
|
|
78
|
-
try {
|
|
79
|
-
const result = await connection.client.callTool({ name: tool.name, arguments: args });
|
|
80
|
-
return toToolResult(result);
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
return { error: err.message };
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return tools;
|
|
90
|
-
}
|
package/dist/acp/sessions.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage } from "@datalabrotterdam/nova-sdk";
|
|
2
|
-
export type StoredSession = {
|
|
3
|
-
sessionId: string;
|
|
4
|
-
cwd: string;
|
|
5
|
-
title: string | null;
|
|
6
|
-
updatedAt: string;
|
|
7
|
-
messages: ChatMessage[];
|
|
8
|
-
};
|
|
9
|
-
export declare function loadStoredSession(sessionId: string): StoredSession | null;
|
|
10
|
-
/**
|
|
11
|
-
* Each turn is appended as its own line rather than rewriting the whole
|
|
12
|
-
* session file, so persisting after every prompt stays O(1) instead of
|
|
13
|
-
* O(history length).
|
|
14
|
-
*/
|
|
15
|
-
export declare function appendSessionTurn(sessionId: string, header: {
|
|
16
|
-
cwd: string;
|
|
17
|
-
title: string | null;
|
|
18
|
-
}, newMessages: ChatMessage[]): void;
|
|
19
|
-
export declare function listStoredSessions(cwd?: string): StoredSession[];
|
|
20
|
-
export declare function deriveTitle(messages: ChatMessage[]): string | null;
|
package/dist/acp/sessions.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { appendFileSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
const SESSIONS_DIR = join(homedir(), ".nova-ai", "sessions");
|
|
5
|
-
function sessionFilePath(sessionId) {
|
|
6
|
-
return join(SESSIONS_DIR, `${sessionId}.jsonl`);
|
|
7
|
-
}
|
|
8
|
-
function parseSessionFile(raw) {
|
|
9
|
-
let header = null;
|
|
10
|
-
const messages = [];
|
|
11
|
-
let updatedAt = "";
|
|
12
|
-
for (const line of raw.split("\n")) {
|
|
13
|
-
if (!line.trim())
|
|
14
|
-
continue;
|
|
15
|
-
const parsed = JSON.parse(line);
|
|
16
|
-
if (parsed.kind === "header") {
|
|
17
|
-
header = parsed;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
messages.push(parsed.message);
|
|
21
|
-
updatedAt = parsed.updatedAt;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (!header)
|
|
25
|
-
return null;
|
|
26
|
-
return { sessionId: "", cwd: header.cwd, title: header.title, updatedAt, messages };
|
|
27
|
-
}
|
|
28
|
-
export function loadStoredSession(sessionId) {
|
|
29
|
-
try {
|
|
30
|
-
const raw = readFileSync(sessionFilePath(sessionId), "utf8");
|
|
31
|
-
const session = parseSessionFile(raw);
|
|
32
|
-
return session ? { ...session, sessionId } : null;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Each turn is appended as its own line rather than rewriting the whole
|
|
40
|
-
* session file, so persisting after every prompt stays O(1) instead of
|
|
41
|
-
* O(history length).
|
|
42
|
-
*/
|
|
43
|
-
export function appendSessionTurn(sessionId, header, newMessages) {
|
|
44
|
-
mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
45
|
-
const path = sessionFilePath(sessionId);
|
|
46
|
-
const updatedAt = new Date().toISOString();
|
|
47
|
-
const lines = [];
|
|
48
|
-
// Re-stating the header is cheap and keeps title updates (set once the
|
|
49
|
-
// first user message arrives) visible without rewriting prior lines.
|
|
50
|
-
lines.push(JSON.stringify({ kind: "header", cwd: header.cwd, title: header.title }));
|
|
51
|
-
for (const message of newMessages) {
|
|
52
|
-
lines.push(JSON.stringify({ kind: "message", updatedAt, message }));
|
|
53
|
-
}
|
|
54
|
-
appendFileSync(path, `${lines.join("\n")}\n`);
|
|
55
|
-
}
|
|
56
|
-
export function listStoredSessions(cwd) {
|
|
57
|
-
let files;
|
|
58
|
-
try {
|
|
59
|
-
files = readdirSync(SESSIONS_DIR);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
const sessions = [];
|
|
65
|
-
for (const file of files) {
|
|
66
|
-
if (!file.endsWith(".jsonl"))
|
|
67
|
-
continue;
|
|
68
|
-
const sessionId = file.slice(0, -".jsonl".length);
|
|
69
|
-
try {
|
|
70
|
-
const raw = readFileSync(join(SESSIONS_DIR, file), "utf8");
|
|
71
|
-
const session = parseSessionFile(raw);
|
|
72
|
-
if (!session)
|
|
73
|
-
continue;
|
|
74
|
-
if (!cwd || session.cwd === cwd)
|
|
75
|
-
sessions.push({ ...session, sessionId });
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// Skip corrupt/partial session files rather than failing the whole listing.
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return sessions.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
82
|
-
}
|
|
83
|
-
export function deriveTitle(messages) {
|
|
84
|
-
const firstUser = messages.find((m) => m.role === "user");
|
|
85
|
-
if (!firstUser || typeof firstUser.content !== "string")
|
|
86
|
-
return null;
|
|
87
|
-
const text = firstUser.content.trim();
|
|
88
|
-
if (!text)
|
|
89
|
-
return null;
|
|
90
|
-
return text.length > 60 ? `${text.slice(0, 60)}…` : text;
|
|
91
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { extractToolCall, hasPendingFence } from "./marker.js";
|
|
2
|
-
export { requestPermissionIfNeeded } from "./permission.js";
|
|
3
|
-
export { availableTools, findTool } from "./registry.js";
|
|
4
|
-
export { sendToolCallPending, sendToolCallUpdate } from "./reporting.js";
|
|
5
|
-
export { buildToolsSystemPrompt } from "./system-prompt.js";
|
|
6
|
-
export type { ToolContext, ToolDefinition, ToolResult } from "./types.js";
|
package/dist/acp/tools/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { extractToolCall, hasPendingFence } from "./marker.js";
|
|
2
|
-
export { requestPermissionIfNeeded } from "./permission.js";
|
|
3
|
-
export { availableTools, findTool } from "./registry.js";
|
|
4
|
-
export { sendToolCallPending, sendToolCallUpdate } from "./reporting.js";
|
|
5
|
-
export { buildToolsSystemPrompt } from "./system-prompt.js";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type ParsedToolCall = {
|
|
2
|
-
name: string;
|
|
3
|
-
args: Record<string, unknown>;
|
|
4
|
-
matchStart: number;
|
|
5
|
-
matchEnd: number;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Looks for one complete ```tool_call fenced block in the accumulated stream
|
|
9
|
-
* buffer. Returns null while the block hasn't fully arrived yet (it may be
|
|
10
|
-
* split across multiple stream chunks).
|
|
11
|
-
*/
|
|
12
|
-
export declare function extractToolCall(buffer: string): ParsedToolCall | null;
|
|
13
|
-
/**
|
|
14
|
-
* True once the buffer contains the fence start, or ends with a prefix of it
|
|
15
|
-
* (the opening marker may itself be split across stream chunks).
|
|
16
|
-
*/
|
|
17
|
-
export declare function hasPendingFence(buffer: string): boolean;
|
package/dist/acp/tools/marker.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Greedy match: takes the LAST closing ``` in the buffer, not the first. The
|
|
2
|
-
// JSON payload (e.g. write_file content) may itself contain literal ``` runs
|
|
3
|
-
// (markdown snippets, code fences) — a lazy match would close on those and
|
|
4
|
-
// truncate/corrupt the JSON.
|
|
5
|
-
const FENCE_RE = /```tool_call\s*\n([\s\S]*)\n```/;
|
|
6
|
-
/**
|
|
7
|
-
* Looks for one complete ```tool_call fenced block in the accumulated stream
|
|
8
|
-
* buffer. Returns null while the block hasn't fully arrived yet (it may be
|
|
9
|
-
* split across multiple stream chunks).
|
|
10
|
-
*/
|
|
11
|
-
export function extractToolCall(buffer) {
|
|
12
|
-
const match = FENCE_RE.exec(buffer);
|
|
13
|
-
if (!match)
|
|
14
|
-
return null;
|
|
15
|
-
try {
|
|
16
|
-
const parsed = JSON.parse(match[1]);
|
|
17
|
-
if (typeof parsed?.name !== "string")
|
|
18
|
-
return null;
|
|
19
|
-
return {
|
|
20
|
-
name: parsed.name,
|
|
21
|
-
args: typeof parsed.args === "object" && parsed.args !== null ? parsed.args : parsed,
|
|
22
|
-
matchStart: match.index,
|
|
23
|
-
matchEnd: match.index + match[0].length,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const FENCE_START = "```tool_call";
|
|
31
|
-
/**
|
|
32
|
-
* True once the buffer contains the fence start, or ends with a prefix of it
|
|
33
|
-
* (the opening marker may itself be split across stream chunks).
|
|
34
|
-
*/
|
|
35
|
-
export function hasPendingFence(buffer) {
|
|
36
|
-
if (buffer.includes(FENCE_START))
|
|
37
|
-
return true;
|
|
38
|
-
for (let len = Math.min(FENCE_START.length, buffer.length); len > 0; len--) {
|
|
39
|
-
if (buffer.endsWith(FENCE_START.slice(0, len)))
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export async function requestPermissionIfNeeded(ctx, toolCallId, tool, args) {
|
|
3
|
-
if (!tool.mutating)
|
|
4
|
-
return true;
|
|
5
|
-
const response = await ctx.client.request(acp.methods.client.session.requestPermission, {
|
|
6
|
-
sessionId: ctx.sessionId,
|
|
7
|
-
toolCall: {
|
|
8
|
-
toolCallId,
|
|
9
|
-
title: tool.name,
|
|
10
|
-
kind: "execute",
|
|
11
|
-
status: "pending",
|
|
12
|
-
rawInput: args,
|
|
13
|
-
},
|
|
14
|
-
options: [
|
|
15
|
-
{ optionId: "allow", name: "Allow", kind: "allow_once" },
|
|
16
|
-
{ optionId: "reject", name: "Reject", kind: "reject_once" },
|
|
17
|
-
],
|
|
18
|
-
}, { cancellationSignal: ctx.signal });
|
|
19
|
-
return response.outcome.outcome === "selected" && response.outcome.optionId === "allow";
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export const readFileTool = {
|
|
3
|
-
name: "read_file",
|
|
4
|
-
description: 'read_file: {"path": "<absolute path>"} — read a text file in the workspace.',
|
|
5
|
-
requiredCapability: (caps) => !!caps?.fs?.readTextFile,
|
|
6
|
-
mutating: false,
|
|
7
|
-
async execute({ client, sessionId, signal }, args) {
|
|
8
|
-
const path = typeof args.path === "string" ? args.path : "";
|
|
9
|
-
if (!path)
|
|
10
|
-
return { error: "read_file requires a 'path' argument." };
|
|
11
|
-
try {
|
|
12
|
-
const result = await client.request(acp.methods.client.fs.readTextFile, { sessionId, path }, { cancellationSignal: signal });
|
|
13
|
-
return { output: result.content };
|
|
14
|
-
}
|
|
15
|
-
catch (err) {
|
|
16
|
-
const message = err instanceof Error ? err.message : "Failed to read file.";
|
|
17
|
-
return { error: `${message} (path tried: ${path})` };
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
import type { ToolDefinition } from "./types.js";
|
|
3
|
-
export declare function availableTools(caps: acp.ClientCapabilities | undefined): ToolDefinition[];
|
|
4
|
-
export declare function findTool(name: string): ToolDefinition | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { readFileTool } from "./read-file.js";
|
|
2
|
-
import { runCommandTool } from "./run-command.js";
|
|
3
|
-
import { writeFileTool } from "./write-file.js";
|
|
4
|
-
const TOOLS = [readFileTool, writeFileTool, runCommandTool];
|
|
5
|
-
export function availableTools(caps) {
|
|
6
|
-
return TOOLS.filter((tool) => tool.requiredCapability(caps));
|
|
7
|
-
}
|
|
8
|
-
export function findTool(name) {
|
|
9
|
-
return TOOLS.find((tool) => tool.name === name);
|
|
10
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ToolContext, ToolDefinition } from "./types.js";
|
|
2
|
-
export declare function sendToolCallPending(ctx: ToolContext, toolCallId: string, tool: ToolDefinition, args: Record<string, unknown>): Promise<void>;
|
|
3
|
-
export declare function sendToolCallUpdate(ctx: ToolContext, toolCallId: string, status: "completed" | "failed", output: string): Promise<void>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export async function sendToolCallPending(ctx, toolCallId, tool, args) {
|
|
3
|
-
await ctx.client.notify(acp.methods.client.session.update, {
|
|
4
|
-
sessionId: ctx.sessionId,
|
|
5
|
-
update: {
|
|
6
|
-
sessionUpdate: "tool_call",
|
|
7
|
-
toolCallId,
|
|
8
|
-
title: tool.name,
|
|
9
|
-
kind: tool.mutating ? "execute" : "read",
|
|
10
|
-
status: "pending",
|
|
11
|
-
rawInput: args,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export async function sendToolCallUpdate(ctx, toolCallId, status, output) {
|
|
16
|
-
await ctx.client.notify(acp.methods.client.session.update, {
|
|
17
|
-
sessionId: ctx.sessionId,
|
|
18
|
-
update: {
|
|
19
|
-
sessionUpdate: "tool_call_update",
|
|
20
|
-
toolCallId,
|
|
21
|
-
status,
|
|
22
|
-
content: [{ type: "content", content: { type: "text", text: output } }],
|
|
23
|
-
rawOutput: { output },
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export const runCommandTool = {
|
|
3
|
-
name: "run_command",
|
|
4
|
-
description: 'run_command: {"command": "<shell command>"} — run a shell command in the workspace and return its output.',
|
|
5
|
-
requiredCapability: (caps) => !!caps?.terminal,
|
|
6
|
-
mutating: true,
|
|
7
|
-
async execute({ client, sessionId, signal }, args) {
|
|
8
|
-
const command = typeof args.command === "string" ? args.command : "";
|
|
9
|
-
if (!command)
|
|
10
|
-
return { error: "run_command requires a 'command' argument." };
|
|
11
|
-
let terminalId;
|
|
12
|
-
try {
|
|
13
|
-
const created = await client.request(acp.methods.client.terminal.create, { sessionId, command }, { cancellationSignal: signal });
|
|
14
|
-
terminalId = created.terminalId;
|
|
15
|
-
const exit = await client.request(acp.methods.client.terminal.waitForExit, { sessionId, terminalId }, { cancellationSignal: signal });
|
|
16
|
-
const { output, truncated } = await client.request(acp.methods.client.terminal.output, { sessionId, terminalId }, { cancellationSignal: signal });
|
|
17
|
-
const exitNote = exit.exitCode !== undefined && exit.exitCode !== null ? ` (exit code ${exit.exitCode})` : "";
|
|
18
|
-
return { output: `${output}${truncated ? "\n[output truncated]" : ""}${exitNote}` };
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
return { error: err instanceof Error ? err.message : "Failed to run command." };
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
if (terminalId) {
|
|
25
|
-
void client.request(acp.methods.client.terminal.release, { sessionId, terminalId }).catch(() => { });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function buildToolsSystemPrompt(tools, cwd) {
|
|
2
|
-
if (tools.length === 0)
|
|
3
|
-
return null;
|
|
4
|
-
const toolList = tools.map((tool) => `- ${tool.description}`).join("\n");
|
|
5
|
-
return [
|
|
6
|
-
`The user's workspace root is: ${cwd}`,
|
|
7
|
-
"Always use absolute paths rooted there (e.g. resolve a file named X to the corresponding path under that root). Never guess or invent a path like /home/user/... — use the workspace root given above.",
|
|
8
|
-
"You can use tools to read/write files or run shell commands in the user's workspace.",
|
|
9
|
-
"To use a tool, emit exactly this fenced block and nothing else after it in your turn:",
|
|
10
|
-
"```tool_call",
|
|
11
|
-
'{"name": "<tool name>", "args": { ... }}',
|
|
12
|
-
"```",
|
|
13
|
-
"STRICT rules for this JSON:",
|
|
14
|
-
"- All tool arguments go INSIDE the \"args\" object. Never put them at the top level next to \"name\".",
|
|
15
|
-
"- Include every argument the tool needs, exactly as named below. Do not omit \"path\", \"content\", or \"command\".",
|
|
16
|
-
"- Example for write_file: ```tool_call",
|
|
17
|
-
'{"name": "write_file", "args": {"path": "' + cwd.replace(/\\/g, "\\\\") + '/example.txt", "content": "file contents here"}}',
|
|
18
|
-
"```",
|
|
19
|
-
"- One tool call per turn. After the result comes back, continue or call another tool.",
|
|
20
|
-
"Wait for the tool's result before continuing. Available tools:",
|
|
21
|
-
toolList,
|
|
22
|
-
].join("\n");
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export type ToolContext = {
|
|
3
|
-
client: acp.AgentContext;
|
|
4
|
-
sessionId: string;
|
|
5
|
-
signal: AbortSignal;
|
|
6
|
-
};
|
|
7
|
-
export type ToolResult = {
|
|
8
|
-
output: string;
|
|
9
|
-
} | {
|
|
10
|
-
error: string;
|
|
11
|
-
};
|
|
12
|
-
export type ToolDefinition = {
|
|
13
|
-
name: string;
|
|
14
|
-
description: string;
|
|
15
|
-
requiredCapability: (caps: acp.ClientCapabilities | undefined) => boolean;
|
|
16
|
-
mutating: boolean;
|
|
17
|
-
execute(ctx: ToolContext, args: Record<string, unknown>): Promise<ToolResult>;
|
|
18
|
-
};
|
package/dist/acp/tools/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as acp from "@agentclientprotocol/sdk";
|
|
2
|
-
export const writeFileTool = {
|
|
3
|
-
name: "write_file",
|
|
4
|
-
description: 'write_file: {"path": "<absolute path>", "content": "<full file content>"} — overwrite a text file in the workspace.',
|
|
5
|
-
requiredCapability: (caps) => !!caps?.fs?.writeTextFile,
|
|
6
|
-
mutating: true,
|
|
7
|
-
async execute({ client, sessionId, signal }, args) {
|
|
8
|
-
const path = typeof args.path === "string" ? args.path : "";
|
|
9
|
-
const content = typeof args.content === "string" ? args.content : "";
|
|
10
|
-
if (!path)
|
|
11
|
-
return { error: "write_file requires a 'path' argument." };
|
|
12
|
-
try {
|
|
13
|
-
await client.request(acp.methods.client.fs.writeTextFile, { sessionId, path, content }, { cancellationSignal: signal });
|
|
14
|
-
return { output: `Wrote ${content.length} characters to ${path}.` };
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
return { error: err instanceof Error ? err.message : "Failed to write file." };
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
package/dist/tui/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Placeholder for the interactive terminal chat mode (nova-ai-cli's primary
|
|
3
|
-
* entrypoint, mirroring `claude`/`codex`). ACP mode in index.ts is the
|
|
4
|
-
* machine-facing counterpart of this same auth/credentials plumbing.
|
|
5
|
-
*/
|
|
6
|
-
export declare function runChat(...args: string[]): Promise<void>;
|
|
7
|
-
export default runChat;
|
package/dist/tui/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Placeholder for the interactive terminal chat mode (nova-ai-cli's primary
|
|
3
|
-
* entrypoint, mirroring `claude`/`codex`). ACP mode in index.ts is the
|
|
4
|
-
* machine-facing counterpart of this same auth/credentials plumbing.
|
|
5
|
-
*/
|
|
6
|
-
export async function runChat(...args) {
|
|
7
|
-
console.log("nova-ai-cli is a work in progress — interactive chat isn't built yet.");
|
|
8
|
-
console.log("Right now it only works in ACP mode: run `nova-ai-cli --acp` (or point your ACP client at this binary).");
|
|
9
|
-
console.log("Run `nova-ai-cli --setup` first to connect your Nova API key.");
|
|
10
|
-
}
|
|
11
|
-
export default runChat;
|
package/dist/webui/index.d.ts
DELETED
package/dist/webui/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Placeholder for the standalone browser-based agent UI (nova-ai-cli --web),
|
|
3
|
-
* separate from src/acp/web which only handles the --setup auth page.
|
|
4
|
-
*/
|
|
5
|
-
async function runWebUi(...args) {
|
|
6
|
-
console.log("nova-ai-cli --web is a work in progress — the browser UI isn't built yet.");
|
|
7
|
-
console.log("Use `nova-ai-cli` for the terminal chat, or `nova-ai-cli --acp` for ACP mode.");
|
|
8
|
-
}
|
|
9
|
-
export default runWebUi;
|