@mindbricks/genesis-set 0.2.0 → 0.3.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 CHANGED
@@ -3,6 +3,22 @@
3
3
  The package follows semantic versioning. Each release names the mind-set range it needs
4
4
  (`dependencies["@mindbricks/mind-set"]` in `package.json`).
5
5
 
6
+ ## 0.3.0 (pre-release)
7
+
8
+ - `genesis init [<folder>] [--dry-run]` prepares a project folder so the agent works the
9
+ OpenAPPL + Genesis way from its first session. It writes a marked block into `CLAUDE.md` and
10
+ `AGENTS.md` (the order of work with the skill for each step, and the key rules) and creates
11
+ `design/` and the env and secrets lines of `.gitignore`; it prints the API key status and a
12
+ starter prompt. Content outside the block is kept, and a second run changes nothing.
13
+
14
+ ## 0.2.1 (pre-release)
15
+
16
+ - A stored key is shown as its type prefix and last four characters (`sk_mbx_...9f3a`,
17
+ `sk_test_...a1b2`) in `genesis config show`, `genesis doctor`, the install key step and the
18
+ key page, so the user can tell which key is set and whether it is a test or a live key. At
19
+ least eight characters always stay hidden; a shorter value is only shown as "set". The agent
20
+ tools still answer set or empty only.
21
+
6
22
  ## 0.2.0 (pre-release)
7
23
 
8
24
  Needs mind-set `^0.2.0`.
package/README.md CHANGED
@@ -24,14 +24,44 @@ as an alias). It depends on
24
24
  `@mindbricks/mind-set`, so the global install brings mind-set's package too, and
25
25
  `genesis install` runs `mindset install` when mind-set is not installed yet.
26
26
 
27
+ ## Starting a project
28
+
29
+ The skills start when a request talks about OpenAPPL or Genesis. A plain "build me a booking
30
+ app" can make an agent hand-write a backend instead, so prepare the project folder once:
31
+
32
+ ```bash
33
+ mkdir my-app && cd my-app
34
+ genesis init
35
+ ```
36
+
37
+ `genesis init` writes a marked block into `CLAUDE.md` (Claude Code) and `AGENTS.md` (Codex),
38
+ which the agents read at the start of every session:
39
+ - the backend is an OpenAPPL blueprint compiled by Genesis, never hand-written;
40
+ - the order of work with the skill for each step;
41
+ - the key rules.
42
+
43
+ It also creates `design/` and the env and secrets lines of `.gitignore`, then prints the API
44
+ key status and a starter prompt.
45
+ - Your own content in `CLAUDE.md` and `AGENTS.md` is kept.
46
+ - A second run only refreshes the block.
47
+ - `--dry-run` shows what it would write.
48
+
49
+ Then open the agent in the folder and start, for example:
50
+
51
+ ```text
52
+ Let us design a new application with OpenAPPL and compile it with Genesis: a table booking
53
+ system for cafes, with owner, waiter and guest roles. Start with the requirements interview.
54
+ ```
55
+
27
56
  ## Commands
28
57
 
29
58
  | Command | What it does |
30
59
  |---|---|
60
+ | `genesis init [<folder>] [--dry-run]` | Prepares a project folder (default: the current one) for the agent: the OpenAPPL + Genesis block in `CLAUDE.md` and `AGENTS.md`, `design/`, the env lines of `.gitignore`, then the key status and a starter prompt (see "Starting a project"). |
31
61
  | `genesis install [--claude] [--codex] [--force] [--no-mcp] [--no-key] [--dry-run]` | Makes sure a compatible mind-set is installed (it comes with this package and is installed by its own CLI), copies the corpus to `~/.genesis-set/<version>/` (linked as `~/.genesis-set/current`), writes each `genesis-*` skill to Claude Code (`~/.claude/skills/`) and Codex (`~/.agents/skills/`), registers the MCP server (below), and ends with the API key step (below). |
32
62
  | `genesis update [...]` | Installs this version for every agent installed before (and every detected one), then deletes older corpus versions. |
33
63
  | `genesis uninstall [--dry-run]` | Removes only what `install` recorded in `~/.genesis-set/installed.json`, including the MCP registrations. mind-set and your API key file stay. |
