@osfactory/otel-hook 0.2.0 → 0.4.1
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/{adapter-DIgRACtL.d.ts → adapter-BgqtlADe.d.ts} +12 -5
- package/dist/cli.js +1439 -626
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.js +5 -1
- package/dist/config.js.map +1 -1
- package/dist/{content-CoB7aNP1.d.ts → content-M9xIKG7h.d.ts} +8 -1
- package/dist/{events-VxBnDFaO.d.ts → events-C3h3GvHj.d.ts} +58 -0
- package/dist/{filesystem-store-J8jjDMTh.d.ts → filesystem-store-BAq3VGVv.d.ts} +1 -1
- package/dist/{hook-CGpo-vks.d.ts → hook-CQiNa88Q.d.ts} +13 -5
- package/dist/index.d.ts +16 -15
- package/dist/index.js +1569 -741
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +8 -7
- package/dist/install.js +132 -68
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +18 -11
- package/dist/integration.js +618 -158
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +27 -4
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-DXVBc8V9.d.ts → memory-kflYgZbg.d.ts} +2 -2
- package/dist/model.d.ts +3 -2
- package/dist/model.js +81 -41
- package/dist/model.js.map +1 -1
- package/dist/{otlp-log-sink-CeIFDDpn.d.ts → otlp-log-sink-BZIgYPKN.d.ts} +4 -4
- package/dist/{payload-CHr53E_v.d.ts → payload-DpyU8F-z.d.ts} +1 -1
- package/dist/{policy-D1CrlYn3.d.ts → policy-CimmCfRp.d.ts} +1 -1
- package/dist/{ports-Q8x0ODhs.d.ts → ports-B_iwJQPQ.d.ts} +20 -2
- package/dist/privacy.d.ts +4 -4
- package/dist/privacy.js +11 -0
- package/dist/privacy.js.map +1 -1
- package/dist/providers.d.ts +30 -12
- package/dist/providers.js +983 -552
- package/dist/providers.js.map +1 -1
- package/dist/{registry-BzYmC9OC.d.ts → registry-BSBS8t7S.d.ts} +1 -1
- package/dist/runtime.d.ts +88 -12
- package/dist/runtime.js +392 -68
- package/dist/runtime.js.map +1 -1
- package/dist/{semconv-Baoz-0OI.d.ts → semconv-BeUPQ7_q.d.ts} +2 -1
- package/dist/{service-j4jEO6cZ.d.ts → service-CbI9CObT.d.ts} +8 -2
- package/dist/state.d.ts +4 -4
- package/dist/state.js.map +1 -1
- package/dist/target-8RfaVxp8.d.ts +83 -0
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +186 -46
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +17 -10
- package/dist/testing.js +1149 -593
- package/dist/testing.js.map +1 -1
- package/package.json +4 -1
package/dist/providers.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/providers/adapter.ts
|
|
2
|
-
import { z as
|
|
2
|
+
import { z as z10 } from "zod";
|
|
3
3
|
|
|
4
4
|
// src/model/events.ts
|
|
5
|
-
import { z as
|
|
5
|
+
import { z as z9 } from "zod";
|
|
6
6
|
|
|
7
7
|
// src/errors/taxonomy.ts
|
|
8
8
|
import { z } from "zod";
|
|
@@ -392,16 +392,37 @@ var identityClaimSchema = z5.strictObject({
|
|
|
392
392
|
fields: identityClaimFieldsSchema
|
|
393
393
|
});
|
|
394
394
|
|
|
395
|
-
// src/model/
|
|
395
|
+
// src/model/target.ts
|
|
396
396
|
import { z as z6 } from "zod";
|
|
397
|
-
var
|
|
398
|
-
var
|
|
397
|
+
var targetSourceSchema = z6.enum(["tool-path", "shell-cwd", "session-cwd"]);
|
|
398
|
+
var MAX_TARGET_HINT_PATHS = 8;
|
|
399
|
+
var MAX_TARGET_PATH_LENGTH = 4096;
|
|
400
|
+
var localPathSchema = z6.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
|
|
401
|
+
var targetHintSchema = z6.strictObject({
|
|
402
|
+
source: targetSourceSchema,
|
|
403
|
+
paths: z6.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
|
|
404
|
+
/** Absolute directory that relative `paths` resolve against. */
|
|
405
|
+
baseDirectory: localPathSchema.optional()
|
|
406
|
+
}).readonly();
|
|
407
|
+
var workspaceTargetSchema = z6.strictObject({
|
|
408
|
+
workspaceId: workspaceIdSchema,
|
|
409
|
+
/** Branch checked out in that worktree; absent on a detached HEAD. */
|
|
410
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
411
|
+
source: targetSourceSchema
|
|
412
|
+
}).readonly();
|
|
413
|
+
var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
414
|
+
var subagentIdSchema = z6.string().regex(SUBAGENT_ID_PATTERN);
|
|
415
|
+
|
|
416
|
+
// src/model/usage.ts
|
|
417
|
+
import { z as z7 } from "zod";
|
|
418
|
+
var usageTemporalitySchema = z7.enum(["delta", "cumulative"]);
|
|
419
|
+
var cacheCreationAccountingSchema = z7.enum([
|
|
399
420
|
"included-in-input",
|
|
400
421
|
"disjoint-from-input",
|
|
401
422
|
"not-reported"
|
|
402
423
|
]);
|
|
403
|
-
var providerTotalAgreementSchema =
|
|
404
|
-
var usageReportSchema =
|
|
424
|
+
var providerTotalAgreementSchema = z7.enum(["unreported", "agrees", "disagrees"]);
|
|
425
|
+
var usageReportSchema = z7.strictObject({
|
|
405
426
|
temporality: usageTemporalitySchema,
|
|
406
427
|
/** Inclusive input tokens. */
|
|
407
428
|
inputTokens: tokenCountSchema.optional(),
|
|
@@ -418,7 +439,7 @@ var usageReportSchema = z6.strictObject({
|
|
|
418
439
|
/** Total exactly as the provider reported it, if it reported one. */
|
|
419
440
|
providerTotalTokens: tokenCountSchema.optional()
|
|
420
441
|
});
|
|
421
|
-
var canonicalUsageSchema =
|
|
442
|
+
var canonicalUsageSchema = z7.strictObject({
|
|
422
443
|
temporality: usageTemporalitySchema,
|
|
423
444
|
inputTokens: tokenCountSchema,
|
|
424
445
|
cachedInputTokens: tokenCountSchema,
|
|
@@ -573,24 +594,24 @@ var EMPTY_DELTA_USAGE = Object.freeze(
|
|
|
573
594
|
);
|
|
574
595
|
|
|
575
596
|
// src/model/version.ts
|
|
576
|
-
import { z as
|
|
597
|
+
import { z as z8 } from "zod";
|
|
577
598
|
var CANONICAL_SCHEMA_VERSION = 1;
|
|
578
|
-
var canonicalSchemaVersionSchema =
|
|
599
|
+
var canonicalSchemaVersionSchema = z8.literal(CANONICAL_SCHEMA_VERSION);
|
|
579
600
|
|
|
580
601
|
// src/model/events.ts
|
|
581
|
-
var modelDescriptorSchema =
|
|
602
|
+
var modelDescriptorSchema = z9.strictObject({
|
|
582
603
|
modelId: nonEmptyStringSchema,
|
|
583
604
|
/** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
|
|
584
605
|
vendor: nonEmptyStringSchema.optional(),
|
|
585
606
|
family: nonEmptyStringSchema.optional()
|
|
586
607
|
});
|
|
587
|
-
var costFactsSchema =
|
|
608
|
+
var costFactsSchema = z9.strictObject({
|
|
588
609
|
/** ISO 4217 code. */
|
|
589
|
-
currency:
|
|
590
|
-
amount:
|
|
591
|
-
source:
|
|
610
|
+
currency: z9.string().length(3),
|
|
611
|
+
amount: z9.number().min(0).finite(),
|
|
612
|
+
source: z9.enum(["provider-reported", "computed"])
|
|
592
613
|
});
|
|
593
|
-
var canonicalEventTypeSchema =
|
|
614
|
+
var canonicalEventTypeSchema = z9.enum([
|
|
594
615
|
"session.start",
|
|
595
616
|
"session.end",
|
|
596
617
|
"prompt.submitted",
|
|
@@ -604,7 +625,7 @@ var canonicalEventTypeSchema = z8.enum([
|
|
|
604
625
|
"error.raised"
|
|
605
626
|
]);
|
|
606
627
|
var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
|
|
607
|
-
var outcomeSchema =
|
|
628
|
+
var outcomeSchema = z9.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
|
|
608
629
|
var baseEventFields = {
|
|
609
630
|
schemaVersion: canonicalSchemaVersionSchema,
|
|
610
631
|
eventId: eventIdSchema,
|
|
@@ -615,39 +636,45 @@ var baseEventFields = {
|
|
|
615
636
|
occurredAt: epochMillisSchema,
|
|
616
637
|
provenance: sourceProvenanceSchema,
|
|
617
638
|
workspace: workspaceIdentitySchema,
|
|
639
|
+
/**
|
|
640
|
+
* The provider's own id for the subagent this event was emitted inside (e.g.
|
|
641
|
+
* Claude Code's `agent_id`). Absent for the top-level agent. Set by the event
|
|
642
|
+
* factory, never by hand.
|
|
643
|
+
*/
|
|
644
|
+
subagentId: subagentIdSchema.optional(),
|
|
618
645
|
extensions: extensionsSchema.default(emptyExtensions)
|
|
619
646
|
};
|
|
620
|
-
var event = (shape) =>
|
|
647
|
+
var event = (shape) => z9.strictObject({ ...baseEventFields, ...shape });
|
|
621
648
|
var sessionStartEventSchema = event({
|
|
622
|
-
type:
|
|
623
|
-
sessionKind:
|
|
649
|
+
type: z9.literal("session.start"),
|
|
650
|
+
sessionKind: z9.enum(["interactive", "non-interactive", "unknown"]),
|
|
624
651
|
agentName: nonEmptyStringSchema.optional(),
|
|
625
652
|
agentVersion: nonEmptyStringSchema.optional(),
|
|
626
653
|
model: modelDescriptorSchema.optional()
|
|
627
654
|
});
|
|
628
655
|
var sessionEndEventSchema = event({
|
|
629
|
-
type:
|
|
630
|
-
reason:
|
|
656
|
+
type: z9.literal("session.end"),
|
|
657
|
+
reason: z9.enum(["completed", "aborted", "error", "timeout", "unknown"]),
|
|
631
658
|
durationMillis: durationMillisSchema.optional(),
|
|
632
659
|
/** Session totals, typically cumulative. */
|
|
633
660
|
usage: canonicalUsageSchema.optional(),
|
|
634
661
|
cost: costFactsSchema.optional()
|
|
635
662
|
});
|
|
636
663
|
var promptSubmittedEventSchema = event({
|
|
637
|
-
type:
|
|
638
|
-
promptSource:
|
|
664
|
+
type: z9.literal("prompt.submitted"),
|
|
665
|
+
promptSource: z9.enum(["user", "automation", "resumed", "unknown"]),
|
|
639
666
|
content: contentFactSchema.optional(),
|
|
640
|
-
turnIndex:
|
|
667
|
+
turnIndex: z9.number().int().min(0).optional()
|
|
641
668
|
});
|
|
642
669
|
var generationStartEventSchema = event({
|
|
643
|
-
type:
|
|
670
|
+
type: z9.literal("generation.start"),
|
|
644
671
|
generationId: nonEmptyStringSchema,
|
|
645
672
|
model: modelDescriptorSchema,
|
|
646
673
|
requestedMaxOutputTokens: tokenCountSchema.optional(),
|
|
647
674
|
inputContent: contentFactsSchema.optional()
|
|
648
675
|
});
|
|
649
676
|
var generationEndEventSchema = event({
|
|
650
|
-
type:
|
|
677
|
+
type: z9.literal("generation.end"),
|
|
651
678
|
generationId: nonEmptyStringSchema,
|
|
652
679
|
model: modelDescriptorSchema,
|
|
653
680
|
outcome: outcomeSchema,
|
|
@@ -657,7 +684,7 @@ var generationEndEventSchema = event({
|
|
|
657
684
|
cost: costFactsSchema.optional(),
|
|
658
685
|
outputContent: contentFactsSchema.optional()
|
|
659
686
|
});
|
|
660
|
-
var toolKindSchema =
|
|
687
|
+
var toolKindSchema = z9.enum([
|
|
661
688
|
"read",
|
|
662
689
|
"write",
|
|
663
690
|
"execute",
|
|
@@ -668,59 +695,63 @@ var toolKindSchema = z8.enum([
|
|
|
668
695
|
"unknown"
|
|
669
696
|
]);
|
|
670
697
|
var toolStartEventSchema = event({
|
|
671
|
-
type:
|
|
698
|
+
type: z9.literal("tool.start"),
|
|
672
699
|
toolCallId: nonEmptyStringSchema,
|
|
673
700
|
toolName: nonEmptyStringSchema,
|
|
674
701
|
toolKind: toolKindSchema,
|
|
675
702
|
generationId: nonEmptyStringSchema.optional(),
|
|
676
|
-
input: contentFactSchema.optional()
|
|
703
|
+
input: contentFactSchema.optional(),
|
|
704
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
705
|
+
target: workspaceTargetSchema.optional()
|
|
677
706
|
});
|
|
678
707
|
var toolEndEventSchema = event({
|
|
679
|
-
type:
|
|
708
|
+
type: z9.literal("tool.end"),
|
|
680
709
|
toolCallId: nonEmptyStringSchema,
|
|
681
710
|
toolName: nonEmptyStringSchema,
|
|
682
711
|
outcome: outcomeSchema,
|
|
683
712
|
durationMillis: durationMillisSchema.optional(),
|
|
684
713
|
/** Present when the host asked for or recorded a permission decision. */
|
|
685
|
-
permissionDecision:
|
|
686
|
-
output: contentFactSchema.optional()
|
|
714
|
+
permissionDecision: z9.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
|
|
715
|
+
output: contentFactSchema.optional(),
|
|
716
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
717
|
+
target: workspaceTargetSchema.optional()
|
|
687
718
|
});
|
|
688
719
|
var subagentStartEventSchema = event({
|
|
689
|
-
type:
|
|
720
|
+
type: z9.literal("subagent.start"),
|
|
690
721
|
subagentInvocationId: invocationIdSchema,
|
|
691
722
|
subagentType: nonEmptyStringSchema.optional(),
|
|
692
723
|
/** 0 for the top-level agent; 1 for its direct children. */
|
|
693
|
-
delegationDepth:
|
|
724
|
+
delegationDepth: z9.number().int().min(0).max(64),
|
|
694
725
|
model: modelDescriptorSchema.optional()
|
|
695
726
|
});
|
|
696
727
|
var subagentEndEventSchema = event({
|
|
697
|
-
type:
|
|
728
|
+
type: z9.literal("subagent.end"),
|
|
698
729
|
subagentInvocationId: invocationIdSchema,
|
|
699
730
|
outcome: outcomeSchema,
|
|
700
731
|
durationMillis: durationMillisSchema.optional(),
|
|
701
732
|
usage: canonicalUsageSchema.optional()
|
|
702
733
|
});
|
|
703
734
|
var compactionPerformedEventSchema = event({
|
|
704
|
-
type:
|
|
705
|
-
trigger:
|
|
735
|
+
type: z9.literal("compaction.performed"),
|
|
736
|
+
trigger: z9.enum(["automatic", "manual", "unknown"]),
|
|
706
737
|
/** Provider-reported context size before and after compaction, if known. */
|
|
707
738
|
contextTokensBefore: tokenCountSchema.optional(),
|
|
708
739
|
contextTokensAfter: tokenCountSchema.optional(),
|
|
709
|
-
droppedMessageCount:
|
|
740
|
+
droppedMessageCount: z9.number().int().min(0).optional(),
|
|
710
741
|
usage: canonicalUsageSchema.optional()
|
|
711
742
|
});
|
|
712
743
|
var errorRaisedEventSchema = event({
|
|
713
|
-
type:
|
|
744
|
+
type: z9.literal("error.raised"),
|
|
714
745
|
errorCode: otelHookErrorCodeSchema,
|
|
715
746
|
severity: errorSeveritySchema,
|
|
716
747
|
phase: errorPhaseSchema,
|
|
717
|
-
retryable:
|
|
748
|
+
retryable: z9.boolean(),
|
|
718
749
|
/** Error text is content: it is described, never embedded verbatim by default. */
|
|
719
750
|
message: contentFactSchema.optional(),
|
|
720
751
|
/** Non-sensitive, provider-agnostic short label. */
|
|
721
752
|
detail: nonEmptyStringSchema.optional()
|
|
722
753
|
});
|
|
723
|
-
var canonicalEventSchema =
|
|
754
|
+
var canonicalEventSchema = z9.discriminatedUnion("type", [
|
|
724
755
|
sessionStartEventSchema,
|
|
725
756
|
sessionEndEventSchema,
|
|
726
757
|
promptSubmittedEventSchema,
|
|
@@ -735,26 +766,26 @@ var canonicalEventSchema = z8.discriminatedUnion("type", [
|
|
|
735
766
|
]);
|
|
736
767
|
|
|
737
768
|
// src/providers/adapter.ts
|
|
738
|
-
var providerDetectionSchema =
|
|
769
|
+
var providerDetectionSchema = z10.strictObject({
|
|
739
770
|
providerId: resolvedProviderIdSchema,
|
|
740
771
|
confidence: detectionConfidenceSchema,
|
|
741
772
|
/**
|
|
742
773
|
* Short, non-sensitive justifications, e.g. `"payload.hook_event_name present"`.
|
|
743
774
|
* Reasons are exported in diagnostics, so they must not quote payload values.
|
|
744
775
|
*/
|
|
745
|
-
reasons:
|
|
776
|
+
reasons: z10.array(z10.string().min(1).max(160)).max(8),
|
|
746
777
|
providerVersion: nonEmptyStringSchema.optional(),
|
|
747
778
|
/** The provider's own name for this event, when the payload states one. */
|
|
748
779
|
sourceEventName: nonEmptyStringSchema.optional()
|
|
749
780
|
});
|
|
750
|
-
var deliveryIdentifierSupportSchema =
|
|
781
|
+
var deliveryIdentifierSupportSchema = z10.enum(["none", "partial", "all"]);
|
|
751
782
|
var DELIVERY_COMPONENT_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
752
|
-
var deliveryComponentSchema =
|
|
783
|
+
var deliveryComponentSchema = z10.string().regex(
|
|
753
784
|
DELIVERY_COMPONENT_PATTERN,
|
|
754
785
|
"delivery component must be identifier-shaped: no whitespace, no path separators"
|
|
755
786
|
);
|
|
756
787
|
var MAX_DELIVERY_COMPONENTS = 8;
|
|
757
|
-
var providerDeliveryClaimSchema =
|
|
788
|
+
var providerDeliveryClaimSchema = z10.strictObject({
|
|
758
789
|
/**
|
|
759
790
|
* The provider's own session/conversation id. Scopes the callback identity, so
|
|
760
791
|
* two sessions reusing one tool-call id never collide.
|
|
@@ -766,26 +797,26 @@ var providerDeliveryClaimSchema = z9.strictObject({
|
|
|
766
797
|
* Identifier-shaped payload fields that, together with `sourceEventName`,
|
|
767
798
|
* name this callback within the session exactly once.
|
|
768
799
|
*/
|
|
769
|
-
components:
|
|
800
|
+
components: z10.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
|
|
770
801
|
/**
|
|
771
802
|
* Short, non-sensitive justifications, e.g. `"payload.tool_use_id names one
|
|
772
803
|
* tool call"`. Evidence reaches diagnostics, so it must name fields, never
|
|
773
804
|
* quote their values.
|
|
774
805
|
*/
|
|
775
|
-
evidence:
|
|
806
|
+
evidence: z10.array(z10.string().min(1).max(160)).min(1).max(4).readonly()
|
|
776
807
|
});
|
|
777
808
|
var DELIVERY_GAP_REASON_PATTERN = /^[^\n\r\t\\/]{1,240}$/;
|
|
778
|
-
var deliveryGapReasonSchema =
|
|
809
|
+
var deliveryGapReasonSchema = z10.string().regex(
|
|
779
810
|
DELIVERY_GAP_REASON_PATTERN,
|
|
780
811
|
"delivery gap reason must be one line of prose: no path separators, no control characters"
|
|
781
812
|
);
|
|
782
813
|
var MAX_DELIVERY_GAPS = 48;
|
|
783
|
-
var providerDeliveryGapsSchema =
|
|
814
|
+
var providerDeliveryGapsSchema = z10.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
|
|
784
815
|
message: `at most ${String(MAX_DELIVERY_GAPS)} delivery gaps may be declared`
|
|
785
816
|
});
|
|
786
|
-
var providerCapabilitiesSchema =
|
|
817
|
+
var providerCapabilitiesSchema = z10.strictObject({
|
|
787
818
|
/** Event types the adapter can produce. */
|
|
788
|
-
lifecycleEvents:
|
|
819
|
+
lifecycleEvents: z10.array(canonicalEventTypeSchema).max(32).readonly(),
|
|
789
820
|
usageTemporality: usageTemporalitySchema,
|
|
790
821
|
/**
|
|
791
822
|
* Which accumulator series a `cumulative` report continues — that is, which
|
|
@@ -804,32 +835,32 @@ var providerCapabilitiesSchema = z9.strictObject({
|
|
|
804
835
|
* Subagent snapshots keep their own series regardless: a delegated agent's
|
|
805
836
|
* counter is not a point on the parent session's curve.
|
|
806
837
|
*/
|
|
807
|
-
cumulativeUsageSeries:
|
|
808
|
-
reportsCachedInput:
|
|
809
|
-
reportsCacheCreation:
|
|
838
|
+
cumulativeUsageSeries: z10.enum(["event-scope", "session-lifetime"]).optional(),
|
|
839
|
+
reportsCachedInput: z10.boolean(),
|
|
840
|
+
reportsCacheCreation: z10.boolean(),
|
|
810
841
|
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
811
|
-
reportsReasoningOutput:
|
|
812
|
-
reportsProviderTotal:
|
|
813
|
-
reportsCost:
|
|
814
|
-
emitsSubagentEvents:
|
|
815
|
-
emitsCompactionEvents:
|
|
842
|
+
reportsReasoningOutput: z10.boolean(),
|
|
843
|
+
reportsProviderTotal: z10.boolean(),
|
|
844
|
+
reportsCost: z10.boolean(),
|
|
845
|
+
emitsSubagentEvents: z10.boolean(),
|
|
846
|
+
emitsCompactionEvents: z10.boolean(),
|
|
816
847
|
/** True when the provider reads a structured response from stdout. */
|
|
817
|
-
requiresHookResponse:
|
|
848
|
+
requiresHookResponse: z10.boolean(),
|
|
818
849
|
/** How much of this provider's hook traffic is replay-identifiable. */
|
|
819
850
|
deliveryIdentifier: deliveryIdentifierSupportSchema
|
|
820
851
|
});
|
|
821
|
-
var providerHookResponseSchema =
|
|
852
|
+
var providerHookResponseSchema = z10.strictObject({
|
|
822
853
|
/**
|
|
823
854
|
* Always 0. A telemetry hook that can fail the host agent is a liability, so
|
|
824
855
|
* the type forbids expressing anything else (ADR 0004).
|
|
825
856
|
*/
|
|
826
|
-
exitCode:
|
|
857
|
+
exitCode: z10.literal(0),
|
|
827
858
|
/** Protocol response text. Omit to write nothing at all. */
|
|
828
|
-
stdout:
|
|
859
|
+
stdout: z10.string().max(8192).optional(),
|
|
829
860
|
/** Non-sensitive diagnostic text for stderr. */
|
|
830
|
-
stderr:
|
|
861
|
+
stderr: z10.string().max(8192).optional(),
|
|
831
862
|
/** Declares which of the two stdout contracts this response follows. */
|
|
832
|
-
contract:
|
|
863
|
+
contract: z10.enum(["silent", "provider-protocol"])
|
|
833
864
|
});
|
|
834
865
|
var SILENT_HOOK_RESPONSE = Object.freeze({
|
|
835
866
|
exitCode: 0,
|
|
@@ -882,14 +913,14 @@ var unknownDetection = (reasons = ["no adapter recognized the input"]) => provid
|
|
|
882
913
|
});
|
|
883
914
|
|
|
884
915
|
// src/errors/index.ts
|
|
885
|
-
import { z as
|
|
886
|
-
var otelHookErrorInfoSchema =
|
|
916
|
+
import { z as z11 } from "zod";
|
|
917
|
+
var otelHookErrorInfoSchema = z11.strictObject({
|
|
887
918
|
code: otelHookErrorCodeSchema,
|
|
888
919
|
severity: errorSeveritySchema,
|
|
889
920
|
phase: errorPhaseSchema,
|
|
890
921
|
posture: failurePostureSchema,
|
|
891
|
-
retryable:
|
|
892
|
-
message:
|
|
922
|
+
retryable: z11.boolean(),
|
|
923
|
+
message: z11.string().min(1).max(512),
|
|
893
924
|
details: attributesSchema.optional(),
|
|
894
925
|
occurredAt: epochMillisSchema.optional()
|
|
895
926
|
});
|
|
@@ -947,10 +978,15 @@ var createEventFactory = (input) => {
|
|
|
947
978
|
const { identity, context } = input;
|
|
948
979
|
const built = [];
|
|
949
980
|
const dropped = [];
|
|
981
|
+
const hints = /* @__PURE__ */ new Map();
|
|
950
982
|
let sequence = input.sequenceBase;
|
|
983
|
+
const subagentId = input.subagentId !== void 0 && subagentIdSchema.safeParse(input.subagentId).success ? input.subagentId : void 0;
|
|
951
984
|
return {
|
|
952
985
|
build: (draft) => {
|
|
953
|
-
const { occurredAt, extensions, idDiscriminator, ...
|
|
986
|
+
const { occurredAt, extensions, idDiscriminator, targetHint, ...drafted } = draft;
|
|
987
|
+
const rest = { ...drafted };
|
|
988
|
+
delete rest.target;
|
|
989
|
+
delete rest.subagentId;
|
|
954
990
|
const sanitized = extensions === void 0 ? { extensions: {}, droppedKeys: [] } : context.privacy.sanitizeExtensions(extensions);
|
|
955
991
|
dropped.push(...sanitized.droppedKeys);
|
|
956
992
|
const currentSequence = sequence;
|
|
@@ -970,6 +1006,7 @@ var createEventFactory = (input) => {
|
|
|
970
1006
|
occurredAt: occurredAt ?? context.clock.now(),
|
|
971
1007
|
provenance: identity.provenance,
|
|
972
1008
|
workspace: identity.workspace,
|
|
1009
|
+
...subagentId === void 0 ? {} : { subagentId },
|
|
973
1010
|
extensions: sanitized.extensions
|
|
974
1011
|
};
|
|
975
1012
|
const parsed = canonicalEventSchema.safeParse(candidate);
|
|
@@ -982,11 +1019,18 @@ var createEventFactory = (input) => {
|
|
|
982
1019
|
});
|
|
983
1020
|
}
|
|
984
1021
|
built.push(parsed.data);
|
|
1022
|
+
if (targetHint !== void 0 && (parsed.data.type === "tool.start" || parsed.data.type === "tool.end")) {
|
|
1023
|
+
const hint = targetHintSchema.safeParse(targetHint);
|
|
1024
|
+
if (hint.success) {
|
|
1025
|
+
hints.set(parsed.data.eventId, hint.data);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
985
1028
|
return parsed.data;
|
|
986
1029
|
},
|
|
987
1030
|
events: () => [...built],
|
|
988
1031
|
nextSequence: () => sequence,
|
|
989
|
-
droppedExtensionKeys: () => [...dropped]
|
|
1032
|
+
droppedExtensionKeys: () => [...dropped],
|
|
1033
|
+
targetHints: () => new Map(hints)
|
|
990
1034
|
};
|
|
991
1035
|
};
|
|
992
1036
|
|
|
@@ -1146,35 +1190,35 @@ var CLAUDE_CODE_CAPABILITIES = Object.freeze({
|
|
|
1146
1190
|
});
|
|
1147
1191
|
|
|
1148
1192
|
// src/providers/claude/schema.ts
|
|
1149
|
-
import { z as
|
|
1193
|
+
import { z as z12 } from "zod";
|
|
1150
1194
|
var commonFields = {
|
|
1151
|
-
session_id:
|
|
1152
|
-
transcript_path:
|
|
1153
|
-
cwd:
|
|
1154
|
-
permission_mode:
|
|
1195
|
+
session_id: z12.string().min(1),
|
|
1196
|
+
transcript_path: z12.string().min(1).optional(),
|
|
1197
|
+
cwd: z12.string().min(1).optional(),
|
|
1198
|
+
permission_mode: z12.string().min(1).optional(),
|
|
1155
1199
|
/** Correlates a hook firing with the user prompt that triggered it (Claude Code v2.1.196+). */
|
|
1156
|
-
prompt_id:
|
|
1200
|
+
prompt_id: z12.string().min(1).optional(),
|
|
1157
1201
|
/** Present when the hook fired while running inside a subagent. */
|
|
1158
|
-
agent_id:
|
|
1159
|
-
agent_type:
|
|
1202
|
+
agent_id: z12.string().min(1).optional(),
|
|
1203
|
+
agent_type: z12.string().min(1).optional()
|
|
1160
1204
|
};
|
|
1161
|
-
var claudeCacheCreationSchema =
|
|
1162
|
-
ephemeral_5m_input_tokens:
|
|
1163
|
-
ephemeral_1h_input_tokens:
|
|
1205
|
+
var claudeCacheCreationSchema = z12.object({
|
|
1206
|
+
ephemeral_5m_input_tokens: z12.number().int().min(0).optional(),
|
|
1207
|
+
ephemeral_1h_input_tokens: z12.number().int().min(0).optional()
|
|
1164
1208
|
});
|
|
1165
|
-
var claudeUsageIterationSchema =
|
|
1166
|
-
input_tokens:
|
|
1167
|
-
output_tokens:
|
|
1168
|
-
cache_creation_input_tokens:
|
|
1169
|
-
cache_read_input_tokens:
|
|
1209
|
+
var claudeUsageIterationSchema = z12.object({
|
|
1210
|
+
input_tokens: z12.number().int().min(0).optional(),
|
|
1211
|
+
output_tokens: z12.number().int().min(0).optional(),
|
|
1212
|
+
cache_creation_input_tokens: z12.number().int().min(0).optional(),
|
|
1213
|
+
cache_read_input_tokens: z12.number().int().min(0).optional()
|
|
1170
1214
|
});
|
|
1171
|
-
var claudeUsageSchema =
|
|
1172
|
-
input_tokens:
|
|
1173
|
-
output_tokens:
|
|
1174
|
-
cache_creation_input_tokens:
|
|
1175
|
-
cache_read_input_tokens:
|
|
1215
|
+
var claudeUsageSchema = z12.object({
|
|
1216
|
+
input_tokens: z12.number().int().min(0),
|
|
1217
|
+
output_tokens: z12.number().int().min(0),
|
|
1218
|
+
cache_creation_input_tokens: z12.number().int().min(0).optional(),
|
|
1219
|
+
cache_read_input_tokens: z12.number().int().min(0).optional(),
|
|
1176
1220
|
cache_creation: claudeCacheCreationSchema.optional(),
|
|
1177
|
-
iterations:
|
|
1221
|
+
iterations: z12.array(claudeUsageIterationSchema).optional(),
|
|
1178
1222
|
/**
|
|
1179
1223
|
* Counters the canonical model has a home for but Claude Code never reports:
|
|
1180
1224
|
* 0 of 4,999 real usage objects carried either (finding 5).
|
|
@@ -1183,105 +1227,112 @@ var claudeUsageSchema = z11.object({
|
|
|
1183
1227
|
* that a harness attaching one gets told it was excluded, instead of watching
|
|
1184
1228
|
* it vanish. See `CLAUDE_EXCLUDED_USAGE_COUNTERS`.
|
|
1185
1229
|
*/
|
|
1186
|
-
total_tokens:
|
|
1187
|
-
reasoning_output_tokens:
|
|
1230
|
+
total_tokens: z12.number().int().min(0).optional(),
|
|
1231
|
+
reasoning_output_tokens: z12.number().int().min(0).optional()
|
|
1188
1232
|
});
|
|
1189
|
-
var sessionStartPayloadSchema =
|
|
1233
|
+
var sessionStartPayloadSchema = z12.object({
|
|
1190
1234
|
...commonFields,
|
|
1191
|
-
hook_event_name:
|
|
1235
|
+
hook_event_name: z12.literal("SessionStart"),
|
|
1192
1236
|
/** Matcher values: startup | resume | clear | compact | fork. Forward-compatible: any string. */
|
|
1193
|
-
source:
|
|
1194
|
-
model:
|
|
1195
|
-
session_title:
|
|
1237
|
+
source: z12.string().min(1).optional(),
|
|
1238
|
+
model: z12.string().min(1).optional(),
|
|
1239
|
+
session_title: z12.string().min(1).optional()
|
|
1196
1240
|
});
|
|
1197
|
-
var sessionEndPayloadSchema =
|
|
1241
|
+
var sessionEndPayloadSchema = z12.object({
|
|
1198
1242
|
...commonFields,
|
|
1199
|
-
hook_event_name:
|
|
1243
|
+
hook_event_name: z12.literal("SessionEnd"),
|
|
1200
1244
|
/** Current Claude Code field; values include clear, logout, prompt_input_exit, and other. */
|
|
1201
|
-
reason:
|
|
1245
|
+
reason: z12.string().min(1).optional(),
|
|
1202
1246
|
/** Compatibility alias emitted by older wrappers and hook integrations. */
|
|
1203
|
-
end_reason:
|
|
1247
|
+
end_reason: z12.string().min(1).optional()
|
|
1204
1248
|
});
|
|
1205
|
-
var userPromptSubmitPayloadSchema =
|
|
1249
|
+
var userPromptSubmitPayloadSchema = z12.object({
|
|
1206
1250
|
...commonFields,
|
|
1207
|
-
hook_event_name:
|
|
1208
|
-
prompt:
|
|
1251
|
+
hook_event_name: z12.literal("UserPromptSubmit"),
|
|
1252
|
+
prompt: z12.string()
|
|
1209
1253
|
});
|
|
1210
|
-
var preToolUsePayloadSchema =
|
|
1254
|
+
var preToolUsePayloadSchema = z12.object({
|
|
1211
1255
|
...commonFields,
|
|
1212
|
-
hook_event_name:
|
|
1213
|
-
tool_name:
|
|
1214
|
-
tool_input:
|
|
1215
|
-
tool_use_id:
|
|
1256
|
+
hook_event_name: z12.literal("PreToolUse"),
|
|
1257
|
+
tool_name: z12.string().min(1),
|
|
1258
|
+
tool_input: z12.unknown(),
|
|
1259
|
+
tool_use_id: z12.string().min(1)
|
|
1216
1260
|
});
|
|
1217
|
-
var postToolUsePayloadSchema =
|
|
1261
|
+
var postToolUsePayloadSchema = z12.object({
|
|
1218
1262
|
...commonFields,
|
|
1219
|
-
hook_event_name:
|
|
1220
|
-
tool_name:
|
|
1221
|
-
tool_input:
|
|
1222
|
-
tool_response:
|
|
1223
|
-
tool_use_id:
|
|
1263
|
+
hook_event_name: z12.literal("PostToolUse"),
|
|
1264
|
+
tool_name: z12.string().min(1),
|
|
1265
|
+
tool_input: z12.unknown().optional(),
|
|
1266
|
+
tool_response: z12.unknown(),
|
|
1267
|
+
tool_use_id: z12.string().min(1)
|
|
1224
1268
|
});
|
|
1225
|
-
var postToolUseFailurePayloadSchema =
|
|
1269
|
+
var postToolUseFailurePayloadSchema = z12.object({
|
|
1226
1270
|
...commonFields,
|
|
1227
|
-
hook_event_name:
|
|
1228
|
-
tool_name:
|
|
1229
|
-
tool_input:
|
|
1230
|
-
tool_error:
|
|
1231
|
-
tool_use_id:
|
|
1271
|
+
hook_event_name: z12.literal("PostToolUseFailure"),
|
|
1272
|
+
tool_name: z12.string().min(1),
|
|
1273
|
+
tool_input: z12.unknown().optional(),
|
|
1274
|
+
tool_error: z12.unknown(),
|
|
1275
|
+
tool_use_id: z12.string().min(1)
|
|
1232
1276
|
});
|
|
1233
|
-
var permissionRequestPayloadSchema =
|
|
1277
|
+
var permissionRequestPayloadSchema = z12.object({
|
|
1234
1278
|
...commonFields,
|
|
1235
|
-
hook_event_name:
|
|
1236
|
-
tool_name:
|
|
1237
|
-
tool_input:
|
|
1238
|
-
tool_use_id:
|
|
1279
|
+
hook_event_name: z12.literal("PermissionRequest"),
|
|
1280
|
+
tool_name: z12.string().min(1),
|
|
1281
|
+
tool_input: z12.unknown().optional(),
|
|
1282
|
+
tool_use_id: z12.string().min(1)
|
|
1239
1283
|
});
|
|
1240
|
-
var subagentStartPayloadSchema =
|
|
1284
|
+
var subagentStartPayloadSchema = z12.object({
|
|
1241
1285
|
...commonFields,
|
|
1242
|
-
hook_event_name:
|
|
1243
|
-
agent_type:
|
|
1244
|
-
agent_id:
|
|
1286
|
+
hook_event_name: z12.literal("SubagentStart"),
|
|
1287
|
+
agent_type: z12.string().min(1),
|
|
1288
|
+
agent_id: z12.string().min(1)
|
|
1245
1289
|
});
|
|
1246
|
-
var subagentStopPayloadSchema =
|
|
1290
|
+
var subagentStopPayloadSchema = z12.object({
|
|
1247
1291
|
...commonFields,
|
|
1248
|
-
hook_event_name:
|
|
1249
|
-
agent_type:
|
|
1250
|
-
agent_id:
|
|
1251
|
-
last_assistant_message:
|
|
1292
|
+
hook_event_name: z12.literal("SubagentStop"),
|
|
1293
|
+
agent_type: z12.string().min(1),
|
|
1294
|
+
agent_id: z12.string().min(1),
|
|
1295
|
+
last_assistant_message: z12.string().optional(),
|
|
1252
1296
|
/** True when this stop fired because a hook continued the subagent's turn. */
|
|
1253
|
-
stop_hook_active:
|
|
1297
|
+
stop_hook_active: z12.boolean().optional(),
|
|
1254
1298
|
usage: claudeUsageSchema.optional()
|
|
1255
1299
|
});
|
|
1256
|
-
var preCompactPayloadSchema =
|
|
1300
|
+
var preCompactPayloadSchema = z12.object({
|
|
1257
1301
|
...commonFields,
|
|
1258
|
-
hook_event_name:
|
|
1302
|
+
hook_event_name: z12.literal("PreCompact"),
|
|
1259
1303
|
/** Upstream values: manual | auto. Forward-compatible: any string. */
|
|
1260
|
-
trigger:
|
|
1304
|
+
trigger: z12.string().min(1).optional(),
|
|
1261
1305
|
/** Compatibility alias emitted by older wrappers and hook integrations. */
|
|
1262
|
-
compact_trigger:
|
|
1306
|
+
compact_trigger: z12.string().min(1).optional(),
|
|
1263
1307
|
/**
|
|
1264
1308
|
* Harness-supplied, never upstream. Reported as an explicit exclusion rather
|
|
1265
1309
|
* than carried across the process boundary: see `events.ts`.
|
|
1266
1310
|
*/
|
|
1267
|
-
context_tokens_before:
|
|
1268
|
-
estimated_tokens_removed:
|
|
1311
|
+
context_tokens_before: z12.number().int().min(0).optional(),
|
|
1312
|
+
estimated_tokens_removed: z12.number().int().min(0).optional()
|
|
1269
1313
|
});
|
|
1270
|
-
var postCompactPayloadSchema =
|
|
1314
|
+
var postCompactPayloadSchema = z12.object({
|
|
1271
1315
|
...commonFields,
|
|
1272
|
-
hook_event_name:
|
|
1273
|
-
trigger:
|
|
1274
|
-
compact_trigger:
|
|
1316
|
+
hook_event_name: z12.literal("PostCompact"),
|
|
1317
|
+
trigger: z12.string().min(1).optional(),
|
|
1318
|
+
compact_trigger: z12.string().min(1).optional(),
|
|
1275
1319
|
/** Harness-supplied, never upstream; accepted here because one callback carries both. */
|
|
1276
|
-
context_tokens_before:
|
|
1277
|
-
context_tokens_after:
|
|
1278
|
-
dropped_message_count:
|
|
1320
|
+
context_tokens_before: z12.number().int().min(0).optional(),
|
|
1321
|
+
context_tokens_after: z12.number().int().min(0).optional(),
|
|
1322
|
+
dropped_message_count: z12.number().int().min(0).optional(),
|
|
1279
1323
|
usage: claudeUsageSchema.optional()
|
|
1280
1324
|
});
|
|
1281
|
-
var stopPayloadSchema =
|
|
1325
|
+
var stopPayloadSchema = z12.object({
|
|
1282
1326
|
...commonFields,
|
|
1283
|
-
hook_event_name:
|
|
1284
|
-
|
|
1327
|
+
hook_event_name: z12.literal("Stop"),
|
|
1328
|
+
/**
|
|
1329
|
+
* Interactive Stop field (Claude Code ≥ 2.1.47). Print / `-p` / Agent SDK
|
|
1330
|
+
* result messages use `result` instead; `events.ts` reads both (and camelCase
|
|
1331
|
+
* `lastAssistantMessage`) through `extractClaudeAssistantText`.
|
|
1332
|
+
*/
|
|
1333
|
+
last_assistant_message: z12.string().optional(),
|
|
1334
|
+
/** Print / `-p` JSON result field; accepted so a harness can attach it as-is. */
|
|
1335
|
+
result: z12.string().optional(),
|
|
1285
1336
|
/**
|
|
1286
1337
|
* True when this stop fired because a hook continued the turn.
|
|
1287
1338
|
*
|
|
@@ -1289,22 +1340,22 @@ var stopPayloadSchema = z11.object({
|
|
|
1289
1340
|
* stop from a continuation stop, which is what lets `delivery.ts` deduplicate
|
|
1290
1341
|
* the former without suppressing the latter.
|
|
1291
1342
|
*/
|
|
1292
|
-
stop_hook_active:
|
|
1343
|
+
stop_hook_active: z12.boolean().optional(),
|
|
1293
1344
|
usage: claudeUsageSchema.optional()
|
|
1294
1345
|
});
|
|
1295
|
-
var stopFailurePayloadSchema =
|
|
1346
|
+
var stopFailurePayloadSchema = z12.object({
|
|
1296
1347
|
...commonFields,
|
|
1297
|
-
hook_event_name:
|
|
1348
|
+
hook_event_name: z12.literal("StopFailure"),
|
|
1298
1349
|
/**
|
|
1299
1350
|
* Matcher values: rate_limit | overloaded | authentication_failed |
|
|
1300
1351
|
* oauth_org_not_allowed | billing_error | invalid_request | model_not_found
|
|
1301
1352
|
* | server_error | max_output_tokens | unknown.
|
|
1302
1353
|
*/
|
|
1303
|
-
error_type:
|
|
1304
|
-
error_message:
|
|
1354
|
+
error_type: z12.string().min(1),
|
|
1355
|
+
error_message: z12.string().optional(),
|
|
1305
1356
|
usage: claudeUsageSchema.optional()
|
|
1306
1357
|
});
|
|
1307
|
-
var claudeHookPayloadSchema =
|
|
1358
|
+
var claudeHookPayloadSchema = z12.discriminatedUnion("hook_event_name", [
|
|
1308
1359
|
sessionStartPayloadSchema,
|
|
1309
1360
|
sessionEndPayloadSchema,
|
|
1310
1361
|
userPromptSubmitPayloadSchema,
|
|
@@ -1334,16 +1385,239 @@ var CLAUDE_HOOK_EVENT_NAMES = [
|
|
|
1334
1385
|
"Stop",
|
|
1335
1386
|
"StopFailure"
|
|
1336
1387
|
];
|
|
1337
|
-
var claudeIdentityFieldsSchema =
|
|
1338
|
-
session_id:
|
|
1339
|
-
hook_event_name:
|
|
1340
|
-
cwd:
|
|
1341
|
-
prompt_id:
|
|
1342
|
-
agent_id:
|
|
1343
|
-
tool_use_id:
|
|
1388
|
+
var claudeIdentityFieldsSchema = z12.object({
|
|
1389
|
+
session_id: z12.string().min(1),
|
|
1390
|
+
hook_event_name: z12.string().min(1),
|
|
1391
|
+
cwd: z12.string().min(1).optional(),
|
|
1392
|
+
prompt_id: z12.string().min(1).optional(),
|
|
1393
|
+
agent_id: z12.string().min(1).optional(),
|
|
1394
|
+
tool_use_id: z12.string().min(1).optional(),
|
|
1344
1395
|
/** Read by `delivery.ts` to tell a once-per-prompt stop from a continuation. */
|
|
1345
|
-
stop_hook_active:
|
|
1396
|
+
stop_hook_active: z12.boolean().optional()
|
|
1397
|
+
});
|
|
1398
|
+
|
|
1399
|
+
// src/providers/claude/usage.ts
|
|
1400
|
+
var CLAUDE_EXCLUDED_USAGE_COUNTERS = Object.freeze({
|
|
1401
|
+
total_tokens: `usage.total_tokens is outside Claude Code's usage contract (capability reportsProviderTotal=false): it is not read, so providerTotalAgreement stays "unreported"`,
|
|
1402
|
+
reasoning_output_tokens: "usage.reasoning_output_tokens is outside Claude Code's usage contract (capability reportsReasoningOutput=false): Anthropic bills thinking tokens inside output_tokens with no separate counter, so it is not read and reasoningOutputTokens stays 0"
|
|
1403
|
+
});
|
|
1404
|
+
var ITERATION_COUNTERS = [
|
|
1405
|
+
"input_tokens",
|
|
1406
|
+
"output_tokens",
|
|
1407
|
+
"cache_read_input_tokens",
|
|
1408
|
+
"cache_creation_input_tokens"
|
|
1409
|
+
];
|
|
1410
|
+
var ttlSplitTotal = (raw) => {
|
|
1411
|
+
const split = raw.cache_creation;
|
|
1412
|
+
if (split === void 0) {
|
|
1413
|
+
return void 0;
|
|
1414
|
+
}
|
|
1415
|
+
return (split.ephemeral_5m_input_tokens ?? 0) + (split.ephemeral_1h_input_tokens ?? 0);
|
|
1416
|
+
};
|
|
1417
|
+
var resolveCacheCreationTokens = (raw, warnings) => {
|
|
1418
|
+
const declared = raw.cache_creation_input_tokens;
|
|
1419
|
+
const split = ttlSplitTotal(raw);
|
|
1420
|
+
if (declared === void 0) {
|
|
1421
|
+
return split ?? 0;
|
|
1422
|
+
}
|
|
1423
|
+
if (split !== void 0 && split !== declared) {
|
|
1424
|
+
warnings.push(
|
|
1425
|
+
`usage.cache_creation TTL buckets sum to ${String(split)} but usage.cache_creation_input_tokens reports ${String(declared)}; the explicit counter is used and the buckets are never added to it`
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
return declared;
|
|
1429
|
+
};
|
|
1430
|
+
var auditIterations = (raw, cacheCreationInputTokens, warnings) => {
|
|
1431
|
+
const iterations = raw.iterations;
|
|
1432
|
+
if (iterations === void 0 || iterations.length === 0) {
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
const outer = {
|
|
1436
|
+
input_tokens: raw.input_tokens,
|
|
1437
|
+
output_tokens: raw.output_tokens,
|
|
1438
|
+
cache_read_input_tokens: raw.cache_read_input_tokens ?? 0,
|
|
1439
|
+
cache_creation_input_tokens: cacheCreationInputTokens
|
|
1440
|
+
};
|
|
1441
|
+
for (const counter of ITERATION_COUNTERS) {
|
|
1442
|
+
const summed = iterations.reduce((total, iteration) => total + (iteration[counter] ?? 0), 0);
|
|
1443
|
+
if (summed !== outer[counter]) {
|
|
1444
|
+
warnings.push(
|
|
1445
|
+
`usage.iterations[].${counter} sums to ${String(summed)} but usage.${counter} reports ${String(outer[counter])}; the outer counter is used and per-iteration figures are never added to it`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
var auditExcludedCounters = (raw, warnings) => {
|
|
1451
|
+
if (raw.total_tokens !== void 0) {
|
|
1452
|
+
warnings.push(CLAUDE_EXCLUDED_USAGE_COUNTERS.total_tokens);
|
|
1453
|
+
}
|
|
1454
|
+
if (raw.reasoning_output_tokens !== void 0) {
|
|
1455
|
+
warnings.push(CLAUDE_EXCLUDED_USAGE_COUNTERS.reasoning_output_tokens);
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
var ACCOUNTING_RETAINED_NOTE_PREFIX = "cacheCreationAccounting=";
|
|
1459
|
+
var forwardableNotes = (notes) => notes.filter((note) => !note.startsWith(ACCOUNTING_RETAINED_NOTE_PREFIX));
|
|
1460
|
+
var asRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1461
|
+
var asNonNegativeInt = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
1462
|
+
var coerceClaudeUsage = (value) => {
|
|
1463
|
+
const record = asRecord(value);
|
|
1464
|
+
if (record === void 0) {
|
|
1465
|
+
return void 0;
|
|
1466
|
+
}
|
|
1467
|
+
const inputTokens = asNonNegativeInt(record.input_tokens ?? record.inputTokens);
|
|
1468
|
+
const outputTokens = asNonNegativeInt(record.output_tokens ?? record.outputTokens);
|
|
1469
|
+
if (inputTokens === void 0 || outputTokens === void 0) {
|
|
1470
|
+
return void 0;
|
|
1471
|
+
}
|
|
1472
|
+
const cacheCreation = asRecord(record.cache_creation ?? record.cacheCreation);
|
|
1473
|
+
const parsed = claudeUsageSchema.safeParse({
|
|
1474
|
+
input_tokens: inputTokens,
|
|
1475
|
+
output_tokens: outputTokens,
|
|
1476
|
+
...asNonNegativeInt(record.cache_creation_input_tokens ?? record.cacheCreationInputTokens) === void 0 ? {} : {
|
|
1477
|
+
cache_creation_input_tokens: asNonNegativeInt(
|
|
1478
|
+
record.cache_creation_input_tokens ?? record.cacheCreationInputTokens
|
|
1479
|
+
)
|
|
1480
|
+
},
|
|
1481
|
+
...asNonNegativeInt(record.cache_read_input_tokens ?? record.cacheReadInputTokens) === void 0 ? {} : {
|
|
1482
|
+
cache_read_input_tokens: asNonNegativeInt(
|
|
1483
|
+
record.cache_read_input_tokens ?? record.cacheReadInputTokens
|
|
1484
|
+
)
|
|
1485
|
+
},
|
|
1486
|
+
...cacheCreation === void 0 ? {} : {
|
|
1487
|
+
cache_creation: {
|
|
1488
|
+
...asNonNegativeInt(
|
|
1489
|
+
cacheCreation.ephemeral_5m_input_tokens ?? cacheCreation.ephemeral5mInputTokens
|
|
1490
|
+
) === void 0 ? {} : {
|
|
1491
|
+
ephemeral_5m_input_tokens: asNonNegativeInt(
|
|
1492
|
+
cacheCreation.ephemeral_5m_input_tokens ?? cacheCreation.ephemeral5mInputTokens
|
|
1493
|
+
)
|
|
1494
|
+
},
|
|
1495
|
+
...asNonNegativeInt(
|
|
1496
|
+
cacheCreation.ephemeral_1h_input_tokens ?? cacheCreation.ephemeral1hInputTokens
|
|
1497
|
+
) === void 0 ? {} : {
|
|
1498
|
+
ephemeral_1h_input_tokens: asNonNegativeInt(
|
|
1499
|
+
cacheCreation.ephemeral_1h_input_tokens ?? cacheCreation.ephemeral1hInputTokens
|
|
1500
|
+
)
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
},
|
|
1504
|
+
...Array.isArray(record.iterations) ? { iterations: record.iterations } : {},
|
|
1505
|
+
...asNonNegativeInt(record.total_tokens ?? record.totalTokens) === void 0 ? {} : { total_tokens: asNonNegativeInt(record.total_tokens ?? record.totalTokens) },
|
|
1506
|
+
...asNonNegativeInt(record.reasoning_output_tokens ?? record.reasoningOutputTokens) === void 0 ? {} : {
|
|
1507
|
+
reasoning_output_tokens: asNonNegativeInt(
|
|
1508
|
+
record.reasoning_output_tokens ?? record.reasoningOutputTokens
|
|
1509
|
+
)
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
return parsed.success ? parsed.data : void 0;
|
|
1513
|
+
};
|
|
1514
|
+
var extractClaudeUsage = (payload) => {
|
|
1515
|
+
const record = asRecord(payload);
|
|
1516
|
+
if (record === void 0) {
|
|
1517
|
+
return void 0;
|
|
1518
|
+
}
|
|
1519
|
+
const message = asRecord(record.message);
|
|
1520
|
+
const candidates = [
|
|
1521
|
+
record.usage,
|
|
1522
|
+
record.token_usage,
|
|
1523
|
+
record.tokenUsage,
|
|
1524
|
+
message?.usage,
|
|
1525
|
+
record
|
|
1526
|
+
];
|
|
1527
|
+
for (const candidate of candidates) {
|
|
1528
|
+
const usage = coerceClaudeUsage(candidate);
|
|
1529
|
+
if (usage !== void 0) {
|
|
1530
|
+
return usage;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return void 0;
|
|
1534
|
+
};
|
|
1535
|
+
var normalizeClaudeUsage = (raw) => {
|
|
1536
|
+
if (raw === void 0) {
|
|
1537
|
+
return { warnings: [] };
|
|
1538
|
+
}
|
|
1539
|
+
const warnings = [];
|
|
1540
|
+
const cachedInputTokens = raw.cache_read_input_tokens ?? 0;
|
|
1541
|
+
const cacheCreationInputTokens = resolveCacheCreationTokens(raw, warnings);
|
|
1542
|
+
auditIterations(raw, cacheCreationInputTokens, warnings);
|
|
1543
|
+
auditExcludedCounters(raw, warnings);
|
|
1544
|
+
const result = normalizeUsage({
|
|
1545
|
+
temporality: "delta",
|
|
1546
|
+
inputTokens: raw.input_tokens + cachedInputTokens + cacheCreationInputTokens,
|
|
1547
|
+
cachedInputTokens,
|
|
1548
|
+
cacheCreationInputTokens,
|
|
1549
|
+
cacheCreationAccounting: "included-in-input",
|
|
1550
|
+
outputTokens: raw.output_tokens
|
|
1551
|
+
});
|
|
1552
|
+
if (result.status === "invalid") {
|
|
1553
|
+
return { warnings: [...warnings, ...result.issues.map((issue) => issue.message)] };
|
|
1554
|
+
}
|
|
1555
|
+
return { usage: result.usage, warnings: [...warnings, ...forwardableNotes(result.notes)] };
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
// src/providers/claude/payload-normalize.ts
|
|
1559
|
+
var FIELD_ALIASES = Object.freeze({
|
|
1560
|
+
hookEventName: "hook_event_name",
|
|
1561
|
+
sessionId: "session_id",
|
|
1562
|
+
lastAssistantMessage: "last_assistant_message",
|
|
1563
|
+
transcriptPath: "transcript_path",
|
|
1564
|
+
promptId: "prompt_id",
|
|
1565
|
+
toolUseId: "tool_use_id",
|
|
1566
|
+
toolName: "tool_name",
|
|
1567
|
+
toolInput: "tool_input",
|
|
1568
|
+
toolResponse: "tool_response",
|
|
1569
|
+
toolError: "tool_error",
|
|
1570
|
+
stopHookActive: "stop_hook_active",
|
|
1571
|
+
agentId: "agent_id",
|
|
1572
|
+
agentType: "agent_type",
|
|
1573
|
+
errorType: "error_type",
|
|
1574
|
+
errorMessage: "error_message",
|
|
1575
|
+
tokenUsage: "token_usage"
|
|
1346
1576
|
});
|
|
1577
|
+
var asRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1578
|
+
var applyFieldAliases = (record) => {
|
|
1579
|
+
const normalized = { ...record };
|
|
1580
|
+
for (const [alias, canonical] of Object.entries(FIELD_ALIASES)) {
|
|
1581
|
+
if (normalized[canonical] === void 0 && normalized[alias] !== void 0) {
|
|
1582
|
+
normalized[canonical] = normalized[alias];
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
return normalized;
|
|
1586
|
+
};
|
|
1587
|
+
var applyPrintResultShape = (record) => {
|
|
1588
|
+
if (record.hook_event_name !== void 0 || record.type !== "result") {
|
|
1589
|
+
return record;
|
|
1590
|
+
}
|
|
1591
|
+
if (typeof record.session_id !== "string" || record.session_id.length === 0) {
|
|
1592
|
+
return record;
|
|
1593
|
+
}
|
|
1594
|
+
const isError = record.subtype === "error" || record.is_error === true;
|
|
1595
|
+
const normalized = {
|
|
1596
|
+
...record,
|
|
1597
|
+
hook_event_name: isError ? "StopFailure" : "Stop"
|
|
1598
|
+
};
|
|
1599
|
+
if (normalized.last_assistant_message === void 0 && typeof record.result === "string" && record.result.length > 0) {
|
|
1600
|
+
normalized.last_assistant_message = record.result;
|
|
1601
|
+
}
|
|
1602
|
+
if (isError && (typeof normalized.error_type !== "string" || normalized.error_type.length === 0)) {
|
|
1603
|
+
normalized.error_type = "unknown";
|
|
1604
|
+
}
|
|
1605
|
+
return normalized;
|
|
1606
|
+
};
|
|
1607
|
+
var normalizeClaudeHookPayload = (payload) => {
|
|
1608
|
+
const record = asRecord2(payload);
|
|
1609
|
+
if (record === void 0) {
|
|
1610
|
+
return payload;
|
|
1611
|
+
}
|
|
1612
|
+
return applyUsageShape(applyPrintResultShape(applyFieldAliases(record)));
|
|
1613
|
+
};
|
|
1614
|
+
var applyUsageShape = (record) => {
|
|
1615
|
+
const usage = coerceClaudeUsage(record.usage) ?? coerceClaudeUsage(record.token_usage) ?? coerceClaudeUsage(record.tokenUsage);
|
|
1616
|
+
if (usage === void 0) {
|
|
1617
|
+
return record;
|
|
1618
|
+
}
|
|
1619
|
+
return { ...record, usage };
|
|
1620
|
+
};
|
|
1347
1621
|
|
|
1348
1622
|
// src/providers/claude/delivery.ts
|
|
1349
1623
|
var TOOL_SCOPED_EVENTS = [
|
|
@@ -1353,7 +1627,7 @@ var TOOL_SCOPED_EVENTS = [
|
|
|
1353
1627
|
"PermissionRequest"
|
|
1354
1628
|
];
|
|
1355
1629
|
var claudeDeliveryIdentity = (input) => {
|
|
1356
|
-
const parsed = claudeIdentityFieldsSchema.safeParse(input.payload);
|
|
1630
|
+
const parsed = claudeIdentityFieldsSchema.safeParse(normalizeClaudeHookPayload(input.payload));
|
|
1357
1631
|
if (!parsed.success) {
|
|
1358
1632
|
return void 0;
|
|
1359
1633
|
}
|
|
@@ -1429,7 +1703,7 @@ var none = (reason) => providerDetectionSchema.parse({
|
|
|
1429
1703
|
reasons: [reason]
|
|
1430
1704
|
});
|
|
1431
1705
|
var detectClaudeCode = (input) => {
|
|
1432
|
-
const
|
|
1706
|
+
const payload = normalizeClaudeHookPayload(input.payload);
|
|
1433
1707
|
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
1434
1708
|
return none("payload is not a JSON object");
|
|
1435
1709
|
}
|
|
@@ -1443,14 +1717,16 @@ var detectClaudeCode = (input) => {
|
|
|
1443
1717
|
return none("session_id is missing");
|
|
1444
1718
|
}
|
|
1445
1719
|
const hasTranscriptPath = typeof record.transcript_path === "string" && record.transcript_path.length > 0;
|
|
1720
|
+
const isPrintResult = record.type === "result";
|
|
1446
1721
|
const hinted = input.providerHint === CLAUDE_CODE_PROVIDER_ID;
|
|
1447
1722
|
return providerDetectionSchema.parse({
|
|
1448
1723
|
providerId: CLAUDE_CODE_PROVIDER_ID,
|
|
1449
|
-
confidence: hinted ? "exact" : hasTranscriptPath ? "strong" : "weak",
|
|
1724
|
+
confidence: hinted ? "exact" : hasTranscriptPath || isPrintResult ? "strong" : "weak",
|
|
1450
1725
|
reasons: [
|
|
1451
1726
|
`hook_event_name=${hookEventName} matches the Claude Code hooks protocol`,
|
|
1452
1727
|
"session_id present",
|
|
1453
1728
|
...hasTranscriptPath ? ["transcript_path present"] : [],
|
|
1729
|
+
...isPrintResult ? ["type=result print/SDK result message"] : [],
|
|
1454
1730
|
...hinted ? ["caller asserted providerHint=claude-code"] : []
|
|
1455
1731
|
],
|
|
1456
1732
|
sourceEventName: hookEventName
|
|
@@ -1507,7 +1783,7 @@ var deriveWorkspaceIdentity = (privacy, input, labels = {}) => {
|
|
|
1507
1783
|
// src/providers/claude/identity.ts
|
|
1508
1784
|
var subagentInvocationIdFor = (context, sessionId, agentId) => invocationIdSchema.parse(`subagent_${context.ids.newOpaqueId(["claude-subagent", sessionId, agentId])}`);
|
|
1509
1785
|
var identifyClaudeCode = (input, context) => {
|
|
1510
|
-
const parsed = claudeIdentityFieldsSchema.safeParse(input.payload);
|
|
1786
|
+
const parsed = claudeIdentityFieldsSchema.safeParse(normalizeClaudeHookPayload(input.payload));
|
|
1511
1787
|
if (!parsed.success) {
|
|
1512
1788
|
return [];
|
|
1513
1789
|
}
|
|
@@ -1539,6 +1815,93 @@ var identifyClaudeCode = (input, context) => {
|
|
|
1539
1815
|
return [claim];
|
|
1540
1816
|
};
|
|
1541
1817
|
|
|
1818
|
+
// src/providers/claude/stop-content.ts
|
|
1819
|
+
var TOP_LEVEL_TEXT_FIELDS = [
|
|
1820
|
+
"last_assistant_message",
|
|
1821
|
+
"lastAssistantMessage",
|
|
1822
|
+
"result",
|
|
1823
|
+
"assistant_message",
|
|
1824
|
+
"final_message"
|
|
1825
|
+
];
|
|
1826
|
+
var MESSAGE_TEXT_FIELDS = ["content", "text", "result"];
|
|
1827
|
+
var asRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1828
|
+
var nonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1829
|
+
var textFromContentBlocks = (value) => {
|
|
1830
|
+
if (!Array.isArray(value)) {
|
|
1831
|
+
return void 0;
|
|
1832
|
+
}
|
|
1833
|
+
const parts = [];
|
|
1834
|
+
for (const block of value) {
|
|
1835
|
+
const record = asRecord3(block);
|
|
1836
|
+
if (record === void 0) {
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1839
|
+
const text = nonEmptyString(record.text);
|
|
1840
|
+
if (text !== void 0 && (record.type === void 0 || record.type === "text")) {
|
|
1841
|
+
parts.push(text);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
return parts.length === 0 ? void 0 : parts.join("");
|
|
1845
|
+
};
|
|
1846
|
+
var extractClaudeAssistantText = (payload) => {
|
|
1847
|
+
const record = asRecord3(payload);
|
|
1848
|
+
if (record === void 0) {
|
|
1849
|
+
return void 0;
|
|
1850
|
+
}
|
|
1851
|
+
for (const field of TOP_LEVEL_TEXT_FIELDS) {
|
|
1852
|
+
const text = nonEmptyString(record[field]);
|
|
1853
|
+
if (text !== void 0) {
|
|
1854
|
+
return text;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
const messageText2 = nonEmptyString(record.message);
|
|
1858
|
+
if (messageText2 !== void 0) {
|
|
1859
|
+
return messageText2;
|
|
1860
|
+
}
|
|
1861
|
+
const message = asRecord3(record.message);
|
|
1862
|
+
if (message === void 0) {
|
|
1863
|
+
return void 0;
|
|
1864
|
+
}
|
|
1865
|
+
for (const field of MESSAGE_TEXT_FIELDS) {
|
|
1866
|
+
const text = nonEmptyString(message[field]) ?? textFromContentBlocks(message[field]);
|
|
1867
|
+
if (text !== void 0) {
|
|
1868
|
+
return text;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
return void 0;
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
// src/providers/claude/target.ts
|
|
1875
|
+
var PATH_FIELDS = Object.freeze({
|
|
1876
|
+
Read: ["file_path"],
|
|
1877
|
+
Write: ["file_path"],
|
|
1878
|
+
Edit: ["file_path"],
|
|
1879
|
+
MultiEdit: ["file_path"],
|
|
1880
|
+
NotebookEdit: ["notebook_path"],
|
|
1881
|
+
NotebookRead: ["notebook_path"],
|
|
1882
|
+
// Optional on both: absent means "search the session's directory".
|
|
1883
|
+
Glob: ["path"],
|
|
1884
|
+
Grep: ["path"]
|
|
1885
|
+
});
|
|
1886
|
+
var asRecord4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1887
|
+
var claudeTargetHint = (toolName, toolInput, cwd) => {
|
|
1888
|
+
const fields = Object.hasOwn(PATH_FIELDS, toolName) ? PATH_FIELDS[toolName] : void 0;
|
|
1889
|
+
const input = asRecord4(toolInput);
|
|
1890
|
+
if (fields !== void 0 && input !== void 0) {
|
|
1891
|
+
for (const field of fields) {
|
|
1892
|
+
const candidate = input[field];
|
|
1893
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
1894
|
+
return {
|
|
1895
|
+
source: "tool-path",
|
|
1896
|
+
paths: [candidate],
|
|
1897
|
+
...cwd === void 0 ? {} : { baseDirectory: cwd }
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
return cwd === void 0 ? void 0 : { source: "session-cwd", paths: [cwd] };
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1542
1905
|
// src/providers/claude/tool-kind.ts
|
|
1543
1906
|
var BUILT_IN_TOOL_KIND = Object.freeze({
|
|
1544
1907
|
Bash: "execute",
|
|
@@ -1567,90 +1930,6 @@ var inferToolKind = (toolName) => {
|
|
|
1567
1930
|
return BUILT_IN_TOOL_KIND[toolName] ?? "unknown";
|
|
1568
1931
|
};
|
|
1569
1932
|
|
|
1570
|
-
// src/providers/claude/usage.ts
|
|
1571
|
-
var CLAUDE_EXCLUDED_USAGE_COUNTERS = Object.freeze({
|
|
1572
|
-
total_tokens: `usage.total_tokens is outside Claude Code's usage contract (capability reportsProviderTotal=false): it is not read, so providerTotalAgreement stays "unreported"`,
|
|
1573
|
-
reasoning_output_tokens: "usage.reasoning_output_tokens is outside Claude Code's usage contract (capability reportsReasoningOutput=false): Anthropic bills thinking tokens inside output_tokens with no separate counter, so it is not read and reasoningOutputTokens stays 0"
|
|
1574
|
-
});
|
|
1575
|
-
var ITERATION_COUNTERS = [
|
|
1576
|
-
"input_tokens",
|
|
1577
|
-
"output_tokens",
|
|
1578
|
-
"cache_read_input_tokens",
|
|
1579
|
-
"cache_creation_input_tokens"
|
|
1580
|
-
];
|
|
1581
|
-
var ttlSplitTotal = (raw) => {
|
|
1582
|
-
const split = raw.cache_creation;
|
|
1583
|
-
if (split === void 0) {
|
|
1584
|
-
return void 0;
|
|
1585
|
-
}
|
|
1586
|
-
return (split.ephemeral_5m_input_tokens ?? 0) + (split.ephemeral_1h_input_tokens ?? 0);
|
|
1587
|
-
};
|
|
1588
|
-
var resolveCacheCreationTokens = (raw, warnings) => {
|
|
1589
|
-
const declared = raw.cache_creation_input_tokens;
|
|
1590
|
-
const split = ttlSplitTotal(raw);
|
|
1591
|
-
if (declared === void 0) {
|
|
1592
|
-
return split ?? 0;
|
|
1593
|
-
}
|
|
1594
|
-
if (split !== void 0 && split !== declared) {
|
|
1595
|
-
warnings.push(
|
|
1596
|
-
`usage.cache_creation TTL buckets sum to ${String(split)} but usage.cache_creation_input_tokens reports ${String(declared)}; the explicit counter is used and the buckets are never added to it`
|
|
1597
|
-
);
|
|
1598
|
-
}
|
|
1599
|
-
return declared;
|
|
1600
|
-
};
|
|
1601
|
-
var auditIterations = (raw, cacheCreationInputTokens, warnings) => {
|
|
1602
|
-
const iterations = raw.iterations;
|
|
1603
|
-
if (iterations === void 0 || iterations.length === 0) {
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
const outer = {
|
|
1607
|
-
input_tokens: raw.input_tokens,
|
|
1608
|
-
output_tokens: raw.output_tokens,
|
|
1609
|
-
cache_read_input_tokens: raw.cache_read_input_tokens ?? 0,
|
|
1610
|
-
cache_creation_input_tokens: cacheCreationInputTokens
|
|
1611
|
-
};
|
|
1612
|
-
for (const counter of ITERATION_COUNTERS) {
|
|
1613
|
-
const summed = iterations.reduce((total, iteration) => total + (iteration[counter] ?? 0), 0);
|
|
1614
|
-
if (summed !== outer[counter]) {
|
|
1615
|
-
warnings.push(
|
|
1616
|
-
`usage.iterations[].${counter} sums to ${String(summed)} but usage.${counter} reports ${String(outer[counter])}; the outer counter is used and per-iteration figures are never added to it`
|
|
1617
|
-
);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
var auditExcludedCounters = (raw, warnings) => {
|
|
1622
|
-
if (raw.total_tokens !== void 0) {
|
|
1623
|
-
warnings.push(CLAUDE_EXCLUDED_USAGE_COUNTERS.total_tokens);
|
|
1624
|
-
}
|
|
1625
|
-
if (raw.reasoning_output_tokens !== void 0) {
|
|
1626
|
-
warnings.push(CLAUDE_EXCLUDED_USAGE_COUNTERS.reasoning_output_tokens);
|
|
1627
|
-
}
|
|
1628
|
-
};
|
|
1629
|
-
var ACCOUNTING_RETAINED_NOTE_PREFIX = "cacheCreationAccounting=";
|
|
1630
|
-
var forwardableNotes = (notes) => notes.filter((note) => !note.startsWith(ACCOUNTING_RETAINED_NOTE_PREFIX));
|
|
1631
|
-
var normalizeClaudeUsage = (raw) => {
|
|
1632
|
-
if (raw === void 0) {
|
|
1633
|
-
return { warnings: [] };
|
|
1634
|
-
}
|
|
1635
|
-
const warnings = [];
|
|
1636
|
-
const cachedInputTokens = raw.cache_read_input_tokens ?? 0;
|
|
1637
|
-
const cacheCreationInputTokens = resolveCacheCreationTokens(raw, warnings);
|
|
1638
|
-
auditIterations(raw, cacheCreationInputTokens, warnings);
|
|
1639
|
-
auditExcludedCounters(raw, warnings);
|
|
1640
|
-
const result = normalizeUsage({
|
|
1641
|
-
temporality: "delta",
|
|
1642
|
-
inputTokens: raw.input_tokens + cachedInputTokens + cacheCreationInputTokens,
|
|
1643
|
-
cachedInputTokens,
|
|
1644
|
-
cacheCreationInputTokens,
|
|
1645
|
-
cacheCreationAccounting: "included-in-input",
|
|
1646
|
-
outputTokens: raw.output_tokens
|
|
1647
|
-
});
|
|
1648
|
-
if (result.status === "invalid") {
|
|
1649
|
-
return { warnings: [...warnings, ...result.issues.map((issue) => issue.message)] };
|
|
1650
|
-
}
|
|
1651
|
-
return { usage: result.usage, warnings: [...warnings, ...forwardableNotes(result.notes)] };
|
|
1652
|
-
};
|
|
1653
|
-
|
|
1654
1933
|
// src/providers/claude/events.ts
|
|
1655
1934
|
var UNKNOWN_MODEL = { modelId: "unknown" };
|
|
1656
1935
|
var SESSION_END_REASON = Object.freeze({
|
|
@@ -1683,7 +1962,8 @@ var DENIED_STOP_FAILURE_TYPES = /* @__PURE__ */ new Set([
|
|
|
1683
1962
|
var mapStopFailureOutcome = (errorType) => DENIED_STOP_FAILURE_TYPES.has(errorType) ? "denied" : "error";
|
|
1684
1963
|
var applyUsage = (normalized) => normalized.usage === void 0 ? {} : { usage: normalized.usage };
|
|
1685
1964
|
var parseClaudeCode = (input, context) => {
|
|
1686
|
-
const
|
|
1965
|
+
const normalizedPayload = normalizeClaudeHookPayload(input.payload);
|
|
1966
|
+
const parsed = claudeHookPayloadSchema.safeParse(normalizedPayload);
|
|
1687
1967
|
if (!parsed.success) {
|
|
1688
1968
|
const rawEventName = typeof input.payload === "object" && input.payload !== null ? input.payload.hook_event_name : void 0;
|
|
1689
1969
|
return {
|
|
@@ -1697,12 +1977,20 @@ var parseClaudeCode = (input, context) => {
|
|
|
1697
1977
|
};
|
|
1698
1978
|
}
|
|
1699
1979
|
const payload = parsed.data;
|
|
1980
|
+
const extractedUsage = extractClaudeUsage(normalizedPayload);
|
|
1700
1981
|
const factory = createEventFactory({
|
|
1701
1982
|
identity: input.identity,
|
|
1702
1983
|
sequenceBase: input.sequenceBase,
|
|
1703
|
-
context
|
|
1984
|
+
context,
|
|
1985
|
+
// Present exactly when the hook fired inside a subagent (or describes one,
|
|
1986
|
+
// on SubagentStart/SubagentStop).
|
|
1987
|
+
...payload.agent_id === void 0 ? {} : { subagentId: payload.agent_id }
|
|
1704
1988
|
});
|
|
1705
1989
|
const warnings = [];
|
|
1990
|
+
const targetHintFor = (toolName, toolInput) => {
|
|
1991
|
+
const hint = claudeTargetHint(toolName, toolInput, payload.cwd);
|
|
1992
|
+
return hint === void 0 ? {} : { targetHint: hint };
|
|
1993
|
+
};
|
|
1706
1994
|
const withUsage = (usage) => {
|
|
1707
1995
|
const normalized = normalizeClaudeUsage(usage);
|
|
1708
1996
|
warnings.push(...normalized.warnings);
|
|
@@ -1720,7 +2008,8 @@ var parseClaudeCode = (input, context) => {
|
|
|
1720
2008
|
case "SessionEnd":
|
|
1721
2009
|
factory.build({
|
|
1722
2010
|
type: "session.end",
|
|
1723
|
-
reason: mapSessionEndReason(payload.reason ?? payload.end_reason)
|
|
2011
|
+
reason: mapSessionEndReason(payload.reason ?? payload.end_reason),
|
|
2012
|
+
...withUsage(extractedUsage)
|
|
1724
2013
|
});
|
|
1725
2014
|
break;
|
|
1726
2015
|
case "UserPromptSubmit":
|
|
@@ -1736,6 +2025,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
1736
2025
|
toolCallId: payload.tool_use_id,
|
|
1737
2026
|
toolName: payload.tool_name,
|
|
1738
2027
|
toolKind: inferToolKind(payload.tool_name),
|
|
2028
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
1739
2029
|
...payload.tool_input === void 0 ? {} : {
|
|
1740
2030
|
input: context.privacy.describeStructured({
|
|
1741
2031
|
kind: "tool-input",
|
|
@@ -1751,6 +2041,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
1751
2041
|
toolCallId: payload.tool_use_id,
|
|
1752
2042
|
toolName: payload.tool_name,
|
|
1753
2043
|
outcome: "ok",
|
|
2044
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
1754
2045
|
output: context.privacy.describeStructured({
|
|
1755
2046
|
kind: "tool-output",
|
|
1756
2047
|
value: payload.tool_response,
|
|
@@ -1764,6 +2055,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
1764
2055
|
toolCallId: payload.tool_use_id,
|
|
1765
2056
|
toolName: payload.tool_name,
|
|
1766
2057
|
outcome: "error",
|
|
2058
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
1767
2059
|
output: context.privacy.describeStructured({
|
|
1768
2060
|
kind: "tool-output",
|
|
1769
2061
|
value: payload.tool_error,
|
|
@@ -1813,22 +2105,24 @@ var parseClaudeCode = (input, context) => {
|
|
|
1813
2105
|
payload.session_id,
|
|
1814
2106
|
payload.prompt_id ?? String(input.sequenceBase)
|
|
1815
2107
|
]);
|
|
2108
|
+
const assistantText = extractClaudeAssistantText(normalizedPayload);
|
|
1816
2109
|
factory.build({ type: "generation.start", generationId, model: UNKNOWN_MODEL });
|
|
1817
2110
|
factory.build({
|
|
1818
2111
|
type: "generation.end",
|
|
1819
2112
|
generationId,
|
|
1820
2113
|
model: UNKNOWN_MODEL,
|
|
1821
2114
|
outcome: "ok",
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2115
|
+
// Always a response fact: a body when Claude sent text, otherwise a
|
|
2116
|
+
// zero-length omitted fact so the log mapping can emit metadata_only
|
|
2117
|
+
// instead of a generation.end with no content.kind.
|
|
2118
|
+
outputContent: [
|
|
2119
|
+
assistantText === void 0 ? context.privacy.describeUnavailableContent({ kind: "response", role: "assistant" }) : context.privacy.describeContent({
|
|
2120
|
+
kind: "response",
|
|
2121
|
+
role: "assistant",
|
|
2122
|
+
text: assistantText
|
|
2123
|
+
})
|
|
2124
|
+
],
|
|
2125
|
+
...withUsage(extractedUsage ?? payload.usage)
|
|
1832
2126
|
});
|
|
1833
2127
|
break;
|
|
1834
2128
|
}
|
|
@@ -1838,6 +2132,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
1838
2132
|
payload.session_id,
|
|
1839
2133
|
payload.prompt_id ?? String(input.sequenceBase)
|
|
1840
2134
|
]);
|
|
2135
|
+
const assistantText = extractClaudeAssistantText(normalizedPayload);
|
|
1841
2136
|
factory.build({ type: "generation.start", generationId, model: UNKNOWN_MODEL });
|
|
1842
2137
|
factory.build({
|
|
1843
2138
|
type: "generation.end",
|
|
@@ -1845,15 +2140,26 @@ var parseClaudeCode = (input, context) => {
|
|
|
1845
2140
|
model: UNKNOWN_MODEL,
|
|
1846
2141
|
outcome: mapStopFailureOutcome(payload.error_type),
|
|
1847
2142
|
stopReason: payload.error_type,
|
|
1848
|
-
...
|
|
2143
|
+
...assistantText === void 0 ? {} : {
|
|
2144
|
+
outputContent: [
|
|
2145
|
+
context.privacy.describeContent({
|
|
2146
|
+
kind: "response",
|
|
2147
|
+
role: "assistant",
|
|
2148
|
+
text: assistantText
|
|
2149
|
+
})
|
|
2150
|
+
]
|
|
2151
|
+
},
|
|
2152
|
+
...withUsage(extractedUsage ?? payload.usage)
|
|
1849
2153
|
});
|
|
1850
2154
|
break;
|
|
1851
2155
|
}
|
|
1852
2156
|
}
|
|
2157
|
+
const targetHints = factory.targetHints();
|
|
1853
2158
|
return {
|
|
1854
2159
|
status: "parsed",
|
|
1855
2160
|
events: factory.events(),
|
|
1856
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
2161
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
2162
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
1857
2163
|
};
|
|
1858
2164
|
};
|
|
1859
2165
|
|
|
@@ -1871,7 +2177,7 @@ var createClaudeCodeAdapter = (options = {}) => ({
|
|
|
1871
2177
|
});
|
|
1872
2178
|
|
|
1873
2179
|
// src/providers/cursor/payload.ts
|
|
1874
|
-
import { z as
|
|
2180
|
+
import { z as z13 } from "zod";
|
|
1875
2181
|
var CURSOR_PROVIDER_ID = "cursor";
|
|
1876
2182
|
var CURSOR_HOOK_EVENT_NAMES = [
|
|
1877
2183
|
"sessionStart",
|
|
@@ -1906,23 +2212,23 @@ var CURSOR_DECISION_EVENTS = Object.freeze({
|
|
|
1906
2212
|
subagentStart: "permission",
|
|
1907
2213
|
beforeSubmitPrompt: "continue"
|
|
1908
2214
|
});
|
|
1909
|
-
var modelParamSchema =
|
|
1910
|
-
id:
|
|
1911
|
-
value:
|
|
2215
|
+
var modelParamSchema = z13.object({
|
|
2216
|
+
id: z13.string(),
|
|
2217
|
+
value: z13.string()
|
|
1912
2218
|
});
|
|
1913
|
-
var attachmentSchema =
|
|
1914
|
-
type:
|
|
1915
|
-
file_path:
|
|
2219
|
+
var attachmentSchema = z13.object({
|
|
2220
|
+
type: z13.string().optional(),
|
|
2221
|
+
file_path: z13.string().optional()
|
|
1916
2222
|
});
|
|
1917
|
-
var fileEditSchema =
|
|
1918
|
-
old_string:
|
|
1919
|
-
new_string:
|
|
2223
|
+
var fileEditSchema = z13.object({
|
|
2224
|
+
old_string: z13.string().optional(),
|
|
2225
|
+
new_string: z13.string().optional()
|
|
1920
2226
|
});
|
|
1921
2227
|
var usageFields = {
|
|
1922
|
-
input_tokens:
|
|
1923
|
-
output_tokens:
|
|
1924
|
-
cache_read_tokens:
|
|
1925
|
-
cache_write_tokens:
|
|
2228
|
+
input_tokens: z13.number().int().min(0).optional(),
|
|
2229
|
+
output_tokens: z13.number().int().min(0).optional(),
|
|
2230
|
+
cache_read_tokens: z13.number().int().min(0).optional(),
|
|
2231
|
+
cache_write_tokens: z13.number().int().min(0).optional()
|
|
1926
2232
|
};
|
|
1927
2233
|
var envelopeShape = {
|
|
1928
2234
|
// Not `.min(1)`: see `cursorSessionId`. A payload naming neither
|
|
@@ -1930,136 +2236,136 @@ var envelopeShape = {
|
|
|
1930
2236
|
// `recognizeCursorPayload`'s post-parse check — but rejecting it here would
|
|
1931
2237
|
// fail the whole discriminated union on a field the adapter can source from
|
|
1932
2238
|
// either name.
|
|
1933
|
-
conversation_id:
|
|
1934
|
-
generation_id:
|
|
1935
|
-
session_id:
|
|
1936
|
-
model:
|
|
1937
|
-
model_id:
|
|
1938
|
-
model_params:
|
|
1939
|
-
cursor_version:
|
|
1940
|
-
workspace_roots:
|
|
1941
|
-
cwd:
|
|
2239
|
+
conversation_id: z13.string().optional(),
|
|
2240
|
+
generation_id: z13.string().optional(),
|
|
2241
|
+
session_id: z13.string().optional(),
|
|
2242
|
+
model: z13.string().optional(),
|
|
2243
|
+
model_id: z13.string().optional(),
|
|
2244
|
+
model_params: z13.array(modelParamSchema).max(64).optional(),
|
|
2245
|
+
cursor_version: z13.string().optional(),
|
|
2246
|
+
workspace_roots: z13.array(z13.string()).max(64).optional(),
|
|
2247
|
+
cwd: z13.string().optional(),
|
|
1942
2248
|
/** Never propagated. */
|
|
1943
|
-
user_email:
|
|
2249
|
+
user_email: z13.string().nullish(),
|
|
1944
2250
|
/** Never propagated. */
|
|
1945
|
-
transcript_path:
|
|
2251
|
+
transcript_path: z13.string().nullish()
|
|
1946
2252
|
};
|
|
1947
|
-
var event2 = (name, shape) =>
|
|
2253
|
+
var event2 = (name, shape) => z13.object({ ...envelopeShape, hook_event_name: z13.literal(name), ...shape });
|
|
1948
2254
|
var sessionStartPayloadSchema2 = event2("sessionStart", {
|
|
1949
|
-
is_background_agent:
|
|
1950
|
-
composer_mode:
|
|
2255
|
+
is_background_agent: z13.boolean().optional(),
|
|
2256
|
+
composer_mode: z13.string().optional()
|
|
1951
2257
|
});
|
|
1952
2258
|
var sessionEndPayloadSchema2 = event2("sessionEnd", {
|
|
1953
|
-
reason:
|
|
1954
|
-
duration_ms:
|
|
1955
|
-
is_background_agent:
|
|
1956
|
-
final_status:
|
|
1957
|
-
error_message:
|
|
2259
|
+
reason: z13.string().optional(),
|
|
2260
|
+
duration_ms: z13.number().min(0).optional(),
|
|
2261
|
+
is_background_agent: z13.boolean().optional(),
|
|
2262
|
+
final_status: z13.string().optional(),
|
|
2263
|
+
error_message: z13.string().optional()
|
|
1958
2264
|
});
|
|
1959
2265
|
var beforeSubmitPromptPayloadSchema = event2("beforeSubmitPrompt", {
|
|
1960
|
-
prompt:
|
|
1961
|
-
attachments:
|
|
1962
|
-
composer_mode:
|
|
2266
|
+
prompt: z13.string().optional(),
|
|
2267
|
+
attachments: z13.array(attachmentSchema).max(256).optional(),
|
|
2268
|
+
composer_mode: z13.string().optional()
|
|
1963
2269
|
});
|
|
1964
2270
|
var afterAgentResponsePayloadSchema = event2("afterAgentResponse", {
|
|
1965
|
-
text:
|
|
2271
|
+
text: z13.string().optional(),
|
|
1966
2272
|
...usageFields
|
|
1967
2273
|
});
|
|
1968
2274
|
var afterAgentThoughtPayloadSchema = event2("afterAgentThought", {
|
|
1969
|
-
text:
|
|
1970
|
-
duration_ms:
|
|
2275
|
+
text: z13.string().optional(),
|
|
2276
|
+
duration_ms: z13.number().min(0).optional()
|
|
1971
2277
|
});
|
|
1972
2278
|
var preToolUsePayloadSchema2 = event2("preToolUse", {
|
|
1973
|
-
tool_name:
|
|
1974
|
-
tool_input:
|
|
1975
|
-
tool_use_id:
|
|
1976
|
-
agent_message:
|
|
2279
|
+
tool_name: z13.string().min(1),
|
|
2280
|
+
tool_input: z13.unknown().optional(),
|
|
2281
|
+
tool_use_id: z13.string().optional(),
|
|
2282
|
+
agent_message: z13.string().optional()
|
|
1977
2283
|
});
|
|
1978
2284
|
var postToolUsePayloadSchema2 = event2("postToolUse", {
|
|
1979
|
-
tool_name:
|
|
1980
|
-
tool_input:
|
|
1981
|
-
tool_output:
|
|
1982
|
-
tool_use_id:
|
|
1983
|
-
duration:
|
|
2285
|
+
tool_name: z13.string().min(1),
|
|
2286
|
+
tool_input: z13.unknown().optional(),
|
|
2287
|
+
tool_output: z13.unknown().optional(),
|
|
2288
|
+
tool_use_id: z13.string().optional(),
|
|
2289
|
+
duration: z13.number().min(0).optional()
|
|
1984
2290
|
});
|
|
1985
2291
|
var postToolUseFailurePayloadSchema2 = event2("postToolUseFailure", {
|
|
1986
|
-
tool_name:
|
|
1987
|
-
tool_input:
|
|
1988
|
-
tool_use_id:
|
|
1989
|
-
error_message:
|
|
1990
|
-
failure_type:
|
|
1991
|
-
duration:
|
|
1992
|
-
is_interrupt:
|
|
2292
|
+
tool_name: z13.string().min(1),
|
|
2293
|
+
tool_input: z13.unknown().optional(),
|
|
2294
|
+
tool_use_id: z13.string().optional(),
|
|
2295
|
+
error_message: z13.string().optional(),
|
|
2296
|
+
failure_type: z13.string().optional(),
|
|
2297
|
+
duration: z13.number().min(0).optional(),
|
|
2298
|
+
is_interrupt: z13.boolean().optional()
|
|
1993
2299
|
});
|
|
1994
2300
|
var beforeShellExecutionPayloadSchema = event2("beforeShellExecution", {
|
|
1995
|
-
command:
|
|
1996
|
-
sandbox:
|
|
2301
|
+
command: z13.string(),
|
|
2302
|
+
sandbox: z13.boolean().optional()
|
|
1997
2303
|
});
|
|
1998
2304
|
var afterShellExecutionPayloadSchema = event2("afterShellExecution", {
|
|
1999
|
-
command:
|
|
2000
|
-
output:
|
|
2001
|
-
duration:
|
|
2002
|
-
sandbox:
|
|
2305
|
+
command: z13.string(),
|
|
2306
|
+
output: z13.string().optional(),
|
|
2307
|
+
duration: z13.number().min(0).optional(),
|
|
2308
|
+
sandbox: z13.boolean().optional()
|
|
2003
2309
|
});
|
|
2004
2310
|
var beforeMcpExecutionPayloadSchema = event2("beforeMCPExecution", {
|
|
2005
|
-
tool_name:
|
|
2006
|
-
tool_input:
|
|
2007
|
-
url:
|
|
2008
|
-
command:
|
|
2311
|
+
tool_name: z13.string().min(1),
|
|
2312
|
+
tool_input: z13.unknown().optional(),
|
|
2313
|
+
url: z13.string().optional(),
|
|
2314
|
+
command: z13.string().optional()
|
|
2009
2315
|
});
|
|
2010
2316
|
var afterMcpExecutionPayloadSchema = event2("afterMCPExecution", {
|
|
2011
|
-
tool_name:
|
|
2012
|
-
tool_input:
|
|
2013
|
-
result_json:
|
|
2014
|
-
duration:
|
|
2317
|
+
tool_name: z13.string().min(1),
|
|
2318
|
+
tool_input: z13.unknown().optional(),
|
|
2319
|
+
result_json: z13.string().optional(),
|
|
2320
|
+
duration: z13.number().min(0).optional()
|
|
2015
2321
|
});
|
|
2016
2322
|
var beforeReadFilePayloadSchema = event2("beforeReadFile", {
|
|
2017
|
-
file_path:
|
|
2018
|
-
content:
|
|
2019
|
-
attachments:
|
|
2323
|
+
file_path: z13.string(),
|
|
2324
|
+
content: z13.string().optional(),
|
|
2325
|
+
attachments: z13.array(attachmentSchema).max(256).optional()
|
|
2020
2326
|
});
|
|
2021
2327
|
var afterFileEditPayloadSchema = event2("afterFileEdit", {
|
|
2022
|
-
file_path:
|
|
2023
|
-
edits:
|
|
2328
|
+
file_path: z13.string(),
|
|
2329
|
+
edits: z13.array(fileEditSchema).max(1024).optional()
|
|
2024
2330
|
});
|
|
2025
2331
|
var subagentStartPayloadSchema2 = event2("subagentStart", {
|
|
2026
|
-
subagent_id:
|
|
2027
|
-
subagent_type:
|
|
2028
|
-
task:
|
|
2029
|
-
parent_conversation_id:
|
|
2030
|
-
tool_call_id:
|
|
2031
|
-
subagent_model:
|
|
2032
|
-
is_parallel_worker:
|
|
2033
|
-
git_branch:
|
|
2332
|
+
subagent_id: z13.string().optional(),
|
|
2333
|
+
subagent_type: z13.string().optional(),
|
|
2334
|
+
task: z13.string().optional(),
|
|
2335
|
+
parent_conversation_id: z13.string().optional(),
|
|
2336
|
+
tool_call_id: z13.string().optional(),
|
|
2337
|
+
subagent_model: z13.string().optional(),
|
|
2338
|
+
is_parallel_worker: z13.boolean().optional(),
|
|
2339
|
+
git_branch: z13.string().optional()
|
|
2034
2340
|
});
|
|
2035
2341
|
var subagentStopPayloadSchema2 = event2("subagentStop", {
|
|
2036
|
-
subagent_type:
|
|
2037
|
-
status:
|
|
2038
|
-
task:
|
|
2039
|
-
description:
|
|
2040
|
-
summary:
|
|
2041
|
-
duration_ms:
|
|
2042
|
-
message_count:
|
|
2043
|
-
tool_call_count:
|
|
2044
|
-
loop_count:
|
|
2045
|
-
modified_files:
|
|
2046
|
-
agent_transcript_path:
|
|
2342
|
+
subagent_type: z13.string().optional(),
|
|
2343
|
+
status: z13.string().optional(),
|
|
2344
|
+
task: z13.string().optional(),
|
|
2345
|
+
description: z13.string().optional(),
|
|
2346
|
+
summary: z13.string().optional(),
|
|
2347
|
+
duration_ms: z13.number().min(0).optional(),
|
|
2348
|
+
message_count: z13.number().int().min(0).optional(),
|
|
2349
|
+
tool_call_count: z13.number().int().min(0).optional(),
|
|
2350
|
+
loop_count: z13.number().int().min(0).optional(),
|
|
2351
|
+
modified_files: z13.array(z13.string()).max(1024).optional(),
|
|
2352
|
+
agent_transcript_path: z13.string().nullish()
|
|
2047
2353
|
});
|
|
2048
2354
|
var preCompactPayloadSchema2 = event2("preCompact", {
|
|
2049
|
-
trigger:
|
|
2050
|
-
context_usage_percent:
|
|
2051
|
-
context_tokens:
|
|
2052
|
-
context_window_size:
|
|
2053
|
-
message_count:
|
|
2054
|
-
messages_to_compact:
|
|
2055
|
-
is_first_compaction:
|
|
2355
|
+
trigger: z13.string().optional(),
|
|
2356
|
+
context_usage_percent: z13.number().optional(),
|
|
2357
|
+
context_tokens: z13.number().int().min(0).optional(),
|
|
2358
|
+
context_window_size: z13.number().int().min(0).optional(),
|
|
2359
|
+
message_count: z13.number().int().min(0).optional(),
|
|
2360
|
+
messages_to_compact: z13.number().int().min(0).optional(),
|
|
2361
|
+
is_first_compaction: z13.boolean().optional()
|
|
2056
2362
|
});
|
|
2057
2363
|
var stopPayloadSchema2 = event2("stop", {
|
|
2058
|
-
status:
|
|
2059
|
-
loop_count:
|
|
2364
|
+
status: z13.string().optional(),
|
|
2365
|
+
loop_count: z13.number().int().min(0).optional(),
|
|
2060
2366
|
...usageFields
|
|
2061
2367
|
});
|
|
2062
|
-
var cursorPayloadSchema =
|
|
2368
|
+
var cursorPayloadSchema = z13.discriminatedUnion("hook_event_name", [
|
|
2063
2369
|
sessionStartPayloadSchema2,
|
|
2064
2370
|
sessionEndPayloadSchema2,
|
|
2065
2371
|
beforeSubmitPromptPayloadSchema,
|
|
@@ -2196,6 +2502,33 @@ var cursorDeliveryIdentity = (input) => {
|
|
|
2196
2502
|
};
|
|
2197
2503
|
};
|
|
2198
2504
|
|
|
2505
|
+
// src/providers/cursor/target.ts
|
|
2506
|
+
var singleWorkspaceRoot = (payload) => {
|
|
2507
|
+
const roots = (payload.workspace_roots ?? []).filter((root) => root.length > 0);
|
|
2508
|
+
return roots.length === 1 ? roots[0] : void 0;
|
|
2509
|
+
};
|
|
2510
|
+
var sessionHint = (root) => root === void 0 ? void 0 : { source: "session-cwd", paths: [root] };
|
|
2511
|
+
var cursorTargetHint = (payload) => {
|
|
2512
|
+
const root = singleWorkspaceRoot(payload);
|
|
2513
|
+
const base = root === void 0 ? {} : { baseDirectory: root };
|
|
2514
|
+
switch (payload.hook_event_name) {
|
|
2515
|
+
case "afterFileEdit":
|
|
2516
|
+
case "beforeReadFile":
|
|
2517
|
+
return payload.file_path.length === 0 ? sessionHint(root) : { source: "tool-path", paths: [payload.file_path], ...base };
|
|
2518
|
+
case "beforeShellExecution":
|
|
2519
|
+
case "afterShellExecution":
|
|
2520
|
+
return payload.cwd !== void 0 && payload.cwd.length > 0 ? { source: "shell-cwd", paths: [payload.cwd], ...base } : sessionHint(root);
|
|
2521
|
+
case "preToolUse":
|
|
2522
|
+
case "postToolUse":
|
|
2523
|
+
case "postToolUseFailure":
|
|
2524
|
+
case "beforeMCPExecution":
|
|
2525
|
+
case "afterMCPExecution":
|
|
2526
|
+
return sessionHint(root);
|
|
2527
|
+
default:
|
|
2528
|
+
return void 0;
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2199
2532
|
// src/providers/cursor/usage.ts
|
|
2200
2533
|
var normalizeCursorUsage = (raw) => {
|
|
2201
2534
|
const inputTokens = raw.input_tokens;
|
|
@@ -2451,12 +2784,6 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2451
2784
|
reason: "afterAgentThought is a reasoning notification, not a generation lifecycle event; no canonical event type represents it and thought text is never exported"
|
|
2452
2785
|
};
|
|
2453
2786
|
}
|
|
2454
|
-
if (payload.hook_event_name === "beforeReadFile") {
|
|
2455
|
-
return {
|
|
2456
|
-
status: "ignored",
|
|
2457
|
-
reason: "beforeReadFile has no completion callback in the cursor hook protocol, so emitting tool.start here would leave a tool lifecycle that never closes"
|
|
2458
|
-
};
|
|
2459
|
-
}
|
|
2460
2787
|
if (payload.hook_event_name === "subagentStart" || payload.hook_event_name === "subagentStop") {
|
|
2461
2788
|
return {
|
|
2462
2789
|
status: "ignored",
|
|
@@ -2471,6 +2798,8 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2471
2798
|
const warnings = [];
|
|
2472
2799
|
const sessionId = input.identity.sessionId;
|
|
2473
2800
|
const model = toModelDescriptor(payload);
|
|
2801
|
+
const targetHint = cursorTargetHint(payload);
|
|
2802
|
+
const targetHintField = targetHint === void 0 ? {} : { targetHint };
|
|
2474
2803
|
switch (payload.hook_event_name) {
|
|
2475
2804
|
case "sessionStart":
|
|
2476
2805
|
factory.build({
|
|
@@ -2523,6 +2852,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2523
2852
|
case "preToolUse":
|
|
2524
2853
|
factory.build({
|
|
2525
2854
|
type: "tool.start",
|
|
2855
|
+
...targetHintField,
|
|
2526
2856
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
2527
2857
|
"tool",
|
|
2528
2858
|
payload.generation_id ?? "",
|
|
@@ -2546,6 +2876,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2546
2876
|
case "postToolUse":
|
|
2547
2877
|
factory.build({
|
|
2548
2878
|
type: "tool.end",
|
|
2879
|
+
...targetHintField,
|
|
2549
2880
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
2550
2881
|
"tool",
|
|
2551
2882
|
payload.generation_id ?? "",
|
|
@@ -2568,6 +2899,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2568
2899
|
case "postToolUseFailure":
|
|
2569
2900
|
factory.build({
|
|
2570
2901
|
type: "tool.end",
|
|
2902
|
+
...targetHintField,
|
|
2571
2903
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
2572
2904
|
"tool",
|
|
2573
2905
|
payload.generation_id ?? "",
|
|
@@ -2588,6 +2920,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2588
2920
|
case "beforeShellExecution":
|
|
2589
2921
|
factory.build({
|
|
2590
2922
|
type: "tool.start",
|
|
2923
|
+
...targetHintField,
|
|
2591
2924
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
2592
2925
|
"shell",
|
|
2593
2926
|
payload.generation_id ?? "",
|
|
@@ -2607,6 +2940,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2607
2940
|
case "afterShellExecution":
|
|
2608
2941
|
factory.build({
|
|
2609
2942
|
type: "tool.end",
|
|
2943
|
+
...targetHintField,
|
|
2610
2944
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
2611
2945
|
"shell",
|
|
2612
2946
|
payload.generation_id ?? "",
|
|
@@ -2631,6 +2965,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2631
2965
|
case "beforeMCPExecution":
|
|
2632
2966
|
factory.build({
|
|
2633
2967
|
type: "tool.start",
|
|
2968
|
+
...targetHintField,
|
|
2634
2969
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
2635
2970
|
"mcp",
|
|
2636
2971
|
payload.generation_id ?? "",
|
|
@@ -2651,6 +2986,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2651
2986
|
case "afterMCPExecution":
|
|
2652
2987
|
factory.build({
|
|
2653
2988
|
type: "tool.end",
|
|
2989
|
+
...targetHintField,
|
|
2654
2990
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
2655
2991
|
"mcp",
|
|
2656
2992
|
payload.generation_id ?? "",
|
|
@@ -2678,6 +3014,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2678
3014
|
]);
|
|
2679
3015
|
factory.build({
|
|
2680
3016
|
type: "tool.start",
|
|
3017
|
+
...targetHintField,
|
|
2681
3018
|
toolCallId,
|
|
2682
3019
|
toolName: "edit_file",
|
|
2683
3020
|
toolKind: "write",
|
|
@@ -2690,6 +3027,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2690
3027
|
});
|
|
2691
3028
|
factory.build({
|
|
2692
3029
|
type: "tool.end",
|
|
3030
|
+
...targetHintField,
|
|
2693
3031
|
toolCallId,
|
|
2694
3032
|
toolName: "edit_file",
|
|
2695
3033
|
outcome: "ok",
|
|
@@ -2699,6 +3037,34 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2699
3037
|
});
|
|
2700
3038
|
break;
|
|
2701
3039
|
}
|
|
3040
|
+
case "beforeReadFile": {
|
|
3041
|
+
const toolCallId = derivedToolCallId(context, sessionId, [
|
|
3042
|
+
"read-file",
|
|
3043
|
+
payload.generation_id ?? "",
|
|
3044
|
+
payload.file_path
|
|
3045
|
+
]);
|
|
3046
|
+
factory.build({
|
|
3047
|
+
type: "tool.start",
|
|
3048
|
+
...targetHintField,
|
|
3049
|
+
toolCallId,
|
|
3050
|
+
toolName: "read_file",
|
|
3051
|
+
toolKind: "read",
|
|
3052
|
+
...payload.generation_id === void 0 || payload.generation_id.length === 0 ? {} : { generationId: payload.generation_id },
|
|
3053
|
+
input: context.privacy.describeContent({
|
|
3054
|
+
kind: "tool-input",
|
|
3055
|
+
text: payload.file_path,
|
|
3056
|
+
label: "read_file"
|
|
3057
|
+
})
|
|
3058
|
+
});
|
|
3059
|
+
factory.build({
|
|
3060
|
+
type: "tool.end",
|
|
3061
|
+
...targetHintField,
|
|
3062
|
+
toolCallId,
|
|
3063
|
+
toolName: "read_file",
|
|
3064
|
+
outcome: "unknown"
|
|
3065
|
+
});
|
|
3066
|
+
break;
|
|
3067
|
+
}
|
|
2702
3068
|
case "preCompact":
|
|
2703
3069
|
factory.build({
|
|
2704
3070
|
type: "compaction.performed",
|
|
@@ -2736,10 +3102,12 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2736
3102
|
break;
|
|
2737
3103
|
}
|
|
2738
3104
|
}
|
|
3105
|
+
const targetHints = factory.targetHints();
|
|
2739
3106
|
return {
|
|
2740
3107
|
status: "parsed",
|
|
2741
3108
|
events: factory.events(),
|
|
2742
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
3109
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
3110
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
2743
3111
|
};
|
|
2744
3112
|
};
|
|
2745
3113
|
const hookResponse2 = (input) => {
|
|
@@ -2770,105 +3138,105 @@ var createCursorAdapter = (options = {}) => {
|
|
|
2770
3138
|
};
|
|
2771
3139
|
|
|
2772
3140
|
// src/providers/codex/payload.ts
|
|
2773
|
-
import { z as
|
|
2774
|
-
var permissionModeSchema =
|
|
3141
|
+
import { z as z14 } from "zod";
|
|
3142
|
+
var permissionModeSchema = z14.enum([
|
|
2775
3143
|
"default",
|
|
2776
3144
|
"acceptEdits",
|
|
2777
3145
|
"plan",
|
|
2778
3146
|
"dontAsk",
|
|
2779
3147
|
"bypassPermissions"
|
|
2780
3148
|
]);
|
|
2781
|
-
var codexUsageSchema =
|
|
2782
|
-
input_tokens:
|
|
2783
|
-
cached_input_tokens:
|
|
2784
|
-
output_tokens:
|
|
2785
|
-
reasoning_output_tokens:
|
|
2786
|
-
total_tokens:
|
|
3149
|
+
var codexUsageSchema = z14.object({
|
|
3150
|
+
input_tokens: z14.number().int().min(0).optional(),
|
|
3151
|
+
cached_input_tokens: z14.number().int().min(0).optional(),
|
|
3152
|
+
output_tokens: z14.number().int().min(0).optional(),
|
|
3153
|
+
reasoning_output_tokens: z14.number().int().min(0).optional(),
|
|
3154
|
+
total_tokens: z14.number().int().min(0).optional()
|
|
2787
3155
|
});
|
|
2788
3156
|
var baseFields = {
|
|
2789
|
-
session_id:
|
|
2790
|
-
cwd:
|
|
2791
|
-
model:
|
|
3157
|
+
session_id: z14.string().min(1).max(256),
|
|
3158
|
+
cwd: z14.string().min(1).max(4096).optional(),
|
|
3159
|
+
model: z14.string().min(1).max(256).optional(),
|
|
2792
3160
|
permission_mode: permissionModeSchema.optional(),
|
|
2793
|
-
transcript_path:
|
|
2794
|
-
codex_version:
|
|
3161
|
+
transcript_path: z14.string().min(1).max(4096).optional(),
|
|
3162
|
+
codex_version: z14.string().min(1).max(64).optional(),
|
|
2795
3163
|
/** Not part of the documented protocol; lets tests and replay stay deterministic. */
|
|
2796
|
-
occurred_at:
|
|
3164
|
+
occurred_at: z14.number().int().min(0).optional()
|
|
2797
3165
|
};
|
|
2798
|
-
var codexSessionStartPayloadSchema =
|
|
3166
|
+
var codexSessionStartPayloadSchema = z14.object({
|
|
2799
3167
|
...baseFields,
|
|
2800
|
-
hook_event_name:
|
|
2801
|
-
source:
|
|
3168
|
+
hook_event_name: z14.literal("SessionStart"),
|
|
3169
|
+
source: z14.enum(["startup", "resume", "clear", "compact"]).optional()
|
|
2802
3170
|
});
|
|
2803
|
-
var codexUserPromptSubmitPayloadSchema =
|
|
3171
|
+
var codexUserPromptSubmitPayloadSchema = z14.object({
|
|
2804
3172
|
...baseFields,
|
|
2805
|
-
hook_event_name:
|
|
2806
|
-
turn_id:
|
|
2807
|
-
prompt:
|
|
3173
|
+
hook_event_name: z14.literal("UserPromptSubmit"),
|
|
3174
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3175
|
+
prompt: z14.string().max(1e6).optional()
|
|
2808
3176
|
});
|
|
2809
|
-
var codexPreToolUsePayloadSchema =
|
|
3177
|
+
var codexPreToolUsePayloadSchema = z14.object({
|
|
2810
3178
|
...baseFields,
|
|
2811
|
-
hook_event_name:
|
|
2812
|
-
turn_id:
|
|
2813
|
-
tool_name:
|
|
2814
|
-
tool_call_id:
|
|
2815
|
-
tool_input:
|
|
3179
|
+
hook_event_name: z14.literal("PreToolUse"),
|
|
3180
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3181
|
+
tool_name: z14.string().min(1).max(256),
|
|
3182
|
+
tool_call_id: z14.string().min(1).max(256).optional(),
|
|
3183
|
+
tool_input: z14.unknown().optional()
|
|
2816
3184
|
});
|
|
2817
|
-
var codexPermissionRequestPayloadSchema =
|
|
3185
|
+
var codexPermissionRequestPayloadSchema = z14.object({
|
|
2818
3186
|
...baseFields,
|
|
2819
|
-
hook_event_name:
|
|
2820
|
-
turn_id:
|
|
2821
|
-
tool_name:
|
|
2822
|
-
tool_call_id:
|
|
2823
|
-
tool_input:
|
|
3187
|
+
hook_event_name: z14.literal("PermissionRequest"),
|
|
3188
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3189
|
+
tool_name: z14.string().min(1).max(256).optional(),
|
|
3190
|
+
tool_call_id: z14.string().min(1).max(256).optional(),
|
|
3191
|
+
tool_input: z14.unknown().optional()
|
|
2824
3192
|
});
|
|
2825
|
-
var codexPostToolUsePayloadSchema =
|
|
3193
|
+
var codexPostToolUsePayloadSchema = z14.object({
|
|
2826
3194
|
...baseFields,
|
|
2827
|
-
hook_event_name:
|
|
2828
|
-
turn_id:
|
|
2829
|
-
tool_name:
|
|
2830
|
-
tool_call_id:
|
|
2831
|
-
tool_input:
|
|
2832
|
-
tool_response:
|
|
2833
|
-
permission_decision:
|
|
2834
|
-
duration_ms:
|
|
3195
|
+
hook_event_name: z14.literal("PostToolUse"),
|
|
3196
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3197
|
+
tool_name: z14.string().min(1).max(256),
|
|
3198
|
+
tool_call_id: z14.string().min(1).max(256).optional(),
|
|
3199
|
+
tool_input: z14.unknown().optional(),
|
|
3200
|
+
tool_response: z14.unknown().optional(),
|
|
3201
|
+
permission_decision: z14.enum(["allowed", "denied", "deferred"]).optional(),
|
|
3202
|
+
duration_ms: z14.number().min(0).optional()
|
|
2835
3203
|
});
|
|
2836
|
-
var codexPreCompactPayloadSchema =
|
|
3204
|
+
var codexPreCompactPayloadSchema = z14.object({
|
|
2837
3205
|
...baseFields,
|
|
2838
|
-
hook_event_name:
|
|
2839
|
-
trigger:
|
|
2840
|
-
context_tokens_before:
|
|
3206
|
+
hook_event_name: z14.literal("PreCompact"),
|
|
3207
|
+
trigger: z14.enum(["auto", "manual"]).optional(),
|
|
3208
|
+
context_tokens_before: z14.number().int().min(0).optional()
|
|
2841
3209
|
});
|
|
2842
|
-
var codexPostCompactPayloadSchema =
|
|
3210
|
+
var codexPostCompactPayloadSchema = z14.object({
|
|
2843
3211
|
...baseFields,
|
|
2844
|
-
hook_event_name:
|
|
2845
|
-
trigger:
|
|
2846
|
-
context_tokens_after:
|
|
2847
|
-
dropped_message_count:
|
|
3212
|
+
hook_event_name: z14.literal("PostCompact"),
|
|
3213
|
+
trigger: z14.enum(["auto", "manual"]).optional(),
|
|
3214
|
+
context_tokens_after: z14.number().int().min(0).optional(),
|
|
3215
|
+
dropped_message_count: z14.number().int().min(0).optional(),
|
|
2848
3216
|
usage: codexUsageSchema.optional()
|
|
2849
3217
|
});
|
|
2850
|
-
var codexSubagentStartPayloadSchema =
|
|
3218
|
+
var codexSubagentStartPayloadSchema = z14.object({
|
|
2851
3219
|
...baseFields,
|
|
2852
|
-
hook_event_name:
|
|
2853
|
-
turn_id:
|
|
2854
|
-
subagent_id:
|
|
2855
|
-
subagent_type:
|
|
3220
|
+
hook_event_name: z14.literal("SubagentStart"),
|
|
3221
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3222
|
+
subagent_id: z14.string().min(1).max(256),
|
|
3223
|
+
subagent_type: z14.string().min(1).max(256).optional()
|
|
2856
3224
|
});
|
|
2857
|
-
var codexSubagentStopPayloadSchema =
|
|
3225
|
+
var codexSubagentStopPayloadSchema = z14.object({
|
|
2858
3226
|
...baseFields,
|
|
2859
|
-
hook_event_name:
|
|
2860
|
-
turn_id:
|
|
2861
|
-
subagent_id:
|
|
2862
|
-
status:
|
|
3227
|
+
hook_event_name: z14.literal("SubagentStop"),
|
|
3228
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3229
|
+
subagent_id: z14.string().min(1).max(256),
|
|
3230
|
+
status: z14.enum(["completed", "failed", "cancelled"]).optional(),
|
|
2863
3231
|
usage: codexUsageSchema.optional()
|
|
2864
3232
|
});
|
|
2865
|
-
var codexStopPayloadSchema =
|
|
3233
|
+
var codexStopPayloadSchema = z14.object({
|
|
2866
3234
|
...baseFields,
|
|
2867
|
-
hook_event_name:
|
|
2868
|
-
turn_id:
|
|
2869
|
-
stop_reason:
|
|
3235
|
+
hook_event_name: z14.literal("Stop"),
|
|
3236
|
+
turn_id: z14.string().min(1).max(256).optional(),
|
|
3237
|
+
stop_reason: z14.string().min(1).max(256).optional(),
|
|
2870
3238
|
usage: codexUsageSchema.optional(),
|
|
2871
|
-
duration_ms:
|
|
3239
|
+
duration_ms: z14.number().min(0).optional()
|
|
2872
3240
|
});
|
|
2873
3241
|
var CODEX_HOOK_EVENT_NAMES = [
|
|
2874
3242
|
"SessionStart",
|
|
@@ -2882,7 +3250,7 @@ var CODEX_HOOK_EVENT_NAMES = [
|
|
|
2882
3250
|
"SubagentStop",
|
|
2883
3251
|
"Stop"
|
|
2884
3252
|
];
|
|
2885
|
-
var codexHookPayloadSchema =
|
|
3253
|
+
var codexHookPayloadSchema = z14.discriminatedUnion("hook_event_name", [
|
|
2886
3254
|
codexSessionStartPayloadSchema,
|
|
2887
3255
|
codexUserPromptSubmitPayloadSchema,
|
|
2888
3256
|
codexPreToolUsePayloadSchema,
|
|
@@ -2894,9 +3262,9 @@ var codexHookPayloadSchema = z13.discriminatedUnion("hook_event_name", [
|
|
|
2894
3262
|
codexSubagentStopPayloadSchema,
|
|
2895
3263
|
codexStopPayloadSchema
|
|
2896
3264
|
]);
|
|
2897
|
-
var codexHookEnvelopeSchema =
|
|
2898
|
-
session_id:
|
|
2899
|
-
hook_event_name:
|
|
3265
|
+
var codexHookEnvelopeSchema = z14.object({
|
|
3266
|
+
session_id: z14.string().min(1),
|
|
3267
|
+
hook_event_name: z14.enum(CODEX_HOOK_EVENT_NAMES)
|
|
2900
3268
|
});
|
|
2901
3269
|
|
|
2902
3270
|
// src/providers/codex/delivery.ts
|
|
@@ -2957,6 +3325,61 @@ var codexDeliveryIdentity = (input) => {
|
|
|
2957
3325
|
};
|
|
2958
3326
|
};
|
|
2959
3327
|
|
|
3328
|
+
// src/providers/codex/target.ts
|
|
3329
|
+
var PATCH_HEADER = /^\*\*\* (?:Add File|Update File|Delete File|Move to): (.+)$/;
|
|
3330
|
+
var asRecord5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
3331
|
+
var nonEmptyString2 = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
3332
|
+
var commandText = (input) => {
|
|
3333
|
+
const command = input?.command ?? input?.cmd;
|
|
3334
|
+
if (typeof command === "string") {
|
|
3335
|
+
return command;
|
|
3336
|
+
}
|
|
3337
|
+
if (Array.isArray(command) && command.every((part) => typeof part === "string")) {
|
|
3338
|
+
return command.join(" ");
|
|
3339
|
+
}
|
|
3340
|
+
return void 0;
|
|
3341
|
+
};
|
|
3342
|
+
var patchHeaderPaths = (patch) => {
|
|
3343
|
+
const paths = /* @__PURE__ */ new Set();
|
|
3344
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
3345
|
+
const match = PATCH_HEADER.exec(line.trimEnd());
|
|
3346
|
+
const named = match?.[1]?.trim();
|
|
3347
|
+
if (named !== void 0 && named.length > 0) {
|
|
3348
|
+
paths.add(named);
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return paths.size === 0 || paths.size > MAX_TARGET_HINT_PATHS ? void 0 : [...paths];
|
|
3352
|
+
};
|
|
3353
|
+
var patchTextOf = (toolName, input) => {
|
|
3354
|
+
if (typeof input === "string") {
|
|
3355
|
+
return /^apply[_-]?patch$/i.test(toolName) ? input : void 0;
|
|
3356
|
+
}
|
|
3357
|
+
const record = asRecord5(input);
|
|
3358
|
+
if (/^apply[_-]?patch$/i.test(toolName)) {
|
|
3359
|
+
return nonEmptyString2(record?.patch) ?? nonEmptyString2(record?.input) ?? commandText(record);
|
|
3360
|
+
}
|
|
3361
|
+
const command = commandText(record);
|
|
3362
|
+
return command !== void 0 && /^\s*apply_patch\b/.test(command) ? command : void 0;
|
|
3363
|
+
};
|
|
3364
|
+
var codexTargetHint = (toolName, toolInput, cwd) => {
|
|
3365
|
+
const record = asRecord5(toolInput);
|
|
3366
|
+
const workdir = nonEmptyString2(record?.workdir);
|
|
3367
|
+
const base = workdir ?? cwd;
|
|
3368
|
+
const patch = patchTextOf(toolName, toolInput);
|
|
3369
|
+
if (patch !== void 0) {
|
|
3370
|
+
const paths = patchHeaderPaths(patch);
|
|
3371
|
+
return paths === void 0 ? void 0 : { source: "tool-path", paths, ...base === void 0 ? {} : { baseDirectory: base } };
|
|
3372
|
+
}
|
|
3373
|
+
if (workdir !== void 0) {
|
|
3374
|
+
return {
|
|
3375
|
+
source: "shell-cwd",
|
|
3376
|
+
paths: [workdir],
|
|
3377
|
+
...cwd === void 0 ? {} : { baseDirectory: cwd }
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
return cwd === void 0 ? void 0 : { source: "session-cwd", paths: [cwd] };
|
|
3381
|
+
};
|
|
3382
|
+
|
|
2960
3383
|
// src/providers/codex/tool-kind.ts
|
|
2961
3384
|
var PATTERNS = [
|
|
2962
3385
|
[/^(apply[_-]?patch|patch)$/i, "write"],
|
|
@@ -3021,7 +3444,7 @@ var CODEX_CAPABILITIES = Object.freeze({
|
|
|
3021
3444
|
// compaction callbacks do not. See `./delivery.ts` for which and why.
|
|
3022
3445
|
deliveryIdentifier: "partial"
|
|
3023
3446
|
});
|
|
3024
|
-
var
|
|
3447
|
+
var asRecord6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
3025
3448
|
var hasExactMarker = (payload) => {
|
|
3026
3449
|
if (payload.codex_version !== void 0) {
|
|
3027
3450
|
return true;
|
|
@@ -3114,7 +3537,7 @@ var outcomeFromToolResponse = (toolResponse) => {
|
|
|
3114
3537
|
if (toolResponse === void 0) {
|
|
3115
3538
|
return "unknown";
|
|
3116
3539
|
}
|
|
3117
|
-
const record =
|
|
3540
|
+
const record = asRecord6(toolResponse);
|
|
3118
3541
|
if (record === void 0) {
|
|
3119
3542
|
return "ok";
|
|
3120
3543
|
}
|
|
@@ -3186,6 +3609,10 @@ var parse = (input, context) => {
|
|
|
3186
3609
|
context
|
|
3187
3610
|
});
|
|
3188
3611
|
const warnings = [];
|
|
3612
|
+
const targetHintFor = (toolName, toolInput) => {
|
|
3613
|
+
const hint = codexTargetHint(toolName, toolInput, payload.cwd);
|
|
3614
|
+
return hint === void 0 ? {} : { targetHint: hint };
|
|
3615
|
+
};
|
|
3189
3616
|
const buildUsage = (usage) => {
|
|
3190
3617
|
if (usage === void 0) {
|
|
3191
3618
|
return void 0;
|
|
@@ -3230,6 +3657,7 @@ var parse = (input, context) => {
|
|
|
3230
3657
|
toolName: payload.tool_name,
|
|
3231
3658
|
toolKind: classifyCodexToolKind(payload.tool_name),
|
|
3232
3659
|
occurredAt,
|
|
3660
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
3233
3661
|
...payload.tool_input === void 0 ? {} : {
|
|
3234
3662
|
input: context.privacy.describeStructured({
|
|
3235
3663
|
kind: "tool-input",
|
|
@@ -3256,6 +3684,7 @@ var parse = (input, context) => {
|
|
|
3256
3684
|
outcome,
|
|
3257
3685
|
permissionDecision,
|
|
3258
3686
|
occurredAt,
|
|
3687
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
3259
3688
|
...payload.duration_ms === void 0 ? {} : { durationMillis: payload.duration_ms },
|
|
3260
3689
|
...payload.tool_response === void 0 ? {} : {
|
|
3261
3690
|
output: context.privacy.describeStructured({
|
|
@@ -3338,10 +3767,12 @@ var parse = (input, context) => {
|
|
|
3338
3767
|
break;
|
|
3339
3768
|
}
|
|
3340
3769
|
}
|
|
3770
|
+
const targetHints = factory.targetHints();
|
|
3341
3771
|
return {
|
|
3342
3772
|
status: "parsed",
|
|
3343
3773
|
events: factory.events(),
|
|
3344
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
3774
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
3775
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
3345
3776
|
};
|
|
3346
3777
|
};
|
|
3347
3778
|
var hookResponse = () => SILENT_HOOK_RESPONSE;
|
|
@@ -3448,7 +3879,7 @@ var geminiCorrelationSeed = (input) => {
|
|
|
3448
3879
|
};
|
|
3449
3880
|
|
|
3450
3881
|
// src/providers/gemini/schema.ts
|
|
3451
|
-
import { z as
|
|
3882
|
+
import { z as z15 } from "zod";
|
|
3452
3883
|
var GEMINI_HOOK_EVENT_NAMES = [
|
|
3453
3884
|
"SessionStart",
|
|
3454
3885
|
"SessionEnd",
|
|
@@ -3462,113 +3893,113 @@ var GEMINI_HOOK_EVENT_NAMES = [
|
|
|
3462
3893
|
"PreCompress",
|
|
3463
3894
|
"Notification"
|
|
3464
3895
|
];
|
|
3465
|
-
var baseHookInputSchema =
|
|
3466
|
-
session_id:
|
|
3467
|
-
transcript_path:
|
|
3468
|
-
cwd:
|
|
3469
|
-
timestamp:
|
|
3896
|
+
var baseHookInputSchema = z15.object({
|
|
3897
|
+
session_id: z15.string().min(1),
|
|
3898
|
+
transcript_path: z15.string().optional(),
|
|
3899
|
+
cwd: z15.string().optional(),
|
|
3900
|
+
timestamp: z15.string().min(1).optional()
|
|
3470
3901
|
});
|
|
3471
|
-
var llmMessageSchema =
|
|
3472
|
-
role:
|
|
3473
|
-
content:
|
|
3902
|
+
var llmMessageSchema = z15.object({
|
|
3903
|
+
role: z15.enum(["user", "model", "system"]).optional(),
|
|
3904
|
+
content: z15.union([z15.string(), z15.array(z15.unknown())]).optional()
|
|
3474
3905
|
}).loose();
|
|
3475
|
-
var llmRequestConfigSchema =
|
|
3476
|
-
temperature:
|
|
3477
|
-
maxOutputTokens:
|
|
3906
|
+
var llmRequestConfigSchema = z15.object({
|
|
3907
|
+
temperature: z15.number().optional(),
|
|
3908
|
+
maxOutputTokens: z15.number().int().min(0).optional()
|
|
3478
3909
|
}).loose();
|
|
3479
|
-
var geminiLlmRequestSchema =
|
|
3480
|
-
model:
|
|
3481
|
-
messages:
|
|
3910
|
+
var geminiLlmRequestSchema = z15.object({
|
|
3911
|
+
model: z15.string().min(1).optional(),
|
|
3912
|
+
messages: z15.array(llmMessageSchema).optional(),
|
|
3482
3913
|
config: llmRequestConfigSchema.optional(),
|
|
3483
|
-
toolConfig:
|
|
3914
|
+
toolConfig: z15.unknown().optional()
|
|
3484
3915
|
}).loose();
|
|
3485
|
-
var geminiUsageMetadataSchema =
|
|
3486
|
-
promptTokenCount:
|
|
3487
|
-
cachedContentTokenCount:
|
|
3488
|
-
candidatesTokenCount:
|
|
3489
|
-
thoughtsTokenCount:
|
|
3490
|
-
totalTokenCount:
|
|
3916
|
+
var geminiUsageMetadataSchema = z15.object({
|
|
3917
|
+
promptTokenCount: z15.number().int().min(0).optional(),
|
|
3918
|
+
cachedContentTokenCount: z15.number().int().min(0).optional(),
|
|
3919
|
+
candidatesTokenCount: z15.number().int().min(0).optional(),
|
|
3920
|
+
thoughtsTokenCount: z15.number().int().min(0).optional(),
|
|
3921
|
+
totalTokenCount: z15.number().int().min(0).optional()
|
|
3491
3922
|
}).loose();
|
|
3492
|
-
var geminiCandidateSchema =
|
|
3493
|
-
content:
|
|
3494
|
-
role:
|
|
3495
|
-
parts:
|
|
3923
|
+
var geminiCandidateSchema = z15.object({
|
|
3924
|
+
content: z15.object({
|
|
3925
|
+
role: z15.string().optional(),
|
|
3926
|
+
parts: z15.array(z15.unknown()).optional()
|
|
3496
3927
|
}).loose().optional(),
|
|
3497
|
-
finishReason:
|
|
3498
|
-
index:
|
|
3928
|
+
finishReason: z15.string().optional(),
|
|
3929
|
+
index: z15.number().int().min(0).optional()
|
|
3499
3930
|
}).loose();
|
|
3500
|
-
var geminiLlmResponseSchema =
|
|
3931
|
+
var geminiLlmResponseSchema = z15.object({
|
|
3501
3932
|
/** Whole-response text, set by the translator from `getResponseText`. */
|
|
3502
|
-
text:
|
|
3503
|
-
candidates:
|
|
3933
|
+
text: z15.string().optional(),
|
|
3934
|
+
candidates: z15.array(geminiCandidateSchema).optional(),
|
|
3504
3935
|
usageMetadata: geminiUsageMetadataSchema.optional()
|
|
3505
3936
|
}).loose();
|
|
3506
|
-
var geminiMcpContextSchema =
|
|
3507
|
-
server_name:
|
|
3508
|
-
tool_name:
|
|
3937
|
+
var geminiMcpContextSchema = z15.object({
|
|
3938
|
+
server_name: z15.string().optional(),
|
|
3939
|
+
tool_name: z15.string().optional()
|
|
3509
3940
|
}).loose();
|
|
3510
|
-
var geminiToolResponseSchema =
|
|
3511
|
-
llmContent:
|
|
3512
|
-
returnDisplay:
|
|
3513
|
-
error:
|
|
3941
|
+
var geminiToolResponseSchema = z15.object({
|
|
3942
|
+
llmContent: z15.unknown().optional(),
|
|
3943
|
+
returnDisplay: z15.unknown().optional(),
|
|
3944
|
+
error: z15.unknown().optional()
|
|
3514
3945
|
}).loose();
|
|
3515
3946
|
var sessionStartInputSchema = baseHookInputSchema.extend({
|
|
3516
|
-
hook_event_name:
|
|
3517
|
-
source:
|
|
3947
|
+
hook_event_name: z15.literal("SessionStart"),
|
|
3948
|
+
source: z15.enum(["startup", "resume", "clear"]).optional()
|
|
3518
3949
|
});
|
|
3519
3950
|
var sessionEndInputSchema = baseHookInputSchema.extend({
|
|
3520
|
-
hook_event_name:
|
|
3521
|
-
reason:
|
|
3951
|
+
hook_event_name: z15.literal("SessionEnd"),
|
|
3952
|
+
reason: z15.enum(["exit", "clear", "logout", "prompt_input_exit", "other"]).optional()
|
|
3522
3953
|
});
|
|
3523
3954
|
var beforeAgentInputSchema = baseHookInputSchema.extend({
|
|
3524
|
-
hook_event_name:
|
|
3525
|
-
prompt:
|
|
3955
|
+
hook_event_name: z15.literal("BeforeAgent"),
|
|
3956
|
+
prompt: z15.string().optional()
|
|
3526
3957
|
});
|
|
3527
3958
|
var afterAgentInputSchema = baseHookInputSchema.extend({
|
|
3528
|
-
hook_event_name:
|
|
3529
|
-
prompt:
|
|
3530
|
-
prompt_response:
|
|
3531
|
-
stop_hook_active:
|
|
3959
|
+
hook_event_name: z15.literal("AfterAgent"),
|
|
3960
|
+
prompt: z15.string().optional(),
|
|
3961
|
+
prompt_response: z15.string().optional(),
|
|
3962
|
+
stop_hook_active: z15.boolean().optional()
|
|
3532
3963
|
});
|
|
3533
3964
|
var beforeModelInputSchema = baseHookInputSchema.extend({
|
|
3534
|
-
hook_event_name:
|
|
3965
|
+
hook_event_name: z15.literal("BeforeModel"),
|
|
3535
3966
|
llm_request: geminiLlmRequestSchema
|
|
3536
3967
|
});
|
|
3537
3968
|
var afterModelInputSchema = baseHookInputSchema.extend({
|
|
3538
|
-
hook_event_name:
|
|
3969
|
+
hook_event_name: z15.literal("AfterModel"),
|
|
3539
3970
|
llm_request: geminiLlmRequestSchema,
|
|
3540
3971
|
llm_response: geminiLlmResponseSchema
|
|
3541
3972
|
});
|
|
3542
3973
|
var beforeToolSelectionInputSchema = baseHookInputSchema.extend({
|
|
3543
|
-
hook_event_name:
|
|
3974
|
+
hook_event_name: z15.literal("BeforeToolSelection"),
|
|
3544
3975
|
llm_request: geminiLlmRequestSchema
|
|
3545
3976
|
});
|
|
3546
3977
|
var beforeToolInputSchema = baseHookInputSchema.extend({
|
|
3547
|
-
hook_event_name:
|
|
3548
|
-
tool_name:
|
|
3549
|
-
tool_input:
|
|
3978
|
+
hook_event_name: z15.literal("BeforeTool"),
|
|
3979
|
+
tool_name: z15.string().min(1),
|
|
3980
|
+
tool_input: z15.unknown().optional(),
|
|
3550
3981
|
mcp_context: geminiMcpContextSchema.optional(),
|
|
3551
|
-
original_request_name:
|
|
3982
|
+
original_request_name: z15.string().min(1).optional()
|
|
3552
3983
|
});
|
|
3553
3984
|
var afterToolInputSchema = baseHookInputSchema.extend({
|
|
3554
|
-
hook_event_name:
|
|
3555
|
-
tool_name:
|
|
3556
|
-
tool_input:
|
|
3985
|
+
hook_event_name: z15.literal("AfterTool"),
|
|
3986
|
+
tool_name: z15.string().min(1),
|
|
3987
|
+
tool_input: z15.unknown().optional(),
|
|
3557
3988
|
tool_response: geminiToolResponseSchema.optional(),
|
|
3558
3989
|
mcp_context: geminiMcpContextSchema.optional(),
|
|
3559
|
-
original_request_name:
|
|
3990
|
+
original_request_name: z15.string().min(1).optional()
|
|
3560
3991
|
});
|
|
3561
3992
|
var preCompressInputSchema = baseHookInputSchema.extend({
|
|
3562
|
-
hook_event_name:
|
|
3563
|
-
trigger:
|
|
3993
|
+
hook_event_name: z15.literal("PreCompress"),
|
|
3994
|
+
trigger: z15.enum(["auto", "manual"]).optional()
|
|
3564
3995
|
});
|
|
3565
3996
|
var notificationInputSchema = baseHookInputSchema.extend({
|
|
3566
|
-
hook_event_name:
|
|
3567
|
-
notification_type:
|
|
3568
|
-
message:
|
|
3569
|
-
details:
|
|
3997
|
+
hook_event_name: z15.literal("Notification"),
|
|
3998
|
+
notification_type: z15.string().optional(),
|
|
3999
|
+
message: z15.string().optional(),
|
|
4000
|
+
details: z15.unknown().optional()
|
|
3570
4001
|
});
|
|
3571
|
-
var geminiHookInputSchema =
|
|
4002
|
+
var geminiHookInputSchema = z15.discriminatedUnion("hook_event_name", [
|
|
3572
4003
|
sessionStartInputSchema,
|
|
3573
4004
|
sessionEndInputSchema,
|
|
3574
4005
|
beforeAgentInputSchema,
|
|
@@ -4013,7 +4444,7 @@ var normalizeUsageOrWarn = (usage, warnings) => {
|
|
|
4013
4444
|
};
|
|
4014
4445
|
|
|
4015
4446
|
// src/providers/antigravity/payload.ts
|
|
4016
|
-
import { z as
|
|
4447
|
+
import { z as z16 } from "zod";
|
|
4017
4448
|
var ANTIGRAVITY_HOOK_EVENT_NAMES = [
|
|
4018
4449
|
"PreInvocation",
|
|
4019
4450
|
"PostInvocation",
|
|
@@ -4021,48 +4452,48 @@ var ANTIGRAVITY_HOOK_EVENT_NAMES = [
|
|
|
4021
4452
|
"PostToolUse",
|
|
4022
4453
|
"Stop"
|
|
4023
4454
|
];
|
|
4024
|
-
var hookEventNameSchema =
|
|
4025
|
-
var antigravityWeakShapeSchema =
|
|
4455
|
+
var hookEventNameSchema = z16.enum(ANTIGRAVITY_HOOK_EVENT_NAMES);
|
|
4456
|
+
var antigravityWeakShapeSchema = z16.object({ hookEventName: hookEventNameSchema }).passthrough();
|
|
4026
4457
|
var commonFields2 = {
|
|
4027
|
-
conversationId:
|
|
4028
|
-
workspacePaths:
|
|
4029
|
-
invocationNum:
|
|
4458
|
+
conversationId: z16.string().min(1),
|
|
4459
|
+
workspacePaths: z16.array(z16.string().min(1)).max(64),
|
|
4460
|
+
invocationNum: z16.number().int().min(0),
|
|
4030
4461
|
/** Never disclosed: a real filesystem path. Accepted, never propagated. */
|
|
4031
|
-
transcriptPath:
|
|
4462
|
+
transcriptPath: z16.string().min(1).optional(),
|
|
4032
4463
|
/** Never disclosed: a real filesystem path. Accepted, never propagated. */
|
|
4033
|
-
artifactDirectoryPath:
|
|
4464
|
+
artifactDirectoryPath: z16.string().min(1).optional()
|
|
4034
4465
|
};
|
|
4035
|
-
var preInvocationPayloadSchema =
|
|
4036
|
-
hookEventName:
|
|
4466
|
+
var preInvocationPayloadSchema = z16.object({
|
|
4467
|
+
hookEventName: z16.literal("PreInvocation"),
|
|
4037
4468
|
...commonFields2,
|
|
4038
|
-
agentVersion:
|
|
4469
|
+
agentVersion: z16.string().min(1).optional()
|
|
4039
4470
|
});
|
|
4040
|
-
var postInvocationPayloadSchema =
|
|
4041
|
-
hookEventName:
|
|
4471
|
+
var postInvocationPayloadSchema = z16.object({
|
|
4472
|
+
hookEventName: z16.literal("PostInvocation"),
|
|
4042
4473
|
...commonFields2,
|
|
4043
|
-
agentVersion:
|
|
4474
|
+
agentVersion: z16.string().min(1).optional()
|
|
4044
4475
|
});
|
|
4045
|
-
var preToolUsePayloadSchema3 =
|
|
4046
|
-
hookEventName:
|
|
4476
|
+
var preToolUsePayloadSchema3 = z16.object({
|
|
4477
|
+
hookEventName: z16.literal("PreToolUse"),
|
|
4047
4478
|
...commonFields2,
|
|
4048
|
-
stepIdx:
|
|
4049
|
-
toolName:
|
|
4050
|
-
toolInput:
|
|
4479
|
+
stepIdx: z16.number().int().min(0),
|
|
4480
|
+
toolName: z16.string().min(1),
|
|
4481
|
+
toolInput: z16.unknown().optional()
|
|
4051
4482
|
});
|
|
4052
|
-
var postToolUsePayloadSchema3 =
|
|
4053
|
-
hookEventName:
|
|
4483
|
+
var postToolUsePayloadSchema3 = z16.object({
|
|
4484
|
+
hookEventName: z16.literal("PostToolUse"),
|
|
4054
4485
|
...commonFields2,
|
|
4055
|
-
stepIdx:
|
|
4056
|
-
toolName:
|
|
4057
|
-
toolResponse:
|
|
4058
|
-
isError:
|
|
4486
|
+
stepIdx: z16.number().int().min(0),
|
|
4487
|
+
toolName: z16.string().min(1),
|
|
4488
|
+
toolResponse: z16.unknown().optional(),
|
|
4489
|
+
isError: z16.boolean().optional()
|
|
4059
4490
|
});
|
|
4060
|
-
var stopPayloadSchema3 =
|
|
4061
|
-
hookEventName:
|
|
4491
|
+
var stopPayloadSchema3 = z16.object({
|
|
4492
|
+
hookEventName: z16.literal("Stop"),
|
|
4062
4493
|
...commonFields2,
|
|
4063
|
-
fullyIdle:
|
|
4494
|
+
fullyIdle: z16.boolean()
|
|
4064
4495
|
});
|
|
4065
|
-
var antigravityHookPayloadSchema =
|
|
4496
|
+
var antigravityHookPayloadSchema = z16.discriminatedUnion("hookEventName", [
|
|
4066
4497
|
preInvocationPayloadSchema,
|
|
4067
4498
|
postInvocationPayloadSchema,
|
|
4068
4499
|
preToolUsePayloadSchema3,
|