@ariso-ai/ari-hooks 0.1.8 → 0.1.9
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/package.json +1 -1
- package/src/hooks.js +21 -1
package/package.json
CHANGED
package/src/hooks.js
CHANGED
|
@@ -81,6 +81,26 @@ function agentTypeOf(input, agent) {
|
|
|
81
81
|
return 'codex';
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// Claude Code auto-delivers a background task's completion as a synthetic
|
|
85
|
+
// UserPromptSubmit turn — the entire prompt is a <task-notification> block,
|
|
86
|
+
// not something the user typed. Recording it verbatim as a "request"
|
|
87
|
+
// pollutes the activity feed with agent-internal bookkeeping, so swap it for
|
|
88
|
+
// a short human-readable stand-in built from the notification's <summary>.
|
|
89
|
+
const TASK_NOTIFICATION_RE = /^<task-notification>[\s\S]*<\/task-notification>$/;
|
|
90
|
+
const SUMMARY_RE = /<summary>([\s\S]*?)<\/summary>/;
|
|
91
|
+
const XML_ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
92
|
+
const decodeXmlEntities = (text) =>
|
|
93
|
+
text.replace(/&(amp|lt|gt|quot|apos);/g, (_, name) => XML_ENTITIES[name]);
|
|
94
|
+
|
|
95
|
+
function taskNotificationStandIn(prompt) {
|
|
96
|
+
const trimmed = prompt.trim();
|
|
97
|
+
if (!TASK_NOTIFICATION_RE.test(trimmed)) return null;
|
|
98
|
+
const summary = trimmed.match(SUMMARY_RE)?.[1]?.trim();
|
|
99
|
+
return summary
|
|
100
|
+
? `The coding agent ran a background task: ${decodeXmlEntities(summary)}`
|
|
101
|
+
: 'The coding agent ran a background task.';
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
/**
|
|
85
105
|
* UserPromptSubmit (Claude Code) / beforeSubmitPrompt (Cursor): remember the
|
|
86
106
|
* prompt so the Stop hook can pair it with the turn's outcome. Both hosts
|
|
@@ -90,7 +110,7 @@ async function onUserPromptSubmit(input) {
|
|
|
90
110
|
const sessionId = sessionIdOf(input);
|
|
91
111
|
if (!sessionId || typeof input.prompt !== 'string') return;
|
|
92
112
|
const session = loadSession(sessionId);
|
|
93
|
-
session.prompts.push(input.prompt);
|
|
113
|
+
session.prompts.push(taskNotificationStandIn(input.prompt) ?? input.prompt);
|
|
94
114
|
saveSession(sessionId, session);
|
|
95
115
|
}
|
|
96
116
|
|