@mindbricks/genesis-set 0.2.1 → 0.4.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/mcp/key-tools.mjs CHANGED
@@ -7,6 +7,7 @@
7
7
  // genesis_listKeys every key: name, label, description, set / empty
8
8
  // genesis_openKeyManager the page link, to manage every key
9
9
  // genesis_writeKeyToEnvFile copy a stored value into a gitignored env file
10
+ // genesis_openBoard the project board (flow, documents, blueprint, keys)
10
11
  //
11
12
  // They work without a Genesis API key: the first one is how the user sets it.
12
13
 
@@ -15,13 +16,22 @@ import fs from 'node:fs';
15
16
  import path from 'node:path';
16
17
 
17
18
  import { genesisError } from './client.mjs';
19
+ import { ensureBoard } from './board.mjs';
18
20
  import { ensureKeyPage } from './key-page.mjs';
19
- import { BUILTIN_KEY, KeyStoreError, checkKeyName, findKey, keyValue, listKeys, requestKey } from './key-store.mjs';
21
+ import { BUILTIN_KEY, KeyStoreError, SCOPES, checkKeyName, findKey, keyValue, listKeys, requestKey } from './key-store.mjs';
22
+ import { findProject } from './project.mjs';
20
23
 
21
24
  const KEY_NAME = {
22
25
  type: 'string',
23
26
  description: `The key's name: lowercase kebab-case, for example "stripe-secret-key". "${BUILTIN_KEY}" is the Genesis API key itself.`,
24
27
  };
28
+ const SCOPE = {
29
+ type: 'string',
30
+ enum: SCOPES,
31
+ description:
32
+ 'Where the key is stored: "project" (this genesis project only; the default inside a project, see genesis init) or "global" (every project of this user). ' +
33
+ 'Both live in the user\'s home, never in the project folder.',
34
+ };
25
35
  const OPEN = {
26
36
  type: 'boolean',
27
37
  description: "Also open the page in the user's default browser on this machine (default false). Only when the user agreed.",
@@ -44,6 +54,7 @@ export const KEY_TOOLS = [
44
54
  type: 'string',
45
55
  description: 'What the key is for and where the user gets it, shown on the page (for example "Stripe dashboard, Developers > API keys; a test-mode key starting sk_test_").',
46
56
  },
57
+ scope: SCOPE,
47
58
  open: OPEN,
48
59
  },
49
60
  required: ['name', 'label'],
@@ -54,7 +65,7 @@ export const KEY_TOOLS = [
54
65
  {
55
66
  name: 'genesis_listKeys',
56
67
  title: 'List the keys of the local key store',
57
- description: 'Every key of the local key store with its label, description and status (set or empty). Values are never answered.',
68
+ description: 'Every key this folder can use: the project\'s keys (inside a genesis project) and the global ones, each with its scope, label, description and status (set or empty). Values are never answered.',
58
69
  inputSchema: { type: 'object', properties: {}, additionalProperties: false },
59
70
  annotations: { readOnlyHint: true, openWorldHint: false },
60
71
  },
@@ -77,12 +88,23 @@ export const KEY_TOOLS = [
77
88
  name: KEY_NAME,
78
89
  file: { type: 'string', description: 'The env file (absolute, or relative to the folder the agent was started in).' },
79
90
  variable: { type: 'string', description: 'The variable name in the file, for example STRIPE_SECRET_KEY.' },
91
+ scope: { ...SCOPE, description: 'Read the key from this scope only. Default: the project\'s key when there is one, else the global key.' },
80
92
  },
81
93
  required: ['name', 'file', 'variable'],
82
94
  additionalProperties: false,
83
95
  },
84
96
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
85
97
  },
98
+ {
99
+ name: 'genesis_openBoard',
100
+ title: 'Open the project board',
101
+ description:
102
+ 'The link of the local project board for the genesis project of this folder: the design flow with the state and check of every document, the documents themselves, ' +
103
+ 'the interview, the blueprint with its validation, and the project and global keys. Offer it when a design document is written or the user asks where to follow the work; ' +
104
+ 'the user can also open it any time with "genesis board" in the project folder. Works on this machine only.',
105
+ inputSchema: { type: 'object', properties: { open: OPEN }, additionalProperties: false },
106
+ annotations: { readOnlyHint: true, openWorldHint: false },
107
+ },
86
108
  ];
