@agent-api/cli 0.2.1 → 0.3.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.
Files changed (61) hide show
  1. package/README.md +11 -5
  2. package/dist/index.js +8 -6
  3. package/dist/runtime.d.ts +4 -0
  4. package/dist/runtime.js +4 -0
  5. package/dist/tui/ink/app.d.ts +1 -1
  6. package/dist/tui/ink/app.js +27 -130
  7. package/dist/tui/ink/components.d.ts +1 -2
  8. package/dist/tui/ink/components.js +1 -3
  9. package/package.json +9 -6
  10. package/dist/agent/runner.d.ts +0 -117
  11. package/dist/agent/runner.js +0 -486
  12. package/dist/agent.d.ts +0 -2
  13. package/dist/agent.js +0 -2
  14. package/dist/chat-options.d.ts +0 -37
  15. package/dist/chat-options.js +0 -42
  16. package/dist/config.d.ts +0 -66
  17. package/dist/config.js +0 -201
  18. package/dist/conversation/index.d.ts +0 -17
  19. package/dist/conversation/index.js +0 -54
  20. package/dist/profile.d.ts +0 -57
  21. package/dist/profile.js +0 -211
  22. package/dist/runtime/index.d.ts +0 -5
  23. package/dist/runtime/index.js +0 -152
  24. package/dist/tui/workbench.d.ts +0 -187
  25. package/dist/tui/workbench.js +0 -392
  26. package/dist/update.d.ts +0 -16
  27. package/dist/update.js +0 -74
  28. package/dist/workbench/auth-controller.d.ts +0 -43
  29. package/dist/workbench/auth-controller.js +0 -84
  30. package/dist/workbench/auth-gate-controller.d.ts +0 -62
  31. package/dist/workbench/auth-gate-controller.js +0 -231
  32. package/dist/workbench/command-controller.d.ts +0 -29
  33. package/dist/workbench/command-controller.js +0 -426
  34. package/dist/workbench/conversation-controller.d.ts +0 -32
  35. package/dist/workbench/conversation-controller.js +0 -53
  36. package/dist/workbench/engine.d.ts +0 -66
  37. package/dist/workbench/engine.js +0 -291
  38. package/dist/workbench/input-controller.d.ts +0 -44
  39. package/dist/workbench/input-controller.js +0 -71
  40. package/dist/workbench/isolator-installer.d.ts +0 -29
  41. package/dist/workbench/isolator-installer.js +0 -208
  42. package/dist/workbench/lifecycle-controller.d.ts +0 -30
  43. package/dist/workbench/lifecycle-controller.js +0 -75
  44. package/dist/workbench/local-controller.d.ts +0 -21
  45. package/dist/workbench/local-controller.js +0 -94
  46. package/dist/workbench/render-model.d.ts +0 -46
  47. package/dist/workbench/render-model.js +0 -61
  48. package/dist/workbench/runtime-controller.d.ts +0 -12
  49. package/dist/workbench/runtime-controller.js +0 -57
  50. package/dist/workbench/session.d.ts +0 -27
  51. package/dist/workbench/session.js +0 -42
  52. package/dist/workbench/settings-controller.d.ts +0 -80
  53. package/dist/workbench/settings-controller.js +0 -309
  54. package/dist/workbench/shell-isolation.d.ts +0 -20
  55. package/dist/workbench/shell-isolation.js +0 -13
  56. package/dist/workbench/turn-controller.d.ts +0 -25
  57. package/dist/workbench/turn-controller.js +0 -164
  58. package/dist/workbench/view-model.d.ts +0 -34
  59. package/dist/workbench/view-model.js +0 -121
  60. package/dist/workdir/index.d.ts +0 -22
  61. package/dist/workdir/index.js +0 -46
