@adrive/cli 0.1.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/LICENSE +202 -0
- package/README.md +84 -0
- package/dist/commands/auth-login.js +23 -0
- package/dist/commands/auth-logout.js +24 -0
- package/dist/commands/auth-status.js +20 -0
- package/dist/commands/billing.js +32 -0
- package/dist/commands/context.js +33 -0
- package/dist/commands/init.js +84 -0
- package/dist/commands/ls.js +23 -0
- package/dist/commands/plan.js +36 -0
- package/dist/commands/pull.js +29 -0
- package/dist/commands/push.js +31 -0
- package/dist/commands/run-log.js +21 -0
- package/dist/commands/search.js +37 -0
- package/dist/commands/whoami.js +13 -0
- package/dist/index.js +121 -0
- package/dist/lib/api-client.js +122 -0
- package/dist/lib/config.js +65 -0
- package/dist/lib/detect-agents.js +223 -0
- package/dist/lib/poll-auth.js +57 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @adrive/cli
|
|
2
|
+
|
|
3
|
+
The `adrive` binary — a thin CLI for [AgentDrive](https://agentdrive.sh), the persistent workspace your agents share across Claude Code, Codex, Cursor, and LangGraph.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -g @adrive/cli
|
|
9
|
+
adrive init
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or use the one-line installer:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
curl -fsSL agentdrive.sh/install | sh
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`adrive init` opens a browser to log you in (no localhost server, polling-style), then auto-detects installed agent tools (Claude Code, Cursor, Codex CLI, Cline, Continue, Zed) and wires the AgentDrive MCP server into each.
|
|
19
|
+
|
|
20
|
+
## Configuration
|
|
21
|
+
|
|
22
|
+
Stored at `$XDG_CONFIG_HOME/agentdrive/config.json`, falling back to `~/.config/agentdrive/config.json`. The file is chmod 600. Schema:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"api_url": "https://app.agentdrive.sh",
|
|
27
|
+
"api_key": "agentdrive_live_...",
|
|
28
|
+
"agent_id": "ag_...",
|
|
29
|
+
"org_id": "org_...",
|
|
30
|
+
"agent_platform": "cli",
|
|
31
|
+
"default_workspace": "ws_..."
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Commands
|
|
36
|
+
|
|
37
|
+
| Command | Purpose |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `adrive init` | First-run wizard: log in + wire MCP into every installed agent tool |
|
|
40
|
+
| `adrive auth login` | Open browser, log in, store API key |
|
|
41
|
+
| `adrive auth logout` | Wipe local credentials |
|
|
42
|
+
| `adrive auth status` | Show whether you're logged in + masked key |
|
|
43
|
+
| `adrive whoami` | Print principal info from the API |
|
|
44
|
+
| `adrive ls` | List workspaces |
|
|
45
|
+
| `adrive push <file> [--workspace ws] [--remote-path p]` | Upload a local file |
|
|
46
|
+
| `adrive pull <ws-id>/<path> [-o out]` | Download a file (stdout by default) |
|
|
47
|
+
| `adrive search <query> [--top-k N] [--platform claude-code] [--workspace ws]` | Semantic search across artifacts |
|
|
48
|
+
| `adrive context <task> [--limit N] [--workspace ws]` | Auto-pull artifacts relevant to a task |
|
|
49
|
+
| `adrive run-log <task> [--status success|failure|partial] [--ref f] [--produced f]` | Log an agent run |
|
|
50
|
+
| `adrive billing` | Open the Stripe billing portal in your browser |
|
|
51
|
+
| `adrive plan` | Show current plan, usage, and quotas |
|
|
52
|
+
|
|
53
|
+
`-v` / `--version` and `--help` work at every level.
|
|
54
|
+
|
|
55
|
+
## Authentication
|
|
56
|
+
|
|
57
|
+
`adrive` uses Cursor-style polling auth — no localhost server:
|
|
58
|
+
|
|
59
|
+
1. `adrive auth login` calls `POST /v1/auth/cli/start` to get a short-lived auth URL.
|
|
60
|
+
2. The CLI opens the URL in your default browser. You complete the login in the dashboard (Google, GitHub, or email magic link).
|
|
61
|
+
3. The CLI polls `GET /v1/auth/cli/poll?id=<id>` every 1.5s for up to 10 minutes.
|
|
62
|
+
4. On success, the returned `api_key` is stored at chmod 600.
|
|
63
|
+
|
|
64
|
+
If the browser does not auto-launch (e.g. headless server, SSH session), the URL is printed prominently so you can open it manually.
|
|
65
|
+
|
|
66
|
+
## Auto-detect + wire
|
|
67
|
+
|
|
68
|
+
`adrive init` looks for these config files and merges the AgentDrive MCP server entry in (preserving any servers you already have):
|
|
69
|
+
|
|
70
|
+
| Tool | Config path |
|
|
71
|
+
|---|---|
|
|
72
|
+
| Claude Code | `~/.claude/mcp-servers.json` |
|
|
73
|
+
| Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS), `%APPDATA%/Claude/claude_desktop_config.json` (Windows), `~/.config/Claude/claude_desktop_config.json` (Linux) |
|
|
74
|
+
| Codex CLI | `~/.codex/config.toml` |
|
|
75
|
+
| Cursor | `~/.cursor/mcp.json` |
|
|
76
|
+
| Cline | `~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` (or the Linux equivalent) |
|
|
77
|
+
| Continue | `~/.continue/config.json` |
|
|
78
|
+
| Zed | `~/.config/zed/settings.json` |
|
|
79
|
+
|
|
80
|
+
Existing entries are merged, not overwritten. An existing `agentdrive` entry is replaced in place.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
Apache-2.0. See the repo's [LICENSING.md](https://github.com/Rakesh1002/agentdrive/blob/main/LICENSING.md) for the full package-by-package breakdown.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
3
|
+
import { DEFAULT_API_URL, readConfig, writeConfig } from '../lib/config.js';
|
|
4
|
+
import { pollAuth } from '../lib/poll-auth.js';
|
|
5
|
+
export async function cmdAuthLogin(opts = {}) {
|
|
6
|
+
const existing = await readConfig();
|
|
7
|
+
const apiUrl = opts.apiUrl ?? existing?.api_url ?? DEFAULT_API_URL;
|
|
8
|
+
const client = new CliApiClient({ baseUrl: apiUrl, agentPlatform: 'cli' });
|
|
9
|
+
const result = await pollAuth(client);
|
|
10
|
+
await writeConfig({
|
|
11
|
+
api_url: apiUrl,
|
|
12
|
+
api_key: result.api_key,
|
|
13
|
+
agent_id: result.agent_id,
|
|
14
|
+
org_id: result.org_id,
|
|
15
|
+
agent_platform: 'cli',
|
|
16
|
+
default_workspace: existing?.default_workspace,
|
|
17
|
+
});
|
|
18
|
+
process.stdout.write(`${kleur.green('[ok]')} API key saved.\n`);
|
|
19
|
+
if (result.agent_id)
|
|
20
|
+
process.stdout.write(` agent_id: ${result.agent_id}\n`);
|
|
21
|
+
if (result.org_id)
|
|
22
|
+
process.stdout.write(` org_id: ${result.org_id}\n`);
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import kleur from 'kleur';
|
|
3
|
+
import { configPath, deleteConfig } from '../lib/config.js';
|
|
4
|
+
export async function cmdAuthLogout(opts = {}) {
|
|
5
|
+
if (!opts.yes) {
|
|
6
|
+
const res = await prompts({
|
|
7
|
+
type: 'confirm',
|
|
8
|
+
name: 'ok',
|
|
9
|
+
message: 'Wipe local AgentDrive credentials?',
|
|
10
|
+
initial: false,
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
process.stdout.write('Cancelled.\n');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const removed = await deleteConfig();
|
|
18
|
+
if (removed) {
|
|
19
|
+
process.stdout.write(`${kleur.green('[ok]')} Logged out. Removed ${configPath()}.\n`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
process.stdout.write('Nothing to remove — already logged out.\n');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { readConfig } from '../lib/config.js';
|
|
3
|
+
export async function cmdAuthStatus() {
|
|
4
|
+
const c = await readConfig();
|
|
5
|
+
if (!c || !c.api_key) {
|
|
6
|
+
process.stdout.write(`${kleur.yellow('[not logged in]')} Run \`adrive auth login\` or \`adrive init\`.\n`);
|
|
7
|
+
process.exitCode = 1;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const masked = `${c.api_key.slice(0, 12)}${'.'.repeat(8)}`;
|
|
11
|
+
process.stdout.write(`${kleur.green('[ok]')} Logged in.\n`);
|
|
12
|
+
process.stdout.write(` api_url: ${c.api_url}\n`);
|
|
13
|
+
process.stdout.write(` api_key: ${masked}\n`);
|
|
14
|
+
if (c.org_id)
|
|
15
|
+
process.stdout.write(` org_id: ${c.org_id}\n`);
|
|
16
|
+
if (c.agent_id)
|
|
17
|
+
process.stdout.write(` agent_id: ${c.agent_id}\n`);
|
|
18
|
+
if (c.default_workspace)
|
|
19
|
+
process.stdout.write(` workspace: ${c.default_workspace}\n`);
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import kleur from 'kleur';
|
|
3
|
+
import { ApiError, CliApiClient } from '../lib/api-client.js';
|
|
4
|
+
import { requireLogin } from '../lib/config.js';
|
|
5
|
+
export async function cmdBilling() {
|
|
6
|
+
const cfg = await requireLogin();
|
|
7
|
+
const client = new CliApiClient({
|
|
8
|
+
baseUrl: cfg.api_url,
|
|
9
|
+
apiKey: cfg.api_key,
|
|
10
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
11
|
+
agentRole: cfg.agent_role,
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
const portal = await client.billingPortal();
|
|
15
|
+
try {
|
|
16
|
+
await open(portal.url);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Browser launch can fail in headless contexts; the URL is printed below.
|
|
20
|
+
}
|
|
21
|
+
process.stdout.write(`${kleur.green('[ok]')} Opened billing portal in browser.\n`);
|
|
22
|
+
process.stdout.write(` ${portal.url}\n`);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
26
|
+
process.stdout.write(`${kleur.yellow('[info]')} Billing portal not yet enabled — coming in v1.\n`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
3
|
+
import { requireLogin } from '../lib/config.js';
|
|
4
|
+
function truncate(s, n) {
|
|
5
|
+
if (!s)
|
|
6
|
+
return '';
|
|
7
|
+
return s.length <= n ? s : `${s.slice(0, n - 1)}…`;
|
|
8
|
+
}
|
|
9
|
+
export async function cmdContext(task, opts = {}) {
|
|
10
|
+
const cfg = await requireLogin();
|
|
11
|
+
const client = new CliApiClient({
|
|
12
|
+
baseUrl: cfg.api_url,
|
|
13
|
+
apiKey: cfg.api_key,
|
|
14
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
15
|
+
agentRole: cfg.agent_role,
|
|
16
|
+
});
|
|
17
|
+
const limit = opts.limit ? Number.parseInt(opts.limit, 10) : undefined;
|
|
18
|
+
const res = await client.context({
|
|
19
|
+
task,
|
|
20
|
+
workspace_id: opts.workspace ?? cfg.default_workspace,
|
|
21
|
+
limit,
|
|
22
|
+
});
|
|
23
|
+
if (!res.artifacts.length) {
|
|
24
|
+
process.stdout.write('No relevant artifacts.\n');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const a of res.artifacts) {
|
|
28
|
+
const score = a.score.toFixed(2);
|
|
29
|
+
process.stdout.write(`${kleur.cyan(a.path)} · score=${score} · by=${a.agent_id}@${a.agent_platform}\n`);
|
|
30
|
+
if (a.snippet)
|
|
31
|
+
process.stdout.write(` ${kleur.dim(truncate(a.snippet, 500))}\n`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import kleur from 'kleur';
|
|
3
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
4
|
+
import { DEFAULT_API_URL, readConfig, writeConfig } from '../lib/config.js';
|
|
5
|
+
import { pollAuth } from '../lib/poll-auth.js';
|
|
6
|
+
import { detectInstalledAgents, wireAgent } from '../lib/detect-agents.js';
|
|
7
|
+
export async function cmdInit(opts = {}) {
|
|
8
|
+
const existing = await readConfig();
|
|
9
|
+
const apiUrl = opts.apiUrl ?? existing?.api_url ?? DEFAULT_API_URL;
|
|
10
|
+
let apiKey = existing?.api_key;
|
|
11
|
+
let agentId = existing?.agent_id;
|
|
12
|
+
let orgId = existing?.org_id;
|
|
13
|
+
if (apiKey) {
|
|
14
|
+
process.stdout.write(`Already logged in (api key ${apiKey.slice(0, 12)}...).\n`);
|
|
15
|
+
if (!opts.yes) {
|
|
16
|
+
const res = await prompts({
|
|
17
|
+
type: 'confirm',
|
|
18
|
+
name: 'relogin',
|
|
19
|
+
message: 'Log in again?',
|
|
20
|
+
initial: false,
|
|
21
|
+
});
|
|
22
|
+
if (res.relogin) {
|
|
23
|
+
apiKey = undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!apiKey) {
|
|
28
|
+
process.stdout.write(`${kleur.bold('Step 1.')} Log in.\n`);
|
|
29
|
+
const client = new CliApiClient({ baseUrl: apiUrl, agentPlatform: 'cli' });
|
|
30
|
+
const auth = await pollAuth(client);
|
|
31
|
+
apiKey = auth.api_key;
|
|
32
|
+
agentId = auth.agent_id;
|
|
33
|
+
orgId = auth.org_id;
|
|
34
|
+
await writeConfig({
|
|
35
|
+
api_url: apiUrl,
|
|
36
|
+
api_key: apiKey,
|
|
37
|
+
agent_id: agentId,
|
|
38
|
+
org_id: orgId,
|
|
39
|
+
agent_platform: 'cli',
|
|
40
|
+
default_workspace: existing?.default_workspace,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
process.stdout.write(`\n${kleur.bold('Step 2.')} Detect installed agent tools.\n`);
|
|
44
|
+
const installed = await detectInstalledAgents();
|
|
45
|
+
if (installed.length === 0) {
|
|
46
|
+
process.stdout.write(' No agent configs found. Skipping MCP wiring.\n');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
process.stdout.write(` Found: ${installed.map((t) => t.name).join(', ')}\n`);
|
|
50
|
+
}
|
|
51
|
+
const wired = [];
|
|
52
|
+
const skipped = [];
|
|
53
|
+
for (const t of installed) {
|
|
54
|
+
let go = opts.yes ?? false;
|
|
55
|
+
if (!go) {
|
|
56
|
+
const res = await prompts({
|
|
57
|
+
type: 'confirm',
|
|
58
|
+
name: 'wire',
|
|
59
|
+
message: `Wire AgentDrive MCP into ${t.name} (${t.configPath})?`,
|
|
60
|
+
initial: true,
|
|
61
|
+
});
|
|
62
|
+
go = !!res.wire;
|
|
63
|
+
}
|
|
64
|
+
if (!go) {
|
|
65
|
+
skipped.push(t.name);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
await wireAgent(t, { apiKey: apiKey, apiUrl, agentPlatform: t.defaultPlatform });
|
|
70
|
+
wired.push(t.name);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
74
|
+
skipped.push(`${t.name} (${msg})`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
process.stdout.write(`\n${kleur.bold('Summary')}\n`);
|
|
78
|
+
process.stdout.write(` Wired: ${wired.length ? wired.join(', ') : '(none)'}\n`);
|
|
79
|
+
process.stdout.write(` Skipped: ${skipped.length ? skipped.join(', ') : '(none)'}\n`);
|
|
80
|
+
process.stdout.write('\nNext steps:\n');
|
|
81
|
+
process.stdout.write(' - Try: `adrive ls` to list workspaces\n');
|
|
82
|
+
process.stdout.write(' - Try: `adrive push README.md` to share a file\n');
|
|
83
|
+
process.stdout.write(' - Or ask Claude Code: "share this file via AgentDrive"\n');
|
|
84
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
2
|
+
import { requireLogin } from '../lib/config.js';
|
|
3
|
+
export async function cmdLs() {
|
|
4
|
+
const cfg = await requireLogin();
|
|
5
|
+
const client = new CliApiClient({
|
|
6
|
+
baseUrl: cfg.api_url,
|
|
7
|
+
apiKey: cfg.api_key,
|
|
8
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
9
|
+
agentRole: cfg.agent_role,
|
|
10
|
+
});
|
|
11
|
+
const workspaces = await client.listWorkspaces();
|
|
12
|
+
if (workspaces.length === 0) {
|
|
13
|
+
process.stdout.write('No workspaces. Create one via the dashboard or `POST /v1/workspaces`.\n');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const idWidth = Math.max(...workspaces.map((w) => w.id.length));
|
|
17
|
+
const nameWidth = Math.max(...workspaces.map((w) => w.name.length));
|
|
18
|
+
for (const w of workspaces) {
|
|
19
|
+
const id = w.id.padEnd(idWidth);
|
|
20
|
+
const name = w.name.padEnd(nameWidth);
|
|
21
|
+
process.stdout.write(`${id} ${name} ${w.created_at}\n`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
3
|
+
import { requireLogin } from '../lib/config.js';
|
|
4
|
+
function fmt(n) {
|
|
5
|
+
return Number.isFinite(n) ? n.toLocaleString() : '-';
|
|
6
|
+
}
|
|
7
|
+
export async function cmdPlan() {
|
|
8
|
+
const cfg = await requireLogin();
|
|
9
|
+
const client = new CliApiClient({
|
|
10
|
+
baseUrl: cfg.api_url,
|
|
11
|
+
apiKey: cfg.api_key,
|
|
12
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
13
|
+
agentRole: cfg.agent_role,
|
|
14
|
+
});
|
|
15
|
+
const plan = await client.billingPlan();
|
|
16
|
+
process.stdout.write(`${kleur.bold('Plan')}: ${plan.plan}\n`);
|
|
17
|
+
if (plan.trial_ends_at) {
|
|
18
|
+
process.stdout.write(`Trial ends: ${plan.trial_ends_at}\n`);
|
|
19
|
+
}
|
|
20
|
+
const keys = new Set([...Object.keys(plan.usage ?? {}), ...Object.keys(plan.quota ?? {})]);
|
|
21
|
+
if (keys.size === 0)
|
|
22
|
+
return;
|
|
23
|
+
const rows = [...keys].map((k) => ({
|
|
24
|
+
metric: k,
|
|
25
|
+
usage: fmt(plan.usage?.[k] ?? 0),
|
|
26
|
+
quota: fmt(plan.quota?.[k] ?? 0),
|
|
27
|
+
}));
|
|
28
|
+
const w1 = Math.max('metric'.length, ...rows.map((r) => r.metric.length));
|
|
29
|
+
const w2 = Math.max('usage'.length, ...rows.map((r) => r.usage.length));
|
|
30
|
+
const w3 = Math.max('quota'.length, ...rows.map((r) => r.quota.length));
|
|
31
|
+
process.stdout.write(`\n${'metric'.padEnd(w1)} ${'usage'.padEnd(w2)} ${'quota'.padEnd(w3)}\n`);
|
|
32
|
+
process.stdout.write(`${'-'.repeat(w1)} ${'-'.repeat(w2)} ${'-'.repeat(w3)}\n`);
|
|
33
|
+
for (const r of rows) {
|
|
34
|
+
process.stdout.write(`${r.metric.padEnd(w1)} ${r.usage.padEnd(w2)} ${r.quota.padEnd(w3)}\n`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import kleur from 'kleur';
|
|
3
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
4
|
+
import { requireLogin } from '../lib/config.js';
|
|
5
|
+
export async function cmdPull(spec, opts = {}) {
|
|
6
|
+
const cfg = await requireLogin();
|
|
7
|
+
const client = new CliApiClient({
|
|
8
|
+
baseUrl: cfg.api_url,
|
|
9
|
+
apiKey: cfg.api_key,
|
|
10
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
11
|
+
agentRole: cfg.agent_role,
|
|
12
|
+
});
|
|
13
|
+
const slash = spec.indexOf('/');
|
|
14
|
+
if (slash <= 0) {
|
|
15
|
+
throw new Error('Expected <workspace-id>/<path>');
|
|
16
|
+
}
|
|
17
|
+
const workspaceId = spec.slice(0, slash);
|
|
18
|
+
const remotePath = spec.slice(slash + 1);
|
|
19
|
+
const file = await client.readFileByPath(workspaceId, remotePath);
|
|
20
|
+
if (opts.out) {
|
|
21
|
+
await fs.writeFile(opts.out, file.content, 'utf8');
|
|
22
|
+
process.stdout.write(`${kleur.green('[ok]')} wrote ${opts.out} (v${file.version})\n`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
process.stdout.write(file.content);
|
|
26
|
+
if (!file.content.endsWith('\n'))
|
|
27
|
+
process.stdout.write('\n');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import kleur from 'kleur';
|
|
4
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
5
|
+
import { requireLogin } from '../lib/config.js';
|
|
6
|
+
export async function cmdPush(localPath, opts = {}) {
|
|
7
|
+
const cfg = await requireLogin();
|
|
8
|
+
const client = new CliApiClient({
|
|
9
|
+
baseUrl: cfg.api_url,
|
|
10
|
+
apiKey: cfg.api_key,
|
|
11
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
12
|
+
agentRole: cfg.agent_role,
|
|
13
|
+
});
|
|
14
|
+
const content = await fs.readFile(localPath, 'utf8');
|
|
15
|
+
const remotePath = opts.remotePath ?? basename(localPath);
|
|
16
|
+
let workspaceId = opts.workspace ?? cfg.default_workspace;
|
|
17
|
+
if (!workspaceId) {
|
|
18
|
+
const list = await client.listWorkspaces();
|
|
19
|
+
if (list.length === 1) {
|
|
20
|
+
workspaceId = list[0].id;
|
|
21
|
+
}
|
|
22
|
+
else if (list.length === 0) {
|
|
23
|
+
throw new Error('No workspaces. Create one first.');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`Multiple workspaces — specify --workspace <id>. Available: ${list.map((w) => w.id).join(', ')}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const result = await client.writeFile(workspaceId, remotePath, content, opts.message);
|
|
30
|
+
process.stdout.write(`${kleur.green('[ok]')} pushed ${localPath} -> ${workspaceId}:${result.path} (v${result.version})\n`);
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { CliApiClient } from '../lib/api-client.js';
|
|
3
|
+
import { requireLogin } from '../lib/config.js';
|
|
4
|
+
export async function cmdRunLog(task, opts = {}) {
|
|
5
|
+
const cfg = await requireLogin();
|
|
6
|
+
const client = new CliApiClient({
|
|
7
|
+
baseUrl: cfg.api_url,
|
|
8
|
+
apiKey: cfg.api_key,
|
|
9
|
+
agentPlatform: cfg.agent_platform ?? 'cli',
|
|
10
|
+
agentRole: cfg.agent_role,
|
|
11
|
+
});
|
|
12
|
+
const duration = opts.duration ? Number.parseInt(opts.duration, 10) : undefined;
|
|
13
|
+
const res = await client.logRun({
|
|
14
|
+
task,
|
|
15
|
+
status: opts.status ?? 'success',
|
|
16
|
+
artifacts_referenced: opts.ref,
|
|
17
|
+
artifacts_produced: opts.produced,
|
|
18
|
+
duration_ms: duration,
|
|
19
|
+
});
|
|
20
|
+
process.stdout.write(`${kleur.green('[ok]')} run logged: ${res.run_id}\n`);
|
|
21
|
+
}
|