@bevel-software/platform-core-backend 0.8.0 → 0.9.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/core/core-ports.d.ts +7 -0
- package/dist/core/core-ports.d.ts.map +1 -1
- package/dist/core/core-ports.js.map +1 -1
- package/dist/core/create-core-server.d.ts.map +1 -1
- package/dist/core/create-core-server.js +24 -11
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +7 -2
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +39 -18
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/modules/access/access.routes.d.ts +3 -1
- package/dist/modules/access/access.routes.d.ts.map +1 -1
- package/dist/modules/access/access.routes.js +4 -2
- package/dist/modules/access/access.routes.js.map +1 -1
- package/dist/modules/access/render-roles-yaml.d.ts +22 -0
- package/dist/modules/access/render-roles-yaml.d.ts.map +1 -0
- package/dist/modules/access/render-roles-yaml.js +56 -0
- package/dist/modules/access/render-roles-yaml.js.map +1 -0
- package/dist/modules/access/roles-admin.service.d.ts +15 -1
- package/dist/modules/access/roles-admin.service.d.ts.map +1 -1
- package/dist/modules/access/roles-admin.service.js +30 -15
- package/dist/modules/access/roles-admin.service.js.map +1 -1
- package/dist/modules/settings/setup.routes.d.ts +10 -1
- package/dist/modules/settings/setup.routes.d.ts.map +1 -1
- package/dist/modules/settings/setup.routes.js +111 -6
- package/dist/modules/settings/setup.routes.js.map +1 -1
- package/dist/modules/workspace/startup/kb-git.d.ts +23 -0
- package/dist/modules/workspace/startup/kb-git.d.ts.map +1 -0
- package/dist/modules/workspace/startup/kb-git.js +86 -0
- package/dist/modules/workspace/startup/kb-git.js.map +1 -0
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts +74 -0
- package/dist/modules/workspace/startup/kb-startup-runner.d.ts.map +1 -0
- package/dist/modules/workspace/startup/kb-startup-runner.js +528 -0
- package/dist/modules/workspace/startup/kb-startup-runner.js.map +1 -0
- package/dist/modules/workspace/startup/on-server-start.d.ts +105 -0
- package/dist/modules/workspace/startup/on-server-start.d.ts.map +1 -0
- package/dist/modules/workspace/startup/on-server-start.js +21 -0
- package/dist/modules/workspace/startup/on-server-start.js.map +1 -0
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts +46 -0
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts.map +1 -0
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js +492 -0
- package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js.map +1 -0
- package/dist/modules/workspace/startup/steps/roles-yaml.step.d.ts +23 -0
- package/dist/modules/workspace/startup/steps/roles-yaml.step.d.ts.map +1 -0
- package/dist/modules/workspace/startup/steps/roles-yaml.step.js +69 -0
- package/dist/modules/workspace/startup/steps/roles-yaml.step.js.map +1 -0
- package/dist/modules/workspace/startup/steps/seed-tree.d.ts +17 -0
- package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -0
- package/dist/modules/workspace/startup/steps/seed-tree.js +109 -0
- package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -0
- package/dist/modules/workspace/startup/steps/template-files.step.d.ts +103 -0
- package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -0
- package/dist/modules/workspace/startup/steps/template-files.step.js +337 -0
- package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -0
- package/dist/modules/workspace/workspace.service.d.ts +0 -35
- package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.service.js +2 -101
- package/dist/modules/workspace/workspace.service.js.map +1 -1
- package/kb-template/gitignore.template +16 -0
- package/package.json +3 -3
- package/src/core/core-ports.ts +7 -0
- package/src/core/create-core-server.ts +30 -11
- package/src/core/create-core-services.ts +43 -22
- package/src/modules/access/__tests__/roles-admin.service.test.ts +24 -2
- package/src/modules/access/access.routes.ts +3 -0
- package/src/modules/access/render-roles-yaml.ts +65 -0
- package/src/modules/access/roles-admin.service.ts +32 -14
- package/src/modules/settings/__tests__/setup.routes.test.ts +124 -3
- package/src/modules/settings/setup.routes.ts +112 -5
- package/src/modules/workspace/__tests__/workspace.service.test.ts +5 -94
- package/src/modules/workspace/startup/__tests__/kb-startup-runner.test.ts +495 -0
- package/src/modules/workspace/startup/kb-git.ts +94 -0
- package/src/modules/workspace/startup/kb-startup-runner.ts +597 -0
- package/src/modules/workspace/startup/on-server-start.ts +97 -0
- package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +636 -0
- package/src/modules/workspace/{plugins-migration.ts → startup/steps/groups-to-plugins.step.ts} +342 -260
- package/src/modules/workspace/startup/steps/roles-yaml.step.ts +71 -0
- package/src/modules/workspace/startup/steps/seed-tree.ts +115 -0
- package/src/modules/workspace/startup/steps/template-files.step.ts +360 -0
- package/src/modules/workspace/workspace.service.ts +2 -106
- package/src/modules/workspace/__tests__/kb-seed.service.test.ts +0 -512
- package/src/modules/workspace/__tests__/plugins-migration.test.ts +0 -427
- package/src/modules/workspace/kb-seed.interface.ts +0 -36
- package/src/modules/workspace/kb-seed.service.ts +0 -584
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { HEXIS_EXTENSION_NS, HEXIS_TOOLS_DIR, LEGACY_GROUPS_DIR, PLUGINS_DIR, PLUGIN_MANIFEST_FILE, PLUGIN_MCP_FILE, PLUGIN_MCP_SCHEMA, PLUGIN_SKILLS_DIR, renderPluginManifest, } from '@bevel-software/platform-shared';
|
|
4
|
+
import { normalizeToolManual } from '../../../tool-manuals/tool-manuals.service.js';
|
|
5
|
+
import { parseOwnAccessEntries } from '../../../access/access-control.service.js';
|
|
6
|
+
import { containsVariableReference } from '../../../../shared/variable-refs.js';
|
|
7
|
+
import { IGNORE_FILENAME } from '../../bevel-ignore.js';
|
|
8
|
+
/**
|
|
9
|
+
* One-way migration of a knowledge base from `Groups/` to the Agent Plugins
|
|
10
|
+
* layout under `Plugins/` (https://agent-plugins.org, v1.0.0), as an
|
|
11
|
+
* {@link OnServerStart} step. (It began life as an in-place module run from
|
|
12
|
+
* the lazy top-up; that path is gone, and this is the only form.) Steps
|
|
13
|
+
* never write: every change is DECLARED on the branch handle
|
|
14
|
+
* (`move`/`write`/`remove`) and the runner applies it, while every read goes
|
|
15
|
+
* against the real, pre-step tree via `repoDir()`.
|
|
16
|
+
*
|
|
17
|
+
* Idempotent: a KB already on the new layout is untouched, and a half-finished
|
|
18
|
+
* run is completed by the next one.
|
|
19
|
+
*
|
|
20
|
+
* What moves — and what CONVERTS:
|
|
21
|
+
*
|
|
22
|
+
* Groups/GTM/access.md → Plugins/GTM/access.md (stays put)
|
|
23
|
+
* Groups/GTM/deploy/SKILL.md → Plugins/GTM/skills/deploy/SKILL.md
|
|
24
|
+
* Groups/GTM/web-search.tool → Plugins/GTM/software.bevel.hexis/tools/web-search.tool
|
|
25
|
+
* Groups/GTM/notion.tool (mcp) → an entry in Plugins/GTM/mcp.json, and the
|
|
26
|
+
* `.tool` file is DELETED — mcp.json is
|
|
27
|
+
* authoritative for MCP servers now.
|
|
28
|
+
* Plugins/GTM/plugin.json (written)
|
|
29
|
+
*
|
|
30
|
+
* The mcp.json entry is keyed by the `.tool`'s manual id: that id is the
|
|
31
|
+
* namespace vault secrets bind to (`<id>_<VAR>`), so keeping it is what keeps
|
|
32
|
+
* every configured secret and completed OAuth grant bound. What mcp.json
|
|
33
|
+
* cannot carry — auth headers with `${VAR}` references, variable declarations,
|
|
34
|
+
* the local-only flag — moves into `plugin.json`'s
|
|
35
|
+
* `extensions["software.bevel.hexis"].mcpServers[<id>]` block, the reverse-DNS
|
|
36
|
+
* namespace the spec reserves for client-specific data. `http`/`inline`
|
|
37
|
+
* manuals still MOVE as `.tool` files: nothing but this platform can run them.
|
|
38
|
+
*
|
|
39
|
+
* Scope: EVERY branch, drafts included and writable (`ctx.allBranches()`) —
|
|
40
|
+
* maintenance applied uniformly at the quiet moment is what keeps a draft's
|
|
41
|
+
* change-request diff down to the user's own changes; a stale draft against a
|
|
42
|
+
* migrated target would diff by the whole rename.
|
|
43
|
+
*
|
|
44
|
+
* Outcomes: a per-manual NOT-converted refusal makes the step `partial` with
|
|
45
|
+
* the reasons (the declared ops for everything else still apply); a branch
|
|
46
|
+
* carrying BOTH roots contributes nothing but a note; everything else is `ok`.
|
|
47
|
+
*/
|
|
48
|
+
export class GroupsToPluginsStep {
|
|
49
|
+
name = 'groups-to-plugins';
|
|
50
|
+
async run(ctx) {
|
|
51
|
+
const refusals = [];
|
|
52
|
+
for (const branch of await ctx.allBranches()) {
|
|
53
|
+
await migrateBranch(branch, refusals);
|
|
54
|
+
}
|
|
55
|
+
return refusals.length > 0 ? { outcome: 'partial', reason: refusals.join('; ') } : { outcome: 'ok' };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// lstat, both helpers: SYMLINKS ARE NOT SUPPORTED IN PLUGINS, anywhere, so a
|
|
59
|
+
// link never counts as the thing it points at — following one here would let
|
|
60
|
+
// a symlinked directory pull files from outside the plugin into the sweep
|
|
61
|
+
// (and delete them from wherever they really live).
|
|
62
|
+
async function exists(p) {
|
|
63
|
+
try {
|
|
64
|
+
await fs.lstat(p);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function isDir(p) {
|
|
72
|
+
try {
|
|
73
|
+
return (await fs.lstat(p)).isDirectory();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A header value referencing a vault variable rather than carrying a literal.
|
|
81
|
+
* The substitutor's own grammar decides (shared/variable-refs.ts): both
|
|
82
|
+
* spellings it expands — `${VAR}` and bare `$VAR`, digit-leading names
|
|
83
|
+
* included — count, because either one copied into mcp.json would be
|
|
84
|
+
* transmitted verbatim by a conformant client. That means a prose `$5` in a
|
|
85
|
+
* header routes to the non-portable half too: over-classifying costs a header
|
|
86
|
+
* its portability, under-classifying leaks whatever `$5TOKEN` expands to.
|
|
87
|
+
*/
|
|
88
|
+
const isCredentialReference = containsVariableReference;
|
|
89
|
+
/** Split a manual's headers into what mcp.json may carry and what may not. */
|
|
90
|
+
function splitHeaders(headers) {
|
|
91
|
+
const literal = {};
|
|
92
|
+
const credential = {};
|
|
93
|
+
for (const [k, v] of Object.entries(headers ?? {})) {
|
|
94
|
+
(isCredentialReference(v) ? credential : literal)[k] = v;
|
|
95
|
+
}
|
|
96
|
+
return { literal, credential };
|
|
97
|
+
}
|
|
98
|
+
/** Read+parse a JSON file, or `null` when absent or unparsable. */
|
|
99
|
+
async function readJson(p) {
|
|
100
|
+
try {
|
|
101
|
+
const parsed = JSON.parse(await fs.readFile(p, 'utf-8'));
|
|
102
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
|
|
103
|
+
? parsed
|
|
104
|
+
: null;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Parse a `.tool`; a convertible MCP manual (has a url) parses to a
|
|
112
|
+
* descriptor. A non-candidate (other types, a file that will not parse)
|
|
113
|
+
* is `null` and moves as a plain `.tool`; an MCP manual REFUSED conversion
|
|
114
|
+
* comes back as the reason string, so the migration log distinguishes a
|
|
115
|
+
* deliberately-retained integration from one that silently failed — the
|
|
116
|
+
* same courtesy the manifest-missing refusal already extends.
|
|
117
|
+
*/
|
|
118
|
+
async function asMcpManual(abs, repoRel) {
|
|
119
|
+
try {
|
|
120
|
+
const content = await fs.readFile(abs, 'utf-8');
|
|
121
|
+
const d = normalizeToolManual(path.basename(abs).replace(/\.tool$/i, ''), repoRel, content);
|
|
122
|
+
// The mcp.json loader accepts only names it can serve as a namespace and
|
|
123
|
+
// route slug — converting a manual whose id fails that shape would DELETE
|
|
124
|
+
// a working integration and write an entry discovery then skips. Such a
|
|
125
|
+
// manual stays a `.tool`.
|
|
126
|
+
if (d.type !== 'mcp' || !d.url)
|
|
127
|
+
return null;
|
|
128
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(d.name)) {
|
|
129
|
+
return `its id "${d.name}" is not a valid mcp.json server name`;
|
|
130
|
+
}
|
|
131
|
+
// Same refusal for the url: the mcp.json loader accepts only a directly
|
|
132
|
+
// parseable http(s) url, so a templated one (`${BASE}/mcp` — legal in a
|
|
133
|
+
// `.tool`, where the substitutor expands it) would convert into an entry
|
|
134
|
+
// discovery then skips, with the source already deleted. And a parseable
|
|
135
|
+
// url carrying `user:pass@` may not land in the PORTABLE file at all —
|
|
136
|
+
// stripping it would break the server, so the manual keeps its `.tool`
|
|
137
|
+
// form, where the credential stays platform-internal.
|
|
138
|
+
let url;
|
|
139
|
+
try {
|
|
140
|
+
url = new URL(d.url);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return 'its url is not directly parseable (a templated url only a .tool can carry)';
|
|
144
|
+
}
|
|
145
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
146
|
+
return `its url scheme "${url.protocol}" cannot land in mcp.json (http(s) only)`;
|
|
147
|
+
}
|
|
148
|
+
if (url.username || url.password) {
|
|
149
|
+
return 'its url embeds credentials, which may not land in the portable mcp.json';
|
|
150
|
+
}
|
|
151
|
+
// A `.tool` can gate ITSELF with frontmatter access verbs, read by the
|
|
152
|
+
// access resolver from the file's own path. An mcp.json entry has no
|
|
153
|
+
// per-server home for those — the file's ACL governs every server in it —
|
|
154
|
+
// so converting would silently widen who may configure and run the
|
|
155
|
+
// server. Such a manual stays a `.tool`, verbs and all.
|
|
156
|
+
if (parseOwnAccessEntries(content) !== null) {
|
|
157
|
+
return 'it gates itself with frontmatter access verbs, which mcp.json cannot carry';
|
|
158
|
+
}
|
|
159
|
+
return d;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Migrate one branch. Declares ops only; a branch whose migration declares
|
|
167
|
+
* nothing stays clean, so a notes-only pass (advisory refusals) commits
|
|
168
|
+
* nothing — the same contract the in-place migration's `migrated` flag
|
|
169
|
+
* carried.
|
|
170
|
+
*/
|
|
171
|
+
async function migrateBranch(branch, refusals) {
|
|
172
|
+
const repoDir = await branch.repoDir();
|
|
173
|
+
const legacyDir = path.join(repoDir, LEGACY_GROUPS_DIR);
|
|
174
|
+
const pluginsDir = path.join(repoDir, PLUGINS_DIR);
|
|
175
|
+
const hasLegacy = await isDir(legacyDir);
|
|
176
|
+
const hasPlugins = await isDir(pluginsDir);
|
|
177
|
+
// `hasPlugins` is false for a FILE or SYMLINK squatting the `Plugins` name.
|
|
178
|
+
// Checked BEFORE the nothing-to-do early return below: a branch with a
|
|
179
|
+
// squatter and NO Groups/ would otherwise be silently skipped (and on a
|
|
180
|
+
// draft nothing later ever reports it), while a branch mid-migration would
|
|
181
|
+
// die in the applier with a bare ENOTDIR. Throw the actionable version
|
|
182
|
+
// either way: under the phase's fail-closed contract this stops the boot,
|
|
183
|
+
// which a squatted reserved root deserves (same stance as
|
|
184
|
+
// template-files.step.ts's reserved-dir check).
|
|
185
|
+
if (!hasPlugins && (await exists(pluginsDir))) {
|
|
186
|
+
throw new Error(`Branch "${branch.name}": "${PLUGINS_DIR}" exists but is not a directory` +
|
|
187
|
+
(hasLegacy ? `, so ${LEGACY_GROUPS_DIR}/ cannot be renamed to ${PLUGINS_DIR}/` : '') +
|
|
188
|
+
`. Remove or rename the "${PLUGINS_DIR}" entry — the platform requires this name to be a folder.`);
|
|
189
|
+
}
|
|
190
|
+
if (hasLegacy && hasPlugins) {
|
|
191
|
+
// Both present: somebody is mid-migration by hand, or two branches merged
|
|
192
|
+
// badly. Merging them here would guess at which copy of a same-named
|
|
193
|
+
// plugin wins, so we refuse and say so — loudly, because the KB is in a
|
|
194
|
+
// state a human needs to look at. The branch contributes no ops, only a
|
|
195
|
+
// note (which surfaces in a commit only if a later step dirties it).
|
|
196
|
+
console.warn(`[groups-to-plugins] ${branch.name}: both ${LEGACY_GROUPS_DIR}/ and ${PLUGINS_DIR}/ exist — leaving both alone. ` +
|
|
197
|
+
`Merge ${LEGACY_GROUPS_DIR}/ into ${PLUGINS_DIR}/ by hand; nothing is being migrated automatically.`);
|
|
198
|
+
branch.note(`${LEGACY_GROUPS_DIR}/ and ${PLUGINS_DIR}/ both exist — merge by hand; nothing was migrated automatically`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!hasLegacy && !hasPlugins)
|
|
202
|
+
return;
|
|
203
|
+
// Every read below goes against the PRE-STEP tree: when the root rename is
|
|
204
|
+
// declared this run it is NOT yet on disk, so the plugin folders are still
|
|
205
|
+
// read under their legacy root while every declared op speaks post-rename
|
|
206
|
+
// `Plugins/…` paths — the root move is declared FIRST, so by the time the
|
|
207
|
+
// per-folder ops apply, the tree is already under `Plugins/`.
|
|
208
|
+
const rootOnDisk = hasLegacy ? legacyDir : pluginsDir;
|
|
209
|
+
// Detail notes are held back until we know ops were declared: the subject
|
|
210
|
+
// line must describe a commit that will actually exist.
|
|
211
|
+
const details = [];
|
|
212
|
+
let changed = false;
|
|
213
|
+
if (hasLegacy) {
|
|
214
|
+
// The Groups→Plugins root rename is ONE declared op, directory and all.
|
|
215
|
+
branch.move(LEGACY_GROUPS_DIR, PLUGINS_DIR);
|
|
216
|
+
details.push(`${LEGACY_GROUPS_DIR}/ → ${PLUGINS_DIR}/`);
|
|
217
|
+
changed = true;
|
|
218
|
+
// Rides WITH the rename, not on every run: the rename is what turned the
|
|
219
|
+
// ignore rule stale, so the run that renames is the run that heals it.
|
|
220
|
+
changed = (await rewriteIgnoreRootRule(repoDir, branch, details)) || changed;
|
|
221
|
+
}
|
|
222
|
+
// Runs whether or not the rename just happened, so a KB already on
|
|
223
|
+
// `Plugins/` still gets missing manifests and any half-done reorganisation
|
|
224
|
+
// finished. That is what makes this idempotent rather than once-only.
|
|
225
|
+
for (const entry of await fs.readdir(rootOnDisk, { withFileTypes: true })) {
|
|
226
|
+
if (!entry.isDirectory() || entry.name.startsWith('.'))
|
|
227
|
+
continue;
|
|
228
|
+
const folderChanged = await migratePluginFolder(branch, path.join(rootOnDisk, entry.name), entry.name, details, refusals);
|
|
229
|
+
changed = changed || folderChanged;
|
|
230
|
+
}
|
|
231
|
+
if (!changed)
|
|
232
|
+
return;
|
|
233
|
+
// First note becomes the commit subject — the same messages the lazy
|
|
234
|
+
// top-up committed under; the detail notes become its body.
|
|
235
|
+
branch.note(hasLegacy
|
|
236
|
+
? `Move ${LEGACY_GROUPS_DIR}/ to ${PLUGINS_DIR}/ (Agent Plugins layout)`
|
|
237
|
+
: `Reorganise ${PLUGINS_DIR}/ to the Agent Plugins layout`);
|
|
238
|
+
for (const line of details)
|
|
239
|
+
branch.note(line);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Rewrite the KB's `.bevelignore` rule for the renamed root: the exact line
|
|
243
|
+
* `Groups/` becomes `Plugins/`. Without this a migrated KB is left with a
|
|
244
|
+
* stale rule for a folder that no longer exists and NO rule for the new one,
|
|
245
|
+
* so plugin internals start showing up in the file tree and agent view.
|
|
246
|
+
*
|
|
247
|
+
* The file is the operator's — this touches ONE line, the one the platform's
|
|
248
|
+
* own rename invalidated, and only when `Plugins/` is not already listed
|
|
249
|
+
* (in which case the stale line is harmlessly dead and left alone).
|
|
250
|
+
*/
|
|
251
|
+
async function rewriteIgnoreRootRule(repoDir, branch, details) {
|
|
252
|
+
let current;
|
|
253
|
+
try {
|
|
254
|
+
current = await fs.readFile(path.join(repoDir, IGNORE_FILENAME), 'utf-8');
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return false; // no ignore file — nothing went stale
|
|
258
|
+
}
|
|
259
|
+
const legacyRule = `${LEGACY_GROUPS_DIR}/`;
|
|
260
|
+
const newRule = `${PLUGINS_DIR}/`;
|
|
261
|
+
const lines = current.split('\n');
|
|
262
|
+
if (lines.some((l) => l.trim() === newRule))
|
|
263
|
+
return false;
|
|
264
|
+
const idx = lines.findIndex((l) => l.trim() === legacyRule);
|
|
265
|
+
if (idx === -1)
|
|
266
|
+
return false;
|
|
267
|
+
// EVERY exact-match line follows the rename: the first becomes the new
|
|
268
|
+
// rule, any further duplicates are dropped — rewriting only the first would
|
|
269
|
+
// leave stale `Groups/` lines behind, and the already-has-Plugins guard
|
|
270
|
+
// above means a second pass would never touch them.
|
|
271
|
+
lines[idx] = newRule;
|
|
272
|
+
const rewritten = lines.filter((l, i) => i <= idx || l.trim() !== legacyRule);
|
|
273
|
+
branch.write(IGNORE_FILENAME, rewritten.join('\n'));
|
|
274
|
+
details.push(`${IGNORE_FILENAME}: ${legacyRule} → ${newRule}`);
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Reorganise ONE plugin folder. `folderDir` is where the folder sits ON DISK
|
|
279
|
+
* (under the legacy root when the rename is buffered this run); declared op
|
|
280
|
+
* paths always speak `Plugins/<folder>/…`. Returns whether ops were declared.
|
|
281
|
+
*/
|
|
282
|
+
async function migratePluginFolder(branch, folderDir, folderName, details, refusals) {
|
|
283
|
+
const relPlugin = `${PLUGINS_DIR}/${folderName}`;
|
|
284
|
+
let changed = false;
|
|
285
|
+
// When the manifest is written this run its content is remembered: the
|
|
286
|
+
// buffered write is not on disk yet, and the fold below must see it.
|
|
287
|
+
let renderedManifest = null;
|
|
288
|
+
if (!(await exists(path.join(folderDir, PLUGIN_MANIFEST_FILE)))) {
|
|
289
|
+
renderedManifest = renderPluginManifest(folderName);
|
|
290
|
+
branch.write(`${relPlugin}/${PLUGIN_MANIFEST_FILE}`, renderedManifest);
|
|
291
|
+
details.push(`${folderName}: wrote ${PLUGIN_MANIFEST_FILE}`);
|
|
292
|
+
changed = true;
|
|
293
|
+
}
|
|
294
|
+
const entries = await fs.readdir(folderDir, { withFileTypes: true });
|
|
295
|
+
const converted = [];
|
|
296
|
+
const convertOrMove = async (abs, rel, note) => {
|
|
297
|
+
const manual = await asMcpManual(abs, rel);
|
|
298
|
+
if (manual !== null && typeof manual !== 'string') {
|
|
299
|
+
// QUEUED for conversion — the `.tool`'s removal is declared only AFTER
|
|
300
|
+
// its entry's writes (see foldIntoPluginFiles). Buffering makes the
|
|
301
|
+
// apply all-or-nothing anyway, but the declaration order keeps the old
|
|
302
|
+
// recovery reasoning legible: the file IS the recovery path until the
|
|
303
|
+
// fold has landed.
|
|
304
|
+
converted.push({ manual, rel, note });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (typeof manual === 'string') {
|
|
308
|
+
// The operator's answer to "why is this integration not in mcp.json":
|
|
309
|
+
// a refused conversion must read as the deliberate retention it is —
|
|
310
|
+
// surfaced through the step's `partial` reason rather than a note, so
|
|
311
|
+
// it names what did NOT change instead of decorating a commit.
|
|
312
|
+
refusals.push(`${branch.name}: ${folderName}: ${note} NOT converted — ${manual}; kept as a .tool`);
|
|
313
|
+
}
|
|
314
|
+
const destDisk = path.join(folderDir, ...HEXIS_TOOLS_DIR.split('/'), path.basename(abs));
|
|
315
|
+
// Never overwrite: a destination that already exists means a previous run
|
|
316
|
+
// got there first (or a human did), and clobbering it would destroy the
|
|
317
|
+
// newer copy. The check is against the pre-step tree — the only tree that
|
|
318
|
+
// exists while this step runs.
|
|
319
|
+
if (abs !== destDisk && !(await exists(destDisk))) {
|
|
320
|
+
branch.move(rel, `${relPlugin}/${HEXIS_TOOLS_DIR}/${path.basename(abs)}`);
|
|
321
|
+
details.push(`${folderName}: ${note} → ${HEXIS_TOOLS_DIR}/${path.basename(abs)}`);
|
|
322
|
+
changed = true;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
for (const entry of entries) {
|
|
326
|
+
if (entry.name.startsWith('.'))
|
|
327
|
+
continue;
|
|
328
|
+
if (entry.name === PLUGIN_SKILLS_DIR || entry.name === PLUGIN_MANIFEST_FILE)
|
|
329
|
+
continue;
|
|
330
|
+
if (entry.name === PLUGIN_MCP_FILE || entry.name === 'access.md')
|
|
331
|
+
continue;
|
|
332
|
+
if (entry.name === HEXIS_TOOLS_DIR.split('/')[0])
|
|
333
|
+
continue;
|
|
334
|
+
const abs = path.join(folderDir, entry.name);
|
|
335
|
+
// A skill is a folder carrying SKILL.md — the same rule the catalog uses.
|
|
336
|
+
if (entry.isDirectory() && (await exists(path.join(abs, 'SKILL.md')))) {
|
|
337
|
+
if (!(await exists(path.join(folderDir, PLUGIN_SKILLS_DIR, entry.name)))) {
|
|
338
|
+
branch.move(`${relPlugin}/${entry.name}`, `${relPlugin}/${PLUGIN_SKILLS_DIR}/${entry.name}`);
|
|
339
|
+
details.push(`${folderName}: ${entry.name}/ → ${PLUGIN_SKILLS_DIR}/${entry.name}/`);
|
|
340
|
+
changed = true;
|
|
341
|
+
}
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (entry.isFile() && entry.name.toLowerCase().endsWith('.tool')) {
|
|
345
|
+
await convertOrMove(abs, `${relPlugin}/${entry.name}`, entry.name);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// Second sweep: mcp `.tool`s an EARLIER run moved into the extension dir
|
|
349
|
+
// (when mcp.json was a projection, not the authority). Converting them here
|
|
350
|
+
// is what makes the migration complete itself rather than strand a twin.
|
|
351
|
+
// `isDir` is lstat-based, so a SYMLINK planted at this path is not swept:
|
|
352
|
+
// this sweep DELETES what it converts, and following a link would delete
|
|
353
|
+
// `.tool` files from wherever the link really points.
|
|
354
|
+
//
|
|
355
|
+
// Under buffered ops this sweep reads the PRE-STEP tree, so a `.tool` the
|
|
356
|
+
// first sweep just declared moved here is not visible — and does not need
|
|
357
|
+
// to be: same-run movables were already converted or refused by the same
|
|
358
|
+
// `asMcpManual` logic above. The sweep exists for files parked by EARLIER
|
|
359
|
+
// runs, which are on disk. (The old in-place code happened to re-see
|
|
360
|
+
// same-run moves and no-op on them; the buffered read makes that a
|
|
361
|
+
// non-event by construction.)
|
|
362
|
+
const extToolsDir = path.join(folderDir, ...HEXIS_TOOLS_DIR.split('/'));
|
|
363
|
+
if (await isDir(extToolsDir)) {
|
|
364
|
+
for (const entry of await fs.readdir(extToolsDir, { withFileTypes: true })) {
|
|
365
|
+
if (!entry.isFile() || !entry.name.toLowerCase().endsWith('.tool'))
|
|
366
|
+
continue;
|
|
367
|
+
const abs = path.join(extToolsDir, entry.name);
|
|
368
|
+
const rel = `${relPlugin}/${HEXIS_TOOLS_DIR}/${entry.name}`;
|
|
369
|
+
const manual = await asMcpManual(abs, rel);
|
|
370
|
+
// A refusal reason here is a SETTLED resident of the tools dir — it
|
|
371
|
+
// was named the run it moved in, and this sweep repeats every boot,
|
|
372
|
+
// so re-raising it would be log spam. Only a convertible manual queues.
|
|
373
|
+
if (manual !== null && typeof manual !== 'string') {
|
|
374
|
+
converted.push({ manual, rel, note: `${HEXIS_TOOLS_DIR}/${entry.name}` });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
changed =
|
|
379
|
+
(await foldIntoPluginFiles(branch, folderDir, relPlugin, folderName, renderedManifest, converted, details, refusals)) ||
|
|
380
|
+
changed;
|
|
381
|
+
return changed;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Fold converted mcp manuals into the plugin's mcp.json and plugin.json.
|
|
385
|
+
*
|
|
386
|
+
* MERGE, never clobber: an entry already present under a manual's key — hand
|
|
387
|
+
* written or from a previous run — wins, because overwriting it would discard
|
|
388
|
+
* the newer intent. The extension block merges the same way. A plugin.json
|
|
389
|
+
* that does not parse costs the extension write (logged), not the migration.
|
|
390
|
+
*/
|
|
391
|
+
async function foldIntoPluginFiles(branch, folderDir, relPlugin, folderName, renderedManifest, manuals, details, refusals) {
|
|
392
|
+
if (manuals.length === 0)
|
|
393
|
+
return false;
|
|
394
|
+
const mcp = (await readJson(path.join(folderDir, PLUGIN_MCP_FILE))) ?? {
|
|
395
|
+
$schema: PLUGIN_MCP_SCHEMA,
|
|
396
|
+
mcpServers: {},
|
|
397
|
+
};
|
|
398
|
+
// An array (or any non-object) here would take property assignments and then
|
|
399
|
+
// drop them at stringify — normalize to an object before merging into it.
|
|
400
|
+
if (typeof mcp.mcpServers !== 'object' || mcp.mcpServers === null || Array.isArray(mcp.mcpServers)) {
|
|
401
|
+
mcp.mcpServers = {};
|
|
402
|
+
}
|
|
403
|
+
const servers = mcp.mcpServers;
|
|
404
|
+
// The manifest may have been DECLARED this very run — a buffered write not
|
|
405
|
+
// yet on disk. Reading the disk then would see "missing" and refuse
|
|
406
|
+
// conversions the write-then-read in-place code performed, so the step's
|
|
407
|
+
// own rendered content stands in for the tree it is about to produce.
|
|
408
|
+
const manifest = renderedManifest !== null
|
|
409
|
+
? JSON.parse(renderedManifest)
|
|
410
|
+
: await readJson(path.join(folderDir, PLUGIN_MANIFEST_FILE));
|
|
411
|
+
if (manifest === null) {
|
|
412
|
+
console.warn(`[groups-to-plugins] ${branch.name}: ${folderName}/${PLUGIN_MANIFEST_FILE} is missing or unparsable — ` +
|
|
413
|
+
'mcp manuals convert only when they carry NOTHING for the extensions block; any ' +
|
|
414
|
+
'non-portable half (auth headers, variables, a description, or the local-only flag) ' +
|
|
415
|
+
'keeps the manual a `.tool` until the manifest is fixed.');
|
|
416
|
+
}
|
|
417
|
+
let wroteMcp = false;
|
|
418
|
+
let wroteManifest = false;
|
|
419
|
+
const folded = [];
|
|
420
|
+
for (const item of manuals.sort((a, b) => a.manual.name.localeCompare(b.manual.name))) {
|
|
421
|
+
const m = item.manual;
|
|
422
|
+
const { literal, credential } = splitHeaders(m.headers);
|
|
423
|
+
// A manual whose non-portable half (auth headers, variables, local flag)
|
|
424
|
+
// has nowhere to go — the manifest is missing or unparsable — is NOT
|
|
425
|
+
// converted at all: writing only its portable half and deleting the
|
|
426
|
+
// source would silently discard the credential wiring. It stays a
|
|
427
|
+
// `.tool` until the manifest is fixed.
|
|
428
|
+
const extEntry = {
|
|
429
|
+
...(Object.keys(credential).length > 0 ? { headers: credential } : {}),
|
|
430
|
+
...(m.variables && m.variables.length > 0 ? { variables: m.variables } : {}),
|
|
431
|
+
...(typeof m.description === 'string' ? { description: m.description } : {}),
|
|
432
|
+
...(m.remote === false ? { local: true } : {}),
|
|
433
|
+
};
|
|
434
|
+
if (manifest === null && Object.keys(extEntry).length > 0) {
|
|
435
|
+
refusals.push(`${branch.name}: ${folderName}: ${item.note} NOT converted — ${PLUGIN_MANIFEST_FILE} is missing/unparsable ` +
|
|
436
|
+
'and the manual carries declarations (auth headers, variables, a description, or the ' +
|
|
437
|
+
'local-only flag) that would be lost; fix the manifest first');
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
folded.push(item);
|
|
441
|
+
// Own-property check: `in` sees `constructor` and friends on the prototype,
|
|
442
|
+
// which would silently skip a legitimately named server.
|
|
443
|
+
if (!Object.prototype.hasOwnProperty.call(servers, m.name)) {
|
|
444
|
+
servers[m.name] = {
|
|
445
|
+
type: 'streamable-http',
|
|
446
|
+
url: m.url,
|
|
447
|
+
...(Object.keys(literal).length > 0 ? { headers: literal } : {}),
|
|
448
|
+
};
|
|
449
|
+
wroteMcp = true;
|
|
450
|
+
details.push(`${folderName}: ${m.name} → ${PLUGIN_MCP_FILE}`);
|
|
451
|
+
}
|
|
452
|
+
// The non-portable half: auth headers, variable declarations, local-only.
|
|
453
|
+
if (manifest !== null && Object.keys(extEntry).length > 0) {
|
|
454
|
+
// Normalize each level: a parseable manifest can still carry a string or
|
|
455
|
+
// array where an object belongs, and mutating that would throw mid-run.
|
|
456
|
+
if (typeof manifest.extensions !== 'object' || manifest.extensions === null || Array.isArray(manifest.extensions)) {
|
|
457
|
+
manifest.extensions = {};
|
|
458
|
+
}
|
|
459
|
+
const ext = manifest.extensions;
|
|
460
|
+
if (typeof ext[HEXIS_EXTENSION_NS] !== 'object' || ext[HEXIS_EXTENSION_NS] === null || Array.isArray(ext[HEXIS_EXTENSION_NS])) {
|
|
461
|
+
ext[HEXIS_EXTENSION_NS] = {};
|
|
462
|
+
}
|
|
463
|
+
const ns = ext[HEXIS_EXTENSION_NS];
|
|
464
|
+
if (typeof ns.mcpServers !== 'object' || ns.mcpServers === null || Array.isArray(ns.mcpServers)) {
|
|
465
|
+
ns.mcpServers = {};
|
|
466
|
+
}
|
|
467
|
+
const extServers = ns.mcpServers;
|
|
468
|
+
if (!Object.prototype.hasOwnProperty.call(extServers, m.name)) {
|
|
469
|
+
extServers[m.name] = extEntry;
|
|
470
|
+
wroteManifest = true;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (wroteMcp) {
|
|
475
|
+
branch.write(`${relPlugin}/${PLUGIN_MCP_FILE}`, `${JSON.stringify(mcp, null, 2)}\n`);
|
|
476
|
+
}
|
|
477
|
+
if (wroteManifest) {
|
|
478
|
+
// May supersede the bare manifest declared above — ops apply in order, so
|
|
479
|
+
// the extended content is what lands.
|
|
480
|
+
branch.write(`${relPlugin}/${PLUGIN_MANIFEST_FILE}`, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
481
|
+
details.push(`${folderName}: wrote mcp-server declarations into ${PLUGIN_MANIFEST_FILE}`);
|
|
482
|
+
}
|
|
483
|
+
// Sources go LAST in declaration order, once everything they carried has
|
|
484
|
+
// been declared elsewhere — the same shape the in-place code used so a
|
|
485
|
+
// failure never stranded the non-portable half with no source to retry from.
|
|
486
|
+
for (const item of folded) {
|
|
487
|
+
branch.remove(item.rel);
|
|
488
|
+
details.push(`${folderName}: ${item.note} converted to an ${PLUGIN_MCP_FILE} entry`);
|
|
489
|
+
}
|
|
490
|
+
return wroteMcp || wroteManifest || folded.length > 0;
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=groups-to-plugins.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groups-to-plugins.step.js","sourceRoot":"","sources":["../../../../../src/modules/workspace/startup/steps/groups-to-plugins.step.ts"],"names":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IAAI,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,aAAa,EAAE,CAAC;QAClB,0EAA0E;QAC1E,sCAAsC;QACtC,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,IAAI,oBAAoB,EAAE,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/F,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,wCAAwC,oBAAoB,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,yEAAyE;IACzE,uEAAuE;IACvE,6EAA6E;IAC7E,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,KAAK,IAAI,CAAC,IAAI,oBAAoB,eAAe,QAAQ,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,QAAQ,IAAI,aAAa,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OnServerStart, ServerStartContext, StepResult } from '../on-server-start.js';
|
|
2
|
+
/**
|
|
3
|
+
* Write `roles.yaml` on any protected branch missing it, generated from the
|
|
4
|
+
* configured seed admins (`ADMIN_EMAIL`) via the shared validated renderer
|
|
5
|
+
* (../../../access/render-roles-yaml.ts — a malformed email stops the boot
|
|
6
|
+
* with a message naming the fix). Never part of the template: a template copy
|
|
7
|
+
* would seed repos with a stale hard-coded Admin list.
|
|
8
|
+
*
|
|
9
|
+
* An existing regular file — whatever it says — is the operator's and is left
|
|
10
|
+
* alone.
|
|
11
|
+
*
|
|
12
|
+
* A missing file with NO admins configured is a declared `skipped`: the lazy
|
|
13
|
+
* top-up warned and left the file absent, and under the startup contract that
|
|
14
|
+
* survivable-but-incomplete state is the step's to declare, not to bury in a
|
|
15
|
+
* log. Access resolution will fail until an Admin roles.yaml exists.
|
|
16
|
+
*/
|
|
17
|
+
export declare class RolesYamlStep implements OnServerStart {
|
|
18
|
+
private readonly seedAdminEmails;
|
|
19
|
+
readonly name = "roles-yaml";
|
|
20
|
+
constructor(seedAdminEmails: readonly string[]);
|
|
21
|
+
run(ctx: ServerStartContext): Promise<StepResult>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=roles-yaml.step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-yaml.step.d.ts","sourceRoot":"","sources":["../../../../../src/modules/workspace/startup/steps/roles-yaml.step.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE3F;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAc,YAAW,aAAa;IAGrC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAF5C,QAAQ,CAAC,IAAI,gBAAgB;gBAEA,eAAe,EAAE,SAAS,MAAM,EAAE;IAEzD,GAAG,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAoCxD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { renderRolesYaml } from '../../../access/render-roles-yaml.js';
|
|
4
|
+
/**
|
|
5
|
+
* Write `roles.yaml` on any protected branch missing it, generated from the
|
|
6
|
+
* configured seed admins (`ADMIN_EMAIL`) via the shared validated renderer
|
|
7
|
+
* (../../../access/render-roles-yaml.ts — a malformed email stops the boot
|
|
8
|
+
* with a message naming the fix). Never part of the template: a template copy
|
|
9
|
+
* would seed repos with a stale hard-coded Admin list.
|
|
10
|
+
*
|
|
11
|
+
* An existing regular file — whatever it says — is the operator's and is left
|
|
12
|
+
* alone.
|
|
13
|
+
*
|
|
14
|
+
* A missing file with NO admins configured is a declared `skipped`: the lazy
|
|
15
|
+
* top-up warned and left the file absent, and under the startup contract that
|
|
16
|
+
* survivable-but-incomplete state is the step's to declare, not to bury in a
|
|
17
|
+
* log. Access resolution will fail until an Admin roles.yaml exists.
|
|
18
|
+
*/
|
|
19
|
+
export class RolesYamlStep {
|
|
20
|
+
seedAdminEmails;
|
|
21
|
+
name = 'roles-yaml';
|
|
22
|
+
constructor(seedAdminEmails) {
|
|
23
|
+
this.seedAdminEmails = seedAdminEmails;
|
|
24
|
+
}
|
|
25
|
+
async run(ctx) {
|
|
26
|
+
const adminless = [];
|
|
27
|
+
for (const branch of await ctx.protectedBranches()) {
|
|
28
|
+
const repoDir = await branch.repoDir();
|
|
29
|
+
// `lstat`, not `exists`: a DIRECTORY or SYMLINK squatting the name would
|
|
30
|
+
// read as "present" and be skipped over — reporting success over a
|
|
31
|
+
// knowledge base whose access roster cannot be read. Fail closed, same
|
|
32
|
+
// as template-files' squatter checks: this is a state a human must fix.
|
|
33
|
+
const found = await lstatOrNull(path.join(repoDir, 'roles.yaml'));
|
|
34
|
+
if (found) {
|
|
35
|
+
if (found.isFile())
|
|
36
|
+
continue; // the operator's file — leave it alone
|
|
37
|
+
throw new Error(`"roles.yaml" on branch "${branch.name}" exists but is not a regular file ` +
|
|
38
|
+
`(${found.isSymbolicLink() ? 'symlink' : found.isDirectory() ? 'directory' : 'special file'}). ` +
|
|
39
|
+
'Remove or rename it — access loading requires this name to be a readable file at the repository root.');
|
|
40
|
+
}
|
|
41
|
+
if (this.seedAdminEmails.length === 0) {
|
|
42
|
+
adminless.push(branch.name);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
branch.write('roles.yaml', renderRolesYaml(this.seedAdminEmails));
|
|
46
|
+
branch.note('Add roles.yaml granting Admin to the configured seed admins');
|
|
47
|
+
}
|
|
48
|
+
if (adminless.length > 0) {
|
|
49
|
+
// With an empty admin list nothing was declared for ANY branch, so the
|
|
50
|
+
// skip discards nothing another branch needed.
|
|
51
|
+
return {
|
|
52
|
+
outcome: 'skipped',
|
|
53
|
+
reason: `roles.yaml is missing on ${adminless.join(', ')} and ADMIN_EMAIL is unset — leaving it absent. ` +
|
|
54
|
+
'Access resolution will fail until an Admin roles.yaml exists; set ADMIN_EMAIL or add roles.yaml manually.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return { outcome: 'ok' };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** `lstat` without the throw — null when nothing is at `p`. */
|
|
61
|
+
async function lstatOrNull(p) {
|
|
62
|
+
try {
|
|
63
|
+
return await fs.lstat(p);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=roles-yaml.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-yaml.step.js","sourceRoot":"","sources":["../../../../../src/modules/workspace/startup/steps/roles-yaml.step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAGvE;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,aAAa;IAGK;IAFpB,IAAI,GAAG,YAAY,CAAC;IAE7B,YAA6B,eAAkC;QAAlC,oBAAe,GAAf,eAAe,CAAmB;IAAG,CAAC;IAEnE,KAAK,CAAC,GAAG,CAAC,GAAuB;QAC/B,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAI,MAAM,GAAG,CAAC,iBAAiB,EAAE,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvC,yEAAyE;YACzE,mEAAmE;YACnE,uEAAuE;YACvE,wEAAwE;YACxE,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,O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
|
+
/**
|
|
2
|
+
* The empty-remote seed builder the runner takes as `buildSeedTree`: the full
|
|
3
|
+
* template tree, every reserved root, and a generated roles.yaml. DIRECT fs
|
|
4
|
+
* writes are correct here — the target is a temp directory the runner inits,
|
|
5
|
+
* commits and pushes itself, not a branch handle with buffered ops.
|
|
6
|
+
*
|
|
7
|
+
* Resolves to the repo-relative paths it GENERATED (roles.yaml plus each
|
|
8
|
+
* reserved root's .gitkeep): a template `.gitignore` rule could match any of
|
|
9
|
+
* them, and the runner force-adds them after `git add -A` so a required seed
|
|
10
|
+
* file can never be silently dropped from the seed commit.
|
|
11
|
+
*
|
|
12
|
+
* `extraRootDirs` is validated eagerly, at composition time: a bad value
|
|
13
|
+
* should fail at boot beside the rest of the wiring, not mid-seed of
|
|
14
|
+
* somebody's knowledge base.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildSeedTree(templateDir: string, extraRootDirs: readonly string[], seedAdminEmails: readonly string[]): (dir: string) => Promise<string[]>;
|
|
17
|
+
//# sourceMappingURL=seed-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-tree.d.ts","sourceRoot":"","sources":["../../../../../src/modules/workspace/startup/steps/seed-tree.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,eAAe,EAAE,SAAS,MAAM,EAAE,GACjC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CA8BpC"}
|