@mindbricks/genesis-set 0.3.0 → 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.
@@ -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.3.0",
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