@tacitai/mcp-server 0.8.1 → 0.9.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/claude-config.d.ts +2 -0
- package/dist/claude-config.js +5 -4
- package/dist/flags.js +1 -0
- package/dist/index.js +39 -8
- package/dist/setup.js +4 -3
- package/dist/templates/role-loader.js +1 -1
- package/dist/tools/chronicle.d.ts +14 -0
- package/dist/tools/chronicle.js +34 -1
- package/dist/tools/content-removal.d.ts +85 -0
- package/dist/tools/content-removal.js +251 -0
- package/dist/tools/exec-route.d.ts +28 -5
- package/dist/tools/exec-route.js +147 -14
- package/dist/tools/gm.d.ts +7 -0
- package/dist/tools/gm.js +11 -0
- package/dist/tools/move.d.ts +2 -2
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/registry.js +11 -3
- package/dist/tools/workflow-types.js +86 -11
- package/dist/transport.d.ts +9 -0
- package/dist/transport.js +13 -3
- package/dist/workflow-gate.d.ts +50 -3
- package/dist/workflow-gate.js +183 -6
- package/dist/workflow-registry.d.ts +31 -0
- package/dist/workflow-registry.js +36 -1
- package/dist/workflow-type-schema.d.ts +2 -2
- package/dist/workflow-type-schema.js +5 -0
- package/package.json +5 -5
package/dist/transport.js
CHANGED
|
@@ -74,6 +74,18 @@ function getClientIp(req) {
|
|
|
74
74
|
?? req.socket.remoteAddress
|
|
75
75
|
?? 'unknown';
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Workflow-gate / autonomy principal for an authenticated HTTP request (FEAT-271 M1).
|
|
79
|
+
* OAuth principals are scoped by workspace (`${user_email}:${workspace_id}`) so the same
|
|
80
|
+
* user in two workspaces never shares gate state; bearer tokens are already per workspace.
|
|
81
|
+
*/
|
|
82
|
+
export function httpPrincipalOf(auth) {
|
|
83
|
+
if (auth.type === 'oauth') {
|
|
84
|
+
const { user_email, workspace_id } = auth.info;
|
|
85
|
+
return workspace_id ? `${user_email}:${workspace_id}` : user_email;
|
|
86
|
+
}
|
|
87
|
+
return createHash('sha256').update(auth.token).digest('hex').slice(0, 16);
|
|
88
|
+
}
|
|
77
89
|
export async function startHttpTransport(server) {
|
|
78
90
|
const port = Number.parseInt(process.env['MCP_HTTPS_PORT'] ?? '8319', 10);
|
|
79
91
|
const apiUrl = (process.env['TACIT_API_URL'] ?? 'http://127.0.0.1:7473').replace(/\/$/, '');
|
|
@@ -166,9 +178,7 @@ export async function startHttpTransport(server) {
|
|
|
166
178
|
return;
|
|
167
179
|
}
|
|
168
180
|
const requestToken = auth.type === 'oauth' ? auth.info.tacit_token : auth.token;
|
|
169
|
-
const principal = auth
|
|
170
|
-
? auth.info.user_email
|
|
171
|
-
: createHash('sha256').update(auth.token).digest('hex').slice(0, 16);
|
|
181
|
+
const principal = httpPrincipalOf(auth);
|
|
172
182
|
const run = async () => {
|
|
173
183
|
const transport = new StreamableHTTPServerTransport({
|
|
174
184
|
sessionIdGenerator: undefined,
|
package/dist/workflow-gate.d.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Scoping (AC-isolation): one gate per server process. State is keyed by caller
|
|
11
11
|
* principal — on the HTTP transport `getRequestPrincipal()` returns the bearer-token
|
|
12
|
-
* principal (AsyncLocalStorage); on stdio it
|
|
13
|
-
*
|
|
12
|
+
* principal (AsyncLocalStorage, `${user_email}:${workspace_id}` for OAuth); on stdio it
|
|
13
|
+
* returns null and every call shares the '__stdio__' slot, suffixed with the active
|
|
14
|
+
* workspace id (`stdioWorkspace` option) so `tacit_switch_workspace` moves the session
|
|
15
|
+
* to a separate key and each workspace keeps its own instances.
|
|
14
16
|
*/
|
|
15
17
|
import { WorkflowRegistry } from './workflow-registry.js';
|
|
16
18
|
import { type AutonomyLevel as _AutonomyLevel } from './client.js';
|
|
@@ -76,6 +78,8 @@ export interface WorkflowGateOpts {
|
|
|
76
78
|
onEvent?: (event: WorkflowChronicleEvent) => void;
|
|
77
79
|
persistence?: WorkflowPersistencePort;
|
|
78
80
|
autonomyResolver?: (principal: string) => AutonomyLevel;
|
|
81
|
+
/** stdio only: the active workspace id; scopes the '__stdio__' key per workspace. */
|
|
82
|
+
stdioWorkspace?: () => string | null | undefined;
|
|
79
83
|
}
|
|
80
84
|
export interface StartWorkflowOpts {
|
|
81
85
|
artifactId?: string;
|
|
@@ -106,6 +110,7 @@ export declare class WorkflowGate {
|
|
|
106
110
|
private readonly onEvent;
|
|
107
111
|
private readonly persistencePort?;
|
|
108
112
|
private readonly autonomyResolver?;
|
|
113
|
+
private readonly stdioWorkspace?;
|
|
109
114
|
private readonly states;
|
|
110
115
|
private totalInstances;
|
|
111
116
|
private readonly restoredPrincipals;
|
|
@@ -185,6 +190,23 @@ export declare class WorkflowGate {
|
|
|
185
190
|
phase: string;
|
|
186
191
|
blockedTool: string;
|
|
187
192
|
} & Partial<GateVerdict>) | null;
|
|
193
|
+
/**
|
|
194
|
+
* FEAT-271 W3: refuse a tool while one of the principal's active instances denies it.
|
|
195
|
+
* Two rules, both read from the system type definition only:
|
|
196
|
+
* - `denyWhileActive` lists raw tools refused for the whole life of the instance;
|
|
197
|
+
* - `enforcePhaseOrder` refuses a tool whose first owning phase is after the current one.
|
|
198
|
+
* Called in the pre-call hook before recordCallForAll/routeToolCall. Returns null when allowed.
|
|
199
|
+
*/
|
|
200
|
+
checkDeniedWhileActive(principal: string | null, toolName: string, args?: Record<string, unknown>): GateVerdict & {
|
|
201
|
+
error: string;
|
|
202
|
+
instanceId?: string;
|
|
203
|
+
} | null;
|
|
204
|
+
/**
|
|
205
|
+
* FEAT-271 W3: a domain tool (e.g. tacit_removal_approve) releases the approval gate of the
|
|
206
|
+
* principal's active instance of `typeName` when that instance is in `phaseName`.
|
|
207
|
+
* Returns the released instance id, or null if no such instance.
|
|
208
|
+
*/
|
|
209
|
+
releaseApprovalGate(principal: string | null, typeName: string, phaseName: string, bindValue?: string): string | null;
|
|
188
210
|
/**
|
|
189
211
|
* Check whether a tool is gated by any registered phased workflow type, even when
|
|
190
212
|
* the caller has no active instance (first-contact rejection).
|
|
@@ -197,11 +219,36 @@ export declare class WorkflowGate {
|
|
|
197
219
|
* routeToolCall miss and checkColdToolBlock.
|
|
198
220
|
*/
|
|
199
221
|
autoStartForTool(principal: string | null, toolName: string): WorkflowInstance | null;
|
|
222
|
+
/**
|
|
223
|
+
* FEAT-271 W3: post-call counterpart of autoStartForTool for `startOnSuccess` types. The pre-call
|
|
224
|
+
* hook calls it only after the phase-0 tool's handler succeeded, so a failed call (403, 404,
|
|
225
|
+
* flag off, error) leaves no instance. Records the call on the new instance.
|
|
226
|
+
*/
|
|
227
|
+
autoStartAfterSuccess(principal: string | null, toolName: string, args?: Record<string, unknown>): WorkflowInstance | null;
|
|
228
|
+
private autoStartMatching;
|
|
200
229
|
/**
|
|
201
230
|
* Record a tool call for ALL active instances that include this tool in their
|
|
202
231
|
* type definition. For legacy GM callers, the 2-arg recordCall below also works.
|
|
203
232
|
*/
|
|
204
|
-
recordCallForAll(principal: string | null, toolName: string): void;
|
|
233
|
+
recordCallForAll(principal: string | null, toolName: string, args?: Record<string, unknown>): void;
|
|
234
|
+
/**
|
|
235
|
+
* FEAT-271 W3: post-call record for `recordOnSuccess` tools; the hook calls it only when the
|
|
236
|
+
* handler succeeded. Other tools are untouched (they are recorded pre-call by recordCallForAll).
|
|
237
|
+
*/
|
|
238
|
+
recordSuccessForAll(principal: string | null, toolName: string, args?: Record<string, unknown>): void;
|
|
239
|
+
/**
|
|
240
|
+
* FEAT-271 W3: bind the principal's first active, unbound instance of `typeName` to a backend
|
|
241
|
+
* request id (stored under the type's bindMetadataKey). Returns the bound instance id, or null.
|
|
242
|
+
*/
|
|
243
|
+
bindInstance(principal: string | null, typeName: string, value: string): string | null;
|
|
244
|
+
/** FEAT-271 W3: deactivate only the instances of `typeName` bound to `value`. Returns how many. */
|
|
245
|
+
deactivateBound(principal: string | null, typeName: string, value: string): number;
|
|
246
|
+
/**
|
|
247
|
+
* FEAT-271 W3: does this call belong to the instance? True when the type has no binding key, or
|
|
248
|
+
* the call carries no value for it (e.g. footprint, propose). A call naming a request id belongs
|
|
249
|
+
* only to the instance bound to that same id; an unbound instance owns no request yet.
|
|
250
|
+
*/
|
|
251
|
+
private callMatchesBinding;
|
|
205
252
|
recordCall(principal: string | null, toolName: string): void;
|
|
206
253
|
startWorkflow(principal: string | null, opts: {
|
|
207
254
|
artifactId: string;
|
package/dist/workflow-gate.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Scoping (AC-isolation): one gate per server process. State is keyed by caller
|
|
11
11
|
* principal — on the HTTP transport `getRequestPrincipal()` returns the bearer-token
|
|
12
|
-
* principal (AsyncLocalStorage); on stdio it
|
|
13
|
-
*
|
|
12
|
+
* principal (AsyncLocalStorage, `${user_email}:${workspace_id}` for OAuth); on stdio it
|
|
13
|
+
* returns null and every call shares the '__stdio__' slot, suffixed with the active
|
|
14
|
+
* workspace id (`stdioWorkspace` option) so `tacit_switch_workspace` moves the session
|
|
15
|
+
* to a separate key and each workspace keeps its own instances.
|
|
14
16
|
*/
|
|
15
17
|
import { createDefaultRegistry, PYRAMID_PREREQ_TOOLS as _PYRAMID_PREREQ_TOOLS, KB_PREREQ_TOOL as _KB_PREREQ_TOOL, } from './workflow-registry.js';
|
|
16
18
|
import { getCachedAutonomy as _getCachedAutonomyFromClient, autonomyAtLeast, } from './client.js';
|
|
@@ -40,6 +42,7 @@ export class WorkflowGate {
|
|
|
40
42
|
onEvent;
|
|
41
43
|
persistencePort;
|
|
42
44
|
autonomyResolver;
|
|
45
|
+
stdioWorkspace;
|
|
43
46
|
states = new Map();
|
|
44
47
|
totalInstances = 0;
|
|
45
48
|
restoredPrincipals = new Set();
|
|
@@ -60,6 +63,7 @@ export class WorkflowGate {
|
|
|
60
63
|
this.onEvent = maxPrincipalsOrOpts.onEvent ?? (() => { });
|
|
61
64
|
this.persistencePort = maxPrincipalsOrOpts.persistence;
|
|
62
65
|
this.autonomyResolver = maxPrincipalsOrOpts.autonomyResolver;
|
|
66
|
+
this.stdioWorkspace = maxPrincipalsOrOpts.stdioWorkspace;
|
|
63
67
|
}
|
|
64
68
|
else {
|
|
65
69
|
this.registry = createDefaultRegistry();
|
|
@@ -73,7 +77,10 @@ export class WorkflowGate {
|
|
|
73
77
|
return this.registry;
|
|
74
78
|
}
|
|
75
79
|
keyOf(principal) {
|
|
76
|
-
|
|
80
|
+
if (principal !== null)
|
|
81
|
+
return principal;
|
|
82
|
+
const ws = this.stdioWorkspace?.();
|
|
83
|
+
return ws ? `__stdio__:${ws}` : '__stdio__';
|
|
77
84
|
}
|
|
78
85
|
getCachedAutonomy(principal) {
|
|
79
86
|
if (this.autonomyResolver)
|
|
@@ -108,8 +115,8 @@ export class WorkflowGate {
|
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
117
|
checkToolAutonomy(principal, toolName) {
|
|
111
|
-
|
|
112
|
-
const current = this.getCachedAutonomy(
|
|
118
|
+
// Autonomy is cached under the unscoped principal (index.ts ensureAutonomy), not the gate key.
|
|
119
|
+
const current = this.getCachedAutonomy(principal ?? '__stdio__');
|
|
113
120
|
if (!current)
|
|
114
121
|
return null; // not yet resolved — ensureAutonomy must be called first
|
|
115
122
|
if (!autonomyAtLeast(current, 'SCRIBE')) {
|
|
@@ -631,6 +638,88 @@ export class WorkflowGate {
|
|
|
631
638
|
}
|
|
632
639
|
return null;
|
|
633
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* FEAT-271 W3: refuse a tool while one of the principal's active instances denies it.
|
|
643
|
+
* Two rules, both read from the system type definition only:
|
|
644
|
+
* - `denyWhileActive` lists raw tools refused for the whole life of the instance;
|
|
645
|
+
* - `enforcePhaseOrder` refuses a tool whose first owning phase is after the current one.
|
|
646
|
+
* Called in the pre-call hook before recordCallForAll/routeToolCall. Returns null when allowed.
|
|
647
|
+
*/
|
|
648
|
+
checkDeniedWhileActive(principal, toolName, args) {
|
|
649
|
+
const map = this.states.get(this.keyOf(principal));
|
|
650
|
+
if (!map)
|
|
651
|
+
return null;
|
|
652
|
+
for (const inst of map.values()) {
|
|
653
|
+
if (!inst.active)
|
|
654
|
+
continue;
|
|
655
|
+
const typeDef = this.registry.get(inst.typeRef);
|
|
656
|
+
if (!typeDef)
|
|
657
|
+
continue;
|
|
658
|
+
const phases = typeDef.prereqs.kind === 'phased' ? typeDef.prereqs.phases : [];
|
|
659
|
+
const currentPhase = phases[inst.currentPhase]?.name;
|
|
660
|
+
if (typeDef.denyWhileActive?.includes(toolName)) {
|
|
661
|
+
return {
|
|
662
|
+
error: 'denied_while_active',
|
|
663
|
+
allowed: false,
|
|
664
|
+
missing: [],
|
|
665
|
+
workflowType: typeDef.name,
|
|
666
|
+
currentPhase,
|
|
667
|
+
message: `Tool ${toolName} is refused while a ${typeDef.name} workflow (${inst.instanceId}) is active. Use the workflow's own tools, or end it with tacit_workflow_deactivate first.`,
|
|
668
|
+
userMessage: `${toolName} is not allowed during an active ${typeDef.name} workflow.`,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
// A call naming another request (e.g. retry, restore or cancel of an older removal) is not
|
|
672
|
+
// this instance's step: the backend state machine enforces that request's order.
|
|
673
|
+
if (typeDef.enforcePhaseOrder && phases.length > 0 && this.callMatchesBinding(inst, typeDef, args)) {
|
|
674
|
+
const owner = phases.findIndex((p) => p.requiredTools.includes(toolName) || p.gatedTools.includes(toolName));
|
|
675
|
+
if (owner > inst.currentPhase) {
|
|
676
|
+
const pending = phases.slice(inst.currentPhase, owner).map((p) => p.name);
|
|
677
|
+
const missing = phases[inst.currentPhase].requiredTools.filter((t) => !inst.callLog.has(t));
|
|
678
|
+
return {
|
|
679
|
+
error: 'phase_order',
|
|
680
|
+
allowed: false,
|
|
681
|
+
missing,
|
|
682
|
+
workflowType: typeDef.name,
|
|
683
|
+
currentPhase,
|
|
684
|
+
instanceId: inst.instanceId,
|
|
685
|
+
message: `Tool ${toolName} belongs to the ${phases[owner].name} phase of ${typeDef.name}; the workflow is in the ${currentPhase} phase. Complete ${pending.join(' → ')} first (tacit_workflow_advance with instanceId "${inst.instanceId}" between phases).`,
|
|
686
|
+
userMessage: `Complete the ${pending.join(' → ')} step(s) before ${phases[owner].name}.`,
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* FEAT-271 W3: a domain tool (e.g. tacit_removal_approve) releases the approval gate of the
|
|
695
|
+
* principal's active instance of `typeName` when that instance is in `phaseName`.
|
|
696
|
+
* Returns the released instance id, or null if no such instance.
|
|
697
|
+
*/
|
|
698
|
+
releaseApprovalGate(principal, typeName, phaseName, bindValue) {
|
|
699
|
+
const key = this.keyOf(principal);
|
|
700
|
+
const map = this.states.get(key);
|
|
701
|
+
if (!map)
|
|
702
|
+
return null;
|
|
703
|
+
for (const inst of map.values()) {
|
|
704
|
+
if (!inst.active || inst.typeRef !== typeName)
|
|
705
|
+
continue;
|
|
706
|
+
const typeDef = this.registry.get(inst.typeRef);
|
|
707
|
+
if (typeDef?.prereqs.kind !== 'phased')
|
|
708
|
+
continue;
|
|
709
|
+
// Bound instances release only for their own request.
|
|
710
|
+
if (typeDef.bindMetadataKey && bindValue !== undefined && inst.metadata[typeDef.bindMetadataKey] !== bindValue)
|
|
711
|
+
continue;
|
|
712
|
+
if (typeDef.prereqs.phases[inst.currentPhase]?.name !== phaseName)
|
|
713
|
+
continue;
|
|
714
|
+
inst.phaseApproved = true;
|
|
715
|
+
if (inst.paused) {
|
|
716
|
+
inst.paused = false;
|
|
717
|
+
this.emitEvent('workflow.phase.resumed', inst, key, { releasedBy: 'domain_tool' });
|
|
718
|
+
}
|
|
719
|
+
return inst.instanceId;
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
634
723
|
/**
|
|
635
724
|
* Check whether a tool is gated by any registered phased workflow type, even when
|
|
636
725
|
* the caller has no active instance (first-contact rejection).
|
|
@@ -666,10 +755,26 @@ export class WorkflowGate {
|
|
|
666
755
|
* routeToolCall miss and checkColdToolBlock.
|
|
667
756
|
*/
|
|
668
757
|
autoStartForTool(principal, toolName) {
|
|
758
|
+
return this.autoStartMatching(principal, toolName, false);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* FEAT-271 W3: post-call counterpart of autoStartForTool for `startOnSuccess` types. The pre-call
|
|
762
|
+
* hook calls it only after the phase-0 tool's handler succeeded, so a failed call (403, 404,
|
|
763
|
+
* flag off, error) leaves no instance. Records the call on the new instance.
|
|
764
|
+
*/
|
|
765
|
+
autoStartAfterSuccess(principal, toolName, args) {
|
|
766
|
+
const inst = this.autoStartMatching(principal, toolName, true);
|
|
767
|
+
if (inst)
|
|
768
|
+
this.recordCallForAll(principal, toolName, args);
|
|
769
|
+
return inst;
|
|
770
|
+
}
|
|
771
|
+
autoStartMatching(principal, toolName, startOnSuccess) {
|
|
669
772
|
const candidates = [];
|
|
670
773
|
for (const typeDef of this.registry.list()) {
|
|
671
774
|
if (typeDef.prereqs.kind !== 'phased')
|
|
672
775
|
continue;
|
|
776
|
+
if (!!typeDef.startOnSuccess !== startOnSuccess)
|
|
777
|
+
continue;
|
|
673
778
|
if (!isWorkflowTypeActive(typeDef.name))
|
|
674
779
|
continue;
|
|
675
780
|
const phase0 = typeDef.prereqs.phases[0];
|
|
@@ -688,7 +793,7 @@ export class WorkflowGate {
|
|
|
688
793
|
* Record a tool call for ALL active instances that include this tool in their
|
|
689
794
|
* type definition. For legacy GM callers, the 2-arg recordCall below also works.
|
|
690
795
|
*/
|
|
691
|
-
recordCallForAll(principal, toolName) {
|
|
796
|
+
recordCallForAll(principal, toolName, args) {
|
|
692
797
|
const map = this.states.get(this.keyOf(principal));
|
|
693
798
|
if (!map)
|
|
694
799
|
return;
|
|
@@ -696,10 +801,82 @@ export class WorkflowGate {
|
|
|
696
801
|
for (const inst of map.values()) {
|
|
697
802
|
if (!inst.active)
|
|
698
803
|
continue;
|
|
804
|
+
const typeDef = this.registry.get(inst.typeRef);
|
|
805
|
+
if (typeDef) {
|
|
806
|
+
// FEAT-271 W3: success-only tools are recorded post-call (recordSuccessForAll).
|
|
807
|
+
if (typeDef.recordOnSuccess?.includes(toolName))
|
|
808
|
+
continue;
|
|
809
|
+
if (!this.callMatchesBinding(inst, typeDef, args))
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
699
812
|
inst.callLog.set(toolName, (inst.callLog.get(toolName) ?? 0) + 1);
|
|
700
813
|
inst.lastActivityAt = now;
|
|
701
814
|
}
|
|
702
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* FEAT-271 W3: post-call record for `recordOnSuccess` tools; the hook calls it only when the
|
|
818
|
+
* handler succeeded. Other tools are untouched (they are recorded pre-call by recordCallForAll).
|
|
819
|
+
*/
|
|
820
|
+
recordSuccessForAll(principal, toolName, args) {
|
|
821
|
+
const map = this.states.get(this.keyOf(principal));
|
|
822
|
+
if (!map)
|
|
823
|
+
return;
|
|
824
|
+
const now = Date.now();
|
|
825
|
+
for (const inst of map.values()) {
|
|
826
|
+
if (!inst.active)
|
|
827
|
+
continue;
|
|
828
|
+
const typeDef = this.registry.get(inst.typeRef);
|
|
829
|
+
if (!typeDef?.recordOnSuccess?.includes(toolName))
|
|
830
|
+
continue;
|
|
831
|
+
if (!this.callMatchesBinding(inst, typeDef, args))
|
|
832
|
+
continue;
|
|
833
|
+
inst.callLog.set(toolName, (inst.callLog.get(toolName) ?? 0) + 1);
|
|
834
|
+
inst.lastActivityAt = now;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* FEAT-271 W3: bind the principal's first active, unbound instance of `typeName` to a backend
|
|
839
|
+
* request id (stored under the type's bindMetadataKey). Returns the bound instance id, or null.
|
|
840
|
+
*/
|
|
841
|
+
bindInstance(principal, typeName, value) {
|
|
842
|
+
const typeDef = this.registry.get(typeName);
|
|
843
|
+
const key = typeDef?.bindMetadataKey;
|
|
844
|
+
if (!key)
|
|
845
|
+
return null;
|
|
846
|
+
for (const inst of this.getInstancesByType(principal, typeName)) {
|
|
847
|
+
if (!inst.active || inst.metadata[key] !== undefined)
|
|
848
|
+
continue;
|
|
849
|
+
inst.metadata[key] = value;
|
|
850
|
+
return inst.instanceId;
|
|
851
|
+
}
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
/** FEAT-271 W3: deactivate only the instances of `typeName` bound to `value`. Returns how many. */
|
|
855
|
+
deactivateBound(principal, typeName, value) {
|
|
856
|
+
const key = this.registry.get(typeName)?.bindMetadataKey;
|
|
857
|
+
if (!key)
|
|
858
|
+
return 0;
|
|
859
|
+
let n = 0;
|
|
860
|
+
for (const inst of this.getInstancesByType(principal, typeName)) {
|
|
861
|
+
if (inst.metadata[key] === value && this.deactivateWorkflow(principal, inst.instanceId))
|
|
862
|
+
n++;
|
|
863
|
+
}
|
|
864
|
+
return n;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* FEAT-271 W3: does this call belong to the instance? True when the type has no binding key, or
|
|
868
|
+
* the call carries no value for it (e.g. footprint, propose). A call naming a request id belongs
|
|
869
|
+
* only to the instance bound to that same id; an unbound instance owns no request yet.
|
|
870
|
+
*/
|
|
871
|
+
callMatchesBinding(inst, typeDef, args) {
|
|
872
|
+
const key = typeDef.bindMetadataKey;
|
|
873
|
+
if (!key)
|
|
874
|
+
return true;
|
|
875
|
+
const value = args?.[key];
|
|
876
|
+
if (value === undefined || value === null || value === '')
|
|
877
|
+
return true;
|
|
878
|
+
return inst.metadata[key] === value;
|
|
879
|
+
}
|
|
703
880
|
// ── Legacy 2-arg API (GM backwards compatibility) ────────────────────────
|
|
704
881
|
recordCall(principal, toolName) {
|
|
705
882
|
const inst = this.findOrCreateGmInstance(principal);
|
|
@@ -47,6 +47,36 @@ export interface WorkflowTypeDef {
|
|
|
47
47
|
resumeMode?: 'tool' | 'skill-preamble';
|
|
48
48
|
guidance?: string;
|
|
49
49
|
maxInstances?: number;
|
|
50
|
+
/** FEAT-272 D1: newline-delimited tool-call step list for dynamic user types (buildScript fallthrough). */
|
|
51
|
+
scriptTemplate?: string;
|
|
52
|
+
/** FEAT-272 D2: human-readable guidance text for dynamic user types (GUIDANCE_MAP fallthrough). */
|
|
53
|
+
guidanceText?: string;
|
|
54
|
+
/**
|
|
55
|
+
* FEAT-271 W3: tools refused for the principal while an instance of this type is active
|
|
56
|
+
* (checkDeniedWhileActive, called in the pre-call hook before routeToolCall). System types only.
|
|
57
|
+
*/
|
|
58
|
+
denyWhileActive?: readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* FEAT-271 W3: refuse a tool whose first owning phase is later than the instance's current
|
|
61
|
+
* phase (e.g. execute before approve). System types only.
|
|
62
|
+
*/
|
|
63
|
+
enforcePhaseOrder?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* FEAT-271 W3: start the instance only after the phase-0 tool's handler succeeds (post-call),
|
|
66
|
+
* instead of auto-starting it before the call. A failed first call leaves no instance. System types only.
|
|
67
|
+
*/
|
|
68
|
+
startOnSuccess?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* FEAT-271 W3: metadata key that binds an instance to one backend request (e.g. removal_id).
|
|
71
|
+
* Once bound, phase order and call recording apply only to calls whose argument of the same
|
|
72
|
+
* name matches; calls naming another request bypass the instance. System types only.
|
|
73
|
+
*/
|
|
74
|
+
bindMetadataKey?: string;
|
|
75
|
+
/**
|
|
76
|
+
* FEAT-271 W3: tools that count toward requiredTools only when their handler succeeded
|
|
77
|
+
* (recorded post-call instead of pre-call). System types only.
|
|
78
|
+
*/
|
|
79
|
+
recordOnSuccess?: readonly string[];
|
|
50
80
|
}
|
|
51
81
|
export declare const GM_TYPE_DEF: WorkflowTypeDef;
|
|
52
82
|
export declare class WorkflowRegistry {
|
|
@@ -85,4 +115,5 @@ export declare const SECURITY_AUDIT_TYPE_DEF: WorkflowTypeDef;
|
|
|
85
115
|
export declare const SECRET_ROTATION_TYPE_DEF: WorkflowTypeDef;
|
|
86
116
|
export declare const CAREER_APPLICATION_TYPE_DEF: WorkflowTypeDef;
|
|
87
117
|
export declare const VOICE_COMPOSE_TYPE_DEF: WorkflowTypeDef;
|
|
118
|
+
export declare const CONTENT_REMOVAL_TYPE_DEF: WorkflowTypeDef;
|
|
88
119
|
export declare function createDefaultRegistry(): WorkflowRegistry;
|
|
@@ -298,9 +298,13 @@ export const RESEARCH_TYPE_DEF = {
|
|
|
298
298
|
{ name: 'plan_approval', requiredTools: [], gatedTools: ['tacit_research_launch'], approvalGate: true, guidance: 'RESEARCH_PLAN_APPROVAL' },
|
|
299
299
|
{ name: 'dispatch', requiredTools: ['tacit_research_launch'], gatedTools: [], approvalGate: false, guidance: 'RESEARCH_DISPATCH' },
|
|
300
300
|
{ name: 'synthesis', requiredTools: [], gatedTools: [], approvalGate: false, guidance: 'RESEARCH_SYNTHESIS' },
|
|
301
|
-
{ name: '
|
|
301
|
+
{ name: 'handoff', requiredTools: [], gatedTools: [], approvalGate: false, guidance: 'RESEARCH_HANDOFF' },
|
|
302
302
|
],
|
|
303
303
|
},
|
|
304
|
+
handoff: {
|
|
305
|
+
targetTypes: ['gm_content_placement'],
|
|
306
|
+
preserveParent: true,
|
|
307
|
+
},
|
|
304
308
|
persistent: true,
|
|
305
309
|
ttlDays: 7,
|
|
306
310
|
failDirection: 'open',
|
|
@@ -459,6 +463,36 @@ export const VOICE_COMPOSE_TYPE_DEF = {
|
|
|
459
463
|
guidance: 'VOICE_COMPOSE',
|
|
460
464
|
maxInstances: 3,
|
|
461
465
|
};
|
|
466
|
+
// ─── Content Removal type definition (FEAT-271 W3) ─────────────────────────
|
|
467
|
+
// The backend state machine (409 on illegal transitions) is the real enforcement; this type
|
|
468
|
+
// orders the steps for an agent inside one MCP session. tacit_removal_approve releases the
|
|
469
|
+
// approve gate. tacit_pyramid_update_dossier is deliberately NOT denied: general dossier
|
|
470
|
+
// edits must keep working while a removal is in flight.
|
|
471
|
+
export const CONTENT_REMOVAL_TYPE_DEF = {
|
|
472
|
+
name: 'gm_content_removal',
|
|
473
|
+
entryTool: null,
|
|
474
|
+
prereqs: {
|
|
475
|
+
kind: 'phased',
|
|
476
|
+
phases: [
|
|
477
|
+
{ name: 'discover', requiredTools: ['tacit_content_footprint'], gatedTools: [], approvalGate: false, guidance: 'CONTENT_REMOVAL_DISCOVER' },
|
|
478
|
+
{ name: 'propose', requiredTools: ['tacit_removal_propose'], gatedTools: [], approvalGate: false, guidance: 'CONTENT_REMOVAL_PROPOSE' },
|
|
479
|
+
{ name: 'approve', requiredTools: ['tacit_removal_approve'], gatedTools: [], approvalGate: true, guidance: 'CONTENT_REMOVAL_APPROVE' },
|
|
480
|
+
{ name: 'execute', requiredTools: ['tacit_removal_execute'], gatedTools: [], approvalGate: false, guidance: 'CONTENT_REMOVAL_EXECUTE' },
|
|
481
|
+
{ name: 'verify', requiredTools: ['tacit_removal_verify'], gatedTools: [], approvalGate: false, guidance: 'CONTENT_REMOVAL_VERIFY' },
|
|
482
|
+
],
|
|
483
|
+
},
|
|
484
|
+
denyWhileActive: ['tacit_artifact_delete', 'tacit_chronicle_exclude_event', 'tacit_lake_delete_catalog_item'],
|
|
485
|
+
enforcePhaseOrder: true,
|
|
486
|
+
startOnSuccess: true,
|
|
487
|
+
bindMetadataKey: 'removal_id',
|
|
488
|
+
// FEAT-271 L2: a refused propose (e.g. 409 active_removal_exists) must not satisfy the propose phase.
|
|
489
|
+
recordOnSuccess: ['tacit_removal_propose', 'tacit_removal_approve'],
|
|
490
|
+
persistent: false,
|
|
491
|
+
failDirection: 'closed',
|
|
492
|
+
sharedToolPolicy: 'passthrough',
|
|
493
|
+
guidance: 'GM_CONTENT_REMOVAL',
|
|
494
|
+
maxInstances: 1,
|
|
495
|
+
};
|
|
462
496
|
// ─── Factory ────────────────────────────────────────────────────────────────
|
|
463
497
|
export function createDefaultRegistry() {
|
|
464
498
|
const registry = new WorkflowRegistry();
|
|
@@ -480,5 +514,6 @@ export function createDefaultRegistry() {
|
|
|
480
514
|
registry.register(SECRET_ROTATION_TYPE_DEF);
|
|
481
515
|
registry.register(CAREER_APPLICATION_TYPE_DEF);
|
|
482
516
|
registry.register(VOICE_COMPOSE_TYPE_DEF);
|
|
517
|
+
registry.register(CONTENT_REMOVAL_TYPE_DEF);
|
|
483
518
|
return registry;
|
|
484
519
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Hand-written TS validation for user-authored workflow type definitions (MV-1539 W7 Step 29).
|
|
3
3
|
* No ajv dependency — validation is structural checks only.
|
|
4
4
|
*/
|
|
5
|
-
export declare const SYSTEM_RESERVED_TYPE_NAMES: readonly ["gm_content_placement", "cos_coordination", "pyr_exec", "coo_operations", "cmo_marketing_pipeline", "sales_full_pipeline", "research_exec", "wiki_authoring", "kb_management", "lake_operations", "cto_engineering", "secretary_chronicle"];
|
|
6
|
-
export declare const SYSTEM_RESERVED_TOOLS: readonly ["tacit_gm_ingest", "tacit_gm_approve", "tacit_gm_reset", "tacit_kb_promote_from_artifact", "tacit_kb_promote_from_catalog", "tacit_cmo_lint", "tacit_dispatch_crew", "tacit_research_launch", "tacit_research_prepare", "tacit_research_place", "tacit_secretary_log", "tacit_secretary_recall"];
|
|
5
|
+
export declare const SYSTEM_RESERVED_TYPE_NAMES: readonly ["gm_content_placement", "cos_coordination", "pyr_exec", "coo_operations", "cmo_marketing_pipeline", "sales_full_pipeline", "research_exec", "wiki_authoring", "kb_management", "lake_operations", "cto_engineering", "secretary_chronicle", "gm_content_removal"];
|
|
6
|
+
export declare const SYSTEM_RESERVED_TOOLS: readonly ["tacit_gm_ingest", "tacit_gm_approve", "tacit_gm_reset", "tacit_kb_promote_from_artifact", "tacit_kb_promote_from_catalog", "tacit_cmo_lint", "tacit_dispatch_crew", "tacit_research_launch", "tacit_research_prepare", "tacit_research_place", "tacit_secretary_log", "tacit_secretary_recall", "tacit_content_footprint", "tacit_removal_propose", "tacit_removal_approve", "tacit_removal_execute", "tacit_removal_verify", "tacit_removal_restore", "tacit_removal_list", "tacit_chronicle_exclude_event"];
|
|
7
7
|
export interface UserTypeValidationResult {
|
|
8
8
|
valid: boolean;
|
|
9
9
|
errors: string[];
|
|
@@ -7,6 +7,7 @@ export const SYSTEM_RESERVED_TYPE_NAMES = [
|
|
|
7
7
|
'coo_operations', 'cmo_marketing_pipeline', 'sales_full_pipeline', 'research_exec',
|
|
8
8
|
'wiki_authoring', 'kb_management', 'lake_operations',
|
|
9
9
|
'cto_engineering', 'secretary_chronicle',
|
|
10
|
+
'gm_content_removal',
|
|
10
11
|
];
|
|
11
12
|
export const SYSTEM_RESERVED_TOOLS = [
|
|
12
13
|
'tacit_gm_ingest', 'tacit_gm_approve', 'tacit_gm_reset',
|
|
@@ -14,6 +15,10 @@ export const SYSTEM_RESERVED_TOOLS = [
|
|
|
14
15
|
'tacit_cmo_lint', 'tacit_dispatch_crew',
|
|
15
16
|
'tacit_research_launch', 'tacit_research_prepare', 'tacit_research_place',
|
|
16
17
|
'tacit_secretary_log', 'tacit_secretary_recall',
|
|
18
|
+
// FEAT-271: removal workflow tools must never appear in user-authored workflow types.
|
|
19
|
+
'tacit_content_footprint', 'tacit_removal_propose', 'tacit_removal_approve',
|
|
20
|
+
'tacit_removal_execute', 'tacit_removal_verify', 'tacit_removal_restore',
|
|
21
|
+
'tacit_removal_list', 'tacit_chronicle_exclude_event',
|
|
17
22
|
];
|
|
18
23
|
const TYPE_NAME_PATTERN = /^[a-z][a-z0-9_]{2,63}$/;
|
|
19
24
|
export function validateUserTypeDef(input) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tacitai/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "stdio MCP server wrapping Tacit /api/v1 REST/SSE API",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "SEE LICENSE IN ../../LICENSE",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "git+https://github.com/scottkmcmillan/tacit.git",
|
|
@@ -42,8 +45,5 @@
|
|
|
42
45
|
"@types/semver": "^7.5.0",
|
|
43
46
|
"typescript": "^5.4.0",
|
|
44
47
|
"vitest": "^4.1.7"
|
|
45
|
-
},
|
|
46
|
-
"publishConfig": {
|
|
47
|
-
"access": "public"
|
|
48
48
|
}
|
|
49
49
|
}
|