@mindbricks/genesis-set 0.0.0-stage → 0.2.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/CHANGELOG.md +44 -0
- package/LICENSE +202 -0
- package/README.md +148 -2
- package/bin/genesis-set.mjs +153 -0
- package/corpus/README.md +25 -0
- package/corpus/genesis/compile-results.md +246 -0
- package/corpus/genesis/compiler-api.md +265 -0
- package/corpus/genesis/custom-code.md +519 -0
- package/corpus/genesis/deploy.md +190 -0
- package/corpus/genesis/pitfalls.md +231 -0
- package/corpus/genesis/procedures/README.md +17 -0
- package/corpus/genesis/procedures/agent-hub-blueprint.md +13 -0
- package/corpus/genesis/procedures/auth-blueprint.md +14 -0
- package/corpus/genesis/procedures/bff-blueprint.md +16 -0
- package/corpus/genesis/procedures/blueprint-authoring.md +16 -0
- package/corpus/genesis/procedures/howto-mail-to-tasks.md +26 -0
- package/corpus/genesis/procedures/howto-payment-flow.md +112 -0
- package/corpus/genesis/procedures/howto-subscription.md +33 -0
- package/corpus/genesis/procedures/notifications-blueprint.md +13 -0
- package/corpus/genesis/procedures/patterns-catalog.md +12 -0
- package/corpus/genesis/procedures/project-lifecycle.md +27 -0
- package/corpus/genesis/run-locally.md +310 -0
- package/corpus/genesis/testing.md +532 -0
- package/lib/config-cli.mjs +179 -0
- package/lib/install.mjs +639 -0
- package/lib/mcp-config.mjs +222 -0
- package/lib/semver.mjs +94 -0
- package/mcp/blueprint.mjs +64 -0
- package/mcp/client.mjs +141 -0
- package/mcp/config.mjs +166 -0
- package/mcp/key-page-html.mjs +275 -0
- package/mcp/key-page.mjs +217 -0
- package/mcp/key-store.mjs +204 -0
- package/mcp/key-tools.mjs +225 -0
- package/mcp/server.mjs +164 -0
- package/mcp/tools.mjs +270 -0
- package/package.json +44 -4
- package/skills/genesis-compiler-api/SKILL.md +56 -0
- package/skills/genesis-deploy/SKILL.md +36 -0
- package/skills/genesis-generated-code/SKILL.md +48 -0
- package/skills/genesis-run-and-test/SKILL.md +43 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// `genesis config`: the Genesis API key and API base in the genesis-set
|
|
2
|
+
// config file (<data>/config.json, mode 0600; <data> = GENESIS_SET_HOME or
|
|
3
|
+
// ~/.genesis-set). The key is read from stdin, never from the command line (it
|
|
4
|
+
// would land in the shell history), and never printed back.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
API_BASE_ENV,
|
|
8
|
+
API_KEY_ENV,
|
|
9
|
+
DEFAULT_API_BASE,
|
|
10
|
+
configPathOf,
|
|
11
|
+
normalizeApiBase,
|
|
12
|
+
portalKeysUrl,
|
|
13
|
+
readConfigFile,
|
|
14
|
+
resolveSettings,
|
|
15
|
+
writeConfigFile,
|
|
16
|
+
} from '../mcp/config.mjs';
|
|
17
|
+
|
|
18
|
+
/** One line from stdin; on a terminal, without echo. */
|
|
19
|
+
async function readSecretLine(prompt, errOut) {
|
|
20
|
+
const stdin = process.stdin;
|
|
21
|
+
if (stdin.isTTY && typeof stdin.setRawMode === 'function') {
|
|
22
|
+
errOut(prompt);
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
let value = '';
|
|
25
|
+
stdin.setRawMode(true);
|
|
26
|
+
stdin.setEncoding('utf8');
|
|
27
|
+
stdin.resume();
|
|
28
|
+
const onData = (chunk) => {
|
|
29
|
+
for (const ch of chunk) {
|
|
30
|
+
if (ch === '\r' || ch === '\n' || ch === '\u0004') {
|
|
31
|
+
stdin.setRawMode(false);
|
|
32
|
+
stdin.pause();
|
|
33
|
+
stdin.off('data', onData);
|
|
34
|
+
process.stderr.write('\n');
|
|
35
|
+
resolve(value);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (ch === '\u0003') {
|
|
39
|
+
stdin.setRawMode(false);
|
|
40
|
+
process.stderr.write('\n');
|
|
41
|
+
resolve(null);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (ch === '\u007f' || ch === '\b') value = value.slice(0, -1);
|
|
45
|
+
else value += ch;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
stdin.on('data', onData);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let text = '';
|
|
52
|
+
stdin.setEncoding('utf8');
|
|
53
|
+
for await (const chunk of stdin) text += chunk;
|
|
54
|
+
return text.split(/\r?\n/)[0] ?? '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Why a key cannot be stored, or null when it can. */
|
|
58
|
+
function keyProblem(key) {
|
|
59
|
+
if (!key) return 'no key read';
|
|
60
|
+
if (/\s/.test(key)) return 'the key must not contain whitespace';
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The key step at the end of `genesis install`. A set key is only reported (never its
|
|
66
|
+
* value). Without one: on a terminal the user is pointed at the portal and the key is read
|
|
67
|
+
* hidden (Enter skips); without a terminal (an agent runs the install) the link and the
|
|
68
|
+
* command are printed and nothing waits for input. Never fails the install.
|
|
69
|
+
*/
|
|
70
|
+
export async function offerApiKey({
|
|
71
|
+
env = process.env,
|
|
72
|
+
out,
|
|
73
|
+
err,
|
|
74
|
+
dryRun = false,
|
|
75
|
+
interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
76
|
+
readSecret = readSecretLine,
|
|
77
|
+
}) {
|
|
78
|
+
const s = resolveSettings(env);
|
|
79
|
+
const url = portalKeysUrl(s.apiBase);
|
|
80
|
+
if (s.apiKey) {
|
|
81
|
+
out(`Genesis API key: set (from ${s.keySource}); its value is never printed.`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const later = `"genesis config set-key" in a terminal, or set ${API_KEY_ENV} in the environment the agent starts from`;
|
|
85
|
+
if (dryRun) {
|
|
86
|
+
out(`dry run: no API key asked. Create one at ${url}, then ${later}.`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!interactive) {
|
|
90
|
+
out(`No Genesis API key yet: the user creates one at ${url} (it is shown once), then runs ${later}.`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const file = configPathOf(env);
|
|
94
|
+
const current = readConfigFile(file);
|
|
95
|
+
if (current.__error) {
|
|
96
|
+
err(`No API key stored: ${current.__error}. Fix or delete it, then run "genesis config set-key".`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
out(`No Genesis API key yet. Create one at ${url} (it is shown once).`);
|
|
100
|
+
const key = ((await readSecret('Paste the key (input hidden), or press Enter to skip: ', (l) => process.stderr.write(l))) ?? '').trim();
|
|
101
|
+
if (!key) {
|
|
102
|
+
out(`Skipped. Later: ${later} (key from ${url}).`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const problem = keyProblem(key);
|
|
106
|
+
if (problem) {
|
|
107
|
+
err(`No API key stored: ${problem}. Run "genesis config set-key" to try again.`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
writeConfigFile(file, Object.fromEntries(Object.entries({ ...current, apiKey: key }).filter(([k, v]) => k !== '__error' && v !== undefined)));
|
|
111
|
+
out(`API key stored in ${file} (readable only by you). Manage it and your other keys any time with "genesis keys".`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function show(env, out) {
|
|
115
|
+
const s = resolveSettings(env);
|
|
116
|
+
out(`config file: ${s.configFile}`);
|
|
117
|
+
out(`API key: ${s.apiKey ? `set (from ${s.keySource}); the value is never printed` : `not set (${API_KEY_ENV} or "genesis config set-key"; create one at ${portalKeysUrl(s.apiBase)})`}`);
|
|
118
|
+
out(`API base: ${s.apiBase} (${s.baseSource})`);
|
|
119
|
+
for (const p of s.problems) out(`problem: ${p}`);
|
|
120
|
+
return s.problems.length ? 1 : 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function configCommand(args, { env = process.env, out, err }) {
|
|
124
|
+
const [sub = 'show', value] = args;
|
|
125
|
+
const file = configPathOf(env);
|
|
126
|
+
const current = readConfigFile(file);
|
|
127
|
+
if (current.__error && sub !== 'show') {
|
|
128
|
+
err(`error: ${current.__error}; fix or delete it first`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
const save = (next) => writeConfigFile(file, Object.fromEntries(Object.entries(next).filter(([k, v]) => k !== '__error' && v !== undefined)));
|
|
132
|
+
switch (sub) {
|
|
133
|
+
case 'show':
|
|
134
|
+
return show(env, out);
|
|
135
|
+
case 'set-key': {
|
|
136
|
+
const key = ((await readSecretLine('Genesis API key (input hidden), then Enter: ', (l) => process.stderr.write(l))) ?? '').trim();
|
|
137
|
+
const problem = keyProblem(key);
|
|
138
|
+
if (problem) {
|
|
139
|
+
err(`error: ${problem === 'no key read' ? 'no key read from stdin' : problem}; nothing changed`);
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
save({ ...current, apiKey: key });
|
|
143
|
+
out(`API key stored in ${file} (readable only by you).${env[API_KEY_ENV] ? ` Note: ${API_KEY_ENV} is set and wins over the file.` : ''}`);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
case 'unset-key':
|
|
147
|
+
save({ ...current, apiKey: undefined });
|
|
148
|
+
out(`API key removed from ${file}`);
|
|
149
|
+
return 0;
|
|
150
|
+
case 'set-base': {
|
|
151
|
+
if (!value) {
|
|
152
|
+
err('error: set-base needs a URL (or "default")');
|
|
153
|
+
return 2;
|
|
154
|
+
}
|
|
155
|
+
if (value === 'default') {
|
|
156
|
+
save({ ...current, apiBase: undefined });
|
|
157
|
+
out(`API base reset to ${DEFAULT_API_BASE}`);
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
let base;
|
|
161
|
+
try {
|
|
162
|
+
base = normalizeApiBase(value);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
err(`error: ${e.message}`);
|
|
165
|
+
return 2;
|
|
166
|
+
}
|
|
167
|
+
save({ ...current, apiBase: base });
|
|
168
|
+
out(`API base set to ${base} in ${file}${env[API_BASE_ENV] ? ` (${API_BASE_ENV} is set and wins over the file)` : ''}`);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
case 'unset-base':
|
|
172
|
+
save({ ...current, apiBase: undefined });
|
|
173
|
+
out(`API base reset to ${DEFAULT_API_BASE}`);
|
|
174
|
+
return 0;
|
|
175
|
+
default:
|
|
176
|
+
err(`error: unknown config command "${sub}" (show, set-key, unset-key, set-base <url>, unset-base)`);
|
|
177
|
+
return 2;
|
|
178
|
+
}
|
|
179
|
+
}
|