@bevel-software/platform-core-backend 0.8.0 → 0.9.1
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/AGENTS.md +11 -5
- package/kb-template/access.md +40 -30
- 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,94 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { execFile } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The startup phase's own git plumbing — the runner owns every remote and
|
|
11
|
+
* repository operation of the phase (steps only declare buffered ops), so
|
|
12
|
+
* this is deliberately small and self-contained rather than borrowed from
|
|
13
|
+
* the runtime workspace service.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Fallback committer identity; workflow commits override with `--author`. */
|
|
17
|
+
export const BOT_NAME = 'Bevel Workflow';
|
|
18
|
+
export const BOT_EMAIL = 'bevel-workflow@bevel.software';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Scrub credentials from anything that reaches a log or an error message:
|
|
22
|
+
* the configured token wherever it appears, and URL userinfo — a remote
|
|
23
|
+
* spelled `https://user:pass@host` would otherwise leak `pass` verbatim
|
|
24
|
+
* through every git failure that quotes the URL back.
|
|
25
|
+
*/
|
|
26
|
+
export function redactSecret(text: string): string {
|
|
27
|
+
const token = process.env.GITHUB_TOKEN;
|
|
28
|
+
const scrubbed = token ? text.replaceAll(token, '***') : text;
|
|
29
|
+
return scrubbed.replace(/:\/\/[^/@\s]+@/g, '://***@');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Per-invocation `-c` config. Long paths always (Windows checkouts of deep
|
|
34
|
+
* KB trees); when a token is present, an inline credential helper that reads
|
|
35
|
+
* it from the environment at call time — the secret never appears in argv.
|
|
36
|
+
*/
|
|
37
|
+
function credArgs(gitUsername: string): string[] {
|
|
38
|
+
const args = ['-c', 'core.longpaths=true'];
|
|
39
|
+
if (process.env.GITHUB_TOKEN) {
|
|
40
|
+
args.push(
|
|
41
|
+
'-c',
|
|
42
|
+
`credential.helper=!f() { echo "username=${gitUsername}"; echo "password=$GITHUB_TOKEN"; }; f`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function git(cwd: string, gitUsername: string, args: string[]): Promise<string> {
|
|
49
|
+
try {
|
|
50
|
+
const { stdout } = await execFileAsync('git', [...credArgs(gitUsername), ...args], {
|
|
51
|
+
cwd,
|
|
52
|
+
// A stalled remote must FAIL the phase, not hang the boot forever —
|
|
53
|
+
// fail-closed (and KB_SAFE_BOOT's demotion) can only engage on an error
|
|
54
|
+
// that actually arrives. 10 minutes is generous for the largest clone.
|
|
55
|
+
timeout: 600_000,
|
|
56
|
+
// The 1MiB default truncates `ls-remote --heads` on remotes with very
|
|
57
|
+
// many branches, which would silently drop heads from the phase's view.
|
|
58
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
59
|
+
// A credential prompt must fail the phase, not hang the boot forever
|
|
60
|
+
// waiting on a terminal nobody is watching.
|
|
61
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
62
|
+
});
|
|
63
|
+
return stdout.toString();
|
|
64
|
+
} catch (err) {
|
|
65
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
66
|
+
throw new Error(redactSecret(`git ${args[0]} failed: ${msg}`));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function stampIdentity(repo: string, gitUsername: string): Promise<void> {
|
|
71
|
+
await git(repo, gitUsername, ['config', 'user.name', BOT_NAME]);
|
|
72
|
+
await git(repo, gitUsername, ['config', 'user.email', BOT_EMAIL]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Branch names present on the remote, from `ls-remote --heads`. */
|
|
76
|
+
export async function lsRemoteHeads(repoUrl: string, gitUsername: string): Promise<Set<string>> {
|
|
77
|
+
const out = await git(os.tmpdir(), gitUsername, ['ls-remote', '--heads', repoUrl]);
|
|
78
|
+
const heads = new Set<string>();
|
|
79
|
+
for (const line of out.split('\n')) {
|
|
80
|
+
const m = /\srefs\/heads\/(.+)$/.exec(line.trim());
|
|
81
|
+
if (m) heads.add(m[1]!);
|
|
82
|
+
}
|
|
83
|
+
return heads;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A temp dir that is always removed, success or failure. */
|
|
87
|
+
export async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
|
88
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'kb-startup-'));
|
|
89
|
+
try {
|
|
90
|
+
return await fn(dir);
|
|
91
|
+
} finally {
|
|
92
|
+
await fs.rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
93
|
+
}
|
|
94
|
+
}
|