approval-box 0.1.27 → 0.1.29

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/dist/cli.mjs +57 -32
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -11816,7 +11816,7 @@ var require_dist = __commonJS({
11816
11816
 
11817
11817
  // src/cli.ts
11818
11818
  var import_qrcode = __toESM(require_lib(), 1);
11819
- import { cpSync, existsSync as existsSync7, mkdirSync as mkdirSync5, rmSync as rmSync3 } from "node:fs";
11819
+ import { cpSync, existsSync as existsSync7, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
11820
11820
  import { hostname } from "node:os";
11821
11821
  import { join as join10 } from "node:path";
11822
11822
  import { createInterface } from "node:readline/promises";
@@ -11914,7 +11914,7 @@ var Api = class {
11914
11914
  };
11915
11915
 
11916
11916
  // src/config.ts
11917
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
11917
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
11918
11918
  import { dirname, join } from "node:path";
11919
11919
  var OFFICIAL_SERVER = "https://approval-box.kitepon.dev";
11920
11920
  var configFile = () => join(home(), "config.json");
@@ -11930,9 +11930,18 @@ function requireConfig() {
11930
11930
  function writeJsonFile(file, value) {
11931
11931
  mkdirSync(dirname(file), { recursive: true, mode: 448 });
11932
11932
  const temp = `${file}.${process.pid}.tmp`;
11933
- writeFileSync(temp, `${JSON.stringify(value, null, 2)}
11933
+ try {
11934
+ writeFileSync(temp, `${JSON.stringify(value, null, 2)}
11934
11935
  `, { mode: 384 });
11935
- renameSync(temp, file);
11936
+ renameSync(temp, file);
11937
+ } catch (error) {
11938
+ try {
11939
+ rmSync(temp, { force: true });
11940
+ } catch {
11941
+ process.stderr.write("approval-box: \u4FDD\u5B58\u306B\u5931\u6557\u3057\u305F\u4E00\u6642\u30D5\u30A1\u30A4\u30EB\u3092\u56DE\u53CE\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\n");
11942
+ }
11943
+ throw error;
11944
+ }
11936
11945
  }
11937
11946
  function writeConfig(config) {
11938
11947
  writeJsonFile(configFile(), config);
@@ -11940,11 +11949,32 @@ function writeConfig(config) {
11940
11949
 
11941
11950
  // src/daemon-launch.ts
11942
11951
  import { spawn, spawnSync } from "node:child_process";
11943
- import { appendFileSync, closeSync, openSync } from "node:fs";
11952
+ import { writeFileSync as writeFileSync2 } from "node:fs";
11944
11953
  import { join as join2, resolve } from "node:path";
11954
+ function daemonBootstrap(entry, cwd, environment = {}) {
11955
+ return `Object.assign(process.env,${JSON.stringify(environment)});
11956
+ const fs=require('node:fs'),file=${JSON.stringify(join2(cwd, "daemon.log"))},fallback=process.stderr.write.bind(process.stderr);
11957
+ process.stderr.write=(chunk,encoding,callback)=>{
11958
+ try {
11959
+ const limit=1024*1024,next=Buffer.from(chunk,typeof encoding==='string'?encoding:undefined).subarray(-limit);
11960
+ const fd=fs.openSync(file,fs.constants.O_CREAT|fs.constants.O_RDWR,0o600);
11961
+ try {
11962
+ const size=fs.fstatSync(fd).size,keep=Math.min(size,limit-next.length),data=Buffer.alloc(keep+next.length);
11963
+ const read=keep?fs.readSync(fd,data,0,keep,size-keep):0;
11964
+ next.copy(data,read);
11965
+ fs.writeFileSync(fd,data.subarray(0,read+next.length));
11966
+ fs.ftruncateSync(fd,read+next.length);
11967
+ } finally { fs.closeSync(fd); }
11968
+ } catch { try { fallback('approval-box: daemon log write failed\\n'); } catch {} }
11969
+ if(typeof encoding==='function')encoding();else if(typeof callback==='function')callback();
11970
+ return true;
11971
+ };
11972
+ process.argv=[process.execPath,${JSON.stringify(entry)},'daemon'];
11973
+ import(require('node:url').pathToFileURL(${JSON.stringify(entry)}).href).catch(error=>{process.stderr.write(String(error)+'\\n');process.exit(1);});`;
11974
+ }
11945
11975
  function windowsDaemonLaunchScript(executable, entry, cwd, environment) {
11946
11976
  const env = Object.fromEntries(["APPROVAL_BOX_HOME", "HOME", "USERPROFILE", "APPDATA", "LOCALAPPDATA", "PATH", "CODEX_HOME", "GROK_HOME", "CODEX_BIN"].flatMap((key) => environment[key] === void 0 ? [] : [[key, environment[key]]]));
11947
- const bootstrap = `Object.assign(process.env,${JSON.stringify(env)});const fs=require('node:fs');process.stderr.write=(text)=>{fs.appendFileSync(${JSON.stringify(join2(cwd, "daemon.log"))},text);return true;};process.argv=[process.execPath,${JSON.stringify(entry)},'daemon'];import(require('node:url').pathToFileURL(${JSON.stringify(entry)}).href).catch(error=>{process.stderr.write(String(error)+'\\n');process.exit(1);});`;
11977
+ const bootstrap = daemonBootstrap(entry, cwd, env);
11948
11978
  const command2 = `"${executable}" -e "eval(Buffer.from('${Buffer.from(bootstrap).toString("base64")}','base64').toString())"`;
11949
11979
  const literal2 = (s) => `'${s.replaceAll("'", "''")}'`;
11950
11980
  return `$ErrorActionPreference='Stop';$ProgressPreference='SilentlyContinue';$startup=New-CimInstance -ClassName Win32_ProcessStartup -ClientOnly -Property @{ShowWindow=[uint16]0};$result=Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{CommandLine=${literal2(command2)};CurrentDirectory=${literal2(cwd)};ProcessStartupInformation=$startup};if($result.ReturnValue -ne 0){throw ('daemon creation failed: '+$result.ReturnValue)};$result.ProcessId`;
@@ -11958,22 +11988,17 @@ function launchDaemon(executable, entry, cwd) {
11958
11988
  return;
11959
11989
  }
11960
11990
  const file = join2(cwd, "daemon.log");
11961
- const log = openSync(file, "a", 384);
11962
- try {
11963
- const child = spawn(executable, [entry, "daemon"], { cwd, detached: true, stdio: ["ignore", "ignore", log], windowsHide: true });
11964
- child.on("error", (error) => {
11965
- const line = `approval-box: \u914D\u9001\u30C7\u30FC\u30E2\u30F3\u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\uFF08DAEMON_LAUNCH_FAILED\uFF09: ${executable}: ${error.message}
11991
+ const child = spawn(executable, ["-e", daemonBootstrap(entry, cwd)], { cwd, detached: true, stdio: "ignore", windowsHide: true });
11992
+ child.on("error", (error) => {
11993
+ const line = `approval-box: \u914D\u9001\u30C7\u30FC\u30E2\u30F3\u3092\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\uFF08DAEMON_LAUNCH_FAILED\uFF09: ${executable}: ${error.message}
11966
11994
  `;
11967
- try {
11968
- appendFileSync(file, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}`, { mode: 384 });
11969
- } catch {
11970
- }
11971
- process.stderr.write(line);
11972
- });
11973
- child.unref();
11974
- } finally {
11975
- closeSync(log);
11976
- }
11995
+ try {
11996
+ writeFileSync2(file, Buffer.from(`${(/* @__PURE__ */ new Date()).toISOString()} ${line}`).subarray(-1024 * 1024), { mode: 384 });
11997
+ } catch {
11998
+ }
11999
+ process.stderr.write(line);
12000
+ });
12001
+ child.unref();
11977
12002
  }
11978
12003
 
11979
12004
  // src/channel-delivery.ts
@@ -12006,12 +12031,12 @@ async function channelAnswerState(channelId, deliveryId, codex = provider) {
12006
12031
  }
12007
12032
 
12008
12033
  // src/daemon.ts
12009
- import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync as rmSync2 } from "node:fs";
12034
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync as rmSync3 } from "node:fs";
12010
12035
  import { join as join5 } from "node:path";
