Initial repository snapshot
This commit is contained in:
commit
b7951de3b3
|
|
@ -0,0 +1,12 @@
|
|||
.venv/
|
||||
.codex/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
.pytest_cache/
|
||||
.ruff_cache/
|
||||
.mypy_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
PYTHON ?= python3
|
||||
|
||||
.PHONY: generate-proto test lint format
|
||||
|
||||
generate-proto:
|
||||
$(PYTHON) tools/gen_proto.py
|
||||
|
||||
test:
|
||||
$(PYTHON) -m pytest
|
||||
|
||||
lint:
|
||||
ruff check src tests
|
||||
black --check src tests
|
||||
|
||||
format:
|
||||
black src tests
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
WF-Agent Gen4 artifact bundle
|
||||
|
||||
Includes:
|
||||
- versioned .proto source contracts
|
||||
- YAML configuration layout
|
||||
- code generation scripts
|
||||
- runtime/dev dependency manifests
|
||||
- systemd service example
|
||||
- sysusers.d and tmpfiles.d examples
|
||||
- bootstrap skeleton for app.main
|
||||
- loader skeleton for multi-YAML config
|
||||
- minimal smoke tests
|
||||
|
||||
Typical workflow:
|
||||
1. Install deps
|
||||
2. Generate protobuf bindings
|
||||
3. Load /etc/wf-agent/app.yaml as root config
|
||||
4. Run tests
|
||||
5. Extend bootstrap into full runtime
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
WF_AGENT_CONFIG_DIR=/etc/wf-agent
|
||||
WF_AGENT_LOG_LEVEL=INFO
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
[Unit]
|
||||
Description=WF-Agent Gen4
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=wifi-agent
|
||||
Group=wifi-agent
|
||||
WorkingDirectory=/var/lib/wf-agent
|
||||
EnvironmentFile=-/etc/wf-agent/wf-agent.env
|
||||
ExecStart=/usr/bin/python3 -m app.main
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
RuntimeDirectory=wf-agent
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
u wifi-agent - "WF-Agent service user"
|
||||
g wifi-agent - -
|
||||
m wifi-agent wifi-agent
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
d /run/wf-agent 0755 wifi-agent wifi-agent -
|
||||
d /var/lib/wf-agent 0755 wifi-agent wifi-agent -
|
||||
d /var/log/wf-agent 0755 wifi-agent wifi-agent -
|
||||
d /var/lib/wf-agent/in 0755 wifi-agent wifi-agent -
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
WF-Agent configuration layout
|
||||
|
||||
Entry point:
|
||||
- /etc/wf-agent/app.yaml
|
||||
|
||||
Related files:
|
||||
- /etc/wf-agent/events.yaml
|
||||
- /etc/wf-agent/commands.yaml
|
||||
- /etc/wf-agent/cron.yaml
|
||||
- /etc/wf-agent/observability.yaml
|
||||
- /etc/wf-agent/listeners/*.yaml
|
||||
- /etc/wf-agent/executors/*.yaml
|
||||
|
||||
Bootstrap rule:
|
||||
- app.yaml is the root config
|
||||
- app.yaml lists included YAML files under `includes`
|
||||
- the loader resolves includes in order and builds a single runtime config model
|
||||
|
||||
Validation expectations:
|
||||
- missing required include targets -> startup error
|
||||
- duplicate logical object names -> startup error
|
||||
- unknown critical fields -> validation warning or error per loader policy
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
app:
|
||||
name: wf-agent-gen4
|
||||
instance_id: host-default
|
||||
environment: production
|
||||
|
||||
runtime:
|
||||
shutdown_timeout_sec: 20
|
||||
journald_logging: true
|
||||
|
||||
paths:
|
||||
state_dir: /var/lib/wf-agent
|
||||
run_dir: /run/wf-agent
|
||||
|
||||
includes:
|
||||
- events.yaml
|
||||
- commands.yaml
|
||||
- cron.yaml
|
||||
- observability.yaml
|
||||
- listeners/file.yaml
|
||||
- listeners/dbus.yaml
|
||||
- executors/dbus.yaml
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
commands:
|
||||
enabled: true
|
||||
|
||||
dispatcher:
|
||||
default_timeout_ms: 10000
|
||||
default_priority: NORMAL
|
||||
|
||||
spool:
|
||||
enabled: true
|
||||
max_items: 10000
|
||||
default_queueing_policy: ENQUEUE_ALWAYS
|
||||
default_retry_policy: NO_RETRY
|
||||
scheduler_tick_ms: 200
|
||||
|
||||
bridge:
|
||||
enabled: true
|
||||
transport: websocket
|
||||
bind_host: 127.0.0.1
|
||||
bind_port: 18101
|
||||
websocket_path: /commands
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
cron:
|
||||
enabled: true
|
||||
jobs:
|
||||
- cron_id: periodic-status
|
||||
enabled: true
|
||||
schedule_expr: "*/5 * * * *"
|
||||
misfire_policy: SKIP_MISSED
|
||||
default_priority: LOW
|
||||
default_timeout_ms: 5000
|
||||
template:
|
||||
header:
|
||||
command_kind: status
|
||||
target_type: dbus
|
||||
target_id: fi.w1.wpa_supplicant1
|
||||
issuer_type: cron
|
||||
issuer_id: periodic-status
|
||||
expects_response: true
|
||||
payload:
|
||||
args: []
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
events:
|
||||
enabled: true
|
||||
|
||||
dispatcher:
|
||||
fanout:
|
||||
cache: true
|
||||
spool: true
|
||||
|
||||
cache:
|
||||
enabled: true
|
||||
ttl_sec: 300
|
||||
quantity_limit: 10000
|
||||
|
||||
spool:
|
||||
enabled: true
|
||||
max_items: 20000
|
||||
default_priority: NORMAL
|
||||
default_delivery_mode: BEST_EFFORT
|
||||
default_retry_policy: RETRY_BACKOFF
|
||||
default_retry_backoff_ms: 1000
|
||||
|
||||
bridge:
|
||||
enabled: true
|
||||
transport: websocket
|
||||
bind_host: 127.0.0.1
|
||||
bind_port: 18100
|
||||
websocket_path: /events
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
executor:
|
||||
name: dbus-default
|
||||
type: dbus
|
||||
enabled: true
|
||||
priority: 100
|
||||
|
||||
bus:
|
||||
kind: system
|
||||
|
||||
selection:
|
||||
target_types:
|
||||
- dbus
|
||||
command_kinds:
|
||||
- status
|
||||
- scan
|
||||
- disconnect
|
||||
- reassociate
|
||||
- get_property
|
||||
- set_property
|
||||
|
||||
timeouts:
|
||||
default_timeout_ms: 10000
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
listener:
|
||||
name: dbus-events
|
||||
type: dbus
|
||||
enabled: true
|
||||
|
||||
bus:
|
||||
kind: system
|
||||
|
||||
subscriptions:
|
||||
- bus_name: fi.w1.wpa_supplicant1
|
||||
object_path: /fi/w1/wpa_supplicant1
|
||||
interface_name: fi.w1.wpa_supplicant1
|
||||
signal_name: InterfaceAdded
|
||||
|
||||
- bus_name: fi.w1.wpa_supplicant1
|
||||
object_path: /fi/w1/wpa_supplicant1/Interfaces/0
|
||||
interface_name: org.freedesktop.DBus.Properties
|
||||
signal_name: PropertiesChanged
|
||||
|
||||
routing:
|
||||
source_type: dbus
|
||||
source_id: system-bus
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
listener:
|
||||
name: file-events
|
||||
type: file
|
||||
enabled: true
|
||||
|
||||
connection:
|
||||
path: /var/lib/wf-agent/in/events.jsonl
|
||||
encoding: utf-8
|
||||
|
||||
acquisition:
|
||||
mode: file_tail
|
||||
poll_interval_ms: 500
|
||||
start_from_end: true
|
||||
|
||||
format:
|
||||
type: json
|
||||
framing: ndjson
|
||||
require_envelope: true
|
||||
require_payload: true
|
||||
require_meta: true
|
||||
|
||||
routing:
|
||||
source_type: file
|
||||
source_id: file-events
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
observability:
|
||||
enabled: true
|
||||
metrics:
|
||||
enabled: true
|
||||
traces:
|
||||
enabled: true
|
||||
status_snapshots:
|
||||
enabled: true
|
||||
interval_sec: 30
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,34 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=68", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "wf-agent-gen4"
|
||||
version = "0.1.0"
|
||||
description = "WF-Agent Gen4 architecture baseline artifacts"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
"protobuf>=5.0.0",
|
||||
"dbus-next>=0.2.3",
|
||||
"PyYAML>=6.0.1",
|
||||
"websockets>=12.0",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest>=8.0.0",
|
||||
"ruff>=0.6.0",
|
||||
"black>=24.0.0",
|
||||
"mypy>=1.10.0",
|
||||
"grpcio-tools>=1.60.0",
|
||||
]
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 88
|
||||
target-version = "py311"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
-r requirements.txt
|
||||
pytest>=8.0.0
|
||||
ruff>=0.6.0
|
||||
black>=24.0.0
|
||||
mypy>=1.10.0
|
||||
grpcio-tools>=1.60.0
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
protobuf>=5.0.0
|
||||
dbus-next>=0.2.3
|
||||
PyYAML>=6.0.1
|
||||
websockets>=12.0
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
from app.main.app import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from app.runtime.config.loader import load_runtime_config
|
||||
|
||||
LOG = logging.getLogger("wf-agent")
|
||||
|
||||
|
||||
def configure_logging() -> None:
|
||||
level = os.environ.get("WF_AGENT_LOG_LEVEL", "INFO").upper()
|
||||
logging.basicConfig(
|
||||
level=level,
|
||||
format="%(asctime)s %(levelname)s %(name)s %(message)s",
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
configure_logging()
|
||||
|
||||
config_dir = Path(os.environ.get("WF_AGENT_CONFIG_DIR", "/etc/wf-agent"))
|
||||
config = load_runtime_config(config_dir)
|
||||
|
||||
LOG.info("wf-agent bootstrap started")
|
||||
LOG.info("loaded app config: name=%s instance_id=%s", config.app.name, config.app.instance_id)
|
||||
|
||||
# TODO:
|
||||
# - create event runtime
|
||||
# - create command runtime
|
||||
# - start bridge services
|
||||
# - wait for shutdown signal
|
||||
LOG.info("bootstrap skeleton finished")
|
||||
return 0
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
from app.runtime.config.models import AppConfig, PathsConfig, RootConfig, RuntimeConfig
|
||||
|
||||
|
||||
def _read_yaml(path: Path) -> dict[str, Any]:
|
||||
with path.open("r", encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f) or {}
|
||||
if not isinstance(data, dict):
|
||||
raise ValueError(f"YAML root must be a mapping: {path}")
|
||||
return data
|
||||
|
||||
|
||||
def _merge_sections(root: dict[str, Any], incoming: dict[str, Any], source_name: str) -> None:
|
||||
for key, value in incoming.items():
|
||||
if key in root and key not in {"includes"}:
|
||||
# Keep this strict for now; later it can be made schema-aware.
|
||||
raise ValueError(f"duplicate top-level section '{key}' while loading {source_name}")
|
||||
root[key] = value
|
||||
|
||||
|
||||
def load_runtime_config(config_dir: Path) -> RootConfig:
|
||||
app_yaml = config_dir / "app.yaml"
|
||||
if not app_yaml.exists():
|
||||
raise FileNotFoundError(f"missing root config: {app_yaml}")
|
||||
|
||||
root_data = _read_yaml(app_yaml)
|
||||
includes = root_data.get("includes", []) or []
|
||||
if not isinstance(includes, list):
|
||||
raise ValueError("app.yaml: 'includes' must be a list")
|
||||
|
||||
merged: dict[str, Any] = dict(root_data)
|
||||
merged.pop("includes", None)
|
||||
|
||||
for rel in includes:
|
||||
include_path = config_dir / rel
|
||||
if not include_path.exists():
|
||||
raise FileNotFoundError(f"missing included config: {include_path}")
|
||||
include_data = _read_yaml(include_path)
|
||||
_merge_sections(merged, include_data, rel)
|
||||
|
||||
app = merged.get("app") or {}
|
||||
runtime = merged.get("runtime") or {}
|
||||
paths = merged.get("paths") or {}
|
||||
|
||||
if "name" not in app or "instance_id" not in app:
|
||||
raise ValueError("app section must contain 'name' and 'instance_id'")
|
||||
|
||||
return RootConfig(
|
||||
app=AppConfig(
|
||||
name=app["name"],
|
||||
instance_id=app["instance_id"],
|
||||
environment=app.get("environment", "production"),
|
||||
),
|
||||
runtime=RuntimeConfig(
|
||||
shutdown_timeout_sec=int(runtime.get("shutdown_timeout_sec", 20)),
|
||||
journald_logging=bool(runtime.get("journald_logging", True)),
|
||||
),
|
||||
paths=PathsConfig(
|
||||
state_dir=paths.get("state_dir", "/var/lib/wf-agent"),
|
||||
run_dir=paths.get("run_dir", "/run/wf-agent"),
|
||||
),
|
||||
includes=includes,
|
||||
raw_sections=merged,
|
||||
)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppConfig:
|
||||
name: str
|
||||
instance_id: str
|
||||
environment: str = "production"
|
||||
|
||||
|
||||
@dataclass
|
||||
class RuntimeConfig:
|
||||
shutdown_timeout_sec: int = 20
|
||||
journald_logging: bool = True
|
||||
|
||||
|
||||
@dataclass
|
||||
class PathsConfig:
|
||||
state_dir: str = "/var/lib/wf-agent"
|
||||
run_dir: str = "/run/wf-agent"
|
||||
|
||||
|
||||
@dataclass
|
||||
class RootConfig:
|
||||
app: AppConfig
|
||||
runtime: RuntimeConfig = field(default_factory=RuntimeConfig)
|
||||
paths: PathsConfig = field(default_factory=PathsConfig)
|
||||
includes: list[str] = field(default_factory=list)
|
||||
raw_sections: dict[str, Any] = field(default_factory=dict)
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package wfagent.proto.v1;
|
||||
|
||||
import "common.proto";
|
||||
|
||||
message CommandArgument {
|
||||
string name = 1;
|
||||
oneof value {
|
||||
string string_value = 2;
|
||||
int64 int_value = 3;
|
||||
double double_value = 4;
|
||||
bool bool_value = 5;
|
||||
bytes bytes_value = 6;
|
||||
}
|
||||
}
|
||||
|
||||
message CommandRequestPayload {
|
||||
repeated CommandArgument args = 1;
|
||||
}
|
||||
|
||||
message CommandRequestEnvelope {
|
||||
Meta meta = 1;
|
||||
CommandRequestHeader header = 2;
|
||||
CommandRequestPayload payload = 3;
|
||||
}
|
||||
|
||||
message CommandRequestHeader {
|
||||
string command_kind = 1;
|
||||
string target_type = 2;
|
||||
string target_id = 3;
|
||||
string issuer_type = 4; // webui, cli, cron, internal
|
||||
string issuer_id = 5;
|
||||
int32 priority = 6;
|
||||
int64 not_before_unix_ms = 7;
|
||||
int64 expires_at_unix_ms = 8;
|
||||
bool expects_response = 9;
|
||||
}
|
||||
|
||||
message CommandResultEnvelope {
|
||||
Meta meta = 1;
|
||||
CommandResultHeader header = 2;
|
||||
CommandResultPayload payload = 3;
|
||||
}
|
||||
|
||||
message CommandResultHeader {
|
||||
string command_kind = 1;
|
||||
string executor_type = 2;
|
||||
string executor_id = 3;
|
||||
string target_type = 4;
|
||||
string target_id = 5;
|
||||
string status = 6; // queued, dispatched, running, succeeded, failed, timed_out, rejected
|
||||
int64 started_at_unix_ms = 7;
|
||||
int64 finished_at_unix_ms = 8;
|
||||
int32 exit_code = 9;
|
||||
}
|
||||
|
||||
message CommandResultPayload {
|
||||
oneof body {
|
||||
string text = 1;
|
||||
bytes raw_bytes = 2;
|
||||
KeyValueList kv = 3;
|
||||
StructuredFields structured = 4;
|
||||
ErrorInfo error = 5;
|
||||
}
|
||||
}
|
||||
|
||||
message CommandExecutionPolicy {
|
||||
int32 priority = 1;
|
||||
int64 not_before_unix_ms = 2;
|
||||
int64 expires_at_unix_ms = 3;
|
||||
int32 max_attempts = 4;
|
||||
string retry_policy = 5; // NO_RETRY, RETRY_IMMEDIATE, RETRY_BACKOFF, RETRY_UNTIL_EXPIRES
|
||||
int64 retry_backoff_ms = 6;
|
||||
int64 timeout_ms = 7;
|
||||
string deduplication_key = 8;
|
||||
string target_lock_key = 9;
|
||||
string concurrency_group = 10;
|
||||
string failure_policy = 11; // MARK_FAILED, REQUEUE, RETRY_THEN_FAIL, DROP_IF_EXPIRED
|
||||
string queueing_policy = 12; // ENQUEUE_ALWAYS, REPLACE_OLDER_BY_KEY, REJECT_IF_DUPLICATE, KEEP_LATEST_ONLY
|
||||
}
|
||||
|
||||
message CommandSpoolItemState {
|
||||
string spool_state = 1; // QUEUED, BLOCKED, SCHEDULED, READY, DISPATCHING, RUNNING, WAIT_RETRY, SUCCEEDED, FAILED, EXPIRED, CANCELLED, REPLACED
|
||||
int32 attempt_count = 2;
|
||||
int64 queued_at_unix_ms = 3;
|
||||
int64 last_started_at_unix_ms = 4;
|
||||
int64 last_finished_at_unix_ms = 5;
|
||||
int64 next_attempt_at_unix_ms = 6;
|
||||
string assigned_executor_type = 7;
|
||||
repeated string executor_candidate_types = 8;
|
||||
string last_failure_code = 9;
|
||||
string last_failure_message = 10;
|
||||
}
|
||||
|
||||
message CommandSpoolItem {
|
||||
Meta meta = 1;
|
||||
CommandRequestEnvelope request = 2;
|
||||
CommandExecutionPolicy policy = 3;
|
||||
CommandSpoolItemState state = 4;
|
||||
}
|
||||
|
||||
message CronCommandSpec {
|
||||
string cron_id = 1;
|
||||
string schedule_expr = 2;
|
||||
CommandRequestEnvelope template = 3;
|
||||
bool enabled = 4;
|
||||
string misfire_policy = 5; // SKIP_MISSED, RUN_ONCE_AFTER_RECOVERY, CATCH_UP_ALL, DISABLE_JOB_ON_MISFIRE
|
||||
int32 default_priority = 6;
|
||||
int64 default_timeout_ms = 7;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package wfagent.proto.v1;
|
||||
|
||||
message Meta {
|
||||
string message_id = 1;
|
||||
string correlation_id = 2;
|
||||
string causation_id = 3;
|
||||
int64 created_at_unix_ms = 4;
|
||||
string producer_module = 5;
|
||||
string producer_instance = 6;
|
||||
map<string, string> labels = 7;
|
||||
}
|
||||
|
||||
message KeyValue {
|
||||
string key = 1;
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message KeyValueList {
|
||||
repeated KeyValue items = 1;
|
||||
}
|
||||
|
||||
message StructuredField {
|
||||
string key = 1;
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message StructuredFields {
|
||||
repeated StructuredField items = 1;
|
||||
}
|
||||
|
||||
message ErrorInfo {
|
||||
string code = 1;
|
||||
string message = 2;
|
||||
string details = 3;
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package wfagent.proto.v1;
|
||||
|
||||
import "common.proto";
|
||||
|
||||
message EventEnvelope {
|
||||
Meta meta = 1;
|
||||
EventHeader header = 2;
|
||||
EventPayload payload = 3;
|
||||
EventDelivery delivery = 4;
|
||||
}
|
||||
|
||||
message EventHeader {
|
||||
string event_type = 1;
|
||||
string source_type = 2;
|
||||
string source_id = 3;
|
||||
string entity_id = 4;
|
||||
string severity = 5;
|
||||
int64 observed_at_unix_ms = 6;
|
||||
}
|
||||
|
||||
message EventPayload {
|
||||
oneof body {
|
||||
bytes raw_bytes = 1;
|
||||
string text = 2;
|
||||
string json_text = 3;
|
||||
KeyValueList kv = 4;
|
||||
StructuredFields structured = 5;
|
||||
}
|
||||
}
|
||||
|
||||
message EventDelivery {
|
||||
string priority = 1; // CRITICAL, HIGH, NORMAL, LOW, BULK
|
||||
string delivery_mode = 2; // IMMEDIATE, BATCHED, LATEST_ONLY, BEST_EFFORT, DROP_IF_BUSY
|
||||
string audience_scope = 3; // ALL_SUBSCRIBERS, WEBUI_ONLY, CLI_ONLY, MATCHED_SUBSCRIBERS
|
||||
int64 expires_at_unix_ms = 4;
|
||||
string retry_policy = 5; // NO_RETRY, RETRY_IMMEDIATE, RETRY_BACKOFF, RETRY_UNTIL_TTL
|
||||
int32 max_attempts = 6;
|
||||
int64 retry_backoff_ms = 7;
|
||||
string failure_policy = 8; // DROP, REQUEUE, MARK_FAILED, DOWNGRADE_AND_REQUEUE
|
||||
string drop_policy = 9; // DROP_OLDEST, DROP_NEWEST, DROP_LOW_PRIORITY_FIRST, KEEP_LATEST_PER_KEY
|
||||
string coalescing_key = 10;
|
||||
string sequence_class = 11; // STRICT_ORDERED, ORDER_PREFERRED, UNORDERED
|
||||
}
|
||||
|
||||
message EventSpoolItemState {
|
||||
string spool_state = 1; // READY, DISPATCHING, WAIT_RETRY, DELIVERED, DROPPED, FAILED, EXPIRED, COALESCED
|
||||
int32 attempt_count = 2;
|
||||
int64 queued_at_unix_ms = 3;
|
||||
int64 last_attempt_at_unix_ms = 4;
|
||||
int64 next_attempt_at_unix_ms = 5;
|
||||
string last_failure_code = 6;
|
||||
string last_failure_message = 7;
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package wfagent.northbound.v1;
|
||||
|
||||
import "common.proto";
|
||||
import "commands.proto";
|
||||
|
||||
message ClientEnvelope {
|
||||
string protocol_version = 1;
|
||||
string message_kind = 2; // COMMAND_REQUEST, COMMAND_CANCEL, SUBSCRIBE, UNSUBSCRIBE, PING, ...
|
||||
string session_id = 3;
|
||||
string request_id = 4;
|
||||
string correlation_id = 5;
|
||||
int64 sent_at_unix_ms = 6;
|
||||
|
||||
oneof body {
|
||||
ClientHello client_hello = 10;
|
||||
CommandRequestMessage command_request = 11;
|
||||
CommandCancelMessage command_cancel = 12;
|
||||
SubscribeRequest subscribe = 13;
|
||||
UnsubscribeRequest unsubscribe = 14;
|
||||
Ping ping = 15;
|
||||
}
|
||||
}
|
||||
|
||||
message ServerEnvelope {
|
||||
string protocol_version = 1;
|
||||
string message_kind = 2; // COMMAND_RESPONSE, ERROR, EVENT, PONG, ...
|
||||
string session_id = 3;
|
||||
string request_id = 4;
|
||||
string correlation_id = 5;
|
||||
int64 sent_at_unix_ms = 6;
|
||||
|
||||
oneof body {
|
||||
ServerHello server_hello = 10;
|
||||
CommandResponseMessage command_response = 11;
|
||||
EventMessage event = 12;
|
||||
ErrorResponse error = 13;
|
||||
Pong pong = 14;
|
||||
SessionStateUpdate session_state = 15;
|
||||
}
|
||||
}
|
||||
|
||||
message ClientHello {
|
||||
string client_type = 1; // webui, cli
|
||||
string client_version = 2;
|
||||
}
|
||||
|
||||
message ServerHello {
|
||||
string server_name = 1;
|
||||
string protocol_version = 2;
|
||||
string server_version = 3;
|
||||
}
|
||||
|
||||
message CommandRequestMessage {
|
||||
CommandTarget target = 1;
|
||||
CommandDescriptor command = 2;
|
||||
repeated wfagent.proto.v1.CommandArgument arguments = 3;
|
||||
CommandClientOptions options = 4;
|
||||
}
|
||||
|
||||
message CommandTarget {
|
||||
string target_type = 1; // dbus, shell, ctrl_iface, file, internal, ...
|
||||
string target_id = 2;
|
||||
string target_scope = 3;
|
||||
}
|
||||
|
||||
message CommandDescriptor {
|
||||
string command_kind = 1; // scan, disconnect, reassociate, status, ...
|
||||
string command_name = 2;
|
||||
}
|
||||
|
||||
message CommandClientOptions {
|
||||
bool expects_response = 1;
|
||||
int64 timeout_ms = 2;
|
||||
int32 priority_hint = 3;
|
||||
bool allow_queueing = 4;
|
||||
bool allow_retry = 5;
|
||||
}
|
||||
|
||||
message CommandCancelMessage {
|
||||
string target_request_id = 1;
|
||||
string reason = 2;
|
||||
}
|
||||
|
||||
message CommandResponseMessage {
|
||||
string status = 1; // ACCEPTED, QUEUED, RUNNING, SUCCEEDED, FAILED, TIMED_OUT, REJECTED, CANCELLED
|
||||
string command_kind = 2;
|
||||
string target_type = 3;
|
||||
string target_id = 4;
|
||||
int64 started_at_unix_ms = 5;
|
||||
int64 finished_at_unix_ms = 6;
|
||||
|
||||
oneof result {
|
||||
string text = 10;
|
||||
wfagent.proto.v1.KeyValueList kv = 11;
|
||||
wfagent.proto.v1.StructuredFields structured = 12;
|
||||
wfagent.proto.v1.ErrorInfo error = 13;
|
||||
}
|
||||
}
|
||||
|
||||
message EventMessage {
|
||||
string event_type = 1;
|
||||
string source_type = 2;
|
||||
string source_id = 3;
|
||||
string severity = 4;
|
||||
int64 observed_at_unix_ms = 5;
|
||||
oneof payload {
|
||||
string text = 10;
|
||||
wfagent.proto.v1.KeyValueList kv = 11;
|
||||
wfagent.proto.v1.StructuredFields structured = 12;
|
||||
}
|
||||
}
|
||||
|
||||
message SubscribeRequest {
|
||||
string subscription_id = 1;
|
||||
string event_type = 2;
|
||||
string source_type = 3;
|
||||
string source_id = 4;
|
||||
string topic = 5;
|
||||
string severity = 6;
|
||||
}
|
||||
|
||||
message UnsubscribeRequest {
|
||||
string subscription_id = 1;
|
||||
}
|
||||
|
||||
message ErrorResponse {
|
||||
string error_code = 1;
|
||||
string error_message = 2;
|
||||
string details = 3;
|
||||
}
|
||||
|
||||
message SessionStateUpdate {
|
||||
string session_state = 1;
|
||||
string reason = 2;
|
||||
}
|
||||
|
||||
message Ping {}
|
||||
message Pong {}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
from pathlib import Path
|
||||
|
||||
from app.runtime.config.loader import load_runtime_config
|
||||
|
||||
|
||||
def test_load_runtime_config():
|
||||
base = Path(__file__).resolve().parents[1] / "etc" / "wf-agent"
|
||||
cfg = load_runtime_config(base)
|
||||
assert cfg.app.name == "wf-agent-gen4"
|
||||
assert cfg.app.instance_id == "host-default"
|
||||
assert "events" in cfg.raw_sections
|
||||
assert "commands" in cfg.raw_sections
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from pathlib import Path
|
||||
|
||||
def test_proto_files_exist():
|
||||
base = Path(__file__).resolve().parents[1] / "src" / "app" / "shared" / "contracts" / "proto" / "v1"
|
||||
assert (base / "common.proto").exists()
|
||||
assert (base / "events.proto").exists()
|
||||
assert (base / "commands.proto").exists()
|
||||
assert (base / "northbound.proto").exists()
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
from pathlib import Path
|
||||
|
||||
def test_yaml_layout_exists():
|
||||
base = Path(__file__).resolve().parents[1] / "etc" / "wf-agent"
|
||||
assert (base / "app.yaml").exists()
|
||||
assert (base / "events.yaml").exists()
|
||||
assert (base / "commands.yaml").exists()
|
||||
assert (base / "cron.yaml").exists()
|
||||
assert (base / "observability.yaml").exists()
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
Code generation scripts
|
||||
|
||||
Files:
|
||||
- tools/gen_proto.sh
|
||||
- tools/gen_proto.py
|
||||
- tools/requirements-codegen.txt
|
||||
|
||||
Usage:
|
||||
1. Install tooling:
|
||||
python -m pip install -r tools/requirements-codegen.txt
|
||||
|
||||
2. Generate Python bindings:
|
||||
bash tools/gen_proto.sh
|
||||
or
|
||||
python tools/gen_proto.py
|
||||
|
||||
Output:
|
||||
- generated/python/
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def main() -> int:
|
||||
root_dir = Path(__file__).resolve().parents[1]
|
||||
proto_dir = root_dir / "src" / "app" / "shared" / "contracts" / "proto" / "v1"
|
||||
out_dir = root_dir / "generated" / "python"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
"grpc_tools.protoc",
|
||||
f"-I{proto_dir}",
|
||||
f"--python_out={out_dir}",
|
||||
str(proto_dir / "common.proto"),
|
||||
str(proto_dir / "events.proto"),
|
||||
str(proto_dir / "commands.proto"),
|
||||
str(proto_dir / "northbound.proto"),
|
||||
]
|
||||
|
||||
subprocess.run(cmd, check=True)
|
||||
print(f"Generated Python protobuf files into: {out_dir}")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
PROTO_DIR="$ROOT_DIR/src/app/shared/contracts/proto/v1"
|
||||
OUT_DIR="$ROOT_DIR/generated/python"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
python -m grpc_tools.protoc -I"$PROTO_DIR" --python_out="$OUT_DIR" "$PROTO_DIR/common.proto" "$PROTO_DIR/events.proto" "$PROTO_DIR/commands.proto" "$PROTO_DIR/northbound.proto"
|
||||
|
||||
echo "Generated Python protobuf files into: $OUT_DIR"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
protobuf>=5.0.0
|
||||
grpcio-tools>=1.60.0
|
||||
Loading…
Reference in New Issue