@akasecurity/cli 0.9.12 → 0.9.13
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/cli.js +553 -82
- package/extension/background.js +1 -1
- package/extension/bridge.js +1 -0
- package/extension/content.js +1 -1
- package/extension/manifest.json +24 -1
- package/extension/popup.html +9 -0
- package/extension/popup.js +1 -1
- package/extension/tap.js +1 -0
- package/native-host/host.js +919 -142
- package/native-host/scan-worker.js +209 -17
- package/native-host/sync.js +250 -32
- package/package.json +6 -6
- package/web-ui/web-ui/.next/BUILD_ID +1 -1
- package/web-ui/web-ui/.next/app-build-manifest.json +72 -72
- package/web-ui/web-ui/.next/app-path-routes-manifest.json +7 -7
- package/web-ui/web-ui/.next/build-manifest.json +2 -2
- package/web-ui/web-ui/.next/prerender-manifest.json +18 -18
- package/web-ui/web-ui/.next/server/app/(app)/activity/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/activity/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/activity/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/data-shares/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/data-shares/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/data-shares/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/detections/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/detections/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/detections/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/[id]/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/[id]/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/[id]/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/new/page.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/new/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/new/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/page.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/exceptions/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/findings/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/findings/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/findings/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/inventory/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/inventory/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/inventory/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/policies/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/policies/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/policies/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/scan/page.js +3 -3
- package/web-ui/web-ui/.next/server/app/(app)/scan/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/scan/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/security/page.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/security/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/security/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/settings/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/settings/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/settings/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/updates/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/updates/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/updates/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/vault/page.js +2 -2
- package/web-ui/web-ui/.next/server/app/(app)/vault/page.js.nft.json +1 -1
- package/web-ui/web-ui/.next/server/app/(app)/vault/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app/_not-found.html +1 -1
- package/web-ui/web-ui/.next/server/app/_not-found.rsc +2 -2
- package/web-ui/web-ui/.next/server/app/index.html +1 -1
- package/web-ui/web-ui/.next/server/app/index.rsc +2 -2
- package/web-ui/web-ui/.next/server/app/page_client-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/app-paths-manifest.json +7 -7
- package/web-ui/web-ui/.next/server/chunks/121.js +1 -1
- package/web-ui/web-ui/.next/server/chunks/130.js +1026 -0
- package/web-ui/web-ui/.next/server/chunks/290.js +1 -1
- package/web-ui/web-ui/.next/server/chunks/3.js +1017 -0
- package/web-ui/web-ui/.next/server/chunks/300.js +1 -0
- package/web-ui/web-ui/.next/server/chunks/475.js +1 -1
- package/web-ui/web-ui/.next/server/chunks/662.js +1 -0
- package/web-ui/web-ui/.next/server/chunks/70.js +1 -0
- package/web-ui/web-ui/.next/server/functions-config-manifest.json +6 -6
- package/web-ui/web-ui/.next/server/middleware-manifest.json +5 -5
- package/web-ui/web-ui/.next/server/pages/404.html +1 -1
- package/web-ui/web-ui/.next/server/pages/500.html +1 -1
- package/web-ui/web-ui/.next/server/server-reference-manifest.js +1 -1
- package/web-ui/web-ui/.next/server/server-reference-manifest.json +1 -1
- package/web-ui/web-ui/.next/static/chunks/421-cc967c01935826d1.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/activity/{page-a27c8937989448e4.js → page-41fba0354cc950be.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/data-shares/{page-2b805f9e1f995092.js → page-d2e03c3ab61af01a.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/detections/{page-a87cfee370c4e0f4.js → page-566036afcc87e4c9.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/{error-190085728a856072.js → error-4baae46bcee63009.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/exceptions/[id]/{page-4e214491c7be8d43.js → page-73dbcf0078b82ec4.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/exceptions/new/page-8051503193da1baf.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/exceptions/{page-f16ba40d88e414b1.js → page-32c8a853bc8b5d34.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/findings/page-dc8fadb56d6d1e77.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/inventory/page-9b49ef42350ea7bd.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/{layout-cb3c8c7b6b33414c.js → layout-f5f361f817f90ac9.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/policies/{page-ab639e48f60ad7ee.js → page-01b303adf3c8ee56.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/scan/page-8db3b62245c333a3.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/security/{page-a3095119b3e87341.js → page-7a4ba61626e0d130.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/settings/page-0930b49f6ab951bc.js +1 -0
- package/web-ui/web-ui/.next/static/chunks/app/(app)/updates/{page-5b32bd569c9569d9.js → page-9b04f3441a1a3f96.js} +1 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/vault/page-911a76e75f5a1419.js +1 -0
- package/web-ui/web-ui/.next/static/css/298a651f6af38209.css +2 -0
- package/web-ui/web-ui/dist/scan-worker.js +209 -17
- package/web-ui/web-ui/.next/server/chunks/611.js +0 -1015
- package/web-ui/web-ui/.next/server/chunks/7.js +0 -1
- package/web-ui/web-ui/.next/server/chunks/816.js +0 -1
- package/web-ui/web-ui/.next/server/chunks/968.js +0 -1006
- package/web-ui/web-ui/.next/static/chunks/674-d8237c5d0faa4a53.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/exceptions/new/page-c1bb992ee1f12566.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/findings/page-59c76da638f22b0e.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/inventory/page-c37447caf89a86e1.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/scan/page-494614fccc8c62cc.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/settings/page-469613d499e41093.js +0 -1
- package/web-ui/web-ui/.next/static/chunks/app/(app)/vault/page-3152ceb31f024b8d.js +0 -1
- package/web-ui/web-ui/.next/static/css/6e72259eccdf4435.css +0 -2
- /package/web-ui/web-ui/.next/static/{PMeePXfXsQ2xxrXppySG_ → pkVZ1_T311YNkJgZOLTx5}/_buildManifest.js +0 -0
- /package/web-ui/web-ui/.next/static/{PMeePXfXsQ2xxrXppySG_ → pkVZ1_T311YNkJgZOLTx5}/_ssgManifest.js +0 -0
package/native-host/host.js
CHANGED
|
@@ -492,6 +492,7 @@ var require_ignore = __commonJS({
|
|
|
492
492
|
});
|
|
493
493
|
|
|
494
494
|
// src/native-host/host.ts
|
|
495
|
+
import { randomUUID as randomUUID20 } from "crypto";
|
|
495
496
|
import { homedir as homedir3 } from "os";
|
|
496
497
|
|
|
497
498
|
// ../../packages/persistence/src/attached-derived.ts
|
|
@@ -3458,12 +3459,12 @@ var $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
|
3458
3459
|
});
|
|
3459
3460
|
var URL_BAD_FORMAT = 1;
|
|
3460
3461
|
var URL_UNPARSEABLE = 2;
|
|
3461
|
-
function parseURLObject(
|
|
3462
|
-
if (!def.normalize && def.protocol?.source === httpProtocol.source && !/^https?:\/\//i.test(
|
|
3462
|
+
function parseURLObject(trimmed2, def) {
|
|
3463
|
+
if (!def.normalize && def.protocol?.source === httpProtocol.source && !/^https?:\/\//i.test(trimmed2)) {
|
|
3463
3464
|
return URL_BAD_FORMAT;
|
|
3464
3465
|
}
|
|
3465
3466
|
try {
|
|
3466
|
-
return new URL(
|
|
3467
|
+
return new URL(trimmed2);
|
|
3467
3468
|
} catch {
|
|
3468
3469
|
return URL_UNPARSEABLE;
|
|
3469
3470
|
}
|
|
@@ -3484,8 +3485,8 @@ var $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
|
3484
3485
|
$ZodStringFormat.init(inst, def);
|
|
3485
3486
|
inst._zod.check = (payload) => {
|
|
3486
3487
|
try {
|
|
3487
|
-
const
|
|
3488
|
-
const url2 = parseURLObject(
|
|
3488
|
+
const trimmed2 = payload.value.trim();
|
|
3489
|
+
const url2 = parseURLObject(trimmed2, def);
|
|
3489
3490
|
if (url2 === URL_BAD_FORMAT) {
|
|
3490
3491
|
payload.issues.push({
|
|
3491
3492
|
code: "invalid_format",
|
|
@@ -3529,7 +3530,7 @@ var $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
|
3529
3530
|
continue: !def.abort
|
|
3530
3531
|
});
|
|
3531
3532
|
}
|
|
3532
|
-
payload.value = def.normalize ? url2.href : stripTabAndNewline(
|
|
3533
|
+
payload.value = def.normalize ? url2.href : stripTabAndNewline(trimmed2);
|
|
3533
3534
|
return;
|
|
3534
3535
|
} catch (_) {
|
|
3535
3536
|
payload.issues.push({
|
|
@@ -20481,7 +20482,17 @@ var UNPRICEABLE_PROVIDERS = Object.freeze([
|
|
|
20481
20482
|
"gateway",
|
|
20482
20483
|
"unknown",
|
|
20483
20484
|
"cli",
|
|
20484
|
-
"api"
|
|
20485
|
+
"api",
|
|
20486
|
+
// The browser extension's native host records these as `llm_call.provider`
|
|
20487
|
+
// for a web-chat turn — the web tool id, deliberately never the vendor id
|
|
20488
|
+
// (`openai`/`anthropic`) the session root carries. Subscription traffic
|
|
20489
|
+
// burns rate-limit budget, not dollar credits, and listing them here is
|
|
20490
|
+
// what keeps that true structurally: a later maintainer who wants to price
|
|
20491
|
+
// web-chat traffic at API rates has to delete this entry first, and meet
|
|
20492
|
+
// the reason on the way, rather than quietly adding one to
|
|
20493
|
+
// PROVIDER_PLATFORM.
|
|
20494
|
+
"chatgpt",
|
|
20495
|
+
"claude-ai"
|
|
20485
20496
|
]);
|
|
20486
20497
|
function platformForProvider(provider) {
|
|
20487
20498
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
@@ -20624,7 +20635,12 @@ var HARNESS = {
|
|
|
20624
20635
|
ClaudeDesktop: "claudedesktop",
|
|
20625
20636
|
ChatGpt: "chatgpt",
|
|
20626
20637
|
ClaudeAi: "claudeai",
|
|
20627
|
-
Api: "api"
|
|
20638
|
+
Api: "api",
|
|
20639
|
+
// Not a coding assistant a person drives — an in-process SDK embedded in an
|
|
20640
|
+
// application, so it has no IDE/CLI/desktop/web surface of its own. Carries
|
|
20641
|
+
// the same id as its SOURCE_TOOL counterpart, unlike every capture-side tool
|
|
20642
|
+
// whose wire spelling differs from its display spelling.
|
|
20643
|
+
AiTcSdk: "ai-tc-sdk"
|
|
20628
20644
|
};
|
|
20629
20645
|
var Harness = external_exports.enum(HARNESS).meta({ id: "Harness" });
|
|
20630
20646
|
var SOURCE_TOOL = {
|
|
@@ -20640,9 +20656,15 @@ var SOURCE_TOOL = {
|
|
|
20640
20656
|
// whose tool could not be identified both render through the read side's
|
|
20641
20657
|
// miss path rather than as a harness of their own.
|
|
20642
20658
|
Cli: "cli",
|
|
20643
|
-
Unknown: "unknown"
|
|
20659
|
+
Unknown: "unknown",
|
|
20660
|
+
// The wire id an in-process, request-path SDK stamps on its own structural
|
|
20661
|
+
// rows (`request_decision`) — never a capture of prompt/response/tool text,
|
|
20662
|
+
// since the SDK sits in front of a model call rather than inside a coding
|
|
20663
|
+
// assistant's own hook contract.
|
|
20664
|
+
AiTcSdk: "ai-tc-sdk"
|
|
20644
20665
|
};
|
|
20645
20666
|
var SourceTool = external_exports.enum(SOURCE_TOOL).meta({ id: "SourceTool" });
|
|
20667
|
+
var WebSourceTool = SourceTool.extract(["ChatGpt", "ClaudeAi"]);
|
|
20646
20668
|
var TOOL_TO_HARNESS = {
|
|
20647
20669
|
[SOURCE_TOOL.ClaudeCode]: HARNESS.ClaudeCode,
|
|
20648
20670
|
[SOURCE_TOOL.ClaudeDesktop]: HARNESS.ClaudeDesktop,
|
|
@@ -20651,7 +20673,12 @@ var TOOL_TO_HARNESS = {
|
|
|
20651
20673
|
[SOURCE_TOOL.ChatGpt]: HARNESS.ChatGpt,
|
|
20652
20674
|
[SOURCE_TOOL.Codex]: HARNESS.Codex,
|
|
20653
20675
|
[SOURCE_TOOL.Antigravity]: HARNESS.Antigravity,
|
|
20654
|
-
[SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi
|
|
20676
|
+
[SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi,
|
|
20677
|
+
// Wire and display id are the same string here, but the row still belongs:
|
|
20678
|
+
// both vocabularies carry the `AiTcSdk` member, and the join is exactly
|
|
20679
|
+
// their intersection — leaving a shared member out would read as an
|
|
20680
|
+
// uninstrumented tool on both surfaces, which this one is not.
|
|
20681
|
+
[SOURCE_TOOL.AiTcSdk]: HARNESS.AiTcSdk
|
|
20655
20682
|
};
|
|
20656
20683
|
function harnessFromTool(tool) {
|
|
20657
20684
|
return (Object.hasOwn(TOOL_TO_HARNESS, tool) ? TOOL_TO_HARNESS[tool] : void 0) ?? tool;
|
|
@@ -20688,7 +20715,8 @@ var FindingProvider = Harness.extract([
|
|
|
20688
20715
|
"ClaudeAi",
|
|
20689
20716
|
"Codex",
|
|
20690
20717
|
"Antigravity",
|
|
20691
|
-
"Api"
|
|
20718
|
+
"Api",
|
|
20719
|
+
"AiTcSdk"
|
|
20692
20720
|
]).meta({ id: "FindingProvider" });
|
|
20693
20721
|
var FindingCategory = external_exports.enum([
|
|
20694
20722
|
"secret",
|
|
@@ -21065,18 +21093,41 @@ var AuditEventType = external_exports.enum([
|
|
|
21065
21093
|
// 'tool_call' is the reconciler's structural row for every call, while
|
|
21066
21094
|
// 'tool_use' exists only where a hook enforced against the arguments.
|
|
21067
21095
|
"tool_use",
|
|
21068
|
-
// One row per model REFUSAL
|
|
21069
|
-
//
|
|
21070
|
-
//
|
|
21071
|
-
//
|
|
21072
|
-
//
|
|
21073
|
-
//
|
|
21096
|
+
// One row per model REFUSAL, across all four seams a prohibited model can be
|
|
21097
|
+
// stopped at: a switch onto it, a turn already running on it, a subagent
|
|
21098
|
+
// spawn asking for it, or a request-path refusal an embedded request-path
|
|
21099
|
+
// SDK makes in-process before the call leaves the application. Which seam
|
|
21100
|
+
// rides `attributes.refusal_seam`, never this member name. A structural row
|
|
21101
|
+
// like the ones above rather than a capture — it carries the model that was
|
|
21102
|
+
// refused and nothing the user typed, because what is worth recording about
|
|
21103
|
+
// a governance decision is the decision, and prompt text is the thing this
|
|
21104
|
+
// product exists to keep from travelling.
|
|
21074
21105
|
"model_refusal",
|
|
21106
|
+
// One row per request-path DECISION: a policy check an embedded request-path
|
|
21107
|
+
// SDK performs in-process before a model call leaves the application, or
|
|
21108
|
+
// against that call's non-streamed response. A structural row like
|
|
21109
|
+
// 'model_refusal' rather than a capture — content-free in the same way:
|
|
21110
|
+
// which side, which seam, what action and which field are decided rides
|
|
21111
|
+
// `attributes`, never this member name, and the matched text itself never
|
|
21112
|
+
// travels.
|
|
21113
|
+
//
|
|
21114
|
+
// A prohibited-model refusal on the request path is deliberately NOT this
|
|
21115
|
+
// member: it stays 'model_refusal' with `refusal_seam: 'request'`, so it
|
|
21116
|
+
// shares one bucket with the plugin's switch/turn/spawn refusals rather
|
|
21117
|
+
// than splitting one governance concept across two event types. This
|
|
21118
|
+
// member carries every OTHER request-path decision.
|
|
21119
|
+
"request_decision",
|
|
21075
21120
|
// One row per config-inventory scan, hung off the session root. It is the
|
|
21076
21121
|
// fact the posture inspection findings reference (findings require an
|
|
21077
21122
|
// audit_event_id), and its started_at is the "scanned Nm ago" the read
|
|
21078
21123
|
// surface renders.
|
|
21079
|
-
"config_scan"
|
|
21124
|
+
"config_scan",
|
|
21125
|
+
// One row per reported browser-extension capture status, hung off the web
|
|
21126
|
+
// session root. The durable home of what one tab's network interception
|
|
21127
|
+
// is doing — a write-through of the native host's in-memory tracker, so a
|
|
21128
|
+
// second process (aka extension status) and a restarted host both have
|
|
21129
|
+
// somewhere to read it back from.
|
|
21130
|
+
"capture_status"
|
|
21080
21131
|
]).meta({ id: "AuditEventType" });
|
|
21081
21132
|
var AttributeBag = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
21082
21133
|
var HostAttributes = external_exports.object({
|
|
@@ -21236,6 +21287,20 @@ var CaptureAttributes = external_exports.object({
|
|
|
21236
21287
|
// repeated rather than referenced because a store reader opens this file.
|
|
21237
21288
|
redact_degraded_to: ActionTaken.optional()
|
|
21238
21289
|
}).catchall(external_exports.unknown());
|
|
21290
|
+
var CaptureStatusAttributes = external_exports.object({
|
|
21291
|
+
source_tool: external_exports.string().optional(),
|
|
21292
|
+
patched: external_exports.boolean().optional(),
|
|
21293
|
+
live: external_exports.boolean().optional(),
|
|
21294
|
+
blind: external_exports.boolean().optional(),
|
|
21295
|
+
sends_seen_dom: external_exports.number().int().nonnegative().optional(),
|
|
21296
|
+
exchanges_seen_net: external_exports.number().int().nonnegative().optional(),
|
|
21297
|
+
parse_failures: external_exports.number().int().nonnegative().optional(),
|
|
21298
|
+
unparsed_bodies: external_exports.number().int().nonnegative().optional(),
|
|
21299
|
+
shape_misses: external_exports.array(external_exports.string()).optional(),
|
|
21300
|
+
conversation_endpoints: external_exports.number().int().nonnegative().optional(),
|
|
21301
|
+
closed: external_exports.boolean().optional(),
|
|
21302
|
+
enforcement: external_exports.string().optional()
|
|
21303
|
+
}).catchall(external_exports.unknown());
|
|
21239
21304
|
var ToolCallInspection = external_exports.object({
|
|
21240
21305
|
ruleId: external_exports.string().min(1),
|
|
21241
21306
|
ruleName: external_exports.string(),
|
|
@@ -22209,6 +22274,30 @@ var AttachedCredential = external_exports.object({
|
|
|
22209
22274
|
keyPrefix: external_exports.string().min(1).max(16).optional(),
|
|
22210
22275
|
mintedAt: external_exports.iso.datetime().optional()
|
|
22211
22276
|
});
|
|
22277
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
22278
|
+
function unsafeEndpointReason(endpoint) {
|
|
22279
|
+
let parsed2;
|
|
22280
|
+
try {
|
|
22281
|
+
parsed2 = new URL(endpoint);
|
|
22282
|
+
} catch {
|
|
22283
|
+
return "unparseable";
|
|
22284
|
+
}
|
|
22285
|
+
if (parsed2.username !== "" || parsed2.password !== "") return "userinfo";
|
|
22286
|
+
if (parsed2.search !== "" || parsed2.hash !== "") return "query-or-fragment";
|
|
22287
|
+
if (parsed2.protocol === "https:") return null;
|
|
22288
|
+
return parsed2.protocol === "http:" && LOOPBACK_HOSTS.has(parsed2.hostname) ? null : "insecure";
|
|
22289
|
+
}
|
|
22290
|
+
function isSafeEndpoint(endpoint) {
|
|
22291
|
+
return unsafeEndpointReason(endpoint) === null;
|
|
22292
|
+
}
|
|
22293
|
+
function originOnly(endpoint) {
|
|
22294
|
+
try {
|
|
22295
|
+
const parsed2 = new URL(endpoint);
|
|
22296
|
+
return `${parsed2.protocol}//${parsed2.host}`;
|
|
22297
|
+
} catch {
|
|
22298
|
+
return "(unparseable endpoint)";
|
|
22299
|
+
}
|
|
22300
|
+
}
|
|
22212
22301
|
var MAX_DATE_MS = 253402300799999;
|
|
22213
22302
|
var MAX_INT4 = 2147483647;
|
|
22214
22303
|
var StorePosturePack = external_exports.object({
|
|
@@ -22363,6 +22452,11 @@ var RemoteFailureKind = external_exports.enum([
|
|
|
22363
22452
|
"rejected",
|
|
22364
22453
|
"unreachable"
|
|
22365
22454
|
]);
|
|
22455
|
+
var ControlPlaneFailure = RemoteFailureKind.extract([
|
|
22456
|
+
"unauthorized",
|
|
22457
|
+
"forbidden",
|
|
22458
|
+
"unreachable"
|
|
22459
|
+
]);
|
|
22366
22460
|
var AttachDeviceRequest = external_exports.object({
|
|
22367
22461
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22368
22462
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22902,7 +22996,12 @@ var EventMetadata = external_exports.object({
|
|
|
22902
22996
|
// in — set by the browser extension's network capture so a stored `response`
|
|
22903
22997
|
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
22904
22998
|
// on every other capture path, which has no such id.
|
|
22905
|
-
|
|
22999
|
+
//
|
|
23000
|
+
// Non-empty for the reason WebExchange.messageId is: it is the join key, and
|
|
23001
|
+
// a blank one matches no `llm_call` leaf. That refusal reaches only the
|
|
23002
|
+
// places an event is PARSED; the local write path types the event and parses
|
|
23003
|
+
// nothing, which is why `toCaptureAttributes` omits a blank one separately.
|
|
23004
|
+
messageId: external_exports.string().min(1).optional(),
|
|
22906
23005
|
conversationId: external_exports.string().optional(),
|
|
22907
23006
|
// How long THIS capture's inspection blocked its caller, in whole
|
|
22908
23007
|
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
@@ -23749,6 +23848,85 @@ function policyIdIsReversible(policyId) {
|
|
|
23749
23848
|
var DEFAULT_ACTIONS = Object.fromEntries(
|
|
23750
23849
|
DetectionCategory.options.map((c) => [c, builtinPolicyToAction(severityFloorPolicy(c))])
|
|
23751
23850
|
);
|
|
23851
|
+
function ruleCategoryMap(wireRules, localRules, compiledRules) {
|
|
23852
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
23853
|
+
for (const rule of wireRules ?? []) map2.set(rule.id, rule.category);
|
|
23854
|
+
for (const rule of localRules ?? []) map2.set(rule.id, rule.category);
|
|
23855
|
+
for (const rule of compiledRules) map2.set(rule.id, rule.category);
|
|
23856
|
+
return map2;
|
|
23857
|
+
}
|
|
23858
|
+
function policyKey(policy) {
|
|
23859
|
+
return "ruleId" in policy.target ? `rule:${policy.target.ruleId}` : `category:${policy.target.category}`;
|
|
23860
|
+
}
|
|
23861
|
+
function floorFor(policy, categoryByRuleId) {
|
|
23862
|
+
const category = "category" in policy.target ? policy.target.category : categoryByRuleId.get(policy.target.ruleId);
|
|
23863
|
+
return category === void 0 ? null : DEFAULT_ACTIONS[category];
|
|
23864
|
+
}
|
|
23865
|
+
function strongerOf(a, b) {
|
|
23866
|
+
if (a === null) return b;
|
|
23867
|
+
if (b === null) return a;
|
|
23868
|
+
return strongerAction(a, b);
|
|
23869
|
+
}
|
|
23870
|
+
function mergeRaiseOnly(localPolicies, remotePolicies, categoryByRuleId) {
|
|
23871
|
+
const merged = /* @__PURE__ */ new Map();
|
|
23872
|
+
const disabled = [];
|
|
23873
|
+
const remoteCategoryAction = /* @__PURE__ */ new Map();
|
|
23874
|
+
for (const policy of remotePolicies) {
|
|
23875
|
+
if (!policy.enabled) continue;
|
|
23876
|
+
if (!("category" in policy.target)) continue;
|
|
23877
|
+
if (remoteCategoryAction.has(policy.target.category)) continue;
|
|
23878
|
+
const floor = floorFor(policy, categoryByRuleId);
|
|
23879
|
+
remoteCategoryAction.set(
|
|
23880
|
+
policy.target.category,
|
|
23881
|
+
floor !== null && !isActionAtLeast(policy.action, floor) ? floor : policy.action
|
|
23882
|
+
);
|
|
23883
|
+
}
|
|
23884
|
+
for (const policy of localPolicies) {
|
|
23885
|
+
if (!policy.enabled) {
|
|
23886
|
+
disabled.push(policy);
|
|
23887
|
+
continue;
|
|
23888
|
+
}
|
|
23889
|
+
const key = policyKey(policy);
|
|
23890
|
+
if (merged.has(key)) continue;
|
|
23891
|
+
let remoteFloor = null;
|
|
23892
|
+
if ("ruleId" in policy.target) {
|
|
23893
|
+
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
23894
|
+
if (category !== void 0) remoteFloor = remoteCategoryAction.get(category) ?? null;
|
|
23895
|
+
}
|
|
23896
|
+
merged.set(
|
|
23897
|
+
key,
|
|
23898
|
+
remoteFloor !== null && !isActionAtLeast(policy.action, remoteFloor) ? { ...policy, action: remoteFloor } : policy
|
|
23899
|
+
);
|
|
23900
|
+
}
|
|
23901
|
+
const localCategoryAction = /* @__PURE__ */ new Map();
|
|
23902
|
+
for (const policy of merged.values()) {
|
|
23903
|
+
if ("category" in policy.target) localCategoryAction.set(policy.target.category, policy.action);
|
|
23904
|
+
}
|
|
23905
|
+
for (const policy of remotePolicies) {
|
|
23906
|
+
if (!policy.enabled) {
|
|
23907
|
+
disabled.push(policy);
|
|
23908
|
+
continue;
|
|
23909
|
+
}
|
|
23910
|
+
const key = policyKey(policy);
|
|
23911
|
+
const floor = floorFor(policy, categoryByRuleId);
|
|
23912
|
+
let localFloor = null;
|
|
23913
|
+
if ("ruleId" in policy.target) {
|
|
23914
|
+
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
23915
|
+
if (category !== void 0) localFloor = localCategoryAction.get(category) ?? null;
|
|
23916
|
+
}
|
|
23917
|
+
const effectiveFloor = strongerOf(floor, localFloor);
|
|
23918
|
+
const clamped = effectiveFloor !== null && !isActionAtLeast(policy.action, effectiveFloor) ? { ...policy, action: effectiveFloor } : policy;
|
|
23919
|
+
const existing = merged.get(key);
|
|
23920
|
+
if (existing === void 0) {
|
|
23921
|
+
merged.set(key, clamped);
|
|
23922
|
+
continue;
|
|
23923
|
+
}
|
|
23924
|
+
if (actionRank(clamped.action) > actionRank(existing.action)) {
|
|
23925
|
+
merged.set(key, clamped);
|
|
23926
|
+
}
|
|
23927
|
+
}
|
|
23928
|
+
return [...merged.values(), ...disabled];
|
|
23929
|
+
}
|
|
23752
23930
|
var BUILTIN_POLICIES = Object.fromEntries(
|
|
23753
23931
|
KNOWN_BUILTIN_IDS.map((id) => [id, { id, ...BUILTIN_POLICY_SPECS[id] }])
|
|
23754
23932
|
);
|
|
@@ -23979,6 +24157,22 @@ function isHistorySyncConsentValid(consent, endpoint) {
|
|
|
23979
24157
|
if (consent === void 0 || endpoint === void 0) return false;
|
|
23980
24158
|
return consent.payloadVersion === HISTORY_SYNC_PAYLOAD_VERSION && consent.endpoint === endpoint;
|
|
23981
24159
|
}
|
|
24160
|
+
var WEB_CHAT_CAPTURE_CONSENT_VERSION = 1;
|
|
24161
|
+
var WebChatCaptureConsent = external_exports.object({
|
|
24162
|
+
acknowledgedAt: external_exports.iso.datetime(),
|
|
24163
|
+
version: external_exports.number().int().positive()
|
|
24164
|
+
});
|
|
24165
|
+
var WebChatResponseCapture = external_exports.enum(["with-findings", "always", "never"]);
|
|
24166
|
+
var WebChatCapture = external_exports.object({
|
|
24167
|
+
responses: WebChatResponseCapture.default("with-findings"),
|
|
24168
|
+
account: external_exports.boolean().default(false),
|
|
24169
|
+
// Absent until granted. Presence alone does not authorize anything — see
|
|
24170
|
+
// isWebChatCaptureConsentValid.
|
|
24171
|
+
consent: WebChatCaptureConsent.optional()
|
|
24172
|
+
});
|
|
24173
|
+
function isWebChatCaptureConsentValid(consent) {
|
|
24174
|
+
return consent?.version === WEB_CHAT_CAPTURE_CONSENT_VERSION;
|
|
24175
|
+
}
|
|
23982
24176
|
var BODY_RETENTION_DEFAULT_DAYS = 30;
|
|
23983
24177
|
var BodyRetention = external_exports.object({
|
|
23984
24178
|
enabled: external_exports.boolean().default(false),
|
|
@@ -24037,6 +24231,16 @@ var WorkspaceSettings = external_exports.object({
|
|
|
24037
24231
|
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
24038
24232
|
// or an older payload no longer counts.
|
|
24039
24233
|
historySyncConsent: HistorySyncConsent.optional(),
|
|
24234
|
+
// What the browser extension may record from a web chat, and the grant that
|
|
24235
|
+
// authorizes it. Absent until the user answers: recording something that was
|
|
24236
|
+
// never recorded before is never an assumed grant on upgrade, so the whole
|
|
24237
|
+
// block is optional rather than defaulted in. What an absent block means is
|
|
24238
|
+
// webChatCaptureOf's answer, in one place.
|
|
24239
|
+
//
|
|
24240
|
+
// Enforcement is NOT gated on this. A machine that has never answered still
|
|
24241
|
+
// blocks, redacts and warns on what a user sends; the grant covers what is
|
|
24242
|
+
// written down.
|
|
24243
|
+
webChatCapture: WebChatCapture.optional(),
|
|
24040
24244
|
// Local body expiry (see BodyRetention). Off until switched on; expiring a
|
|
24041
24245
|
// body never removes the row or its findings.
|
|
24042
24246
|
bodyRetention: BodyRetention.default({
|
|
@@ -24047,6 +24251,9 @@ var WorkspaceSettings = external_exports.object({
|
|
|
24047
24251
|
function defaultWorkspaceSettings() {
|
|
24048
24252
|
return WorkspaceSettings.parse({});
|
|
24049
24253
|
}
|
|
24254
|
+
function webChatCaptureOf(settings) {
|
|
24255
|
+
return settings.webChatCapture ?? WebChatCapture.parse({});
|
|
24256
|
+
}
|
|
24050
24257
|
function isAttached(settings) {
|
|
24051
24258
|
return settings.runMode === "attached" && settings.controlPlane !== void 0;
|
|
24052
24259
|
}
|
|
@@ -24144,7 +24351,10 @@ function toCaptureAttributes(event) {
|
|
|
24144
24351
|
// `.catchall(z.unknown())` carries the long tail.
|
|
24145
24352
|
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
24146
24353
|
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {},
|
|
24147
|
-
|
|
24354
|
+
// A blank id is omitted rather than stored: it is a join key and `''` joins
|
|
24355
|
+
// nothing. This runs on the local write path, which types the event but
|
|
24356
|
+
// never parses it, so EventMetadata's own `.min(1)` does not reach here.
|
|
24357
|
+
...metadata?.messageId !== void 0 && metadata.messageId !== "" ? { message_id: metadata.messageId } : {},
|
|
24148
24358
|
...metadata?.conversationId !== void 0 ? { conversation_id: metadata.conversationId } : {}
|
|
24149
24359
|
};
|
|
24150
24360
|
}
|
|
@@ -24518,12 +24728,14 @@ var RecommendedActionIdParam = external_exports.object({ id: external_exports.st
|
|
|
24518
24728
|
// ../../packages/schema/src/zod/settings-action.ts
|
|
24519
24729
|
var HistorySyncConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "HistorySyncConsentChoice" });
|
|
24520
24730
|
var ModelJudgeConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "ModelJudgeConsentChoice" });
|
|
24731
|
+
var WebChatCaptureConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "WebChatCaptureConsentChoice" });
|
|
24521
24732
|
var SaveSettingsInput = external_exports.object({
|
|
24522
24733
|
historicalAccess: external_exports.string(),
|
|
24523
24734
|
modelJudgeConsent: ModelJudgeConsentChoice,
|
|
24524
24735
|
historySyncConsent: HistorySyncConsentChoice,
|
|
24525
24736
|
vaultConsent: external_exports.string(),
|
|
24526
24737
|
vaultInlineReveal: external_exports.string(),
|
|
24738
|
+
webChatCaptureConsent: WebChatCaptureConsentChoice,
|
|
24527
24739
|
// Widened to `string` like its neighbours rather than typed as
|
|
24528
24740
|
// `RedactFallback`, on this module's own layering rule: shape here, VALUE at
|
|
24529
24741
|
// the call site, so the domain check receives the type it was written for.
|
|
@@ -24738,11 +24950,24 @@ var WebExchange = external_exports.object({
|
|
|
24738
24950
|
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
24739
24951
|
toolCalls: external_exports.array(WebToolCall).default([]),
|
|
24740
24952
|
// Absent when the adapter recovered no text. Capped by the caller at
|
|
24741
|
-
// RESPONSE_TEXT_MAX_BYTES
|
|
24742
|
-
//
|
|
24953
|
+
// RESPONSE_TEXT_MAX_BYTES, so a short capture is never mistaken for a short
|
|
24954
|
+
// reply.
|
|
24743
24955
|
responseText: external_exports.string().optional(),
|
|
24956
|
+
// The stored text is short of the reply. It does NOT say which of the two
|
|
24957
|
+
// ceilings on this path cut it: the caller applies its own cap on the raw
|
|
24958
|
+
// bytes it reads off the wire, which can be reached by a stream whose
|
|
24959
|
+
// recovered text stays well under RESPONSE_TEXT_MAX_BYTES, and applies that
|
|
24960
|
+
// one to the text. A reader cannot tell them apart, and nothing downstream
|
|
24961
|
+
// should branch as though it could.
|
|
24744
24962
|
truncated: external_exports.boolean().default(false)
|
|
24745
24963
|
});
|
|
24964
|
+
var WebEnforcementState = external_exports.enum([
|
|
24965
|
+
"watching",
|
|
24966
|
+
"composer-only",
|
|
24967
|
+
"button-only",
|
|
24968
|
+
"unattached",
|
|
24969
|
+
"unknown"
|
|
24970
|
+
]);
|
|
24746
24971
|
var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
|
|
24747
24972
|
var WebCaptureStatus = external_exports.object({
|
|
24748
24973
|
patched: external_exports.boolean(),
|
|
@@ -24754,8 +24979,82 @@ var WebCaptureStatus = external_exports.object({
|
|
|
24754
24979
|
unparsedBodies: external_exports.number().int().nonnegative(),
|
|
24755
24980
|
// The adapter-declared JSON key paths that were absent from a real payload —
|
|
24756
24981
|
// the earliest signal that a site's contract moved.
|
|
24757
|
-
shapeMisses: external_exports.array(external_exports.string()).default([])
|
|
24758
|
-
|
|
24982
|
+
shapeMisses: external_exports.array(external_exports.string()).default([]),
|
|
24983
|
+
// How many `kind: 'conversation'` endpoints the reporting tab's adapter
|
|
24984
|
+
// compiled. Zero means this build declares none for the site, so observing
|
|
24985
|
+
// nothing is the design rather than a fault — the one fact that separates a
|
|
24986
|
+
// site nobody has surveyed yet from one whose contract moved. Defaulted so a
|
|
24987
|
+
// build predating the field is read as declaring nothing rather than refused.
|
|
24988
|
+
conversationEndpoints: external_exports.number().int().nonnegative().default(0),
|
|
24989
|
+
// The document that sent this report is going away. The bridge sets it on
|
|
24990
|
+
// its `pagehide` report and nowhere else.
|
|
24991
|
+
//
|
|
24992
|
+
// A property of the REPORT rather than of capture health, which is why
|
|
24993
|
+
// nothing in `deriveWebCaptureState` reads it and why it stays out of the
|
|
24994
|
+
// bridge's own report signature — a closing tab's last word must not be
|
|
24995
|
+
// suppressed for carrying the same health as the report before it. What
|
|
24996
|
+
// reads it is the per-site fold: a document that said it was unloading stops
|
|
24997
|
+
// voting on the site's state, so the reload the `blind` remediation asks for
|
|
24998
|
+
// can actually clear the verdict it was shown. A document that dies without
|
|
24999
|
+
// sending one is covered by CAPTURE_STATUS_DOCUMENT_QUIET_MS instead.
|
|
25000
|
+
//
|
|
25001
|
+
// Defaulted so a build predating the field reads as a document that never
|
|
25002
|
+
// said it was closing — which keeps it voting, the same as every report that
|
|
25003
|
+
// is not a final one.
|
|
25004
|
+
closed: external_exports.boolean().default(false),
|
|
25005
|
+
// What the DOM enforcement path is doing, which none of the counters above
|
|
25006
|
+
// can say: `sendsSeenDom` rises only once a send has COMPLETED, so a tab
|
|
25007
|
+
// whose watcher never bound reports zero exactly like a tab nobody typed in.
|
|
25008
|
+
// Defaulted to 'unknown' rather than 'watching' so a status from a build
|
|
25009
|
+
// predating the field is not read as reporting a healthy one.
|
|
25010
|
+
enforcement: WebEnforcementState.default("unknown")
|
|
25011
|
+
});
|
|
25012
|
+
function webCaptureStatusObservedTurnPath(status) {
|
|
25013
|
+
if (!status.patched) return true;
|
|
25014
|
+
if (status.conversationEndpoints === 0) return true;
|
|
25015
|
+
return status.blind || status.shapeMisses.length > 0 || status.parseFailures > 0 || status.unparsedBodies > 0 || status.exchangesSeenNet > 0;
|
|
25016
|
+
}
|
|
25017
|
+
function pickReportedCaptureStatus(candidates) {
|
|
25018
|
+
return candidates.find((c) => webCaptureStatusObservedTurnPath(c.status)) ?? candidates[0];
|
|
25019
|
+
}
|
|
25020
|
+
var CAPTURE_STATUS_RECENCY_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
25021
|
+
var CAPTURE_STATUS_RECENCY_DAYS = CAPTURE_STATUS_RECENCY_MS / (24 * 60 * 60 * 1e3);
|
|
25022
|
+
var CAPTURE_STATUS_DOCUMENT_QUIET_MS = 12 * 60 * 60 * 1e3;
|
|
25023
|
+
function toCaptureStatusAttributes(status, tool) {
|
|
25024
|
+
return {
|
|
25025
|
+
source_tool: tool,
|
|
25026
|
+
patched: status.patched,
|
|
25027
|
+
live: status.live,
|
|
25028
|
+
blind: status.blind,
|
|
25029
|
+
sends_seen_dom: status.sendsSeenDom,
|
|
25030
|
+
exchanges_seen_net: status.exchangesSeenNet,
|
|
25031
|
+
parse_failures: status.parseFailures,
|
|
25032
|
+
unparsed_bodies: status.unparsedBodies,
|
|
25033
|
+
shape_misses: status.shapeMisses,
|
|
25034
|
+
conversation_endpoints: status.conversationEndpoints,
|
|
25035
|
+
closed: status.closed,
|
|
25036
|
+
enforcement: status.enforcement
|
|
25037
|
+
};
|
|
25038
|
+
}
|
|
25039
|
+
function fromCaptureStatusAttributes(bag) {
|
|
25040
|
+
const parsedBag = CaptureStatusAttributes.safeParse(bag);
|
|
25041
|
+
if (!parsedBag.success) return null;
|
|
25042
|
+
const b = parsedBag.data;
|
|
25043
|
+
const parsedStatus = WebCaptureStatus.safeParse({
|
|
25044
|
+
patched: b.patched,
|
|
25045
|
+
live: b.live,
|
|
25046
|
+
blind: b.blind,
|
|
25047
|
+
sendsSeenDom: b.sends_seen_dom,
|
|
25048
|
+
exchangesSeenNet: b.exchanges_seen_net,
|
|
25049
|
+
parseFailures: b.parse_failures,
|
|
25050
|
+
unparsedBodies: b.unparsed_bodies,
|
|
25051
|
+
shapeMisses: b.shape_misses,
|
|
25052
|
+
conversationEndpoints: b.conversation_endpoints,
|
|
25053
|
+
closed: b.closed,
|
|
25054
|
+
enforcement: b.enforcement
|
|
25055
|
+
});
|
|
25056
|
+
return parsedStatus.success ? parsedStatus.data : null;
|
|
25057
|
+
}
|
|
24759
25058
|
|
|
24760
25059
|
// ../../packages/persistence/src/paths.ts
|
|
24761
25060
|
import {
|
|
@@ -24886,17 +25185,6 @@ function publishByLink(tmp, file2, data) {
|
|
|
24886
25185
|
function controlPlaneCredentialPath(settingsDir2) {
|
|
24887
25186
|
return join2(settingsDir2, ATTACHED_CREDENTIAL_FILENAME);
|
|
24888
25187
|
}
|
|
24889
|
-
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
24890
|
-
function isSafeEndpoint(endpoint) {
|
|
24891
|
-
let parsed2;
|
|
24892
|
-
try {
|
|
24893
|
-
parsed2 = new URL(endpoint);
|
|
24894
|
-
} catch {
|
|
24895
|
-
return false;
|
|
24896
|
-
}
|
|
24897
|
-
if (parsed2.protocol === "https:") return true;
|
|
24898
|
-
return parsed2.protocol === "http:" && LOOPBACK_HOSTS.has(parsed2.hostname);
|
|
24899
|
-
}
|
|
24900
25188
|
function repairOrRefuseMode(file2) {
|
|
24901
25189
|
const link = lstatSync2(file2, { throwIfNoEntry: false });
|
|
24902
25190
|
if (link === void 0) return "absent";
|
|
@@ -26693,7 +26981,7 @@ var SESSION_ROOT = `event_type = 'session'`;
|
|
|
26693
26981
|
var HAS_ACTIVITY = `EXISTS (
|
|
26694
26982
|
SELECT 1 FROM audit_events c
|
|
26695
26983
|
WHERE c.root_session_id = audit_events.id
|
|
26696
|
-
AND c.event_type NOT IN ('hook', 'config_scan'))`;
|
|
26984
|
+
AND c.event_type NOT IN ('hook', 'config_scan', 'capture_status'))`;
|
|
26697
26985
|
var SqliteActivityRepository = class {
|
|
26698
26986
|
constructor(db, now = () => Date.now()) {
|
|
26699
26987
|
this.db = db;
|
|
@@ -26720,10 +27008,10 @@ var SqliteActivityRepository = class {
|
|
|
26720
27008
|
SELECT id FROM audit_events WHERE event_type = 'session' AND started_at >= ?
|
|
26721
27009
|
UNION
|
|
26722
27010
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_started_at
|
|
26723
|
-
WHERE started_at >= ?
|
|
27011
|
+
WHERE started_at >= ? AND event_type <> 'capture_status'
|
|
26724
27012
|
UNION
|
|
26725
27013
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_ended_at
|
|
26726
|
-
WHERE ended_at >= ?)`,
|
|
27014
|
+
WHERE ended_at >= ? AND event_type <> 'capture_status')`,
|
|
26727
27015
|
[liveThreshold, liveThreshold, liveThreshold]
|
|
26728
27016
|
);
|
|
26729
27017
|
const toolCallsToday = countScalar(
|
|
@@ -27130,7 +27418,10 @@ var SqliteAuditEventsRepository = class {
|
|
|
27130
27418
|
attributes = excluded.attributes,
|
|
27131
27419
|
ended_at = excluded.ended_at
|
|
27132
27420
|
WHERE COALESCE(json_extract(excluded.attributes, '$.output_tokens'), 0)
|
|
27133
|
-
> COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)
|
|
27421
|
+
> COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)
|
|
27422
|
+
OR (json_extract(excluded.attributes, '$.usage_source') IS NOT NULL
|
|
27423
|
+
AND json_extract(excluded.attributes, '$.output_tokens') IS NULL
|
|
27424
|
+
AND excluded.attributes <> audit_events.attributes)`
|
|
27134
27425
|
);
|
|
27135
27426
|
this.upsertSessionRootStmt = db.prepare(
|
|
27136
27427
|
`INSERT OR IGNORE INTO audit_events
|
|
@@ -27398,6 +27689,87 @@ var SqliteBodyRetentionRepository = class {
|
|
|
27398
27689
|
}
|
|
27399
27690
|
};
|
|
27400
27691
|
|
|
27692
|
+
// ../../packages/persistence/src/repositories/capture-status.ts
|
|
27693
|
+
var STATUS_LOOKBACK_ROWS = 128;
|
|
27694
|
+
var SqliteCaptureStatusRepository = class {
|
|
27695
|
+
constructor(db) {
|
|
27696
|
+
this.db = db;
|
|
27697
|
+
this.recentStmt = db.prepare(
|
|
27698
|
+
`SELECT a.started_at AS startedAt,
|
|
27699
|
+
a.attributes AS attributes,
|
|
27700
|
+
a.root_session_id AS rootSessionId
|
|
27701
|
+
FROM audit_events a
|
|
27702
|
+
WHERE a.event_type = 'capture_status'
|
|
27703
|
+
AND a.source_tool = ?
|
|
27704
|
+
AND a.started_at >= ?
|
|
27705
|
+
ORDER BY a.started_at DESC, a.id DESC
|
|
27706
|
+
LIMIT ?`
|
|
27707
|
+
);
|
|
27708
|
+
}
|
|
27709
|
+
db;
|
|
27710
|
+
recentStmt;
|
|
27711
|
+
/**
|
|
27712
|
+
* Every document that reported for a site, in registry order by site, from
|
|
27713
|
+
* the last `CAPTURE_STATUS_RECENCY_MS`.
|
|
27714
|
+
*
|
|
27715
|
+
* SEVERAL per site, not one: a browser is many documents and each reports
|
|
27716
|
+
* for itself, so one row per site is a choice about which of them a user
|
|
27717
|
+
* sees — and the newest is the wrong one, since a healthy tab writing a
|
|
27718
|
+
* fresh report would hide a drifting tab's verdict, which is the whole
|
|
27719
|
+
* reason these rows exist. The pick WITHIN a document is made here (the
|
|
27720
|
+
* unchanged `pickReportedCaptureStatus`, over that document's own rows);
|
|
27721
|
+
* choosing between documents belongs where the state semantics live, and
|
|
27722
|
+
* that is `reportedCaptureDocumentForSite` in `@akasecurity/detections` —
|
|
27723
|
+
* this package may not import it.
|
|
27724
|
+
*
|
|
27725
|
+
* `now` is a required argument rather than a `Date.now()` read, so a caller
|
|
27726
|
+
* that already holds a render instant passes THAT one and a test can drive
|
|
27727
|
+
* the window without moving the wall clock.
|
|
27728
|
+
*
|
|
27729
|
+
* A site whose reports have all aged out contributes nothing, so it derives
|
|
27730
|
+
* to `unreported`. That is the point: nothing but the browser extension ever
|
|
27731
|
+
* writes these rows, so an uninstalled extension's last verdict would
|
|
27732
|
+
* otherwise stand as a live claim for ever with no later report able to
|
|
27733
|
+
* clear it.
|
|
27734
|
+
*/
|
|
27735
|
+
latest(now) {
|
|
27736
|
+
const since = now - CAPTURE_STATUS_RECENCY_MS;
|
|
27737
|
+
const documents = [];
|
|
27738
|
+
for (const tool of WebSourceTool.options) {
|
|
27739
|
+
const rows = /* @__PURE__ */ new Map();
|
|
27740
|
+
const lastWord = /* @__PURE__ */ new Map();
|
|
27741
|
+
for (const row of allRows(this.recentStmt, [
|
|
27742
|
+
tool,
|
|
27743
|
+
since,
|
|
27744
|
+
STATUS_LOOKBACK_ROWS
|
|
27745
|
+
])) {
|
|
27746
|
+
const status = fromCaptureStatusAttributes(parseJsonObject(row.attributes));
|
|
27747
|
+
if (status === null) continue;
|
|
27748
|
+
const record2 = { tool, observedAt: epochMillisToIso(row.startedAt), status };
|
|
27749
|
+
const group = rows.get(row.rootSessionId);
|
|
27750
|
+
if (group === void 0) {
|
|
27751
|
+
rows.set(row.rootSessionId, [record2]);
|
|
27752
|
+
lastWord.set(row.rootSessionId, { at: record2.observedAt, closed: status.closed });
|
|
27753
|
+
} else {
|
|
27754
|
+
group.push(record2);
|
|
27755
|
+
}
|
|
27756
|
+
}
|
|
27757
|
+
for (const [root, candidates] of rows) {
|
|
27758
|
+
const picked = pickReportedCaptureStatus(candidates);
|
|
27759
|
+
const last = lastWord.get(root);
|
|
27760
|
+
if (picked === void 0 || last === void 0) continue;
|
|
27761
|
+
documents.push({
|
|
27762
|
+
...picked,
|
|
27763
|
+
...root === null ? {} : { rootSessionId: root },
|
|
27764
|
+
lastReportAt: last.at,
|
|
27765
|
+
closed: last.closed
|
|
27766
|
+
});
|
|
27767
|
+
}
|
|
27768
|
+
}
|
|
27769
|
+
return documents;
|
|
27770
|
+
}
|
|
27771
|
+
};
|
|
27772
|
+
|
|
27401
27773
|
// ../../packages/persistence/src/repositories/classified-data.ts
|
|
27402
27774
|
var SqliteClassifiedDataRepository = class {
|
|
27403
27775
|
constructor(db) {
|
|
@@ -32975,6 +33347,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
32975
33347
|
activity: new SqliteActivityRepository(db),
|
|
32976
33348
|
sourceProject: new SqliteSourceProjectRepository(db),
|
|
32977
33349
|
auditEvents: new SqliteAuditEventsRepository(db),
|
|
33350
|
+
captureStatus: new SqliteCaptureStatusRepository(db),
|
|
32978
33351
|
classifiedData: new SqliteClassifiedDataRepository(db),
|
|
32979
33352
|
inspectionDefinitions: new SqliteInspectionDefinitionsRepository(db),
|
|
32980
33353
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
@@ -33015,6 +33388,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
33015
33388
|
activity,
|
|
33016
33389
|
sourceProject,
|
|
33017
33390
|
auditEvents,
|
|
33391
|
+
captureStatus,
|
|
33018
33392
|
classifiedData,
|
|
33019
33393
|
inspectionDefinitions,
|
|
33020
33394
|
inspectionFindings,
|
|
@@ -33232,6 +33606,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
33232
33606
|
activity,
|
|
33233
33607
|
sourceProject,
|
|
33234
33608
|
auditEvents,
|
|
33609
|
+
captureStatus,
|
|
33235
33610
|
classifiedData,
|
|
33236
33611
|
inspectionDefinitions,
|
|
33237
33612
|
inspectionFindings,
|
|
@@ -33274,12 +33649,12 @@ function trimSlashes(path) {
|
|
|
33274
33649
|
return path.slice(start, end);
|
|
33275
33650
|
}
|
|
33276
33651
|
function canonicalGitUrl(url2) {
|
|
33277
|
-
const
|
|
33278
|
-
if (DOS_DRIVE.test(
|
|
33279
|
-
const scheme = SCHEME_FORM.exec(
|
|
33280
|
-
const scp = scheme === null ? SCP_FORM.exec(
|
|
33652
|
+
const trimmed2 = url2.trim();
|
|
33653
|
+
if (DOS_DRIVE.test(trimmed2) || FILE_URL.test(trimmed2)) return trimmed2;
|
|
33654
|
+
const scheme = SCHEME_FORM.exec(trimmed2);
|
|
33655
|
+
const scp = scheme === null ? SCP_FORM.exec(trimmed2) : null;
|
|
33281
33656
|
const host = (scheme?.[1] ?? scp?.[1])?.toLowerCase();
|
|
33282
|
-
if (host === void 0) return
|
|
33657
|
+
if (host === void 0) return trimmed2;
|
|
33283
33658
|
const path = (scheme === null ? scp?.[2] : scheme[2]) ?? "";
|
|
33284
33659
|
const bare = trimSlashes(path);
|
|
33285
33660
|
const cleaned = bare.endsWith(GIT_SUFFIX) ? bare.slice(0, -GIT_SUFFIX.length) : bare;
|
|
@@ -33457,11 +33832,6 @@ function fingerprintValue(key, raw) {
|
|
|
33457
33832
|
// ../../packages/persistence/src/forward-health.ts
|
|
33458
33833
|
import { readFileSync as readFileSync7 } from "fs";
|
|
33459
33834
|
import { join as join9 } from "path";
|
|
33460
|
-
var FAILURES = /* @__PURE__ */ new Set([
|
|
33461
|
-
"unauthorized",
|
|
33462
|
-
"forbidden",
|
|
33463
|
-
"unreachable"
|
|
33464
|
-
]);
|
|
33465
33835
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
33466
33836
|
function parseForwardHealth(raw, nowMs) {
|
|
33467
33837
|
try {
|
|
@@ -33470,7 +33840,8 @@ function parseForwardHealth(raw, nowMs) {
|
|
|
33470
33840
|
const record2 = parsed2;
|
|
33471
33841
|
const failures = typeof record2.consecutiveFailures === "number" && record2.consecutiveFailures >= 0 ? record2.consecutiveFailures : 0;
|
|
33472
33842
|
const openedAtMs = typeof record2.openedAtMs === "number" && Number.isFinite(record2.openedAtMs) && record2.openedAtMs <= nowMs ? record2.openedAtMs : null;
|
|
33473
|
-
const
|
|
33843
|
+
const parsedFailure = ControlPlaneFailure.safeParse(record2.lastFailure);
|
|
33844
|
+
const lastFailure = parsedFailure.success ? parsedFailure.data : null;
|
|
33474
33845
|
return { consecutiveFailures: failures, openedAtMs, lastFailure };
|
|
33475
33846
|
} catch {
|
|
33476
33847
|
return null;
|
|
@@ -33560,6 +33931,12 @@ var RemoteRequestInvalid = class extends Error {
|
|
|
33560
33931
|
}
|
|
33561
33932
|
cause;
|
|
33562
33933
|
};
|
|
33934
|
+
var RemoteEndpointRefused = class extends Error {
|
|
33935
|
+
constructor(endpoint) {
|
|
33936
|
+
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
33937
|
+
this.name = "RemoteEndpointRefused";
|
|
33938
|
+
}
|
|
33939
|
+
};
|
|
33563
33940
|
var RemoteResponseInvalid = class extends Error {
|
|
33564
33941
|
constructor(route, detail) {
|
|
33565
33942
|
super(`control plane answered ${route} with ${detail}`);
|
|
@@ -33712,14 +34089,15 @@ function parsed(schema, body, route) {
|
|
|
33712
34089
|
}
|
|
33713
34090
|
return result.data;
|
|
33714
34091
|
}
|
|
33715
|
-
function
|
|
34092
|
+
function resolveBaseUrl(endpoint) {
|
|
34093
|
+
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
33716
34094
|
let end = endpoint.length;
|
|
33717
34095
|
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
33718
34096
|
return endpoint.slice(0, end);
|
|
33719
34097
|
}
|
|
33720
34098
|
var SLASH2 = "/".charCodeAt(0);
|
|
33721
34099
|
function createRemoteClient(options) {
|
|
33722
|
-
const base =
|
|
34100
|
+
const base = resolveBaseUrl(options.endpoint);
|
|
33723
34101
|
const url2 = (route) => `${base}${route}`;
|
|
33724
34102
|
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
33725
34103
|
const sendOne = async (event) => {
|
|
@@ -33849,6 +34227,7 @@ function classifyRemoteFailure(err) {
|
|
|
33849
34227
|
case "RemoteRouteAbsent":
|
|
33850
34228
|
return "route-absent";
|
|
33851
34229
|
case "RemoteRequestInvalid":
|
|
34230
|
+
case "RemoteEndpointRefused":
|
|
33852
34231
|
return "invalid-request";
|
|
33853
34232
|
case "RemoteResponseInvalid":
|
|
33854
34233
|
return "rejected";
|
|
@@ -34786,8 +35165,8 @@ function isCorroborated(candidate, candidates, text) {
|
|
|
34786
35165
|
"label",
|
|
34787
35166
|
req,
|
|
34788
35167
|
() => labels.map((label) => {
|
|
34789
|
-
const
|
|
34790
|
-
return
|
|
35168
|
+
const trimmed2 = label.trim();
|
|
35169
|
+
return trimmed2.length === 0 ? void 0 : new RegExp(`(?<![A-Za-z0-9])${escapeRegExp2(trimmed2)}(?![A-Za-z0-9])`, "i");
|
|
34791
35170
|
})
|
|
34792
35171
|
)) {
|
|
34793
35172
|
if (re?.test(haystack)) return true;
|
|
@@ -35047,6 +35426,96 @@ function whole(command) {
|
|
|
35047
35426
|
return { start: 0, end: command.length };
|
|
35048
35427
|
}
|
|
35049
35428
|
|
|
35429
|
+
// ../../packages/detections/src/posture/web-capture-posture.ts
|
|
35430
|
+
var RULE_VERSION2 = "1";
|
|
35431
|
+
var DRIFT_MIN_PARSE_FAILURES = 2;
|
|
35432
|
+
var WEB_CAPTURE_DRIFT_STATES = /* @__PURE__ */ new Set([
|
|
35433
|
+
"blind",
|
|
35434
|
+
"degraded"
|
|
35435
|
+
]);
|
|
35436
|
+
var WEB_CAPTURE_DRIFT_RULE = {
|
|
35437
|
+
ruleId: "web-capture-drift",
|
|
35438
|
+
version: RULE_VERSION2,
|
|
35439
|
+
name: "Web chat capture is not reading the site",
|
|
35440
|
+
category: "config",
|
|
35441
|
+
severity: "medium",
|
|
35442
|
+
definition: JSON.stringify({
|
|
35443
|
+
kind: "web-capture-drift",
|
|
35444
|
+
states: [...WEB_CAPTURE_DRIFT_STATES],
|
|
35445
|
+
minParseFailures: DRIFT_MIN_PARSE_FAILURES
|
|
35446
|
+
})
|
|
35447
|
+
};
|
|
35448
|
+
function deriveWebCaptureState(status) {
|
|
35449
|
+
if (status === void 0) return "unreported";
|
|
35450
|
+
if (status.conversationEndpoints === 0) return "standby";
|
|
35451
|
+
if (!status.patched) return "unpatched";
|
|
35452
|
+
if (status.blind) return "blind";
|
|
35453
|
+
if (status.shapeMisses.length > 0) return "degraded";
|
|
35454
|
+
if (status.parseFailures >= DRIFT_MIN_PARSE_FAILURES) return "degraded";
|
|
35455
|
+
return status.live ? "active" : "idle";
|
|
35456
|
+
}
|
|
35457
|
+
var STATE_SEVERITY = {
|
|
35458
|
+
blind: 0,
|
|
35459
|
+
degraded: 1,
|
|
35460
|
+
unpatched: 2,
|
|
35461
|
+
idle: 3,
|
|
35462
|
+
standby: 4,
|
|
35463
|
+
active: 5,
|
|
35464
|
+
unreported: 6
|
|
35465
|
+
};
|
|
35466
|
+
function worseThan(a, b) {
|
|
35467
|
+
const sa = STATE_SEVERITY[deriveWebCaptureState(a.status)];
|
|
35468
|
+
const sb = STATE_SEVERITY[deriveWebCaptureState(b.status)];
|
|
35469
|
+
if (sa !== sb) return sa < sb;
|
|
35470
|
+
if (a.observedAt !== b.observedAt) return a.observedAt > b.observedAt;
|
|
35471
|
+
return (a.rootSessionId ?? "") > (b.rootSessionId ?? "");
|
|
35472
|
+
}
|
|
35473
|
+
function reportedCaptureDocumentForSite(documents) {
|
|
35474
|
+
let newestReport = "";
|
|
35475
|
+
for (const d of documents) if (d.lastReportAt > newestReport) newestReport = d.lastReportAt;
|
|
35476
|
+
const retired = (d) => {
|
|
35477
|
+
if (d.closed) return true;
|
|
35478
|
+
const behind = Date.parse(newestReport) - Date.parse(d.lastReportAt);
|
|
35479
|
+
return Number.isFinite(behind) && behind > CAPTURE_STATUS_DOCUMENT_QUIET_MS;
|
|
35480
|
+
};
|
|
35481
|
+
const voting = documents.filter((d) => !retired(d));
|
|
35482
|
+
const tested = voting.some((d) => webCaptureStatusObservedTurnPath(d.status));
|
|
35483
|
+
const pool = tested ? voting : documents;
|
|
35484
|
+
let worst;
|
|
35485
|
+
for (const d of pool) if (worst === void 0 || worseThan(d, worst)) worst = d;
|
|
35486
|
+
return worst;
|
|
35487
|
+
}
|
|
35488
|
+
var STATIC_COPY = {
|
|
35489
|
+
active: { headline: "turns are being observed on this site" },
|
|
35490
|
+
unreported: {
|
|
35491
|
+
// Says "recently" rather than "yet": the store read is bounded to
|
|
35492
|
+
// CAPTURE_STATUS_RECENCY_MS, so this state covers a site nothing has ever
|
|
35493
|
+
// reported for AND one whose last report has aged out. The two are the
|
|
35494
|
+
// same fact to a reader — nobody has confirmed anything lately — and the
|
|
35495
|
+
// copy may not claim the stronger of them.
|
|
35496
|
+
headline: `no report in the last ${String(CAPTURE_STATUS_RECENCY_DAYS)} days \u2014 open the site in Chrome with the extension loaded`
|
|
35497
|
+
},
|
|
35498
|
+
standby: {
|
|
35499
|
+
headline: "this build declares no endpoints for the site, so nothing is observed yet"
|
|
35500
|
+
},
|
|
35501
|
+
unpatched: {
|
|
35502
|
+
// Says what the flags say and no more. `patched` is false both for a tap
|
|
35503
|
+
// that installed and hooked neither transport and for one that never ran
|
|
35504
|
+
// at all — a page reports the same status either way, so the copy may not
|
|
35505
|
+
// assert one of them.
|
|
35506
|
+
headline: "the page tap captured neither fetch nor XHR \u2014 it may not have installed; reload the extension at chrome://extensions"
|
|
35507
|
+
},
|
|
35508
|
+
idle: { headline: "watching; no turn has been observed yet" },
|
|
35509
|
+
blind: {
|
|
35510
|
+
headline: "messages were sent in the page that the network capture never saw",
|
|
35511
|
+
remediation: "reload the tab. If it persists after `aka update` and reloading the extension at chrome://extensions, the site's send path has changed and needs a new extension build."
|
|
35512
|
+
},
|
|
35513
|
+
degraded: {
|
|
35514
|
+
headline: "the site's payloads no longer carry the fields the extension reads",
|
|
35515
|
+
remediation: "run `aka update`, then reload the extension at chrome://extensions. If it stays degraded after an update, the site's contract has changed and needs a new extension build."
|
|
35516
|
+
}
|
|
35517
|
+
};
|
|
35518
|
+
|
|
35050
35519
|
// ../../packages/detections/src/security/redos-probe.ts
|
|
35051
35520
|
var BUDGET_MS = 100;
|
|
35052
35521
|
var EXPONENTIAL_UNITS = [
|
|
@@ -37545,8 +38014,8 @@ function collectUserClaudeJson(scan2, path, cwd, repoIdentity) {
|
|
|
37545
38014
|
}
|
|
37546
38015
|
function projectEntryFor(projects, cwd) {
|
|
37547
38016
|
const candidates = /* @__PURE__ */ new Set([cwd]);
|
|
37548
|
-
const
|
|
37549
|
-
if (
|
|
38017
|
+
const trimmed2 = cwd.replace(/\/+$/, "");
|
|
38018
|
+
if (trimmed2.length > 0) candidates.add(trimmed2);
|
|
37550
38019
|
try {
|
|
37551
38020
|
candidates.add(realpathSync2(cwd));
|
|
37552
38021
|
} catch {
|
|
@@ -37623,8 +38092,8 @@ function memoryConfigFile(scan2, path, scope, kind) {
|
|
|
37623
38092
|
if (!entry) return;
|
|
37624
38093
|
const raw = readOptional(path);
|
|
37625
38094
|
if (raw !== void 0) {
|
|
37626
|
-
const
|
|
37627
|
-
const lines =
|
|
38095
|
+
const trimmed2 = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
|
|
38096
|
+
const lines = trimmed2 === "" ? 0 : trimmed2.split("\n").length;
|
|
37628
38097
|
entry.detail = `${String(lines)} lines`;
|
|
37629
38098
|
}
|
|
37630
38099
|
scan2.configFiles.push(entry);
|
|
@@ -37866,6 +38335,9 @@ function str2(value) {
|
|
|
37866
38335
|
function offersMaintenance(gateway, member) {
|
|
37867
38336
|
return typeof gateway[member] === "function";
|
|
37868
38337
|
}
|
|
38338
|
+
function offersCaptureStatusReader(gateway) {
|
|
38339
|
+
return typeof gateway.readCaptureStatuses === "function";
|
|
38340
|
+
}
|
|
37869
38341
|
|
|
37870
38342
|
// ../../packages/plugin-sdk/src/events.ts
|
|
37871
38343
|
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
@@ -39205,86 +39677,10 @@ function createForwardPolicy(deps) {
|
|
|
39205
39677
|
}
|
|
39206
39678
|
|
|
39207
39679
|
// ../../packages/plugin-runtime/src/attached/gateway.ts
|
|
39208
|
-
|
|
39209
|
-
|
|
39210
|
-
|
|
39211
|
-
return
|
|
39212
|
-
}
|
|
39213
|
-
function ruleCategoryMap(wireRules, localRules) {
|
|
39214
|
-
const map2 = /* @__PURE__ */ new Map();
|
|
39215
|
-
for (const rule of wireRules ?? []) map2.set(rule.id, rule.category);
|
|
39216
|
-
for (const rule of localRules ?? []) map2.set(rule.id, rule.category);
|
|
39217
|
-
for (const pack of bundledDetections()) {
|
|
39218
|
-
for (const rule of pack.rules) map2.set(rule.id, rule.category);
|
|
39219
|
-
}
|
|
39220
|
-
return map2;
|
|
39221
|
-
}
|
|
39222
|
-
function policyKey(policy) {
|
|
39223
|
-
return "ruleId" in policy.target ? `rule:${policy.target.ruleId}` : `category:${policy.target.category}`;
|
|
39224
|
-
}
|
|
39225
|
-
function floorFor(policy, categoryByRuleId) {
|
|
39226
|
-
const category = "category" in policy.target ? policy.target.category : categoryByRuleId.get(policy.target.ruleId);
|
|
39227
|
-
return category === void 0 ? null : DEFAULT_ACTIONS[category];
|
|
39228
|
-
}
|
|
39229
|
-
function mergeRaiseOnly(localPolicies, remotePolicies, categoryByRuleId) {
|
|
39230
|
-
const merged = /* @__PURE__ */ new Map();
|
|
39231
|
-
const disabled = [];
|
|
39232
|
-
const remoteCategoryAction = /* @__PURE__ */ new Map();
|
|
39233
|
-
for (const policy of remotePolicies) {
|
|
39234
|
-
if (!policy.enabled) continue;
|
|
39235
|
-
if (!("category" in policy.target)) continue;
|
|
39236
|
-
if (remoteCategoryAction.has(policy.target.category)) continue;
|
|
39237
|
-
const floor = floorFor(policy, categoryByRuleId);
|
|
39238
|
-
remoteCategoryAction.set(
|
|
39239
|
-
policy.target.category,
|
|
39240
|
-
floor !== null && !isActionAtLeast(policy.action, floor) ? floor : policy.action
|
|
39241
|
-
);
|
|
39242
|
-
}
|
|
39243
|
-
for (const policy of localPolicies) {
|
|
39244
|
-
if (!policy.enabled) {
|
|
39245
|
-
disabled.push(policy);
|
|
39246
|
-
continue;
|
|
39247
|
-
}
|
|
39248
|
-
const key = policyKey(policy);
|
|
39249
|
-
if (merged.has(key)) continue;
|
|
39250
|
-
let remoteFloor = null;
|
|
39251
|
-
if ("ruleId" in policy.target) {
|
|
39252
|
-
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
39253
|
-
if (category !== void 0) remoteFloor = remoteCategoryAction.get(category) ?? null;
|
|
39254
|
-
}
|
|
39255
|
-
merged.set(
|
|
39256
|
-
key,
|
|
39257
|
-
remoteFloor !== null && !isActionAtLeast(policy.action, remoteFloor) ? { ...policy, action: remoteFloor } : policy
|
|
39258
|
-
);
|
|
39259
|
-
}
|
|
39260
|
-
const localCategoryAction = /* @__PURE__ */ new Map();
|
|
39261
|
-
for (const policy of merged.values()) {
|
|
39262
|
-
if ("category" in policy.target) localCategoryAction.set(policy.target.category, policy.action);
|
|
39263
|
-
}
|
|
39264
|
-
for (const policy of remotePolicies) {
|
|
39265
|
-
if (!policy.enabled) {
|
|
39266
|
-
disabled.push(policy);
|
|
39267
|
-
continue;
|
|
39268
|
-
}
|
|
39269
|
-
const key = policyKey(policy);
|
|
39270
|
-
const floor = floorFor(policy, categoryByRuleId);
|
|
39271
|
-
let localFloor = null;
|
|
39272
|
-
if ("ruleId" in policy.target) {
|
|
39273
|
-
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
39274
|
-
if (category !== void 0) localFloor = localCategoryAction.get(category) ?? null;
|
|
39275
|
-
}
|
|
39276
|
-
const effectiveFloor = strongerOf(floor, localFloor);
|
|
39277
|
-
const clamped = effectiveFloor !== null && !isActionAtLeast(policy.action, effectiveFloor) ? { ...policy, action: effectiveFloor } : policy;
|
|
39278
|
-
const existing = merged.get(key);
|
|
39279
|
-
if (existing === void 0) {
|
|
39280
|
-
merged.set(key, clamped);
|
|
39281
|
-
continue;
|
|
39282
|
-
}
|
|
39283
|
-
if (actionRank(clamped.action) > actionRank(existing.action)) {
|
|
39284
|
-
merged.set(key, clamped);
|
|
39285
|
-
}
|
|
39286
|
-
}
|
|
39287
|
-
return [...merged.values(), ...disabled];
|
|
39680
|
+
var bundledRulesFlatCache;
|
|
39681
|
+
function bundledRulesFlat() {
|
|
39682
|
+
bundledRulesFlatCache ??= bundledDetections().flatMap((pack) => pack.rules);
|
|
39683
|
+
return bundledRulesFlatCache;
|
|
39288
39684
|
}
|
|
39289
39685
|
var AttachedDataGateway = class {
|
|
39290
39686
|
constructor(deps) {
|
|
@@ -39604,6 +40000,9 @@ var AttachedDataGateway = class {
|
|
|
39604
40000
|
async readSessionProvider(sessionId) {
|
|
39605
40001
|
return this.deps.local.readSessionProvider(sessionId);
|
|
39606
40002
|
}
|
|
40003
|
+
async readCaptureStatuses() {
|
|
40004
|
+
return this.deps.local.readCaptureStatuses();
|
|
40005
|
+
}
|
|
39607
40006
|
async facets() {
|
|
39608
40007
|
return this.deps.local.facets();
|
|
39609
40008
|
}
|
|
@@ -39686,7 +40085,7 @@ var AttachedDataGateway = class {
|
|
|
39686
40085
|
policies: mergeRaiseOnly(
|
|
39687
40086
|
local.policies,
|
|
39688
40087
|
cached2.policies,
|
|
39689
|
-
ruleCategoryMap(cached2.rules, local.rules)
|
|
40088
|
+
ruleCategoryMap(cached2.rules, local.rules, bundledRulesFlat())
|
|
39690
40089
|
),
|
|
39691
40090
|
customKeywords: [...local.customKeywords, ...cached2.customKeywords],
|
|
39692
40091
|
// TAKEN FROM THE CACHE, unlike the two fields below — and the asymmetry
|
|
@@ -39911,10 +40310,15 @@ import { join as join27 } from "path";
|
|
|
39911
40310
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
39912
40311
|
import { rename as rename2 } from "fs/promises";
|
|
39913
40312
|
var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
39914
|
-
var
|
|
40313
|
+
var IMMEDIATE_RETRIES = 8;
|
|
40314
|
+
var TIMED_RETRIES = 4;
|
|
40315
|
+
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
39915
40316
|
var delay = (ms) => new Promise((resolve2) => {
|
|
39916
40317
|
setTimeout(resolve2, ms);
|
|
39917
40318
|
});
|
|
40319
|
+
var yieldToLoop = () => new Promise((resolve2) => {
|
|
40320
|
+
setImmediate(resolve2);
|
|
40321
|
+
});
|
|
39918
40322
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
39919
40323
|
for (let attempt = 1; ; attempt += 1) {
|
|
39920
40324
|
try {
|
|
@@ -39923,7 +40327,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
39923
40327
|
} catch (err) {
|
|
39924
40328
|
const code = err.code;
|
|
39925
40329
|
if (attempt >= ATTEMPTS || code === void 0 || !RETRYABLE.has(code)) throw err;
|
|
39926
|
-
await delay(attempt * 10);
|
|
40330
|
+
await (attempt <= IMMEDIATE_RETRIES ? yieldToLoop() : delay((attempt - IMMEDIATE_RETRIES) * 10));
|
|
39927
40331
|
}
|
|
39928
40332
|
}
|
|
39929
40333
|
}
|
|
@@ -40431,6 +40835,9 @@ var StandaloneDataGateway = class {
|
|
|
40431
40835
|
readSessionProvider(sessionId) {
|
|
40432
40836
|
return Promise.resolve(this.db.auditEvents.sessionProvider(sessionId));
|
|
40433
40837
|
}
|
|
40838
|
+
readCaptureStatuses() {
|
|
40839
|
+
return Promise.resolve(this.db.captureStatus.latest(Date.now()));
|
|
40840
|
+
}
|
|
40434
40841
|
facets() {
|
|
40435
40842
|
return Promise.resolve(this.db.facets());
|
|
40436
40843
|
}
|
|
@@ -40915,8 +41322,120 @@ function buildSessionRoot(sessionId, input2, ctx, resolved, provider, branch) {
|
|
|
40915
41322
|
var name = "@akasecurity/plugin-browser-extension";
|
|
40916
41323
|
var version2 = "0.9.4";
|
|
40917
41324
|
|
|
41325
|
+
// src/native-host/exchange.ts
|
|
41326
|
+
var MAX_TARGET_LEN = 500;
|
|
41327
|
+
var truncateTarget = (s) => s.length > MAX_TARGET_LEN ? `${s.slice(0, MAX_TARGET_LEN)}\u2026` : s;
|
|
41328
|
+
var TARGET_SCAN_MAX_BYTES = 64 * 1024;
|
|
41329
|
+
var MAX_TOOL_CALLS = 256;
|
|
41330
|
+
function cutToBytes(text, maxBytes) {
|
|
41331
|
+
const bytes = new TextEncoder().encode(text);
|
|
41332
|
+
if (bytes.byteLength <= maxBytes) return { text, truncated: false };
|
|
41333
|
+
let end = maxBytes;
|
|
41334
|
+
while (end > 0 && ((bytes[end] ?? 0) & 192) === 128) end -= 1;
|
|
41335
|
+
return { text: new TextDecoder().decode(bytes.subarray(0, end)), truncated: true };
|
|
41336
|
+
}
|
|
41337
|
+
function capResponseText(exchange, maxBytes = RESPONSE_TEXT_MAX_BYTES) {
|
|
41338
|
+
if (exchange.responseText === void 0) return exchange;
|
|
41339
|
+
const cut = cutToBytes(exchange.responseText, maxBytes);
|
|
41340
|
+
return {
|
|
41341
|
+
...exchange,
|
|
41342
|
+
responseText: cut.text,
|
|
41343
|
+
// OR, never assign: a text already marked truncated upstream (the tap's
|
|
41344
|
+
// raw-byte cut, or the bridge's own text cut) must stay truncated even
|
|
41345
|
+
// when this cut has nothing left to do.
|
|
41346
|
+
truncated: exchange.truncated || cut.truncated
|
|
41347
|
+
};
|
|
41348
|
+
}
|
|
41349
|
+
function trimmed(value) {
|
|
41350
|
+
if (value === void 0) return void 0;
|
|
41351
|
+
const t = value.trim();
|
|
41352
|
+
return t === "" ? void 0 : t;
|
|
41353
|
+
}
|
|
41354
|
+
function setNum(attrs, key, value) {
|
|
41355
|
+
if (typeof value === "number" && Number.isFinite(value)) attrs[key] = value;
|
|
41356
|
+
}
|
|
41357
|
+
function toLlmCallInput(exchange, sessionId, tool) {
|
|
41358
|
+
const messageId = trimmed(exchange.messageId);
|
|
41359
|
+
if (messageId === void 0) return null;
|
|
41360
|
+
const attrs = { provider: tool, message_id: messageId };
|
|
41361
|
+
const model = trimmed(exchange.model);
|
|
41362
|
+
if (model !== void 0) attrs.model = model;
|
|
41363
|
+
if (exchange.usageSource === "site") {
|
|
41364
|
+
setNum(attrs, "input_tokens", exchange.usage?.inputTokens);
|
|
41365
|
+
setNum(attrs, "output_tokens", exchange.usage?.outputTokens);
|
|
41366
|
+
setNum(attrs, "cache_read_input_tokens", exchange.usage?.cacheReadInputTokens);
|
|
41367
|
+
setNum(attrs, "cache_creation_input_tokens", exchange.usage?.cacheCreationInputTokens);
|
|
41368
|
+
} else if (exchange.usageSource === "estimated") {
|
|
41369
|
+
setNum(attrs, "estimated_input_tokens", exchange.usage?.inputTokens);
|
|
41370
|
+
setNum(attrs, "estimated_output_tokens", exchange.usage?.outputTokens);
|
|
41371
|
+
}
|
|
41372
|
+
attrs.usage_source = exchange.usageSource;
|
|
41373
|
+
const stopReason = trimmed(exchange.stopReason);
|
|
41374
|
+
if (stopReason !== void 0) attrs.stop_reason = stopReason;
|
|
41375
|
+
const conversationId = trimmed(exchange.conversationId);
|
|
41376
|
+
if (conversationId !== void 0) {
|
|
41377
|
+
attrs.run_key = conversationId;
|
|
41378
|
+
attrs.site_conversation_id = conversationId;
|
|
41379
|
+
}
|
|
41380
|
+
if (exchange.turnIndex !== void 0) attrs.turn_index = exchange.turnIndex;
|
|
41381
|
+
if (exchange.truncated) attrs.response_truncated = true;
|
|
41382
|
+
return {
|
|
41383
|
+
sessionId,
|
|
41384
|
+
messageId,
|
|
41385
|
+
parentId: sessionId,
|
|
41386
|
+
rootSessionId: sessionId,
|
|
41387
|
+
startedAt: exchange.startedAt,
|
|
41388
|
+
attributes: attrs
|
|
41389
|
+
};
|
|
41390
|
+
}
|
|
41391
|
+
function toToolCallInputs(exchange, sessionId, scanTarget) {
|
|
41392
|
+
const conversationId = trimmed(exchange.conversationId);
|
|
41393
|
+
const seen = /* @__PURE__ */ new Set();
|
|
41394
|
+
const inputs = [];
|
|
41395
|
+
const toolCalls = exchange.toolCalls ?? [];
|
|
41396
|
+
for (const tc of toolCalls.slice(0, MAX_TOOL_CALLS)) {
|
|
41397
|
+
const toolUseId = trimmed(tc.toolUseId);
|
|
41398
|
+
if (toolUseId === void 0) continue;
|
|
41399
|
+
if (seen.has(toolUseId)) continue;
|
|
41400
|
+
seen.add(toolUseId);
|
|
41401
|
+
const attrs = { tool_use_id: toolUseId };
|
|
41402
|
+
const toolName = trimmed(tc.toolName);
|
|
41403
|
+
if (toolName !== void 0) attrs.tool_name = toolName;
|
|
41404
|
+
let inspections = [];
|
|
41405
|
+
if (tc.target !== void 0) {
|
|
41406
|
+
const { masked, findings } = scanTarget(cutToBytes(tc.target, TARGET_SCAN_MAX_BYTES).text);
|
|
41407
|
+
if (masked !== "") attrs.target = truncateTarget(masked);
|
|
41408
|
+
inspections = findings.map((f) => ({
|
|
41409
|
+
ruleId: f.ruleId,
|
|
41410
|
+
ruleName: f.ruleName,
|
|
41411
|
+
ruleVersion: f.ruleVersion,
|
|
41412
|
+
category: f.category,
|
|
41413
|
+
severity: f.severity,
|
|
41414
|
+
span: f.span,
|
|
41415
|
+
maskedMatch: f.maskedMatch,
|
|
41416
|
+
actionTaken: "log",
|
|
41417
|
+
confidence: f.confidence
|
|
41418
|
+
}));
|
|
41419
|
+
}
|
|
41420
|
+
if (tc.isError !== void 0) attrs.is_error = tc.isError;
|
|
41421
|
+
if (tc.inputSize !== void 0) attrs.input_size = tc.inputSize;
|
|
41422
|
+
if (tc.outputSize !== void 0) attrs.output_size = tc.outputSize;
|
|
41423
|
+
if (conversationId !== void 0) attrs.run_key = conversationId;
|
|
41424
|
+
inputs.push({
|
|
41425
|
+
sessionId,
|
|
41426
|
+
toolUseId,
|
|
41427
|
+
parentId: sessionId,
|
|
41428
|
+
rootSessionId: sessionId,
|
|
41429
|
+
startedAt: exchange.startedAt,
|
|
41430
|
+
attributes: attrs,
|
|
41431
|
+
inspections
|
|
41432
|
+
});
|
|
41433
|
+
}
|
|
41434
|
+
return inputs;
|
|
41435
|
+
}
|
|
41436
|
+
|
|
40918
41437
|
// src/native-host/protocol.ts
|
|
40919
|
-
var WEB_SOURCE_TOOLS =
|
|
41438
|
+
var WEB_SOURCE_TOOLS = WebSourceTool.options;
|
|
40920
41439
|
function isWebSourceTool(value) {
|
|
40921
41440
|
return WEB_SOURCE_TOOLS.includes(value);
|
|
40922
41441
|
}
|
|
@@ -40932,6 +41451,16 @@ function isHostRequest(value) {
|
|
|
40932
41451
|
return typeof v.sessionId === "string" && isWebSourceTool(v.tool) && typeof v.hostname === "string";
|
|
40933
41452
|
case "capture":
|
|
40934
41453
|
return typeof v.sessionId === "string" && isWebSourceTool(v.tool) && isEventKind(v.kind) && typeof v.text === "string";
|
|
41454
|
+
// A successful safeParse proves the payload is ACCEPTABLE, not that the
|
|
41455
|
+
// narrowed object carries the schema's defaults — `toolCalls` and
|
|
41456
|
+
// `truncated` are `.default(...)`, and a guard does not rewrite its input.
|
|
41457
|
+
// The handler re-parses and reads `parsed.data`; nothing may read
|
|
41458
|
+
// `request.exchange` / `request.status` directly.
|
|
41459
|
+
case "exchange":
|
|
41460
|
+
return typeof v.sessionId === "string" && isWebSourceTool(v.tool) && WebExchange.safeParse(v.exchange).success;
|
|
41461
|
+
case "capture_status":
|
|
41462
|
+
return typeof v.sessionId === "string" && isWebSourceTool(v.tool) && WebCaptureStatus.safeParse(v.status).success;
|
|
41463
|
+
case "capture_state":
|
|
40935
41464
|
case "ping":
|
|
40936
41465
|
case "health":
|
|
40937
41466
|
return true;
|
|
@@ -40978,7 +41507,60 @@ var WEB_TOOL_TO_SOURCE = {
|
|
|
40978
41507
|
[SOURCE_TOOL.ChatGpt]: SOURCE_TOOL.ChatGpt,
|
|
40979
41508
|
[SOURCE_TOOL.ClaudeAi]: SOURCE_TOOL.ClaudeAi
|
|
40980
41509
|
};
|
|
41510
|
+
var WEB_SOURCE_TOOLS2 = Object.keys(WEB_TOOL_TO_SOURCE);
|
|
40981
41511
|
var PLUGIN_BUILD = { package: name, version: version2 };
|
|
41512
|
+
var MAX_TRACKED_SESSIONS = 32;
|
|
41513
|
+
var captureStatuses = /* @__PURE__ */ new Map();
|
|
41514
|
+
function readCaptureStatus(sessionId) {
|
|
41515
|
+
return captureStatuses.get(sessionId);
|
|
41516
|
+
}
|
|
41517
|
+
function recordCaptureStatus(sessionId, record2) {
|
|
41518
|
+
captureStatuses.delete(sessionId);
|
|
41519
|
+
captureStatuses.set(sessionId, record2);
|
|
41520
|
+
while (captureStatuses.size > MAX_TRACKED_SESSIONS) {
|
|
41521
|
+
const oldest = captureStatuses.keys().next().value;
|
|
41522
|
+
if (oldest === void 0) break;
|
|
41523
|
+
captureStatuses.delete(oldest);
|
|
41524
|
+
}
|
|
41525
|
+
}
|
|
41526
|
+
function trackedFor(tool) {
|
|
41527
|
+
return [...captureStatuses.entries()].filter(([, record2]) => record2.tool === tool).map(([sessionId, record2]) => ({
|
|
41528
|
+
tool: record2.tool,
|
|
41529
|
+
observedAt: record2.observedAt,
|
|
41530
|
+
status: record2.status,
|
|
41531
|
+
rootSessionId: sessionId,
|
|
41532
|
+
// One entry per session and every report overwrites it, so this IS the
|
|
41533
|
+
// document's last word — there is no older row here to pick between.
|
|
41534
|
+
lastReportAt: record2.observedAt,
|
|
41535
|
+
closed: record2.status.closed
|
|
41536
|
+
}));
|
|
41537
|
+
}
|
|
41538
|
+
function mergeCaptureDocuments(stored, tracked) {
|
|
41539
|
+
const byDocument = /* @__PURE__ */ new Map();
|
|
41540
|
+
for (const document of [...stored, ...tracked]) {
|
|
41541
|
+
const group = byDocument.get(document.rootSessionId);
|
|
41542
|
+
if (group === void 0) byDocument.set(document.rootSessionId, [document]);
|
|
41543
|
+
else group.push(document);
|
|
41544
|
+
}
|
|
41545
|
+
const merged = [];
|
|
41546
|
+
for (const group of byDocument.values()) {
|
|
41547
|
+
const ordered = [...group].sort(
|
|
41548
|
+
(a, b) => a.observedAt < b.observedAt ? 1 : a.observedAt > b.observedAt ? -1 : 0
|
|
41549
|
+
);
|
|
41550
|
+
const picked = pickReportedCaptureStatus(ordered);
|
|
41551
|
+
if (picked === void 0) continue;
|
|
41552
|
+
let lastReportAt = picked.lastReportAt;
|
|
41553
|
+
let closed = picked.closed;
|
|
41554
|
+
for (const document of group) {
|
|
41555
|
+
if (document.lastReportAt > lastReportAt) {
|
|
41556
|
+
lastReportAt = document.lastReportAt;
|
|
41557
|
+
closed = document.closed;
|
|
41558
|
+
}
|
|
41559
|
+
}
|
|
41560
|
+
merged.push({ ...picked, lastReportAt, closed });
|
|
41561
|
+
}
|
|
41562
|
+
return merged;
|
|
41563
|
+
}
|
|
40982
41564
|
function resolveWebProvider(tool) {
|
|
40983
41565
|
return () => tool === "chatgpt" ? { provider: "openai" } : { provider: "anthropic" };
|
|
40984
41566
|
}
|
|
@@ -41053,6 +41635,200 @@ async function handleRequest(request, configForTool = defaultConfigForTool) {
|
|
|
41053
41635
|
...result.blockedReferences ? { blockedReferences: result.blockedReferences } : {}
|
|
41054
41636
|
};
|
|
41055
41637
|
}
|
|
41638
|
+
case "exchange": {
|
|
41639
|
+
const config2 = configForTool(request.tool);
|
|
41640
|
+
const webChat = webChatCaptureOf(config2.settings);
|
|
41641
|
+
if (!isWebChatCaptureConsentValid(webChat.consent)) {
|
|
41642
|
+
return {
|
|
41643
|
+
type: "exchange",
|
|
41644
|
+
requestId: request.requestId,
|
|
41645
|
+
ok: true,
|
|
41646
|
+
accepted: false,
|
|
41647
|
+
skipped: "no-consent",
|
|
41648
|
+
llmCalls: 0,
|
|
41649
|
+
toolCalls: 0,
|
|
41650
|
+
ruleIds: []
|
|
41651
|
+
};
|
|
41652
|
+
}
|
|
41653
|
+
const parsed2 = WebExchange.safeParse(request.exchange);
|
|
41654
|
+
if (!parsed2.success) {
|
|
41655
|
+
return {
|
|
41656
|
+
type: "error",
|
|
41657
|
+
requestId: request.requestId,
|
|
41658
|
+
ok: false,
|
|
41659
|
+
message: "malformed exchange payload"
|
|
41660
|
+
};
|
|
41661
|
+
}
|
|
41662
|
+
const exchange = capResponseText(parsed2.data);
|
|
41663
|
+
const llm = toLlmCallInput(exchange, request.sessionId, request.tool);
|
|
41664
|
+
let llmCalls = 0;
|
|
41665
|
+
let toolCalls = 0;
|
|
41666
|
+
if (llm !== null) {
|
|
41667
|
+
let gateway;
|
|
41668
|
+
try {
|
|
41669
|
+
gateway = resolveDataGateway(config2);
|
|
41670
|
+
await gateway.recordAuditEvent({
|
|
41671
|
+
id: request.sessionId,
|
|
41672
|
+
eventType: "session",
|
|
41673
|
+
startedAt: exchange.startedAt
|
|
41674
|
+
});
|
|
41675
|
+
await gateway.recordLlmCall(llm);
|
|
41676
|
+
llmCalls = 1;
|
|
41677
|
+
let ruleVersions;
|
|
41678
|
+
try {
|
|
41679
|
+
ruleVersions = (await gateway.getPolicyBundle()).ruleVersions;
|
|
41680
|
+
} catch {
|
|
41681
|
+
ruleVersions = void 0;
|
|
41682
|
+
}
|
|
41683
|
+
const tools = toToolCallInputs(
|
|
41684
|
+
exchange,
|
|
41685
|
+
request.sessionId,
|
|
41686
|
+
(text2) => scanText(text2, ruleVersions)
|
|
41687
|
+
);
|
|
41688
|
+
if (tools.length > 0) {
|
|
41689
|
+
await gateway.recordToolCalls(tools);
|
|
41690
|
+
toolCalls = tools.length;
|
|
41691
|
+
}
|
|
41692
|
+
} catch {
|
|
41693
|
+
} finally {
|
|
41694
|
+
await gateway?.close();
|
|
41695
|
+
}
|
|
41696
|
+
}
|
|
41697
|
+
const text = exchange.responseText;
|
|
41698
|
+
let responseAction = {};
|
|
41699
|
+
let ruleIds = [];
|
|
41700
|
+
const model = llm === null ? trimmed(exchange.model) : llm.attributes.model;
|
|
41701
|
+
const conversationId = llm === null ? trimmed(exchange.conversationId) : llm.attributes.site_conversation_id;
|
|
41702
|
+
if (text !== void 0 && text.length > 0 && webChat.responses !== "never") {
|
|
41703
|
+
const result = await handleCapture(
|
|
41704
|
+
{
|
|
41705
|
+
kind: "response",
|
|
41706
|
+
sourceTool: WEB_TOOL_TO_SOURCE[request.tool],
|
|
41707
|
+
text,
|
|
41708
|
+
occurredAt: exchange.startedAt,
|
|
41709
|
+
metadata: {
|
|
41710
|
+
sessionId: request.sessionId,
|
|
41711
|
+
...model !== void 0 ? { model } : {},
|
|
41712
|
+
// Omitted for an unkeyable exchange rather than blanked: this is
|
|
41713
|
+
// correlation metadata, and an empty id correlates to nothing
|
|
41714
|
+
// while reading as an id that exists.
|
|
41715
|
+
...llm !== null ? { messageId: llm.messageId } : {},
|
|
41716
|
+
...conversationId !== void 0 ? { conversationId } : {},
|
|
41717
|
+
...exchange.turnIndex !== void 0 ? { turnIndex: exchange.turnIndex } : {}
|
|
41718
|
+
}
|
|
41719
|
+
},
|
|
41720
|
+
config2,
|
|
41721
|
+
// No rewritable: false. Nothing about a response is rewritable in
|
|
41722
|
+
// the sense that field means (a host input it must not mutate) —
|
|
41723
|
+
// saying so here would degrade a resolved redact to
|
|
41724
|
+
// settings.redactFallback, trading a meaningless decision for a
|
|
41725
|
+
// real leak at rest. No dedupe, no preAuthorizedGrantIds either.
|
|
41726
|
+
{ persist: webChat.responses === "always" ? "always" : "with-findings" }
|
|
41727
|
+
);
|
|
41728
|
+
responseAction = { responseAction: result.action };
|
|
41729
|
+
ruleIds = [...new Set(result.findings.map((f) => f.ruleId))];
|
|
41730
|
+
}
|
|
41731
|
+
return {
|
|
41732
|
+
type: "exchange",
|
|
41733
|
+
requestId: request.requestId,
|
|
41734
|
+
ok: true,
|
|
41735
|
+
// `accepted` is about the LEAVES, which an unkeyable exchange writes
|
|
41736
|
+
// none of — the response capture above may still have recorded a
|
|
41737
|
+
// finding, which `ruleIds` and `responseAction` report either way.
|
|
41738
|
+
accepted: llm !== null,
|
|
41739
|
+
...llm === null ? { skipped: "unkeyable" } : {},
|
|
41740
|
+
llmCalls,
|
|
41741
|
+
toolCalls,
|
|
41742
|
+
...responseAction,
|
|
41743
|
+
ruleIds
|
|
41744
|
+
};
|
|
41745
|
+
}
|
|
41746
|
+
case "capture_status": {
|
|
41747
|
+
const config2 = configForTool(request.tool);
|
|
41748
|
+
const webChat = webChatCaptureOf(config2.settings);
|
|
41749
|
+
if (!isWebChatCaptureConsentValid(webChat.consent)) {
|
|
41750
|
+
return {
|
|
41751
|
+
type: "capture_status",
|
|
41752
|
+
requestId: request.requestId,
|
|
41753
|
+
ok: true,
|
|
41754
|
+
accepted: false,
|
|
41755
|
+
skipped: "no-consent"
|
|
41756
|
+
};
|
|
41757
|
+
}
|
|
41758
|
+
const parsed2 = WebCaptureStatus.safeParse(request.status);
|
|
41759
|
+
if (!parsed2.success) {
|
|
41760
|
+
return {
|
|
41761
|
+
type: "error",
|
|
41762
|
+
requestId: request.requestId,
|
|
41763
|
+
ok: false,
|
|
41764
|
+
message: "malformed capture status payload"
|
|
41765
|
+
};
|
|
41766
|
+
}
|
|
41767
|
+
const observedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
41768
|
+
recordCaptureStatus(request.sessionId, {
|
|
41769
|
+
tool: request.tool,
|
|
41770
|
+
status: parsed2.data,
|
|
41771
|
+
observedAt
|
|
41772
|
+
});
|
|
41773
|
+
const gateway = resolveDataGateway(config2);
|
|
41774
|
+
try {
|
|
41775
|
+
await gateway.recordAuditEvent({
|
|
41776
|
+
id: randomUUID20(),
|
|
41777
|
+
eventType: "capture_status",
|
|
41778
|
+
startedAt: observedAt,
|
|
41779
|
+
parentId: request.sessionId,
|
|
41780
|
+
rootSessionId: request.sessionId,
|
|
41781
|
+
attributes: toCaptureStatusAttributes(parsed2.data, request.tool)
|
|
41782
|
+
});
|
|
41783
|
+
} catch {
|
|
41784
|
+
} finally {
|
|
41785
|
+
await gateway.close();
|
|
41786
|
+
}
|
|
41787
|
+
return { type: "capture_status", requestId: request.requestId, ok: true, accepted: true };
|
|
41788
|
+
}
|
|
41789
|
+
case "capture_state": {
|
|
41790
|
+
const config2 = configForTool(void 0);
|
|
41791
|
+
const webChat = webChatCaptureOf(config2.settings);
|
|
41792
|
+
let stored = [];
|
|
41793
|
+
let gateway;
|
|
41794
|
+
try {
|
|
41795
|
+
gateway = resolveDataGateway(config2);
|
|
41796
|
+
if (offersCaptureStatusReader(gateway)) stored = await gateway.readCaptureStatuses();
|
|
41797
|
+
} catch {
|
|
41798
|
+
stored = [];
|
|
41799
|
+
} finally {
|
|
41800
|
+
await gateway?.close();
|
|
41801
|
+
}
|
|
41802
|
+
const sites = WEB_SOURCE_TOOLS2.map((tool) => {
|
|
41803
|
+
const record2 = reportedCaptureDocumentForSite(
|
|
41804
|
+
mergeCaptureDocuments(
|
|
41805
|
+
stored.filter((s) => s.tool === tool),
|
|
41806
|
+
trackedFor(tool)
|
|
41807
|
+
)
|
|
41808
|
+
);
|
|
41809
|
+
return {
|
|
41810
|
+
tool,
|
|
41811
|
+
state: deriveWebCaptureState(record2?.status),
|
|
41812
|
+
...record2 !== void 0 ? { enforcement: record2.status.enforcement, observedAt: record2.observedAt } : {}
|
|
41813
|
+
};
|
|
41814
|
+
});
|
|
41815
|
+
return {
|
|
41816
|
+
type: "capture_state",
|
|
41817
|
+
requestId: request.requestId,
|
|
41818
|
+
ok: true,
|
|
41819
|
+
consented: isWebChatCaptureConsentValid(webChat.consent),
|
|
41820
|
+
sites
|
|
41821
|
+
};
|
|
41822
|
+
}
|
|
41823
|
+
default: {
|
|
41824
|
+
const unrecognized = request;
|
|
41825
|
+
return {
|
|
41826
|
+
type: "error",
|
|
41827
|
+
requestId: unrecognized.requestId,
|
|
41828
|
+
ok: false,
|
|
41829
|
+
message: `unsupported request type: ${unrecognized.type}`
|
|
41830
|
+
};
|
|
41831
|
+
}
|
|
41056
41832
|
}
|
|
41057
41833
|
}
|
|
41058
41834
|
async function runHost(stdin, stdout, configForTool = defaultConfigForTool) {
|
|
@@ -41092,5 +41868,6 @@ main().catch(() => {
|
|
|
41092
41868
|
});
|
|
41093
41869
|
export {
|
|
41094
41870
|
handleRequest,
|
|
41871
|
+
readCaptureStatus,
|
|
41095
41872
|
runHost
|
|
41096
41873
|
};
|