create-insight 0.8.0 → 0.21.1

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.
Files changed (2) hide show
  1. package/create-insight.mjs +34 -6
  2. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  // installer/create-insight.mjs
4
4
  import { spawnSync } from "node:child_process";
5
- import { createHash, randomBytes } from "node:crypto";
5
+ import { createHash, randomBytes as randomBytes2 } from "node:crypto";
6
6
  import { appendFileSync, copyFileSync, createWriteStream, existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, readdirSync, renameSync, rmSync, statSync, writeFileSync as writeFileSync2 } from "node:fs";
7
7
  import { createServer } from "node:net";
8
8
  import { arch as hostArch, homedir, userInfo } from "node:os";
@@ -29,11 +29,26 @@ ${help}`);
29
29
  }
30
30
 
31
31
  // src/auth/keys.ts
32
- import { generateKeyPairSync, randomUUID } from "node:crypto";
32
+ import { generateKeyPairSync, randomBytes, randomUUID } from "node:crypto";
33
33
  import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
34
34
  import { join } from "node:path";
35
35
  var SIGNING_FILE = "insight-signing-key.json";
36
36
  var PUBLIC_FILE = "insight-public-keys.json";
37
+ var APP_SECRET_FILE = "insight-app-secret";
38
+ function readAppSecret(dir2) {
39
+ const file = join(dir2, APP_SECRET_FILE);
40
+ if (!existsSync(file)) return null;
41
+ const secret = readFileSync(file, "utf8").trim();
42
+ return secret || null;
43
+ }
44
+ function ensureAppSecret(dir2) {
45
+ const kept = readAppSecret(dir2);
46
+ if (kept) return { secret: kept, made: false };
47
+ const secret = randomBytes(32).toString("hex");
48
+ writeFileSync(join(dir2, APP_SECRET_FILE), `${secret}
49
+ `, { mode: 384 });
50
+ return { secret, made: true };
51
+ }
37
52
  var KeysError = class extends Error {
38
53
  };
39
54
  function makeKeys(dir2, options = {}) {
@@ -205,6 +220,15 @@ done(`Loaded Insight ${version} into ${engine.name === "podman" ? "Podman" : "Do
205
220
  var packageDirs = upgrading ? (saved.INSIGHT_APP_PACKAGES ?? "").split(",").filter(Boolean).map((d) => resolve(dir, d)) : values["no-package"] ? [] : [dir, ...(values.also ?? []).map((d) => resolve(dir, d))];
206
221
  for (const target of packageDirs) addPackage(target);
207
222
  if (upgrading) {
223
+ if (!saved.INSIGHT_APP_SECRET) {
224
+ const keysDir2 = join2(dir, "keys");
225
+ mkdirSync(keysDir2, { recursive: true });
226
+ const { secret } = ensureAppSecret(keysDir2);
227
+ appendFileSync(envFile, `${readFileSync2(envFile, "utf8").endsWith("\n") ? "" : "\n"}# Watches: the secret Insight sends your app's token route (the same as keys/insight-app-secret)
228
+ INSIGHT_APP_SECRET=${secret}
229
+ `);
230
+ done("Added the watch secret to insight.env and keys/insight-app-secret");
231
+ }
208
232
  const compose = join2(dir, "docker-compose.yml");
209
233
  writeFileSync2(compose, readFileSync2(compose, "utf8").replace(/(image:\s*)\S+\/insight:\S+/, `$1${image}`));
210
234
  const up2 = run(engine.compose[0], [...engine.compose.slice(1), "up", "-d"], { stdio: ["ignore", "ignore", "pipe"] });
@@ -223,8 +247,10 @@ var name = values.name ?? (run("git", ["config", "user.name"]).stdout?.trim() ||
223
247
  var project = projectName(basename(dir));
224
248
  var names = containerNames(project);
225
249
  var appUrl = values["app-url"] ?? defaultAppUrl(engine.name);
226
- var dbPassword = randomBytes(18).toString("hex");
250
+ var dbPassword = randomBytes2(18).toString("hex");
227
251
  var consoleUrl = `http://127.0.0.1:${port}`;
252
+ mkdirSync(join2(dir, "keys"), { recursive: true });
253
+ var appSecret = ensureAppSecret(join2(dir, "keys")).secret;
228
254
  mkdirSync(join2(dir, "insight-config"), { recursive: true });
229
255
  writeFileSync2(join2(dir, "docker-compose.yml"), composeYaml({ engine: engine.name, selinux: engine.selinux, project, image, port }));
230
256
  writeFileSync2(
@@ -234,9 +260,11 @@ writeFileSync2(
234
260
  "INSIGHT_CONFIG=/config/insight.yaml",
235
261
  "INSIGHT_TRUSTED_KEYS=/config/insight-public-keys.json",
236
262
  "INSIGHT_SETUP_HOST_DIR=./insight-config",
237
- `INSIGHT_CONSOLE_SECRET=${randomBytes(32).toString("hex")}`,
263
+ `INSIGHT_CONSOLE_SECRET=${randomBytes2(32).toString("hex")}`,
238
264
  `INSIGHT_CONSOLE_URL=${consoleUrl}`,
239
265
  `INSIGHT_READ_URL=${appUrl.replace(/\/+$/, "")}/api/insight/read`,
266
+ // Watches: the secret Insight sends your app's token route (the same as keys/insight-app-secret).
267
+ `INSIGHT_APP_SECRET=${appSecret}`,
240
268
  // Insight's model, through Kaleyla, opened by the Kaleyla key below. Another model: the console, Settings › AI models.
241
269
  `INSIGHT_MODEL_URL=${init_defaults_default.modelUrl}`,
242
270
  `INSIGHT_MODEL=${init_defaults_default.model}`,
@@ -267,7 +295,7 @@ mkdirSync(keysDir, { recursive: true });
267
295
  var existingKey = join2(keysDir, "insight-signing-key.json");
268
296
  var keyPair = existsSync2(existingKey) ? { kid: JSON.parse(readFileSync2(existingKey, "utf8")).kid, publicPath: join2(keysDir, "insight-public-keys.json") } : makeKeys(keysDir, { name: project.replace(/^insight-/, "") });
269
297
  copyFileSync(keyPair.publicPath, join2(dir, "insight-config", "insight-public-keys.json"));
270
- done(`Made the app\u2019s signing key (${keyPair.kid}) in keys/; Insight trusts its public half`);
298
+ done(`Made the app\u2019s signing key (${keyPair.kid}) in keys/; Insight trusts its public half. keys/ also holds the watch secret Insight shares with your app`);
271
299
  say(" Starting Insight and its database\u2026");
272
300
  var up = run(engine.compose[0], [...engine.compose.slice(1), "-p", project, "up", "-d"], { stdio: ["ignore", "ignore", "pipe"] });
273
301
  if (up.status !== 0) stop(`${tool} up didn\u2019t start:
@@ -283,7 +311,7 @@ done(opened ? "Opened the console, signed in as its Owner" : `Sign in to the con
283
311
  say();
284
312
  say("Your app\u2019s server needs two settings (in its .env, say):");
285
313
  say(` INSIGHT_URL=${consoleUrl}`);
286
- say(` INSIGHT_KEYS_DIR=${keysDir}`);
314
+ say(` INSIGHT_KEYS_DIR=${keysDir} (deploy this folder with the app: its signing key and watch secret)`);
287
315
  if (packageDirs.length) say(`Commit vendor/kaleyla-insight-${version}.tgz with package.json: your CI installs Insight\u2019s package from it, with no key.`);
288
316
  say("Next, in the console: Your app \u203A Connection. Choose how people will ask, then give the prompt to your coding agent.");
289
317
  say(`Later: ${tool} down to stop, ${tool} up -d to start again, npx create-insight upgrade for a new release.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-insight",
3
- "version": "0.8.0",
3
+ "version": "0.21.1",
4
4
  "description": "Sets Insight up beside your app, with your Kaleyla key: npx create-insight",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",