87
109
 
88
110
  const KEY_TOOL_NAMES = new Set(KEY_TOOLS.map((t) => t.name));
@@ -177,40 +199,65 @@ async function pageLink(settings, open) {
177
199
  return { ...link, opened };
178
200
  }
179
201
 
202
+ /** The project board's links (the write link opens the Keys tab when `tab` says so). */
203
+ async function boardLink(settings, project, { open, tab } = {}) {
204
+ const b = await ensureBoard({ env: settings.env ?? process.env, project });
205
+ const hash = tab ? `#${tab}` : '';
206
+ const url = `${b.url}${hash}`;
207
+ const opened = open === true ? openInBrowser(url) : false;
208
+ return { url, readUrl: `${b.readUrl}${hash}`, port: b.port, opened, reopen: 'genesis board (in the project folder)' };
209
+ }
210
+
180
211
  const HANDLERS = {
181
212
  async genesis_requestKey(args, settings) {
182
213
  const env = settings.env ?? process.env;
183
- const key = forAgent(requestKey(env, { name: args.name, label: args.label, description: args.description }));
184
- const link = await pageLink(settings, args.open);
214
+ const project = findProject(settings.cwd ?? process.cwd());
215
+ const scope = args.name === BUILTIN_KEY ? 'global' : args.scope ?? (project ? 'project' : 'global');
216
+ const key = forAgent(requestKey(env, { name: args.name, label: args.label, description: args.description }, { scope, project }));
217
+ // Inside a project the keys are on the board (project and global); outside, on the global key page.
218
+ const link = project ? await boardLink(settings, project, { open: args.open, tab: 'keys' }) : await pageLink(settings, args.open);
185
219
  return {
186
220
  key,
221
+ ...(project ? { project: { name: project.name, root: project.root } } : {}),
187
222
  keyPage: link,
188
223
  next:
189
224
  key.status === 'set'
190
225
  ? `"${key.label}" is already set. Use it; the user can change it on the key page.`
191
226
  : `Ask the user to open ${link.url} on this machine and save "${key.label}" there, then call genesis_listKeys to see it set. ` +
192
- 'Never ask for the value in the chat. Later the user can open the page themselves with "genesis keys" in a terminal.',
227
+ `Never ask for the value in the chat. Later the user can open it themselves with ${project ? '"genesis board" in the project folder' : '"genesis keys"'} in a terminal.`,
193
228
  };
194
229
  },
195
230
  async genesis_listKeys(_args, settings) {
196
- return { keys: listKeys(settings.env ?? process.env).map(forAgent) };
231
+ const project = findProject(settings.cwd ?? process.cwd());
232
+ return {
233
+ ...(project ? { project: { name: project.name, root: project.root } } : { project: null }),
234
+ keys: listKeys(settings.env ?? process.env, { project }).map(forAgent),
235
+ };
197
236
  },
198
237
  async genesis_openKeyManager(args, settings) {
199
238
  return { keyPage: await pageLink(settings, args.open) };
200
239
  },
240
+ async genesis_openBoard(args, settings) {
241
+ const project = findProject(settings.cwd ?? process.cwd());
242
+ if (!project) {
243
+ throw new KeyStoreError('GENESIS_KEY_NO_PROJECT', 'this folder is not a genesis project; run "genesis init" in the project folder first', 409);
244
+ }
245
+ return { project: { name: project.name, root: project.root }, board: await boardLink(settings, project, { open: args.open }) };
246
+ },
201
247
  async genesis_writeKeyToEnvFile(args, settings) {
202
248
  const env = settings.env ?? process.env;
203
249
  checkKeyName(args.name);
204
250
  if (!VARIABLE.test(args.variable)) throw new KeyStoreError('GENESIS_KEY_BAD_INPUT', `"${args.variable}" is not an env variable name`);
205
- const row = findKey(env, args.name);
206
- if (!row) throw new KeyStoreError('GENESIS_KEY_NOT_FOUND', `no key named "${args.name}"; register it with genesis_requestKey`, 404);
207
- const value = keyValue(env, args.name);
251
+ const project = findProject(settings.cwd ?? process.cwd());
252
+ const row = findKey(env, args.name, { scope: args.scope, project });
253
+ if (!row) throw new KeyStoreError('GENESIS_KEY_NOT_FOUND', `no key named "${args.name}"${args.scope ? ` in the ${args.scope} scope` : ''}; register it with genesis_requestKey`, 404);
254
+ const value = args.scope === 'global' ? keyValue(env, args.name) : keyValue(env, args.name, { project: row.scope === 'project' ? project : null });
208
255
  if (!value) throw new KeyStoreError('GENESIS_KEY_NOT_SET', `"${row.label}" has no value yet; ask the user to save it on the key page (genesis_openKeyManager)`, 409);
209
256
  const file = path.resolve(settings.cwd ?? process.cwd(), args.file);
210
257
  const refusal = envFileRefusal(file);
211
258
  if (refusal) throw new KeyStoreError('GENESIS_ENV_FILE_REFUSED', refusal, 422);
212
259
  const { created, replaced } = writeEnvVariable(file, args.variable, value);
213
- return { written: true, key: args.name, file, variable: args.variable, created, replaced };
260
+ return { written: true, key: args.name, scope: row.scope, file, variable: args.variable, created, replaced };
214
261
  },
215
262
  };
