@cleocode/cleo 2026.3.72 → 2026.3.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +561 -107
- package/dist/cli/index.js.map +4 -4
- package/dist/mcp/index.js +493 -108
- package/dist/mcp/index.js.map +4 -4
- package/package.json +4 -4
package/dist/mcp/index.js
CHANGED
|
@@ -733,22 +733,42 @@ __export(registry_exports, {
|
|
|
733
733
|
HookRegistry: () => HookRegistry,
|
|
734
734
|
hooks: () => hooks
|
|
735
735
|
});
|
|
736
|
-
var DEFAULT_HOOK_CONFIG, HookRegistry, hooks;
|
|
736
|
+
var LEGACY_EVENT_MAP, DEFAULT_HOOK_CONFIG, HookRegistry, hooks;
|
|
737
737
|
var init_registry = __esm({
|
|
738
738
|
"packages/core/src/hooks/registry.ts"() {
|
|
739
739
|
"use strict";
|
|
740
740
|
init_logger();
|
|
741
|
+
LEGACY_EVENT_MAP = {
|
|
742
|
+
onSessionStart: "SessionStart",
|
|
743
|
+
onSessionEnd: "SessionEnd",
|
|
744
|
+
onToolStart: "PreToolUse",
|
|
745
|
+
onToolComplete: "PostToolUse",
|
|
746
|
+
onFileChange: "Notification",
|
|
747
|
+
onError: "PostToolUseFailure",
|
|
748
|
+
onPromptSubmit: "PromptSubmit",
|
|
749
|
+
onResponseComplete: "ResponseComplete"
|
|
750
|
+
};
|
|
741
751
|
DEFAULT_HOOK_CONFIG = {
|
|
742
752
|
enabled: true,
|
|
743
753
|
events: {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
754
|
+
// CAAMP canonical events (16)
|
|
755
|
+
SessionStart: true,
|
|
756
|
+
SessionEnd: true,
|
|
757
|
+
PromptSubmit: true,
|
|
758
|
+
ResponseComplete: true,
|
|
759
|
+
PreToolUse: true,
|
|
760
|
+
PostToolUse: true,
|
|
761
|
+
PostToolUseFailure: true,
|
|
762
|
+
PermissionRequest: true,
|
|
763
|
+
SubagentStart: true,
|
|
764
|
+
SubagentStop: true,
|
|
765
|
+
PreModel: true,
|
|
766
|
+
PostModel: true,
|
|
767
|
+
PreCompact: true,
|
|
768
|
+
PostCompact: true,
|
|
769
|
+
Notification: true,
|
|
770
|
+
ConfigChange: true,
|
|
771
|
+
// CLEO internal coordination events (5)
|
|
752
772
|
onWorkAvailable: true,
|
|
753
773
|
onAgentSpawn: true,
|
|
754
774
|
onAgentComplete: true,
|
|
@@ -759,12 +779,33 @@ var init_registry = __esm({
|
|
|
759
779
|
HookRegistry = class {
|
|
760
780
|
handlers = /* @__PURE__ */ new Map();
|
|
761
781
|
config = DEFAULT_HOOK_CONFIG;
|
|
782
|
+
/**
|
|
783
|
+
* Resolve a potentially-legacy event name to its canonical equivalent.
|
|
784
|
+
*
|
|
785
|
+
* If the event name matches a known legacy `on`-prefix name, it is
|
|
786
|
+
* remapped and a deprecation warning is logged. Unknown names pass through
|
|
787
|
+
* unchanged so callers using the new canonical names are unaffected.
|
|
788
|
+
*/
|
|
789
|
+
resolveEvent(event) {
|
|
790
|
+
const canonical = LEGACY_EVENT_MAP[event];
|
|
791
|
+
if (canonical) {
|
|
792
|
+
getLogger("hooks").warn(
|
|
793
|
+
{ legacyEvent: event, canonicalEvent: canonical },
|
|
794
|
+
`[DEPRECATED] Hook event '${event}' has been renamed to '${canonical}'. Update your handler registration.`
|
|
795
|
+
);
|
|
796
|
+
return canonical;
|
|
797
|
+
}
|
|
798
|
+
return event;
|
|
799
|
+
}
|
|
762
800
|
/**
|
|
763
801
|
* Register a hook handler for a specific event.
|
|
764
802
|
*
|
|
765
803
|
* Handlers are sorted by priority (highest first) and executed
|
|
766
804
|
* in parallel when the event is dispatched.
|
|
767
805
|
*
|
|
806
|
+
* Backward compatibility: legacy `on`-prefix event names are automatically
|
|
807
|
+
* remapped to their canonical equivalents.
|
|
808
|
+
*
|
|
768
809
|
* @param registration - The hook registration containing event, handler, priority, and ID
|
|
769
810
|
* @returns A function to unregister the handler
|
|
770
811
|
*
|
|
@@ -772,7 +813,7 @@ var init_registry = __esm({
|
|
|
772
813
|
* ```typescript
|
|
773
814
|
* const unregister = hooks.register({
|
|
774
815
|
* id: 'my-handler',
|
|
775
|
-
* event: '
|
|
816
|
+
* event: 'SessionStart',
|
|
776
817
|
* handler: async (root, payload) => { console.log('Session started'); },
|
|
777
818
|
* priority: 100
|
|
778
819
|
* });
|
|
@@ -781,12 +822,14 @@ var init_registry = __esm({
|
|
|
781
822
|
* ```
|
|
782
823
|
*/
|
|
783
824
|
register(registration) {
|
|
784
|
-
const
|
|
785
|
-
|
|
825
|
+
const resolvedEvent = this.resolveEvent(registration.event);
|
|
826
|
+
const resolvedRegistration = { ...registration, event: resolvedEvent };
|
|
827
|
+
const list = this.handlers.get(resolvedEvent) || [];
|
|
828
|
+
list.push(resolvedRegistration);
|
|
786
829
|
list.sort((a, b) => b.priority - a.priority);
|
|
787
|
-
this.handlers.set(
|
|
830
|
+
this.handlers.set(resolvedEvent, list);
|
|
788
831
|
return () => {
|
|
789
|
-
const handlers = this.handlers.get(
|
|
832
|
+
const handlers = this.handlers.get(resolvedEvent);
|
|
790
833
|
if (handlers) {
|
|
791
834
|
const idx = handlers.findIndex((h) => h.id === registration.id);
|
|
792
835
|
if (idx !== -1) handlers.splice(idx, 1);
|
|
@@ -800,14 +843,17 @@ var init_registry = __esm({
|
|
|
800
843
|
* execution. Errors in individual handlers are logged but do not block
|
|
801
844
|
* other handlers or propagate to the caller.
|
|
802
845
|
*
|
|
803
|
-
*
|
|
846
|
+
* Backward compatibility: legacy `on`-prefix event names are automatically
|
|
847
|
+
* remapped to their canonical equivalents.
|
|
848
|
+
*
|
|
849
|
+
* @param event - The CAAMP canonical hook event to dispatch
|
|
804
850
|
* @param projectRoot - The project root directory path
|
|
805
851
|
* @param payload - The event payload (typed by event)
|
|
806
852
|
* @returns Promise that resolves when all handlers have completed
|
|
807
853
|
*
|
|
808
854
|
* @example
|
|
809
855
|
* ```typescript
|
|
810
|
-
* await hooks.dispatch('
|
|
856
|
+
* await hooks.dispatch('SessionStart', '/project', {
|
|
811
857
|
* timestamp: new Date().toISOString(),
|
|
812
858
|
* sessionId: 'sess-123',
|
|
813
859
|
* name: 'My Session',
|
|
@@ -817,15 +863,19 @@ var init_registry = __esm({
|
|
|
817
863
|
*/
|
|
818
864
|
async dispatch(event, projectRoot, payload) {
|
|
819
865
|
if (!this.config.enabled) return;
|
|
820
|
-
|
|
821
|
-
|
|
866
|
+
const resolvedEvent = this.resolveEvent(event);
|
|
867
|
+
if (!this.config.events[resolvedEvent]) return;
|
|
868
|
+
const handlers = this.handlers.get(resolvedEvent);
|
|
822
869
|
if (!handlers || handlers.length === 0) return;
|
|
823
870
|
await Promise.allSettled(
|
|
824
871
|
handlers.map(async (reg) => {
|
|
825
872
|
try {
|
|
826
873
|
await reg.handler(projectRoot, payload);
|
|
827
874
|
} catch (error40) {
|
|
828
|
-
getLogger("hooks").warn(
|
|
875
|
+
getLogger("hooks").warn(
|
|
876
|
+
{ err: error40, hookId: reg.id, event: resolvedEvent },
|
|
877
|
+
"Hook handler failed"
|
|
878
|
+
);
|
|
829
879
|
}
|
|
830
880
|
})
|
|
831
881
|
);
|
|
@@ -834,12 +884,14 @@ var init_registry = __esm({
|
|
|
834
884
|
* Check if a specific event is currently enabled.
|
|
835
885
|
*
|
|
836
886
|
* Both the global enabled flag and the per-event flag must be true.
|
|
887
|
+
* Automatically resolves legacy `on`-prefix event names.
|
|
837
888
|
*
|
|
838
889
|
* @param event - The CAAMP hook event to check
|
|
839
890
|
* @returns True if the event is enabled
|
|
840
891
|
*/
|
|
841
892
|
isEnabled(event) {
|
|
842
|
-
|
|
893
|
+
const resolvedEvent = this.resolveEvent(event);
|
|
894
|
+
return this.config.enabled && this.config.events[resolvedEvent];
|
|
843
895
|
}
|
|
844
896
|
/**
|
|
845
897
|
* Update the hook system configuration.
|
|
@@ -851,7 +903,7 @@ var init_registry = __esm({
|
|
|
851
903
|
* @example
|
|
852
904
|
* ```typescript
|
|
853
905
|
* hooks.setConfig({ enabled: false }); // Disable all hooks
|
|
854
|
-
* hooks.setConfig({ events: {
|
|
906
|
+
* hooks.setConfig({ events: { PostToolUseFailure: false } }); // Disable specific event
|
|
855
907
|
* ```
|
|
856
908
|
*/
|
|
857
909
|
setConfig(config2) {
|
|
@@ -869,12 +921,14 @@ var init_registry = __esm({
|
|
|
869
921
|
* List all registered handlers for a specific event.
|
|
870
922
|
*
|
|
871
923
|
* Returns handlers in priority order (highest first).
|
|
924
|
+
* Automatically resolves legacy `on`-prefix event names.
|
|
872
925
|
*
|
|
873
926
|
* @param event - The CAAMP hook event
|
|
874
927
|
* @returns Array of hook registrations
|
|
875
928
|
*/
|
|
876
929
|
listHandlers(event) {
|
|
877
|
-
|
|
930
|
+
const resolvedEvent = this.resolveEvent(event);
|
|
931
|
+
return [...this.handlers.get(resolvedEvent) || []];
|
|
878
932
|
}
|
|
879
933
|
};
|
|
880
934
|
hooks = new HookRegistry();
|
|
@@ -13695,7 +13749,7 @@ async function saveJson(filePath, data, options) {
|
|
|
13695
13749
|
}
|
|
13696
13750
|
await atomicWriteJson(filePath, data, { indent: options?.indent });
|
|
13697
13751
|
Promise.resolve().then(() => (init_registry(), registry_exports)).then(
|
|
13698
|
-
({ hooks: h }) => h.dispatch("
|
|
13752
|
+
({ hooks: h }) => h.dispatch("Notification", process.cwd(), {
|
|
13699
13753
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
13700
13754
|
filePath,
|
|
13701
13755
|
changeType: "write"
|
|
@@ -20929,13 +20983,13 @@ var init_session_hooks = __esm({
|
|
|
20929
20983
|
init_memory_bridge_refresh();
|
|
20930
20984
|
hooks.register({
|
|
20931
20985
|
id: "brain-session-start",
|
|
20932
|
-
event: "
|
|
20986
|
+
event: "SessionStart",
|
|
20933
20987
|
handler: handleSessionStart,
|
|
20934
20988
|
priority: 100
|
|
20935
20989
|
});
|
|
20936
20990
|
hooks.register({
|
|
20937
20991
|
id: "brain-session-end",
|
|
20938
|
-
event: "
|
|
20992
|
+
event: "SessionEnd",
|
|
20939
20993
|
handler: handleSessionEnd,
|
|
20940
20994
|
priority: 100
|
|
20941
20995
|
});
|
|
@@ -20982,13 +21036,13 @@ var init_task_hooks = __esm({
|
|
|
20982
21036
|
init_memory_bridge_refresh();
|
|
20983
21037
|
hooks.register({
|
|
20984
21038
|
id: "brain-tool-start",
|
|
20985
|
-
event: "
|
|
21039
|
+
event: "PreToolUse",
|
|
20986
21040
|
handler: handleToolStart,
|
|
20987
21041
|
priority: 100
|
|
20988
21042
|
});
|
|
20989
21043
|
hooks.register({
|
|
20990
21044
|
id: "brain-tool-complete",
|
|
20991
|
-
event: "
|
|
21045
|
+
event: "PostToolUse",
|
|
20992
21046
|
handler: handleToolComplete,
|
|
20993
21047
|
priority: 100
|
|
20994
21048
|
});
|
|
@@ -21018,7 +21072,7 @@ var init_error_hooks = __esm({
|
|
|
21018
21072
|
init_registry();
|
|
21019
21073
|
hooks.register({
|
|
21020
21074
|
id: "brain-error",
|
|
21021
|
-
event: "
|
|
21075
|
+
event: "PostToolUseFailure",
|
|
21022
21076
|
handler: handleError,
|
|
21023
21077
|
priority: 100
|
|
21024
21078
|
});
|
|
@@ -21049,6 +21103,7 @@ async function isFileCaptureEnabled(projectRoot) {
|
|
|
21049
21103
|
}
|
|
21050
21104
|
}
|
|
21051
21105
|
async function handleFileChange(projectRoot, payload) {
|
|
21106
|
+
if (!payload.filePath || !payload.changeType) return;
|
|
21052
21107
|
if (!await isFileCaptureEnabled(projectRoot)) return;
|
|
21053
21108
|
const now2 = Date.now();
|
|
21054
21109
|
const lastWrite = recentWrites.get(payload.filePath);
|
|
@@ -21095,7 +21150,7 @@ var init_file_hooks = __esm({
|
|
|
21095
21150
|
];
|
|
21096
21151
|
hooks.register({
|
|
21097
21152
|
id: "brain-file-change",
|
|
21098
|
-
event: "
|
|
21153
|
+
event: "Notification",
|
|
21099
21154
|
handler: handleFileChange,
|
|
21100
21155
|
priority: 100
|
|
21101
21156
|
});
|
|
@@ -21149,22 +21204,51 @@ async function handleResponseComplete(projectRoot, payload) {
|
|
|
21149
21204
|
if (!isMissingBrainSchemaError4(err)) throw err;
|
|
21150
21205
|
}
|
|
21151
21206
|
}
|
|
21207
|
+
async function handleSystemNotification(projectRoot, payload) {
|
|
21208
|
+
if (payload.filePath || payload.changeType) return;
|
|
21209
|
+
if (!payload.message) return;
|
|
21210
|
+
try {
|
|
21211
|
+
const { loadConfig: loadConfig4 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
21212
|
+
const config2 = await loadConfig4(projectRoot);
|
|
21213
|
+
if (!config2.brain?.autoCapture) return;
|
|
21214
|
+
} catch {
|
|
21215
|
+
return;
|
|
21216
|
+
}
|
|
21217
|
+
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
21218
|
+
try {
|
|
21219
|
+
await observeBrain2(projectRoot, {
|
|
21220
|
+
text: `System notification: ${payload.message}`,
|
|
21221
|
+
title: `Notification: ${payload.message.slice(0, 60)}`,
|
|
21222
|
+
type: "discovery",
|
|
21223
|
+
sourceSessionId: payload.sessionId,
|
|
21224
|
+
sourceType: "agent"
|
|
21225
|
+
});
|
|
21226
|
+
} catch (err) {
|
|
21227
|
+
if (!isMissingBrainSchemaError4(err)) throw err;
|
|
21228
|
+
}
|
|
21229
|
+
}
|
|
21152
21230
|
var init_mcp_hooks = __esm({
|
|
21153
21231
|
"packages/core/src/hooks/handlers/mcp-hooks.ts"() {
|
|
21154
21232
|
"use strict";
|
|
21155
21233
|
init_registry();
|
|
21156
21234
|
hooks.register({
|
|
21157
21235
|
id: "brain-prompt-submit",
|
|
21158
|
-
event: "
|
|
21236
|
+
event: "PromptSubmit",
|
|
21159
21237
|
handler: handlePromptSubmit,
|
|
21160
21238
|
priority: 100
|
|
21161
21239
|
});
|
|
21162
21240
|
hooks.register({
|
|
21163
21241
|
id: "brain-response-complete",
|
|
21164
|
-
event: "
|
|
21242
|
+
event: "ResponseComplete",
|
|
21165
21243
|
handler: handleResponseComplete,
|
|
21166
21244
|
priority: 100
|
|
21167
21245
|
});
|
|
21246
|
+
hooks.register({
|
|
21247
|
+
id: "brain-system-notification",
|
|
21248
|
+
event: "Notification",
|
|
21249
|
+
handler: handleSystemNotification,
|
|
21250
|
+
priority: 90
|
|
21251
|
+
});
|
|
21168
21252
|
}
|
|
21169
21253
|
});
|
|
21170
21254
|
|
|
@@ -21241,19 +21325,158 @@ var init_work_capture_hooks = __esm({
|
|
|
21241
21325
|
]);
|
|
21242
21326
|
hooks.register({
|
|
21243
21327
|
id: "work-capture-prompt-submit",
|
|
21244
|
-
event: "
|
|
21328
|
+
event: "PromptSubmit",
|
|
21245
21329
|
handler: handleWorkPromptSubmit,
|
|
21246
21330
|
priority: 90
|
|
21247
21331
|
});
|
|
21248
21332
|
hooks.register({
|
|
21249
21333
|
id: "work-capture-response-complete",
|
|
21250
|
-
event: "
|
|
21334
|
+
event: "ResponseComplete",
|
|
21251
21335
|
handler: handleWorkResponseComplete,
|
|
21252
21336
|
priority: 90
|
|
21253
21337
|
});
|
|
21254
21338
|
}
|
|
21255
21339
|
});
|
|
21256
21340
|
|
|
21341
|
+
// packages/core/src/hooks/handlers/agent-hooks.ts
|
|
21342
|
+
function isMissingBrainSchemaError6(err) {
|
|
21343
|
+
if (!(err instanceof Error)) return false;
|
|
21344
|
+
const message = String(err.message || "").toLowerCase();
|
|
21345
|
+
return message.includes("no such table") && message.includes("brain_");
|
|
21346
|
+
}
|
|
21347
|
+
async function isAutoCaptureEnabled(projectRoot) {
|
|
21348
|
+
try {
|
|
21349
|
+
const { loadConfig: loadConfig4 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
21350
|
+
const config2 = await loadConfig4(projectRoot);
|
|
21351
|
+
return config2.brain?.autoCapture ?? false;
|
|
21352
|
+
} catch {
|
|
21353
|
+
return false;
|
|
21354
|
+
}
|
|
21355
|
+
}
|
|
21356
|
+
async function handleSubagentStart(projectRoot, payload) {
|
|
21357
|
+
if (!await isAutoCaptureEnabled(projectRoot)) return;
|
|
21358
|
+
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
21359
|
+
const rolePart = payload.role ? ` role=${payload.role}` : "";
|
|
21360
|
+
const taskPart = payload.taskId ? ` task=${payload.taskId}` : "";
|
|
21361
|
+
try {
|
|
21362
|
+
await observeBrain2(projectRoot, {
|
|
21363
|
+
text: `Subagent spawned: ${payload.agentId}${rolePart}${taskPart}`,
|
|
21364
|
+
title: `Subagent start: ${payload.agentId}`,
|
|
21365
|
+
type: "discovery",
|
|
21366
|
+
sourceSessionId: payload.sessionId,
|
|
21367
|
+
sourceType: "agent"
|
|
21368
|
+
});
|
|
21369
|
+
} catch (err) {
|
|
21370
|
+
if (!isMissingBrainSchemaError6(err)) throw err;
|
|
21371
|
+
}
|
|
21372
|
+
}
|
|
21373
|
+
async function handleSubagentStop(projectRoot, payload) {
|
|
21374
|
+
if (!await isAutoCaptureEnabled(projectRoot)) return;
|
|
21375
|
+
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
21376
|
+
const statusPart = payload.status ? ` status=${payload.status}` : "";
|
|
21377
|
+
const taskPart = payload.taskId ? ` task=${payload.taskId}` : "";
|
|
21378
|
+
const summaryPart = payload.summary ? `
|
|
21379
|
+
Summary: ${payload.summary}` : "";
|
|
21380
|
+
try {
|
|
21381
|
+
await observeBrain2(projectRoot, {
|
|
21382
|
+
text: `Subagent completed: ${payload.agentId}${statusPart}${taskPart}${summaryPart}`,
|
|
21383
|
+
title: `Subagent stop: ${payload.agentId}`,
|
|
21384
|
+
type: "change",
|
|
21385
|
+
sourceSessionId: payload.sessionId,
|
|
21386
|
+
sourceType: "agent"
|
|
21387
|
+
});
|
|
21388
|
+
} catch (err) {
|
|
21389
|
+
if (!isMissingBrainSchemaError6(err)) throw err;
|
|
21390
|
+
}
|
|
21391
|
+
}
|
|
21392
|
+
var init_agent_hooks = __esm({
|
|
21393
|
+
"packages/core/src/hooks/handlers/agent-hooks.ts"() {
|
|
21394
|
+
"use strict";
|
|
21395
|
+
init_registry();
|
|
21396
|
+
hooks.register({
|
|
21397
|
+
id: "brain-subagent-start",
|
|
21398
|
+
event: "SubagentStart",
|
|
21399
|
+
handler: handleSubagentStart,
|
|
21400
|
+
priority: 100
|
|
21401
|
+
});
|
|
21402
|
+
hooks.register({
|
|
21403
|
+
id: "brain-subagent-stop",
|
|
21404
|
+
event: "SubagentStop",
|
|
21405
|
+
handler: handleSubagentStop,
|
|
21406
|
+
priority: 100
|
|
21407
|
+
});
|
|
21408
|
+
}
|
|
21409
|
+
});
|
|
21410
|
+
|
|
21411
|
+
// packages/core/src/hooks/handlers/context-hooks.ts
|
|
21412
|
+
function isMissingBrainSchemaError7(err) {
|
|
21413
|
+
if (!(err instanceof Error)) return false;
|
|
21414
|
+
const message = String(err.message || "").toLowerCase();
|
|
21415
|
+
return message.includes("no such table") && message.includes("brain_");
|
|
21416
|
+
}
|
|
21417
|
+
async function isAutoCaptureEnabled2(projectRoot) {
|
|
21418
|
+
try {
|
|
21419
|
+
const { loadConfig: loadConfig4 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
21420
|
+
const config2 = await loadConfig4(projectRoot);
|
|
21421
|
+
return config2.brain?.autoCapture ?? false;
|
|
21422
|
+
} catch {
|
|
21423
|
+
return false;
|
|
21424
|
+
}
|
|
21425
|
+
}
|
|
21426
|
+
async function handlePreCompact(projectRoot, payload) {
|
|
21427
|
+
if (!await isAutoCaptureEnabled2(projectRoot)) return;
|
|
21428
|
+
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
21429
|
+
const tokensPart = payload.tokensBefore != null ? ` (~${payload.tokensBefore.toLocaleString()} tokens)` : "";
|
|
21430
|
+
const reasonPart = payload.reason ? ` Reason: ${payload.reason}` : "";
|
|
21431
|
+
try {
|
|
21432
|
+
await observeBrain2(projectRoot, {
|
|
21433
|
+
text: `Context compaction about to begin${tokensPart}.${reasonPart}`,
|
|
21434
|
+
title: "Pre-compaction context snapshot",
|
|
21435
|
+
type: "discovery",
|
|
21436
|
+
sourceSessionId: payload.sessionId,
|
|
21437
|
+
sourceType: "agent"
|
|
21438
|
+
});
|
|
21439
|
+
} catch (err) {
|
|
21440
|
+
if (!isMissingBrainSchemaError7(err)) throw err;
|
|
21441
|
+
}
|
|
21442
|
+
}
|
|
21443
|
+
async function handlePostCompact(projectRoot, payload) {
|
|
21444
|
+
if (!await isAutoCaptureEnabled2(projectRoot)) return;
|
|
21445
|
+
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
21446
|
+
const statusPart = payload.success ? "succeeded" : "failed";
|
|
21447
|
+
const beforePart = payload.tokensBefore != null ? ` before=${payload.tokensBefore.toLocaleString()}` : "";
|
|
21448
|
+
const afterPart = payload.tokensAfter != null ? ` after=${payload.tokensAfter.toLocaleString()}` : "";
|
|
21449
|
+
try {
|
|
21450
|
+
await observeBrain2(projectRoot, {
|
|
21451
|
+
text: `Context compaction ${statusPart}${beforePart}${afterPart}`,
|
|
21452
|
+
title: "Post-compaction record",
|
|
21453
|
+
type: "change",
|
|
21454
|
+
sourceSessionId: payload.sessionId,
|
|
21455
|
+
sourceType: "agent"
|
|
21456
|
+
});
|
|
21457
|
+
} catch (err) {
|
|
21458
|
+
if (!isMissingBrainSchemaError7(err)) throw err;
|
|
21459
|
+
}
|
|
21460
|
+
}
|
|
21461
|
+
var init_context_hooks = __esm({
|
|
21462
|
+
"packages/core/src/hooks/handlers/context-hooks.ts"() {
|
|
21463
|
+
"use strict";
|
|
21464
|
+
init_registry();
|
|
21465
|
+
hooks.register({
|
|
21466
|
+
id: "brain-pre-compact",
|
|
21467
|
+
event: "PreCompact",
|
|
21468
|
+
handler: handlePreCompact,
|
|
21469
|
+
priority: 100
|
|
21470
|
+
});
|
|
21471
|
+
hooks.register({
|
|
21472
|
+
id: "brain-post-compact",
|
|
21473
|
+
event: "PostCompact",
|
|
21474
|
+
handler: handlePostCompact,
|
|
21475
|
+
priority: 100
|
|
21476
|
+
});
|
|
21477
|
+
}
|
|
21478
|
+
});
|
|
21479
|
+
|
|
21257
21480
|
// packages/core/src/hooks/handlers/index.ts
|
|
21258
21481
|
var init_handlers = __esm({
|
|
21259
21482
|
"packages/core/src/hooks/handlers/index.ts"() {
|
|
@@ -21264,6 +21487,10 @@ var init_handlers = __esm({
|
|
|
21264
21487
|
init_file_hooks();
|
|
21265
21488
|
init_mcp_hooks();
|
|
21266
21489
|
init_work_capture_hooks();
|
|
21490
|
+
init_agent_hooks();
|
|
21491
|
+
init_context_hooks();
|
|
21492
|
+
init_agent_hooks();
|
|
21493
|
+
init_context_hooks();
|
|
21267
21494
|
init_error_hooks();
|
|
21268
21495
|
init_file_hooks();
|
|
21269
21496
|
init_mcp_hooks();
|
|
@@ -23114,7 +23341,7 @@ async function startSession(options, cwd, accessor) {
|
|
|
23114
23341
|
});
|
|
23115
23342
|
}
|
|
23116
23343
|
const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
|
|
23117
|
-
hooks2.dispatch("
|
|
23344
|
+
hooks2.dispatch("SessionStart", cwd ?? process.cwd(), {
|
|
23118
23345
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23119
23346
|
sessionId: session.id,
|
|
23120
23347
|
name: options.name,
|
|
@@ -23152,7 +23379,7 @@ async function endSession(options = {}, cwd, accessor) {
|
|
|
23152
23379
|
session.endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
23153
23380
|
const duration3 = Math.floor((Date.now() - new Date(session.startedAt).getTime()) / 1e3);
|
|
23154
23381
|
const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
|
|
23155
|
-
hooks2.dispatch("
|
|
23382
|
+
hooks2.dispatch("SessionEnd", cwd ?? process.cwd(), {
|
|
23156
23383
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23157
23384
|
sessionId: session.id,
|
|
23158
23385
|
duration: duration3,
|
|
@@ -35888,7 +36115,7 @@ function validatePayload(event, payload) {
|
|
|
35888
36115
|
const errors = result.error.issues.map((issue2) => `${issue2.path.join(".")}: ${issue2.message}`);
|
|
35889
36116
|
return { valid: false, errors };
|
|
35890
36117
|
}
|
|
35891
|
-
var HookPayloadSchema, OnSessionStartPayloadSchema, OnSessionEndPayloadSchema, OnToolStartPayloadSchema, OnToolCompletePayloadSchema, OnFileChangePayloadSchema, OnErrorPayloadSchema, OnPromptSubmitPayloadSchema, OnResponseCompletePayloadSchema, OnWorkAvailablePayloadSchema, OnAgentSpawnPayloadSchema, OnAgentCompletePayloadSchema, OnCascadeStartPayloadSchema, OnPatrolPayloadSchema, EVENT_SCHEMA_MAP;
|
|
36118
|
+
var HookPayloadSchema, SessionStartPayloadSchema, OnSessionStartPayloadSchema, SessionEndPayloadSchema, OnSessionEndPayloadSchema, PreToolUsePayloadSchema, OnToolStartPayloadSchema, PostToolUsePayloadSchema, OnToolCompletePayloadSchema, NotificationPayloadSchema, OnFileChangePayloadSchema, PostToolUseFailurePayloadSchema, OnErrorPayloadSchema, PromptSubmitPayloadSchema, OnPromptSubmitPayloadSchema, ResponseCompletePayloadSchema, OnResponseCompletePayloadSchema, SubagentStartPayloadSchema, SubagentStopPayloadSchema, PreCompactPayloadSchema, PostCompactPayloadSchema, ConfigChangePayloadSchema, OnWorkAvailablePayloadSchema, OnAgentSpawnPayloadSchema, OnAgentCompletePayloadSchema, OnCascadeStartPayloadSchema, OnPatrolPayloadSchema, EVENT_SCHEMA_MAP;
|
|
35892
36119
|
var init_payload_schemas = __esm({
|
|
35893
36120
|
"packages/core/src/hooks/payload-schemas.ts"() {
|
|
35894
36121
|
"use strict";
|
|
@@ -35900,33 +36127,42 @@ var init_payload_schemas = __esm({
|
|
|
35900
36127
|
providerId: external_exports.string().optional(),
|
|
35901
36128
|
metadata: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
35902
36129
|
});
|
|
35903
|
-
|
|
36130
|
+
SessionStartPayloadSchema = HookPayloadSchema.extend({
|
|
35904
36131
|
sessionId: external_exports.string(),
|
|
35905
36132
|
name: external_exports.string(),
|
|
35906
36133
|
scope: external_exports.string(),
|
|
35907
36134
|
agent: external_exports.string().optional()
|
|
35908
36135
|
});
|
|
35909
|
-
|
|
36136
|
+
OnSessionStartPayloadSchema = SessionStartPayloadSchema;
|
|
36137
|
+
SessionEndPayloadSchema = HookPayloadSchema.extend({
|
|
35910
36138
|
sessionId: external_exports.string(),
|
|
35911
36139
|
duration: external_exports.number(),
|
|
35912
36140
|
tasksCompleted: external_exports.array(external_exports.string())
|
|
35913
36141
|
});
|
|
35914
|
-
|
|
36142
|
+
OnSessionEndPayloadSchema = SessionEndPayloadSchema;
|
|
36143
|
+
PreToolUsePayloadSchema = HookPayloadSchema.extend({
|
|
35915
36144
|
taskId: external_exports.string(),
|
|
35916
36145
|
taskTitle: external_exports.string(),
|
|
35917
|
-
previousTask: external_exports.string().optional()
|
|
36146
|
+
previousTask: external_exports.string().optional(),
|
|
36147
|
+
toolName: external_exports.string().optional(),
|
|
36148
|
+
toolInput: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
35918
36149
|
});
|
|
35919
|
-
|
|
36150
|
+
OnToolStartPayloadSchema = PreToolUsePayloadSchema;
|
|
36151
|
+
PostToolUsePayloadSchema = HookPayloadSchema.extend({
|
|
35920
36152
|
taskId: external_exports.string(),
|
|
35921
36153
|
taskTitle: external_exports.string(),
|
|
35922
|
-
status: external_exports.enum(["done", "archived", "cancelled"])
|
|
36154
|
+
status: external_exports.enum(["done", "archived", "cancelled"]),
|
|
36155
|
+
toolResult: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
35923
36156
|
});
|
|
35924
|
-
|
|
35925
|
-
|
|
35926
|
-
|
|
35927
|
-
|
|
36157
|
+
OnToolCompletePayloadSchema = PostToolUsePayloadSchema;
|
|
36158
|
+
NotificationPayloadSchema = HookPayloadSchema.extend({
|
|
36159
|
+
filePath: external_exports.string().optional(),
|
|
36160
|
+
changeType: external_exports.enum(["write", "create", "delete"]).optional(),
|
|
36161
|
+
sizeBytes: external_exports.number().optional(),
|
|
36162
|
+
message: external_exports.string().optional()
|
|
35928
36163
|
});
|
|
35929
|
-
|
|
36164
|
+
OnFileChangePayloadSchema = NotificationPayloadSchema;
|
|
36165
|
+
PostToolUseFailurePayloadSchema = HookPayloadSchema.extend({
|
|
35930
36166
|
errorCode: external_exports.union([external_exports.number(), external_exports.string()]),
|
|
35931
36167
|
message: external_exports.string(),
|
|
35932
36168
|
domain: external_exports.string().optional(),
|
|
@@ -35934,13 +36170,15 @@ var init_payload_schemas = __esm({
|
|
|
35934
36170
|
gateway: external_exports.string().optional(),
|
|
35935
36171
|
stack: external_exports.string().optional()
|
|
35936
36172
|
});
|
|
35937
|
-
|
|
36173
|
+
OnErrorPayloadSchema = PostToolUseFailurePayloadSchema;
|
|
36174
|
+
PromptSubmitPayloadSchema = HookPayloadSchema.extend({
|
|
35938
36175
|
gateway: external_exports.string(),
|
|
35939
36176
|
domain: external_exports.string(),
|
|
35940
36177
|
operation: external_exports.string(),
|
|
35941
36178
|
source: external_exports.string().optional()
|
|
35942
36179
|
});
|
|
35943
|
-
|
|
36180
|
+
OnPromptSubmitPayloadSchema = PromptSubmitPayloadSchema;
|
|
36181
|
+
ResponseCompletePayloadSchema = HookPayloadSchema.extend({
|
|
35944
36182
|
gateway: external_exports.string(),
|
|
35945
36183
|
domain: external_exports.string(),
|
|
35946
36184
|
operation: external_exports.string(),
|
|
@@ -35948,6 +36186,32 @@ var init_payload_schemas = __esm({
|
|
|
35948
36186
|
durationMs: external_exports.number().optional(),
|
|
35949
36187
|
errorCode: external_exports.string().optional()
|
|
35950
36188
|
});
|
|
36189
|
+
OnResponseCompletePayloadSchema = ResponseCompletePayloadSchema;
|
|
36190
|
+
SubagentStartPayloadSchema = HookPayloadSchema.extend({
|
|
36191
|
+
agentId: external_exports.string(),
|
|
36192
|
+
role: external_exports.string().optional(),
|
|
36193
|
+
taskId: external_exports.string().optional()
|
|
36194
|
+
});
|
|
36195
|
+
SubagentStopPayloadSchema = HookPayloadSchema.extend({
|
|
36196
|
+
agentId: external_exports.string(),
|
|
36197
|
+
status: external_exports.enum(["complete", "partial", "blocked", "failed"]).optional(),
|
|
36198
|
+
taskId: external_exports.string().optional(),
|
|
36199
|
+
summary: external_exports.string().optional()
|
|
36200
|
+
});
|
|
36201
|
+
PreCompactPayloadSchema = HookPayloadSchema.extend({
|
|
36202
|
+
tokensBefore: external_exports.number().optional(),
|
|
36203
|
+
reason: external_exports.string().optional()
|
|
36204
|
+
});
|
|
36205
|
+
PostCompactPayloadSchema = HookPayloadSchema.extend({
|
|
36206
|
+
tokensBefore: external_exports.number().optional(),
|
|
36207
|
+
tokensAfter: external_exports.number().optional(),
|
|
36208
|
+
success: external_exports.boolean()
|
|
36209
|
+
});
|
|
36210
|
+
ConfigChangePayloadSchema = HookPayloadSchema.extend({
|
|
36211
|
+
key: external_exports.string(),
|
|
36212
|
+
previousValue: external_exports.unknown().optional(),
|
|
36213
|
+
newValue: external_exports.unknown().optional()
|
|
36214
|
+
});
|
|
35951
36215
|
OnWorkAvailablePayloadSchema = HookPayloadSchema.extend({
|
|
35952
36216
|
taskIds: external_exports.array(external_exports.string()),
|
|
35953
36217
|
epicId: external_exports.string().optional(),
|
|
@@ -35979,14 +36243,21 @@ var init_payload_schemas = __esm({
|
|
|
35979
36243
|
scope: external_exports.string().optional()
|
|
35980
36244
|
});
|
|
35981
36245
|
EVENT_SCHEMA_MAP = {
|
|
35982
|
-
|
|
35983
|
-
|
|
35984
|
-
|
|
35985
|
-
|
|
35986
|
-
|
|
35987
|
-
|
|
35988
|
-
|
|
35989
|
-
|
|
36246
|
+
// CAAMP canonical events (16)
|
|
36247
|
+
SessionStart: SessionStartPayloadSchema,
|
|
36248
|
+
SessionEnd: SessionEndPayloadSchema,
|
|
36249
|
+
PreToolUse: PreToolUsePayloadSchema,
|
|
36250
|
+
PostToolUse: PostToolUsePayloadSchema,
|
|
36251
|
+
Notification: NotificationPayloadSchema,
|
|
36252
|
+
PostToolUseFailure: PostToolUseFailurePayloadSchema,
|
|
36253
|
+
PromptSubmit: PromptSubmitPayloadSchema,
|
|
36254
|
+
ResponseComplete: ResponseCompletePayloadSchema,
|
|
36255
|
+
SubagentStart: SubagentStartPayloadSchema,
|
|
36256
|
+
SubagentStop: SubagentStopPayloadSchema,
|
|
36257
|
+
PreCompact: PreCompactPayloadSchema,
|
|
36258
|
+
PostCompact: PostCompactPayloadSchema,
|
|
36259
|
+
ConfigChange: ConfigChangePayloadSchema,
|
|
36260
|
+
// CLEO internal coordination events (5)
|
|
35990
36261
|
onWorkAvailable: OnWorkAvailablePayloadSchema,
|
|
35991
36262
|
onAgentSpawn: OnAgentSpawnPayloadSchema,
|
|
35992
36263
|
onAgentComplete: OnAgentCompletePayloadSchema,
|
|
@@ -36016,10 +36287,15 @@ __export(hooks_exports, {
|
|
|
36016
36287
|
OnWorkAvailablePayloadSchema: () => OnWorkAvailablePayloadSchema,
|
|
36017
36288
|
handleError: () => handleError,
|
|
36018
36289
|
handleFileChange: () => handleFileChange,
|
|
36290
|
+
handlePostCompact: () => handlePostCompact,
|
|
36291
|
+
handlePreCompact: () => handlePreCompact,
|
|
36019
36292
|
handlePromptSubmit: () => handlePromptSubmit,
|
|
36020
36293
|
handleResponseComplete: () => handleResponseComplete,
|
|
36021
36294
|
handleSessionEnd: () => handleSessionEnd,
|
|
36022
36295
|
handleSessionStart: () => handleSessionStart,
|
|
36296
|
+
handleSubagentStart: () => handleSubagentStart,
|
|
36297
|
+
handleSubagentStop: () => handleSubagentStop,
|
|
36298
|
+
handleSystemNotification: () => handleSystemNotification,
|
|
36023
36299
|
handleToolComplete: () => handleToolComplete,
|
|
36024
36300
|
handleToolStart: () => handleToolStart,
|
|
36025
36301
|
handleWorkPromptSubmit: () => handleWorkPromptSubmit,
|
|
@@ -62451,7 +62727,7 @@ async function startTask(taskId, cwd, accessor) {
|
|
|
62451
62727
|
accessor
|
|
62452
62728
|
);
|
|
62453
62729
|
const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
|
|
62454
|
-
hooks2.dispatch("
|
|
62730
|
+
hooks2.dispatch("PreToolUse", cwd ?? process.cwd(), {
|
|
62455
62731
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
62456
62732
|
taskId,
|
|
62457
62733
|
taskTitle: task.title
|
|
@@ -62477,7 +62753,7 @@ async function stopTask(cwd, accessor) {
|
|
|
62477
62753
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
62478
62754
|
if (taskId && task) {
|
|
62479
62755
|
const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
|
|
62480
|
-
hooks2.dispatch("
|
|
62756
|
+
hooks2.dispatch("PostToolUse", cwd ?? process.cwd(), {
|
|
62481
62757
|
timestamp: now2,
|
|
62482
62758
|
taskId,
|
|
62483
62759
|
taskTitle: task.title,
|
|
@@ -67985,7 +68261,7 @@ async function restoreSession(projectRoot, snapshot, options = {}, accessor) {
|
|
|
67985
68261
|
await acc.upsertSingleSession(restoredSession);
|
|
67986
68262
|
try {
|
|
67987
68263
|
const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
|
|
67988
|
-
await hooks2.dispatch("
|
|
68264
|
+
await hooks2.dispatch("SessionStart", projectRoot, {
|
|
67989
68265
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
67990
68266
|
sessionId: restoredSession.id,
|
|
67991
68267
|
name: restoredSession.name,
|
|
@@ -69575,6 +69851,14 @@ var init_protocol_enforcement = __esm({
|
|
|
69575
69851
|
});
|
|
69576
69852
|
|
|
69577
69853
|
// packages/core/src/hooks/types.ts
|
|
69854
|
+
import {
|
|
69855
|
+
buildHookMatrix,
|
|
69856
|
+
CANONICAL_HOOK_EVENTS,
|
|
69857
|
+
HOOK_CATEGORIES,
|
|
69858
|
+
supportsHook,
|
|
69859
|
+
toCanonical,
|
|
69860
|
+
toNative
|
|
69861
|
+
} from "@cleocode/caamp";
|
|
69578
69862
|
import { getCommonHookEvents, getProvidersByHookEvent } from "@cleocode/caamp";
|
|
69579
69863
|
function isProviderHookEvent(event) {
|
|
69580
69864
|
return !INTERNAL_HOOK_EVENT_SET.has(event);
|
|
@@ -82384,6 +82668,30 @@ var init_registry5 = __esm({
|
|
|
82384
82668
|
sessionRequired: false,
|
|
82385
82669
|
requiredParams: []
|
|
82386
82670
|
},
|
|
82671
|
+
{
|
|
82672
|
+
gateway: "query",
|
|
82673
|
+
domain: "admin",
|
|
82674
|
+
operation: "hooks.matrix",
|
|
82675
|
+
description: "admin.hooks.matrix (query) \u2014 cross-provider hook support matrix using CAAMP canonical taxonomy",
|
|
82676
|
+
tier: 1,
|
|
82677
|
+
idempotent: true,
|
|
82678
|
+
sessionRequired: false,
|
|
82679
|
+
requiredParams: [],
|
|
82680
|
+
params: [
|
|
82681
|
+
{
|
|
82682
|
+
name: "providerIds",
|
|
82683
|
+
type: "string",
|
|
82684
|
+
required: false,
|
|
82685
|
+
description: "Limit matrix to specific provider IDs (default: all mapped providers)"
|
|
82686
|
+
},
|
|
82687
|
+
{
|
|
82688
|
+
name: "detectProvider",
|
|
82689
|
+
type: "boolean",
|
|
82690
|
+
required: false,
|
|
82691
|
+
description: "Detect current runtime provider (default: true)"
|
|
82692
|
+
}
|
|
82693
|
+
]
|
|
82694
|
+
},
|
|
82387
82695
|
{
|
|
82388
82696
|
gateway: "query",
|
|
82389
82697
|
domain: "admin",
|
|
@@ -83208,6 +83516,114 @@ var init_config_engine = __esm({
|
|
|
83208
83516
|
}
|
|
83209
83517
|
});
|
|
83210
83518
|
|
|
83519
|
+
// packages/cleo/src/dispatch/engines/hooks-engine.ts
|
|
83520
|
+
var hooks_engine_exports = {};
|
|
83521
|
+
__export(hooks_engine_exports, {
|
|
83522
|
+
queryCommonHooks: () => queryCommonHooks,
|
|
83523
|
+
queryHookProviders: () => queryHookProviders,
|
|
83524
|
+
systemHooksMatrix: () => systemHooksMatrix
|
|
83525
|
+
});
|
|
83526
|
+
async function queryHookProviders(event) {
|
|
83527
|
+
if (!isProviderHookEvent(event)) {
|
|
83528
|
+
return engineSuccess({
|
|
83529
|
+
event,
|
|
83530
|
+
providers: []
|
|
83531
|
+
});
|
|
83532
|
+
}
|
|
83533
|
+
const { getProvidersByHookEvent: getProvidersByHookEvent2 } = await import("@cleocode/caamp");
|
|
83534
|
+
const providers = getProvidersByHookEvent2(event);
|
|
83535
|
+
return engineSuccess({
|
|
83536
|
+
event,
|
|
83537
|
+
providers: providers.map((p) => ({
|
|
83538
|
+
id: p.id,
|
|
83539
|
+
name: p.name,
|
|
83540
|
+
supportedHooks: p.capabilities?.hooks?.supported ?? []
|
|
83541
|
+
}))
|
|
83542
|
+
});
|
|
83543
|
+
}
|
|
83544
|
+
async function queryCommonHooks(providerIds) {
|
|
83545
|
+
const { getCommonHookEvents: getCommonHookEvents2 } = await import("@cleocode/caamp");
|
|
83546
|
+
const commonEvents = getCommonHookEvents2(providerIds);
|
|
83547
|
+
return engineSuccess({
|
|
83548
|
+
providerIds,
|
|
83549
|
+
commonEvents
|
|
83550
|
+
});
|
|
83551
|
+
}
|
|
83552
|
+
async function systemHooksMatrix(params) {
|
|
83553
|
+
try {
|
|
83554
|
+
const { buildHookMatrix: buildHookMatrix2, getProviderSummary, getHookMappingsVersion, detectAllProviders: detectAllProviders3 } = await import("@cleocode/caamp");
|
|
83555
|
+
const caampVersion = getHookMappingsVersion();
|
|
83556
|
+
const raw = buildHookMatrix2(params?.providerIds);
|
|
83557
|
+
const boolMatrix = {};
|
|
83558
|
+
for (const event of raw.events) {
|
|
83559
|
+
boolMatrix[event] = {};
|
|
83560
|
+
for (const providerId of raw.providers) {
|
|
83561
|
+
const mapping = raw.matrix[event]?.[providerId];
|
|
83562
|
+
boolMatrix[event][providerId] = mapping?.supported ?? false;
|
|
83563
|
+
}
|
|
83564
|
+
}
|
|
83565
|
+
const summary = raw.providers.map((providerId) => {
|
|
83566
|
+
const provSummary = getProviderSummary(providerId);
|
|
83567
|
+
if (provSummary) {
|
|
83568
|
+
return {
|
|
83569
|
+
providerId,
|
|
83570
|
+
supportedCount: provSummary.supportedCount,
|
|
83571
|
+
totalCanonical: provSummary.totalCanonical,
|
|
83572
|
+
coverage: provSummary.coverage,
|
|
83573
|
+
supported: provSummary.supported,
|
|
83574
|
+
unsupported: provSummary.unsupported
|
|
83575
|
+
};
|
|
83576
|
+
}
|
|
83577
|
+
const supported = raw.events.filter((ev) => boolMatrix[ev]?.[providerId] === true);
|
|
83578
|
+
const unsupported = raw.events.filter((ev) => boolMatrix[ev]?.[providerId] !== true);
|
|
83579
|
+
const totalCanonical = raw.events.length;
|
|
83580
|
+
const coverage = totalCanonical > 0 ? Math.round(supported.length / totalCanonical * 100) : 0;
|
|
83581
|
+
return {
|
|
83582
|
+
providerId,
|
|
83583
|
+
supportedCount: supported.length,
|
|
83584
|
+
totalCanonical,
|
|
83585
|
+
coverage,
|
|
83586
|
+
supported,
|
|
83587
|
+
unsupported
|
|
83588
|
+
};
|
|
83589
|
+
});
|
|
83590
|
+
let detectedProvider = null;
|
|
83591
|
+
const shouldDetect = params?.detectProvider !== false;
|
|
83592
|
+
if (shouldDetect) {
|
|
83593
|
+
try {
|
|
83594
|
+
const detectionResults = detectAllProviders3();
|
|
83595
|
+
const detected = detectionResults.find((r) => r.installed && r.projectDetected);
|
|
83596
|
+
if (detected) {
|
|
83597
|
+
detectedProvider = detected.provider.id;
|
|
83598
|
+
} else {
|
|
83599
|
+
const anyInstalled = detectionResults.find((r) => r.installed);
|
|
83600
|
+
if (anyInstalled) {
|
|
83601
|
+
detectedProvider = anyInstalled.provider.id;
|
|
83602
|
+
}
|
|
83603
|
+
}
|
|
83604
|
+
} catch {
|
|
83605
|
+
}
|
|
83606
|
+
}
|
|
83607
|
+
return engineSuccess({
|
|
83608
|
+
caampVersion,
|
|
83609
|
+
events: raw.events,
|
|
83610
|
+
providers: raw.providers,
|
|
83611
|
+
matrix: boolMatrix,
|
|
83612
|
+
summary,
|
|
83613
|
+
detectedProvider
|
|
83614
|
+
});
|
|
83615
|
+
} catch (err) {
|
|
83616
|
+
return engineError("E_GENERAL", err.message);
|
|
83617
|
+
}
|
|
83618
|
+
}
|
|
83619
|
+
var init_hooks_engine = __esm({
|
|
83620
|
+
"packages/cleo/src/dispatch/engines/hooks-engine.ts"() {
|
|
83621
|
+
"use strict";
|
|
83622
|
+
init_internal();
|
|
83623
|
+
init_error();
|
|
83624
|
+
}
|
|
83625
|
+
});
|
|
83626
|
+
|
|
83211
83627
|
// packages/cleo/src/dispatch/engines/init-engine.ts
|
|
83212
83628
|
async function initProject2(projectRoot, options) {
|
|
83213
83629
|
try {
|
|
@@ -86573,7 +86989,7 @@ async function dispatchFromCli(gateway, domain2, operation, params, outputOpts)
|
|
|
86573
86989
|
const dispatcher = getCliDispatcher();
|
|
86574
86990
|
const projectRoot = getProjectRoot();
|
|
86575
86991
|
const dispatchStart = Date.now();
|
|
86576
|
-
hooks.dispatch("
|
|
86992
|
+
hooks.dispatch("PromptSubmit", projectRoot, {
|
|
86577
86993
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
86578
86994
|
gateway,
|
|
86579
86995
|
domain: domain2,
|
|
@@ -86589,7 +87005,7 @@ async function dispatchFromCli(gateway, domain2, operation, params, outputOpts)
|
|
|
86589
87005
|
source: "cli",
|
|
86590
87006
|
requestId: randomUUID10()
|
|
86591
87007
|
});
|
|
86592
|
-
hooks.dispatch("
|
|
87008
|
+
hooks.dispatch("ResponseComplete", projectRoot, {
|
|
86593
87009
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
86594
87010
|
gateway,
|
|
86595
87011
|
domain: domain2,
|
|
@@ -86646,7 +87062,7 @@ async function dispatchRaw(gateway, domain2, operation, params) {
|
|
|
86646
87062
|
const dispatcher = getCliDispatcher();
|
|
86647
87063
|
const projectRoot = getProjectRoot();
|
|
86648
87064
|
const dispatchStart = Date.now();
|
|
86649
|
-
hooks.dispatch("
|
|
87065
|
+
hooks.dispatch("PromptSubmit", projectRoot, {
|
|
86650
87066
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
86651
87067
|
gateway,
|
|
86652
87068
|
domain: domain2,
|
|
@@ -86662,7 +87078,7 @@ async function dispatchRaw(gateway, domain2, operation, params) {
|
|
|
86662
87078
|
source: "cli",
|
|
86663
87079
|
requestId: randomUUID10()
|
|
86664
87080
|
});
|
|
86665
|
-
hooks.dispatch("
|
|
87081
|
+
hooks.dispatch("ResponseComplete", projectRoot, {
|
|
86666
87082
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
86667
87083
|
gateway,
|
|
86668
87084
|
domain: domain2,
|
|
@@ -88494,6 +88910,7 @@ var init_engine2 = __esm({
|
|
|
88494
88910
|
init_internal();
|
|
88495
88911
|
init_codebase_map_engine();
|
|
88496
88912
|
init_config_engine();
|
|
88913
|
+
init_hooks_engine();
|
|
88497
88914
|
init_init_engine();
|
|
88498
88915
|
init_lifecycle_engine();
|
|
88499
88916
|
init_memory_engine();
|
|
@@ -89022,6 +89439,13 @@ var init_admin2 = __esm({
|
|
|
89022
89439
|
const result = await systemSmoke();
|
|
89023
89440
|
return wrapResult(result, "query", "admin", operation, startTime);
|
|
89024
89441
|
}
|
|
89442
|
+
case "hooks.matrix": {
|
|
89443
|
+
const result = await systemHooksMatrix({
|
|
89444
|
+
providerIds: params?.providerIds,
|
|
89445
|
+
detectProvider: params?.detectProvider !== false
|
|
89446
|
+
});
|
|
89447
|
+
return wrapResult(result, "query", "admin", operation, startTime);
|
|
89448
|
+
}
|
|
89025
89449
|
default:
|
|
89026
89450
|
return unsupportedOp("query", "admin", operation, startTime);
|
|
89027
89451
|
}
|
|
@@ -89506,7 +89930,8 @@ var init_admin2 = __esm({
|
|
|
89506
89930
|
"backup",
|
|
89507
89931
|
"export",
|
|
89508
89932
|
"map",
|
|
89509
|
-
"smoke"
|
|
89933
|
+
"smoke",
|
|
89934
|
+
"hooks.matrix"
|
|
89510
89935
|
],
|
|
89511
89936
|
mutate: [
|
|
89512
89937
|
"init",
|
|
@@ -93208,46 +93633,6 @@ var init_tasks4 = __esm({
|
|
|
93208
93633
|
}
|
|
93209
93634
|
});
|
|
93210
93635
|
|
|
93211
|
-
// packages/cleo/src/dispatch/engines/hooks-engine.ts
|
|
93212
|
-
var hooks_engine_exports = {};
|
|
93213
|
-
__export(hooks_engine_exports, {
|
|
93214
|
-
queryCommonHooks: () => queryCommonHooks,
|
|
93215
|
-
queryHookProviders: () => queryHookProviders
|
|
93216
|
-
});
|
|
93217
|
-
async function queryHookProviders(event) {
|
|
93218
|
-
if (!isProviderHookEvent(event)) {
|
|
93219
|
-
return engineSuccess({
|
|
93220
|
-
event,
|
|
93221
|
-
providers: []
|
|
93222
|
-
});
|
|
93223
|
-
}
|
|
93224
|
-
const { getProvidersByHookEvent: getProvidersByHookEvent2 } = await import("@cleocode/caamp");
|
|
93225
|
-
const providers = getProvidersByHookEvent2(event);
|
|
93226
|
-
return engineSuccess({
|
|
93227
|
-
event,
|
|
93228
|
-
providers: providers.map((p) => ({
|
|
93229
|
-
id: p.id,
|
|
93230
|
-
name: p.name,
|
|
93231
|
-
supportedHooks: p.capabilities?.hooks?.supported ?? []
|
|
93232
|
-
}))
|
|
93233
|
-
});
|
|
93234
|
-
}
|
|
93235
|
-
async function queryCommonHooks(providerIds) {
|
|
93236
|
-
const { getCommonHookEvents: getCommonHookEvents2 } = await import("@cleocode/caamp");
|
|
93237
|
-
const commonEvents = getCommonHookEvents2(providerIds);
|
|
93238
|
-
return engineSuccess({
|
|
93239
|
-
providerIds,
|
|
93240
|
-
commonEvents
|
|
93241
|
-
});
|
|
93242
|
-
}
|
|
93243
|
-
var init_hooks_engine = __esm({
|
|
93244
|
-
"packages/cleo/src/dispatch/engines/hooks-engine.ts"() {
|
|
93245
|
-
"use strict";
|
|
93246
|
-
init_internal();
|
|
93247
|
-
init_error();
|
|
93248
|
-
}
|
|
93249
|
-
});
|
|
93250
|
-
|
|
93251
93636
|
// packages/cleo/src/dispatch/engines/tools-engine.ts
|
|
93252
93637
|
import {
|
|
93253
93638
|
buildInjectionContent,
|
|
@@ -98936,7 +99321,7 @@ async function main() {
|
|
|
98936
99321
|
};
|
|
98937
99322
|
}
|
|
98938
99323
|
}
|
|
98939
|
-
hooks.dispatch("
|
|
99324
|
+
hooks.dispatch("PromptSubmit", process.cwd(), {
|
|
98940
99325
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
98941
99326
|
gateway: name2,
|
|
98942
99327
|
domain: domain2,
|
|
@@ -98946,7 +99331,7 @@ async function main() {
|
|
|
98946
99331
|
});
|
|
98947
99332
|
const dispatchStart = Date.now();
|
|
98948
99333
|
let result = await handleMcpToolCall(name2, domain2, operation, params);
|
|
98949
|
-
hooks.dispatch("
|
|
99334
|
+
hooks.dispatch("ResponseComplete", process.cwd(), {
|
|
98950
99335
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
98951
99336
|
gateway: name2,
|
|
98952
99337
|
domain: domain2,
|
|
@@ -99014,7 +99399,7 @@ async function main() {
|
|
|
99014
99399
|
} catch (error40) {
|
|
99015
99400
|
reqLog.error({ err: error40 }, "Tool call error");
|
|
99016
99401
|
const errorMessage = error40 instanceof Error ? error40.message : String(error40);
|
|
99017
|
-
hooks.dispatch("
|
|
99402
|
+
hooks.dispatch("PostToolUseFailure", process.cwd(), {
|
|
99018
99403
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
99019
99404
|
errorCode: "E_INTERNAL_ERROR",
|
|
99020
99405
|
message: errorMessage,
|