@agent-api/cli 0.2.0 → 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.
- package/README.md +11 -5
- package/dist/index.js +8 -6
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +4 -0
- package/dist/tui/ink/app.d.ts +1 -1
- package/dist/tui/ink/app.js +27 -126
- package/dist/tui/ink/components.d.ts +1 -2
- package/dist/tui/ink/components.js +1 -3
- package/package.json +9 -6
- package/dist/agent/runner.d.ts +0 -117
- package/dist/agent/runner.js +0 -486
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +0 -2
- package/dist/chat-options.d.ts +0 -37
- package/dist/chat-options.js +0 -42
- package/dist/config.d.ts +0 -66
- package/dist/config.js +0 -201
- package/dist/conversation/index.d.ts +0 -17
- package/dist/conversation/index.js +0 -54
- package/dist/profile.d.ts +0 -57
- package/dist/profile.js +0 -211
- package/dist/runtime/index.d.ts +0 -5
- package/dist/runtime/index.js +0 -104
- package/dist/tui/workbench.d.ts +0 -187
- package/dist/tui/workbench.js +0 -392
- package/dist/update.d.ts +0 -16
- package/dist/update.js +0 -74
- package/dist/workbench/auth-controller.d.ts +0 -43
- package/dist/workbench/auth-controller.js +0 -84
- package/dist/workbench/auth-gate-controller.d.ts +0 -62
- package/dist/workbench/auth-gate-controller.js +0 -231
- package/dist/workbench/command-controller.d.ts +0 -29
- package/dist/workbench/command-controller.js +0 -426
- package/dist/workbench/conversation-controller.d.ts +0 -32
- package/dist/workbench/conversation-controller.js +0 -53
- package/dist/workbench/engine.d.ts +0 -66
- package/dist/workbench/engine.js +0 -291
- package/dist/workbench/input-controller.d.ts +0 -44
- package/dist/workbench/input-controller.js +0 -71
- package/dist/workbench/isolator-installer.d.ts +0 -29
- package/dist/workbench/isolator-installer.js +0 -208
- package/dist/workbench/lifecycle-controller.d.ts +0 -30
- package/dist/workbench/lifecycle-controller.js +0 -75
- package/dist/workbench/local-controller.d.ts +0 -21
- package/dist/workbench/local-controller.js +0 -94
- package/dist/workbench/render-model.d.ts +0 -46
- package/dist/workbench/render-model.js +0 -61
- package/dist/workbench/runtime-controller.d.ts +0 -12
- package/dist/workbench/runtime-controller.js +0 -57
- package/dist/workbench/session.d.ts +0 -27
- package/dist/workbench/session.js +0 -42
- package/dist/workbench/settings-controller.d.ts +0 -79
- package/dist/workbench/settings-controller.js +0 -288
- package/dist/workbench/shell-isolation.d.ts +0 -20
- package/dist/workbench/shell-isolation.js +0 -13
- package/dist/workbench/turn-controller.d.ts +0 -25
- package/dist/workbench/turn-controller.js +0 -164
- package/dist/workbench/view-model.d.ts +0 -34
- package/dist/workbench/view-model.js +0 -121
- package/dist/workdir/index.d.ts +0 -22
- package/dist/workdir/index.js +0 -46
package/dist/tui/workbench.d.ts
DELETED
|
@@ -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";
|
package/dist/tui/workbench.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
export function createInitialWorkbenchState(options) {
|
|
2
|
-
const accessMode = options.accessMode ?? (options.contextEnabled ? "approval" : "off");
|
|
3
|
-
return {
|
|
4
|
-
messages: [
|
|
5
|
-
newMessage("system", "Agent API Workbench is ready. Type /help for commands."),
|
|
6
|
-
],
|
|
7
|
-
activities: [
|
|
8
|
-
newActivity("info", "Workbench started"),
|
|
9
|
-
],
|
|
10
|
-
busy: false,
|
|
11
|
-
contextEnabled: options.contextEnabled || accessMode === "approval" || accessMode === "full",
|
|
12
|
-
workdir: null,
|
|
13
|
-
activeAssistantMessageId: null,
|
|
14
|
-
pendingLocalTool: null,
|
|
15
|
-
accessMode,
|
|
16
|
-
currentConversation: options.conversation || "default",
|
|
17
|
-
runPreset: options.preset,
|
|
18
|
-
runModel: options.model,
|
|
19
|
-
renderMode: options.renderMode ?? "markdown",
|
|
20
|
-
defaultPreset: options.defaultPreset,
|
|
21
|
-
shellIsolation: options.shellIsolation,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function createInputHistory(limit = 100) {
|
|
25
|
-
const entries = [];
|
|
26
|
-
let cursor = null;
|
|
27
|
-
let draftBeforeBrowse = "";
|
|
28
|
-
return {
|
|
29
|
-
record(value) {
|
|
30
|
-
const trimmed = value.trim();
|
|
31
|
-
if (!trimmed)
|
|
32
|
-
return;
|
|
33
|
-
if (entries.at(-1) !== trimmed) {
|
|
34
|
-
entries.push(trimmed);
|
|
35
|
-
if (entries.length > limit)
|
|
36
|
-
entries.splice(0, entries.length - limit);
|
|
37
|
-
}
|
|
38
|
-
cursor = null;
|
|
39
|
-
draftBeforeBrowse = "";
|
|
40
|
-
},
|
|
41
|
-
previous(currentDraft) {
|
|
42
|
-
if (entries.length === 0)
|
|
43
|
-
return currentDraft;
|
|
44
|
-
if (cursor === null) {
|
|
45
|
-
draftBeforeBrowse = currentDraft;
|
|
46
|
-
cursor = entries.length - 1;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
cursor = Math.max(0, cursor - 1);
|
|
50
|
-
}
|
|
51
|
-
return entries[cursor] ?? currentDraft;
|
|
52
|
-
},
|
|
53
|
-
next(currentDraft) {
|
|
54
|
-
if (entries.length === 0 || cursor === null)
|
|
55
|
-
return currentDraft;
|
|
56
|
-
if (cursor < entries.length - 1) {
|
|
57
|
-
cursor += 1;
|
|
58
|
-
return entries[cursor] ?? currentDraft;
|
|
59
|
-
}
|
|
60
|
-
cursor = null;
|
|
61
|
-
const restored = draftBeforeBrowse;
|
|
62
|
-
draftBeforeBrowse = "";
|
|
63
|
-
return restored;
|
|
64
|
-
},
|
|
65
|
-
reset() {
|
|
66
|
-
cursor = null;
|
|
67
|
-
draftBeforeBrowse = "";
|
|
68
|
-
},
|
|
69
|
-
values() {
|
|
70
|
-
return [...entries];
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export function workbenchReducer(state, action) {
|
|
75
|
-
switch (action.type) {
|
|
76
|
-
case "message.add":
|
|
77
|
-
return {
|
|
78
|
-
...state,
|
|
79
|
-
messages: [...state.messages, newMessage(action.role, action.text, action.id)],
|
|
80
|
-
};
|
|
81
|
-
case "message.append":
|
|
82
|
-
return {
|
|
83
|
-
...state,
|
|
84
|
-
messages: state.messages.map((message) => message.id === action.id ? { ...message, text: message.text + action.delta } : message),
|
|
85
|
-
};
|
|
86
|
-
case "messages.clear":
|
|
87
|
-
return {
|
|
88
|
-
...state,
|
|
89
|
-
messages: [newMessage("system", "Cleared. Type /help for commands.")],
|
|
90
|
-
};
|
|
91
|
-
case "activity.add":
|
|
92
|
-
return {
|
|
93
|
-
...state,
|
|
94
|
-
activities: [...state.activities, newActivity(action.level ?? "info", action.text)].slice(-20),
|
|
95
|
-
};
|
|
96
|
-
case "busy.set":
|
|
97
|
-
return { ...state, busy: action.busy };
|
|
98
|
-
case "context.toggle":
|
|
99
|
-
return setLocalAccess(state, state.contextEnabled ? "off" : "approval");
|
|
100
|
-
case "context.set":
|
|
101
|
-
return setLocalAccess(state, action.enabled ? "approval" : "off");
|
|
102
|
-
case "workdir.set":
|
|
103
|
-
return {
|
|
104
|
-
...state,
|
|
105
|
-
workdir: action.workdir,
|
|
106
|
-
activities: [...state.activities, newActivity("success", `Workdir loaded: ${action.workdir.name}`)].slice(-20),
|
|
107
|
-
};
|
|
108
|
-
case "assistant.active":
|
|
109
|
-
return { ...state, activeAssistantMessageId: action.id };
|
|
110
|
-
case "local_tool.pending.set": {
|
|
111
|
-
const pending = {
|
|
112
|
-
...action.approval,
|
|
113
|
-
id: `local-${Date.now()}`,
|
|
114
|
-
createdAt: Date.now(),
|
|
115
|
-
};
|
|
116
|
-
return {
|
|
117
|
-
...state,
|
|
118
|
-
pendingLocalTool: pending,
|
|
119
|
-
activities: [
|
|
120
|
-
...state.activities,
|
|
121
|
-
newActivity("warning", `Local approval ready: ${pending.name}${pending.action ? `.${pending.action}` : ""}`),
|
|
122
|
-
].slice(-20),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
case "local_tool.pending.clear":
|
|
126
|
-
return {
|
|
127
|
-
...state,
|
|
128
|
-
pendingLocalTool: null,
|
|
129
|
-
};
|
|
130
|
-
case "access.set":
|
|
131
|
-
return setLocalAccess(state, action.mode);
|
|
132
|
-
case "conversation.set":
|
|
133
|
-
return {
|
|
134
|
-
...state,
|
|
135
|
-
currentConversation: action.name,
|
|
136
|
-
activities: [...state.activities, newActivity("info", `Conversation: ${action.name}`)].slice(-20),
|
|
137
|
-
};
|
|
138
|
-
case "settings.set":
|
|
139
|
-
return {
|
|
140
|
-
...state,
|
|
141
|
-
...action.settings,
|
|
142
|
-
};
|
|
143
|
-
default:
|
|
144
|
-
return state;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function setLocalAccess(state, mode) {
|
|
148
|
-
return {
|
|
149
|
-
...state,
|
|
150
|
-
accessMode: mode,
|
|
151
|
-
contextEnabled: mode !== "off",
|
|
152
|
-
pendingLocalTool: mode === "off" ? null : state.pendingLocalTool,
|
|
153
|
-
activities: [...state.activities, newActivity(mode === "off" ? "warning" : "success", `Local access: ${mode}`)].slice(-20),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
export function parseWorkbenchCommand(input) {
|
|
157
|
-
const trimmed = input.trim();
|
|
158
|
-
if (!trimmed.startsWith("/"))
|
|
159
|
-
return null;
|
|
160
|
-
const [name = "", ...rest] = trimmed.slice(1).split(/\s+/);
|
|
161
|
-
switch (name) {
|
|
162
|
-
case "abort":
|
|
163
|
-
case "cancel":
|
|
164
|
-
return { kind: "abort" };
|
|
165
|
-
case "quit":
|
|
166
|
-
return { kind: "quit" };
|
|
167
|
-
case "exit":
|
|
168
|
-
return { kind: "quit" };
|
|
169
|
-
case "help":
|
|
170
|
-
return { kind: "help" };
|
|
171
|
-
case "clear":
|
|
172
|
-
return { kind: "clear" };
|
|
173
|
-
case "login":
|
|
174
|
-
case "signin":
|
|
175
|
-
return { kind: "login" };
|
|
176
|
-
case "logout":
|
|
177
|
-
case "signout":
|
|
178
|
-
return { kind: "logout" };
|
|
179
|
-
case "delete-profile":
|
|
180
|
-
case "delete_profile":
|
|
181
|
-
return { kind: "delete_profile" };
|
|
182
|
-
case "switch-profile":
|
|
183
|
-
case "switch_profile":
|
|
184
|
-
return { kind: "switch_profile", name: rest.join(" ").trim() || undefined };
|
|
185
|
-
case "auth":
|
|
186
|
-
return { kind: "auth_status" };
|
|
187
|
-
case "config":
|
|
188
|
-
case "settings": {
|
|
189
|
-
const [field, ...valueParts] = rest;
|
|
190
|
-
if (!field)
|
|
191
|
-
return { kind: "config" };
|
|
192
|
-
if (field === "preset" || field === "isolation" || field === "isolator") {
|
|
193
|
-
return { kind: "config", field, value: valueParts.join(" ").trim() || undefined };
|
|
194
|
-
}
|
|
195
|
-
return { kind: "invalid", command: `${name} ${field}` };
|
|
196
|
-
}
|
|
197
|
-
case "render":
|
|
198
|
-
case "display":
|
|
199
|
-
case "view": {
|
|
200
|
-
const mode = rest[0];
|
|
201
|
-
if (mode === "raw" || mode === "markdown")
|
|
202
|
-
return { kind: "render", mode };
|
|
203
|
-
return { kind: "render" };
|
|
204
|
-
}
|
|
205
|
-
case "transcript":
|
|
206
|
-
return { kind: "transcript" };
|
|
207
|
-
case "export":
|
|
208
|
-
return { kind: "export", path: rest.join(" ").trim() || undefined };
|
|
209
|
-
case "context":
|
|
210
|
-
return { kind: "context", enabled: parseOnOff(rest[0]) };
|
|
211
|
-
case "access": {
|
|
212
|
-
const mode = rest[0];
|
|
213
|
-
if (mode === "off" || mode === "approval" || mode === "full")
|
|
214
|
-
return { kind: "access", mode };
|
|
215
|
-
return { kind: "access" };
|
|
216
|
-
}
|
|
217
|
-
case "preset": {
|
|
218
|
-
const value = rest.join(" ").trim();
|
|
219
|
-
return { kind: "preset", value: value || undefined };
|
|
220
|
-
}
|
|
221
|
-
case "model": {
|
|
222
|
-
const value = rest.join(" ").trim();
|
|
223
|
-
return { kind: "model", value: value || undefined };
|
|
224
|
-
}
|
|
225
|
-
case "workdir":
|
|
226
|
-
case "local":
|
|
227
|
-
return { kind: "workdir", enabled: parseOnOff(rest[0]) };
|
|
228
|
-
case "summary":
|
|
229
|
-
return { kind: "summary" };
|
|
230
|
-
case "new":
|
|
231
|
-
case "thread":
|
|
232
|
-
return { kind: "new_conversation", name: rest.join(" ").trim() || undefined };
|
|
233
|
-
case "conversation":
|
|
234
|
-
case "switch":
|
|
235
|
-
case "use":
|
|
236
|
-
if (rest.length === 0)
|
|
237
|
-
return { kind: "list_conversations" };
|
|
238
|
-
return { kind: "switch_conversation", name: rest.join(" ").trim() };
|
|
239
|
-
case "conversations":
|
|
240
|
-
case "threads":
|
|
241
|
-
return { kind: "list_conversations" };
|
|
242
|
-
case "refresh":
|
|
243
|
-
case "reload":
|
|
244
|
-
case "refresh-catalog":
|
|
245
|
-
return { kind: "refresh_catalog" };
|
|
246
|
-
case "search":
|
|
247
|
-
case "grep":
|
|
248
|
-
return { kind: "search", query: rest.join(" ").trim() };
|
|
249
|
-
case "preview":
|
|
250
|
-
return { kind: "preview" };
|
|
251
|
-
case "apply":
|
|
252
|
-
return { kind: "apply" };
|
|
253
|
-
case "apply-all":
|
|
254
|
-
case "yes-all":
|
|
255
|
-
return { kind: "apply_all" };
|
|
256
|
-
case "reject":
|
|
257
|
-
return { kind: "reject" };
|
|
258
|
-
default:
|
|
259
|
-
return { kind: "invalid", command: name };
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
export function parsePendingApprovalCommand(input) {
|
|
263
|
-
const trimmed = input.trim().toLowerCase();
|
|
264
|
-
if (!trimmed.startsWith("/"))
|
|
265
|
-
return null;
|
|
266
|
-
const [name = ""] = trimmed.slice(1).split(/\s+/);
|
|
267
|
-
switch (name) {
|
|
268
|
-
case "apply":
|
|
269
|
-
case "yes":
|
|
270
|
-
return { kind: "apply" };
|
|
271
|
-
case "apply-all":
|
|
272
|
-
case "yes-all":
|
|
273
|
-
return { kind: "apply_all" };
|
|
274
|
-
case "reject":
|
|
275
|
-
case "no":
|
|
276
|
-
return { kind: "reject" };
|
|
277
|
-
default:
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
export function helpText() {
|
|
282
|
-
return [
|
|
283
|
-
"Commands:",
|
|
284
|
-
"/auth show current auth profile",
|
|
285
|
-
"/login return to auth gate without deleting profiles",
|
|
286
|
-
"/logout leave current session and return to auth gate",
|
|
287
|
-
"/switch-profile switch/sign in with a different profile",
|
|
288
|
-
"/delete-profile delete current saved profile and return to auth",
|
|
289
|
-
"/config show current run configuration and saved defaults",
|
|
290
|
-
"/render [mode] show or set output rendering: markdown or raw",
|
|
291
|
-
"/transcript show a plain-text transcript preview",
|
|
292
|
-
"/export [file] save the plain-text transcript to a file",
|
|
293
|
-
"/config preset save default preset; use none/off for no preset, reset for built-in",
|
|
294
|
-
"/config isolation save shell isolation mode: none, auto, or required",
|
|
295
|
-
"/config isolator save agent-isolator path; use none/off to clear",
|
|
296
|
-
"/preset [name] show or set preset; use none/off to clear",
|
|
297
|
-
"/model [name] show or set explicit model; use auto/none/off to clear",
|
|
298
|
-
"/access [mode] show or set local tool access: off, approval, or full",
|
|
299
|
-
"/workdir show local workdir status",
|
|
300
|
-
"/workdir on shortcut for /access approval; /workdir off hides local tools",
|
|
301
|
-
"/new [name] start a fresh conversation in this workbench",
|
|
302
|
-
"/switch <name> switch to an existing/new conversation handle",
|
|
303
|
-
"/conversations list saved local conversation handles",
|
|
304
|
-
"/summary show local workdir summary previews",
|
|
305
|
-
"/search <query> search text in the local workdir",
|
|
306
|
-
"/preview show pending local action preview",
|
|
307
|
-
"/apply apply pending local action",
|
|
308
|
-
"/apply-all apply pending action and allow future local actions",
|
|
309
|
-
"/reject reject pending local action",
|
|
310
|
-
"/abort cancel the in-flight agent turn",
|
|
311
|
-
"/context toggle local context packaging for each agent turn",
|
|
312
|
-
"/clear clear the visible terminal transcript",
|
|
313
|
-
"/quit leave the workbench",
|
|
314
|
-
].join("\n");
|
|
315
|
-
}
|
|
316
|
-
export function formatTranscript(messages) {
|
|
317
|
-
return messages
|
|
318
|
-
.map((message) => {
|
|
319
|
-
const body = message.text.trimEnd();
|
|
320
|
-
return body ? `${roleLabel(message.role)}:\n${body}` : `${roleLabel(message.role)}:`;
|
|
321
|
-
})
|
|
322
|
-
.join("\n\n")
|
|
323
|
-
.trimEnd() + "\n";
|
|
324
|
-
}
|
|
325
|
-
export function formatTranscriptPreview(messages, maxLines = 80) {
|
|
326
|
-
const lines = formatTranscript(messages).trimEnd().split(/\r?\n/);
|
|
327
|
-
if (lines.length <= maxLines) {
|
|
328
|
-
return ["Transcript preview:", "", ...lines].join("\n");
|
|
329
|
-
}
|
|
330
|
-
return [
|
|
331
|
-
`Transcript preview: showing last ${maxLines} lines of ${lines.length}. Use /export [file] for the full transcript.`,
|
|
332
|
-
"",
|
|
333
|
-
...lines.slice(-maxLines),
|
|
334
|
-
].join("\n");
|
|
335
|
-
}
|
|
336
|
-
function parseOnOff(value) {
|
|
337
|
-
if (!value)
|
|
338
|
-
return undefined;
|
|
339
|
-
const normalized = value.toLowerCase();
|
|
340
|
-
if (["on", "enable", "enabled", "yes", "true"].includes(normalized))
|
|
341
|
-
return true;
|
|
342
|
-
if (["off", "disable", "disabled", "no", "false"].includes(normalized))
|
|
343
|
-
return false;
|
|
344
|
-
return undefined;
|
|
345
|
-
}
|
|
346
|
-
export function workdirText(status) {
|
|
347
|
-
if (!status)
|
|
348
|
-
return "Workdir summary is still loading.";
|
|
349
|
-
return [
|
|
350
|
-
`Workdir: ${status.root}`,
|
|
351
|
-
`Files: ${status.fileCount}`,
|
|
352
|
-
`Size: ${formatBytes(status.totalBytes)}`,
|
|
353
|
-
`Scan truncated: ${status.scanTruncated ? "yes" : "no"}`,
|
|
354
|
-
].join("\n");
|
|
355
|
-
}
|
|
356
|
-
export function formatBytes(bytes) {
|
|
357
|
-
if (bytes < 1024)
|
|
358
|
-
return `${bytes} B`;
|
|
359
|
-
if (bytes < 1024 * 1024)
|
|
360
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
361
|
-
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
362
|
-
}
|
|
363
|
-
export function activityColor(level) {
|
|
364
|
-
if (level === "success")
|
|
365
|
-
return "green";
|
|
366
|
-
if (level === "warning")
|
|
367
|
-
return "yellow";
|
|
368
|
-
if (level === "error")
|
|
369
|
-
return "red";
|
|
370
|
-
return "gray";
|
|
371
|
-
}
|
|
372
|
-
function newMessage(role, text, id = randomId()) {
|
|
373
|
-
return { id, role, text };
|
|
374
|
-
}
|
|
375
|
-
function roleLabel(role) {
|
|
376
|
-
if (role === "user")
|
|
377
|
-
return "You";
|
|
378
|
-
if (role === "assistant")
|
|
379
|
-
return "Agent";
|
|
380
|
-
return "System";
|
|
381
|
-
}
|
|
382
|
-
function newActivity(level, text) {
|
|
383
|
-
return {
|
|
384
|
-
id: randomId(),
|
|
385
|
-
level,
|
|
386
|
-
text,
|
|
387
|
-
timestamp: Date.now(),
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
function randomId() {
|
|
391
|
-
return Math.random().toString(36).slice(2);
|
|
392
|
-
}
|
package/dist/update.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface UpdateCheckResult {
|
|
2
|
-
current: string;
|
|
3
|
-
latest: string;
|
|
4
|
-
packageName: string;
|
|
5
|
-
updateAvailable: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface UpdateCheckOptions {
|
|
8
|
-
currentVersion?: string;
|
|
9
|
-
packageName?: string;
|
|
10
|
-
registryURL?: string;
|
|
11
|
-
signal?: AbortSignal;
|
|
12
|
-
timeoutMs?: number;
|
|
13
|
-
}
|
|
14
|
-
export declare function checkForUpdate(options?: UpdateCheckOptions): Promise<UpdateCheckResult | null>;
|
|
15
|
-
export declare function formatUpdateNotice(result: UpdateCheckResult): string;
|
|
16
|
-
export declare function compareVersions(a: string, b: string): number;
|
package/dist/update.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { cliVersion } from "./runtime/index.js";
|
|
2
|
-
const defaultPackageName = "@agent-api/cli";
|
|
3
|
-
const defaultRegistryURL = "https://registry.npmjs.org";
|
|
4
|
-
export async function checkForUpdate(options = {}) {
|
|
5
|
-
const packageName = options.packageName || process.env.AGENT_TUI_UPDATE_PACKAGE || defaultPackageName;
|
|
6
|
-
const current = options.currentVersion || cliVersion;
|
|
7
|
-
const registryURL = (options.registryURL || process.env.AGENT_TUI_NPM_REGISTRY || defaultRegistryURL).replace(/\/+$/, "");
|
|
8
|
-
const timeoutMs = options.timeoutMs ?? 1500;
|
|
9
|
-
const controller = new AbortController();
|
|
10
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
11
|
-
const signal = combineSignals(options.signal, controller.signal);
|
|
12
|
-
try {
|
|
13
|
-
const response = await fetch(`${registryURL}/${encodeURIComponent(packageName).replace(/^%40/, "@")}/latest`, {
|
|
14
|
-
headers: { Accept: "application/json" },
|
|
15
|
-
signal,
|
|
16
|
-
});
|
|
17
|
-
if (!response.ok)
|
|
18
|
-
return null;
|
|
19
|
-
const payload = await response.json().catch(() => undefined);
|
|
20
|
-
const latest = typeof payload?.version === "string" ? payload.version : "";
|
|
21
|
-
if (!latest)
|
|
22
|
-
return null;
|
|
23
|
-
return {
|
|
24
|
-
current,
|
|
25
|
-
latest,
|
|
26
|
-
packageName,
|
|
27
|
-
updateAvailable: compareVersions(latest, current) > 0,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function formatUpdateNotice(result) {
|
|
38
|
-
return `Update available: ${result.packageName} ${result.current} -> ${result.latest}. Run: npm install -g ${result.packageName}@latest`;
|
|
39
|
-
}
|
|
40
|
-
export function compareVersions(a, b) {
|
|
41
|
-
const left = parseVersion(a);
|
|
42
|
-
const right = parseVersion(b);
|
|
43
|
-
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
44
|
-
const delta = (left[index] ?? 0) - (right[index] ?? 0);
|
|
45
|
-
if (delta !== 0)
|
|
46
|
-
return delta > 0 ? 1 : -1;
|
|
47
|
-
}
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
function parseVersion(version) {
|
|
51
|
-
return version
|
|
52
|
-
.replace(/^[^\d]*/, "")
|
|
53
|
-
.split(/[.-]/)
|
|
54
|
-
.slice(0, 3)
|
|
55
|
-
.map((part) => {
|
|
56
|
-
const parsed = Number.parseInt(part, 10);
|
|
57
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function combineSignals(...signals) {
|
|
61
|
-
const active = signals.filter((signal) => Boolean(signal));
|
|
62
|
-
if (active.length === 1)
|
|
63
|
-
return active[0];
|
|
64
|
-
const controller = new AbortController();
|
|
65
|
-
const abort = () => controller.abort();
|
|
66
|
-
for (const signal of active) {
|
|
67
|
-
if (signal.aborted) {
|
|
68
|
-
controller.abort();
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
72
|
-
}
|
|
73
|
-
return controller.signal;
|
|
74
|
-
}
|