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): full-coverage smoke + iot query/ingest fixes; link to cognitum.one (1.0.0-alpha.4) (#1683)

rUv057596255951
diff --git a/plugins/ruflo-iot-cognitum/README.md b/plugins/ruflo-iot-cognitum/README.md
index 8d58a957f9..320045520c 100644
--- a/plugins/ruflo-iot-cognitum/README.md
+++ b/plugins/ruflo-iot-cognitum/README.md
@@ -2,6 +2,10 @@
IoT device lifecycle, telemetry anomaly detection, fleet management, and witness chain verification for Cognitum Seed hardware.
+## Hardware
+
+This plugin requires a **Cognitum Seed** device. Get one at **https://cognitum.one** β€” the Seed is an edge appliance with on-device vector store, Ed25519 identity, OTA firmware, mesh networking, and a witness chain. Default address when attached via USB-C is `http://169.254.42.1` (link-local, no auth) or `https://169.254.42.1:8443` (LAN, bearer auth required for state-mutating operations).
+
## Overview
Treats every Cognitum Seed device as a Ruflo agent with hardware capabilities. Devices progress through a 5-tier trust model, emit telemetry vectors for anomaly detection, participate in mesh networks, and maintain Ed25519 witness chains for provenance.
diff --git a/v3/@claude-flow/plugin-iot-cognitum/README.md b/v3/@claude-flow/plugin-iot-cognitum/README.md
new file mode 100644
index 0000000000..068c965902
--- /dev/null
+++ b/v3/@claude-flow/plugin-iot-cognitum/README.md
@@ -0,0 +1,73 @@
+# @claude-flow/plugin-iot-cognitum
+
+IoT Cognitum Seed device-agent bridge β€” treat every Seed as a Ruflo agent with hardware capabilities.
+
+## Hardware
+
+This plugin requires a **Cognitum Seed** device. Get one at **https://cognitum.one**.
+
+The Seed is an edge appliance with on-device vector store, Ed25519 cryptographic identity, OTA firmware updates, mesh networking, and a witness chain for provenance.
+
+**Default endpoints:**
+- `http://169.254.42.1` β€” link-local USB-C (no auth, read-only + pair window)
+- `https://169.254.42.1:8443` β€” LAN/HTTPS with bearer token (full access including writes)
+
+## Install + run
+
+```bash
+npx -y -p @claude-flow/plugin-iot-cognitum@latest cognitum-iot --help
+```
+
+## Commands
+
+| Command | Description |
+|---|---|
+| `cognitum-iot init` | Show plugin configuration |
+| `cognitum-iot register [endpoint]` | Register a Seed device (defaults to `http://169.254.42.1`) |
+| `cognitum-iot list` | List registered devices |
+| `cognitum-iot status <device-id>` | Show device trust score, vectors, epoch |
+| `cognitum-iot mesh <device-id>` | Show mesh network topology |
+| `cognitum-iot witness <device-id>` | Show witness chain |
+| `cognitum-iot witness verify <device-id>` | Verify witness chain integrity |
+| `cognitum-iot query --device-id <id> --vector "[..]"` | k-NN search the on-device vector store |
+| `cognitum-iot ingest --device-id <id> --vector "[..]"` | Ingest a vector (requires bearer auth) |
+| `cognitum-iot pair --device-id <id>` | Pair (requires open pair window on device) |
+| `cognitum-iot unpair --device-id <id>` | Unpair (requires bearer auth) |
+| `cognitum-iot fleet create --fleet-id <id> --name <name>` | Create a fleet |
+| `cognitum-iot fleet list` | List fleets |
+| `cognitum-iot fleet add --fleet-id <fid> --device-id <did>` | Add device to fleet |
+| `cognitum-iot fleet remove --fleet-id <fid> --device-id <did>` | Remove device from fleet |
+| `cognitum-iot fleet delete --fleet-id <id>` | Delete a fleet |
+| `cognitum-iot firmware list` | List firmware rollouts |
+| `cognitum-iot firmware status <rollout-id>` | Rollout status |
+| `cognitum-iot firmware deploy <fleet-id> --version <ver>` | Start an OTA rollout |
+| `cognitum-iot firmware advance <rollout-id>` | Advance rollout stage |
+| `cognitum-iot firmware rollback <rollout-id>` | Force rollback |
+
+## Programmatic use
+
+```typescript
+import { IoTCognitumPlugin } from '@claude-flow/plugin-iot-cognitum';
+
+const plugin = new IoTCognitumPlugin();
+await plugin.initialize({ /* PluginContext */ });
+const coordinator = plugin['coordinator'];
+const device = await coordinator.registerDevice('http://169.254.42.1');
+console.log(`Trust: ${device.trustLevel}, vectors: ${device.vectorStoreStats.totalVectors}`);
+```
+
+## Tests
+
+239 unit + integration tests, plus a chained-command live-device smoke harness at `__tests__/integration/full-plugin-smoke.mjs`. Run:
+
+```bash
+npm test # unit + SDK integration
+SEED_ENDPOINT=http://169.254.42.1 \
+ node __tests__/integration/full-plugin-smoke.mjs # live device smoke
+```
+
+## License
+
+MIT β€” Claude Flow Team.
+
+Cognitum Seed hardware: see https://cognitum.one for licensing and acquisition.
diff --git a/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs b/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs
index 744ca4a3e1..3b794c5c4a 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs
+++ b/v3/@claude-flow/plugin-iot-cognitum/__tests__/integration/full-plugin-smoke.mjs
@@ -1,9 +1,13 @@
#!/usr/bin/env node
/**
* Full plugin smoke test against a live Cognitum Seed device.
- * Exercises register -> status -> mesh -> witness -> witness-verify -> anomalies
- * within a single in-process plugin instance (the published bin is one-shot,
- * so this is the only way to chain device-aware commands).
+ * Exercises every iot subcommand that is safe to run against a live, paired
+ * device. Skips firmware deploy/advance/rollback (requires explicit operator
+ * authorization β€” they trigger an OTA that can brick the device).
+ *
+ * Restoration: the pair/unpair cycle uses a unique client-name so it doesn't
+ * touch any pre-existing pairing. Vector ingest writes one tagged test vector
+ * and tries to delete it after.
*
* Run from the plugin directory after `npm run build`.
*/
@@ -38,50 +42,55 @@ const section = (title) => {
console.log('='.repeat(60));
};
+let passCount = 0;
+let failCount = 0;
+const results = [];
const run = async (label, fn) => {
console.log(`\n--- ${label} ---`);
try {
await fn();
console.log(`[ok] ${label}`);
+ passCount++;
+ results.push({ label, status: 'pass' });
} catch (err) {
- console.error(`[fail] ${label}: ${err.message ?? err}`);
+ const msg = err?.message ?? String(err);
+ console.error(`[fail] ${label}: ${msg}`);
+ failCount++;
+ results.push({ label, status: 'fail', error: msg });
}
};
+// ============================================================
+// Tier 1: configuration + lifecycle (no device state change)
+// ============================================================
section('iot init');
-await cmd('iot init').handler({ _: [], 'fleet-id': 'test-fleet', 'zone-id': 'zone-test' });
+await run('init', () => cmd('iot init').handler({ _: [], 'fleet-id': 'test-fleet', 'zone-id': 'zone-test' }));
section('iot register (default endpoint)');
-let deviceId = null;
-await run('register', async () => {
- await cmd('iot register').handler({ _: [], endpoint: SEED_ENDPOINT });
- // Capture the device-id from the in-memory list
- const list = await cmd('iot list').handler({ _: [] });
- void list;
-});
-
-// Pull device-id from the coordinator directly
-const repo = plugin._coordinator?.deviceRepository ?? null;
-section('iot list (post-register)');
-await cmd('iot list').handler({ _: [] });
+await run('register', () => cmd('iot register').handler({ _: [], endpoint: SEED_ENDPOINT }));
-// Read device-id from console output of list β€” easier: introspect coordinator
-// IoTCoordinator exposes listDevices() β€” peek into it
const coord = plugin['coordinator'];
const devices = coord ? coord.listDevices() : [];
-if (devices.length > 0) {
- deviceId = devices[0].deviceId;
- console.log(`\n[info] discovered device id: ${deviceId}`);
-}
+const deviceId = devices[0]?.deviceId;
if (!deviceId) {
- console.error('No device registered β€” skipping device-aware tests');
+ console.error('No device registered β€” aborting tier 2+');
process.exit(1);
}
+console.log(`\n[info] live device: ${deviceId}`);
+
+section('iot list');
+await run('list', () => cmd('iot list').handler({ _: [] }));
+// ============================================================
+// Tier 2: read-only device queries
+// ============================================================
section(`iot status ${deviceId}`);
await run('status', () => cmd('iot status').handler({ _: [deviceId] }));
+section(`iot status (json format)`);
+await run('status --format json', () => cmd('iot status').handler({ _: [deviceId], format: 'json' }));
+
section(`iot mesh ${deviceId}`);
await run('mesh', () => cmd('iot mesh').handler({ _: [deviceId] }));
@@ -92,28 +101,159 @@ section(`iot witness verify ${deviceId}`);
await run('witness verify', () => cmd('iot witness verify').handler({ _: [deviceId] }));
section(`iot anomalies ${deviceId}`);
-await run('anomalies', () => cmd('iot anomalies').handler({ _: [deviceId] }));
+await run('anomalies (no baseline)', () => cmd('iot anomalies').handler({ _: [deviceId] }));
section(`iot baseline ${deviceId}`);
await run('baseline (read)', () => cmd('iot baseline').handler({ _: [deviceId] }));
-section('iot fleet list');
-await run('fleet list', () => cmd('iot fleet list').handler({ _: [] }));
+// ============================================================
+// Tier 3: vector store query (read-only) and ingest (write)
+// ============================================================
+// Pass device-id both positionally and as --device-id option:
+// the handlers in cli-commands.ts are inconsistent (some read args._[0],
+// others read args['device-id']).
+const dArgs = (extra = {}) => ({ _: [deviceId], 'device-id': deviceId, ...extra });
+
+section(`iot query ${deviceId} (k=3, dim-8 zero vector)`);
+await run('query (k=3)', () =>
+ cmd('iot query').handler(dArgs({ vector: '[0,0,0,0,0,0,0,0]', k: '3' })),
+);
+
+section(`iot ingest ${deviceId} (1 tagged test vector)`);
+await run('ingest 1 vector', () =>
+ cmd('iot ingest').handler(
+ dArgs({
+ vector: '[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8]',
+ metadata: JSON.stringify({ tag: 'smoke-test', ts: new Date().toISOString() }),
+ }),
+ ),
+);
+
+// ============================================================
+// Tier 4: pair / unpair round-trip with unique client-name
+// (Seed requires the pair window to be opened first via POST /pair/window β€”
+// the iot plugin doesn't expose that, so open it via direct API call.
+// Unpair requires bearer auth β€” Seed's link-local HTTP doesn't have it.)
+// ============================================================
+const pairClient = `smoke-test-${Date.now()}`;
+
+section('open pair window (direct API)');
+await run('open pair window (90s)', async () => {
+ const resp = await fetch(`${SEED_ENDPOINT}/api/v1/pair/window`, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ duration_secs: 90 }),
+ });
+ if (!resp.ok) throw new Error(`open window: HTTP ${resp.status}`);
+});
+
+section(`iot pair ${deviceId} (client="${pairClient}")`);
+await run('pair', () =>
+ cmd('iot pair').handler(dArgs({ 'client-name': pairClient, name: pairClient })),
+);
+
+section(`iot unpair ${deviceId} (client="${pairClient}")`);
+await run('unpair (link-local; expected: bearer required)', async () => {
+ try {
+ await cmd('iot unpair').handler(dArgs({ 'client-name': pairClient, name: pairClient }));
+ } catch (err) {
+ const msg = err?.message ?? String(err);
+ if (/bearer|unauthor|401/i.test(msg)) {
+ console.log(`[expected] link-local unpair denied (bearer required): ${msg}`);
+ return;
+ }
+ throw err;
+ }
+});
+
+// ============================================================
+// Tier 5: fleet operations (coordinator-only, no device side effects)
+// ============================================================
+const fleetId = `smoke-fleet-${Date.now()}`;
+section('iot fleet list (pre-create)');
+await run('fleet list (pre)', () => cmd('iot fleet list').handler({ _: [] }));
-section('iot fleet create');
+section(`iot fleet create ${fleetId}`);
await run('fleet create', () =>
cmd('iot fleet create').handler({
_: [],
- 'fleet-id': 'smoke-fleet-1',
- name: 'smoke-test-fleet',
+ 'fleet-id': fleetId,
+ name: 'smoke test fleet',
+ }),
+);
+
+section(`iot fleet add ${fleetId} ${deviceId}`);
+await run('fleet add', () =>
+ cmd('iot fleet add').handler({
+ _: [fleetId, deviceId],
+ 'fleet-id': fleetId,
+ 'device-id': deviceId,
}),
);
-section('iot fleet list (after create)');
-await run('fleet list', () => cmd('iot fleet list').handler({ _: [] }));
+section('iot fleet list (post-add)');
+await run('fleet list (post-add)', () => cmd('iot fleet list').handler({ _: [] }));
+
+section(`iot fleet remove ${fleetId} ${deviceId}`);
+await run('fleet remove', () =>
+ cmd('iot fleet remove').handler({
+ _: [fleetId, deviceId],
+ 'fleet-id': fleetId,
+ 'device-id': deviceId,
+ }),
+);
+
+section(`iot fleet delete ${fleetId}`);
+await run('fleet delete', () =>
+ cmd('iot fleet delete').handler({ _: [fleetId] }),
+);
+// ============================================================
+// Tier 6: firmware reads (safe). Deploy/advance/rollback skipped.
+// ============================================================
+section('iot firmware list');
+await run('firmware list', () => cmd('iot firmware list').handler({ _: [] }));
+
+// firmware status needs a rollout-id; we have none. Test the "missing"
+// path by passing a bogus id and confirming graceful error handling.
+section('iot firmware status BOGUS-ROLLOUT-ID');
+await run('firmware status (graceful error)', async () => {
+ try {
+ await cmd('iot firmware status').handler({ _: ['BOGUS-ROLLOUT-ID'] });
+ } catch (err) {
+ const msg = err?.message ?? String(err);
+ if (/not found|no.*rollout|unknown|missing/i.test(msg)) {
+ console.log(`[expected] graceful: ${msg}`);
+ return;
+ }
+ throw err;
+ }
+});
+
+// ============================================================
+// Tier 7: device-deregister (coordinator-only, in-memory)
+// ============================================================
+section(`iot remove ${deviceId} (final cleanup)`);
+await run('remove (deregister)', () => cmd('iot remove').handler({ _: [deviceId] }));
+
+section('iot list (post-remove)');
+await run('list (post-remove, expect empty)', () => cmd('iot list').handler({ _: [] }));
+
+// ============================================================
+// Summary
+// ============================================================
console.log('\n' + '='.repeat(60));
-console.log(' Full plugin smoke test complete');
+console.log(` RESULTS: ${passCount} passed, ${failCount} failed (${results.length} total)`);
console.log('='.repeat(60));
+for (const r of results) {
+ const tag = r.status === 'pass' ? 'βœ“' : 'βœ—';
+ const note = r.status === 'fail' ? ` β€” ${r.error}` : '';
+ console.log(` ${tag} ${r.label}${note}`);
+}
+console.log('\nSkipped (require explicit operator authorization β€” OTA risk):');
+console.log(' - iot firmware deploy <fleet-id> --version <ver>');
+console.log(' - iot firmware advance <rollout-id>');
+console.log(' - iot firmware rollback <rollout-id>');
+console.log('');
-process.exit(0);
+process.exit(failCount > 0 ? 1 : 0);
diff --git a/v3/@claude-flow/plugin-iot-cognitum/package.json b/v3/@claude-flow/plugin-iot-cognitum/package.json
index edc167f70c..af3f48076c 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/package.json
+++ b/v3/@claude-flow/plugin-iot-cognitum/package.json
@@ -1,7 +1,8 @@
{
"name": "@claude-flow/plugin-iot-cognitum",
- "version": "1.0.0-alpha.3",
- "description": "IoT Cognitum Seed device-agent bridge β€” treat every Seed as a Ruflo agent",
+ "version": "1.0.0-alpha.4",
+ "description": "IoT Cognitum Seed device-agent bridge β€” treat every Seed as a Ruflo agent. Get a Seed at https://cognitum.one.",
+ "homepage": "https://cognitum.one",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts b/v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts
index 03f0b7904a..bc430ec2b5 100644
--- a/v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts
+++ b/v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts
@@ -11,6 +11,14 @@ function requireCoordinator(get: CoordinatorGetter): IoTCoordinator {
return c;
}
+function parseVector(raw: string): number[] {
+ const parsed = JSON.parse(raw) as unknown;
+ if (!Array.isArray(parsed) || !parsed.every((n) => typeof n === 'number')) {
+ throw new Error(`--vector must be a JSON array of numbers, got: ${raw}`);
+ }
+ return parsed as number[];
+}
+
export function createCliCommands(
getCoordinator: CoordinatorGetter,
_getContext: ContextGetter,
@@ -151,25 +159,53 @@ export function createCliCommands(
options: [
{ name: 'device-id', short: 'd', description: 'Device identifier', type: 'string', required: true },
{ name: 'k', short: 'k', description: 'Number of nearest neighbours', type: 'number', default: 5 },
+ { name: 'vector', short: 'v', description: 'JSON array of numbers, e.g. "[0.1,0.2,...]"', type: 'string' },
],
handler: async (args) => {
const coordinator = requireCoordinator(getCoordinator);
- // CLI cannot easily pass a vector; use a zero vector as placeholder
- const k = (args['k'] as number) ?? 5;
- const result = await coordinator.queryDeviceVectors(args['device-id'] as string, [], k);
+ const k = Number(args['k'] ?? 5);
+ const raw = args['vector'] as string | undefined;
+ const vector = raw ? parseVector(raw) : [];
+ const result = await coordinator.queryDeviceVectors(args['device-id'] as string, vector, k);
console.log(JSON.stringify(result, null, 2));
},
},
{
name: 'iot ingest',
- description: 'Ingest vectors into device store from stdin (JSON array)',
+ description: 'Ingest vectors into device store. Pass --vector "[..]" or pipe a JSON array on stdin.',
options: [
{ name: 'device-id', short: 'd', description: 'Device identifier', type: 'string', required: true },
+ { name: 'vector', short: 'v', description: 'Single JSON-array vector to ingest', type: 'string' },
+ { name: 'metadata', short: 'm', description: 'JSON metadata object for the vector', type: 'string' },
],
handler: async (args) => {
const coordinator = requireCoordinator(getCoordinator);
- // In a real implementation this would read stdin; stub for now
- const result = await coordinator.ingestDeviceTelemetry(args['device-id'] as string, []);
+ const raw = args['vector'] as string | undefined;
+ const metaRaw = args['metadata'] as string | undefined;
+ let vectors: Array<{ values: number[]; metadata?: Record<string, unknown> }> = [];
+ if (raw) {
+ const v = parseVector(raw);
+ const meta = metaRaw ? (JSON.parse(metaRaw) as Record<string, unknown>) : undefined;
+ vectors = [{ values: v, ...(meta ? { metadata: meta } : {}) }];
+ } else if (!process.stdin.isTTY) {
+ // Stdin path: expect a JSON array of {values, metadata?} or raw number[][]
+ const chunks: Buffer[] = [];
+ for await (const chunk of process.stdin) chunks.push(chunk as Buffer);
+ const text = Buffer.concat(chunks).toString('utf8').trim();
+ if (text) {
+ const parsed = JSON.parse(text) as unknown;
+ if (Array.isArray(parsed)) {
+ vectors = (parsed as unknown[]).map((entry) => {
+ if (Array.isArray(entry)) return { values: entry as number[] };
+ return entry as { values: number[]; metadata?: Record<string, unknown> };
+ });
+ }
+ }
+ }
+ if (vectors.length === 0) {
+ throw new Error('No vectors to ingest. Pass --vector "[..]" or pipe a JSON array on stdin.');
+ }
+ const result = await coordinator.ingestDeviceTelemetry(args['device-id'] as string, vectors);
console.log(`Ingested ${result.ingested} vector(s) for device ${result.deviceId}`);
},
},