@blxzer/cursor-trellis-core 0.4.2 → 0.5.0-beta.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.
Files changed (98) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/task/adapter-middleware.d.ts +118 -0
  6. package/dist/task/adapter-middleware.d.ts.map +1 -0
  7. package/dist/task/adapter-middleware.js +508 -0
  8. package/dist/task/adapter-middleware.js.map +1 -0
  9. package/dist/task/contract-migrate.d.ts +29 -0
  10. package/dist/task/contract-migrate.d.ts.map +1 -0
  11. package/dist/task/contract-migrate.js +207 -0
  12. package/dist/task/contract-migrate.js.map +1 -0
  13. package/dist/task/full-quality.d.ts +89 -0
  14. package/dist/task/full-quality.d.ts.map +1 -0
  15. package/dist/task/full-quality.js +379 -0
  16. package/dist/task/full-quality.js.map +1 -0
  17. package/dist/task/index.d.ts +22 -0
  18. package/dist/task/index.d.ts.map +1 -1
  19. package/dist/task/index.js +11 -0
  20. package/dist/task/index.js.map +1 -1
  21. package/dist/task/kernel-cli.d.ts +44 -0
  22. package/dist/task/kernel-cli.d.ts.map +1 -0
  23. package/dist/task/kernel-cli.js +287 -0
  24. package/dist/task/kernel-cli.js.map +1 -0
  25. package/dist/task/kernel-contract.d.ts +113 -0
  26. package/dist/task/kernel-contract.d.ts.map +1 -0
  27. package/dist/task/kernel-contract.js +332 -0
  28. package/dist/task/kernel-contract.js.map +1 -0
  29. package/dist/task/kernel-store.d.ts +99 -0
  30. package/dist/task/kernel-store.d.ts.map +1 -0
  31. package/dist/task/kernel-store.js +735 -0
  32. package/dist/task/kernel-store.js.map +1 -0
  33. package/dist/task/kernel-surface.d.ts +39 -0
  34. package/dist/task/kernel-surface.d.ts.map +1 -0
  35. package/dist/task/kernel-surface.js +73 -0
  36. package/dist/task/kernel-surface.js.map +1 -0
  37. package/dist/task/lite-context-pack.d.ts +71 -0
  38. package/dist/task/lite-context-pack.d.ts.map +1 -0
  39. package/dist/task/lite-context-pack.js +175 -0
  40. package/dist/task/lite-context-pack.js.map +1 -0
  41. package/dist/task/ondemand-topology.d.ts +108 -0
  42. package/dist/task/ondemand-topology.d.ts.map +1 -0
  43. package/dist/task/ondemand-topology.js +453 -0
  44. package/dist/task/ondemand-topology.js.map +1 -0
  45. package/dist/task/p36-artifact-migrate.d.ts +61 -0
  46. package/dist/task/p36-artifact-migrate.d.ts.map +1 -0
  47. package/dist/task/p36-artifact-migrate.js +336 -0
  48. package/dist/task/p36-artifact-migrate.js.map +1 -0
  49. package/dist/task/p36-wave-c.d.ts +39 -0
  50. package/dist/task/p36-wave-c.d.ts.map +1 -0
  51. package/dist/task/p36-wave-c.js +100 -0
  52. package/dist/task/p36-wave-c.js.map +1 -0
  53. package/dist/task/phase.d.ts +4 -4
  54. package/dist/task/records.d.ts +9 -0
  55. package/dist/task/records.d.ts.map +1 -1
  56. package/dist/task/records.js +11 -0
  57. package/dist/task/records.js.map +1 -1
  58. package/package.json +1 -6
  59. package/dist/rpc/broker/audit.d.ts +0 -16
  60. package/dist/rpc/broker/audit.d.ts.map +0 -1
  61. package/dist/rpc/broker/audit.js +0 -33
  62. package/dist/rpc/broker/audit.js.map +0 -1
  63. package/dist/rpc/broker/in-process.d.ts +0 -62
  64. package/dist/rpc/broker/in-process.d.ts.map +0 -1
  65. package/dist/rpc/broker/in-process.js +0 -490
  66. package/dist/rpc/broker/in-process.js.map +0 -1
  67. package/dist/rpc/broker/journal.d.ts +0 -11
  68. package/dist/rpc/broker/journal.d.ts.map +0 -1
  69. package/dist/rpc/broker/journal.js +0 -17
  70. package/dist/rpc/broker/journal.js.map +0 -1
  71. package/dist/rpc/contract/errors.d.ts +0 -18
  72. package/dist/rpc/contract/errors.d.ts.map +0 -1
  73. package/dist/rpc/contract/errors.js +0 -55
  74. package/dist/rpc/contract/errors.js.map +0 -1
  75. package/dist/rpc/contract/parse.d.ts +0 -9
  76. package/dist/rpc/contract/parse.d.ts.map +0 -1
  77. package/dist/rpc/contract/parse.js +0 -144
  78. package/dist/rpc/contract/parse.js.map +0 -1
  79. package/dist/rpc/contract/topics.d.ts +0 -11
  80. package/dist/rpc/contract/topics.d.ts.map +0 -1
  81. package/dist/rpc/contract/topics.js +0 -42
  82. package/dist/rpc/contract/topics.js.map +0 -1
  83. package/dist/rpc/contract/types.d.ts +0 -54
  84. package/dist/rpc/contract/types.d.ts.map +0 -1
  85. package/dist/rpc/contract/types.js +0 -39
  86. package/dist/rpc/contract/types.js.map +0 -1
  87. package/dist/rpc/index.d.ts +0 -10
  88. package/dist/rpc/index.d.ts.map +0 -1
  89. package/dist/rpc/index.js +0 -11
  90. package/dist/rpc/index.js.map +0 -1
  91. package/dist/rpc/transport/localhost-server.d.ts +0 -36
  92. package/dist/rpc/transport/localhost-server.d.ts.map +0 -1
  93. package/dist/rpc/transport/localhost-server.js +0 -275
  94. package/dist/rpc/transport/localhost-server.js.map +0 -1
  95. package/dist/rpc/transport/websocket.d.ts +0 -20
  96. package/dist/rpc/transport/websocket.d.ts.map +0 -1
  97. package/dist/rpc/transport/websocket.js +0 -156
  98. package/dist/rpc/transport/websocket.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./channel/index.js";
