working on sensors and rules

This commit is contained in:
2026-02-19 20:37:17 -06:00
parent a1b9b8d2b1
commit f9cfcf8f40
31 changed files with 1316 additions and 586 deletions

View File

@@ -442,12 +442,20 @@ class PackLoader:
sensor_ids = {}
cursor = self.conn.cursor()
# Look up sensor runtime from already-loaded runtimes
sensor_runtime_id = runtime_ids.get("builtin") or runtime_ids.get(
"core.builtin"
)
if not sensor_runtime_id:
print(" ⚠ No sensor runtime found, sensors will have no runtime")
# Runtime name mapping: runner_type values to core runtime refs
runner_type_to_ref = {
"native": "core.native",
"standalone": "core.native",
"builtin": "core.native",
"shell": "core.shell",
"bash": "core.shell",
"sh": "core.shell",
"python": "core.python",
"python3": "core.python",
"node": "core.nodejs",
"nodejs": "core.nodejs",
"node.js": "core.nodejs",
}
for yaml_file in sorted(sensors_dir.glob("*.yaml")):
sensor_data = self.load_yaml(yaml_file)
@@ -483,6 +491,20 @@ class PackLoader:
trigger_ref = f"{self.pack_ref}.{first_trigger}"
trigger_id = trigger_ids.get(trigger_ref)
# Resolve sensor runtime from YAML runner_type field
# Defaults to "native" (compiled binary, no interpreter)
runner_type = sensor_data.get("runner_type", "native").lower()
runtime_ref = runner_type_to_ref.get(runner_type, runner_type)
# Look up runtime ID: try the mapped ref, then the raw runner_type
sensor_runtime_id = runtime_ids.get(runtime_ref)
if not sensor_runtime_id:
# Try looking up by the short name (e.g., "python" key in runtime_ids)
sensor_runtime_id = runtime_ids.get(runner_type)
if not sensor_runtime_id:
print(
f" ⚠ No runtime found for runner_type '{runner_type}' (ref: {runtime_ref}), sensor will have no runtime"
)
# Determine entrypoint
entry_point = sensor_data.get("entry_point", "")
if not entry_point:
@@ -521,7 +543,7 @@ class PackLoader:
description,
entry_point,
sensor_runtime_id,
"core.builtin",
runtime_ref,
trigger_id,
trigger_ref,
enabled,

View File

@@ -48,21 +48,29 @@ BEGIN
updated = NOW()
RETURNING id INTO v_action_runtime_id;
-- Create built-in runtime for sensors (no execution_config = not executable by worker)
INSERT INTO attune.runtime (ref, pack, pack_ref, name, description, distributions)
VALUES (
'core.builtin',
v_pack_id,
'core',
'Builtin',
'Built-in sensor runtime for native Attune sensors (timers, webhooks, etc.)',
'{"verification": {"always_available": true, "check_required": false}, "type": "builtin"}'::jsonb
)
ON CONFLICT (ref) DO UPDATE SET
name = EXCLUDED.name,
description = EXCLUDED.description,
updated = NOW()
RETURNING id INTO v_sensor_runtime_id;
-- Use the native runtime for sensors that are compiled binaries
SELECT id INTO v_sensor_runtime_id
FROM attune.runtime
WHERE ref = 'core.native';
-- If core.native doesn't exist yet (shouldn't happen), create it
IF v_sensor_runtime_id IS NULL THEN
INSERT INTO attune.runtime (ref, pack, pack_ref, name, description, distributions, execution_config)
VALUES (
'core.native',
v_pack_id,
'core',
'Native',
'Native compiled runtime (Rust, Go, C, etc.) - executes binaries directly without an interpreter',
'{"verification": {"always_available": true, "check_required": false}}'::jsonb,
'{}'::jsonb
)
ON CONFLICT (ref) DO UPDATE SET
name = EXCLUDED.name,
description = EXCLUDED.description,
updated = NOW()
RETURNING id INTO v_sensor_runtime_id;
END IF;
-- Create generic timer triggers (these define trigger types, not instances)
@@ -366,9 +374,9 @@ BEGIN
'core',
'10 Second Timer Sensor',
'Timer sensor that fires every 10 seconds',
'builtin:interval_timer',
'attune-core-timer-sensor',
v_sensor_runtime_id,
'core.builtin',
'core.native',
v_intervaltimer_id,
'core.intervaltimer',
true,