Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9259506
checkpoint
nasrlol Jan 7, 2026
f4e0d6f
feature: the total list of returned unit lists now return a complete…
nasrlol Jan 7, 2026
f4f7dc3
feature: killing process and retrieving processes states protobuf
nasrlol Jan 8, 2026
8dfd98f
refactor: added the new services and resources version
nasrlol Jan 8, 2026
fe524d1
feature: new grpcurl tests
nasrlol Jan 8, 2026
e42d0b3
feature: v3 services
nasrlol Jan 8, 2026
16a3aba
feature: resources services v2 and file restructure
nasrlol Jan 8, 2026
431c113
feature: adjusted the dbus manager for filtered services and better l…
nasrlol Jan 8, 2026
826b993
feature: v2 resources grpc handler
nasrlol Jan 8, 2026
f3f4a12
feature: v3 grpc handler
nasrlol Jan 8, 2026
f1b5c6b
refacor: folder restructure
nasrlol Jan 8, 2026
d9de1dc
debug: checkpoint fixing the process status
nasrlol Jan 8, 2026
94e33df
feature: updated entry poitns for v2 and v3
nasrlol Jan 8, 2026
99ea9ad
checkpoint
nasrlol Jan 8, 2026
fa7c697
feature: updated process kill from string to boolean
nasrlol Jan 9, 2026
d1d454c
bugfix: fixed process state
nasrlol Jan 9, 2026
69bd5d8
test: studyreflect
nasrlol Jan 9, 2026
b3f946f
feature: wrapper cleanup + process signal handling
nasrlol Jan 9, 2026
2e179f4
feature: refactored services grpc handler to better handle filtered a…
nasrlol Jan 9, 2026
d038403
debug: moved from ssh to https for the git submodule
nasrlol Jan 9, 2026
2a48c72
feature: v3 test services
nasrlol Jan 9, 2026
109573f
feature: v3 services grpc and protobufs, still one issue but thats fo…
nasrlol Jan 9, 2026
65f137f
debug: array for file states
nasrlol Jan 9, 2026
f0c6eab
feature: refactor mapLoadedUnits to return error, update GetAllUnits …
nasrlol Jan 10, 2026
c351a41
refactor: update ParseUnits to accept slice input and return filtered…
nasrlol Jan 10, 2026
d5cd34c
refactor: update MapUnits to return error, remove channels, improve e…
nasrlol Jan 10, 2026
c6c89ca
refactor: update GetUnits to return slice and error instead of using …
nasrlol Jan 10, 2026
3a7efee
chore: update agent-resources submodule URL to use SSH
nasrlol Jan 10, 2026
c365046
chore: set diagnostics flag default to false
nasrlol Jan 10, 2026
06364f5
checkpoint?
nasrlol Jan 10, 2026
d239cd3
refactor: update ParseUnits and ParseLoadedUnits to return slices and…
nasrlol Jan 10, 2026
40443b9
refactor: streamline unit retrieval and status functions, replacing c…
nasrlol Jan 10, 2026
6b16881
refactor: update unit retrieval functions to return slices and errors…
nasrlol Jan 10, 2026
bee5856
refactor: implement runtime diagnostics using bubbletea for improved …
nasrlol Jan 10, 2026
120e7d0
refactor: update go.mod and go.sum to include additional indirect dep…
nasrlol Jan 10, 2026
86ea77b
refactor: update UnitAction to use RunRetrievalDeprecated for improve…
nasrlol Jan 10, 2026
5889aab
refactor: update service methods to use deprecated retrieval and impr…
nasrlol Jan 10, 2026
ae8dc06
debug: connection closed errror
nasrlol Jan 10, 2026
e7913de
checkpoint: played around with build scripts
nasrlol Jan 10, 2026
439a700
feature: implemented total time and idle time in protobbufs and cgo w…
nasrlol Jan 10, 2026
a8d8ebc
feature: updated scripts for correct versiona and correct namings
nasrlol Jan 10, 2026
9095621
bugfix: fixed memory issue
nasrlol Jan 10, 2026
83541a1
feature: added idle time and total time to cpu resources
nasrlol Jan 10, 2026
0573262
refactore: improved documentation and todos in certain features
nasrlol Jan 10, 2026
96ef9bc
refactor: test names
nasrlol Jan 10, 2026
0270ac9
checkpoint: refactor
nasrlol Jan 10, 2026
88c8d73
debug: removed deprecated test
nasrlol Jan 10, 2026
1751bb5
debug: removed deprecated test
nasrlol Jan 10, 2026
96ed346
debug: removed deprecated tests
nasrlol Jan 10, 2026
8206566
bugfix: grpc process action call was wrongly named
nasrlol Jan 12, 2026
0fad65c
checkpoint: agent-resources update
nasrlol Jan 12, 2026
5dc1453
checkpoint: package manager
nasrlol Jan 12, 2026
0cc8098
feature: disk resources
nasrlol Jan 12, 2026
aa16843
feature: converted ram strings to int
nasrlol Jan 12, 2026
ccdcdb4
feature: fixed compile script to handle parsing function
nasrlol Jan 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ OUT_DIR="$AGENT_RES_DIR/build"

