@datagusto/cli 0.2.1 → 0.2.2
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/README.md +1 -0
- package/dist/adapters/claude-code.js +2 -1
- package/dist/adapters/claude-code.js.map +1 -1
- package/dist/hooks/init/update-check.d.ts +3 -0
- package/dist/hooks/init/update-check.js +34 -0
- package/dist/hooks/init/update-check.js.map +1 -0
- package/dist/update-check.d.ts +30 -0
- package/dist/update-check.js +109 -0
- package/dist/update-check.js.map +1 -0
- package/package.json +4 -1
- package/vendor/claude_code/.claude-plugin/plugin.json +2 -2
- package/vendor/claude_code/README.md +47 -16
- package/vendor/claude_code/dist/api-client.js +9 -0
- package/vendor/claude_code/dist/extractors.js +109 -0
- package/vendor/claude_code/dist/index.js +149 -2
- package/vendor/claude_code/hooks/hooks.json +3 -0
- package/vendor/claude_code/package.json +1 -1
- package/vendor/kiro/dist/api-client.js +9 -0
- package/vendor/kiro/dist/extractors.js +109 -0
- package/vendor/kiro/dist/index.js +133 -6
- package/vendor/kiro/package.json +1 -1
- package/vendor/manifest.json +14 -14
|
@@ -39,7 +39,7 @@ import { dirname, join } from "node:path";
|
|
|
39
39
|
import { fileURLToPath } from "node:url";
|
|
40
40
|
import { DatagustoApiClient } from "./api-client.js";
|
|
41
41
|
import { buildToolDefinitions, detectEngine } from "./engine.js";
|
|
42
|
-
import { extractBlockReason, extractPhase, hashPayload, isClaudeCodeCommand, normalizeEvaluateResponse, serializeToolResult, } from "./extractors.js";
|
|
42
|
+
import { clampInspectionContent, extractBlockReason, extractInspectionReason, extractPhase, hashPayload, isBareSlashCommand, isClaudeCodeCommand, normalizeEvaluateResponse, serializeToolResult, } from "./extractors.js";
|
|
43
43
|
import { describeMonitoring, readMonitoringFlag, resolveMonitoring, } from "./monitoring.js";
|
|
44
44
|
import { deleteState, loadState, mutateState, saveState } from "./state.js";
|
|
45
45
|
/**
|
|
@@ -220,6 +220,15 @@ function normalizeHookEvent(value) {
|
|
|
220
220
|
const key = value.trim().toLowerCase().replace(/[\s_-]/g, "");
|
|
221
221
|
return HOOK_EVENT_ALIASES[key] ?? null;
|
|
222
222
|
}
|
|
223
|
+
/** `hook_event_name` from raw stdin, or undefined when it is not JSON. */
|
|
224
|
+
function peekEventName(raw) {
|
|
225
|
+
try {
|
|
226
|
+
return JSON.parse(raw)?.hook_event_name;
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
223
232
|
/**
|
|
224
233
|
* True when the payload carries tool context. This is what decides how an
|
|
225
234
|
* unrecognized event name is handled: an unknown TOOL event is a call we were
|
|
@@ -308,6 +317,43 @@ function resolveMonitoringForHook(cfg, sessionId, state, response, dbg) {
|
|
|
308
317
|
dbg(`Monitoring mode active (${describeMonitoring(decision)}).`);
|
|
309
318
|
return decision;
|
|
310
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Call /sessions/inspect and resolve monitoring mode from its response.
|
|
322
|
+
* "skipped" means nothing was inspected and nothing went wrong: no session,
|
|
323
|
+
* nothing to inspect, or a server that predates the endpoint (FastAPI answers
|
|
324
|
+
* an unknown route with 404 `{"detail":"Not Found"}`, unlike the endpoint's
|
|
325
|
+
* own 404 `{"detail":"Session not found"}`). "error" is for failClosed to
|
|
326
|
+
* judge.
|
|
327
|
+
*/
|
|
328
|
+
async function inspectContent(client, cfg, sessionId, state, evaluationPoint, text, dbg) {
|
|
329
|
+
if (!state.sessionId) {
|
|
330
|
+
dbg(`No sessionId; skipping ${evaluationPoint} inspection.`);
|
|
331
|
+
return { kind: "skipped" };
|
|
332
|
+
}
|
|
333
|
+
const content = clampInspectionContent(text);
|
|
334
|
+
if (content === null) {
|
|
335
|
+
dbg(`Nothing to inspect at ${evaluationPoint}.`);
|
|
336
|
+
return { kind: "skipped" };
|
|
337
|
+
}
|
|
338
|
+
const res = await client.inspectSession({
|
|
339
|
+
session_id: state.sessionId,
|
|
340
|
+
evaluation_point: evaluationPoint,
|
|
341
|
+
content,
|
|
342
|
+
});
|
|
343
|
+
dbg(`Inspect ${evaluationPoint} result: ok=${res.ok}, status=${res.status}`);
|
|
344
|
+
if (res.status === 404 && res.data?.detail === "Not Found") {
|
|
345
|
+
dbg("Server has no /sessions/inspect endpoint; skipping inspection.");
|
|
346
|
+
return { kind: "skipped" };
|
|
347
|
+
}
|
|
348
|
+
if (!res.ok || !res.data)
|
|
349
|
+
return { kind: "error" };
|
|
350
|
+
const monitoring = resolveMonitoringForHook(cfg, sessionId, state, res.data, dbg);
|
|
351
|
+
return { kind: "verdict", data: res.data, monitoring };
|
|
352
|
+
}
|
|
353
|
+
/** Drop trailing periods so the reason can be followed by another sentence. */
|
|
354
|
+
function trimSentence(text) {
|
|
355
|
+
return text.replace(/[\s.。]+$/u, "");
|
|
356
|
+
}
|
|
311
357
|
// ---------------------------------------------------------------------------
|
|
312
358
|
// SessionStart — eager tool registration
|
|
313
359
|
//
|
|
@@ -335,14 +381,63 @@ async function handleSessionStart(payload, client, cfg, dbg) {
|
|
|
335
381
|
saveState(payload.session_id, state);
|
|
336
382
|
}
|
|
337
383
|
// ---------------------------------------------------------------------------
|
|
338
|
-
// Stop — state cleanup (Kiro CLI's
|
|
384
|
+
// Stop — final-response inspection, then state cleanup (Kiro CLI's
|
|
385
|
+
// equivalent of Claude Code's SessionEnd)
|
|
386
|
+
//
|
|
387
|
+
// The response is inspected first: inspection needs the session id that the
|
|
388
|
+
// cleanup deletes. Only V1 and V2 send the response (`assistant_response`);
|
|
389
|
+
// V3 sends none (still so on Kiro CLI 2.34.0), so there is nothing to inspect
|
|
390
|
+
// there.
|
|
391
|
+
//
|
|
392
|
+
// Kiro CLI 2.x cannot hold a response back: its docs give `stop` no blocking
|
|
393
|
+
// or continue mechanism, and any non-zero exit is shown to the user as a
|
|
394
|
+
// warning. So a violation is recorded on the platform and reported to the
|
|
395
|
+
// user on stderr, with exit 2 (observed on 2.34.0 V2: the session ended with
|
|
396
|
+
// the response as it was). V3 can ask the agent to continue (exit 1, or a
|
|
397
|
+
// `decision: "block"` JSON on stdout), but sends no response to inspect, so
|
|
398
|
+
// the plugin never needs it; exit 2 on V3 leaves the response finished.
|
|
399
|
+
// An API error never blocks (the response is already shown, as in the Claude
|
|
400
|
+
// Code plugin); a notice says it went unchecked.
|
|
339
401
|
// ---------------------------------------------------------------------------
|
|
340
402
|
async function handleStop(payload, client, cfg, dbg) {
|
|
341
|
-
|
|
342
|
-
|
|
403
|
+
const state = loadState(payload.session_id);
|
|
404
|
+
try {
|
|
405
|
+
const outcome = await inspectContent(client, cfg, payload.session_id, state, "on_response", payload.assistant_response, dbg);
|
|
406
|
+
if (outcome.kind === "error") {
|
|
407
|
+
emitNotice("[datagusto] The agent's last response could not be checked (inspection API error).");
|
|
408
|
+
}
|
|
409
|
+
else if (outcome.kind === "verdict" && outcome.data.should_proceed === false) {
|
|
410
|
+
const reason = trimSentence(extractInspectionReason(outcome.data));
|
|
411
|
+
dbg(`on_response BLOCKED: ${reason}`);
|
|
412
|
+
if (outcome.monitoring.active) {
|
|
413
|
+
dbg(`[MONITOR] Response block skipped (${describeMonitoring(outcome.monitoring)}).`);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
emitBlock(`[datagusto] The agent's last response violates a policy (Kiro cannot hold it back). ${reason}.`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else if (outcome.kind === "verdict") {
|
|
420
|
+
dbg("on_response ALLOWED");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
finally {
|
|
424
|
+
dbg(`Stop: deleting state for session ${payload.session_id}`);
|
|
425
|
+
deleteState(payload.session_id);
|
|
426
|
+
}
|
|
343
427
|
}
|
|
344
428
|
// ---------------------------------------------------------------------------
|
|
345
|
-
// UserPromptSubmit — tool registration + alignment
|
|
429
|
+
// UserPromptSubmit — tool registration + alignment + prompt inspection
|
|
430
|
+
//
|
|
431
|
+
// The prompt is inspected after alignment, because inspection needs the
|
|
432
|
+
// session alignment creates. Unlike alignment it is not deduplicated by
|
|
433
|
+
// hash: re-sending a flagged prompt must be flagged again.
|
|
434
|
+
//
|
|
435
|
+
// Kiro CLI cannot block a prompt: per its docs the prompt is sent whatever
|
|
436
|
+
// the exit code (observed on 2.34.0, V2 and V3). A violation exits 2 with the
|
|
437
|
+
// reason on stderr, which 2.x shows to the user as a warning, V3 hands to the
|
|
438
|
+
// agent as context, and the IDE treats as a block (per its docs; unverified
|
|
439
|
+
// here). The message is written for all three readers. The verdict is
|
|
440
|
+
// recorded on the platform either way.
|
|
346
441
|
// ---------------------------------------------------------------------------
|
|
347
442
|
async function handleUserPromptSubmit(payload, client, cfg, dbg) {
|
|
348
443
|
const state = loadState(payload.session_id);
|
|
@@ -385,6 +480,33 @@ async function handleUserPromptSubmit(payload, client, cfg, dbg) {
|
|
|
385
480
|
dbg("Prompt is a slash command / bash-mode shortcut, skipping alignment.");
|
|
386
481
|
}
|
|
387
482
|
saveState(payload.session_id, state);
|
|
483
|
+
if (isBareSlashCommand(payload.prompt))
|
|
484
|
+
return;
|
|
485
|
+
const outcome = await inspectContent(client, cfg, payload.session_id, state, "on_prompt_submit", payload.prompt, dbg);
|
|
486
|
+
if (outcome.kind === "error") {
|
|
487
|
+
// Only the plugin's own monitorOnly relaxes fail-closed, as on tool calls.
|
|
488
|
+
if (cfg.failClosed && !cfg.monitorOnly) {
|
|
489
|
+
emitBlock("[datagusto] This prompt could not be checked against the policies (inspection API error).");
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
dbg("Prompt inspection failed; letting the prompt through (fail-open).");
|
|
493
|
+
}
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (outcome.kind !== "verdict")
|
|
497
|
+
return;
|
|
498
|
+
if (outcome.data.should_proceed !== false) {
|
|
499
|
+
dbg("on_prompt_submit ALLOWED");
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const reason = trimSentence(extractInspectionReason(outcome.data));
|
|
503
|
+
dbg(`on_prompt_submit BLOCKED: ${reason}`);
|
|
504
|
+
if (outcome.monitoring.active) {
|
|
505
|
+
dbg(`[MONITOR] Prompt block skipped (${describeMonitoring(outcome.monitoring)}).`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
emitBlock(`[datagusto] This prompt violates a policy. ${reason}. ` +
|
|
509
|
+
"Do not use, repeat or store that content; the prompt should be sent again without it.");
|
|
388
510
|
}
|
|
389
511
|
// ---------------------------------------------------------------------------
|
|
390
512
|
// PreToolUse — on_start validation
|
|
@@ -655,7 +777,9 @@ async function main() {
|
|
|
655
777
|
// DELIBERATE non-blocking fail-open on misconfiguration: exit 1 warns and
|
|
656
778
|
// allows, per the Kiro CLI contract (exit 1 is not the block code — that's
|
|
657
779
|
// exit 2). A broken config must never hard-block every tool call.
|
|
658
|
-
|
|
780
|
+
// Except on Stop, where V3 reads exit 1 as "continue for another turn"
|
|
781
|
+
// (kiro.dev/docs/hooks/types.md): every turn would end in another one.
|
|
782
|
+
process.exit(normalizeHookEvent(peekEventName(raw)) === "Stop" ? 0 : 1);
|
|
659
783
|
}
|
|
660
784
|
// Empty stdin means we have zero context: we cannot tell whether this
|
|
661
785
|
// invocation is gating a tool call or not. Previously this allowed (exit 0),
|
|
@@ -716,6 +840,9 @@ async function main() {
|
|
|
716
840
|
if (event === "PreToolUse" || event === "PostToolUse" || hasToolContext(payload)) {
|
|
717
841
|
emitBlock("Datagusto safety: validation failed.");
|
|
718
842
|
}
|
|
843
|
+
else if (event === "UserPromptSubmit") {
|
|
844
|
+
emitBlock("[datagusto] This prompt could not be checked against the policies.");
|
|
845
|
+
}
|
|
719
846
|
}
|
|
720
847
|
}
|
|
721
848
|
dbg(`=== ${rawEventName} END ===`);
|
package/vendor/kiro/package.json
CHANGED
package/vendor/manifest.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
|
-
"sourceCommit": "
|
|
3
|
+
"sourceCommit": "000628e",
|
|
4
4
|
"plugins": {
|
|
5
5
|
"claude_code": {
|
|
6
|
-
"pluginVersion": "1.
|
|
6
|
+
"pluginVersion": "1.1.0",
|
|
7
7
|
"files": {
|
|
8
|
-
".claude-plugin/plugin.json": "
|
|
9
|
-
"README.md": "
|
|
10
|
-
"dist/api-client.js": "
|
|
8
|
+
".claude-plugin/plugin.json": "01bd48ad1f8d8b000e276e4c00b60283735cd1a3390a243690d294bf28b5c65c",
|
|
9
|
+
"README.md": "4a52a8bb48672ae86d178340f017b2632eec1c71f8e62fbab0ef16cb64143ab9",
|
|
10
|
+
"dist/api-client.js": "e7eec2024f83cda93dcc390e47592ab9a9cb98a545ef230a3e51f73cc9ed5ba8",
|
|
11
11
|
"dist/builtin-tools.generated.js": "870422c2a4403627486e48834fdae6ea5a1cd63dbfe707fa4db613a87028c214",
|
|
12
|
-
"dist/extractors.js": "
|
|
13
|
-
"dist/index.js": "
|
|
12
|
+
"dist/extractors.js": "c22a4ee1d8949a9972ba69ec6154f4e55612da8334cd0247adaff57282c8ff16",
|
|
13
|
+
"dist/index.js": "a33220647ed78b98aa5750285ebaf4aefd8626331490c6be40d0571fc533b2b3",
|
|
14
14
|
"dist/monitoring.js": "81e82124624e0deca9d11472c9ba4cd3ac7b2711b55fa10c45c22bd25f95a9d7",
|
|
15
15
|
"dist/state.js": "66e724266b61fa73760a597d9ca328dd6fc31c7dfe2fb9370c764fadb20b190c",
|
|
16
16
|
"dist/types.js": "a76a10af480d422f5f301cfc7d91a02db1d87695fcbf6d7475063faeb82f76a8",
|
|
17
|
-
"hooks/hooks.json": "
|
|
18
|
-
"package.json": "
|
|
17
|
+
"hooks/hooks.json": "0536e52460908b6595b69516c4cd4e4c1df1c2b2983dce01c62b13dfa3af94ef",
|
|
18
|
+
"package.json": "abeec58ee9a70c625ed259da6074046255a420168597175e8062ead069ab9a67"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"kiro": {
|
|
22
|
-
"pluginVersion": "1.
|
|
22
|
+
"pluginVersion": "1.1.0",
|
|
23
23
|
"files": {
|
|
24
24
|
".kiro/agents/kiro_default.json": "f5cccf42d4f1a4b1a2268685ac74bae0b1068bf18dea7ff4965518a6c7b8d770",
|
|
25
25
|
".kiro/hooks/datagusto-post-tool-use.json": "58dacc6b875e733d63fd13f0f47cb2385eecea1ec29b076f71e8b9d137676258",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
".kiro/hooks/datagusto-session-start.json": "992697cb2504e5527b26400c7aebe7e41f80d410bc0150520503897f6ff33a27",
|
|
28
28
|
".kiro/hooks/datagusto-stop.json": "f416a77d84fd74d97af8fba7b08161bc39d963fe1e4bfa86f9ed49589a16ae51",
|
|
29
29
|
".kiro/hooks/datagusto-user-prompt-submit.json": "752b562e871b19996ec0c63e90d43fdaec9930ed0871db32a95e4cd849c7237a",
|
|
30
|
-
"dist/api-client.js": "
|
|
30
|
+
"dist/api-client.js": "e7eec2024f83cda93dcc390e47592ab9a9cb98a545ef230a3e51f73cc9ed5ba8",
|
|
31
31
|
"dist/builtin-tools.generated.js": "d13ae530ed33a55ec2e7d04c2f78e3b34505f68a952ecdb30a979cb9e26b3493",
|
|
32
32
|
"dist/engine.js": "db0fca121485a6065c6626b4c3b114f06bd9cc8b374fad2d63f6c39565a4e891",
|
|
33
|
-
"dist/extractors.js": "
|
|
34
|
-
"dist/index.js": "
|
|
33
|
+
"dist/extractors.js": "c22a4ee1d8949a9972ba69ec6154f4e55612da8334cd0247adaff57282c8ff16",
|
|
34
|
+
"dist/index.js": "a39bc071062c112434678b8864df7f99e2296f61a39d76fbad3c4c9c3f39f61e",
|
|
35
35
|
"dist/monitoring.js": "81e82124624e0deca9d11472c9ba4cd3ac7b2711b55fa10c45c22bd25f95a9d7",
|
|
36
36
|
"dist/state.js": "66e724266b61fa73760a597d9ca328dd6fc31c7dfe2fb9370c764fadb20b190c",
|
|
37
37
|
"dist/types.js": "a76a10af480d422f5f301cfc7d91a02db1d87695fcbf6d7475063faeb82f76a8",
|
|
38
|
-
"package.json": "
|
|
38
|
+
"package.json": "121b94594a26c9e60ffb7de5c981ce2cb3c729405003600d0f12ba51818a3f8a"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|