@@ -1,152 +0,0 @@
1
- import { createLocalRuntime } from "@agent-api/sdk/local";
2
- import { cp, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
3
- import path from "node:path";
4
- export const cliName = "agent-tui";
5
- export const cliAuthor = "AgentsWay";
6
- export const cliVersion = "0.2.1";
7
- const legacyCliName = "agent-api-cli";
8
- export const runtime = createLocalRuntime({
9
- appName: cliName,
10
- appAuthor: cliAuthor,
11
- });
12
- const legacyRuntime = createLocalRuntime({
13
- appName: legacyCliName,
14
- appAuthor: cliAuthor,
15
- });
16
- let migrationPromise = null;
17
- export async function ensureRuntime() {
18
- migrationPromise ??= migrateLegacyRuntime();
19
- await migrationPromise;
20
- await runtime.ensure();
21
- await splitMonolithicConfig();
22
- return runtime;
23
- }
24
- async function migrateLegacyRuntime() {
25
- await migrateLegacyConfigDirectory();
26
- for (const key of ["data", "cache", "logs"]) {
27
- await moveDirectoryIfNeeded(legacyRuntime.dirs[key], runtime.dirs[key]);
28
- }
29
- }
30
- async function moveDirectoryIfNeeded(from, to) {
31
- if (from === to || !(await isDirectory(from)))
32
- return;
33
- await mkdir(path.dirname(to), { recursive: true });
34
- if (await pathExists(to)) {
35
- await cp(from, to, { recursive: true, errorOnExist: false, force: false });
36
- await rm(from, { recursive: true, force: true });
37
- return;
38
- }
39
- try {
40
- await rename(from, to);
41
- }
42
- catch (error) {
43
- if (error?.code !== "EXDEV")
44
- throw error;
45
- await cp(from, to, { recursive: true, errorOnExist: false });
46
- await rm(from, { recursive: true, force: true });
47
- }
48
- }
49
- async function migrateLegacyConfigDirectory() {
50
- const from = legacyRuntime.dirs.config;
51
- const to = runtime.dirs.config;
52
- if (from === to || !(await isDirectory(from)))
53
- return;
54
- await mkdir(to, { recursive: true });
55
- const legacyProfilesPath = path.join(from, "profiles.json");
56
- const profilesPath = path.join(to, "profiles.json");
57
- const legacyRaw = await readJSONRecord(legacyProfilesPath);
58
- if (legacyRaw) {
59
- const nextRaw = await readJSONRecord(profilesPath) ?? {};
60
- const legacyProfiles = recordValue(legacyRaw.profiles);
61
- const nextProfiles = recordValue(nextRaw.profiles);
62
- const mergedProfiles = { ...legacyProfiles, ...nextProfiles };
63
- const activeProfile = typeof nextRaw.activeProfile === "string"
64
- ? nextRaw.activeProfile
65
- : typeof legacyRaw.activeProfile === "string"
66
- ? legacyRaw.activeProfile
67
- : "default";
68
- await writeJSON(profilesPath, { ...nextRaw, activeProfile, profiles: mergedProfiles });
69
- const configurationPath = path.join(to, "configuration.json");
70
- if ("workbench" in legacyRaw && !(await pathExists(configurationPath))) {
71
- await writeJSON(configurationPath, { workbench: recordValue(legacyRaw.workbench) });
72
- }
73
- const conversationsPath = path.join(to, "conversations.json");
74
- if ("conversations" in legacyRaw && !(await pathExists(conversationsPath))) {
75
- await writeJSON(conversationsPath, { conversations: recordValue(legacyRaw.conversations) });
76
- }
77
- }
78
- await copyFileIfMissing(path.join(from, "configuration.json"), path.join(to, "configuration.json"));
79
- await copyFileIfMissing(path.join(from, "conversations.json"), path.join(to, "conversations.json"));
80
- await rm(from, { recursive: true, force: true });
81
- }
82
- async function splitMonolithicConfig() {
83
- const profilesPath = path.join(runtime.dirs.config, "profiles.json");
84
- const raw = await readJSONRecord(profilesPath);
85
- if (!raw)
86
- return;
87
- let changed = false;
88
- if ("workbench" in raw && !(await pathExists(path.join(runtime.dirs.config, "configuration.json")))) {
89
- await writeJSON(path.join(runtime.dirs.config, "configuration.json"), { workbench: raw.workbench && typeof raw.workbench === "object" ? raw.workbench : {} });
90
- }
91
- if ("workbench" in raw) {
92
- delete raw.workbench;
93
- changed = true;
94
- }
95
- if ("conversations" in raw && !(await pathExists(path.join(runtime.dirs.config, "conversations.json")))) {
96
- await writeJSON(path.join(runtime.dirs.config, "conversations.json"), {
97
- conversations: raw.conversations && typeof raw.conversations === "object" ? raw.conversations : {},
98
- });
99
- }
100
- if ("conversations" in raw) {
101
- delete raw.conversations;
102
- changed = true;
103
- }
104
- if (changed) {
105
- await writeJSON(profilesPath, raw);
106
- }
107
- }
108
- function recordValue(value) {
109
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
110
- }
111
- async function readJSONRecord(file) {
112
- try {
113
- const value = JSON.parse(await readFile(file, "utf8"));
114
- return value && typeof value === "object" && !Array.isArray(value) ? value : null;
115
- }
116
- catch (error) {
117
- if (error?.code === "ENOENT")
118
- return null;
119
- throw error;
120
- }
121
- }
122
- async function writeJSON(file, value) {
123
- await mkdir(path.dirname(file), { recursive: true });
124
- await writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
125
- }
126
- async function copyFileIfMissing(from, to) {
127
- if (!(await pathExists(from)) || await pathExists(to))
128
- return;
129
- await mkdir(path.dirname(to), { recursive: true });
130
- await cp(from, to, { errorOnExist: true, force: false });
131
- }
132
- async function pathExists(file) {
133
- try {
134
- await stat(file);
135
- return true;
136
- }
137
- catch (error) {
138
- if (error?.code === "ENOENT")
139
- return false;
140
- throw error;
141
- }
142
- }
143
- async function isDirectory(file) {
144
- try {
145
- return (await stat(file)).isDirectory();
146
- }
147
- catch (error) {
148
- if (error?.code === "ENOENT")
149
- return false;
150
- throw error;
151
- }
152
- }
@@ -1,187 +0,0 @@
1
- import type { LocalToolApprovalRequest, WorkdirAccessMode } from "../agent.js";
2
- import type { ShellIsolationPreferences } from "../workbench/shell-isolation.js";
3
- export type WorkbenchRole = "user" | "assistant" | "system";
4
- export interface WorkbenchMessage {
5
- id: string;
6
- role: WorkbenchRole;
7
- text: string;
8
- }
9
- export type ActivityLevel = "info" | "success" | "warning" | "error";
10
- export interface WorkbenchActivity {
11
- id: string;
12
- level: ActivityLevel;
13
- text: string;
14
- timestamp: number;
15
- }
16
- export interface WorkbenchWorkdirStatus {
17
- root: string;
18
- name: string;
19
- fileCount: number;
20
- totalBytes: number;
21
- scanTruncated: boolean;
22
- }
23
- export interface LocalToolApproval extends LocalToolApprovalRequest {
24
- id: string;
25
- createdAt: number;
26
- }
27
- export type RenderMode = "markdown" | "raw";
28
- export interface WorkbenchState {
29
- messages: WorkbenchMessage[];
30
- activities: WorkbenchActivity[];
31
- busy: boolean;
32
- contextEnabled: boolean;
33
- workdir: WorkbenchWorkdirStatus | null;
34
- activeAssistantMessageId: string | null;
35
- pendingLocalTool: LocalToolApproval | null;
36
- accessMode: WorkdirAccessMode;
37
- currentConversation: string;
38
- runPreset?: string;
39
- runModel?: string;
40
- renderMode: RenderMode;
41
- defaultPreset?: string | null;
42
- shellIsolation?: ShellIsolationPreferences;
43
- }
44
- export interface InputHistory {
45
- record(value: string): void;
46
- previous(currentDraft: string): string;
47
- next(currentDraft: string): string;
48
- reset(): void;
49
- values(): string[];
50
- }
51
- export type WorkbenchAction = {
52
- type: "message.add";
53
- role: WorkbenchRole;
54
- text: string;
55
- id?: string;
56
- } | {
57
- type: "message.append";
58
- id: string;
59
- delta: string;
60
- } | {
61
- type: "messages.clear";
62
- } | {
63
- type: "activity.add";
64
- level?: ActivityLevel;
65
- text: string;
66
- } | {
67
- type: "busy.set";
68
- busy: boolean;
69
- } | {
70
- type: "context.toggle";
71
- } | {
72
- type: "context.set";
73
- enabled: boolean;
74
- } | {
75
- type: "workdir.set";
76
- workdir: WorkbenchWorkdirStatus;
77
- } | {
78
- type: "assistant.active";
79
- id: string | null;
80
- } | {
81
- type: "local_tool.pending.set";
82
- approval: LocalToolApprovalRequest;
83
- } | {
84
- type: "local_tool.pending.clear";
85
- } | {
86
- type: "access.set";
87
- mode: WorkdirAccessMode;
88
- } | {
89
- type: "conversation.set";
90
- name: string;
91
- } | {
92
- type: "settings.set";
93
- settings: Partial<Pick<WorkbenchState, "runPreset" | "runModel" | "renderMode" | "defaultPreset" | "shellIsolation">>;
94
- };
95
- export type WorkbenchCommand = {
96
- kind: "invalid";
97
- command: string;
98
- } | {
99
- kind: "abort";
100
- } | {
101
- kind: "quit";
102
- } | {
103
- kind: "help";
104
- } | {
105
- kind: "clear";
106
- } | {
107
- kind: "login";
108
- } | {
109
- kind: "logout";
110
- } | {
111
- kind: "delete_profile";
112
- } | {
113
- kind: "switch_profile";
114
- name?: string;
115
- } | {
116
- kind: "auth_status";
117
- } | {
118
- kind: "config";
119
- field?: "preset" | "isolation" | "isolator";
120
- value?: string;
121
- } | {
122
- kind: "render";
123
- mode?: RenderMode;
124
- } | {
125
- kind: "transcript";
126
- } | {
127
- kind: "export";
128
- path?: string;
129
- } | {
130
- kind: "context";
131
- enabled?: boolean;
132
- } | {
133
- kind: "workdir";
134
- enabled?: boolean;
135
- } | {
136
- kind: "access";
137
- mode?: WorkdirAccessMode;
138
- } | {
139
- kind: "preset";
140
- value?: string;
141
- } | {
142
- kind: "model";
143
- value?: string;
144
- } | {
145
- kind: "summary";
146
- } | {
147
- kind: "search";
148
- query: string;
149
- } | {
150
- kind: "new_conversation";
151
- name?: string;
152
- } | {
153
- kind: "switch_conversation";
154
- name: string;
155
- } | {
156
- kind: "list_conversations";
157
- } | {
158
- kind: "refresh_catalog";
159
- } | {
160
- kind: "preview";
161
- } | {
162
- kind: "apply";
163
- } | {
164
- kind: "apply_all";
165
- } | {
166
- kind: "reject";
167
- };
168
- export declare function createInitialWorkbenchState(options: {
169
- contextEnabled: boolean;
170
- accessMode?: WorkdirAccessMode;
171
- conversation?: string;
172
- preset?: string;
173
- model?: string;
174
- renderMode?: RenderMode;
175
- defaultPreset?: string | null;
176
- shellIsolation?: ShellIsolationPreferences;
177
- }): WorkbenchState;
178
- export declare function createInputHistory(limit?: number): InputHistory;
179
- export declare function workbenchReducer(state: WorkbenchState, action: WorkbenchAction): WorkbenchState;
180
- export declare function parseWorkbenchCommand(input: string): WorkbenchCommand | null;
181
- export declare function parsePendingApprovalCommand(input: string): WorkbenchCommand | null;
182
- export declare function helpText(): string;
183
- export declare function formatTranscript(messages: WorkbenchMessage[]): string;
184
- export declare function formatTranscriptPreview(messages: WorkbenchMessage[], maxLines?: number): string;
185
- export declare function workdirText(status: WorkbenchWorkdirStatus | null): string;
186
- export declare function formatBytes(bytes: number): string;
187
- export declare function activityColor(level: ActivityLevel): "green" | "yellow" | "red" | "gray";