@osfactory/otel-hook 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-DXpNtnaf.d.ts → adapter-BS7xHKGQ.d.ts} +9 -3
- package/dist/cli.js +1043 -487
- package/dist/cli.js.map +1 -1
- package/dist/{events-VxBnDFaO.d.ts → events-CzZ5kukS.d.ts} +177 -1
- package/dist/{filesystem-store-J8jjDMTh.d.ts → filesystem-store-BcOveJYY.d.ts} +1 -1
- package/dist/{hook-_mlO3akA.d.ts → hook-DxTakjAD.d.ts} +12 -4
- package/dist/index.d.ts +12 -12
- package/dist/index.js +1171 -599
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +103 -68
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +14 -8
- package/dist/integration.js +547 -121
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +27 -2
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-DXVBc8V9.d.ts → memory-DkTohdIa.d.ts} +2 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +84 -41
- package/dist/model.js.map +1 -1
- package/dist/{otlp-log-sink-DTSa0KRF.d.ts → otlp-log-sink-DaZDPKnR.d.ts} +3 -3
- package/dist/{payload-BWV5-4n3.d.ts → payload-2lnpKodw.d.ts} +1 -1
- package/dist/{ports-Q8x0ODhs.d.ts → ports-B0rC49b3.d.ts} +28 -2
- package/dist/providers.d.ts +26 -9
- package/dist/providers.js +668 -452
- package/dist/providers.js.map +1 -1
- package/dist/{registry-Dqr3VNmT.d.ts → registry-DVnPA_b6.d.ts} +1 -1
- package/dist/runtime.d.ts +103 -11
- package/dist/runtime.js +416 -67
- package/dist/runtime.js.map +1 -1
- package/dist/{semconv-CIU-2kGO.d.ts → semconv-CtnDdsPk.d.ts} +1 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +92 -10
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +13 -7
- package/dist/testing.js +821 -492
- package/dist/testing.js.map +1 -1
- package/package.json +4 -1
package/dist/testing.js
CHANGED
|
@@ -754,11 +754,11 @@ var createPrivacyService = (policyInput) => {
|
|
|
754
754
|
};
|
|
755
755
|
const flattenToAttributes = (value, prefix) => {
|
|
756
756
|
const attributes = {};
|
|
757
|
-
const walk = (current,
|
|
757
|
+
const walk = (current, path2) => {
|
|
758
758
|
if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
759
759
|
const primitive = toAttributePrimitive(current);
|
|
760
760
|
if (primitive !== void 0) {
|
|
761
|
-
attributes[
|
|
761
|
+
attributes[path2] = primitive;
|
|
762
762
|
}
|
|
763
763
|
return;
|
|
764
764
|
}
|
|
@@ -777,16 +777,16 @@ var createPrivacyService = (policyInput) => {
|
|
|
777
777
|
primitives.push(entryPrimitive);
|
|
778
778
|
}
|
|
779
779
|
if (uniform) {
|
|
780
|
-
attributes[
|
|
780
|
+
attributes[path2] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
|
|
781
781
|
return;
|
|
782
782
|
}
|
|
783
783
|
for (const [index, entry] of current.entries()) {
|
|
784
|
-
walk(entry, `${
|
|
784
|
+
walk(entry, `${path2}.${index}`);
|
|
785
785
|
}
|
|
786
786
|
return;
|
|
787
787
|
}
|
|
788
788
|
for (const [key, entry] of Object.entries(current)) {
|
|
789
|
-
walk(entry,
|
|
789
|
+
walk(entry, path2 === "" ? key : `${path2}.${key}`);
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
792
|
walk(value, prefix);
|
|
@@ -879,10 +879,10 @@ var createPrivacyService = (policyInput) => {
|
|
|
879
879
|
};
|
|
880
880
|
|
|
881
881
|
// src/providers/adapter.ts
|
|
882
|
-
import { z as
|
|
882
|
+
import { z as z13 } from "zod";
|
|
883
883
|
|
|
884
884
|
// src/model/events.ts
|
|
885
|
-
import { z as
|
|
885
|
+
import { z as z12 } from "zod";
|
|
886
886
|
|
|
887
887
|
// src/errors/taxonomy.ts
|
|
888
888
|
import { z as z7 } from "zod";
|
|
@@ -1118,16 +1118,41 @@ var contentFactsSchema = z8.array(contentFactSchema).max(64);
|
|
|
1118
1118
|
var isContentFactConsistent = (fact) => fact.disclosure === "omitted" ? fact.text === void 0 : fact.text !== void 0;
|
|
1119
1119
|
var isUnavailableContentFact = (fact) => fact.disclosure === "omitted" && fact.text === void 0 && fact.characterLength === 0 && fact.byteLength === 0;
|
|
1120
1120
|
|
|
1121
|
-
// src/model/
|
|
1121
|
+
// src/model/target.ts
|
|
1122
1122
|
import { z as z9 } from "zod";
|
|
1123
|
-
var
|
|
1124
|
-
var
|
|
1123
|
+
var targetSourceSchema = z9.enum(["tool-path", "shell-cwd", "session-cwd"]);
|
|
1124
|
+
var MAX_TARGET_HINT_PATHS = 8;
|
|
1125
|
+
var MAX_TARGET_PATH_LENGTH = 4096;
|
|
1126
|
+
var localPathSchema = z9.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
|
|
1127
|
+
var targetHintSchema = z9.strictObject({
|
|
1128
|
+
source: targetSourceSchema,
|
|
1129
|
+
paths: z9.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
|
|
1130
|
+
/** Absolute directory that relative `paths` resolve against. */
|
|
1131
|
+
baseDirectory: localPathSchema.optional()
|
|
1132
|
+
}).readonly();
|
|
1133
|
+
var worktreeKindSchema = z9.enum(["main", "linked"]);
|
|
1134
|
+
var workspaceTargetSchema = z9.strictObject({
|
|
1135
|
+
workspaceId: workspaceIdSchema,
|
|
1136
|
+
/** Branch checked out in that worktree; absent on a detached HEAD. */
|
|
1137
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
1138
|
+
source: targetSourceSchema,
|
|
1139
|
+
/** `git-root` handle of the repository's main worktree; absent when there is none to name. */
|
|
1140
|
+
repositoryId: workspaceIdSchema.optional(),
|
|
1141
|
+
worktreeKind: worktreeKindSchema.optional()
|
|
1142
|
+
}).readonly();
|
|
1143
|
+
var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
1144
|
+
var subagentIdSchema = z9.string().regex(SUBAGENT_ID_PATTERN);
|
|
1145
|
+
|
|
1146
|
+
// src/model/usage.ts
|
|
1147
|
+
import { z as z10 } from "zod";
|
|
1148
|
+
var usageTemporalitySchema = z10.enum(["delta", "cumulative"]);
|
|
1149
|
+
var cacheCreationAccountingSchema = z10.enum([
|
|
1125
1150
|
"included-in-input",
|
|
1126
1151
|
"disjoint-from-input",
|
|
1127
1152
|
"not-reported"
|
|
1128
1153
|
]);
|
|
1129
|
-
var providerTotalAgreementSchema =
|
|
1130
|
-
var usageReportSchema =
|
|
1154
|
+
var providerTotalAgreementSchema = z10.enum(["unreported", "agrees", "disagrees"]);
|
|
1155
|
+
var usageReportSchema = z10.strictObject({
|
|
1131
1156
|
temporality: usageTemporalitySchema,
|
|
1132
1157
|
/** Inclusive input tokens. */
|
|
1133
1158
|
inputTokens: tokenCountSchema.optional(),
|
|
@@ -1144,7 +1169,7 @@ var usageReportSchema = z9.strictObject({
|
|
|
1144
1169
|
/** Total exactly as the provider reported it, if it reported one. */
|
|
1145
1170
|
providerTotalTokens: tokenCountSchema.optional()
|
|
1146
1171
|
});
|
|
1147
|
-
var canonicalUsageSchema =
|
|
1172
|
+
var canonicalUsageSchema = z10.strictObject({
|
|
1148
1173
|
temporality: usageTemporalitySchema,
|
|
1149
1174
|
inputTokens: tokenCountSchema,
|
|
1150
1175
|
cachedInputTokens: tokenCountSchema,
|
|
@@ -1345,24 +1370,24 @@ var toReport = (usage) => ({
|
|
|
1345
1370
|
});
|
|
1346
1371
|
|
|
1347
1372
|
// src/model/version.ts
|
|
1348
|
-
import { z as
|
|
1373
|
+
import { z as z11 } from "zod";
|
|
1349
1374
|
var CANONICAL_SCHEMA_VERSION = 1;
|
|
1350
|
-
var canonicalSchemaVersionSchema =
|
|
1375
|
+
var canonicalSchemaVersionSchema = z11.literal(CANONICAL_SCHEMA_VERSION);
|
|
1351
1376
|
|
|
1352
1377
|
// src/model/events.ts
|
|
1353
|
-
var modelDescriptorSchema =
|
|
1378
|
+
var modelDescriptorSchema = z12.strictObject({
|
|
1354
1379
|
modelId: nonEmptyStringSchema,
|
|
1355
1380
|
/** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
|
|
1356
1381
|
vendor: nonEmptyStringSchema.optional(),
|
|
1357
1382
|
family: nonEmptyStringSchema.optional()
|
|
1358
1383
|
});
|
|
1359
|
-
var costFactsSchema =
|
|
1384
|
+
var costFactsSchema = z12.strictObject({
|
|
1360
1385
|
/** ISO 4217 code. */
|
|
1361
|
-
currency:
|
|
1362
|
-
amount:
|
|
1363
|
-
source:
|
|
1386
|
+
currency: z12.string().length(3),
|
|
1387
|
+
amount: z12.number().min(0).finite(),
|
|
1388
|
+
source: z12.enum(["provider-reported", "computed"])
|
|
1364
1389
|
});
|
|
1365
|
-
var canonicalEventTypeSchema =
|
|
1390
|
+
var canonicalEventTypeSchema = z12.enum([
|
|
1366
1391
|
"session.start",
|
|
1367
1392
|
"session.end",
|
|
1368
1393
|
"prompt.submitted",
|
|
@@ -1376,7 +1401,7 @@ var canonicalEventTypeSchema = z11.enum([
|
|
|
1376
1401
|
"error.raised"
|
|
1377
1402
|
]);
|
|
1378
1403
|
var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
|
|
1379
|
-
var outcomeSchema =
|
|
1404
|
+
var outcomeSchema = z12.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
|
|
1380
1405
|
var baseEventFields = {
|
|
1381
1406
|
schemaVersion: canonicalSchemaVersionSchema,
|
|
1382
1407
|
eventId: eventIdSchema,
|
|
@@ -1387,39 +1412,45 @@ var baseEventFields = {
|
|
|
1387
1412
|
occurredAt: epochMillisSchema,
|
|
1388
1413
|
provenance: sourceProvenanceSchema,
|
|
1389
1414
|
workspace: workspaceIdentitySchema,
|
|
1415
|
+
/**
|
|
1416
|
+
* The provider's own id for the subagent this event was emitted inside (e.g.
|
|
1417
|
+
* Claude Code's `agent_id`). Absent for the top-level agent. Set by the event
|
|
1418
|
+
* factory, never by hand.
|
|
1419
|
+
*/
|
|
1420
|
+
subagentId: subagentIdSchema.optional(),
|
|
1390
1421
|
extensions: extensionsSchema.default(emptyExtensions)
|
|
1391
1422
|
};
|
|
1392
|
-
var event = (shape) =>
|
|
1423
|
+
var event = (shape) => z12.strictObject({ ...baseEventFields, ...shape });
|
|
1393
1424
|
var sessionStartEventSchema = event({
|
|
1394
|
-
type:
|
|
1395
|
-
sessionKind:
|
|
1425
|
+
type: z12.literal("session.start"),
|
|
1426
|
+
sessionKind: z12.enum(["interactive", "non-interactive", "unknown"]),
|
|
1396
1427
|
agentName: nonEmptyStringSchema.optional(),
|
|
1397
1428
|
agentVersion: nonEmptyStringSchema.optional(),
|
|
1398
1429
|
model: modelDescriptorSchema.optional()
|
|
1399
1430
|
});
|
|
1400
1431
|
var sessionEndEventSchema = event({
|
|
1401
|
-
type:
|
|
1402
|
-
reason:
|
|
1432
|
+
type: z12.literal("session.end"),
|
|
1433
|
+
reason: z12.enum(["completed", "aborted", "error", "timeout", "unknown"]),
|
|
1403
1434
|
durationMillis: durationMillisSchema.optional(),
|
|
1404
1435
|
/** Session totals, typically cumulative. */
|
|
1405
1436
|
usage: canonicalUsageSchema.optional(),
|
|
1406
1437
|
cost: costFactsSchema.optional()
|
|
1407
1438
|
});
|
|
1408
1439
|
var promptSubmittedEventSchema = event({
|
|
1409
|
-
type:
|
|
1410
|
-
promptSource:
|
|
1440
|
+
type: z12.literal("prompt.submitted"),
|
|
1441
|
+
promptSource: z12.enum(["user", "automation", "resumed", "unknown"]),
|
|
1411
1442
|
content: contentFactSchema.optional(),
|
|
1412
|
-
turnIndex:
|
|
1443
|
+
turnIndex: z12.number().int().min(0).optional()
|
|
1413
1444
|
});
|
|
1414
1445
|
var generationStartEventSchema = event({
|
|
1415
|
-
type:
|
|
1446
|
+
type: z12.literal("generation.start"),
|
|
1416
1447
|
generationId: nonEmptyStringSchema,
|
|
1417
1448
|
model: modelDescriptorSchema,
|
|
1418
1449
|
requestedMaxOutputTokens: tokenCountSchema.optional(),
|
|
1419
1450
|
inputContent: contentFactsSchema.optional()
|
|
1420
1451
|
});
|
|
1421
1452
|
var generationEndEventSchema = event({
|
|
1422
|
-
type:
|
|
1453
|
+
type: z12.literal("generation.end"),
|
|
1423
1454
|
generationId: nonEmptyStringSchema,
|
|
1424
1455
|
model: modelDescriptorSchema,
|
|
1425
1456
|
outcome: outcomeSchema,
|
|
@@ -1429,7 +1460,7 @@ var generationEndEventSchema = event({
|
|
|
1429
1460
|
cost: costFactsSchema.optional(),
|
|
1430
1461
|
outputContent: contentFactsSchema.optional()
|
|
1431
1462
|
});
|
|
1432
|
-
var toolKindSchema =
|
|
1463
|
+
var toolKindSchema = z12.enum([
|
|
1433
1464
|
"read",
|
|
1434
1465
|
"write",
|
|
1435
1466
|
"execute",
|
|
@@ -1440,59 +1471,63 @@ var toolKindSchema = z11.enum([
|
|
|
1440
1471
|
"unknown"
|
|
1441
1472
|
]);
|
|
1442
1473
|
var toolStartEventSchema = event({
|
|
1443
|
-
type:
|
|
1474
|
+
type: z12.literal("tool.start"),
|
|
1444
1475
|
toolCallId: nonEmptyStringSchema,
|
|
1445
1476
|
toolName: nonEmptyStringSchema,
|
|
1446
1477
|
toolKind: toolKindSchema,
|
|
1447
1478
|
generationId: nonEmptyStringSchema.optional(),
|
|
1448
|
-
input: contentFactSchema.optional()
|
|
1479
|
+
input: contentFactSchema.optional(),
|
|
1480
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
1481
|
+
target: workspaceTargetSchema.optional()
|
|
1449
1482
|
});
|
|
1450
1483
|
var toolEndEventSchema = event({
|
|
1451
|
-
type:
|
|
1484
|
+
type: z12.literal("tool.end"),
|
|
1452
1485
|
toolCallId: nonEmptyStringSchema,
|
|
1453
1486
|
toolName: nonEmptyStringSchema,
|
|
1454
1487
|
outcome: outcomeSchema,
|
|
1455
1488
|
durationMillis: durationMillisSchema.optional(),
|
|
1456
1489
|
/** Present when the host asked for or recorded a permission decision. */
|
|
1457
|
-
permissionDecision:
|
|
1458
|
-
output: contentFactSchema.optional()
|
|
1490
|
+
permissionDecision: z12.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
|
|
1491
|
+
output: contentFactSchema.optional(),
|
|
1492
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
1493
|
+
target: workspaceTargetSchema.optional()
|
|
1459
1494
|
});
|
|
1460
1495
|
var subagentStartEventSchema = event({
|
|
1461
|
-
type:
|
|
1496
|
+
type: z12.literal("subagent.start"),
|
|
1462
1497
|
subagentInvocationId: invocationIdSchema,
|
|
1463
1498
|
subagentType: nonEmptyStringSchema.optional(),
|
|
1464
1499
|
/** 0 for the top-level agent; 1 for its direct children. */
|
|
1465
|
-
delegationDepth:
|
|
1500
|
+
delegationDepth: z12.number().int().min(0).max(64),
|
|
1466
1501
|
model: modelDescriptorSchema.optional()
|
|
1467
1502
|
});
|
|
1468
1503
|
var subagentEndEventSchema = event({
|
|
1469
|
-
type:
|
|
1504
|
+
type: z12.literal("subagent.end"),
|
|
1470
1505
|
subagentInvocationId: invocationIdSchema,
|
|
1471
1506
|
outcome: outcomeSchema,
|
|
1472
1507
|
durationMillis: durationMillisSchema.optional(),
|
|
1473
1508
|
usage: canonicalUsageSchema.optional()
|
|
1474
1509
|
});
|
|
1475
1510
|
var compactionPerformedEventSchema = event({
|
|
1476
|
-
type:
|
|
1477
|
-
trigger:
|
|
1511
|
+
type: z12.literal("compaction.performed"),
|
|
1512
|
+
trigger: z12.enum(["automatic", "manual", "unknown"]),
|
|
1478
1513
|
/** Provider-reported context size before and after compaction, if known. */
|
|
1479
1514
|
contextTokensBefore: tokenCountSchema.optional(),
|
|
1480
1515
|
contextTokensAfter: tokenCountSchema.optional(),
|
|
1481
|
-
droppedMessageCount:
|
|
1516
|
+
droppedMessageCount: z12.number().int().min(0).optional(),
|
|
1482
1517
|
usage: canonicalUsageSchema.optional()
|
|
1483
1518
|
});
|
|
1484
1519
|
var errorRaisedEventSchema = event({
|
|
1485
|
-
type:
|
|
1520
|
+
type: z12.literal("error.raised"),
|
|
1486
1521
|
errorCode: otelHookErrorCodeSchema,
|
|
1487
1522
|
severity: errorSeveritySchema,
|
|
1488
1523
|
phase: errorPhaseSchema,
|
|
1489
|
-
retryable:
|
|
1524
|
+
retryable: z12.boolean(),
|
|
1490
1525
|
/** Error text is content: it is described, never embedded verbatim by default. */
|
|
1491
1526
|
message: contentFactSchema.optional(),
|
|
1492
1527
|
/** Non-sensitive, provider-agnostic short label. */
|
|
1493
1528
|
detail: nonEmptyStringSchema.optional()
|
|
1494
1529
|
});
|
|
1495
|
-
var canonicalEventSchema =
|
|
1530
|
+
var canonicalEventSchema = z12.discriminatedUnion("type", [
|
|
1496
1531
|
sessionStartEventSchema,
|
|
1497
1532
|
sessionEndEventSchema,
|
|
1498
1533
|
promptSubmittedEventSchema,
|
|
@@ -1507,26 +1542,26 @@ var canonicalEventSchema = z11.discriminatedUnion("type", [
|
|
|
1507
1542
|
]);
|
|
1508
1543
|
|
|
1509
1544
|
// src/providers/adapter.ts
|
|
1510
|
-
var providerDetectionSchema =
|
|
1545
|
+
var providerDetectionSchema = z13.strictObject({
|
|
1511
1546
|
providerId: resolvedProviderIdSchema,
|
|
1512
1547
|
confidence: detectionConfidenceSchema,
|
|
1513
1548
|
/**
|
|
1514
1549
|
* Short, non-sensitive justifications, e.g. `"payload.hook_event_name present"`.
|
|
1515
1550
|
* Reasons are exported in diagnostics, so they must not quote payload values.
|
|
1516
1551
|
*/
|
|
1517
|
-
reasons:
|
|
1552
|
+
reasons: z13.array(z13.string().min(1).max(160)).max(8),
|
|
1518
1553
|
providerVersion: nonEmptyStringSchema.optional(),
|
|
1519
1554
|
/** The provider's own name for this event, when the payload states one. */
|
|
1520
1555
|
sourceEventName: nonEmptyStringSchema.optional()
|
|
1521
1556
|
});
|
|
1522
|
-
var deliveryIdentifierSupportSchema =
|
|
1557
|
+
var deliveryIdentifierSupportSchema = z13.enum(["none", "partial", "all"]);
|
|
1523
1558
|
var DELIVERY_COMPONENT_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
1524
|
-
var deliveryComponentSchema =
|
|
1559
|
+
var deliveryComponentSchema = z13.string().regex(
|
|
1525
1560
|
DELIVERY_COMPONENT_PATTERN,
|
|
1526
1561
|
"delivery component must be identifier-shaped: no whitespace, no path separators"
|
|
1527
1562
|
);
|
|
1528
1563
|
var MAX_DELIVERY_COMPONENTS = 8;
|
|
1529
|
-
var providerDeliveryClaimSchema =
|
|
1564
|
+
var providerDeliveryClaimSchema = z13.strictObject({
|
|
1530
1565
|
/**
|
|
1531
1566
|
* The provider's own session/conversation id. Scopes the callback identity, so
|
|
1532
1567
|
* two sessions reusing one tool-call id never collide.
|
|
@@ -1538,26 +1573,26 @@ var providerDeliveryClaimSchema = z12.strictObject({
|
|
|
1538
1573
|
* Identifier-shaped payload fields that, together with `sourceEventName`,
|
|
1539
1574
|
* name this callback within the session exactly once.
|
|
1540
1575
|
*/
|
|
1541
|
-
components:
|
|
1576
|
+
components: z13.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
|
|
1542
1577
|
/**
|
|
1543
1578
|
* Short, non-sensitive justifications, e.g. `"payload.tool_use_id names one
|
|
1544
1579
|
* tool call"`. Evidence reaches diagnostics, so it must name fields, never
|
|
1545
1580
|
* quote their values.
|
|
1546
1581
|
*/
|
|
1547
|
-
evidence:
|
|
1582
|
+
evidence: z13.array(z13.string().min(1).max(160)).min(1).max(4).readonly()
|
|
1548
1583
|
});
|
|
1549
1584
|
var DELIVERY_GAP_REASON_PATTERN = /^[^\n\r\t\\/]{1,240}$/;
|
|
1550
|
-
var deliveryGapReasonSchema =
|
|
1585
|
+
var deliveryGapReasonSchema = z13.string().regex(
|
|
1551
1586
|
DELIVERY_GAP_REASON_PATTERN,
|
|
1552
1587
|
"delivery gap reason must be one line of prose: no path separators, no control characters"
|
|
1553
1588
|
);
|
|
1554
1589
|
var MAX_DELIVERY_GAPS = 48;
|
|
1555
|
-
var providerDeliveryGapsSchema =
|
|
1590
|
+
var providerDeliveryGapsSchema = z13.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
|
|
1556
1591
|
message: `at most ${String(MAX_DELIVERY_GAPS)} delivery gaps may be declared`
|
|
1557
1592
|
});
|
|
1558
|
-
var providerCapabilitiesSchema =
|
|
1593
|
+
var providerCapabilitiesSchema = z13.strictObject({
|
|
1559
1594
|
/** Event types the adapter can produce. */
|
|
1560
|
-
lifecycleEvents:
|
|
1595
|
+
lifecycleEvents: z13.array(canonicalEventTypeSchema).max(32).readonly(),
|
|
1561
1596
|
usageTemporality: usageTemporalitySchema,
|
|
1562
1597
|
/**
|
|
1563
1598
|
* Which accumulator series a `cumulative` report continues — that is, which
|
|
@@ -1576,32 +1611,32 @@ var providerCapabilitiesSchema = z12.strictObject({
|
|
|
1576
1611
|
* Subagent snapshots keep their own series regardless: a delegated agent's
|
|
1577
1612
|
* counter is not a point on the parent session's curve.
|
|
1578
1613
|
*/
|
|
1579
|
-
cumulativeUsageSeries:
|
|
1580
|
-
reportsCachedInput:
|
|
1581
|
-
reportsCacheCreation:
|
|
1614
|
+
cumulativeUsageSeries: z13.enum(["event-scope", "session-lifetime"]).optional(),
|
|
1615
|
+
reportsCachedInput: z13.boolean(),
|
|
1616
|
+
reportsCacheCreation: z13.boolean(),
|
|
1582
1617
|
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
1583
|
-
reportsReasoningOutput:
|
|
1584
|
-
reportsProviderTotal:
|
|
1585
|
-
reportsCost:
|
|
1586
|
-
emitsSubagentEvents:
|
|
1587
|
-
emitsCompactionEvents:
|
|
1618
|
+
reportsReasoningOutput: z13.boolean(),
|
|
1619
|
+
reportsProviderTotal: z13.boolean(),
|
|
1620
|
+
reportsCost: z13.boolean(),
|
|
1621
|
+
emitsSubagentEvents: z13.boolean(),
|
|
1622
|
+
emitsCompactionEvents: z13.boolean(),
|
|
1588
1623
|
/** True when the provider reads a structured response from stdout. */
|
|
1589
|
-
requiresHookResponse:
|
|
1624
|
+
requiresHookResponse: z13.boolean(),
|
|
1590
1625
|
/** How much of this provider's hook traffic is replay-identifiable. */
|
|
1591
1626
|
deliveryIdentifier: deliveryIdentifierSupportSchema
|
|
1592
1627
|
});
|
|
1593
|
-
var providerHookResponseSchema =
|
|
1628
|
+
var providerHookResponseSchema = z13.strictObject({
|
|
1594
1629
|
/**
|
|
1595
1630
|
* Always 0. A telemetry hook that can fail the host agent is a liability, so
|
|
1596
1631
|
* the type forbids expressing anything else (ADR 0004).
|
|
1597
1632
|
*/
|
|
1598
|
-
exitCode:
|
|
1633
|
+
exitCode: z13.literal(0),
|
|
1599
1634
|
/** Protocol response text. Omit to write nothing at all. */
|
|
1600
|
-
stdout:
|
|
1635
|
+
stdout: z13.string().max(8192).optional(),
|
|
1601
1636
|
/** Non-sensitive diagnostic text for stderr. */
|
|
1602
|
-
stderr:
|
|
1637
|
+
stderr: z13.string().max(8192).optional(),
|
|
1603
1638
|
/** Declares which of the two stdout contracts this response follows. */
|
|
1604
|
-
contract:
|
|
1639
|
+
contract: z13.enum(["silent", "provider-protocol"])
|
|
1605
1640
|
});
|
|
1606
1641
|
var SILENT_HOOK_RESPONSE = Object.freeze({
|
|
1607
1642
|
exitCode: 0,
|
|
@@ -1646,14 +1681,14 @@ var unknownDetection = (reasons = ["no adapter recognized the input"]) => provid
|
|
|
1646
1681
|
});
|
|
1647
1682
|
|
|
1648
1683
|
// src/errors/index.ts
|
|
1649
|
-
import { z as
|
|
1650
|
-
var otelHookErrorInfoSchema =
|
|
1684
|
+
import { z as z14 } from "zod";
|
|
1685
|
+
var otelHookErrorInfoSchema = z14.strictObject({
|
|
1651
1686
|
code: otelHookErrorCodeSchema,
|
|
1652
1687
|
severity: errorSeveritySchema,
|
|
1653
1688
|
phase: errorPhaseSchema,
|
|
1654
1689
|
posture: failurePostureSchema,
|
|
1655
|
-
retryable:
|
|
1656
|
-
message:
|
|
1690
|
+
retryable: z14.boolean(),
|
|
1691
|
+
message: z14.string().min(1).max(512),
|
|
1657
1692
|
details: attributesSchema.optional(),
|
|
1658
1693
|
occurredAt: epochMillisSchema.optional()
|
|
1659
1694
|
});
|
|
@@ -1711,10 +1746,15 @@ var createEventFactory = (input) => {
|
|
|
1711
1746
|
const { identity, context } = input;
|
|
1712
1747
|
const built = [];
|
|
1713
1748
|
const dropped = [];
|
|
1749
|
+
const hints = /* @__PURE__ */ new Map();
|
|
1714
1750
|
let sequence = input.sequenceBase;
|
|
1751
|
+
const subagentId = input.subagentId !== void 0 && subagentIdSchema.safeParse(input.subagentId).success ? input.subagentId : void 0;
|
|
1715
1752
|
return {
|
|
1716
1753
|
build: (draft) => {
|
|
1717
|
-
const { occurredAt, extensions, idDiscriminator, ...
|
|
1754
|
+
const { occurredAt, extensions, idDiscriminator, targetHint, ...drafted } = draft;
|
|
1755
|
+
const rest = { ...drafted };
|
|
1756
|
+
delete rest.target;
|
|
1757
|
+
delete rest.subagentId;
|
|
1718
1758
|
const sanitized = extensions === void 0 ? { extensions: {}, droppedKeys: [] } : context.privacy.sanitizeExtensions(extensions);
|
|
1719
1759
|
dropped.push(...sanitized.droppedKeys);
|
|
1720
1760
|
const currentSequence = sequence;
|
|
@@ -1734,6 +1774,7 @@ var createEventFactory = (input) => {
|
|
|
1734
1774
|
occurredAt: occurredAt ?? context.clock.now(),
|
|
1735
1775
|
provenance: identity.provenance,
|
|
1736
1776
|
workspace: identity.workspace,
|
|
1777
|
+
...subagentId === void 0 ? {} : { subagentId },
|
|
1737
1778
|
extensions: sanitized.extensions
|
|
1738
1779
|
};
|
|
1739
1780
|
const parsed = canonicalEventSchema.safeParse(candidate);
|
|
@@ -1746,11 +1787,18 @@ var createEventFactory = (input) => {
|
|
|
1746
1787
|
});
|
|
1747
1788
|
}
|
|
1748
1789
|
built.push(parsed.data);
|
|
1790
|
+
if (targetHint !== void 0 && (parsed.data.type === "tool.start" || parsed.data.type === "tool.end")) {
|
|
1791
|
+
const hint = targetHintSchema.safeParse(targetHint);
|
|
1792
|
+
if (hint.success) {
|
|
1793
|
+
hints.set(parsed.data.eventId, hint.data);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1749
1796
|
return parsed.data;
|
|
1750
1797
|
},
|
|
1751
1798
|
events: () => [...built],
|
|
1752
1799
|
nextSequence: () => sequence,
|
|
1753
|
-
droppedExtensionKeys: () => [...dropped]
|
|
1800
|
+
droppedExtensionKeys: () => [...dropped],
|
|
1801
|
+
targetHints: () => new Map(hints)
|
|
1754
1802
|
};
|
|
1755
1803
|
};
|
|
1756
1804
|
|
|
@@ -1910,35 +1958,35 @@ var CLAUDE_CODE_CAPABILITIES = Object.freeze({
|
|
|
1910
1958
|
});
|
|
1911
1959
|
|
|
1912
1960
|
// src/providers/claude/schema.ts
|
|
1913
|
-
import { z as
|
|
1961
|
+
import { z as z15 } from "zod";
|
|
1914
1962
|
var commonFields = {
|
|
1915
|
-
session_id:
|
|
1916
|
-
transcript_path:
|
|
1917
|
-
cwd:
|
|
1918
|
-
permission_mode:
|
|
1963
|
+
session_id: z15.string().min(1),
|
|
1964
|
+
transcript_path: z15.string().min(1).optional(),
|
|
1965
|
+
cwd: z15.string().min(1).optional(),
|
|
1966
|
+
permission_mode: z15.string().min(1).optional(),
|
|
1919
1967
|
/** Correlates a hook firing with the user prompt that triggered it (Claude Code v2.1.196+). */
|
|
1920
|
-
prompt_id:
|
|
1968
|
+
prompt_id: z15.string().min(1).optional(),
|
|
1921
1969
|
/** Present when the hook fired while running inside a subagent. */
|
|
1922
|
-
agent_id:
|
|
1923
|
-
agent_type:
|
|
1970
|
+
agent_id: z15.string().min(1).optional(),
|
|
1971
|
+
agent_type: z15.string().min(1).optional()
|
|
1924
1972
|
};
|
|
1925
|
-
var claudeCacheCreationSchema =
|
|
1926
|
-
ephemeral_5m_input_tokens:
|
|
1927
|
-
ephemeral_1h_input_tokens:
|
|
1928
|
-
});
|
|
1929
|
-
var claudeUsageIterationSchema =
|
|
1930
|
-
input_tokens:
|
|
1931
|
-
output_tokens:
|
|
1932
|
-
cache_creation_input_tokens:
|
|
1933
|
-
cache_read_input_tokens:
|
|
1934
|
-
});
|
|
1935
|
-
var claudeUsageSchema =
|
|
1936
|
-
input_tokens:
|
|
1937
|
-
output_tokens:
|
|
1938
|
-
cache_creation_input_tokens:
|
|
1939
|
-
cache_read_input_tokens:
|
|
1973
|
+
var claudeCacheCreationSchema = z15.object({
|
|
1974
|
+
ephemeral_5m_input_tokens: z15.number().int().min(0).optional(),
|
|
1975
|
+
ephemeral_1h_input_tokens: z15.number().int().min(0).optional()
|
|
1976
|
+
});
|
|
1977
|
+
var claudeUsageIterationSchema = z15.object({
|
|
1978
|
+
input_tokens: z15.number().int().min(0).optional(),
|
|
1979
|
+
output_tokens: z15.number().int().min(0).optional(),
|
|
1980
|
+
cache_creation_input_tokens: z15.number().int().min(0).optional(),
|
|
1981
|
+
cache_read_input_tokens: z15.number().int().min(0).optional()
|
|
1982
|
+
});
|
|
1983
|
+
var claudeUsageSchema = z15.object({
|
|
1984
|
+
input_tokens: z15.number().int().min(0),
|
|
1985
|
+
output_tokens: z15.number().int().min(0),
|
|
1986
|
+
cache_creation_input_tokens: z15.number().int().min(0).optional(),
|
|
1987
|
+
cache_read_input_tokens: z15.number().int().min(0).optional(),
|
|
1940
1988
|
cache_creation: claudeCacheCreationSchema.optional(),
|
|
1941
|
-
iterations:
|
|
1989
|
+
iterations: z15.array(claudeUsageIterationSchema).optional(),
|
|
1942
1990
|
/**
|
|
1943
1991
|
* Counters the canonical model has a home for but Claude Code never reports:
|
|
1944
1992
|
* 0 of 4,999 real usage objects carried either (finding 5).
|
|
@@ -1947,112 +1995,112 @@ var claudeUsageSchema = z14.object({
|
|
|
1947
1995
|
* that a harness attaching one gets told it was excluded, instead of watching
|
|
1948
1996
|
* it vanish. See `CLAUDE_EXCLUDED_USAGE_COUNTERS`.
|
|
1949
1997
|
*/
|
|
1950
|
-
total_tokens:
|
|
1951
|
-
reasoning_output_tokens:
|
|
1998
|
+
total_tokens: z15.number().int().min(0).optional(),
|
|
1999
|
+
reasoning_output_tokens: z15.number().int().min(0).optional()
|
|
1952
2000
|
});
|
|
1953
|
-
var sessionStartPayloadSchema =
|
|
2001
|
+
var sessionStartPayloadSchema = z15.object({
|
|
1954
2002
|
...commonFields,
|
|
1955
|
-
hook_event_name:
|
|
2003
|
+
hook_event_name: z15.literal("SessionStart"),
|
|
1956
2004
|
/** Matcher values: startup | resume | clear | compact | fork. Forward-compatible: any string. */
|
|
1957
|
-
source:
|
|
1958
|
-
model:
|
|
1959
|
-
session_title:
|
|
2005
|
+
source: z15.string().min(1).optional(),
|
|
2006
|
+
model: z15.string().min(1).optional(),
|
|
2007
|
+
session_title: z15.string().min(1).optional()
|
|
1960
2008
|
});
|
|
1961
|
-
var sessionEndPayloadSchema =
|
|
2009
|
+
var sessionEndPayloadSchema = z15.object({
|
|
1962
2010
|
...commonFields,
|
|
1963
|
-
hook_event_name:
|
|
2011
|
+
hook_event_name: z15.literal("SessionEnd"),
|
|
1964
2012
|
/** Current Claude Code field; values include clear, logout, prompt_input_exit, and other. */
|
|
1965
|
-
reason:
|
|
2013
|
+
reason: z15.string().min(1).optional(),
|
|
1966
2014
|
/** Compatibility alias emitted by older wrappers and hook integrations. */
|
|
1967
|
-
end_reason:
|
|
2015
|
+
end_reason: z15.string().min(1).optional()
|
|
1968
2016
|
});
|
|
1969
|
-
var userPromptSubmitPayloadSchema =
|
|
2017
|
+
var userPromptSubmitPayloadSchema = z15.object({
|
|
1970
2018
|
...commonFields,
|
|
1971
|
-
hook_event_name:
|
|
1972
|
-
prompt:
|
|
2019
|
+
hook_event_name: z15.literal("UserPromptSubmit"),
|
|
2020
|
+
prompt: z15.string()
|
|
1973
2021
|
});
|
|
1974
|
-
var preToolUsePayloadSchema =
|
|
2022
|
+
var preToolUsePayloadSchema = z15.object({
|
|
1975
2023
|
...commonFields,
|
|
1976
|
-
hook_event_name:
|
|
1977
|
-
tool_name:
|
|
1978
|
-
tool_input:
|
|
1979
|
-
tool_use_id:
|
|
2024
|
+
hook_event_name: z15.literal("PreToolUse"),
|
|
2025
|
+
tool_name: z15.string().min(1),
|
|
2026
|
+
tool_input: z15.unknown(),
|
|
2027
|
+
tool_use_id: z15.string().min(1)
|
|
1980
2028
|
});
|
|
1981
|
-
var postToolUsePayloadSchema =
|
|
2029
|
+
var postToolUsePayloadSchema = z15.object({
|
|
1982
2030
|
...commonFields,
|
|
1983
|
-
hook_event_name:
|
|
1984
|
-
tool_name:
|
|
1985
|
-
tool_input:
|
|
1986
|
-
tool_response:
|
|
1987
|
-
tool_use_id:
|
|
2031
|
+
hook_event_name: z15.literal("PostToolUse"),
|
|
2032
|
+
tool_name: z15.string().min(1),
|
|
2033
|
+
tool_input: z15.unknown().optional(),
|
|
2034
|
+
tool_response: z15.unknown(),
|
|
2035
|
+
tool_use_id: z15.string().min(1)
|
|
1988
2036
|
});
|
|
1989
|
-
var postToolUseFailurePayloadSchema =
|
|
2037
|
+
var postToolUseFailurePayloadSchema = z15.object({
|
|
1990
2038
|
...commonFields,
|
|
1991
|
-
hook_event_name:
|
|
1992
|
-
tool_name:
|
|
1993
|
-
tool_input:
|
|
1994
|
-
tool_error:
|
|
1995
|
-
tool_use_id:
|
|
2039
|
+
hook_event_name: z15.literal("PostToolUseFailure"),
|
|
2040
|
+
tool_name: z15.string().min(1),
|
|
2041
|
+
tool_input: z15.unknown().optional(),
|
|
2042
|
+
tool_error: z15.unknown(),
|
|
2043
|
+
tool_use_id: z15.string().min(1)
|
|
1996
2044
|
});
|
|
1997
|
-
var permissionRequestPayloadSchema =
|
|
2045
|
+
var permissionRequestPayloadSchema = z15.object({
|
|
1998
2046
|
...commonFields,
|
|
1999
|
-
hook_event_name:
|
|
2000
|
-
tool_name:
|
|
2001
|
-
tool_input:
|
|
2002
|
-
tool_use_id:
|
|
2047
|
+
hook_event_name: z15.literal("PermissionRequest"),
|
|
2048
|
+
tool_name: z15.string().min(1),
|
|
2049
|
+
tool_input: z15.unknown().optional(),
|
|
2050
|
+
tool_use_id: z15.string().min(1)
|
|
2003
2051
|
});
|
|
2004
|
-
var subagentStartPayloadSchema =
|
|
2052
|
+
var subagentStartPayloadSchema = z15.object({
|
|
2005
2053
|
...commonFields,
|
|
2006
|
-
hook_event_name:
|
|
2007
|
-
agent_type:
|
|
2008
|
-
agent_id:
|
|
2054
|
+
hook_event_name: z15.literal("SubagentStart"),
|
|
2055
|
+
agent_type: z15.string().min(1),
|
|
2056
|
+
agent_id: z15.string().min(1)
|
|
2009
2057
|
});
|
|
2010
|
-
var subagentStopPayloadSchema =
|
|
2058
|
+
var subagentStopPayloadSchema = z15.object({
|
|
2011
2059
|
...commonFields,
|
|
2012
|
-
hook_event_name:
|
|
2013
|
-
agent_type:
|
|
2014
|
-
agent_id:
|
|
2015
|
-
last_assistant_message:
|
|
2060
|
+
hook_event_name: z15.literal("SubagentStop"),
|
|
2061
|
+
agent_type: z15.string().min(1),
|
|
2062
|
+
agent_id: z15.string().min(1),
|
|
2063
|
+
last_assistant_message: z15.string().optional(),
|
|
2016
2064
|
/** True when this stop fired because a hook continued the subagent's turn. */
|
|
2017
|
-
stop_hook_active:
|
|
2065
|
+
stop_hook_active: z15.boolean().optional(),
|
|
2018
2066
|
usage: claudeUsageSchema.optional()
|
|
2019
2067
|
});
|
|
2020
|
-
var preCompactPayloadSchema =
|
|
2068
|
+
var preCompactPayloadSchema = z15.object({
|
|
2021
2069
|
...commonFields,
|
|
2022
|
-
hook_event_name:
|
|
2070
|
+
hook_event_name: z15.literal("PreCompact"),
|
|
2023
2071
|
/** Upstream values: manual | auto. Forward-compatible: any string. */
|
|
2024
|
-
trigger:
|
|
2072
|
+
trigger: z15.string().min(1).optional(),
|
|
2025
2073
|
/** Compatibility alias emitted by older wrappers and hook integrations. */
|
|
2026
|
-
compact_trigger:
|
|
2074
|
+
compact_trigger: z15.string().min(1).optional(),
|
|
2027
2075
|
/**
|
|
2028
2076
|
* Harness-supplied, never upstream. Reported as an explicit exclusion rather
|
|
2029
2077
|
* than carried across the process boundary: see `events.ts`.
|
|
2030
2078
|
*/
|
|
2031
|
-
context_tokens_before:
|
|
2032
|
-
estimated_tokens_removed:
|
|
2079
|
+
context_tokens_before: z15.number().int().min(0).optional(),
|
|
2080
|
+
estimated_tokens_removed: z15.number().int().min(0).optional()
|
|
2033
2081
|
});
|
|
2034
|
-
var postCompactPayloadSchema =
|
|
2082
|
+
var postCompactPayloadSchema = z15.object({
|
|
2035
2083
|
...commonFields,
|
|
2036
|
-
hook_event_name:
|
|
2037
|
-
trigger:
|
|
2038
|
-
compact_trigger:
|
|
2084
|
+
hook_event_name: z15.literal("PostCompact"),
|
|
2085
|
+
trigger: z15.string().min(1).optional(),
|
|
2086
|
+
compact_trigger: z15.string().min(1).optional(),
|
|
2039
2087
|
/** Harness-supplied, never upstream; accepted here because one callback carries both. */
|
|
2040
|
-
context_tokens_before:
|
|
2041
|
-
context_tokens_after:
|
|
2042
|
-
dropped_message_count:
|
|
2088
|
+
context_tokens_before: z15.number().int().min(0).optional(),
|
|
2089
|
+
context_tokens_after: z15.number().int().min(0).optional(),
|
|
2090
|
+
dropped_message_count: z15.number().int().min(0).optional(),
|
|
2043
2091
|
usage: claudeUsageSchema.optional()
|
|
2044
2092
|
});
|
|
2045
|
-
var stopPayloadSchema =
|
|
2093
|
+
var stopPayloadSchema = z15.object({
|
|
2046
2094
|
...commonFields,
|
|
2047
|
-
hook_event_name:
|
|
2095
|
+
hook_event_name: z15.literal("Stop"),
|
|
2048
2096
|
/**
|
|
2049
2097
|
* Interactive Stop field (Claude Code ≥ 2.1.47). Print / `-p` / Agent SDK
|
|
2050
2098
|
* result messages use `result` instead; `events.ts` reads both (and camelCase
|
|
2051
2099
|
* `lastAssistantMessage`) through `extractClaudeAssistantText`.
|
|
2052
2100
|
*/
|
|
2053
|
-
last_assistant_message:
|
|
2101
|
+
last_assistant_message: z15.string().optional(),
|
|
2054
2102
|
/** Print / `-p` JSON result field; accepted so a harness can attach it as-is. */
|
|
2055
|
-
result:
|
|
2103
|
+
result: z15.string().optional(),
|
|
2056
2104
|
/**
|
|
2057
2105
|
* True when this stop fired because a hook continued the turn.
|
|
2058
2106
|
*
|
|
@@ -2060,22 +2108,22 @@ var stopPayloadSchema = z14.object({
|
|
|
2060
2108
|
* stop from a continuation stop, which is what lets `delivery.ts` deduplicate
|
|
2061
2109
|
* the former without suppressing the latter.
|
|
2062
2110
|
*/
|
|
2063
|
-
stop_hook_active:
|
|
2111
|
+
stop_hook_active: z15.boolean().optional(),
|
|
2064
2112
|
usage: claudeUsageSchema.optional()
|
|
2065
2113
|
});
|
|
2066
|
-
var stopFailurePayloadSchema =
|
|
2114
|
+
var stopFailurePayloadSchema = z15.object({
|
|
2067
2115
|
...commonFields,
|
|
2068
|
-
hook_event_name:
|
|
2116
|
+
hook_event_name: z15.literal("StopFailure"),
|
|
2069
2117
|
/**
|
|
2070
2118
|
* Matcher values: rate_limit | overloaded | authentication_failed |
|
|
2071
2119
|
* oauth_org_not_allowed | billing_error | invalid_request | model_not_found
|
|
2072
2120
|
* | server_error | max_output_tokens | unknown.
|
|
2073
2121
|
*/
|
|
2074
|
-
error_type:
|
|
2075
|
-
error_message:
|
|
2122
|
+
error_type: z15.string().min(1),
|
|
2123
|
+
error_message: z15.string().optional(),
|
|
2076
2124
|
usage: claudeUsageSchema.optional()
|
|
2077
2125
|
});
|
|
2078
|
-
var claudeHookPayloadSchema =
|
|
2126
|
+
var claudeHookPayloadSchema = z15.discriminatedUnion("hook_event_name", [
|
|
2079
2127
|
sessionStartPayloadSchema,
|
|
2080
2128
|
sessionEndPayloadSchema,
|
|
2081
2129
|
userPromptSubmitPayloadSchema,
|
|
@@ -2105,15 +2153,15 @@ var CLAUDE_HOOK_EVENT_NAMES = [
|
|
|
2105
2153
|
"Stop",
|
|
2106
2154
|
"StopFailure"
|
|
2107
2155
|
];
|
|
2108
|
-
var claudeIdentityFieldsSchema =
|
|
2109
|
-
session_id:
|
|
2110
|
-
hook_event_name:
|
|
2111
|
-
cwd:
|
|
2112
|
-
prompt_id:
|
|
2113
|
-
agent_id:
|
|
2114
|
-
tool_use_id:
|
|
2156
|
+
var claudeIdentityFieldsSchema = z15.object({
|
|
2157
|
+
session_id: z15.string().min(1),
|
|
2158
|
+
hook_event_name: z15.string().min(1),
|
|
2159
|
+
cwd: z15.string().min(1).optional(),
|
|
2160
|
+
prompt_id: z15.string().min(1).optional(),
|
|
2161
|
+
agent_id: z15.string().min(1).optional(),
|
|
2162
|
+
tool_use_id: z15.string().min(1).optional(),
|
|
2115
2163
|
/** Read by `delivery.ts` to tell a once-per-prompt stop from a continuation. */
|
|
2116
|
-
stop_hook_active:
|
|
2164
|
+
stop_hook_active: z15.boolean().optional()
|
|
2117
2165
|
});
|
|
2118
2166
|
|
|
2119
2167
|
// src/providers/claude/usage.ts
|
|
@@ -2591,6 +2639,37 @@ var extractClaudeAssistantText = (payload) => {
|
|
|
2591
2639
|
return void 0;
|
|
2592
2640
|
};
|
|
2593
2641
|
|
|
2642
|
+
// src/providers/claude/target.ts
|
|
2643
|
+
var PATH_FIELDS = Object.freeze({
|
|
2644
|
+
Read: ["file_path"],
|
|
2645
|
+
Write: ["file_path"],
|
|
2646
|
+
Edit: ["file_path"],
|
|
2647
|
+
MultiEdit: ["file_path"],
|
|
2648
|
+
NotebookEdit: ["notebook_path"],
|
|
2649
|
+
NotebookRead: ["notebook_path"],
|
|
2650
|
+
// Optional on both: absent means "search the session's directory".
|
|
2651
|
+
Glob: ["path"],
|
|
2652
|
+
Grep: ["path"]
|
|
2653
|
+
});
|
|
2654
|
+
var asRecord4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
2655
|
+
var claudeTargetHint = (toolName, toolInput, cwd) => {
|
|
2656
|
+
const fields = Object.hasOwn(PATH_FIELDS, toolName) ? PATH_FIELDS[toolName] : void 0;
|
|
2657
|
+
const input = asRecord4(toolInput);
|
|
2658
|
+
if (fields !== void 0 && input !== void 0) {
|
|
2659
|
+
for (const field of fields) {
|
|
2660
|
+
const candidate = input[field];
|
|
2661
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
2662
|
+
return {
|
|
2663
|
+
source: "tool-path",
|
|
2664
|
+
paths: [candidate],
|
|
2665
|
+
...cwd === void 0 ? {} : { baseDirectory: cwd }
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
return cwd === void 0 ? void 0 : { source: "session-cwd", paths: [cwd] };
|
|
2671
|
+
};
|
|
2672
|
+
|
|
2594
2673
|
// src/providers/claude/tool-kind.ts
|
|
2595
2674
|
var BUILT_IN_TOOL_KIND = Object.freeze({
|
|
2596
2675
|
Bash: "execute",
|
|
@@ -2670,9 +2749,16 @@ var parseClaudeCode = (input, context) => {
|
|
|
2670
2749
|
const factory = createEventFactory({
|
|
2671
2750
|
identity: input.identity,
|
|
2672
2751
|
sequenceBase: input.sequenceBase,
|
|
2673
|
-
context
|
|
2752
|
+
context,
|
|
2753
|
+
// Present exactly when the hook fired inside a subagent (or describes one,
|
|
2754
|
+
// on SubagentStart/SubagentStop).
|
|
2755
|
+
...payload.agent_id === void 0 ? {} : { subagentId: payload.agent_id }
|
|
2674
2756
|
});
|
|
2675
2757
|
const warnings = [];
|
|
2758
|
+
const targetHintFor = (toolName, toolInput) => {
|
|
2759
|
+
const hint = claudeTargetHint(toolName, toolInput, payload.cwd);
|
|
2760
|
+
return hint === void 0 ? {} : { targetHint: hint };
|
|
2761
|
+
};
|
|
2676
2762
|
const withUsage = (usage) => {
|
|
2677
2763
|
const normalized = normalizeClaudeUsage(usage);
|
|
2678
2764
|
warnings.push(...normalized.warnings);
|
|
@@ -2707,6 +2793,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
2707
2793
|
toolCallId: payload.tool_use_id,
|
|
2708
2794
|
toolName: payload.tool_name,
|
|
2709
2795
|
toolKind: inferToolKind(payload.tool_name),
|
|
2796
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
2710
2797
|
...payload.tool_input === void 0 ? {} : {
|
|
2711
2798
|
input: context.privacy.describeStructured({
|
|
2712
2799
|
kind: "tool-input",
|
|
@@ -2722,6 +2809,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
2722
2809
|
toolCallId: payload.tool_use_id,
|
|
2723
2810
|
toolName: payload.tool_name,
|
|
2724
2811
|
outcome: "ok",
|
|
2812
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
2725
2813
|
output: context.privacy.describeStructured({
|
|
2726
2814
|
kind: "tool-output",
|
|
2727
2815
|
value: payload.tool_response,
|
|
@@ -2735,6 +2823,7 @@ var parseClaudeCode = (input, context) => {
|
|
|
2735
2823
|
toolCallId: payload.tool_use_id,
|
|
2736
2824
|
toolName: payload.tool_name,
|
|
2737
2825
|
outcome: "error",
|
|
2826
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
2738
2827
|
output: context.privacy.describeStructured({
|
|
2739
2828
|
kind: "tool-output",
|
|
2740
2829
|
value: payload.tool_error,
|
|
@@ -2833,10 +2922,12 @@ var parseClaudeCode = (input, context) => {
|
|
|
2833
2922
|
break;
|
|
2834
2923
|
}
|
|
2835
2924
|
}
|
|
2925
|
+
const targetHints = factory.targetHints();
|
|
2836
2926
|
return {
|
|
2837
2927
|
status: "parsed",
|
|
2838
2928
|
events: factory.events(),
|
|
2839
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
2929
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
2930
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
2840
2931
|
};
|
|
2841
2932
|
};
|
|
2842
2933
|
|
|
@@ -2854,7 +2945,7 @@ var createClaudeCodeAdapter = (options = {}) => ({
|
|
|
2854
2945
|
});
|
|
2855
2946
|
|
|
2856
2947
|
// src/providers/cursor/payload.ts
|
|
2857
|
-
import { z as
|
|
2948
|
+
import { z as z16 } from "zod";
|
|
2858
2949
|
var CURSOR_PROVIDER_ID = "cursor";
|
|
2859
2950
|
var CURSOR_HOOK_EVENT_NAMES = [
|
|
2860
2951
|
"sessionStart",
|
|
@@ -2889,23 +2980,23 @@ var CURSOR_DECISION_EVENTS = Object.freeze({
|
|
|
2889
2980
|
subagentStart: "permission",
|
|
2890
2981
|
beforeSubmitPrompt: "continue"
|
|
2891
2982
|
});
|
|
2892
|
-
var modelParamSchema =
|
|
2893
|
-
id:
|
|
2894
|
-
value:
|
|
2983
|
+
var modelParamSchema = z16.object({
|
|
2984
|
+
id: z16.string(),
|
|
2985
|
+
value: z16.string()
|
|
2895
2986
|
});
|
|
2896
|
-
var attachmentSchema =
|
|
2897
|
-
type:
|
|
2898
|
-
file_path:
|
|
2987
|
+
var attachmentSchema = z16.object({
|
|
2988
|
+
type: z16.string().optional(),
|
|
2989
|
+
file_path: z16.string().optional()
|
|
2899
2990
|
});
|
|
2900
|
-
var fileEditSchema =
|
|
2901
|
-
old_string:
|
|
2902
|
-
new_string:
|
|
2991
|
+
var fileEditSchema = z16.object({
|
|
2992
|
+
old_string: z16.string().optional(),
|
|
2993
|
+
new_string: z16.string().optional()
|
|
2903
2994
|
});
|
|
2904
2995
|
var usageFields = {
|
|
2905
|
-
input_tokens:
|
|
2906
|
-
output_tokens:
|
|
2907
|
-
cache_read_tokens:
|
|
2908
|
-
cache_write_tokens:
|
|
2996
|
+
input_tokens: z16.number().int().min(0).optional(),
|
|
2997
|
+
output_tokens: z16.number().int().min(0).optional(),
|
|
2998
|
+
cache_read_tokens: z16.number().int().min(0).optional(),
|
|
2999
|
+
cache_write_tokens: z16.number().int().min(0).optional()
|
|
2909
3000
|
};
|
|
2910
3001
|
var envelopeShape = {
|
|
2911
3002
|
// Not `.min(1)`: see `cursorSessionId`. A payload naming neither
|
|
@@ -2913,136 +3004,136 @@ var envelopeShape = {
|
|
|
2913
3004
|
// `recognizeCursorPayload`'s post-parse check — but rejecting it here would
|
|
2914
3005
|
// fail the whole discriminated union on a field the adapter can source from
|
|
2915
3006
|
// either name.
|
|
2916
|
-
conversation_id:
|
|
2917
|
-
generation_id:
|
|
2918
|
-
session_id:
|
|
2919
|
-
model:
|
|
2920
|
-
model_id:
|
|
2921
|
-
model_params:
|
|
2922
|
-
cursor_version:
|
|
2923
|
-
workspace_roots:
|
|
2924
|
-
cwd:
|
|
3007
|
+
conversation_id: z16.string().optional(),
|
|
3008
|
+
generation_id: z16.string().optional(),
|
|
3009
|
+
session_id: z16.string().optional(),
|
|
3010
|
+
model: z16.string().optional(),
|
|
3011
|
+
model_id: z16.string().optional(),
|
|
3012
|
+
model_params: z16.array(modelParamSchema).max(64).optional(),
|
|
3013
|
+
cursor_version: z16.string().optional(),
|
|
3014
|
+
workspace_roots: z16.array(z16.string()).max(64).optional(),
|
|
3015
|
+
cwd: z16.string().optional(),
|
|
2925
3016
|
/** Never propagated. */
|
|
2926
|
-
user_email:
|
|
3017
|
+
user_email: z16.string().nullish(),
|
|
2927
3018
|
/** Never propagated. */
|
|
2928
|
-
transcript_path:
|
|
3019
|
+
transcript_path: z16.string().nullish()
|
|
2929
3020
|
};
|
|
2930
|
-
var event2 = (name, shape) =>
|
|
3021
|
+
var event2 = (name, shape) => z16.object({ ...envelopeShape, hook_event_name: z16.literal(name), ...shape });
|
|
2931
3022
|
var sessionStartPayloadSchema2 = event2("sessionStart", {
|
|
2932
|
-
is_background_agent:
|
|
2933
|
-
composer_mode:
|
|
3023
|
+
is_background_agent: z16.boolean().optional(),
|
|
3024
|
+
composer_mode: z16.string().optional()
|
|
2934
3025
|
});
|
|
2935
3026
|
var sessionEndPayloadSchema2 = event2("sessionEnd", {
|
|
2936
|
-
reason:
|
|
2937
|
-
duration_ms:
|
|
2938
|
-
is_background_agent:
|
|
2939
|
-
final_status:
|
|
2940
|
-
error_message:
|
|
3027
|
+
reason: z16.string().optional(),
|
|
3028
|
+
duration_ms: z16.number().min(0).optional(),
|
|
3029
|
+
is_background_agent: z16.boolean().optional(),
|
|
3030
|
+
final_status: z16.string().optional(),
|
|
3031
|
+
error_message: z16.string().optional()
|
|
2941
3032
|
});
|
|
2942
3033
|
var beforeSubmitPromptPayloadSchema = event2("beforeSubmitPrompt", {
|
|
2943
|
-
prompt:
|
|
2944
|
-
attachments:
|
|
2945
|
-
composer_mode:
|
|
3034
|
+
prompt: z16.string().optional(),
|
|
3035
|
+
attachments: z16.array(attachmentSchema).max(256).optional(),
|
|
3036
|
+
composer_mode: z16.string().optional()
|
|
2946
3037
|
});
|
|
2947
3038
|
var afterAgentResponsePayloadSchema = event2("afterAgentResponse", {
|
|
2948
|
-
text:
|
|
3039
|
+
text: z16.string().optional(),
|
|
2949
3040
|
...usageFields
|
|
2950
3041
|
});
|
|
2951
3042
|
var afterAgentThoughtPayloadSchema = event2("afterAgentThought", {
|
|
2952
|
-
text:
|
|
2953
|
-
duration_ms:
|
|
3043
|
+
text: z16.string().optional(),
|
|
3044
|
+
duration_ms: z16.number().min(0).optional()
|
|
2954
3045
|
});
|
|
2955
3046
|
var preToolUsePayloadSchema2 = event2("preToolUse", {
|
|
2956
|
-
tool_name:
|
|
2957
|
-
tool_input:
|
|
2958
|
-
tool_use_id:
|
|
2959
|
-
agent_message:
|
|
3047
|
+
tool_name: z16.string().min(1),
|
|
3048
|
+
tool_input: z16.unknown().optional(),
|
|
3049
|
+
tool_use_id: z16.string().optional(),
|
|
3050
|
+
agent_message: z16.string().optional()
|
|
2960
3051
|
});
|
|
2961
3052
|
var postToolUsePayloadSchema2 = event2("postToolUse", {
|
|
2962
|
-
tool_name:
|
|
2963
|
-
tool_input:
|
|
2964
|
-
tool_output:
|
|
2965
|
-
tool_use_id:
|
|
2966
|
-
duration:
|
|
3053
|
+
tool_name: z16.string().min(1),
|
|
3054
|
+
tool_input: z16.unknown().optional(),
|
|
3055
|
+
tool_output: z16.unknown().optional(),
|
|
3056
|
+
tool_use_id: z16.string().optional(),
|
|
3057
|
+
duration: z16.number().min(0).optional()
|
|
2967
3058
|
});
|
|
2968
3059
|
var postToolUseFailurePayloadSchema2 = event2("postToolUseFailure", {
|
|
2969
|
-
tool_name:
|
|
2970
|
-
tool_input:
|
|
2971
|
-
tool_use_id:
|
|
2972
|
-
error_message:
|
|
2973
|
-
failure_type:
|
|
2974
|
-
duration:
|
|
2975
|
-
is_interrupt:
|
|
3060
|
+
tool_name: z16.string().min(1),
|
|
3061
|
+
tool_input: z16.unknown().optional(),
|
|
3062
|
+
tool_use_id: z16.string().optional(),
|
|
3063
|
+
error_message: z16.string().optional(),
|
|
3064
|
+
failure_type: z16.string().optional(),
|
|
3065
|
+
duration: z16.number().min(0).optional(),
|
|
3066
|
+
is_interrupt: z16.boolean().optional()
|
|
2976
3067
|
});
|
|
2977
3068
|
var beforeShellExecutionPayloadSchema = event2("beforeShellExecution", {
|
|
2978
|
-
command:
|
|
2979
|
-
sandbox:
|
|
3069
|
+
command: z16.string(),
|
|
3070
|
+
sandbox: z16.boolean().optional()
|
|
2980
3071
|
});
|
|
2981
3072
|
var afterShellExecutionPayloadSchema = event2("afterShellExecution", {
|
|
2982
|
-
command:
|
|
2983
|
-
output:
|
|
2984
|
-
duration:
|
|
2985
|
-
sandbox:
|
|
3073
|
+
command: z16.string(),
|
|
3074
|
+
output: z16.string().optional(),
|
|
3075
|
+
duration: z16.number().min(0).optional(),
|
|
3076
|
+
sandbox: z16.boolean().optional()
|
|
2986
3077
|
});
|
|
2987
3078
|
var beforeMcpExecutionPayloadSchema = event2("beforeMCPExecution", {
|
|
2988
|
-
tool_name:
|
|
2989
|
-
tool_input:
|
|
2990
|
-
url:
|
|
2991
|
-
command:
|
|
3079
|
+
tool_name: z16.string().min(1),
|
|
3080
|
+
tool_input: z16.unknown().optional(),
|
|
3081
|
+
url: z16.string().optional(),
|
|
3082
|
+
command: z16.string().optional()
|
|
2992
3083
|
});
|
|
2993
3084
|
var afterMcpExecutionPayloadSchema = event2("afterMCPExecution", {
|
|
2994
|
-
tool_name:
|
|
2995
|
-
tool_input:
|
|
2996
|
-
result_json:
|
|
2997
|
-
duration:
|
|
3085
|
+
tool_name: z16.string().min(1),
|
|
3086
|
+
tool_input: z16.unknown().optional(),
|
|
3087
|
+
result_json: z16.string().optional(),
|
|
3088
|
+
duration: z16.number().min(0).optional()
|
|
2998
3089
|
});
|
|
2999
3090
|
var beforeReadFilePayloadSchema = event2("beforeReadFile", {
|
|
3000
|
-
file_path:
|
|
3001
|
-
content:
|
|
3002
|
-
attachments:
|
|
3091
|
+
file_path: z16.string(),
|
|
3092
|
+
content: z16.string().optional(),
|
|
3093
|
+
attachments: z16.array(attachmentSchema).max(256).optional()
|
|
3003
3094
|
});
|
|
3004
3095
|
var afterFileEditPayloadSchema = event2("afterFileEdit", {
|
|
3005
|
-
file_path:
|
|
3006
|
-
edits:
|
|
3096
|
+
file_path: z16.string(),
|
|
3097
|
+
edits: z16.array(fileEditSchema).max(1024).optional()
|
|
3007
3098
|
});
|
|
3008
3099
|
var subagentStartPayloadSchema2 = event2("subagentStart", {
|
|
3009
|
-
subagent_id:
|
|
3010
|
-
subagent_type:
|
|
3011
|
-
task:
|
|
3012
|
-
parent_conversation_id:
|
|
3013
|
-
tool_call_id:
|
|
3014
|
-
subagent_model:
|
|
3015
|
-
is_parallel_worker:
|
|
3016
|
-
git_branch:
|
|
3100
|
+
subagent_id: z16.string().optional(),
|
|
3101
|
+
subagent_type: z16.string().optional(),
|
|
3102
|
+
task: z16.string().optional(),
|
|
3103
|
+
parent_conversation_id: z16.string().optional(),
|
|
3104
|
+
tool_call_id: z16.string().optional(),
|
|
3105
|
+
subagent_model: z16.string().optional(),
|
|
3106
|
+
is_parallel_worker: z16.boolean().optional(),
|
|
3107
|
+
git_branch: z16.string().optional()
|
|
3017
3108
|
});
|
|
3018
3109
|
var subagentStopPayloadSchema2 = event2("subagentStop", {
|
|
3019
|
-
subagent_type:
|
|
3020
|
-
status:
|
|
3021
|
-
task:
|
|
3022
|
-
description:
|
|
3023
|
-
summary:
|
|
3024
|
-
duration_ms:
|
|
3025
|
-
message_count:
|
|
3026
|
-
tool_call_count:
|
|
3027
|
-
loop_count:
|
|
3028
|
-
modified_files:
|
|
3029
|
-
agent_transcript_path:
|
|
3110
|
+
subagent_type: z16.string().optional(),
|
|
3111
|
+
status: z16.string().optional(),
|
|
3112
|
+
task: z16.string().optional(),
|
|
3113
|
+
description: z16.string().optional(),
|
|
3114
|
+
summary: z16.string().optional(),
|
|
3115
|
+
duration_ms: z16.number().min(0).optional(),
|
|
3116
|
+
message_count: z16.number().int().min(0).optional(),
|
|
3117
|
+
tool_call_count: z16.number().int().min(0).optional(),
|
|
3118
|
+
loop_count: z16.number().int().min(0).optional(),
|
|
3119
|
+
modified_files: z16.array(z16.string()).max(1024).optional(),
|
|
3120
|
+
agent_transcript_path: z16.string().nullish()
|
|
3030
3121
|
});
|
|
3031
3122
|
var preCompactPayloadSchema2 = event2("preCompact", {
|
|
3032
|
-
trigger:
|
|
3033
|
-
context_usage_percent:
|
|
3034
|
-
context_tokens:
|
|
3035
|
-
context_window_size:
|
|
3036
|
-
message_count:
|
|
3037
|
-
messages_to_compact:
|
|
3038
|
-
is_first_compaction:
|
|
3123
|
+
trigger: z16.string().optional(),
|
|
3124
|
+
context_usage_percent: z16.number().optional(),
|
|
3125
|
+
context_tokens: z16.number().int().min(0).optional(),
|
|
3126
|
+
context_window_size: z16.number().int().min(0).optional(),
|
|
3127
|
+
message_count: z16.number().int().min(0).optional(),
|
|
3128
|
+
messages_to_compact: z16.number().int().min(0).optional(),
|
|
3129
|
+
is_first_compaction: z16.boolean().optional()
|
|
3039
3130
|
});
|
|
3040
3131
|
var stopPayloadSchema2 = event2("stop", {
|
|
3041
|
-
status:
|
|
3042
|
-
loop_count:
|
|
3132
|
+
status: z16.string().optional(),
|
|
3133
|
+
loop_count: z16.number().int().min(0).optional(),
|
|
3043
3134
|
...usageFields
|
|
3044
3135
|
});
|
|
3045
|
-
var cursorPayloadSchema =
|
|
3136
|
+
var cursorPayloadSchema = z16.discriminatedUnion("hook_event_name", [
|
|
3046
3137
|
sessionStartPayloadSchema2,
|
|
3047
3138
|
sessionEndPayloadSchema2,
|
|
3048
3139
|
beforeSubmitPromptPayloadSchema,
|
|
@@ -3179,6 +3270,33 @@ var cursorDeliveryIdentity = (input) => {
|
|
|
3179
3270
|
};
|
|
3180
3271
|
};
|
|
3181
3272
|
|
|
3273
|
+
// src/providers/cursor/target.ts
|
|
3274
|
+
var singleWorkspaceRoot = (payload) => {
|
|
3275
|
+
const roots = (payload.workspace_roots ?? []).filter((root) => root.length > 0);
|
|
3276
|
+
return roots.length === 1 ? roots[0] : void 0;
|
|
3277
|
+
};
|
|
3278
|
+
var sessionHint = (root) => root === void 0 ? void 0 : { source: "session-cwd", paths: [root] };
|
|
3279
|
+
var cursorTargetHint = (payload) => {
|
|
3280
|
+
const root = singleWorkspaceRoot(payload);
|
|
3281
|
+
const base = root === void 0 ? {} : { baseDirectory: root };
|
|
3282
|
+
switch (payload.hook_event_name) {
|
|
3283
|
+
case "afterFileEdit":
|
|
3284
|
+
case "beforeReadFile":
|
|
3285
|
+
return payload.file_path.length === 0 ? sessionHint(root) : { source: "tool-path", paths: [payload.file_path], ...base };
|
|
3286
|
+
case "beforeShellExecution":
|
|
3287
|
+
case "afterShellExecution":
|
|
3288
|
+
return payload.cwd !== void 0 && payload.cwd.length > 0 ? { source: "shell-cwd", paths: [payload.cwd], ...base } : sessionHint(root);
|
|
3289
|
+
case "preToolUse":
|
|
3290
|
+
case "postToolUse":
|
|
3291
|
+
case "postToolUseFailure":
|
|
3292
|
+
case "beforeMCPExecution":
|
|
3293
|
+
case "afterMCPExecution":
|
|
3294
|
+
return sessionHint(root);
|
|
3295
|
+
default:
|
|
3296
|
+
return void 0;
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3182
3300
|
// src/providers/cursor/usage.ts
|
|
3183
3301
|
var normalizeCursorUsage = (raw) => {
|
|
3184
3302
|
const inputTokens = raw.input_tokens;
|
|
@@ -3434,12 +3552,6 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3434
3552
|
reason: "afterAgentThought is a reasoning notification, not a generation lifecycle event; no canonical event type represents it and thought text is never exported"
|
|
3435
3553
|
};
|
|
3436
3554
|
}
|
|
3437
|
-
if (payload.hook_event_name === "beforeReadFile") {
|
|
3438
|
-
return {
|
|
3439
|
-
status: "ignored",
|
|
3440
|
-
reason: "beforeReadFile has no completion callback in the cursor hook protocol, so emitting tool.start here would leave a tool lifecycle that never closes"
|
|
3441
|
-
};
|
|
3442
|
-
}
|
|
3443
3555
|
if (payload.hook_event_name === "subagentStart" || payload.hook_event_name === "subagentStop") {
|
|
3444
3556
|
return {
|
|
3445
3557
|
status: "ignored",
|
|
@@ -3454,6 +3566,8 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3454
3566
|
const warnings = [];
|
|
3455
3567
|
const sessionId = input.identity.sessionId;
|
|
3456
3568
|
const model = toModelDescriptor(payload);
|
|
3569
|
+
const targetHint = cursorTargetHint(payload);
|
|
3570
|
+
const targetHintField = targetHint === void 0 ? {} : { targetHint };
|
|
3457
3571
|
switch (payload.hook_event_name) {
|
|
3458
3572
|
case "sessionStart":
|
|
3459
3573
|
factory.build({
|
|
@@ -3506,6 +3620,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3506
3620
|
case "preToolUse":
|
|
3507
3621
|
factory.build({
|
|
3508
3622
|
type: "tool.start",
|
|
3623
|
+
...targetHintField,
|
|
3509
3624
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
3510
3625
|
"tool",
|
|
3511
3626
|
payload.generation_id ?? "",
|
|
@@ -3529,6 +3644,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3529
3644
|
case "postToolUse":
|
|
3530
3645
|
factory.build({
|
|
3531
3646
|
type: "tool.end",
|
|
3647
|
+
...targetHintField,
|
|
3532
3648
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
3533
3649
|
"tool",
|
|
3534
3650
|
payload.generation_id ?? "",
|
|
@@ -3551,6 +3667,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3551
3667
|
case "postToolUseFailure":
|
|
3552
3668
|
factory.build({
|
|
3553
3669
|
type: "tool.end",
|
|
3670
|
+
...targetHintField,
|
|
3554
3671
|
toolCallId: payload.tool_use_id ?? derivedToolCallId(context, sessionId, [
|
|
3555
3672
|
"tool",
|
|
3556
3673
|
payload.generation_id ?? "",
|
|
@@ -3571,6 +3688,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3571
3688
|
case "beforeShellExecution":
|
|
3572
3689
|
factory.build({
|
|
3573
3690
|
type: "tool.start",
|
|
3691
|
+
...targetHintField,
|
|
3574
3692
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
3575
3693
|
"shell",
|
|
3576
3694
|
payload.generation_id ?? "",
|
|
@@ -3590,6 +3708,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3590
3708
|
case "afterShellExecution":
|
|
3591
3709
|
factory.build({
|
|
3592
3710
|
type: "tool.end",
|
|
3711
|
+
...targetHintField,
|
|
3593
3712
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
3594
3713
|
"shell",
|
|
3595
3714
|
payload.generation_id ?? "",
|
|
@@ -3614,6 +3733,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3614
3733
|
case "beforeMCPExecution":
|
|
3615
3734
|
factory.build({
|
|
3616
3735
|
type: "tool.start",
|
|
3736
|
+
...targetHintField,
|
|
3617
3737
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
3618
3738
|
"mcp",
|
|
3619
3739
|
payload.generation_id ?? "",
|
|
@@ -3634,6 +3754,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3634
3754
|
case "afterMCPExecution":
|
|
3635
3755
|
factory.build({
|
|
3636
3756
|
type: "tool.end",
|
|
3757
|
+
...targetHintField,
|
|
3637
3758
|
toolCallId: derivedToolCallId(context, sessionId, [
|
|
3638
3759
|
"mcp",
|
|
3639
3760
|
payload.generation_id ?? "",
|
|
@@ -3661,6 +3782,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3661
3782
|
]);
|
|
3662
3783
|
factory.build({
|
|
3663
3784
|
type: "tool.start",
|
|
3785
|
+
...targetHintField,
|
|
3664
3786
|
toolCallId,
|
|
3665
3787
|
toolName: "edit_file",
|
|
3666
3788
|
toolKind: "write",
|
|
@@ -3673,6 +3795,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3673
3795
|
});
|
|
3674
3796
|
factory.build({
|
|
3675
3797
|
type: "tool.end",
|
|
3798
|
+
...targetHintField,
|
|
3676
3799
|
toolCallId,
|
|
3677
3800
|
toolName: "edit_file",
|
|
3678
3801
|
outcome: "ok",
|
|
@@ -3682,6 +3805,34 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3682
3805
|
});
|
|
3683
3806
|
break;
|
|
3684
3807
|
}
|
|
3808
|
+
case "beforeReadFile": {
|
|
3809
|
+
const toolCallId = derivedToolCallId(context, sessionId, [
|
|
3810
|
+
"read-file",
|
|
3811
|
+
payload.generation_id ?? "",
|
|
3812
|
+
payload.file_path
|
|
3813
|
+
]);
|
|
3814
|
+
factory.build({
|
|
3815
|
+
type: "tool.start",
|
|
3816
|
+
...targetHintField,
|
|
3817
|
+
toolCallId,
|
|
3818
|
+
toolName: "read_file",
|
|
3819
|
+
toolKind: "read",
|
|
3820
|
+
...payload.generation_id === void 0 || payload.generation_id.length === 0 ? {} : { generationId: payload.generation_id },
|
|
3821
|
+
input: context.privacy.describeContent({
|
|
3822
|
+
kind: "tool-input",
|
|
3823
|
+
text: payload.file_path,
|
|
3824
|
+
label: "read_file"
|
|
3825
|
+
})
|
|
3826
|
+
});
|
|
3827
|
+
factory.build({
|
|
3828
|
+
type: "tool.end",
|
|
3829
|
+
...targetHintField,
|
|
3830
|
+
toolCallId,
|
|
3831
|
+
toolName: "read_file",
|
|
3832
|
+
outcome: "unknown"
|
|
3833
|
+
});
|
|
3834
|
+
break;
|
|
3835
|
+
}
|
|
3685
3836
|
case "preCompact":
|
|
3686
3837
|
factory.build({
|
|
3687
3838
|
type: "compaction.performed",
|
|
@@ -3719,10 +3870,12 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3719
3870
|
break;
|
|
3720
3871
|
}
|
|
3721
3872
|
}
|
|
3873
|
+
const targetHints = factory.targetHints();
|
|
3722
3874
|
return {
|
|
3723
3875
|
status: "parsed",
|
|
3724
3876
|
events: factory.events(),
|
|
3725
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
3877
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
3878
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
3726
3879
|
};
|
|
3727
3880
|
};
|
|
3728
3881
|
const hookResponse2 = (input) => {
|
|
@@ -3753,105 +3906,105 @@ var createCursorAdapter = (options = {}) => {
|
|
|
3753
3906
|
};
|
|
3754
3907
|
|
|
3755
3908
|
// src/providers/codex/payload.ts
|
|
3756
|
-
import { z as
|
|
3757
|
-
var permissionModeSchema =
|
|
3909
|
+
import { z as z17 } from "zod";
|
|
3910
|
+
var permissionModeSchema = z17.enum([
|
|
3758
3911
|
"default",
|
|
3759
3912
|
"acceptEdits",
|
|
3760
3913
|
"plan",
|
|
3761
3914
|
"dontAsk",
|
|
3762
3915
|
"bypassPermissions"
|
|
3763
3916
|
]);
|
|
3764
|
-
var codexUsageSchema =
|
|
3765
|
-
input_tokens:
|
|
3766
|
-
cached_input_tokens:
|
|
3767
|
-
output_tokens:
|
|
3768
|
-
reasoning_output_tokens:
|
|
3769
|
-
total_tokens:
|
|
3917
|
+
var codexUsageSchema = z17.object({
|
|
3918
|
+
input_tokens: z17.number().int().min(0).optional(),
|
|
3919
|
+
cached_input_tokens: z17.number().int().min(0).optional(),
|
|
3920
|
+
output_tokens: z17.number().int().min(0).optional(),
|
|
3921
|
+
reasoning_output_tokens: z17.number().int().min(0).optional(),
|
|
3922
|
+
total_tokens: z17.number().int().min(0).optional()
|
|
3770
3923
|
});
|
|
3771
3924
|
var baseFields = {
|
|
3772
|
-
session_id:
|
|
3773
|
-
cwd:
|
|
3774
|
-
model:
|
|
3925
|
+
session_id: z17.string().min(1).max(256),
|
|
3926
|
+
cwd: z17.string().min(1).max(4096).optional(),
|
|
3927
|
+
model: z17.string().min(1).max(256).optional(),
|
|
3775
3928
|
permission_mode: permissionModeSchema.optional(),
|
|
3776
|
-
transcript_path:
|
|
3777
|
-
codex_version:
|
|
3929
|
+
transcript_path: z17.string().min(1).max(4096).optional(),
|
|
3930
|
+
codex_version: z17.string().min(1).max(64).optional(),
|
|
3778
3931
|
/** Not part of the documented protocol; lets tests and replay stay deterministic. */
|
|
3779
|
-
occurred_at:
|
|
3932
|
+
occurred_at: z17.number().int().min(0).optional()
|
|
3780
3933
|
};
|
|
3781
|
-
var codexSessionStartPayloadSchema =
|
|
3934
|
+
var codexSessionStartPayloadSchema = z17.object({
|
|
3782
3935
|
...baseFields,
|
|
3783
|
-
hook_event_name:
|
|
3784
|
-
source:
|
|
3936
|
+
hook_event_name: z17.literal("SessionStart"),
|
|
3937
|
+
source: z17.enum(["startup", "resume", "clear", "compact"]).optional()
|
|
3785
3938
|
});
|
|
3786
|
-
var codexUserPromptSubmitPayloadSchema =
|
|
3939
|
+
var codexUserPromptSubmitPayloadSchema = z17.object({
|
|
3787
3940
|
...baseFields,
|
|
3788
|
-
hook_event_name:
|
|
3789
|
-
turn_id:
|
|
3790
|
-
prompt:
|
|
3941
|
+
hook_event_name: z17.literal("UserPromptSubmit"),
|
|
3942
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3943
|
+
prompt: z17.string().max(1e6).optional()
|
|
3791
3944
|
});
|
|
3792
|
-
var codexPreToolUsePayloadSchema =
|
|
3945
|
+
var codexPreToolUsePayloadSchema = z17.object({
|
|
3793
3946
|
...baseFields,
|
|
3794
|
-
hook_event_name:
|
|
3795
|
-
turn_id:
|
|
3796
|
-
tool_name:
|
|
3797
|
-
tool_call_id:
|
|
3798
|
-
tool_input:
|
|
3947
|
+
hook_event_name: z17.literal("PreToolUse"),
|
|
3948
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3949
|
+
tool_name: z17.string().min(1).max(256),
|
|
3950
|
+
tool_call_id: z17.string().min(1).max(256).optional(),
|
|
3951
|
+
tool_input: z17.unknown().optional()
|
|
3799
3952
|
});
|
|
3800
|
-
var codexPermissionRequestPayloadSchema =
|
|
3953
|
+
var codexPermissionRequestPayloadSchema = z17.object({
|
|
3801
3954
|
...baseFields,
|
|
3802
|
-
hook_event_name:
|
|
3803
|
-
turn_id:
|
|
3804
|
-
tool_name:
|
|
3805
|
-
tool_call_id:
|
|
3806
|
-
tool_input:
|
|
3955
|
+
hook_event_name: z17.literal("PermissionRequest"),
|
|
3956
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3957
|
+
tool_name: z17.string().min(1).max(256).optional(),
|
|
3958
|
+
tool_call_id: z17.string().min(1).max(256).optional(),
|
|
3959
|
+
tool_input: z17.unknown().optional()
|
|
3807
3960
|
});
|
|
3808
|
-
var codexPostToolUsePayloadSchema =
|
|
3961
|
+
var codexPostToolUsePayloadSchema = z17.object({
|
|
3809
3962
|
...baseFields,
|
|
3810
|
-
hook_event_name:
|
|
3811
|
-
turn_id:
|
|
3812
|
-
tool_name:
|
|
3813
|
-
tool_call_id:
|
|
3814
|
-
tool_input:
|
|
3815
|
-
tool_response:
|
|
3816
|
-
permission_decision:
|
|
3817
|
-
duration_ms:
|
|
3963
|
+
hook_event_name: z17.literal("PostToolUse"),
|
|
3964
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3965
|
+
tool_name: z17.string().min(1).max(256),
|
|
3966
|
+
tool_call_id: z17.string().min(1).max(256).optional(),
|
|
3967
|
+
tool_input: z17.unknown().optional(),
|
|
3968
|
+
tool_response: z17.unknown().optional(),
|
|
3969
|
+
permission_decision: z17.enum(["allowed", "denied", "deferred"]).optional(),
|
|
3970
|
+
duration_ms: z17.number().min(0).optional()
|
|
3818
3971
|
});
|
|
3819
|
-
var codexPreCompactPayloadSchema =
|
|
3972
|
+
var codexPreCompactPayloadSchema = z17.object({
|
|
3820
3973
|
...baseFields,
|
|
3821
|
-
hook_event_name:
|
|
3822
|
-
trigger:
|
|
3823
|
-
context_tokens_before:
|
|
3974
|
+
hook_event_name: z17.literal("PreCompact"),
|
|
3975
|
+
trigger: z17.enum(["auto", "manual"]).optional(),
|
|
3976
|
+
context_tokens_before: z17.number().int().min(0).optional()
|
|
3824
3977
|
});
|
|
3825
|
-
var codexPostCompactPayloadSchema =
|
|
3978
|
+
var codexPostCompactPayloadSchema = z17.object({
|
|
3826
3979
|
...baseFields,
|
|
3827
|
-
hook_event_name:
|
|
3828
|
-
trigger:
|
|
3829
|
-
context_tokens_after:
|
|
3830
|
-
dropped_message_count:
|
|
3980
|
+
hook_event_name: z17.literal("PostCompact"),
|
|
3981
|
+
trigger: z17.enum(["auto", "manual"]).optional(),
|
|
3982
|
+
context_tokens_after: z17.number().int().min(0).optional(),
|
|
3983
|
+
dropped_message_count: z17.number().int().min(0).optional(),
|
|
3831
3984
|
usage: codexUsageSchema.optional()
|
|
3832
3985
|
});
|
|
3833
|
-
var codexSubagentStartPayloadSchema =
|
|
3986
|
+
var codexSubagentStartPayloadSchema = z17.object({
|
|
3834
3987
|
...baseFields,
|
|
3835
|
-
hook_event_name:
|
|
3836
|
-
turn_id:
|
|
3837
|
-
subagent_id:
|
|
3838
|
-
subagent_type:
|
|
3988
|
+
hook_event_name: z17.literal("SubagentStart"),
|
|
3989
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3990
|
+
subagent_id: z17.string().min(1).max(256),
|
|
3991
|
+
subagent_type: z17.string().min(1).max(256).optional()
|
|
3839
3992
|
});
|
|
3840
|
-
var codexSubagentStopPayloadSchema =
|
|
3993
|
+
var codexSubagentStopPayloadSchema = z17.object({
|
|
3841
3994
|
...baseFields,
|
|
3842
|
-
hook_event_name:
|
|
3843
|
-
turn_id:
|
|
3844
|
-
subagent_id:
|
|
3845
|
-
status:
|
|
3995
|
+
hook_event_name: z17.literal("SubagentStop"),
|
|
3996
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
3997
|
+
subagent_id: z17.string().min(1).max(256),
|
|
3998
|
+
status: z17.enum(["completed", "failed", "cancelled"]).optional(),
|
|
3846
3999
|
usage: codexUsageSchema.optional()
|
|
3847
4000
|
});
|
|
3848
|
-
var codexStopPayloadSchema =
|
|
4001
|
+
var codexStopPayloadSchema = z17.object({
|
|
3849
4002
|
...baseFields,
|
|
3850
|
-
hook_event_name:
|
|
3851
|
-
turn_id:
|
|
3852
|
-
stop_reason:
|
|
4003
|
+
hook_event_name: z17.literal("Stop"),
|
|
4004
|
+
turn_id: z17.string().min(1).max(256).optional(),
|
|
4005
|
+
stop_reason: z17.string().min(1).max(256).optional(),
|
|
3853
4006
|
usage: codexUsageSchema.optional(),
|
|
3854
|
-
duration_ms:
|
|
4007
|
+
duration_ms: z17.number().min(0).optional()
|
|
3855
4008
|
});
|
|
3856
4009
|
var CODEX_HOOK_EVENT_NAMES = [
|
|
3857
4010
|
"SessionStart",
|
|
@@ -3865,7 +4018,7 @@ var CODEX_HOOK_EVENT_NAMES = [
|
|
|
3865
4018
|
"SubagentStop",
|
|
3866
4019
|
"Stop"
|
|
3867
4020
|
];
|
|
3868
|
-
var codexHookPayloadSchema =
|
|
4021
|
+
var codexHookPayloadSchema = z17.discriminatedUnion("hook_event_name", [
|
|
3869
4022
|
codexSessionStartPayloadSchema,
|
|
3870
4023
|
codexUserPromptSubmitPayloadSchema,
|
|
3871
4024
|
codexPreToolUsePayloadSchema,
|
|
@@ -3877,9 +4030,9 @@ var codexHookPayloadSchema = z16.discriminatedUnion("hook_event_name", [
|
|
|
3877
4030
|
codexSubagentStopPayloadSchema,
|
|
3878
4031
|
codexStopPayloadSchema
|
|
3879
4032
|
]);
|
|
3880
|
-
var codexHookEnvelopeSchema =
|
|
3881
|
-
session_id:
|
|
3882
|
-
hook_event_name:
|
|
4033
|
+
var codexHookEnvelopeSchema = z17.object({
|
|
4034
|
+
session_id: z17.string().min(1),
|
|
4035
|
+
hook_event_name: z17.enum(CODEX_HOOK_EVENT_NAMES)
|
|
3883
4036
|
});
|
|
3884
4037
|
|
|
3885
4038
|
// src/providers/codex/delivery.ts
|
|
@@ -3940,6 +4093,61 @@ var codexDeliveryIdentity = (input) => {
|
|
|
3940
4093
|
};
|
|
3941
4094
|
};
|
|
3942
4095
|
|
|
4096
|
+
// src/providers/codex/target.ts
|
|
4097
|
+
var PATCH_HEADER = /^\*\*\* (?:Add File|Update File|Delete File|Move to): (.+)$/;
|
|
4098
|
+
var asRecord5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
4099
|
+
var nonEmptyString2 = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
4100
|
+
var commandText = (input) => {
|
|
4101
|
+
const command = input?.command ?? input?.cmd;
|
|
4102
|
+
if (typeof command === "string") {
|
|
4103
|
+
return command;
|
|
4104
|
+
}
|
|
4105
|
+
if (Array.isArray(command) && command.every((part) => typeof part === "string")) {
|
|
4106
|
+
return command.join(" ");
|
|
4107
|
+
}
|
|
4108
|
+
return void 0;
|
|
4109
|
+
};
|
|
4110
|
+
var patchHeaderPaths = (patch) => {
|
|
4111
|
+
const paths = /* @__PURE__ */ new Set();
|
|
4112
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
4113
|
+
const match = PATCH_HEADER.exec(line.trimEnd());
|
|
4114
|
+
const named = match?.[1]?.trim();
|
|
4115
|
+
if (named !== void 0 && named.length > 0) {
|
|
4116
|
+
paths.add(named);
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
return paths.size === 0 || paths.size > MAX_TARGET_HINT_PATHS ? void 0 : [...paths];
|
|
4120
|
+
};
|
|
4121
|
+
var patchTextOf = (toolName, input) => {
|
|
4122
|
+
if (typeof input === "string") {
|
|
4123
|
+
return /^apply[_-]?patch$/i.test(toolName) ? input : void 0;
|
|
4124
|
+
}
|
|
4125
|
+
const record = asRecord5(input);
|
|
4126
|
+
if (/^apply[_-]?patch$/i.test(toolName)) {
|
|
4127
|
+
return nonEmptyString2(record?.patch) ?? nonEmptyString2(record?.input) ?? commandText(record);
|
|
4128
|
+
}
|
|
4129
|
+
const command = commandText(record);
|
|
4130
|
+
return command !== void 0 && /^\s*apply_patch\b/.test(command) ? command : void 0;
|
|
4131
|
+
};
|
|
4132
|
+
var codexTargetHint = (toolName, toolInput, cwd) => {
|
|
4133
|
+
const record = asRecord5(toolInput);
|
|
4134
|
+
const workdir = nonEmptyString2(record?.workdir);
|
|
4135
|
+
const base = workdir ?? cwd;
|
|
4136
|
+
const patch = patchTextOf(toolName, toolInput);
|
|
4137
|
+
if (patch !== void 0) {
|
|
4138
|
+
const paths = patchHeaderPaths(patch);
|
|
4139
|
+
return paths === void 0 ? void 0 : { source: "tool-path", paths, ...base === void 0 ? {} : { baseDirectory: base } };
|
|
4140
|
+
}
|
|
4141
|
+
if (workdir !== void 0) {
|
|
4142
|
+
return {
|
|
4143
|
+
source: "shell-cwd",
|
|
4144
|
+
paths: [workdir],
|
|
4145
|
+
...cwd === void 0 ? {} : { baseDirectory: cwd }
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4148
|
+
return cwd === void 0 ? void 0 : { source: "session-cwd", paths: [cwd] };
|
|
4149
|
+
};
|
|
4150
|
+
|
|
3943
4151
|
// src/providers/codex/tool-kind.ts
|
|
3944
4152
|
var PATTERNS = [
|
|
3945
4153
|
[/^(apply[_-]?patch|patch)$/i, "write"],
|
|
@@ -4004,7 +4212,7 @@ var CODEX_CAPABILITIES = Object.freeze({
|
|
|
4004
4212
|
// compaction callbacks do not. See `./delivery.ts` for which and why.
|
|
4005
4213
|
deliveryIdentifier: "partial"
|
|
4006
4214
|
});
|
|
4007
|
-
var
|
|
4215
|
+
var asRecord6 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
4008
4216
|
var hasExactMarker = (payload) => {
|
|
4009
4217
|
if (payload.codex_version !== void 0) {
|
|
4010
4218
|
return true;
|
|
@@ -4097,7 +4305,7 @@ var outcomeFromToolResponse = (toolResponse) => {
|
|
|
4097
4305
|
if (toolResponse === void 0) {
|
|
4098
4306
|
return "unknown";
|
|
4099
4307
|
}
|
|
4100
|
-
const record =
|
|
4308
|
+
const record = asRecord6(toolResponse);
|
|
4101
4309
|
if (record === void 0) {
|
|
4102
4310
|
return "ok";
|
|
4103
4311
|
}
|
|
@@ -4169,6 +4377,10 @@ var parse = (input, context) => {
|
|
|
4169
4377
|
context
|
|
4170
4378
|
});
|
|
4171
4379
|
const warnings = [];
|
|
4380
|
+
const targetHintFor = (toolName, toolInput) => {
|
|
4381
|
+
const hint = codexTargetHint(toolName, toolInput, payload.cwd);
|
|
4382
|
+
return hint === void 0 ? {} : { targetHint: hint };
|
|
4383
|
+
};
|
|
4172
4384
|
const buildUsage = (usage) => {
|
|
4173
4385
|
if (usage === void 0) {
|
|
4174
4386
|
return void 0;
|
|
@@ -4213,6 +4425,7 @@ var parse = (input, context) => {
|
|
|
4213
4425
|
toolName: payload.tool_name,
|
|
4214
4426
|
toolKind: classifyCodexToolKind(payload.tool_name),
|
|
4215
4427
|
occurredAt,
|
|
4428
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
4216
4429
|
...payload.tool_input === void 0 ? {} : {
|
|
4217
4430
|
input: context.privacy.describeStructured({
|
|
4218
4431
|
kind: "tool-input",
|
|
@@ -4239,6 +4452,7 @@ var parse = (input, context) => {
|
|
|
4239
4452
|
outcome,
|
|
4240
4453
|
permissionDecision,
|
|
4241
4454
|
occurredAt,
|
|
4455
|
+
...targetHintFor(payload.tool_name, payload.tool_input),
|
|
4242
4456
|
...payload.duration_ms === void 0 ? {} : { durationMillis: payload.duration_ms },
|
|
4243
4457
|
...payload.tool_response === void 0 ? {} : {
|
|
4244
4458
|
output: context.privacy.describeStructured({
|
|
@@ -4321,10 +4535,12 @@ var parse = (input, context) => {
|
|
|
4321
4535
|
break;
|
|
4322
4536
|
}
|
|
4323
4537
|
}
|
|
4538
|
+
const targetHints = factory.targetHints();
|
|
4324
4539
|
return {
|
|
4325
4540
|
status: "parsed",
|
|
4326
4541
|
events: factory.events(),
|
|
4327
|
-
...warnings.length === 0 ? {} : { warnings }
|
|
4542
|
+
...warnings.length === 0 ? {} : { warnings },
|
|
4543
|
+
...targetHints.size === 0 ? {} : { targetHints }
|
|
4328
4544
|
};
|
|
4329
4545
|
};
|
|
4330
4546
|
var hookResponse = () => SILENT_HOOK_RESPONSE;
|
|
@@ -4431,7 +4647,7 @@ var geminiCorrelationSeed = (input) => {
|
|
|
4431
4647
|
};
|
|
4432
4648
|
|
|
4433
4649
|
// src/providers/gemini/schema.ts
|
|
4434
|
-
import { z as
|
|
4650
|
+
import { z as z18 } from "zod";
|
|
4435
4651
|
var GEMINI_HOOK_EVENT_NAMES = [
|
|
4436
4652
|
"SessionStart",
|
|
4437
4653
|
"SessionEnd",
|
|
@@ -4445,113 +4661,113 @@ var GEMINI_HOOK_EVENT_NAMES = [
|
|
|
4445
4661
|
"PreCompress",
|
|
4446
4662
|
"Notification"
|
|
4447
4663
|
];
|
|
4448
|
-
var baseHookInputSchema =
|
|
4449
|
-
session_id:
|
|
4450
|
-
transcript_path:
|
|
4451
|
-
cwd:
|
|
4452
|
-
timestamp:
|
|
4453
|
-
});
|
|
4454
|
-
var llmMessageSchema =
|
|
4455
|
-
role:
|
|
4456
|
-
content:
|
|
4664
|
+
var baseHookInputSchema = z18.object({
|
|
4665
|
+
session_id: z18.string().min(1),
|
|
4666
|
+
transcript_path: z18.string().optional(),
|
|
4667
|
+
cwd: z18.string().optional(),
|
|
4668
|
+
timestamp: z18.string().min(1).optional()
|
|
4669
|
+
});
|
|
4670
|
+
var llmMessageSchema = z18.object({
|
|
4671
|
+
role: z18.enum(["user", "model", "system"]).optional(),
|
|
4672
|
+
content: z18.union([z18.string(), z18.array(z18.unknown())]).optional()
|
|
4457
4673
|
}).loose();
|
|
4458
|
-
var llmRequestConfigSchema =
|
|
4459
|
-
temperature:
|
|
4460
|
-
maxOutputTokens:
|
|
4674
|
+
var llmRequestConfigSchema = z18.object({
|
|
4675
|
+
temperature: z18.number().optional(),
|
|
4676
|
+
maxOutputTokens: z18.number().int().min(0).optional()
|
|
4461
4677
|
}).loose();
|
|
4462
|
-
var geminiLlmRequestSchema =
|
|
4463
|
-
model:
|
|
4464
|
-
messages:
|
|
4678
|
+
var geminiLlmRequestSchema = z18.object({
|
|
4679
|
+
model: z18.string().min(1).optional(),
|
|
4680
|
+
messages: z18.array(llmMessageSchema).optional(),
|
|
4465
4681
|
config: llmRequestConfigSchema.optional(),
|
|
4466
|
-
toolConfig:
|
|
4682
|
+
toolConfig: z18.unknown().optional()
|
|
4467
4683
|
}).loose();
|
|
4468
|
-
var geminiUsageMetadataSchema =
|
|
4469
|
-
promptTokenCount:
|
|
4470
|
-
cachedContentTokenCount:
|
|
4471
|
-
candidatesTokenCount:
|
|
4472
|
-
thoughtsTokenCount:
|
|
4473
|
-
totalTokenCount:
|
|
4684
|
+
var geminiUsageMetadataSchema = z18.object({
|
|
4685
|
+
promptTokenCount: z18.number().int().min(0).optional(),
|
|
4686
|
+
cachedContentTokenCount: z18.number().int().min(0).optional(),
|
|
4687
|
+
candidatesTokenCount: z18.number().int().min(0).optional(),
|
|
4688
|
+
thoughtsTokenCount: z18.number().int().min(0).optional(),
|
|
4689
|
+
totalTokenCount: z18.number().int().min(0).optional()
|
|
4474
4690
|
}).loose();
|
|
4475
|
-
var geminiCandidateSchema =
|
|
4476
|
-
content:
|
|
4477
|
-
role:
|
|
4478
|
-
parts:
|
|
4691
|
+
var geminiCandidateSchema = z18.object({
|
|
4692
|
+
content: z18.object({
|
|
4693
|
+
role: z18.string().optional(),
|
|
4694
|
+
parts: z18.array(z18.unknown()).optional()
|
|
4479
4695
|
}).loose().optional(),
|
|
4480
|
-
finishReason:
|
|
4481
|
-
index:
|
|
4696
|
+
finishReason: z18.string().optional(),
|
|
4697
|
+
index: z18.number().int().min(0).optional()
|
|
4482
4698
|
}).loose();
|
|
4483
|
-
var geminiLlmResponseSchema =
|
|
4699
|
+
var geminiLlmResponseSchema = z18.object({
|
|
4484
4700
|
/** Whole-response text, set by the translator from `getResponseText`. */
|
|
4485
|
-
text:
|
|
4486
|
-
candidates:
|
|
4701
|
+
text: z18.string().optional(),
|
|
4702
|
+
candidates: z18.array(geminiCandidateSchema).optional(),
|
|
4487
4703
|
usageMetadata: geminiUsageMetadataSchema.optional()
|
|
4488
4704
|
}).loose();
|
|
4489
|
-
var geminiMcpContextSchema =
|
|
4490
|
-
server_name:
|
|
4491
|
-
tool_name:
|
|
4705
|
+
var geminiMcpContextSchema = z18.object({
|
|
4706
|
+
server_name: z18.string().optional(),
|
|
4707
|
+
tool_name: z18.string().optional()
|
|
4492
4708
|
}).loose();
|
|
4493
|
-
var geminiToolResponseSchema =
|
|
4494
|
-
llmContent:
|
|
4495
|
-
returnDisplay:
|
|
4496
|
-
error:
|
|
4709
|
+
var geminiToolResponseSchema = z18.object({
|
|
4710
|
+
llmContent: z18.unknown().optional(),
|
|
4711
|
+
returnDisplay: z18.unknown().optional(),
|
|
4712
|
+
error: z18.unknown().optional()
|
|
4497
4713
|
}).loose();
|
|
4498
4714
|
var sessionStartInputSchema = baseHookInputSchema.extend({
|
|
4499
|
-
hook_event_name:
|
|
4500
|
-
source:
|
|
4715
|
+
hook_event_name: z18.literal("SessionStart"),
|
|
4716
|
+
source: z18.enum(["startup", "resume", "clear"]).optional()
|
|
4501
4717
|
});
|
|
4502
4718
|
var sessionEndInputSchema = baseHookInputSchema.extend({
|
|
4503
|
-
hook_event_name:
|
|
4504
|
-
reason:
|
|
4719
|
+
hook_event_name: z18.literal("SessionEnd"),
|
|
4720
|
+
reason: z18.enum(["exit", "clear", "logout", "prompt_input_exit", "other"]).optional()
|
|
4505
4721
|
});
|
|
4506
4722
|
var beforeAgentInputSchema = baseHookInputSchema.extend({
|
|
4507
|
-
hook_event_name:
|
|
4508
|
-
prompt:
|
|
4723
|
+
hook_event_name: z18.literal("BeforeAgent"),
|
|
4724
|
+
prompt: z18.string().optional()
|
|
4509
4725
|
});
|
|
4510
4726
|
var afterAgentInputSchema = baseHookInputSchema.extend({
|
|
4511
|
-
hook_event_name:
|
|
4512
|
-
prompt:
|
|
4513
|
-
prompt_response:
|
|
4514
|
-
stop_hook_active:
|
|
4727
|
+
hook_event_name: z18.literal("AfterAgent"),
|
|
4728
|
+
prompt: z18.string().optional(),
|
|
4729
|
+
prompt_response: z18.string().optional(),
|
|
4730
|
+
stop_hook_active: z18.boolean().optional()
|
|
4515
4731
|
});
|
|
4516
4732
|
var beforeModelInputSchema = baseHookInputSchema.extend({
|
|
4517
|
-
hook_event_name:
|
|
4733
|
+
hook_event_name: z18.literal("BeforeModel"),
|
|
4518
4734
|
llm_request: geminiLlmRequestSchema
|
|
4519
4735
|
});
|
|
4520
4736
|
var afterModelInputSchema = baseHookInputSchema.extend({
|
|
4521
|
-
hook_event_name:
|
|
4737
|
+
hook_event_name: z18.literal("AfterModel"),
|
|
4522
4738
|
llm_request: geminiLlmRequestSchema,
|
|
4523
4739
|
llm_response: geminiLlmResponseSchema
|
|
4524
4740
|
});
|
|
4525
4741
|
var beforeToolSelectionInputSchema = baseHookInputSchema.extend({
|
|
4526
|
-
hook_event_name:
|
|
4742
|
+
hook_event_name: z18.literal("BeforeToolSelection"),
|
|
4527
4743
|
llm_request: geminiLlmRequestSchema
|
|
4528
4744
|
});
|
|
4529
4745
|
var beforeToolInputSchema = baseHookInputSchema.extend({
|
|
4530
|
-
hook_event_name:
|
|
4531
|
-
tool_name:
|
|
4532
|
-
tool_input:
|
|
4746
|
+
hook_event_name: z18.literal("BeforeTool"),
|
|
4747
|
+
tool_name: z18.string().min(1),
|
|
4748
|
+
tool_input: z18.unknown().optional(),
|
|
4533
4749
|
mcp_context: geminiMcpContextSchema.optional(),
|
|
4534
|
-
original_request_name:
|
|
4750
|
+
original_request_name: z18.string().min(1).optional()
|
|
4535
4751
|
});
|
|
4536
4752
|
var afterToolInputSchema = baseHookInputSchema.extend({
|
|
4537
|
-
hook_event_name:
|
|
4538
|
-
tool_name:
|
|
4539
|
-
tool_input:
|
|
4753
|
+
hook_event_name: z18.literal("AfterTool"),
|
|
4754
|
+
tool_name: z18.string().min(1),
|
|
4755
|
+
tool_input: z18.unknown().optional(),
|
|
4540
4756
|
tool_response: geminiToolResponseSchema.optional(),
|
|
4541
4757
|
mcp_context: geminiMcpContextSchema.optional(),
|
|
4542
|
-
original_request_name:
|
|
4758
|
+
original_request_name: z18.string().min(1).optional()
|
|
4543
4759
|
});
|
|
4544
4760
|
var preCompressInputSchema = baseHookInputSchema.extend({
|
|
4545
|
-
hook_event_name:
|
|
4546
|
-
trigger:
|
|
4761
|
+
hook_event_name: z18.literal("PreCompress"),
|
|
4762
|
+
trigger: z18.enum(["auto", "manual"]).optional()
|
|
4547
4763
|
});
|
|
4548
4764
|
var notificationInputSchema = baseHookInputSchema.extend({
|
|
4549
|
-
hook_event_name:
|
|
4550
|
-
notification_type:
|
|
4551
|
-
message:
|
|
4552
|
-
details:
|
|
4765
|
+
hook_event_name: z18.literal("Notification"),
|
|
4766
|
+
notification_type: z18.string().optional(),
|
|
4767
|
+
message: z18.string().optional(),
|
|
4768
|
+
details: z18.unknown().optional()
|
|
4553
4769
|
});
|
|
4554
|
-
var geminiHookInputSchema =
|
|
4770
|
+
var geminiHookInputSchema = z18.discriminatedUnion("hook_event_name", [
|
|
4555
4771
|
sessionStartInputSchema,
|
|
4556
4772
|
sessionEndInputSchema,
|
|
4557
4773
|
beforeAgentInputSchema,
|
|
@@ -4996,7 +5212,7 @@ var normalizeUsageOrWarn = (usage, warnings) => {
|
|
|
4996
5212
|
};
|
|
4997
5213
|
|
|
4998
5214
|
// src/providers/antigravity/payload.ts
|
|
4999
|
-
import { z as
|
|
5215
|
+
import { z as z19 } from "zod";
|
|
5000
5216
|
var ANTIGRAVITY_HOOK_EVENT_NAMES = [
|
|
5001
5217
|
"PreInvocation",
|
|
5002
5218
|
"PostInvocation",
|
|
@@ -5004,48 +5220,48 @@ var ANTIGRAVITY_HOOK_EVENT_NAMES = [
|
|
|
5004
5220
|
"PostToolUse",
|
|
5005
5221
|
"Stop"
|
|
5006
5222
|
];
|
|
5007
|
-
var hookEventNameSchema =
|
|
5008
|
-
var antigravityWeakShapeSchema =
|
|
5223
|
+
var hookEventNameSchema = z19.enum(ANTIGRAVITY_HOOK_EVENT_NAMES);
|
|
5224
|
+
var antigravityWeakShapeSchema = z19.object({ hookEventName: hookEventNameSchema }).passthrough();
|
|
5009
5225
|
var commonFields2 = {
|
|
5010
|
-
conversationId:
|
|
5011
|
-
workspacePaths:
|
|
5012
|
-
invocationNum:
|
|
5226
|
+
conversationId: z19.string().min(1),
|
|
5227
|
+
workspacePaths: z19.array(z19.string().min(1)).max(64),
|
|
5228
|
+
invocationNum: z19.number().int().min(0),
|
|
5013
5229
|
/** Never disclosed: a real filesystem path. Accepted, never propagated. */
|
|
5014
|
-
transcriptPath:
|
|
5230
|
+
transcriptPath: z19.string().min(1).optional(),
|
|
5015
5231
|
/** Never disclosed: a real filesystem path. Accepted, never propagated. */
|
|
5016
|
-
artifactDirectoryPath:
|
|
5232
|
+
artifactDirectoryPath: z19.string().min(1).optional()
|
|
5017
5233
|
};
|
|
5018
|
-
var preInvocationPayloadSchema =
|
|
5019
|
-
hookEventName:
|
|
5234
|
+
var preInvocationPayloadSchema = z19.object({
|
|
5235
|
+
hookEventName: z19.literal("PreInvocation"),
|
|
5020
5236
|
...commonFields2,
|
|
5021
|
-
agentVersion:
|
|
5237
|
+
agentVersion: z19.string().min(1).optional()
|
|
5022
5238
|
});
|
|
5023
|
-
var postInvocationPayloadSchema =
|
|
5024
|
-
hookEventName:
|
|
5239
|
+
var postInvocationPayloadSchema = z19.object({
|
|
5240
|
+
hookEventName: z19.literal("PostInvocation"),
|
|
5025
5241
|
...commonFields2,
|
|
5026
|
-
agentVersion:
|
|
5242
|
+
agentVersion: z19.string().min(1).optional()
|
|
5027
5243
|
});
|
|
5028
|
-
var preToolUsePayloadSchema3 =
|
|
5029
|
-
hookEventName:
|
|
5244
|
+
var preToolUsePayloadSchema3 = z19.object({
|
|
5245
|
+
hookEventName: z19.literal("PreToolUse"),
|
|
5030
5246
|
...commonFields2,
|
|
5031
|
-
stepIdx:
|
|
5032
|
-
toolName:
|
|
5033
|
-
toolInput:
|
|
5247
|
+
stepIdx: z19.number().int().min(0),
|
|
5248
|
+
toolName: z19.string().min(1),
|
|
5249
|
+
toolInput: z19.unknown().optional()
|
|
5034
5250
|
});
|
|
5035
|
-
var postToolUsePayloadSchema3 =
|
|
5036
|
-
hookEventName:
|
|
5251
|
+
var postToolUsePayloadSchema3 = z19.object({
|
|
5252
|
+
hookEventName: z19.literal("PostToolUse"),
|
|
5037
5253
|
...commonFields2,
|
|
5038
|
-
stepIdx:
|
|
5039
|
-
toolName:
|
|
5040
|
-
toolResponse:
|
|
5041
|
-
isError:
|
|
5254
|
+
stepIdx: z19.number().int().min(0),
|
|
5255
|
+
toolName: z19.string().min(1),
|
|
5256
|
+
toolResponse: z19.unknown().optional(),
|
|
5257
|
+
isError: z19.boolean().optional()
|
|
5042
5258
|
});
|
|
5043
|
-
var stopPayloadSchema3 =
|
|
5044
|
-
hookEventName:
|
|
5259
|
+
var stopPayloadSchema3 = z19.object({
|
|
5260
|
+
hookEventName: z19.literal("Stop"),
|
|
5045
5261
|
...commonFields2,
|
|
5046
|
-
fullyIdle:
|
|
5262
|
+
fullyIdle: z19.boolean()
|
|
5047
5263
|
});
|
|
5048
|
-
var antigravityHookPayloadSchema =
|
|
5264
|
+
var antigravityHookPayloadSchema = z19.discriminatedUnion("hookEventName", [
|
|
5049
5265
|
preInvocationPayloadSchema,
|
|
5050
5266
|
postInvocationPayloadSchema,
|
|
5051
5267
|
preToolUsePayloadSchema3,
|
|
@@ -5338,7 +5554,7 @@ var createFixedClock = (options = {}) => {
|
|
|
5338
5554
|
};
|
|
5339
5555
|
|
|
5340
5556
|
// src/runtime/hook.ts
|
|
5341
|
-
import { z as
|
|
5557
|
+
import { z as z21 } from "zod";
|
|
5342
5558
|
|
|
5343
5559
|
// src/runtime/delivery.ts
|
|
5344
5560
|
var PROVIDER_SCOPE_PREFIX = "provider-session";
|
|
@@ -5405,15 +5621,15 @@ var createDeterministicIdGenerator = (options = {}) => {
|
|
|
5405
5621
|
};
|
|
5406
5622
|
|
|
5407
5623
|
// src/runtime/ports.ts
|
|
5408
|
-
import { z as
|
|
5409
|
-
var appliedDeliverySchema =
|
|
5410
|
-
callbackId:
|
|
5624
|
+
import { z as z20 } from "zod";
|
|
5625
|
+
var appliedDeliverySchema = z20.strictObject({
|
|
5626
|
+
callbackId: z20.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
|
|
5411
5627
|
/** How many of that delivery's observations are folded in, counted from one. */
|
|
5412
|
-
applications:
|
|
5628
|
+
applications: z20.number().int().min(1).max(4096)
|
|
5413
5629
|
});
|
|
5414
|
-
var stateValueSchema =
|
|
5415
|
-
|
|
5416
|
-
kind:
|
|
5630
|
+
var stateValueSchema = z20.discriminatedUnion("kind", [
|
|
5631
|
+
z20.strictObject({
|
|
5632
|
+
kind: z20.literal("usage-cumulative"),
|
|
5417
5633
|
usage: canonicalUsageSchema,
|
|
5418
5634
|
/**
|
|
5419
5635
|
* Optional: absent on every record written before this field existed, which
|
|
@@ -5422,22 +5638,22 @@ var stateValueSchema = z19.discriminatedUnion("kind", [
|
|
|
5422
5638
|
*/
|
|
5423
5639
|
appliedDelivery: appliedDeliverySchema.optional()
|
|
5424
5640
|
}),
|
|
5425
|
-
|
|
5426
|
-
kind:
|
|
5641
|
+
z20.strictObject({
|
|
5642
|
+
kind: z20.literal("sequence"),
|
|
5427
5643
|
next: sequenceNumberSchema
|
|
5428
5644
|
}),
|
|
5429
|
-
|
|
5430
|
-
kind:
|
|
5645
|
+
z20.strictObject({
|
|
5646
|
+
kind: z20.literal("attributes"),
|
|
5431
5647
|
attributes: attributesSchema
|
|
5432
5648
|
})
|
|
5433
5649
|
]);
|
|
5434
|
-
var stateRecordSchema =
|
|
5650
|
+
var stateRecordSchema = z20.strictObject({
|
|
5435
5651
|
/** Incremented on each write; lets callers detect lost updates. */
|
|
5436
|
-
revision:
|
|
5652
|
+
revision: z20.number().int().min(0),
|
|
5437
5653
|
updatedAt: epochMillisSchema,
|
|
5438
5654
|
value: stateValueSchema
|
|
5439
5655
|
});
|
|
5440
|
-
var logLevelSchema =
|
|
5656
|
+
var logLevelSchema = z20.enum(["silent", "error", "warn", "info", "debug"]);
|
|
5441
5657
|
var LOG_LEVEL_RANK = Object.freeze({
|
|
5442
5658
|
silent: 0,
|
|
5443
5659
|
error: 1,
|
|
@@ -5454,6 +5670,96 @@ var createNullLogger = () => ({
|
|
|
5454
5670
|
debug: () => void 0
|
|
5455
5671
|
});
|
|
5456
5672
|
|
|
5673
|
+
// src/runtime/target-resolution.ts
|
|
5674
|
+
import * as path from "path";
|
|
5675
|
+
var DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS = 50;
|
|
5676
|
+
var absolutePathsOf = (hint) => {
|
|
5677
|
+
const base = hint.baseDirectory !== void 0 && path.isAbsolute(hint.baseDirectory) ? hint.baseDirectory : void 0;
|
|
5678
|
+
const resolved = [];
|
|
5679
|
+
for (const candidate of hint.paths) {
|
|
5680
|
+
if (path.isAbsolute(candidate)) {
|
|
5681
|
+
resolved.push(path.resolve(candidate));
|
|
5682
|
+
} else if (base !== void 0) {
|
|
5683
|
+
resolved.push(path.resolve(base, candidate));
|
|
5684
|
+
} else {
|
|
5685
|
+
return void 0;
|
|
5686
|
+
}
|
|
5687
|
+
}
|
|
5688
|
+
return resolved;
|
|
5689
|
+
};
|
|
5690
|
+
var resolveHint = async (hint, locator, privacy) => {
|
|
5691
|
+
const paths = absolutePathsOf(hint);
|
|
5692
|
+
if (paths === void 0) {
|
|
5693
|
+
return void 0;
|
|
5694
|
+
}
|
|
5695
|
+
const located = await Promise.all(
|
|
5696
|
+
[...new Set(paths)].map((candidate) => locator.locate(candidate))
|
|
5697
|
+
);
|
|
5698
|
+
const [first] = located;
|
|
5699
|
+
if (first === void 0 || located.some((entry) => entry?.root !== first.root)) {
|
|
5700
|
+
return void 0;
|
|
5701
|
+
}
|
|
5702
|
+
const identity = deriveWorkspaceIdentity(
|
|
5703
|
+
privacy,
|
|
5704
|
+
{ kind: "git-root", absolutePath: first.root },
|
|
5705
|
+
first.branch === void 0 ? {} : { vcsBranchName: first.branch }
|
|
5706
|
+
);
|
|
5707
|
+
if (identity.keySource !== "git-root") {
|
|
5708
|
+
return void 0;
|
|
5709
|
+
}
|
|
5710
|
+
const repository = first.mainRoot === void 0 ? void 0 : deriveWorkspaceIdentity(privacy, { kind: "git-root", absolutePath: first.mainRoot });
|
|
5711
|
+
const parsed = workspaceTargetSchema.safeParse({
|
|
5712
|
+
workspaceId: identity.workspaceId,
|
|
5713
|
+
...identity.vcsBranchName === void 0 ? {} : { vcsBranchName: identity.vcsBranchName },
|
|
5714
|
+
source: hint.source,
|
|
5715
|
+
...repository?.keySource === "git-root" ? { repositoryId: repository.workspaceId } : {},
|
|
5716
|
+
...first.kind === void 0 ? {} : { worktreeKind: first.kind }
|
|
5717
|
+
});
|
|
5718
|
+
return parsed.success ? parsed.data : void 0;
|
|
5719
|
+
};
|
|
5720
|
+
var resolveEventTargets = async (input) => {
|
|
5721
|
+
const pending = input.events.filter(
|
|
5722
|
+
(event3) => (event3.type === "tool.start" || event3.type === "tool.end") && input.hints.has(event3.eventId)
|
|
5723
|
+
);
|
|
5724
|
+
if (pending.length === 0) {
|
|
5725
|
+
return { events: input.events, resolved: 0, timedOut: false };
|
|
5726
|
+
}
|
|
5727
|
+
const targets = /* @__PURE__ */ new Map();
|
|
5728
|
+
const work = Promise.all(
|
|
5729
|
+
pending.map(async (event3) => {
|
|
5730
|
+
const hint = input.hints.get(event3.eventId);
|
|
5731
|
+
if (hint === void 0) {
|
|
5732
|
+
return;
|
|
5733
|
+
}
|
|
5734
|
+
try {
|
|
5735
|
+
const target = await resolveHint(hint, input.locator, input.privacy);
|
|
5736
|
+
if (target !== void 0) {
|
|
5737
|
+
targets.set(event3.eventId, target);
|
|
5738
|
+
}
|
|
5739
|
+
} catch {
|
|
5740
|
+
}
|
|
5741
|
+
})
|
|
5742
|
+
).then(() => "done");
|
|
5743
|
+
let timer;
|
|
5744
|
+
const deadline = new Promise((resolve2) => {
|
|
5745
|
+
timer = setTimeout(() => resolve2("timeout"), Math.max(0, input.budgetMillis));
|
|
5746
|
+
timer.unref?.();
|
|
5747
|
+
});
|
|
5748
|
+
const finished = await Promise.race([work, deadline]);
|
|
5749
|
+
if (timer !== void 0) {
|
|
5750
|
+
clearTimeout(timer);
|
|
5751
|
+
}
|
|
5752
|
+
const settled = new Map(targets);
|
|
5753
|
+
const events = input.events.map((event3) => {
|
|
5754
|
+
const target = settled.get(event3.eventId);
|
|
5755
|
+
if (target === void 0 || event3.type !== "tool.start" && event3.type !== "tool.end") {
|
|
5756
|
+
return event3;
|
|
5757
|
+
}
|
|
5758
|
+
return { ...event3, target };
|
|
5759
|
+
});
|
|
5760
|
+
return { events, resolved: settled.size, timedOut: finished === "timeout" };
|
|
5761
|
+
};
|
|
5762
|
+
|
|
5457
5763
|
// src/state/async-lock.ts
|
|
5458
5764
|
var LockWaitTimeoutError = class extends Error {
|
|
5459
5765
|
lockKey;
|
|
@@ -5483,7 +5789,7 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
|
|
|
5483
5789
|
};
|
|
5484
5790
|
|
|
5485
5791
|
// src/runtime/hook.ts
|
|
5486
|
-
var usageScopeSchema =
|
|
5792
|
+
var usageScopeSchema = z21.enum(["session", "generation", "subagent"]);
|
|
5487
5793
|
var classifyDurability = (input) => {
|
|
5488
5794
|
if (!input.attempted) {
|
|
5489
5795
|
return "nothing-to-deliver";
|
|
@@ -6021,7 +6327,12 @@ var createOtelHook = (deps) => {
|
|
|
6021
6327
|
);
|
|
6022
6328
|
}
|
|
6023
6329
|
}
|
|
6024
|
-
return {
|
|
6330
|
+
return {
|
|
6331
|
+
kind: "ready",
|
|
6332
|
+
batch: batch2,
|
|
6333
|
+
dropped: screened.dropped,
|
|
6334
|
+
...parsed.targetHints === void 0 ? {} : { targetHints: parsed.targetHints }
|
|
6335
|
+
};
|
|
6025
6336
|
};
|
|
6026
6337
|
let prepared;
|
|
6027
6338
|
try {
|
|
@@ -6066,7 +6377,24 @@ var createOtelHook = (deps) => {
|
|
|
6066
6377
|
if (prepared.kind === "early") {
|
|
6067
6378
|
return prepared.outcome;
|
|
6068
6379
|
}
|
|
6069
|
-
const {
|
|
6380
|
+
const { dropped } = prepared;
|
|
6381
|
+
let batch = prepared.batch;
|
|
6382
|
+
if (!suppress && deps.worktreeLocator !== void 0 && prepared.targetHints !== void 0 && prepared.targetHints.size > 0) {
|
|
6383
|
+
const targeted = await resolveEventTargets({
|
|
6384
|
+
events: batch,
|
|
6385
|
+
hints: prepared.targetHints,
|
|
6386
|
+
locator: deps.worktreeLocator,
|
|
6387
|
+
privacy,
|
|
6388
|
+
budgetMillis: deps.targetResolutionBudgetMillis ?? DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS
|
|
6389
|
+
});
|
|
6390
|
+
batch = targeted.events;
|
|
6391
|
+
if (targeted.timedOut) {
|
|
6392
|
+
logger.debug("worktree target resolution exceeded its budget", {
|
|
6393
|
+
"provider.id": detection.providerId,
|
|
6394
|
+
"target.resolved": targeted.resolved
|
|
6395
|
+
});
|
|
6396
|
+
}
|
|
6397
|
+
}
|
|
6070
6398
|
let emitted = 0;
|
|
6071
6399
|
let exportRejected = 0;
|
|
6072
6400
|
if (!suppress && batch.length > 0) {
|
|
@@ -6334,11 +6662,11 @@ var createRecordingLogger = (level = "debug") => {
|
|
|
6334
6662
|
};
|
|
6335
6663
|
|
|
6336
6664
|
// src/testing/fixture-adapter.ts
|
|
6337
|
-
import { z as
|
|
6338
|
-
var syntheticPayloadSchema =
|
|
6339
|
-
provider:
|
|
6340
|
-
sessionId:
|
|
6341
|
-
event:
|
|
6665
|
+
import { z as z22 } from "zod";
|
|
6666
|
+
var syntheticPayloadSchema = z22.object({
|
|
6667
|
+
provider: z22.string().min(1),
|
|
6668
|
+
sessionId: z22.string().min(1),
|
|
6669
|
+
event: z22.enum([
|
|
6342
6670
|
"session.start",
|
|
6343
6671
|
"prompt",
|
|
6344
6672
|
"generation",
|
|
@@ -6348,15 +6676,15 @@ var syntheticPayloadSchema = z21.object({
|
|
|
6348
6676
|
"session.end",
|
|
6349
6677
|
"noop"
|
|
6350
6678
|
]),
|
|
6351
|
-
requestId:
|
|
6352
|
-
model:
|
|
6353
|
-
promptText:
|
|
6354
|
-
toolName:
|
|
6355
|
-
toolInput:
|
|
6356
|
-
workspaceKey:
|
|
6357
|
-
occurredAt:
|
|
6679
|
+
requestId: z22.string().min(1).optional(),
|
|
6680
|
+
model: z22.string().min(1).optional(),
|
|
6681
|
+
promptText: z22.string().optional(),
|
|
6682
|
+
toolName: z22.string().min(1).optional(),
|
|
6683
|
+
toolInput: z22.unknown().optional(),
|
|
6684
|
+
workspaceKey: z22.string().min(1).optional(),
|
|
6685
|
+
occurredAt: z22.number().int().min(0).optional(),
|
|
6358
6686
|
usage: usageReportSchema.optional(),
|
|
6359
|
-
agentVersion:
|
|
6687
|
+
agentVersion: z22.string().min(1).optional()
|
|
6360
6688
|
});
|
|
6361
6689
|
var SYNTHETIC_PROVIDER_ID = "fixture";
|
|
6362
6690
|
var DEFAULT_FIXTURE_CAPABILITIES = Object.freeze({
|
|
@@ -6758,7 +7086,8 @@ var createTestHook = (options = {}) => {
|
|
|
6758
7086
|
clock,
|
|
6759
7087
|
ids,
|
|
6760
7088
|
privacy,
|
|
6761
|
-
logger
|
|
7089
|
+
logger,
|
|
7090
|
+
...options.worktreeLocator === void 0 ? {} : { worktreeLocator: options.worktreeLocator }
|
|
6762
7091
|
});
|
|
6763
7092
|
return { hook, sink, stateStore, clock, ids, privacy, logger, registry, config };
|
|
6764
7093
|
};
|