@bevel-software/platform-shared 0.14.0 → 0.19.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/dist/auth/types.d.ts +12 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/git/pr.types.d.ts +75 -11
- package/dist/git/pr.types.d.ts.map +1 -1
- package/dist/git/types.d.ts +75 -2
- package/dist/git/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/workflow/events.d.ts +39 -4
- package/dist/workflow/events.d.ts.map +1 -1
- package/dist/workflow/events.js.map +1 -1
- package/dist/workflow/interface.d.ts +137 -5
- package/dist/workflow/interface.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +93 -0
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workspace/access-verbs.d.ts +83 -0
- package/dist/workspace/access-verbs.d.ts.map +1 -0
- package/dist/workspace/access-verbs.js +110 -0
- package/dist/workspace/access-verbs.js.map +1 -0
- package/dist/workspace/agent-preamble.d.ts +33 -0
- package/dist/workspace/agent-preamble.d.ts.map +1 -0
- package/dist/workspace/agent-preamble.js +45 -0
- package/dist/workspace/agent-preamble.js.map +1 -0
- package/dist/workspace/entry-exists.d.ts +27 -0
- package/dist/workspace/entry-exists.d.ts.map +1 -0
- package/dist/workspace/entry-exists.js +33 -0
- package/dist/workspace/entry-exists.js.map +1 -0
- package/dist/workspace/filename.d.ts +15 -0
- package/dist/workspace/filename.d.ts.map +1 -1
- package/dist/workspace/filename.js +37 -3
- package/dist/workspace/filename.js.map +1 -1
- package/dist/workspace/frontmatter-carriers.d.ts +44 -0
- package/dist/workspace/frontmatter-carriers.d.ts.map +1 -0
- package/dist/workspace/frontmatter-carriers.js +52 -0
- package/dist/workspace/frontmatter-carriers.js.map +1 -0
- package/dist/workspace/frontmatter.d.ts +23 -4
- package/dist/workspace/frontmatter.d.ts.map +1 -1
- package/dist/workspace/frontmatter.js +59 -9
- package/dist/workspace/frontmatter.js.map +1 -1
- package/dist/workspace/kb-layout.d.ts +365 -19
- package/dist/workspace/kb-layout.d.ts.map +1 -1
- package/dist/workspace/kb-layout.js +619 -20
- package/dist/workspace/kb-layout.js.map +1 -1
- package/dist/workspace/placeholder.d.ts +21 -0
- package/dist/workspace/placeholder.d.ts.map +1 -0
- package/dist/workspace/placeholder.js +28 -0
- package/dist/workspace/placeholder.js.map +1 -0
- package/dist/workspace/platform-files.d.ts +105 -0
- package/dist/workspace/platform-files.d.ts.map +1 -0
- package/dist/workspace/platform-files.js +147 -0
- package/dist/workspace/platform-files.js.map +1 -0
- package/dist/workspace/types.d.ts +8 -0
- package/dist/workspace/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/types.ts +12 -0
- package/src/git/pr.types.ts +77 -11
- package/src/git/types.ts +81 -3
- package/src/index.ts +6 -0
- package/src/workflow/events.ts +40 -3
- package/src/workflow/interface.ts +162 -6
- package/src/workflow/types.ts +70 -0
- package/src/workspace/access-verbs.ts +124 -0
- package/src/workspace/agent-preamble.ts +47 -0
- package/src/workspace/entry-exists.ts +36 -0
- package/src/workspace/filename.ts +38 -3
- package/src/workspace/frontmatter-carriers.ts +57 -0
- package/src/workspace/frontmatter.ts +57 -8
- package/src/workspace/kb-layout.ts +660 -24
- package/src/workspace/placeholder.ts +29 -0
- package/src/workspace/platform-files.ts +188 -0
- package/src/workspace/types.ts +8 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { branchSegment } from '../git/branchAuthor.js';
|
|
2
|
+
import { PREAMBLE_FILE } from './agent-preamble.js';
|
|
3
|
+
import { validateFilename } from './filename.js';
|
|
2
4
|
/**
|
|
3
5
|
* Top-level layout of the KB repo (inside the `KB_DIR_NAME` clone).
|
|
4
6
|
*
|
|
@@ -7,7 +9,8 @@ import { branchSegment } from '../git/branchAuthor.js';
|
|
|
7
9
|
*
|
|
8
10
|
* <kbDirName>/
|
|
9
11
|
* ├── KnowledgeBase/ ← all team ontologies live here (the knowledge graph)
|
|
10
|
-
* ├──
|
|
12
|
+
* ├── Skills/ ← shared skills, organised by ownership; plugins LINK to them
|
|
13
|
+
* ├── Plugins/ ← one folder per plugin: manifest, MCP servers, tools, links
|
|
11
14
|
* ├── Data/ ← agent-produced records; parsed like KnowledgeBase/
|
|
12
15
|
* ├── Agents/ ← .agent files — agent role configurations (not the graph)
|
|
13
16
|
* ├── Pipelines/ ← .pipeline files — execution-layer processes (not the graph)
|
|
@@ -23,21 +26,44 @@ import { branchSegment } from '../git/branchAuthor.js';
|
|
|
23
26
|
*
|
|
24
27
|
* These names are the single source of truth for both sides of the app:
|
|
25
28
|
* - Backend: the graph parser discovers ontologies under the
|
|
26
|
-
* {@link
|
|
29
|
+
* {@link ontologyRoots} (`KnowledgeBase/` and `Data/`); `Plugins/`,
|
|
27
30
|
* `Agents/`, `Pipelines/` (and anything else at the root) are ignored by
|
|
28
31
|
* parsing, validation, and the diagram.
|
|
29
32
|
* - Frontend: the file tree renders these root folders as distinct
|
|
30
33
|
* top-level sections.
|
|
31
34
|
*
|
|
32
35
|
* Don't hard-code these strings elsewhere — import them from here.
|
|
36
|
+
*
|
|
37
|
+
* CONFIGURABLE, WITH DEFAULTS. The three roots a deployment may rename
|
|
38
|
+
* (`KnowledgeBase/`, `Skills/`, `Plugins/`) are `let` bindings applied by
|
|
39
|
+
* {@link configureKbLayout} — the backend from its deployment settings, the
|
|
40
|
+
* browser from `GET /api/config` — the same live-binding pattern as the branch
|
|
41
|
+
* model in `git/protected.ts`. Unlike the branch model they carry defaults, so
|
|
42
|
+
* nothing has to wait for configuration; but the same rule applies: read them
|
|
43
|
+
* inside a function body, never capture one at module scope.
|
|
33
44
|
*/
|
|
34
45
|
/** Folder under the repo root that contains all team ontologies. */
|
|
35
|
-
export
|
|
46
|
+
export let KNOWLEDGE_BASE_DIR = 'KnowledgeBase';
|
|
47
|
+
/**
|
|
48
|
+
* Folder under the repo root that holds SHARED skills, organised by ownership:
|
|
49
|
+
*
|
|
50
|
+
* Skills/<scope>/…/<skill>/SKILL.md a skill, at any depth
|
|
51
|
+
* Skills/<scope>/access.md who owns / may read the scope
|
|
52
|
+
*
|
|
53
|
+
* A skill's readability comes from ITS OWN path walk — the scope folders'
|
|
54
|
+
* `access.md` files — never from the plugins that link it. Plugins point at
|
|
55
|
+
* skills here by path (see `HEXIS_LINKED_SKILLS_KEY`), so one definition can
|
|
56
|
+
* ship in several plugins, and a skill in no plugin at all is a normal state.
|
|
57
|
+
* Inline skills under `Plugins/<Plugin>/skills/` remain supported (personal
|
|
58
|
+
* folders, legacy layouts); the catalog is the union of both trees.
|
|
59
|
+
*/
|
|
60
|
+
export let SKILLS_DIR = 'Skills';
|
|
36
61
|
/**
|
|
37
62
|
* Folder under the repo root that holds the plugins.
|
|
38
63
|
*
|
|
39
|
-
* Plugins/<Plugin>/plugin.json the Agent Plugins manifest
|
|
40
|
-
*
|
|
64
|
+
* Plugins/<Plugin>/plugin.json the Agent Plugins manifest; its
|
|
65
|
+
* hexis extension lists LINKED skills
|
|
66
|
+
* Plugins/<Plugin>/skills/<skill>/SKILL.md an inline skill
|
|
41
67
|
* Plugins/<Plugin>/mcp.json MCP servers
|
|
42
68
|
* Plugins/<Plugin>/software.bevel.hexis/tools/ http + inline `.tool` manuals
|
|
43
69
|
* Plugins/<Plugin>/access.md who can read/write the plugin
|
|
@@ -56,10 +82,11 @@ export const KNOWLEDGE_BASE_DIR = 'KnowledgeBase';
|
|
|
56
82
|
* `inline` types the spec has no slot for. `mcp`-type manuals are emitted as
|
|
57
83
|
* real `mcp.json` entries instead, so the portable half stays portable.
|
|
58
84
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
85
|
+
* A plugin's own `access.md` governs what the plugin FOLDER holds: the
|
|
86
|
+
* manifest, the MCP servers, the tools, and any inline skills. Shared skills
|
|
87
|
+
* under `Skills/` are governed by their own scope and are made visible to a
|
|
88
|
+
* plugin's members by granting the plugin's principal (`plugin/<Name>/read`)
|
|
89
|
+
* on the skill — ownership decides, the plugin is a view.
|
|
63
90
|
*
|
|
64
91
|
* A plugin is not a registry of unique names — it is a folder. The same
|
|
65
92
|
* integration may exist in several plugins as separate files (`Everyone/…/
|
|
@@ -71,7 +98,389 @@ export const KNOWLEDGE_BASE_DIR = 'KnowledgeBase';
|
|
|
71
98
|
* display casing. The lowercase slug the spec does constrain lives in the
|
|
72
99
|
* manifest's `name` field.
|
|
73
100
|
*/
|
|
74
|
-
export
|
|
101
|
+
export let PLUGINS_DIR = 'Plugins';
|
|
102
|
+
/**
|
|
103
|
+
* The file name of the platform's MANAGED agent guide at the repository root —
|
|
104
|
+
* the document every connected agent is told to read first, written and
|
|
105
|
+
* refreshed from the packaged template on every start.
|
|
106
|
+
*
|
|
107
|
+
* Configurable for one reason: `AGENTS.md` is the name coding agents look for
|
|
108
|
+
* by convention, so a customer arriving with a repository of their own very
|
|
109
|
+
* often already HAS one, and under the default name the platform would
|
|
110
|
+
* overwrite it on the first boot and on every boot after. Renaming the managed
|
|
111
|
+
* guide (`HEXIS.md`, say) hands that name back: `AGENTS.md` becomes ordinary
|
|
112
|
+
* content the platform never writes, never refreshes and never hides, and the
|
|
113
|
+
* customer's file is the one that points at ours (see
|
|
114
|
+
* {@link agentsFilePointerSentence}).
|
|
115
|
+
*
|
|
116
|
+
* A live binding like the three roots above — read it inside a function body,
|
|
117
|
+
* never capture it at module scope.
|
|
118
|
+
*/
|
|
119
|
+
export let AGENTS_FILE = 'AGENTS.md';
|
|
120
|
+
/**
|
|
121
|
+
* The name the managed guide had when it was the only name it could have.
|
|
122
|
+
*
|
|
123
|
+
* Referenced ONLY by the code that has to tell OUR file from THEIRS — the
|
|
124
|
+
* boot-time removal of a platform-written `AGENTS.md`, the ignore rule that
|
|
125
|
+
* stops hiding it, the instruction telling an agent to read the customer's
|
|
126
|
+
* file too. In the spirit of {@link LEGACY_GROUPS_DIR}: a second live spelling
|
|
127
|
+
* of the CURRENT name is how two layouts start being supported by accident, so
|
|
128
|
+
* this one is a constant and means exactly one thing.
|
|
129
|
+
*/
|
|
130
|
+
export const LEGACY_AGENTS_FILE = 'AGENTS.md';
|
|
131
|
+
/**
|
|
132
|
+
* The platform files whose names are FIXED — the ones no deployment renames.
|
|
133
|
+
* The guide is the fourth platform file and is deliberately absent here: its
|
|
134
|
+
* name is {@link AGENTS_FILE}, and `platform-files.ts` composes the two into
|
|
135
|
+
* the set every gate reads.
|
|
136
|
+
*
|
|
137
|
+
* It lives in this module rather than beside that composition because the
|
|
138
|
+
* LAYOUT has to validate against it (a guide may not be called `access.md`),
|
|
139
|
+
* and `platform-files.ts` already reads this module — the other direction
|
|
140
|
+
* would be a cycle.
|
|
141
|
+
*/
|
|
142
|
+
export const FIXED_PLATFORM_FILE_NAMES = Object.freeze([
|
|
143
|
+
'access.md',
|
|
144
|
+
'roles.yaml',
|
|
145
|
+
'.bevelignore',
|
|
146
|
+
]);
|
|
147
|
+
/** The layout a deployment gets when it names nothing. */
|
|
148
|
+
export const DEFAULT_KB_LAYOUT = Object.freeze({
|
|
149
|
+
knowledgeBaseDir: 'KnowledgeBase',
|
|
150
|
+
skillsDir: 'Skills',
|
|
151
|
+
pluginsDir: 'Plugins',
|
|
152
|
+
agentsFile: 'AGENTS.md',
|
|
153
|
+
});
|
|
154
|
+
/** The guide's name in a layout, with the default standing in for an absent one. */
|
|
155
|
+
export function agentsFileOf(layout) {
|
|
156
|
+
return (layout.agentsFile ?? '').trim() || DEFAULT_KB_LAYOUT.agentsFile;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* `name` as one literal gitignore pattern. The guide's name is the
|
|
160
|
+
* operator's, and the name rules admit characters gitignore reads as syntax:
|
|
161
|
+
* a leading `#` is a comment and a leading `!` a negation (the rule would
|
|
162
|
+
* silently hide nothing), `[`, `]`, `*` and `?` are globs, and a backslash is
|
|
163
|
+
* the escape itself. Each is escaped so the pattern names exactly the file.
|
|
164
|
+
*/
|
|
165
|
+
export function gitignoreLiteral(name) {
|
|
166
|
+
return name.replace(/[[\]*?\\]/g, '\\$&').replace(/^([#!])/, '\\$1');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The ONE sentence the platform offers to keep in a customer's own
|
|
170
|
+
* `AGENTS.md`, pointing at the managed guide beside it.
|
|
171
|
+
*
|
|
172
|
+
* Defined here, once, because two surfaces must produce the identical text:
|
|
173
|
+
* the deployment-settings field previews it before the admin consents, and the
|
|
174
|
+
* startup step appends it. A sentence written twice is a sentence that drifts,
|
|
175
|
+
* and a drifted one appends a SECOND copy to every customer file on the boot
|
|
176
|
+
* after the drift — which is the one thing this whole feature exists to stop.
|
|
177
|
+
*
|
|
178
|
+
* A guide name is a FILE NAME, not an identifier: everything `validateFilename`
|
|
179
|
+
* admits can appear in it — spaces, brackets, parentheses, `#`, `%` — and each
|
|
180
|
+
* of those means something in an inline link. So the link is BUILT rather than
|
|
181
|
+
* interpolated: the label backslash-escaped ({@link markdownLinkLabel}), the
|
|
182
|
+
* destination percent-encoded ({@link agentsFileLinkPath}). A name that only
|
|
183
|
+
* parenthesised would break the destination; `#` would turn the rest of the
|
|
184
|
+
* name into a URL fragment, and the link would point at the customer's own
|
|
185
|
+
* file.
|
|
186
|
+
*
|
|
187
|
+
* Neither spelling need match the name as it is on disk, so nothing may ask
|
|
188
|
+
* whether this sentence is present by searching for the RAW name — see
|
|
189
|
+
* {@link mentionsAgentsFile}, which is how the startup step asks.
|
|
190
|
+
*/
|
|
191
|
+
export function agentsFilePointerSentence(agentsFile = AGENTS_FILE) {
|
|
192
|
+
return `Read [${markdownLinkLabel(agentsFile)}](${agentsFileLinkPath(agentsFile)})${POINTER_SENTENCE_TAIL}`;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Everything of the sentence that does NOT depend on the guide's name — split
|
|
196
|
+
* out so the one definition above can also be RECOGNISED, by the pattern below,
|
|
197
|
+
* when the name it was written with is no longer the name in effect.
|
|
198
|
+
*/
|
|
199
|
+
const POINTER_SENTENCE_TAIL = " before working in this knowledge base — it is the platform's guide to its layout, files and rules.";
|
|
200
|
+
/**
|
|
201
|
+
* A pointer sentence the platform wrote, naming ANY guide.
|
|
202
|
+
*
|
|
203
|
+
* The label admits a backslash escape (`\[`, `\]`) because that is what
|
|
204
|
+
* {@link markdownLinkLabel} puts there; the destination cannot contain a `)`
|
|
205
|
+
* or a newline because {@link agentsFileLinkPath} encodes both. Anchored at
|
|
206
|
+
* both ends by text the platform fixed, so the shape is the provenance —
|
|
207
|
+
* a customer would have to reproduce our sentence word for word to be taken
|
|
208
|
+
* for us, which is the same bar the managed-guide header sets.
|
|
209
|
+
*/
|
|
210
|
+
const POINTER_SENTENCE_PATTERN = new RegExp(`Read \\[(?:[^\\]\\n\\\\]|\\\\[\\s\\S])*\\]\\(\\.\\/[^)\\n]*\\)${escapeRegExp(POINTER_SENTENCE_TAIL)}`, 'g');
|
|
211
|
+
/** `text` as a literal inside a regular expression. */
|
|
212
|
+
function escapeRegExp(text) {
|
|
213
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* `text` with every pointer sentence THE PLATFORM WROTE aimed at `agentsFile`
|
|
217
|
+
* — or null when it holds none of ours.
|
|
218
|
+
*
|
|
219
|
+
* This is what a SECOND rename needs. The guide's name is a setting an admin
|
|
220
|
+
* may change again: a knowledge base whose `AGENTS.md` was given a sentence
|
|
221
|
+
* pointing at `HEXIS.md` and is then renamed to `GUIDE.md` must have that
|
|
222
|
+
* sentence aimed at the new file, not a second one appended beneath a first
|
|
223
|
+
* that now points at nothing. Asking only whether the NEW name is mentioned
|
|
224
|
+
* cannot see that — the old sentence does not mention it.
|
|
225
|
+
*
|
|
226
|
+
* Returning the text unchanged (rather than null) when the sentence is already
|
|
227
|
+
* right is deliberate: "ours and correct" and "not ours at all" are different
|
|
228
|
+
* answers, and only the caller knows that the second one means "consider
|
|
229
|
+
* appending".
|
|
230
|
+
*/
|
|
231
|
+
export function retargetAgentsFilePointer(text, agentsFile = AGENTS_FILE) {
|
|
232
|
+
let found = false;
|
|
233
|
+
const wanted = agentsFilePointerSentence(agentsFile);
|
|
234
|
+
const updated = text.replace(POINTER_SENTENCE_PATTERN, () => {
|
|
235
|
+
found = true;
|
|
236
|
+
return wanted;
|
|
237
|
+
});
|
|
238
|
+
return found ? updated : null;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* `text` as an inline link's LABEL: the characters that would end the label or
|
|
242
|
+
* start emphasis or code inside it, backslash-escaped. Nothing else is touched
|
|
243
|
+
* — a filename is read by people, and `AGENTS\.md` helps no one.
|
|
244
|
+
*/
|
|
245
|
+
function markdownLinkLabel(text) {
|
|
246
|
+
return text.replace(/[\\[\]`*_]/g, (c) => `\\${c}`);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The guide as an inline link's DESTINATION: `./` and the name, percent-encoded.
|
|
250
|
+
*
|
|
251
|
+
* `encodeURI` does most of it (a space, a bracket, and `%` itself, so an
|
|
252
|
+
* already-encoded-looking name is not decoded by a reader). Three more are
|
|
253
|
+
* encoded by hand because `encodeURI` leaves them and each one ENDS the path
|
|
254
|
+
* early: `#` opens a fragment, and `(`/`)` close the destination in
|
|
255
|
+
* CommonMark's bare form. `?` and the rest of the URL-significant set are
|
|
256
|
+
* already refused by {@link validateFilename}.
|
|
257
|
+
*
|
|
258
|
+
* An ordinary name has none of these and comes out exactly as it went in.
|
|
259
|
+
*/
|
|
260
|
+
function agentsFileLinkPath(agentsFile) {
|
|
261
|
+
return `./${encodeURI(agentsFile).replace(/[#()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`)}`;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Whether `text` already points at the guide — the ONE question the startup
|
|
265
|
+
* step asks before appending {@link agentsFilePointerSentence} to a customer's
|
|
266
|
+
* own `AGENTS.md`.
|
|
267
|
+
*
|
|
268
|
+
* The plain name is the answer that matters: a mention in the customer's own
|
|
269
|
+
* words, a heading, a link they wrote, all count, and the platform stays out
|
|
270
|
+
* of a file it does not own. The other two spellings are the platform's OWN,
|
|
271
|
+
* and they are here for idempotence: the sentence writes the name escaped in
|
|
272
|
+
* the label and encoded in the destination, so on a punctuated name the file
|
|
273
|
+
* the last boot wrote need not contain the raw name at all. Asking only for
|
|
274
|
+
* that one would append a second copy on the next boot, and a third on the
|
|
275
|
+
* one after — the exact failure this feature exists to prevent.
|
|
276
|
+
*/
|
|
277
|
+
export function mentionsAgentsFile(text, agentsFile = AGENTS_FILE) {
|
|
278
|
+
return (text.includes(agentsFile) ||
|
|
279
|
+
text.includes(markdownLinkLabel(agentsFile)) ||
|
|
280
|
+
text.includes(agentsFileLinkPath(agentsFile)));
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* What is wrong with one root name, or null. A root is joined onto the repo
|
|
284
|
+
* root and onto `<dir>/.gitkeep`, so a separator or `..` would write outside
|
|
285
|
+
* the repository; a dot-prefixed name would be skipped by every scanner that
|
|
286
|
+
* treats dot-entries as bookkeeping; `.git` in any case would corrupt the clone.
|
|
287
|
+
*/
|
|
288
|
+
export function validateKbRootName(name) {
|
|
289
|
+
const v = name.trim();
|
|
290
|
+
if (!v)
|
|
291
|
+
return 'A folder name is required.';
|
|
292
|
+
if (v.includes('/') || v.includes('\\'))
|
|
293
|
+
return 'Use a single folder name — no slashes.';
|
|
294
|
+
// The ONE rule for what a path segment may be called — the same one every
|
|
295
|
+
// file and folder made through the platform passes (reserved Windows
|
|
296
|
+
// names, trailing dots, forbidden characters, length) — plus what a ROOT
|
|
297
|
+
// must not be: dot-prefixed, which every scanner skips as bookkeeping.
|
|
298
|
+
const asName = validateFilename(v);
|
|
299
|
+
if (asName)
|
|
300
|
+
return asName;
|
|
301
|
+
if (v.startsWith('.'))
|
|
302
|
+
return 'The name can\'t start with a dot.';
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* What is wrong with the agent guide's file name, or null.
|
|
307
|
+
*
|
|
308
|
+
* The rules, and what each one is for:
|
|
309
|
+
*
|
|
310
|
+
* - ONE FILE NAME. The name is joined onto the repository root and read from
|
|
311
|
+
* there and nowhere else, so a separator would name a file the platform
|
|
312
|
+
* would write but never read back.
|
|
313
|
+
* - A MARKDOWN NAME. The guide is a markdown document that people open in the
|
|
314
|
+
* app and agents read as text; `.md` is also what the per-file access rules
|
|
315
|
+
* apply to, so a guide under any other extension would take its folder's
|
|
316
|
+
* rules and stop being readable by everyone.
|
|
317
|
+
* - NOT `CLAUDE.md`. That is the guide's own pre-rename name; knowledge bases
|
|
318
|
+
* seeded before the rename still carry one, and it stays legacy content
|
|
319
|
+
* rather than becoming a second managed file.
|
|
320
|
+
* - NOT ANOTHER PLATFORM FILE. Two platform roles on one path means whichever
|
|
321
|
+
* writer runs last wins, silently.
|
|
322
|
+
* - NOT A ROOT FOLDER'S NAME, compared case-insensitively like the roots are
|
|
323
|
+
* to each other: the workspaces live on case-insensitive filesystems, where
|
|
324
|
+
* a file `Docs.md` and a folder `docs.md` are one entry.
|
|
325
|
+
*
|
|
326
|
+
* `roots` is the layout the name is judged against — the names this save would
|
|
327
|
+
* put in effect, not necessarily the ones running now.
|
|
328
|
+
*/
|
|
329
|
+
export function validateAgentsFileName(name, roots = currentKbLayout()) {
|
|
330
|
+
const v = name.trim();
|
|
331
|
+
if (!v)
|
|
332
|
+
return 'A file name is required.';
|
|
333
|
+
if (v.includes('/') || v.includes('\\'))
|
|
334
|
+
return 'Use a single file name — no folders.';
|
|
335
|
+
// The ONE rule for what a path component may be called, as everywhere else.
|
|
336
|
+
const asName = validateFilename(v);
|
|
337
|
+
if (asName)
|
|
338
|
+
return asName;
|
|
339
|
+
const lower = v.toLowerCase();
|
|
340
|
+
// The taken names come FIRST, so a name that is wrong for a specific reason
|
|
341
|
+
// is refused with that reason rather than with whichever general rule it
|
|
342
|
+
// happens to break as well (`roles.yaml` is not merely 'not markdown').
|
|
343
|
+
if (lower === 'claude.md') {
|
|
344
|
+
return 'CLAUDE.md is the guide\'s pre-rename name and stays reserved for it.';
|
|
345
|
+
}
|
|
346
|
+
for (const reserved of [...FIXED_PLATFORM_FILE_NAMES, PREAMBLE_FILE]) {
|
|
347
|
+
if (lower === reserved.toLowerCase())
|
|
348
|
+
return `${reserved} is a platform file name.`;
|
|
349
|
+
}
|
|
350
|
+
// A dot-prefixed name is skipped by every scanner that treats dot-entries as
|
|
351
|
+
// bookkeeping — including the one that would show the guide in the tree.
|
|
352
|
+
if (v.startsWith('.'))
|
|
353
|
+
return 'The name can\'t start with a dot.';
|
|
354
|
+
if (!v.endsWith('.md'))
|
|
355
|
+
return 'The name must end in .md.';
|
|
356
|
+
for (const [label, dir] of [
|
|
357
|
+
['knowledge', roots.knowledgeBaseDir],
|
|
358
|
+
['skills', roots.skillsDir],
|
|
359
|
+
['plugins', roots.pluginsDir],
|
|
360
|
+
]) {
|
|
361
|
+
if (lower === (dir ?? '').trim().toLowerCase()) {
|
|
362
|
+
return `That is already the ${label} folder's name.`;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* What is wrong with a layout, or null — the same rule {@link configureKbLayout}
|
|
369
|
+
* enforces, without applying anything. Separate so the setup screen can judge a
|
|
370
|
+
* proposed layout before it is saved. The three folder names must differ,
|
|
371
|
+
* compared case-insensitively: the workspaces live on case-insensitive
|
|
372
|
+
* filesystems too, where `Skills` and `skills` are one folder. The guide's
|
|
373
|
+
* file name is judged against all three by the same rule (see
|
|
374
|
+
* {@link validateAgentsFileName}), which makes the four names distinct.
|
|
375
|
+
*/
|
|
376
|
+
export function validateKbLayout(layout) {
|
|
377
|
+
for (const [label, value] of [
|
|
378
|
+
['knowledge base', layout.knowledgeBaseDir],
|
|
379
|
+
['skills', layout.skillsDir],
|
|
380
|
+
['plugins', layout.pluginsDir],
|
|
381
|
+
]) {
|
|
382
|
+
const problem = validateKbRootName(value ?? '');
|
|
383
|
+
if (problem)
|
|
384
|
+
return `The ${label} folder: ${problem}`;
|
|
385
|
+
}
|
|
386
|
+
const names = [layout.knowledgeBaseDir, layout.skillsDir, layout.pluginsDir].map((n) => n.trim().toLowerCase());
|
|
387
|
+
if (new Set(names).size !== names.length) {
|
|
388
|
+
return 'The knowledge base, skills and plugins folders must have three different names.';
|
|
389
|
+
}
|
|
390
|
+
// The fixed reserved roots are taken too: naming the skills folder `Data`
|
|
391
|
+
// would give one directory two reserved roles.
|
|
392
|
+
const fixed = [DATA_DIR, AGENTS_DIR, PIPELINES_DIR].map((n) => n.toLowerCase());
|
|
393
|
+
const clash = names.find((n) => fixed.includes(n));
|
|
394
|
+
if (clash)
|
|
395
|
+
return `"${clash}" is a reserved folder name (${[DATA_DIR, AGENTS_DIR, PIPELINES_DIR].join(', ')}).`;
|
|
396
|
+
// Judged against the roots THIS layout declares, not the ones in effect: a
|
|
397
|
+
// save that renames the plugins folder and the guide together must be read
|
|
398
|
+
// as the pair it is.
|
|
399
|
+
const guide = validateAgentsFileName(agentsFileOf(layout), layout);
|
|
400
|
+
if (guide)
|
|
401
|
+
return `The agent guide's file name: ${guide}`;
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
/** Everything that has asked to hear when the layout is applied. */
|
|
405
|
+
const layoutListeners = new Set();
|
|
406
|
+
/**
|
|
407
|
+
* Be told when {@link configureKbLayout} runs — for the few things that cannot
|
|
408
|
+
* read a live binding at the moment they are used.
|
|
409
|
+
*
|
|
410
|
+
* Almost nothing needs this: the roots and the guide's name are `let` bindings
|
|
411
|
+
* read inside function bodies, so code that follows the rule follows the
|
|
412
|
+
* layout for free. The exception is a value BUILT ONCE and handed to something
|
|
413
|
+
* that keeps it — the tool catalog's descriptions, which are validated into
|
|
414
|
+
* frozen-ish defs at registration and then served to agents from a map. Boot
|
|
415
|
+
* applies the layout before they are built, but the save that completes
|
|
416
|
+
* FIRST-RUN SETUP applies it afterwards (see `setup.routes.ts`, which must, so
|
|
417
|
+
* the KB phase that runs in the same request scaffolds the names the admin
|
|
418
|
+
* just chose) — and without this the catalog would go on naming `AGENTS.md`
|
|
419
|
+
* until someone restarted the server.
|
|
420
|
+
*
|
|
421
|
+
* Listeners run in registration order, after the bindings are updated and only
|
|
422
|
+
* when the layout was accepted.
|
|
423
|
+
*/
|
|
424
|
+
export function onKbLayoutApplied(listener) {
|
|
425
|
+
layoutListeners.add(listener);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Apply the layout. Called once during boot on each side; throws on an invalid
|
|
429
|
+
* one so a bad deployment setting fails beside the rest of the wiring rather
|
|
430
|
+
* than scattering a half-renamed tree. Applying the defaults is a no-op.
|
|
431
|
+
*/
|
|
432
|
+
export function configureKbLayout(layout) {
|
|
433
|
+
const problem = validateKbLayout(layout);
|
|
434
|
+
if (problem)
|
|
435
|
+
throw new Error(problem);
|
|
436
|
+
KNOWLEDGE_BASE_DIR = layout.knowledgeBaseDir.trim();
|
|
437
|
+
SKILLS_DIR = layout.skillsDir.trim();
|
|
438
|
+
PLUGINS_DIR = layout.pluginsDir.trim();
|
|
439
|
+
AGENTS_FILE = agentsFileOf(layout);
|
|
440
|
+
for (const listener of layoutListeners)
|
|
441
|
+
listener();
|
|
442
|
+
}
|
|
443
|
+
/** The layout currently in effect. */
|
|
444
|
+
export function currentKbLayout() {
|
|
445
|
+
return {
|
|
446
|
+
knowledgeBaseDir: KNOWLEDGE_BASE_DIR,
|
|
447
|
+
skillsDir: SKILLS_DIR,
|
|
448
|
+
pluginsDir: PLUGINS_DIR,
|
|
449
|
+
agentsFile: AGENTS_FILE,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Whether a layout — the one in effect, unless one is given — is the default
|
|
454
|
+
* one. The setup-completing save applies the stored names while this holds,
|
|
455
|
+
* the same "only from none to some" rule the branch model follows — and also
|
|
456
|
+
* on a retry after its own failed initialization run, when the process holds
|
|
457
|
+
* names setup applied but the app never opened (see `setup.routes.ts`). A
|
|
458
|
+
* layout the process booted with is never replaced here.
|
|
459
|
+
*/
|
|
460
|
+
export function isDefaultKbLayout(layout = currentKbLayout()) {
|
|
461
|
+
return (layout.knowledgeBaseDir === DEFAULT_KB_LAYOUT.knowledgeBaseDir &&
|
|
462
|
+
layout.skillsDir === DEFAULT_KB_LAYOUT.skillsDir &&
|
|
463
|
+
layout.pluginsDir === DEFAULT_KB_LAYOUT.pluginsDir &&
|
|
464
|
+
agentsFileOf(layout) === DEFAULT_KB_LAYOUT.agentsFile);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Render the layout placeholders a managed template carries —
|
|
468
|
+
* `{{knowledgeBaseDir}}`, `{{skillsDir}}`, `{{pluginsDir}}`, `{{agentsFile}}`
|
|
469
|
+
* — with the names in effect. The packaged guide and `.bevelignore` are
|
|
470
|
+
* written this way so a deployment that renamed its roots hands the agent a
|
|
471
|
+
* guide that names the folders it will actually find, and a deployment that
|
|
472
|
+
* renamed the guide gets a guide naming the file it lives in. Text without
|
|
473
|
+
* placeholders passes through unchanged.
|
|
474
|
+
*/
|
|
475
|
+
export function renderKbLayoutPlaceholders(text, layout = currentKbLayout()) {
|
|
476
|
+
// Replacer FUNCTIONS: a string replacement would interpret `$&`, `$$` and
|
|
477
|
+
// friends inside a folder name, and `$` is a legal character in one.
|
|
478
|
+
return text
|
|
479
|
+
.replaceAll('{{knowledgeBaseDir}}', () => layout.knowledgeBaseDir)
|
|
480
|
+
.replaceAll('{{skillsDir}}', () => layout.skillsDir)
|
|
481
|
+
.replaceAll('{{pluginsDir}}', () => layout.pluginsDir)
|
|
482
|
+
.replaceAll('{{agentsFile}}', () => agentsFileOf(layout));
|
|
483
|
+
}
|
|
75
484
|
/**
|
|
76
485
|
* The pre-rename name of {@link PLUGINS_DIR}. Referenced ONLY by the migration
|
|
77
486
|
* that renames it — every other consumer should be reading the new name, and a
|
|
@@ -94,6 +503,105 @@ export const PLUGIN_SKILLS_DIR = 'skills';
|
|
|
94
503
|
export const HEXIS_EXTENSION_NS = 'software.bevel.hexis';
|
|
95
504
|
/** UTCP manuals whose `http`/`inline` types the spec cannot express. */
|
|
96
505
|
export const HEXIS_TOOLS_DIR = `${HEXIS_EXTENSION_NS}/tools`;
|
|
506
|
+
/**
|
|
507
|
+
* The manifest key under which a plugin LINKS shared skills:
|
|
508
|
+
*
|
|
509
|
+
* plugin.json → extensions["software.bevel.hexis"].skills: [
|
|
510
|
+
* "Skills/Engineering/deploy", ← one skill folder
|
|
511
|
+
* "Skills/Sales" ← a folder of skills: every skill beneath
|
|
512
|
+
* ]
|
|
513
|
+
*
|
|
514
|
+
* Entries are repo-root-relative folder paths. A plugin's effective skill set
|
|
515
|
+
* is its inline `skills/` folder PLUS everything these roots resolve to. The
|
|
516
|
+
* spec reserves `extensions` for exactly this kind of client-specific data, so
|
|
517
|
+
* a conformant client that ignores it still gets a valid manifest; the
|
|
518
|
+
* compiled distribution copies the linked skills in for it.
|
|
519
|
+
*
|
|
520
|
+
* Linking is a reference, not a grant: a member of the plugin can read a
|
|
521
|
+
* linked skill only because the skill's own access rules name the plugin's
|
|
522
|
+
* principal (`plugin/<Name>/read`). The link service writes both together.
|
|
523
|
+
*/
|
|
524
|
+
export const HEXIS_LINKED_SKILLS_KEY = 'skills';
|
|
525
|
+
/**
|
|
526
|
+
* Normalise a linked-skill root, or null when it cannot be one: a
|
|
527
|
+
* repo-root-relative POSIX folder path with no `..`, no leading slash, no
|
|
528
|
+
* backslashes and no empty segments. Trailing slashes are dropped.
|
|
529
|
+
*/
|
|
530
|
+
export function normalizeSkillRoot(raw) {
|
|
531
|
+
if (typeof raw !== 'string')
|
|
532
|
+
return null;
|
|
533
|
+
const trimmed = raw.trim();
|
|
534
|
+
if (!trimmed || trimmed.includes('\\') || trimmed.startsWith('/'))
|
|
535
|
+
return null;
|
|
536
|
+
const segments = trimmed.split('/');
|
|
537
|
+
// Only TRAILING slashes are forgiven; an empty segment anywhere else
|
|
538
|
+
// (`Skills//deploy`) is a malformed path, not a spelling of a valid one.
|
|
539
|
+
while (segments.length > 0 && segments[segments.length - 1] === '')
|
|
540
|
+
segments.pop();
|
|
541
|
+
if (segments.length === 0)
|
|
542
|
+
return null;
|
|
543
|
+
if (segments.some((s) => s === '' || s === '.' || s === '..'))
|
|
544
|
+
return null;
|
|
545
|
+
return segments.join('/');
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* The linked-skill roots a parsed manifest declares — invalid entries are
|
|
549
|
+
* dropped, duplicates collapsed, order kept. A manifest with no extension
|
|
550
|
+
* block links nothing.
|
|
551
|
+
*/
|
|
552
|
+
export function linkedSkillRoots(manifest) {
|
|
553
|
+
if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest))
|
|
554
|
+
return [];
|
|
555
|
+
const ext = manifest.extensions;
|
|
556
|
+
if (typeof ext !== 'object' || ext === null)
|
|
557
|
+
return [];
|
|
558
|
+
const ns = ext[HEXIS_EXTENSION_NS];
|
|
559
|
+
if (typeof ns !== 'object' || ns === null)
|
|
560
|
+
return [];
|
|
561
|
+
const raw = ns[HEXIS_LINKED_SKILLS_KEY];
|
|
562
|
+
if (!Array.isArray(raw))
|
|
563
|
+
return [];
|
|
564
|
+
const out = [];
|
|
565
|
+
for (const entry of raw) {
|
|
566
|
+
const root = normalizeSkillRoot(typeof entry === 'string' ? entry : '');
|
|
567
|
+
if (root !== null && !out.includes(root))
|
|
568
|
+
out.push(root);
|
|
569
|
+
}
|
|
570
|
+
return out;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* The manifest with its linked-skill roots REPLACED by `roots`, every other
|
|
574
|
+
* byte of the object preserved (the MCP extension block beside it, the
|
|
575
|
+
* portable fields above it). An empty list removes the key rather than
|
|
576
|
+
* leaving `skills: []` behind.
|
|
577
|
+
*/
|
|
578
|
+
export function withLinkedSkillRoots(manifest, roots) {
|
|
579
|
+
const extensions = typeof manifest.extensions === 'object' && manifest.extensions !== null && !Array.isArray(manifest.extensions)
|
|
580
|
+
? { ...manifest.extensions }
|
|
581
|
+
: {};
|
|
582
|
+
const current = extensions[HEXIS_EXTENSION_NS];
|
|
583
|
+
const ns = typeof current === 'object' && current !== null && !Array.isArray(current)
|
|
584
|
+
? { ...current }
|
|
585
|
+
: {};
|
|
586
|
+
if (roots.length > 0)
|
|
587
|
+
ns[HEXIS_LINKED_SKILLS_KEY] = [...roots];
|
|
588
|
+
else
|
|
589
|
+
delete ns[HEXIS_LINKED_SKILLS_KEY];
|
|
590
|
+
if (Object.keys(ns).length > 0)
|
|
591
|
+
extensions[HEXIS_EXTENSION_NS] = ns;
|
|
592
|
+
else
|
|
593
|
+
delete extensions[HEXIS_EXTENSION_NS];
|
|
594
|
+
const out = { ...manifest };
|
|
595
|
+
if (Object.keys(extensions).length > 0)
|
|
596
|
+
out.extensions = extensions;
|
|
597
|
+
else
|
|
598
|
+
delete out.extensions;
|
|
599
|
+
return out;
|
|
600
|
+
}
|
|
601
|
+
/** Whether `skillPath` (a skill folder) falls under `root` (a skill folder or a folder of skills). */
|
|
602
|
+
export function skillUnderRoot(skillPath, root) {
|
|
603
|
+
return skillPath === root || skillPath.startsWith(`${root}/`);
|
|
604
|
+
}
|
|
97
605
|
/**
|
|
98
606
|
* The manifest `name` for a plugin folder: lowercased, anything outside
|
|
99
607
|
* `[a-z0-9.-]` folded to `-`, runs collapsed, ends trimmed to alphanumerics.
|
|
@@ -123,19 +631,76 @@ export const AGENT_PLUGINS_SCHEMA_VERSION = '1.0.0';
|
|
|
123
631
|
export const PLUGIN_MANIFEST_SCHEMA = `https://agent-plugins.org/schemas/${AGENT_PLUGINS_SCHEMA_VERSION}/plugin.schema.json`;
|
|
124
632
|
export const PLUGIN_MCP_SCHEMA = `https://agent-plugins.org/schemas/${AGENT_PLUGINS_SCHEMA_VERSION}/mcp.schema.json`;
|
|
125
633
|
/**
|
|
126
|
-
*
|
|
634
|
+
* The Agent Plugins `name`: a kebab-case identifier — lowercase letters and
|
|
635
|
+
* digits in hyphen-separated runs, nothing else. It is the plugin's IDENTITY:
|
|
636
|
+
* what the marketplace publishes it as, what the access principals are
|
|
637
|
+
* spelled from (`plugin/<name>/<verb>`), what the catalog and the URLs key
|
|
638
|
+
* on. `pluginManifestName` folds any spelling into one of these.
|
|
639
|
+
*/
|
|
640
|
+
export const PLUGIN_IDENTIFIER_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
641
|
+
export function isPluginIdentifier(name) {
|
|
642
|
+
return typeof name === 'string' && PLUGIN_IDENTIFIER_RE.test(name);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* The identity of a plugin folder: the manifest's `name` when it IS an
|
|
646
|
+
* identifier, else the folder name folded into one. A manifest naming
|
|
647
|
+
* something that cannot be an identifier is not silently reinterpreted; the
|
|
648
|
+
* folder stands in, and discovery says so.
|
|
649
|
+
*/
|
|
650
|
+
export function pluginIdentityOf(manifest, folderName) {
|
|
651
|
+
const declared = manifest?.name;
|
|
652
|
+
return isPluginIdentifier(declared) ? declared : pluginManifestName(folderName);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* What a person sees the plugin called: the manifest's `displayName` (the
|
|
656
|
+
* vendor field Claude Code shows in its picker; any casing, spaces allowed),
|
|
657
|
+
* else the manifest's `name`.
|
|
658
|
+
*
|
|
659
|
+
* THE MANIFEST IS THE ONLY SOURCE — there is no folder argument, on purpose.
|
|
660
|
+
* The folder's spelling used to stand in here, which made where a plugin
|
|
661
|
+
* happens to live a hidden input to what everyone sees it called: the API
|
|
662
|
+
* always answered with a display name while the file sometimes omitted the
|
|
663
|
+
* field, and moving or re-casing a folder silently renamed the plugin. Every
|
|
664
|
+
* write path now persists the field (see {@link renderPluginManifest} and
|
|
665
|
+
* the rename service), and one startup step backfilled the folder's spelling
|
|
666
|
+
* into the manifests written before that, so nothing renames itself.
|
|
667
|
+
*
|
|
668
|
+
* Empty only for a manifest that names nothing at all — the shape discovery
|
|
669
|
+
* already warns about and stands the folder in as the IDENTITY for; its
|
|
670
|
+
* display name then follows that identity, never the folder directly.
|
|
671
|
+
*/
|
|
672
|
+
export function pluginDisplayNameOf(manifest) {
|
|
673
|
+
const declared = manifest?.displayName;
|
|
674
|
+
if (typeof declared === 'string' && declared.trim())
|
|
675
|
+
return declared.trim();
|
|
676
|
+
const name = manifest?.name;
|
|
677
|
+
return typeof name === 'string' ? name.trim() : '';
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* A minimal, valid `plugin.json` for a plugin folder: the identifier the
|
|
681
|
+
* folder name folds into, and the name a person sees it by — `displayName`,
|
|
682
|
+
* ALWAYS written, so a client's picker shows "Sales Team" for `sales-team`
|
|
683
|
+
* and every reader has the one field to read.
|
|
127
684
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
685
|
+
* ONE argument, deliberately: `folderName` is the folder's own leaf, and on
|
|
686
|
+
* the creation path that leaf IS the name its creator typed, trimmed — the
|
|
687
|
+
* dialog's route and the `create_plugin` tool make the folder out of the
|
|
688
|
+
* typed name and hand the same string to both. A second `displayName`
|
|
689
|
+
* parameter would be a way for the two to disagree that no caller needs.
|
|
690
|
+
* The field is written even when it equals the identifier: a manifest that
|
|
691
|
+
* omits it when the two agree is a manifest whose readers need a second rule.
|
|
132
692
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
693
|
+
* Nothing else: `version`, `license` and the rest are metadata about a
|
|
694
|
+
* DISTRIBUTED package, and inventing values for a folder someone just made
|
|
695
|
+
* in the app would be asserting things nobody said.
|
|
136
696
|
*/
|
|
137
697
|
export function renderPluginManifest(folderName) {
|
|
138
|
-
|
|
698
|
+
const name = pluginManifestName(folderName);
|
|
699
|
+
// Always a non-blank, trimmed answer: the spelling asked for, else the
|
|
700
|
+
// identifier — a `displayName` of spaces would be a field present and
|
|
701
|
+
// saying nothing, which is the shape every reader here exists to avoid.
|
|
702
|
+
const shown = folderName.trim() || name;
|
|
703
|
+
return `${JSON.stringify({ $schema: PLUGIN_MANIFEST_SCHEMA, name, displayName: shown }, null, 2)}\n`;
|
|
139
704
|
}
|
|
140
705
|
/**
|
|
141
706
|
* The reserved name prefix marking a personal folder under `Plugins/` —
|
|
@@ -164,6 +729,17 @@ export function personalPluginFolderName(userId) {
|
|
|
164
729
|
export function isPersonalPluginFolder(folderName) {
|
|
165
730
|
return folderName.startsWith(PERSONAL_PLUGIN_PREFIX);
|
|
166
731
|
}
|
|
732
|
+
/**
|
|
733
|
+
* THE structural rule for a personal shelf: a repo-relative folder that is a
|
|
734
|
+
* DIRECT child of the plugins root and carries the personal prefix. A deeper
|
|
735
|
+
* folder so named is just a name, and a plugin whose manifest name happens
|
|
736
|
+
* to start with the prefix is a plugin — discovery, the principal picker and
|
|
737
|
+
* the item pages all ask this one question of the FOLDER.
|
|
738
|
+
*/
|
|
739
|
+
export function isPersonalPluginDir(repoRelDir) {
|
|
740
|
+
const segments = repoRelDir.split('/').filter(Boolean);
|
|
741
|
+
return segments.length === 2 && segments[0] === PLUGINS_DIR && isPersonalPluginFolder(segments[1]);
|
|
742
|
+
}
|
|
167
743
|
/**
|
|
168
744
|
* The plugin a repo-root-relative path belongs to, or `null` for content that
|
|
169
745
|
* sits outside any plugin.
|
|
@@ -199,8 +775,31 @@ export const PIPELINES_DIR = 'Pipelines';
|
|
|
199
775
|
/**
|
|
200
776
|
* The roots whose subfolders are discovered as ontologies by the graph parser
|
|
201
777
|
* (each subfolder with both `NodeTypes/` and `Knowledge/` is an ontology).
|
|
778
|
+
* A function, not a constant: `KNOWLEDGE_BASE_DIR` is configurable, and a
|
|
779
|
+
* module-scope array would snapshot the default before configuration.
|
|
202
780
|
*/
|
|
203
|
-
export
|
|
781
|
+
export function ontologyRoots() {
|
|
782
|
+
return [KNOWLEDGE_BASE_DIR, DATA_DIR];
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Every reserved root name, as currently configured — the set the file tree
|
|
786
|
+
* renders as its own sections rather than folding into Knowledge.
|
|
787
|
+
*/
|
|
788
|
+
export function reservedRootDirNames() {
|
|
789
|
+
return new Set([KNOWLEDGE_BASE_DIR, SKILLS_DIR, PLUGINS_DIR, DATA_DIR, AGENTS_DIR, PIPELINES_DIR]);
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* The roots anyone may start a new folder in — knowledge, skills and plugins
|
|
793
|
+
* — whatever the root's own `access.md` grants them. Everywhere else a change
|
|
794
|
+
* needs read access to where it lands (the "read before write" rule); a new
|
|
795
|
+
* folder directly under one of these three is the one place that rule does
|
|
796
|
+
* not apply, because the new folder carries its creator's own grant. A
|
|
797
|
+
* function, like {@link reservedRootDirNames}, because the names are
|
|
798
|
+
* configurable.
|
|
799
|
+
*/
|
|
800
|
+
export function creatableRootDirNames() {
|
|
801
|
+
return new Set([KNOWLEDGE_BASE_DIR, SKILLS_DIR, PLUGINS_DIR]);
|
|
802
|
+
}
|
|
204
803
|
/** The `Knowledge/` marker subfolder of an ontology (holds the graph nodes). */
|
|
205
804
|
export const KNOWLEDGE_DIR = 'Knowledge';
|
|
206
805
|
/** The `NodeTypes/` marker subfolder of an ontology (holds the type definitions). */
|