216
263
 
@@ -0,0 +1,90 @@
1
+ // The project identity of genesis-set (#9385, epic #9384).
2
+ //
3
+ // A folder is a project when it, or one of its parents, holds
4
+ // `.genesis/project.json`: `{ "id": "<random>", "name": "<name>" }`. The file
5
+ // carries no secret and may be committed, so a clone or a moved folder keeps its
6
+ // identity. `genesis init` writes it; nothing ever changes an existing id.
7
+ //
8
+ // The project's own settings and keys live in the user's home, under that id
9
+ // (`<genesis-set data>/projects/<id>/`), never in the project folder.
10
+
11
+ import { randomUUID } from 'node:crypto';
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+
15
+ import { dataDirOf } from './config.mjs';
16
+
17
+ export const PROJECT_DIR = '.genesis';
18
+ export const PROJECT_FILE = 'project.json';
19
+ /** An id goes into a path under the user's home: letters, digits and dashes only. */
20
+ export const PROJECT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9-]{7,63}$/;
21
+ const MAX_NAME = 80;
22
+
23
+ function readJson(file) {
24
+ try {
25
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ /** The project file of `dir` itself (not of a parent). */
32
+ export function projectFileOf(dir) {
33
+ return path.join(path.resolve(dir), PROJECT_DIR, PROJECT_FILE);
34
+ }
35
+
36
+ /**
37
+ * The project `start` belongs to: `{ root, id, name, file }`, or null. Walks up
38
+ * from `start`; a project file with an unusable id is treated as no project.
39
+ */
40
+ export function findProject(start = process.cwd()) {
41
+ let dir = path.resolve(start);
42
+ for (;;) {
43
+ const file = projectFileOf(dir);
44
+ if (fs.existsSync(file)) {
45
+ const p = readJson(file);
46
+ if (p && typeof p.id === 'string' && PROJECT_ID_PATTERN.test(p.id)) {
47
+ const name = typeof p.name === 'string' && p.name.trim() ? p.name.trim().slice(0, MAX_NAME) : path.basename(dir);
48
+ return { root: dir, id: p.id, name, file };
49
+ }
50
+ return null;
51
+ }
52
+ const up = path.dirname(dir);
53
+ if (up === dir) return null;
54
+ dir = up;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * The project of `dir` itself, created when absent: answers `{ project, created }`.
60
+ * An existing file is never changed; `dryRun` writes nothing.
61
+ */
62
+ export function ensureProject(dir, { name, dryRun = false } = {}) {
63
+ const file = projectFileOf(dir);
64
+ if (fs.existsSync(file)) {
65
+ const found = findProject(dir);
66
+ if (found && found.root === path.resolve(dir)) return { project: found, created: false };
67
+ throw new Error(`${file} is not a usable project file (its id must match ${PROJECT_ID_PATTERN}); fix or delete it`);
68
+ }
69
+ const project = {
70
+ root: path.resolve(dir),
71
+ id: randomUUID(),
72
+ name: String(name || path.basename(path.resolve(dir))).trim().slice(0, MAX_NAME),
73
+ file,
74
+ };
75
+ if (!dryRun) {
76
+ fs.mkdirSync(path.dirname(file), { recursive: true });
77
+ fs.writeFileSync(file, `${JSON.stringify({ id: project.id, name: project.name }, null, 2)}\n`);
78
+ }
79
+ return { project, created: true };
80
+ }
81
+
82
+ /** Where a project's settings and keys live: under the user's genesis-set folder, by id. */
83
+ export function projectDataDir(env, id) {
84
+ if (!PROJECT_ID_PATTERN.test(id)) throw new Error(`"${id}" is not a project id`);
85
+ return path.join(dataDirOf(env), 'projects', id);
86
+ }
87
+
88
+ export function projectKeysFile(env, id) {
89
+ return path.join(projectDataDir(env, id), 'keys.json');
90
+ }
package/mcp/server.mjs CHANGED
@@ -14,6 +14,7 @@ import path from 'node:path';
14
14
  import { fileURLToPath, pathToFileURL } from 'node:url';
15
15
 
16
16
  import { resolveSettings } from './config.mjs';
17
+ import { closeBoard } from './board.mjs';
17
18
  import { closeKeyPage } from './key-page.mjs';
18
19
  import { TOOLS, hasTool, runTool } from './tools.mjs';
19
20
 
@@ -38,6 +39,7 @@ const INSTRUCTIONS =
38
39
  'Blueprint paths are read on this machine and sent inline. Every failure is a Genesis error { error: { code, message, details } }: report the code. ' +
39
40
  'Keys (the Genesis API key, provider secrets): never ask for a value in the chat. Register the key with genesis_requestKey, give the user the local key page link it answers, and check genesis_listKeys; ' +
40
41
  'genesis_writeKeyToEnvFile puts a stored key into a gitignored env file without you seeing it. ' +
42
+ 'In a genesis project, genesis_openBoard gives the project board (design flow, documents, interview, blueprint, keys): offer it when a design document is written, and answer "where can I follow this?" with it. ' +
41
43
  'The genesis-compiler-api skill has the full procedure.';
42
44
 
43
45
  /**
@@ -148,7 +150,7 @@ export function serve({ input = process.stdin, output = process.stdout, log = (l
148
150
  maybeFinish();
149
151
  });
150
152
  // The key page lives only as long as this server.
151
- return done.then(() => closeKeyPage());
153
+ return done.then(() => Promise.all([closeKeyPage(), closeBoard()]));
152
154
  }
153
155
 
154
156
  function isMain() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindbricks/genesis-set",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "PRE-RELEASE. Genesis compiler skills for coding agents (Claude Code, Codex): the generated code, its runtime and the Genesis Compiler API, on top of mind-set.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -28,6 +28,9 @@ service build's result is `{{CORPUS}}/genesis/compile-results.md`.
28
28
  easiest way for the user is the local key page: `genesis_requestKey` with
29
29
  `name: "genesis-api-key"` answers its link; then check `genesis_listKeys`. Never ask for the key
30
30
  in the chat, never write it into a file, never print it.
31
+ 4. In a genesis project (`genesis init` made it), the user follows the work on the project board:
32
+ `genesis_openBoard` gives its link (the user opens it with `genesis board`). Offer it when a
33
+ build finishes or the user asks where to see the project.
31
34
 
32
35
  ## The calls
33
36