@raytrace-cli/cli 0.4.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.
Files changed (102) hide show
  1. package/README.md +132 -126
  2. package/bin/raytrace.mjs +41 -20
  3. package/dist/dashboard/assets/dm-sans-latin-400-normal-BwCSEQnW.woff +0 -0
  4. package/dist/dashboard/assets/dm-sans-latin-400-normal-CW0RaeGs.woff2 +0 -0
  5. package/dist/dashboard/assets/dm-sans-latin-500-normal-B9HHJjqV.woff2 +0 -0
  6. package/dist/dashboard/assets/dm-sans-latin-500-normal-Dr3UlScf.woff +0 -0
  7. package/dist/dashboard/assets/dm-sans-latin-600-normal-Aqo67rzb.woff2 +0 -0
  8. package/dist/dashboard/assets/dm-sans-latin-600-normal-BmdmIIQ2.woff +0 -0
  9. package/dist/dashboard/assets/dm-sans-latin-700-normal-CUSSCpQX.woff +0 -0
  10. package/dist/dashboard/assets/dm-sans-latin-700-normal-DvUfVpUG.woff2 +0 -0
  11. package/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BjWJ59Pq.woff +0 -0
  12. package/dist/dashboard/assets/dm-sans-latin-ext-400-normal-BtiwyxMk.woff2 +0 -0
  13. package/dist/dashboard/assets/dm-sans-latin-ext-500-normal-BJfUCQsA.woff2 +0 -0
  14. package/dist/dashboard/assets/dm-sans-latin-ext-500-normal-DR84L5F-.woff +0 -0
  15. package/dist/dashboard/assets/dm-sans-latin-ext-600-normal-4vooXBpG.woff2 +0 -0
  16. package/dist/dashboard/assets/dm-sans-latin-ext-600-normal-DRtaDpgU.woff +0 -0
  17. package/dist/dashboard/assets/dm-sans-latin-ext-700-normal-BLI3TTWz.woff +0 -0
  18. package/dist/dashboard/assets/dm-sans-latin-ext-700-normal-CJIcxD6K.woff2 +0 -0
  19. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  20. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  21. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  22. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  23. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-CTOM6hUh.woff2 +0 -0
  24. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-600-normal-fLZuRloM.woff +0 -0
  25. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  26. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  27. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  28. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  29. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-9HEixskS.woff +0 -0
  30. package/dist/dashboard/assets/ibm-plex-mono-cyrillic-ext-600-normal-V-xxqcpd.woff2 +0 -0
  31. package/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  32. package/dist/dashboard/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  33. package/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  34. package/dist/dashboard/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  35. package/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
  36. package/dist/dashboard/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
  37. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  38. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  39. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  40. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  41. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-D38SheWl.woff2 +0 -0
  42. package/dist/dashboard/assets/ibm-plex-mono-latin-ext-600-normal-DmB0ttJJ.woff +0 -0
  43. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  44. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  45. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  46. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  47. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-D2EvbN8M.woff2 +0 -0
  48. package/dist/dashboard/assets/ibm-plex-mono-vietnamese-600-normal-iLQfcSjf.woff +0 -0
  49. package/dist/dashboard/assets/index-DtV3UdEB.css +1 -0
  50. package/dist/dashboard/assets/index-jyV5iYHJ.js +38 -0
  51. package/dist/dashboard/index.html +2 -2
  52. package/package.json +3 -1
  53. package/proxy/call-assessment.mjs +385 -0
  54. package/proxy/call-category.mjs +461 -0
  55. package/proxy/capture.mjs +31 -0
  56. package/proxy/claude-code-adapter.mjs +46 -3
  57. package/proxy/evidence-store.mjs +617 -15
  58. package/proxy/exec-narrative.mjs +625 -0
  59. package/proxy/execution-correlation.mjs +185 -0
  60. package/proxy/experiment-engine.mjs +7 -4
  61. package/proxy/failure-signature.mjs +56 -0
  62. package/proxy/gvisor-forwarder.mjs +454 -0
  63. package/proxy/init-evidence-db.mjs +136 -12
  64. package/proxy/local-sandboxes.mjs +94 -0
  65. package/proxy/playground.mjs +411 -0
  66. package/proxy/prompt-context.mjs +12 -7
  67. package/proxy/prompt-traces.mjs +6 -0
  68. package/proxy/raytace-proxy.mjs +460 -176
  69. package/proxy/run-recap.mjs +139 -0
  70. package/proxy/runtime-attribution.mjs +110 -0
  71. package/proxy/sandbox-bridge.mjs +46 -0
  72. package/proxy/schema/EVIDENCE_DATABASE.md +276 -0
  73. package/proxy/schema/auxiliary.sql +48 -1
  74. package/proxy/schema/classification.sql +89 -0
  75. package/proxy/schema/file_context.sql +53 -0
  76. package/proxy/schema/runtime_evidence.sql +201 -0
  77. package/proxy/schema/search.sql +66 -0
  78. package/proxy/search.mjs +418 -0
  79. package/proxy/step-attribution.mjs +380 -0
  80. package/proxy/tool-metadata.mjs +36 -0
  81. package/proxy/trace-view.mjs +276 -0
  82. package/proxy/typesafe.mjs +63 -0
  83. package/src/commands.mjs +73 -4
  84. package/src/lima.mjs +135 -0
  85. package/src/local-sandbox.mjs +324 -0
  86. package/src/proxy-process.mjs +20 -1
  87. package/src/sandbox.mjs +24 -6
  88. package/worker/sandbox/Dockerfile +8 -0
  89. package/worker/sandbox/SYSCALL_CATALOG.md +197 -0
  90. package/worker/sandbox/claude-hook.mjs +331 -0
  91. package/worker/sandbox/collector.py +357 -0
  92. package/worker/sandbox/dns_forwarder.py +255 -0
  93. package/worker/sandbox/engine.py +940 -0
  94. package/worker/sandbox/file_scan.py +491 -0
  95. package/worker/sandbox/lima.yaml +29 -0
  96. package/worker/sandbox/network.py +90 -0
  97. package/worker/sandbox/projects.py +678 -0
  98. package/worker/sandbox/setup.py +159 -0
  99. package/worker/sandbox/syscall_catalog.sql +985 -0
  100. package/worker/sandbox/viewer.py +132 -0
  101. package/dist/dashboard/assets/index-BQ9_JxGq.js +0 -27
  102. package/dist/dashboard/assets/index-L5cUAvhE.css +0 -1
