@tacitai/mcp-server 0.6.40 → 0.6.42
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/cli.d.ts +2 -0
- package/dist/cli.js +454 -0
- package/dist/client.d.ts +22 -4
- package/dist/client.js +119 -18
- package/dist/index.js +17 -3
- package/dist/prompts.d.ts +4 -4
- package/dist/prompts.js +4 -4
- package/dist/setup.d.ts +31 -0
- package/dist/setup.js +21 -5
- package/dist/tools/agents.d.ts +2 -2
- package/dist/tools/artifacts.d.ts +2 -2
- package/dist/tools/drafts.d.ts +2 -2
- package/package.json +4 -2
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
import * as readline from 'readline';
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import { deviceAuthFlow, deriveAppUrl, workspaceNameToProfile } from './setup.js';
|
|
8
|
+
const PROFILES_DIR = path.join(os.homedir(), '.tacit', 'profiles');
|
|
9
|
+
const DEFAULT_FILE = path.join(os.homedir(), '.tacit', 'default');
|
|
10
|
+
const PROFILE_REGEX = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
11
|
+
const RESERVED_NAMES = new Set(['login', 'ls', 'use', 'rm', 'status', 'install', 'help', 'setup', 'version']);
|
|
12
|
+
const DEFAULT_API_URL = 'https://api-beta.tacitai.app';
|
|
13
|
+
function listV2Profiles() {
|
|
14
|
+
if (!fs.existsSync(PROFILES_DIR))
|
|
15
|
+
return [];
|
|
16
|
+
const files = fs.readdirSync(PROFILES_DIR).filter(f => f.endsWith('.json'));
|
|
17
|
+
const profiles = [];
|
|
18
|
+
for (const f of files) {
|
|
19
|
+
try {
|
|
20
|
+
const data = JSON.parse(fs.readFileSync(path.join(PROFILES_DIR, f), 'utf-8'));
|
|
21
|
+
if (data.version === 2) {
|
|
22
|
+
profiles.push({ name: f.replace(/\.json$/, ''), data: data });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch { /* skip corrupt */ }
|
|
26
|
+
}
|
|
27
|
+
return profiles;
|
|
28
|
+
}
|
|
29
|
+
function getDefault() {
|
|
30
|
+
if (!fs.existsSync(DEFAULT_FILE))
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const name = fs.readFileSync(DEFAULT_FILE, 'utf-8').trim();
|
|
34
|
+
return name || null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function setDefault(name) {
|
|
41
|
+
const dir = path.dirname(DEFAULT_FILE);
|
|
42
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
43
|
+
const tmp = DEFAULT_FILE + '.tmp';
|
|
44
|
+
fs.writeFileSync(tmp, name + '\n', { mode: 0o600 });
|
|
45
|
+
fs.renameSync(tmp, DEFAULT_FILE);
|
|
46
|
+
}
|
|
47
|
+
function loadProfile(name) {
|
|
48
|
+
if (!PROFILE_REGEX.test(name)) {
|
|
49
|
+
process.stderr.write(`Invalid profile name '${name}'. Names must match: ${PROFILE_REGEX}\n`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const filePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
53
|
+
if (!fs.existsSync(filePath)) {
|
|
54
|
+
process.stderr.write(`Profile '${name}' not found. Run: npx -p @tacitai/mcp-server tacit ls\n`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
let data;
|
|
58
|
+
try {
|
|
59
|
+
data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
process.stderr.write(`Profile '${name}' is corrupted: ${err instanceof Error ? err.message : ''}. Re-run: tacit login\n`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (data.version !== 2) {
|
|
66
|
+
process.stderr.write(`Profile '${name}' was created by setup and lacks credentials. Re-run: npx -p @tacitai/mcp-server tacit login\n`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
function writeProfile(name, data) {
|
|
72
|
+
fs.mkdirSync(PROFILES_DIR, { recursive: true, mode: 0o700 });
|
|
73
|
+
try {
|
|
74
|
+
fs.chmodSync(PROFILES_DIR, 0o700);
|
|
75
|
+
}
|
|
76
|
+
catch { /* unsupported OS */ }
|
|
77
|
+
const filePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
78
|
+
const tmp = filePath + '.tmp';
|
|
79
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 });
|
|
80
|
+
fs.renameSync(tmp, filePath);
|
|
81
|
+
}
|
|
82
|
+
function validateProfileName(name) {
|
|
83
|
+
return PROFILE_REGEX.test(name) && !RESERVED_NAMES.has(name);
|
|
84
|
+
}
|
|
85
|
+
function promptLine(question) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
88
|
+
rl.question(question, (answer) => { rl.close(); resolve(answer.trim()); });
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function tryLoadProfile(name) {
|
|
92
|
+
if (!PROFILE_REGEX.test(name))
|
|
93
|
+
return null;
|
|
94
|
+
const filePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
95
|
+
try {
|
|
96
|
+
if (!fs.existsSync(filePath))
|
|
97
|
+
return null;
|
|
98
|
+
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
99
|
+
if (data.version !== 2)
|
|
100
|
+
return null;
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ─── Subcommands ─────────────────────────────────────────────────────────────
|
|
108
|
+
async function cmdLaunch(name, extraArgs) {
|
|
109
|
+
const profile = loadProfile(name);
|
|
110
|
+
if (profile.expires_at) {
|
|
111
|
+
const expiresMs = Date.parse(profile.expires_at);
|
|
112
|
+
if (!Number.isNaN(expiresMs) && Date.now() > expiresMs) {
|
|
113
|
+
process.stderr.write(`Profile '${name}' token expired ${profile.expires_at}. Re-run: tacit login\n`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
const daysLeft = Math.floor((expiresMs - Date.now()) / 86400000);
|
|
117
|
+
if (daysLeft < 14) {
|
|
118
|
+
process.stderr.write(`[TACIT] Token expires in ${daysLeft} day${daysLeft === 1 ? '' : 's'}.\n`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const child = spawn('claude', extraArgs, {
|
|
122
|
+
stdio: 'inherit',
|
|
123
|
+
env: { ...process.env, TACIT_PROFILE: name },
|
|
124
|
+
});
|
|
125
|
+
const ignore = () => { };
|
|
126
|
+
process.on('SIGINT', ignore);
|
|
127
|
+
process.on('SIGTERM', ignore);
|
|
128
|
+
child.on('error', (err) => {
|
|
129
|
+
if (err.code === 'ENOENT') {
|
|
130
|
+
process.stderr.write('Claude Code CLI not found. Install: npm i -g @anthropic-ai/claude-code\n');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
process.stderr.write(`Failed to launch claude: ${err.message}\n`);
|
|
134
|
+
}
|
|
135
|
+
process.exit(1);
|
|
136
|
+
});
|
|
137
|
+
child.on('exit', (code) => {
|
|
138
|
+
process.exit(code ?? 0);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async function cmdLogin(args) {
|
|
142
|
+
let apiUrl = DEFAULT_API_URL;
|
|
143
|
+
let nameOverride = null;
|
|
144
|
+
for (let i = 0; i < args.length; i++) {
|
|
145
|
+
if (args[i] === '--api-url' && args[i + 1]) {
|
|
146
|
+
apiUrl = args[++i];
|
|
147
|
+
}
|
|
148
|
+
else if (args[i] === '--name' && args[i + 1]) {
|
|
149
|
+
nameOverride = args[++i];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = await deviceAuthFlow(apiUrl);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
158
|
+
if (msg.includes('timed out')) {
|
|
159
|
+
process.stderr.write('Authentication timed out (120s). Try again or check browser.\n');
|
|
160
|
+
}
|
|
161
|
+
else if (msg.includes('state mismatch')) {
|
|
162
|
+
process.stderr.write('Authentication failed: state mismatch. Try again.\n');
|
|
163
|
+
}
|
|
164
|
+
else if (msg.includes('EADDRINUSE')) {
|
|
165
|
+
process.stderr.write('Port 9123 busy (another login running?). Try again.\n');
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
process.stderr.write(`Authentication failed: ${msg}\n`);
|
|
169
|
+
}
|
|
170
|
+
process.exit(1);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let workspaceId;
|
|
174
|
+
let displayName = result.workspaceName;
|
|
175
|
+
try {
|
|
176
|
+
const resp = await fetch(`${apiUrl}/api/v1/workspaces/mine`, {
|
|
177
|
+
headers: { 'Authorization': `Bearer ${result.token}`, 'Accept': 'application/json' },
|
|
178
|
+
});
|
|
179
|
+
if (resp.status === 401) {
|
|
180
|
+
process.stderr.write('Token lacks required claims. The TACIT server may need updating.\n');
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
if (!resp.ok) {
|
|
184
|
+
throw new Error(`HTTP ${resp.status}`);
|
|
185
|
+
}
|
|
186
|
+
const data = await resp.json();
|
|
187
|
+
workspaceId = data.active_workspace_id;
|
|
188
|
+
if (!workspaceId)
|
|
189
|
+
throw new Error('No active_workspace_id in response');
|
|
190
|
+
if (Array.isArray(data.workspaces)) {
|
|
191
|
+
const match = data.workspaces.find(w => w.workspace_id === workspaceId || w.id === workspaceId);
|
|
192
|
+
if (match) {
|
|
193
|
+
const n = match.display_name ?? match.name;
|
|
194
|
+
if (typeof n === 'string')
|
|
195
|
+
displayName = n;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
process.stderr.write(`Failed to resolve workspace: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let profileName;
|
|
205
|
+
if (nameOverride) {
|
|
206
|
+
profileName = nameOverride;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
profileName = workspaceNameToProfile(displayName);
|
|
210
|
+
}
|
|
211
|
+
if (!validateProfileName(profileName)) {
|
|
212
|
+
process.stderr.write(`Derived name '${profileName}' is invalid or reserved.\n`);
|
|
213
|
+
if (process.stdin.isTTY) {
|
|
214
|
+
profileName = await promptLine('Profile name: ');
|
|
215
|
+
if (!validateProfileName(profileName)) {
|
|
216
|
+
process.stderr.write('Invalid profile name.\n');
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const existingPath = path.join(PROFILES_DIR, `${profileName}.json`);
|
|
225
|
+
if (fs.existsSync(existingPath)) {
|
|
226
|
+
if (process.stdin.isTTY) {
|
|
227
|
+
const answer = await promptLine(`Profile '${profileName}' exists. Overwrite? [y/N] `);
|
|
228
|
+
if (answer.toLowerCase() !== 'y') {
|
|
229
|
+
process.stderr.write('Aborted.\n');
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
process.stderr.write(`Profile '${profileName}' already exists. Use --name to specify a different name.\n`);
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const appUrl = deriveAppUrl(apiUrl);
|
|
239
|
+
writeProfile(profileName, {
|
|
240
|
+
version: 2,
|
|
241
|
+
workspace_id: workspaceId,
|
|
242
|
+
workspace_name: displayName,
|
|
243
|
+
api_url: apiUrl,
|
|
244
|
+
app_url: appUrl,
|
|
245
|
+
token: result.token,
|
|
246
|
+
created_at: new Date().toISOString(),
|
|
247
|
+
expires_at: result.expiresAt,
|
|
248
|
+
});
|
|
249
|
+
if (!getDefault()) {
|
|
250
|
+
setDefault(profileName);
|
|
251
|
+
}
|
|
252
|
+
process.stdout.write(`\n Profile '${profileName}' created (${displayName}).\n`);
|
|
253
|
+
process.stdout.write(` Launch: tacit ${profileName}\n\n`);
|
|
254
|
+
}
|
|
255
|
+
function cmdLs() {
|
|
256
|
+
const profiles = listV2Profiles();
|
|
257
|
+
if (profiles.length === 0) {
|
|
258
|
+
process.stdout.write('No profiles. Run: npx -p @tacitai/mcp-server tacit login\n');
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const defaultName = getDefault();
|
|
262
|
+
for (const p of profiles) {
|
|
263
|
+
const marker = p.name === defaultName ? ' (default)' : '';
|
|
264
|
+
const wsName = p.data.workspace_name ?? '';
|
|
265
|
+
process.stdout.write(` ${p.name}${marker} — ${wsName} (${p.data.api_url})\n`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function cmdUse(name) {
|
|
269
|
+
if (!name) {
|
|
270
|
+
process.stderr.write('Usage: tacit use <name>\n');
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
loadProfile(name);
|
|
274
|
+
setDefault(name);
|
|
275
|
+
process.stdout.write(`Default profile set to '${name}'.\n`);
|
|
276
|
+
}
|
|
277
|
+
function cmdRm(name) {
|
|
278
|
+
if (!name) {
|
|
279
|
+
process.stderr.write('Usage: tacit rm <name>\n');
|
|
280
|
+
process.exit(1);
|
|
281
|
+
}
|
|
282
|
+
if (!PROFILE_REGEX.test(name)) {
|
|
283
|
+
process.stderr.write(`Invalid profile name '${name}'.\n`);
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
const filePath = path.join(PROFILES_DIR, `${name}.json`);
|
|
287
|
+
if (!fs.existsSync(filePath)) {
|
|
288
|
+
process.stderr.write(`Profile '${name}' not found.\n`);
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
fs.unlinkSync(filePath);
|
|
292
|
+
const defaultName = getDefault();
|
|
293
|
+
if (defaultName === name) {
|
|
294
|
+
try {
|
|
295
|
+
fs.unlinkSync(DEFAULT_FILE);
|
|
296
|
+
}
|
|
297
|
+
catch { /* ok */ }
|
|
298
|
+
process.stderr.write('Default profile cleared.\n');
|
|
299
|
+
}
|
|
300
|
+
process.stdout.write(`Profile '${name}' removed.\n`);
|
|
301
|
+
}
|
|
302
|
+
function cmdStatus() {
|
|
303
|
+
const profileEnv = process.env['TACIT_PROFILE']?.trim();
|
|
304
|
+
const wsId = process.env['TACIT_WORKSPACE_ID']?.trim();
|
|
305
|
+
const token = process.env['TACIT_TOKEN']?.trim();
|
|
306
|
+
const apiUrl = process.env['TACIT_API_URL']?.trim();
|
|
307
|
+
const defaultName = getDefault();
|
|
308
|
+
process.stdout.write('Resolution chain:\n');
|
|
309
|
+
process.stdout.write(` 1. TACIT_PROFILE: ${profileEnv || '(unset)'}\n`);
|
|
310
|
+
process.stdout.write(` 2. TACIT_WORKSPACE_ID: ${wsId || '(unset)'}\n`);
|
|
311
|
+
process.stdout.write(` TACIT_TOKEN: ${token ? '(set)' : '(unset)'}\n`);
|
|
312
|
+
process.stdout.write(` TACIT_API_URL: ${apiUrl || '(unset)'}\n`);
|
|
313
|
+
process.stdout.write(` 3. sync.json: ${fs.existsSync('.tacit/sync.json') ? '(present)' : '(absent)'}\n`);
|
|
314
|
+
process.stdout.write(` 4. Default profile: ${defaultName || '(unset)'}\n`);
|
|
315
|
+
if (profileEnv) {
|
|
316
|
+
try {
|
|
317
|
+
const p = tryLoadProfile(profileEnv);
|
|
318
|
+
if (p) {
|
|
319
|
+
process.stdout.write(`\nResolved via TACIT_PROFILE → ${profileEnv}\n`);
|
|
320
|
+
process.stdout.write(` Workspace: ${p.workspace_name ?? p.workspace_id}\n`);
|
|
321
|
+
process.stdout.write(` API: ${p.api_url}\n`);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
process.stdout.write(`\nTACIT_PROFILE='${profileEnv}' set but profile not loadable.\n`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch { /* shown in chain */ }
|
|
328
|
+
}
|
|
329
|
+
else if (wsId && token) {
|
|
330
|
+
process.stdout.write('\nResolved via env vars (TACIT_WORKSPACE_ID + TACIT_TOKEN)\n');
|
|
331
|
+
}
|
|
332
|
+
else if (defaultName) {
|
|
333
|
+
const p = tryLoadProfile(defaultName);
|
|
334
|
+
if (p) {
|
|
335
|
+
process.stdout.write(`\nResolved via default profile → ${defaultName}\n`);
|
|
336
|
+
process.stdout.write(` Workspace: ${p.workspace_name ?? p.workspace_id}\n`);
|
|
337
|
+
process.stdout.write(` API: ${p.api_url}\n`);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
process.stdout.write(`\nDefault profile '${defaultName}' not loadable.\n`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
process.stdout.write('\nNo workspace configured. Run: npx -p @tacitai/mcp-server tacit login\n');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function cmdInstall() {
|
|
348
|
+
const mcpPath = path.join(process.cwd(), '.mcp.json');
|
|
349
|
+
let config = {};
|
|
350
|
+
if (fs.existsSync(mcpPath)) {
|
|
351
|
+
try {
|
|
352
|
+
config = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
process.stderr.write('Warning: .mcp.json could not be parsed. Creating new.\n');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const servers = (config.mcpServers ?? {});
|
|
359
|
+
servers['tacit'] = {
|
|
360
|
+
type: 'stdio',
|
|
361
|
+
command: 'npx',
|
|
362
|
+
args: ['-y', '@tacitai/mcp-server'],
|
|
363
|
+
env: {
|
|
364
|
+
TACIT_PROFILE: '${TACIT_PROFILE:-}',
|
|
365
|
+
TACIT_MCP_FILE_ROOTS: process.cwd(),
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
config.mcpServers = servers;
|
|
369
|
+
fs.writeFileSync(mcpPath, JSON.stringify(config, null, 2) + '\n');
|
|
370
|
+
process.stdout.write(`Updated ${mcpPath} with generic 'tacit' entry.\n`);
|
|
371
|
+
}
|
|
372
|
+
async function cmdPicker() {
|
|
373
|
+
if (!process.stdin.isTTY) {
|
|
374
|
+
process.stderr.write('Usage: tacit <profile-name> | tacit login | tacit ls\n');
|
|
375
|
+
process.exit(1);
|
|
376
|
+
}
|
|
377
|
+
const profiles = listV2Profiles();
|
|
378
|
+
if (profiles.length === 0) {
|
|
379
|
+
process.stderr.write('No profiles configured. Run: npx -p @tacitai/mcp-server tacit login\n');
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
const defaultName = getDefault();
|
|
383
|
+
process.stdout.write('\nWorkspaces:\n');
|
|
384
|
+
for (let i = 0; i < profiles.length; i++) {
|
|
385
|
+
const p = profiles[i];
|
|
386
|
+
const marker = p.name === defaultName ? ' *' : '';
|
|
387
|
+
process.stdout.write(` ${i + 1}. ${p.data.workspace_name ?? p.name}${marker} (${p.name})\n`);
|
|
388
|
+
}
|
|
389
|
+
const choice = await promptLine('\nSelect [1]: ');
|
|
390
|
+
const idx = (choice ? parseInt(choice, 10) : 1) - 1;
|
|
391
|
+
if (idx < 0 || idx >= profiles.length || Number.isNaN(idx)) {
|
|
392
|
+
process.stderr.write('Invalid selection.\n');
|
|
393
|
+
process.exit(1);
|
|
394
|
+
}
|
|
395
|
+
await cmdLaunch(profiles[idx].name, []);
|
|
396
|
+
}
|
|
397
|
+
// ─── Main ────────────────────────────────────────────────────────────────────
|
|
398
|
+
async function main() {
|
|
399
|
+
const args = process.argv.slice(2);
|
|
400
|
+
const cmd = args[0] ?? '';
|
|
401
|
+
switch (cmd) {
|
|
402
|
+
case 'login':
|
|
403
|
+
await cmdLogin(args.slice(1));
|
|
404
|
+
break;
|
|
405
|
+
case 'ls':
|
|
406
|
+
cmdLs();
|
|
407
|
+
break;
|
|
408
|
+
case 'use':
|
|
409
|
+
cmdUse(args[1]);
|
|
410
|
+
break;
|
|
411
|
+
case 'rm':
|
|
412
|
+
cmdRm(args[1]);
|
|
413
|
+
break;
|
|
414
|
+
case 'status':
|
|
415
|
+
cmdStatus();
|
|
416
|
+
break;
|
|
417
|
+
case 'install':
|
|
418
|
+
cmdInstall();
|
|
419
|
+
break;
|
|
420
|
+
case 'help':
|
|
421
|
+
case '--help':
|
|
422
|
+
case '-h':
|
|
423
|
+
process.stdout.write([
|
|
424
|
+
'tacit — workspace launcher for Claude Code + TACIT',
|
|
425
|
+
'',
|
|
426
|
+
'Commands:',
|
|
427
|
+
' tacit Interactive workspace picker',
|
|
428
|
+
' tacit <name> Launch Claude Code connected to <name>',
|
|
429
|
+
' tacit login Authenticate and create a profile',
|
|
430
|
+
' tacit ls List workspace profiles',
|
|
431
|
+
' tacit use <name> Set the default profile',
|
|
432
|
+
' tacit rm <name> Remove a profile',
|
|
433
|
+
' tacit status Show connection info',
|
|
434
|
+
' tacit install Add generic entry to .mcp.json',
|
|
435
|
+
'',
|
|
436
|
+
].join('\n'));
|
|
437
|
+
break;
|
|
438
|
+
case '':
|
|
439
|
+
await cmdPicker();
|
|
440
|
+
break;
|
|
441
|
+
default:
|
|
442
|
+
if (!cmd.startsWith('-')) {
|
|
443
|
+
await cmdLaunch(cmd, args.slice(1));
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
process.stderr.write(`Unknown command: ${cmd}\nRun: tacit help\n`);
|
|
447
|
+
process.exit(1);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
main().catch((err) => {
|
|
452
|
+
process.stderr.write(`tacit: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
453
|
+
process.exit(1);
|
|
454
|
+
});
|
package/dist/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - TACIT_TOKEN is NEVER written to any output stream (stdout, stderr, logs).
|
|
6
6
|
* - The Authorization header value is NEVER logged at any level.
|
|
7
7
|
* - No anthropic/openai SDK import.
|
|
8
|
-
* - Token sourced
|
|
8
|
+
* - Token sourced from process.env.TACIT_TOKEN or v2 profile files (~/.tacit/profiles/).
|
|
9
9
|
*/
|
|
10
10
|
export interface TacitClientOptions {
|
|
11
11
|
apiUrl?: string;
|
|
@@ -41,9 +41,10 @@ export declare class TacitClient {
|
|
|
41
41
|
}>;
|
|
42
42
|
/**
|
|
43
43
|
* Resolve the workspace ID:
|
|
44
|
-
* 1.
|
|
45
|
-
* 2.
|
|
46
|
-
* 3.
|
|
44
|
+
* 1. Return this._workspaceId if already set (from constructor opts/profile).
|
|
45
|
+
* 2. TACIT_WORKSPACE_ID env var (BUG-369: takes priority over sync.json).
|
|
46
|
+
* 3. Fall back to <rootDir>/.tacit/sync.json.
|
|
47
|
+
* 4. Return null if no source is available.
|
|
47
48
|
*/
|
|
48
49
|
resolveWorkspaceId(): Promise<string | null>;
|
|
49
50
|
/**
|
|
@@ -109,6 +110,23 @@ export declare class TokenExpiredError extends Error {
|
|
|
109
110
|
readonly setupCommand: string;
|
|
110
111
|
constructor(renewalUrl: string, setupCommand: string);
|
|
111
112
|
}
|
|
113
|
+
export interface ProfileData {
|
|
114
|
+
version: number;
|
|
115
|
+
workspace_id: string;
|
|
116
|
+
workspace_name?: string;
|
|
117
|
+
api_url: string;
|
|
118
|
+
app_url?: string;
|
|
119
|
+
token: string;
|
|
120
|
+
created_at?: string;
|
|
121
|
+
expires_at?: string;
|
|
122
|
+
}
|
|
123
|
+
export declare function loadProfile(name: string): ProfileData;
|
|
124
|
+
/**
|
|
125
|
+
* 5-level resolution chain (FEAT-255 §2.1). Empty-string-as-unset rule applies.
|
|
126
|
+
* Returns TacitClientOptions from the first matching level.
|
|
127
|
+
* Throws on set-but-invalid states (profile missing, WORKSPACE_ID without TOKEN).
|
|
128
|
+
*/
|
|
129
|
+
export declare function resolveProfileOptions(): TacitClientOptions;
|
|
112
130
|
/** HTTPS mode: bind the caller's token/apiUrl/principal to everything run inside fn. */
|
|
113
131
|
export declare function runWithRequestContext<T>(token: string, apiUrl: string, fn: () => Promise<T>, principal?: string): Promise<T>;
|
|
114
132
|
export declare function getRequestPrincipal(): string | null;
|
package/dist/client.js
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* - TACIT_TOKEN is NEVER written to any output stream (stdout, stderr, logs).
|
|
6
6
|
* - The Authorization header value is NEVER logged at any level.
|
|
7
7
|
* - No anthropic/openai SDK import.
|
|
8
|
-
* - Token sourced
|
|
8
|
+
* - Token sourced from process.env.TACIT_TOKEN or v2 profile files (~/.tacit/profiles/).
|
|
9
9
|
*/
|
|
10
10
|
import * as fs from 'fs';
|
|
11
11
|
import * as path from 'path';
|
|
12
|
+
import * as os from 'os';
|
|
12
13
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
13
14
|
function isHmacSessionToken(token) {
|
|
14
15
|
const parts = token.split('.');
|
|
@@ -46,20 +47,21 @@ export class TacitClient {
|
|
|
46
47
|
// Token from env only — NEVER log this value.
|
|
47
48
|
this.token = resolvedOpts.token ?? process.env['TACIT_TOKEN'] ?? '';
|
|
48
49
|
this._rootDir = resolvedOpts.rootDir ?? process.cwd();
|
|
49
|
-
// MV-1057e: read workspace_id from .tacit/sync.json if present.
|
|
50
|
-
// Whichever mission (1057c or 1057e) lands second wires the full schema.
|
|
51
50
|
let resolvedWorkspaceId = resolvedOpts.workspaceId ?? process.env['TACIT_WORKSPACE_ID'] ?? '';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
|
|
51
|
+
// BUG-369: sync.json is a FALLBACK, not an override. Only use when opts/env didn't provide a value.
|
|
52
|
+
if (!resolvedWorkspaceId) {
|
|
53
|
+
try {
|
|
54
|
+
const syncPath = path.join(this._rootDir, '.tacit', 'sync.json');
|
|
55
|
+
if (fs.existsSync(syncPath)) {
|
|
56
|
+
const sync = JSON.parse(fs.readFileSync(syncPath, 'utf-8'));
|
|
57
|
+
if (typeof sync['workspace_id'] === 'string' && sync['workspace_id']) {
|
|
58
|
+
resolvedWorkspaceId = sync['workspace_id'];
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
catch {
|
|
63
|
+
// Soft-coupled: ignore read errors.
|
|
64
|
+
}
|
|
63
65
|
}
|
|
64
66
|
this._workspaceId = resolvedWorkspaceId;
|
|
65
67
|
}
|
|
@@ -121,11 +123,18 @@ export class TacitClient {
|
|
|
121
123
|
}
|
|
122
124
|
/**
|
|
123
125
|
* Resolve the workspace ID:
|
|
124
|
-
* 1.
|
|
125
|
-
* 2.
|
|
126
|
-
* 3.
|
|
126
|
+
* 1. Return this._workspaceId if already set (from constructor opts/profile).
|
|
127
|
+
* 2. TACIT_WORKSPACE_ID env var (BUG-369: takes priority over sync.json).
|
|
128
|
+
* 3. Fall back to <rootDir>/.tacit/sync.json.
|
|
129
|
+
* 4. Return null if no source is available.
|
|
127
130
|
*/
|
|
128
131
|
async resolveWorkspaceId() {
|
|
132
|
+
if (this._workspaceId)
|
|
133
|
+
return this._workspaceId;
|
|
134
|
+
// BUG-369: env takes precedence over sync.json
|
|
135
|
+
const envId = process.env['TACIT_WORKSPACE_ID'];
|
|
136
|
+
if (envId && envId.length > 0)
|
|
137
|
+
return envId;
|
|
129
138
|
try {
|
|
130
139
|
const syncPath = path.join(this._rootDir, '.tacit', 'sync.json');
|
|
131
140
|
if (fs.existsSync(syncPath)) {
|
|
@@ -136,10 +145,9 @@ export class TacitClient {
|
|
|
136
145
|
}
|
|
137
146
|
}
|
|
138
147
|
catch {
|
|
139
|
-
// Soft-coupled: ignore read errors
|
|
148
|
+
// Soft-coupled: ignore read errors.
|
|
140
149
|
}
|
|
141
|
-
|
|
142
|
-
return (envId && envId.length > 0) ? envId : null;
|
|
150
|
+
return null;
|
|
143
151
|
}
|
|
144
152
|
/**
|
|
145
153
|
* Build a user-facing URL for an entity in the TACIT web app.
|
|
@@ -426,6 +434,99 @@ export class TokenExpiredError extends Error {
|
|
|
426
434
|
this.name = 'TokenExpiredError';
|
|
427
435
|
}
|
|
428
436
|
}
|
|
437
|
+
function isNonEmpty(val) {
|
|
438
|
+
return typeof val === 'string' && val.trim().length > 0;
|
|
439
|
+
}
|
|
440
|
+
const PROFILE_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
441
|
+
export function loadProfile(name) {
|
|
442
|
+
if (!PROFILE_NAME_RE.test(name)) {
|
|
443
|
+
throw new Error(`Invalid profile name '${name}'. Names must match: ${PROFILE_NAME_RE}`);
|
|
444
|
+
}
|
|
445
|
+
const profilePath = path.join(os.homedir(), '.tacit', 'profiles', `${name}.json`);
|
|
446
|
+
if (!fs.existsSync(profilePath)) {
|
|
447
|
+
throw new Error(`Profile '${name}' not found at ${profilePath}`);
|
|
448
|
+
}
|
|
449
|
+
let data;
|
|
450
|
+
try {
|
|
451
|
+
data = JSON.parse(fs.readFileSync(profilePath, 'utf-8'));
|
|
452
|
+
}
|
|
453
|
+
catch (err) {
|
|
454
|
+
throw new Error(`Profile '${name}' is corrupted: ${err instanceof Error ? err.message : String(err)}. Re-run: tacit login`);
|
|
455
|
+
}
|
|
456
|
+
if (data.version !== 2) {
|
|
457
|
+
throw new Error(`Profile '${name}' was created by setup and lacks credentials. Re-run: npx -p @tacitai/mcp-server tacit login`);
|
|
458
|
+
}
|
|
459
|
+
if (typeof data.workspace_id !== 'string' || !data.workspace_id ||
|
|
460
|
+
typeof data.token !== 'string' || !data.token ||
|
|
461
|
+
typeof data.api_url !== 'string' || !data.api_url) {
|
|
462
|
+
throw new Error(`Profile '${name}' is missing required fields (workspace_id, token, api_url). Re-run: tacit login`);
|
|
463
|
+
}
|
|
464
|
+
if (typeof data.expires_at === 'string') {
|
|
465
|
+
const expiresMs = Date.parse(data.expires_at);
|
|
466
|
+
if (!Number.isNaN(expiresMs) && Date.now() > expiresMs) {
|
|
467
|
+
process.stderr.write(`[TACIT] Warning: profile '${name}' token expired ${data.expires_at}. Re-run: tacit login\n`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return data;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* 5-level resolution chain (FEAT-255 §2.1). Empty-string-as-unset rule applies.
|
|
474
|
+
* Returns TacitClientOptions from the first matching level.
|
|
475
|
+
* Throws on set-but-invalid states (profile missing, WORKSPACE_ID without TOKEN).
|
|
476
|
+
*/
|
|
477
|
+
export function resolveProfileOptions() {
|
|
478
|
+
// Level 1: TACIT_PROFILE env → load profile
|
|
479
|
+
const profileName = process.env['TACIT_PROFILE'];
|
|
480
|
+
if (isNonEmpty(profileName)) {
|
|
481
|
+
const profile = loadProfile(profileName);
|
|
482
|
+
return {
|
|
483
|
+
apiUrl: isNonEmpty(process.env['TACIT_API_URL']) ? process.env['TACIT_API_URL'].trim() : profile.api_url,
|
|
484
|
+
appUrl: isNonEmpty(process.env['TACIT_APP_URL']) ? process.env['TACIT_APP_URL'].trim() : profile.app_url,
|
|
485
|
+
token: profile.token,
|
|
486
|
+
workspaceId: profile.workspace_id,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
// Level 2: explicit env vars (backward compat)
|
|
490
|
+
if (isNonEmpty(process.env['TACIT_WORKSPACE_ID'])) {
|
|
491
|
+
if (!isNonEmpty(process.env['TACIT_TOKEN'])) {
|
|
492
|
+
throw new Error('TACIT_WORKSPACE_ID set but TACIT_TOKEN missing');
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
apiUrl: process.env['TACIT_API_URL']?.trim() || undefined,
|
|
496
|
+
token: process.env['TACIT_TOKEN'].trim(),
|
|
497
|
+
workspaceId: process.env['TACIT_WORKSPACE_ID'].trim(),
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if (isNonEmpty(process.env['TACIT_TOKEN'])) {
|
|
501
|
+
return {
|
|
502
|
+
apiUrl: process.env['TACIT_API_URL']?.trim() || undefined,
|
|
503
|
+
token: process.env['TACIT_TOKEN'].trim(),
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
// Level 3: sync.json workspace_id + default profile credentials
|
|
507
|
+
// (constructor handles sync.json as fallback when no profile opts are set)
|
|
508
|
+
// Level 4: ~/.tacit/default → profile name
|
|
509
|
+
const defaultPath = path.join(os.homedir(), '.tacit', 'default');
|
|
510
|
+
try {
|
|
511
|
+
if (fs.existsSync(defaultPath)) {
|
|
512
|
+
const defaultName = fs.readFileSync(defaultPath, 'utf-8').trim();
|
|
513
|
+
if (defaultName) {
|
|
514
|
+
const profile = loadProfile(defaultName);
|
|
515
|
+
return {
|
|
516
|
+
apiUrl: isNonEmpty(process.env['TACIT_API_URL']) ? process.env['TACIT_API_URL'].trim() : profile.api_url,
|
|
517
|
+
appUrl: isNonEmpty(process.env['TACIT_APP_URL']) ? process.env['TACIT_APP_URL'].trim() : profile.app_url,
|
|
518
|
+
token: profile.token,
|
|
519
|
+
workspaceId: profile.workspace_id,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
catch (err) {
|
|
525
|
+
process.stderr.write(`[TACIT] Default profile load failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
526
|
+
}
|
|
527
|
+
// Level 5: no profile config — return empty (backward compat with env-only setup)
|
|
528
|
+
return {};
|
|
529
|
+
}
|
|
429
530
|
const requestStore = new AsyncLocalStorage();
|
|
430
531
|
/** HTTPS mode: bind the caller's token/apiUrl/principal to everything run inside fn. */
|
|
431
532
|
export function runWithRequestContext(token, apiUrl, fn, principal) {
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ import { registerWorkflowTypeTools } from './tools/workflow-types.js';
|
|
|
66
66
|
import { registerWorkflowPrereqsTool } from './tools/workflow-prereqs.js';
|
|
67
67
|
import { registerCmoTools } from './tools/cmo.js';
|
|
68
68
|
import { registerPrompts } from './prompts.js';
|
|
69
|
-
import { getRequestPrincipal, ensureAutonomy } from './client.js';
|
|
69
|
+
import { getRequestPrincipal, ensureAutonomy, resolveProfileOptions } from './client.js';
|
|
70
70
|
// Setup wizard (MV-1057h / W5)
|
|
71
71
|
import { setup, profileToEnvVar } from './setup.js';
|
|
72
72
|
import { WorkflowGate } from './workflow-gate.js';
|
|
@@ -311,13 +311,27 @@ async function run() {
|
|
|
311
311
|
});
|
|
312
312
|
const isHttpMode = process.env['MCP_TRANSPORT'] === 'http';
|
|
313
313
|
let clientInstance = null;
|
|
314
|
+
// FEAT-255: resolve profile options once at startup (5-level chain). Skip in HTTP mode.
|
|
315
|
+
let profileOpts;
|
|
316
|
+
if (!isHttpMode) {
|
|
317
|
+
try {
|
|
318
|
+
profileOpts = resolveProfileOptions();
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
322
|
+
process.stderr.write(`[TACIT] Profile resolution failed: ${msg}\n`);
|
|
323
|
+
if (process.env['TACIT_PROFILE']?.trim()) {
|
|
324
|
+
process.stderr.write('[TACIT] TACIT_PROFILE was explicitly set — cannot continue without a valid profile.\n');
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
314
329
|
const getClient = async () => {
|
|
315
330
|
if (isHttpMode) {
|
|
316
|
-
// Per-request client via AsyncLocalStorage (caller's token)
|
|
317
331
|
return getModuleClient();
|
|
318
332
|
}
|
|
319
333
|
if (!clientInstance) {
|
|
320
|
-
clientInstance = new TacitClient();
|
|
334
|
+
clientInstance = new TacitClient(profileOpts);
|
|
321
335
|
await clientInstance.initialize();
|
|
322
336
|
}
|
|
323
337
|
return clientInstance;
|
package/dist/prompts.d.ts
CHANGED
|
@@ -33,21 +33,21 @@ export declare const GM_WORKFLOW: {
|
|
|
33
33
|
}, {
|
|
34
34
|
readonly id: "review_structure";
|
|
35
35
|
readonly name: "Review workspace structure (MANDATORY for pyramid placement)";
|
|
36
|
-
readonly action: "You MUST call ALL FOUR tools in sequence — do not skip any: (1) Call tacit_pyramid_list_portfolios to see all portfolios. Pick the best fit. (2) Call tacit_pyramid_list_value_streams — if value streams exist, identify which one aligns with the content. (3) Call tacit_pyramid_list_programs with the portfolio_id. Pick the best-fit program. (4) Call tacit_pyramid_list_dossiers with that program_id. Pick the best-fit dossier. If
|
|
36
|
+
readonly action: "You MUST call ALL FOUR tools in sequence — do not skip any: (1) Call tacit_pyramid_list_portfolios to see all portfolios. Pick the best fit. (2) Call tacit_pyramid_list_value_streams — if value streams exist, identify which one aligns with the content. (3) Call tacit_pyramid_list_programs with the portfolio_id. Pick the best-fit program. After selecting the target program, check its value_stream_id in the list response. If value_stream_id is null or missing, the program is an orphan — it is not linked to any value stream. In step 4, include this in your proposal: \"Note: [program] is not linked to a value stream. I'd recommend linking it to [VS name] — should I do that too?\" If the user approves, call tacit_pyramid_assign_program_to_value_stream before tacit_gm_approve. (4) Call tacit_pyramid_list_dossiers with that program_id. Pick the best-fit dossier. If tacit_pyramid_list_dossiers returns zero results for the selected program, you MUST propose creating a new dossier. Derive the dossier name from the content title (e.g., for a research report titled \"AI Agents for SMB Operations\", propose a dossier called \"AI Agents for SMB Operations\" or similar). The user can override the proposed name or decline the dossier, but the GM must always propose one — never silently skip it. Do NOT proceed to step 4 without either an existing dossier ID or a new dossier name to propose. You MUST drill down to the dossier level — placing at the program level without a dossier creates an orphan. For a KB surface: call tacit_kb_list_collections and pick the best-fit collection.";
|
|
37
37
|
readonly tools: readonly ["tacit_pyramid_list_portfolios", "tacit_pyramid_list_value_streams", "tacit_pyramid_list_programs", "tacit_pyramid_list_dossiers"];
|
|
38
38
|
readonly signal: "You have identified a specific portfolio → value stream (if any) → program → dossier, or determined a new dossier name is needed.";
|
|
39
39
|
readonly skip_when: "User chose lake-only.";
|
|
40
40
|
}, {
|
|
41
41
|
readonly id: "propose";
|
|
42
42
|
readonly name: "Propose and WAIT for approval";
|
|
43
|
-
readonly action: "Present a specific proposal and STOP. Do not call tacit_gm_approve yet. For pyramid, say: \"I'd file this under [portfolio] → [value stream] → [program] → [dossier] — [one sentence reason]. Should I go ahead?\" (Omit value stream only if the workspace has none.) If
|
|
43
|
+
readonly action: "Present a specific proposal and STOP. Do not call tacit_gm_approve yet. Your proposal MUST include a dossier. For pyramid, say: \"I'd file this under [portfolio] → [value stream] → [program] → [dossier] — [one sentence reason]. Should I go ahead?\" (Omit value stream only if the workspace has none.) If no existing dossier fits, propose a new one: \"I'd file this under [portfolio] → [VS] → [program] → **new dossier: [name]**. Good?\" For KB: \"I'd add this to your [collection] knowledge base as a draft article you can publish anytime. Approve?\" If the selected program has no value_stream_id (flagged in step 3), include: \"Note: [program] is not linked to a value stream. I'd recommend linking it to [VS name] — should I do that too?\" CRITICAL: You MUST wait for the user to say yes, approve, or confirm BEFORE proceeding to the next step. Do NOT interpret ANY of these as approval of a specific location: \"place it\", \"add it to the workspace\", \"you decide\", \"pyramid\", \"KB\", \"knowledge base\", \"workspace structure\". Those are SURFACE choices — the user still needs to see and approve the SPECIFIC portfolio → value stream → program → dossier path (or specific collection for KB) that you are proposing. If the classifier's suggestion does not fit, propose a better location; never place it yourself instead of asking.";
|
|
44
44
|
readonly tools: readonly [];
|
|
45
45
|
readonly signal: "User explicitly approves (\"yes\", \"approve\", \"do it\", \"go ahead\"), redirects to a different location, or declines.";
|
|
46
46
|
}, {
|
|
47
47
|
readonly id: "place";
|
|
48
48
|
readonly name: "Execute approved placement";
|
|
49
|
-
readonly action: "ONLY after the user explicitly approved the proposal in step 4: For pyramid — if a new dossier
|
|
50
|
-
readonly tools: readonly ["tacit_gm_approve", "tacit_kb_promote_from_artifact", "tacit_pyramid_create_dossier"];
|
|
49
|
+
readonly action: "PRECONDITION: You MUST have a dossier_id before calling tacit_gm_approve for pyramid placement. If you reach this step without a dossier_id, STOP and go back to step 4 to propose one. ONLY after the user explicitly approved the proposal in step 4: For pyramid — if a new dossier was approved, call tacit_pyramid_create_dossier first to get the dossier_id. If the user also approved linking the program to a value stream (flagged in step 3), call tacit_pyramid_assign_program_to_value_stream first. Then call tacit_gm_approve with the catalog_id from step 1, surface=\"pyramid\", collection_or_program set to the program UUID, and dossier_id set to the dossier UUID. NEVER call tacit_gm_approve without a dossier_id for pyramid placement. For KB: call tacit_kb_promote_from_artifact with the artifact_id from step 1, the collection UUID, and status \"DRAFT\" — the article lands as a draft the user can publish anytime (tacit_gm_approve does not place KB content). For both: pyramid first, then KB (two separate calls). For lake-only: no call needed.";
|
|
50
|
+
readonly tools: readonly ["tacit_gm_approve", "tacit_kb_promote_from_artifact", "tacit_pyramid_create_dossier", "tacit_pyramid_assign_program_to_value_stream"];
|
|
51
51
|
readonly signal: "tacit_gm_approve or tacit_kb_promote_from_artifact returns success.";
|
|
52
52
|
readonly skip_when: "User chose lake-only.";
|
|
53
53
|
}, {
|
package/dist/prompts.js
CHANGED
|
@@ -176,7 +176,7 @@ export const GM_WORKFLOW = {
|
|
|
176
176
|
{
|
|
177
177
|
id: 'review_structure',
|
|
178
178
|
name: 'Review workspace structure (MANDATORY for pyramid placement)',
|
|
179
|
-
action: 'You MUST call ALL FOUR tools in sequence — do not skip any: (1) Call tacit_pyramid_list_portfolios to see all portfolios. Pick the best fit. (2) Call tacit_pyramid_list_value_streams — if value streams exist, identify which one aligns with the content. (3) Call tacit_pyramid_list_programs with the portfolio_id. Pick the best-fit program. (4) Call tacit_pyramid_list_dossiers with that program_id. Pick the best-fit dossier. If
|
|
179
|
+
action: 'You MUST call ALL FOUR tools in sequence — do not skip any: (1) Call tacit_pyramid_list_portfolios to see all portfolios. Pick the best fit. (2) Call tacit_pyramid_list_value_streams — if value streams exist, identify which one aligns with the content. (3) Call tacit_pyramid_list_programs with the portfolio_id. Pick the best-fit program. After selecting the target program, check its value_stream_id in the list response. If value_stream_id is null or missing, the program is an orphan — it is not linked to any value stream. In step 4, include this in your proposal: "Note: [program] is not linked to a value stream. I\'d recommend linking it to [VS name] — should I do that too?" If the user approves, call tacit_pyramid_assign_program_to_value_stream before tacit_gm_approve. (4) Call tacit_pyramid_list_dossiers with that program_id. Pick the best-fit dossier. If tacit_pyramid_list_dossiers returns zero results for the selected program, you MUST propose creating a new dossier. Derive the dossier name from the content title (e.g., for a research report titled "AI Agents for SMB Operations", propose a dossier called "AI Agents for SMB Operations" or similar). The user can override the proposed name or decline the dossier, but the GM must always propose one — never silently skip it. Do NOT proceed to step 4 without either an existing dossier ID or a new dossier name to propose. You MUST drill down to the dossier level — placing at the program level without a dossier creates an orphan. For a KB surface: call tacit_kb_list_collections and pick the best-fit collection.',
|
|
180
180
|
tools: ['tacit_pyramid_list_portfolios', 'tacit_pyramid_list_value_streams', 'tacit_pyramid_list_programs', 'tacit_pyramid_list_dossiers'],
|
|
181
181
|
signal: 'You have identified a specific portfolio → value stream (if any) → program → dossier, or determined a new dossier name is needed.',
|
|
182
182
|
skip_when: 'User chose lake-only.',
|
|
@@ -184,15 +184,15 @@ export const GM_WORKFLOW = {
|
|
|
184
184
|
{
|
|
185
185
|
id: 'propose',
|
|
186
186
|
name: 'Propose and WAIT for approval',
|
|
187
|
-
action: 'Present a specific proposal and STOP. Do not call tacit_gm_approve yet. For pyramid, say: "I\'d file this under [portfolio] → [value stream] → [program] → [dossier] — [one sentence reason]. Should I go ahead?" (Omit value stream only if the workspace has none.) If
|
|
187
|
+
action: 'Present a specific proposal and STOP. Do not call tacit_gm_approve yet. Your proposal MUST include a dossier. For pyramid, say: "I\'d file this under [portfolio] → [value stream] → [program] → [dossier] — [one sentence reason]. Should I go ahead?" (Omit value stream only if the workspace has none.) If no existing dossier fits, propose a new one: "I\'d file this under [portfolio] → [VS] → [program] → **new dossier: [name]**. Good?" For KB: "I\'d add this to your [collection] knowledge base as a draft article you can publish anytime. Approve?" If the selected program has no value_stream_id (flagged in step 3), include: "Note: [program] is not linked to a value stream. I\'d recommend linking it to [VS name] — should I do that too?" CRITICAL: You MUST wait for the user to say yes, approve, or confirm BEFORE proceeding to the next step. Do NOT interpret ANY of these as approval of a specific location: "place it", "add it to the workspace", "you decide", "pyramid", "KB", "knowledge base", "workspace structure". Those are SURFACE choices — the user still needs to see and approve the SPECIFIC portfolio → value stream → program → dossier path (or specific collection for KB) that you are proposing. If the classifier\'s suggestion does not fit, propose a better location; never place it yourself instead of asking.',
|
|
188
188
|
tools: [],
|
|
189
189
|
signal: 'User explicitly approves ("yes", "approve", "do it", "go ahead"), redirects to a different location, or declines.',
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
192
|
id: 'place',
|
|
193
193
|
name: 'Execute approved placement',
|
|
194
|
-
action: 'ONLY after the user explicitly approved the proposal in step 4: For pyramid — if a new dossier
|
|
195
|
-
tools: ['tacit_gm_approve', 'tacit_kb_promote_from_artifact', 'tacit_pyramid_create_dossier'],
|
|
194
|
+
action: 'PRECONDITION: You MUST have a dossier_id before calling tacit_gm_approve for pyramid placement. If you reach this step without a dossier_id, STOP and go back to step 4 to propose one. ONLY after the user explicitly approved the proposal in step 4: For pyramid — if a new dossier was approved, call tacit_pyramid_create_dossier first to get the dossier_id. If the user also approved linking the program to a value stream (flagged in step 3), call tacit_pyramid_assign_program_to_value_stream first. Then call tacit_gm_approve with the catalog_id from step 1, surface="pyramid", collection_or_program set to the program UUID, and dossier_id set to the dossier UUID. NEVER call tacit_gm_approve without a dossier_id for pyramid placement. For KB: call tacit_kb_promote_from_artifact with the artifact_id from step 1, the collection UUID, and status "DRAFT" — the article lands as a draft the user can publish anytime (tacit_gm_approve does not place KB content). For both: pyramid first, then KB (two separate calls). For lake-only: no call needed.',
|
|
195
|
+
tools: ['tacit_gm_approve', 'tacit_kb_promote_from_artifact', 'tacit_pyramid_create_dossier', 'tacit_pyramid_assign_program_to_value_stream'],
|
|
196
196
|
signal: 'tacit_gm_approve or tacit_kb_promote_from_artifact returns success.',
|
|
197
197
|
skip_when: 'User chose lake-only.',
|
|
198
198
|
},
|
package/dist/setup.d.ts
CHANGED
|
@@ -41,4 +41,35 @@ export declare function profileToEnvVar(profile: string): string;
|
|
|
41
41
|
* AC-12: lowercased, spaces→hyphens, non-alphanumeric-hyphen stripped.
|
|
42
42
|
*/
|
|
43
43
|
export declare function workspaceNameToProfile(name: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Web app URL for shareable links: api.* → app.*, localhost API → localhost:5174.
|
|
46
|
+
*/
|
|
47
|
+
export declare function deriveAppUrl(apiUrl: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Write ~/.tacit/profiles/<profile>.json with { expires_at, api_url }.
|
|
50
|
+
* Token plaintext is NEVER written here — metadata only.
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeProfileMetadata(profile: string, expiresAt: string, apiUrl: string): void;
|
|
53
|
+
interface DeviceAuthResult {
|
|
54
|
+
token: string;
|
|
55
|
+
expiresAt: string;
|
|
56
|
+
workspaceName: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Opens a browser to the device-auth URL and waits for the OAuth callback.
|
|
60
|
+
* Returns the token, expiry, and workspace name from the exchange response.
|
|
61
|
+
*
|
|
62
|
+
* Security:
|
|
63
|
+
* - State nonce is generated via crypto.randomBytes (never user-provided).
|
|
64
|
+
* - Tampered state → exit 1 (S-10 / AC-13).
|
|
65
|
+
* - Token plaintext is NEVER logged.
|
|
66
|
+
*
|
|
67
|
+
* Error paths:
|
|
68
|
+
* - /auth/device returns 404 → reject immediately (pre-flight probe).
|
|
69
|
+
* - Port 9123 occupied → reject (caller falls back to loginFlow).
|
|
70
|
+
* - 120s timeout → reject (caller falls back to loginFlow).
|
|
71
|
+
* - Browser open fails → print URL to stdout for manual copy-paste (AC-16 fallback).
|
|
72
|
+
*/
|
|
73
|
+
export declare function deviceAuthFlow(apiUrl: string): Promise<DeviceAuthResult>;
|
|
44
74
|
export declare function setup(argv: string[]): Promise<void>;
|
|
75
|
+
export {};
|
package/dist/setup.js
CHANGED
|
@@ -132,7 +132,7 @@ function readExistingConfig() {
|
|
|
132
132
|
/**
|
|
133
133
|
* Web app URL for shareable links: api.* → app.*, localhost API → localhost:5174.
|
|
134
134
|
*/
|
|
135
|
-
function deriveAppUrl(apiUrl) {
|
|
135
|
+
export function deriveAppUrl(apiUrl) {
|
|
136
136
|
const url = new URL(apiUrl);
|
|
137
137
|
url.username = '';
|
|
138
138
|
url.password = '';
|
|
@@ -187,10 +187,26 @@ function configToBytes(cfg) {
|
|
|
187
187
|
* Write ~/.tacit/profiles/<profile>.json with { expires_at, api_url }.
|
|
188
188
|
* Token plaintext is NEVER written here — metadata only.
|
|
189
189
|
*/
|
|
190
|
-
function writeProfileMetadata(profile, expiresAt, apiUrl) {
|
|
190
|
+
export function writeProfileMetadata(profile, expiresAt, apiUrl) {
|
|
191
191
|
const metaDir = path.join(os.homedir(), '.tacit', 'profiles');
|
|
192
|
-
fs.mkdirSync(metaDir, { recursive: true });
|
|
193
|
-
|
|
192
|
+
fs.mkdirSync(metaDir, { recursive: true, mode: 0o700 });
|
|
193
|
+
try {
|
|
194
|
+
fs.chmodSync(metaDir, 0o700);
|
|
195
|
+
}
|
|
196
|
+
catch { /* unsupported OS */ }
|
|
197
|
+
const filePath = path.join(metaDir, `${profile}.json`);
|
|
198
|
+
// v2 non-clobber: if a login profile exists, don't overwrite with metadata-only
|
|
199
|
+
if (fs.existsSync(filePath)) {
|
|
200
|
+
try {
|
|
201
|
+
const existing = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
202
|
+
if (existing.version === 2) {
|
|
203
|
+
process.stderr.write(`[TACIT] Profile '${profile}' is a v2 login profile — skipping metadata write.\n`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch { /* corrupt file, overwrite */ }
|
|
208
|
+
}
|
|
209
|
+
fs.writeFileSync(filePath, JSON.stringify({ expires_at: expiresAt, api_url: apiUrl }, null, 2), { mode: 0o600 });
|
|
194
210
|
}
|
|
195
211
|
// ─── Device-auth flow ─────────────────────────────────────────────────────────
|
|
196
212
|
const DEVICE_AUTH_CALLBACK_PORT = 9123;
|
|
@@ -210,7 +226,7 @@ const DEVICE_AUTH_TIMEOUT_MS = 120_000;
|
|
|
210
226
|
* - 120s timeout → reject (caller falls back to loginFlow).
|
|
211
227
|
* - Browser open fails → print URL to stdout for manual copy-paste (AC-16 fallback).
|
|
212
228
|
*/
|
|
213
|
-
async function deviceAuthFlow(apiUrl) {
|
|
229
|
+
export async function deviceAuthFlow(apiUrl) {
|
|
214
230
|
// Pre-flight: check if /auth/device exists before opening a browser to it.
|
|
215
231
|
try {
|
|
216
232
|
const probe = await fetch(`${apiUrl}/auth/device`, { method: 'HEAD', redirect: 'manual' });
|
package/dist/tools/agents.d.ts
CHANGED
|
@@ -201,11 +201,11 @@ export declare const agentApprovalsInputSchema: z.ZodObject<{
|
|
|
201
201
|
status: z.ZodOptional<z.ZodString>;
|
|
202
202
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
203
203
|
}, "strip", z.ZodTypeAny, {
|
|
204
|
-
limit?: number | undefined;
|
|
205
204
|
status?: string | undefined;
|
|
206
|
-
}, {
|
|
207
205
|
limit?: number | undefined;
|
|
206
|
+
}, {
|
|
208
207
|
status?: string | undefined;
|
|
208
|
+
limit?: number | undefined;
|
|
209
209
|
}>;
|
|
210
210
|
export type AgentApprovalsInput = z.infer<typeof agentApprovalsInputSchema>;
|
|
211
211
|
export declare const AGENT_APPROVALS_TOOL_DEF: {
|
|
@@ -36,15 +36,15 @@ export declare const artifactListInputSchema: z.ZodObject<{
|
|
|
36
36
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
37
37
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
39
|
-
limit?: number | undefined;
|
|
40
39
|
status?: string | undefined;
|
|
40
|
+
limit?: number | undefined;
|
|
41
41
|
origin?: "IMPORTED" | "SYNTHESIZED" | "WIKI_CONVERGENCE" | undefined;
|
|
42
42
|
q?: string | undefined;
|
|
43
43
|
portfolio_id?: string | undefined;
|
|
44
44
|
offset?: number | undefined;
|
|
45
45
|
}, {
|
|
46
|
-
limit?: number | undefined;
|
|
47
46
|
status?: string | undefined;
|
|
47
|
+
limit?: number | undefined;
|
|
48
48
|
origin?: "IMPORTED" | "SYNTHESIZED" | "WIKI_CONVERGENCE" | undefined;
|
|
49
49
|
q?: string | undefined;
|
|
50
50
|
portfolio_id?: string | undefined;
|
package/dist/tools/drafts.d.ts
CHANGED
|
@@ -30,16 +30,16 @@ export declare const draftSearchInputSchema: z.ZodObject<{
|
|
|
30
30
|
limit: z.ZodOptional<z.ZodNumber>;
|
|
31
31
|
}, "strip", z.ZodTypeAny, {
|
|
32
32
|
q: string;
|
|
33
|
+
mode?: "hybrid" | "keyword" | "semantic" | undefined;
|
|
33
34
|
limit?: number | undefined;
|
|
34
35
|
origin?: "IMPORTED" | "SYNTHESIZED" | "WIKI_CONVERGENCE" | undefined;
|
|
35
36
|
portfolio_id?: string | undefined;
|
|
36
|
-
mode?: "hybrid" | "keyword" | "semantic" | undefined;
|
|
37
37
|
}, {
|
|
38
38
|
q: string;
|
|
39
|
+
mode?: "hybrid" | "keyword" | "semantic" | undefined;
|
|
39
40
|
limit?: number | undefined;
|
|
40
41
|
origin?: "IMPORTED" | "SYNTHESIZED" | "WIKI_CONVERGENCE" | undefined;
|
|
41
42
|
portfolio_id?: string | undefined;
|
|
42
|
-
mode?: "hybrid" | "keyword" | "semantic" | undefined;
|
|
43
43
|
}>;
|
|
44
44
|
export type DraftSearchInput = z.infer<typeof draftSearchInputSchema>;
|
|
45
45
|
export declare const DRAFT_SEARCH_TOOL_DEF: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tacitai/mcp-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.42",
|
|
4
4
|
"description": "stdio MCP server wrapping Tacit /api/v1 REST/SSE API",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"bin": {
|
|
14
|
-
"tacit-mcp-server": "dist/index.js"
|
|
14
|
+
"tacit-mcp-server": "dist/index.js",
|
|
15
|
+
"tacit": "dist/cli.js",
|
|
16
|
+
"mcp-server": "dist/index.js"
|
|
15
17
|
},
|
|
16
18
|
"files": [
|
|
17
19
|
"dist",
|