34
- | `genesis doctor` | Both versions (genesis-set and mind-set) and whether they are compatible, the skills of each package and the MCP server per agent, where the API key comes from (never its value) and the API base. |
64
+ | `genesis doctor` | Both versions (genesis-set and mind-set) and whether they are compatible, the skills of each package and the MCP server per agent, where the API key comes from and which key it is (its type prefix and last four characters, such as `sk_mbx_...9f3a`, never the whole key) and the API base. |
35
65
  | `genesis config [show \| set-key \| unset-key \| set-base <url> \| unset-base]` | The API key and API base in `~/.genesis-set/config.json` (mode 0600). `set-key` reads the key from stdin (hidden on a terminal), never from the command line. |
36
66
  | `genesis keys [--no-open]` | Opens the local key page in your browser: add, change, clear or delete the keys your agent uses. The link is new each time; the page closes after 15 idle minutes or on Ctrl+C. `--no-open` only prints the link. |
37
67
  | `genesis mcp` | Runs the MCP server on stdio from the package (for a registration by hand). |
@@ -83,7 +113,8 @@ without a Genesis API key:
83
113
  - **Where the keys live:** in `~/.genesis-set/config.json` (mode 0600).
84
114
  - The Genesis API key is the built-in key `genesis-api-key`, the same value `config set-key` stores.
85
115
  - Every other key is `keys.<name>`.
86
- - **What the page shows:** whether a key is set, and the last four characters of a long value. A
116
+ - **What the page shows:** whether a key is set and, for a long value, its type prefix and last
117
+ four characters (`sk_test_...a1b2`), so test and live keys can be told apart. A
87
118
  value is sent once, when the user saves it. The field the user types into is hidden, with a
88
119
  Show / Hide toggle; the stored value is never shown again.
89
120
  - **Env files:** `genesis_writeKeyToEnvFile` accepts only a file named `.env`, `.env.local` or
@@ -111,7 +142,8 @@ without a Genesis API key:
111
142
  ### Projects and credentials
112
143
 
113
144
  - The project's identity is the blueprint's (`projectSettings.basicSettings.name`); there is
114
- no binding file, and genesis-set writes nothing into a project folder.
145
+ no binding file. Only `genesis init`, run on a project folder, writes there (the agent
146
+ instructions, `design/`, `.gitignore`); nothing else genesis-set does touches a project.
115
147
  - **Getting the key:** the user signs in to the Genesis portal and creates one on its API keys
116
148
  page, `https://portal.genesiscompiler.com/keys` (the stage API `sapi.genesiscompiler.com`
117
149
  has `https://stage.genesiscompiler.com/keys`). The key is shown once.
@@ -6,6 +6,7 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import { configCommand, offerApiKey } from '../lib/config-cli.mjs';
9
+ import { initProject } from '../lib/init.mjs';
9
10
  import { chooseAgents, doctor, install, resolveContext, uninstall, update } from '../lib/install.mjs';
10
11
 
11
12
  const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
@@ -18,6 +19,7 @@ const HELP = `genesis ${pkg.version}: Genesis compiler skills for coding agents
18
19
 
19
20
  Usage:
20
21
  genesis install [--claude] [--codex] [--force] [--no-mcp] [--no-key] [--dry-run]
22
+ genesis init [<folder>] [--dry-run]
21
23
  genesis update [--claude] [--codex] [--force] [--no-mcp] [--dry-run]
22
24
  genesis uninstall [--dry-run]
23
25
  genesis doctor
@@ -40,6 +42,13 @@ install makes sure mind-set ${pkg.dependencies?.['@mindbricks/mind-set'] ?? '
40
42
  API key: with none set, it names the portal page that creates one
41
43
  and, on a terminal, reads it hidden (Enter skips; --no-key skips
42
44
  the step). Nothing is written into a project folder.
45
+ init prepares a project folder (default: the current one) so the agent
46
+ works the OpenAPPL + Genesis way from its first session: a marked
47
+ block in CLAUDE.md (Claude Code) and AGENTS.md (Codex) with the
48
+ order of work and the key rules (your own content in those files
49
+ is kept; a second run only refreshes the block), design/ and the
50
+ env and secrets lines of .gitignore. It prints the API key status
51
+ and a starter prompt. The one command that writes into a project.
43
52
  update install for this version (and every agent installed before), then
44
53
  delete older genesis-set corpus versions.
45
54
  uninstall removes only what install recorded in ~/.genesis-set/installed.json;
@@ -81,6 +90,7 @@ function parseArgs(argv) {
81
90
 
82
91
  const KNOWN_FLAGS = {
83
92
  install: ['claude', 'codex', 'force', 'noMcp', 'noKey', 'dryRun'],
93
+ init: ['dryRun'],
84
94
  update: ['claude', 'codex', 'force', 'noMcp', 'dryRun'],
85
95
  uninstall: ['dryRun'],
86
96
  doctor: [],
@@ -109,6 +119,13 @@ async function main(argv) {
109
119
  err(`error: unknown option for ${command}: ${unknown.map((f) => `--${f}`).join(', ')}`);
110
120
  return 2;
111
121
  }
122
+ if (command === 'init') {
123
+ if (positional.length > 2) {
124
+ err('error: init takes one folder at most');
125
+ return 2;
126
+ }
127
+ return initProject({ dir: positional[1] ?? process.cwd(), env: process.env, out, err, dryRun: flags.dryRun === true });
128
+ }
112
129
  if (command === 'keys') {
113
130
  const { ensureKeyPage, keyPageClosed, closeKeyPage } = await import('../mcp/key-page.mjs');
114
131
  const { openInBrowser } = await import('../mcp/key-tools.mjs');
@@ -59,7 +59,8 @@ Genesis never deploys anything and never runs your services.
59
59
  and how to set the key: pass it on as it is.
60
60
  3. The API base is `https://api.genesiscompiler.com`. Change it only when the user names
