@docyrus/docyrus 0.0.39 → 0.0.40

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/main.js CHANGED
@@ -100323,7 +100323,7 @@ var require_snapshot_utils = __commonJS({
100323
100323
  var require_snapshot_recorder = __commonJS({
100324
100324
  "../../node_modules/.pnpm/undici@7.22.0/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
100325
100325
  "use strict";
100326
- var { writeFile: writeFile9, readFile: readFile16, mkdir: mkdir10 } = require("node:fs/promises");
100326
+ var { writeFile: writeFile9, readFile: readFile17, mkdir: mkdir10 } = require("node:fs/promises");
100327
100327
  var { dirname: dirname13, resolve: resolve2 } = require("node:path");
100328
100328
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
100329
100329
  var { InvalidArgumentError, UndiciError } = require_errors3();
@@ -100525,7 +100525,7 @@ var require_snapshot_recorder = __commonJS({
100525
100525
  throw new InvalidArgumentError("Snapshot path is required");
100526
100526
  }
100527
100527
  try {
100528
- const data = await readFile16(resolve2(path3), "utf8");
100528
+ const data = await readFile17(resolve2(path3), "utf8");
100529
100529
  const parsed = JSON.parse(data);
100530
100530
  if (Array.isArray(parsed)) {
100531
100531
  this.#snapshots.clear();
@@ -137151,13 +137151,16 @@ function buildInputSchema(args2, env2, options2) {
137151
137151
  // package.json
137152
137152
  var package_default = {
137153
137153
  name: "@docyrus/docyrus",
137154
- version: "0.0.39",
137154
+ version: "0.0.40",
137155
137155
  private: false,
137156
137156
  description: "Docyrus API CLI",
137157
137157
  main: "./main.js",
137158
137158
  bin: {
137159
137159
  docyrus: "main.js"
137160
137160
  },
137161
+ scripts: {
137162
+ postinstall: "node ./resources/officecli/install.mjs"
137163
+ },
137161
137164
  dependencies: {
137162
137165
  "@clack/prompts": "^0.11.0",
137163
137166
  "@hono/node-server": "^1.14.1",
@@ -150055,7 +150058,7 @@ var DOCYRUS_EXTERNAL_SKILL_AGENT_IDS = [
150055
150058
  ];
150056
150059
  var DOCYRUS_EXTERNAL_SKILL_MARKER_FILE = ".docyrus-external-skills-installed.json";
150057
150060
  var DOCYRUS_DIFFITY_PACKAGE_SPEC = "diffity@0.9.0";
150058
- var DOCYRUS_OFFICECLI_RELEASES_BASE_URL = "https://github.com/iOfficeAI/OfficeCli/releases/latest/download";
150061
+ var DOCYRUS_OFFICECLI_MANIFEST_FILE_NAME = "manifest.json";
150059
150062
  function summarizeFailure3(result, commandLabel = "Command") {
150060
150063
  const stderr = result.stderr?.toString().trim();
150061
150064
  if (stderr && stderr.length > 0) {
@@ -150416,6 +150419,12 @@ async function ensureManagedDiffityInstalled(params) {
150416
150419
  function resolvePackagedDocyrusPlatformSkillPath(resourceRoot) {
150417
150420
  return (0, import_node_path23.join)(resourceRoot, "skills", DOCYRUS_PACKAGED_PLATFORM_SKILL_NAME);
150418
150421
  }
150422
+ function resolvePackagedOfficeCliRootPath(resourceRoot) {
150423
+ return (0, import_node_path23.join)((0, import_node_path23.resolve)(resourceRoot, ".."), "officecli");
150424
+ }
150425
+ function resolvePackagedOfficeCliManifestPath(resourceRoot) {
150426
+ return (0, import_node_path23.join)(resolvePackagedOfficeCliRootPath(resourceRoot), DOCYRUS_OFFICECLI_MANIFEST_FILE_NAME);
150427
+ }
150419
150428
  function resolveManagedOfficeCliInstallRoot(agentRootPath) {
150420
150429
  return (0, import_node_path23.join)(agentRootPath, "tools", "officecli");
150421
150430
  }
@@ -150425,43 +150434,112 @@ function resolveManagedOfficeCliExecutablePath(agentRootPath) {
150425
150434
  process.platform === "win32" ? "officecli.exe" : "officecli"
150426
150435
  );
150427
150436
  }
150428
- function resolveOfficeCliReleaseAssetName() {
150429
- switch (process.platform) {
150437
+ function resolveOfficeCliReleaseAssetName(options2 = {}) {
150438
+ const platform2 = options2.platform ?? process.platform;
150439
+ const arch = options2.arch ?? process.arch;
150440
+ const isAlpine = options2.isAlpine ?? (0, import_node_fs12.existsSync)("/etc/alpine-release");
150441
+ switch (platform2) {
150430
150442
  case "darwin":
150431
- if (process.arch === "arm64") {
150443
+ if (arch === "arm64") {
150432
150444
  return "officecli-mac-arm64";
150433
150445
  }
150434
- if (process.arch === "x64") {
150446
+ if (arch === "x64") {
150435
150447
  return "officecli-mac-x64";
150436
150448
  }
150437
150449
  break;
150438
150450
  case "linux": {
150439
- const alpineSuffix = (0, import_node_fs12.existsSync)("/etc/alpine-release") ? "-alpine" : "";
150440
- if (process.arch === "arm64") {
150451
+ const alpineSuffix = isAlpine ? "-alpine" : "";
150452
+ if (arch === "arm64") {
150441
150453
  return `officecli-linux${alpineSuffix}-arm64`;
150442
150454
  }
150443
- if (process.arch === "x64") {
150455
+ if (arch === "x64") {
150444
150456
  return `officecli-linux${alpineSuffix}-x64`;
150445
150457
  }
150446
150458
  break;
150447
150459
  }
150448
150460
  case "win32":
150449
- if (process.arch === "arm64") {
150461
+ if (arch === "arm64") {
150450
150462
  return "officecli-win-arm64.exe";
150451
150463
  }
150452
- if (process.arch === "x64") {
150464
+ if (arch === "x64") {
150453
150465
  return "officecli-win-x64.exe";
150454
150466
  }
150455
150467
  break;
150456
150468
  default:
150457
150469
  break;
150458
150470
  }
150459
- throw new UserInputError(`OfficeCLI is not supported on ${process.platform}/${process.arch}.`);
150471
+ throw new UserInputError(`OfficeCLI is not supported on ${platform2}/${arch}.`);
150472
+ }
150473
+ function resolvePackagedOfficeCliExecutablePath(resourceRoot, options2) {
150474
+ return (0, import_node_path23.join)(
150475
+ resolvePackagedOfficeCliRootPath(resourceRoot),
150476
+ "bundled",
150477
+ resolveOfficeCliReleaseAssetName(options2)
150478
+ );
150479
+ }
150480
+ async function readPackagedOfficeCliVersion(resourceRoot) {
150481
+ const manifestRaw = await (0, import_promises17.readFile)(resolvePackagedOfficeCliManifestPath(resourceRoot), "utf8");
150482
+ const manifest = JSON.parse(manifestRaw);
150483
+ const version2 = typeof manifest.version === "string" ? manifest.version.trim() : "";
150484
+ if (version2.length === 0) {
150485
+ throw new UserInputError("OfficeCLI manifest is missing a valid version.");
150486
+ }
150487
+ return version2;
150488
+ }
150489
+ async function downloadOfficeCliBinary(params) {
150490
+ const assetName = resolveOfficeCliReleaseAssetName();
150491
+ const version2 = await readPackagedOfficeCliVersion(params.resourceRoot);
150492
+ const response = await fetch(`https://github.com/iOfficeAI/OfficeCLI/releases/download/v${version2}/${assetName}`);
150493
+ if (!response.ok) {
150494
+ throw new UserInputError(`OfficeCLI download failed with status ${response.status}.`);
150495
+ }
150496
+ const binary2 = Buffer.from(await response.arrayBuffer());
150497
+ await (0, import_promises17.writeFile)(params.destinationPath, binary2, {
150498
+ mode: process.platform === "win32" ? 384 : 448
150499
+ });
150500
+ }
150501
+ function resolveManagedOfficeCliConfigMarkerPath(agentRootPath) {
150502
+ return (0, import_node_path23.join)(resolveManagedOfficeCliInstallRoot(agentRootPath), ".docyrus-officecli-configured.json");
150503
+ }
150504
+ async function disableManagedOfficeCliAutoUpdate(params) {
150505
+ const markerPath = resolveManagedOfficeCliConfigMarkerPath(params.agentRootPath);
150506
+ if ((0, import_node_fs12.existsSync)(markerPath)) {
150507
+ return;
150508
+ }
150509
+ const result = params.spawnCommand(params.executablePath, ["config", "autoUpdate", "false"], {
150510
+ stdio: ["ignore", "pipe", "pipe"],
150511
+ encoding: "utf8",
150512
+ cwd: params.cwd,
150513
+ env: {
150514
+ ...process.env,
150515
+ OFFICECLI_SKIP_UPDATE: "1"
150516
+ }
150517
+ });
150518
+ if (result.error || result.status !== 0) {
150519
+ process.stderr.write(
150520
+ `[docyrus] OfficeCLI auto-update disable failed. Continuing with env override only: ${result.error?.message || summarizeFailure3(result, "officecli config autoUpdate false")}
150521
+ `
150522
+ );
150523
+ return;
150524
+ }
150525
+ await (0, import_promises17.writeFile)(markerPath, `${JSON.stringify({
150526
+ configuredAt: (/* @__PURE__ */ new Date()).toISOString()
150527
+ }, null, 2)}
150528
+ `, {
150529
+ encoding: "utf8",
150530
+ mode: 384
150531
+ });
150460
150532
  }
150461
150533
  async function ensureManagedOfficeCliInstalled(params) {
150462
150534
  const executablePath = resolveManagedOfficeCliExecutablePath(params.agentRootPath);
150463
150535
  const binDir = (0, import_node_path23.dirname)(executablePath);
150464
150536
  if ((0, import_node_fs12.existsSync)(executablePath)) {
150537
+ await disableManagedOfficeCliAutoUpdate({
150538
+ agentRootPath: params.agentRootPath,
150539
+ executablePath,
150540
+ cwd: params.cwd,
150541
+ spawnCommand: params.spawnCommand
150542
+ });
150465
150543
  return {
150466
150544
  available: true,
150467
150545
  executablePath,
@@ -150474,15 +150552,17 @@ async function ensureManagedOfficeCliInstalled(params) {
150474
150552
  recursive: true,
150475
150553
  mode: 448
150476
150554
  });
150477
- const assetName = resolveOfficeCliReleaseAssetName();
150478
- const response = await fetch(`${DOCYRUS_OFFICECLI_RELEASES_BASE_URL}/${assetName}`);
150479
- if (!response.ok) {
150480
- throw new UserInputError(`OfficeCLI download failed with status ${response.status}.`);
150555
+ const bundledExecutablePath = resolvePackagedOfficeCliExecutablePath(params.resourceRoot);
150556
+ if ((0, import_node_fs12.existsSync)(bundledExecutablePath)) {
150557
+ await (0, import_promises17.cp)(bundledExecutablePath, tempPath, {
150558
+ force: true
150559
+ });
150560
+ } else {
150561
+ await downloadOfficeCliBinary({
150562
+ resourceRoot: params.resourceRoot,
150563
+ destinationPath: tempPath
150564
+ });
150481
150565
  }
150482
- const binary2 = Buffer.from(await response.arrayBuffer());
150483
- await (0, import_promises17.writeFile)(tempPath, binary2, {
150484
- mode: process.platform === "win32" ? 384 : 448
150485
- });
150486
150566
  if (process.platform !== "win32") {
150487
150567
  await (0, import_promises17.chmod)(tempPath, 448);
150488
150568
  }
@@ -150504,6 +150584,12 @@ async function ensureManagedOfficeCliInstalled(params) {
150504
150584
  if (process.platform !== "win32") {
150505
150585
  await (0, import_promises17.chmod)(executablePath, 448);
150506
150586
  }
150587
+ await disableManagedOfficeCliAutoUpdate({
150588
+ agentRootPath: params.agentRootPath,
150589
+ executablePath,
150590
+ cwd: params.cwd,
150591
+ spawnCommand: params.spawnCommand
150592
+ });
150507
150593
  return {
150508
150594
  available: true,
150509
150595
  executablePath,
@@ -150616,6 +150702,7 @@ function createPiAgentLauncher(options2) {
150616
150702
  });
150617
150703
  const officeCli = await ensureManagedOfficeCliInstalled({
150618
150704
  agentRootPath,
150705
+ resourceRoot,
150619
150706
  cwd,
150620
150707
  spawnCommand
150621
150708
  });
@@ -150734,6 +150821,7 @@ function createPiAgentServerLauncher(options2) {
150734
150821
  spinner.update("Installing tools...");
150735
150822
  const officeCli = await ensureManagedOfficeCliInstalled({
150736
150823
  agentRootPath,
150824
+ resourceRoot,
150737
150825
  cwd,
150738
150826
  spawnCommand: import_node_child_process7.spawnSync
150739
150827
  });