@tacitai/mcp-server 0.6.55 → 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/career.js +25 -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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client profile store (MV-1542c step 1.1).
|
|
3
|
+
*
|
|
4
|
+
* `~/.tacit/profiles/<slug>.json` is the only place a CLI token lives (design
|
|
5
|
+
* rule 6). This module owns every read and write of that folder, of
|
|
6
|
+
* `~/.tacit/default` and of `~/.tacit/device-id`:
|
|
7
|
+
*
|
|
8
|
+
* - folder 0700, files 0600, atomic write (temp file + rename, O_EXCL)
|
|
9
|
+
* - reads open with O_NOFOLLOW and refuse symlinks, foreign owners and any
|
|
10
|
+
* group/world permission bits
|
|
11
|
+
* - JWT-shaped tokens are refused at load (D-53)
|
|
12
|
+
* - tokens never appear in an error message or a log line
|
|
13
|
+
*
|
|
14
|
+
* Paths are resolved from `os.homedir()` on every call so tests can point HOME
|
|
15
|
+
* at a temp directory.
|
|
16
|
+
*/
|
|
17
|
+
export interface ProfileData {
|
|
18
|
+
version: 2;
|
|
19
|
+
workspace_id: string;
|
|
20
|
+
workspace_name?: string;
|
|
21
|
+
api_url: string;
|
|
22
|
+
app_url?: string;
|
|
23
|
+
token: string;
|
|
24
|
+
created_at?: string;
|
|
25
|
+
expires_at?: string;
|
|
26
|
+
identity_email?: string;
|
|
27
|
+
token_id?: string;
|
|
28
|
+
device_label?: string;
|
|
29
|
+
credential_kind?: 'iam_token' | 'dev_token';
|
|
30
|
+
claude_config_dir?: string;
|
|
31
|
+
}
|
|
32
|
+
export type ProfileErrorCode = 'INVALID_NAME' | 'NOT_FOUND' | 'UNSAFE' | 'CORRUPT' | 'NOT_V2' | 'MISSING_FIELDS' | 'JWT_TOKEN';
|
|
33
|
+
export declare class ProfileError extends Error {
|
|
34
|
+
readonly code: ProfileErrorCode;
|
|
35
|
+
readonly profile?: string | undefined;
|
|
36
|
+
constructor(code: ProfileErrorCode, message: string, profile?: string | undefined);
|
|
37
|
+
}
|
|
38
|
+
export interface IdentityKey {
|
|
39
|
+
api_url: string;
|
|
40
|
+
workspace_id: string;
|
|
41
|
+
identity_email?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const PROFILE_NAME_RE: RegExp;
|
|
44
|
+
export declare const RESERVED_PROFILE_NAMES: ReadonlySet<string>;
|
|
45
|
+
export declare function tacitHome(): string;
|
|
46
|
+
export declare function profilesDir(): string;
|
|
47
|
+
export declare function defaultFilePath(): string;
|
|
48
|
+
export declare function deviceIdPath(): string;
|
|
49
|
+
export declare function profilePath(name: string): string;
|
|
50
|
+
/** Shape check only: what `loadProfile` has always accepted. */
|
|
51
|
+
export declare function isValidProfileName(name: string): boolean;
|
|
52
|
+
/** Shape check plus the reserved CLI words: what a new profile may be called. */
|
|
53
|
+
export declare function isUsableProfileName(name: string): boolean;
|
|
54
|
+
/** workspace_name to slug: lowercase, spaces to hyphens, anything else stripped, max 64. */
|
|
55
|
+
export declare function slugFromWorkspaceName(name: string): string;
|
|
56
|
+
/** Load a profile through every safety check. Throws ProfileError. */
|
|
57
|
+
export declare function readProfile(name: string): ProfileData;
|
|
58
|
+
/** Like readProfile, but returns null instead of throwing. */
|
|
59
|
+
export declare function tryReadProfile(name: string): ProfileData | null;
|
|
60
|
+
/** True if a file or symlink exists at the profile path (readable or not). */
|
|
61
|
+
export declare function profileExists(name: string): boolean;
|
|
62
|
+
/** Every loadable profile, sorted by name. Unsafe, corrupt and non-v2 files are skipped. */
|
|
63
|
+
export declare function listProfiles(): {
|
|
64
|
+
name: string;
|
|
65
|
+
data: ProfileData;
|
|
66
|
+
}[];
|
|
67
|
+
/** Atomic write: folder 0700, file 0600. Refuses to write through a symlink. */
|
|
68
|
+
export declare function writeProfile(name: string, data: ProfileData): void;
|
|
69
|
+
/**
|
|
70
|
+
* Delete a profile file. Clears `~/.tacit/default` when it named this profile.
|
|
71
|
+
* Returns whether the default was cleared; throws NOT_FOUND if there was no file.
|
|
72
|
+
*/
|
|
73
|
+
export declare function removeProfile(name: string): {
|
|
74
|
+
defaultCleared: boolean;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Pick the slug for a sign-in. Same (api_url, workspace_id, identity_email)
|
|
78
|
+
* updates that profile in place; a different workspace_id on the same slug
|
|
79
|
+
* gets a numeric suffix (-2, -3, ...). Reserved words are treated as taken.
|
|
80
|
+
*/
|
|
81
|
+
export declare function pickProfileSlug(workspaceName: string, id: IdentityKey): {
|
|
82
|
+
slug: string;
|
|
83
|
+
update: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** Name in `~/.tacit/default`, or null when unset, unreadable or not a valid name. */
|
|
86
|
+
export declare function getDefault(): string | null;
|
|
87
|
+
export declare function setDefault(name: string): void;
|
|
88
|
+
export declare function clearDefault(): void;
|
|
89
|
+
/** Short hostname (before the first dot), restricted to the server's device_label alphabet. */
|
|
90
|
+
export declare function shortHostname(raw?: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* `~/.tacit/device-id` (0600): short hostname + 8 hex digits, generated once.
|
|
93
|
+
* The suffix is regenerated when the stored hostname part differs from the
|
|
94
|
+
* current short hostname (AR-07). Fits `^[A-Za-z0-9 ._-]{1,64}$`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getDeviceLabel(): string;
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client profile store (MV-1542c step 1.1).
|
|
3
|
+
*
|
|
4
|
+
* `~/.tacit/profiles/<slug>.json` is the only place a CLI token lives (design
|
|
5
|
+
* rule 6). This module owns every read and write of that folder, of
|
|
6
|
+
* `~/.tacit/default` and of `~/.tacit/device-id`:
|
|
7
|
+
*
|
|
8
|
+
* - folder 0700, files 0600, atomic write (temp file + rename, O_EXCL)
|
|
9
|
+
* - reads open with O_NOFOLLOW and refuse symlinks, foreign owners and any
|
|
10
|
+
* group/world permission bits
|
|
11
|
+
* - JWT-shaped tokens are refused at load (D-53)
|
|
12
|
+
* - tokens never appear in an error message or a log line
|
|
13
|
+
*
|
|
14
|
+
* Paths are resolved from `os.homedir()` on every call so tests can point HOME
|
|
15
|
+
* at a temp directory.
|
|
16
|
+
*/
|
|
17
|
+
import * as fs from 'node:fs';
|
|
18
|
+
import * as os from 'node:os';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import * as crypto from 'node:crypto';
|
|
21
|
+
export class ProfileError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
profile;
|
|
24
|
+
constructor(code, message, profile) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.profile = profile;
|
|
28
|
+
this.name = 'ProfileError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// ─── Names and paths ─────────────────────────────────────────────────────────
|
|
32
|
+
export const PROFILE_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
33
|
+
export const RESERVED_PROFILE_NAMES = new Set(['login', 'ls', 'use', 'rm', 'status', 'install', 'help', 'setup', 'version', 'mode']);
|
|
34
|
+
const MAX_PROFILE_BYTES = 64 * 1024;
|
|
35
|
+
const JWT_SHAPE_RE = /^eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;
|
|
36
|
+
const DEVICE_ID_RE = /^([A-Za-z0-9._-]{1,55})-([0-9a-f]{8})$/;
|
|
37
|
+
const IS_WINDOWS = process.platform === 'win32';
|
|
38
|
+
export function tacitHome() { return path.join(os.homedir(), '.tacit'); }
|
|
39
|
+
export function profilesDir() { return path.join(tacitHome(), 'profiles'); }
|
|
40
|
+
export function defaultFilePath() { return path.join(tacitHome(), 'default'); }
|
|
41
|
+
export function deviceIdPath() { return path.join(tacitHome(), 'device-id'); }
|
|
42
|
+
export function profilePath(name) { return path.join(profilesDir(), `${name}.json`); }
|
|
43
|
+
/** Shape check only: what `loadProfile` has always accepted. */
|
|
44
|
+
export function isValidProfileName(name) {
|
|
45
|
+
return PROFILE_NAME_RE.test(name);
|
|
46
|
+
}
|
|
47
|
+
/** Shape check plus the reserved CLI words: what a new profile may be called. */
|
|
48
|
+
export function isUsableProfileName(name) {
|
|
49
|
+
return PROFILE_NAME_RE.test(name) && !RESERVED_PROFILE_NAMES.has(name);
|
|
50
|
+
}
|
|
51
|
+
/** workspace_name to slug: lowercase, spaces to hyphens, anything else stripped, max 64. */
|
|
52
|
+
export function slugFromWorkspaceName(name) {
|
|
53
|
+
const slug = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '').replace(/^-+/, '');
|
|
54
|
+
if (!slug || !/^[a-z0-9]/.test(slug))
|
|
55
|
+
return 'workspace';
|
|
56
|
+
return slug.slice(0, 64);
|
|
57
|
+
}
|
|
58
|
+
function assertValidName(name) {
|
|
59
|
+
if (!isValidProfileName(name)) {
|
|
60
|
+
throw new ProfileError('INVALID_NAME', `Invalid profile name '${name}'. Names must match: ${PROFILE_NAME_RE}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// ─── Safe file access ────────────────────────────────────────────────────────
|
|
64
|
+
const O_NOFOLLOW = fs.constants.O_NOFOLLOW ?? 0;
|
|
65
|
+
function modeString(mode) {
|
|
66
|
+
return (mode & 0o777).toString(8).padStart(4, '0');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read a small file the store owns. Refuses symlinks, non-regular files,
|
|
70
|
+
* foreign owners and any group/world permission bit. Returns null when the
|
|
71
|
+
* file does not exist.
|
|
72
|
+
*/
|
|
73
|
+
function readOwnedFile(filePath, label, profile) {
|
|
74
|
+
let fd;
|
|
75
|
+
try {
|
|
76
|
+
fd = fs.openSync(filePath, fs.constants.O_RDONLY | O_NOFOLLOW);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const code = err.code;
|
|
80
|
+
if (code === 'ENOENT')
|
|
81
|
+
return null;
|
|
82
|
+
if (code === 'ELOOP' || code === 'EMLINK') {
|
|
83
|
+
throw new ProfileError('UNSAFE', `${label} is a symlink and was refused: ${filePath}`, profile);
|
|
84
|
+
}
|
|
85
|
+
throw new ProfileError('UNSAFE', `${label} could not be opened (${code ?? 'error'}): ${filePath}`, profile);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const st = fs.fstatSync(fd);
|
|
89
|
+
if (!st.isFile()) {
|
|
90
|
+
throw new ProfileError('UNSAFE', `${label} is not a regular file and was refused: ${filePath}`, profile);
|
|
91
|
+
}
|
|
92
|
+
if (!IS_WINDOWS) {
|
|
93
|
+
if (typeof process.getuid === 'function' && st.uid !== process.getuid()) {
|
|
94
|
+
throw new ProfileError('UNSAFE', `${label} is owned by another user and was refused: ${filePath}`, profile);
|
|
95
|
+
}
|
|
96
|
+
if ((st.mode & 0o077) !== 0) {
|
|
97
|
+
throw new ProfileError('UNSAFE', `${label} has mode ${modeString(st.mode)}; it must be 0600. Run: chmod 600 "${filePath}"`, profile);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (st.size > MAX_PROFILE_BYTES) {
|
|
101
|
+
throw new ProfileError('CORRUPT', `${label} is unexpectedly large and was refused: ${filePath}`, profile);
|
|
102
|
+
}
|
|
103
|
+
return fs.readFileSync(fd, 'utf-8');
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
fs.closeSync(fd);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Create `dir` (0700) if missing; tighten it to 0700 when `tighten` is set. */
|
|
110
|
+
function ensureDir(dir, tighten) {
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
112
|
+
let isLink = false;
|
|
113
|
+
try {
|
|
114
|
+
isLink = fs.lstatSync(dir).isSymbolicLink();
|
|
115
|
+
}
|
|
116
|
+
catch { /* checked by the caller */ }
|
|
117
|
+
if (tighten && !isLink) {
|
|
118
|
+
try {
|
|
119
|
+
fs.chmodSync(dir, 0o700);
|
|
120
|
+
}
|
|
121
|
+
catch { /* unsupported OS */ }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Temp file (O_EXCL, 0600) + fsync + rename. Never leaves a partial target. */
|
|
125
|
+
function atomicWrite(filePath, content) {
|
|
126
|
+
const tmp = `${filePath}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
127
|
+
const fd = fs.openSync(tmp, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | O_NOFOLLOW, 0o600);
|
|
128
|
+
try {
|
|
129
|
+
try {
|
|
130
|
+
fs.writeFileSync(fd, content);
|
|
131
|
+
try {
|
|
132
|
+
fs.fchmodSync(fd, 0o600);
|
|
133
|
+
}
|
|
134
|
+
catch { /* unsupported OS */ }
|
|
135
|
+
fs.fsyncSync(fd);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
fs.closeSync(fd);
|
|
139
|
+
}
|
|
140
|
+
fs.renameSync(tmp, filePath);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
try {
|
|
144
|
+
fs.unlinkSync(tmp);
|
|
145
|
+
}
|
|
146
|
+
catch { /* already gone */ }
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** The profiles folder must be ours and not writable by others, or files in it could be swapped. */
|
|
151
|
+
function assertProfilesDirSafe() {
|
|
152
|
+
const dir = profilesDir();
|
|
153
|
+
let st;
|
|
154
|
+
try {
|
|
155
|
+
st = fs.lstatSync(dir);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
if (err.code === 'ENOENT')
|
|
159
|
+
return;
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
if (IS_WINDOWS)
|
|
163
|
+
return;
|
|
164
|
+
if (!st.isDirectory() && !st.isSymbolicLink()) {
|
|
165
|
+
throw new ProfileError('UNSAFE', `Profiles folder is not a directory: ${dir}`);
|
|
166
|
+
}
|
|
167
|
+
// L-11: a symlinked profiles folder could point anywhere; refuse it.
|
|
168
|
+
if (st.isSymbolicLink()) {
|
|
169
|
+
throw new ProfileError('UNSAFE', `Profiles folder is a symbolic link and was refused: ${dir}`);
|
|
170
|
+
}
|
|
171
|
+
const real = st;
|
|
172
|
+
if (typeof process.getuid === 'function' && real.uid !== process.getuid()) {
|
|
173
|
+
throw new ProfileError('UNSAFE', `Profiles folder is owned by another user and was refused: ${dir}`);
|
|
174
|
+
}
|
|
175
|
+
if ((real.mode & 0o077) !== 0) {
|
|
176
|
+
throw new ProfileError('UNSAFE', `Profiles folder has mode ${modeString(real.mode)}; it must be 0700. Run: chmod 700 "${dir}"`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// ─── Profiles ────────────────────────────────────────────────────────────────
|
|
180
|
+
function optString(raw, key) {
|
|
181
|
+
const v = raw[key];
|
|
182
|
+
return typeof v === 'string' && v.length > 0 ? v : undefined;
|
|
183
|
+
}
|
|
184
|
+
function parseProfile(name, text) {
|
|
185
|
+
let raw;
|
|
186
|
+
try {
|
|
187
|
+
const parsed = JSON.parse(text);
|
|
188
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
189
|
+
throw new Error('not an object');
|
|
190
|
+
raw = parsed;
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
throw new ProfileError('CORRUPT', `Profile '${name}' is corrupted: ${err instanceof Error ? err.message : String(err)}. Re-run: tacit login`, name);
|
|
194
|
+
}
|
|
195
|
+
if (raw['version'] !== 2) {
|
|
196
|
+
throw new ProfileError('NOT_V2', `Profile '${name}' was created by setup and lacks credentials. Re-run: tacit login`, name);
|
|
197
|
+
}
|
|
198
|
+
const workspace_id = optString(raw, 'workspace_id');
|
|
199
|
+
const token = optString(raw, 'token');
|
|
200
|
+
const api_url = optString(raw, 'api_url');
|
|
201
|
+
if (!workspace_id || !token || !api_url) {
|
|
202
|
+
throw new ProfileError('MISSING_FIELDS', `Profile '${name}' is missing required fields (workspace_id, token, api_url). Re-run: tacit login`, name);
|
|
203
|
+
}
|
|
204
|
+
if (JWT_SHAPE_RE.test(token)) {
|
|
205
|
+
throw new ProfileError('JWT_TOKEN', 'This profile holds a browser login, not a CLI login. Run: tacit login', name);
|
|
206
|
+
}
|
|
207
|
+
const kind = raw['credential_kind'];
|
|
208
|
+
const data = { version: 2, workspace_id, api_url, token };
|
|
209
|
+
const strings = [
|
|
210
|
+
'workspace_name', 'app_url', 'created_at', 'expires_at', 'identity_email', 'token_id', 'device_label',
|
|
211
|
+
'claude_config_dir',
|
|
212
|
+
];
|
|
213
|
+
for (const key of strings) {
|
|
214
|
+
const v = optString(raw, key);
|
|
215
|
+
if (v !== undefined)
|
|
216
|
+
data[key] = v;
|
|
217
|
+
}
|
|
218
|
+
if (kind === 'iam_token' || kind === 'dev_token')
|
|
219
|
+
data.credential_kind = kind;
|
|
220
|
+
return data;
|
|
221
|
+
}
|
|
222
|
+
/** Load a profile through every safety check. Throws ProfileError. */
|
|
223
|
+
export function readProfile(name) {
|
|
224
|
+
assertValidName(name);
|
|
225
|
+
assertProfilesDirSafe();
|
|
226
|
+
const filePath = profilePath(name);
|
|
227
|
+
const text = readOwnedFile(filePath, `Profile '${name}'`, name);
|
|
228
|
+
if (text === null) {
|
|
229
|
+
throw new ProfileError('NOT_FOUND', `Profile '${name}' not found at ${filePath}. Run: tacit ls`, name);
|
|
230
|
+
}
|
|
231
|
+
return parseProfile(name, text);
|
|
232
|
+
}
|
|
233
|
+
/** Like readProfile, but returns null instead of throwing. */
|
|
234
|
+
export function tryReadProfile(name) {
|
|
235
|
+
try {
|
|
236
|
+
return readProfile(name);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** True if a file or symlink exists at the profile path (readable or not). */
|
|
243
|
+
export function profileExists(name) {
|
|
244
|
+
if (!isValidProfileName(name))
|
|
245
|
+
return false;
|
|
246
|
+
try {
|
|
247
|
+
fs.lstatSync(profilePath(name));
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** Every loadable profile, sorted by name. Unsafe, corrupt and non-v2 files are skipped. */
|
|
255
|
+
export function listProfiles() {
|
|
256
|
+
let files;
|
|
257
|
+
try {
|
|
258
|
+
assertProfilesDirSafe();
|
|
259
|
+
files = fs.readdirSync(profilesDir()).filter(f => f.endsWith('.json'));
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
const out = [];
|
|
265
|
+
for (const f of files.sort()) {
|
|
266
|
+
const name = f.replace(/\.json$/, '');
|
|
267
|
+
const data = tryReadProfile(name);
|
|
268
|
+
if (data)
|
|
269
|
+
out.push({ name, data });
|
|
270
|
+
}
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
/** Atomic write: folder 0700, file 0600. Refuses to write through a symlink. */
|
|
274
|
+
export function writeProfile(name, data) {
|
|
275
|
+
assertValidName(name);
|
|
276
|
+
ensureDir(profilesDir(), true);
|
|
277
|
+
assertProfilesDirSafe();
|
|
278
|
+
const filePath = profilePath(name);
|
|
279
|
+
try {
|
|
280
|
+
if (fs.lstatSync(filePath).isSymbolicLink()) {
|
|
281
|
+
throw new ProfileError('UNSAFE', `Profile '${name}' is a symlink and was refused: ${filePath}`, name);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
if (err instanceof ProfileError)
|
|
286
|
+
throw err;
|
|
287
|
+
if (err.code !== 'ENOENT')
|
|
288
|
+
throw err;
|
|
289
|
+
}
|
|
290
|
+
atomicWrite(filePath, JSON.stringify(data, null, 2) + '\n');
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Delete a profile file. Clears `~/.tacit/default` when it named this profile.
|
|
294
|
+
* Returns whether the default was cleared; throws NOT_FOUND if there was no file.
|
|
295
|
+
*/
|
|
296
|
+
export function removeProfile(name) {
|
|
297
|
+
assertValidName(name);
|
|
298
|
+
try {
|
|
299
|
+
fs.unlinkSync(profilePath(name));
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
if (err.code === 'ENOENT') {
|
|
303
|
+
throw new ProfileError('NOT_FOUND', `Profile '${name}' not found.`, name);
|
|
304
|
+
}
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
if (getDefault() === name) {
|
|
308
|
+
clearDefault();
|
|
309
|
+
return { defaultCleared: true };
|
|
310
|
+
}
|
|
311
|
+
return { defaultCleared: false };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Pick the slug for a sign-in. Same (api_url, workspace_id, identity_email)
|
|
315
|
+
* updates that profile in place; a different workspace_id on the same slug
|
|
316
|
+
* gets a numeric suffix (-2, -3, ...). Reserved words are treated as taken.
|
|
317
|
+
*/
|
|
318
|
+
export function pickProfileSlug(workspaceName, id) {
|
|
319
|
+
const base = slugFromWorkspaceName(workspaceName);
|
|
320
|
+
const email = id.identity_email?.toLowerCase();
|
|
321
|
+
for (let n = 1; n < 1000; n++) {
|
|
322
|
+
const suffix = n === 1 ? '' : `-${n}`;
|
|
323
|
+
const slug = base.slice(0, 64 - suffix.length) + suffix;
|
|
324
|
+
if (RESERVED_PROFILE_NAMES.has(slug))
|
|
325
|
+
continue;
|
|
326
|
+
if (!profileExists(slug))
|
|
327
|
+
return { slug, update: false };
|
|
328
|
+
const existing = tryReadProfile(slug);
|
|
329
|
+
if (existing &&
|
|
330
|
+
existing.api_url === id.api_url &&
|
|
331
|
+
existing.workspace_id === id.workspace_id &&
|
|
332
|
+
existing.identity_email?.toLowerCase() === email) {
|
|
333
|
+
return { slug, update: true };
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
throw new ProfileError('INVALID_NAME', `No free profile name for '${base}'.`);
|
|
337
|
+
}
|
|
338
|
+
// ─── Default profile ─────────────────────────────────────────────────────────
|
|
339
|
+
/** Name in `~/.tacit/default`, or null when unset, unreadable or not a valid name. */
|
|
340
|
+
export function getDefault() {
|
|
341
|
+
try {
|
|
342
|
+
const text = readOwnedFile(defaultFilePath(), 'Default profile file');
|
|
343
|
+
const name = text?.trim();
|
|
344
|
+
return name && isValidProfileName(name) ? name : null;
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
export function setDefault(name) {
|
|
351
|
+
assertValidName(name);
|
|
352
|
+
ensureDir(tacitHome(), false);
|
|
353
|
+
atomicWrite(defaultFilePath(), name + '\n');
|
|
354
|
+
}
|
|
355
|
+
export function clearDefault() {
|
|
356
|
+
try {
|
|
357
|
+
fs.unlinkSync(defaultFilePath());
|
|
358
|
+
}
|
|
359
|
+
catch { /* already gone */ }
|
|
360
|
+
}
|
|
361
|
+
// ─── Device label ────────────────────────────────────────────────────────────
|
|
362
|
+
/** Short hostname (before the first dot), restricted to the server's device_label alphabet. */
|
|
363
|
+
export function shortHostname(raw = os.hostname()) {
|
|
364
|
+
const host = raw.split('.')[0].replace(/[^A-Za-z0-9._-]/g, '-').replace(/^-+|-+$/g, '');
|
|
365
|
+
return (host || 'device').slice(0, 55);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* `~/.tacit/device-id` (0600): short hostname + 8 hex digits, generated once.
|
|
369
|
+
* The suffix is regenerated when the stored hostname part differs from the
|
|
370
|
+
* current short hostname (AR-07). Fits `^[A-Za-z0-9 ._-]{1,64}$`.
|
|
371
|
+
*/
|
|
372
|
+
export function getDeviceLabel() {
|
|
373
|
+
const host = shortHostname();
|
|
374
|
+
const text = readOwnedFile(deviceIdPath(), 'Device id file');
|
|
375
|
+
const match = text === null ? null : DEVICE_ID_RE.exec(text.trim());
|
|
376
|
+
if (match && match[1] === host)
|
|
377
|
+
return text.trim();
|
|
378
|
+
const label = `${host}-${crypto.randomBytes(4).toString('hex')}`;
|
|
379
|
+
ensureDir(tacitHome(), false);
|
|
380
|
+
atomicWrite(deviceIdPath(), label + '\n');
|
|
381
|
+
return label;
|
|
382
|
+
}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hidden prompt for secrets such as a password (MV-1542c step 1.1).
|
|
3
|
+
*
|
|
4
|
+
* Reads the terminal in raw mode so nothing is echoed and no readline
|
|
5
|
+
* interface (with its history and line buffer) ever sees the secret. The
|
|
6
|
+
* terminal is restored on success, Ctrl-C, Ctrl-D, input error and process
|
|
7
|
+
* exit. The typed value is returned to the caller only; it is never written
|
|
8
|
+
* anywhere here.
|
|
9
|
+
*/
|
|
10
|
+
export type PromptErrorCode = 'NO_TTY' | 'CANCELLED' | 'INPUT_ERROR';
|
|
11
|
+
export declare class PromptError extends Error {
|
|
12
|
+
readonly code: PromptErrorCode;
|
|
13
|
+
constructor(code: PromptErrorCode, message: string);
|
|
14
|
+
}
|
|
15
|
+
export interface HiddenInput {
|
|
16
|
+
isTTY?: boolean;
|
|
17
|
+
isRaw?: boolean;
|
|
18
|
+
setRawMode?(mode: boolean): unknown;
|
|
19
|
+
setEncoding(encoding: BufferEncoding): unknown;
|
|
20
|
+
resume(): unknown;
|
|
21
|
+
pause(): unknown;
|
|
22
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
23
|
+
removeListener(event: string, listener: (...args: never[]) => void): unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface HiddenOutput {
|
|
26
|
+
write(chunk: string): unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface PromptHiddenOptions {
|
|
29
|
+
input?: HiddenInput;
|
|
30
|
+
output?: HiddenOutput;
|
|
31
|
+
}
|
|
32
|
+
export declare function promptHidden(question: string, options?: PromptHiddenOptions): Promise<string>;
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hidden prompt for secrets such as a password (MV-1542c step 1.1).
|
|
3
|
+
*
|
|
4
|
+
* Reads the terminal in raw mode so nothing is echoed and no readline
|
|
5
|
+
* interface (with its history and line buffer) ever sees the secret. The
|
|
6
|
+
* terminal is restored on success, Ctrl-C, Ctrl-D, input error and process
|
|
7
|
+
* exit. The typed value is returned to the caller only; it is never written
|
|
8
|
+
* anywhere here.
|
|
9
|
+
*/
|
|
10
|
+
export class PromptError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(code, message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = 'PromptError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const ESCAPE_SEQUENCE_RE = /\u001b(?:\[[0-9;?]*[ -/]*[@-~]|O[@-~]|[@-Z\\-_])/g;
|
|
19
|
+
export function promptHidden(question, options = {}) {
|
|
20
|
+
const input = options.input ?? process.stdin;
|
|
21
|
+
const output = options.output ?? process.stdout;
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
if (!input.isTTY || typeof input.setRawMode !== 'function') {
|
|
24
|
+
reject(new PromptError('NO_TTY', 'A hidden prompt needs an interactive terminal.'));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const wasRaw = input.isRaw === true;
|
|
28
|
+
let value = '';
|
|
29
|
+
let finished = false;
|
|
30
|
+
const restore = () => {
|
|
31
|
+
try {
|
|
32
|
+
input.setRawMode(wasRaw);
|
|
33
|
+
}
|
|
34
|
+
catch { /* terminal already gone */ }
|
|
35
|
+
};
|
|
36
|
+
const finish = (outcome) => {
|
|
37
|
+
if (finished)
|
|
38
|
+
return;
|
|
39
|
+
finished = true;
|
|
40
|
+
input.removeListener('data', onData);
|
|
41
|
+
input.removeListener('error', onError);
|
|
42
|
+
input.removeListener('end', onEnd);
|
|
43
|
+
process.removeListener('exit', restore);
|
|
44
|
+
restore();
|
|
45
|
+
if (!wasRaw)
|
|
46
|
+
input.pause();
|
|
47
|
+
value = '';
|
|
48
|
+
output.write('\n');
|
|
49
|
+
if ('ok' in outcome)
|
|
50
|
+
resolve(outcome.ok);
|
|
51
|
+
else
|
|
52
|
+
reject(outcome.err);
|
|
53
|
+
};
|
|
54
|
+
const onData = (chunk) => {
|
|
55
|
+
const text = (typeof chunk === 'string' ? chunk : chunk.toString('utf8')).replace(ESCAPE_SEQUENCE_RE, '');
|
|
56
|
+
for (const ch of text) {
|
|
57
|
+
if (ch === '\r' || ch === '\n') {
|
|
58
|
+
finish({ ok: value });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (ch === '\u0003') {
|
|
62
|
+
finish({ err: new PromptError('CANCELLED', 'Cancelled.') });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ch === '\u0004') {
|
|
66
|
+
if (value.length === 0)
|
|
67
|
+
finish({ err: new PromptError('CANCELLED', 'Cancelled.') });
|
|
68
|
+
else
|
|
69
|
+
finish({ ok: value });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (ch === '\u007f' || ch === '\b') {
|
|
73
|
+
const chars = Array.from(value);
|
|
74
|
+
chars.pop();
|
|
75
|
+
value = chars.join('');
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (ch < ' ')
|
|
79
|
+
continue;
|
|
80
|
+
value += ch;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const onError = () => finish({ err: new PromptError('INPUT_ERROR', 'Could not read from the terminal.') });
|
|
84
|
+
const onEnd = () => finish({ err: new PromptError('CANCELLED', 'Input closed before Enter.') });
|
|
85
|
+
try {
|
|
86
|
+
output.write(question);
|
|
87
|
+
input.setEncoding('utf8');
|
|
88
|
+
input.setRawMode(true);
|
|
89
|
+
process.once('exit', restore);
|
|
90
|
+
input.on('data', onData);
|
|
91
|
+
input.on('error', onError);
|
|
92
|
+
input.on('end', onEnd);
|
|
93
|
+
input.resume();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
finish({ err: new PromptError('INPUT_ERROR', 'Could not read from the terminal.') });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
package/dist/prompts.d.ts
CHANGED
|
@@ -185,7 +185,7 @@ export declare const EXPERIENCES: readonly [{
|
|
|
185
185
|
readonly name: "Run Sales";
|
|
186
186
|
readonly tier: 2;
|
|
187
187
|
readonly tierName: "The Operating System";
|
|
188
|
-
readonly action: "Part 1 — Discovery Brief: Say \"Prepare a discovery brief for a potential client.\" TACIT uses workspace knowledge to build a discovery framework. The brief should be a STYLED HTML REPORT using /artifact-design — same flow as Experience 7: invoke artifact-design, build the HTML, publish as a Claude artifact, save the file to disk, then ingest the HTML file via tacit_gm_ingest for placement. ONBOARDING PLACEMENT DEFAULT: If the user reached this experience through onboarding (the completed set includes your_first_structure), default to placing the output in their onboarding program — look up the \"Onboarding\" VS via tacit_pyramid_list_value_streams, then find their \"{Name}'s Onboarding Journey\" program via tacit_pyramid_list_programs filtered by that VS. Propose this program as the target; the user can override. Part 2 — Voice Composition: After the brief, draft an intro email using the TACIT Voice Resonance system. MANDATORY TWO-STEP FLOW: (1) GROUND FIRST — assemble the key facts from the discovery brief (prospect name, pain points, value proposition, relevant capabilities) into a structured plain-text brief. This is the content the voice system will work with. (2) COMPOSE IN VOICE — call tacit_voice_list_profiles to find the user's voice profile (it MUST exist — voice samples were pre-loaded). Then call tacit_compose_in_voice, passing the grounded-facts brief as the content
|
|
188
|
+
readonly action: "Part 1 — Discovery Brief: Say \"Prepare a discovery brief for a potential client.\" TACIT uses workspace knowledge to build a discovery framework. The brief should be a STYLED HTML REPORT using /artifact-design — same flow as Experience 7: invoke artifact-design, build the HTML, publish as a Claude artifact, save the file to disk, then ingest the HTML file via tacit_gm_ingest for placement. ONBOARDING PLACEMENT DEFAULT: If the user reached this experience through onboarding (the completed set includes your_first_structure), default to placing the output in their onboarding program — look up the \"Onboarding\" VS via tacit_pyramid_list_value_streams, then find their \"{Name}'s Onboarding Journey\" program via tacit_pyramid_list_programs filtered by that VS. Propose this program as the target; the user can override. Part 2 — Voice Composition: After the brief, draft an intro email using the TACIT Voice Resonance system. MANDATORY TWO-STEP FLOW: (1) GROUND FIRST — assemble the key facts from the discovery brief (prospect name, pain points, value proposition, relevant capabilities) into a structured plain-text brief. This is the content the voice system will work with. (2) COMPOSE IN VOICE — call tacit_voice_list_profiles to find the user's voice profile (it MUST exist — voice samples were pre-loaded). Then call tacit_compose_in_voice, passing the grounded-facts brief as the `content` argument (the instruction goes in `query`). This ensures the voice system has concrete facts instead of re-retrieving from workspace docs. This uses TACIT's actual voice fingerprinting system, NOT LLM approximation. NEVER draft the email yourself and claim it matches the user's voice. NEVER offer to \"paste a sample email\" or \"upload writing samples\" — voice profiles are already loaded. If tacit_voice_list_profiles returns no profiles, say \"I expected to find your voice profile but it is not set up yet — let me check with the team\" and move on.\n\nGROUNDING ENFORCEMENT: NEVER fabricate people names, meeting dates, verbatim quotes, financial figures, or technical specifications. Every claim in the discovery brief and email must be grounded in workspace data returned by TACIT tools. If the workspace has thin data on the prospect, produce an honest thin brief — state what is known, flag what is missing, and suggest how to fill the gaps. A short, honest brief is always better than a fabricated detailed one.";
|
|
189
189
|
readonly signal: "First sales deliverable as HTML report, then first voice-matched composition using TACIT Voice Resonance (not LLM approximation)";
|
|
190
190
|
readonly tip: "Voice Resonance is a real system — it analyzes your writing samples to capture your cadence, vocabulary, and patterns. Every \"in my voice\" request routes through this system.";
|
|
191
191
|
}, {
|
|
@@ -194,7 +194,7 @@ export declare const EXPERIENCES: readonly [{
|
|
|
194
194
|
readonly name: "Morning Brief";
|
|
195
195
|
readonly tier: 2;
|
|
196
196
|
readonly tierName: "The Operating System";
|
|
197
|
-
readonly action: "IMPORTANT — CONNECTOR DETECTION: Before running the brief, CHECK your available MCP tool list to determine what is connected. Gmail IS connected if you have mcp__claude_ai_Gmail__* tools available. Slack IS connected if you have mcp__plugin_*_slack__* tools. Calendar IS connected if you have mcp__claude_ai_Google_Calendar__* tools. Do NOT say \"Gmail not connected\" if you can see Gmail MCP tools — that is a false negative.\n\nSCOPE CHECK: After detecting connected tools, verify each connector belongs to the same organization as the workspace. If Slack channels or Gmail accounts reference a different company than the workspace name, exclude that connector data and explain why — say \"Your connected [tool] appears to belong to a different organization than [workspace name]. That data has been excluded to maintain workspace isolation.\" Only include connector data from the workspace-matched organization.\n\nRun the COS daily brief: gather workspace state (programs, deadlines, proposals, KB freshness), and for each connected tool, pull real data — Gmail threads, Slack channels, Calendar events. Present the full operating picture. If a connector genuinely has no MCP tools available, say \"not yet connected\" and explain how to connect via claude.ai Integrations. After the brief, offer to draft a team message in the user's voice. TWO-STEP VOICE FLOW (mandatory): (1) GROUND FIRST — assemble a structured brief of the key facts, numbers, and updates you gathered from the morning brief (programs, deadlines, email highlights, meeting items). Write this as plain text with concrete data points. (2) COMPOSE IN VOICE — call tacit_compose_in_voice, passing the grounded-facts brief as the content
|
|
197
|
+
readonly action: "IMPORTANT — CONNECTOR DETECTION: Before running the brief, CHECK your available MCP tool list to determine what is connected. Gmail IS connected if you have mcp__claude_ai_Gmail__* tools available. Slack IS connected if you have mcp__plugin_*_slack__* tools. Calendar IS connected if you have mcp__claude_ai_Google_Calendar__* tools. Do NOT say \"Gmail not connected\" if you can see Gmail MCP tools — that is a false negative.\n\nSCOPE CHECK: After detecting connected tools, verify each connector belongs to the same organization as the workspace. If Slack channels or Gmail accounts reference a different company than the workspace name, exclude that connector data and explain why — say \"Your connected [tool] appears to belong to a different organization than [workspace name]. That data has been excluded to maintain workspace isolation.\" Only include connector data from the workspace-matched organization.\n\nRun the COS daily brief: gather workspace state (programs, deadlines, proposals, KB freshness), and for each connected tool, pull real data — Gmail threads, Slack channels, Calendar events. Present the full operating picture. If a connector genuinely has no MCP tools available, say \"not yet connected\" and explain how to connect via claude.ai Integrations. After the brief, offer to draft a team message in the user's voice. TWO-STEP VOICE FLOW (mandatory): (1) GROUND FIRST — assemble a structured brief of the key facts, numbers, and updates you gathered from the morning brief (programs, deadlines, email highlights, meeting items). Write this as plain text with concrete data points. (2) COMPOSE IN VOICE — call tacit_compose_in_voice, passing the grounded-facts brief as the `content` argument (the instruction goes in `query`). This ensures the voice system has verified facts to work with instead of re-retrieving from workspace documents (which cannot see the live MCP query results you just gathered). NEVER skip step 1 and call tacit_compose_in_voice with just \"draft a team update\" — the voice system cannot access the live data you collected.";
|
|
198
198
|
readonly signal: "First daily operating picture with accurate connector status and real data from connected tools";
|
|
199
199
|
readonly tip: "Meet your executive team. COS (Chief of Staff — daily ops, email, meetings), COO (Chief Operating Officer — business ops, sales, audits), GM (General Manager — content ingestion, classification, pyramid placement). Address them by name to route through their workflow.";
|
|
200
200
|
}, {
|