sharedthink 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # sharedthink
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A team's shared brain for AI agents. One live place per project: agents read it when they need project knowledge,
4
+ send a note when they find something that helps everyone, and the owner's agent decides what goes in.
5
+ The server runs no model: it stores, checks access, and serves the project's rules.
6
+
7
+ ## How it works
8
+
9
+ - **Read live:** agents search the brain over MCP. Nobody pulls, nothing to sync.
10
+ - **Send rarely:** a note is one line + why + source. Only things that help everyone (a tool, a decision, a gotcha).
11
+ - **Owner decides:** teammates' notes go only to the owner's inbox. Everyone else sees approved facts only,
12
+ so a bad note never reaches other agents. The owner's agent merges, rejects, or applies the code change itself.
13
+ Owner notes go straight in.
14
+ - **Rules live in the brain:** each project's rules are sent to every agent as the MCP instructions.
15
+ Change them with `sharedthink rules --set`, every agent follows the new ones next session.
16
+ - **No hooks, no nudges:** zero extra tokens beyond the rules text and the reads an agent chooses to do.
17
+ - **Safe by default:** tokens stored as hashes, obvious secrets refused, notes capped at 300 chars,
18
+ brain content always framed as information, never instructions. Facts are never overwritten.
19
+
20
+ ## Use it
21
+
22
+ ```sh
23
+ # owner
24
+ sharedthink create <project>
25
+ sharedthink invite <project> # prints a single-use code
26
+ cd <repo> && sharedthink init <project>
27
+
28
+ # teammate
29
+ npx sharedthink join <code> --name <you>
30
+ cd <repo> && npx sharedthink init <project>
31
+ ```
32
+
33
+ `init` writes `.sharedthink.json` (safe to commit) and adds the `sharedthink` MCP server in local scope
34
+ (this repo, this machine; the token stays out of the repo).
35
+
36
+ Your other machines: run `npx sharedthink pair` there, then `sharedthink approve <words>` on a machine
37
+ that is already logged in. No token is copied between machines.
38
+
39
+ Other commands: `read [words]`, `send "<text>" --why .. --source ..`, `inbox`, `merge <id>`, `reject <id> "why"`, `rules`, `log`,
40
+ `members`, `remove <name>` (owner: access ends at once), `rotate` (new token if yours leaked).
41
+
42
+ ## Run the server
43
+
44
+ ```sh
45
+ npm install
46
+ npx convex dev # dev deployment
47
+ npx convex deploy # prod
48
+ npx convex run --prod admin:createUser '{"name":"<you>"}' # first account, prints the token once
49
+ ```
50
+
51
+ The CLI talks to the prod URL by default. Override with `SHAREDTHINK_URL`.
@@ -0,0 +1,285 @@
1
+ #!/usr/bin/env node
2
+ // sharedthink CLI: a team's shared brain for agents. Zero dependencies.
3
+ import { execSync, spawnSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+
8
+ const DEFAULT_URL = "https://moonlit-herring-411.convex.site";
9
+ const HOME = process.env.SHAREDTHINK_HOME || path.join(os.homedir(), ".sharedthink");
10
+ const CONFIG = path.join(HOME, "config.json");
11
+ const LINK_FILE = ".sharedthink.json";
12
+
13
+ const readJson = (f, d = null) => {
14
+ try {
15
+ return JSON.parse(fs.readFileSync(f, "utf8"));
16
+ } catch {
17
+ return d;
18
+ }
19
+ };
20
+ const writeJson = (f, data, mode) => {
21
+ fs.mkdirSync(path.dirname(f), { recursive: true });
22
+ fs.writeFileSync(f, JSON.stringify(data, null, 2) + "\n", mode ? { mode } : undefined);
23
+ };
24
+ const die = (msg, code = 1) => {
25
+ process.stderr.write(`sharedthink: ${msg}\n`);
26
+ process.exit(code);
27
+ };
28
+
29
+ function repoRoot() {
30
+ try {
31
+ return execSync("git rev-parse --show-toplevel", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
32
+ } catch {
33
+ return process.cwd();
34
+ }
35
+ }
36
+ function linkedProject() {
37
+ let dir = process.cwd();
38
+ while (true) {
39
+ const p = readJson(path.join(dir, LINK_FILE))?.project;
40
+ if (p) return p;
41
+ const up = path.dirname(dir);
42
+ if (up === dir) return null;
43
+ dir = up;
44
+ }
45
+ }
46
+ function project(explicit) {
47
+ const p = explicit || linkedProject();
48
+ if (!p) die(`no project: pass one, or run 'sharedthink init <project>' in the repo`);
49
+ return p;
50
+ }
51
+ const serverUrl = () => (process.env.SHAREDTHINK_URL || readJson(CONFIG)?.url || DEFAULT_URL).replace(/\/$/, "");
52
+ const token = () => process.env.SHAREDTHINK_TOKEN || readJson(CONFIG)?.token;
53
+ function needToken() {
54
+ const t = token();
55
+ if (!t) die("not logged in: 'sharedthink join <invite-code> --name <you>' or 'sharedthink login --token <token>'");
56
+ return t;
57
+ }
58
+
59
+ async function api(op, body = {}, { auth = true } = {}) {
60
+ const t = auth ? needToken() : token();
61
+ const res = await fetch(`${serverUrl()}/api/${op}`, {
62
+ method: "POST",
63
+ headers: { "Content-Type": "application/json", ...(t ? { Authorization: `Bearer ${t}` } : {}) },
64
+ body: JSON.stringify(body),
65
+ });
66
+ const data = await res.json().catch(() => ({}));
67
+ if (!res.ok) die(data?.error ? `${data.error.code}: ${data.error.message}` : `HTTP ${res.status}`);
68
+ return data;
69
+ }
70
+
71
+ function parseArgs(argv) {
72
+ const flags = {};
73
+ const pos = [];
74
+ for (let i = 0; i < argv.length; i++) {
75
+ const a = argv[i];
76
+ if (a.startsWith("--")) {
77
+ const k = a.slice(2);
78
+ const next = argv[i + 1];
79
+ if (next === undefined || next.startsWith("--")) flags[k] = true;
80
+ else flags[k] = argv[++i];
81
+ } else pos.push(a);
82
+ }
83
+ return { flags, pos };
84
+ }
85
+
86
+ const age = (ms) => {
87
+ const m = Math.round((Date.now() - ms) / 60000);
88
+ return m < 60 ? `${m}m` : m < 2880 ? `${Math.round(m / 60)}h` : `${Math.round(m / 1440)}d`;
89
+ };
90
+ const noteLine = (n) =>
91
+ `- [${n.id}] ${n.kind === "add" ? "" : n.kind + ": "}${n.text} (by ${n.author}, ${age(n.createdAt)})\n why: ${n.why} | source: ${n.source}` +
92
+ (n.replaces ? `\n replaces: ${n.replaces}` : "");
93
+
94
+ function saveLogin(t) {
95
+ writeJson(CONFIG, { url: serverUrl(), token: t }, 0o600);
96
+ }
97
+
98
+ // Adds the MCP server for this repo only (local scope). The token lives in Claude's local config, never in the repo.
99
+ function addMcp(root, slug) {
100
+ const url = `${serverUrl()}/mcp?project=${encodeURIComponent(slug)}`;
101
+ spawnSync("claude", ["mcp", "remove", "--scope", "local", "sharedthink"], { cwd: root, stdio: "ignore" });
102
+ const r = spawnSync(
103
+ "claude",
104
+ ["mcp", "add", "--transport", "http", "--scope", "local", "sharedthink", url, "--header", `Authorization: Bearer ${needToken()}`],
105
+ { cwd: root, stdio: "pipe" },
106
+ );
107
+ if (r.status === 0) console.log(`added MCP server 'sharedthink' for this repo -> ${url}`);
108
+ else
109
+ console.log(
110
+ `could not add the MCP server automatically. In ${root} run:\n claude mcp add --transport http --scope local sharedthink ${url} --header "Authorization: Bearer <your token>"`,
111
+ );
112
+ }
113
+
114
+ const commands = {
115
+ async login({ flags }) {
116
+ const t = flags.token || process.env.SHAREDTHINK_TOKEN;
117
+ if (!t || t === true) die("usage: sharedthink login --token <token> [--url <server>]");
118
+ if (flags.url) process.env.SHAREDTHINK_URL = flags.url;
119
+ saveLogin(t);
120
+ console.log(`saved ${CONFIG}`);
121
+ },
122
+
123
+ // Redeem an invite. New here: --name creates your account. Already logged in: adds the project to it.
124
+ async join({ pos, flags }) {
125
+ const code = pos[0];
126
+ if (!code) die("usage: sharedthink join <invite-code> [--name <you>]");
127
+ if (flags.url) process.env.SHAREDTHINK_URL = flags.url;
128
+ const r = await api("join", { code, name: flags.name }, { auth: false });
129
+ if (r.token) saveLogin(r.token);
130
+ console.log(`joined '${r.project}' as ${r.name}${r.created ? ` (new account, token saved to ${CONFIG})` : ""}`);
131
+ console.log(`next: in the project's repo, run 'sharedthink init ${r.project}'`);
132
+ },
133
+
134
+ // On a NEW machine: log in as yourself. Approve the words from a machine that is already logged in.
135
+ async pair({ flags }) {
136
+ if (flags.url) process.env.SHAREDTHINK_URL = flags.url;
137
+ const r = await api("pair/start", {}, { auth: false });
138
+ console.log(`on a machine where you are logged in, run:\n\n sharedthink approve ${r.words}\n\nwaiting (10 minutes)...`);
139
+ const until = Date.now() + 10 * 60_000;
140
+ while (Date.now() < until) {
141
+ await new Promise((ok) => setTimeout(ok, 3000));
142
+ const p = await api("pair/poll", { secret: r.secret }, { auth: false });
143
+ if (p.status === "approved") {
144
+ saveLogin(p.token);
145
+ return console.log(`this machine is now logged in as ${p.name}. Next: in a repo, run 'sharedthink init <project>'`);
146
+ }
147
+ }
148
+ die("pairing expired: run 'sharedthink pair' again");
149
+ },
150
+
151
+ // On a logged-in machine: let a new machine in as you.
152
+ async approve({ pos }) {
153
+ if (!pos[0]) die("usage: sharedthink approve <words>");
154
+ const r = await api("pair/approve", { words: pos[0] });
155
+ console.log(`approved: that machine is now logged in as ${r.name}`);
156
+ },
157
+
158
+ async create({ pos }) {
159
+ if (!pos[0]) die("usage: sharedthink create <project>");
160
+ const r = await api("create", { project: pos[0] });
161
+ console.log(`created '${r.project}', owner ${r.owner}. Link a repo: sharedthink init ${r.project}`);
162
+ },
163
+
164
+ async invite({ pos, flags }) {
165
+ const r = await api("invite", { project: project(pos[0]), days: flags.days });
166
+ console.log(`invite for '${r.project}', single use, expires ${new Date(r.expiresAt).toISOString().slice(0, 10)}:\n npx sharedthink join ${r.code} --name <their-name>`);
167
+ },
168
+
169
+ // Links this repo: .sharedthink.json (safe to commit) + MCP server in local scope.
170
+ async init({ pos, flags }) {
171
+ const slug = pos[0] || linkedProject();
172
+ if (!slug) die("usage: sharedthink init <project>");
173
+ await api("rules", { project: slug }); // fails early if you can't access it
174
+ const root = repoRoot();
175
+ writeJson(path.join(root, LINK_FILE), { project: slug });
176
+ console.log(`wrote ${path.join(root, LINK_FILE)}`);
177
+ if (!flags["no-mcp"]) addMcp(root, slug);
178
+ },
179
+
180
+ async read({ pos, flags }) {
181
+ const r = await api("read", { project: project(flags.project), query: pos.join(" ") || undefined });
182
+ if (!r.facts.length) console.log(pos.length ? "nothing matches" : `'${r.project}' is empty`);
183
+ for (const f of r.facts) console.log(`- [${f.id}] ${f.text}\n why: ${f.why} | source: ${f.source}`);
184
+ if (r.waiting) console.log(`\n${r.waiting} note(s) waiting: sharedthink inbox`);
185
+ },
186
+
187
+ async send({ pos, flags }) {
188
+ const text = pos.join(" ");
189
+ if (!flags.why || !flags.source || (!text && flags.kind !== "retire"))
190
+ die('usage: sharedthink send "<text>" --why "<why>" --source "<commit|file|url>" [--fact <id> [--kind retire]]');
191
+ const r = await api("send", {
192
+ project: project(flags.project),
193
+ kind: flags.kind || (flags.fact ? "update" : "add"),
194
+ factId: flags.fact,
195
+ text,
196
+ why: flags.why,
197
+ source: flags.source,
198
+ });
199
+ console.log(`note ${r.id}: ${r.status === "open" ? "sent to the owner for review" : r.status}${r.duplicate ? " (already sent)" : ""}`);
200
+ },
201
+
202
+ async inbox({ flags }) {
203
+ const list = await api("inbox", { project: project(flags.project) });
204
+ console.log(list.length ? list.map(noteLine).join("\n") : "inbox is empty");
205
+ },
206
+
207
+ async merge({ pos, flags }) {
208
+ if (!pos[0]) die("usage: sharedthink merge <note-id>");
209
+ const r = await api("decide", { project: project(flags.project), noteId: pos[0], action: "merge" });
210
+ console.log(`note ${pos[0]}: ${r.status}`);
211
+ },
212
+
213
+ async reject({ pos, flags }) {
214
+ if (!pos[0]) die('usage: sharedthink reject <note-id> ["reason"]');
215
+ const r = await api("decide", { project: project(flags.project), noteId: pos[0], action: "reject", reason: pos.slice(1).join(" ") });
216
+ console.log(`note ${pos[0]}: ${r.status}`);
217
+ },
218
+
219
+ // Show the brain's rules, or replace them: --set <file> (owner only).
220
+ async rules({ flags }) {
221
+ const slug = project(flags.project);
222
+ if (flags.set) {
223
+ const text = fs.readFileSync(flags.set === "-" ? 0 : flags.set, "utf8");
224
+ const r = await api("rules", { project: slug, set: text });
225
+ return console.log(`rules for '${r.project}' updated (${r.chars} chars). Agents pick them up on their next session.`);
226
+ }
227
+ const r = await api("rules", { project: slug });
228
+ console.log(r.rules);
229
+ },
230
+
231
+ async members({ pos, flags }) {
232
+ const list = await api("members", { project: project(pos[0] || flags.project) });
233
+ for (const m of list) console.log(`${m.role.padEnd(7)} ${m.name}`);
234
+ },
235
+
236
+ // Owner: take someone out of the project. Their access ends immediately.
237
+ async remove({ pos, flags }) {
238
+ if (!pos[0]) die("usage: sharedthink remove <name>");
239
+ const r = await api("remove", { project: project(flags.project), name: pos[0] });
240
+ console.log(`removed ${r.removed} from '${r.project}'`);
241
+ },
242
+
243
+ // New token for you; the old one stops working everywhere. Run init again in your repos to update the MCP entry.
244
+ async rotate() {
245
+ const r = await api("rotate");
246
+ saveLogin(r.token);
247
+ console.log(`new token saved for ${r.name}. The old one no longer works. Run 'sharedthink init' again in each linked repo.`);
248
+ },
249
+
250
+ async log({ flags }) {
251
+ const rows = await api("log", { project: project(flags.project), limit: flags.n ? Number(flags.n) : 20 });
252
+ for (const n of rows)
253
+ console.log(
254
+ `${n.status.padEnd(8)} ${age(n.createdAt).padStart(4)} ${n.text || "(retire)"} (by ${n.author}` +
255
+ `${n.decidedBy ? `, ${n.status} by ${n.decidedBy}` : ""}${n.reason ? `: ${n.reason}` : ""})`,
256
+ );
257
+ },
258
+ };
259
+
260
+ const [cmd, ...rest] = process.argv.slice(2);
261
+ if (!cmd || !commands[cmd]) {
262
+ console.log(`sharedthink: a team's shared brain for agents
263
+
264
+ join <invite-code> --name <you> join a project (creates your account if new)
265
+ login --token <token> use an existing token on this machine
266
+ pair on a new machine: log in as you (approve it from another)
267
+ approve <words> let that new machine in
268
+ create <project> create a project, you are the owner
269
+ invite [project] make a single-use invite code (owner)
270
+ init <project> link this repo: .sharedthink.json + MCP for this repo only
271
+
272
+ read [words] search the brain
273
+ send "<text>" --why .. --source .. send a note [--fact <id> [--kind retire]]
274
+ inbox notes waiting for a decision (owner)
275
+ merge <id> | reject <id> "why" decide a note (owner)
276
+ rules [--set <file>] show or replace how this brain works (owner sets)
277
+ log [--n 20] recent notes
278
+ members who is in the project
279
+ remove <name> take someone out (owner)
280
+ rotate replace your token (if it leaked)
281
+
282
+ server: ${serverUrl()} (override with SHAREDTHINK_URL)`);
283
+ process.exit(cmd ? 1 : 0);
284
+ }
285
+ commands[cmd](parseArgs(rest)).catch((e) => die(e.message));
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "sharedthink",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "A team's shared brain for AI agents: one live place your agents read from, send to, and you approve.",
5
+ "keywords": [
6
+ "ai",
7
+ "agents",
8
+ "mcp",
9
+ "claude",
10
+ "knowledge-base",
11
+ "team",
12
+ "memory"
13
+ ],
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "bin": {
17
+ "sharedthink": "cli/sharedthink.mjs"
18
+ },
19
+ "files": [
20
+ "cli/"
21
+ ],
22
+ "engines": {
23
+ "node": ">=18"
24
+ },
25
+ "scripts": {
26
+ "dev": "convex dev",
27
+ "deploy": "convex deploy"
28
+ },
29
+ "devDependencies": {
30
+ "convex": "^1.51.0",
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }