@akasecurity/ai-tc-codex 0.9.17-beta.1 → 0.9.17
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/.codex-plugin/plugin.json +1 -1
- package/package.json +4 -4
- package/scripts/apply-suppressions.js +61 -11
- package/scripts/backfill.js +162 -25
- package/scripts/content-retention.js +20 -1
- package/scripts/filescan.js +162 -25
- package/scripts/firstrun.js +62 -11
- package/scripts/history-sync.js +27 -1
- package/scripts/intro.js +18 -1
- package/scripts/onboard.js +61 -11
- package/scripts/post-tool-use.js +211 -33
- package/scripts/pre-tool-use.js +193 -26
- package/scripts/query.js +62 -11
- package/scripts/reconcile.js +62 -11
- package/scripts/remediate.js +162 -25
- package/scripts/scan-worker.js +50 -1
- package/scripts/session-start.js +84 -19
- package/scripts/start-light.js +50 -1
- package/scripts/stop.js +51 -1
- package/scripts/sync.js +162 -25
- package/scripts/user-prompt-submit.js +254 -86
|
@@ -21684,6 +21684,11 @@ var CaptureAttributes = external_exports.object({
|
|
|
21684
21684
|
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
21685
21685
|
// repeated rather than referenced because a store reader opens this file.
|
|
21686
21686
|
redact_degraded_to: ActionTaken.optional(),
|
|
21687
|
+
// Why a capture has no content and no findings: its field was refused
|
|
21688
|
+
// because its bounded scan did not finish (see EventMetadata.scanIncomplete,
|
|
21689
|
+
// whose value this is). Absent on every capture that was scanned, so a
|
|
21690
|
+
// reader can tell a refused row from an empty clean one.
|
|
21691
|
+
scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
|
|
21687
21692
|
// The scope key this capture was stamped with: the canonical repository
|
|
21688
21693
|
// (`host/owner/repo`) of the path the capture names (a relative path is read
|
|
21689
21694
|
// against its working directory), else of its own working directory, or a
|
|
@@ -23025,7 +23030,19 @@ var EventMetadata = external_exports.object({
|
|
|
23025
23030
|
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
23026
23031
|
// Closing either means moving the reason onto the finding row, which
|
|
23027
23032
|
// already carries its own action.
|
|
23028
|
-
redactDegradedTo: ActionTaken.optional()
|
|
23033
|
+
redactDegradedTo: ActionTaken.optional(),
|
|
23034
|
+
// Set when this capture's field was REFUSED rather than scanned: a hook
|
|
23035
|
+
// bounds the scan of a large field (see `LargeInputScanOptions` in
|
|
23036
|
+
// @akasecurity/plugin-sdk), and a scan that did not finish blocks the
|
|
23037
|
+
// field instead of letting it through unscanned.
|
|
23038
|
+
//
|
|
23039
|
+
// - 'timeout': the bounded scan ran out of time.
|
|
23040
|
+
// - 'unavailable': no worker could run it.
|
|
23041
|
+
//
|
|
23042
|
+
// A refused row stores '' as its content and has no findings, which is
|
|
23043
|
+
// exactly what a clean, empty capture looks like — this marker is the only
|
|
23044
|
+
// thing that tells the two apart. Absent on every capture that was scanned.
|
|
23045
|
+
scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
|
|
23029
23046
|
}).meta({ id: "EventMetadata" });
|
|
23030
23047
|
var Event = external_exports.object({
|
|
23031
23048
|
id: external_exports.guid(),
|
|
@@ -24842,6 +24859,7 @@ function toCaptureAttributes(event) {
|
|
|
24842
24859
|
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
24843
24860
|
...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
|
|
24844
24861
|
...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
|
|
24862
|
+
...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
|
|
24845
24863
|
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
24846
24864
|
// has ever populated either), but every legacy metadata key still rides
|
|
24847
24865
|
// the bag rather than being silently dropped — CaptureAttributes'
|
|
@@ -36865,6 +36883,38 @@ function worstProbeMs(rule, now = wallClock, corroborate) {
|
|
|
36865
36883
|
}
|
|
36866
36884
|
var CPU_CORROBORATION_SHARE = 0.2;
|
|
36867
36885
|
var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
36886
|
+
function repeatTo(unit, length) {
|
|
36887
|
+
return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
|
|
36888
|
+
}
|
|
36889
|
+
function joinTo(length, open3, close, item) {
|
|
36890
|
+
const parts = [];
|
|
36891
|
+
let size = open3.length;
|
|
36892
|
+
for (let i = 0; size < length; i++) {
|
|
36893
|
+
const next = (i === 0 ? "" : ",") + item(i);
|
|
36894
|
+
parts.push(next);
|
|
36895
|
+
size += next.length;
|
|
36896
|
+
}
|
|
36897
|
+
return (open3 + parts.join("") + close).slice(0, length);
|
|
36898
|
+
}
|
|
36899
|
+
var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
|
|
36900
|
+
var GROWTH_CORPORA = [
|
|
36901
|
+
{
|
|
36902
|
+
name: "one-line JSON dictionary",
|
|
36903
|
+
build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
|
|
36904
|
+
},
|
|
36905
|
+
{
|
|
36906
|
+
name: "JSON array of quoted SQL keywords",
|
|
36907
|
+
build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
|
|
36908
|
+
},
|
|
36909
|
+
{ name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
|
|
36910
|
+
{ name: "double-quote run", build: (length) => repeatTo('"', length) },
|
|
36911
|
+
{ name: "space run", build: (length) => repeatTo(" ", length) },
|
|
36912
|
+
{ name: "newline run", build: (length) => repeatTo("\n", length) },
|
|
36913
|
+
...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
|
|
36914
|
+
name: `unit run ${JSON.stringify(unit)}`,
|
|
36915
|
+
build: (length) => repeatTo(unit, length)
|
|
36916
|
+
}))
|
|
36917
|
+
];
|
|
36868
36918
|
function checkRuleTiming(rule, corroborate) {
|
|
36869
36919
|
const { ms, probe, corroboratedMs } = worstProbeMs(rule, wallClock, corroborate);
|
|
36870
36920
|
const work = corroboratedMs ?? 0;
|
|
@@ -37166,7 +37216,7 @@ var auth_jwt_no_verify_default = {
|
|
|
37166
37216
|
severity: "critical",
|
|
37167
37217
|
matcher: {
|
|
37168
37218
|
type: "regex",
|
|
37169
|
-
pattern: "(verify\\s*=\\s*false|verify_signature
|
|
37219
|
+
pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
|
|
37170
37220
|
flags: "gi"
|
|
37171
37221
|
},
|
|
37172
37222
|
requiresNearby: {
|
|
@@ -37254,7 +37304,7 @@ var cmd_inject_shell_default = {
|
|
|
37254
37304
|
severity: "critical",
|
|
37255
37305
|
matcher: {
|
|
37256
37306
|
type: "regex",
|
|
37257
|
-
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
|
|
37307
|
+
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
|
|
37258
37308
|
flags: "gi"
|
|
37259
37309
|
},
|
|
37260
37310
|
requiresNearby: {
|
|
@@ -37383,7 +37433,7 @@ var deser_yaml_unsafe_default = {
|
|
|
37383
37433
|
severity: "high",
|
|
37384
37434
|
matcher: {
|
|
37385
37435
|
type: "regex",
|
|
37386
|
-
pattern: "\\byaml\\.load\\s*\\((?![^)]
|
|
37436
|
+
pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
|
|
37387
37437
|
flags: "gi"
|
|
37388
37438
|
},
|
|
37389
37439
|
examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
|
|
@@ -37600,7 +37650,7 @@ var sql_inject_concat_dot_default = {
|
|
|
37600
37650
|
severity: "high",
|
|
37601
37651
|
matcher: {
|
|
37602
37652
|
type: "regex",
|
|
37603
|
-
pattern: `["'][
|
|
37653
|
+
pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
|
|
37604
37654
|
flags: "gi"
|
|
37605
37655
|
},
|
|
37606
37656
|
appliesTo: {
|
|
@@ -37618,7 +37668,7 @@ var sql_inject_concat_default = {
|
|
|
37618
37668
|
severity: "high",
|
|
37619
37669
|
matcher: {
|
|
37620
37670
|
type: "regex",
|
|
37621
|
-
pattern: `["']\\s*(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?["']\\s*\\+`,
|
|
37671
|
+
pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
|
|
37622
37672
|
flags: "gi"
|
|
37623
37673
|
},
|
|
37624
37674
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -37633,7 +37683,7 @@ var sql_inject_format_default = {
|
|
|
37633
37683
|
severity: "high",
|
|
37634
37684
|
matcher: {
|
|
37635
37685
|
type: "regex",
|
|
37636
|
-
pattern: "\\b(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?(?:[%][sd]|\\{[^}]+\\})",
|
|
37686
|
+
pattern: "\\b(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\1(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|\\b(?=(where\\b(?:(?!\\bwhere\\b)[^\\n])*?=))\\2(?:(?!\\bwhere\\b)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})",
|
|
37637
37687
|
flags: "gi"
|
|
37638
37688
|
},
|
|
37639
37689
|
examples: [
|
|
@@ -37651,7 +37701,7 @@ var sql_inject_interp_default = {
|
|
|
37651
37701
|
severity: "high",
|
|
37652
37702
|
matcher: {
|
|
37653
37703
|
type: "regex",
|
|
37654
|
-
pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
|
|
37704
|
+
pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
|
|
37655
37705
|
flags: "gi"
|
|
37656
37706
|
},
|
|
37657
37707
|
examples: [
|
|
@@ -38026,7 +38076,7 @@ var stack_trace_default = {
|
|
|
38026
38076
|
severity: "low",
|
|
38027
38077
|
matcher: {
|
|
38028
38078
|
type: "regex",
|
|
38029
|
-
pattern: "(
|
|
38079
|
+
pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
|
|
38030
38080
|
flags: "g"
|
|
38031
38081
|
},
|
|
38032
38082
|
examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
|
|
@@ -39184,7 +39234,7 @@ var BUNDLED_PACKS = [
|
|
|
39184
39234
|
{
|
|
39185
39235
|
packId: "code-flaws",
|
|
39186
39236
|
name: "Code Security Flaws",
|
|
39187
|
-
version: "0.1.
|
|
39237
|
+
version: "0.1.1",
|
|
39188
39238
|
rawRules: [
|
|
39189
39239
|
sql_inject_concat_default,
|
|
39190
39240
|
sql_inject_concat_dot_default,
|
|
@@ -39234,7 +39284,7 @@ var BUNDLED_PACKS = [
|
|
|
39234
39284
|
{
|
|
39235
39285
|
packId: "core-code-context",
|
|
39236
39286
|
name: "Code Context",
|
|
39237
|
-
version: "0.2.
|
|
39287
|
+
version: "0.2.2",
|
|
39238
39288
|
rawRules: [
|
|
39239
39289
|
internal_ip_default,
|
|
39240
39290
|
localhost_ref_default,
|
|
@@ -39684,9 +39734,10 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39684
39734
|
if (job.timer !== void 0) return;
|
|
39685
39735
|
job.startedAt = performance.now();
|
|
39686
39736
|
job.progressAt = job.startedAt;
|
|
39737
|
+
const budget = job.deadlineAt === void 0 ? job.budgetMs : Math.max(0, Math.min(job.budgetMs, job.deadlineAt - job.startedAt));
|
|
39687
39738
|
job.timer = setTimeout(() => {
|
|
39688
39739
|
onDeadline(job);
|
|
39689
|
-
},
|
|
39740
|
+
}, budget);
|
|
39690
39741
|
}
|
|
39691
39742
|
function runOne(spec, fail) {
|
|
39692
39743
|
if (closed) {
|
|
@@ -39697,6 +39748,12 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39697
39748
|
fail({ status: "unavailable", reason: `the scan worker crashed: ${broken}` });
|
|
39698
39749
|
return;
|
|
39699
39750
|
}
|
|
39751
|
+
const now = performance.now();
|
|
39752
|
+
const deadlineAt = spec.deadlineAt;
|
|
39753
|
+
if (deadlineAt !== void 0 && deadlineAt <= now) {
|
|
39754
|
+
fail({ status: "timeout", culpritIndex: void 0, elapsedMs: 0 });
|
|
39755
|
+
return;
|
|
39756
|
+
}
|
|
39700
39757
|
const started = ensureWorker();
|
|
39701
39758
|
if (!(started instanceof Worker)) {
|
|
39702
39759
|
broken = started.error;
|
|
@@ -39704,11 +39761,11 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39704
39761
|
return;
|
|
39705
39762
|
}
|
|
39706
39763
|
const id = nextJobId++;
|
|
39707
|
-
const now = performance.now();
|
|
39708
39764
|
const job = {
|
|
39709
39765
|
id,
|
|
39710
39766
|
worker: started,
|
|
39711
39767
|
budgetMs: spec.budgetMs,
|
|
39768
|
+
deadlineAt,
|
|
39712
39769
|
startedAt: now,
|
|
39713
39770
|
progressIndex: -1,
|
|
39714
39771
|
progressAt: now,
|
|
@@ -39722,14 +39779,19 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39722
39779
|
if (readyWorker === started) {
|
|
39723
39780
|
beginDeadline(job);
|
|
39724
39781
|
} else {
|
|
39782
|
+
const startBudget = spec.startBudgetMs ?? startBudgetMs;
|
|
39783
|
+
const callerLimited = deadlineAt !== void 0 && deadlineAt - now < startBudget;
|
|
39784
|
+
const startWaitMs = callerLimited ? deadlineAt - now : startBudget;
|
|
39725
39785
|
job.startupTimer = setTimeout(() => {
|
|
39726
39786
|
if (pending !== job) return;
|
|
39727
39787
|
kill(job.worker);
|
|
39728
|
-
failPending(
|
|
39729
|
-
status: "
|
|
39730
|
-
|
|
39731
|
-
|
|
39732
|
-
|
|
39788
|
+
failPending(
|
|
39789
|
+
callerLimited ? { status: "timeout", culpritIndex: void 0, elapsedMs: performance.now() - now } : {
|
|
39790
|
+
status: "unavailable",
|
|
39791
|
+
reason: `the scan worker did not start within ${String(startBudget)}ms`
|
|
39792
|
+
}
|
|
39793
|
+
);
|
|
39794
|
+
}, startWaitMs);
|
|
39733
39795
|
}
|
|
39734
39796
|
try {
|
|
39735
39797
|
started.postMessage(spec.build(id));
|
|
@@ -39758,7 +39820,9 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39758
39820
|
return enqueue((resolve3) => {
|
|
39759
39821
|
runOne(
|
|
39760
39822
|
{
|
|
39761
|
-
budgetMs,
|
|
39823
|
+
budgetMs: scanOpts?.budgetMs ?? budgetMs,
|
|
39824
|
+
startBudgetMs: scanOpts?.startBudgetMs,
|
|
39825
|
+
deadlineAt: scanOpts?.deadlineAt,
|
|
39762
39826
|
build: (id) => ({
|
|
39763
39827
|
kind: "scan",
|
|
39764
39828
|
id,
|
|
@@ -39952,6 +40016,9 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
39952
40016
|
let unverified = partition.unverified;
|
|
39953
40017
|
let isolated = unverified.length > 0 ? createIsolatedScanner({ verified, unverified }, opts) : void 0;
|
|
39954
40018
|
let retired = false;
|
|
40019
|
+
let bounded;
|
|
40020
|
+
let boundedWarned = false;
|
|
40021
|
+
let closed = false;
|
|
39955
40022
|
function inProcess(text, context) {
|
|
39956
40023
|
return scan(text, verified, context);
|
|
39957
40024
|
}
|
|
@@ -40013,11 +40080,48 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
40013
40080
|
await degrade();
|
|
40014
40081
|
return inProcess(text, context);
|
|
40015
40082
|
}
|
|
40083
|
+
async function scanBounded(text, context, bound) {
|
|
40084
|
+
const remainingMs = bound.remainingMs;
|
|
40085
|
+
let outcome;
|
|
40086
|
+
if (closed) {
|
|
40087
|
+
outcome = { status: "unavailable", reason: "the scan worker is closed" };
|
|
40088
|
+
} else if (remainingMs !== void 0 && !(remainingMs > 0)) {
|
|
40089
|
+
outcome = { status: "timeout", culpritIndex: void 0, elapsedMs: 0 };
|
|
40090
|
+
} else {
|
|
40091
|
+
bounded ??= createIsolatedScanner({ verified, unverified }, opts);
|
|
40092
|
+
const deadlineAt = remainingMs === void 0 ? void 0 : performance.now() + remainingMs;
|
|
40093
|
+
try {
|
|
40094
|
+
outcome = await bounded.scan(text, context, {
|
|
40095
|
+
budgetMs: bound.budgetMs,
|
|
40096
|
+
startBudgetMs: bound.startBudgetMs,
|
|
40097
|
+
deadlineAt
|
|
40098
|
+
});
|
|
40099
|
+
} catch (error62) {
|
|
40100
|
+
outcome = {
|
|
40101
|
+
status: "unavailable",
|
|
40102
|
+
reason: error62 instanceof Error ? error62.message : "the scan worker failed unexpectedly"
|
|
40103
|
+
};
|
|
40104
|
+
}
|
|
40105
|
+
}
|
|
40106
|
+
if (outcome.status !== "ok" && !boundedWarned) {
|
|
40107
|
+
boundedWarned = true;
|
|
40108
|
+
process.stderr.write(
|
|
40109
|
+
outcome.status === "timeout" ? `[aka] a large input could not be scanned within its time limit and was refused.
|
|
40110
|
+
` : `[aka] a large input could not be scanned and was refused: ${outcome.reason}.
|
|
40111
|
+
`
|
|
40112
|
+
);
|
|
40113
|
+
}
|
|
40114
|
+
return outcome;
|
|
40115
|
+
}
|
|
40016
40116
|
return {
|
|
40017
40117
|
scan: guardedScan,
|
|
40118
|
+
scanBounded,
|
|
40018
40119
|
degraded: () => retired,
|
|
40019
40120
|
async close() {
|
|
40020
|
-
|
|
40121
|
+
closed = true;
|
|
40122
|
+
const live = bounded;
|
|
40123
|
+
bounded = void 0;
|
|
40124
|
+
await Promise.all([retire(), live?.close()]);
|
|
40021
40125
|
}
|
|
40022
40126
|
};
|
|
40023
40127
|
}
|
|
@@ -40303,6 +40407,19 @@ function conditionsMatch(conditions, ctx) {
|
|
|
40303
40407
|
if (conditions.provider !== void 0) return false;
|
|
40304
40408
|
return true;
|
|
40305
40409
|
}
|
|
40410
|
+
var LARGE_INPUT_THRESHOLD_CHARS = 32768;
|
|
40411
|
+
var LARGE_INPUT_SCAN_BUDGET_MS = 2e3;
|
|
40412
|
+
var LARGE_INPUT_START_BUDGET_MS = 1500;
|
|
40413
|
+
function readRemainingMs(largeInput) {
|
|
40414
|
+
const read = largeInput.remainingMs;
|
|
40415
|
+
if (read === void 0) return void 0;
|
|
40416
|
+
try {
|
|
40417
|
+
const remaining = read();
|
|
40418
|
+
return typeof remaining !== "number" || Number.isNaN(remaining) ? 0 : remaining;
|
|
40419
|
+
} catch {
|
|
40420
|
+
return 0;
|
|
40421
|
+
}
|
|
40422
|
+
}
|
|
40306
40423
|
var bundlesPacked = false;
|
|
40307
40424
|
function createPluginRuntime(gateway, settings, opts) {
|
|
40308
40425
|
if (!bundlesPacked) {
|
|
@@ -40312,6 +40429,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40312
40429
|
const policyMode = settings.policy;
|
|
40313
40430
|
let redactFallback = settings.redactFallback;
|
|
40314
40431
|
const dataDir2 = opts?.dataDir;
|
|
40432
|
+
const largeInput = opts?.largeInput;
|
|
40315
40433
|
let rules = [];
|
|
40316
40434
|
let evidenceOf = evidenceLookup(rules);
|
|
40317
40435
|
let scanner;
|
|
@@ -40524,7 +40642,24 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40524
40642
|
await ensureInitialized();
|
|
40525
40643
|
if (!scanner) throw new Error("the runtime initialized without a scanner");
|
|
40526
40644
|
const shielded = shieldPointers(text);
|
|
40527
|
-
|
|
40645
|
+
let matched;
|
|
40646
|
+
if (largeInput !== void 0 && shielded.text.length >= largeInput.thresholdChars) {
|
|
40647
|
+
const outcome = await scanner.scanBounded(shielded.text, context, {
|
|
40648
|
+
budgetMs: largeInput.budgetMs,
|
|
40649
|
+
startBudgetMs: largeInput.startBudgetMs,
|
|
40650
|
+
remainingMs: readRemainingMs(largeInput)
|
|
40651
|
+
});
|
|
40652
|
+
if (outcome.status !== "ok") {
|
|
40653
|
+
return {
|
|
40654
|
+
decision: { action: "block", text: null, findings: [], scanIncomplete: outcome.status },
|
|
40655
|
+
excepted: /* @__PURE__ */ new Set(),
|
|
40656
|
+
exceptionIds: []
|
|
40657
|
+
};
|
|
40658
|
+
}
|
|
40659
|
+
matched = outcome.findings;
|
|
40660
|
+
} else {
|
|
40661
|
+
matched = await scanner.scan(shielded.text, context);
|
|
40662
|
+
}
|
|
40528
40663
|
const findings = dropShieldedFindings(matched, shielded.spans);
|
|
40529
40664
|
const fpCache = /* @__PURE__ */ new Map();
|
|
40530
40665
|
const { excepted, exceptionIds } = await applyExceptions(findings, ctx, fpCache);
|
|
@@ -40565,20 +40700,24 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40565
40700
|
}
|
|
40566
40701
|
async function persistCapture(input2, opts2, { decision, excepted, exceptionIds, timingStartedAt }) {
|
|
40567
40702
|
const filePath = input2.metadata?.filePath;
|
|
40568
|
-
if (opts2.persist === "with-findings" && decision.findings.length === 0)
|
|
40703
|
+
if (opts2.persist === "with-findings" && decision.findings.length === 0 && decision.scanIncomplete === void 0) {
|
|
40704
|
+
return;
|
|
40705
|
+
}
|
|
40569
40706
|
try {
|
|
40570
40707
|
const contentHash = contentHashOf(input2.text);
|
|
40571
40708
|
const maskedFindings = decision.findings.filter(
|
|
40572
40709
|
(match) => isActionAtLeast(actionForFinding(match, excepted, opts2.rewritable), "redact")
|
|
40573
40710
|
);
|
|
40574
|
-
const storedContent = maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
|
|
40711
|
+
const storedContent = decision.scanIncomplete !== void 0 ? "" : maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
|
|
40575
40712
|
const inspectionMs = elapsedMs(timingStartedAt);
|
|
40576
40713
|
const redactDegradedTo = decision.redactDegradedTo;
|
|
40577
|
-
const
|
|
40714
|
+
const scanIncomplete = decision.scanIncomplete;
|
|
40715
|
+
const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 || scanIncomplete !== void 0 ? {
|
|
40578
40716
|
...input2.metadata,
|
|
40579
40717
|
...exceptionIds.length > 0 ? { exceptionIds } : {},
|
|
40580
40718
|
...inspectionMs !== void 0 ? { inspectionMs } : {},
|
|
40581
|
-
...redactDegradedTo !== void 0 ? { redactDegradedTo } : {}
|
|
40719
|
+
...redactDegradedTo !== void 0 ? { redactDegradedTo } : {},
|
|
40720
|
+
...scanIncomplete !== void 0 ? { scanIncomplete } : {}
|
|
40582
40721
|
} : input2.metadata;
|
|
40583
40722
|
const event = buildIngestEvent({
|
|
40584
40723
|
kind: input2.kind,
|
|
@@ -40699,51 +40838,15 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40699
40838
|
};
|
|
40700
40839
|
}
|
|
40701
40840
|
|
|
40702
|
-
// src/
|
|
40703
|
-
var
|
|
40704
|
-
|
|
40705
|
-
|
|
40706
|
-
|
|
40707
|
-
|
|
40708
|
-
|
|
40709
|
-
|
|
40710
|
-
|
|
40711
|
-
// --color-brand · ▸▸ AKA wordmark (accent text)
|
|
40712
|
-
dim: fg("#838995"),
|
|
40713
|
-
// --color-text-3 · separators · "/100" · the "unreviewed" label
|
|
40714
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
40715
|
-
// the health score number
|
|
40716
|
-
ok: fg("#0db15f"),
|
|
40717
|
-
// --color-ok · healthy ● dot
|
|
40718
|
-
critical: fg("#e63448"),
|
|
40719
|
-
// --color-sev-critical · ■ and the open-findings flag
|
|
40720
|
-
high: fg("#e97a0a"),
|
|
40721
|
-
// --color-sev-high · ■ and the mid-health dot
|
|
40722
|
-
medium: fg("#f7bd00"),
|
|
40723
|
-
// --color-sev-medium · ■
|
|
40724
|
-
low: fg("#0581d4")
|
|
40725
|
-
// --color-sev-low · ■ (azure blue, not purple)
|
|
40726
|
-
};
|
|
40727
|
-
|
|
40728
|
-
// src/exception-guidance.ts
|
|
40729
|
-
function blockMessage(input2) {
|
|
40730
|
-
const preview = input2.blockedRef ? ` (${input2.blockedRef.maskedValue})` : "";
|
|
40731
|
-
const commands = input2.blockedRef ? [
|
|
40732
|
-
` aka exception approve ${input2.blockedRef.reference} (asks for scope + reason, then resubmit)`,
|
|
40733
|
-
" aka exception approve <value> (same flow, pasting the blocked value itself)"
|
|
40734
|
-
] : [" aka exception approve (asks for scope + reason, then resubmit)"];
|
|
40735
|
-
const note = input2.note ? ` ${input2.note}` : "";
|
|
40736
|
-
return [
|
|
40737
|
-
`AKA blocked this ${input2.subject} \u2014 flagged ${input2.ruleIds}${preview}.${note} Remove the flagged content and resubmit.`,
|
|
40738
|
-
"If this is intentional and you accept the risk, grant an exception:",
|
|
40739
|
-
...commands,
|
|
40740
|
-
"More: aka exception --help"
|
|
40741
|
-
].join("\n");
|
|
40742
|
-
}
|
|
40743
|
-
function exceptionPointer(references) {
|
|
40744
|
-
const ref = references?.[0];
|
|
40745
|
-
if (ref === void 0) return "";
|
|
40746
|
-
return ` To allow this exact value intentionally, run: aka exception approve ${ref.reference}.`;
|
|
40841
|
+
// src/hooks/large-input.ts
|
|
40842
|
+
var HOOK_SCAN_DEADLINE_MS = 6e3;
|
|
40843
|
+
function largeInputBound(deadlineAt, now = () => performance.now()) {
|
|
40844
|
+
return {
|
|
40845
|
+
thresholdChars: LARGE_INPUT_THRESHOLD_CHARS,
|
|
40846
|
+
budgetMs: LARGE_INPUT_SCAN_BUDGET_MS,
|
|
40847
|
+
startBudgetMs: LARGE_INPUT_START_BUDGET_MS,
|
|
40848
|
+
remainingMs: () => deadlineAt - now()
|
|
40849
|
+
};
|
|
40747
40850
|
}
|
|
40748
40851
|
|
|
40749
40852
|
// src/hooks/model-guard.ts
|
|
@@ -42214,6 +42317,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
|
42214
42317
|
var TRACE_ID = EventMetadata.shape.traceId;
|
|
42215
42318
|
var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
|
|
42216
42319
|
var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
|
|
42320
|
+
var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
|
|
42217
42321
|
|
|
42218
42322
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
42219
42323
|
var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
@@ -43395,6 +43499,79 @@ function warnIfStoreRedirected(config2, sessionId, write = (message) => void pro
|
|
|
43395
43499
|
}
|
|
43396
43500
|
}
|
|
43397
43501
|
|
|
43502
|
+
// src/present.ts
|
|
43503
|
+
var fg = (hex3) => (text) => {
|
|
43504
|
+
const r = Number.parseInt(hex3.slice(1, 3), 16);
|
|
43505
|
+
const g = Number.parseInt(hex3.slice(3, 5), 16);
|
|
43506
|
+
const b = Number.parseInt(hex3.slice(5, 7), 16);
|
|
43507
|
+
return `\x1B[38;2;${String(r)};${String(g)};${String(b)}m${text}\x1B[0m`;
|
|
43508
|
+
};
|
|
43509
|
+
var paint = {
|
|
43510
|
+
brand: fg("#33e6c6"),
|
|
43511
|
+
// --color-brand · ▸▸ AKA wordmark (accent text)
|
|
43512
|
+
dim: fg("#838995"),
|
|
43513
|
+
// --color-text-3 · separators · "/100" · the "unreviewed" label
|
|
43514
|
+
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
43515
|
+
// the health score number
|
|
43516
|
+
ok: fg("#0db15f"),
|
|
43517
|
+
// --color-ok · healthy ● dot
|
|
43518
|
+
critical: fg("#e63448"),
|
|
43519
|
+
// --color-sev-critical · ■ and the open-findings flag
|
|
43520
|
+
high: fg("#e97a0a"),
|
|
43521
|
+
// --color-sev-high · ■ and the mid-health dot
|
|
43522
|
+
medium: fg("#f7bd00"),
|
|
43523
|
+
// --color-sev-medium · ■
|
|
43524
|
+
low: fg("#0581d4")
|
|
43525
|
+
// --color-sev-low · ■ (azure blue, not purple)
|
|
43526
|
+
};
|
|
43527
|
+
|
|
43528
|
+
// src/exception-guidance.ts
|
|
43529
|
+
function blockMessage(input2) {
|
|
43530
|
+
const preview = input2.blockedRef ? ` (${input2.blockedRef.maskedValue})` : "";
|
|
43531
|
+
const commands = input2.blockedRef ? [
|
|
43532
|
+
` aka exception approve ${input2.blockedRef.reference} (asks for scope + reason, then resubmit)`,
|
|
43533
|
+
" aka exception approve <value> (same flow, pasting the blocked value itself)"
|
|
43534
|
+
] : [" aka exception approve (asks for scope + reason, then resubmit)"];
|
|
43535
|
+
const note = input2.note ? ` ${input2.note}` : "";
|
|
43536
|
+
return [
|
|
43537
|
+
`AKA blocked this ${input2.subject} \u2014 flagged ${input2.ruleIds}${preview}.${note} Remove the flagged content and resubmit.`,
|
|
43538
|
+
"If this is intentional and you accept the risk, grant an exception:",
|
|
43539
|
+
...commands,
|
|
43540
|
+
"More: aka exception --help"
|
|
43541
|
+
].join("\n");
|
|
43542
|
+
}
|
|
43543
|
+
function tooLargeToScanMessage(subject) {
|
|
43544
|
+
return `This ${subject} is too large for AKA to scan within the time limit, so it was blocked. Shorten it or send it in smaller parts.`;
|
|
43545
|
+
}
|
|
43546
|
+
function exceptionPointer(references) {
|
|
43547
|
+
const ref = references?.[0];
|
|
43548
|
+
if (ref === void 0) return "";
|
|
43549
|
+
return ` To allow this exact value intentionally, run: aka exception approve ${ref.reference}.`;
|
|
43550
|
+
}
|
|
43551
|
+
|
|
43552
|
+
// src/hooks/user-prompt-submit-decision.ts
|
|
43553
|
+
function decideUserPromptSubmit(result) {
|
|
43554
|
+
if (result.scanIncomplete !== void 0) {
|
|
43555
|
+
return { decision: "block", reason: tooLargeToScanMessage("prompt") };
|
|
43556
|
+
}
|
|
43557
|
+
if (result.action === "block" || result.action === "redact") {
|
|
43558
|
+
return {
|
|
43559
|
+
decision: "block",
|
|
43560
|
+
reason: blockMessage({
|
|
43561
|
+
subject: "prompt",
|
|
43562
|
+
ruleIds: uniqueRuleIds(result.findings),
|
|
43563
|
+
blockedRef: result.blockedReferences?.[0]
|
|
43564
|
+
})
|
|
43565
|
+
};
|
|
43566
|
+
}
|
|
43567
|
+
if (result.action === "warn") {
|
|
43568
|
+
return {
|
|
43569
|
+
systemMessage: `AKA flagged sensitive content (${uniqueRuleIds(result.findings)}) \u2014 sent unchanged.${exceptionPointer(result.blockedReferences)}`
|
|
43570
|
+
};
|
|
43571
|
+
}
|
|
43572
|
+
return null;
|
|
43573
|
+
}
|
|
43574
|
+
|
|
43398
43575
|
// src/hooks/user-prompt-submit.ts
|
|
43399
43576
|
async function main() {
|
|
43400
43577
|
const input2 = parseJson(await readStdin());
|
|
@@ -43423,7 +43600,10 @@ async function main() {
|
|
|
43423
43600
|
)) {
|
|
43424
43601
|
return;
|
|
43425
43602
|
}
|
|
43426
|
-
const runtime = createPluginRuntime(gateway, config2.settings, {
|
|
43603
|
+
const runtime = createPluginRuntime(gateway, config2.settings, {
|
|
43604
|
+
dataDir: config2.dataDir,
|
|
43605
|
+
largeInput: largeInputBound(HOOK_SCAN_DEADLINE_MS)
|
|
43606
|
+
});
|
|
43427
43607
|
let result;
|
|
43428
43608
|
try {
|
|
43429
43609
|
result = await runtime.capture({
|
|
@@ -43436,21 +43616,9 @@ async function main() {
|
|
|
43436
43616
|
} finally {
|
|
43437
43617
|
await runtime.close();
|
|
43438
43618
|
}
|
|
43439
|
-
|
|
43440
|
-
|
|
43441
|
-
|
|
43442
|
-
reason: blockMessage({
|
|
43443
|
-
subject: "prompt",
|
|
43444
|
-
ruleIds: uniqueRuleIds(result.findings),
|
|
43445
|
-
blockedRef: result.blockedReferences?.[0]
|
|
43446
|
-
})
|
|
43447
|
-
});
|
|
43448
|
-
return;
|
|
43449
|
-
}
|
|
43450
|
-
if (result.action === "warn") {
|
|
43451
|
-
await emit({
|
|
43452
|
-
systemMessage: `AKA flagged sensitive content (${uniqueRuleIds(result.findings)}) \u2014 sent unchanged.${exceptionPointer(result.blockedReferences)}`
|
|
43453
|
-
});
|
|
43619
|
+
const decision = decideUserPromptSubmit(result);
|
|
43620
|
+
if (decision !== null) {
|
|
43621
|
+
await emit(decision);
|
|
43454
43622
|
return;
|
|
43455
43623
|
}
|
|
43456
43624
|
if (!config2.onboarded && claimOnboardingNudge(config2.dataDir, sessionId)) {
|