@agent-api/cli 0.0.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 +21 -0
- package/README.md +231 -0
- package/dist/agent/runner.d.ts +115 -0
- package/dist/agent/runner.js +483 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +2 -0
- package/dist/chat-options.d.ts +37 -0
- package/dist/chat-options.js +42 -0
- package/dist/config.d.ts +44 -0
- package/dist/config.js +111 -0
- package/dist/conversation/index.d.ts +17 -0
- package/dist/conversation/index.js +54 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +308 -0
- package/dist/profile.d.ts +57 -0
- package/dist/profile.js +211 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +12 -0
- package/dist/tui/chat.d.ts +5 -0
- package/dist/tui/chat.js +1276 -0
- package/dist/tui/workbench.d.ts +154 -0
- package/dist/tui/workbench.js +288 -0
- package/dist/update.d.ts +16 -0
- package/dist/update.js +74 -0
- package/dist/workdir/index.d.ts +22 -0
- package/dist/workdir/index.js +46 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 scalebox-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Agent API CLI
|
|
2
|
+
|
|
3
|
+
First-class command line interface for Agent API. The CLI is built on `@agent-api/sdk@^1.2.2` with Commander for command routing and Ink for interactive terminal UI.
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
cd cli
|
|
9
|
+
npm install
|
|
10
|
+
npm run build
|
|
11
|
+
node dist/index.js --help
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Create local development commands:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm run dev:link
|
|
18
|
+
agent-tui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Local Release
|
|
22
|
+
|
|
23
|
+
The TUI is distributed as a normal npm CLI package. The app does not self-update;
|
|
24
|
+
startup may show a lightweight update notice, and users update with npm:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @agent-api/cli@latest
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Prepare, verify, and publish a local release:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cd cli
|
|
34
|
+
npm run release:local
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If your npm account requires two-factor auth for publish:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run release:local -- --otp 123456
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The local release script runs `npm ci`, builds and tests the package, creates an
|
|
44
|
+
npm tarball in `artifacts/`, installs that tarball into a temporary npm prefix,
|
|
45
|
+
smoke-tests the published bin aliases, and then publishes the verified tarball
|
|
46
|
+
with `npm publish --access public`.
|
|
47
|
+
|
|
48
|
+
For a no-publish rehearsal:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm run release:local -- --dry-run
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Set `AGENT_TUI_UPDATE_CHECK=0` to disable the startup update notice.
|
|
55
|
+
|
|
56
|
+
## Command Shape
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
agent-tui
|
|
60
|
+
agent-api
|
|
61
|
+
agent-api auth login
|
|
62
|
+
agent-api profiles list
|
|
63
|
+
agent-api agent chat
|
|
64
|
+
agent-api workdir status
|
|
65
|
+
agent-api doctor
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Interactive Workbench
|
|
69
|
+
|
|
70
|
+
Launch the first-class TUI from your current directory:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
agent-tui
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The workbench opens with auth as the first gate. If the active profile is valid,
|
|
77
|
+
it enters the conversation UI automatically. If not, it shows an in-terminal
|
|
78
|
+
auth picker for browser session or API key login.
|
|
79
|
+
|
|
80
|
+
Inside the workbench, configure the agent run dynamically:
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
/auth show current auth profile
|
|
84
|
+
/login return to auth gate without deleting profiles
|
|
85
|
+
/logout leave current session and return to auth gate
|
|
86
|
+
/switch-profile switch/sign in with a different profile
|
|
87
|
+
/delete-profile delete current saved profile and return to auth
|
|
88
|
+
/config show current run configuration
|
|
89
|
+
/preset <name> set preset; /preset none clears it
|
|
90
|
+
/model <name> set explicit model; /model auto clears it
|
|
91
|
+
/access full allow local workdir actions without approval
|
|
92
|
+
/access approval require approval for local workdir actions
|
|
93
|
+
/context toggle local workdir context/tools for each turn
|
|
94
|
+
/new [name] start a fresh conversation
|
|
95
|
+
/switch <name> switch conversation handle
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The current working directory is loaded as the local workdir. Local workdir
|
|
99
|
+
tools are only exposed to the model when you enable local context with
|
|
100
|
+
`/context` or start with `--workdir`.
|
|
101
|
+
|
|
102
|
+
## Authentication
|
|
103
|
+
|
|
104
|
+
The interactive workbench checks the active profile before it starts. If no valid
|
|
105
|
+
profile exists, it opens an in-terminal auth picker with two choices:
|
|
106
|
+
|
|
107
|
+
- Browser session: best for desktop environments and refreshable long-running use.
|
|
108
|
+
- API key: best for shell-only servers, CI, and remote terminals.
|
|
109
|
+
|
|
110
|
+
You can also sign in explicitly from the shell. Browser login is the default for
|
|
111
|
+
humans:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
agent-api auth login --profile work --base-url https://api.agentsway.dev
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
API keys are supported for shell-only environments and automation:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
agent-api auth login --profile ci --api-key sk-...
|
|
121
|
+
agent-api auth whoami --profile ci
|
|
122
|
+
agent-api auth logout --profile ci
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Profiles:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
agent-api profiles list
|
|
129
|
+
agent-api profiles use work
|
|
130
|
+
agent-api profiles show
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Agent Conversations
|
|
134
|
+
|
|
135
|
+
Chat with the remote agent:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
agent-api agent chat "Summarize the current release status" --preset pro-search
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Start the interactive TUI with explicit options:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
agent-api agent chat --conversation release --workdir .
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Named conversations continue automatically:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
agent-api agent chat "Draft the implementation plan" --conversation release
|
|
151
|
+
agent-api agent chat "Now turn that into a checklist" --conversation release
|
|
152
|
+
agent-api agent list
|
|
153
|
+
agent-api agent show release
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Attach local workdir context:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
agent-api agent chat "Review this project and suggest next steps" \
|
|
160
|
+
--workdir . \
|
|
161
|
+
--context-query auth \
|
|
162
|
+
--max-context-files 80
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The CLI sends local context as bounded, secret-aware project context. The remote Agent API remains the core execution path.
|
|
166
|
+
|
|
167
|
+
Workdir access defaults to approval mode:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
agent-api agent chat --workdir . --access approval
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Use full access only for trusted workdirs. In full access mode, valid edit proposals are previewed and applied automatically:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
agent-api agent chat --workdir . --access full
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Local Workdir
|
|
180
|
+
|
|
181
|
+
The CLI uses the SDK local layer for workdir operations:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
agent-api workdir status --path .
|
|
185
|
+
agent-api workdir summary --path .
|
|
186
|
+
agent-api workdir context --path . --query auth --max-files 40
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Inside the interactive workbench:
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
/auth show current auth profile
|
|
193
|
+
/login return to auth gate without deleting profiles
|
|
194
|
+
/logout leave current session and return to auth gate
|
|
195
|
+
/switch-profile switch/sign in with a different profile
|
|
196
|
+
/delete-profile delete current saved profile and return to auth
|
|
197
|
+
/config show current run configuration
|
|
198
|
+
/workdir show local workdir summary
|
|
199
|
+
/summary show local workdir previews
|
|
200
|
+
/search <query> search text in the local workdir
|
|
201
|
+
/preset <name> set or clear preset
|
|
202
|
+
/model <name> set or clear explicit model
|
|
203
|
+
/access <mode> approval or full
|
|
204
|
+
/context toggle local context packaging for each turn
|
|
205
|
+
/clear clear visible transcript
|
|
206
|
+
/quit quit
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Local Edit Approval
|
|
210
|
+
|
|
211
|
+
The workbench can preview and apply local line edits through the SDK local workdir layer:
|
|
212
|
+
|
|
213
|
+
```text
|
|
214
|
+
/edit {"description":"Rename heading","edits":[{"path":"README.md","startLine":1,"endLine":1,"replacement":"# New Heading"}]}
|
|
215
|
+
/preview
|
|
216
|
+
/apply
|
|
217
|
+
/reject
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Edits are previewed before they are applied. Apply uses the SDK edit path with rollback on failure.
|
|
221
|
+
In `--access full`, valid proposals are applied immediately after preview generation.
|
|
222
|
+
|
|
223
|
+
When a workdir is attached, the CLI also tells the remote agent to return local changes as a fenced JSON block:
|
|
224
|
+
|
|
225
|
+
````text
|
|
226
|
+
```agent_api_local_edits
|
|
227
|
+
{"description":"short reason","edits":[{"path":"README.md","startLine":1,"endLine":1,"replacement":"# New Heading"}]}
|
|
228
|
+
```
|
|
229
|
+
````
|
|
230
|
+
|
|
231
|
+
Detected agent proposals go through the same approval/full-access flow as manual `/edit` proposals.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type AgentResponse, type PresetToolCatalogClient, type ResponseStreamEvent, type Tool } from "@agent-api/sdk";
|
|
2
|
+
export interface AgentRunOptions {
|
|
3
|
+
profile?: string;
|
|
4
|
+
promptParts: string[];
|
|
5
|
+
file?: string;
|
|
6
|
+
stdin?: boolean;
|
|
7
|
+
preset?: string;
|
|
8
|
+
presetExplicit?: boolean;
|
|
9
|
+
model?: string;
|
|
10
|
+
modelExplicit?: boolean;
|
|
11
|
+
stream?: boolean;
|
|
12
|
+
conversation?: string;
|
|
13
|
+
continueConversation?: boolean;
|
|
14
|
+
restartConversation?: boolean;
|
|
15
|
+
previousResponseId?: string;
|
|
16
|
+
workdir?: string;
|
|
17
|
+
includeLocalContext?: boolean;
|
|
18
|
+
contextQuery?: string;
|
|
19
|
+
maxContextFiles?: number;
|
|
20
|
+
maxContextBytes?: number;
|
|
21
|
+
accessMode?: WorkdirAccessMode;
|
|
22
|
+
abortSignal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
export type WorkdirAccessMode = "off" | "approval" | "full";
|
|
25
|
+
export interface AgentTurnResult {
|
|
26
|
+
text: string;
|
|
27
|
+
responseID?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface LocalToolApprovalRequest {
|
|
30
|
+
name: string;
|
|
31
|
+
action?: string;
|
|
32
|
+
arguments: Record<string, unknown>;
|
|
33
|
+
preview?: unknown;
|
|
34
|
+
callID: string;
|
|
35
|
+
responseID: string;
|
|
36
|
+
}
|
|
37
|
+
export type AgentTurnEvent = {
|
|
38
|
+
type: "text.delta";
|
|
39
|
+
delta: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "response.started";
|
|
42
|
+
responseID?: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: "response.completed";
|
|
45
|
+
responseID?: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "response.failed";
|
|
48
|
+
message: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "reasoning.started";
|
|
51
|
+
} | {
|
|
52
|
+
type: "reasoning.stopped";
|
|
53
|
+
thought?: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: "reasoning.search_queries";
|
|
56
|
+
queries: string[];
|
|
57
|
+
} | {
|
|
58
|
+
type: "reasoning.search_results";
|
|
59
|
+
count: number;
|
|
60
|
+
} | {
|
|
61
|
+
type: "reasoning.fetch_url_queries";
|
|
62
|
+
urls: string[];
|
|
63
|
+
} | {
|
|
64
|
+
type: "reasoning.fetch_url_results";
|
|
65
|
+
count: number;
|
|
66
|
+
} | {
|
|
67
|
+
type: "tool.completed";
|
|
68
|
+
name: string;
|
|
69
|
+
status?: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: "local_tool.completed";
|
|
72
|
+
name: string;
|
|
73
|
+
action?: string;
|
|
74
|
+
requiresApproval?: boolean;
|
|
75
|
+
} | ({
|
|
76
|
+
type: "local_tool.approval_requested";
|
|
77
|
+
} & LocalToolApprovalRequest) | {
|
|
78
|
+
type: "model.requested";
|
|
79
|
+
model?: string;
|
|
80
|
+
provider?: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: "model.completed";
|
|
83
|
+
model?: string;
|
|
84
|
+
provider?: string;
|
|
85
|
+
} | {
|
|
86
|
+
type: "model.failed";
|
|
87
|
+
model?: string;
|
|
88
|
+
provider?: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "step.completed";
|
|
91
|
+
stepType?: string;
|
|
92
|
+
} | {
|
|
93
|
+
type: "step.failed";
|
|
94
|
+
stepType?: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: "raw";
|
|
97
|
+
eventType: string;
|
|
98
|
+
};
|
|
99
|
+
export interface ResolveAgentRequestToolsOptions {
|
|
100
|
+
baseURL?: string;
|
|
101
|
+
cacheTTLMS?: number;
|
|
102
|
+
}
|
|
103
|
+
export interface PresetSummary {
|
|
104
|
+
preset: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
}
|
|
107
|
+
export declare function runAgent(options: AgentRunOptions): Promise<void>;
|
|
108
|
+
export declare function runAgentTurn(options: AgentRunOptions, onEvent?: (event: AgentTurnEvent) => void): Promise<AgentTurnResult>;
|
|
109
|
+
export declare function resumeAgentAfterLocalApproval(options: AgentRunOptions, approval: LocalToolApprovalRequest, output: string | Record<string, unknown>, onEvent?: (event: AgentTurnEvent) => void): Promise<AgentTurnResult>;
|
|
110
|
+
export declare function listAvailablePresets(profileName?: string): Promise<PresetSummary[]>;
|
|
111
|
+
export declare function isAvailablePreset(profileName: string | undefined, preset: string): Promise<boolean>;
|
|
112
|
+
export declare function agentResponseFailureMessage(response: AgentResponse): string;
|
|
113
|
+
export declare function agentTurnEventFromStreamEvent(event: ResponseStreamEvent): AgentTurnEvent | null;
|
|
114
|
+
export declare function resolveAgentRequestTools(client: PresetToolCatalogClient, preset?: string, tools?: readonly Tool[], options?: ResolveAgentRequestToolsOptions): Promise<Tool[] | undefined>;
|
|
115
|
+
export declare function clearPresetToolCatalogCache(baseURL?: string): void;
|