SRC_RES="$AGENT_RES_DIR/resources.c"
SRC_ARENA="$AGENT_RES_DIR/arena.c"
SRC_BASE="$AGENT_RES_DIR/base.c"

OUT_OBJ_RES="$OUT_DIR/resources.o"
OUT_OBJ_ARENA="$OUT_DIR/arena.o"
OUT_OBJ_BASE="$OUT_DIR/base.o"

OUT_LIB="$OUT_DIR/libagent_resources.a"

Expand Down Expand Up @@ -133,10 +135,13 @@ $CC $CFLAGS -c "$SRC_RES" -o "$OUT_OBJ_RES"
echo "Compiling arena.c..."
$CC $CFLAGS -c "$SRC_ARENA" -o "$OUT_OBJ_ARENA"

echo "Compiling base.c..."
$CC $CFLAGS -c "$SRC_BASE" -o "$OUT_OBJ_BASE"

echo "Creating static library..."
# $AR rcs "$OUT_LIB" "$OUT_OBJ"

$AR rcs "$OUT_LIB" "$OUT_OBJ_RES" "$OUT_OBJ_ARENA"
$AR rcs "$OUT_LIB" "$OUT_OBJ_RES" "$OUT_OBJ_ARENA" "$OUT_OBJ_BASE"

echo "Done: $OUT_LIB"

Expand Down
228 changes: 153 additions & 75 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Package main boots the Paradigm Agent gRPC server.
//
// Responsibilities:
// - Parse runtime flags (IP, port, diagnostics)
// - Bind a TCP listener with automatic port fallback
// - Initialize and register all gRPC services
// - Expose health and reflection endpoints
//
// Design notes:
// - The server must be able to start even if the preferred port is occupied.
// - Reflection is enabled by default for debugging and introspection.
// - Diagnostics are intentionally decoupled from server startup to avoid
// blocking gRPC reflection and request handling.
/*
Package main boots the Paradigm Agent gRPC server.

Responsibilities:
- Parse runtime flags (IP, port, diagnostics)
- Bind a TCP listener with automatic port fallback
- Initialize and register all gRPC services
- Expose health and reflection endpoints

Design notes:
- The server must be able to start even if the preferred port is occupied.
- Reflection is enabled by default for debugging and introspection.
- Diagnostics are intentionally decoupled from server startup to avoid
blocking gRPC reflection and request handling.
*/
package main

