@tacitai/mcp-server 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/api-errors.d.ts +102 -0
  2. package/dist/api-errors.js +165 -0
  3. package/dist/autonomy.d.ts +46 -0
  4. package/dist/autonomy.js +118 -0
  5. package/dist/claude-config.d.ts +139 -0
  6. package/dist/claude-config.js +339 -0
  7. package/dist/cli-launch.d.ts +33 -0
  8. package/dist/cli-launch.js +178 -0
  9. package/dist/cli-login.d.ts +34 -0
  10. package/dist/cli-login.js +200 -0
  11. package/dist/cli-mode.d.ts +47 -0
  12. package/dist/cli-mode.js +170 -0
  13. package/dist/cli-profiles.d.ts +37 -0
  14. package/dist/cli-profiles.js +344 -0
  15. package/dist/cli.d.ts +9 -0
  16. package/dist/cli.js +59 -458
  17. package/dist/client.d.ts +90 -52
  18. package/dist/client.js +198 -296
  19. package/dist/credentials.d.ts +81 -0
  20. package/dist/credentials.js +291 -0
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +37 -89
  23. package/dist/oauth.d.ts +1 -1
  24. package/dist/oauth.js +5 -5
  25. package/dist/profile-store.d.ts +96 -0
  26. package/dist/profile-store.js +382 -0
  27. package/dist/prompt.d.ts +32 -0
  28. package/dist/prompt.js +99 -0
  29. package/dist/prompts.d.ts +2 -2
  30. package/dist/prompts.js +3 -3
  31. package/dist/server-mode.d.ts +65 -0
  32. package/dist/server-mode.js +99 -0
  33. package/dist/setup-migrate.d.ts +35 -0
  34. package/dist/setup-migrate.js +204 -0
  35. package/dist/setup.d.ts +41 -66
  36. package/dist/setup.js +361 -531
  37. package/dist/signin.d.ts +108 -0
  38. package/dist/signin.js +595 -0
  39. package/dist/tools/agents.d.ts +6 -4
  40. package/dist/tools/agents.js +15 -4
  41. package/dist/tools/artifacts.d.ts +2 -0
  42. package/dist/tools/artifacts.js +8 -1
  43. package/dist/tools/capture.js +2 -2
  44. package/dist/tools/career.js +2 -2
  45. package/dist/tools/chronicle.js +7 -7
  46. package/dist/tools/crews.js +8 -8
  47. package/dist/tools/errors.d.ts +18 -0
  48. package/dist/tools/errors.js +73 -1
  49. package/dist/tools/exec-route.d.ts +34 -0
  50. package/dist/tools/exec-route.js +101 -27
  51. package/dist/tools/github.js +2 -2
  52. package/dist/tools/gm.js +2 -2
  53. package/dist/tools/iam.js +2 -3
  54. package/dist/tools/kb.js +2 -2
  55. package/dist/tools/lake-structure.js +8 -8
  56. package/dist/tools/lake.js +2 -2
  57. package/dist/tools/onboarding.js +2 -2
  58. package/dist/tools/people.js +7 -7
  59. package/dist/tools/pyramid.js +2 -2
  60. package/dist/tools/recall.js +2 -2
  61. package/dist/tools/secretary.d.ts +1 -0
  62. package/dist/tools/secretary.js +2 -1
  63. package/dist/tools/synthesize.d.ts +37 -0
  64. package/dist/tools/synthesize.js +128 -9
  65. package/dist/tools/voice.d.ts +3 -2
  66. package/dist/tools/voice.js +70 -18
  67. package/dist/tools/wiki.js +2 -2
  68. package/dist/tools/workspaces.js +20 -6
  69. package/dist/version.d.ts +6 -0
  70. package/dist/version.js +18 -0
  71. package/dist/workflow-registry.d.ts +1 -0
  72. package/dist/workflow-registry.js +21 -0
  73. package/package.json +4 -1
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { z } from 'zod';
13
13
  import { getClient, TacitApiError, TokenExpiredError } from '../client.js';
14
- import { featureDisabledResult } from './errors.js';
14
+ import { featureDisabledResult, apiErrorText } from './errors.js';
15
15
  import { loadRoleTemplates } from '../templates/role-loader.js';