12011
12036
 
12012
12037
  // src/attachments.ts
12013
12038
  import { createHash } from "node:crypto";
12014
- import { existsSync as existsSync2, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmSync, statSync, writeFileSync as writeFileSync2 } from "node:fs";
12039
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmSync as rmSync2, statSync, writeFileSync as writeFileSync3 } from "node:fs";
12015
12040
  import { join as join3 } from "node:path";
12016
12041
  var KEEP_DAYS = 30;
12017
12042
  var attachmentsRoot = () => join3(home(), "attachments");
@@ -12026,7 +12051,7 @@ async function saveAttachment(api, decisionId, meta, index) {
12026
12051
  const data = await api.download(`/decisions/${encodeURIComponent(decisionId)}/attachments/${encodeURIComponent(meta.id)}`);
12027
12052
  if (sha256(data) !== meta.sha256) throw new Error(`${meta.name} \u306E\u4E2D\u8EAB\u304C\u30B5\u30FC\u30D0\u30FC\u306E\u8A18\u9332\u3068\u5408\u3044\u307E\u305B\u3093\uFF08\u53D6\u308A\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\uFF09`);
12028
12053
  mkdirSync2(dir, { recursive: true, mode: 448 });
12029
- writeFileSync2(file, data, { mode: 384 });
12054
+ writeFileSync3(file, data, { mode: 384 });
12030
12055
  return file;
12031
12056
  }