import (
Expand All @@ -22,9 +24,15 @@ import (
devacpb "paradigm-ehb/agent/gen/actions/v1"
"paradigm-ehb/agent/gen/greet"
"paradigm-ehb/agent/gen/journal/v1"
"paradigm-ehb/agent/gen/resources/v1"
services_v1 "paradigm-ehb/agent/gen/services/v1"
services_v2 "paradigm-ehb/agent/gen/services/v2"

"log"

servicesV1 "paradigm-ehb/agent/gen/services/v1"
servicesV2 "paradigm-ehb/agent/gen/services/v2"
servicesV3 "paradigm-ehb/agent/gen/services/v3"

resourcesv1 "paradigm-ehb/agent/gen/resources/v1"
resourcesv2 "paradigm-ehb/agent/gen/resources/v2"

"google.golang.org/grpc"
"google.golang.org/grpc/health"
Expand All @@ -33,54 +41,82 @@ import (

"paradigm-ehb/agent/internal/platform"

"paradigm-ehb/agent/pkg/grpc_handler"
"paradigm-ehb/agent/pkg/grpchandler"

resourcesHandlerV1 "paradigm-ehb/agent/pkg/grpchandler/resources/v1"
resourcesHandlerV2 "paradigm-ehb/agent/pkg/grpchandler/resources/v2"

servicesHandlerV1 "paradigm-ehb/agent/pkg/grpchandler/services/v1"
servicesHandlerV2 "paradigm-ehb/agent/pkg/grpchandler/services/v2"
servicesHandlerV3 "paradigm-ehb/agent/pkg/grpchandler/services/v3"

"syscall"
"time"
)

var (
/**
diagnostics enables periodic runtime diagnostics such as
resource usage, process health, and connectivity checks.
NOTE: When enabled, diagnostics must never block the gRPC server.
**/
/*
diagnostics enables periodic runtime diagnostics such as
resource usage, process health, and connectivity checks.

diagnostics = flag.Bool("diagnostics", true, "run runtime diagnostics")
TODO:
- Add structured configuration for diagnostics intervals.
- Allow diagnostics to be toggled or reconfigured at runtime.
- Ensure diagnostics respect context cancellation on shutdown.

/**
portFlag is the preferred TCP port to bind the gRPC server to.
If unavailable, the server will increment the port until a free
one is found.
NOTE:
When enabled, diagnostics must never block the gRPC server.
*/
diagnostics = flag.Bool("diagnostics", false, "run runtime diagnostics")

/*
portFlag is the preferred TCP port to bind the gRPC server to.

If unavailable:
- The server increments the port until a free one is found.

TODO:
- Log the final selected port explicitly.
- Optionally expose the selected port via diagnostics or metadata.
*/
portFlag = flag.Int("port", 5000, "port to listen on")

/**
ipFlag defines the IP address diagnostics may use when reporting
or exposing runtime information.
/*
ipFlag defines the IP address diagnostics may use when reporting
or exposing runtime information.

TODO:
- Validate IP format early.
- Clarify distinction between bind address vs diagnostics address.
*/
ipFlag = flag.String("ip", "0.0.0.0", "ip addr")
)

func main() {

/**
/*
Parse command-line flags before any runtime behavior.
*/

TODO:
- Add validation for flag combinations.
- Print effective configuration at startup.
*/
flag.Parse()

/**
/*
Attempt to bind a TCP listener.

Strategy:
- Start with the requested port
- If EADDRINUSE is encountered, increment the port and retry
- Fail hard on any other error
- Start with the requested port
- If EADDRINUSE is encountered, increment the port and retry
- Fail hard on any other error

This guarantees the agent can always start, even in constrained
or multi-agent environments.

TODO:
- Add an upper bound to port scanning.
- Support IPv6 or configurable network protocols.
*/
var lis net.Listener
var err error
Expand All @@ -100,83 +136,125 @@ func main() {
}
}

/**
/*
Any error other than "address already in use" is fatal.

TODO:
- Emit structured logs.
- Exit with non-zero status code.
*/
fmt.Println("failed to listen:", err)
log.Printf("failed to listen: %v", err)
return
}
break
}