16
16
  function apiErrorResult(err, toolName) {
17
17
  if (err instanceof TokenExpiredError) {
@@ -24,11 +24,19 @@ function apiErrorResult(err, toolName) {
24
24
  const disabled = featureDisabledResult(err);
25
25
  if (disabled)
26
26
  return disabled;
27
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
27
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
28
28
  }
29
29
  const msg = err instanceof Error ? err.message : String(err);
30
30
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
31
31
  }
32
+ /** True for the "agents table does not exist" failure: a 404, or a 5xx whose body says the table/relation is missing. */
33
+ export function isMissingAgentsTable(err) {
34
+ if (!(err instanceof TacitApiError))
35
+ return false;
36
+ if (err.statusCode === 404)
37
+ return true;
38
+ return err.statusCode >= 500 && /business_agents|relation .* does not exist|table .* (does not exist|missing)/i.test(err.body);
39
+ }
32
40
  async function callAgentTool(client, name, args) {
33
41
  return client.post('/api/v1/agents/mcp/tools/call', { name, arguments: args });
34
42
  }
@@ -65,8 +73,11 @@ export function buildAgentListRequest(client, input) {
65
73
  if (Array.isArray(list))
66
74
  instances = list;
67
75
  }
68
- catch {
69
- // business_agents table may not exist (migration 349 RESERVED)
76
+ catch (e) {
77
+ // Only a missing business_agents table (migration 349 RESERVED) falls back to templates.
78
+ // Membership and auth errors (401/403, removed member) must reach the caller.
79
+ if (!isMissingAgentsTable(e))
80
+ throw e;
70
81
  }
71
82
  const merged = templates.map((t) => {
72
83
  const inst = instances.find((i) => i['role_slug'] === t.slug);
@@ -417,4 +417,6 @@ export declare function handleArtifactDelete(args: unknown): Promise<{
417
417
  }>;
418
418
  isError?: boolean;
419
419
  }>;
420
+ /** Share links made by a non-JWT credential expire (D-83, AR-11); a browser link has `expires_at: null`. Always show the field. */
421
+ export declare function withExpiresAt(data: unknown): unknown;
420
422
  export declare function registerArtifactTools(server: McpServer, getClientFn: () => Promise<TacitClient>): void;
@@ -459,6 +459,13 @@ export async function handleArtifactDelete(args) {
459
459
  }
460
460
  return buildArtifactDeleteRequest(getClient(), parsed.data).execute();
461
461
  }
462
+ /** Share links made by a non-JWT credential expire (D-83, AR-11); a browser link has `expires_at: null`. Always show the field. */
463
+ export function withExpiresAt(data) {
464
+ if (!data || typeof data !== 'object' || Array.isArray(data))
465
+ return data;
466
+ const obj = data;
467
+ return { ...obj, expires_at: obj['expires_at'] ?? null };
468
+ }
462
469
  export function registerArtifactTools(server, getClientFn) {
463
470
  server.tool('tacit_artifact_list', 'List/search artifacts from the Tacit workspace. Route: GET /api/v1/artifacts.', {
464
471
  q: z.string().optional().describe('Full-text search over title and body'),
@@ -581,7 +588,7 @@ export function registerArtifactTools(server, getClientFn) {
581
588
  try {
582
589
  const client = await getClientFn();
583
590
  const data = await client.post(`/api/v1/artifacts/${args.artifact_id}/share-token`, {});
584
- return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
591
+ return { content: [{ type: 'text', text: JSON.stringify(withExpiresAt(data), null, 2) }] };
585
592
  }
586
593
  catch (err) {
587
594
  return apiErrorResult(err, `/api/v1/artifacts/${args.artifact_id}/share-token`);
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { z } from 'zod';
13
13
  import { TacitApiError, TokenExpiredError } from '../client.js';
14
- import { featureDisabledResult } from './errors.js';
14
+ import { apiErrorText, featureDisabledResult } from './errors.js';
15
15
  function apiErrorResult(err, toolName) {
16
16
  if (err instanceof TokenExpiredError) {
17
17
  return { content: [{ type: 'text', text: err.message }], isError: true };
@@ -20,7 +20,7 @@ function apiErrorResult(err, toolName) {
20
20
  const disabled = featureDisabledResult(err);
21
21
  if (disabled)
22
22
  return disabled;
23
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
23
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
24
24
  }
25
25
  const msg = err instanceof Error ? err.message : String(err);
26
26
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -18,7 +18,7 @@
18
18
  import { z } from 'zod';
19
19
  import dns from 'node:dns/promises';
20
20
  import { TacitApiError, TokenExpiredError } from '../client.js';
21
- import { featureDisabledResult } from './errors.js';
21
+ import { apiErrorText, featureDisabledResult } from './errors.js';
22
22
  function flagGuard() {
23
23
  if (process.env['FEATURE_CAREER_EXEC'] === 'true')
24
24
  return null;
@@ -38,7 +38,7 @@ function apiErrorResult(err, toolName) {
38
38
  const disabled = featureDisabledResult(err);
39
39
  if (disabled)
40
40
  return disabled;
41
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
41
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
42
42
  }
43
43
  const msg = err instanceof Error ? err.message : String(err);
44
44
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { TacitApiError } from '../client.js';
2
+ import { TacitApiError, TokenExpiredError } from '../client.js';
3
3
  import { success, error, featureDisabledResult } from './errors.js';
4
4
  export function registerChronicleTools(server, getClient) {
5
5
  server.tool('tacit_chronicle_timeline', 'Query the Chronicle timeline with date range, scope, and text filters.', {
@@ -39,7 +39,7 @@ export function registerChronicleTools(server, getClient) {
39
39
  return success(data);
40
40
  }
41
41
  catch (e) {
42
- if (e instanceof TacitApiError)
42
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
43
43
  return featureDisabledResult(e) ?? error(e.message);
44
44
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
45
45
  }
@@ -72,7 +72,7 @@ export function registerChronicleTools(server, getClient) {
72
72
  return success(data);
73
73
  }
74
74
  catch (e) {
75
- if (e instanceof TacitApiError)
75
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
76
76
  return featureDisabledResult(e) ?? error(e.message);
77
77
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
78
78
  }
@@ -98,7 +98,7 @@ export function registerChronicleTools(server, getClient) {
98
98
  return success(data);
99
99
  }
100
100
  catch (e) {
101
- if (e instanceof TacitApiError)
101
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
102
102
  return featureDisabledResult(e) ?? error(e.message);
103
103
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
104
104
  }
@@ -120,7 +120,7 @@ export function registerChronicleTools(server, getClient) {
120
120
  return success(data);
121
121
  }
122
122
  catch (e) {
123
- if (e instanceof TacitApiError)
123
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
124
124
  return featureDisabledResult(e) ?? error(e.message);
125
125
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
126
126
  }
@@ -143,7 +143,7 @@ export function registerChronicleTools(server, getClient) {
143
143
  return success(data);
144
144
  }
145
145
  catch (e) {
146
- if (e instanceof TacitApiError)
146
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
147
147
  return featureDisabledResult(e) ?? error(e.message);
148
148
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
149
149
  }
@@ -157,7 +157,7 @@ export function registerChronicleTools(server, getClient) {
157
157
  return success(data);
158
158
  }
159
159
  catch (e) {
160
- if (e instanceof TacitApiError)
160
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
161
161
  return featureDisabledResult(e) ?? error(e.message);
162
162
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
163
163
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { TacitApiError } from '../client.js';
2
+ import { TacitApiError, TokenExpiredError } from '../client.js';
3
3
  import { success, error, featureDisabledResult } from './errors.js';
4
4
  export function registerCrewTools(server, getClient) {
5
5
  server.tool('tacit_dispatch_crew', 'Dispatch a crew for autonomous task execution.', {
@@ -11,7 +11,7 @@ export function registerCrewTools(server, getClient) {
11
11
  return success(data);
12
12
  }
13
13
  catch (e) {
14
- if (e instanceof TacitApiError)
14
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
15
15
  return featureDisabledResult(e) ?? error(e.message);
16
16
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
17
17
  }
@@ -25,7 +25,7 @@ export function registerCrewTools(server, getClient) {
25
25
  return success(data);
26
26
  }
27
27
  catch (e) {
28
- if (e instanceof TacitApiError)
28
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
29
29
  return featureDisabledResult(e) ?? error(e.message);
30
30
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
31
31
  }
@@ -40,7 +40,7 @@ export function registerCrewTools(server, getClient) {
40
40
  return success(data);
41
41
  }
42
42
  catch (e) {
43
- if (e instanceof TacitApiError)
43
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
44
44
  return featureDisabledResult(e) ?? error(e.message);
45
45
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
46
46
  }
@@ -58,7 +58,7 @@ export function registerCrewTools(server, getClient) {
58
58
  return success(data);
59
59
  }
60
60
  catch (e) {
61
- if (e instanceof TacitApiError)
61
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
62
62
  return featureDisabledResult(e) ?? error(e.message);
63
63
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
64
64
  }
@@ -76,7 +76,7 @@ export function registerCrewTools(server, getClient) {
76
76
  return success(data);
77
77
  }
78
78
  catch (e) {
79
- if (e instanceof TacitApiError)
79
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
80
80
  return featureDisabledResult(e) ?? error(e.message);
81
81
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
82
82
  }
@@ -90,7 +90,7 @@ export function registerCrewTools(server, getClient) {
90
90
  return success(data);
91
91
  }
92
92
  catch (e) {
93
- if (e instanceof TacitApiError)
93
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
94
94
  return featureDisabledResult(e) ?? error(e.message);
95
95
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
96
96
  }
@@ -107,7 +107,7 @@ export function registerCrewTools(server, getClient) {
107
107
  return success(data);
108
108
  }
109
109
  catch (e) {
110
- if (e instanceof TacitApiError)
110
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
111
111
  return featureDisabledResult(e) ?? error(e.message);
112
112
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
113
113
  }
@@ -1,3 +1,4 @@
1
+ import { TacitApiError } from '../client.js';
1
2
  type ToolResult = {
2
3
  content: Array<{
3
4
  type: 'text';
@@ -12,6 +13,23 @@ export declare function error(message: string): ToolResult & {
12
13
  export declare function featureDisabledResult(err: unknown): (ToolResult & {
13
14
  isError: true;
14
15
  }) | null;
16
+ /** The member was removed from the workspace (403 ACCOUNT_DISABLED / MEMBERSHIP_INACTIVE, 401 MEMBERSHIP_NOT_FOUND). */
17
+ export declare class AccessRemovedError extends Error {
18
+ readonly workspace: string | null;
19
+ constructor(workspace?: string | null);
20
+ }
21
+ /** Server error code from a JSON error body ({"error":{"code"}}, {"code"} or {"error":"CODE"}). */
22
+ export declare function errorCodeOfBody(body: string): string | null;
23
+ /**
24
+ * The AccessRemovedError for an API failure, or null. A removed member is a 403 with a
25
+ * removal code; a 401 MEMBERSHIP_NOT_FOUND reaches tools as TokenExpiredError with the same code.
26
+ */
27
+ export declare function accessRemovedFrom(err: unknown): AccessRemovedError | null;
28
+ /**
29
+ * Text for a failed API call: the access-removed / api-errors.ts message when the table has one,
30
+ * otherwise "API error <status> [on <endpoint>]: <body>". Shared by every tool's error handler.
31
+ */
32
+ export declare function apiErrorText(err: TacitApiError, endpoint?: string): string;
15
33
  export declare function apiErrorResult(err: unknown, endpoint: string): ToolResult & {
16
34
  isError: boolean;
17
35
  };
@@ -1,4 +1,5 @@
1
1
  import { TacitApiError, TokenExpiredError } from '../client.js';
2
+ import { accessRemoved, isAccessRemovedCode, messageForResponse } from '../api-errors.js';
2
3
  export function success(data) {
3
4
  return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
4
5
  }
@@ -23,6 +24,77 @@ export function featureDisabledResult(err) {
23
24
  }
24
25
  return error(`Feature disabled: ${parsed.error.message || 'unknown reason'}`);
25
26
  }
27
+ /** The member was removed from the workspace (403 ACCOUNT_DISABLED / MEMBERSHIP_INACTIVE, 401 MEMBERSHIP_NOT_FOUND). */
28
+ export class AccessRemovedError extends Error {
29
+ workspace;
30
+ constructor(workspace = null) {
31
+ super(accessRemoved({ workspace }));
32
+ this.workspace = workspace;
33
+ this.name = 'AccessRemovedError';
34
+ }
35
+ }
36
+ /** Server error code from a JSON error body ({"error":{"code"}}, {"code"} or {"error":"CODE"}). */
37
+ export function errorCodeOfBody(body) {
38
+ try {
39
+ const parsed = JSON.parse(body);
40
+ const nested = parsed.error;
41
+ if (nested && typeof nested === 'object' && typeof nested.code === 'string') {
42
+ return nested.code;
43
+ }
44
+ if (typeof parsed.code === 'string')
45
+ return parsed.code;
46
+ if (typeof nested === 'string')
47
+ return nested;
48
+ }
49
+ catch {
50
+ // Not JSON.
51
+ }
52
+ return null;
53
+ }
54
+ function reasonOfBody(body) {
55
+ try {
56
+ const parsed = JSON.parse(body);
57
+ if (typeof parsed.reason === 'string')
58
+ return parsed.reason;
59
+ const nested = parsed.error;
60
+ if (nested && typeof nested === 'object' && typeof nested.reason === 'string') {
61
+ return nested.reason;
62
+ }
63
+ }
64
+ catch {
65
+ // Not JSON.
66
+ }
67
+ return null;
68
+ }
69
+ /**
70
+ * The AccessRemovedError for an API failure, or null. A removed member is a 403 with a
71
+ * removal code; a 401 MEMBERSHIP_NOT_FOUND reaches tools as TokenExpiredError with the same code.
72
+ */
73
+ export function accessRemovedFrom(err) {
74
+ if (err instanceof TokenExpiredError) {
75
+ return isAccessRemovedCode(err.code) ? new AccessRemovedError(err.workspace) : null;
76
+ }
77
+ if (err instanceof TacitApiError && err.statusCode === 403) {
78
+ return isAccessRemovedCode(errorCodeOfBody(err.body)) ? new AccessRemovedError(err.workspace) : null;
79
+ }
80
+ return null;
81
+ }
82
+ /**
83
+ * Text for a failed API call: the access-removed / api-errors.ts message when the table has one,
84
+ * otherwise "API error <status> [on <endpoint>]: <body>". Shared by every tool's error handler.
85
+ */
86
+ export function apiErrorText(err, endpoint) {
87
+ const removed = accessRemovedFrom(err);
88
+ if (removed)
89
+ return removed.message;
90
+ const mapped = messageForResponse(err.statusCode, errorCodeOfBody(err.body), {
91
+ workspace: err.workspace,
92
+ reason: reasonOfBody(err.body),
93
+ });
94
+ if (mapped)
95
+ return mapped;
96
+ return `API error ${err.statusCode}${endpoint ? ` on ${endpoint}` : ''}: ${err.body}`;
97
+ }
26
98
  export function apiErrorResult(err, endpoint) {
27
99
  if (err instanceof TokenExpiredError) {
28
100
  return {
@@ -34,7 +106,7 @@ export function apiErrorResult(err, endpoint) {
34
106
  const disabled = featureDisabledResult(err);
35
107
  if (disabled)
36
108
  return disabled;
37
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${endpoint}: ${err.body}` }], isError: true };
109
+ return { content: [{ type: 'text', text: apiErrorText(err, endpoint) }], isError: true };
38
110
  }
39
111
  const msg = err instanceof Error ? err.message : String(err);
40
112
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -21,6 +21,40 @@ export declare function matchRole(request: string): {
21
21
  role_slug: string;
22
22
  reason: string;
23
23
  }>;
24
+ defaulted?: boolean;
25
+ };
26
+ /** BUG-418: "in my voice" requests route to the voice_compose overlay (ADR-212). */
27
+ export declare const VOICE_INTENT_RE: RegExp;
28
+ /** The user is rewriting text they supplied, as opposed to asking for new material. */
29
+ export declare const REWRITE_INTENT_RE: RegExp;
30
+ export interface OverlayWorkflowType {
31
+ /** Must be a type registered in createDefaultRegistry (checked by verify-exec-roles.sh). */
32
+ name: string;
33
+ pattern: RegExp;
34
+ /** For these base workflow types the overlay applies only when the request is a rewrite of supplied text. */
35
+ rewriteOnlyFor?: readonly string[];
36
+ }
37
+ /** ADR-212: intent overlays. Adding one needs an amendment to the ADR. */
38
+ export declare const OVERLAY_WORKFLOW_TYPES: readonly OverlayWorkflowType[];
39
+ export interface RouteResult {
40
+ role_slug: string;
41
+ present_as: string;
42
+ workflow_type: string;
43
+ description: string;
44
+ first_tool: string;
45
+ script: string[];
46
+ alternatives?: Array<{
47
+ role_slug: string;
48
+ reason: string;
49
+ }>;
50
+ overlay_skipped?: {
51
+ overlay: string;
52
+ reason: string;
53
+ };
54
+ }
55
+ /** Pure routing: role from role_hint or matchRole; workflow_type overridden to voice_compose on voice intent. */
56
+ export declare function routeRequest(request: string, roleHint?: string): RouteResult | {
57
+ error: string;
24
58
  };
25
59
  export declare function registerExecRouteTool(server: McpServer): void;
26
60
  export {};
@@ -7,6 +7,7 @@
7
7
  * imperative next-step script the LLM can follow deterministically.
8
8
  */
9
9
  import { z } from 'zod';
10
+ import { createDefaultRegistry } from '../workflow-registry.js';
10
11
  export const ROLE_ROUTES = [
11
12
  {
12
13
  slug: 'general_manager',
@@ -134,6 +135,7 @@ export function matchRole(request) {
134
135
  return {
135
136
  primary: ROLE_ROUTES.find((r) => r.slug === 'general_manager'),
136
137
  alternatives: [],
138
+ defaulted: true,
137
139
  };
138
140
  }
139
141
  const primary = scores[0].route;
@@ -143,8 +145,68 @@ export function matchRole(request) {
143
145
  }));
144
146
  return { primary, alternatives };
145
147
  }
146
- function buildScript(role) {
148
+ /** BUG-418: "in my voice" requests route to the voice_compose overlay (ADR-212). */
149
+ export const VOICE_INTENT_RE = /\b(in my voice|in my style|my writing voice)\b/i;
150
+ /** The user is rewriting text they supplied, as opposed to asking for new material. */
151
+ export const REWRITE_INTENT_RE = /\b(rewrit\w*|rephras\w*|revis\w*|edit(s|ed|ing)?|polish\w*|redo)\b/i;
152
+ /** ADR-212: intent overlays. Adding one needs an amendment to the ADR. */
153
+ export const OVERLAY_WORKFLOW_TYPES = [
154
+ { name: 'voice_compose', pattern: VOICE_INTENT_RE, rewriteOnlyFor: ['career_application'] },
155
+ ];
156
+ const overlayRegistry = createDefaultRegistry();
157
+ /**
158
+ * ADR-212 Decision 2: a workflow type is gated if failDirection is 'closed', terminalAction is set
159
+ * (gatedChecks is declared but never read by WorkflowGate, so it gates nothing), a flat prereqs.tools list is non-empty, or any phase has approvalGate,
160
+ * gatedTools or requiredMetadata. An unregistered type is gated (fail-closed). Read from the registry.
161
+ * Returns the reason, or null when ungated.
162
+ */
163
+ function gatedReason(workflowType) {
164
+ const def = overlayRegistry.get(workflowType);
165
+ const t = `role workflow '${workflowType}'`;
166
+ const inside = "call the overlay's compose tool inside its own produce step";
167
+ if (!def)
168
+ return `${t} is not registered, so it cannot be verified as ungated (fail-closed)`;
169
+ if (def.failDirection === 'closed')
170
+ return `${t} fails closed; ${inside}`;
171
+ if (def.terminalAction)
172
+ return `${t} has a terminal action (${def.terminalAction.tool}); ${inside}`;
173
+ if (def.prereqs.kind === 'flat') {
174
+ return def.prereqs.tools.length > 0
175
+ ? `${t} requires prerequisite tools (${def.prereqs.tools.join(', ')}); ${inside}`
176
+ : null;
177
+ }
178
+ const phase = def.prereqs.phases.find((p) => p.approvalGate === true || p.gatedTools.length > 0 || p.requiredMetadata !== undefined);
179
+ return phase ? `${t} is a gated pipeline (phase '${phase.name}'); ${inside}` : null;
180
+ }
181
+ function applyOverlay(request, baseType, defaulted = false) {
182
+ for (const o of OVERLAY_WORKFLOW_TYPES) {
183
+ if (!o.pattern.test(request))
184
+ continue;
185
+ const gated = defaulted ? null : gatedReason(baseType);
186
+ if (gated)
187
+ return { skipped: { overlay: o.name, reason: gated } };
188
+ if (o.rewriteOnlyFor?.includes(baseType) && !REWRITE_INTENT_RE.test(request)) {
189
+ return { skipped: { overlay: o.name, reason: `'${baseType}' crews already apply the user's voice when generating new material; the overlay applies only to rewriting supplied text` } };
190
+ }
191
+ return { overlay: o };
192
+ }
193
+ return {};
194
+ }
195
+ function overlayFirstTool(name) {
196
+ const def = overlayRegistry.get(name);
197
+ if (def?.prereqs.kind !== 'phased')
198
+ return undefined;
199
+ return def.prereqs.phases.flatMap((p) => p.requiredTools)[0];
200
+ }
201
+ function buildScript(role, workflowType = role.workflow_type) {
147
202
  const steps = [];
203
+ if (workflowType === 'voice_compose') {
204
+ steps.push('1. Call tacit_voice_list_profiles and confirm a profile with voice_active true exists. If none exists, tell the user a voice profile needs 3+ samples and stop.');
205
+ steps.push('2. Assemble the grounded source text yourself (the draft, letter or facts to rewrite). Do not invent facts.');
206
+ steps.push('3. Call tacit_compose_in_voice with the grounded text in `content` and the instruction in `query`. Omit `content` only for KB-grounded drafts.');
207
+ steps.push('4. If the result has voice_match_degraded true, or the tool returns an error, show the user and stop for review. Never draft text yourself and claim it matches their voice.');
208
+ return steps;
209
+ }
148
210
  if (role.workflow_type === 'cto_engineering') {
149
211
  steps.push('CTO routes to the Agentic Engineering Exec. Call tacit_agent_delegate with role_slug="cto_engineer" and describe the engineering request.');
150
212
  steps.push('For new role creation: the AE Exec workflow guides through domain analysis → enforcement type selection → registration → verification.');
@@ -198,39 +260,51 @@ function buildScript(role) {
198
260
  steps.push('Check tacit_workflow_prereqs if a tool returns a workflow block — it shows required prior steps.');
199
261
  return steps;
200
262
  }
263
+ /** Pure routing: role from role_hint or matchRole; workflow_type overridden to voice_compose on voice intent. */
264
+ export function routeRequest(request, roleHint) {
265
+ let primary;
266
+ let alternatives = [];
267
+ let defaulted = false;
268
+ if (roleHint) {
269
+ const found = ROLE_ROUTES.find((r) => r.slug === roleHint);
270
+ if (!found) {
271
+ const slugs = ROLE_ROUTES.map((r) => r.slug).join(', ');
272
+ return { error: `Unknown role_hint: ${roleHint}. Available: ${slugs}` };
273
+ }
274
+ primary = found;
275
+ }
276
+ else {
277
+ const match = matchRole(request);
278
+ primary = match.primary;
279
+ alternatives = match.alternatives;
280
+ defaulted = match.defaulted === true;
281
+ }
282
+ // ADR-212 exception: no keyword matched, so GM is only the triage default, not a chosen gated role.
283
+ const { overlay, skipped } = applyOverlay(request, primary.workflow_type, defaulted);
284
+ const workflowType = overlay ? overlay.name : primary.workflow_type;
285
+ const firstTool = (overlay && overlayFirstTool(overlay.name))
286
+ || (primary.slug === 'researcher' ? 'tacit_research_prepare' : 'tacit_agent_delegate');
287
+ return {
288
+ role_slug: primary.slug,
289
+ present_as: primary.present_as,
290
+ workflow_type: workflowType,
291
+ description: primary.description,
292
+ first_tool: firstTool,
293
+ script: buildScript(primary, workflowType),
294
+ ...(skipped ? { overlay_skipped: skipped } : {}),
295
+ ...(alternatives.length > 0 ? { alternatives } : {}),
296
+ };
297
+ }
201
298
  export function registerExecRouteTool(server) {
202
299
  server.tool('tacit_exec_route', 'Route a business request to the right executive role. Returns the role, workflow type, and a step-by-step script of tools to call. Use this as the first step for any business request.', {
203
300
  request: z.string().min(1).describe('Natural language description of what you want to do'),
204
301
  role_hint: z.string().optional().describe('If you already know the role slug, pass it here to skip matching'),
205
302
  }, async (args) => {
206
303
  const { request, role_hint } = args;
207
- let primary;
208
- let alternatives = [];
209
- if (role_hint) {
210
- const found = ROLE_ROUTES.find((r) => r.slug === role_hint);
211
- if (!found) {
212
- const slugs = ROLE_ROUTES.map((r) => r.slug).join(', ');
213
- return {
214
- content: [{ type: 'text', text: JSON.stringify({ error: `Unknown role_hint: ${role_hint}. Available: ${slugs}` }) }],
215
- isError: true,
216
- };
217
- }
218
- primary = found;
304
+ const result = routeRequest(request, role_hint);
305
+ if ('error' in result) {
306
+ return { content: [{ type: 'text', text: JSON.stringify(result) }], isError: true };
219
307
  }
220
- else {
221
- const match = matchRole(request);
222
- primary = match.primary;
223
- alternatives = match.alternatives;
224
- }
225
- const result = {
226
- role_slug: primary.slug,
227
- present_as: primary.present_as,
228
- workflow_type: primary.workflow_type,
229
- description: primary.description,
230
- first_tool: primary.slug === 'researcher' ? 'tacit_research_prepare' : 'tacit_agent_delegate',
231
- script: buildScript(primary),
232
- ...(alternatives.length > 0 ? { alternatives } : {}),
233
- };
234
308
  return {
235
309
  content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
236
310
  };
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { z } from 'zod';
11
11
  import { TacitApiError, TokenExpiredError } from '../client.js';
12
- import { featureDisabledResult } from './errors.js';
12
+ import { apiErrorText, featureDisabledResult } from './errors.js';
13
13
  function apiErrorResult(err, toolName) {
14
14
  if (err instanceof TokenExpiredError) {
15
15
  return { content: [{ type: 'text', text: err.message }], isError: true };
@@ -18,7 +18,7 @@ function apiErrorResult(err, toolName) {
18
18
  const disabled = featureDisabledResult(err);
19
19
  if (disabled)
20
20
  return disabled;
21
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
21
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
22
22
  }
23
23
  const msg = err instanceof Error ? err.message : String(err);
24
24
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
package/dist/tools/gm.js CHANGED
@@ -10,7 +10,7 @@ import * as fs from 'fs';
10
10
  import * as path from 'path';
11
11
  import { z } from 'zod';
12
12
  import { TacitClient, TacitApiError, TokenExpiredError, getRequestPrincipal } from '../client.js';
13
- import { featureDisabledResult } from './errors.js';
13
+ import { apiErrorText, featureDisabledResult } from './errors.js';
14
14
  import { GM_APPROVE_NEXT_STEP } from '../workflow-gate.js';
15
15
  function apiErrorResult(err, toolName) {
16
16
  if (err instanceof TokenExpiredError) {
@@ -23,7 +23,7 @@ function apiErrorResult(err, toolName) {
23
23
  const disabled = featureDisabledResult(err);
24
24
  if (disabled)
25
25
  return disabled;
26
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
26
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
27
27
  }
28
28
  const msg = err instanceof Error ? err.message : String(err);
29
29
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
package/dist/tools/iam.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import { success, apiErrorResult } from './errors.js';
3
3
  export function registerIamTools(server, getClient) {
4
- server.tool('tacit_iam_grant_membership', 'Add a member to the workspace with an optional role, display name, and initial PIN', {
4
+ server.tool('tacit_iam_grant_membership', 'Add a member to the workspace with an optional role and display name', {
5
5
  email: z.string().describe('Email address of the new member'),
6
6
  role: z.string().optional().describe('Role to assign (e.g. "member", "admin")'),
7
7
  display_name: z.string().optional().describe('Display name for the member'),
8
- initial_pin: z.string().optional().describe('Initial login PIN'),
9
8
  }, async (args) => {
10
9
  try {
11
10
  const client = await getClient();
@@ -100,7 +99,7 @@ export function registerIamTools(server, getClient) {
100
99
  server.tool('tacit_iam_create_approval', 'Create an approval proof for a sensitive operation (offboard, transfer ownership)', {
101
100
  operation_type: z.string().describe('Type of operation requiring approval'),
102
101
  target_user_id: z.string().describe('ID of the user the operation targets'),
103
- pin: z.string().describe('Caller PIN for verification'),
102
+ pin: z.string().describe('Caller password for verification'),
104
103
  }, async (args) => {
105
104
  try {
106
105
  const client = await getClient();
package/dist/tools/kb.js CHANGED
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import { z } from 'zod';
15
15
  import { getClient, getRequestPrincipal, TacitApiError, TokenExpiredError } from '../client.js';
16
- import { apiErrorResult as sharedApiErrorResult, featureDisabledResult } from './errors.js';
16
+ import { apiErrorResult as sharedApiErrorResult, featureDisabledResult, apiErrorText } from './errors.js';
17
17
  import { GM_LIST_TOOL_NEXT_STEP } from '../workflow-gate.js';
18
18
  function apiErrorResult(err, toolName) {
19
19
  if (err instanceof TokenExpiredError) {
@@ -26,7 +26,7 @@ function apiErrorResult(err, toolName) {
26
26
  const disabled = featureDisabledResult(err);
27
27
  if (disabled)
28
28
  return disabled;
29
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
29
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
30
30
  }
31
31
  const msg = err instanceof Error ? err.message : String(err);
32
32
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };