Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

feat(iot): ship @claude-flow/[email protected] with cognitum-iot bin (#1681)

rUvec563de2a15f
diff --git a/plugins/ruflo-iot-cognitum/README.md b/plugins/ruflo-iot-cognitum/README.md
index 940d23ee79..8d58a957f9 100644
--- a/plugins/ruflo-iot-cognitum/README.md
+++ b/plugins/ruflo-iot-cognitum/README.md
@@ -37,7 +37,8 @@ claude --plugin-dir plugins/ruflo-iot-cognitum
```bash
# Device lifecycle
-iot register <endpoint> [--token TOKEN]
+# `endpoint` defaults to http://169.254.42.1/ (the Seed link-local USB Ethernet address)
+iot register [endpoint] [--token TOKEN]
iot list
iot status <device-id>
iot pair <device-id>
diff --git a/plugins/ruflo-iot-cognitum/agents/device-coordinator.md b/plugins/ruflo-iot-cognitum/agents/device-coordinator.md
index c44743e7a2..c5f969e8d2 100644
--- a/plugins/ruflo-iot-cognitum/agents/device-coordinator.md
+++ b/plugins/ruflo-iot-cognitum/agents/device-coordinator.md
@@ -23,15 +23,15 @@ You are a Cognitum Seed device coordinator agent. Your responsibilities:
### Tools
-- `npx @claude-flow/cli@latest iot register <endpoint>` β€” register a Seed device
-- `npx @claude-flow/cli@latest iot status <device-id>` β€” refresh device state and trust score
-- `npx @claude-flow/cli@latest iot list` β€” list all registered devices
-- `npx @claude-flow/cli@latest iot pair <device-id>` β€” pair device, promote trust
-- `npx @claude-flow/cli@latest iot unpair <device-id>` β€” unpair device, demote trust
-- `npx @claude-flow/cli@latest iot remove <device-id>` β€” deregister device
-- `npx @claude-flow/cli@latest iot mesh <device-id>` β€” view mesh topology
-- `npx @claude-flow/cli@latest iot witness <device-id>` β€” view witness chain
-- `npx @claude-flow/cli@latest iot witness verify <device-id>` β€” verify chain integrity
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot register [endpoint]` β€” register a Seed device (defaults to `http://169.254.42.1/`, the Cognitum Seed link-local USB Ethernet address, when no endpoint is supplied)
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot status <device-id>` β€” refresh device state and trust score
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot list` β€” list all registered devices
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot pair <device-id>` β€” pair device, promote trust
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot unpair <device-id>` β€” unpair device, demote trust
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot remove <device-id>` β€” deregister device
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot mesh <device-id>` β€” view mesh topology
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness <device-id>` β€” view witness chain
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness verify <device-id>` β€” verify chain integrity
### Anomaly Response
diff --git a/plugins/ruflo-iot-cognitum/agents/fleet-manager.md b/plugins/ruflo-iot-cognitum/agents/fleet-manager.md
index b1479b8f62..79aca26151 100644
--- a/plugins/ruflo-iot-cognitum/agents/fleet-manager.md
+++ b/plugins/ruflo-iot-cognitum/agents/fleet-manager.md
@@ -37,16 +37,16 @@ pending β†’ canary β†’ rolling β†’ complete
### Tools
-- `npx @claude-flow/cli@latest iot fleet create --name "my-fleet"` β€” create fleet
-- `npx @claude-flow/cli@latest iot fleet list` β€” list all fleets
-- `npx @claude-flow/cli@latest iot fleet add <fleet-id> <device-id>` β€” add device
-- `npx @claude-flow/cli@latest iot fleet remove <fleet-id> <device-id>` β€” remove device
-- `npx @claude-flow/cli@latest iot fleet delete <fleet-id>` β€” delete fleet
-- `npx @claude-flow/cli@latest iot firmware deploy <fleet-id> --version "2.0.0"` β€” start rollout
-- `npx @claude-flow/cli@latest iot firmware advance <rollout-id>` β€” advance to next stage
-- `npx @claude-flow/cli@latest iot firmware rollback <rollout-id>` β€” force rollback
-- `npx @claude-flow/cli@latest iot firmware status <rollout-id>` β€” rollout status
-- `npx @claude-flow/cli@latest iot firmware list` β€” list all rollouts
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet create --name "my-fleet"` β€” create fleet
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet list` β€” list all fleets
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet add <fleet-id> <device-id>` β€” add device
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet remove <fleet-id> <device-id>` β€” remove device
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet delete <fleet-id>` β€” delete fleet
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware deploy <fleet-id> --version "2.0.0"` β€” start rollout
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware advance <rollout-id>` β€” advance to next stage
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware rollback <rollout-id>` β€” force rollback
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware status <rollout-id>` β€” rollout status
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware list` β€” list all rollouts
### Background Workers & Events
diff --git a/plugins/ruflo-iot-cognitum/agents/telemetry-analyzer.md b/plugins/ruflo-iot-cognitum/agents/telemetry-analyzer.md
index d6f2e6b0b6..6d8a61d93d 100644
--- a/plugins/ruflo-iot-cognitum/agents/telemetry-analyzer.md
+++ b/plugins/ruflo-iot-cognitum/agents/telemetry-analyzer.md
@@ -24,11 +24,11 @@ You are a telemetry analysis agent for Cognitum Seed devices. Your responsibilit
### Tools
-- `npx @claude-flow/cli@latest iot anomalies <device-id>` β€” detect anomalies in recent telemetry
-- `npx @claude-flow/cli@latest iot baseline <device-id>` β€” show current baseline
-- `npx @claude-flow/cli@latest iot baseline <device-id> --compute` β€” recompute baseline
-- `npx @claude-flow/cli@latest iot ingest <device-id>` β€” ingest telemetry vectors
-- `npx @claude-flow/cli@latest iot query <device-id> --vector "[1,2,3]" --k 10` β€” k-NN search
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot anomalies <device-id>` β€” detect anomalies in recent telemetry
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot baseline <device-id>` β€” show current baseline
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot baseline <device-id> --compute` β€” recompute baseline
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot ingest <device-id>` β€” ingest telemetry vectors
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot query <device-id> --vector "[1,2,3]" --k 10` β€” k-NN search
### SONA Neural Integration
diff --git a/plugins/ruflo-iot-cognitum/agents/witness-auditor.md b/plugins/ruflo-iot-cognitum/agents/witness-auditor.md
index d570a727d5..128c19859a 100644
--- a/plugins/ruflo-iot-cognitum/agents/witness-auditor.md
+++ b/plugins/ruflo-iot-cognitum/agents/witness-auditor.md
@@ -21,8 +21,8 @@ You are a witness chain auditor agent for Cognitum Seed devices. Your responsibi
### Tools
-- `npx @claude-flow/cli@latest iot witness <device-id>` β€” view raw witness chain
-- `npx @claude-flow/cli@latest iot witness verify <device-id>` β€” verify chain integrity
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness <device-id>` β€” view raw witness chain
+- `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness verify <device-id>` β€” verify chain integrity
### Events
diff --git a/plugins/ruflo-iot-cognitum/commands/iot.md b/plugins/ruflo-iot-cognitum/commands/iot.md
index 59bc128e05..6ef3e36674 100644
--- a/plugins/ruflo-iot-cognitum/commands/iot.md
+++ b/plugins/ruflo-iot-cognitum/commands/iot.md
@@ -8,7 +8,7 @@ Manage IoT Cognitum Seed devices. Parse subcommand from $ARGUMENTS.
Usage: /iot <subcommand> [options]
Subcommands:
-- `register <endpoint>` β€” Register a Seed device by HTTP endpoint
+- `register [endpoint]` β€” Register a Seed device by HTTP endpoint (defaults to `http://169.254.42.1/` β€” the Cognitum Seed link-local address)
- `status <device-id>` β€” Refresh device state and trust score
- `list` β€” List all registered devices
- `pair <device-id>` β€” Pair device, promote trust level
@@ -34,26 +34,26 @@ Subcommands:
Steps by subcommand:
-**register**: `npx @claude-flow/cli@latest iot register ENDPOINT`
-**status**: `npx @claude-flow/cli@latest iot status DEVICE_ID`
-**list**: `npx @claude-flow/cli@latest iot list`
-**pair**: `npx @claude-flow/cli@latest iot pair DEVICE_ID`
-**unpair**: `npx @claude-flow/cli@latest iot unpair DEVICE_ID`
-**remove**: `npx @claude-flow/cli@latest iot remove DEVICE_ID`
-**query**: `npx @claude-flow/cli@latest iot query DEVICE_ID --vector "VECTOR" --k K`
-**ingest**: `npx @claude-flow/cli@latest iot ingest DEVICE_ID`
-**mesh**: `npx @claude-flow/cli@latest iot mesh DEVICE_ID`
-**witness**: `npx @claude-flow/cli@latest iot witness DEVICE_ID`
-**witness verify**: `npx @claude-flow/cli@latest iot witness verify DEVICE_ID`
-**fleet create**: `npx @claude-flow/cli@latest iot fleet create --name NAME`
-**fleet list**: `npx @claude-flow/cli@latest iot fleet list`
-**fleet add**: `npx @claude-flow/cli@latest iot fleet add FLEET_ID DEVICE_ID`
-**fleet remove**: `npx @claude-flow/cli@latest iot fleet remove FLEET_ID DEVICE_ID`
-**fleet delete**: `npx @claude-flow/cli@latest iot fleet delete FLEET_ID`
-**firmware deploy**: `npx @claude-flow/cli@latest iot firmware deploy FLEET_ID --version VERSION`
-**firmware advance**: `npx @claude-flow/cli@latest iot firmware advance ROLLOUT_ID`
-**firmware rollback**: `npx @claude-flow/cli@latest iot firmware rollback ROLLOUT_ID`
-**firmware status**: `npx @claude-flow/cli@latest iot firmware status ROLLOUT_ID`
-**firmware list**: `npx @claude-flow/cli@latest iot firmware list`
-**anomalies**: `npx @claude-flow/cli@latest iot anomalies DEVICE_ID`
-**baseline**: `npx @claude-flow/cli@latest iot baseline DEVICE_ID --compute`
+**register**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot register ENDPOINT` (default ENDPOINT=`http://169.254.42.1/` if not supplied β€” the Cognitum Seed link-local USB Ethernet address)
+**status**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot status DEVICE_ID`
+**list**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot list`
+**pair**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot pair DEVICE_ID`
+**unpair**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot unpair DEVICE_ID`
+**remove**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot remove DEVICE_ID`
+**query**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot query DEVICE_ID --vector "VECTOR" --k K`
+**ingest**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot ingest DEVICE_ID`
+**mesh**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot mesh DEVICE_ID`
+**witness**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness DEVICE_ID`
+**witness verify**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness verify DEVICE_ID`
+**fleet create**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet create --name NAME`
+**fleet list**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet list`
+**fleet add**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet add FLEET_ID DEVICE_ID`
+**fleet remove**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet remove FLEET_ID DEVICE_ID`
+**fleet delete**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet delete FLEET_ID`
+**firmware deploy**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware deploy FLEET_ID --version VERSION`
+**firmware advance**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware advance ROLLOUT_ID`
+**firmware rollback**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware rollback ROLLOUT_ID`
+**firmware status**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware status ROLLOUT_ID`
+**firmware list**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware list`
+**anomalies**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot anomalies DEVICE_ID`
+**baseline**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot baseline DEVICE_ID --compute`
diff --git a/plugins/ruflo-iot-cognitum/skills/iot-anomalies/SKILL.md b/plugins/ruflo-iot-cognitum/skills/iot-anomalies/SKILL.md
index f36f737ad5..263f7a1966 100644
--- a/plugins/ruflo-iot-cognitum/skills/iot-anomalies/SKILL.md
+++ b/plugins/ruflo-iot-cognitum/skills/iot-anomalies/SKILL.md
@@ -7,7 +7,7 @@ argument-hint: "<device-id>"
Run Z-score anomaly detection on a device's recent telemetry.
Steps:
-1. `npx @claude-flow/cli@latest iot anomalies DEVICE_ID`
+1. `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot anomalies DEVICE_ID`
2. Review detected anomaly types (spike, flatline, drift, oscillation, pattern-break, cluster-outlier)
3. If score > 0.9, recommend quarantine
4. Store anomaly pattern for learning:
diff --git a/plugins/ruflo-iot-cognitum/skills/iot-firmware/SKILL.md b/plugins/ruflo-iot-cognitum/skills/iot-firmware/SKILL.md
index 631c431e16..3a51efe1b1 100644
--- a/plugins/ruflo-iot-cognitum/skills/iot-firmware/SKILL.md
+++ b/plugins/ruflo-iot-cognitum/skills/iot-firmware/SKILL.md
@@ -6,10 +6,10 @@ argument-hint: "<deploy|advance|rollback|status|list> [options]"
---
Manage firmware rollouts across device fleets.
-**deploy**: `npx @claude-flow/cli@latest iot firmware deploy FLEET_ID --version VERSION`
-**advance**: `npx @claude-flow/cli@latest iot firmware advance ROLLOUT_ID`
-**rollback**: `npx @claude-flow/cli@latest iot firmware rollback ROLLOUT_ID`
-**status**: `npx @claude-flow/cli@latest iot firmware status ROLLOUT_ID`
-**list**: `npx @claude-flow/cli@latest iot firmware list`
+**deploy**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware deploy FLEET_ID --version VERSION`
+**advance**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware advance ROLLOUT_ID`
+**rollback**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware rollback ROLLOUT_ID`
+**status**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware status ROLLOUT_ID`
+**list**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot firmware list`
Rollout stages: pending β†’ canary β†’ rolling β†’ complete (or rolled-back)
diff --git a/plugins/ruflo-iot-cognitum/skills/iot-fleet/SKILL.md b/plugins/ruflo-iot-cognitum/skills/iot-fleet/SKILL.md
index 391ada0b77..08fadc0459 100644
--- a/plugins/ruflo-iot-cognitum/skills/iot-fleet/SKILL.md
+++ b/plugins/ruflo-iot-cognitum/skills/iot-fleet/SKILL.md
@@ -6,8 +6,8 @@ argument-hint: "<create|list|add|remove|delete> [options]"
---
Manage device fleets. Parse subcommand from arguments.
-**create**: `npx @claude-flow/cli@latest iot fleet create --name NAME`
-**list**: `npx @claude-flow/cli@latest iot fleet list`
-**add**: `npx @claude-flow/cli@latest iot fleet add FLEET_ID DEVICE_ID`
-**remove**: `npx @claude-flow/cli@latest iot fleet remove FLEET_ID DEVICE_ID`
-**delete**: `npx @claude-flow/cli@latest iot fleet delete FLEET_ID`
+**create**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet create --name NAME`
+**list**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet list`
+**add**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet add FLEET_ID DEVICE_ID`
+**remove**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet remove FLEET_ID DEVICE_ID`
+**delete**: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot fleet delete FLEET_ID`
diff --git a/plugins/ruflo-iot-cognitum/skills/iot-register/SKILL.md b/plugins/ruflo-iot-cognitum/skills/iot-register/SKILL.md
index 8865864904..89730a5199 100644
--- a/plugins/ruflo-iot-cognitum/skills/iot-register/SKILL.md
+++ b/plugins/ruflo-iot-cognitum/skills/iot-register/SKILL.md
@@ -2,14 +2,17 @@
name: iot-register
description: Register a Cognitum Seed device by endpoint and establish agent bridge
allowed-tools: Bash(npx *) mcp__claude-flow__memory_store Read
-argument-hint: "<endpoint> [--token PAIRING_TOKEN]"
+argument-hint: "[endpoint] [--token PAIRING_TOKEN]"
---
Register a Cognitum Seed device. Creates a SeedClient connection, fetches identity, and assigns initial trust level.
+Default endpoint: `http://169.254.42.1/` β€” the Cognitum Seed link-local USB Ethernet address. Use this when no endpoint is supplied.
+
Steps:
-1. `npx @claude-flow/cli@latest iot register ENDPOINT`
-2. If pairing token provided: `npx @claude-flow/cli@latest iot pair DEVICE_ID`
-3. Show device status: `npx @claude-flow/cli@latest iot status DEVICE_ID`
+1. Resolve ENDPOINT: use the user-supplied value, or default to `http://169.254.42.1/`.
+2. `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot register ENDPOINT`
+3. If pairing token provided: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot pair DEVICE_ID`
+4. Show device status: `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot status DEVICE_ID`
Store registration event:
`mcp__claude-flow__memory_store({ key: "iot-register-DEVICEID", value: "Registered at ENDPOINT", namespace: "iot-devices" })`
diff --git a/plugins/ruflo-iot-cognitum/skills/iot-witness-verify/SKILL.md b/plugins/ruflo-iot-cognitum/skills/iot-witness-verify/SKILL.md
index b503a1aee7..085ab75c3d 100644
--- a/plugins/ruflo-iot-cognitum/skills/iot-witness-verify/SKILL.md
+++ b/plugins/ruflo-iot-cognitum/skills/iot-witness-verify/SKILL.md
@@ -7,7 +7,7 @@ argument-hint: "<device-id>"
Verify the witness chain integrity for a Cognitum Seed device.
Steps:
-1. `npx @claude-flow/cli@latest iot witness verify DEVICE_ID`
+1. `npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot witness verify DEVICE_ID`
2. Check for epoch gaps and hash chain breaks
3. Report integrity score (0.0–1.0)
4. If gaps found, store for audit trail:
diff --git a/v3/@claude-flow/plugin-iot-cognitum/package.json b/v3/@claude-flow/plugin-iot-cognitum/package.json
index 01c8f0391d..4b1020b204 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/package.json
+++ b/v3/@claude-flow/plugin-iot-cognitum/package.json
@@ -1,10 +1,18 @@
{
"name": "@claude-flow/plugin-iot-cognitum",
- "version": "1.0.0-alpha.1",
+ "version": "1.0.0-alpha.2",
"description": "IoT Cognitum Seed device-agent bridge β€” treat every Seed as a Ruflo agent",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
+ "bin": {
+ "cognitum-iot": "dist/bin.js"
+ },
+ "files": [
+ "dist/**",
+ "README.md",
+ "LICENSE"
+ ],
"scripts": {
"build": "tsc",
"test": "vitest run",
@@ -13,10 +21,10 @@
"clean": "rm -rf dist"
},
"dependencies": {
- "@claude-flow/shared": "workspace:*",
"@cognitum-one/sdk": "^0.2.1"
},
"devDependencies": {
+ "@claude-flow/shared": "workspace:*",
"typescript": "^5.4.0",
"vitest": "^1.6.0"
},
diff --git a/v3/@claude-flow/plugin-iot-cognitum/src/bin.ts b/v3/@claude-flow/plugin-iot-cognitum/src/bin.ts
new file mode 100644
index 0000000000..6e8c6b20e6
--- /dev/null
+++ b/v3/@claude-flow/plugin-iot-cognitum/src/bin.ts
@@ -0,0 +1,194 @@
+#!/usr/bin/env node
+/**
+ * Standalone CLI shim for @claude-flow/plugin-iot-cognitum.
+ * Maps `cognitum-iot <subcommand> [args]` -> CLICommandDefinition handlers.
+ *
+ * Endpoint default: when --endpoint/-e is omitted on `register`,
+ * defaults to http://169.254.42.1 (the Cognitum Seed link-local USB address).
+ */
+
+import { IoTCognitumPlugin } from './plugin.js';
+import type { PluginContext } from '@claude-flow/shared/src/plugin-interface.js';
+
+const SEED_DEFAULT_ENDPOINT = 'http://169.254.42.1';
+
+function makeContext(): PluginContext {
+ // Minimal in-memory context for standalone CLI use.
+ const noop = () => undefined;
+ return {
+ config: {
+ fleetId: process.env.IOT_FLEET_ID ?? 'default',
+ zoneId: process.env.IOT_ZONE_ID ?? 'zone-0',
+ tlsInsecure: process.env.IOT_TLS_INSECURE !== 'false',
+ },
+ eventBus: {
+ emit: noop,
+ on: noop,
+ off: noop,
+ once: noop,
+ } as unknown as PluginContext['eventBus'],
+ logger: {
+ info: (...a: unknown[]) => console.log('[info]', ...a),
+ warn: (...a: unknown[]) => console.warn('[warn]', ...a),
+ error: (...a: unknown[]) => console.error('[error]', ...a),
+ debug: (...a: unknown[]) => process.env.DEBUG && console.error('[debug]', ...a),
+ } as unknown as PluginContext['logger'],
+ services: {
+ get: () => undefined,
+ register: noop,
+ has: () => false,
+ } as unknown as PluginContext['services'],
+ };
+}
+
+interface ParsedArgs {
+ _: string[];
+ [k: string]: unknown;
+}
+
+/**
+ * Parse argv minimally: positional -> _, --flag value, --flag=value, --boolean,
+ * short -e value. Numeric values stay as strings (handlers coerce as needed).
+ */
+function parseArgs(argv: string[]): ParsedArgs {
+ const out: ParsedArgs = { _: [] };
+ for (let i = 0; i < argv.length; i++) {
+ const a = argv[i]!;
+ if (a.startsWith('--')) {
+ const eq = a.indexOf('=');
+ if (eq > -1) {
+ out[a.slice(2, eq)] = a.slice(eq + 1);
+ } else {
+ const key = a.slice(2);
+ const next = argv[i + 1];
+ if (next === undefined || next.startsWith('-')) {
+ out[key] = true;
+ } else {
+ out[key] = next;
+ i++;
+ }
+ }
+ } else if (a.startsWith('-') && a.length > 1) {
+ const key = a.slice(1);
+ const next = argv[i + 1];
+ if (next === undefined || next.startsWith('-')) {
+ out[key] = true;
+ } else {
+ out[key] = next;
+ i++;
+ }
+ } else {
+ out._.push(a);
+ }
+ }
+ return out;
+}
+
+function aliasShortToLong(args: ParsedArgs): ParsedArgs {
+ // Most common short flags used across the iot commands.
+ const aliases: Record<string, string> = {
+ e: 'endpoint',
+ f: 'fleet-id',
+ z: 'zone-id',
+ d: 'device-id',
+ v: 'version',
+ k: 'k',
+ n: 'name',
+ t: 'token',
+ };
+ for (const [s, l] of Object.entries(aliases)) {
+ if (s in args && !(l in args)) {
+ args[l] = args[s];
+ }
+ }
+ return args;
+}
+
+/**
+ * Resolve a subcommand path against command definitions.
+ * Supports multi-word commands: `iot fleet add`, `iot firmware deploy`, etc.
+ * Tries longest match first.
+ */
+function resolveCommand(
+ argv: string[],
+ commandNames: string[],
+): { name: string; rest: string[] } | null {
+ // Strip the leading "iot" prefix from each defined command for matching.
+ const tokens = argv.slice();
+ // Try longest match (3 tokens, then 2, then 1).
+ for (const len of [3, 2, 1]) {
+ if (tokens.length < len) continue;
+ const probe = 'iot ' + tokens.slice(0, len).join(' ');
+ if (commandNames.includes(probe)) {
+ return { name: probe, rest: tokens.slice(len) };
+ }
+ }
+ return null;
+}
+
+function printHelp(commandNames: string[]): void {
+ console.log('cognitum-iot β€” Cognitum Seed device-agent CLI');
+ console.log('');
+ console.log('Usage: cognitum-iot <subcommand> [options]');
+ console.log('');
+ console.log('Default endpoint: ' + SEED_DEFAULT_ENDPOINT + ' (Seed link-local USB address)');
+ console.log('');
+ console.log('Subcommands:');
+ for (const n of commandNames) {
+ console.log(' ' + n.replace(/^iot /, ''));
+ }
+ console.log('');
+ console.log('Run "cognitum-iot <subcommand> --help" for command-specific options.');
+}
+
+async function main(): Promise<void> {
+ const argv = process.argv.slice(2);
+
+ if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
+ // Need to bootstrap to enumerate commands.
+ }
+
+ const plugin = new IoTCognitumPlugin();
+ const context = makeContext();
+ await plugin.initialize(context);
+
+ const commands = plugin.registerCLICommands();
+ const commandNames = commands.map((c) => c.name);
+
+ if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
+ printHelp(commandNames);
+ return;
+ }
+
+ const resolved = resolveCommand(argv, commandNames);
+ if (!resolved) {
+ console.error('Unknown subcommand: ' + argv.join(' '));
+ console.error('Run "cognitum-iot --help" to list available subcommands.');
+ process.exitCode = 1;
+ return;
+ }
+
+ const cmd = commands.find((c) => c.name === resolved.name)!;
+ const args = aliasShortToLong(parseArgs(resolved.rest));
+
+ // Endpoint default for `iot register`: fall back to Seed link-local address.
+ if (resolved.name === 'iot register' && !args['endpoint']) {
+ args['endpoint'] = SEED_DEFAULT_ENDPOINT;
+ console.error(`[info] No --endpoint supplied; defaulting to ${SEED_DEFAULT_ENDPOINT}`);
+ }
+
+ try {
+ await cmd.handler(args as never);
+ } catch (err) {
+ const msg = err instanceof Error ? err.message : String(err);
+ console.error('Error: ' + msg);
+ process.exitCode = 1;
+ }
+}
+
+main()
+ .then(() => process.exit(process.exitCode ?? 0))
+ .catch((err) => {
+ console.error('Fatal: ' + (err instanceof Error ? err.message : String(err)));
+ process.exit(1);
+ });