61
61
  another one (`GENESIS_API_BASE`, or `genesis config set-base <url>`).
62
- 4. `genesis doctor` says where the key comes from (never its value), the API base and
62
+ 4. `genesis doctor` says where the key comes from and which key it is (type prefix and last four
63
+ characters, never the whole key), the API base and
63
64
  whether each agent has the MCP server.
64
65
 
65
66
  ## 4. The tools
@@ -8,6 +8,7 @@ import {
8
8
  API_KEY_ENV,
9
9
  DEFAULT_API_BASE,
10
10
  configPathOf,
11
+ maskSecret,
11
12
  normalizeApiBase,
12
13
  portalKeysUrl,
13
14
  readConfigFile,
@@ -54,6 +55,11 @@ async function readSecretLine(prompt, errOut) {
54
55
  return text.split(/\r?\n/)[0] ?? '';
55
56
  }
56
57
 
58
+ /** A set key as the user sees it: `sk_mbx_...9f3a`, or "set" when it is too short to show any of it. */
59
+ export function shownKey(key) {
60
+ return maskSecret(key) ?? 'set';
61
+ }
62
+
57
63
  /** Why a key cannot be stored, or null when it can. */
58
64
  function keyProblem(key) {
59
65
  if (!key) return 'no key read';
@@ -78,7 +84,7 @@ export async function offerApiKey({
78
84
  const s = resolveSettings(env);
79
85
  const url = portalKeysUrl(s.apiBase);
80
86
  if (s.apiKey) {
81
- out(`Genesis API key: set (from ${s.keySource}); its value is never printed.`);
87
+ out(`Genesis API key: ${shownKey(s.apiKey)} (from ${s.keySource}).`);
82
88
  return;
83
89
  }
84
90
  const later = `"genesis config set-key" in a terminal, or set ${API_KEY_ENV} in the environment the agent starts from`;
@@ -114,7 +120,7 @@ export async function offerApiKey({
114
120
  function show(env, out) {
115
121
  const s = resolveSettings(env);
116
122
  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)})`}`);
123
+ out(`API key: ${s.apiKey ? `${shownKey(s.apiKey)} (from ${s.keySource})` : `not set (${API_KEY_ENV} or "genesis config set-key"; create one at ${portalKeysUrl(s.apiBase)})`}`);
118
124
  out(`API base: ${s.apiBase} (${s.baseSource})`);
119
125
  for (const p of s.problems) out(`problem: ${p}`);
120
126
  return s.problems.length ? 1 : 0;
package/lib/init.mjs ADDED
@@ -0,0 +1,183 @@
1
+ // `genesis init [<folder>] [--dry-run]` (#9383): prepare a project folder so a
2
+ // coding agent works the OpenAPPL + Genesis way from its first session.
3
+ //
4
+ // The mind-set and genesis skills trigger on OpenAPPL / Genesis wording; a plain
5
+ // "build me a booking app" can make an agent hand-write a backend. The agents
6
+ // read CLAUDE.md (Claude Code) and AGENTS.md (Codex) at the start of every
7
+ // session, so init writes the project's way of working there:
8
+ //
9
+ // CLAUDE.md, AGENTS.md a marked block (begin / end markers); content outside
10
+ // it is the user's and is kept; a second run replaces
11
+ // only the block
12
+ // design/README.md where the design documents go (written only when absent)
13
+ // .gitignore the env and secrets lines that are missing
14
+ //
15
+ // This is the one genesis command that writes into a project folder, and only
16
+ // into the folder it is run on. It never runs git and never touches the key store.
17
+
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+
21
+ import { maskSecret, portalKeysUrl, resolveSettings } from '../mcp/config.mjs';
22
+
23
+ export const BLOCK_BEGIN = '<!-- genesis init: begin. "genesis init" rewrites this block; edit outside it -->';
24
+ export const BLOCK_END = '<!-- genesis init: end -->';
25
+
26
+ export const GITIGNORE_LINES = ['.env', '.env.local', '*.secrets.env', 'node_modules/'];
27
+
28
+ /** The instructions both agents read. Plain text: the agent follows it, the user can edit around it. */
29
+ export const INSTRUCTIONS = `## How this project is built: OpenAPPL + Genesis
30
+
31
+ The backend of this project is an OpenAPPL blueprint, \`blueprint.json\`, compiled into service
32
+ code by the Genesis compiler. Never hand-write backend code: describe the system in the
33
+ blueprint, and the compiler writes the services. When a request is about the backend (data,
34
+ APIs, roles, payments, notifications), it is a change to the design or to the blueprint.
35
+
36
+ Work in this order; each step has its skill:
37
+
38
+ 1. **Design** (openappl-blueprint-design): the requirements interview, then the requirement,
39
+ spec and blueprint-plan documents under \`design/\`. The user approves each document.
40
+ 2. **Blueprint** (openappl-blueprint-authoring): write \`blueprint.json\` in small steps and run
41
+ \`mindset validate blueprint.json\` after every step. Custom logic the blueprint declares
42
+ (library functions, edge controllers) is written into the blueprint too
43
+ (genesis-generated-code).
44
+ 3. **Review** (openappl-blueprint-review): the checklist audit; \`mindset spec-coverage\` shows
45
+ that every design document produced its part of the blueprint.
46
+ 4. **Compile** (genesis-compiler-api): validate the whole blueprint, then build one service at a
47
+ time and follow each build to its final status. Builds are dry runs for now.
48
+ 5. **Run and test** (genesis-run-and-test), **deploy** (genesis-deploy): on the generated code.
49
+
50
+ Code that talks to the system (a frontend, a client, tests) is written against the blueprint
51
+ as its contract (openappl-blueprint-contract).
52
+
53
+ **Keys and secrets:** never ask for a key or a password in the chat, and never write one into
54
+ a file of this project yourself. Register the key with the genesis key tools, give the user
55
+ the local key page link to save it there, and check that it is set; a key reaches a service's
56
+ gitignored env file only through the key tool that writes it. The user can open the key page
57
+ any time with \`genesis keys\`.`;
58
+
59
+ /** The block with its markers. */
60
+ export function instructionsBlock() {
61
+ return `${BLOCK_BEGIN}\n${INSTRUCTIONS}\n${BLOCK_END}`;
62
+ }
63
+
64
+ /** The new text of an instructions file: the block replaced, appended, or a new file. */
65
+ export function withBlock(existing) {
66
+ const block = instructionsBlock();
67
+ if (existing === null) return `# Project instructions\n\n${block}\n`;
68
+ const start = existing.indexOf(BLOCK_BEGIN);
69
+ const end = existing.indexOf(BLOCK_END, start < 0 ? 0 : start);
70
+ if (start >= 0 && end > start) {
71
+ return existing.slice(0, start) + block + existing.slice(end + BLOCK_END.length);
72
+ }
73
+ return `${existing.replace(/\s*$/, '')}\n\n${block}\n`;
74
+ }
75
+
76
+ /** The .gitignore with the missing lines appended under a comment; unchanged when none is missing. */
77
+ export function withGitignore(existing) {
78
+ const have = new Set((existing ?? '').split(/\r?\n/).map((l) => l.trim()));
79
+ const missing = GITIGNORE_LINES.filter((l) => !have.has(l));
80
+ if (missing.length === 0) return existing;
81
+ const head = existing ? `${existing.replace(/\s*$/, '')}\n\n` : '';
82
+ return `${head}# genesis init: local env files hold secrets; never commit them\n${missing.join('\n')}\n`;
83
+ }
84
+
85
+ const DESIGN_README = `# Design documents
86
+
87
+ The design of this project: the requirements interview record, the requirement and spec
88
+ documents, and the blueprint plan. The openappl-blueprint-design skill writes them here, one
89
+ file per document, and \`mindset design-check <docName>\` checks each one's structure.
90
+ `;
91
+
92
+ /** The prompt the user pastes into the agent to start. */
93
+ export const STARTER_PROMPT =
94
+ 'Let us design a new application with OpenAPPL and compile it with Genesis: <one or two sentences on what it does and for whom>. ' +
95
+ 'Start with the requirements interview.';
96
+
97
+ function read(file) {
98
+ try {
99
+ return fs.readFileSync(file, 'utf8');
100
+ } catch (e) {
101
+ if (e.code === 'ENOENT') return null;
102
+ throw e;
103
+ }
104
+ }
105
+
106
+ function isGitRepo(dir) {
107
+ let d = path.resolve(dir);
108
+ for (;;) {
109
+ if (fs.existsSync(path.join(d, '.git'))) return true;
110
+ const up = path.dirname(d);
111
+ if (up === d) return false;
112
+ d = up;
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Prepare `dir`. Answers 0, or 1 when a file could not be written. `out` gets the
118
+ * actions (or, with dryRun, what would be done), the key status and the starter prompt.
119
+ */
120
+ export function initProject({ dir = process.cwd(), env = process.env, out, err = out, dryRun = false }) {
121
+ const target = path.resolve(dir);
122
+ const act = (msg) => out(`${dryRun ? 'would ' : ''}${msg}`);
123
+ const writes = [];
124
+
125
+ if (!fs.existsSync(target)) {
126
+ act(`create ${target}`);
127
+ if (!dryRun) fs.mkdirSync(target, { recursive: true });
128
+ } else if (!fs.statSync(target).isDirectory()) {
129
+ err(`error: ${target} is not a folder`);
130
+ return 1;
131
+ }
132
+
133
+ for (const name of ['CLAUDE.md', 'AGENTS.md']) {
134
+ const file = path.join(target, name);
135
+ const before = read(file);
136
+ const after = withBlock(before);
137
+ if (after === before) {
138
+ out(`${name}: up to date`);
139
+ continue;
140
+ }
141
+ act(before === null ? `write ${name}` : before.includes(BLOCK_BEGIN) ? `update the genesis block in ${name}` : `add the genesis block to ${name} (your content is kept)`);
142
+ writes.push([file, after]);
143
+ }
144
+
145
+ const designReadme = path.join(target, 'design', 'README.md');
146
+ if (read(designReadme) === null) {
147
+ act('write design/README.md');
148
+ writes.push([designReadme, DESIGN_README]);
149
+ }
150
+
151
+ const gitignore = path.join(target, '.gitignore');
152
+ const gBefore = read(gitignore);
153
+ const gAfter = withGitignore(gBefore);
154
+ if (gAfter !== gBefore) {
155
+ act(gBefore === null ? 'write .gitignore' : 'add the env and secrets lines to .gitignore');
156
+ writes.push([gitignore, gAfter]);
157
+ }
158
+
159
+ if (!dryRun) {
160
+ try {
161
+ for (const [file, text] of writes) {
162
+ fs.mkdirSync(path.dirname(file), { recursive: true });
163
+ fs.writeFileSync(file, text);
164
+ }
165
+ } catch (e) {
166
+ err(`error: ${e.message}`);
167
+ return 1;
168
+ }
169
+ }
170
+
171
+ const s = resolveSettings(env);
172
+ out('');
173
+ out(
174
+ s.apiKey
175
+ ? `Genesis API key: ${maskSecret(s.apiKey) ?? 'set'} (from ${s.keySource}).`
176
+ : `Genesis API key: not set. Create one at ${portalKeysUrl(s.apiBase)}, then run "genesis config set-key" (or save it on the key page, "genesis keys").`,
177
+ );
178
+ if (!isGitRepo(target)) out('This folder is not a git repository yet; "git init" makes it one.');
179
+ out('');
180
+ out(`Next: open Claude Code or Codex in ${target} and start with:`);
181
+ out(` ${STARTER_PROMPT}`);
182
+ return 0;
183
+ }
package/lib/install.mjs CHANGED
@@ -16,7 +16,8 @@
16
16
  // mind-set keeps its own data folder (~/.mind-set, or MIND_SET_HOME) and is
17
17
  // installed by its own CLI: when it is missing, or older than the range in
18
18
  // package.json `dependencies["@mindbricks/mind-set"]`, install runs the mind-set package
19
- // that came with genesis-set. Nothing is written into a project folder.
19
+ // that came with genesis-set. Nothing is written into a project folder (only
20
+ // `genesis init`, run in a folder, writes there; see init.mjs).
20
21
 
21
22
  import { spawnSync } from 'node:child_process';
22
23
  import fs from 'node:fs';
@@ -25,7 +26,7 @@ import os from 'node:os';
25
26
  import path from 'node:path';
26
27
  import { REGISTER, REGISTRATION, UNREGISTER, copyServer, mcpServerDir, mcpServerFile } from './mcp-config.mjs';
27
28
  import { compareVersions, satisfies } from './semver.mjs';
28
- import { portalKeysUrl, resolveSettings } from '../mcp/config.mjs';
29
+ import { maskSecret, portalKeysUrl, resolveSettings } from '../mcp/config.mjs';
29
30
 
30
31
  export const PACKAGE_NAME = 'genesis-set';
31
32
  export const MARKER = '.genesis-set.json';
@@ -584,8 +585,8 @@ export function doctor(ctx) {
584
585
  if (manifest && !exists(mindSetCorpus(ctx))) problems.push(`the mind-set corpus ${mindSetCorpus(ctx)} the skills point at is missing`);
585
586
  const settings = resolveSettings(ctx.env);
586
587
  say(
587
- `Genesis Compiler API key: ${settings.apiKey ? `set (from ${settings.keySource})` : `not set (${API_KEY_ENV}, or "genesis config set-key"; create one at ${portalKeysUrl(settings.apiBase)})`}; ` +
588
- 'its value is never printed',
588
+ `Genesis Compiler API key: ${settings.apiKey ? `${maskSecret(settings.apiKey) ?? 'set'} (from ${settings.keySource})` : `not set (${API_KEY_ENV}, or "genesis config set-key"; create one at ${portalKeysUrl(settings.apiBase)})`}; ` +
589
+ 'only its type prefix and last four characters are ever printed',
589
590
  );
590
591
  say(`Genesis Compiler API base: ${settings.apiBase} (${settings.baseSource})`);
591
592
  for (const p of settings.problems) problems.push(p);
package/mcp/config.mjs CHANGED
@@ -29,6 +29,29 @@ export function portalKeysUrl(apiBase) {
29
29
  return PORTAL_KEYS_URL;
30
30
  }
31
31
  export const CONFIG_FILE = 'config.json';
32
+
33
+ /** How many characters of a stored key always stay hidden when it is shown. */
34
+ export const MASK_HIDDEN_MIN = 8;
35
+ /** The longest type prefix a masked key shows. */
36
+ export const MASK_PREFIX_MAX = 12;
37
+
38
+ /**
39
+ * A stored key as the user may see it: its type prefix and its last four
40
+ * characters, for example `sk_test_...a1b2` or `sk_mbx_...9f3a`, so the user can
41
+ * tell which key is set (test or live, which account) without the key being
42
+ * shown. The prefix is the leading marker, one or two letter segments that end
43
+ * in `_` or `-` (at most MASK_PREFIX_MAX characters), else the first four
44
+ * characters. Answers null when fewer than MASK_HIDDEN_MIN characters would stay
45
+ * hidden: a short value is only ever "set". Never for an agent's answer.
46
+ */
47
+ export function maskSecret(value) {
48
+ if (typeof value !== 'string') return null;
49
+ const v = value.trim();
50
+ const marker = v.match(/^[A-Za-z]{1,8}[_-](?:[A-Za-z]{1,8}[_-])?/);
51
+ const prefix = marker && marker[0].length <= MASK_PREFIX_MAX ? marker[0] : v.slice(0, 4);
52
+ if (v.length - prefix.length - 4 < MASK_HIDDEN_MIN) return null;
53
+ return `${prefix}...${v.slice(-4)}`;
54
+ }
32
55
  /** The server's default inline-blueprint limit (bytes of the compact JSON text). */
33
56
  export const DEFAULT_MAX_BLUEPRINT_BYTES = 10 * 1024 * 1024;
34
57
  export const DEFAULT_TIMEOUT_MS = 120_000;
@@ -112,7 +112,7 @@ const SCRIPT = `
112
112
  c.append(head);
113
113
  if (k.description) c.append(el('p', 'desc', k.description));
114
114
  const meta = [];
115
- if (k.tail) meta.push('ends with ' + k.tail);
115
+ if (k.masked) meta.push('key ' + k.masked);
116
116
  if (k.status === 'set' && k.updatedAt) meta.push('saved ' + when(k.updatedAt));
117
117
  if (meta.length) c.append(el('p', 'meta', meta.join(' · ')));
118
118
  if (k.source) c.append(el('p', 'note', 'The environment variable ' + k.source + ' is set and wins over a value saved here.'));
package/mcp/key-store.mjs CHANGED
@@ -12,7 +12,7 @@
12
12
  // the last four characters for the page, and `keyValue` is for the code that
13
13
  // uses a key (writing a gitignored env file), never for a tool answer.
14
14
 
15
- import { API_KEY_ENV, configPathOf, readConfigFile, writeConfigFile } from './config.mjs';
15
+ import { API_KEY_ENV, configPathOf, maskSecret, readConfigFile, writeConfigFile } from './config.mjs';
16
16
 
17
17
  export const BUILTIN_KEY = 'genesis-api-key';
18
18
  const BUILTIN_LABEL = 'Genesis API key';
@@ -80,13 +80,9 @@ function checkValue(value) {
80
80
  return v;
81
81
  }
82
82
 
83
- /** The last four characters, for a long value only (a short one would give most of it away). */
84
- function tailOf(value) {
85
- return typeof value === 'string' && value.length >= 12 ? value.slice(-4) : null;
86
- }
87
-
88
- function row(name, entry, { builtin = false, envOverride = false } = {}) {
83
+ function row(name, entry, { builtin = false, envOverride = false, envValue = null } = {}) {
89
84
  const value = typeof entry.value === 'string' && entry.value ? entry.value : null;
85
+ // The key in effect: for the Genesis API key the environment variable wins over the file.
90
86
  return {
91
87
  name,
92
88
  label: entry.label || name,
@@ -94,14 +90,14 @@ function row(name, entry, { builtin = false, envOverride = false } = {}) {
94
90
  builtin,
95
91
  status: value || envOverride ? 'set' : 'empty',
96
92
  ...(envOverride ? { source: API_KEY_ENV } : {}),
97
- tail: tailOf(value),
93
+ masked: maskSecret(envOverride ? envValue : value),
98
94
  updatedAt: entry.updatedAt ?? null,
99
95
  };
100
96
  }
101
97
 
102
98
  /**
103
- * Every key, the built-in Genesis API key first. `tail` (the last four
104
- * characters) is for the page; the tools drop it.
99
+ * Every key, the built-in Genesis API key first. `masked` (the type prefix and
100
+ * the last four characters, see maskSecret) is for the page; the tools drop it.
105
101
  */
106
102
  export function listKeys(env = process.env) {
107
103
  const { cfg, keys } = load(env);
@@ -110,7 +106,7 @@ export function listKeys(env = process.env) {
110
106
  row(
111
107
  BUILTIN_KEY,
112
108
  { label: BUILTIN_LABEL, description: BUILTIN_DESCRIPTION, value: cfg.apiKey, updatedAt: cfg.apiKeyUpdatedAt },
113
- { builtin: true, envOverride: envKey },
109
+ { builtin: true, envOverride: envKey, envValue: envKey ? env[API_KEY_ENV] : null },
114
110
  ),
115
111
  ];
116
112
  for (const name of Object.keys(keys).sort()) {
package/mcp/key-tools.mjs CHANGED
@@ -91,10 +91,10 @@ export function isKeyTool(name) {
91
91
  return KEY_TOOL_NAMES.has(name);
92
92
  }
93
93
 
94
- /** A row for the agent: the page's row without the value's tail. */
94
+ /** A row for the agent: the page's row without any part of the value. */
95
95
  function forAgent(row) {
96
96
  if (!row) return row;
97
- const { tail: _tail, ...rest } = row;
97
+ const { masked: _masked, ...rest } = row;
98
98
  return rest;
99
99
  }
100
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindbricks/genesis-set",
3
- "version": "0.2.0",
3
+ "version": "0.3.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": {