@protoboardai/cli 0.0.0-stage → 0.2.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/NOTICE +13 -0
- package/bin/protoboard.mjs +5 -0
- package/build-info.json +8 -0
- package/package.json +40 -4
- package/src/agents.ts +235 -0
- package/src/bom.ts +145 -0
- package/src/dev/build-worker.ts +63 -0
- package/src/dev/layout.ts +199 -0
- package/src/dev/page.ts +284 -0
- package/src/dev/parts.ts +356 -0
- package/src/dev/relay.d.ts +60 -0
- package/src/dev/relay.js +147 -0
- package/src/dev/server.ts +727 -0
- package/src/dev/sources.ts +120 -0
- package/src/gate.ts +102 -0
- package/src/index.ts +2024 -0
- package/src/layout.ts +166 -0
- package/src/mcp/instructions.ts +60 -0
- package/src/mcp/server.ts +215 -0
- package/src/mcp/tools.ts +392 -0
- package/src/openUrl.ts +71 -0
- package/src/setup.ts +298 -0
- package/src/stack-messages.ts +53 -0
- package/src/views-check.ts +267 -0
- package/README.md +0 -3
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/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Protoboard Stack: @protoboardai/cli
|
|
2
|
+
Copyright 2026 Delta Robotics, Inc.
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Delta Robotics, Inc.
|
|
5
|
+
(https://deltaroboticsinc.com).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
8
|
+
See the LICENSE file in this package for full terms.
|
|
9
|
+
|
|
10
|
+
"Protoboard", the Protoboard logo and the "0" mark are trademarks of
|
|
11
|
+
Delta Robotics, Inc. The License grants no rights to them (section 6);
|
|
12
|
+
see TRADEMARKS.md in the Protoboard Stack repository
|
|
13
|
+
(https://github.com/Delta-Robotics-Inc/protoboard-stack).
|
package/build-info.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protoboardai/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "protoboard command-line interface",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Delta Robotics, Inc.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Delta-Robotics-Inc/protoboard-stack.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"bin": {
|
|
14
|
+
"protoboard": "bin/protoboard.mjs",
|
|
15
|
+
"pb": "bin/protoboard.mjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"src",
|
|
20
|
+
"build-info.json",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"NOTICE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@deltarobotics/uhd-viewer": "^0.2.0",
|
|
33
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
34
|
+
"@protoboardai/core": "^0.2.0",
|
|
35
|
+
"@protoboardai/ext-sourcing": "^0.2.0",
|
|
36
|
+
"@protoboardai/views": "^0.2.0",
|
|
37
|
+
"@protoboardai/web-viewer": "^0.2.0",
|
|
38
|
+
"meow": "^14.1.0",
|
|
39
|
+
"tsx": "^4.23.8",
|
|
40
|
+
"zod": "3.25.76"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/agents.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `protoboard agents`: the agents on this machine and Protoboard's MCP
|
|
3
|
+
* server in their configuration (PB-930, docs/specs/agents-and-mcp.md §4-5).
|
|
4
|
+
* Listing reads only. `setup` and `remove` change an agent's configuration
|
|
5
|
+
* only with the user's yes for that agent: asked at a terminal, or given as
|
|
6
|
+
* `--agent <id> --yes` (or `--all --yes`) where there is none.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { createInterface } from "node:readline/promises";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import {
|
|
14
|
+
KNOWN_AGENTS,
|
|
15
|
+
MCP_SERVER_NAME,
|
|
16
|
+
PORTABLE_COMMAND,
|
|
17
|
+
cliOriginOf,
|
|
18
|
+
findProjectRoot,
|
|
19
|
+
installLauncher,
|
|
20
|
+
launcherCommand,
|
|
21
|
+
launcherDir,
|
|
22
|
+
listAgents,
|
|
23
|
+
otherClientConfig,
|
|
24
|
+
otherClientName,
|
|
25
|
+
removeAgent,
|
|
26
|
+
setupAgent,
|
|
27
|
+
type AgentChange,
|
|
28
|
+
type AgentScope,
|
|
29
|
+
type AgentState,
|
|
30
|
+
type CliOrigin,
|
|
31
|
+
type ServerCommand,
|
|
32
|
+
} from "@protoboardai/core";
|
|
33
|
+
|
|
34
|
+
export interface AgentsFlags {
|
|
35
|
+
agent?: string[];
|
|
36
|
+
all?: boolean;
|
|
37
|
+
yes?: boolean;
|
|
38
|
+
scope?: string;
|
|
39
|
+
/** Project scope: `npx --no-install protoboard mcp` (true), the machine's launcher (false), or decided from the project (undefined). */
|
|
40
|
+
portable?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AgentsIo {
|
|
44
|
+
json: boolean;
|
|
45
|
+
cwd: string;
|
|
46
|
+
version: string;
|
|
47
|
+
out(data: unknown, text: () => string): void;
|
|
48
|
+
/** Ask a yes/no question at the terminal; undefined when there is no terminal to ask at. */
|
|
49
|
+
confirm?: (question: string) => Promise<boolean>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const SELF = fileURLToPath(new URL("../bin/protoboard.mjs", import.meta.url));
|
|
53
|
+
|
|
54
|
+
/** The home folder written as `~`, for messages. */
|
|
55
|
+
const tilde = (p: string) => {
|
|
56
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? homedir();
|
|
57
|
+
return home && p.startsWith(home) ? `~${p.slice(home.length)}` : p;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Write the launcher and record this CLI as one the machine has. */
|
|
61
|
+
function launcher(io: AgentsIo) {
|
|
62
|
+
const from: CliOrigin = process.env.PROTOBOARD_CLI_FROM === "extension" ? "extension" : cliOriginOf(SELF);
|
|
63
|
+
return installLauncher({ cli: { entry: SELF, version: io.version, from } });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The scope, the project folder it needs, and the command an entry at that scope runs. */
|
|
67
|
+
function where(flags: AgentsFlags, io: AgentsIo): { scope: AgentScope; projectDir?: string; command: ServerCommand; portable: boolean } {
|
|
68
|
+
const scope = flags.scope ?? "user";
|
|
69
|
+
if (scope !== "user" && scope !== "project") throw new Error(`--scope takes user or project, not "${scope}"`);
|
|
70
|
+
if (scope === "user") return { scope, command: launcherCommand(), portable: false };
|
|
71
|
+
// a project's file is shared: the folder is the Protoboard project's root, or the folder given when it is not one yet
|
|
72
|
+
const projectDir = findProjectRoot(io.cwd) ?? io.cwd;
|
|
73
|
+
let depends = false;
|
|
74
|
+
try {
|
|
75
|
+
const pkg = JSON.parse(readFileSync(join(projectDir, "package.json"), "utf8")) as { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
76
|
+
depends = !!(pkg.dependencies?.["@protoboardai/cli"] ?? pkg.devDependencies?.["@protoboardai/cli"]);
|
|
77
|
+
} catch {
|
|
78
|
+
depends = false;
|
|
79
|
+
}
|
|
80
|
+
const portable = flags.portable ?? depends;
|
|
81
|
+
return { scope, projectDir, command: portable ? PORTABLE_COMMAND : launcherCommand(), portable };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const STATUS_TEXT: Record<AgentState["status"], string> = { connected: "connected", outdated: "update needed", "not-connected": "not connected", "not-detected": "not found", unreadable: "cannot read its configuration" };
|
|
85
|
+
const MARK: Record<AgentState["status"], string> = { connected: "✓", outdated: "!", "not-connected": "·", "not-detected": " ", unreadable: "✗" };
|
|
86
|
+
|
|
87
|
+
function validIds(ids: string[], scope: AgentScope): string[] {
|
|
88
|
+
for (const id of ids) {
|
|
89
|
+
const known = KNOWN_AGENTS.find((a) => a.id === id);
|
|
90
|
+
if (!known) throw new Error(`no agent "${id}"; known: ${KNOWN_AGENTS.map((a) => a.id).join(", ")}`);
|
|
91
|
+
if (!known.scopes.includes(scope)) throw new Error(`${known.name} has no project configuration for MCP servers; use --scope user`);
|
|
92
|
+
}
|
|
93
|
+
return [...new Set(ids)];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function agentsCommand(sub: string | undefined, rest: string[], flags: AgentsFlags, io: AgentsIo): Promise<void> {
|
|
97
|
+
const usage = "usage: protoboard agents [list] | setup [--agent <id>]… [--all] [--yes] [--scope user|project] | remove [--agent <id>]… [--all] [--yes] [--scope user|project] | config | refresh";
|
|
98
|
+
if (rest.length) throw new Error(usage);
|
|
99
|
+
switch (sub ?? "list") {
|
|
100
|
+
case "list": {
|
|
101
|
+
const w = where(flags, io);
|
|
102
|
+
const agents = listAgents(w);
|
|
103
|
+
io.out({ server: { name: MCP_SERVER_NAME, ...w.command }, scope: w.scope, ...(w.projectDir ? { project: w.projectDir } : {}), agents }, () => {
|
|
104
|
+
const shown = agents.filter((a) => a.status !== "not-detected");
|
|
105
|
+
const width = Math.max(...shown.map((a) => a.name.length), 0);
|
|
106
|
+
return [
|
|
107
|
+
w.scope === "project" ? `Agents and this project's MCP configuration (${w.projectDir})` : "Agents on this machine",
|
|
108
|
+
...shown.map((a) => ` ${MARK[a.status]} ${a.name.padEnd(width)} ${STATUS_TEXT[a.status].padEnd(14)} ${tilde(a.file)}${a.status === "outdated" ? `\n its entry runs ${[a.entry!.command, ...a.entry!.args].join(" ")}` : ""}${a.legacyName ? `\n its entry is named ${a.legacyName}, as before 0.1.7: setup renames it ${a.serverName}` : ""}${a.alphaServer ? `\n the server named protoboard here is another one (${a.alphaServer}, the alpha web app's); it is left as it is` : ""}${a.problem ? `\n ${a.problem}` : ""}${a.manual ? `\n the \`claude\` command was not found from here; connect it yourself with: ${a.manual}` : ""}`),
|
|
109
|
+
...(shown.length ? [] : [" none found"]),
|
|
110
|
+
...(agents.some((a) => a.status === "not-detected") ? [` Not found here: ${agents.filter((a) => a.status === "not-detected").map((a) => a.name).join(", ")}`] : []),
|
|
111
|
+
"",
|
|
112
|
+
"Connect them: `protoboard agents setup` (asks about each). Any other MCP client: `protoboard agents config`.",
|
|
113
|
+
].join("\n");
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
case "setup":
|
|
118
|
+
case "remove": {
|
|
119
|
+
const adding = sub === "setup";
|
|
120
|
+
const w = where(flags, io);
|
|
121
|
+
const named = validIds(flags.agent ?? [], w.scope);
|
|
122
|
+
if (flags.yes && !named.length && !flags.all) throw new Error(`--yes needs to know which agents: --agent <id> (repeatable) or --all. An agent's configuration is not changed without a yes for that agent. See \`protoboard agents\`.`);
|
|
123
|
+
const states = listAgents(w);
|
|
124
|
+
// which to act on: the ones named; else the detected ones that need it
|
|
125
|
+
const needs = (a: AgentState) => (adding ? a.detected && a.status !== "connected" : a.status === "connected" || a.status === "outdated");
|
|
126
|
+
const targets = named.length ? states.filter((a) => named.includes(a.id)) : states.filter(needs);
|
|
127
|
+
if (!flags.yes && !io.confirm) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`there is no terminal to ask at, and an agent's configuration is not changed without a yes for that agent. ${targets.length ? `Name them: ${targets.map((a) => `--agent ${a.id}`).join(" ")} --yes (or --all --yes).` : adding ? "No detected agent needs connecting." : "No agent has Protoboard configured."}`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
// the launcher is Protoboard's own file, but it too is written only once an agent has a yes
|
|
133
|
+
let launcherWritten = !adding || w.portable;
|
|
134
|
+
const results: (AgentChange | { id: string; name: string; scope: AgentScope; file: string; action: "declined" | "failed" | "manual"; message?: string })[] = [];
|
|
135
|
+
for (const a of targets) {
|
|
136
|
+
// nothing to ask: Protoboard will not make this change itself, and says what the user runs
|
|
137
|
+
if (adding && a.manual) {
|
|
138
|
+
results.push({ id: a.id, name: a.name, scope: a.scope, file: a.file, action: "manual", message: `The \`claude\` command was not found from here, and Claude Code's configuration is not edited directly (it rewrites that file while it runs). Run: ${a.manual}${existsSync(join(launcherDir(), "protoboard-mcp.mjs")) ? "" : " (and `protoboard agents refresh` once: it writes the launcher that entry starts)"}` });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (!flags.yes) {
|
|
142
|
+
const q = adding
|
|
143
|
+
? `${a.status === "outdated" ? "Update" : "Connect"} ${a.name}? This ${a.method === "command" ? `runs \`claude mcp add\`, which writes` : "adds"} the "${a.serverName}" MCP server ${a.method === "command" ? "to" : "in"} ${tilde(a.file)}`
|
|
144
|
+
: `Disconnect ${a.name}? This removes the "${a.serverName}" MCP server from ${tilde(a.file)}`;
|
|
145
|
+
if (!(await io.confirm!(q))) {
|
|
146
|
+
results.push({ id: a.id, name: a.name, scope: a.scope, file: a.file, action: "declined" });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
if (!launcherWritten) {
|
|
152
|
+
launcher(io);
|
|
153
|
+
launcherWritten = true;
|
|
154
|
+
}
|
|
155
|
+
results.push(adding ? setupAgent(a.id, w) : removeAgent(a.id, w));
|
|
156
|
+
} catch (e) {
|
|
157
|
+
results.push({ id: a.id, name: a.name, scope: a.scope, file: a.file, action: "failed", message: (e as Error).message });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const done: Record<string, string> = { added: "connected: added to", updated: "updated in", unchanged: "already connected in", removed: "disconnected: removed from", absent: "was not configured in", declined: "left alone:", failed: "failed:", manual: "to connect yourself:" };
|
|
161
|
+
io.out({ server: { name: MCP_SERVER_NAME, ...w.command }, scope: w.scope, results }, () =>
|
|
162
|
+
[
|
|
163
|
+
...results.map((r) =>
|
|
164
|
+
[
|
|
165
|
+
`${r.action === "failed" ? "✗" : r.action === "declined" || r.action === "manual" ? "·" : "✓"} ${r.name}: ${done[r.action]} ${tilde(r.file)}${"method" in r && r.method === "command" && (r.action === "added" || r.action === "updated" || r.action === "removed") ? " (by `claude mcp`)" : ""}`,
|
|
166
|
+
...("movedFrom" in r && r.movedFrom ? [` renamed from "${r.movedFrom}" (its name before 0.1.7) to "${r.serverName}"`] : []),
|
|
167
|
+
...("backup" in r && r.backup ? [` the file as it was is kept as ${tilde(r.backup)}`] : []),
|
|
168
|
+
...("warnings" in r && r.warnings ? r.warnings.map((x) => ` ! ${x}`) : []),
|
|
169
|
+
...("message" in r && r.message ? [` ${r.message}`] : []),
|
|
170
|
+
...("restart" in r && (r.action === "added" || r.action === "updated") ? [` ${r.restart}`] : []),
|
|
171
|
+
].join("\n"),
|
|
172
|
+
),
|
|
173
|
+
...(results.length ? [] : [adding ? "No detected agent needs connecting (`protoboard agents` lists them; `--agent <id>` names one that was not found)." : "No agent has Protoboard configured."]),
|
|
174
|
+
...(adding && results.some((r) => r.action === "added" || r.action === "updated") ? ["", `The entry runs: ${[w.command.command, ...w.command.args].join(" ")}`] : []),
|
|
175
|
+
].join("\n"),
|
|
176
|
+
);
|
|
177
|
+
process.exitCode = results.some((r) => r.action === "failed") ? 1 : 0;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
case "config": {
|
|
181
|
+
// prints only: the launcher the entry names is written by `setup`, or by `refresh` for a client set up by hand
|
|
182
|
+
const w = where(flags, io);
|
|
183
|
+
// always protoboard-stack: the alpha web app's server is named protoboard on many machines
|
|
184
|
+
const c = otherClientConfig(w.command, otherClientName());
|
|
185
|
+
const installed = w.portable || existsSync(join(launcherDir(), "protoboard-mcp.mjs"));
|
|
186
|
+
io.out({ server: c.name, ...c, ...(w.portable ? {} : { launcher: launcherDir(), launcherInstalled: installed }) }, () =>
|
|
187
|
+
[
|
|
188
|
+
"Protoboard's MCP server, for any MCP client",
|
|
189
|
+
"",
|
|
190
|
+
...c.steps.map((s, i) => `${i + 1}. ${s}`),
|
|
191
|
+
"",
|
|
192
|
+
"Command:",
|
|
193
|
+
` ${c.commandLine}`,
|
|
194
|
+
"",
|
|
195
|
+
"JSON (clients that read mcpServers: Claude Desktop, Cursor, Windsurf, Gemini CLI, Cline, …):",
|
|
196
|
+
c.json,
|
|
197
|
+
"",
|
|
198
|
+
"JSON (VS Code's mcp.json):",
|
|
199
|
+
c.vscodeJson,
|
|
200
|
+
"",
|
|
201
|
+
"TOML (Codex):",
|
|
202
|
+
c.toml,
|
|
203
|
+
"",
|
|
204
|
+
"Claude Code:",
|
|
205
|
+
` ${c.claudeLine}`,
|
|
206
|
+
...(w.portable ? [] : ["", `The command is a launcher in ${tilde(launcherDir())}: it finds Node.js and the Protoboard CLI each time, so the entry keeps working when Protoboard updates.`]),
|
|
207
|
+
...(installed ? [] : ["", "The launcher is not on this machine yet, and this command writes nothing. Write it before the client starts the server: `protoboard agents refresh`."]),
|
|
208
|
+
].join("\n"),
|
|
209
|
+
);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
case "refresh": {
|
|
213
|
+
// writes Protoboard's own folder only, never an agent's file: the launcher's files, and this CLI recorded.
|
|
214
|
+
// For a client set up by hand from `agents config`, and what the extension runs when it starts
|
|
215
|
+
const state = launcher(io);
|
|
216
|
+
io.out(state, () => (state.written.length ? `wrote ${state.written.join(", ")} in ${tilde(state.dir)}` : `the launcher in ${tilde(state.dir)} is up to date`));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
throw new Error(usage);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** A yes/no question at the terminal, when there is one. */
|
|
225
|
+
export function terminalConfirm(): AgentsIo["confirm"] {
|
|
226
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY) return undefined;
|
|
227
|
+
return async (question) => {
|
|
228
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
229
|
+
try {
|
|
230
|
+
return /^y(es)?$/i.test((await rl.question(`${question} [y/N] `)).trim());
|
|
231
|
+
} finally {
|
|
232
|
+
rl.close();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|