@blackbelt-technology/pi-dashboard-team-plugin 0.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.
Files changed (102) hide show
  1. package/README.md +101 -0
  2. package/dist/app/assets/InlineTerminalCard-6GBZ9nXN.css +32 -0
  3. package/dist/app/assets/InlineTerminalCard-BRjmM13k.js +53 -0
  4. package/dist/app/assets/PdfPreview-CCfKQhLL.js +2 -0
  5. package/dist/app/assets/RichDiff-BU1YI0CM.css +19 -0
  6. package/dist/app/assets/RichDiff-zrt7rxm3.js +41 -0
  7. package/dist/app/assets/abnfDiagram-VCTEODGH-BNRJZIa7.js +1 -0
  8. package/dist/app/assets/arc-Ccw1WVCw.js +1 -0
  9. package/dist/app/assets/architectureDiagram-5GKGNRK7-CmpCS5s2.js +36 -0
  10. package/dist/app/assets/blockDiagram-I7D4REHJ-M5oRqDla.js +129 -0
  11. package/dist/app/assets/c4Diagram-7LVT6UL2-C6v6KvuZ.js +38 -0
  12. package/dist/app/assets/channel-1wFLoesq.js +1 -0
  13. package/dist/app/assets/chunk-2Q5K7J3B-BrSnR-LD.js +1 -0
  14. package/dist/app/assets/chunk-5VM5RSS4-BAqdD3be.js +15 -0
  15. package/dist/app/assets/chunk-F27PBJKO-DNLocP_Z.js +1 -0
  16. package/dist/app/assets/chunk-IMKFNOWR-DwFLWoAj.js +231 -0
  17. package/dist/app/assets/chunk-JWPE2WC7-DwOQUkPK.js +1 -0
  18. package/dist/app/assets/chunk-POPQ4Y6H-CN6vxbUi.js +1 -0
  19. package/dist/app/assets/chunk-SVP7TREG-mfOuPsxp.js +88 -0
  20. package/dist/app/assets/chunk-TICWLB2K-R4JNWs6J.js +206 -0
  21. package/dist/app/assets/chunk-XXDRQBXY-Bwj8o9dr.js +1 -0
  22. package/dist/app/assets/classDiagram-ZZMXUADV-DeqkIaZ-.js +1 -0
  23. package/dist/app/assets/classDiagram-v2-VYDZK3BY-DeqkIaZ-.js +1 -0
  24. package/dist/app/assets/cose-bilkent-JH36ORCC-qCY2WMN8.js +1 -0
  25. package/dist/app/assets/cursor-editorTextHighlight-kG3uUOwL.svg +8 -0
  26. package/dist/app/assets/cynefin-OW5HDTMX-CNttFTW2.js +178 -0
  27. package/dist/app/assets/cynefinDiagram-5FMLGOSQ-CBX-RJXy.js +62 -0
  28. package/dist/app/assets/cytoscape.esm-Bch-eiPH.js +331 -0
  29. package/dist/app/assets/dagre-GXQ25YYZ-D-VD0Tcu.js +4 -0
  30. package/dist/app/assets/defaultLocale-DX6XiGOO.js +1 -0
  31. package/dist/app/assets/diagram-S7CK7UJ4-CQReIUYr.js +30 -0
  32. package/dist/app/assets/diagram-UQ7AKVKN-DyEU0WYX.js +41 -0
  33. package/dist/app/assets/diagram-VSXAHHWV-NLLDj0k8.js +3 -0
  34. package/dist/app/assets/diagram-VX7I27RA-Daf-u6xI.js +24 -0
  35. package/dist/app/assets/diagram-Z3DM3KII-B0O71sZp.js +24 -0
  36. package/dist/app/assets/ebnfDiagram-PWID7BFC-BSRAXWwk.js +1 -0
  37. package/dist/app/assets/erDiagram-RLTQ6QDP-DKoQjGux.js +99 -0
  38. package/dist/app/assets/flowDiagram-HODETNUW-gq74Q1SF.js +168 -0
  39. package/dist/app/assets/ganttDiagram-EL5Y4UJY-BIAOolFj.js +292 -0
  40. package/dist/app/assets/gitGraphDiagram-WWUBYQGX-BvZquV67.js +106 -0
  41. package/dist/app/assets/index-BTj-g2DX.js +559 -0
  42. package/dist/app/assets/index-owClP-R3.css +1 -0
  43. package/dist/app/assets/infoDiagram-27XIBGKW-dMwJRmit.js +2 -0
  44. package/dist/app/assets/init-Gi6I4Gst.js +1 -0
  45. package/dist/app/assets/ishikawaDiagram-5VMMS53U-DArpl74K.js +70 -0
  46. package/dist/app/assets/journeyDiagram-3NMN7TZE-B2sUGe5l.js +139 -0
  47. package/dist/app/assets/kanban-definition-UXKFOSKX-Cx6oCBKM.js +89 -0
  48. package/dist/app/assets/layout-BjHuHx4m.js +1 -0
  49. package/dist/app/assets/linear-CgCYMSPy.js +1 -0
  50. package/dist/app/assets/mdi-DoP81khn.js +1 -0
  51. package/dist/app/assets/mermaid.core-DiBBwf02.js +312 -0
  52. package/dist/app/assets/mindmap-definition-YA3MSWOX-DP2Penfk.js +96 -0
  53. package/dist/app/assets/ordinal-Cboi1Yqb.js +1 -0
  54. package/dist/app/assets/pdf-CcZYcL52.js +12 -0
  55. package/dist/app/assets/pdf.worker.min-CNKzwYUy.js +1 -0
  56. package/dist/app/assets/pdf.worker.min-yatZIOMy.mjs +21 -0
  57. package/dist/app/assets/pdf_viewer-BXbC1ghE.js +346 -0
  58. package/dist/app/assets/pdf_viewer-I4ZZuHqo.css +1 -0
  59. package/dist/app/assets/pegDiagram-XKGWAZYB-DuPy_Jk1.js +1 -0
  60. package/dist/app/assets/pieDiagram-E7YTZNPT-BHJIw8Ie.js +39 -0
  61. package/dist/app/assets/quadrantDiagram-AXDQQJYC-CKJDe9v8.js +7 -0
  62. package/dist/app/assets/railroadDiagram-O6MQD6OU-CPmw2XqA.js +1 -0
  63. package/dist/app/assets/requirementDiagram-BXWQKSXE-CbgXwlu-.js +84 -0
  64. package/dist/app/assets/sankeyDiagram-P5KCCOFB-xTHr7bNV.js +40 -0
  65. package/dist/app/assets/sequenceDiagram-WJ2MYXX4-BJO_VejT.js +162 -0
  66. package/dist/app/assets/sizeCapture-INFHLROL-BOIqspBs.js +1 -0
  67. package/dist/app/assets/stateDiagram-D77RDMKH-B1M9C9C6.js +1 -0
  68. package/dist/app/assets/stateDiagram-v2-MP3YSRHH-BWPtAAkO.js +1 -0
  69. package/dist/app/assets/swimlanes-42K2YHIH-BtpfWryU.js +1 -0
  70. package/dist/app/assets/swimlanesDiagram-VR7AAH4N-CRZvPlTl.js +8 -0
  71. package/dist/app/assets/timeline-definition-24CTP7MA-BaspCbTG.js +120 -0
  72. package/dist/app/assets/vennDiagram-4TSXK5OY-Rzs4n1uC.js +34 -0
  73. package/dist/app/assets/wardleyDiagram-VM6X3IG4-7u6IS5Iz.js +78 -0
  74. package/dist/app/assets/xychartDiagram-S5SC5T6Z-D-TnlcEC.js +7 -0
  75. package/dist/app/index.html +13 -0
  76. package/package.json +82 -0
  77. package/src/client/FolderTeamSection.tsx +96 -0
  78. package/src/client/TeamProjectDialog.tsx +202 -0
  79. package/src/client/index.tsx +9 -0
  80. package/src/client/match-store.ts +107 -0
  81. package/src/client/team-open.ts +27 -0
  82. package/src/configSchema.json +104 -0
  83. package/src/extension/guard.ts +97 -0
  84. package/src/extension/index.ts +44 -0
  85. package/src/i18n.ts +64 -0
  86. package/src/server/access.ts +43 -0
  87. package/src/server/conversations.ts +799 -0
  88. package/src/server/index.ts +39 -0
  89. package/src/server/paths.ts +164 -0
  90. package/src/server/persona.ts +167 -0
  91. package/src/server/personas-service.ts +178 -0
  92. package/src/server/projects.ts +294 -0
  93. package/src/server/records.ts +130 -0
  94. package/src/server/render.ts +50 -0
  95. package/src/server/routes.ts +239 -0
  96. package/src/server/static.ts +73 -0
  97. package/src/server/store-types.ts +8 -0
  98. package/src/server/store.ts +94 -0
  99. package/src/server/team.ts +105 -0
  100. package/src/server/text-write.ts +15 -0
  101. package/src/server/types.ts +112 -0
  102. package/src/server/users.ts +47 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Enable / settings / disable dialogs for a folder-enabled project (D17).
