kenso 0.1.205 → 0.1.206

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/dist/kenso.js CHANGED
@@ -247,6 +247,7 @@ var init_api_key = __esm({
247
247
  });
248
248
 
249
249
  // src/core/folder.ts
250
+ import { randomBytes } from "node:crypto";
250
251
  import { existsSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
251
252
  import { homedir } from "node:os";
252
253
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -361,10 +362,10 @@ function writeFolderFile(file) {
361
362
  if (file.profile) out.profile = file.profile;
362
363
  else delete out.profile;
363
364
  out.workflows = file.workflows;
364
- const temp = join(dirname(file.path), `.${FOLDER_FILE}.${process.pid}.${Date.now()}.tmp`);
365
+ const temp = join(dirname(file.path), `.${FOLDER_FILE}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`);
365
366
  try {
366
367
  writeFileSync(temp, `${JSON.stringify(out, null, 2)}
367
- `);
368
+ `, { flag: "wx" });
368
369
  renameSync(temp, file.path);
369
370
  } catch (err) {
370
371
  try {
@@ -3539,7 +3540,7 @@ var VERSION;
3539
3540
  var init_version = __esm({
3540
3541
  "src/core/version.ts"() {
3541
3542
  "use strict";
3542
- VERSION = true ? "0.1.205" : "0.0.0-dev";
3543
+ VERSION = true ? "0.1.206" : "0.0.0-dev";
3543
3544
  }
3544
3545
  });
3545
3546
 
@@ -4809,7 +4810,7 @@ var init_results = __esm({
4809
4810
  });
4810
4811
 
4811
4812
  // src/batch/runs.ts
4812
- import { randomBytes } from "node:crypto";
4813
+ import { randomBytes as randomBytes2 } from "node:crypto";
4813
4814
  import { chmodSync as chmodSync2, mkdirSync as mkdirSync2, statSync as statSync2 } from "node:fs";
4814
4815
  import { open, readdir, realpath, rename, stat, unlink, writeFile as writeFile2 } from "node:fs/promises";
4815
4816
  import { join as join7, resolve as resolve3 } from "node:path";
@@ -4818,7 +4819,7 @@ function runsRoot(env = process.env) {
4818
4819
  return resolve3(override2 ? override2 : join7(configDir(env), "runs"));
4819
4820
  }
4820
4821
  function newRunId() {
4821
- const bytes = randomBytes(5);
4822
+ const bytes = randomBytes2(5);
4822
4823
  let bits = 0;
4823
4824
  let value = 0;
4824
4825
  let id = "";
@@ -4907,7 +4908,7 @@ function ensurePrivateDir2(dir3) {
4907
4908
  ensureDir(dir3, 448);
4908
4909
  }
4909
4910
  async function writeFileAtomic(path, content) {
4910
- const temp = `${path}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
4911
+ const temp = `${path}.${process.pid}.${randomBytes2(4).toString("hex")}.tmp`;
4911
4912
  try {
4912
4913
  await writeFile2(temp, content, { mode: 384 });
4913
4914
  await rename(temp, path);
@@ -10428,7 +10429,8 @@ __export(install_exports, {
10428
10429
  readExisting: () => readExisting,
10429
10430
  write: () => write
10430
10431
  });
10431
- import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync12, renameSync as renameSync6, writeFileSync as writeFileSync6 } from "node:fs";
10432
+ import { randomBytes as randomBytes3 } from "node:crypto";
10433
+ import { closeSync as closeSync2, existsSync as existsSync5, fchmodSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync12, renameSync as renameSync6, rmSync as rmSync3, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
10432
10434
  import { basename as basename2, dirname as dirname2, join as join14, resolve as resolve7 } from "node:path";
10433
10435
  function quote(value) {
10434
10436
  return /^[A-Za-z0-9_\-.,:/@=+%~]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
@@ -10442,13 +10444,35 @@ function readExisting(path) {
10442
10444
  throw new KensoError({ code: "file_unreadable", message: `Cannot read ${path}${code ? ` (${code})` : ""}.`, exitCode: ExitCode.Usage });
10443
10445
  }
10444
10446
  }
10445
- function write(path, text5) {
10447
+ function currentMode(path) {
10448
+ if (process.platform === "win32") return void 0;
10449
+ try {
10450
+ return statSync3(path).mode & 511;
10451
+ } catch {
10452
+ return void 0;
10453
+ }
10454
+ }
10455
+ function write(path, text5, opts = {}) {
10456
+ let temp;
10446
10457
  try {
10447
- mkdirSync4(dirname2(path), { recursive: true });
10448
- const temp = `${path}.${process.pid}.tmp`;
10449
- writeFileSync6(temp, text5);
10458
+ mkdirSync4(dirname2(path), opts.dirMode === void 0 ? { recursive: true } : { recursive: true, mode: opts.dirMode });
10459
+ const keep = currentMode(path);
10460
+ const name = `${path}.${process.pid}.${randomBytes3(8).toString("hex")}.tmp`;
10461
+ const fd = openSync2(name, "wx", keep ?? opts.mode ?? 438);
10462
+ temp = name;
10463
+ try {
10464
+ if (keep !== void 0) fchmodSync(fd, keep);
10465
+ writeFileSync6(fd, text5);
10466
+ } finally {
10467
+ closeSync2(fd);
10468
+ }
10450
10469
  renameSync6(temp, path);
10470
+ temp = void 0;
10451
10471
  } catch (err) {
10472
+ try {
10473
+ if (temp !== void 0) rmSync3(temp, { force: true });
10474
+ } catch {
10475
+ }
10452
10476
  const code = err.code;
10453
10477
  throw new KensoError({ code: "file_unwritable", message: `Cannot write ${path}${code ? ` (${code})` : ""}.`, exitCode: ExitCode.Error });
10454
10478
  }
@@ -10531,7 +10555,7 @@ var init_install = __esm({
10531
10555
  return ExitCode.Ok;
10532
10556
  }
10533
10557
  for (const target2 of targets) {
10534
- if (WRITES.has(target2.status)) write(target2.path, texts.get(target2.name));
10558
+ if (WRITES.has(target2.status)) write(target2.path, texts.get(target2.name), dir3 === void 0 ? { dirMode: 448 } : {});
10535
10559
  }
10536
10560
  if (dir3 !== void 0 && basename2(resolve7(dir3)) !== names[0]) {
10537
10561
  ctx.output.warn(`Agents expect the skill's folder to be named ${names[0]}, like the skill: ${resolve7(dir3)} is not.`);
@@ -10676,7 +10700,7 @@ function addMcp(client, env, url) {
10676
10700
  if (text5 === void 0 && client === "opencode") doc.$schema = "https://opencode.ai/config.json";
10677
10701
  t.merge(doc, url);
10678
10702
  write(state2.file, `${JSON.stringify(doc, null, 2)}
10679
- `);
10703
+ `, { mode: 384, dirMode: 448 });
10680
10704
  return { status: "added", file: state2.file, name: SERVER_NAME };
10681
10705
  }
10682
10706
  function signInStep(client) {
@@ -10851,7 +10875,7 @@ var init_setup = __esm({
10851
10875
  for (const row of rows) {
10852
10876
  for (const skill of row.skills) {
10853
10877
  const done2 = installStatus(skill.status, force);
10854
- if (WRITES.has(done2)) write(skill.path, texts.get(skill.name));
10878
+ if (WRITES.has(done2)) write(skill.path, texts.get(skill.name), { dirMode: 448 });
10855
10879
  if (done2 === "edited") edited.push(skill.path);
10856
10880
  skill.status = done2;
10857
10881
  }
@@ -11056,7 +11080,7 @@ var init_browser = __esm({
11056
11080
  });
11057
11081
 
11058
11082
  // src/core/pending-login.ts
11059
- import { chmodSync as chmodSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync14, renameSync as renameSync7, rmSync as rmSync3, unlinkSync as unlinkSync3, writeFileSync as writeFileSync7 } from "node:fs";
11083
+ import { chmodSync as chmodSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync14, renameSync as renameSync7, rmSync as rmSync4, unlinkSync as unlinkSync3, writeFileSync as writeFileSync7 } from "node:fs";
11060
11084
  import { join as join16 } from "node:path";
11061
11085
  function pendingLoginPath(env = process.env) {
11062
11086
  return join16(configDir(env), FILE2);
@@ -11107,7 +11131,7 @@ function writePendingLogin(login, env = process.env) {
11107
11131
  }
11108
11132
  }
11109
11133
  function removePendingLogin(env = process.env) {
11110
- rmSync3(pendingLoginPath(env), { force: true });
11134
+ rmSync4(pendingLoginPath(env), { force: true });
11111
11135
  }
11112
11136
  var FILE2, TEXT_KEYS;
11113
11137
  var init_pending_login = __esm({
@@ -15503,7 +15527,7 @@ var init_docs2 = __esm({
15503
15527
  });
15504
15528
 
15505
15529
  // src/commands/doctor/index.ts
15506
- import { statSync as statSync3 } from "node:fs";
15530
+ import { statSync as statSync4 } from "node:fs";
15507
15531
  function withNext(check, next) {
15508
15532
  return check.ok ? check : { ...check, next };
15509
15533
  }
@@ -15548,7 +15572,7 @@ function configCheck(env) {
15548
15572
  const file = configPath(env);
15549
15573
  let mode;
15550
15574
  try {
15551
- mode = statSync3(file).mode & 511;
15575
+ mode = statSync4(file).mode & 511;
15552
15576
  } catch (err) {
15553
15577
  if (err.code === "ENOENT") return { name: "config_permissions", ok: true, detail: `no config file at ${file}` };
15554
15578
  return { name: "config_permissions", ok: false, detail: `cannot read ${file}: ${err.message}` };
@@ -20188,8 +20212,8 @@ var init_views = __esm({
20188
20212
  });
20189
20213
 
20190
20214
  // src/commands/webhooks/local.ts
20191
- import { createHmac, randomBytes as randomBytes2 } from "node:crypto";
20192
- import { mkdirSync as mkdirSync6, readFileSync as readFileSync17, rmSync as rmSync4, writeFileSync as writeFileSync8 } from "node:fs";
20215
+ import { createHmac, randomBytes as randomBytes4 } from "node:crypto";
20216
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync17, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "node:fs";
20193
20217
  import { join as join22 } from "node:path";
20194
20218
  function webhooksDir(env) {
20195
20219
  const dir3 = join22(configDir(env), "webhooks");
@@ -20206,7 +20230,7 @@ function signingSecret(env) {
20206
20230
  if (/^whsec_[A-Za-z0-9+/]{32,}={0,2}$/.test(saved)) return saved;
20207
20231
  } catch {
20208
20232
  }
20209
- const secret = `whsec_${randomBytes2(24).toString("base64")}`;
20233
+ const secret = `whsec_${randomBytes4(24).toString("base64")}`;
20210
20234
  writeFileSync8(file, `${secret}
20211
20235
  `, { mode: 384 });
20212
20236
  return secret;
@@ -20263,7 +20287,7 @@ function readListenerState(env, workspaceId) {
20263
20287
  }
20264
20288
  }
20265
20289
  function removeListenerState(env, workspaceId, token) {
20266
- if (readListenerState(env, workspaceId)?.token === token) rmSync4(statePath(env, workspaceId), { force: true });
20290
+ if (readListenerState(env, workspaceId)?.token === token) rmSync5(statePath(env, workspaceId), { force: true });
20267
20291
  }
20268
20292
  var FORWARD_TIMEOUT_MS;
20269
20293
  var init_local = __esm({
@@ -20282,7 +20306,7 @@ __export(listen_exports, {
20282
20306
  default: () => listen_default,
20283
20307
  liveBody: () => liveBody
20284
20308
  });
20285
- import { randomBytes as randomBytes3 } from "node:crypto";
20309
+ import { randomBytes as randomBytes5 } from "node:crypto";
20286
20310
  import { setTimeout as delay11 } from "node:timers/promises";
20287
20311
  function eventTypes(value) {
20288
20312
  const list2 = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
@@ -20390,7 +20414,7 @@ var init_listen = __esm({
20390
20414
  throw err;
20391
20415
  }
20392
20416
  }
20393
- const token = randomBytes3(32).toString("base64url");
20417
+ const token = randomBytes5(32).toString("base64url");
20394
20418
  const { createServer } = await import("node:http");
20395
20419
  const server = createServer((req, res) => {
20396
20420
  if (req.method !== "POST" || req.url !== "/events") return reply(res, 404, { error: "not_found" });
@@ -20591,7 +20615,7 @@ var init_status3 = __esm({
20591
20615
  });
20592
20616
 
20593
20617
  // src/work/files.ts
20594
- import { closeSync as closeSync2, constants, fchmodSync, fstatSync, lstatSync, openSync as openSync2, readFileSync as readFileSync18, writeFileSync as writeFileSync9 } from "node:fs";
20618
+ import { closeSync as closeSync3, constants, fchmodSync as fchmodSync2, fstatSync, lstatSync, openSync as openSync3, readFileSync as readFileSync18, writeFileSync as writeFileSync9 } from "node:fs";
20595
20619
  import { join as join23 } from "node:path";
20596
20620
  function agentName(value) {
20597
20621
  if (typeof value !== "string") return void 0;
@@ -20612,26 +20636,26 @@ function writeWorkFile(dir3, work, mode = 384) {
20612
20636
  const name = workFileName(work.claimId);
20613
20637
  if (!isPlainFileName(work.answersFile)) throw new Error("answersFile is not a plain file name");
20614
20638
  const path = join23(dir3, name);
20615
- const fd = openSync2(path, "wx", mode);
20639
+ const fd = openSync3(path, "wx", mode);
20616
20640
  try {
20617
20641
  writeFileSync9(fd, JSON.stringify(work, null, 2) + "\n", "utf8");
20618
- fchmodSync(fd, mode);
20642
+ fchmodSync2(fd, mode);
20619
20643
  } finally {
20620
- closeSync2(fd);
20644
+ closeSync3(fd);
20621
20645
  }
20622
20646
  return path;
20623
20647
  }
20624
20648
  function readRegularFile(path, what) {
20625
20649
  const notPlain = { ok: false, error: `the ${what} is not a plain file` };
20626
20650
  if (!lstatSync(path).isFile()) return notPlain;
20627
- const fd = openSync2(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
20651
+ const fd = openSync3(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
20628
20652
  try {
20629
20653
  const stat4 = fstatSync(fd);
20630
20654
  if (!stat4.isFile()) return notPlain;
20631
20655
  if (stat4.size > MAX_ANSWERS_FILE_BYTES) return { ok: false, error: `the ${what} is too large` };
20632
20656
  return readFileSync18(fd, "utf8");
20633
20657
  } finally {
20634
- closeSync2(fd);
20658
+ closeSync3(fd);
20635
20659
  }
20636
20660
  }
20637
20661
  function isObject2(value) {
@@ -21564,7 +21588,7 @@ var init_egress = __esm({
21564
21588
 
21565
21589
  // src/work/job.ts
21566
21590
  import { spawn as nodeSpawn3 } from "node:child_process";
21567
- import { rmSync as rmSync5, statSync as statSync4 } from "node:fs";
21591
+ import { rmSync as rmSync6, statSync as statSync5 } from "node:fs";
21568
21592
  import { access, constants as constants2 } from "node:fs/promises";
21569
21593
  import { delimiter as delimiter2, join as join26 } from "node:path";
21570
21594
  import { setTimeout as delay12 } from "node:timers/promises";
@@ -21585,7 +21609,7 @@ function childEnv(parent, adapter, extra) {
21585
21609
  async function isExecutableFile(path) {
21586
21610
  try {
21587
21611
  await access(path, constants2.X_OK);
21588
- return statSync4(path).isFile();
21612
+ return statSync5(path).isFile();
21589
21613
  } catch {
21590
21614
  return false;
21591
21615
  }
@@ -21777,7 +21801,7 @@ async function runAgentJob(adapter, job, deps) {
21777
21801
  }
21778
21802
  const answersPath = join26(job.cwd, job.answersFile);
21779
21803
  try {
21780
- rmSync5(answersPath, { force: true });
21804
+ rmSync6(answersPath, { force: true });
21781
21805
  } catch (err) {
21782
21806
  return result("fatal", null, `the answers path could not be cleared: ${err.message}`);
21783
21807
  }
@@ -22317,7 +22341,7 @@ var init_adapters = __esm({
22317
22341
  });
22318
22342
 
22319
22343
  // src/work/scan.ts
22320
- import { createHmac as createHmac2, randomBytes as randomBytes4 } from "node:crypto";
22344
+ import { createHmac as createHmac2, randomBytes as randomBytes6 } from "node:crypto";
22321
22345
  function fold(text5) {
22322
22346
  return text5.normalize("NFKC").replace(/[^A-Za-z0-9]/g, "").toLowerCase();
22323
22347
  }
@@ -22435,7 +22459,7 @@ var init_scan = __esm({
22435
22459
  TOKEN_RUN = /[A-Za-z0-9+/=_.-]{16,}/g;
22436
22460
  LINK = /^\W*(?:[a-z][a-z0-9+.-]*:\/\/|www\.)|^[^/]*\.[a-z]{2,}\//i;
22437
22461
  CredentialIndex = class {
22438
- key = randomBytes4(32);
22462
+ key = randomBytes6(32);
22439
22463
  exact = /* @__PURE__ */ new Set();
22440
22464
  folded = /* @__PURE__ */ new Set();
22441
22465
  /** Adds a credential file's text: its JSON string values (keys skipped), or the whole text when it is not JSON. */
@@ -22581,7 +22605,7 @@ var init_credentials = __esm({
22581
22605
  });
22582
22606
 
22583
22607
  // src/work/guide.ts
22584
- import { closeSync as closeSync3, fchmodSync as fchmodSync2, openSync as openSync3, writeFileSync as writeFileSync10 } from "node:fs";
22608
+ import { closeSync as closeSync4, fchmodSync as fchmodSync3, openSync as openSync4, writeFileSync as writeFileSync10 } from "node:fs";
22585
22609
  import { join as join29 } from "node:path";
22586
22610
  function agentGuide(opts) {
22587
22611
  const browser = opts.browser ?? findOperation("browser-runs", "create") !== void 0;
@@ -22590,12 +22614,12 @@ function agentGuide(opts) {
22590
22614
  }
22591
22615
  function writeAgentGuide(dir3, text5, mode = WORK_FILE_MODE) {
22592
22616
  for (const name of GUIDE_FILES) {
22593
- const fd = openSync3(join29(dir3, name), "wx", mode);
22617
+ const fd = openSync4(join29(dir3, name), "wx", mode);
22594
22618
  try {
22595
22619
  writeFileSync10(fd, text5, "utf8");
22596
- fchmodSync2(fd, mode);
22620
+ fchmodSync3(fd, mode);
22597
22621
  } finally {
22598
- closeSync3(fd);
22622
+ closeSync4(fd);
22599
22623
  }
22600
22624
  }
22601
22625
  }