@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/runtime.js
CHANGED
|
@@ -837,7 +837,7 @@ var resolveDeliveryIdentity = (input) => {
|
|
|
837
837
|
};
|
|
838
838
|
|
|
839
839
|
// src/runtime/hook.ts
|
|
840
|
-
import { z as
|
|
840
|
+
import { z as z16 } from "zod";
|
|
841
841
|
|
|
842
842
|
// src/config/schema.ts
|
|
843
843
|
import { z as z8 } from "zod";
|
|
@@ -1591,11 +1591,11 @@ var createPrivacyService = (policyInput) => {
|
|
|
1591
1591
|
};
|
|
1592
1592
|
const flattenToAttributes = (value, prefix) => {
|
|
1593
1593
|
const attributes = {};
|
|
1594
|
-
const walk = (current,
|
|
1594
|
+
const walk = (current, path3) => {
|
|
1595
1595
|
if (typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
1596
1596
|
const primitive = toAttributePrimitive(current);
|
|
1597
1597
|
if (primitive !== void 0) {
|
|
1598
|
-
attributes[
|
|
1598
|
+
attributes[path3] = primitive;
|
|
1599
1599
|
}
|
|
1600
1600
|
return;
|
|
1601
1601
|
}
|
|
@@ -1614,16 +1614,16 @@ var createPrivacyService = (policyInput) => {
|
|
|
1614
1614
|
primitives.push(entryPrimitive);
|
|
1615
1615
|
}
|
|
1616
1616
|
if (uniform) {
|
|
1617
|
-
attributes[
|
|
1617
|
+
attributes[path3] = primitives.slice(0, MAX_ATTRIBUTE_ARRAY_LENGTH);
|
|
1618
1618
|
return;
|
|
1619
1619
|
}
|
|
1620
1620
|
for (const [index, entry] of current.entries()) {
|
|
1621
|
-
walk(entry, `${
|
|
1621
|
+
walk(entry, `${path3}.${index}`);
|
|
1622
1622
|
}
|
|
1623
1623
|
return;
|
|
1624
1624
|
}
|
|
1625
1625
|
for (const [key, entry] of Object.entries(current)) {
|
|
1626
|
-
walk(entry,
|
|
1626
|
+
walk(entry, path3 === "" ? key : `${path3}.${key}`);
|
|
1627
1627
|
}
|
|
1628
1628
|
};
|
|
1629
1629
|
walk(value, prefix);
|
|
@@ -1716,23 +1716,46 @@ var createPrivacyService = (policyInput) => {
|
|
|
1716
1716
|
};
|
|
1717
1717
|
|
|
1718
1718
|
// src/providers/adapter.ts
|
|
1719
|
-
import { z as
|
|
1719
|
+
import { z as z15 } from "zod";
|
|
1720
1720
|
|
|
1721
1721
|
// src/model/events.ts
|
|
1722
|
+
import { z as z14 } from "zod";
|
|
1723
|
+
|
|
1724
|
+
// src/model/target.ts
|
|
1722
1725
|
import { z as z13 } from "zod";
|
|
1723
|
-
var
|
|
1726
|
+
var targetSourceSchema = z13.enum(["tool-path", "shell-cwd", "session-cwd"]);
|
|
1727
|
+
var MAX_TARGET_HINT_PATHS = 8;
|
|
1728
|
+
var MAX_TARGET_PATH_LENGTH = 4096;
|
|
1729
|
+
var localPathSchema = z13.string().min(1).max(MAX_TARGET_PATH_LENGTH).refine((value) => !value.includes("\0"), "path must not contain NUL");
|
|
1730
|
+
var targetHintSchema = z13.strictObject({
|
|
1731
|
+
source: targetSourceSchema,
|
|
1732
|
+
paths: z13.array(localPathSchema).min(1).max(MAX_TARGET_HINT_PATHS).readonly(),
|
|
1733
|
+
/** Absolute directory that relative `paths` resolve against. */
|
|
1734
|
+
baseDirectory: localPathSchema.optional()
|
|
1735
|
+
}).readonly();
|
|
1736
|
+
var workspaceTargetSchema = z13.strictObject({
|
|
1737
|
+
workspaceId: workspaceIdSchema,
|
|
1738
|
+
/** Branch checked out in that worktree; absent on a detached HEAD. */
|
|
1739
|
+
vcsBranchName: nonEmptyStringSchema.optional(),
|
|
1740
|
+
source: targetSourceSchema
|
|
1741
|
+
}).readonly();
|
|
1742
|
+
var SUBAGENT_ID_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
1743
|
+
var subagentIdSchema = z13.string().regex(SUBAGENT_ID_PATTERN);
|
|
1744
|
+
|
|
1745
|
+
// src/model/events.ts
|
|
1746
|
+
var modelDescriptorSchema = z14.strictObject({
|
|
1724
1747
|
modelId: nonEmptyStringSchema,
|
|
1725
1748
|
/** Vendor of the model, e.g. `anthropic`. Distinct from the agent provider. */
|
|
1726
1749
|
vendor: nonEmptyStringSchema.optional(),
|
|
1727
1750
|
family: nonEmptyStringSchema.optional()
|
|
1728
1751
|
});
|
|
1729
|
-
var costFactsSchema =
|
|
1752
|
+
var costFactsSchema = z14.strictObject({
|
|
1730
1753
|
/** ISO 4217 code. */
|
|
1731
|
-
currency:
|
|
1732
|
-
amount:
|
|
1733
|
-
source:
|
|
1754
|
+
currency: z14.string().length(3),
|
|
1755
|
+
amount: z14.number().min(0).finite(),
|
|
1756
|
+
source: z14.enum(["provider-reported", "computed"])
|
|
1734
1757
|
});
|
|
1735
|
-
var canonicalEventTypeSchema =
|
|
1758
|
+
var canonicalEventTypeSchema = z14.enum([
|
|
1736
1759
|
"session.start",
|
|
1737
1760
|
"session.end",
|
|
1738
1761
|
"prompt.submitted",
|
|
@@ -1746,7 +1769,7 @@ var canonicalEventTypeSchema = z13.enum([
|
|
|
1746
1769
|
"error.raised"
|
|
1747
1770
|
]);
|
|
1748
1771
|
var CANONICAL_EVENT_TYPES = canonicalEventTypeSchema.options;
|
|
1749
|
-
var outcomeSchema =
|
|
1772
|
+
var outcomeSchema = z14.enum(["ok", "error", "cancelled", "timeout", "denied", "unknown"]);
|
|
1750
1773
|
var baseEventFields = {
|
|
1751
1774
|
schemaVersion: canonicalSchemaVersionSchema,
|
|
1752
1775
|
eventId: eventIdSchema,
|
|
@@ -1757,39 +1780,45 @@ var baseEventFields = {
|
|
|
1757
1780
|
occurredAt: epochMillisSchema,
|
|
1758
1781
|
provenance: sourceProvenanceSchema,
|
|
1759
1782
|
workspace: workspaceIdentitySchema,
|
|
1783
|
+
/**
|
|
1784
|
+
* The provider's own id for the subagent this event was emitted inside (e.g.
|
|
1785
|
+
* Claude Code's `agent_id`). Absent for the top-level agent. Set by the event
|
|
1786
|
+
* factory, never by hand.
|
|
1787
|
+
*/
|
|
1788
|
+
subagentId: subagentIdSchema.optional(),
|
|
1760
1789
|
extensions: extensionsSchema.default(emptyExtensions)
|
|
1761
1790
|
};
|
|
1762
|
-
var event = (shape) =>
|
|
1791
|
+
var event = (shape) => z14.strictObject({ ...baseEventFields, ...shape });
|
|
1763
1792
|
var sessionStartEventSchema = event({
|
|
1764
|
-
type:
|
|
1765
|
-
sessionKind:
|
|
1793
|
+
type: z14.literal("session.start"),
|
|
1794
|
+
sessionKind: z14.enum(["interactive", "non-interactive", "unknown"]),
|
|
1766
1795
|
agentName: nonEmptyStringSchema.optional(),
|
|
1767
1796
|
agentVersion: nonEmptyStringSchema.optional(),
|
|
1768
1797
|
model: modelDescriptorSchema.optional()
|
|
1769
1798
|
});
|
|
1770
1799
|
var sessionEndEventSchema = event({
|
|
1771
|
-
type:
|
|
1772
|
-
reason:
|
|
1800
|
+
type: z14.literal("session.end"),
|
|
1801
|
+
reason: z14.enum(["completed", "aborted", "error", "timeout", "unknown"]),
|
|
1773
1802
|
durationMillis: durationMillisSchema.optional(),
|
|
1774
1803
|
/** Session totals, typically cumulative. */
|
|
1775
1804
|
usage: canonicalUsageSchema.optional(),
|
|
1776
1805
|
cost: costFactsSchema.optional()
|
|
1777
1806
|
});
|
|
1778
1807
|
var promptSubmittedEventSchema = event({
|
|
1779
|
-
type:
|
|
1780
|
-
promptSource:
|
|
1808
|
+
type: z14.literal("prompt.submitted"),
|
|
1809
|
+
promptSource: z14.enum(["user", "automation", "resumed", "unknown"]),
|
|
1781
1810
|
content: contentFactSchema.optional(),
|
|
1782
|
-
turnIndex:
|
|
1811
|
+
turnIndex: z14.number().int().min(0).optional()
|
|
1783
1812
|
});
|
|
1784
1813
|
var generationStartEventSchema = event({
|
|
1785
|
-
type:
|
|
1814
|
+
type: z14.literal("generation.start"),
|
|
1786
1815
|
generationId: nonEmptyStringSchema,
|
|
1787
1816
|
model: modelDescriptorSchema,
|
|
1788
1817
|
requestedMaxOutputTokens: tokenCountSchema.optional(),
|
|
1789
1818
|
inputContent: contentFactsSchema.optional()
|
|
1790
1819
|
});
|
|
1791
1820
|
var generationEndEventSchema = event({
|
|
1792
|
-
type:
|
|
1821
|
+
type: z14.literal("generation.end"),
|
|
1793
1822
|
generationId: nonEmptyStringSchema,
|
|
1794
1823
|
model: modelDescriptorSchema,
|
|
1795
1824
|
outcome: outcomeSchema,
|
|
@@ -1799,7 +1828,7 @@ var generationEndEventSchema = event({
|
|
|
1799
1828
|
cost: costFactsSchema.optional(),
|
|
1800
1829
|
outputContent: contentFactsSchema.optional()
|
|
1801
1830
|
});
|
|
1802
|
-
var toolKindSchema =
|
|
1831
|
+
var toolKindSchema = z14.enum([
|
|
1803
1832
|
"read",
|
|
1804
1833
|
"write",
|
|
1805
1834
|
"execute",
|
|
@@ -1810,59 +1839,63 @@ var toolKindSchema = z13.enum([
|
|
|
1810
1839
|
"unknown"
|
|
1811
1840
|
]);
|
|
1812
1841
|
var toolStartEventSchema = event({
|
|
1813
|
-
type:
|
|
1842
|
+
type: z14.literal("tool.start"),
|
|
1814
1843
|
toolCallId: nonEmptyStringSchema,
|
|
1815
1844
|
toolName: nonEmptyStringSchema,
|
|
1816
1845
|
toolKind: toolKindSchema,
|
|
1817
1846
|
generationId: nonEmptyStringSchema.optional(),
|
|
1818
|
-
input: contentFactSchema.optional()
|
|
1847
|
+
input: contentFactSchema.optional(),
|
|
1848
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
1849
|
+
target: workspaceTargetSchema.optional()
|
|
1819
1850
|
});
|
|
1820
1851
|
var toolEndEventSchema = event({
|
|
1821
|
-
type:
|
|
1852
|
+
type: z14.literal("tool.end"),
|
|
1822
1853
|
toolCallId: nonEmptyStringSchema,
|
|
1823
1854
|
toolName: nonEmptyStringSchema,
|
|
1824
1855
|
outcome: outcomeSchema,
|
|
1825
1856
|
durationMillis: durationMillisSchema.optional(),
|
|
1826
1857
|
/** Present when the host asked for or recorded a permission decision. */
|
|
1827
|
-
permissionDecision:
|
|
1828
|
-
output: contentFactSchema.optional()
|
|
1858
|
+
permissionDecision: z14.enum(["allowed", "denied", "deferred", "not-required"]).optional(),
|
|
1859
|
+
output: contentFactSchema.optional(),
|
|
1860
|
+
/** The git worktree this call targeted, resolved by the core (ADR 0008). */
|
|
1861
|
+
target: workspaceTargetSchema.optional()
|
|
1829
1862
|
});
|
|
1830
1863
|
var subagentStartEventSchema = event({
|
|
1831
|
-
type:
|
|
1864
|
+
type: z14.literal("subagent.start"),
|
|
1832
1865
|
subagentInvocationId: invocationIdSchema,
|
|
1833
1866
|
subagentType: nonEmptyStringSchema.optional(),
|
|
1834
1867
|
/** 0 for the top-level agent; 1 for its direct children. */
|
|
1835
|
-
delegationDepth:
|
|
1868
|
+
delegationDepth: z14.number().int().min(0).max(64),
|
|
1836
1869
|
model: modelDescriptorSchema.optional()
|
|
1837
1870
|
});
|
|
1838
1871
|
var subagentEndEventSchema = event({
|
|
1839
|
-
type:
|
|
1872
|
+
type: z14.literal("subagent.end"),
|
|
1840
1873
|
subagentInvocationId: invocationIdSchema,
|
|
1841
1874
|
outcome: outcomeSchema,
|
|
1842
1875
|
durationMillis: durationMillisSchema.optional(),
|
|
1843
1876
|
usage: canonicalUsageSchema.optional()
|
|
1844
1877
|
});
|
|
1845
1878
|
var compactionPerformedEventSchema = event({
|
|
1846
|
-
type:
|
|
1847
|
-
trigger:
|
|
1879
|
+
type: z14.literal("compaction.performed"),
|
|
1880
|
+
trigger: z14.enum(["automatic", "manual", "unknown"]),
|
|
1848
1881
|
/** Provider-reported context size before and after compaction, if known. */
|
|
1849
1882
|
contextTokensBefore: tokenCountSchema.optional(),
|
|
1850
1883
|
contextTokensAfter: tokenCountSchema.optional(),
|
|
1851
|
-
droppedMessageCount:
|
|
1884
|
+
droppedMessageCount: z14.number().int().min(0).optional(),
|
|
1852
1885
|
usage: canonicalUsageSchema.optional()
|
|
1853
1886
|
});
|
|
1854
1887
|
var errorRaisedEventSchema = event({
|
|
1855
|
-
type:
|
|
1888
|
+
type: z14.literal("error.raised"),
|
|
1856
1889
|
errorCode: otelHookErrorCodeSchema,
|
|
1857
1890
|
severity: errorSeveritySchema,
|
|
1858
1891
|
phase: errorPhaseSchema,
|
|
1859
|
-
retryable:
|
|
1892
|
+
retryable: z14.boolean(),
|
|
1860
1893
|
/** Error text is content: it is described, never embedded verbatim by default. */
|
|
1861
1894
|
message: contentFactSchema.optional(),
|
|
1862
1895
|
/** Non-sensitive, provider-agnostic short label. */
|
|
1863
1896
|
detail: nonEmptyStringSchema.optional()
|
|
1864
1897
|
});
|
|
1865
|
-
var canonicalEventSchema =
|
|
1898
|
+
var canonicalEventSchema = z14.discriminatedUnion("type", [
|
|
1866
1899
|
sessionStartEventSchema,
|
|
1867
1900
|
sessionEndEventSchema,
|
|
1868
1901
|
promptSubmittedEventSchema,
|
|
@@ -1877,26 +1910,26 @@ var canonicalEventSchema = z13.discriminatedUnion("type", [
|
|
|
1877
1910
|
]);
|
|
1878
1911
|
|
|
1879
1912
|
// src/providers/adapter.ts
|
|
1880
|
-
var providerDetectionSchema =
|
|
1913
|
+
var providerDetectionSchema = z15.strictObject({
|
|
1881
1914
|
providerId: resolvedProviderIdSchema,
|
|
1882
1915
|
confidence: detectionConfidenceSchema,
|
|
1883
1916
|
/**
|
|
1884
1917
|
* Short, non-sensitive justifications, e.g. `"payload.hook_event_name present"`.
|
|
1885
1918
|
* Reasons are exported in diagnostics, so they must not quote payload values.
|
|
1886
1919
|
*/
|
|
1887
|
-
reasons:
|
|
1920
|
+
reasons: z15.array(z15.string().min(1).max(160)).max(8),
|
|
1888
1921
|
providerVersion: nonEmptyStringSchema.optional(),
|
|
1889
1922
|
/** The provider's own name for this event, when the payload states one. */
|
|
1890
1923
|
sourceEventName: nonEmptyStringSchema.optional()
|
|
1891
1924
|
});
|
|
1892
|
-
var deliveryIdentifierSupportSchema =
|
|
1925
|
+
var deliveryIdentifierSupportSchema = z15.enum(["none", "partial", "all"]);
|
|
1893
1926
|
var DELIVERY_COMPONENT_PATTERN = /^[A-Za-z0-9_.:@+=-]{1,256}$/;
|
|
1894
|
-
var deliveryComponentSchema =
|
|
1927
|
+
var deliveryComponentSchema = z15.string().regex(
|
|
1895
1928
|
DELIVERY_COMPONENT_PATTERN,
|
|
1896
1929
|
"delivery component must be identifier-shaped: no whitespace, no path separators"
|
|
1897
1930
|
);
|
|
1898
1931
|
var MAX_DELIVERY_COMPONENTS = 8;
|
|
1899
|
-
var providerDeliveryClaimSchema =
|
|
1932
|
+
var providerDeliveryClaimSchema = z15.strictObject({
|
|
1900
1933
|
/**
|
|
1901
1934
|
* The provider's own session/conversation id. Scopes the callback identity, so
|
|
1902
1935
|
* two sessions reusing one tool-call id never collide.
|
|
@@ -1908,26 +1941,26 @@ var providerDeliveryClaimSchema = z14.strictObject({
|
|
|
1908
1941
|
* Identifier-shaped payload fields that, together with `sourceEventName`,
|
|
1909
1942
|
* name this callback within the session exactly once.
|
|
1910
1943
|
*/
|
|
1911
|
-
components:
|
|
1944
|
+
components: z15.array(deliveryComponentSchema).min(1).max(MAX_DELIVERY_COMPONENTS).readonly(),
|
|
1912
1945
|
/**
|
|
1913
1946
|
* Short, non-sensitive justifications, e.g. `"payload.tool_use_id names one
|
|
1914
1947
|
* tool call"`. Evidence reaches diagnostics, so it must name fields, never
|
|
1915
1948
|
* quote their values.
|
|
1916
1949
|
*/
|
|
1917
|
-
evidence:
|
|
1950
|
+
evidence: z15.array(z15.string().min(1).max(160)).min(1).max(4).readonly()
|
|
1918
1951
|
});
|
|
1919
1952
|
var DELIVERY_GAP_REASON_PATTERN = /^[^\n\r\t\\/]{1,240}$/;
|
|
1920
|
-
var deliveryGapReasonSchema =
|
|
1953
|
+
var deliveryGapReasonSchema = z15.string().regex(
|
|
1921
1954
|
DELIVERY_GAP_REASON_PATTERN,
|
|
1922
1955
|
"delivery gap reason must be one line of prose: no path separators, no control characters"
|
|
1923
1956
|
);
|
|
1924
1957
|
var MAX_DELIVERY_GAPS = 48;
|
|
1925
|
-
var providerDeliveryGapsSchema =
|
|
1958
|
+
var providerDeliveryGapsSchema = z15.record(deliveryComponentSchema, deliveryGapReasonSchema).refine((gaps) => Object.keys(gaps).length <= MAX_DELIVERY_GAPS, {
|
|
1926
1959
|
message: `at most ${String(MAX_DELIVERY_GAPS)} delivery gaps may be declared`
|
|
1927
1960
|
});
|
|
1928
|
-
var providerCapabilitiesSchema =
|
|
1961
|
+
var providerCapabilitiesSchema = z15.strictObject({
|
|
1929
1962
|
/** Event types the adapter can produce. */
|
|
1930
|
-
lifecycleEvents:
|
|
1963
|
+
lifecycleEvents: z15.array(canonicalEventTypeSchema).max(32).readonly(),
|
|
1931
1964
|
usageTemporality: usageTemporalitySchema,
|
|
1932
1965
|
/**
|
|
1933
1966
|
* Which accumulator series a `cumulative` report continues — that is, which
|
|
@@ -1946,32 +1979,32 @@ var providerCapabilitiesSchema = z14.strictObject({
|
|
|
1946
1979
|
* Subagent snapshots keep their own series regardless: a delegated agent's
|
|
1947
1980
|
* counter is not a point on the parent session's curve.
|
|
1948
1981
|
*/
|
|
1949
|
-
cumulativeUsageSeries:
|
|
1950
|
-
reportsCachedInput:
|
|
1951
|
-
reportsCacheCreation:
|
|
1982
|
+
cumulativeUsageSeries: z15.enum(["event-scope", "session-lifetime"]).optional(),
|
|
1983
|
+
reportsCachedInput: z15.boolean(),
|
|
1984
|
+
reportsCacheCreation: z15.boolean(),
|
|
1952
1985
|
cacheCreationAccounting: cacheCreationAccountingSchema,
|
|
1953
|
-
reportsReasoningOutput:
|
|
1954
|
-
reportsProviderTotal:
|
|
1955
|
-
reportsCost:
|
|
1956
|
-
emitsSubagentEvents:
|
|
1957
|
-
emitsCompactionEvents:
|
|
1986
|
+
reportsReasoningOutput: z15.boolean(),
|
|
1987
|
+
reportsProviderTotal: z15.boolean(),
|
|
1988
|
+
reportsCost: z15.boolean(),
|
|
1989
|
+
emitsSubagentEvents: z15.boolean(),
|
|
1990
|
+
emitsCompactionEvents: z15.boolean(),
|
|
1958
1991
|
/** True when the provider reads a structured response from stdout. */
|
|
1959
|
-
requiresHookResponse:
|
|
1992
|
+
requiresHookResponse: z15.boolean(),
|
|
1960
1993
|
/** How much of this provider's hook traffic is replay-identifiable. */
|
|
1961
1994
|
deliveryIdentifier: deliveryIdentifierSupportSchema
|
|
1962
1995
|
});
|
|
1963
|
-
var providerHookResponseSchema =
|
|
1996
|
+
var providerHookResponseSchema = z15.strictObject({
|
|
1964
1997
|
/**
|
|
1965
1998
|
* Always 0. A telemetry hook that can fail the host agent is a liability, so
|
|
1966
1999
|
* the type forbids expressing anything else (ADR 0004).
|
|
1967
2000
|
*/
|
|
1968
|
-
exitCode:
|
|
2001
|
+
exitCode: z15.literal(0),
|
|
1969
2002
|
/** Protocol response text. Omit to write nothing at all. */
|
|
1970
|
-
stdout:
|
|
2003
|
+
stdout: z15.string().max(8192).optional(),
|
|
1971
2004
|
/** Non-sensitive diagnostic text for stderr. */
|
|
1972
|
-
stderr:
|
|
2005
|
+
stderr: z15.string().max(8192).optional(),
|
|
1973
2006
|
/** Declares which of the two stdout contracts this response follows. */
|
|
1974
|
-
contract:
|
|
2007
|
+
contract: z15.enum(["silent", "provider-protocol"])
|
|
1975
2008
|
});
|
|
1976
2009
|
var SILENT_HOOK_RESPONSE = Object.freeze({
|
|
1977
2010
|
exitCode: 0,
|
|
@@ -2137,6 +2170,142 @@ var createProviderRegistry = (adapters) => {
|
|
|
2137
2170
|
var createDuplicateAdapterError = (id) => new Error(`duplicate provider adapter id: ${id}`);
|
|
2138
2171
|
var BUILT_IN_PROVIDERS = Object.freeze([]);
|
|
2139
2172
|
|
|
2173
|
+
// src/runtime/target-resolution.ts
|
|
2174
|
+
import * as path from "path";
|
|
2175
|
+
|
|
2176
|
+
// src/privacy/workspace.ts
|
|
2177
|
+
var canonicalizeGitRemote = (remoteUrl) => {
|
|
2178
|
+
const trimmed = remoteUrl.trim();
|
|
2179
|
+
const scpLike = /^([^@/]+)@([^:]+):(.+)$/.exec(trimmed);
|
|
2180
|
+
const withoutScheme = scpLike ? `${scpLike[2] ?? ""}/${scpLike[3] ?? ""}` : trimmed.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//, "").replace(/^[^@/]+@/, "");
|
|
2181
|
+
return withoutScheme.replace(/:\d+\//, "/").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "").toLowerCase();
|
|
2182
|
+
};
|
|
2183
|
+
var keySourceOf = (input) => {
|
|
2184
|
+
switch (input.kind) {
|
|
2185
|
+
case "git-remote":
|
|
2186
|
+
return "git-remote";
|
|
2187
|
+
case "git-root":
|
|
2188
|
+
return "git-root";
|
|
2189
|
+
case "working-directory":
|
|
2190
|
+
return "working-directory";
|
|
2191
|
+
case "explicit":
|
|
2192
|
+
return "explicit";
|
|
2193
|
+
case "unknown":
|
|
2194
|
+
return "unknown";
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
var keyMaterialOf = (input) => {
|
|
2198
|
+
switch (input.kind) {
|
|
2199
|
+
case "git-remote":
|
|
2200
|
+
return canonicalizeGitRemote(input.remoteUrl);
|
|
2201
|
+
case "git-root":
|
|
2202
|
+
case "working-directory":
|
|
2203
|
+
return input.absolutePath.replace(/[/\\]+$/, "");
|
|
2204
|
+
case "explicit":
|
|
2205
|
+
return input.value;
|
|
2206
|
+
case "unknown":
|
|
2207
|
+
return void 0;
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
var deriveWorkspaceIdentity = (privacy, input, labels = {}) => {
|
|
2211
|
+
const keySource = keySourceOf(input);
|
|
2212
|
+
const material = keyMaterialOf(input);
|
|
2213
|
+
const workspaceId = material === void 0 || material === "" ? "unknown:0000000000000000" : privacy.deriveOpaqueId(`workspace/${keySource}`, material);
|
|
2214
|
+
return workspaceIdentitySchema.parse({
|
|
2215
|
+
workspaceId,
|
|
2216
|
+
keySource: material === void 0 || material === "" ? "unknown" : keySource,
|
|
2217
|
+
...labels.repositoryName === void 0 ? {} : { repositoryName: labels.repositoryName.slice(0, 128) },
|
|
2218
|
+
...labels.vcsBranchName === void 0 ? {} : { vcsBranchName: labels.vcsBranchName.slice(0, 128) },
|
|
2219
|
+
...labels.vcsRevisionId === void 0 ? {} : { vcsRevisionId: privacy.deriveOpaqueId("workspace/revision", labels.vcsRevisionId) }
|
|
2220
|
+
});
|
|
2221
|
+
};
|
|
2222
|
+
|
|
2223
|
+
// src/runtime/target-resolution.ts
|
|
2224
|
+
var DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS = 50;
|
|
2225
|
+
var absolutePathsOf = (hint) => {
|
|
2226
|
+
const base = hint.baseDirectory !== void 0 && path.isAbsolute(hint.baseDirectory) ? hint.baseDirectory : void 0;
|
|
2227
|
+
const resolved = [];
|
|
2228
|
+
for (const candidate of hint.paths) {
|
|
2229
|
+
if (path.isAbsolute(candidate)) {
|
|
2230
|
+
resolved.push(path.resolve(candidate));
|
|
2231
|
+
} else if (base !== void 0) {
|
|
2232
|
+
resolved.push(path.resolve(base, candidate));
|
|
2233
|
+
} else {
|
|
2234
|
+
return void 0;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
return resolved;
|
|
2238
|
+
};
|
|
2239
|
+
var resolveHint = async (hint, locator, privacy) => {
|
|
2240
|
+
const paths = absolutePathsOf(hint);
|
|
2241
|
+
if (paths === void 0) {
|
|
2242
|
+
return void 0;
|
|
2243
|
+
}
|
|
2244
|
+
const located = await Promise.all(
|
|
2245
|
+
[...new Set(paths)].map((candidate) => locator.locate(candidate))
|
|
2246
|
+
);
|
|
2247
|
+
const [first] = located;
|
|
2248
|
+
if (first === void 0 || located.some((entry) => entry?.root !== first.root)) {
|
|
2249
|
+
return void 0;
|
|
2250
|
+
}
|
|
2251
|
+
const identity = deriveWorkspaceIdentity(
|
|
2252
|
+
privacy,
|
|
2253
|
+
{ kind: "git-root", absolutePath: first.root },
|
|
2254
|
+
first.branch === void 0 ? {} : { vcsBranchName: first.branch }
|
|
2255
|
+
);
|
|
2256
|
+
if (identity.keySource !== "git-root") {
|
|
2257
|
+
return void 0;
|
|
2258
|
+
}
|
|
2259
|
+
const parsed = workspaceTargetSchema.safeParse({
|
|
2260
|
+
workspaceId: identity.workspaceId,
|
|
2261
|
+
...identity.vcsBranchName === void 0 ? {} : { vcsBranchName: identity.vcsBranchName },
|
|
2262
|
+
source: hint.source
|
|
2263
|
+
});
|
|
2264
|
+
return parsed.success ? parsed.data : void 0;
|
|
2265
|
+
};
|
|
2266
|
+
var resolveEventTargets = async (input) => {
|
|
2267
|
+
const pending = input.events.filter(
|
|
2268
|
+
(event2) => (event2.type === "tool.start" || event2.type === "tool.end") && input.hints.has(event2.eventId)
|
|
2269
|
+
);
|
|
2270
|
+
if (pending.length === 0) {
|
|
2271
|
+
return { events: input.events, resolved: 0, timedOut: false };
|
|
2272
|
+
}
|
|
2273
|
+
const targets = /* @__PURE__ */ new Map();
|
|
2274
|
+
const work = Promise.all(
|
|
2275
|
+
pending.map(async (event2) => {
|
|
2276
|
+
const hint = input.hints.get(event2.eventId);
|
|
2277
|
+
if (hint === void 0) {
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
try {
|
|
2281
|
+
const target = await resolveHint(hint, input.locator, input.privacy);
|
|
2282
|
+
if (target !== void 0) {
|
|
2283
|
+
targets.set(event2.eventId, target);
|
|
2284
|
+
}
|
|
2285
|
+
} catch {
|
|
2286
|
+
}
|
|
2287
|
+
})
|
|
2288
|
+
).then(() => "done");
|
|
2289
|
+
let timer;
|
|
2290
|
+
const deadline = new Promise((resolve3) => {
|
|
2291
|
+
timer = setTimeout(() => resolve3("timeout"), Math.max(0, input.budgetMillis));
|
|
2292
|
+
timer.unref?.();
|
|
2293
|
+
});
|
|
2294
|
+
const finished = await Promise.race([work, deadline]);
|
|
2295
|
+
if (timer !== void 0) {
|
|
2296
|
+
clearTimeout(timer);
|
|
2297
|
+
}
|
|
2298
|
+
const settled = new Map(targets);
|
|
2299
|
+
const events = input.events.map((event2) => {
|
|
2300
|
+
const target = settled.get(event2.eventId);
|
|
2301
|
+
if (target === void 0 || event2.type !== "tool.start" && event2.type !== "tool.end") {
|
|
2302
|
+
return event2;
|
|
2303
|
+
}
|
|
2304
|
+
return { ...event2, target };
|
|
2305
|
+
});
|
|
2306
|
+
return { events, resolved: settled.size, timedOut: finished === "timeout" };
|
|
2307
|
+
};
|
|
2308
|
+
|
|
2140
2309
|
// src/state/async-lock.ts
|
|
2141
2310
|
var LockWaitTimeoutError = class extends Error {
|
|
2142
2311
|
lockKey;
|
|
@@ -2166,7 +2335,7 @@ var withOptionalSessionLock = async (store, sessionId, fn, options) => {
|
|
|
2166
2335
|
};
|
|
2167
2336
|
|
|
2168
2337
|
// src/runtime/hook.ts
|
|
2169
|
-
var usageScopeSchema =
|
|
2338
|
+
var usageScopeSchema = z16.enum(["session", "generation", "subagent"]);
|
|
2170
2339
|
var classifyDurability = (input) => {
|
|
2171
2340
|
if (!input.attempted) {
|
|
2172
2341
|
return "nothing-to-deliver";
|
|
@@ -2705,7 +2874,12 @@ var createOtelHook = (deps) => {
|
|
|
2705
2874
|
);
|
|
2706
2875
|
}
|
|
2707
2876
|
}
|
|
2708
|
-
return {
|
|
2877
|
+
return {
|
|
2878
|
+
kind: "ready",
|
|
2879
|
+
batch: batch2,
|
|
2880
|
+
dropped: screened.dropped,
|
|
2881
|
+
...parsed.targetHints === void 0 ? {} : { targetHints: parsed.targetHints }
|
|
2882
|
+
};
|
|
2709
2883
|
};
|
|
2710
2884
|
let prepared;
|
|
2711
2885
|
try {
|
|
@@ -2750,7 +2924,24 @@ var createOtelHook = (deps) => {
|
|
|
2750
2924
|
if (prepared.kind === "early") {
|
|
2751
2925
|
return prepared.outcome;
|
|
2752
2926
|
}
|
|
2753
|
-
const {
|
|
2927
|
+
const { dropped } = prepared;
|
|
2928
|
+
let batch = prepared.batch;
|
|
2929
|
+
if (!suppress && deps.worktreeLocator !== void 0 && prepared.targetHints !== void 0 && prepared.targetHints.size > 0) {
|
|
2930
|
+
const targeted = await resolveEventTargets({
|
|
2931
|
+
events: batch,
|
|
2932
|
+
hints: prepared.targetHints,
|
|
2933
|
+
locator: deps.worktreeLocator,
|
|
2934
|
+
privacy,
|
|
2935
|
+
budgetMillis: deps.targetResolutionBudgetMillis ?? DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS
|
|
2936
|
+
});
|
|
2937
|
+
batch = targeted.events;
|
|
2938
|
+
if (targeted.timedOut) {
|
|
2939
|
+
logger.debug("worktree target resolution exceeded its budget", {
|
|
2940
|
+
"provider.id": detection.providerId,
|
|
2941
|
+
"target.resolved": targeted.resolved
|
|
2942
|
+
});
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2754
2945
|
let emitted = 0;
|
|
2755
2946
|
let exportRejected = 0;
|
|
2756
2947
|
if (!suppress && batch.length > 0) {
|
|
@@ -2898,11 +3089,129 @@ var buildErrorEvents = (diagnostics, identity, sequenceBase, ids, privacy) => {
|
|
|
2898
3089
|
}
|
|
2899
3090
|
return events;
|
|
2900
3091
|
};
|
|
3092
|
+
|
|
3093
|
+
// src/runtime/git-worktree.ts
|
|
3094
|
+
import { open, stat } from "fs/promises";
|
|
3095
|
+
import * as path2 from "path";
|
|
3096
|
+
var MAX_WORKTREE_WALK_DEPTH = 128;
|
|
3097
|
+
var MAX_GIT_FILE_BYTES = 4096;
|
|
3098
|
+
var MAX_CACHE_ENTRIES = 1024;
|
|
3099
|
+
var DEFAULT_WORKTREE_CACHE_TTL_MILLIS = 5e3;
|
|
3100
|
+
var MAX_BRANCH_NAME_LENGTH = 255;
|
|
3101
|
+
var ABSENT = Object.freeze({ kind: "absent" });
|
|
3102
|
+
var INVALID = Object.freeze({ kind: "invalid" });
|
|
3103
|
+
var readBounded = async (filePath) => {
|
|
3104
|
+
let handle;
|
|
3105
|
+
try {
|
|
3106
|
+
handle = await open(filePath, "r");
|
|
3107
|
+
const buffer = Buffer.alloc(MAX_GIT_FILE_BYTES);
|
|
3108
|
+
const { bytesRead } = await handle.read(buffer, 0, MAX_GIT_FILE_BYTES, 0);
|
|
3109
|
+
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
3110
|
+
} catch {
|
|
3111
|
+
return void 0;
|
|
3112
|
+
} finally {
|
|
3113
|
+
await handle?.close().catch(() => void 0);
|
|
3114
|
+
}
|
|
3115
|
+
};
|
|
3116
|
+
var parseHeadBranch = (head) => {
|
|
3117
|
+
const line = head.split(/\r?\n/, 1)[0]?.trim() ?? "";
|
|
3118
|
+
const match = /^ref:\s*refs\/heads\/(.+)$/.exec(line);
|
|
3119
|
+
const branch = match?.[1];
|
|
3120
|
+
if (branch === void 0 || branch.length === 0 || branch.length > MAX_BRANCH_NAME_LENGTH || // git forbids these in ref names; their presence means this is not one.
|
|
3121
|
+
[...branch].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) || /[ ~^:?*[\\]/.test(branch)) {
|
|
3122
|
+
return void 0;
|
|
3123
|
+
}
|
|
3124
|
+
return branch;
|
|
3125
|
+
};
|
|
3126
|
+
var parseGitDirFile = (content, worktreeRoot) => {
|
|
3127
|
+
const line = content.split(/\r?\n/, 1)[0]?.trim() ?? "";
|
|
3128
|
+
const target = line.startsWith("gitdir:") ? line.slice("gitdir:".length).trim() : void 0;
|
|
3129
|
+
if (target === void 0 || target.length === 0 || target.includes("\0")) {
|
|
3130
|
+
return void 0;
|
|
3131
|
+
}
|
|
3132
|
+
return path2.resolve(worktreeRoot, target);
|
|
3133
|
+
};
|
|
3134
|
+
var probeDirectory = async (directory) => {
|
|
3135
|
+
const dotGit = path2.join(directory, ".git");
|
|
3136
|
+
let info;
|
|
3137
|
+
try {
|
|
3138
|
+
info = await stat(dotGit);
|
|
3139
|
+
} catch {
|
|
3140
|
+
return ABSENT;
|
|
3141
|
+
}
|
|
3142
|
+
let gitDir;
|
|
3143
|
+
if (info.isDirectory()) {
|
|
3144
|
+
gitDir = dotGit;
|
|
3145
|
+
} else if (info.isFile()) {
|
|
3146
|
+
const content = await readBounded(dotGit);
|
|
3147
|
+
gitDir = content === void 0 ? void 0 : parseGitDirFile(content, directory);
|
|
3148
|
+
}
|
|
3149
|
+
if (gitDir === void 0) {
|
|
3150
|
+
return INVALID;
|
|
3151
|
+
}
|
|
3152
|
+
const head = await readBounded(path2.join(gitDir, "HEAD"));
|
|
3153
|
+
if (head === void 0) {
|
|
3154
|
+
return INVALID;
|
|
3155
|
+
}
|
|
3156
|
+
const branch = parseHeadBranch(head);
|
|
3157
|
+
return {
|
|
3158
|
+
kind: "worktree",
|
|
3159
|
+
located: { root: directory, ...branch === void 0 ? {} : { branch } }
|
|
3160
|
+
};
|
|
3161
|
+
};
|
|
3162
|
+
var createFilesystemWorktreeLocator = (options = {}) => {
|
|
3163
|
+
const now = options.monotonicMillis ?? (() => performance.now());
|
|
3164
|
+
const ttl = options.cacheTtlMillis ?? DEFAULT_WORKTREE_CACHE_TTL_MILLIS;
|
|
3165
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3166
|
+
const cachedProbe = (directory) => {
|
|
3167
|
+
const hit = cache.get(directory);
|
|
3168
|
+
const at = now();
|
|
3169
|
+
if (hit !== void 0 && at - hit.at <= ttl) {
|
|
3170
|
+
return hit.probe;
|
|
3171
|
+
}
|
|
3172
|
+
if (cache.size >= MAX_CACHE_ENTRIES) {
|
|
3173
|
+
cache.clear();
|
|
3174
|
+
}
|
|
3175
|
+
const probe = probeDirectory(directory).catch(() => INVALID);
|
|
3176
|
+
cache.set(directory, { at, probe });
|
|
3177
|
+
return probe;
|
|
3178
|
+
};
|
|
3179
|
+
const locate = async (absolutePath) => {
|
|
3180
|
+
try {
|
|
3181
|
+
if (!path2.isAbsolute(absolutePath) || absolutePath.includes("\0")) {
|
|
3182
|
+
return void 0;
|
|
3183
|
+
}
|
|
3184
|
+
let directory = path2.resolve(absolutePath);
|
|
3185
|
+
for (let depth = 0; depth < MAX_WORKTREE_WALK_DEPTH; depth += 1) {
|
|
3186
|
+
const probe = await cachedProbe(directory);
|
|
3187
|
+
if (probe.kind === "worktree") {
|
|
3188
|
+
return probe.located;
|
|
3189
|
+
}
|
|
3190
|
+
if (probe.kind === "invalid") {
|
|
3191
|
+
return void 0;
|
|
3192
|
+
}
|
|
3193
|
+
const parent = path2.dirname(directory);
|
|
3194
|
+
if (parent === directory) {
|
|
3195
|
+
return void 0;
|
|
3196
|
+
}
|
|
3197
|
+
directory = parent;
|
|
3198
|
+
}
|
|
3199
|
+
return void 0;
|
|
3200
|
+
} catch {
|
|
3201
|
+
return void 0;
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
return { locate };
|
|
3205
|
+
};
|
|
2901
3206
|
export {
|
|
3207
|
+
DEFAULT_TARGET_RESOLUTION_BUDGET_MILLIS,
|
|
3208
|
+
DEFAULT_WORKTREE_CACHE_TTL_MILLIS,
|
|
2902
3209
|
LOG_LEVEL_RANK,
|
|
3210
|
+
MAX_WORKTREE_WALK_DEPTH,
|
|
2903
3211
|
appliedDeliverySchema,
|
|
2904
3212
|
classifyDurability,
|
|
2905
3213
|
createDeterministicIdGenerator,
|
|
3214
|
+
createFilesystemWorktreeLocator,
|
|
2906
3215
|
createFixedClock,
|
|
2907
3216
|
createInMemoryStateStore,
|
|
2908
3217
|
createNullLogger,
|
|
@@ -2916,7 +3225,10 @@ export {
|
|
|
2916
3225
|
hostDeliveryIdentity,
|
|
2917
3226
|
isCommittable,
|
|
2918
3227
|
logLevelSchema,
|
|
3228
|
+
parseGitDirFile,
|
|
3229
|
+
parseHeadBranch,
|
|
2919
3230
|
resolveDeliveryIdentity,
|
|
3231
|
+
resolveEventTargets,
|
|
2920
3232
|
stateRecordSchema,
|
|
2921
3233
|
stateValueSchema,
|
|
2922
3234
|
usageScopeSchema
|