2
2
  export * from "./task/index.js";
3
- export * from "./rpc/index.js";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- // Root barrel — re-exports the channel, task, and rpc public APIs so callers
1
+ // Root barrel — re-exports the channel and task public APIs so callers
2
2
  // can `import { ... } from "@blxzer/cursor-trellis-core"`. Sub-path
3
- // imports (`@blxzer/cursor-trellis-core/channel`, `/task`, `/rpc`) remain the
3
+ // imports (`@blxzer/cursor-trellis-core/channel`, `/task`) remain the
4
4
  // recommended form for tree-shake-friendly consumption.
5
5
  export * from "./channel/index.js";
6
6
  export * from "./task/index.js";
7
- export * from "./rpc/index.js";
8
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,oEAAoE;AACpE,8EAA8E;AAC9E,wDAAwD;AAExD,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,oEAAoE;AACpE,sEAAsE;AACtE,wDAAwD;AAExD,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Stage 6 Cursor Adapter + Middleware (P27 Middleware, P29 Adapter/Profile,
3
+ * P30 Stage 6).
4
+ *
5
+ * Pure helpers persisted through existing create extras / patch. Does not
6
+ * write Kernel store or task.json. Field names here are an implementation
7
+ * choice — not a frozen Manifest / Event ABI schema.
8
+ */
9
+ export declare const STAGE6_SOURCE = "stage6-adapter-middleware";
10
+ export declare const STAGE6_SCHEMA_VERSION: 1;
11
+ export declare const STAGE6_HOOK_EVENTS: readonly ["sessionStart", "preToolUse", "beforeSubmitPrompt", "beforeShellExecution", "afterShellExecution", "stop"];
12
+ export type Stage6HookEvent = (typeof STAGE6_HOOK_EVENTS)[number];
13
+ export declare const RETRIEVAL_INTENTS: readonly ["exact", "semantic", "structural", "external"];
14
+ export type RetrievalIntent = (typeof RETRIEVAL_INTENTS)[number];
15
+ export type MiddlewareProbeKind = "cli" | "mcp" | "host";
16
+ export declare const SHIPPED_MIDDLEWARE_PROVIDERS: readonly ["smart-search", "codegraph", "fast-context", "chrome-cdp", "playwright", "github", "cursor-ide-browser"];
17
+ export type ShippedMiddlewareProvider = (typeof SHIPPED_MIDDLEWARE_PROVIDERS)[number];
18
+ /** Default `registered` catalog (Protocol v1 shipped table). */
19
+ export declare const DEFAULT_MIDDLEWARE_PROVIDERS: readonly ["smart-search", "codegraph", "fast-context", "chrome-cdp", "playwright", "github", "cursor-ide-browser"];
20
+ export declare const DEFAULT_REQUIRED_MIDDLEWARE_PROVIDERS: readonly ["smart-search"];
21
+ export declare const OPTIONAL_CODE_INTEL_PROVIDERS: readonly ["codegraph", "fast-context"];
22
+ export declare const SMART_SEARCH_PROVIDER = "smart-search";
23
+ export declare const EXTERNAL_KNOWLEDGE_CAPABILITY = "external-knowledge";
24
+ export declare const SHIPPED_PROVIDER_CAPABILITY: Record<ShippedMiddlewareProvider, string>;
25
+ export declare const SHIPPED_PROVIDER_PROBE: Record<ShippedMiddlewareProvider, MiddlewareProbeKind>;
26
+ export type Stage6CommandPhase = "create" | "start" | "archive" | "patch";
27
+ export type ProviderReadinessStatus = "ready" | "missing" | "failed" | "unknown";
28
+ export interface EventSubscription {
29
+ event: string;
30
+ module: string;
31
+ }
32
+ export interface EventBridgeLastEvent {
33
+ event: string;
34
+ at: string;
35
+ source: string;
36
+ delivered: string[];
37
+ skipped: string[];
38
+ }
39
+ export interface EventBridgeState {
40
+ schema_version: typeof STAGE6_SCHEMA_VERSION;
41
+ source: typeof STAGE6_SOURCE;
42
+ subscriptions: EventSubscription[];
43
+ last_event?: EventBridgeLastEvent;
44
+ }
45
+ export interface ProviderReadiness {
46
+ status: ProviderReadinessStatus;
47
+ capability: string;
48
+ evidence?: string | null;
49
+ }
50
+ export interface MiddlewareProviders {
51
+ schema_version: typeof STAGE6_SCHEMA_VERSION;
52
+ source: typeof STAGE6_SOURCE;
53
+ registered: string[];
54
+ required: string[];
55
+ active: string[];
56
+ degraded: string[];
57
+ readiness: Record<string, ProviderReadiness>;
58
+ }
59
+ export interface CapabilityRouter {
60
+ schema_version: typeof STAGE6_SCHEMA_VERSION;
61
+ source: typeof STAGE6_SOURCE;
62
+ exact?: true;
63
+ semantic?: true;
64
+ structural?: true;
65
+ external?: true;
66
+ }
67
+ export interface DispatchHookEventInput {
68
+ event: string;
69
+ source?: string;
70
+ at?: string;
71
+ }
72
+ export declare function defaultEventBridge(): EventBridgeState;
73
+ export declare function defaultMiddlewareProviders(): MiddlewareProviders;
74
+ export declare function defaultCapabilityRouter(): CapabilityRouter;
75
+ export declare function subscribeEvent(extras: Record<string, unknown>, event: string, moduleName: string): EventBridgeState;
76
+ /**
77
+ * Record and dispatch one hook event. Unsubscribed modules are skipped and
78
+ * never fail the hook.
79
+ */
80
+ export declare function recordHookEvent(extras: Record<string, unknown>, input: DispatchHookEventInput): EventBridgeLastEvent;
81
+ export declare function shippedProviderCapability(id: string): string;
82
+ export declare function shippedProviderProbeKind(id: string): MiddlewareProbeKind | null;
83
+ export declare function classifyTransportProbe(input: {
84
+ kind?: MiddlewareProbeKind;
85
+ present?: boolean;
86
+ reachable?: boolean;
87
+ available?: boolean;
88
+ status?: ProviderReadinessStatus;
89
+ evidence?: string | null;
90
+ }): Pick<ProviderReadiness, "status" | "evidence">;
91
+ export declare function mcpServerIdsFromConfig(raw: unknown): string[];
92
+ export declare function selectRegisteredMcpServers(configuredServerIds: readonly string[], registered?: readonly string[]): string[];
93
+ export declare function probeShippedProviderReadiness(id: string, input?: {
94
+ present?: boolean;
95
+ reachable?: boolean;
96
+ available?: boolean;
97
+ status?: ProviderReadinessStatus;
98
+ evidence?: string | null;
99
+ }): ProviderReadiness;
100
+ export declare function probeSmartSearchReadiness(input?: {
101
+ available?: boolean;
102
+ status?: ProviderReadinessStatus;
103
+ evidence?: string | null;
104
+ }): ProviderReadiness;
105
+ export declare function applyShippedProviderReadiness(extras: Record<string, unknown>, id: string, readiness: ProviderReadiness): MiddlewareProviders;
106
+ export declare function applySmartSearchReadiness(extras: Record<string, unknown>, readiness: ProviderReadiness): MiddlewareProviders;
107
+ export declare function normalizeEventBridge(raw: unknown): EventBridgeState;
108
+ export declare function normalizeMiddlewareProviders(raw: unknown): MiddlewareProviders;
109
+ export declare function normalizeCapabilityRouter(raw: unknown): CapabilityRouter;
110
+ export declare function readEventBridge(extras: Record<string, unknown>): EventBridgeState;
111
+ export declare function readMiddlewareProviders(extras: Record<string, unknown>): MiddlewareProviders;
112
+ export declare function readCapabilityRouter(extras: Record<string, unknown>): CapabilityRouter;
113
+ export declare function requiredCapabilities(extras: Record<string, unknown>): string[];
114
+ export declare function externalKnowledgeReady(providers: MiddlewareProviders): boolean;
115
+ export declare function normalizeStage6InExtras(extras: Record<string, unknown>): void;
116
+ export declare function assertStage6ForPhase(extras: Record<string, unknown>, phase: Stage6CommandPhase): void;
117
+ export declare function normalizeStage6InExtrasAndAssert(extras: Record<string, unknown>, phase: Stage6CommandPhase): void;
118
+ //# sourceMappingURL=adapter-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-middleware.d.ts","sourceRoot":"","sources":["../../src/task/adapter-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,eAAO,MAAM,aAAa,8BAA8B,CAAC;AACzD,eAAO,MAAM,qBAAqB,EAAG,CAAU,CAAC;AAEhD,eAAO,MAAM,kBAAkB,sHAOrB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,eAAO,MAAM,iBAAiB,0DAKpB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAE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
3
+ * P30 Stage 6).
4
+ *
5
+ * Pure helpers persisted through existing create extras / patch. Does not
6
+ * write Kernel store or task.json. Field names here are an implementation
7
+ * choice — not a frozen Manifest / Event ABI schema.
8
+ */
9
+ import { KernelError } from "./kernel-contract.js";
10
+ import { isPlainObject } from "./schema.js";
11
+ export const STAGE6_SOURCE = "stage6-adapter-middleware";
12
+ export const STAGE6_SCHEMA_VERSION = 1;
13
+ export const STAGE6_HOOK_EVENTS = [
14
+ "sessionStart",
15
+ "preToolUse",
16
+ "beforeSubmitPrompt",
17
+ "beforeShellExecution",
18
+ "afterShellExecution",
19
+ "stop",
20
+ ];
21
+ export const RETRIEVAL_INTENTS = [
22
+ "exact",
23
+ "semantic",
24
+ "structural",
25
+ "external",
26
+ ];
27
+ export const SHIPPED_MIDDLEWARE_PROVIDERS = [
28
+ "smart-search",
29
+ "codegraph",
30
+ "fast-context",
31
+ "chrome-cdp",
32
+ "playwright",
33
+ "github",
34
+ "cursor-ide-browser",
35
+ ];
36
+ /** Default `registered` catalog (Protocol v1 shipped table). */
37
+ export const DEFAULT_MIDDLEWARE_PROVIDERS = SHIPPED_MIDDLEWARE_PROVIDERS;
38
+ export const DEFAULT_REQUIRED_MIDDLEWARE_PROVIDERS = [
39
+ "smart-search",
40
+ ];
41
+ export const OPTIONAL_CODE_INTEL_PROVIDERS = [
42
+ "codegraph",
43
+ "fast-context",
44
+ ];
45
+ export const SMART_SEARCH_PROVIDER = "smart-search";
46
+ export const EXTERNAL_KNOWLEDGE_CAPABILITY = "external-knowledge";
47
+ export const SHIPPED_PROVIDER_CAPABILITY = {
48
+ "smart-search": EXTERNAL_KNOWLEDGE_CAPABILITY,
49
+ codegraph: "structural",
50
+ "fast-context": "semantic",
51
+ "chrome-cdp": "browser-session",
52
+ playwright: "browser-automation",
53
+ github: "vcs-host",
54
+ "cursor-ide-browser": "ide-browser",
55
+ };
56
+ export const SHIPPED_PROVIDER_PROBE = {
57
+ "smart-search": "cli",
58
+ codegraph: "mcp",
59
+ "fast-context": "mcp",
60
+ "chrome-cdp": "cli",
61
+ playwright: "mcp",
62
+ github: "mcp",
63
+ "cursor-ide-browser": "host",
64
+ };
65
+ export function defaultEventBridge() {
66
+ return {
67
+ schema_version: STAGE6_SCHEMA_VERSION,
68
+ source: STAGE6_SOURCE,
69
+ subscriptions: [],
70
+ };
71
+ }
72
+ function defaultReadinessMap() {
73
+ const readiness = {};
74
+ for (const id of SHIPPED_MIDDLEWARE_PROVIDERS) {
75
+ readiness[id] = {
76
+ status: "unknown",
77
+ capability: SHIPPED_PROVIDER_CAPABILITY[id],
78
+ evidence: null,
79
+ };
80
+ }
81
+ return readiness;
82
+ }
83
+ export function defaultMiddlewareProviders() {
84
+ return {
85
+ schema_version: STAGE6_SCHEMA_VERSION,
86
+ source: STAGE6_SOURCE,
87
+ registered: [...SHIPPED_MIDDLEWARE_PROVIDERS],
88
+ required: [...DEFAULT_REQUIRED_MIDDLEWARE_PROVIDERS],
89
+ active: [],
90
+ degraded: [],
91
+ readiness: defaultReadinessMap(),
92
+ };
93
+ }
94
+ export function defaultCapabilityRouter() {
95
+ return {
96
+ schema_version: STAGE6_SCHEMA_VERSION,
97
+ source: STAGE6_SOURCE,
98
+ exact: true,
99
+ semantic: true,
100
+ structural: true,
101
+ external: true,
102
+ };
103
+ }
104
+ export function subscribeEvent(extras, event, moduleName) {
105
+ const current = readEventBridge(extras);
106
+ const eventName = requireId(event, "event_bridge.subscriptions[].event");
107
+ const module = requireId(moduleName, "event_bridge.subscriptions[].module");
108
+ const subscriptions = [...current.subscriptions];
109
+ if (!subscriptions.some((item) => item.event === eventName && item.module === module)) {
110
+ subscriptions.push({ event: eventName, module });
111
+ }
112
+ const next = { ...current, subscriptions };
113
+ extras.event_bridge = next;
114
+ return next;
115
+ }
116
+ /**
117
+ * Record and dispatch one hook event. Unsubscribed modules are skipped and
118
+ * never fail the hook.
119
+ */
120
+ export function recordHookEvent(extras, input) {
121
+ const current = readEventBridge(extras);
122
+ const event = requireId(input.event, "event_bridge.last_event.event");
123
+ const delivered = [];
124
+ const skipped = [];
125
+ for (const sub of current.subscriptions) {
126
+ if (sub.event !== event) {
127
+ skipped.push(sub.module);
128
+ continue;
129
+ }
130
+ if (!delivered.includes(sub.module))
131
+ delivered.push(sub.module);
132
+ }
133
+ const lastEvent = {
134
+ event,
135
+ at: typeof input.at === "string" && input.at.trim() !== ""
136
+ ? input.at
137
+ : new Date().toISOString(),
138
+ source: typeof input.source === "string" && input.source.trim() !== ""
139
+ ? input.source
140
+ : "cursor-hooks",
141
+ delivered,
142
+ skipped,
143
+ };
144
+ extras.event_bridge = { ...current, last_event: lastEvent };
145
+ return lastEvent;
146
+ }
147
+ export function shippedProviderCapability(id) {
148
+ if (id in SHIPPED_PROVIDER_CAPABILITY) {
149
+ return SHIPPED_PROVIDER_CAPABILITY[id];
150
+ }
151
+ return id === SMART_SEARCH_PROVIDER
152
+ ? EXTERNAL_KNOWLEDGE_CAPABILITY
153
+ : "unknown";
154
+ }
155
+ export function shippedProviderProbeKind(id) {
156
+ if (id in SHIPPED_PROVIDER_PROBE) {
157
+ return SHIPPED_PROVIDER_PROBE[id];
158
+ }
159
+ return null;
160
+ }
161
+ export function classifyTransportProbe(input) {
162
+ if (input.status === "ready" ||
163
+ input.status === "missing" ||
164
+ input.status === "failed" ||
165
+ input.status === "unknown") {
166
+ return { status: input.status, evidence: input.evidence ?? null };
167
+ }
168
+ const present = input.present ?? input.available;
169
+ if (present === false) {
170
+ return { status: "missing", evidence: input.evidence ?? null };
171
+ }
172
+ if (present === true && input.reachable === false) {
173
+ return { status: "failed", evidence: input.evidence ?? null };
174
+ }
175
+ if (present === true) {
176
+ return { status: "ready", evidence: input.evidence ?? null };
177
+ }
178
+ return { status: "unknown", evidence: input.evidence ?? null };
179
+ }
180
+ export function mcpServerIdsFromConfig(raw) {
181
+ if (!isPlainObject(raw))
182
+ return [];
183
+ const servers = raw.mcpServers;
184
+ if (!isPlainObject(servers))
185
+ return [];
186
+ return Object.keys(servers);
187
+ }
188
+ export function selectRegisteredMcpServers(configuredServerIds, registered = SHIPPED_MIDDLEWARE_PROVIDERS) {
189
+ return uniqueStrings(configuredServerIds).filter((id) => registered.includes(id));
190
+ }
191
+ export function probeShippedProviderReadiness(id, input = {}) {
192
+ const classified = classifyTransportProbe({
193
+ kind: shippedProviderProbeKind(id) ?? undefined,
194
+ ...input,
195
+ });
196
+ return {
197
+ status: classified.status,
198
+ capability: shippedProviderCapability(id),
199
+ evidence: classified.evidence ?? null,
200
+ };
201
+ }
202
+ export function probeSmartSearchReadiness(input = {}) {
203
+ return probeShippedProviderReadiness(SMART_SEARCH_PROVIDER, input);
204
+ }
205
+ export function applyShippedProviderReadiness(extras, id, readiness) {
206
+ const current = readMiddlewareProviders(extras);
207
+ if (!current.registered.includes(id)) {
208
+ extras.middleware_providers = applyProviderHealth(current, extras);
209
+ return extras.middleware_providers;
210
+ }
211
+ const next = {
212
+ ...current,
213
+ readiness: {
214
+ ...current.readiness,
215
+ [id]: {
216
+ ...readiness,
217
+ capability: shippedProviderCapability(id),
218
+ },
219
+ },
220
+ };
221
+ extras.middleware_providers = applyProviderHealth(next, extras);
222
+ return extras.middleware_providers;
223
+ }
224
+ export function applySmartSearchReadiness(extras, readiness) {
225
+ return applyShippedProviderReadiness(extras, SMART_SEARCH_PROVIDER, readiness);
226
+ }
227
+ export function normalizeEventBridge(raw) {
228
+ if (raw === undefined || raw === null)
229
+ return defaultEventBridge();
230
+ if (!isPlainObject(raw)) {
231
+ throw new KernelError("INVALID_REQUEST", "event_bridge must be a JSON object");
232
+ }
233
+ const subscriptionsIn = raw.subscriptions;
234
+ const subscriptions = [];
235
+ if (subscriptionsIn !== undefined && subscriptionsIn !== null) {
236
+ if (!Array.isArray(subscriptionsIn)) {
237
+ throw new KernelError("INVALID_REQUEST", "event_bridge.subscriptions must be an array");
238
+ }
239
+ for (const item of subscriptionsIn) {
240
+ if (!isPlainObject(item)) {
241
+ throw new KernelError("INVALID_REQUEST", "event_bridge.subscriptions[] must be objects");
242
+ }
243
+ const sub = {
244
+ event: requireId(item.event, "event_bridge.subscriptions[].event"),
245
+ module: requireId(item.module, "event_bridge.subscriptions[].module"),
246
+ };
247
+ if (!subscriptions.some((existing) => existing.event === sub.event && existing.module === sub.module)) {
248
+ subscriptions.push(sub);
249
+ }
250
+ }
251
+ }
252
+ const lastRaw = raw.last_event;
253
+ let lastEvent;
254
+ if (lastRaw !== undefined && lastRaw !== null) {
255
+ if (!isPlainObject(lastRaw)) {
256
+ throw new KernelError("INVALID_REQUEST", "event_bridge.last_event must be an object");
257
+ }
258
+ lastEvent = {
259
+ event: requireId(lastRaw.event, "event_bridge.last_event.event"),
260
+ at: typeof lastRaw.at === "string" && lastRaw.at.trim() !== ""
261
+ ? lastRaw.at
262
+ : new Date().toISOString(),
263
+ source: typeof lastRaw.source === "string" && lastRaw.source.trim() !== ""
264
+ ? lastRaw.source
265
+ : "cursor-hooks",
266
+ delivered: uniqueStrings(asStringArray(lastRaw.delivered)),
267
+ skipped: uniqueStrings(asStringArray(lastRaw.skipped)),
268
+ };
269
+ }
270
+ return {
271
+ schema_version: STAGE6_SCHEMA_VERSION,
272
+ source: STAGE6_SOURCE,
273
+ subscriptions,
274
+ ...(lastEvent ? { last_event: lastEvent } : {}),
275
+ };
276
+ }
277
+ export function normalizeMiddlewareProviders(raw) {
278
+ if (raw === undefined || raw === null)
279
+ return defaultMiddlewareProviders();
280
+ if (!isPlainObject(raw)) {
281
+ throw new KernelError("INVALID_REQUEST", "middleware_providers must be a JSON object");
282
+ }
283
+ const defaults = defaultMiddlewareProviders();
284
+ const registered = uniqueStrings([
285
+ ...defaults.registered,
286
+ ...asStringArray(raw.registered),
287
+ ]);
288
+ const required = uniqueStrings(asStringArray(raw.required)).filter((name) => registered.includes(name));
289
+ const active = uniqueStrings(asStringArray(raw.active)).filter((name) => registered.includes(name));
290
+ const degraded = uniqueStrings(asStringArray(raw.degraded));
291
+ const readiness = {
292
+ ...defaults.readiness,
293
+ };
294
+ if (isPlainObject(raw.readiness)) {
295
+ for (const [name, value] of Object.entries(raw.readiness)) {
296
+ if (!isPlainObject(value))
297
+ continue;
298
+ const status = parseReadinessStatus(value.status);
299
+ readiness[name] = {
300
+ status,
301
+ capability: typeof value.capability === "string" && value.capability.trim() !== ""
302
+ ? value.capability
303
+ : name === SMART_SEARCH_PROVIDER
304
+ ? EXTERNAL_KNOWLEDGE_CAPABILITY
305
+ : "unknown",
306
+ evidence: typeof value.evidence === "string" ? value.evidence : null,
307
+ };
308
+ }
309
+ }
310
+ return {
311
+ schema_version: STAGE6_SCHEMA_VERSION,
312
+ source: STAGE6_SOURCE,
313
+ registered,
314
+ required: required.length > 0 ? required : [...defaults.required],
315
+ active,
316
+ degraded,
317
+ readiness,
318
+ };
319
+ }
320
+ export function normalizeCapabilityRouter(raw) {
321
+ if (raw === undefined || raw === null)
322
+ return defaultCapabilityRouter();
323
+ if (!isPlainObject(raw)) {
324
+ throw new KernelError("INVALID_REQUEST", "capability_router must be a JSON object");
325
+ }
326
+ const forbidden = [
327
+ ...OPTIONAL_CODE_INTEL_PROVIDERS,
328
+ "fast_context_search",
329
+ "codegraph_explore",
330
+ "codegraph_search",
331
+ "codegraph_callers",
332
+ ];
333
+ for (const key of Object.keys(raw)) {
334
+ if (forbidden.includes(key)) {
335
+ throw new KernelError("INVALID_REQUEST", "capability_router must not bind Optional tool names");
336
+ }
337
+ }
338
+ const next = {
339
+ schema_version: STAGE6_SCHEMA_VERSION,
340
+ source: STAGE6_SOURCE,
341
+ };
342
+ for (const intent of RETRIEVAL_INTENTS) {
343
+ if (raw[intent] !== false) {
344
+ next[intent] = true;
345
+ }
346
+ }
347
+ return next;
348
+ }
349
+ export function readEventBridge(extras) {
350
+ return normalizeEventBridge(extras.event_bridge);
351
+ }
352
+ export function readMiddlewareProviders(extras) {
353
+ return normalizeMiddlewareProviders(extras.middleware_providers);
354
+ }
355
+ export function readCapabilityRouter(extras) {
356
+ return normalizeCapabilityRouter(extras.capability_router);
357
+ }
358
+ export function requiredCapabilities(extras) {
359
+ return uniqueStrings(asStringArray(extras.required_capabilities));
360
+ }
361
+ export function externalKnowledgeReady(providers) {
362
+ const readiness = providers.readiness[SMART_SEARCH_PROVIDER];
363
+ return readiness?.status === "ready";
364
+ }
365
+ export function normalizeStage6InExtras(extras) {
366
+ extras.event_bridge = normalizeEventBridge(extras.event_bridge);
367
+ extras.capability_router = normalizeCapabilityRouter(extras.capability_router);
368
+ const incoming = extras.hook_event;
369
+ if (isPlainObject(incoming) && typeof incoming.event === "string") {
370
+ recordHookEvent(extras, {
371
+ event: incoming.event,
372
+ source: typeof incoming.source === "string" ? incoming.source : undefined,
373
+ at: typeof incoming.at === "string" ? incoming.at : undefined,
374
+ });
375
+ delete extras.hook_event;
376
+ }
377
+ extras.middleware_providers = normalizeMiddlewareProviders(extras.middleware_providers);
378
+ if (isPlainObject(extras.middleware_probes)) {
379
+ applyMiddlewareProbes(extras, extras.middleware_probes);
380
+ delete extras.middleware_probes;
381
+ }
382
+ if (isPlainObject(extras.smart_search_probe)) {
383
+ const probeStatus = extras.smart_search_probe.status;
384
+ applySmartSearchReadiness(extras, probeSmartSearchReadiness({
385
+ available: extras.smart_search_probe.available === true
386
+ ? true
387
+ : extras.smart_search_probe.available === false
388
+ ? false
389
+ : undefined,
390
+ status: probeStatus === "ready" ||
391
+ probeStatus === "missing" ||
392
+ probeStatus === "failed" ||
393
+ probeStatus === "unknown"
394
+ ? probeStatus
395
+ : undefined,
396
+ evidence: typeof extras.smart_search_probe.evidence === "string"
397
+ ? extras.smart_search_probe.evidence
398
+ : null,
399
+ }));
400
+ delete extras.smart_search_probe;
401
+ }
402
+ extras.middleware_providers = applyProviderHealth(extras.middleware_providers, extras);
403
+ }
404
+ export function assertStage6ForPhase(extras, phase) {
405
+ if (phase === "create" || phase === "patch")
406
+ return;
407
+ const providers = readMiddlewareProviders(extras);
408
+ const needsExternal = requiredCapabilities(extras).includes(EXTERNAL_KNOWLEDGE_CAPABILITY);
409
+ if (!needsExternal)
410
+ return;
411
+ if (externalKnowledgeReady(providers))
412
+ return;
413
+ if (extras.external_knowledge_policy === "degrade") {
414
+ extras.profile_health = "degraded";
415
+ return;
416
+ }
417
+ throw new KernelError("INVALID_TRANSITION", "external-knowledge required but smart-search Provider is not ready");
418
+ }
419
+ export function normalizeStage6InExtrasAndAssert(extras, phase) {
420
+ normalizeStage6InExtras(extras);
421
+ assertStage6ForPhase(extras, phase);
422
+ }
423
+ function applyMiddlewareProbes(extras, probes) {
424
+ const current = readMiddlewareProviders(extras);
425
+ for (const [id, value] of Object.entries(probes)) {
426
+ if (!current.registered.includes(id))
427
+ continue;
428
+ if (!isPlainObject(value))
429
+ continue;
430
+ applyShippedProviderReadiness(extras, id, probeShippedProviderReadiness(id, {
431
+ available: value.available === true
432
+ ? true
433
+ : value.available === false
434
+ ? false
435
+ : undefined,
436
+ present: value.present === true
437
+ ? true
438
+ : value.present === false
439
+ ? false
440
+ : undefined,
441
+ reachable: value.reachable === true
442
+ ? true
443
+ : value.reachable === false
444
+ ? false
445
+ : undefined,
446
+ status: value.status === "ready" ||
447
+ value.status === "missing" ||
448
+ value.status === "failed" ||
449
+ value.status === "unknown"
450
+ ? value.status
451
+ : undefined,
452
+ evidence: typeof value.evidence === "string" ? value.evidence : null,
453
+ }));
454
+ }
455
+ }
456
+ function applyProviderHealth(providers, extras) {
457
+ const degraded = uniqueStrings([...providers.degraded]);
458
+ for (const id of providers.required) {
459
+ const row = providers.readiness[id];
460
+ if (row && row.status !== "ready" && row.status !== "unknown") {
461
+ if (!degraded.includes(id))
462
+ degraded.push(id);
463
+ extras.profile_health = "degraded";
464
+ }
465
+ }
466
+ const missing = uniqueStrings(asStringArray(extras.ondemand_required_missing));
467
+ if (missing.includes(EXTERNAL_KNOWLEDGE_CAPABILITY) ||
468
+ missing.includes(SMART_SEARCH_PROVIDER)) {
469
+ if (!degraded.includes(SMART_SEARCH_PROVIDER)) {
470
+ degraded.push(SMART_SEARCH_PROVIDER);
471
+ }
472
+ extras.profile_health = "degraded";
473
+ }
474
+ return { ...providers, degraded };
475
+ }
476
+ function parseReadinessStatus(value) {
477
+ if (value === "ready" ||
478
+ value === "missing" ||
479
+ value === "failed" ||
480
+ value === "unknown") {
481
+ return value;
482
+ }
483
+ return "unknown";
484
+ }
485
+ function asStringArray(value) {
486
+ if (!Array.isArray(value))
487
+ return [];
488
+ return value.filter((item) => typeof item === "string");
489
+ }
490
+ function uniqueStrings(values) {
491
+ const out = [];
492
+ for (const value of values) {
493
+ if (typeof value !== "string")
494
+ continue;
495
+ const id = value.trim();
496
+ if (!id || out.includes(id))
497
+ continue;
498
+ out.push(id);
499
+ }
500
+ return out;
501
+ }
502
+ function requireId(value, field) {
503
+ if (typeof value !== "string" || value.trim() === "") {
504
+ throw new KernelError("INVALID_REQUEST", `${field} must be a non-empty string`);
505
+ }
506
+ return value.trim();
507
+ }
508
+ //# sourceMappingURL=adapter-middleware.js.map