kryptheon 0.1.64 → 0.1.66

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/bin/kryptheon.js CHANGED
@@ -190,6 +190,9 @@ function ensureBrowser() {
190
190
  console.log('');
191
191
  console.log(' Downloading a browser to run your app in.');
192
192
  console.log(' This is about 200MB and only happens once.');
193
+ // A new user took Playwright's own box for an error (2026-11-10): said before it appears.
194
+ console.log(' Playwright may print a WARNING box about installing dependencies first -');
195
+ console.log(' that is harmless here. Wait for the download to finish.');
193
196
  console.log('');
194
197
  // Playwright's install deletes every browser it thinks no other copy of
195
198
  // Playwright still uses. With Kryptheon installed in a project and run by
@@ -974,10 +977,19 @@ function writeSpec(relativeFile, source) {
974
977
 
975
978
  // Passwords typed during recording land in the file as plain text. Swap them
976
979
  // for environment variables before the file is left lying around.
980
+ // The passwords already set for this project (KRYPTHEON_PASSWORD_* in .env or
981
+ // the environment): a recording that typed one of them, into a box whose name
982
+ // says nothing, has it taken out too (blind round 30).
983
+ function knownPasswords() {
984
+ const known = Object.assign(Object.create(null), secrets.readEnvFile(secrets.envFileFor(USER_DIR)));
985
+ for (const name of Object.keys(process.env)) if (/^KRYPTHEON_PASSWORD/.test(name)) known[name] = process.env[name];
986
+ return known;
987
+ }
988
+
977
989
  function takeOutSecrets(relativeFile) {
978
990
  const source = readSpec(relativeFile);
979
991
  if (source === null) return [];
980
- const result = replay.scrubSecrets(source);
992
+ const result = replay.scrubSecrets(source, { known: knownPasswords() });
981
993
  if (!result.replacements.length) return [];
982
994
  return writeSpec(relativeFile, result.source) ? result.replacements : [];
983
995
  }
@@ -1345,6 +1357,12 @@ async function finaliseRecording(outFile, context) {
1345
1357
  // npx, not the bare name: somebody who started with `npx kryptheon record`
1346
1358
  // has no `kryptheon` command, and would be told it does not exist.
1347
1359
  console.log(' Run it any time with: npx kryptheon check');
1360
+ // Recording is only the first step: a new user read the line above and thought Kryptheon just records the
1361
+ // screen (2026-11-10). Where the app is actually checked is said here.
1362
+ console.log('');
1363
+ console.log(' Next: open the dashboard and press "Check my whole app" - that is where your');
1364
+ console.log(' app is checked for bugs and security holes, each with a prompt to fix it:');
1365
+ console.log(' npx kryptheon@latest dashboard');
1348
1366
  console.log('');
1349
1367
 
1350
1368
  reportTidying(tidied);
@@ -1894,9 +1912,8 @@ function triageSpecs() {
1894
1912
  // Recordings made before secrets were stripped still hold the real value.
1895
1913
  // Say so rather than rewriting: a spec that works today should keep
1896
1914
  // working until the person has somewhere to put the password.
1897
- if (replay.scrubSecrets(source).replacements.length) {
1898
- withSecrets.push({ name: name, fields: replay.scrubSecrets(source).replacements });
1899
- }
1915
+ const leftIn = replay.scrubSecrets(source, { known: knownPasswords() }).replacements;
1916
+ if (leftIn.length) withSecrets.push({ name: name, fields: leftIn });
1900
1917
 
1901
1918
  // A recording that falls back to an empty password is not run at all. It
1902
1919
  // would sign in blank, fail, and send the reader looking at their app.
@@ -4082,4 +4099,19 @@ module.exports = {
4082
4099
  nodeIsTooOld: nodeIsTooOld,
4083
4100
  };
4084
4101
 
4085
- if (require.main === module) main();
4102
+ if (require.main === module) {
4103
+ // A newer version on npm, said once at the end of a command (npx can keep handing out an old cached copy, and an
4104
+ // install in a project stays where it was). Not in a dashboard's own jobs: the dashboard says it once, on its page.
4105
+ const newer = require(path.join(__dirname, '..', 'kryptheon-newer.js'));
4106
+ const own = (() => { try { return JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version; } catch (err) { return null; } })();
4107
+ let latestSeen = null;
4108
+ if (own && !process.env.KRYPTHEON_DASHBOARD_JOB) {
4109
+ newer.latestOf('kryptheon').then((v) => { latestSeen = v; });
4110
+ process.on('exit', () => {
4111
+ const words = process.argv.slice(2).filter((a) => !/:\/\/[^@/]*@/.test(a)).join(' ');
4112
+ const said = newer.notice('kryptheon', own, latestSeen, 'npx kryptheon@latest' + (words ? ' ' + words : ''));
4113
+ if (said) process.stderr.write('\n ' + said + '\n\n');
4114
+ });
4115
+ }
4116
+ main();
4117
+ }
@@ -0,0 +1,183 @@
1
+ // The local dashboard's connection to a kryptheon.tech account (owner's decision, 2026-11-10).
2
+ //
3
+ // A connect code (kd_...) is made on the account page for one of the person's apps, and pasted once into the
4
+ // dashboard's "Your account" box. It is kept in this project's own store (account.json, outside the project, like
5
+ // everything else Kryptheon remembers), and is only ever sent to kryptheon.tech's entitlement function. That
6
+ // answers with the plan, and opens Starter's five fix prompts a month for this app, counted there - never here.
7
+ //
8
+ // What leaves this computer: the code, and for each prompt opened on Starter a fingerprint - a hash of the finding's
9
+ // id. Never a finding's words, a route, a file, the app's code or its data.
10
+ //
11
+ // lock() decides what the dashboard's page is sent:
12
+ // - not connected: every finding and its proof; no fix prompt (reason "connect");
13
+ // - Starter: the prompts of findings opened this month; the rest locked (reason "free-left" while some of the five
14
+ // are left, "used" after);
15
+ // - Pro and Studio: everything, and the one prompt for all.
16
+ // buildState itself is not changed: verify, recheck and the other checks read prompts as before.
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const crypto = require('crypto');
21
+ const store = require('./kryptheon-store.js');
22
+
23
+ const ENTITLEMENT = 'https://dkheqkynldupnxorqscd.supabase.co/functions/v1/entitlement';
24
+ const CODE = /^kd_[A-Za-z0-9_-]{20,100}$/;
25
+ const FILE = 'account.json';
26
+ const PAID = new Set(['pro', 'studio']);
27
+ const PRICING = 'https://kryptheon.tech/pricing/';
28
+ const ACCOUNT_PAGE = 'https://kryptheon.tech/dashboard/#computer';
29
+
30
+ const fileOf = (root, env) => path.join(store.pathsFor(root, env).dir, FILE);
31
+ const monthNow = () => new Date().toISOString().slice(0, 7);
32
+
33
+ /** The fingerprint kryptheon.tech counts a finding by: a hash of its id, nothing of its words. */
34
+ function fingerprintOf(findingId) {
35
+ return crypto.createHash('sha256').update('kryptheon-finding:' + String(findingId)).digest('hex').slice(0, 32);
36
+ }
37
+
38
+ function read(root, env) {
39
+ try {
40
+ const a = JSON.parse(fs.readFileSync(fileOf(root, env), 'utf8'));
41
+ return a && typeof a === 'object' ? a : null;
42
+ } catch (err) {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ function write(root, env, value) {
48
+ const file = fileOf(root, env);
49
+ fs.mkdirSync(path.dirname(file), { recursive: true });
50
+ // Readable by this computer's account only, where the file system lets it say so.
51
+ fs.writeFileSync(file, JSON.stringify(value, null, 2), { mode: 0o600 });
52
+ }
53
+
54
+ function forget(root, env) {
55
+ try {
56
+ fs.unlinkSync(fileOf(root, env));
57
+ } catch (err) {
58
+ /* not there */
59
+ }
60
+ }
61
+
62
+ /** Asks kryptheon.tech, with the code: { status, body } or { status: 0, why } when it cannot be reached. */
63
+ async function ask(env, code, body) {
64
+ const url = (env && env.KRYPTHEON_ACCOUNT_URL) || ENTITLEMENT;
65
+ try {
66
+ const res = await fetch(url, {
67
+ method: 'POST',
68
+ headers: { authorization: 'Bearer ' + code, 'content-type': 'application/json' },
69
+ body: JSON.stringify(body || {}),
70
+ signal: AbortSignal.timeout(8000),
71
+ });
72
+ const answer = await res.json().catch(() => ({}));
73
+ return { status: res.status, body: answer };
74
+ } catch (err) {
75
+ return { status: 0, why: 'kryptheon.tech could not be reached - check your internet connection and try again' };
76
+ }
77
+ }
78
+
79
+ /** What kryptheon.tech said about the plan, kept with the code. */
80
+ function keep(root, env, code, body, unlocked) {
81
+ const month = body.month || monthNow();
82
+ const was = unlocked && unlocked.month === month ? unlocked.ids : [];
83
+ write(root, env, {
84
+ code: code,
85
+ app: String(body.project || ''),
86
+ plan: String(body.plan || 'starter'),
87
+ clientReport: !!body.clientReport,
88
+ prompts: body.prompts || { limit: 5, used: 0, left: 5 },
89
+ month: month,
90
+ unlocked: { month: month, ids: was },
91
+ checkedAt: new Date().toISOString(),
92
+ });
93
+ return read(root, env);
94
+ }
95
+
96
+ /** Connects with a code from the account page: { ok, account } or { ok: false, why }. */
97
+ async function connect(root, env, code) {
98
+ const c = String(code || '').trim();
99
+ if (!CODE.test(c)) return { ok: false, why: 'that is not a connect code - it starts with kd_; get it from your account page on kryptheon.tech' };
100
+ const r = await ask(env, c, {});
101
+ if (r.status === 0) return { ok: false, why: r.why };
102
+ if (r.status !== 200) return { ok: false, why: (r.body && r.body.error) || 'kryptheon.tech did not accept that code' };
103
+ const before = read(root, env);
104
+ return { ok: true, account: summary(keep(root, env, c, r.body, before && before.code === c ? before.unlocked : null)) };
105
+ }
106
+
107
+ /** Asks again with the kept code: the plan may have changed, or the code been replaced. */
108
+ async function refresh(root, env) {
109
+ const a = read(root, env);
110
+ if (!a || !a.code) return { ok: true, account: summary(null) };
111
+ const r = await ask(env, a.code, {});
112
+ if (r.status === 0) return { ok: false, why: r.why, account: summary(a) };
113
+ if (r.status === 401) {
114
+ // Replaced on the account page, or the app removed: not connected any more, and said why.
115
+ write(root, env, { problem: (r.body && r.body.error) || 'this connect code no longer works - get a new one from your account on kryptheon.tech' });
116
+ return { ok: true, account: summary(read(root, env)) };
117
+ }
118
+ if (r.status !== 200) return { ok: false, why: (r.body && r.body.error) || 'kryptheon.tech did not answer', account: summary(a) };
119
+ return { ok: true, account: summary(keep(root, env, a.code, r.body, a.unlocked)) };
120
+ }
121
+
122
+ /** Opens one finding's fix prompt: free on Pro and Studio; on Starter, one of the five this month. */
123
+ async function unlock(root, env, findingId) {
124
+ const a = read(root, env);
125
+ if (!a || !a.code) return { ok: false, status: 401, why: 'connect your free Kryptheon account first' };
126
+ if (PAID.has(a.plan)) return { ok: true, account: summary(a) };
127
+ const r = await ask(env, a.code, { unlock: fingerprintOf(findingId) });
128
+ if (r.status === 0) return { ok: false, status: 503, why: r.why };
129
+ if (r.status === 401) {
130
+ write(root, env, { problem: (r.body && r.body.error) || 'this connect code no longer works' });
131
+ return { ok: false, status: 401, why: (r.body && r.body.error) || 'this connect code no longer works' };
132
+ }
133
+ const month = r.body.month || monthNow();
134
+ const ids = a.unlocked && a.unlocked.month === month ? a.unlocked.ids.slice() : [];
135
+ if (r.status === 200 && r.body.unlocked) {
136
+ if (!ids.includes(findingId)) ids.push(findingId);
137
+ }
138
+ write(root, env, Object.assign({}, a, { plan: r.body.plan || a.plan, prompts: r.body.prompts || a.prompts, month: month, unlocked: { month: month, ids: ids }, checkedAt: new Date().toISOString() }));
139
+ if (r.status === 402) return { ok: false, status: 402, why: 'this month\'s free fix prompts are used - Pro opens every one', account: summary(read(root, env)) };
140
+ if (r.status !== 200) return { ok: false, status: r.status, why: (r.body && r.body.error) || 'kryptheon.tech did not answer' };
141
+ return { ok: true, account: summary(read(root, env)) };
142
+ }
143
+
144
+ function disconnect(root, env) {
145
+ forget(root, env);
146
+ return { ok: true, account: summary(null) };
147
+ }
148
+
149
+ /** What the page may know about the account: never the code. */
150
+ function summary(a) {
151
+ if (!a || !a.code) {
152
+ return { connected: false, problem: a && a.problem ? a.problem : '', accountPage: ACCOUNT_PAGE, pricing: PRICING };
153
+ }
154
+ return {
155
+ connected: true, app: a.app, plan: a.plan, clientReport: !!a.clientReport, prompts: a.prompts, month: a.month,
156
+ checkedAt: a.checkedAt, accountPage: ACCOUNT_PAGE, pricing: PRICING,
157
+ };
158
+ }
159
+
160
+ /** The dashboard state as the page may see it, for this account. A new object; `state` is not changed. */
161
+ function lock(state, root, env) {
162
+ const a = read(root, env);
163
+ const out = Object.assign({}, state, { account: summary(a) });
164
+ if (a && a.code && PAID.has(a.plan)) return out;
165
+ const connected = !!(a && a.code);
166
+ const month = monthNow();
167
+ const opened = new Set(connected && a.unlocked && a.unlocked.month === month ? a.unlocked.ids : []);
168
+ const left = connected && a.prompts && typeof a.prompts.left === 'number' ? a.prompts.left : 0;
169
+ out.findings = (state.findings || []).map((f) => {
170
+ if (!f.fixPrompt || opened.has(f.id)) return f;
171
+ const firstLine = String(f.fixPrompt).split('\n').map((l) => l.trim()).find(Boolean) || '';
172
+ return Object.assign({}, f, {
173
+ fixPrompt: '',
174
+ promptLock: { reason: !connected ? 'connect' : left > 0 ? 'free-left' : 'used', left: left, preview: firstLine.slice(0, 160) },
175
+ });
176
+ });
177
+ // The one prompt for every finding at once is Pro's: on Starter it would open them all.
178
+ out.allFixPrompt = '';
179
+ out.allFixPromptLocked = !!state.allFixPrompt;
180
+ return out;
181
+ }
182
+
183
+ module.exports = { connect, refresh, unlock, disconnect, lock, summary, fingerprintOf, read, ENTITLEMENT, CODE };