@bevel-software/platform-shared 0.7.5 → 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.
@@ -1,15 +1,15 @@
1
1
  /**
2
- * The join-request naming convention — how "asking to join a group" rides on
2
+ * The join-request naming convention — how "asking to join a plugin" rides on
3
3
  * plain change requests with zero new backend state.
4
4
  *
5
5
  * A join request IS a change request: a draft branch carrying one commit that
6
- * adds the requester to the group's `access.md` body `read:` list, opened
6
+ * adds the requester to the plugin's `access.md` body `read:` list, opened
7
7
  * against the default branch. What makes it recognisable — to the `Requested`
8
8
  * chip, to the manager-side proposals surface, to idempotency — is only this
9
9
  * branch-name convention. Both sides (backend, frontend) read it from here so
10
10
  * they can never drift.
11
11
  *
12
- * <email-localpart>/join-<group-kebab>-<groupTag>-<requesterTag>
12
+ * <email-localpart>/join-<plugin-kebab>-<pluginTag>-<requesterTag>
13
13
  *
14
14
  * follows the workspace's existing `<email-localpart>/<kebab-slug>` draft
15
15
  * convention, so join branches sort with the requester's other drafts and
@@ -18,15 +18,15 @@
18
18
  * WHY TWO TAGS: the localpart and the kebab slug are both LOSSY, and each
19
19
  * loss has its own failure:
20
20
  *
21
- * - `groupTag` — over the EXACT group name, recomputable by anyone who
22
- * knows the group. `Finance!` and `finance` share the slug `finance`;
23
- * without this tag, listing one group's requests would match the other's
21
+ * - `pluginTag` — over the EXACT plugin name, recomputable by anyone who
22
+ * knows the plugin. `Finance!` and `finance` share the slug `finance`;
23
+ * without this tag, listing one plugin's requests would match the other's
24
24
  * branches, read the wrong `access.md` (unchanged on that branch), see an
25
25
  * empty diff and SETTLE the request — closing a change request and
26
- * deleting a branch that belong to a different group. The settle decision
27
- * is "the diff is empty", so group identity must be exact BEFORE the diff
26
+ * deleting a branch that belong to a different plugin. The settle decision
27
+ * is "the diff is empty", so plugin identity must be exact BEFORE the diff
28
28
  * is consulted, and `isJoinBranchFor` recomputes this tag to make it so.
29
- * - `requesterTag` — over the full email (+ group), NOT recomputable by a
29
+ * - `requesterTag` — over the full email (+ plugin), NOT recomputable by a
30
30
  * reader (a manager listing requests does not know each requester's
31
31
  * email; `isJoinBranchFor` matches its shape only). It exists so
32
32
  * `ali@bevel.software` and `ali@other.com` never share a branch — else
@@ -38,9 +38,9 @@
38
38
  * whose file adds nothing over the default branch.
39
39
  */
40
40
 
