neuralos 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "neuralos",
3
+ "version": "2.8.0",
4
+ "description": "neuralOS — the headless AI-native backend for RTerm. Run RTerm-as-a-service (AI agent, SSH/WinRM/Serial/local terminals, fleet orchestration, advanced automation with event-driven triggers + NATS event mesh, scheduled automation, SRE observability, Netdata integration, AWS APerf performance deep-dive, plugin system, governance/audit with AGT policy engine + maker/checker review model) and drive it over a WebSocket JSON-RPC gateway. No desktop UI required. The RTerm desktop app stays RTerm; neuralOS is the standalone backend daemon.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "bin": {
8
+ "neuralos": "bin/gybackend.js",
9
+ "gybackend": "bin/gybackend.js"
10
+ },
11
+ "main": "bin/gybackend.js",
12
+ "files": [
13
+ "bin/",
14
+ "plugins/",
15
+ "README.md",
16
+ "LICENSE.md"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "os": [
22
+ "darwin",
23
+ "linux",
24
+ "win32"
25
+ ],
26
+ "dependencies": {
27
+ "@nats-io/transport-node": "^3.4.0",
28
+ "better-sqlite3": "^12.11.1",
29
+ "cpu-features": "^0.0.10",
30
+ "node-pty": "^1.2.0-beta.3",
31
+ "ssh2": "^1.17.0",
32
+ "tree-sitter-bash": "^0.25.1",
33
+ "web-tree-sitter": "^0.26.3"
34
+ },
35
+ "optionalDependencies": {
36
+ "serialport": "^13.0.0"
37
+ },
38
+ "keywords": [
39
+ "neuralos",
40
+ "rterm",
41
+ "terminal",
42
+ "ssh",
43
+ "winrm",
44
+ "serial",
45
+ "ai-agent",
46
+ "llm",
47
+ "devops",
48
+ "fleet",
49
+ "automation",
50
+ "event-driven",
51
+ "triggers",
52
+ "nats",
53
+ "headless",
54
+ "backend",
55
+ "websocket",
56
+ "rpc",
57
+ "rundeck",
58
+ "ansible",
59
+ "sre",
60
+ "observability",
61
+ "netdata",
62
+ "aperf",
63
+ "monitoring",
64
+ "governance",
65
+ "audit",
66
+ "maker-checker"
67
+ ],
68
+ "author": "Hyperspace Technologies <rterm@hyperspace.ng>",
69
+ "homepage": "https://github.com/DrOlu/RTerm",
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/DrOlu/RTerm.git"
73
+ },
74
+ "bugs": "https://github.com/DrOlu/RTerm/issues"
75
+ }
@@ -0,0 +1,9 @@
1
+ // fraudops plugin type declarations
2
+ export function register(ctx: any): void
3
+ export function buildPipelineHealthCommand(): string
4
+ export function buildNatsStatusCommand(): string
5
+ export function buildKafkaLagCommand(): string
6
+ export function parsePipelineHealth(output: string): { status: string; jobs: any[]; running: number; failed: number }
7
+ export function buildStrCase(txnId: string, decision: string, indicators?: string[], assignedTo?: string): any
8
+ export function buildDecisionSummary(decisions: Array<{ decision: string }> | null | undefined): { total: number; blocks: number; reviews: number; approves: number; blockRate: number; reviewRate: number; approveRate: number }
9
+ export default any
@@ -0,0 +1,185 @@
1
+ /**
2
+ * fraudops plugin — FraudOps for RTerm.
3
+ *
4
+ * Operational layer for the fraud detection pipeline. Monitors pipeline health
5
+ * (Flink, NATS, Kafka), manages STR workflow, tracks fraud incidents, and
6
+ * provides the unified fraud operations dashboard. Bridges Kafka/NATS metrics
7
+ * into RTerm's SRE pillar.
8
+ */
9
+
10
+ // --- Pure: build pipeline health check command ---
11
+ export function buildPipelineHealthCommand() {
12
+ return 'curl -s http://localhost:8081/jobs 2>/dev/null | head -20 || echo "flink not reachable"'
13
+ }
14
+
15
+ // --- Pure: build NATS JetStream status command ---
16
+ export function buildNatsStatusCommand() {
17
+ return 'curl -s http://localhost:8222/streaming/channelsz 2>/dev/null | head -30 || echo "nats not reachable"'
18
+ }
19
+
20
+ // --- Pure: build Kafka consumer lag command ---
21
+ export function buildKafkaLagCommand() {
22
+ return 'kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group fraud-pipeline 2>/dev/null | head -20 || echo "kafka not reachable"'
23
+ }
24
+
25
+ // --- Pure: parse pipeline health output ---
26
+ export function parsePipelineHealth(output) {
27
+ const health = { status: 'unknown', jobs: [], running: 0, failed: 0 }
28
+ try {
29
+ const parsed = JSON.parse(output)
30
+ if (parsed.jobs && Array.isArray(parsed.jobs)) {
31
+ health.jobs = parsed.jobs.map((j) => ({ id: j.jid, name: j.name, status: j.state }))
32
+ health.running = parsed.jobs.filter((j) => j.state === 'RUNNING').length
33
+ health.failed = parsed.jobs.filter((j) => j.state === 'FAILED').length
34
+ health.status = health.failed > 0 ? 'degraded' : health.running > 0 ? 'healthy' : 'unknown'
35
+ }
36
+ } catch { /* not JSON */ }
37
+ return health
38
+ }
39
+
40
+ // --- Pure: build an STR case record ---
41
+ export function buildStrCase(txnId, decision, indicators, assignedTo) {
42
+ return {
43
+ id: `str-${txnId}-${Date.now().toString(36)}`,
44
+ txnId,
45
+ decision, // BLOCK | REVIEW
46
+ indicators: indicators ?? [],
47
+ assignedTo: assignedTo ?? 'unassigned',
48
+ status: 'pending', // pending | assigned | reviewed | filed | expired
49
+ deadline: Date.now() + 7 * 24 * 60 * 60 * 1000, // 7 days (CBN requirement)
50
+ createdAt: Date.now(),
51
+ }
52
+ }
53
+
54
+ // --- Pure: build a decision summary ---
55
+ export function buildDecisionSummary(decisions) {
56
+ const list = Array.isArray(decisions) ? decisions : []
57
+ const total = list.length
58
+ const blocks = list.filter((d) => d.decision === 'BLOCK').length
59
+ const reviews = list.filter((d) => d.decision === 'REVIEW').length
60
+ const approves = list.filter((d) => d.decision === 'APPROVE').length
61
+ return {
62
+ total,
63
+ blocks,
64
+ reviews,
65
+ approves,
66
+ blockRate: total > 0 ? Math.round((blocks / total) * 100) : 0,
67
+ reviewRate: total > 0 ? Math.round((reviews / total) * 100) : 0,
68
+ approveRate: total > 0 ? Math.round((approves / total) * 100) : 0,
69
+ }
70
+ }
71
+
72
+ // --- Plugin entry ---
73
+ export function register(ctx) {
74
+ const { registerTool, registerTrigger, registerPanel, exec, readLedger, log } = ctx
75
+ const strCases = []
76
+
77
+ // Tool: fraudops_pipeline_status — check the health of the fraud pipeline
78
+ registerTool({
79
+ name: 'fraudops_pipeline_status',
80
+ description: 'Check the health of the fraud detection pipeline (Flink jobs, NATS JetStream, Kafka consumer lag). Returns status for each component.',
81
+ params: {},
82
+ handler: async () => {
83
+ const flinkOut = await exec(buildPipelineHealthCommand(), {})
84
+ const natsOut = await exec(buildNatsStatusCommand(), {})
85
+ const kafkaOut = await exec(buildKafkaLagCommand(), {})
86
+ const flink = parsePipelineHealth(flinkOut)
87
+ log(`[fraudops] pipeline status: flink=${flink.status} nats=${natsOut.slice(0, 50)} kafka=${kafkaOut.slice(0, 50)}`)
88
+ return { flink, nats: natsOut.slice(0, 500), kafka: kafkaOut.slice(0, 500) }
89
+ },
90
+ })
91
+
92
+ // Tool: fraudops_str_assign — assign an STR case to an analyst
93
+ registerTool({
94
+ name: 'fraudops_str_assign',
95
+ description: 'Assign an STR (Suspicious Transaction Report) case to an analyst. Creates the case with a 7-day CBN deadline.',
96
+ params: {
97
+ txnId: { type: 'string', description: 'Transaction ID' },
98
+ decision: { type: 'string', description: 'BLOCK or REVIEW' },
99
+ indicators: { type: 'array', description: 'Fraud indicators (e.g., ["high_velocity", "new_device"])' },
100
+ assignedTo: { type: 'string', description: 'Analyst username' },
101
+ },
102
+ handler: async (params) => {
103
+ const { txnId, decision, indicators, assignedTo } = params ?? {}
104
+ if (!txnId || !decision) return { error: 'txnId and decision are required' }
105
+ const strCase = buildStrCase(txnId, decision, indicators, assignedTo)
106
+ strCase.status = 'assigned'
107
+ strCases.push(strCase)
108
+ log(`[fraudops] STR case ${strCase.id} assigned to ${assignedTo}`)
109
+ return strCase
110
+ },
111
+ })
112
+
113
+ // Tool: fraudops_str_status — get STR case status
114
+ registerTool({
115
+ name: 'fraudops_str_status',
116
+ description: 'Get the status of STR cases. Filter by status, analyst, or overdue.',
117
+ params: {
118
+ status: { type: 'string', description: 'Filter by status: pending, assigned, reviewed, filed, expired' },
119
+ assignedTo: { type: 'string', description: 'Filter by analyst' },
120
+ overdue: { type: 'boolean', description: 'Only show overdue cases (past 7-day deadline)' },
121
+ },
122
+ handler: async (params) => {
123
+ let filtered = [...strCases]
124
+ if (params?.status) filtered = filtered.filter((c) => c.status === params.status)
125
+ if (params?.assignedTo) filtered = filtered.filter((c) => c.assignedTo === params.assignedTo)
126
+ if (params?.overdue) filtered = filtered.filter((c) => Date.now() > c.deadline)
127
+ return { total: filtered.length, cases: filtered }
128
+ },
129
+ })
130
+
131
+ // Tool: fraudops_decision_summary — summarize fraud decisions
132
+ registerTool({
133
+ name: 'fraudops_decision_summary',
134
+ description: 'Summarize fraud decisions (BLOCK/REVIEW/APPROVE counts and rates) from the decision stream.',
135
+ params: {
136
+ decisions: { type: 'array', description: 'Array of decision objects with { decision: "BLOCK"|"REVIEW"|"APPROVE" }' },
137
+ },
138
+ handler: async (params) => {
139
+ const decisions = params?.decisions ?? []
140
+ const summary = buildDecisionSummary(decisions)
141
+ log(`[fraudops] decision summary: ${summary.total} total, ${summary.blockRate}% block, ${summary.reviewRate}% review`)
142
+ return summary
143
+ },
144
+ })
145
+
146
+ // Trigger: fraudops_str_overdue — fires when an STR case is overdue
147
+ registerTrigger({
148
+ name: 'fraudops_str_overdue',
149
+ description: 'Fires when an STR case exceeds the 7-day CBN deadline. Use for escalation to senior analyst.',
150
+ match: (event) => {
151
+ if (event?.source !== 'fraudops') return false
152
+ return event.labels?.status === 'expired' || event.labels?.overdue === true
153
+ },
154
+ action: 'propose-change',
155
+ })
156
+
157
+ // Trigger: fraudops_pipeline_down — fires when a pipeline component is down
158
+ registerTrigger({
159
+ name: 'fraudops_pipeline_down',
160
+ description: 'Fires when a fraud pipeline component (Flink, NATS, Kafka) is detected as down. Use for immediate incident response.',
161
+ match: (event) => {
162
+ if (event?.source !== 'fraudops') return false
163
+ return event.labels?.status === 'down' || event.labels?.failed === true
164
+ },
165
+ action: 'run-playbook',
166
+ })
167
+
168
+ // Panel: fraudops-dashboard — unified fraud operations dashboard
169
+ registerPanel({
170
+ name: 'fraudops-dashboard',
171
+ title: 'Fraud Operations Dashboard',
172
+ render: (data) => {
173
+ const cases = Array.isArray(data?.cases) ? data.cases : strCases
174
+ const summary = data?.summary ?? { total: 0, blocks: 0, reviews: 0, approves: 0, blockRate: 0, reviewRate: 0, approveRate: 0 }
175
+ const rows = cases.map((c) =>
176
+ `<tr><td>${c.id}</td><td>${c.txnId}</td><td>${c.decision}</td><td>${c.assignedTo}</td><td>${c.status}</td><td>${new Date(c.deadline).toLocaleDateString()}</td></tr>`
177
+ ).join('')
178
+ return `<div class="fraudops-dashboard"><h3>Fraud Operations Dashboard</h3><p>Decisions: ${summary.total} | Block: ${summary.blockRate}% | Review: ${summary.reviewRate}% | Approve: ${summary.approveRate}%</p><p>STR Cases: ${cases.length} | Overdue: ${cases.filter((c) => Date.now() > c.deadline).length}</p><table><thead><tr><th>ID</th><th>Txn ID</th><th>Decision</th><th>Assigned</th><th>Status</th><th>Deadline</th></tr></thead><tbody>${rows}</tbody></table></div>`
179
+ },
180
+ })
181
+
182
+ log('[fraudops] registered: 4 tools, 2 triggers, 1 panel')
183
+ }
184
+
185
+ export default { register, buildPipelineHealthCommand, buildNatsStatusCommand, buildKafkaLagCommand, parsePipelineHealth, buildStrCase, buildDecisionSummary }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "fraudops",
3
+ "version": "1.0.0",
4
+ "description": "FraudOps for RTerm — operational layer for the fraud detection pipeline. Monitors pipeline health (Flink, NATS, Kafka), manages STR workflow, tracks fraud incidents, and provides the unified fraud operations dashboard. Bridges Kafka/NATS metrics into RTerm's SRE pillar.",
5
+ "entry": "index.mjs",
6
+ "tools": ["fraudops_pipeline_status", "fraudops_str_assign", "fraudops_str_status", "fraudops_decision_summary"],
7
+ "triggers": ["fraudops_str_overdue", "fraudops_pipeline_down"],
8
+ "panels": ["fraudops-dashboard"],
9
+ "permissions": ["exec", "readLedger:metrics", "readLedger:incidents"]
10
+ }
@@ -0,0 +1,10 @@
1
+ // iam-connector plugin type declarations
2
+ export function register(ctx: any): void
3
+ export function buildUserInfoCommand(username: string, os?: string): string
4
+ export function buildUserGroupsCommand(username: string, os?: string): string
5
+ export function buildDisableUserCommand(username: string, os?: string): string
6
+ export function buildAccessReviewCommand(os?: string): string
7
+ export function parseUserInfo(output: string | null | undefined, os?: string | null | undefined): { username: string; groups: string[]; enabled: boolean; locked: boolean }
8
+ export function parseAccessReview(output: string | null | undefined, os?: string | null | undefined): Array<{ username: string; groups?: string[]; enabled?: boolean }>
9
+ export function isPrivileged(userInfo: { groups: string[] } | null | undefined, privilegedGroups?: string[] | null | undefined): boolean
10
+ export default any
@@ -0,0 +1,229 @@
1
+ /**
2
+ * iam-connector plugin — IAM integration for RTerm.
3
+ *
4
+ * User/group management, role assignment, access review, and audit trail for
5
+ * Active Directory, local users, and service accounts. Covers user lifecycle
6
+ * (create, disable, offboard), group membership, and access compliance.
7
+ * Commands are built for both Linux (id, groups, usermod) and Windows
8
+ * (Get-LocalUser, Get-LocalGroupMember, Disable-LocalUser).
9
+ */
10
+
11
+ // --- Pure: build user info command ---
12
+ export function buildUserInfoCommand(username, os = 'linux') {
13
+ const o = String(os).toLowerCase()
14
+ if (o === 'windows' || o === 'win32') {
15
+ return `powershell -Command "Get-LocalUser -Name '${username}' | Select-Object Name,Enabled,LastLogon,PasswordExpires,LockedOut,Description | Format-List"`
16
+ }
17
+ return `id '${username}' 2>/dev/null && groups '${username}' 2>/dev/null && passwd -S '${username}' 2>/dev/null`
18
+ }
19
+
20
+ // --- Pure: build user groups command ---
21
+ export function buildUserGroupsCommand(username, os = 'linux') {
22
+ const o = String(os).toLowerCase()
23
+ if (o === 'windows' || o === 'win32') {
24
+ return `powershell -Command "Get-LocalGroupMember -Group Administrators | Where-Object {$_.Name -like '*${username}*'} | Select-Object Name; Get-LocalUser -Name '${username}' | Select-Object Name,Enabled"`
25
+ }
26
+ return `groups '${username}' 2>/dev/null && id -Gn '${username}' 2>/dev/null`
27
+ }
28
+
29
+ // --- Pure: build disable user command ---
30
+ export function buildDisableUserCommand(username, os = 'linux') {
31
+ const o = String(os).toLowerCase()
32
+ if (o === 'windows' || o === 'win32') {
33
+ return `powershell -Command "Disable-LocalUser -Name '${username}'; Get-LocalUser -Name '${username}' | Select-Object Name,Enabled"`
34
+ }
35
+ return `usermod -L '${username}' 2>/dev/null && echo "user ${username} disabled" || echo "failed to disable ${username}"`
36
+ }
37
+
38
+ // --- Pure: build access review command (list all users + groups) ---
39
+ export function buildAccessReviewCommand(os = 'linux') {
40
+ const o = String(os).toLowerCase()
41
+ if (o === 'windows' || o === 'win32') {
42
+ return 'powershell -Command "Get-LocalUser | Select-Object Name,Enabled,LastLogon | Format-Table -AutoSize; Write-Host \'---\'; Get-LocalGroup | Select-Object Name | Format-Table -AutoSize"'
43
+ }
44
+ return 'cut -d: -f1 /etc/passwd | while read u; do echo "$u: $(id -Gn $u 2>/dev/null)"; done 2>/dev/null | head -50'
45
+ }
46
+
47
+ // --- Pure: parse user info output ---
48
+ export function parseUserInfo(output, os = 'linux') {
49
+ const o = String(os ?? 'linux').toLowerCase()
50
+ const text = String(output ?? '')
51
+ const info = { username: '', groups: [], enabled: true, locked: false }
52
+
53
+ if (o === 'windows' || o === 'win32') {
54
+ const nameMatch = text.match(/Name\s+:\s+(\S+)/)
55
+ const enabledMatch = text.match(/Enabled\s+:\s+(True|False)/i)
56
+ const lockedMatch = text.match(/LockedOut\s+:\s+(True|False)/i)
57
+ if (nameMatch) info.username = nameMatch[1]
58
+ if (enabledMatch) info.enabled = enabledMatch[1].toLowerCase() === 'true'
59
+ if (lockedMatch) info.locked = lockedMatch[1].toLowerCase() === 'true'
60
+ return info
61
+ }
62
+
63
+ // Linux: parse id + groups + passwd -S output
64
+ const lines = text.split(/\r?\n/)
65
+ for (const line of lines) {
66
+ const l = line.trim()
67
+ const idMatch = l.match(/uid=\d+\((\S+)\)/)
68
+ if (idMatch) info.username = idMatch[1]
69
+ const groupsMatch = l.match(/groups=(.+)/)
70
+ if (groupsMatch) {
71
+ // groups=1000(john),27(sudo) — split by comma, then extract names from NNN(name) format
72
+ info.groups = groupsMatch[1]
73
+ .split(',')
74
+ .map((g) => g.replace(/\d+\(([^)]+)\)/, '$1').trim())
75
+ .filter(Boolean)
76
+ }
77
+ if (l.includes(' L ')) info.locked = true
78
+ }
79
+ return info
80
+ }
81
+
82
+ // --- Pure: parse access review output into a user list ---
83
+ export function parseAccessReview(output, os = 'linux') {
84
+ const o = String(os ?? 'linux').toLowerCase()
85
+ const text = String(output ?? '')
86
+ const users = []
87
+
88
+ if (o === 'windows' || o === 'win32') {
89
+ const lines = text.split(/\r?\n/)
90
+ for (const line of lines) {
91
+ const l = line.trim()
92
+ const match = l.match(/^(\S+)\s+(True|False)\s+/)
93
+ if (match) {
94
+ users.push({ username: match[1], enabled: match[2].toLowerCase() === 'true' })
95
+ }
96
+ }
97
+ return users
98
+ }
99
+
100
+ // Linux: parse "user: group1 group2" lines
101
+ const lines = text.split(/\r?\n/)
102
+ for (const line of lines) {
103
+ const l = line.trim()
104
+ const match = l.match(/^(\S+):\s*(.*)/)
105
+ if (match) {
106
+ users.push({ username: match[1], groups: match[2].split(/\s+/).filter(Boolean) })
107
+ }
108
+ }
109
+ return users
110
+ }
111
+
112
+ // --- Pure: check if a user has privileged access ---
113
+ export function isPrivileged(userInfo, privilegedGroups = ['sudo', 'wheel', 'admin', 'root', 'Administrators']) {
114
+ const groups = Array.isArray(userInfo?.groups) ? userInfo.groups : []
115
+ const privs = Array.isArray(privilegedGroups) ? privilegedGroups : []
116
+ return groups.some((g) => privs.some((pg) => String(g).toLowerCase().includes(String(pg).toLowerCase())))
117
+ }
118
+
119
+ // --- Plugin entry ---
120
+ export function register(ctx) {
121
+ const { registerTool, registerTrigger, registerPanel, exec, readLedger, log } = ctx
122
+
123
+ // Tool: iam_user_info — get user info
124
+ registerTool({
125
+ name: 'iam_user_info',
126
+ description: 'Get user information (username, groups, enabled status, locked status) for a user on a host.',
127
+ params: {
128
+ username: { type: 'string', description: 'Username to query' },
129
+ host: { type: 'string', description: 'Host to query' },
130
+ os: { type: 'string', description: 'OS type: linux, windows' },
131
+ },
132
+ handler: async (params) => {
133
+ const { username, host, os = 'linux' } = params ?? {}
134
+ if (!username || !host) return { error: 'username and host are required' }
135
+ const cmd = buildUserInfoCommand(username, os)
136
+ log(`[iam-connector] querying user ${username} on ${host}`)
137
+ const output = await exec(cmd, { host })
138
+ const info = parseUserInfo(output, os)
139
+ return { username, host, os, ...info, privileged: isPrivileged(info) }
140
+ },
141
+ })
142
+
143
+ // Tool: iam_user_groups — get user group memberships
144
+ registerTool({
145
+ name: 'iam_user_groups',
146
+ description: 'Get group memberships for a user on a host.',
147
+ params: {
148
+ username: { type: 'string', description: 'Username to query' },
149
+ host: { type: 'string', description: 'Host to query' },
150
+ os: { type: 'string', description: 'OS type' },
151
+ },
152
+ handler: async (params) => {
153
+ const { username, host, os = 'linux' } = params ?? {}
154
+ if (!username || !host) return { error: 'username and host are required' }
155
+ const cmd = buildUserGroupsCommand(username, os)
156
+ const output = await exec(cmd, { host })
157
+ const info = parseUserInfo(output, os)
158
+ return { username, host, groups: info.groups, privileged: isPrivileged(info) }
159
+ },
160
+ })
161
+
162
+ // Tool: iam_disable_user — disable a user account (requires approval)
163
+ registerTool({
164
+ name: 'iam_disable_user',
165
+ description: 'Disable a user account on a host. This is a destructive operation — requires approval. Returns the result.',
166
+ params: {
167
+ username: { type: 'string', description: 'Username to disable' },
168
+ host: { type: 'string', description: 'Host to disable on' },
169
+ os: { type: 'string', description: 'OS type' },
170
+ },
171
+ handler: async (params) => {
172
+ const { username, host, os = 'linux' } = params ?? {}
173
+ if (!username || !host) return { error: 'username and host are required' }
174
+ const cmd = buildDisableUserCommand(username, os)
175
+ log(`[iam-connector] disabling user ${username} on ${host}`)
176
+ const output = await exec(cmd, { host })
177
+ const info = parseUserInfo(output, os)
178
+ return { username, host, disabled: !info.enabled, output: output.slice(0, 500) }
179
+ },
180
+ })
181
+
182
+ // Tool: iam_access_review — review all user access on a host
183
+ registerTool({
184
+ name: 'iam_access_review',
185
+ description: 'Review all user accounts and group memberships on a host. Identifies privileged users.',
186
+ params: {
187
+ host: { type: 'string', description: 'Host to review' },
188
+ os: { type: 'string', description: 'OS type' },
189
+ },
190
+ handler: async (params) => {
191
+ const { host, os = 'linux' } = params ?? {}
192
+ if (!host) return { error: 'host is required' }
193
+ const cmd = buildAccessReviewCommand(os)
194
+ const output = await exec(cmd, { host })
195
+ const users = parseAccessReview(output, os)
196
+ const privilegedUsers = users.filter((u) => isPrivileged({ groups: u.groups ?? [] }))
197
+ return { host, totalUsers: users.length, privilegedUsers: privilegedUsers.length, users: users.slice(0, 50), privilegedUsers: privilegedUsers.map((u) => u.username) }
198
+ },
199
+ })
200
+
201
+ // Trigger: iam_privileged_change — fires when a privileged user's access changes
202
+ registerTrigger({
203
+ name: 'iam_privileged_change',
204
+ description: 'Fires when a privileged user account is modified (disabled, group change). Use for compliance monitoring.',
205
+ match: (event) => {
206
+ if (event?.source !== 'iam-connector') return false
207
+ return event.labels?.privileged === true
208
+ },
209
+ action: 'propose-change',
210
+ })
211
+
212
+ // Panel: iam-access-dashboard — IAM access dashboard
213
+ registerPanel({
214
+ name: 'iam-access-dashboard',
215
+ title: 'IAM Access Dashboard',
216
+ render: (data) => {
217
+ const users = Array.isArray(data) ? data : []
218
+ const privileged = users.filter((u) => isPrivileged({ groups: u.groups ?? [] }))
219
+ const rows = users.map((u) =>
220
+ `<tr><td>${u.username}</td><td>${(u.groups ?? []).join(', ')}</td><td>${u.enabled !== false ? '✅' : '❌'}</td><td>${isPrivileged({ groups: u.groups ?? [] }) ? '🔐' : ''}</td></tr>`
221
+ ).join('')
222
+ return `<div class="iam-access-dashboard"><h3>IAM Access Dashboard</h3><p>Total users: ${users.length} | Privileged: ${privileged.length}</p><table><thead><tr><th>User</th><th>Groups</th><th>Enabled</th><th>Privileged</th></tr></thead><tbody>${rows}</tbody></table></div>`
223
+ },
224
+ })
225
+
226
+ log('[iam-connector] registered: 4 tools, 1 trigger, 1 panel')
227
+ }
228
+
229
+ export default { register, buildUserInfoCommand, buildUserGroupsCommand, buildDisableUserCommand, buildAccessReviewCommand, parseUserInfo, parseAccessReview, isPrivileged }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "iam-connector",
3
+ "version": "1.0.0",
4
+ "description": "IAM integration for RTerm — user/group management, role assignment, access review, and audit trail for Active Directory, local users, and service accounts. Covers user lifecycle (create, disable, offboard), group membership, and access compliance.",
5
+ "entry": "index.mjs",
6
+ "tools": ["iam_user_info", "iam_user_groups", "iam_disable_user", "iam_access_review"],
7
+ "triggers": ["iam_privileged_change"],
8
+ "panels": ["iam-access-dashboard"],
9
+ "permissions": ["exec", "readLedger:incidents"]
10
+ }