@blackbelt-technology/pi-dashboard-chat-gateway-plugin 0.8.0 → 0.10.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.
@@ -11,8 +11,21 @@
11
11
  * `plugin_config_write` because only that lane can await the platform before
12
12
  * reporting success — see `shared/types.ts`.
13
13
  *
14
- * See change: add-chat-gateway-team-controls.
14
+ * Presentation runs on the shared settings kit (status pills, items, facts,
15
+ * table, notices): raw codes (`problem`, `configError`, a refusal `reason`)
16
+ * never render — a sentence shows and the raw text is only copyable through
17
+ * "Copy details".
18
+ *
19
+ * See change: add-chat-gateway-team-controls, retro-ux-plugin-settings-wave-2.
15
20
  */
21
+ import {
22
+ SettingsFacts,
23
+ SettingsGroup,
24
+ SettingsItem,
25
+ SettingsNotice,
26
+ SettingsStatusPill,
27
+ SettingsTable,
28
+ } from "@blackbelt-technology/dashboard-plugin-runtime";
16
29
  import { usePluginConfig, usePluginMessage, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime/context";
17
30
  import type React from "react";
18
31
  import { useCallback, useEffect, useState } from "react";
@@ -29,6 +42,18 @@ function formatWhen(at: number): string {
29
42
  return new Date(at).toLocaleString();
30
43
  }
31
44
 
45
+ const MIRROR_LABEL: Record<TeamSurfaceView["bindings"][number]["mirrorLevel"], string> = {
46
+ "names-only": "Mirror: names only",
47
+ "names-and-diffs": "Mirror: names and diffs",
48
+ "full-transcript": "Mirror: full transcript",
49
+ };
50
+
51
+ const SMALL_BUTTON =
52
+ "focus-ring inline-flex min-h-[32px] items-center gap-1 rounded-md border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-2 text-[12px] font-semibold text-[var(--text-primary)] hover:bg-[var(--bg-hover)]";
53
+
54
+ const SUBHEAD = "text-xs font-semibold text-[var(--text-primary)]";
55
+ const MUTED = "text-[12px] text-[var(--text-secondary)]";
56
+
32
57
  /**
33
58
  * The delegation disclosure for one role mapping.
34
59
  *
@@ -41,7 +66,7 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
41
66
  return (
42
67
  <span
43
68
  data-testid={`delegation-unavailable-${role.roleId}`}
44
- className="text-[var(--danger-text,var(--text-secondary))]"
69
+ className="text-[var(--severity-error-fg)]"
45
70
  >
46
71
  Cannot list who can assign this — missing permission: {role.assigners.missingPermission}
47
72
  </span>
@@ -49,7 +74,7 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
49
74
  }
50
75
  if (role.assigners.members.length === 0) {
51
76
  return (
52
- <span data-testid={`delegation-none-${role.roleId}`} className="text-[var(--text-tertiary)]">
77
+ <span data-testid={`delegation-none-${role.roleId}`} className="text-[var(--text-secondary)]">
53
78
  Nobody can assign this role.
54
79
  </span>
55
80
  );
@@ -63,52 +88,49 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
63
88
  }
64
89
 
65
90
  function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }): React.ReactElement {
91
+ const id = binding.workspaceId;
66
92
  return (
67
- <div
68
- data-testid={`team-binding-${binding.workspaceId}`}
69
- className="rounded border border-[var(--border-secondary)] p-2 space-y-1"
93
+ <SettingsItem
94
+ testId={`team-binding-${id}`}
95
+ title={<span data-testid={`team-binding-name-${id}`}>{binding.workspaceName ?? "(workspace missing)"}</span>}
96
+ subtitle={
97
+ binding.channelId ? (
98
+ <>
99
+ channel <code>{binding.channelId}</code>
100
+ </>
101
+ ) : (
102
+ "No channel provisioned."
103
+ )
104
+ }
105
+ status={
106
+ <>
107
+ <SettingsStatusPill tone="neutral" icon={null}>
108
+ Level: {binding.ceiling}
109
+ </SettingsStatusPill>
110
+ <SettingsStatusPill tone="neutral" icon={null}>
111
+ {MIRROR_LABEL[binding.mirrorLevel]}
112
+ </SettingsStatusPill>
113
+ </>
114
+ }
70
115
  >
71
- <div className="flex items-baseline justify-between gap-2">
72
- <span className="text-xs font-medium" data-testid={`team-binding-name-${binding.workspaceId}`}>
73
- {binding.workspaceName ?? "(workspace missing)"}
74
- </span>
75
- <span className="text-[11px] text-[var(--text-tertiary)]">
76
- ceiling {binding.ceiling} · mirror {binding.mirrorLevel}
77
- </span>
78
- </div>
79
-
80
116
  {!binding.bound && (
81
- <p
82
- data-testid={`team-binding-unbound-${binding.workspaceId}`}
83
- className="text-[11px] text-[var(--danger-text,var(--text-secondary))]"
84
- >
117
+ <SettingsNotice tone="warning" testId={`team-binding-unbound-${id}`}>
85
118
  This workspace no longer exists. The binding is retained but inert; its channel is kept.
86
- </p>
119
+ </SettingsNotice>
87
120
  )}
88
121
 
89
122
  {binding.problem && (
90
- <p
91
- data-testid={`team-binding-problem-${binding.workspaceId}`}
92
- className="text-[11px] text-[var(--danger-text,var(--text-secondary))]"
93
- >
94
- Provisioning problem: {binding.problem}
95
- </p>
96
- )}
97
-
98
- {binding.channelId ? (
99
- <p className="text-[11px] text-[var(--text-tertiary)]">
100
- channel <code>{binding.channelId}</code>
101
- </p>
102
- ) : (
103
- <p className="text-[11px] text-[var(--text-tertiary)]">No channel provisioned.</p>
123
+ <SettingsNotice tone="error" testId={`team-binding-problem-${id}`} details={binding.problem}>
124
+ This binding could not be set up, so it stays inactive.
125
+ </SettingsNotice>
104
126
  )}
105
127
 
106
128
  <div>
107
- <span className="block text-[11px] text-[var(--text-secondary)]">Principals</span>
129
+ <p className={SUBHEAD}>Principals</p>
108
130
  {binding.principals.length === 0 ? (
109
- <span className="text-[11px] text-[var(--text-tertiary)]">None mapped.</span>
131
+ <p className={MUTED}>None mapped.</p>
110
132
  ) : (
111
- <ul data-testid={`team-principals-${binding.workspaceId}`} className="text-[11px]">
133
+ <ul data-testid={`team-principals-${id}`} className="text-[12px]">
112
134
  {binding.principals.map((p) => (
113
135
  <li key={p.id}>
114
136
  <code>{p.id}</code> — {p.tier}
@@ -119,11 +141,11 @@ function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }):
119
141
  </div>
120
142
 
121
143
  <div>
122
- <span className="block text-[11px] text-[var(--text-secondary)]">Roles</span>
144
+ <p className={SUBHEAD}>Roles</p>
123
145
  {binding.roles.length === 0 ? (
124
- <span className="text-[11px] text-[var(--text-tertiary)]">None mapped.</span>
146
+ <p className={MUTED}>None mapped.</p>
125
147
  ) : (
126
- <ul data-testid={`team-roles-${binding.workspaceId}`} className="text-[11px] space-y-0.5">
148
+ <ul data-testid={`team-roles-${id}`} className="space-y-0.5 text-[12px]">
127
149
  {binding.roles.map((role) => (
128
150
  <li key={role.roleId}>
129
151
  <code>{role.roleId}</code> — {role.tier}: <Delegation role={role} />
@@ -134,24 +156,21 @@ function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }):
134
156
  </div>
135
157
 
136
158
  <div>
137
- <span className="block text-[11px] text-[var(--text-secondary)]">Folders</span>
138
- <ul data-testid={`team-folders-${binding.workspaceId}`} className="text-[11px]">
159
+ <p className={SUBHEAD}>Folders</p>
160
+ <ul data-testid={`team-folders-${id}`} className="text-[12px]">
139
161
  {binding.folders.map((f) => (
140
- <li key={f.path} data-inert={f.inert ? "true" : "false"}>
162
+ <li key={f.path} data-inert={f.inert ? "true" : "false"} className="flex flex-wrap items-center gap-1">
141
163
  <code>{f.path}</code>
142
164
  {f.inert && (
143
- <span
144
- data-testid={`team-folder-inert-${binding.workspaceId}-${f.path}`}
145
- className="ml-1 text-[var(--danger-text,var(--text-secondary))]"
146
- >
147
- inert — outside allowedRoots
148
- </span>
165
+ <SettingsStatusPill tone="warning" testId={`team-folder-inert-${id}-${f.path}`}>
166
+ Not used · outside the allowed folders
167
+ </SettingsStatusPill>
149
168
  )}
150
169
  </li>
151
170
  ))}
152
171
  </ul>
153
172
  </div>
154
- </div>
173
+ </SettingsItem>
155
174
  );
156
175
  }
157
176
 
@@ -159,7 +178,8 @@ export function TeamControlsPanel(): React.ReactElement {
159
178
  const config = usePluginConfig<ChatGatewayConfig>();
160
179
  const send = usePluginSend();
161
180
  const [surface, setSurface] = useState<TeamSurfaceView | null>(null);
162
- const [writeNotice, setWriteNotice] = useState<string | null>(null);
181
+ // `reason` is the raw refusal code: kept only for "Copy details".
182
+ const [writeNotice, setWriteNotice] = useState<{ ok: true } | { ok: false; reason: string } | null>(null);
163
183
 
164
184
  // The surface answer and the write result both arrive on their own types.
165
185
  usePluginMessage<{ surface?: TeamSurfaceView }>(TEAM_SURFACE_MESSAGE, (msg) => {
@@ -169,8 +189,8 @@ export function TeamControlsPanel(): React.ReactElement {
169
189
  TEAM_CONFIG_MESSAGE,
170
190
  (msg) => {
171
191
  if (msg?.surface) setSurface(msg.surface);
172
- if (msg?.ok === true) setWriteNotice("Saved.");
173
- else if (msg?.reason) setWriteNotice(`Refused: ${msg.reason}`);
192
+ if (msg?.ok === true) setWriteNotice({ ok: true });
193
+ else if (msg?.reason) setWriteNotice({ ok: false, reason: msg.reason });
174
194
  },
175
195
  );
176
196
 
@@ -190,98 +210,113 @@ export function TeamControlsPanel(): React.ReactElement {
190
210
 
191
211
  if (!surface) {
192
212
  return (
193
- <div data-testid="team-controls-panel" className="text-[11px] text-[var(--text-tertiary)]">
213
+ <div data-testid="team-controls-panel" className="text-xs text-[var(--text-secondary)]">
194
214
  Loading team controls…
195
215
  </div>
196
216
  );
197
217
  }
198
218
 
199
219
  return (
200
- <div data-testid="team-controls-panel" className="space-y-2">
201
- <div className="flex items-center gap-2">
202
- <span className="text-xs font-medium">Team controls</span>
203
- <span
204
- data-testid="team-disarm-state"
205
- className={
206
- surface.disarmed
207
- ? "text-[11px] text-[var(--danger-text,var(--text-secondary))]"
208
- : "text-[11px] text-[var(--text-tertiary)]"
209
- }
210
- >
211
- {surface.disarmed ? "DISARMED — action requests are refused" : "armed"}
212
- </span>
213
- {surface.disarmed && (
214
- <button
215
- type="button"
216
- data-testid="team-rearm"
217
- onClick={rearm}
218
- className="px-2 py-0.5 rounded border border-[var(--border-secondary)] text-[11px] hover:bg-[var(--bg-secondary)]"
219
- >
220
- Re-arm
221
- </button>
222
- )}
223
- {writeNotice && (
224
- <span data-testid="team-write-notice" className="text-[11px] text-[var(--text-tertiary)]">
225
- {writeNotice}
226
- </span>
227
- )}
228
- </div>
220
+ <div data-testid="team-controls-panel">
221
+ <SettingsGroup title="Team controls" testId="team-controls-group">
222
+ <div className="flex flex-wrap items-center gap-2">
223
+ {surface.disarmed ? (
224
+ <SettingsStatusPill tone="error" status="disarmed" testId="team-disarm-state">
225
+ Disarmed · action requests are refused
226
+ </SettingsStatusPill>
227
+ ) : (
228
+ <SettingsStatusPill tone="success" status="armed" testId="team-disarm-state">
229
+ Armed
230
+ </SettingsStatusPill>
231
+ )}
232
+ {surface.disarmed && (
233
+ <button type="button" data-testid="team-rearm" onClick={rearm} className={SMALL_BUTTON}>
234
+ Re-arm
235
+ </button>
236
+ )}
237
+ {writeNotice?.ok === true && (
238
+ <span data-testid="team-write-notice" className={MUTED}>
239
+ Saved.
240
+ </span>
241
+ )}
242
+ </div>
229
243
 
230
- {surface.configError && (
231
- <p
232
- data-testid="team-config-error"
233
- className="text-[11px] text-[var(--danger-text,var(--text-secondary))]"
234
- >
235
- Configuration rejected — the layer is running FAIL-CLOSED: {surface.configError}
236
- </p>
237
- )}
244
+ {writeNotice?.ok === false && (
245
+ <SettingsNotice tone="warning" testId="team-write-notice" details={writeNotice.reason}>
246
+ Couldn't apply that change. Nothing was changed.
247
+ </SettingsNotice>
248
+ )}
238
249
 
239
- <p className="text-[11px] text-[var(--text-tertiary)]">
240
- ceiling {surface.ceiling}
241
- {surface.allowedRoots.length > 0 && <> · allowedRoots {surface.allowedRoots.join(", ")}</>}
242
- </p>
250
+ {surface.configError && (
251
+ <SettingsNotice tone="error" testId="team-config-error" details={surface.configError}>
252
+ The team-controls configuration was rejected, so the layer is running FAIL-CLOSED and refuses every
253
+ action.
254
+ </SettingsNotice>
255
+ )}
243
256
 
244
- {surface.bindings.length === 0 ? (
245
- <span data-testid="team-bindings-empty" className="text-[11px] text-[var(--text-tertiary)]">
246
- No workspace bindings configured.
247
- </span>
248
- ) : (
249
- surface.bindings.map((b) => <Binding key={b.workspaceId} binding={b} />)
250
- )}
257
+ <SettingsFacts
258
+ rows={[
259
+ ["Highest level", surface.ceiling],
260
+ ...(surface.allowedRoots.length > 0
261
+ ? [
262
+ [
263
+ "Allowed folders",
264
+ surface.allowedRoots.map((r) => (
265
+ <code key={r} className="mr-2 break-all">
266
+ {r}
267
+ </code>
268
+ )),
269
+ ] as const,
270
+ ]
271
+ : []),
272
+ ]}
273
+ />
251
274
 
252
- <div>
253
- <span className="block text-[11px] text-[var(--text-secondary)]">
254
- Command log (newest first — the dashboard is the only place it is readable)
255
- </span>
256
- {surface.log.length === 0 ? (
257
- <span data-testid="team-log-empty" className="text-[11px] text-[var(--text-tertiary)]">
258
- No activity recorded.
259
- </span>
275
+ {surface.bindings.length === 0 ? (
276
+ <p data-testid="team-bindings-empty" className={MUTED}>
277
+ No workspace bindings configured.
278
+ </p>
260
279
  ) : (
261
- <table data-testid="team-log" className="w-full text-[11px]">
262
- <thead>
263
- <tr className="text-[var(--text-tertiary)] text-left">
264
- <th className="font-normal">when</th>
265
- <th className="font-normal">principal</th>
266
- <th className="font-normal">verb</th>
267
- <th className="font-normal">outcome</th>
268
- <th className="font-normal">reason</th>
269
- </tr>
270
- </thead>
271
- <tbody>
272
- {surface.log.map((e, i) => (
273
- <tr key={`${e.at}-${i}`} data-testid="team-log-row">
274
- <td>{formatWhen(e.at)}</td>
275
- <td className="truncate max-w-[8rem]">{e.principal}</td>
276
- <td>{e.verb}</td>
277
- <td>{e.outcome}</td>
278
- <td className="truncate max-w-[12rem]">{e.reason ?? ""}</td>
279
- </tr>
280
- ))}
281
- </tbody>
282
- </table>
280
+ surface.bindings.map((b) => <Binding key={b.workspaceId} binding={b} />)
283
281
  )}
284
- </div>
282
+
283
+ <div className="space-y-1">
284
+ <p className={SUBHEAD}>Command log</p>
285
+ <p className={MUTED}>Newest first. The dashboard is the only place it is readable.</p>
286
+ {surface.log.length === 0 ? (
287
+ <p data-testid="team-log-empty" className={MUTED}>
288
+ No activity recorded.
289
+ </p>
290
+ ) : (
291
+ <SettingsTable
292
+ testId="team-log"
293
+ caption="Command log"
294
+ columns={["When", "Who", "Command", "Result", "Reason"]}
295
+ rows={surface.log.map((e, i) => ({
296
+ key: `${e.at}-${i}`,
297
+ testId: "team-log-row",
298
+ cells: [
299
+ formatWhen(e.at),
300
+ <span key="p" className="break-all">
301
+ {e.principal}
302
+ </span>,
303
+ e.verb,
304
+ e.outcome === "permitted" ? (
305
+ <SettingsStatusPill key="o" tone="success" status={e.outcome}>
306
+ Done
307
+ </SettingsStatusPill>
308
+ ) : (
309
+ <SettingsStatusPill key="o" tone="error" status={e.outcome}>
310
+ Refused
311
+ </SettingsStatusPill>
312
+ ),
313
+ e.reason ?? "",
314
+ ],
315
+ }))}
316
+ />
317
+ )}
318
+ </div>
319
+ </SettingsGroup>
285
320
  </div>
286
321
  );
287
322
  }
@@ -49,6 +49,22 @@
49
49
  "default": [],
50
50
  "description": "L4: guild channel ids explicitly opted in. Any other guild channel is inert; DMs are isolated."
51
51
  },
52
+ "threadPerConversation": {
53
+ "type": "boolean",
54
+ "default": true,
55
+ "description": "Open a Discord thread on every new message in the channel root and run that conversation in its own session inside the thread. false = one shared session for the whole channel."
56
+ },
57
+ "mirrorDashboardSessions": {
58
+ "type": "boolean",
59
+ "default": false,
60
+ "description": "Show sessions started in the dashboard on Discord: each live, non-hidden session inside a bound workspace gets its own thread in that workspace's channel (existing ones when turned on, new ones as they start). Sends their activity to Discord at the channel's mirror level. You can always attach one by hand with !sessions / !attach."
61
+ },
62
+ "sessionVisibility": {
63
+ "type": "string",
64
+ "enum": ["hidden", "shown"],
65
+ "default": "hidden",
66
+ "description": "Board visibility of sessions the gateway starts or resumes. hidden (default) keeps Discord sessions off the board (revealed by \"show hidden\"); attached sessions are never touched."
67
+ },
52
68
  "steerPrefix": {
53
69
  "type": "string",
54
70
  "default": "!",
@@ -77,6 +77,14 @@ export function resolveConfig(raw: ChatGatewayConfig | undefined): ResolvedConfi
77
77
  groupChannels: normalizeStringArray(src.groupChannels),
78
78
  steerPrefix,
79
79
  editThrottleMs: normalizeThrottle(src.editThrottleMs),
80
+ // Only an explicit "shown" opts out; anything else stays hidden.
81
+ sessionVisibility: src.sessionVisibility === "shown" ? "shown" : CONFIG_DEFAULTS.sessionVisibility,
82
+ threadPerConversation:
83
+ typeof src.threadPerConversation === "boolean"
84
+ ? src.threadPerConversation
85
+ : CONFIG_DEFAULTS.threadPerConversation,
86
+ // Opt-in: sends transcripts to Discord, so only an explicit `true` enables.
87
+ mirrorDashboardSessions: src.mirrorDashboardSessions === true,
80
88
  ...(normalizeToolPolicy(src.toolPolicy) === undefined
81
89
  ? {}
82
90
  : { toolPolicy: normalizeToolPolicy(src.toolPolicy) }),