41
- /** Group name → the kebab slug used in the join branch (lossy by design). */
42
- export function kebabGroupName(group: string): string {
43
- return group
41
+ /** Plugin name → the kebab slug used in the join branch (lossy by design). */
42
+ export function kebabPluginName(plugin: string): string {
43
+ return plugin
44
44
  .trim()
45
45
  .toLowerCase()
46
46
  .replace(/\s+/g, '-')
@@ -70,37 +70,43 @@ function shortTag(input: string): string {
70
70
  return hash.toString(36).padStart(TAG_LENGTH, '0').slice(-TAG_LENGTH);
71
71
  }
72
72
 
73
- /** The exact-group tag — recomputable from the group name alone. */
74
- function groupTag(group: string): string {
75
- return shortTag(`g:${group}`);
73
+ /** The exact-plugin tag — recomputable from the plugin name alone. */
74
+ function pluginTag(plugin: string): string {
75
+ // `g:` predates the group→plugin rename, and it STAYS: the prefix is baked
76
+ // into every join branch already on a remote, and `isJoinBranchFor`
77
+ // recomputes this tag to recognise them. Changing it to `p:` would change
78
+ // every recomputed tag and orphan every in-flight join request. The prefix
79
+ // only disambiguates this tag's input from `u:<email>` — any stable byte
80
+ // does that, so there is nothing to gain by renaming it.
81
+ return shortTag(`g:${plugin}`);
76
82
  }
77
83
 
78
- /** The deterministic join branch for (requester, group). */
79
- export function joinBranchFor(email: string, group: string): string {
84
+ /** The deterministic join branch for (requester, plugin). */
85
+ export function joinBranchFor(email: string, plugin: string): string {
80
86
  const normalizedEmail = email.trim().toLowerCase();
81
87
  const localpart = normalizedEmail.split('@')[0] || normalizedEmail;
82
- const slug = kebabGroupName(group);
83
- const requester = shortTag(`u:${normalizedEmail}\n${group}`);
84
- // A group whose name has no alphanumerics at all (`!!!`) kebabs to '' — the
88
+ const slug = kebabPluginName(plugin);
89
+ const requester = shortTag(`u:${normalizedEmail}\n${plugin}`);
90
+ // A plugin whose name has no alphanumerics at all (`!!!`) kebabs to '' — the
85
91
  // tags alone still yield a valid, matchable branch.
86
92
  const middle = slug ? `${slug}-` : '';
87
- return `${localpart}/join-${middle}${groupTag(group)}-${requester}`;
93
+ return `${localpart}/join-${middle}${pluginTag(plugin)}-${requester}`;
88
94
  }
89
95
 
90
96
  /**
91
- * Does `branch` look like SOMEBODY's join branch for EXACTLY `group`?
97
+ * Does `branch` look like SOMEBODY's join branch for EXACTLY `plugin`?
92
98
  *
93
- * The group half (slug + `groupTag`) is recomputed and must match — this is
94
- * what keeps slug-colliding groups (`Finance!` vs `finance`) from seeing,
99
+ * The plugin half (slug + `pluginTag`) is recomputed and must match — this is
100
+ * what keeps slug-colliding plugins (`Finance!` vs `finance`) from seeing,
95
101
  * and worse settling, each other's requests. The requester half cannot be
96
102
  * recomputed (the reader has no email) and matches by shape; the requester's
97
103
  * identity comes from the change request's own attribution.
98
104
  */
99
- export function isJoinBranchFor(branch: string, group: string): boolean {
100
- const slug = kebabGroupName(group);
105
+ export function isJoinBranchFor(branch: string, plugin: string): boolean {
106
+ const slug = kebabPluginName(plugin);
101
107
  const middle = slug ? `${escapeRegExp(slug)}-` : '';
102
108
  const requester = `[0-9a-z]{${TAG_LENGTH}}`;
103
- return new RegExp(`^[^/]+/join-${middle}${groupTag(group)}-${requester}$`).test(branch);
109
+ return new RegExp(`^[^/]+/join-${middle}${pluginTag(plugin)}-${requester}$`).test(branch);
104
110
  }
105
111
 
106
112
  function escapeRegExp(s: string): string {
@@ -8,7 +8,7 @@ import { branchSegment } from '../git/branchAuthor.js';
8
8
  *
9
9
  * <kbDirName>/
10
10
  * ├── KnowledgeBase/ ← all team ontologies live here (the knowledge graph)
11
- * ├── Groups/ ← one folder per group; each holds BOTH skills and tools
11
+ * ├── Plugins/ ← one folder per plugin; each holds BOTH skills and tools
12
12
  * ├── Data/ ← agent-produced records; parsed like KnowledgeBase/
13
13
  * ├── Agents/ ← .agent files — agent role configurations (not the graph)
14
14
  * ├── Pipelines/ ← .pipeline files — execution-layer processes (not the graph)
@@ -24,7 +24,7 @@ import { branchSegment } from '../git/branchAuthor.js';
24
24
  *
25
25
  * These names are the single source of truth for both sides of the app:
26
26
  * - Backend: the graph parser discovers ontologies under the
27
- * {@link ONTOLOGY_ROOTS} (`KnowledgeBase/` and `Data/`); `Groups/`,
27
+ * {@link ONTOLOGY_ROOTS} (`KnowledgeBase/` and `Data/`); `Plugins/`,
28
28
  * `Agents/`, `Pipelines/` (and anything else at the root) are ignored by
29
29
  * parsing, validation, and the diagram.
30
30
  * - Frontend: the file tree renders these root folders as distinct
@@ -37,36 +37,135 @@ import { branchSegment } from '../git/branchAuthor.js';
37
37
  export const KNOWLEDGE_BASE_DIR = 'KnowledgeBase';
38
38
 
39
39
  /**
40
- * Folder under the repo root that holds the groups.
40
+ * Folder under the repo root that holds the plugins.
41
41
  *
42
- * Groups/<Group>/<skill>/SKILL.md a skill
43
- * Groups/<Group>/<name>.tool a tool manual
44
- * Groups/<Group>/access.md who can read/write the whole group
42
+ * Plugins/<Plugin>/plugin.json the Agent Plugins manifest
43
+ * Plugins/<Plugin>/skills/<skill>/SKILL.md a skill
44
+ * Plugins/<Plugin>/mcp.json MCP servers
45
+ * Plugins/<Plugin>/software.bevel.hexis/tools/ http + inline `.tool` manuals
46
+ * Plugins/<Plugin>/access.md who can read/write the plugin
45
47
  *
46
- * One folder is one group. Skills and tools live TOGETHER inside it because
47
- * they share a single access boundary: a tool a group cannot read is a skill
48
- * that group cannot run, so splitting them across two roots meant maintaining
49
- * the same permission twice and letting them drift.
48
+ * Each folder is one plugin, laid out per the Agent Plugins specification
49
+ * (https://agent-plugins.org, v1.0.0) so another conformant client can load it:
50
+ * it finds the manifest, the skills and the MCP servers, and ignores everything
51
+ * under the reverse-DNS extension directory.
50
52
  *
51
- * A group is not a registry of unique names — it is a folder. The same
52
- * integration may exist in several groups as separate files (`Everyone/
53
- * notion.tool` and `Finance/notion.tool`), each with its own credentials and
53
+ * Two parts of a plugin are ours and deliberately outside the portable core:
54
+ *
55
+ * - `access.md`, which must sit at the PLUGIN ROOT. Access resolution walks
56
+ * repo root → file directory accumulating rules, so the same file one level
57
+ * down would govern only that subtree — silently narrowing what it protects.
58
+ * - `software.bevel.hexis/tools/*.tool`, the UTCP manuals whose `http` and
59
+ * `inline` types the spec has no slot for. `mcp`-type manuals are emitted as
60
+ * real `mcp.json` entries instead, so the portable half stays portable.
61
+ *
62
+ * Skills and tools live TOGETHER in one plugin because they share a single
63
+ * access boundary: a tool a plugin cannot read is a skill that plugin cannot
64
+ * run, so splitting them across two roots meant maintaining the same permission
65
+ * twice and letting them drift.
66
+ *
67
+ * A plugin is not a registry of unique names — it is a folder. The same
68
+ * integration may exist in several plugins as separate files (`Everyone/…/
69
+ * notion.tool` and `Finance/…/notion.tool`), each with its own credentials and
54
70
  * its own access rule. That duplication is the design, not an accident.
71
+ *
72
+ * The DIRECTORY name is unconstrained by the spec (§4.1 — a plugin is located
73
+ * by path, and the name carries no meaning to a client), so folders keep their
74
+ * display casing. The lowercase slug the spec does constrain lives in the
75
+ * manifest's `name` field.
76
+ */
77
+ export const PLUGINS_DIR = 'Plugins';
78
+
79
+ /**
80
+ * The pre-rename name of {@link PLUGINS_DIR}. Referenced ONLY by the migration
81
+ * that renames it — every other consumer should be reading the new name, and a
82
+ * second live spelling is exactly how two layouts start being supported by
83
+ * accident.
84
+ */
85
+ export const LEGACY_GROUPS_DIR = 'Groups';
86
+
87
+ /** The manifest that makes a directory a plugin (Agent Plugins §4.1). */
88
+ export const PLUGIN_MANIFEST_FILE = 'plugin.json';
89
+
90
+ /** The MCP server configuration a conformant client reads (Agent Plugins §8). */
91
+ export const PLUGIN_MCP_FILE = 'mcp.json';
92
+
93
+ /** Where a plugin's skills live, one folder each (Agent Plugins §7.1). */
94
+ export const PLUGIN_SKILLS_DIR = 'skills';
95
+
96
+ /**
97
+ * Our reverse-DNS extension namespace. The spec reserves these directories for
98
+ * exactly this — client-specific behaviour that a portable core should not
99
+ * carry — so anything a conformant third-party client has no way to interpret
100
+ * goes here rather than loose in the plugin root.
55
101
  */
56
- export const GROUPS_DIR = 'Groups';
102
+ export const HEXIS_EXTENSION_NS = 'software.bevel.hexis';
103
+
104
+ /** UTCP manuals whose `http`/`inline` types the spec cannot express. */
105
+ export const HEXIS_TOOLS_DIR = `${HEXIS_EXTENSION_NS}/tools`;
106
+
107
+ /**
108
+ * The manifest `name` for a plugin folder: lowercased, anything outside
109
+ * `[a-z0-9.-]` folded to `-`, runs collapsed, ends trimmed to alphanumerics.
110
+ *
111
+ * The schema's pattern is `^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$`
112
+ * — so a folder like `personal-<user-id>` whose sanitized id happens to contain
113
+ * a doubled separator would produce an INVALID manifest, which is fatal to a
114
+ * conformant client. Collapsing runs is what makes that unrepresentable rather
115
+ * than merely unlikely.
116
+ */
117
+ export function pluginManifestName(folderName: string): string {
118
+ const slug = folderName
119
+ .toLowerCase()
120
+ .replace(/[^a-z0-9.-]+/g, '-')
121
+ .replace(/-{2,}/g, '-')
122
+ .replace(/\.{2,}/g, '.')
123
+ .replace(/^[^a-z0-9]+/, '')
124
+ .replace(/[^a-z0-9]+$/, '')
125
+ .slice(0, 64)
126
+ .replace(/[^a-z0-9]+$/, '');
127
+ // Every character can be stripped (a folder named `---`), and `name` is
128
+ // required — fall back rather than emit a manifest that fails validation.
129
+ return slug || 'plugin';
130
+ }
131
+
132
+ /** The schema a v1.0.0 manifest declares, and the version both files must agree on. */
133
+ export const AGENT_PLUGINS_SCHEMA_VERSION = '1.0.0';
134
+ export const PLUGIN_MANIFEST_SCHEMA = `https://agent-plugins.org/schemas/${AGENT_PLUGINS_SCHEMA_VERSION}/plugin.schema.json`;
135
+ export const PLUGIN_MCP_SCHEMA = `https://agent-plugins.org/schemas/${AGENT_PLUGINS_SCHEMA_VERSION}/mcp.schema.json`;
136
+
137
+ /**
138
+ * A minimal, valid `plugin.json` for a plugin folder.
139
+ *
140
+ * Deliberately only the two required fields. `version`, `license` and the rest
141
+ * are optional metadata about a DISTRIBUTED package, and inventing values for a
142
+ * folder someone just made in the app would be asserting things nobody said —
143
+ * a plugin here is a place a team keeps skills, not something published.
144
+ *
145
+ * The display name is the folder, which is why nothing here carries one: the
146
+ * manifest's `name` is constrained to a lowercase slug, and the field set is
147
+ * closed, so there is no conformant home for "Sales" other than an extension.
148
+ */
149
+ export function renderPluginManifest(folderName: string): string {
150
+ return `${JSON.stringify(
151
+ { $schema: PLUGIN_MANIFEST_SCHEMA, name: pluginManifestName(folderName) },
152
+ null,
153
+ 2,
154
+ )}\n`;
155
+ }
57
156
 
58
157
  /**
59
- * The reserved name prefix marking a personal folder under `Groups/` —
60
- * `Groups/personal-<user-id>/` is where a person's own skills live: created
158
+ * The reserved name prefix marking a personal folder under `Plugins/` —
159
+ * `Plugins/personal-<user-id>/` is where a person's own skills live: created
61
160
  * implicitly on their first personal skill, private by default (its seeded
62
161
  * `access.md` names only its owner), and never listed as a group.
63
162
  *
64
163
  * The marker is STRUCTURAL on purpose: every surface that enumerates groups
65
164
  * (catalog scan, sidebar, counts) filters on the name alone, with no access
66
- * lookup needed, and the group-creation endpoint refuses names carrying the
67
- * prefix — so a regular group can never squat on someone's personal folder.
165
+ * lookup needed, and the plugin-creation endpoint refuses names carrying the
166
+ * prefix — so a regular plugin can never squat on someone's personal folder.
68
167
  */
69
- export const PERSONAL_GROUP_PREFIX = 'personal-';
168
+ export const PERSONAL_PLUGIN_PREFIX = 'personal-';
70
169
 
71
170
  /**
72
171
  * The one personal folder name for a user — keyed to the STABLE user id, not
@@ -76,34 +175,34 @@ export const PERSONAL_GROUP_PREFIX = 'personal-';
76
175
  * sanitizer — the id lands in the folder name exactly as it lands in the
77
176
  * user's suggestion-branch names, so the two spellings can never disagree.
78
177
  */
79
- export function personalGroupFolderName(userId: string): string {
80
- return `${PERSONAL_GROUP_PREFIX}${branchSegment(userId)}`;
178
+ export function personalPluginFolderName(userId: string): string {
179
+ return `${PERSONAL_PLUGIN_PREFIX}${branchSegment(userId)}`;
81
180
  }
82
181
 
83
- /** Whether a `Groups/` child is somebody's personal folder. */
84
- export function isPersonalGroupFolder(folderName: string): boolean {
85
- return folderName.startsWith(PERSONAL_GROUP_PREFIX);
182
+ /** Whether a `Plugins/` child is somebody's personal folder. */
183
+ export function isPersonalPluginFolder(folderName: string): boolean {
184
+ return folderName.startsWith(PERSONAL_PLUGIN_PREFIX);
86
185
  }
87
186
 
88
187
  /**
89
- * The group a repo-root-relative path belongs to, or `null` for content that
90
- * sits outside any group.
188
+ * The plugin a repo-root-relative path belongs to, or `null` for content that
189
+ * sits outside any plugin.
91
190
  *
92
- * Groups/GTM/heyreach-campaign/SKILL.md → 'GTM'
93
- * Groups/GTM/heyreach.tool → 'GTM'
94
- * Groups/loose-skill/SKILL.md → null (no group folder)
95
- * KnowledgeBase/Product/… → null (not a group root)
191
+ * Plugins/GTM/skills/heyreach-campaign/SKILL.md → 'GTM'
192
+ * Plugins/GTM/mcp.json → 'GTM'
193
+ * Plugins/loose-skill/SKILL.md → 'loose-skill' (the folder IS the plugin)
194
+ * KnowledgeBase/Product/… → null (not a plugin root)
96
195
  *
97
- * Returns null rather than throwing because a group is a property SOME paths
98
- * have. Callers bucket by it; nothing requires it. An ungrouped skill is a
196
+ * Returns null rather than throwing because a plugin is a property SOME paths
197
+ * have. Callers bucket by it; nothing requires it. A plugin-less skill is a
99
198
  * real, supported state — the prototype calls those "yours alone".
100
199
  */
101
- export function groupOfPath(repoRelativePath: string): string | null {
200
+ export function pluginOfPath(repoRelativePath: string): string | null {
102
201
  const segments = repoRelativePath.split('/').filter(Boolean);
103
- if (segments[0] !== GROUPS_DIR) return null;
104
- // Needs a segment for the group AND at least one below it, otherwise
105
- // `Groups/GTM` (the folder itself) would report itself as being in a group,
106
- // and a loose `Groups/slack.tool` would report a group named "slack.tool".
202
+ if (segments[0] !== PLUGINS_DIR) return null;
203
+ // Needs a segment for the plugin AND at least one below it, otherwise
204
+ // `Plugins/GTM` (the folder itself) would report itself as being in a plugin,
205
+ // and a loose `Plugins/slack.tool` would report a plugin named "slack.tool".
107
206
  return segments.length >= 3 ? (segments[1] ?? null) : null;
108
207
  }
109
208