@tacitai/mcp-server 0.7.0 → 0.8.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/dist/api-errors.d.ts +102 -0
- package/dist/api-errors.js +165 -0
- package/dist/autonomy.d.ts +46 -0
- package/dist/autonomy.js +118 -0
- package/dist/claude-config.d.ts +139 -0
- package/dist/claude-config.js +339 -0
- package/dist/cli-launch.d.ts +33 -0
- package/dist/cli-launch.js +178 -0
- package/dist/cli-login.d.ts +34 -0
- package/dist/cli-login.js +200 -0
- package/dist/cli-mode.d.ts +47 -0
- package/dist/cli-mode.js +170 -0
- package/dist/cli-profiles.d.ts +37 -0
- package/dist/cli-profiles.js +344 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +59 -458
- package/dist/client.d.ts +88 -52
- package/dist/client.js +195 -295
- package/dist/credentials.d.ts +81 -0
- package/dist/credentials.js +291 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +37 -89
- package/dist/oauth.d.ts +1 -1
- package/dist/oauth.js +5 -5
- package/dist/profile-store.d.ts +96 -0
- package/dist/profile-store.js +382 -0
- package/dist/prompt.d.ts +32 -0
- package/dist/prompt.js +99 -0
- package/dist/prompts.d.ts +2 -2
- package/dist/prompts.js +3 -3
- package/dist/server-mode.d.ts +65 -0
- package/dist/server-mode.js +99 -0
- package/dist/setup-migrate.d.ts +35 -0
- package/dist/setup-migrate.js +204 -0
- package/dist/setup.d.ts +41 -66
- package/dist/setup.js +361 -531
- package/dist/signin.d.ts +108 -0
- package/dist/signin.js +595 -0
- package/dist/tools/agents.d.ts +4 -4
- package/dist/tools/artifacts.d.ts +2 -0
- package/dist/tools/artifacts.js +8 -1
- package/dist/tools/errors.d.ts +12 -0
- package/dist/tools/errors.js +65 -0
- package/dist/tools/exec-route.d.ts +34 -0
- package/dist/tools/exec-route.js +101 -27
- package/dist/tools/iam.js +2 -3
- package/dist/tools/secretary.d.ts +1 -0
- package/dist/tools/secretary.js +2 -1
- package/dist/tools/synthesize.d.ts +37 -0
- package/dist/tools/synthesize.js +126 -7
- package/dist/tools/voice.d.ts +3 -2
- package/dist/tools/voice.js +70 -18
- package/dist/tools/workspaces.js +7 -4
- package/dist/version.d.ts +6 -0
- package/dist/version.js +18 -0
- package/dist/workflow-registry.d.ts +1 -0
- package/dist/workflow-registry.js +21 -0
- package/package.json +4 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tacit login` (MV-1542c step 1.6, P6.3, S-4).
|
|
3
|
+
*
|
|
4
|
+
* tacit login [--api-url <url>] [--app-url <url>] [--name <profile>] [--no-browser]
|
|
5
|
+
* [--device-label <label>] [--claude-config-dir <abs>] [--revoke-old]
|
|
6
|
+
*
|
|
7
|
+
* Same `signIn` as `setup` (device flow, or email + password). It writes the profile and nothing else: no Claude
|
|
8
|
+
* Code config is touched. Only the user-approved login is stored, in the 0600 profile.
|
|
9
|
+
*
|
|
10
|
+
* Re-login of a profile known up front (`--name p`, or "yes" to the renew prompt when exactly one profile
|
|
11
|
+
* matches the server) sends that profile's `token_id` as `rotate_token_id` on the password path, so the server
|
|
12
|
+
* supersedes exactly that row (and answers 403 TOKEN_NOT_OWNED for a row that is not this identity's).
|
|
13
|
+
* `--revoke-old` then signs the replaced login out at once instead of letting it lapse after its 48 h
|
|
14
|
+
* overlap; it presents the OLD token to its own server's self-revoke route, which revokes only that row.
|
|
15
|
+
*/
|
|
16
|
+
import { tokenNotOwned } from './api-errors.js';
|
|
17
|
+
import { checkConfigDir } from './cli-mode.js';
|
|
18
|
+
import { fetchPersonId, revokeSelf, revokeUnsaved } from './cli-profiles.js';
|
|
19
|
+
import { PromptError } from './prompt.js';
|
|
20
|
+
import { ProfileError, getDefault, getDeviceLabel, isUsableProfileName, listProfiles, pickProfileSlug, setDefault, tryReadProfile, writeProfile, } from './profile-store.js';
|
|
21
|
+
import { deriveAppUrl, defaultIo, UsageError } from './setup.js';
|
|
22
|
+
import { SignInError, signIn } from './signin.js';
|
|
23
|
+
// Same value as setup.ts's private DEFAULT_API_URL.
|
|
24
|
+
const DEFAULT_API_URL = 'https://api-beta.tacitai.app';
|
|
25
|
+
const VALUE_FLAGS = ['--api-url', '--app-url', '--name', '--device-label', '--claude-config-dir'];
|
|
26
|
+
export function parseLoginArgs(argv) {
|
|
27
|
+
const o = { noBrowser: false, revokeOld: false };
|
|
28
|
+
for (let i = 0; i < argv.length; i++) {
|
|
29
|
+
const eq = argv[i].startsWith('--') ? argv[i].indexOf('=') : -1;
|
|
30
|
+
const flag = eq > 0 ? argv[i].slice(0, eq) : argv[i];
|
|
31
|
+
const inline = eq > 0 ? argv[i].slice(eq + 1) : undefined;
|
|
32
|
+
if (flag === '--token')
|
|
33
|
+
throw new UsageError('--token was removed: a token on the command line is visible to other users. Run: tacit login');
|
|
34
|
+
let value;
|
|
35
|
+
if (VALUE_FLAGS.includes(flag)) {
|
|
36
|
+
value = inline ?? argv[++i];
|
|
37
|
+
if (value === undefined || value === '' || (inline === undefined && value.startsWith('--')))
|
|
38
|
+
throw new UsageError(`${flag} requires a value`);
|
|
39
|
+
}
|
|
40
|
+
switch (flag) {
|
|
41
|
+
case '--api-url':
|
|
42
|
+
o.apiUrl = value;
|
|
43
|
+
break;
|
|
44
|
+
case '--app-url':
|
|
45
|
+
o.appUrl = value;
|
|
46
|
+
break;
|
|
47
|
+
case '--name':
|
|
48
|
+
if (!isUsableProfileName(value))
|
|
49
|
+
throw new UsageError(`Invalid profile name '${value}'. Use lowercase letters, digits and hyphens, and not a command word.`);
|
|
50
|
+
o.name = value;
|
|
51
|
+
break;
|
|
52
|
+
case '--device-label':
|
|
53
|
+
if (!/^[A-Za-z0-9 ._-]{1,64}$/.test(value))
|
|
54
|
+
throw new UsageError('--device-label may use letters, digits, space, . _ - (1 to 64 characters)');
|
|
55
|
+
o.deviceLabel = value;
|
|
56
|
+
break;
|
|
57
|
+
case '--claude-config-dir':
|
|
58
|
+
o.claudeConfigDir = value;
|
|
59
|
+
break;
|
|
60
|
+
case '--no-browser':
|
|
61
|
+
o.noBrowser = true;
|
|
62
|
+
break;
|
|
63
|
+
case '--revoke-old':
|
|
64
|
+
o.revokeOld = true;
|
|
65
|
+
break;
|
|
66
|
+
default: throw new UsageError(`Unknown option ${flag}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return o;
|
|
70
|
+
}
|
|
71
|
+
const hostOf = (url) => { try {
|
|
72
|
+
return new URL(url).host.toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return url;
|
|
76
|
+
} };
|
|
77
|
+
/** The profile this login is meant to renew, when that is known before the sign-in starts. */
|
|
78
|
+
async function findKnown(o, apiUrl, io) {
|
|
79
|
+
if (o.name) {
|
|
80
|
+
const data = tryReadProfile(o.name);
|
|
81
|
+
return data && hostOf(data.api_url) === hostOf(apiUrl) ? { name: o.name, data } : null;
|
|
82
|
+
}
|
|
83
|
+
const matches = listProfiles().filter((p) => hostOf(p.data.api_url) === hostOf(apiUrl));
|
|
84
|
+
if (matches.length !== 1 || !io.isTTY)
|
|
85
|
+
return null;
|
|
86
|
+
const { name, data } = matches[0];
|
|
87
|
+
const date = data.expires_at ? ` expires ${data.expires_at.slice(0, 10)}` : '';
|
|
88
|
+
const yes = await io.confirm(`You already have a login for ${data.workspace_name ?? data.workspace_id} (${data.identity_email ?? 'no email saved'},${date}). ` +
|
|
89
|
+
'Sign in again to renew it? (Y/n) ', true);
|
|
90
|
+
return yes ? { name, data } : null;
|
|
91
|
+
}
|
|
92
|
+
/** Returns the exit code. */
|
|
93
|
+
export async function runLogin(argv, ctx) {
|
|
94
|
+
let o;
|
|
95
|
+
let apiUrl;
|
|
96
|
+
try {
|
|
97
|
+
o = parseLoginArgs(argv);
|
|
98
|
+
apiUrl = (o.apiUrl ?? ctx.env['TACIT_API_URL'] ?? DEFAULT_API_URL).trim().replace(/\/+$/, '');
|
|
99
|
+
new URL(apiUrl);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
ctx.err(e instanceof UsageError ? e.message : 'The API URL must be a full http(s) URL.');
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
const appUrl = (o.appUrl ?? deriveAppUrl(apiUrl)).replace(/\/+$/, '');
|
|
106
|
+
let configDir;
|
|
107
|
+
if (o.claudeConfigDir !== undefined) {
|
|
108
|
+
const check = checkConfigDir(o.claudeConfigDir);
|
|
109
|
+
if (!check.ok) {
|
|
110
|
+
ctx.err(`--claude-config-dir ${o.claudeConfigDir} cannot be used: ${check.reason}.`);
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
configDir = check.dir;
|
|
114
|
+
}
|
|
115
|
+
const io = ctx.io ?? defaultIo();
|
|
116
|
+
const fetchFn = ctx.fetchFn ?? fetch;
|
|
117
|
+
// Which saved login does this renew? (decides whether `rotate_token_id` is sent)
|
|
118
|
+
let known;
|
|
119
|
+
try {
|
|
120
|
+
known = await findKnown(o, apiUrl, io);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
ctx.err(e instanceof PromptError ? e.message : 'Cancelled.');
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
let issued;
|
|
127
|
+
try {
|
|
128
|
+
issued = await (ctx.signInFn ?? signIn)({
|
|
129
|
+
apiUrl, appUrl, mode: o.noBrowser ? 'pin' : 'auto', deviceLabel: o.deviceLabel ?? getDeviceLabel(),
|
|
130
|
+
rotateTokenId: known?.data.token_id, io, fetchFn, env: ctx.env,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (e instanceof SignInError) {
|
|
135
|
+
if (e.code === 'TOKEN_NOT_OWNED' && known) {
|
|
136
|
+
ctx.err(tokenNotOwned({ workspace: known.data.workspace_name ?? known.data.workspace_id, name: known.name }));
|
|
137
|
+
}
|
|
138
|
+
else if (!e.reported)
|
|
139
|
+
ctx.err(e.message);
|
|
140
|
+
return e.exitCode;
|
|
141
|
+
}
|
|
142
|
+
ctx.err(e instanceof PromptError || e instanceof ProfileError ? e.message : 'Sign-in failed.');
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
// Profile: the only place the token is stored.
|
|
146
|
+
let profile;
|
|
147
|
+
let replaced;
|
|
148
|
+
try {
|
|
149
|
+
const identity = { api_url: apiUrl, workspace_id: issued.workspaceId, identity_email: issued.identityEmail };
|
|
150
|
+
if (o.name) {
|
|
151
|
+
profile = o.name;
|
|
152
|
+
replaced = tryReadProfile(profile);
|
|
153
|
+
if (replaced && (replaced.api_url !== apiUrl || replaced.workspace_id !== issued.workspaceId
|
|
154
|
+
|| (replaced.identity_email ?? '').toLowerCase() !== issued.identityEmail.toLowerCase())) {
|
|
155
|
+
const left = await revokeUnsaved(apiUrl, issued.token, fetchFn);
|
|
156
|
+
ctx.err(`Profile ${profile} already holds a different login. The login just issued was not saved${left ? ` (it expires ${issued.expiresAt.slice(0, 10)})` : ' and was signed out'}. Choose another --name, or run: tacit rm ${profile}`);
|
|
157
|
+
if (left)
|
|
158
|
+
ctx.err(left);
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
profile = pickProfileSlug(issued.workspaceName, identity).slug;
|
|
164
|
+
replaced = tryReadProfile(profile);
|
|
165
|
+
}
|
|
166
|
+
const keepDir = configDir ?? replaced?.claude_config_dir;
|
|
167
|
+
writeProfile(profile, {
|
|
168
|
+
version: 2, workspace_id: issued.workspaceId, workspace_name: issued.workspaceName, api_url: apiUrl, app_url: appUrl,
|
|
169
|
+
token: issued.token, created_at: new Date().toISOString(), expires_at: issued.expiresAt, identity_email: issued.identityEmail,
|
|
170
|
+
token_id: issued.tokenId, device_label: issued.deviceLabel, credential_kind: 'iam_token',
|
|
171
|
+
...(keepDir ? { claude_config_dir: keepDir } : {}),
|
|
172
|
+
});
|
|
173
|
+
if (getDefault() === null)
|
|
174
|
+
setDefault(profile);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
ctx.err(e instanceof ProfileError ? e.message : 'Could not save the login.');
|
|
178
|
+
const left = await revokeUnsaved(apiUrl, issued.token, fetchFn);
|
|
179
|
+
ctx.err(left ?? 'The login just issued was signed out.');
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
ctx.out(`Saved your login as profile ${profile} (${issued.workspaceName}).`);
|
|
183
|
+
ctx.out(`Launch: tacit ${profile}`);
|
|
184
|
+
if (o.revokeOld) {
|
|
185
|
+
if (!replaced || replaced.token === issued.token) {
|
|
186
|
+
ctx.out('Nothing to sign out: there was no earlier login for this workspace on this computer.');
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const personId = await fetchPersonId(apiUrl, issued.token, fetchFn);
|
|
190
|
+
const r = await revokeSelf(replaced.api_url, replaced.token, personId, `${profile} (earlier login)`, fetchFn, replaced.credential_kind);
|
|
191
|
+
if (r.kind === 'revoked')
|
|
192
|
+
ctx.out(`The earlier ${profile} login was signed out.`);
|
|
193
|
+
else if (r.kind === 'already')
|
|
194
|
+
ctx.out(r.line);
|
|
195
|
+
else
|
|
196
|
+
ctx.err(r.line);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tacit mode` and `tacit install`, plus the Claude config-folder helpers the other `tacit` commands share
|
|
3
|
+
* (MV-1542c step 1.6, P6.1 / P6.2 / P6.5).
|
|
4
|
+
*
|
|
5
|
+
* Load mode is derived from the user-scope `tacit` entry in the active config folder, never stored:
|
|
6
|
+
* generic entry -> always no entry -> on-demand anything else -> conflict (an older,
|
|
7
|
+
* token-bearing entry; `tacit` refuses to guess and points at `setup`).
|
|
8
|
+
*
|
|
9
|
+
* `mode` only drives `claude mcp add-json|remove` through claude-config.ts (execFile, no shell). It never
|
|
10
|
+
* edits `.claude.json` itself and never touches a credential.
|
|
11
|
+
*/
|
|
12
|
+
import { type ConfigFolder } from './claude-config.js';
|
|
13
|
+
import { type ProfileData } from './profile-store.js';
|
|
14
|
+
/** Everything a command reads from the outside world, so tests can fake it. */
|
|
15
|
+
export interface CliContext {
|
|
16
|
+
env: NodeJS.ProcessEnv;
|
|
17
|
+
cwd: string;
|
|
18
|
+
out(line: string): void;
|
|
19
|
+
err(line: string): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function defaultContext(): CliContext;
|
|
22
|
+
export declare const CLAUDE_NOT_FOUND = "Claude Code CLI not found. Install: npm i -g @anthropic-ai/claude-code";
|
|
23
|
+
export declare function tilde(p: string): string;
|
|
24
|
+
/** P6.1 step 5: a user-scope `tacit` entry that is not the generic one. */
|
|
25
|
+
export declare function legacyEntryMessage(folder: ConfigFolder): string;
|
|
26
|
+
export type ConfigDirCheck = {
|
|
27
|
+
ok: true;
|
|
28
|
+
dir: string;
|
|
29
|
+
} | {
|
|
30
|
+
ok: false;
|
|
31
|
+
reason: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* `claude_config_dir` must be absolute, a real directory (not a symlink) whose realpath is under `$HOME`,
|
|
35
|
+
* owned by the user and not group/world-writable. Checked at login and again at every launch; the value is
|
|
36
|
+
* never read from the environment or the server.
|
|
37
|
+
*/
|
|
38
|
+
export declare function checkConfigDir(dir: string): ConfigDirCheck;
|
|
39
|
+
/** The Claude config folder a launch or status uses: the profile's `claude_config_dir`, else the inherited one. */
|
|
40
|
+
export declare function folderForProfile(name: string, profile: ProfileData | null, env: NodeJS.ProcessEnv): {
|
|
41
|
+
folder: ConfigFolder;
|
|
42
|
+
} | {
|
|
43
|
+
error: string;
|
|
44
|
+
};
|
|
45
|
+
export declare function runMode(args: string[], ctx: CliContext): Promise<number>;
|
|
46
|
+
/** Adds the generic token-free `tacit` entry to `./.mcp.json`. A file it cannot parse is left alone. */
|
|
47
|
+
export declare function runInstall(ctx: CliContext): number;
|
package/dist/cli-mode.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tacit mode` and `tacit install`, plus the Claude config-folder helpers the other `tacit` commands share
|
|
3
|
+
* (MV-1542c step 1.6, P6.1 / P6.2 / P6.5).
|
|
4
|
+
*
|
|
5
|
+
* Load mode is derived from the user-scope `tacit` entry in the active config folder, never stored:
|
|
6
|
+
* generic entry -> always no entry -> on-demand anything else -> conflict (an older,
|
|
7
|
+
* token-bearing entry; `tacit` refuses to guess and points at `setup`).
|
|
8
|
+
*
|
|
9
|
+
* `mode` only drives `claude mcp add-json|remove` through claude-config.ts (execFile, no shell). It never
|
|
10
|
+
* edits `.claude.json` itself and never touches a credential.
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import * as os from 'node:os';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import { ENTRY_NAME, GENERIC_ENTRY, PACKAGE_NAME, activeConfigFolder, folderFor, loadMode, registerUserEntry, removeUserEntry, userEntryState, } from './claude-config.js';
|
|
16
|
+
import { getDefault, tryReadProfile } from './profile-store.js';
|
|
17
|
+
export function defaultContext() {
|
|
18
|
+
return {
|
|
19
|
+
env: process.env,
|
|
20
|
+
cwd: process.cwd(),
|
|
21
|
+
out: (l) => { process.stdout.write(l + '\n'); },
|
|
22
|
+
err: (l) => { process.stderr.write(l + '\n'); },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export const CLAUDE_NOT_FOUND = 'Claude Code CLI not found. Install: npm i -g @anthropic-ai/claude-code';
|
|
26
|
+
export function tilde(p) {
|
|
27
|
+
const home = os.homedir();
|
|
28
|
+
return p === home ? '~' : p.startsWith(home + path.sep) ? '~' + p.slice(home.length) : p;
|
|
29
|
+
}
|
|
30
|
+
/** P6.1 step 5: a user-scope `tacit` entry that is not the generic one. */
|
|
31
|
+
export function legacyEntryMessage(folder) {
|
|
32
|
+
return `The "${ENTRY_NAME}" entry in ${folder.configFile} still holds a login token from an older setup. ` +
|
|
33
|
+
`Run: npx ${PACKAGE_NAME} setup`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `claude_config_dir` must be absolute, a real directory (not a symlink) whose realpath is under `$HOME`,
|
|
37
|
+
* owned by the user and not group/world-writable. Checked at login and again at every launch; the value is
|
|
38
|
+
* never read from the environment or the server.
|
|
39
|
+
*/
|
|
40
|
+
export function checkConfigDir(dir) {
|
|
41
|
+
if (!path.isAbsolute(dir))
|
|
42
|
+
return { ok: false, reason: 'it is not an absolute path' };
|
|
43
|
+
let st;
|
|
44
|
+
try {
|
|
45
|
+
st = fs.lstatSync(dir);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return { ok: false, reason: 'it does not exist' };
|
|
49
|
+
}
|
|
50
|
+
if (st.isSymbolicLink())
|
|
51
|
+
return { ok: false, reason: 'it is a symlink' };
|
|
52
|
+
if (!st.isDirectory())
|
|
53
|
+
return { ok: false, reason: 'it is not a directory' };
|
|
54
|
+
let real;
|
|
55
|
+
let home;
|
|
56
|
+
try {
|
|
57
|
+
real = fs.realpathSync(dir);
|
|
58
|
+
home = fs.realpathSync(os.homedir());
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return { ok: false, reason: 'it cannot be resolved' };
|
|
62
|
+
}
|
|
63
|
+
if (real !== home && !real.startsWith(home + path.sep))
|
|
64
|
+
return { ok: false, reason: 'it is outside your home folder' };
|
|
65
|
+
if (process.platform !== 'win32') {
|
|
66
|
+
if (typeof process.getuid === 'function' && st.uid !== process.getuid())
|
|
67
|
+
return { ok: false, reason: 'it is owned by another user' };
|
|
68
|
+
if ((st.mode & 0o022) !== 0)
|
|
69
|
+
return { ok: false, reason: 'it is writable by other users' };
|
|
70
|
+
}
|
|
71
|
+
return { ok: true, dir: real };
|
|
72
|
+
}
|
|
73
|
+
/** The Claude config folder a launch or status uses: the profile's `claude_config_dir`, else the inherited one. */
|
|
74
|
+
export function folderForProfile(name, profile, env) {
|
|
75
|
+
const dir = profile?.claude_config_dir;
|
|
76
|
+
if (!dir)
|
|
77
|
+
return { folder: activeConfigFolder(env) };
|
|
78
|
+
const check = checkConfigDir(dir);
|
|
79
|
+
if (!check.ok) {
|
|
80
|
+
return { error: `Profile ${name} has a claude_config_dir (${dir}) that cannot be used: ${check.reason}. ` +
|
|
81
|
+
`Run: tacit login --name ${name} --claude-config-dir <folder>` };
|
|
82
|
+
}
|
|
83
|
+
return { folder: folderFor(check.dir) };
|
|
84
|
+
}
|
|
85
|
+
// ─── tacit mode ──────────────────────────────────────────────────────────────
|
|
86
|
+
export async function runMode(args, ctx) {
|
|
87
|
+
const want = args[0];
|
|
88
|
+
if (args.length > 1 || (want !== undefined && want !== 'always' && want !== 'on-demand')) {
|
|
89
|
+
ctx.err('Usage: tacit mode [always|on-demand]');
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
// Same resolution as `tacit <name>` / `tacit status`: the default profile's claude_config_dir, else the shell's.
|
|
93
|
+
const defaultName = getDefault();
|
|
94
|
+
const defaultProfile = defaultName ? tryReadProfile(defaultName) : null;
|
|
95
|
+
const where = folderForProfile(defaultName ?? '', defaultProfile, ctx.env);
|
|
96
|
+
if ('error' in where) {
|
|
97
|
+
ctx.err(where.error);
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
const folder = where.folder;
|
|
101
|
+
if (want === undefined) {
|
|
102
|
+
const mode = loadMode(folder);
|
|
103
|
+
if (mode === 'conflict') {
|
|
104
|
+
ctx.err(legacyEntryMessage(folder));
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
ctx.out(mode);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
if (want === 'always') {
|
|
111
|
+
const r = await registerUserEntry(folder, { env: ctx.env });
|
|
112
|
+
switch (r.status) {
|
|
113
|
+
case 'added':
|
|
114
|
+
ctx.out(`TACIT now loads in every Claude Code session (registered in ${tilde(folder.configFile)}).`);
|
|
115
|
+
return 0;
|
|
116
|
+
case 'already':
|
|
117
|
+
ctx.out('TACIT already loads in every Claude Code session.');
|
|
118
|
+
return 0;
|
|
119
|
+
case 'foreign':
|
|
120
|
+
ctx.err(legacyEntryMessage(folder));
|
|
121
|
+
return 1;
|
|
122
|
+
case 'no-claude':
|
|
123
|
+
ctx.err(CLAUDE_NOT_FOUND);
|
|
124
|
+
return 1;
|
|
125
|
+
default:
|
|
126
|
+
ctx.err(`Could not register the TACIT entry (${r.detail ?? 'claude mcp add-json failed'}).`);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const state = userEntryState(folder);
|
|
131
|
+
if (state === 'absent') {
|
|
132
|
+
ctx.out('Already on-demand.');
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
if (state === 'foreign') {
|
|
136
|
+
ctx.err(legacyEntryMessage(folder));
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
const r = await removeUserEntry(folder, { env: ctx.env });
|
|
140
|
+
if (r.status === 'removed' || r.status === 'absent') {
|
|
141
|
+
ctx.out('TACIT now loads only when you start Claude Code with `tacit`.');
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
ctx.err(r.status === 'no-claude' ? CLAUDE_NOT_FOUND : `Could not remove the TACIT entry (${r.detail ?? 'claude mcp remove failed'}).`);
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
// ─── tacit install ───────────────────────────────────────────────────────────
|
|
148
|
+
/** Adds the generic token-free `tacit` entry to `./.mcp.json`. A file it cannot parse is left alone. */
|
|
149
|
+
export function runInstall(ctx) {
|
|
150
|
+
const mcpPath = path.join(ctx.cwd, '.mcp.json');
|
|
151
|
+
let config = {};
|
|
152
|
+
if (fs.existsSync(mcpPath)) {
|
|
153
|
+
try {
|
|
154
|
+
const parsed = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
|
|
155
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
156
|
+
throw new Error('not an object');
|
|
157
|
+
config = parsed;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
ctx.err(`${mcpPath} could not be parsed, so it was left as it is. Fix it, then run: tacit install`);
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const servers = (config['mcpServers'] && typeof config['mcpServers'] === 'object' ? config['mcpServers'] : {});
|
|
165
|
+
servers[ENTRY_NAME] = { ...GENERIC_ENTRY, env: { ...GENERIC_ENTRY.env, TACIT_MCP_FILE_ROOTS: ctx.cwd } };
|
|
166
|
+
config['mcpServers'] = servers;
|
|
167
|
+
fs.writeFileSync(mcpPath, JSON.stringify(config, null, 2) + '\n');
|
|
168
|
+
ctx.out(`Updated ${mcpPath} with the generic '${ENTRY_NAME}' entry (no token).`);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { type CliContext } from './cli-mode.js';
|
|
13
|
+
export interface ProfilesContext extends CliContext {
|
|
14
|
+
fetchFn?: typeof fetch;
|
|
15
|
+
now?: () => number;
|
|
16
|
+
}
|
|
17
|
+
export declare function runLs(ctx: ProfilesContext): number;
|
|
18
|
+
export declare function runUse(args: string[], ctx: ProfilesContext): number;
|
|
19
|
+
export type RevokeKind = 'revoked' | 'already' | 'session' | 'shared' | 'mismatch' | 'malformed' | 'skipped' | 'failed';
|
|
20
|
+
export interface RevokeResult {
|
|
21
|
+
kind: RevokeKind;
|
|
22
|
+
line: string;
|
|
23
|
+
}
|
|
24
|
+
/** Best effort: who does the server say this credential is? null when it can't be confirmed. */
|
|
25
|
+
export declare function fetchPersonId(apiUrl: string, token: string, fetchFn: typeof fetch): Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Present `token` to its own server's self-revoke route. Only the presented row is revoked. `personId`
|
|
28
|
+
* (when known) makes the server refuse a shared or foreign row instead of revoking it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function revokeSelf(apiUrl: string, token: string, personId: string | null, name: string, fetchFn: typeof fetch, credentialKind?: 'iam_token' | 'dev_token'): Promise<RevokeResult>;
|
|
31
|
+
/**
|
|
32
|
+
* L-13: a token was just issued but could not be saved, so nothing holds it. Sign it out so it does
|
|
33
|
+
* not sit live for 90 days. Returns the line to show when the revoke itself failed, else null.
|
|
34
|
+
*/
|
|
35
|
+
export declare function revokeUnsaved(apiUrl: string, token: string, fetchFn: typeof fetch): Promise<string | null>;
|
|
36
|
+
export declare function runRm(args: string[], ctx: ProfilesContext): Promise<number>;
|
|
37
|
+
export declare function runStatus(args: string[], ctx: ProfilesContext): Promise<number>;
|