@blackbelt-technology/pi-dashboard-chat-gateway-plugin 0.9.0 → 0.11.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,9 +11,14 @@
|
|
|
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
|
-
*
|
|
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
|
*/
|
|
16
|
-
import { usePluginConfig, usePluginMessage, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime
|
|
21
|
+
import { SettingsFacts, SettingsGroup, SettingsItem, SettingsNotice, SettingsStatusPill, SettingsTable, usePluginConfig, usePluginMessage, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
17
22
|
import type React from "react";
|
|
18
23
|
import { useCallback, useEffect, useState } from "react";
|
|
19
24
|
import {
|
|
@@ -29,6 +34,18 @@ function formatWhen(at: number): string {
|
|
|
29
34
|
return new Date(at).toLocaleString();
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
const MIRROR_LABEL: Record<TeamSurfaceView["bindings"][number]["mirrorLevel"], string> = {
|
|
38
|
+
"names-only": "Mirror: names only",
|
|
39
|
+
"names-and-diffs": "Mirror: names and diffs",
|
|
40
|
+
"full-transcript": "Mirror: full transcript",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const SMALL_BUTTON =
|
|
44
|
+
"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)]";
|
|
45
|
+
|
|
46
|
+
const SUBHEAD = "text-xs font-semibold text-[var(--text-primary)]";
|
|
47
|
+
const MUTED = "text-[12px] text-[var(--text-secondary)]";
|
|
48
|
+
|
|
32
49
|
/**
|
|
33
50
|
* The delegation disclosure for one role mapping.
|
|
34
51
|
*
|
|
@@ -41,7 +58,7 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
|
|
|
41
58
|
return (
|
|
42
59
|
<span
|
|
43
60
|
data-testid={`delegation-unavailable-${role.roleId}`}
|
|
44
|
-
className="text-[var(--
|
|
61
|
+
className="text-[var(--severity-error-fg)]"
|
|
45
62
|
>
|
|
46
63
|
Cannot list who can assign this — missing permission: {role.assigners.missingPermission}
|
|
47
64
|
</span>
|
|
@@ -49,7 +66,7 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
|
|
|
49
66
|
}
|
|
50
67
|
if (role.assigners.members.length === 0) {
|
|
51
68
|
return (
|
|
52
|
-
<span data-testid={`delegation-none-${role.roleId}`} className="text-[var(--text-
|
|
69
|
+
<span data-testid={`delegation-none-${role.roleId}`} className="text-[var(--text-secondary)]">
|
|
53
70
|
Nobody can assign this role.
|
|
54
71
|
</span>
|
|
55
72
|
);
|
|
@@ -63,52 +80,49 @@ function Delegation({ role }: { role: SurfaceRoleMapping }): React.ReactElement
|
|
|
63
80
|
}
|
|
64
81
|
|
|
65
82
|
function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }): React.ReactElement {
|
|
83
|
+
const id = binding.workspaceId;
|
|
66
84
|
return (
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
<SettingsItem
|
|
86
|
+
testId={`team-binding-${id}`}
|
|
87
|
+
title={<span data-testid={`team-binding-name-${id}`}>{binding.workspaceName ?? "(workspace missing)"}</span>}
|
|
88
|
+
subtitle={
|
|
89
|
+
binding.channelId ? (
|
|
90
|
+
<>
|
|
91
|
+
channel <code>{binding.channelId}</code>
|
|
92
|
+
</>
|
|
93
|
+
) : (
|
|
94
|
+
"No channel provisioned."
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
status={
|
|
98
|
+
<>
|
|
99
|
+
<SettingsStatusPill tone="neutral" icon={null}>
|
|
100
|
+
Level: {binding.ceiling}
|
|
101
|
+
</SettingsStatusPill>
|
|
102
|
+
<SettingsStatusPill tone="neutral" icon={null}>
|
|
103
|
+
{MIRROR_LABEL[binding.mirrorLevel]}
|
|
104
|
+
</SettingsStatusPill>
|
|
105
|
+
</>
|
|
106
|
+
}
|
|
70
107
|
>
|
|
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
108
|
{!binding.bound && (
|
|
81
|
-
<
|
|
82
|
-
data-testid={`team-binding-unbound-${binding.workspaceId}`}
|
|
83
|
-
className="text-[11px] text-[var(--danger-text,var(--text-secondary))]"
|
|
84
|
-
>
|
|
109
|
+
<SettingsNotice tone="warning" testId={`team-binding-unbound-${id}`}>
|
|
85
110
|
This workspace no longer exists. The binding is retained but inert; its channel is kept.
|
|
86
|
-
</
|
|
111
|
+
</SettingsNotice>
|
|
87
112
|
)}
|
|
88
113
|
|
|
89
114
|
{binding.problem && (
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
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>
|
|
115
|
+
<SettingsNotice tone="error" testId={`team-binding-problem-${id}`} details={binding.problem}>
|
|
116
|
+
This binding could not be set up, so it stays inactive.
|
|
117
|
+
</SettingsNotice>
|
|
104
118
|
)}
|
|
105
119
|
|
|
106
120
|
<div>
|
|
107
|
-
<
|
|
121
|
+
<p className={SUBHEAD}>Principals</p>
|
|
108
122
|
{binding.principals.length === 0 ? (
|
|
109
|
-
<
|
|
123
|
+
<p className={MUTED}>None mapped.</p>
|
|
110
124
|
) : (
|
|
111
|
-
<ul data-testid={`team-principals-${
|
|
125
|
+
<ul data-testid={`team-principals-${id}`} className="text-[12px]">
|
|
112
126
|
{binding.principals.map((p) => (
|
|
113
127
|
<li key={p.id}>
|
|
114
128
|
<code>{p.id}</code> — {p.tier}
|
|
@@ -119,11 +133,11 @@ function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }):
|
|
|
119
133
|
</div>
|
|
120
134
|
|
|
121
135
|
<div>
|
|
122
|
-
<
|
|
136
|
+
<p className={SUBHEAD}>Roles</p>
|
|
123
137
|
{binding.roles.length === 0 ? (
|
|
124
|
-
<
|
|
138
|
+
<p className={MUTED}>None mapped.</p>
|
|
125
139
|
) : (
|
|
126
|
-
<ul data-testid={`team-roles-${
|
|
140
|
+
<ul data-testid={`team-roles-${id}`} className="space-y-0.5 text-[12px]">
|
|
127
141
|
{binding.roles.map((role) => (
|
|
128
142
|
<li key={role.roleId}>
|
|
129
143
|
<code>{role.roleId}</code> — {role.tier}: <Delegation role={role} />
|
|
@@ -134,24 +148,21 @@ function Binding({ binding }: { binding: TeamSurfaceView["bindings"][number] }):
|
|
|
134
148
|
</div>
|
|
135
149
|
|
|
136
150
|
<div>
|
|
137
|
-
<
|
|
138
|
-
<ul data-testid={`team-folders-${
|
|
151
|
+
<p className={SUBHEAD}>Folders</p>
|
|
152
|
+
<ul data-testid={`team-folders-${id}`} className="text-[12px]">
|
|
139
153
|
{binding.folders.map((f) => (
|
|
140
|
-
<li key={f.path} data-inert={f.inert ? "true" : "false"}>
|
|
154
|
+
<li key={f.path} data-inert={f.inert ? "true" : "false"} className="flex flex-wrap items-center gap-1">
|
|
141
155
|
<code>{f.path}</code>
|
|
142
156
|
{f.inert && (
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
>
|
|
147
|
-
inert — outside allowedRoots
|
|
148
|
-
</span>
|
|
157
|
+
<SettingsStatusPill tone="warning" testId={`team-folder-inert-${id}-${f.path}`}>
|
|
158
|
+
Not used · outside the allowed folders
|
|
159
|
+
</SettingsStatusPill>
|
|
149
160
|
)}
|
|
150
161
|
</li>
|
|
151
162
|
))}
|
|
152
163
|
</ul>
|
|
153
164
|
</div>
|
|
154
|
-
</
|
|
165
|
+
</SettingsItem>
|
|
155
166
|
);
|
|
156
167
|
}
|
|
157
168
|
|
|
@@ -159,7 +170,8 @@ export function TeamControlsPanel(): React.ReactElement {
|
|
|
159
170
|
const config = usePluginConfig<ChatGatewayConfig>();
|
|
160
171
|
const send = usePluginSend();
|
|
161
172
|
const [surface, setSurface] = useState<TeamSurfaceView | null>(null);
|
|
162
|
-
|
|
173
|
+
// `reason` is the raw refusal code: kept only for "Copy details".
|
|
174
|
+
const [writeNotice, setWriteNotice] = useState<{ ok: true } | { ok: false; reason: string } | null>(null);
|
|
163
175
|
|
|
164
176
|
// The surface answer and the write result both arrive on their own types.
|
|
165
177
|
usePluginMessage<{ surface?: TeamSurfaceView }>(TEAM_SURFACE_MESSAGE, (msg) => {
|
|
@@ -169,8 +181,8 @@ export function TeamControlsPanel(): React.ReactElement {
|
|
|
169
181
|
TEAM_CONFIG_MESSAGE,
|
|
170
182
|
(msg) => {
|
|
171
183
|
if (msg?.surface) setSurface(msg.surface);
|
|
172
|
-
if (msg?.ok === true) setWriteNotice(
|
|
173
|
-
else if (msg?.reason) setWriteNotice(
|
|
184
|
+
if (msg?.ok === true) setWriteNotice({ ok: true });
|
|
185
|
+
else if (msg?.reason) setWriteNotice({ ok: false, reason: msg.reason });
|
|
174
186
|
},
|
|
175
187
|
);
|
|
176
188
|
|
|
@@ -190,98 +202,113 @@ export function TeamControlsPanel(): React.ReactElement {
|
|
|
190
202
|
|
|
191
203
|
if (!surface) {
|
|
192
204
|
return (
|
|
193
|
-
<div data-testid="team-controls-panel" className="text-
|
|
205
|
+
<div data-testid="team-controls-panel" className="text-xs text-[var(--text-secondary)]">
|
|
194
206
|
Loading team controls…
|
|
195
207
|
</div>
|
|
196
208
|
);
|
|
197
209
|
}
|
|
198
210
|
|
|
199
211
|
return (
|
|
200
|
-
<div data-testid="team-controls-panel"
|
|
201
|
-
<
|
|
202
|
-
<
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{writeNotice && (
|
|
224
|
-
<span data-testid="team-write-notice" className="text-[11px] text-[var(--text-tertiary)]">
|
|
225
|
-
{writeNotice}
|
|
226
|
-
</span>
|
|
227
|
-
)}
|
|
228
|
-
</div>
|
|
212
|
+
<div data-testid="team-controls-panel">
|
|
213
|
+
<SettingsGroup title="Team controls" testId="team-controls-group">
|
|
214
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
215
|
+
{surface.disarmed ? (
|
|
216
|
+
<SettingsStatusPill tone="error" status="disarmed" testId="team-disarm-state">
|
|
217
|
+
Disarmed · action requests are refused
|
|
218
|
+
</SettingsStatusPill>
|
|
219
|
+
) : (
|
|
220
|
+
<SettingsStatusPill tone="success" status="armed" testId="team-disarm-state">
|
|
221
|
+
Armed
|
|
222
|
+
</SettingsStatusPill>
|
|
223
|
+
)}
|
|
224
|
+
{surface.disarmed && (
|
|
225
|
+
<button type="button" data-testid="team-rearm" onClick={rearm} className={SMALL_BUTTON}>
|
|
226
|
+
Re-arm
|
|
227
|
+
</button>
|
|
228
|
+
)}
|
|
229
|
+
{writeNotice?.ok === true && (
|
|
230
|
+
<span data-testid="team-write-notice" className={MUTED}>
|
|
231
|
+
Saved.
|
|
232
|
+
</span>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
229
235
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
Configuration rejected — the layer is running FAIL-CLOSED: {surface.configError}
|
|
236
|
-
</p>
|
|
237
|
-
)}
|
|
236
|
+
{writeNotice?.ok === false && (
|
|
237
|
+
<SettingsNotice tone="warning" testId="team-write-notice" details={writeNotice.reason}>
|
|
238
|
+
Couldn't apply that change. Nothing was changed.
|
|
239
|
+
</SettingsNotice>
|
|
240
|
+
)}
|
|
238
241
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
{surface.configError && (
|
|
243
|
+
<SettingsNotice tone="error" testId="team-config-error" details={surface.configError}>
|
|
244
|
+
The team-controls configuration was rejected, so the layer is running FAIL-CLOSED and refuses every
|
|
245
|
+
action.
|
|
246
|
+
</SettingsNotice>
|
|
247
|
+
)}
|
|
243
248
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
<SettingsFacts
|
|
250
|
+
rows={[
|
|
251
|
+
["Highest level", surface.ceiling],
|
|
252
|
+
...(surface.allowedRoots.length > 0
|
|
253
|
+
? [
|
|
254
|
+
[
|
|
255
|
+
"Allowed folders",
|
|
256
|
+
surface.allowedRoots.map((r) => (
|
|
257
|
+
<code key={r} className="mr-2 break-all">
|
|
258
|
+
{r}
|
|
259
|
+
</code>
|
|
260
|
+
)),
|
|
261
|
+
] as const,
|
|
262
|
+
]
|
|
263
|
+
: []),
|
|
264
|
+
]}
|
|
265
|
+
/>
|
|
251
266
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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>
|
|
267
|
+
{surface.bindings.length === 0 ? (
|
|
268
|
+
<p data-testid="team-bindings-empty" className={MUTED}>
|
|
269
|
+
No workspace bindings configured.
|
|
270
|
+
</p>
|
|
260
271
|
) : (
|
|
261
|
-
<
|
|
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>
|
|
272
|
+
surface.bindings.map((b) => <Binding key={b.workspaceId} binding={b} />)
|
|
283
273
|
)}
|
|
284
|
-
|
|
274
|
+
|
|
275
|
+
<div className="space-y-1">
|
|
276
|
+
<p className={SUBHEAD}>Command log</p>
|
|
277
|
+
<p className={MUTED}>Newest first. The dashboard is the only place it is readable.</p>
|
|
278
|
+
{surface.log.length === 0 ? (
|
|
279
|
+
<p data-testid="team-log-empty" className={MUTED}>
|
|
280
|
+
No activity recorded.
|
|
281
|
+
</p>
|
|
282
|
+
) : (
|
|
283
|
+
<SettingsTable
|
|
284
|
+
testId="team-log"
|
|
285
|
+
caption="Command log"
|
|
286
|
+
columns={["When", "Who", "Command", "Result", "Reason"]}
|
|
287
|
+
rows={surface.log.map((e, i) => ({
|
|
288
|
+
key: `${e.at}-${i}`,
|
|
289
|
+
testId: "team-log-row",
|
|
290
|
+
cells: [
|
|
291
|
+
formatWhen(e.at),
|
|
292
|
+
<span key="p" className="break-all">
|
|
293
|
+
{e.principal}
|
|
294
|
+
</span>,
|
|
295
|
+
e.verb,
|
|
296
|
+
e.outcome === "permitted" ? (
|
|
297
|
+
<SettingsStatusPill key="o" tone="success" status={e.outcome}>
|
|
298
|
+
Done
|
|
299
|
+
</SettingsStatusPill>
|
|
300
|
+
) : (
|
|
301
|
+
<SettingsStatusPill key="o" tone="error" status={e.outcome}>
|
|
302
|
+
Refused
|
|
303
|
+
</SettingsStatusPill>
|
|
304
|
+
),
|
|
305
|
+
e.reason ?? "",
|
|
306
|
+
],
|
|
307
|
+
}))}
|
|
308
|
+
/>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
</SettingsGroup>
|
|
285
312
|
</div>
|
|
286
313
|
);
|
|
287
314
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Pure over (author, binding, verb, targetCwd, disarmed) — the verb→tier table
|
|
11
11
|
* and command allowlist are injectable purely to make the table-driven tests
|
|
12
|
-
* possible; production uses the shared `
|
|
12
|
+
* possible; production uses the shared `GENERATED_VERB_TIERS` table.
|
|
13
13
|
*
|
|
14
14
|
* See change: add-chat-gateway-team-controls (D2).
|
|
15
15
|
*/
|
package/src/server/team/tier.ts
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Verb→tier resolution for the chat team-controls layer.
|
|
3
3
|
*
|
|
4
4
|
* The tier required by a verb is READ from the dashboard's shared effective
|
|
5
|
-
* table (`
|
|
6
|
-
*
|
|
5
|
+
* table (`GENERATED_VERB_TIERS`, generated into `packages/shared/src/mcp/` by the
|
|
6
|
+
* mcp-server codegen), never re-declared here — so the chat surface and the MCP surface
|
|
7
7
|
* cannot drift apart. A curated command allowlist narrows what chat may invoke
|
|
8
8
|
* at all, and a non-configurable deny-list carves credential/state-minting
|
|
9
9
|
* verbs out of `operate`.
|
|
10
10
|
*
|
|
11
|
-
* See change: add-chat-gateway-team-controls (D3).
|
|
11
|
+
* See change: add-chat-gateway-team-controls (D3); decouple-plugins-from-core (task 2.6).
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { GENERATED_VERB_TIERS } from "@blackbelt-technology/pi-dashboard-shared/mcp/verb-tiers.generated.js";
|
|
14
14
|
import { minTier, rank, type Tier } from "@blackbelt-technology/pi-dashboard-shared/tiers.js";
|
|
15
15
|
|
|
16
16
|
/** Roles may never grant `operate` — see `authorize.ts` / `tier-config.ts`. */
|
|
@@ -83,9 +83,9 @@ export const CHAT_LOCAL_VERB_TIERS: ReadonlyMap<string, Tier> = new Map([
|
|
|
83
83
|
["close_session", "control"],
|
|
84
84
|
]);
|
|
85
85
|
|
|
86
|
-
/** The effective per-verb tier table, read from the shared generated
|
|
86
|
+
/** The effective per-verb tier table, read from the shared generated table. */
|
|
87
87
|
export const VERB_TIERS: ReadonlyMap<string, Tier> = new Map(
|
|
88
|
-
|
|
88
|
+
GENERATED_VERB_TIERS.map((t) => [t.name, t.tier] as const),
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
/** `undefined` means the verb has no row in the shared table — never infer one. */
|