@datalabrotterdam/nova-ai-cli 1.0.1-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/LICENSE +201 -0
- package/README.md +148 -0
- package/dist/acp/agent.d.ts +12 -0
- package/dist/acp/agent.js +206 -0
- package/dist/acp/auth-server.d.ts +10 -0
- package/dist/acp/auth-server.js +67 -0
- package/dist/acp/credentials.d.ts +11 -0
- package/dist/acp/credentials.js +30 -0
- package/dist/acp/index.d.ts +2 -0
- package/dist/acp/index.js +20 -0
- package/dist/acp/sessions.d.ts +20 -0
- package/dist/acp/sessions.js +91 -0
- package/dist/acp/tools/index.d.ts +6 -0
- package/dist/acp/tools/index.js +5 -0
- package/dist/acp/tools/marker.d.ts +17 -0
- package/dist/acp/tools/marker.js +43 -0
- package/dist/acp/tools/permission.d.ts +2 -0
- package/dist/acp/tools/permission.js +20 -0
- package/dist/acp/tools/read-file.d.ts +2 -0
- package/dist/acp/tools/read-file.js +20 -0
- package/dist/acp/tools/registry.d.ts +4 -0
- package/dist/acp/tools/registry.js +10 -0
- package/dist/acp/tools/reporting.d.ts +3 -0
- package/dist/acp/tools/reporting.js +26 -0
- package/dist/acp/tools/run-command.d.ts +2 -0
- package/dist/acp/tools/run-command.js +29 -0
- package/dist/acp/tools/system-prompt.d.ts +2 -0
- package/dist/acp/tools/system-prompt.js +23 -0
- package/dist/acp/tools/types.d.ts +18 -0
- package/dist/acp/tools/types.js +1 -0
- package/dist/acp/tools/write-file.d.ts +2 -0
- package/dist/acp/tools/write-file.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -0
- package/dist/tui/index.d.ts +7 -0
- package/dist/tui/index.js +11 -0
- package/dist/webui/index.d.ts +6 -0
- package/dist/webui/index.js +9 -0
- package/package.json +78 -0
- package/src/acp/web/dist/assets/index-B3sTKEem.js +1 -0
- package/src/acp/web/dist/assets/index-DwysEXf2.css +1 -0
- package/src/acp/web/dist/index.html +13 -0
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("authenticate", (ctx) => agentImpl.authenticate(ctx.params))
|
|
16
|
+
.onRequest("session/prompt", (ctx) => agentImpl.prompt(ctx.params, ctx.client))
|
|
17
|
+
.onNotification("session/cancel", (ctx) => agentImpl.cancel(ctx.params))
|
|
18
|
+
.connect(stream);
|
|
19
|
+
}
|
|
20
|
+
export default runAcp;
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
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";
|
|
@@ -0,0 +1,5 @@
|
|
|
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";
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
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/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runBrowserAuth } from "./acp/auth-server.js";
|
|
3
|
+
import chat from "./tui/index.js";
|
|
4
|
+
import web from "./webui/index.js";
|
|
5
|
+
import acp from "./acp/index.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
if (args.includes("--setup")) {
|
|
9
|
+
await runBrowserAuth();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (args.includes("--acp")) {
|
|
13
|
+
await acp(...args.slice(1));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (args.includes("--web")) {
|
|
17
|
+
await web(...args.slice(1));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
await chat(...args.slice(1));
|
|
21
|
+
}
|
|
22
|
+
main().catch((err) => {
|
|
23
|
+
console.error(err);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@datalabrotterdam/nova-ai-cli",
|
|
3
|
+
"version": "1.0.1-alpha.1",
|
|
4
|
+
"description": "CLI for DataLab Rotterdam's Nova AI, with an Agent Client Protocol mode for editors/IDEs, backed by @datalabrotterdam/nova-sdk",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "DataLab Rotterdam",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"nova-ai-cli": "dist/index.js",
|
|
12
|
+
"nova-ai": "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src/acp/web/dist",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/Datalab-Rotterdam/nova-ai-cli.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Datalab-Rotterdam/nova-ai-cli/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/Datalab-Rotterdam/nova-ai-cli#readme",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "npm install --prefix src/acp/web && npm run build --prefix src/acp/web && tsc -p tsconfig.json",
|
|
35
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
36
|
+
"test": "tsc -p tsconfig.json --noEmit && npm run test:unit",
|
|
37
|
+
"test:unit": "node -e \"require('fs').rmSync('dist-test',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test \"dist-test/tests/**/*.test.js\""
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@agentclientprotocol/sdk": "^0.29.0",
|
|
41
|
+
"@datalabrotterdam/nova-sdk": "^1.3.2",
|
|
42
|
+
"@sourceregistry/node-webserver": "^1.8.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
46
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
47
|
+
"@semantic-release/git": "^10.0.1",
|
|
48
|
+
"@semantic-release/npm": "^13.1.5",
|
|
49
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
50
|
+
"@types/node": "^22.20.0",
|
|
51
|
+
"typescript": "^5.6.0"
|
|
52
|
+
},
|
|
53
|
+
"release": {
|
|
54
|
+
"branches": [
|
|
55
|
+
"main",
|
|
56
|
+
{
|
|
57
|
+
"name": "alpha",
|
|
58
|
+
"prerelease": true
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"plugins": [
|
|
62
|
+
"@semantic-release/commit-analyzer",
|
|
63
|
+
"@semantic-release/release-notes-generator",
|
|
64
|
+
"@semantic-release/changelog",
|
|
65
|
+
"@semantic-release/npm",
|
|
66
|
+
[
|
|
67
|
+
"@semantic-release/git",
|
|
68
|
+
{
|
|
69
|
+
"assets": [
|
|
70
|
+
"package.json",
|
|
71
|
+
"CHANGELOG.md"
|
|
72
|
+
],
|
|
73
|
+
"message": "nova-ai-cli(release): 🚀 v${nextRelease.version}\n\n${nextRelease.notes}"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|