/**
/*
Create the gRPC server instance.

TODO:
- Configure server options (timeouts, interceptors, limits).
- Add graceful shutdown handling.
*/
server := grpc.NewServer()

/**
/*
Health server is used by orchestration systems (systemd, Kubernetes,
external monitors) to determine liveness and readiness.

TODO:
- Set explicit serving statuses per service.
*/
healthServer := health.NewServer()
grpc_health_v1.RegisterHealthServer(server, healthServer)
/**

Register all application services.
/*
Register all application services.

Each service implements a distinct responsibility:
- Greeter: connectivity / handshake testing
- HandlerService: service lifecycle and orchestration
- JournalService: event and state journaling
- ResourcesService: system resource inspection and reporting
Each service implements a distinct responsibility:
- Greeter: connectivity / handshake testing
- HandlerService: service lifecycle and orchestration
- JournalService: event and state journaling
- ResourcesService: system resource inspection and reporting

TODO:
- Centralize service registration.
- Version-gate deprecated service versions.
*/

greet.RegisterGreeterServer(server, &grpc_handler.GreeterServer{})
services_v1.RegisterHandlerServiceServer(server, &grpc_handler.HandlerService{})
services_v2.RegisterHandlerServiceServer(server, &grpc_handler.HandlerServiceV2{})
journal.RegisterJournalServiceServer(server, &grpc_handler.JournalService{})
resourcespb.RegisterResourcesServiceServer(server, &grpc_handler.ResourcesService{})
devacpb.RegisterActionServiceServer(server, &grpc_handler.DeviceActionsService{})
greet.RegisterGreeterServer(
server,
&grpc_handler.GreeterServer{},
)

servicesV1.RegisterHandlerServiceServer(
server,
&servicesHandlerV1.HandlerService{},
)

servicesV2.RegisterHandlerServiceServer(
server,
&servicesHandlerV2.HandlerServiceV2{},
)

servicesV3.RegisterHandlerServiceServer(
server,
&servicesHandlerV3.HandlerServicev3{},
)

journal.RegisterJournalServiceServer(
server,
&grpc_handler.JournalService{},
)

resourcesv1.RegisterResourcesServiceServer(
server,
&resourcesHandlerV1.ResourcesService{},
)

resourcesv2.RegisterResourcesServiceServer(
server,
&resourcesHandlerV2.ResourcesServiceV2{},
)

devacpb.RegisterActionServiceServer(
server,
&grpc_handler.DeviceActionsService{},
)

/*
Diagnostics mode (disabled for now)

Problem:
- Running diagnostics synchronously introduces an infinite loop
that blocks gRPC reflection and request handling.

Important invariant:
- Diagnostics must run asynchronously and must never interfere
with server startup, reflection, or request processing.

TODO(nasr):
- Move diagnostics into a separate goroutine
- Introduce a proper shutdown context
- Ensure diagnostics respect server lifecycle
*/

/**
Enable gRPC reflection unconditionally.

This allows tools such as grpcurl and gRPC UI to inspect services
and message schemas at runtime.

TODO:
- Make reflection configurable for production environments.
*/
reflection.Register(server)
fmt.Printf("\nserver listening at %v\n", lis.Addr())

log.Printf("\nserver listening at %v\n", lis.Addr())

if *diagnostics {

/*
TODO:
- Tie diagnostics lifecycle to server context.
- Ensure diagnostics terminate on server shutdown.
*/
go platform.RunRuntimeDiagnostics(time.Second*2, *ipFlag, *portFlag)

}


/**
/*
Start serving requests.

This call blocks until the server is stopped or encounters a fatal error.

TODO:
- Implement graceful shutdown (signals, context).
- Flush diagnostics and logs before exit.
*/
if err := server.Serve(lis); err != nil {
fmt.Println("failed to serve:", err)
log.Printf("failed to serve: %v", err)
}
}
Loading
Loading