bikeshed-now 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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Bikeshed contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,68 @@
1
+ Bikeshed
2
+ Copyright 2026 Bikeshed contributors
3
+
4
+ This product includes software developed by the Bikeshed contributors.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7
+ this file except in compliance with the License. You may obtain a copy of the
8
+ License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software distributed
13
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
15
+ specific language governing permissions and limitations under the License.
16
+
17
+
18
+ -------------------------------------------------------------------------------
19
+ THIRD-PARTY MATERIAL INCLUDED IN THIS DISTRIBUTION
20
+ -------------------------------------------------------------------------------
21
+
22
+ Runtime and build dependencies are not vendored; they are fetched by npm and
23
+ their licenses are listed in THIRD_PARTY_LICENSES.md. The items below are files
24
+ that ship inside this repository and are not covered by the Apache License above.
25
+
26
+
27
+ 1. docs/acf/** and .claude/scripts/
28
+ -------------------------------------------------------------------------
29
+ Agentic Coding Framework (ACF) documentation and helper scripts.
30
+ Copyright (c) 2025 Fibonacci Seven, LLC. All rights reserved.
31
+
32
+ KNOWN LICENSE CONFLICT — READ BEFORE REDISTRIBUTING.
33
+
34
+ These files originate from a work published under a PROPRIETARY LICENSE whose
35
+ terms state, in relevant part, that you may NOT "copy, modify, merge,
36
+ publish, distribute, sublicense, or sell copies of the Software" and may NOT
37
+ "redistribute the Software in any form, modified or unmodified."
38
+
39
+ They are present here at the express direction of this repository's author,
40
+ who is also the author of the substantial majority of the upstream work, and
41
+ who accepted this risk knowingly after it was raised. Their presence is
42
+ recorded here rather than left silent.
43
+
44
+ Consequences a downstream recipient must understand:
45
+
46
+ - These paths are NOT licensed to you under Apache-2.0. Nothing in the
47
+ LICENSE file grants any right in them.
48
+ - At least one upstream commit is authored by a third party, so the
49
+ author's own rights may not cover the whole of the material.
50
+ - Before publishing, forking, mirroring or redistributing this repository,
51
+ obtain written permission from Fibonacci Seven, LLC (acf@fib7.ai), or
52
+ remove these paths.
53
+
54
+ Removing them is safe and affects no product behaviour: they are
55
+ agent-workflow documentation and a shell status line. Nothing in app/,
56
+ functions/, scripts/, cli/ or content/ reads them at build time or at
57
+ runtime.
58
+
59
+
60
+ 2. app/public/fonts/*.woff2 — "Bikeshed Sans"
61
+ -------------------------------------------------------------------------
62
+ A subset of an upstream typeface released under the SIL Open Font License,
63
+ Version 1.1. Subsetting is a modification, so under the OFL's Reserved Font
64
+ Name clause the modified file is distributed under a different name.
65
+
66
+ The upstream face, its author, and the full OFL text are recorded in
67
+ app/public/fonts/OFL.txt and in THIRD_PARTY_LICENSES.md. The OFL applies to
68
+ the font files only and does not extend to any other part of this work.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # bikeshed
2
+
3
+ Publish a document to a [Bikeshed](https://bikeshed.now) deployment, then read
4
+ the comments people left on it — each one with the exact sentence it is about.
5
+
6
+ Bikeshed is self-hosted. This client talks to whichever deployment you point it
7
+ at, over HTTPS, with a personal access token that carries exactly your own
8
+ permissions.
9
+
10
+ ```bash
11
+ npm i -g bikeshed-now
12
+ bikeshed login # asks for the deployment and a token
13
+ ```
14
+
15
+ Create a token in the deployment's interface, under **Account → Access tokens**.
16
+ It is shown once. `BIKESHED_ORIGIN` and `BIKESHED_TOKEN` work instead of
17
+ `login` where an interactive command cannot run — a CI job, or an agent.
18
+
19
+ ## The loop
20
+
21
+ ```bash
22
+ bikeshed publish proposal.md --title "Storage migration"
23
+ # published storage-migration v1 — https://<deployment>/d/storage-migration
24
+
25
+ # Somebody highlights a sentence and says what is wrong with it.
26
+ bikeshed comments storage-migration
27
+
28
+ # Fix that sentence, publish the revision, and say what you changed.
29
+ bikeshed update storage-migration proposal.md
30
+ bikeshed reply storage-migration <thread> "Rewritten to describe the dual-write period."
31
+ ```
32
+
33
+ Publishing identical bytes is a no-op: the bundle is hashed, and a matching hash
34
+ mints no new version. So `update` is safe in a loop, in CI, or after a change you
35
+ are not sure you made.
36
+
37
+ `bikeshed --help` lists the rest — listing documents, folders, and installing the
38
+ agent skills a deployment serves.
39
+
40
+ ## Sharing is not automated
41
+
42
+ There is no command that shares a document, changes who can read it, or sets an
43
+ expiry. Those are decisions a person makes in the interface, deliberately.
44
+
45
+ ## For agents
46
+
47
+ A deployment serves its own instructions at `https://<deployment>/llms.txt`, and
48
+ the skills behind them at `/skills/index.json`. `bikeshed skills install <dir>`
49
+ writes them where your harness reads skills from.
50
+
51
+ Everything done with a token is stamped with the channel it came through, so a
52
+ reviewer can always tell which feedback came from a person.
53
+
54
+ ## Licence
55
+
56
+ Apache-2.0. The deployment it talks to is the same repository:
57
+ [DeputyHumans/bikeshed-now](https://github.com/DeputyHumans/bikeshed-now).
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "bikeshed-now",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "description": "Publish and revise documents on a Bikeshed deployment from the terminal.",
7
+ "keywords": [
8
+ "bikeshed",
9
+ "documents",
10
+ "publishing",
11
+ "review",
12
+ "comments",
13
+ "mcp",
14
+ "agents"
15
+ ],
16
+ "homepage": "https://bikeshed.now",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/DeputyHumans/bikeshed-now.git",
20
+ "directory": "cli"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/DeputyHumans/bikeshed-now/issues"
24
+ },
25
+ "bin": {
26
+ "bikeshed": "./src/index.mjs"
27
+ },
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "files": [
32
+ "src",
33
+ "README.md",
34
+ "LICENSE",
35
+ "NOTICE"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "test": "node --test test/*.test.mjs",
42
+ "prepack": "cp ../LICENSE ../NOTICE .",
43
+ "postpack": "rm -f LICENSE NOTICE"
44
+ }
45
+ }
package/src/client.mjs ADDED
@@ -0,0 +1,142 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The HTTP and MCP client the CLI is built on (SPEC §19).
3
+
4
+ import { readFileSync } from "node:fs";
5
+ import { basename } from "node:path";
6
+
7
+ export const CLIENT_NAME = "bikeshed-cli/0.1.0";
8
+
9
+ /**
10
+ * Two surfaces, and the split is deliberate rather than untidy.
11
+ *
12
+ * POST /publish takes RAW BYTES, so it is the only way to send a .zip
13
+ * bundle without base64-inflating it through JSON. It is
14
+ * also the exact endpoint the browser uploader calls.
15
+ * POST /mcp is the API for everything else — list, read, update,
16
+ * comments, reply — because those tools already exist and
17
+ * adding a parallel REST surface would mean two
18
+ * implementations of the same six operations.
19
+ *
20
+ * Both carry the same Bearer token, and both stamp provenance server-side. The
21
+ * `X-Bikeshed-Client` and `X-Bikeshed-Agent` headers are self-reported and are
22
+ * recorded as such: they are for a human reading an activity feed, not for
23
+ * anything that makes a decision.
24
+ */
25
+
26
+ function headers(token, extra = {}) {
27
+ return {
28
+ Authorization: `Bearer ${token}`,
29
+ "X-Bikeshed-Client": CLIENT_NAME,
30
+ ...(process.env.BIKESHED_AGENT ? { "X-Bikeshed-Agent": process.env.BIKESHED_AGENT } : {}),
31
+ ...extra,
32
+ };
33
+ }
34
+
35
+ export class CliError extends Error {}
36
+
37
+ async function readError(res, fallback) {
38
+ try {
39
+ const body = await res.json();
40
+ if (body?.error) return body.error;
41
+ } catch {
42
+ /* keep the fallback */
43
+ }
44
+ return fallback;
45
+ }
46
+
47
+ /** Call one MCP tool and return its structured result. */
48
+ export async function callTool(origin, token, name, args = {}) {
49
+ const res = await fetch(`${origin}/mcp`, {
50
+ method: "POST",
51
+ headers: headers(token, { "Content-Type": "application/json" }),
52
+ body: JSON.stringify({
53
+ jsonrpc: "2.0",
54
+ id: 1,
55
+ method: "tools/call",
56
+ params: { name, arguments: args },
57
+ }),
58
+ });
59
+
60
+ if (res.status === 401) {
61
+ throw new CliError(
62
+ "That token was not accepted. Run `bikeshed login` again, or check BIKESHED_ORIGIN.",
63
+ );
64
+ }
65
+ if (!res.ok) {
66
+ throw new CliError(await readError(res, `The server returned ${res.status}.`));
67
+ }
68
+
69
+ const body = await res.json();
70
+ if (body.error) throw new CliError(body.error.message);
71
+
72
+ const result = body.result;
73
+ if (result?.isError) {
74
+ // A tool failure arrives INSIDE the result rather than as a transport
75
+ // error, because the protocol reserves transport errors for transport
76
+ // problems — and the message is the part worth showing.
77
+ throw new CliError(result.content?.[0]?.text ?? "That did not work.");
78
+ }
79
+ return result?.structuredContent ?? result;
80
+ }
81
+
82
+ /** Upload a file as a NEW document, exactly as the browser uploader does. */
83
+ export async function uploadFile(origin, token, path, { title, folder } = {}) {
84
+ const bytes = readFileSync(path);
85
+ const params = new URLSearchParams({ filename: basename(path) });
86
+ if (title) params.set("title", title);
87
+ if (folder) params.set("folderId", folder);
88
+
89
+ const res = await fetch(`${origin}/publish?${params}`, {
90
+ method: "POST",
91
+ headers: headers(token, { "Content-Type": "application/octet-stream" }),
92
+ body: bytes,
93
+ });
94
+
95
+ if (res.status === 401) {
96
+ throw new CliError("That token was not accepted. Run `bikeshed login` again.");
97
+ }
98
+ if (!res.ok) {
99
+ throw new CliError(await readError(res, `Upload failed (${res.status}).`));
100
+ }
101
+ return res.json();
102
+ }
103
+
104
+ /**
105
+ * The skills a deployment publishes, and their text.
106
+ *
107
+ * Unauthenticated on purpose: these are static files beside `/llms.txt`,
108
+ * describing what the deployment can do, not anything belonging to an account.
109
+ * Asking for a token to read public instructions would mean an agent has to be
110
+ * credentialed before it can learn how to ask for credentials.
111
+ */
112
+ export async function listSkills(origin) {
113
+ const res = await fetch(`${origin}/skills/index.json`);
114
+ if (!res.ok) {
115
+ throw new CliError(
116
+ `${origin} publishes no skills (${res.status}). It may be an older deployment.`,
117
+ );
118
+ }
119
+ const body = await res.json().catch(() => null);
120
+ if (!Array.isArray(body?.skills)) {
121
+ // A Hosting catch-all rewrite answers a missing file with the SPA's
122
+ // index.html and a 200, so "it parsed as JSON" is the real test of whether
123
+ // the endpoint exists — not the status code.
124
+ throw new CliError(`${origin} returned something that is not a skill index.`);
125
+ }
126
+ return body;
127
+ }
128
+
129
+ /** Fetch one skill's Markdown, by the path its index gave. */
130
+ export async function fetchSkill(origin, skill) {
131
+ const res = await fetch(`${origin}/${skill.path}`);
132
+ if (!res.ok) throw new CliError(`could not read ${skill.name} (${res.status})`);
133
+ return res.text();
134
+ }
135
+
136
+ /** Check that a token works, and say who it belongs to. */
137
+ export async function whoami(origin, token) {
138
+ // list_documents is the cheapest authenticated call, and a token that can
139
+ // list is a token that works.
140
+ await callTool(origin, token, "list_documents", { limit: 1 });
141
+ return true;
142
+ }
package/src/config.mjs ADDED
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Where the CLI keeps its credential, and how it finds the deployment (SPEC §19).
3
+
4
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+
8
+ /**
9
+ * The token file.
10
+ *
11
+ * Under XDG_CONFIG_HOME when set, so it lands where the rest of a person's
12
+ * tooling lives, and mode 0600 because it holds a credential that can do
13
+ * everything its owner can do. Never in the project directory: a token in a
14
+ * repository is a token in somebody's next commit.
15
+ */
16
+ function configDir() {
17
+ const xdg = process.env.XDG_CONFIG_HOME;
18
+ return xdg ? join(xdg, "bikeshed") : join(homedir(), ".config", "bikeshed");
19
+ }
20
+
21
+ export const CONFIG_PATH = join(configDir(), "config.json");
22
+
23
+ export function readConfig() {
24
+ if (!existsSync(CONFIG_PATH)) return {};
25
+ try {
26
+ return JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
27
+ } catch {
28
+ return {};
29
+ }
30
+ }
31
+
32
+ export function writeConfig(config) {
33
+ mkdirSync(dirname(CONFIG_PATH), { recursive: true });
34
+ writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
35
+ try {
36
+ chmodSync(CONFIG_PATH, 0o600);
37
+ } catch {
38
+ // Best effort: some filesystems (and Windows) do not support it. The token
39
+ // is still no more exposed than any other file in a home directory.
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Resolve the deployment and the token.
45
+ *
46
+ * Environment first, so a CI job can supply both without writing a file, and so
47
+ * a token can be scoped to one shell rather than to the whole machine.
48
+ */
49
+ export function resolveAuth(flags = {}) {
50
+ const config = readConfig();
51
+ const origin = (
52
+ flags.origin ||
53
+ process.env.BIKESHED_ORIGIN ||
54
+ config.origin ||
55
+ "https://bikeshed.now"
56
+ ).replace(/\/+$/, "");
57
+ const token = flags.token || process.env.BIKESHED_TOKEN || config.token || "";
58
+ return { origin, token };
59
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,401 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // `bikeshed` — publish and revise documents from the terminal (SPEC §19).
4
+
5
+ import { parseArgs } from "node:util";
6
+ import { mkdirSync, readFileSync, watch, writeFileSync } from "node:fs";
7
+ import { basename, join, resolve } from "node:path";
8
+ import { createInterface } from "node:readline/promises";
9
+
10
+ import { CONFIG_PATH, readConfig, resolveAuth, writeConfig } from "./config.mjs";
11
+ import { CliError, callTool, fetchSkill, listSkills, uploadFile, whoami } from "./client.mjs";
12
+
13
+ /**
14
+ * This is the END-USER tool, and it is deliberately not the same thing as the
15
+ * scripts in `scripts/`. Conflating the two is how somebody runs a teardown
16
+ * against production, so the difference is stated in `--help`, in the README,
17
+ * and here:
18
+ *
19
+ * scripts/*.mjs whoever owns the deployment. Admin credentials. Talks to
20
+ * Firestore and Storage directly. Provisions and withdraws.
21
+ * bikeshed any signed-up user. A personal access token. Talks to the
22
+ * deployment over HTTPS. Publishes and revises documents.
23
+ *
24
+ * Every command takes `--json`, so it composes inside a script or an agent's
25
+ * shell without anybody parsing human-readable output.
26
+ */
27
+
28
+ const USAGE = `bikeshed — publish and revise documents
29
+
30
+ bikeshed login store a personal access token
31
+ bikeshed list documents you can read
32
+ bikeshed publish <file> create a new document
33
+ bikeshed update <id> <file> publish a new version
34
+ bikeshed get <id> print a document's source
35
+ bikeshed comments <id> unresolved feedback, with its anchored text
36
+ bikeshed reply <id> <thread> <text> reply in a thread
37
+ bikeshed open <id> open it in a browser
38
+
39
+ Organising
40
+ bikeshed folders the folder tree, with ids
41
+ bikeshed mkdir <name> [--parent <id>] create a folder
42
+ bikeshed mv <id> <folder|root> move a document
43
+
44
+ Skills
45
+ bikeshed skills skills this deployment publishes
46
+ bikeshed skills install <dir> write them into an agent's skills directory
47
+ (Claude Code: ~/.claude/skills)
48
+
49
+ Options
50
+ --json machine-readable output
51
+ --title <text> title for publish
52
+ --folder <id> destination folder for publish
53
+ --parent <id> parent folder for mkdir
54
+ --watch with publish/update: republish on every save
55
+ --origin <url> the deployment (default: the one you logged in to)
56
+ --token <token> override the stored token
57
+ --help this
58
+
59
+ Environment
60
+ BIKESHED_ORIGIN, BIKESHED_TOKEN, BIKESHED_AGENT
61
+
62
+ This is the end-user tool. The scripts in scripts/ are the OPERATOR tools: they
63
+ use admin credentials, talk to the database directly, and can tear a deployment
64
+ down. They are not the same thing.
65
+ `;
66
+
67
+ function fail(message) {
68
+ console.error(`error: ${message}`);
69
+ process.exit(1);
70
+ }
71
+
72
+ function out(json, value, human) {
73
+ if (json) {
74
+ console.log(JSON.stringify(value, null, 2));
75
+ return;
76
+ }
77
+ human();
78
+ }
79
+
80
+ // --- Commands --------------------------------------------------------------
81
+
82
+ async function login(flags) {
83
+ const { origin } = resolveAuth(flags);
84
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
85
+ try {
86
+ const where =
87
+ flags.origin ||
88
+ (await rl.question(`Deployment [${origin}]: `)).trim() ||
89
+ origin;
90
+ console.log(`\nCreate a token at ${where}/account — choose "Command line".`);
91
+ console.log("It is shown once, so copy it now.\n");
92
+ const token = (await rl.question("Token: ")).trim();
93
+ if (!token) fail("no token given");
94
+
95
+ // Verified before it is stored, so a typo fails here rather than on the
96
+ // next command with a confusing message.
97
+ await whoami(where, token);
98
+ writeConfig({ ...readConfig(), origin: where, token });
99
+ console.log(`\nSaved to ${CONFIG_PATH} (readable only by you).`);
100
+ } finally {
101
+ rl.close();
102
+ }
103
+ }
104
+
105
+ async function list(flags) {
106
+ const { origin, token } = resolveAuth(flags);
107
+ const result = await callTool(origin, token, "list_documents", {
108
+ limit: Number(flags.limit) || 20,
109
+ });
110
+ out(flags.json, result, () => {
111
+ if (result.documents.length === 0) {
112
+ console.log("Nothing yet. `bikeshed publish <file>` to start.");
113
+ return;
114
+ }
115
+ for (const doc of result.documents) {
116
+ const marker = doc.visibility === "private" ? " " : doc.visibility === "public" ? "◉" : "◐";
117
+ console.log(`${marker} ${doc.id.padEnd(34)} ${doc.version.padEnd(5)} ${doc.title}`);
118
+ }
119
+ if (result.nextCursor) console.log(`\n… more: --cursor ${result.nextCursor}`);
120
+ });
121
+ }
122
+
123
+ async function publish(flags, [path]) {
124
+ if (!path) fail("usage: bikeshed publish <file>");
125
+ const { origin, token } = resolveAuth(flags);
126
+ const file = resolve(path);
127
+
128
+ const once = async () => {
129
+ const result = await uploadFile(origin, token, file, {
130
+ title: flags.title,
131
+ folder: flags.folder,
132
+ });
133
+ // The address is in the human line already; `--json` carried only the id, so
134
+ // anything reading it had to know how to build a URL out of a docId.
135
+ out(flags.json, { ...result, url: result.url ?? `${origin}/d/${result.docId}` }, () =>
136
+ console.log(`published ${result.docId} ${result.versionId} — ${origin}/d/${result.docId}`),
137
+ );
138
+ return result;
139
+ };
140
+
141
+ const first = await once();
142
+ if (flags.watch) {
143
+ // Watch republishes as UPDATES after the first, or every save would create
144
+ // another document.
145
+ await watchFile(file, () =>
146
+ update({ ...flags, watch: false }, [first.docId, file]),
147
+ );
148
+ }
149
+ }
150
+
151
+ async function update(flags, [id, path]) {
152
+ if (!id || !path) fail("usage: bikeshed update <id> <file>");
153
+ const { origin, token } = resolveAuth(flags);
154
+ const file = resolve(path);
155
+
156
+ const once = async () => {
157
+ const content = readFileSync(file, "utf8");
158
+ const result = await callTool(origin, token, "update_document", { id, content });
159
+ out(flags.json, { ...result, url: result.url ?? `${origin}/d/${id}` }, () =>
160
+ console.log(
161
+ result.deduped
162
+ ? `no change — identical to ${result.versionId}`
163
+ : `published ${result.versionId} (${result.fileCount} file(s), ${result.bytes} bytes)`,
164
+ ),
165
+ );
166
+ return result;
167
+ };
168
+
169
+ await once();
170
+ if (flags.watch) await watchFile(file, once);
171
+ }
172
+
173
+ async function get(flags, [id]) {
174
+ if (!id) fail("usage: bikeshed get <id>");
175
+ const { origin, token } = resolveAuth(flags);
176
+ const result = await callTool(origin, token, "get_document", { id });
177
+ out(flags.json, result, () => process.stdout.write(result.source));
178
+ }
179
+
180
+ async function comments(flags, [id]) {
181
+ if (!id) fail("usage: bikeshed comments <id>");
182
+ const { origin, token } = resolveAuth(flags);
183
+ const result = await callTool(origin, token, "get_comments", {
184
+ id,
185
+ includeResolved: Boolean(flags.all),
186
+ });
187
+ out(flags.json, result, () => {
188
+ if (result.threads.length === 0) {
189
+ console.log("No open comments.");
190
+ return;
191
+ }
192
+ for (const thread of result.threads) {
193
+ // The QUOTE first, because it is what makes a comment actionable: it says
194
+ // which passage to change without opening the document.
195
+ console.log(`\n── ${thread.threadId}${thread.section ? ` (${thread.section})` : ""}`);
196
+ if (thread.quote) console.log(` “${thread.quote}”`);
197
+ for (const comment of thread.comments) {
198
+ const via = comment.via && comment.via !== "web" ? ` [via ${comment.via}]` : "";
199
+ console.log(` ${comment.author}${via}: ${comment.body}`);
200
+ }
201
+ }
202
+ console.log("");
203
+ });
204
+ }
205
+
206
+ async function reply(flags, [id, threadId, ...rest]) {
207
+ const body = rest.join(" ");
208
+ if (!id || !threadId || !body) fail("usage: bikeshed reply <id> <thread> <text>");
209
+ const { origin, token } = resolveAuth(flags);
210
+ const result = await callTool(origin, token, "reply_to_comment", { id, threadId, body });
211
+ out(flags.json, result, () => console.log(`replied in ${threadId}`));
212
+ }
213
+
214
+ async function folders(flags) {
215
+ const { origin, token } = resolveAuth(flags);
216
+ const result = await callTool(origin, token, "list_folders", {});
217
+ out(flags.json, result, () => {
218
+ if (result.folders.length === 0) {
219
+ console.log("No folders. `bikeshed mkdir <name>` to make one.");
220
+ return;
221
+ }
222
+ for (const folder of result.folders) {
223
+ // Indentation comes from the PATH, not from walking parents: a folder
224
+ // whose parent is not shared with you still sits at its real depth, and
225
+ // its path already says so with an ellipsis for the level you cannot see.
226
+ const depth = folder.path.split("/").length - 1;
227
+ const label = `${" ".repeat(depth)}${folder.name}`;
228
+ const note = folder.canWrite ? "" : " (read-only)";
229
+ console.log(`${label.padEnd(40)} ${folder.id}${note}`);
230
+ }
231
+ if (result.truncated) {
232
+ console.log("\nThere are more folders than this listing shows.");
233
+ }
234
+ });
235
+ }
236
+
237
+ async function mkdir(flags, rest) {
238
+ const name = rest.join(" ");
239
+ if (!name) fail("usage: bikeshed mkdir <name> [--parent <id>]");
240
+ const { origin, token } = resolveAuth(flags);
241
+ const args = { name };
242
+ if (flags.parent) args.parent = flags.parent;
243
+ const result = await callTool(origin, token, "create_folder", args);
244
+ out(flags.json, result, () => console.log(`${result.name} ${result.folderId}`));
245
+ }
246
+
247
+ async function mv(flags, [id, dest]) {
248
+ /**
249
+ * The destination is REQUIRED, and the workspace root has to be spelled.
250
+ *
251
+ * On the MCP side an omitted `folder` means the root, because the protocol
252
+ * has no way to send an empty one. A positional argument does: leaving it off
253
+ * is something a person does by accident, and "bikeshed mv report" silently
254
+ * pulling a document out of the folder it was filed in is not a mistake the
255
+ * interface should make easy.
256
+ */
257
+ if (!id || !dest) fail("usage: bikeshed mv <id> <folder|root>");
258
+ const { origin, token } = resolveAuth(flags);
259
+ const args = dest === "root" ? { id } : { id, folder: dest };
260
+ const result = await callTool(origin, token, "move_document", args);
261
+ out(flags.json, result, () =>
262
+ console.log(result.folder ? `moved ${id} into ${result.folder}` : `moved ${id} to the root`),
263
+ );
264
+ }
265
+
266
+ /**
267
+ * Skills are instructions, not code, and they are fetched from the DEPLOYMENT
268
+ * rather than bundled with this CLI on purpose: a deployment running an older
269
+ * version should hand out the skills that describe what it can actually do.
270
+ *
271
+ * No token is needed — they are public static files, the same ones `/llms.txt`
272
+ * points at.
273
+ */
274
+ async function skillsCommand(flags, [sub, dir]) {
275
+ const { origin } = resolveAuth(flags);
276
+ const index = await listSkills(origin);
277
+
278
+ if (!sub) {
279
+ out(flags.json, index, () => {
280
+ for (const skill of index.skills) {
281
+ console.log(`${skill.name}\n ${skill.description}\n`);
282
+ }
283
+ console.log(`bikeshed skills install <dir> — Claude Code: ~/.claude/skills`);
284
+ });
285
+ return;
286
+ }
287
+ if (sub !== "install") fail("usage: bikeshed skills [install <dir>]");
288
+ if (!dir) fail("usage: bikeshed skills install <dir>");
289
+
290
+ const root = resolve(dir);
291
+ const written = [];
292
+ for (const skill of index.skills) {
293
+ // The name decides a path on this machine, so it is validated here rather
294
+ // than trusted from the response. A deployment is not an adversary, but a
295
+ // name is still the wrong place to find out it could have been one.
296
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(skill.name)) {
297
+ fail(`refusing a skill with an unusable name: ${skill.name}`);
298
+ }
299
+ const body = await fetchSkill(origin, skill);
300
+ const target = join(root, skill.name);
301
+ mkdirSync(target, { recursive: true });
302
+ writeFileSync(join(target, "SKILL.md"), body);
303
+ written.push(join(skill.name, "SKILL.md"));
304
+ }
305
+ out(flags.json, { installed: written, into: root }, () => {
306
+ for (const file of written) console.log(`${root}/${file}`);
307
+ });
308
+ }
309
+
310
+ async function open(flags, [id]) {
311
+ if (!id) fail("usage: bikeshed open <id>");
312
+ const { origin } = resolveAuth(flags);
313
+ const url = `${origin}/d/${id}`;
314
+ const { spawn } = await import("node:child_process");
315
+ const opener =
316
+ process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
317
+ spawn(opener, [url], { stdio: "ignore", detached: true }).unref();
318
+ console.log(url);
319
+ }
320
+
321
+ /**
322
+ * Re-run on every save, debounced.
323
+ *
324
+ * Editors write in bursts — a truncate, then a write, sometimes a rename — so a
325
+ * naive watcher fires three times per save and publishes twice more than it
326
+ * should. The content hash would make the extra calls no-ops, but they would
327
+ * still be three round trips per keystroke-pause.
328
+ */
329
+ async function watchFile(file, run) {
330
+ console.log(`watching ${basename(file)} — ctrl-C to stop`);
331
+ let timer = null;
332
+ watch(file, () => {
333
+ if (timer) clearTimeout(timer);
334
+ timer = setTimeout(() => {
335
+ run().catch((e) => console.error(`error: ${e.message}`));
336
+ }, 250);
337
+ });
338
+ await new Promise(() => {}); // until interrupted
339
+ }
340
+
341
+ // --- Entry point -----------------------------------------------------------
342
+
343
+ const COMMANDS = {
344
+ login,
345
+ list,
346
+ publish,
347
+ update,
348
+ get,
349
+ comments,
350
+ reply,
351
+ open,
352
+ folders,
353
+ mkdir,
354
+ mv,
355
+ skills: skillsCommand,
356
+ };
357
+
358
+ /** Commands that reach a deployment without authenticating as anybody. */
359
+ const NO_TOKEN = new Set(["login", "open", "skills"]);
360
+
361
+ async function main() {
362
+ const { values, positionals } = parseArgs({
363
+ args: process.argv.slice(2),
364
+ allowPositionals: true,
365
+ strict: false,
366
+ options: {
367
+ json: { type: "boolean", default: false },
368
+ watch: { type: "boolean", default: false },
369
+ all: { type: "boolean", default: false },
370
+ help: { type: "boolean", default: false },
371
+ title: { type: "string" },
372
+ folder: { type: "string" },
373
+ parent: { type: "string" },
374
+ origin: { type: "string" },
375
+ token: { type: "string" },
376
+ limit: { type: "string" },
377
+ cursor: { type: "string" },
378
+ },
379
+ });
380
+
381
+ const [name, ...rest] = positionals;
382
+ if (values.help || !name) {
383
+ console.log(USAGE);
384
+ return;
385
+ }
386
+
387
+ const command = COMMANDS[name];
388
+ if (!command) fail(`unknown command: ${name}\n\n${USAGE}`);
389
+
390
+ const { token } = resolveAuth(values);
391
+ if (!token && !NO_TOKEN.has(name)) {
392
+ fail("no token. Run `bikeshed login`, or set BIKESHED_TOKEN.");
393
+ }
394
+
395
+ await command(values, rest);
396
+ }
397
+
398
+ main().catch((e) => {
399
+ if (e instanceof CliError) fail(e.message);
400
+ fail(e?.message ?? String(e));
401
+ });