Track artifact operations from trusted plugin markers (#38057)

## What changed

- Recognize validated create and edit marker commands from the trusted presentations, documents, spreadsheets, and PDF plugins.
- Emit a `codex_artifact_operation` analytics event plus started-count and expected-output-count metrics when a recognized marker starts through unified exec.
- Attribute remote executor commands only when their plugin cache path and script contents match a trusted local plugin, including primary-runtime plugins.

## Testing

- Cover supported marker combinations and reject mismatched plugins, paths, arguments, counts, and output formats.
- Cover local, relocated remote, and Windows-style plugin attribution, including rejection of modified remote scripts.

GitOrigin-RevId: 475cc1689aa7f371a24dec0a8bdb6f7fd5a2e922
This commit is contained in:
edwardysun3 authored and copyberry committed 2026-08-11 19:26:41 +00:00
1 parent 285abc0368
commit 44d992c14e
18 files changed
+971 -60

No files matched your search

+57
View File
@@ -2,6 +2,8 @@ use std::time::Instant;
use crate::facts::AcceptedLineFingerprint;
use crate::facts::AppInvocation;
use crate::facts::ArtifactOperation;
use crate::facts::ArtifactOperationLifecycle;
use crate::facts::CodexCompactionEvent;
use crate::facts::CodexErrKind;
use crate::facts::CodexGoalEvent;
@@ -72,6 +74,7 @@ pub(crate) enum TrackEventRequest {
Goal(Box<CodexGoalEventRequest>),
TurnEvent(Box<CodexTurnEventRequest>),
TurnSteer(CodexTurnSteerEventRequest),
ArtifactOperation(CodexArtifactOperationEventRequest),
CommandExecution(CodexCommandExecutionEventRequest),
FileChange(CodexFileChangeEventRequest),
McpToolCall(CodexMcpToolCallEventRequest),
@@ -93,6 +96,59 @@ pub(crate) enum TrackEventRequest {
ExternalAgentConfigImportFailure(CodexOnboardingExternalAgentImportFailureEventRequest),
}
#[derive(Serialize)]
pub(crate) struct CodexArtifactOperationEventParams {
pub(crate) thread_id: String,
pub(crate) turn_id: String,
pub(crate) item_id: String,
pub(crate) lifecycle: ArtifactOperationLifecycle,
pub(crate) occurred_at_ms: u64,
pub(crate) product_client_id: String,
pub(crate) runtime: CodexRuntimeMetadata,
pub(crate) model_slug: String,
pub(crate) plugin_id: String,
pub(crate) script_path: String,
pub(crate) skill: String,
pub(crate) artifact_type: String,
pub(crate) operation_kind: String,
pub(crate) expected_output_count: u32,
pub(crate) output_format: String,
pub(crate) execution_backend: String,
}
#[derive(Serialize)]
pub(crate) struct CodexArtifactOperationEventRequest {
pub(crate) event_type: &'static str,
pub(crate) event_params: CodexArtifactOperationEventParams,
}
pub(crate) fn codex_artifact_operation_event_request(
tracking: TrackEventsContext,
operation: ArtifactOperation,
) -> CodexArtifactOperationEventRequest {
CodexArtifactOperationEventRequest {
event_type: "codex_artifact_operation",
event_params: CodexArtifactOperationEventParams {
thread_id: tracking.thread_id,
turn_id: tracking.turn_id,
item_id: operation.item_id,
lifecycle: operation.lifecycle,
occurred_at_ms: operation.occurred_at_ms,
product_client_id: tracking.product_client_id,
runtime: current_runtime_metadata(),
model_slug: tracking.model_slug,
plugin_id: operation.plugin_id,
script_path: operation.script_path,
skill: operation.skill,
artifact_type: operation.artifact_type,
operation_kind: operation.operation_kind,
expected_output_count: operation.expected_output_count,
output_format: operation.output_format,
execution_backend: operation.execution_backend,
},
}
}
impl TrackEventRequest {
pub(crate) fn should_send_in_isolated_request(&self) -> bool {
matches!(self, Self::AcceptedLineFingerprints(_))
@@ -103,6 +159,7 @@ impl TrackEventRequest {
Self::PluginUsed(event) => event.event_params.plugin.plugin_id.is_some(),
Self::SkillInvocation(event) => event.event_params.plugin_id.is_some(),
Self::McpToolCall(event) => event.event_params.plugin_id.is_some(),
Self::ArtifactOperation(event) => !event.event_params.plugin_id.is_empty(),
_ => false,
}
}