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