12032
12057
  async function saveAll(api, decisionId, items) {
@@ -12047,7 +12072,7 @@ function pruneAttachments() {
12047
12072
  for (const name of readdirSync(root)) {
12048
12073
  const dir = join3(root, name);
12049
12074
  try {
12050
- if (statSync(dir).mtimeMs < before) rmSync(dir, { recursive: true, force: true });
12075
+ if (statSync(dir).mtimeMs < before) rmSync2(dir, { recursive: true, force: true });
12051
12076
  } catch {
12052
12077
  }
12053
12078
  }
@@ -12249,7 +12274,7 @@ async function runDaemon() {
12249
12274
  const releaseLock = () => {
12250
12275
  try {
12251
12276
  const lock = JSON.parse(readFileSync3(lockFile(), "utf8"));
12252
- if (lock.pid === process.pid) rmSync2(lockFile(), { force: true });
12277
+ if (lock.pid === process.pid) rmSync3(lockFile(), { force: true });
12253
12278
  } catch {
12254
12279
  }
12255
12280
  };
@@ -12304,7 +12329,7 @@ import { homedir as homedir2 } from "node:os";
12304
12329
  import { delimiter, dirname as dirname4, join as join7 } from "node:path";
12305
12330
 
12306
12331
  // src/instructions.ts
12307
- import { existsSync as existsSync4, lstatSync, mkdirSync as mkdirSync4, readFileSync as readFileSync4, readdirSync as readdirSync2, readlinkSync, writeFileSync as writeFileSync3 } from "node:fs";
12332
+ import { existsSync as existsSync4, lstatSync, mkdirSync as mkdirSync4, readFileSync as readFileSync4, readdirSync as readdirSync2, readlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
12308
12333
  import { homedir } from "node:os";
12309
12334
  import { dirname as dirname3, join as join6, resolve as resolve2 } from "node:path";
12310
12335
  var INSTRUCTION_TEXT = "\u30E6\u30FC\u30B6\u30FC\u306E\u5224\u65AD\u30FB\u627F\u8A8D\u30FB\u64CD\u4F5C\u304C\u5FC5\u8981\u306A\u3068\u304D\u306F\u3001\u6C7A\u88C1\u30B7\u30B9\u30C6\u30E0\u3067\u3042\u308B Approval Box \u306E request_decision \u3067\u3082\u7533\u8ACB\u3059\u308B\u3002\u3053\u308C\u3092\u4F7F\u3048\u3070\u30E6\u30FC\u30B6\u30FC\u304C\u7533\u8ACB\u306B\u6C17\u3065\u304D\u3084\u3059\u3044\u306E\u3067\u3001\u5F37\u304F\u63A8\u5968\u3059\u308B\u3002";
@@ -12352,7 +12377,7 @@ function writeInstructions(file) {
12352
12377
  if (managedElsewhere(file)) return "managed_elsewhere";
12353
12378
  const current = existsSync4(file) ? readFileSync4(file, "utf8").replace(PATTERN, "\n").trimEnd() : "";
12354
12379
  mkdirSync4(dirname3(file), { recursive: true, mode: 448 });
12355
- writeFileSync3(file, current ? `${current}
12380
+ writeFileSync4(file, current ? `${current}
12356
12381
 
12357
12382
  ${BLOCK}` : BLOCK);
12358
12383
  return "written";
@@ -12360,7 +12385,7 @@ ${BLOCK}` : BLOCK);
12360
12385
  function removeInstructions(file) {
12361
12386
  if (!existsSync4(file) || !readFileSync4(file, "utf8").includes(START)) return;
12362
12387
  const rest = readFileSync4(file, "utf8").replace(PATTERN, "\n").trimEnd();
12363
- writeFileSync3(file, rest ? `${rest}
12388
+ writeFileSync4(file, rest ? `${rest}
12364
12389
  ` : "");
12365
12390
  }
12366
12391
 
@@ -16001,7 +16026,7 @@ function claudeChannelIsCurrent(profile, channelId, parent) {
16001
16026
  }
16002
16027
 
16003
16028
  // src/version.ts
16004
- var VERSION = true ? "0.1.27" : "0.0.0-dev";
16029
+ var VERSION = true ? "0.1.29" : "0.0.0-dev";
16005
16030
  function osName() {
16006
16031
  return process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : process.platform;
16007
16032
  }
@@ -16391,7 +16416,7 @@ async function ask(question) {
16391
16416
  function installRuntime() {
16392
16417
  const target = join10(home(), "runtime", VERSION);
16393
16418
  if (runtimeDir() !== target) {
16394
- rmSync3(target, { recursive: true, force: true });
16419
+ rmSync4(target, { recursive: true, force: true });
16395
16420
  mkdirSync5(target, { recursive: true });
16396
16421
  cpSync(runtimeDir(), target, { recursive: true });
16397
16422
  }
@@ -16540,7 +16565,7 @@ async function uninstall() {
16540
16565
  out(` \u30B5\u30FC\u30D0\u30FC: \u63A5\u7D9A\u306E\u89E3\u9664\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08\u30A2\u30D7\u30EA\u306E\u300C\u63A5\u7D9A\u300D\u304B\u3089\u5916\u3057\u3066\u304F\u3060\u3055\u3044\uFF09: ${error.message}`);
16541
16566
  }
16542
16567
  }
16543
- rmSync3(join10(home(), "config.json"), { force: true });
16568
+ rmSync4(join10(home(), "config.json"), { force: true });
16544
16569
  out("\nApproval Box\u3092\u5916\u3057\u307E\u3057\u305F\u3002npm install -g \u3067\u5165\u308C\u305F\u5834\u5408\u306F\u3001npm uninstall -g approval-box \u3067\u672C\u4F53\u3082\u6D88\u305B\u307E\u3059\u3002");
16545
16570
  }
16546
16571
  async function status() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "approval-box",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Approval Box connector: lets Claude Code, Codex, Cursor and Grok ask you for a decision, and steers your answer back into the same session.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://approval-box.kitepon.dev",