@tacitai/mcp-server 0.7.0 → 0.8.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.
Files changed (73) hide show
  1. package/dist/api-errors.d.ts +102 -0
  2. package/dist/api-errors.js +165 -0
  3. package/dist/autonomy.d.ts +46 -0
  4. package/dist/autonomy.js +118 -0
  5. package/dist/claude-config.d.ts +139 -0
  6. package/dist/claude-config.js +339 -0
  7. package/dist/cli-launch.d.ts +33 -0
  8. package/dist/cli-launch.js +178 -0
  9. package/dist/cli-login.d.ts +34 -0
  10. package/dist/cli-login.js +200 -0
  11. package/dist/cli-mode.d.ts +47 -0
  12. package/dist/cli-mode.js +170 -0
  13. package/dist/cli-profiles.d.ts +37 -0
  14. package/dist/cli-profiles.js +344 -0
  15. package/dist/cli.d.ts +9 -0
  16. package/dist/cli.js +59 -458
  17. package/dist/client.d.ts +90 -52
  18. package/dist/client.js +198 -296
  19. package/dist/credentials.d.ts +81 -0
  20. package/dist/credentials.js +291 -0
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +37 -89
  23. package/dist/oauth.d.ts +1 -1
  24. package/dist/oauth.js +5 -5
  25. package/dist/profile-store.d.ts +96 -0
  26. package/dist/profile-store.js +382 -0
  27. package/dist/prompt.d.ts +32 -0
  28. package/dist/prompt.js +99 -0
  29. package/dist/prompts.d.ts +2 -2
  30. package/dist/prompts.js +3 -3
  31. package/dist/server-mode.d.ts +65 -0
  32. package/dist/server-mode.js +99 -0
  33. package/dist/setup-migrate.d.ts +35 -0
  34. package/dist/setup-migrate.js +204 -0
  35. package/dist/setup.d.ts +41 -66
  36. package/dist/setup.js +361 -531
  37. package/dist/signin.d.ts +108 -0
  38. package/dist/signin.js +595 -0
  39. package/dist/tools/agents.d.ts +6 -4
  40. package/dist/tools/agents.js +15 -4
  41. package/dist/tools/artifacts.d.ts +2 -0
  42. package/dist/tools/artifacts.js +8 -1
  43. package/dist/tools/capture.js +2 -2
  44. package/dist/tools/career.js +2 -2
  45. package/dist/tools/chronicle.js +7 -7
  46. package/dist/tools/crews.js +8 -8
  47. package/dist/tools/errors.d.ts +18 -0
  48. package/dist/tools/errors.js +73 -1
  49. package/dist/tools/exec-route.d.ts +34 -0
  50. package/dist/tools/exec-route.js +101 -27
  51. package/dist/tools/github.js +2 -2
  52. package/dist/tools/gm.js +2 -2
  53. package/dist/tools/iam.js +2 -3
  54. package/dist/tools/kb.js +2 -2
  55. package/dist/tools/lake-structure.js +8 -8
  56. package/dist/tools/lake.js +2 -2
  57. package/dist/tools/onboarding.js +2 -2
  58. package/dist/tools/people.js +7 -7
  59. package/dist/tools/pyramid.js +2 -2
  60. package/dist/tools/recall.js +2 -2
  61. package/dist/tools/secretary.d.ts +1 -0
  62. package/dist/tools/secretary.js +2 -1
  63. package/dist/tools/synthesize.d.ts +37 -0
  64. package/dist/tools/synthesize.js +128 -9
  65. package/dist/tools/voice.d.ts +3 -2
  66. package/dist/tools/voice.js +70 -18
  67. package/dist/tools/wiki.js +2 -2
  68. package/dist/tools/workspaces.js +20 -6
  69. package/dist/version.d.ts +6 -0
  70. package/dist/version.js +18 -0
  71. package/dist/workflow-registry.d.ts +1 -0
  72. package/dist/workflow-registry.js +21 -0
  73. package/package.json +4 -1
