Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Keep the native vcs block intact in the Elastic pack

Claude57c11cb70589
diff --git a/cli/beacon/internal/endpoint/elastic/elastic_test.go b/cli/beacon/internal/endpoint/elastic/elastic_test.go
index 513f72a0..c77ab418 100644
--- a/cli/beacon/internal/endpoint/elastic/elastic_test.go
+++ b/cli/beacon/internal/endpoint/elastic/elastic_test.go
@@ -269,3 +269,44 @@ func TestInputSnippet_DefaultLogPath(t *testing.T) {
t.Fatalf("InputSnippet with empty logPath should use DefaultLogPath %q, got: %s", DefaultLogPath, got)
}
}
+
+// The native vcs block (session.commit_linked events) must not collide with the ECS vcs fields the
+// pipeline derives from repository and branch: it is kept whole under beacon.vcs, and the ECS
+// fields prefer its remote URL, branch and revision.
+func TestIngestPipelineKeepsNativeVCS(t *testing.T) {
+ pipeline := mustRead("pack/ingest-pipeline.json")
+ for _, want := range []string{
+ "ctx.remove('vcs')",
+ "beacon.vcs = nativeVcs",
+ "nativeVcs.repository.url.full",
+ "'head').revision = vcsRevision",
+ } {
+ if !strings.Contains(pipeline, want) {
+ t.Fatalf("ingest pipeline missing %s", want)
+ }
+ }
+ // The native block is read before the ECS fields are written, or the first write would replace
+ // the remote URL with the local path.
+ if strings.Index(pipeline, "ctx.remove('vcs')") > strings.Index(pipeline, "ensure(ensure(ctx, 'vcs'), 'repository').url") {
+ t.Fatal("native vcs must be captured before ECS vcs fields are set")
+ }
+ var mappings map[string]interface{}
+ if err := json.Unmarshal([]byte(mustRead("pack/component-template-mappings.json")), &mappings); err != nil {
+ t.Fatal(err)
+ }
+ props := mappings["template"].(map[string]interface{})["mappings"].(map[string]interface{})["properties"].(map[string]interface{})
+ beacon := props["beacon"].(map[string]interface{})["properties"].(map[string]interface{})
+ if _, ok := beacon["vcs"]; !ok {
+ t.Fatal("beacon.vcs is not mapped")
+ }
+ sawLink := false
+ scanner := bufio.NewScanner(strings.NewReader(mustRead("pack/sample-event.jsonl")))
+ for scanner.Scan() {
+ if strings.Contains(scanner.Text(), `"session.commit_linked"`) {
+ sawLink = true
+ }
+ }
+ if !sawLink {
+ t.Fatal("sample events should include a session.commit_linked event")
+ }
+}
diff --git a/cli/beacon/internal/endpoint/elastic/pack/component-template-mappings.json b/cli/beacon/internal/endpoint/elastic/pack/component-template-mappings.json
index 92767beb..53dbdbf9 100644
--- a/cli/beacon/internal/endpoint/elastic/pack/component-template-mappings.json
+++ b/cli/beacon/internal/endpoint/elastic/pack/component-template-mappings.json
@@ -130,6 +130,13 @@
"name": { "type": "keyword" }
}
},
+ "vcs": {
+ "properties": {
+ "ref": { "properties": { "head": { "properties": { "revision": { "type": "keyword" }, "name": { "type": "keyword" }, "type": { "type": "keyword" } } } } },
+ "repository": { "properties": { "url": { "properties": { "full": { "type": "keyword" } } } } },
+ "attribution": { "properties": { "method": { "type": "keyword" }, "changed_files": { "type": "long" }, "matched_files": { "type": "long" } } }
+ }
+ },
"otel": {
"properties": {
"signal": { "type": "keyword" },
@@ -232,7 +239,8 @@
"properties": {
"head": {
"properties": {
- "name": { "type": "keyword" }
+ "name": { "type": "keyword" },
+ "revision": { "type": "keyword" }
}
}
}
diff --git a/cli/beacon/internal/endpoint/elastic/pack/ingest-pipeline.json b/cli/beacon/internal/endpoint/elastic/pack/ingest-pipeline.json
index 94c79bf5..9ef8d87f 100644
--- a/cli/beacon/internal/endpoint/elastic/pack/ingest-pipeline.json
+++ b/cli/beacon/internal/endpoint/elastic/pack/ingest-pipeline.json
@@ -38,7 +38,7 @@
"script": {
"description": "Copy Beacon fields to ECS and preserve native fields under beacon.*",
"lang": "painless",
- "source": "Map ensure(Map parent, String key) { if (parent[key] == null || !(parent[key] instanceof Map)) { parent[key] = new HashMap(); } return parent[key]; } Map beacon = ensure(ctx, 'beacon'); if (ctx.vendor != null) { beacon.vendor = ctx.vendor; } if (ctx.product != null) { beacon.product = ctx.product; } if (ctx.schema_version != null) { beacon.schema_version = ctx.schema_version; } if (ctx.sequence != null) { beacon.sequence = ctx.sequence; } if (ctx.severity != null) { beacon.severity = ctx.severity; } if (ctx.field_truncated != null) { beacon.truncated = ctx.field_truncated; } Map agent = ensure(ctx, 'agent'); agent.name = 'beacon'; agent.type = 'endpoint-agent'; if (ctx.endpoint instanceof Map && ctx.endpoint.agent_version != null) { agent.version = ctx.endpoint.agent_version; } else if (ctx.schema_version != null) { agent.version = ctx.schema_version; } Map event = ensure(ctx, 'event'); event.kind = 'event'; if (ctx.event instanceof Map) { if (ctx.event.action != null) { event.action = ctx.event.action; } if (ctx.event.category != null) { event.category = [ctx.event.category.toString()]; } } if (ctx.severity != null) { Map sev = new HashMap(); sev.put('info', 2); sev.put('low', 3); sev.put('medium', 4); sev.put('high', 5); sev.put('critical', 6); String key = ctx.severity.toString().toLowerCase(); if (sev.containsKey(key)) { event.severity = sev[key]; } } if (ctx.endpoint instanceof Map) { Map host = ensure(ctx, 'host'); if (ctx.endpoint.hostname != null) { host.hostname = ctx.endpoint.hostname; host.name = ctx.endpoint.hostname; } if (ctx.endpoint.os != null) { Map os = ensure(host, 'os'); String osName = ctx.endpoint.os.toString(); os.family = osName; os.type = osName == 'darwin' ? 'macos' : osName; } } if (ctx.user instanceof Map) { Map user = ensure(ctx, 'user'); if (ctx.user.name != null) { user.name = ctx.user.name; } if (ctx.user.uid != null) { user.id = ctx.user.uid; } } if (ctx.harness instanceof Map) { Map harness = ensure(beacon, 'harness'); if (ctx.harness.name != null) { harness.name = ctx.harness.name; ensure(ctx, 'service').name = ctx.harness.name; } if (ctx.harness.version != null) { harness.version = ctx.harness.version; } if (ctx.harness.executable_path != null) { harness.executable_path = ctx.harness.executable_path; } if (ctx.harness.config_path != null) { harness.config_path = ctx.harness.config_path; } } if (ctx.session instanceof Map) { Map session = ensure(beacon, 'session'); if (ctx.session.id != null) { session.id = ctx.session.id; if (ctx.trace == null) { ctx.trace = new HashMap(); } if (ctx.trace.id == null && ctx.session.id.toString().length() == 32) { ctx.trace.id = ctx.session.id; } } if (ctx.session.working_directory != null) { ensure(ctx, 'process').working_directory = ctx.session.working_directory; } } if (ctx.tool instanceof Map) { Map tool = ensure(beacon, 'tool'); if (ctx.tool.name != null) { tool.name = ctx.tool.name; } Map process = ensure(ctx, 'process'); if (process.command_line == null && ctx.tool.command != null) { process.command_line = ctx.tool.command; } if (ctx.tool.path != null) { process.executable = ctx.tool.path; } } if (ctx.command instanceof Map) { Map process = ensure(ctx, 'process'); if (ctx.command.command != null) { process.command_line = ctx.command.command; } if (ctx.command.exit_code != null) { process.exit_code = ctx.command.exit_code; } if (ctx.command.duration_ms != null) { event.duration = ((long)ctx.command.duration_ms) * 1000000L; } } if (ctx.file instanceof Map) { Map file = ensure(ctx, 'file'); Map beaconFile = ensure(beacon, 'file'); if (ctx.file.path != null) { String p = ctx.file.path.toString(); file.path = p; int slash = p.lastIndexOf('/'); String name = slash >= 0 ? p.substring(slash + 1) : p; if (slash > 0) { file.directory = p.substring(0, slash); } file.name = name; int dot = name.lastIndexOf('.'); if (dot > 0 && dot < name.length() - 1) { file.extension = name.substring(dot + 1); } } if (ctx.file.diff_hash != null) { ensure(file, 'hash').sha256 = ctx.file.diff_hash; } if (ctx.file.diff_bytes != null) { file.size = ctx.file.diff_bytes; } if (ctx.file.operation != null) { beaconFile.operation = ctx.file.operation; } if (ctx.file.language != null) { beaconFile.language = ctx.file.language; } } if (ctx.mcp instanceof Map) { Map mcp = ensure(beacon, 'mcp'); if (ctx.mcp.server != null) { mcp.server = ctx.mcp.server; } if (ctx.mcp.tool != null) { mcp.tool = ctx.mcp.tool; } } if (ctx.approval instanceof Map) { Map approval = ensure(beacon, 'approval'); if (ctx.approval.required != null) { approval.required = ctx.approval.required; } if (ctx.approval.decision != null) { String decision = ctx.approval.decision.toString(); approval.decision = decision; if (decision == 'allow' || decision == 'approved') { event.outcome = 'success'; } else if (decision == 'deny' || decision == 'denied' || decision == 'block' || decision == 'blocked') { event.outcome = 'failure'; } } if (ctx.approval.reason != null) { approval.reason = ctx.approval.reason; } } if (ctx.policy instanceof Map) { Map policy = ensure(beacon, 'policy'); if (ctx.policy.id != null) { policy.id = ctx.policy.id; } if (ctx.policy.name != null) { policy.name = ctx.policy.name; } if (ctx.policy.decision != null) { policy.decision = ctx.policy.decision; } if (ctx.policy.enforcement != null) { policy.enforcement = ctx.policy.enforcement; } if (ctx.policy.reason != null) { policy.reason = ctx.policy.reason; } } if (ctx.prompt instanceof Map && ctx.prompt.text != null) { ensure(beacon, 'prompt').text = ctx.prompt.text; } if (ctx.content instanceof Map) { Map content = ensure(beacon, 'content'); if (ctx.content.retention != null) { content.retention = ctx.content.retention; } if (ctx.content.included != null) { content.included = ctx.content.included; } if (ctx.content.redacted != null) { content.redacted = ctx.content.redacted; } if (ctx.content.truncated != null) { content.truncated = ctx.content.truncated; } } if (ctx.destination instanceof Map) { Map destination = ensure(beacon, 'destination'); if (ctx.destination.type != null) { destination.type = ctx.destination.type; } if (ctx.destination.mode != null) { destination.mode = ctx.destination.mode; } if (ctx.destination.status != null) { destination.status = ctx.destination.status; } } if (ctx.health instanceof Map) { Map health = ensure(beacon, 'health'); if (ctx.health.component != null) { health.component = ctx.health.component; } if (ctx.health.status != null) { health.status = ctx.health.status; } if (ctx.health.reason != null) { health.reason = ctx.health.reason; } } if (ctx.model != null) { ensure(ensure(ctx, 'gen_ai'), 'request').model = ctx.model; } if (ctx.repository != null) { ensure(ensure(ctx, 'vcs'), 'repository').url = ctx.repository; } if (ctx.branch != null) { ensure(ensure(ensure(ctx, 'vcs'), 'ref'), 'head').name = ctx.branch; } if (ctx.raw instanceof Map) { Map otel = ensure(beacon, 'otel'); if (ctx.raw.otel_signal != null) { otel.signal = ctx.raw.otel_signal; } if (ctx.raw.metric_name != null) { ensure(beacon, 'metric').name = ctx.raw.metric_name; if (event.action == null || event.action == 'metric.observed') { event.action = ctx.raw.metric_name; } } if (ctx.raw.metric_description != null) { otel.metric_description = ctx.raw.metric_description; } if (ctx.raw.metric_unit != null) { otel.metric_unit = ctx.raw.metric_unit; } if (ctx.raw.attribute_count != null) { otel.attribute_count = ctx.raw.attribute_count; } if (ctx.raw.attributes != null) { otel.attributes = ctx.raw.attributes; } }"
+ "source": "Map ensure(Map parent, String key) { if (parent[key] == null || !(parent[key] instanceof Map)) { parent[key] = new HashMap(); } return parent[key]; } Map beacon = ensure(ctx, 'beacon'); if (ctx.vendor != null) { beacon.vendor = ctx.vendor; } if (ctx.product != null) { beacon.product = ctx.product; } if (ctx.schema_version != null) { beacon.schema_version = ctx.schema_version; } if (ctx.sequence != null) { beacon.sequence = ctx.sequence; } if (ctx.severity != null) { beacon.severity = ctx.severity; } if (ctx.field_truncated != null) { beacon.truncated = ctx.field_truncated; } Map agent = ensure(ctx, 'agent'); agent.name = 'beacon'; agent.type = 'endpoint-agent'; if (ctx.endpoint instanceof Map && ctx.endpoint.agent_version != null) { agent.version = ctx.endpoint.agent_version; } else if (ctx.schema_version != null) { agent.version = ctx.schema_version; } Map event = ensure(ctx, 'event'); event.kind = 'event'; if (ctx.event instanceof Map) { if (ctx.event.action != null) { event.action = ctx.event.action; } if (ctx.event.category != null) { event.category = [ctx.event.category.toString()]; } } if (ctx.severity != null) { Map sev = new HashMap(); sev.put('info', 2); sev.put('low', 3); sev.put('medium', 4); sev.put('high', 5); sev.put('critical', 6); String key = ctx.severity.toString().toLowerCase(); if (sev.containsKey(key)) { event.severity = sev[key]; } } if (ctx.endpoint instanceof Map) { Map host = ensure(ctx, 'host'); if (ctx.endpoint.hostname != null) { host.hostname = ctx.endpoint.hostname; host.name = ctx.endpoint.hostname; } if (ctx.endpoint.os != null) { Map os = ensure(host, 'os'); String osName = ctx.endpoint.os.toString(); os.family = osName; os.type = osName == 'darwin' ? 'macos' : osName; } } if (ctx.user instanceof Map) { Map user = ensure(ctx, 'user'); if (ctx.user.name != null) { user.name = ctx.user.name; } if (ctx.user.uid != null) { user.id = ctx.user.uid; } } if (ctx.harness instanceof Map) { Map harness = ensure(beacon, 'harness'); if (ctx.harness.name != null) { harness.name = ctx.harness.name; ensure(ctx, 'service').name = ctx.harness.name; } if (ctx.harness.version != null) { harness.version = ctx.harness.version; } if (ctx.harness.executable_path != null) { harness.executable_path = ctx.harness.executable_path; } if (ctx.harness.config_path != null) { harness.config_path = ctx.harness.config_path; } } if (ctx.session instanceof Map) { Map session = ensure(beacon, 'session'); if (ctx.session.id != null) { session.id = ctx.session.id; if (ctx.trace == null) { ctx.trace = new HashMap(); } if (ctx.trace.id == null && ctx.session.id.toString().length() == 32) { ctx.trace.id = ctx.session.id; } } if (ctx.session.working_directory != null) { ensure(ctx, 'process').working_directory = ctx.session.working_directory; } } if (ctx.tool instanceof Map) { Map tool = ensure(beacon, 'tool'); if (ctx.tool.name != null) { tool.name = ctx.tool.name; } Map process = ensure(ctx, 'process'); if (process.command_line == null && ctx.tool.command != null) { process.command_line = ctx.tool.command; } if (ctx.tool.path != null) { process.executable = ctx.tool.path; } } if (ctx.command instanceof Map) { Map process = ensure(ctx, 'process'); if (ctx.command.command != null) { process.command_line = ctx.command.command; } if (ctx.command.exit_code != null) { process.exit_code = ctx.command.exit_code; } if (ctx.command.duration_ms != null) { event.duration = ((long)ctx.command.duration_ms) * 1000000L; } } if (ctx.file instanceof Map) { Map file = ensure(ctx, 'file'); Map beaconFile = ensure(beacon, 'file'); if (ctx.file.path != null) { String p = ctx.file.path.toString(); file.path = p; int slash = p.lastIndexOf('/'); String name = slash >= 0 ? p.substring(slash + 1) : p; if (slash > 0) { file.directory = p.substring(0, slash); } file.name = name; int dot = name.lastIndexOf('.'); if (dot > 0 && dot < name.length() - 1) { file.extension = name.substring(dot + 1); } } if (ctx.file.diff_hash != null) { ensure(file, 'hash').sha256 = ctx.file.diff_hash; } if (ctx.file.diff_bytes != null) { file.size = ctx.file.diff_bytes; } if (ctx.file.operation != null) { beaconFile.operation = ctx.file.operation; } if (ctx.file.language != null) { beaconFile.language = ctx.file.language; } } if (ctx.mcp instanceof Map) { Map mcp = ensure(beacon, 'mcp'); if (ctx.mcp.server != null) { mcp.server = ctx.mcp.server; } if (ctx.mcp.tool != null) { mcp.tool = ctx.mcp.tool; } } if (ctx.approval instanceof Map) { Map approval = ensure(beacon, 'approval'); if (ctx.approval.required != null) { approval.required = ctx.approval.required; } if (ctx.approval.decision != null) { String decision = ctx.approval.decision.toString(); approval.decision = decision; if (decision == 'allow' || decision == 'approved') { event.outcome = 'success'; } else if (decision == 'deny' || decision == 'denied' || decision == 'block' || decision == 'blocked') { event.outcome = 'failure'; } } if (ctx.approval.reason != null) { approval.reason = ctx.approval.reason; } } if (ctx.policy instanceof Map) { Map policy = ensure(beacon, 'policy'); if (ctx.policy.id != null) { policy.id = ctx.policy.id; } if (ctx.policy.name != null) { policy.name = ctx.policy.name; } if (ctx.policy.decision != null) { policy.decision = ctx.policy.decision; } if (ctx.policy.enforcement != null) { policy.enforcement = ctx.policy.enforcement; } if (ctx.policy.reason != null) { policy.reason = ctx.policy.reason; } } if (ctx.prompt instanceof Map && ctx.prompt.text != null) { ensure(beacon, 'prompt').text = ctx.prompt.text; } if (ctx.content instanceof Map) { Map content = ensure(beacon, 'content'); if (ctx.content.retention != null) { content.retention = ctx.content.retention; } if (ctx.content.included != null) { content.included = ctx.content.included; } if (ctx.content.redacted != null) { content.redacted = ctx.content.redacted; } if (ctx.content.truncated != null) { content.truncated = ctx.content.truncated; } } if (ctx.destination instanceof Map) { Map destination = ensure(beacon, 'destination'); if (ctx.destination.type != null) { destination.type = ctx.destination.type; } if (ctx.destination.mode != null) { destination.mode = ctx.destination.mode; } if (ctx.destination.status != null) { destination.status = ctx.destination.status; } } if (ctx.health instanceof Map) { Map health = ensure(beacon, 'health'); if (ctx.health.component != null) { health.component = ctx.health.component; } if (ctx.health.status != null) { health.status = ctx.health.status; } if (ctx.health.reason != null) { health.reason = ctx.health.reason; } } if (ctx.model != null) { ensure(ensure(ctx, 'gen_ai'), 'request').model = ctx.model; } Map nativeVcs = ctx.vcs instanceof Map ? ctx.vcs : null; ctx.remove('vcs'); String vcsUrl = null; String vcsHeadName = null; String vcsRevision = null; if (nativeVcs != null) { beacon.vcs = nativeVcs; if (nativeVcs.repository instanceof Map && nativeVcs.repository.url instanceof Map && nativeVcs.repository.url.full != null) { vcsUrl = nativeVcs.repository.url.full.toString(); } if (nativeVcs.ref instanceof Map && nativeVcs.ref.head instanceof Map) { if (nativeVcs.ref.head.name != null) { vcsHeadName = nativeVcs.ref.head.name.toString(); } if (nativeVcs.ref.head.revision != null) { vcsRevision = nativeVcs.ref.head.revision.toString(); } } } if (vcsUrl == null && ctx.repository != null) { vcsUrl = ctx.repository.toString(); } if (vcsHeadName == null && ctx.branch != null) { vcsHeadName = ctx.branch.toString(); } if (vcsUrl != null) { ensure(ensure(ctx, 'vcs'), 'repository').url = vcsUrl; } if (vcsHeadName != null) { ensure(ensure(ensure(ctx, 'vcs'), 'ref'), 'head').name = vcsHeadName; } if (vcsRevision != null) { ensure(ensure(ensure(ctx, 'vcs'), 'ref'), 'head').revision = vcsRevision; } if (ctx.raw instanceof Map) { Map otel = ensure(beacon, 'otel'); if (ctx.raw.otel_signal != null) { otel.signal = ctx.raw.otel_signal; } if (ctx.raw.metric_name != null) { ensure(beacon, 'metric').name = ctx.raw.metric_name; if (event.action == null || event.action == 'metric.observed') { event.action = ctx.raw.metric_name; } } if (ctx.raw.metric_description != null) { otel.metric_description = ctx.raw.metric_description; } if (ctx.raw.metric_unit != null) { otel.metric_unit = ctx.raw.metric_unit; } if (ctx.raw.attribute_count != null) { otel.attribute_count = ctx.raw.attribute_count; } if (ctx.raw.attributes != null) { otel.attributes = ctx.raw.attributes; } }"
}
},
{
diff --git a/cli/beacon/internal/endpoint/elastic/pack/sample-event.jsonl b/cli/beacon/internal/endpoint/elastic/pack/sample-event.jsonl
index 1bfde409..b4fb652d 100644
--- a/cli/beacon/internal/endpoint/elastic/pack/sample-event.jsonl
+++ b/cli/beacon/internal/endpoint/elastic/pack/sample-event.jsonl
@@ -1,2 +1,3 @@
{"timestamp":"2026-05-11T22:21:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"command.executed","category":"command"},"severity":"info","endpoint":{"hostname":"example-mac","os":"darwin","agent_version":"0.1.0"},"user":{"name":"local-user","uid":"501"},"harness":{"name":"cursor","version":"0.50.0"},"session":{"id":"conversation-1","working_directory":"/Users/local-user/repo"},"tool":{"name":"Shell","command":"go test ./...","path":"/bin/zsh"},"command":{"command":"go test ./...","exit_code":0,"duration_ms":1234},"repository":"file:///Users/local-user/repo","branch":"main","message":"Shell command executed"}
{"timestamp":"2026-05-11T22:22:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"metric.observed","category":"metric"},"severity":"info","endpoint":{"hostname":"example-mac","os":"darwin","agent_version":"0.1.0"},"user":{"name":"local-user"},"harness":{"name":"codex_cli"},"raw":{"otel_signal":"metrics","metric_name":"codex.tool.call.duration_ms","metric_description":"Codex tool call duration","metric_unit":"ms","attributes":{"service.name":"codex","session.id":"conversation-2"}},"message":"codex.tool.call.duration_ms"}
+{"timestamp":"2026-09-27T17:56:51.202501793Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"id":"fcc0e96e-6204-545e-9c17-37c061d4db4f","kind":"agent_runtime","action":"session.commit_linked","category":"session","fidelity":"inferred"},"severity":"info","endpoint":{"hostname":"dev-laptop","os":"darwin","agent_version":"0.0.1"},"user":{"name":"dev"},"harness":{"name":"claude_code"},"session":{"id":"sess-e2e3","working_directory":"/Users/dev/src/demo"},"trace":{"id":"session:claude_code:sess-e2e3"},"vcs":{"ref":{"head":{"revision":"72bd2a425588ab61c311fdc7d5bcfd0afcb34f4b","name":"main","type":"branch"}},"repository":{"url":{"full":"https://github.com/org/demo.git"}},"attribution":{"method":"file_overlap","changed_files":1,"matched_files":1}},"repository":"/Users/dev/src/demo","branch":"main","message":"commit 72bd2a425588 linked to this session: it wrote 1 of the 1 file(s) the commit changes"}