@openai/codex-security 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -9
- package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/core-scan.md +2 -0
- package/_bundled_plugin/references/final-report.md +5 -1
- package/_bundled_plugin/references/investigation-time-budget.md +11 -0
- package/_bundled_plugin/references/sarif-adapter.md +1 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -6
- package/_bundled_plugin/references/scan-runtime.md +15 -0
- package/_bundled_plugin/references/threat-model.md +2 -0
- package/_bundled_plugin/schemas/coverage.schema.json +45 -126
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
- package/_bundled_plugin/schemas/findings.schema.json +140 -427
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
- package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
- package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
- package/_bundled_plugin/scripts/finding_preview.py +5 -3
- package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
- package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
- package/_bundled_plugin/scripts/report_projection.py +35 -13
- package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
- package/_bundled_plugin/scripts/workbench_cli.py +9 -9
- package/_bundled_plugin/scripts/workbench_constants.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +103 -45
- package/_bundled_plugin/scripts/workbench_progress.py +0 -50
- package/_bundled_plugin/scripts/workbench_publication.py +216 -247
- package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
- package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
- package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
- package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
- package/_bundled_plugin/scripts/workbench_target.py +7 -5
- package/_bundled_plugin/scripts/workbench_validation.py +52 -2
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
- package/_bundled_plugin/shared/workbench-migrations.json +22 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
- package/dist/api.d.ts +6 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +266 -39
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +2 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +38 -23
- package/dist/artifact-export.js.map +1 -1
- package/dist/classify-severity-records.d.ts +76 -0
- package/dist/classify-severity-records.d.ts.map +1 -0
- package/dist/classify-severity-records.js +141 -0
- package/dist/classify-severity-records.js.map +1 -0
- package/dist/classify-severity.d.ts +1 -23
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -24
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +2 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +4 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +148 -149
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +1 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.js +1 -1
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.js +1 -1
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +5 -4
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -4
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +6 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +69 -20
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +7 -2
- package/dist/cost-model.js.map +1 -1
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +1 -5
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +2 -2
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts +3 -8
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -171
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.js +1 -1
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +10 -9
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +4 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +21 -1
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +15 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +15 -16
- package/dist/deep-progress.js.map +1 -1
- package/dist/executable-path.d.ts +2 -0
- package/dist/executable-path.d.ts.map +1 -0
- package/dist/executable-path.js +12 -0
- package/dist/executable-path.js.map +1 -0
- package/dist/feedback.d.ts +1 -4
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +1 -1
- package/dist/feedback.js.map +1 -1
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +3 -3
- package/dist/findings-import.js.map +1 -1
- package/dist/git-remote.d.ts +10 -0
- package/dist/git-remote.d.ts.map +1 -0
- package/dist/git-remote.js +24 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +5 -7
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +19 -0
- package/dist/host-protocol.d.ts.map +1 -0
- package/dist/host-protocol.js +270 -0
- package/dist/host-protocol.js.map +1 -0
- package/dist/host-records-protocol.d.ts +15 -0
- package/dist/host-records-protocol.d.ts.map +1 -0
- package/dist/host-records-protocol.js +15 -0
- package/dist/host-records-protocol.js.map +1 -0
- package/dist/hosted-scan-protocol.d.ts +4 -0
- package/dist/hosted-scan-protocol.d.ts.map +1 -0
- package/dist/hosted-scan-protocol.js +25 -0
- package/dist/hosted-scan-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +112 -0
- package/dist/hosted-scan.d.ts.map +1 -0
- package/dist/hosted-scan.js +260 -0
- package/dist/hosted-scan.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +87 -7
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +108 -36
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-publication.d.ts +26 -0
- package/dist/patch-publication.d.ts.map +1 -0
- package/dist/patch-publication.js +105 -0
- package/dist/patch-publication.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +16 -6
- package/dist/project-config.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +73 -63
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +0 -2
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +135 -24
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +39 -25
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +5 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +86 -58
- package/dist/runtime.js.map +1 -1
- package/dist/scan-executor.d.ts +104 -0
- package/dist/scan-executor.d.ts.map +1 -0
- package/dist/scan-executor.js +62 -0
- package/dist/scan-executor.js.map +1 -0
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +7 -1
- package/dist/scan-settings.js.map +1 -1
- package/dist/scan-time-budget.d.ts +9 -0
- package/dist/scan-time-budget.d.ts.map +1 -0
- package/dist/scan-time-budget.js +16 -0
- package/dist/scan-time-budget.js.map +1 -0
- package/dist/severity-review.d.ts +29 -0
- package/dist/severity-review.d.ts.map +1 -0
- package/dist/severity-review.js +47 -0
- package/dist/severity-review.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +17 -25
- package/dist/targets.js.map +1 -1
- package/dist/validation-records.d.ts +38 -0
- package/dist/validation-records.d.ts.map +1 -0
- package/dist/validation-records.js +76 -0
- package/dist/validation-records.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +4 -2
- package/dist/version.js.map +1 -1
- package/dist/worker-progress.d.ts +43 -15
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +22 -80
- package/dist/worker-progress.js.map +1 -1
- package/docs/classify-severity-records.md +89 -0
- package/docs/cli.md +281 -35
- package/docs/hosted-scans.md +242 -0
- package/docs/validate-records.md +69 -0
- package/package.json +18 -14
- package/schemas/hosted-scan-v2.fixture.json +145 -0
- package/schemas/project-config.schema.json +7 -1
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
- package/_bundled_plugin/references/config-preflight.md +0 -93
- package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
- package/_bundled_plugin/scripts/config_preflight.py +0 -911
package/dist/worker-progress.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { isRecord } from "./record.js";
|
|
2
|
-
import {
|
|
2
|
+
import { parseJson } from "./value.js";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
const WORKER_STATUS_PREFIX = "CODEX_SECURITY_WORKER_STATUS ";
|
|
4
5
|
const SCAN_PROGRESS_PREFIX = "CODEX_SECURITY_SCAN_PROGRESS ";
|
|
5
|
-
const
|
|
6
|
-
const WORKER_PHASES = new Set([
|
|
6
|
+
const workerPhaseSchema = z.enum([
|
|
7
7
|
"ranking",
|
|
8
8
|
"file_review",
|
|
9
9
|
"validation",
|
|
10
10
|
"attack_path",
|
|
11
11
|
]);
|
|
12
|
+
const scanPhaseSchema = z.enum([
|
|
13
|
+
"preflight",
|
|
14
|
+
"threat_model",
|
|
15
|
+
"discovery",
|
|
16
|
+
"validation",
|
|
17
|
+
"attack_path",
|
|
18
|
+
"reporting",
|
|
19
|
+
]);
|
|
20
|
+
const count = z.number().int().nonnegative();
|
|
21
|
+
const scanProgressSchema = z
|
|
22
|
+
.object({ phase: scanPhaseSchema, filesCompleted: count, filesTotal: count })
|
|
23
|
+
.refine(({ filesCompleted, filesTotal }) => filesCompleted <= filesTotal);
|
|
24
|
+
const dispatchSchema = z
|
|
25
|
+
.object({ phase: workerPhaseSchema, planned: count, started: count })
|
|
26
|
+
.refine(({ started, planned }) => started <= planned);
|
|
12
27
|
export function scanPhaseLabel(value) {
|
|
13
28
|
return {
|
|
14
29
|
preflight: "preflight",
|
|
@@ -26,8 +41,6 @@ export function workerStatusFromEvent(event) {
|
|
|
26
41
|
return null;
|
|
27
42
|
}
|
|
28
43
|
const item = event["item"];
|
|
29
|
-
if (item["type"] === "command_execution")
|
|
30
|
-
return preflightStatus(item);
|
|
31
44
|
if (item["type"] === "agent_message")
|
|
32
45
|
return dispatchStatus(item);
|
|
33
46
|
return null;
|
|
@@ -79,58 +92,8 @@ function linesOutsideFences(text) {
|
|
|
79
92
|
return lines;
|
|
80
93
|
}
|
|
81
94
|
function scanProgressFromMarker(marker) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
!isScanPhase(payload["phase"]) ||
|
|
85
|
-
!isSafeNonNegativeInteger(payload["filesCompleted"]) ||
|
|
86
|
-
!isSafeNonNegativeInteger(payload["filesTotal"]) ||
|
|
87
|
-
payload["filesCompleted"] > payload["filesTotal"]) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
phase: payload["phase"],
|
|
92
|
-
filesCompleted: payload["filesCompleted"],
|
|
93
|
-
filesTotal: payload["filesTotal"],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function preflightStatus(item) {
|
|
97
|
-
if (typeof item["command"] !== "string" ||
|
|
98
|
-
!PREFLIGHT_COMMAND.test(item["command"]) ||
|
|
99
|
-
typeof item["aggregated_output"] !== "string") {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const payload = parseJson(() => item["aggregated_output"]);
|
|
103
|
-
if (!isRecord(payload) ||
|
|
104
|
-
(payload["profile"] !== "security_scan" &&
|
|
105
|
-
payload["profile"] !== "security_diff_scan") ||
|
|
106
|
-
!Array.isArray(payload["results"])) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const results = payload["results"];
|
|
110
|
-
const delegated = results.filter((result) => isRecord(result) && result["capability"] === "delegated_workers");
|
|
111
|
-
const delegatedResult = delegated[0];
|
|
112
|
-
if (delegated.length !== 1 || delegatedResult === undefined)
|
|
113
|
-
return null;
|
|
114
|
-
const delegation = delegatedResult["status"] === "pass"
|
|
115
|
-
? "available"
|
|
116
|
-
: delegatedResult["status"] === "fail"
|
|
117
|
-
? "unavailable"
|
|
118
|
-
: delegatedResult["status"] === "unknown"
|
|
119
|
-
? "unknown"
|
|
120
|
-
: null;
|
|
121
|
-
if (delegation === null)
|
|
122
|
-
return null;
|
|
123
|
-
const capacity = results.filter((result) => isRecord(result) &&
|
|
124
|
-
typeof result["capability"] === "string" &&
|
|
125
|
-
result["capability"].startsWith("usable_worker_slots_"));
|
|
126
|
-
if (capacity.length > 1)
|
|
127
|
-
return null;
|
|
128
|
-
const capacityResult = capacity[0];
|
|
129
|
-
const configuredSlots = capacityResult !== undefined &&
|
|
130
|
-
isSafeNonNegativeInteger(capacityResult["actual"])
|
|
131
|
-
? capacityResult["actual"]
|
|
132
|
-
: null;
|
|
133
|
-
return { kind: "preflight", delegation, configuredSlots };
|
|
95
|
+
const parsed = scanProgressSchema.safeParse(parseJson(() => marker.slice(SCAN_PROGRESS_PREFIX.length)));
|
|
96
|
+
return parsed.success ? parsed.data : null;
|
|
134
97
|
}
|
|
135
98
|
function dispatchStatus(item) {
|
|
136
99
|
if (typeof item["text"] !== "string")
|
|
@@ -139,28 +102,7 @@ function dispatchStatus(item) {
|
|
|
139
102
|
const marker = markers[0];
|
|
140
103
|
if (markers.length !== 1 || marker === undefined)
|
|
141
104
|
return null;
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
typeof payload["phase"] !== "string" ||
|
|
145
|
-
!WORKER_PHASES.has(payload["phase"]) ||
|
|
146
|
-
!isSafeNonNegativeInteger(payload["planned"]) ||
|
|
147
|
-
!isSafeNonNegativeInteger(payload["started"]) ||
|
|
148
|
-
payload["started"] > payload["planned"]) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
kind: "dispatch",
|
|
153
|
-
phase: payload["phase"],
|
|
154
|
-
planned: payload["planned"],
|
|
155
|
-
started: payload["started"],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function isScanPhase(value) {
|
|
159
|
-
return (value === "preflight" ||
|
|
160
|
-
value === "threat_model" ||
|
|
161
|
-
value === "discovery" ||
|
|
162
|
-
value === "validation" ||
|
|
163
|
-
value === "attack_path" ||
|
|
164
|
-
value === "reporting");
|
|
105
|
+
const parsed = dispatchSchema.safeParse(parseJson(() => marker.slice(WORKER_STATUS_PREFIX.length)));
|
|
106
|
+
return parsed.success ? { kind: "dispatch", ...parsed.data } : null;
|
|
165
107
|
}
|
|
166
108
|
//# sourceMappingURL=worker-progress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-progress.js","sourceRoot":"","sources":["../src/worker-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE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CAAC,wBAAwB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7C,CAAC,wBAAwB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7C,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,EACvC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAoB;QAC1C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,CACL,KAAK,KAAK,WAAW;QACrB,KAAK,KAAK,cAAc;QACxB,KAAK,KAAK,WAAW;QACrB,KAAK,KAAK,YAAY;QACtB,KAAK,KAAK,aAAa;QACvB,KAAK,KAAK,WAAW,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { isSafeNonNegativeInteger, parseJson } from \"./value.js\";\n\nconst WORKER_STATUS_PREFIX = \"CODEX_SECURITY_WORKER_STATUS \";\nconst SCAN_PROGRESS_PREFIX = \"CODEX_SECURITY_SCAN_PROGRESS \";\nconst PREFLIGHT_COMMAND = /(?:^|[\\\\/])config_preflight\\.py(?=$|[\"'\\s])/u;\nconst WORKER_PHASES = new Set([\n \"ranking\",\n \"file_review\",\n \"validation\",\n \"attack_path\",\n]);\n\nexport type ScanWorkerPhase =\n \"ranking\" | \"file_review\" | \"validation\" | \"attack_path\";\n\nexport type ScanPhase =\n | \"preflight\"\n | \"threat_model\"\n | \"discovery\"\n | \"validation\"\n | \"attack_path\"\n | \"reporting\";\n\nexport interface ScanProgress {\n phase: ScanPhase;\n filesCompleted: number;\n filesTotal: number;\n}\n\nexport function scanPhaseLabel(value: ScanWorkerPhase | ScanPhase): string {\n return {\n preflight: \"preflight\",\n threat_model: \"building threat model\",\n discovery: \"reviewing files\",\n ranking: \"ranking scan targets\",\n file_review: \"reviewing files\",\n validation: \"validating findings\",\n attack_path: \"analyzing attack paths\",\n reporting: \"writing report\",\n }[value];\n}\n\n/** Preflight is tool-derived; dispatch counts depend on model-emitted markers. */\nexport type ScanWorkerStatus =\n | {\n kind: \"preflight\";\n delegation: \"available\" | \"unavailable\" | \"unknown\";\n configuredSlots: number | null;\n }\n | {\n kind: \"dispatch\";\n phase: ScanWorkerPhase;\n planned: number;\n started: number;\n };\n\nexport function workerStatusFromEvent(\n event: Readonly<Record<string, unknown>>,\n): ScanWorkerStatus | null {\n if (event[\"type\"] !== \"item.completed\" || !isRecord(event[\"item\"])) {\n return null;\n }\n const item = event[\"item\"];\n if (item[\"type\"] === \"command_execution\") return preflightStatus(item);\n if (item[\"type\"] === \"agent_message\") return dispatchStatus(item);\n return null;\n}\n\nexport function scanProgressUpdatesFromEvent(\n event: Readonly<Record<string, unknown>>,\n): ScanProgress[] {\n if (event[\"type\"] !== \"item.completed\" || !isRecord(event[\"item\"])) {\n return [];\n }\n const item = event[\"item\"];\n const output =\n item[\"type\"] === \"agent_message\"\n ? item[\"text\"]\n : item[\"type\"] === \"command_execution\"\n ? item[\"aggregated_output\"]\n : null;\n return typeof output === \"string\" ? scanProgressUpdatesFromText(output) : [];\n}\n\nexport function scanProgressUpdatesFromText(output: string): ScanProgress[] {\n const updates: ScanProgress[] = [];\n for (const line of linesOutsideFences(output)) {\n if (!line.startsWith(SCAN_PROGRESS_PREFIX)) continue;\n const progress = scanProgressFromMarker(line);\n if (progress !== null) updates.push(progress);\n }\n return updates;\n}\n\n/** Return lines outside Markdown fences so quoted markers are not read as live. */\nfunction linesOutsideFences(text: string): string[] {\n const lines: string[] = [];\n let fence: { marker: string; length: number } | null = null;\n for (const line of text.split(/\\r?\\n/u)) {\n const delimiter = /^\\s*(`{3,}|~{3,})(.*)$/u.exec(line);\n if (delimiter !== null) {\n const run = delimiter[1]!;\n if (fence === null) {\n fence = { marker: run[0]!, length: run.length };\n } else if (\n run[0] === fence.marker &&\n run.length >= fence.length &&\n delimiter[2]!.trim() === \"\"\n ) {\n fence = null;\n }\n continue;\n }\n if (fence === null) lines.push(line);\n }\n return lines;\n}\n\nfunction scanProgressFromMarker(marker: string): ScanProgress | null {\n const payload = parseJson(() => marker.slice(SCAN_PROGRESS_PREFIX.length));\n if (\n !isRecord(payload) ||\n !isScanPhase(payload[\"phase\"]) ||\n !isSafeNonNegativeInteger(payload[\"filesCompleted\"]) ||\n !isSafeNonNegativeInteger(payload[\"filesTotal\"]) ||\n payload[\"filesCompleted\"] > payload[\"filesTotal\"]\n ) {\n return null;\n }\n return {\n phase: payload[\"phase\"],\n filesCompleted: payload[\"filesCompleted\"],\n filesTotal: payload[\"filesTotal\"],\n };\n}\n\nfunction preflightStatus(\n item: Readonly<Record<string, unknown>>,\n): ScanWorkerStatus | null {\n if (\n typeof item[\"command\"] !== \"string\" ||\n !PREFLIGHT_COMMAND.test(item[\"command\"]) ||\n typeof item[\"aggregated_output\"] !== \"string\"\n ) {\n return null;\n }\n const payload = parseJson(() => item[\"aggregated_output\"] as string);\n if (\n !isRecord(payload) ||\n (payload[\"profile\"] !== \"security_scan\" &&\n payload[\"profile\"] !== \"security_diff_scan\") ||\n !Array.isArray(payload[\"results\"])\n ) {\n return null;\n }\n const results = payload[\"results\"];\n const delegated = results.filter(\n (result): result is Record<string, unknown> =>\n isRecord(result) && result[\"capability\"] === \"delegated_workers\",\n );\n const delegatedResult = delegated[0];\n if (delegated.length !== 1 || delegatedResult === undefined) return null;\n const delegation =\n delegatedResult[\"status\"] === \"pass\"\n ? \"available\"\n : delegatedResult[\"status\"] === \"fail\"\n ? \"unavailable\"\n : delegatedResult[\"status\"] === \"unknown\"\n ? \"unknown\"\n : null;\n if (delegation === null) return null;\n const capacity = results.filter(\n (result): result is Record<string, unknown> =>\n isRecord(result) &&\n typeof result[\"capability\"] === \"string\" &&\n result[\"capability\"].startsWith(\"usable_worker_slots_\"),\n );\n if (capacity.length > 1) return null;\n const capacityResult = capacity[0];\n const configuredSlots =\n capacityResult !== undefined &&\n isSafeNonNegativeInteger(capacityResult[\"actual\"])\n ? capacityResult[\"actual\"]\n : null;\n return { kind: \"preflight\", delegation, configuredSlots };\n}\n\nfunction dispatchStatus(\n item: Readonly<Record<string, unknown>>,\n): ScanWorkerStatus | null {\n if (typeof item[\"text\"] !== \"string\") return null;\n const markers = linesOutsideFences(item[\"text\"]).filter((line) =>\n line.startsWith(WORKER_STATUS_PREFIX),\n );\n const marker = markers[0];\n if (markers.length !== 1 || marker === undefined) return null;\n const payload = parseJson(() => marker.slice(WORKER_STATUS_PREFIX.length));\n if (\n !isRecord(payload) ||\n typeof payload[\"phase\"] !== \"string\" ||\n !WORKER_PHASES.has(payload[\"phase\"]) ||\n !isSafeNonNegativeInteger(payload[\"planned\"]) ||\n !isSafeNonNegativeInteger(payload[\"started\"]) ||\n payload[\"started\"] > payload[\"planned\"]\n ) {\n return null;\n }\n return {\n kind: \"dispatch\",\n phase: payload[\"phase\"] as ScanWorkerPhase,\n planned: payload[\"planned\"],\n started: payload[\"started\"],\n };\n}\n\nfunction isScanPhase(value: unknown): value is ScanPhase {\n return (\n value === \"preflight\" ||\n value === \"threat_model\" ||\n value === \"discovery\" ||\n value === \"validation\" ||\n value === \"attack_path\" ||\n value === \"reporting\"\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-progress.js","sourceRoot":"","sources":["../src/worker-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAC7D,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAC7D,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC/B,SAAS;IACT,aAAa;IAC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AQ;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAC/D,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CACtC,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC9D,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CACrC,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAC3D,CAAC;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { parseJson } from \"./value.js\";\nimport { z } from \"zod\";\n\nconst WORKER_STATUS_PREFIX = \"CODEX_SECURITY_WORKER_STATUS \";\nconst SCAN_PROGRESS_PREFIX = \"CODEX_SECURITY_SCAN_PROGRESS \";\nconst workerPhaseSchema = z.enum([\n \"ranking\",\n \"file_review\",\n \"validation\",\n \"attack_path\",\n]);\n\nexport type ScanWorkerPhase = z.infer<typeof workerPhaseSchema>;\n\nconst scanPhaseSchema = z.enum([\n \"preflight\",\n \"threat_model\",\n \"discovery\",\n \"validation\",\n \"attack_path\",\n \"reporting\",\n]);\nexport type ScanPhase = z.infer<typeof scanPhaseSchema>;\n\nconst count = z.number().int().nonnegative();\nconst scanProgressSchema = z\n .object({ phase: scanPhaseSchema, filesCompleted: count, filesTotal: count })\n .refine(({ filesCompleted, filesTotal }) => filesCompleted <= filesTotal);\nconst dispatchSchema = z\n .object({ phase: workerPhaseSchema, planned: count, started: count })\n .refine(({ started, planned }) => started <= planned);\n\nexport interface ScanProgress extends z.infer<typeof scanProgressSchema> {}\n\nexport function scanPhaseLabel(value: ScanWorkerPhase | ScanPhase): string {\n return {\n preflight: \"preflight\",\n threat_model: \"building threat model\",\n discovery: \"reviewing files\",\n ranking: \"ranking scan targets\",\n file_review: \"reviewing files\",\n validation: \"validating findings\",\n attack_path: \"analyzing attack paths\",\n reporting: \"writing report\",\n }[value];\n}\n\n/** Dispatch counts depend on model-emitted markers. */\nexport type ScanWorkerStatus = {\n kind: \"dispatch\";\n} & z.infer<typeof dispatchSchema>;\n\nexport function workerStatusFromEvent(\n event: Readonly<Record<string, unknown>>,\n): ScanWorkerStatus | null {\n if (event[\"type\"] !== \"item.completed\" || !isRecord(event[\"item\"])) {\n return null;\n }\n const item = event[\"item\"];\n if (item[\"type\"] === \"agent_message\") return dispatchStatus(item);\n return null;\n}\n\nexport function scanProgressUpdatesFromEvent(\n event: Readonly<Record<string, unknown>>,\n): ScanProgress[] {\n if (event[\"type\"] !== \"item.completed\" || !isRecord(event[\"item\"])) {\n return [];\n }\n const item = event[\"item\"];\n const output =\n item[\"type\"] === \"agent_message\"\n ? item[\"text\"]\n : item[\"type\"] === \"command_execution\"\n ? item[\"aggregated_output\"]\n : null;\n return typeof output === \"string\" ? scanProgressUpdatesFromText(output) : [];\n}\n\nexport function scanProgressUpdatesFromText(output: string): ScanProgress[] {\n const updates: ScanProgress[] = [];\n for (const line of linesOutsideFences(output)) {\n if (!line.startsWith(SCAN_PROGRESS_PREFIX)) continue;\n const progress = scanProgressFromMarker(line);\n if (progress !== null) updates.push(progress);\n }\n return updates;\n}\n\n/** Return lines outside Markdown fences so quoted markers are not read as live. */\nfunction linesOutsideFences(text: string): string[] {\n const lines: string[] = [];\n let fence: { marker: string; length: number } | null = null;\n for (const line of text.split(/\\r?\\n/u)) {\n const delimiter = /^\\s*(`{3,}|~{3,})(.*)$/u.exec(line);\n if (delimiter !== null) {\n const run = delimiter[1]!;\n if (fence === null) {\n fence = { marker: run[0]!, length: run.length };\n } else if (\n run[0] === fence.marker &&\n run.length >= fence.length &&\n delimiter[2]!.trim() === \"\"\n ) {\n fence = null;\n }\n continue;\n }\n if (fence === null) lines.push(line);\n }\n return lines;\n}\n\nfunction scanProgressFromMarker(marker: string): ScanProgress | null {\n const parsed = scanProgressSchema.safeParse(\n parseJson(() => marker.slice(SCAN_PROGRESS_PREFIX.length)),\n );\n return parsed.success ? parsed.data : null;\n}\n\nfunction dispatchStatus(\n item: Readonly<Record<string, unknown>>,\n): ScanWorkerStatus | null {\n if (typeof item[\"text\"] !== \"string\") return null;\n const markers = linesOutsideFences(item[\"text\"]).filter((line) =>\n line.startsWith(WORKER_STATUS_PREFIX),\n );\n const marker = markers[0];\n if (markers.length !== 1 || marker === undefined) return null;\n const parsed = dispatchSchema.safeParse(\n parseJson(() => marker.slice(WORKER_STATUS_PREFIX.length)),\n );\n return parsed.success ? { kind: \"dispatch\", ...parsed.data } : null;\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Classify canonical records with host-provided execution
|
|
2
|
+
|
|
3
|
+
`codex-security classify-severity --records` accepts canonical reports without a
|
|
4
|
+
repository, saved scan, synthetic provenance, local Codex login, or filesystem
|
|
5
|
+
state. It uses the same bidirectional JSON-RPC transport as [record deduplication](dedupe-records.md).
|
|
6
|
+
Use `--records` alone; saved-scan classification remains unchanged.
|
|
7
|
+
|
|
8
|
+
The SDK exports `classifySeverityRecords`, `classifySeverityRecordsInputSchema`,
|
|
9
|
+
and their input, result, and review-request types. The protocol and input have
|
|
10
|
+
version `1`. This is an additive capability: pin an artifact containing this
|
|
11
|
+
implementation until it is included in a published release. A prior CLI that does
|
|
12
|
+
not advertise `--records` in `classify-severity --help` cannot run this protocol.
|
|
13
|
+
|
|
14
|
+
## Immutable inputs
|
|
15
|
+
|
|
16
|
+
Send one newline-delimited JSON-RPC request with `method: "run"` and these params:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
{
|
|
20
|
+
version: 1,
|
|
21
|
+
rubric: { revision: 4, markdown: rubricMarkdown, sha256: rubricSha256 },
|
|
22
|
+
model: "your-authorized-model",
|
|
23
|
+
effort: "high",
|
|
24
|
+
records: [{ id: "canonical-one", revision: 7, findingJson, inputSha256 }]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`findingJson` is the exact JSON text of an object with nonblank `findingId`,
|
|
29
|
+
`title`, and `summary`. `findingId` must equal the canonical `id`. Optional
|
|
30
|
+
`severity.level` uses `critical`, `high`, `medium`, `low`, or `informational`.
|
|
31
|
+
Other report fields are preserved as evidence. Missing legacy titles or summaries
|
|
32
|
+
must be resolved by the caller; do not invent evidence or scan metadata.
|
|
33
|
+
|
|
34
|
+
Both hashes are lowercase SHA-256 hex of the exact UTF-8 string bytes, without
|
|
35
|
+
normalizing newlines, whitespace, Unicode, object key order, or JSON numbers.
|
|
36
|
+
Compute `inputSha256` from `findingJson`, not from its parsed/reserialized object.
|
|
37
|
+
For example, Node uses `createHash("sha256").update(text, "utf8").digest("hex")`;
|
|
38
|
+
Python uses `hashlib.sha256(text.encode("utf-8")).hexdigest()`.
|
|
39
|
+
The CLI recomputes both hashes before requesting any review. Rubric revisions are
|
|
40
|
+
positive safe integers; record revisions are nonnegative safe integers. Duplicate
|
|
41
|
+
canonical IDs and invalid records reject the entire input before host work.
|
|
42
|
+
The implementation snapshots caller input before awaiting model execution and
|
|
43
|
+
preserves the validated report JSON text verbatim in the model prompt, including
|
|
44
|
+
numeric evidence that JavaScript cannot represent exactly.
|
|
45
|
+
|
|
46
|
+
## Host execution contract
|
|
47
|
+
|
|
48
|
+
For each record the CLI emits `method: "review.run"`, with a unique request ID
|
|
49
|
+
and params containing `requestId`, `stage: "severity-classification"`, explicit
|
|
50
|
+
`model` and `effort`, `trustedInstructions`, untrusted report/rubric `prompt`, and
|
|
51
|
+
an output JSON `schema`. The host must authorize the requested model and effort,
|
|
52
|
+
create a fresh independent review context, preserve the instruction/data boundary,
|
|
53
|
+
and disable tools, repository access, browsing, and source inspection.
|
|
54
|
+
A managed-agent host can execute this request directly in its existing session
|
|
55
|
+
infrastructure; it does not need a repository checkout. The CLI does not provide
|
|
56
|
+
credentials, create sessions, or select an authentication fallback.
|
|
57
|
+
|
|
58
|
+
Reply with the same JSON-RPC ID and `result` set to the schema-conforming assessment
|
|
59
|
+
object. Do not wrap the assessment in a string or an array. An assessment contains
|
|
60
|
+
`findingId`, `decision` (`assessed` or `excluded`), normalized `level`, original
|
|
61
|
+
`rubricLabel`, `rationale`, separate `confidence`, and nullable `reviewTrigger`.
|
|
62
|
+
Excluded assessments require null level and label; assessed ones require both.
|
|
63
|
+
|
|
64
|
+
The host owns model budgets, transport limits, timeouts, and session cancellation.
|
|
65
|
+
Use the transport's `cancel` notification with the active run ID and also stop
|
|
66
|
+
any remote execution. EOF or a broken pipe means disconnection, not successful
|
|
67
|
+
completion. No review is retried automatically, including after an ambiguous
|
|
68
|
+
host execution error.
|
|
69
|
+
|
|
70
|
+
## Results and persistence
|
|
71
|
+
|
|
72
|
+
A completed result contains `version: 1`, `status: "completed"`, the rubric's
|
|
73
|
+
`revision` and `sha256`, and `assessments`. Each assessment replaces model-provided
|
|
74
|
+
`findingId` with the verified canonical `id`, `revision`, and `inputSha256`.
|
|
75
|
+
The original report and severity are never rewritten.
|
|
76
|
+
|
|
77
|
+
Invalid or mismatched model output and host failures return `status: "unresolved"`,
|
|
78
|
+
an empty `assessments` array, and an error with `recordId` and stable code
|
|
79
|
+
`invalid_assessment` or `review_failed`. Earlier assessments in that invocation
|
|
80
|
+
are discarded. Invalid input, protocol errors, and cancellation use JSON-RPC error
|
|
81
|
+
responses. Exit codes are 0 for completion, 1 for unresolved review, and 2 for
|
|
82
|
+
input/protocol failure (130/143 for SIGINT/SIGTERM).
|
|
83
|
+
|
|
84
|
+
Prefer one canonical record per workflow invocation when the host needs independent
|
|
85
|
+
retries and partial success. The host should retain immutable rubric/report
|
|
86
|
+
snapshots, compare every echoed binding, and conditionally persist only computed
|
|
87
|
+
prioritization fields if the expected canonical version and rubric still apply.
|
|
88
|
+
Keep manual edits and original severity intact. Repeating the same inputs binds
|
|
89
|
+
results to the same hashes; it does not promise deterministic model answers.
|