@@ -0,0 +1,344 @@
1
+ /**
2
+ * `tacit ls | use | status | rm` (MV-1542c step 1.6, P6.4, S-6).
3
+ *
4
+ * `use` and `ls` only read or select stored profiles; the server decides what a token can reach.
5
+ * `rm` signs out ONLY the caller's own login: `POST /api/v1/iam/tokens/self/revoke` with the profile's
6
+ * token as the Bearer (and `if_bound_to_person_id` when `whoami` could confirm who it is). It never calls
7
+ * `DELETE /api/v1/developer-tokens`, which would revoke other members' tokens. The profile file is removed
8
+ * whatever the server said, because the user asked to remove it.
9
+ *
10
+ * Nothing here prints, logs or sends a token anywhere except as the Bearer of the profile's own server.
11
+ */
12
+ import * as fs from 'node:fs';
13
+ import { loadMode } from './claude-config.js';
14
+ import { TacitClient } from './client.js';
15
+ import { CredentialError, resolveCredentials, verifyIdentity, StartupFault, } from './credentials.js';
16
+ import { networkError, printable, revokeMalformed, SIGNED_OUT } from './api-errors.js';
17
+ import { folderForProfile, tilde } from './cli-mode.js';
18
+ import { launchEnv } from './cli-launch.js';
19
+ import { ProfileError, getDefault, isValidProfileName, profileExists, profilesDir, readProfile, removeProfile, setDefault, } from './profile-store.js';
20
+ const DAY_MS = 86_400_000;
21
+ const EXPIRY_WARN_DAYS = 14;
22
+ const dateOf = (ms) => new Date(ms).toISOString().slice(0, 10);
23
+ const kindOf = (p) => p.credential_kind ?? 'dev_token';
24
+ function expiryText(expiresAt, now) {
25
+ if (!expiresAt)
26
+ return 'no expiry date';
27
+ const ms = Date.parse(expiresAt);
28
+ if (Number.isNaN(ms))
29
+ return 'unknown expiry';
30
+ if (now > ms)
31
+ return `expired ${dateOf(ms)}`;
32
+ const days = Math.floor((ms - now) / DAY_MS);
33
+ return `expires ${dateOf(ms)} (${days} day${days === 1 ? '' : 's'} left)`;
34
+ }
35
+ function readAll() {
36
+ let files;
37
+ try {
38
+ files = fs.readdirSync(profilesDir()).filter((f) => f.endsWith('.json')).sort();
39
+ }
40
+ catch {
41
+ return [];
42
+ }
43
+ return files.map((f) => {
44
+ const name = f.replace(/\.json$/, '');
45
+ try {
46
+ return { name, data: readProfile(name) };
47
+ }
48
+ catch (err) {
49
+ return { name, reason: err instanceof ProfileError ? err.message : 'could not be read' };
50
+ }
51
+ });
52
+ }
53
+ export function runLs(ctx) {
54
+ const rows = readAll();
55
+ if (rows.length === 0) {
56
+ ctx.out('No saved logins. Run: npx @tacitai/mcp-server setup');
57
+ return 0;
58
+ }
59
+ const now = (ctx.now ?? Date.now)();
60
+ const defaultName = getDefault();
61
+ const label = (r) => (r.name === defaultName ? `${r.name} (default)` : r.name);
62
+ const width = Math.max(...rows.map((r) => label(r).length));
63
+ for (const r of rows) {
64
+ const head = ` ${label(r).padEnd(width)}`;
65
+ if (!r.data) {
66
+ ctx.out(`${head} unusable: ${r.reason}`);
67
+ continue;
68
+ }
69
+ const d = r.data;
70
+ ctx.out(`${head} ${d.workspace_name ?? d.workspace_id} ${d.identity_email ?? '(no email saved)'} ${kindOf(d)} ${expiryText(d.expires_at, now)}`);
71
+ }
72
+ return 0;
73
+ }
74
+ // ─── use ─────────────────────────────────────────────────────────────────────
75
+ export function runUse(args, ctx) {
76
+ const name = args[0];
77
+ if (!name || args.length > 1) {
78
+ ctx.err('Usage: tacit use <name>');
79
+ return 1;
80
+ }
81
+ try {
82
+ readProfile(name);
83
+ setDefault(name);
84
+ }
85
+ catch (err) {
86
+ if (err instanceof ProfileError) {
87
+ ctx.err(err.message);
88
+ return 1;
89
+ }
90
+ throw err;
91
+ }
92
+ ctx.out(`Default profile set to '${name}'. Plain \`claude\` now uses it.`);
93
+ return 0;
94
+ }
95
+ /** Best effort: who does the server say this credential is? null when it can't be confirmed. */
96
+ export async function fetchPersonId(apiUrl, token, fetchFn) {
97
+ try {
98
+ const res = await fetchFn(`${apiUrl.replace(/\/+$/, '')}/api/v1/auth/whoami`, {
99
+ headers: { Authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(10_000),
100
+ });
101
+ if (!res.ok)
102
+ return null;
103
+ const who = (await res.json());
104
+ return typeof who.person_id === 'string' && who.person_id ? who.person_id : null;
105
+ }
106
+ catch {
107
+ return null;
108
+ }
109
+ }
110
+ async function errorCode(res) {
111
+ try {
112
+ const b = (await res.json());
113
+ return (typeof b.error === 'object' ? b.error?.code : undefined) ?? b.code ?? '';
114
+ }
115
+ catch {
116
+ return '';
117
+ }
118
+ }
119
+ /**
120
+ * Present `token` to its own server's self-revoke route. Only the presented row is revoked. `personId`
121
+ * (when known) makes the server refuse a shared or foreign row instead of revoking it.
122
+ */
123
+ export async function revokeSelf(apiUrl, token, personId, name, fetchFn, credentialKind) {
124
+ // M-2 / D-104: an unguarded revoke of a legacy token could revoke a shared owner-bound row for
125
+ // every holder. Without a person id to guard it, send nothing. IAM rows are always one person's own.
126
+ if (!personId && credentialKind !== 'iam_token') {
127
+ return { kind: 'skipped', line: `The login for ${name} is an older workspace token that can't be confirmed as yours. It was left active; ask the workspace owner.` };
128
+ }
129
+ try {
130
+ const res = await fetchFn(`${apiUrl.replace(/\/+$/, '')}/api/v1/iam/tokens/self/revoke`, {
131
+ method: 'POST',
132
+ headers: personId
133
+ ? { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }
134
+ : { Authorization: `Bearer ${token}` },
135
+ ...(personId ? { body: JSON.stringify({ if_bound_to_person_id: personId }) } : {}),
136
+ signal: AbortSignal.timeout(15_000),
137
+ });
138
+ if (res.ok)
139
+ return { kind: 'revoked', line: `Signed out ${name} on this computer.` };
140
+ const code = await errorCode(res);
141
+ if (res.status === 401)
142
+ return { kind: 'already', line: `The login for ${name} was already expired or revoked.` };
143
+ if (res.status === 400 && code === 'NOT_A_DEVELOPER_TOKEN') {
144
+ return { kind: 'session', line: `The login for ${name} is a browser session token. It can't be revoked from here.` };
145
+ }
146
+ if (res.status === 400 && code === 'INVALID_REQUEST_BODY')
147
+ return { kind: 'malformed', line: revokeMalformed({ name }) };
148
+ if (res.status === 409 && code === 'UNBOUND_TOKEN_SHARED') {
149
+ return { kind: 'shared', line: `The login for ${name} is a shared workspace token. It was left active; ask the workspace owner.` };
150
+ }
151
+ if (res.status === 409 && code === 'BINDING_MISMATCH') {
152
+ return { kind: 'mismatch', line: `The login for ${name} belongs to a different member. It was left unchanged.` };
153
+ }
154
+ return { kind: 'failed', line: `Could not sign out ${name} on the server (HTTP ${res.status}). It remains valid.` };
155
+ }
156
+ catch (err) {
157
+ return { kind: 'failed', line: `Could not sign out ${name} on the server (${err instanceof Error ? err.name : 'network error'}). It remains valid.` };
158
+ }
159
+ }
160
+ /**
161
+ * L-13: a token was just issued but could not be saved, so nothing holds it. Sign it out so it does
162
+ * not sit live for 90 days. Returns the line to show when the revoke itself failed, else null.
163
+ */
164
+ export async function revokeUnsaved(apiUrl, token, fetchFn) {
165
+ const r = await revokeSelf(apiUrl, token, null, 'the new login', fetchFn, 'iam_token');
166
+ return r.kind === 'revoked' || r.kind === 'already' ? null : r.line;
167
+ }
168
+ // ─── rm ──────────────────────────────────────────────────────────────────────
169
+ export async function runRm(args, ctx) {
170
+ const localOnly = args.includes('--local-only');
171
+ const rest = args.filter((a) => a !== '--local-only');
172
+ const name = rest[0];
173
+ if (!name || rest.length > 1) {
174
+ ctx.err('Usage: tacit rm <name> [--local-only]');
175
+ return 1;
176
+ }
177
+ if (name.startsWith('-')) {
178
+ ctx.err(`Unknown option ${name}\nUsage: tacit rm <name> [--local-only]`);
179
+ return 1;
180
+ }
181
+ if (!isValidProfileName(name)) {
182
+ ctx.err(`Invalid profile name '${name}'.`);
183
+ return 1;
184
+ }
185
+ if (!profileExists(name)) {
186
+ ctx.err(`Profile '${name}' not found.`);
187
+ return 1;
188
+ }
189
+ const fetchFn = ctx.fetchFn ?? fetch;
190
+ // Expired is fine here; a profile that cannot be loaded safely is removed without a server call.
191
+ let profile = null;
192
+ try {
193
+ profile = readProfile(name);
194
+ }
195
+ catch (err) {
196
+ if (!(err instanceof ProfileError))
197
+ throw err;
198
+ ctx.err(`Profile ${name} could not be read (${err.message.replace(/\s*(?:Re-run|Run): [\s\S]*$/, '')}); removing it without signing out on the server.`);
199
+ }
200
+ let finalLine;
201
+ let revokeFailed = false;
202
+ if (profile && !localOnly) {
203
+ const personId = await fetchPersonId(profile.api_url, profile.token, fetchFn);
204
+ const r = await revokeSelf(profile.api_url, profile.token, personId, name, fetchFn, profile.credential_kind);
205
+ if (r.kind === 'revoked')
206
+ finalLine = r.line;
207
+ else {
208
+ ctx.err(r.line);
209
+ finalLine = `Removed profile ${name} from this computer.`;
210
+ // L-14: the local copy is still deleted (S-6), but a failed server revoke leaves a valid token: say so in the exit code.
211
+ if (r.kind === 'failed' || r.kind === 'malformed')
212
+ revokeFailed = true;
213
+ }
214
+ }
215
+ else if (profile) {
216
+ finalLine = `Removed profile ${name} from this computer. Its login was not signed out on the server.`;
217
+ }
218
+ else {
219
+ finalLine = `Removed profile ${name} from this computer.`;
220
+ }
221
+ try {
222
+ if (removeProfile(name).defaultCleared)
223
+ ctx.err('Default profile cleared.');
224
+ }
225
+ catch (err) {
226
+ if (err instanceof ProfileError) {
227
+ ctx.err(err.message);
228
+ return 1;
229
+ }
230
+ throw err;
231
+ }
232
+ ctx.out(finalLine);
233
+ return revokeFailed ? 1 : 0;
234
+ }
235
+ // ─── status ──────────────────────────────────────────────────────────────────
236
+ function credentialLine(r) {
237
+ const s = r.source;
238
+ if (s.level === 0)
239
+ return 'environment (TACIT_TOKEN + TACIT_API_URL + TACIT_WORKSPACE_ID) [level 0]';
240
+ if (s.level === 1)
241
+ return `profile '${s.profile}' (via TACIT_PROFILE) [level 1]`;
242
+ if (s.level === 2)
243
+ return `environment (${r.options.token ? 'TACIT_TOKEN' : 'TACIT_SESSION_TOKEN'}) [level 2]`;
244
+ if (s.level === 4)
245
+ return `profile '${s.profile}' (via default) [level 4]`;
246
+ return 'none';
247
+ }
248
+ export async function runStatus(args, ctx) {
249
+ let offline = false;
250
+ let only;
251
+ for (let i = 0; i < args.length; i++) {
252
+ if (args[i] === '--offline')
253
+ offline = true;
254
+ else if (args[i] === '--name' && args[i + 1] && !args[i + 1].startsWith('--'))
255
+ only = args[++i];
256
+ else {
257
+ ctx.err('Usage: tacit status [--offline] [--name <profile>]');
258
+ return 1;
259
+ }
260
+ }
261
+ if (only !== undefined && !isValidProfileName(only)) {
262
+ ctx.err(`Invalid profile name '${only}'.`);
263
+ return 1;
264
+ }
265
+ const now = (ctx.now ?? Date.now)();
266
+ // `--name p` reports what `tacit p` would start with: the five credential variables are ignored.
267
+ const env = only ? launchEnv(ctx.env, only).env : ctx.env;
268
+ let resolved;
269
+ try {
270
+ resolved = resolveCredentials(env, now);
271
+ }
272
+ catch (err) {
273
+ if (err instanceof CredentialError) {
274
+ ctx.err(err.message);
275
+ return 1;
276
+ }
277
+ throw err;
278
+ }
279
+ if (resolved.source.level === 5) {
280
+ ctx.err(SIGNED_OUT);
281
+ return 1;
282
+ }
283
+ const profile = resolved.profile ?? null;
284
+ const profileName = resolved.source.level === 1 || resolved.source.level === 4 ? resolved.source.profile : '';
285
+ const lines = [['Credential', credentialLine(resolved)]];
286
+ const wsId = profile?.workspace_id ?? resolved.options.workspaceId;
287
+ const wsName = profile?.workspace_name;
288
+ lines.push(['Workspace', wsId ? `${wsName ?? wsId}${wsName ? ` (${wsId})` : ''}` : '(the server decides)']);
289
+ let exit = 0;
290
+ let expiresAt = profile?.expires_at;
291
+ let identity = profile ? `${profile.identity_email ?? '(no email saved)'} (${kindOf(profile)}${profile.device_label ? `, device ${profile.device_label}` : ''}` : '';
292
+ if (!offline) {
293
+ const client = new TacitClient(ctx.fetchFn ?? globalThis.fetch.bind(globalThis), { ...resolved.options, rootDir: ctx.cwd });
294
+ try {
295
+ const check = await verifyIdentity(client, resolved);
296
+ if (check.status === 'verified') {
297
+ const w = check.who;
298
+ lines.push(['Server says', `${printable(w.workspace_name || w.workspace_id)} - ${profile ? 'matches the profile' : 'reported by the server'}`]);
299
+ expiresAt = w.expires_at ?? expiresAt;
300
+ identity = `${printable(w.identity_email ?? profile?.identity_email ?? '(no email)')} (${w.credential_type}${w.device_label ? `, device ${printable(w.device_label)}` : ''}`;
301
+ }
302
+ else if (check.status === 'unsupported') {
303
+ lines.push(['Server says', `this server cannot confirm identity (HTTP ${check.httpStatus}); showing the saved profile`]);
304
+ }
305
+ else {
306
+ lines.push(['Server says', networkError(new URL(resolved.options.apiUrl ?? 'http://localhost').host, check.cause)]);
307
+ }
308
+ }
309
+ catch (err) {
310
+ if (!(err instanceof StartupFault))
311
+ throw err;
312
+ lines.push(['Server says', err.code === 'WORKSPACE_MISMATCH' ? `MISMATCH: ${err.message}` : err.message]);
313
+ exit = 1;
314
+ }
315
+ }
316
+ if (identity)
317
+ lines.push(['Identity', `${identity}${expiresAt ? `, ${expiryText(expiresAt, now)}` : ''})`]);
318
+ lines.push(['API', resolved.options.apiUrl ?? '']);
319
+ const warnings = [...resolved.warnings];
320
+ let folderPick = folderForProfile(profileName, profile, env);
321
+ if ('error' in folderPick) {
322
+ warnings.push(folderPick.error);
323
+ folderPick = folderForProfile(profileName, null, env);
324
+ }
325
+ if ('folder' in folderPick) {
326
+ const mode = loadMode(folderPick.folder);
327
+ const file = tilde(folderPick.folder.configFile);
328
+ lines.push(['Load mode', mode === 'always' ? `always (user entry in ${file})`
329
+ : mode === 'on-demand' ? `on-demand (no user entry in ${file})`
330
+ : `conflict (an older token-bearing entry in ${file}; run: npx @tacitai/mcp-server setup)`]);
331
+ }
332
+ if (profile && profile.credential_kind !== 'iam_token')
333
+ warnings.push(`Profile ${profileName} uses an older login. Run: tacit login`);
334
+ if (expiresAt) {
335
+ const ms = Date.parse(expiresAt);
336
+ if (!Number.isNaN(ms) && ms - now < EXPIRY_WARN_DAYS * DAY_MS)
337
+ warnings.push('This login expires soon. Run: tacit login');
338
+ }
339
+ for (const w of warnings)
340
+ lines.push(['Warnings', w]);
341
+ for (const [k, v] of lines)
342
+ ctx.out(`${k.padEnd(12)} ${v}`);
343
+ return exit;
344
+ }
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * `tacit` — workspace launcher for Claude Code + TACIT. A thin dispatcher (MV-1542c step 1.6):
4
+ * every command lives in its own module and returns an exit code.
5
+ *
6
+ * cli-launch.ts tacit <name> [claude args...], bare tacit (picker)
7
+ * cli-login.ts tacit login
8
+ * cli-profiles.ts tacit ls | use | status | rm
9
+ * cli-mode.ts tacit mode | install
10
+ */
2
11
  export {};