@@ -0,0 +1,89 @@
1
+ -- Classification reference and derived results. No classifier executes here.
2
+ CREATE TABLE classification_versions (
3
+ id TEXT NOT NULL PRIMARY KEY,
4
+ catalog_version TEXT NOT NULL,
5
+ classifier_version TEXT NOT NULL,
6
+ content_sha256 TEXT NOT NULL CHECK (length(content_sha256)=64 AND content_sha256 NOT GLOB '*[^0-9a-f]*'),
7
+ created_at_ms INTEGER NOT NULL CHECK (typeof(created_at_ms)='integer'),
8
+ description TEXT NOT NULL
9
+ );
10
+ CREATE TABLE classification_impact_levels (
11
+ level INTEGER NOT NULL PRIMARY KEY CHECK (typeof(level)='integer' AND level BETWEEN 0 AND 3),
12
+ label TEXT NOT NULL,
13
+ description TEXT NOT NULL
14
+ );
15
+ CREATE TABLE classification_categories (
16
+ id TEXT NOT NULL PRIMARY KEY,
17
+ label TEXT NOT NULL,
18
+ description TEXT NOT NULL
19
+ );
20
+ CREATE TABLE classification_syscall_rules (
21
+ version_id TEXT NOT NULL REFERENCES classification_versions(id),
22
+ syscall_name TEXT NOT NULL,
23
+ description TEXT NOT NULL,
24
+ category_id TEXT NOT NULL REFERENCES classification_categories(id),
25
+ default_impact_level INTEGER REFERENCES classification_impact_levels(level),
26
+ rule_identifier TEXT NOT NULL,
27
+ required_evidence_json TEXT NOT NULL CHECK (json_valid(required_evidence_json) AND json_type(required_evidence_json)='array'),
28
+ interpretation_notes TEXT NOT NULL,
29
+ PRIMARY KEY(version_id, syscall_name)
30
+ );
31
+ CREATE TABLE classification_results (
32
+ id TEXT NOT NULL PRIMARY KEY,
33
+ syscall_call_id TEXT NOT NULL REFERENCES runtime_syscall_calls(id),
34
+ version_id TEXT NOT NULL REFERENCES classification_versions(id),
35
+ input_sha256 TEXT NOT NULL CHECK (length(input_sha256)=64 AND input_sha256 NOT GLOB '*[^0-9a-f]*'),
36
+ category_id TEXT REFERENCES classification_categories(id),
37
+ operation_level INTEGER REFERENCES classification_impact_levels(level),
38
+ confirmed_effect_level INTEGER REFERENCES classification_impact_levels(level),
39
+ effect_status TEXT NOT NULL CHECK (effect_status IN ('confirmed','no_effect','unknown','not_applicable')),
40
+ reason TEXT NOT NULL,
41
+ classified_at_ms INTEGER NOT NULL CHECK (typeof(classified_at_ms)='integer'),
42
+ UNIQUE(syscall_call_id, version_id, input_sha256),
43
+ CHECK (effect_status='confirmed' OR confirmed_effect_level IS NULL),
44
+ CHECK (effect_status!='confirmed' OR confirmed_effect_level IS NOT NULL)
45
+ );
46
+ CREATE INDEX classification_rules_category ON classification_syscall_rules(category_id, version_id);
47
+ CREATE INDEX classification_results_version ON classification_results(version_id, classified_at_ms);
48
+ CREATE INDEX classification_results_category ON classification_results(category_id, operation_level);
49
+ CREATE TRIGGER classification_confirmed_success BEFORE INSERT ON classification_results
50
+ WHEN NEW.effect_status='confirmed' AND NOT EXISTS (
51
+ SELECT 1 FROM runtime_syscall_calls WHERE id=NEW.syscall_call_id AND outcome='succeeded'
52
+ )
53
+ BEGIN SELECT RAISE(ABORT, 'confirmed effect requires a successful syscall'); END;
54
+ CREATE TRIGGER classification_versions_no_update BEFORE UPDATE ON classification_versions
55
+ BEGIN SELECT RAISE(ABORT, 'classification_versions is append-only'); END;
56
+ CREATE TRIGGER classification_versions_no_delete BEFORE DELETE ON classification_versions
57
+ BEGIN SELECT RAISE(ABORT, 'classification_versions is append-only'); END;
58
+ CREATE TRIGGER classification_versions_no_replace BEFORE INSERT ON classification_versions
59
+ WHEN EXISTS (SELECT 1 FROM classification_versions WHERE id=NEW.id)
60
+ BEGIN SELECT RAISE(ABORT, 'classification_versions existing key cannot be replaced'); END;
61
+ CREATE TRIGGER classification_impact_levels_no_update BEFORE UPDATE ON classification_impact_levels
62
+ BEGIN SELECT RAISE(ABORT, 'classification_impact_levels is append-only'); END;
63
+ CREATE TRIGGER classification_impact_levels_no_delete BEFORE DELETE ON classification_impact_levels
64
+ BEGIN SELECT RAISE(ABORT, 'classification_impact_levels is append-only'); END;
65
+ CREATE TRIGGER classification_impact_levels_no_replace BEFORE INSERT ON classification_impact_levels
66
+ WHEN EXISTS (SELECT 1 FROM classification_impact_levels WHERE level=NEW.level)
67
+ BEGIN SELECT RAISE(ABORT, 'classification_impact_levels existing key cannot be replaced'); END;
68
+ CREATE TRIGGER classification_categories_no_update BEFORE UPDATE ON classification_categories
69
+ BEGIN SELECT RAISE(ABORT, 'classification_categories is append-only'); END;
70
+ CREATE TRIGGER classification_categories_no_delete BEFORE DELETE ON classification_categories
71
+ BEGIN SELECT RAISE(ABORT, 'classification_categories is append-only'); END;
72
+ CREATE TRIGGER classification_categories_no_replace BEFORE INSERT ON classification_categories
73
+ WHEN EXISTS (SELECT 1 FROM classification_categories WHERE id=NEW.id)
74
+ BEGIN SELECT RAISE(ABORT, 'classification_categories existing key cannot be replaced'); END;
75
+ CREATE TRIGGER classification_syscall_rules_no_update BEFORE UPDATE ON classification_syscall_rules
76
+ BEGIN SELECT RAISE(ABORT, 'classification_syscall_rules is append-only'); END;
77
+ CREATE TRIGGER classification_syscall_rules_no_delete BEFORE DELETE ON classification_syscall_rules
78
+ BEGIN SELECT RAISE(ABORT, 'classification_syscall_rules is append-only'); END;
79
+ CREATE TRIGGER classification_syscall_rules_no_replace BEFORE INSERT ON classification_syscall_rules
80
+ WHEN EXISTS (SELECT 1 FROM classification_syscall_rules WHERE version_id=NEW.version_id AND syscall_name=NEW.syscall_name)
81
+ BEGIN SELECT RAISE(ABORT, 'classification_syscall_rules existing key cannot be replaced'); END;
82
+ CREATE TRIGGER classification_results_no_update BEFORE UPDATE ON classification_results
83
+ BEGIN SELECT RAISE(ABORT, 'classification_results is append-only'); END;
84
+ CREATE TRIGGER classification_results_no_delete BEFORE DELETE ON classification_results
85
+ BEGIN SELECT RAISE(ABORT, 'classification_results is append-only'); END;
86
+ CREATE TRIGGER classification_results_no_replace BEFORE INSERT ON classification_results
87
+ WHEN EXISTS (SELECT 1 FROM classification_results WHERE id=NEW.id OR
88
+ (syscall_call_id=NEW.syscall_call_id AND version_id=NEW.version_id AND input_sha256=NEW.input_sha256))
89
+ BEGIN SELECT RAISE(ABORT, 'classification_results existing key cannot be replaced'); END;
@@ -0,0 +1,53 @@
1
+ -- File identity and contextual labels; no automatic identity resolution or scanning.
2
+ CREATE TABLE file_objects (
3
+ id TEXT NOT NULL PRIMARY KEY,
4
+ sandbox_id TEXT NOT NULL REFERENCES runtime_sandboxes(id),
5
+ object_type TEXT NOT NULL CHECK (object_type IN ('regular','directory','symlink','pipe','socket','device','unknown')),
6
+ filesystem_identity TEXT,
7
+ inode_number TEXT,
8
+ generation TEXT,
9
+ identity_basis TEXT NOT NULL,
10
+ first_seen_ns TEXT NOT NULL CHECK (first_seen_ns='0' OR (first_seen_ns GLOB '[1-9]*' AND first_seen_ns NOT GLOB '*[^0-9]*')),
11
+ last_seen_ns TEXT NOT NULL CHECK (last_seen_ns='0' OR (last_seen_ns GLOB '[1-9]*' AND last_seen_ns NOT GLOB '*[^0-9]*')),
12
+ UNIQUE(id, sandbox_id),
13
+ CHECK (length(last_seen_ns)>length(first_seen_ns) OR (length(last_seen_ns)=length(first_seen_ns) AND last_seen_ns COLLATE BINARY >= first_seen_ns COLLATE BINARY))
14
+ );
15
+ CREATE TABLE file_operation_targets (
16
+ id TEXT NOT NULL PRIMARY KEY,
17
+ syscall_call_id TEXT NOT NULL,
18
+ sandbox_id TEXT NOT NULL REFERENCES runtime_sandboxes(id),
19
+ file_object_id TEXT,
20
+ target_role TEXT NOT NULL CHECK (target_role IN ('target','source','destination','replaced_destination')),
21
+ supplied_path TEXT,
22
+ observed_path TEXT,
23
+ dirfd INTEGER CHECK (dirfd IS NULL OR typeof(dirfd)='integer'),
24
+ fd INTEGER CHECK (fd IS NULL OR (typeof(fd)='integer' AND fd>=0)),
25
+ base_path TEXT,
26
+ resolution_status TEXT NOT NULL CHECK (resolution_status IN ('unresolved','supplied_only','lexical','runtime_resolved')),
27
+ identity_basis_json TEXT CHECK (identity_basis_json IS NULL OR json_valid(identity_basis_json)),
28
+ FOREIGN KEY(syscall_call_id, sandbox_id) REFERENCES runtime_syscall_calls(id, sandbox_id),
29
+ FOREIGN KEY(file_object_id, sandbox_id) REFERENCES file_objects(id, sandbox_id),
30
+ CHECK (resolution_status!='supplied_only' OR supplied_path IS NOT NULL),
31
+ CHECK (resolution_status NOT IN ('lexical','runtime_resolved') OR observed_path IS NOT NULL)
32
+ );
33
+ CREATE TABLE file_labels (
34
+ id TEXT NOT NULL PRIMARY KEY,
35
+ label TEXT NOT NULL,
36
+ description TEXT NOT NULL
37
+ );
38
+ CREATE TABLE file_label_assignments (
39
+ id TEXT NOT NULL PRIMARY KEY,
40
+ target_id TEXT NOT NULL REFERENCES file_operation_targets(id),
41
+ label_id TEXT NOT NULL REFERENCES file_labels(id),
42
+ basis TEXT NOT NULL,
43
+ confidence TEXT NOT NULL CHECK (confidence IN ('exact','corroborated','inferred')),
44
+ rule_version TEXT NOT NULL,
45
+ reason TEXT NOT NULL,
46
+ assigned_at_ms INTEGER NOT NULL CHECK (typeof(assigned_at_ms)='integer')
47
+ );
48
+ CREATE INDEX file_objects_sandbox ON file_objects(sandbox_id, filesystem_identity, inode_number);
49
+ CREATE INDEX file_targets_call ON file_operation_targets(syscall_call_id);
50
+ CREATE INDEX file_targets_object ON file_operation_targets(file_object_id);
51
+ CREATE INDEX file_targets_path ON file_operation_targets(sandbox_id, observed_path);
52
+ CREATE INDEX file_assignments_target ON file_label_assignments(target_id);
53
+ CREATE INDEX file_assignments_label ON file_label_assignments(label_id, assigned_at_ms);
@@ -0,0 +1,201 @@
1
+ -- Runtime evidence: schema definitions only. Load through init-evidence-db.mjs.
2
+ CREATE TABLE runtime_sandboxes (
3
+ id TEXT NOT NULL PRIMARY KEY,
4
+ external_container_id TEXT NOT NULL,
5
+ -- The sandbox manager's rtp-<id>: the same id the agent's session carries
6
+ -- (agent_sessions.external_session_id), which is how the two domains join.
7
+ project_id TEXT,
8
+ runtime_name TEXT NOT NULL,
9
+ -- Unknown until the runtime reports them; null rather than guessed.
10
+ runtime_version TEXT,
11
+ runtime_build_digest TEXT,
12
+ architecture TEXT CHECK (architecture IS NULL OR architecture IN ('aarch64','x86_64')),
13
+ started_at_ms INTEGER CHECK (started_at_ms IS NULL OR (typeof(started_at_ms) = 'integer')),
14
+ ended_at_ms INTEGER CHECK (ended_at_ms IS NULL OR (typeof(ended_at_ms) = 'integer')),
15
+ capture_config_json TEXT CHECK (capture_config_json IS NULL OR json_valid(capture_config_json)),
16
+ CHECK (started_at_ms IS NULL OR ended_at_ms IS NULL OR ended_at_ms >= started_at_ms)
17
+ );
18
+ CREATE TABLE runtime_processes (
19
+ id TEXT NOT NULL PRIMARY KEY,
20
+ sandbox_id TEXT NOT NULL REFERENCES runtime_sandboxes(id),
21
+ pid INTEGER NOT NULL CHECK (pid IS NULL OR (typeof(pid) = 'integer' AND pid >= 1)),
22
+ start_time_ns TEXT CHECK (start_time_ns IS NULL OR (start_time_ns = '0' OR (start_time_ns GLOB '[1-9]*' AND start_time_ns NOT GLOB '*[^0-9]*'))),
23
+ parent_process_id TEXT,
24
+ observed_ppid INTEGER CHECK (observed_ppid IS NULL OR (typeof(observed_ppid) = 'integer' AND observed_ppid >= 0)),
25
+ first_seen_ns TEXT NOT NULL CHECK (first_seen_ns IS NULL OR (first_seen_ns = '0' OR (first_seen_ns GLOB '[1-9]*' AND first_seen_ns NOT GLOB '*[^0-9]*'))),
26
+ exited_at_ns TEXT CHECK (exited_at_ns IS NULL OR (exited_at_ns = '0' OR (exited_at_ns GLOB '[1-9]*' AND exited_at_ns NOT GLOB '*[^0-9]*'))),
27
+ exit_code INTEGER CHECK (exit_code IS NULL OR (typeof(exit_code) = 'integer' AND exit_code >= 0)),
28
+ exit_signal INTEGER CHECK (exit_signal IS NULL OR (typeof(exit_signal) = 'integer' AND exit_signal >= 1)),
29
+ identity_basis TEXT NOT NULL CHECK (length(trim(identity_basis)) > 0),
30
+ -- first_seen_ns/exited_at_ns are the sandbox clock; these are the same
31
+ -- instants on the proxy's clock (offset measured when observed), so they
32
+ -- compare directly with agent_exchanges times.
33
+ first_seen_ms INTEGER CHECK (first_seen_ms IS NULL OR typeof(first_seen_ms) = 'integer'),
34
+ exited_at_ms INTEGER CHECK (exited_at_ms IS NULL OR typeof(exited_at_ms) = 'integer'),
35
+ -- Set when the evidence that would report this process's exit can no
36
+ -- longer arrive (collector disconnected, sandbox removed). Cleared if a
37
+ -- real exit arrives after all. Never implies failure.
38
+ evidence_lost TEXT,
39
+ UNIQUE(id, sandbox_id),
40
+ FOREIGN KEY(parent_process_id, sandbox_id) REFERENCES runtime_processes(id, sandbox_id),
41
+ CHECK (parent_process_id IS NULL OR parent_process_id != id),
42
+ CHECK (start_time_ns IS NULL OR (length(first_seen_ns) > length(start_time_ns) OR (length(first_seen_ns) = length(start_time_ns) AND first_seen_ns COLLATE BINARY >= start_time_ns COLLATE BINARY))),
43
+ CHECK (exited_at_ns IS NULL OR (length(exited_at_ns) > length(first_seen_ns) OR (length(exited_at_ns) = length(first_seen_ns) AND exited_at_ns COLLATE BINARY >= first_seen_ns COLLATE BINARY))),
44
+ CHECK (exit_code IS NULL OR exit_signal IS NULL),
45
+ CHECK ((exit_code IS NULL AND exit_signal IS NULL) OR exited_at_ns IS NOT NULL)
46
+ );
47
+ CREATE TABLE runtime_events (
48
+ id TEXT NOT NULL PRIMARY KEY,
49
+ sandbox_id TEXT REFERENCES runtime_sandboxes(id),
50
+ process_id TEXT,
51
+ stream_id TEXT NOT NULL,
52
+ stream_sequence INTEGER NOT NULL CHECK (stream_sequence IS NULL OR (typeof(stream_sequence) = 'integer' AND stream_sequence >= 0)),
53
+ event_kind TEXT NOT NULL CHECK (length(trim(event_kind)) > 0),
54
+ observed_at_ns TEXT CHECK (observed_at_ns IS NULL OR (observed_at_ns = '0' OR (observed_at_ns GLOB '[1-9]*' AND observed_at_ns NOT GLOB '*[^0-9]*'))),
55
+ received_at_ms INTEGER NOT NULL CHECK (received_at_ms IS NULL OR (typeof(received_at_ms) = 'integer')),
56
+ tid INTEGER CHECK (tid IS NULL OR (typeof(tid) = 'integer' AND tid >= 1)),
57
+ payload_json TEXT NOT NULL CHECK (payload_json IS NULL OR json_valid(payload_json)),
58
+ retained_packet BLOB CHECK (retained_packet IS NULL OR typeof(retained_packet) = 'blob'),
59
+ decoder_version TEXT NOT NULL,
60
+ UNIQUE(stream_id, stream_sequence),
61
+ UNIQUE(id, sandbox_id),
62
+ FOREIGN KEY(process_id, sandbox_id) REFERENCES runtime_processes(id, sandbox_id),
63
+ CHECK (process_id IS NULL OR sandbox_id IS NOT NULL),
64
+ CHECK (json_type(payload_json) = 'object')
65
+ );
66
+ CREATE TABLE runtime_syscall_calls (
67
+ id TEXT NOT NULL PRIMARY KEY,
68
+ sandbox_id TEXT NOT NULL REFERENCES runtime_sandboxes(id),
69
+ process_id TEXT,
70
+ tid INTEGER CHECK (tid IS NULL OR (typeof(tid) = 'integer' AND tid >= 1)),
71
+ syscall_name TEXT,
72
+ syscall_number INTEGER NOT NULL CHECK (syscall_number IS NULL OR (typeof(syscall_number) = 'integer' AND syscall_number >= 0)),
73
+ entry_event_id TEXT,
74
+ exit_event_id TEXT,
75
+ arguments_json TEXT NOT NULL CHECK (arguments_json IS NULL OR json_valid(arguments_json)),
76
+ return_value TEXT CHECK (return_value IS NULL OR ((return_value = '0' OR (return_value GLOB '[1-9]*' AND return_value NOT GLOB '*[^0-9]*')) OR (return_value GLOB '-[1-9]*' AND substr(return_value, 2) NOT GLOB '*[^0-9]*'))),
77
+ errno INTEGER CHECK (errno IS NULL OR (typeof(errno) = 'integer' AND errno >= 0)),
78
+ outcome TEXT NOT NULL DEFAULT 'unknown' CHECK (outcome IN ('succeeded','failed','unknown')),
79
+ correlation_status TEXT NOT NULL CHECK (correlation_status IN ('paired','entry_only','exit_only','uncertain')),
80
+ normalizer_version TEXT NOT NULL,
81
+ UNIQUE(id, sandbox_id),
82
+ FOREIGN KEY(process_id, sandbox_id) REFERENCES runtime_processes(id, sandbox_id),
83
+ FOREIGN KEY(entry_event_id, sandbox_id) REFERENCES runtime_events(id, sandbox_id),
84
+ FOREIGN KEY(exit_event_id, sandbox_id) REFERENCES runtime_events(id, sandbox_id),
85
+ CHECK (entry_event_id IS NOT NULL OR exit_event_id IS NOT NULL),
86
+ CHECK (entry_event_id IS NULL OR exit_event_id IS NULL OR entry_event_id != exit_event_id),
87
+ CHECK (json_type(arguments_json) = 'object'),
88
+ CHECK ((correlation_status = 'paired' AND entry_event_id IS NOT NULL AND exit_event_id IS NOT NULL)
89
+ OR (correlation_status = 'entry_only' AND entry_event_id IS NOT NULL AND exit_event_id IS NULL)
90
+ OR (correlation_status = 'exit_only' AND entry_event_id IS NULL AND exit_event_id IS NOT NULL)
91
+ OR correlation_status = 'uncertain'),
92
+ CHECK (outcome = 'unknown' OR (exit_event_id IS NOT NULL AND return_value IS NOT NULL AND errno IS NOT NULL)),
93
+ CHECK (outcome != 'succeeded' OR errno = 0),
94
+ CHECK (outcome != 'failed' OR errno > 0),
95
+ CHECK (correlation_status NOT IN ('entry_only','uncertain') OR outcome = 'unknown'),
96
+ CHECK (exit_event_id IS NOT NULL OR (return_value IS NULL AND errno IS NULL))
97
+ );
98
+ CREATE TABLE runtime_attributions (
99
+ id TEXT NOT NULL PRIMARY KEY,
100
+ tool_call_id TEXT NOT NULL REFERENCES agent_tool_calls(id),
101
+ -- The exec event of the attributed process.
102
+ event_id TEXT NOT NULL REFERENCES runtime_events(id),
103
+ -- marker: the call id travelled with the process (RAYTRACE_CALL_ID)
104
+ -- window: command text matched inside the call's causal window
105
+ -- text: command text matched within a fixed window (no causal bounds)
106
+ -- inherited: started by a process already attributed to the call
107
+ method TEXT NOT NULL CHECK (length(trim(method)) > 0),
108
+ score REAL CHECK (score IS NULL OR (score >= 0 AND score <= 1)),
109
+ -- The causal window that justified a 'window' match, proxy-clock ms;
110
+ -- window_end_ms is null when no result had been sent yet.
111
+ window_start_ms INTEGER CHECK (window_start_ms IS NULL OR typeof(window_start_ms) = 'integer'),
112
+ window_end_ms INTEGER CHECK (window_end_ms IS NULL OR typeof(window_end_ms) = 'integer'),
113
+ -- The agent's own report of the call's result (exit code, wall time from
114
+ -- agent_tool_calls.reported_result_sha) against this process's observed
115
+ -- exit. Null until both exist and are comparable.
116
+ reported_check TEXT CHECK (reported_check IS NULL OR reported_check IN ('agrees','exit_code_differs','duration_differs')),
117
+ confidence TEXT NOT NULL CHECK (confidence IN ('exact','corroborated','inferred')),
118
+ status TEXT NOT NULL CHECK (status IN ('candidate','accepted','rejected')),
119
+ basis_json TEXT NOT NULL CHECK (basis_json IS NULL OR json_valid(basis_json)),
120
+ attributor_version TEXT NOT NULL,
121
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms IS NULL OR (typeof(created_at_ms) = 'integer'))
122
+ );
123
+ CREATE INDEX runtime_processes_identity ON runtime_processes(sandbox_id, pid, start_time_ns);
124
+ CREATE INDEX runtime_processes_parent ON runtime_processes(parent_process_id);
125
+ CREATE INDEX runtime_events_time ON runtime_events(sandbox_id, received_at_ms, id);
126
+ CREATE INDEX runtime_events_process ON runtime_events(process_id, received_at_ms, id);
127
+ CREATE INDEX runtime_syscalls_process ON runtime_syscall_calls(sandbox_id, process_id, id);
128
+ CREATE INDEX runtime_syscalls_entry ON runtime_syscall_calls(entry_event_id);
129
+ CREATE INDEX runtime_syscalls_exit ON runtime_syscall_calls(exit_event_id);
130
+ CREATE INDEX runtime_attributions_call ON runtime_attributions(tool_call_id, status);
131
+ CREATE INDEX runtime_attributions_event ON runtime_attributions(event_id, status);
132
+ CREATE INDEX runtime_sandboxes_project ON runtime_sandboxes(project_id);
133
+ CREATE TRIGGER runtime_sandbox_config_fixed BEFORE UPDATE OF capture_config_json ON runtime_sandboxes
134
+ WHEN NEW.capture_config_json IS NOT OLD.capture_config_json
135
+ BEGIN SELECT RAISE(ABORT, 'capture configuration is fixed for a sandbox lifetime'); END;
136
+ CREATE TRIGGER runtime_process_identity_fixed BEFORE UPDATE OF id, sandbox_id, pid, start_time_ns ON runtime_processes
137
+ WHEN NEW.id IS NOT OLD.id OR NEW.sandbox_id IS NOT OLD.sandbox_id OR NEW.pid IS NOT OLD.pid OR NEW.start_time_ns IS NOT OLD.start_time_ns
138
+ BEGIN SELECT RAISE(ABORT, 'process identity is immutable; retain unresolved identity when unknown'); END;
139
+ CREATE TRIGGER runtime_syscall_evidence BEFORE INSERT ON runtime_syscall_calls
140
+ BEGIN
141
+ SELECT CASE WHEN EXISTS (
142
+ SELECT 1 FROM runtime_events e WHERE e.id=NEW.exit_event_id AND (
143
+ (NEW.return_value IS NOT NULL AND json_type(e.payload_json, '$.return_value') IS NOT NULL AND
144
+ (json_type(e.payload_json, '$.return_value') != 'text' OR json_extract(e.payload_json, '$.return_value') != NEW.return_value))
145
+ OR (NEW.errno IS NOT NULL AND json_type(e.payload_json, '$.errno') IS NOT NULL AND
146
+ (json_type(e.payload_json, '$.errno') != 'integer' OR json_extract(e.payload_json, '$.errno') != NEW.errno))
147
+ )
148
+ ) THEN RAISE(ABORT, 'decoded result disagrees with exit evidence') END;
149
+ SELECT CASE WHEN EXISTS (
150
+ SELECT 1 FROM runtime_events e WHERE e.id IN (NEW.entry_event_id, NEW.exit_event_id)
151
+ AND (
152
+ (e.id = NEW.entry_event_id AND e.event_kind != 'syscall_enter')
153
+ OR (e.id = NEW.exit_event_id AND e.event_kind != 'syscall_exit')
154
+ OR (e.process_id IS NOT NULL AND NEW.process_id IS NOT NULL AND e.process_id != NEW.process_id)
155
+ OR (e.tid IS NOT NULL AND NEW.tid IS NOT NULL AND e.tid != NEW.tid)
156
+ OR (json_type(e.payload_json, '$.syscall_number') IS NOT NULL AND
157
+ (json_type(e.payload_json, '$.syscall_number') != 'integer' OR json_extract(e.payload_json, '$.syscall_number') != NEW.syscall_number))
158
+ OR (json_type(e.payload_json, '$.syscall_name') IS NOT NULL AND json_type(e.payload_json, '$.syscall_name') != 'null' AND
159
+ (json_type(e.payload_json, '$.syscall_name') != 'text' OR
160
+ (NEW.syscall_name IS NOT NULL AND json_extract(e.payload_json, '$.syscall_name') != NEW.syscall_name)))
161
+ )
162
+ ) THEN RAISE(ABORT, 'syscall phase or identity disagrees with evidence') END;
163
+ SELECT CASE WHEN EXISTS (
164
+ SELECT 1 FROM runtime_events a JOIN runtime_events b
165
+ ON a.id = NEW.entry_event_id AND b.id = NEW.exit_event_id
166
+ WHERE (a.process_id IS NOT NULL AND b.process_id IS NOT NULL AND a.process_id != b.process_id)
167
+ OR (a.tid IS NOT NULL AND b.tid IS NOT NULL AND a.tid != b.tid)
168
+ OR (json_extract(a.payload_json, '$.syscall_name') IS NOT NULL AND
169
+ json_extract(b.payload_json, '$.syscall_name') IS NOT NULL AND
170
+ json_extract(a.payload_json, '$.syscall_name') != json_extract(b.payload_json, '$.syscall_name'))
171
+ OR (a.observed_at_ns IS NOT NULL AND b.observed_at_ns IS NOT NULL AND NOT (length(b.observed_at_ns) > length(a.observed_at_ns) OR (length(b.observed_at_ns) = length(a.observed_at_ns) AND b.observed_at_ns COLLATE BINARY >= a.observed_at_ns COLLATE BINARY)))
172
+ ) THEN RAISE(ABORT, 'entry and exit observations disagree') END;
173
+ SELECT CASE WHEN NEW.outcome != 'unknown' AND NOT EXISTS (
174
+ SELECT 1 FROM runtime_events e WHERE e.id = NEW.exit_event_id
175
+ AND json_type(e.payload_json, '$.return_value') = 'text'
176
+ AND json_extract(e.payload_json, '$.return_value') = NEW.return_value
177
+ AND json_type(e.payload_json, '$.errno') = 'integer'
178
+ AND json_extract(e.payload_json, '$.errno') = NEW.errno
179
+ ) THEN RAISE(ABORT, 'known outcome requires matching decoded exit result') END;
180
+ END;
181
+ CREATE TRIGGER runtime_events_no_update BEFORE UPDATE ON runtime_events
182
+ BEGIN SELECT RAISE(ABORT, 'runtime_events is append-only'); END;
183
+ CREATE TRIGGER runtime_events_no_delete BEFORE DELETE ON runtime_events
184
+ BEGIN SELECT RAISE(ABORT, 'runtime_events is append-only'); END;
185
+ CREATE TRIGGER runtime_syscall_calls_no_update BEFORE UPDATE ON runtime_syscall_calls
186
+ BEGIN SELECT RAISE(ABORT, 'runtime_syscall_calls is append-only'); END;
187
+ CREATE TRIGGER runtime_syscall_calls_no_delete BEFORE DELETE ON runtime_syscall_calls
188
+ BEGIN SELECT RAISE(ABORT, 'runtime_syscall_calls is append-only'); END;
189
+ CREATE TRIGGER runtime_events_no_replace BEFORE INSERT ON runtime_events
190
+ WHEN EXISTS (SELECT 1 FROM runtime_events WHERE id=NEW.id OR
191
+ (stream_id=NEW.stream_id AND stream_sequence=NEW.stream_sequence))
192
+ BEGIN SELECT RAISE(ABORT, 'runtime event identity cannot be replaced'); END;
193
+ CREATE TRIGGER runtime_syscalls_no_replace BEFORE INSERT ON runtime_syscall_calls
194
+ WHEN EXISTS (SELECT 1 FROM runtime_syscall_calls WHERE id=NEW.id)
195
+ BEGIN SELECT RAISE(ABORT, 'syscall identity cannot be replaced'); END;
196
+ CREATE TRIGGER runtime_sandboxes_no_replace BEFORE INSERT ON runtime_sandboxes
197
+ WHEN EXISTS (SELECT 1 FROM runtime_sandboxes WHERE id=NEW.id)
198
+ BEGIN SELECT RAISE(ABORT, 'sandbox lifetime cannot be replaced'); END;
199
+ CREATE TRIGGER runtime_processes_no_replace BEFORE INSERT ON runtime_processes
200
+ WHEN EXISTS (SELECT 1 FROM runtime_processes WHERE id=NEW.id)
201
+ BEGIN SELECT RAISE(ABORT, 'process lifetime cannot be replaced'); END;
@@ -0,0 +1,66 @@
1
+ -- Derived search index (schema version 6): one denormalized, searchable
2
+ -- event per tool call, per turn and per proxy error, with the failure
3
+ -- outcome decided at index time (proxy/search.mjs) from the agent's own
4
+ -- report and, when present, the sandbox-observed process exit. These rows
5
+ -- are derived, never evidence: they can be dropped and rebuilt from the
6
+ -- agent-intent and runtime tables at any time (evidence-store reindex).
7
+ -- No foreign keys, so a rebuild never fights the evidence it derives from.
8
+ -- Only post-redaction payload text is indexed, capped per event.
9
+ CREATE TABLE search_events (
10
+ id TEXT NOT NULL PRIMARY KEY,
11
+ kind TEXT NOT NULL CHECK (kind IN ('call','turn','proxy_error')),
12
+ ts_ms INTEGER NOT NULL CHECK (typeof(ts_ms)='integer'),
13
+ session_id TEXT,
14
+ session_external TEXT,
15
+ turn_id TEXT,
16
+ exchange_id TEXT,
17
+ call_id TEXT,
18
+ external_call_id TEXT,
19
+ output_index INTEGER CHECK (output_index IS NULL OR typeof(output_index)='integer'),
20
+ agent TEXT,
21
+ model TEXT,
22
+ provider TEXT,
23
+ tool_name TEXT,
24
+ category TEXT,
25
+ outcome TEXT NOT NULL CHECK (outcome IN ('failed','ok','unknown')),
26
+ outcome_reported TEXT NOT NULL CHECK (outcome_reported IN ('failed','ok','unknown')),
27
+ outcome_observed TEXT NOT NULL CHECK (outcome_observed IN ('failed','ok','unknown')),
28
+ reported_check TEXT,
29
+ exit_code INTEGER CHECK (exit_code IS NULL OR typeof(exit_code)='integer'),
30
+ http_status INTEGER CHECK (http_status IS NULL OR typeof(http_status)='integer'),
31
+ error_text TEXT,
32
+ failure_signature TEXT,
33
+ signature_label TEXT,
34
+ command_text TEXT,
35
+ file_paths TEXT,
36
+ prompt_text TEXT,
37
+ args_text TEXT,
38
+ result_text TEXT,
39
+ duration_ms INTEGER CHECK (duration_ms IS NULL OR typeof(duration_ms)='integer'),
40
+ indexed_at_ms INTEGER NOT NULL CHECK (typeof(indexed_at_ms)='integer')
41
+ );
42
+ CREATE INDEX search_events_time ON search_events(ts_ms DESC);
43
+ CREATE INDEX search_events_outcome_time ON search_events(outcome, ts_ms DESC);
44
+ CREATE INDEX search_events_tool_time ON search_events(tool_name, ts_ms DESC);
45
+ CREATE INDEX search_events_signature ON search_events(failure_signature, ts_ms DESC);
46
+ CREATE INDEX search_events_turn ON search_events(turn_id, ts_ms);
47
+ CREATE INDEX search_events_exchange ON search_events(exchange_id);
48
+ CREATE INDEX search_events_call ON search_events(call_id);
49
+ CREATE VIRTUAL TABLE search_fts USING fts5(
50
+ prompt_text, command_text, error_text, args_text, result_text, file_paths, tool_name,
51
+ content='search_events', content_rowid='rowid', tokenize='porter unicode61 remove_diacritics 2'
52
+ );
53
+ CREATE TRIGGER search_events_ai AFTER INSERT ON search_events BEGIN
54
+ INSERT INTO search_fts(rowid, prompt_text, command_text, error_text, args_text, result_text, file_paths, tool_name)
55
+ VALUES (new.rowid, new.prompt_text, new.command_text, new.error_text, new.args_text, new.result_text, new.file_paths, new.tool_name);
56
+ END;
57
+ CREATE TRIGGER search_events_ad AFTER DELETE ON search_events BEGIN
58
+ INSERT INTO search_fts(search_fts, rowid, prompt_text, command_text, error_text, args_text, result_text, file_paths, tool_name)
59
+ VALUES ('delete', old.rowid, old.prompt_text, old.command_text, old.error_text, old.args_text, old.result_text, old.file_paths, old.tool_name);
60
+ END;
61
+ CREATE TRIGGER search_events_au AFTER UPDATE ON search_events BEGIN
62
+ INSERT INTO search_fts(search_fts, rowid, prompt_text, command_text, error_text, args_text, result_text, file_paths, tool_name)
63
+ VALUES ('delete', old.rowid, old.prompt_text, old.command_text, old.error_text, old.args_text, old.result_text, old.file_paths, old.tool_name);
64
+ INSERT INTO search_fts(rowid, prompt_text, command_text, error_text, args_text, result_text, file_paths, tool_name)
65
+ VALUES (new.rowid, new.prompt_text, new.command_text, new.error_text, new.args_text, new.result_text, new.file_paths, new.tool_name);
66
+ END;