3
+ * See change: add-team-plugin.
4
+ */
5
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
6
+ import { Dialog } from "@blackbelt-technology/pi-dashboard-client-utils/Dialog";
7
+ import { useEffect, useState } from "react";
8
+
9
+ interface KnownUser {
10
+ iss: string;
11
+ sub: string;
12
+ email?: string;
13
+ name?: string;
14
+ }
15
+
16
+ export interface ProjectDialogProps {
17
+ mode: "enable" | "settings";
18
+ cwd: string;
19
+ projectId?: string;
20
+ initialName: string;
21
+ onClose(): void;
22
+ onDone(): void;
23
+ }
24
+
25
+ async function json<T>(res: Response): Promise<T> {
26
+ return (await res.json()) as T;
27
+ }
28
+
29
+ export function TeamProjectDialog({ mode, cwd, projectId, initialName, onClose, onDone }: ProjectDialogProps) {
30
+ const t = useT();
31
+ const [name, setName] = useState(initialName);
32
+ const [who, setWho] = useState<"everyone" | "selected">("everyone");
33
+ const [picked, setPicked] = useState<Set<string>>(new Set());
34
+ const [users, setUsers] = useState<KnownUser[]>([]);
35
+ const [multi, setMulti] = useState(false);
36
+ const [ctx, setCtx] = useState(false);
37
+ const [errors, setErrors] = useState<{ name?: string; users?: string; save?: string }>({});
38
+ const [busy, setBusy] = useState(false);
39
+
40
+ useEffect(() => {
41
+ let cancelled = false;
42
+ void (async () => {
43
+ try {
44
+ const me = await json<{ mode: "single" | "multi" }>(await fetch("/api/plugins/team/me"));
45
+ if (cancelled || me.mode !== "multi") return;
46
+ setMulti(true);
47
+ const res = await fetch("/api/plugins/team/users");
48
+ if (res.ok) setUsers((await json<{ users: KnownUser[] }>(res)).users);
49
+ } catch {
50
+ /* single-user or offline: keep defaults */
51
+ }
52
+ })();
53
+ return () => {
54
+ cancelled = true;
55
+ };
56
+ }, []);
57
+
58
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: many small independent branches (field / state rendering); splitting would scatter one linear flow
59
+ const submit = async () => {
60
+ const e: typeof errors = {};
61
+ if (!name.trim()) e.name = t("errName", undefined, "Give the project a name.");
62
+ if (multi && who === "selected" && picked.size === 0) e.users = t("errUsers", undefined, "Pick at least one user, or allow everyone.");
63
+ setErrors(e);
64
+ if (e.name || e.users) return;
65
+ setBusy(true);
66
+ const usersBody = !multi || who === "everyone" ? "*" : users.filter((u) => picked.has(`${u.iss}\0${u.sub}`)).map((u) => ({ iss: u.iss, sub: u.sub }));
67
+ try {
68
+ const res =
69
+ mode === "enable"
70
+ ? await fetch("/api/plugins/team/projects", {
71
+ method: "POST",
72
+ headers: { "Content-Type": "application/json" },
73
+ body: JSON.stringify({ path: cwd, name: name.trim(), users: usersBody, contextFiles: ctx }),
74
+ })
75
+ : await fetch(`/api/plugins/team/projects/${encodeURIComponent(projectId ?? "")}`, {
76
+ method: "PATCH",
77
+ headers: { "Content-Type": "application/json" },
78
+ body: JSON.stringify({ name: name.trim(), users: usersBody, contextFiles: ctx }),
79
+ });
80
+ if (!res.ok) throw new Error(String(res.status));
81
+ onDone();
82
+ onClose();
83
+ } catch {
84
+ setBusy(false);
85
+ setErrors({ save: t("errSave", undefined, "Could not save. Try again.") });
86
+ }
87
+ };
88
+
89
+ return (
90
+ <Dialog
91
+ open
92
+ onClose={onClose}
93
+ title={t(mode === "enable" ? "dlgEnableTitle" : "dlgSettingsTitle", { name: initialName }, mode === "enable" ? `Enable team: ${initialName}` : `Team settings: ${initialName}`)}
94
+ size="md"
95
+ testId="team-project-dialog"
96
+ >
97
+ <form
98
+ className="flex flex-col gap-3"
99
+ noValidate
100
+ onSubmit={(ev) => {
101
+ ev.preventDefault();
102
+ void submit();
103
+ }}
104
+ >
105
+ <div className="flex flex-col gap-1">
106
+ <label htmlFor="team-proj-name" className="text-sm font-semibold">{t("projName", undefined, "Project name")}</label>
107
+ <p className="text-xs text-[var(--text-tertiary)]">{t("projNameHint", undefined, "Users see this in the project selector.")}</p>
108
+ <input
109
+ id="team-proj-name"
110
+ value={name}
111
+ onChange={(e) => setName(e.target.value)}
112
+ aria-invalid={errors.name ? true : undefined}
113
+ className="rounded border border-[var(--border-secondary)] bg-[var(--bg-tertiary)] px-2 py-1"
114
+ />
115
+ {errors.name ? <p role="alert" className="text-xs text-red-400">{errors.name}</p> : null}
116
+ </div>
117
+ {multi ? (
118
+ <fieldset className="flex flex-col gap-1">
119
+ <legend className="text-sm font-semibold">{t("who", undefined, "Who may use it")}</legend>
120
+ <label className="flex items-center gap-2 text-sm">
121
+ <input type="radio" name="who" checked={who === "everyone"} onChange={() => setWho("everyone")} />
122
+ {t("everyone", undefined, "Everyone signed in")}
123
+ </label>
124
+ <label className="flex items-center gap-2 text-sm">
125
+ <input type="radio" name="who" checked={who === "selected"} onChange={() => setWho("selected")} />
126
+ {t("selected", undefined, "Selected users")}
127
+ </label>
128
+ {who === "selected" ? (
129
+ <div className="ml-5 flex flex-col gap-1">
130
+ <p className="text-xs text-[var(--text-tertiary)]">{t("usersHint", undefined, "Only users who already opened the team app are listed.")}</p>
131
+ {users.map((u) => {
132
+ const k = `${u.iss}\0${u.sub}`;
133
+ return (
134
+ <label key={k} className="flex items-center gap-2 text-sm">
135
+ <input
136
+ type="checkbox"
137
+ checked={picked.has(k)}
138
+ onChange={(e) =>
139
+ setPicked((s) => {
140
+ const n = new Set(s);
141
+ if (e.target.checked) n.add(k);
142
+ else n.delete(k);
143
+ return n;
144
+ })
145
+ }
146
+ />
147
+ {u.name ?? u.email ?? u.sub}
148
+ </label>
149
+ );
150
+ })}
151
+ </div>
152
+ ) : null}
153
+ {errors.users ? <p role="alert" className="text-xs text-red-400">{errors.users}</p> : null}
154
+ </fieldset>
155
+ ) : null}
156
+ <label className="flex items-start gap-2 text-sm">
157
+ <input type="checkbox" checked={ctx} onChange={(e) => setCtx(e.target.checked)} />
158
+ <span>
159
+ {t("ctxFiles", undefined, "Agents also get this folder's AGENTS.md and CLAUDE.md")}
160
+ <span className="block text-xs text-[var(--text-tertiary)]">{t("ctxHint", undefined, "Up to 64 KiB per file, treated as untrusted input.")}</span>
161
+ </span>
162
+ </label>
163
+ {errors.save ? <p role="alert" className="text-xs text-red-400">{errors.save}</p> : null}
164
+ <div className="flex justify-end gap-2">
165
+ <button type="button" className="rounded px-3 py-1 border border-[var(--border-secondary)]" onClick={onClose}>
166
+ {t("cancel", undefined, "Cancel")}
167
+ </button>
168
+ <button type="submit" disabled={busy} className="rounded px-3 py-1 bg-[var(--accent-solid)] text-white" data-testid="team-project-submit">
169
+ {t(mode === "enable" ? "ok" : "save", undefined, mode === "enable" ? "Enable" : "Save")}
170
+ </button>
171
+ </div>
172
+ </form>
173
+ </Dialog>
174
+ );
175
+ }
176
+
177
+ export function DisableTeamDialog({ name, projectId, onClose, onDone }: { name: string; projectId: string; onClose(): void; onDone(): void }) {
178
+ const t = useT();
179
+ return (
180
+ <Dialog open onClose={onClose} title={t("disTitle", { name }, `Disable team: ${name}?`)} size="sm" testId="team-disable-dialog">
181
+ <p className="text-sm text-[var(--text-secondary)]">{t("disBody", undefined, "Conversations and files are kept; enabling it again brings them back.")}</p>
182
+ <div className="mt-3 flex justify-end gap-2">
183
+ <button type="button" className="rounded px-3 py-1 border border-[var(--border-secondary)]" onClick={onClose}>
184
+ {t("cancel", undefined, "Cancel")}
185
+ </button>
186
+ <button
187
+ type="button"
188
+ className="rounded px-3 py-1 bg-red-600 text-white"
189
+ data-testid="team-disable-confirm"
190
+ onClick={() => {
191
+ void fetch(`/api/plugins/team/projects/${encodeURIComponent(projectId)}`, { method: "DELETE" }).then(() => {
192
+ onDone();
193
+ onClose();
194
+ });
195
+ }}
196
+ >
197
+ {t("disOk", undefined, "Disable")}
198
+ </button>
199
+ </div>
200
+ </Dialog>
201
+ );
202
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Client entry barrel for the team plugin: the `sidebar-folder-section` slot
3
+ * component referenced by the manifest + the i18n catalog. The embedded app
4
+ * claims (`shell-overlay-route` presentation "content") arrive with
5
+ * `add-plugin-app-host`; until then the folder entry opens the standalone app.
6
+ * See change: add-team-plugin.
7
+ */
8
+ export { catalog } from "../i18n.js";
9
+ export { FolderTeamSection } from "./FolderTeamSection.js";
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Folder → project matching for the sidebar rows (D17): ONE batched
3
+ * `POST /projects/match` for every visible folder, cached per cwd, refreshed by
4
+ * the folder menu's unified refresh and on window focus (no per-row polling).
5
+ * See change: add-team-plugin.
6
+ */
7
+ import { useEffect, useSyncExternalStore } from "react";
8
+
9
+ interface MatchProject {
10
+ id: string;
11
+ name: string;
12
+ available: boolean;
13
+ source: "config" | "folder";
14
+ agents: number;
15
+ active: number;
16
+ }
17
+ interface MatchResult {
18
+ cwd: string;
19
+ project: MatchProject | null;
20
+ enableable: boolean;
21
+ manageable?: boolean;
22
+ }
23
+ export type MatchState = { status: "loading" } | { status: "error" } | { status: "ready"; result: MatchResult };
24
+
25
+ const BATCH_MS = 25;
26
+ const MAX_BATCH = 200;
27
+ const state = new Map<string, MatchState>();
28
+ const subscribers = new Map<string, Set<() => void>>();
29
+ let pending = new Set<string>();
30
+ let timer: ReturnType<typeof setTimeout> | undefined;
31
+ let focusBound = false;
32
+
33
+ const LOADING: MatchState = { status: "loading" };
34
+ const emit = (cwd: string) => {
35
+ for (const cb of subscribers.get(cwd) ?? []) cb();
36
+ };
37
+
38
+ async function flush(): Promise<void> {
39
+ timer = undefined;
40
+ const cwds = [...pending];
41
+ pending = new Set();
42
+ for (let i = 0; i < cwds.length; i += MAX_BATCH) {
43
+ const chunk = cwds.slice(i, i + MAX_BATCH);
44
+ try {
45
+ const res = await fetch("/api/plugins/team/projects/match", {
46
+ method: "POST",
47
+ headers: { "Content-Type": "application/json" },
48
+ body: JSON.stringify({ cwds: chunk }),
49
+ });
50
+ if (!res.ok) throw new Error(String(res.status));
51
+ const body = (await res.json()) as { results: MatchResult[] };
52
+ const byCwd = new Map(body.results.map((r) => [r.cwd, r]));
53
+ for (const cwd of chunk) {
54
+ const r = byCwd.get(cwd);
55
+ state.set(cwd, r ? { status: "ready", result: r } : { status: "error" });
56
+ emit(cwd);
57
+ }
58
+ } catch {
59
+ for (const cwd of chunk) {
60
+ state.set(cwd, { status: "error" });
61
+ emit(cwd);
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ function requestMatch(cwd: string): void {
68
+ pending.add(cwd);
69
+ timer ??= setTimeout(() => void flush(), BATCH_MS);
70
+ }
71
+
72
+ /** Refetch every folder that currently has a subscriber (one batched call). */
73
+ export function invalidateMatches(): void {
74
+ for (const [cwd, subs] of subscribers) if (subs.size > 0) requestMatch(cwd);
75
+ }
76
+
77
+ export function resetMatchStore(): void {
78
+ state.clear();
79
+ subscribers.clear();
80
+ pending = new Set();
81
+ if (timer) clearTimeout(timer);
82
+ timer = undefined;
83
+ }
84
+
85
+ export function useFolderMatch(cwd: string | undefined): MatchState {
86
+ const get = () => (cwd ? (state.get(cwd) ?? LOADING) : LOADING);
87
+ const snapshot = useSyncExternalStore(
88
+ (cb) => {
89
+ if (!cwd) return () => {};
90
+ let set = subscribers.get(cwd);
91
+ if (!set) subscribers.set(cwd, (set = new Set()));
92
+ set.add(cb);
93
+ return () => set.delete(cb);
94
+ },
95
+ get,
96
+ get,
97
+ );
98
+ useEffect(() => {
99
+ if (!cwd) return;
100
+ if (!state.has(cwd)) requestMatch(cwd);
101
+ if (!focusBound && typeof window !== "undefined") {
102
+ focusBound = true;
103
+ window.addEventListener("focus", invalidateMatches);
104
+ }
105
+ }, [cwd]);
106
+ return snapshot;
107
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Where "open the team" goes. With the dashboard's app host
3
+ * (`add-plugin-app-host`: `EmbeddedApp`) the team opens in the content area;
4
+ * without it the standalone app opens in a new tab (D17 fallback).
5
+ * See change: add-team-plugin.
6
+ */
7
+ import * as runtime from "@blackbelt-technology/dashboard-plugin-runtime";
8
+
9
+ export function hasEmbeddedHost(mod: object = runtime): boolean {
10
+ return "EmbeddedApp" in mod;
11
+ }
12
+
13
+ function standaloneUrl(projectId: string): string {
14
+ return `/apps/team/?project=${encodeURIComponent(projectId)}`;
15
+ }
16
+
17
+ export function openTeam(projectId: string, navigate: (path: string) => void, cwd: string, embedded = hasEmbeddedHost()): void {
18
+ if (embedded) {
19
+ const bytes = new TextEncoder().encode(cwd);
20
+ let bin = "";
21
+ for (const b of bytes) bin += String.fromCharCode(b);
22
+ const enc = btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
23
+ navigate(`/folder/${enc}/team`);
24
+ return;
25
+ }
26
+ window.open(standaloneUrl(projectId), "_blank", "noopener");
27
+ }
@@ -0,0 +1,104 @@
1
+ {
2
+ "type": "object",
3
+ "additionalProperties": false,
4
+ "properties": {
5
+ "admins": {
6
+ "type": "array",
7
+ "description": "Principals ({iss, sub}) allowed to manage shared personas and folder projects (multi-user mode).",
8
+ "items": {
9
+ "type": "object",
10
+ "required": [
11
+ "iss",
12
+ "sub"
13
+ ],
14
+ "additionalProperties": false,
15
+ "properties": {
16
+ "iss": {
17
+ "type": "string"
18
+ },
19
+ "sub": {
20
+ "type": "string"
21
+ }
22
+ }
23
+ }
24
+ },
25
+ "skillCatalog": {
26
+ "type": "object",
27
+ "description": "Admin skill catalog: name -> absolute skill path. Personas pick names only.",
28
+ "additionalProperties": {
29
+ "type": "string"
30
+ }
31
+ },
32
+ "idleMinutes": {
33
+ "type": "number",
34
+ "minimum": 0,
35
+ "default": 30,
36
+ "description": "End idle sessions after N minutes (0 = off)."
37
+ },
38
+ "maxConversations": {
39
+ "type": "number",
40
+ "minimum": 1,
41
+ "default": 50,
42
+ "description": "Active conversations per user x agent x target."
43
+ },
44
+ "teamHome": {
45
+ "type": "string",
46
+ "description": "Team data directory (default ~/.pi/dashboard/team)."
47
+ },
48
+ "projects": {
49
+ "type": "object",
50
+ "description": "Admin-configured projects: id -> { name, path, users, contextFiles }.",
51
+ "additionalProperties": {
52
+ "type": "object",
53
+ "required": [
54
+ "name",
55
+ "path",
56
+ "users"
57
+ ],
58
+ "additionalProperties": false,
59
+ "properties": {
60
+ "name": {
61
+ "type": "string"
62
+ },
63
+ "path": {
64
+ "type": "string"
65
+ },
66
+ "users": {
67
+ "oneOf": [
68
+ {
69
+ "const": "*"
70
+ },
71
+ {
72
+ "type": "array",
73
+ "items": {
74
+ "type": "object",
75
+ "required": [
76
+ "iss",
77
+ "sub"
78
+ ],
79
+ "properties": {
80
+ "iss": {
81
+ "type": "string"
82
+ },
83
+ "sub": {
84
+ "type": "string"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ]
90
+ },
91
+ "contextFiles": {
92
+ "type": "boolean"
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "maxLiveSessions": {
98
+ "type": "number",
99
+ "minimum": 1,
100
+ "default": 10,
101
+ "description": "Live pi processes per user (across all agents and targets)."
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Team isolation guard (D7): a deny-first `tool_call` decision. Pure — the
3
+ * policy comes from the spawn-time env projection, the filesystem is only read
4
+ * to canonicalise path arguments. See change: add-team-plugin.
5
+ */
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+
9
+ export type Preset = "chat" | "files" | "full";
10
+
11
+ export const PRESET_TOOLS: Record<Preset, readonly string[]> = {
12
+ chat: ["read", "grep", "find", "ls"],
13
+ files: ["read", "grep", "find", "ls", "write", "edit"],
14
+ full: ["read", "grep", "find", "ls", "write", "edit", "bash"],
15
+ };
16
+
17
+ /** Mutating tools additionally may not touch VCS / agent-config dirs (a planted hook or `.pi` resource would run for the operator). */
18
+ const WRITE_TOOLS = new Set(["write", "edit"]);
19
+ const PROTECTED_SEGMENTS = new Set([".git", ".pi", ".claude"]);
20
+
21
+ /** Tools whose `path` argument is confined to the target root. */
22
+ const PATH_TOOLS = new Set(["read", "write", "edit", "grep", "find", "ls"]);
23
+
24
+ export interface TeamPolicy {
25
+ preset: Preset;
26
+ /** Target root (project realpath or own workspace). */
27
+ root: string;
28
+ }
29
+
30
+ export type Decision = { allow: true } | { allow: false; reason: string };
31
+
32
+ /** Read the policy from `PI_EXT_TEAM_*`; missing / garbage ⇒ null (caller blocks everything). */
33
+ export function policyFromEnv(env: Record<string, string | undefined> = process.env): TeamPolicy | null {
34
+ const tools = env.PI_EXT_TEAM_TOOLS;
35
+ const root = env.PI_EXT_TEAM_ROOT;
36
+ if (tools !== "chat" && tools !== "files" && tools !== "full") return null;
37
+ if (typeof root !== "string" || !path.isAbsolute(root)) return null;
38
+ return { preset: tools, root };
39
+ }
40
+
41
+ function canonicalize(p: string): string {
42
+ const abs = path.resolve(p);
43
+ let head = abs;
44
+ const tail: string[] = [];
45
+ for (;;) {
46
+ try {
47
+ const real = fs.realpathSync(head);
48
+ return tail.length ? path.join(real, ...tail.reverse()) : real;
49
+ } catch {
50
+ const parent = path.dirname(head);
51
+ if (parent === head) return abs;
52
+ tail.push(path.basename(head));
53
+ head = parent;
54
+ }
55
+ }
56
+ }
57
+
58
+ function inside(root: string, p: string): boolean {
59
+ const rel = path.relative(root, p);
60
+ return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
61
+ }
62
+
63
+ /** Mirror pi's path normalisation (`@` prefix, unicode spaces) before resolving. */
64
+ function normalise(raw: string): string | null {
65
+ if (raw.includes("\0")) return null;
66
+ let p = raw.replace(/[\u00a0\u2000-\u200a\u202f\u205f\u3000]/g, " ");
67
+ if (p.startsWith("@")) p = p.slice(1);
68
+ if (p.startsWith("~")) return null; // pi expands ~ to the home dir: never confine-able lexically
69
+ // pi turns `file://…` into a real filesystem path; any `scheme:` prefix (≥ 2 chars, so a drive letter
70
+ // stays legal) is refused instead of mirroring every conversion pi might add.
71
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]+:/.test(p)) return null;
72
+ return p;
73
+ }
74
+
75
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: many small independent branches (field / state rendering); splitting would scatter one linear flow
76
+ export function decideToolCall(toolName: unknown, input: unknown, policy: TeamPolicy | null): Decision {
77
+ if (!policy) return { allow: false, reason: "policy_unavailable" };
78
+ if (typeof toolName !== "string" || !PRESET_TOOLS[policy.preset].includes(toolName)) {
79
+ return { allow: false, reason: "tool_not_allowed" };
80
+ }
81
+ if (!PATH_TOOLS.has(toolName)) return { allow: true };
82
+ const args = input && typeof input === "object" ? (input as Record<string, unknown>) : {};
83
+ const root = canonicalize(policy.root);
84
+ for (const key of ["path", "file_path"]) {
85
+ const v = args[key];
86
+ if (v === undefined) continue;
87
+ if (typeof v !== "string") return { allow: false, reason: "invalid_path" };
88
+ const n = normalise(v);
89
+ if (n === null) return { allow: false, reason: "invalid_path" };
90
+ const target = canonicalize(path.isAbsolute(n) ? n : path.join(root, n));
91
+ if (!inside(root, target)) return { allow: false, reason: "path_outside_root" };
92
+ if (WRITE_TOOLS.has(toolName) && path.relative(root, target).split(path.sep).some((seg) => PROTECTED_SEGMENTS.has(seg))) {
93
+ return { allow: false, reason: "protected_path" };
94
+ }
95
+ }
96
+ return { allow: true };
97
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Team guard — companion pi extension loaded into every team session.
3
+ * - `tool_call`: deny-first name gate + path confinement (see guard.ts).
4
+ * - `session_start`: announces `team_guard_ready` to the plugin server so a
5
+ * session without a working guard is aborted instead of running ungated.
6
+ * See change: add-team-plugin (D7).
7
+ */
8
+ import { decideToolCall, policyFromEnv, type TeamPolicy } from "./guard.js";
9
+
10
+ export const TEAM_PLUGIN_ID = "team";
11
+ export const GUARD_READY_MESSAGE = "team_guard_ready";
12
+
13
+ interface PiLike {
14
+ on(event: string, handler: (event: unknown, ctx: unknown) => unknown): void;
15
+ events?: { emit: (name: string, payload: unknown) => void };
16
+ }
17
+
18
+ export function createToolCallHandler(policy: TeamPolicy | null) {
19
+ return (event: { toolName?: unknown; input?: unknown }): { block: true; reason: string } | undefined => {
20
+ const d = decideToolCall(event?.toolName, event?.input, policy);
21
+ return d.allow ? undefined : { block: true, reason: `team: ${d.reason}` };
22
+ };
23
+ }
24
+
25
+ export default function teamGuard(pi: PiLike, options?: { policy?: TeamPolicy | null }): void {
26
+ const policy = options?.policy !== undefined ? options.policy : policyFromEnv();
27
+ const onToolCall = createToolCallHandler(policy);
28
+ pi.on("tool_call", (event) => onToolCall((event ?? {}) as { toolName?: unknown; input?: unknown }));
29
+
30
+ const announce = () =>
31
+ pi.events?.emit("dashboard:plugin-message", {
32
+ pluginId: TEAM_PLUGIN_ID,
33
+ messageType: GUARD_READY_MESSAGE,
34
+ // The spawn's runId: readiness is per RUN, so a resumed session can never be credited with an old signal.
35
+ payload: { runId: process.env.PI_EXT_TEAM_RUN_ID },
36
+ });
37
+ pi.on("session_start", () => {
38
+ // Only a session with a usable policy claims readiness.
39
+ if (!policy) return;
40
+ announce();
41
+ // The bridge socket may not be up yet at session_start: repeat briefly (idempotent server-side).
42
+ for (const ms of [1_000, 3_000, 8_000]) setTimeout(announce, ms).unref?.();
43
+ });
44
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Team plugin i18n catalog — UNPREFIXED leaf keys (the shell merges them under
3
+ * `plugin.team.*`; component code resolves via the scoped `useT()`). zh-CN and
4
+ * hu keep identical key sets; English is the call-site fallback.
5
+ * See change: add-team-plugin.
6
+ */
7
+ export const catalog = {
8
+ "zh-CN": {
9
+ rowLabel: "团队",
10
+ rowCount: "{agents} 个智能体 · {active} 个活跃",
11
+ rowTitle: "打开此文件夹的 AI 团队",
12
+ openTeam: "团队",
13
+ teamSettings: "团队设置…",
14
+ disableTeam: "关闭团队",
15
+ enableTeam: "为此文件夹开启团队",
16
+ dlgEnableTitle: "开启团队:{name}",
17
+ dlgSettingsTitle: "团队设置:{name}",
18
+ projName: "项目名称",
19
+ projNameHint: "用户在项目选择器中看到此名称。",
20
+ who: "谁可以使用",
21
+ everyone: "所有已登录用户",
22
+ selected: "选定的用户",
23
+ usersHint: "这里只列出已打开过团队应用的用户。",
24
+ ctxFiles: "同时向智能体提供此文件夹的 AGENTS.md 和 CLAUDE.md",
25
+ ctxHint: "每个文件最大 64 KiB,按不受信任的输入处理。",
26
+ ok: "开启",
27
+ save: "保存",
28
+ cancel: "取消",
29
+ errName: "请填写项目名称。",
30
+ errUsers: "请至少选择一位用户,或允许所有人。",
31
+ errSave: "无法保存。请重试。",
32
+ disTitle: "关闭团队:{name}?",
33
+ disBody: "对话和文件会保留;重新开启后会恢复。",
34
+ disOk: "关闭",
35
+ },
36
+ hu: {
37
+ rowLabel: "Csapat",
38
+ rowCount: "{agents} ügynök · {active} aktív",
39
+ rowTitle: "A mappa AI csapatának megnyitása",
40
+ openTeam: "Csapat",
41
+ teamSettings: "Csapat beállításai…",
42
+ disableTeam: "Csapat kikapcsolása",
43
+ enableTeam: "Csapat bekapcsolása ehhez a mappához",
44
+ dlgEnableTitle: "Csapat bekapcsolása: {name}",
45
+ dlgSettingsTitle: "Csapat beállításai: {name}",
46
+ projName: "Projekt neve",
47
+ projNameHint: "A felhasználók ezt látják a projektválasztóban.",
48
+ who: "Kik használhatják",
49
+ everyone: "Mindenki, aki be van jelentkezve",
50
+ selected: "Kiválasztott felhasználók",
51
+ usersHint: "Azok szerepelnek itt, akik már megnyitották a csapat alkalmazást.",
52
+ ctxFiles: "A mappa AGENTS.md és CLAUDE.md fájlját is megkapják az ügynökök",
53
+ ctxHint: "Fájlonként legfeljebb 64 KiB, nem megbízható bemenetként kezelve.",
54
+ ok: "Bekapcsolás",
55
+ save: "Mentés",
56
+ cancel: "Mégse",
57
+ errName: "Adj nevet a projektnek.",
58
+ errUsers: "Válassz legalább egy felhasználót, vagy engedd mindenkinek.",
59
+ errSave: "A mentés nem sikerült. Próbáld újra.",
60
+ disTitle: "Csapat kikapcsolása: {name}?",
61
+ disBody: "A beszélgetések és a fájlok megmaradnak; ha újra bekapcsolod, visszajönnek.",
62
+ disOk: "Kikapcsolás",
63
+ },
64
+ } as const;