engine7 7.1.122 → 7.1.123

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 +69 -39
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -861,8 +861,8 @@ function parseWall(s) {
861
861
  warnOnce("parseWall", "unparseable", raw);
862
862
  return raw;
863
863
  }
864
- const tail = raw.slice(m[0].length);
865
- if (tail && !/^\.\d+$/.test(tail)) {
864
+ const tail2 = raw.slice(m[0].length);
865
+ if (tail2 && !/^\.\d+$/.test(tail2)) {
866
866
  warnOnce("parseWall", "unparseable-tail", raw);
867
867
  return raw;
868
868
  }
@@ -871,7 +871,7 @@ function parseWall(s) {
871
871
  warnOnce("parseWall", "out-of-range", raw);
872
872
  return raw;
873
873
  }
874
- const ms = tail ? Math.round(Number(`0${tail}`) * 1e3) : 0;
874
+ const ms = tail2 ? Math.round(Number(`0${tail2}`) * 1e3) : 0;
875
875
  return withMs(wallToUtc(Y, Mo, D, H, Mi, S), ms);
876
876
  }
877
877
  function daysInMonth(y, mo) {
@@ -10652,6 +10652,32 @@ var init_wechat = __esm({
10652
10652
  }
10653
10653
  });
10654
10654
 
10655
+ // src/cli-stdout.ts
10656
+ function writeTo(stream, text) {
10657
+ const p = new Promise((resolve20) => {
10658
+ stream.write(text, () => resolve20());
10659
+ });
10660
+ if (stream === process.stdout) tail = p;
10661
+ return p;
10662
+ }
10663
+ function writeStdout(text) {
10664
+ return writeTo(process.stdout, text);
10665
+ }
10666
+ function flushStdout() {
10667
+ return tail;
10668
+ }
10669
+ async function exitCli(code) {
10670
+ await flushStdout();
10671
+ return process.exit(code);
10672
+ }
10673
+ var tail;
10674
+ var init_cli_stdout = __esm({
10675
+ "src/cli-stdout.ts"() {
10676
+ "use strict";
10677
+ tail = Promise.resolve();
10678
+ }
10679
+ });
10680
+
10655
10681
  // src/cli-events.ts
10656
10682
  var cli_events_exports = {};
10657
10683
  __export(cli_events_exports, {
@@ -10660,7 +10686,7 @@ __export(cli_events_exports, {
10660
10686
  });
10661
10687
  function createEmitter(sink = process.stdout) {
10662
10688
  return (ev) => {
10663
- sink.write(JSON.stringify(ev) + "\n");
10689
+ void writeTo(sink, JSON.stringify(ev) + "\n");
10664
10690
  };
10665
10691
  }
10666
10692
  function redirectConsoleToStderr() {
@@ -10670,6 +10696,7 @@ function redirectConsoleToStderr() {
10670
10696
  var init_cli_events = __esm({
10671
10697
  "src/cli-events.ts"() {
10672
10698
  "use strict";
10699
+ init_cli_stdout();
10673
10700
  }
10674
10701
  });
10675
10702
 
@@ -14058,8 +14085,8 @@ var init_think_stripper = __esm({
14058
14085
  holdLen() {
14059
14086
  const b = this.buf;
14060
14087
  for (let k = Math.min(MAX_TAG - 1, b.length); k > 0; k--) {
14061
- const tail = b.slice(b.length - k);
14062
- if (OPEN.startsWith(tail) || CLOSE.startsWith(tail)) return k;
14088
+ const tail2 = b.slice(b.length - k);
14089
+ if (OPEN.startsWith(tail2) || CLOSE.startsWith(tail2)) return k;
14063
14090
  }
14064
14091
  return 0;
14065
14092
  }
@@ -40303,7 +40330,9 @@ function startStdinHandler() {
40303
40330
  }
40304
40331
  };
40305
40332
  const rl = readline2.createInterface({ input: process.stdin, terminal: false });
40306
- const respond = (obj) => process.stdout.write(JSON.stringify(obj) + "\n");
40333
+ const respond = (obj) => {
40334
+ void writeStdout(JSON.stringify(obj) + "\n");
40335
+ };
40307
40336
  rl.on("line", (line) => {
40308
40337
  const s = line.trim();
40309
40338
  if (!s) return;
@@ -40575,9 +40604,9 @@ async function doCcRun(argv) {
40575
40604
  if (mid) models.push(`${pid}/${mid}`);
40576
40605
  }
40577
40606
  }
40578
- process.stdout.write(JSON.stringify(models, null, 2) + "\n");
40607
+ await writeStdout(JSON.stringify(models, null, 2) + "\n");
40579
40608
  } catch (e) {
40580
- process.stdout.write("[]\n");
40609
+ await writeStdout("[]\n");
40581
40610
  process.stderr.write(`[cc-run] --list-models failed: ${e?.message}
40582
40611
  `);
40583
40612
  }
@@ -40662,21 +40691,20 @@ async function doCcRun(argv) {
40662
40691
  emitTurn(result, model);
40663
40692
  await flushStdout();
40664
40693
  } else {
40665
- process.stdout.write(result.text.endsWith("\n") ? result.text : result.text + "\n");
40666
- await flushStdout();
40694
+ await writeStdout(result.text.endsWith("\n") ? result.text : result.text + "\n");
40667
40695
  }
40668
40696
  return 0;
40669
40697
  }
40670
- function flushStdout() {
40671
- return new Promise((resolve20) => process.stdout.write("", () => resolve20()));
40672
- }
40673
40698
  var CCRUN_VERSION, writeLine;
40674
40699
  var init_cli_ccrun = __esm({
40675
40700
  "src/cli-ccrun.ts"() {
40676
40701
  "use strict";
40677
40702
  init_secrets_env();
40703
+ init_cli_stdout();
40678
40704
  CCRUN_VERSION = "7.1.57-ccrun";
40679
- writeLine = (obj) => process.stdout.write(JSON.stringify(obj) + "\n");
40705
+ writeLine = (obj) => {
40706
+ void writeStdout(JSON.stringify(obj) + "\n");
40707
+ };
40680
40708
  }
40681
40709
  });
40682
40710
 
@@ -41590,8 +41618,8 @@ function parseArgs(args) {
41590
41618
  const configName = CONFIG_NAME;
41591
41619
  return { stateDir, configPath: path40.join(stateDir, "configs", `${configName}.json`), configName, file: file2, badArgs };
41592
41620
  }
41593
- function emit2(obj) {
41594
- process.stdout.write(JSON.stringify(obj) + "\n");
41621
+ async function emit2(obj) {
41622
+ await writeStdout(JSON.stringify(obj) + "\n");
41595
41623
  }
41596
41624
  function put(obj, dotPath, val) {
41597
41625
  const keys = dotPath.split(".");
@@ -41713,7 +41741,7 @@ async function runConfigCommand(args) {
41713
41741
  return 2;
41714
41742
  }
41715
41743
  if (sub === "schema") {
41716
- emit2({ version: 1, fields: listSchemaFields() });
41744
+ await emit2({ version: 1, fields: listSchemaFields() });
41717
41745
  return 0;
41718
41746
  }
41719
41747
  if (sub === "get") {
@@ -41724,7 +41752,7 @@ async function runConfigCommand(args) {
41724
41752
  for (const f of listFields()) {
41725
41753
  if (f.type === "secret") names.add(secretEnvName(f.path, raw));
41726
41754
  }
41727
- emit2({
41755
+ await emit2({
41728
41756
  values: raw,
41729
41757
  secrets: readSecretStatus(p.stateDir, p.configName, [...names]),
41730
41758
  // 与上面的状态**同源**(都取"第一个存在的候选")。绝不把写路径(恒为候选 #1)
@@ -41806,14 +41834,14 @@ async function runConfigCommand(args) {
41806
41834
  flat[dotPath] = c.value;
41807
41835
  }
41808
41836
  if (errors.length > 0) {
41809
- emit2({ ok: false, ineffective, errors });
41837
+ await emit2({ ok: false, ineffective, errors });
41810
41838
  return 1;
41811
41839
  }
41812
41840
  const nested = {};
41813
41841
  for (const [dotPath, v] of Object.entries(flat)) put(nested, dotPath, v);
41814
41842
  const errs = validateAll(nested, current);
41815
41843
  if (errs.length > 0) {
41816
- emit2({ ok: false, ineffective: [], errors: errs });
41844
+ await emit2({ ok: false, ineffective: [], errors: errs });
41817
41845
  return 1;
41818
41846
  }
41819
41847
  const merged = JSON.parse(JSON.stringify(current));
@@ -41863,7 +41891,7 @@ async function runConfigCommand(args) {
41863
41891
  try {
41864
41892
  writeConfigAtomic(p.configPath, merged);
41865
41893
  } catch (e) {
41866
- emit2({ ok: false, ineffective: [], errors: [{ path: p.configPath, error: e?.message || String(e) }] });
41894
+ await emit2({ ok: false, ineffective: [], errors: [{ path: p.configPath, error: e?.message || String(e) }] });
41867
41895
  return 1;
41868
41896
  }
41869
41897
  for (const s of secretWrites) {
@@ -41892,7 +41920,7 @@ async function runConfigCommand(args) {
41892
41920
  }
41893
41921
  const changedDedup = [...new Set(changed)];
41894
41922
  if (failed.length > 0) {
41895
- emit2({
41923
+ await emit2({
41896
41924
  ok: false,
41897
41925
  ineffective: [],
41898
41926
  failed: failed.map((f) => f.path),
@@ -41906,7 +41934,7 @@ async function runConfigCommand(args) {
41906
41934
  });
41907
41935
  return 1;
41908
41936
  }
41909
- emit2({
41937
+ await emit2({
41910
41938
  ok: true,
41911
41939
  changed: changedDedup,
41912
41940
  needsRestart: needsRestart(changedDedup),
@@ -41917,7 +41945,7 @@ async function runConfigCommand(args) {
41917
41945
  if (sub === "migrate") {
41918
41946
  try {
41919
41947
  const r = migrateChannelSecrets(p.configPath);
41920
- emit2({
41948
+ await emit2({
41921
41949
  ok: true,
41922
41950
  changed: r.changed,
41923
41951
  backup: r.backup,
@@ -41926,7 +41954,7 @@ async function runConfigCommand(args) {
41926
41954
  });
41927
41955
  return 0;
41928
41956
  } catch (e) {
41929
- emit2({
41957
+ await emit2({
41930
41958
  ok: false,
41931
41959
  changed: [],
41932
41960
  errors: [{ path: p.configPath, error: e?.message || String(e) }]
@@ -41947,6 +41975,7 @@ var init_cli_config = __esm({
41947
41975
  init_secrets_io();
41948
41976
  init_secrets_env();
41949
41977
  init_migrations2();
41978
+ init_cli_stdout();
41950
41979
  init_persona();
41951
41980
  init_channel_secrets();
41952
41981
  CONFIG_NAME = "main7";
@@ -45324,6 +45353,7 @@ init_feishu_quick_register();
45324
45353
  init_wechat();
45325
45354
  init_qr_render();
45326
45355
  init_cli_events();
45356
+ init_cli_stdout();
45327
45357
  import * as readline3 from "node:readline";
45328
45358
  import { fileURLToPath as fileURLToPath13 } from "node:url";
45329
45359
 
@@ -46349,12 +46379,12 @@ async function main() {
46349
46379
  if (subcommand === "doctor") {
46350
46380
  const { runDoctor: runDoctor2, resolveStateDirFromArgs: resolveStateDirFromArgs2 } = await Promise.resolve().then(() => (init_cli_doctor(), cli_doctor_exports));
46351
46381
  const stateDir = resolveStateDirFromArgs2(args.slice(1));
46352
- console.log(JSON.stringify(await runDoctor2(stateDir), null, 2));
46353
- process.exit(0);
46382
+ await writeStdout(JSON.stringify(await runDoctor2(stateDir), null, 2) + "\n");
46383
+ await exitCli(0);
46354
46384
  }
46355
46385
  if (subcommand === "config") {
46356
46386
  const { runConfigCommand: runConfigCommand2 } = await Promise.resolve().then(() => (init_cli_config(), cli_config_exports));
46357
- process.exit(await runConfigCommand2(args.slice(1)));
46387
+ await exitCli(await runConfigCommand2(args.slice(1)));
46358
46388
  }
46359
46389
  if (subcommand === "mem-serve") {
46360
46390
  const { runMemServe: runMemServe2 } = await Promise.resolve().then(() => (init_cli(), cli_exports));
@@ -46382,8 +46412,8 @@ async function main() {
46382
46412
  // 和 init 写 config 的路径一致(cli-init.ts 里 configPath 就是这么拼的)
46383
46413
  configPath: path51.join(stateDir, "configs", "main7.json")
46384
46414
  });
46385
- console.log(JSON.stringify(result, null, 2));
46386
- process.exit(0);
46415
+ await writeStdout(JSON.stringify(result, null, 2) + "\n");
46416
+ await exitCli(0);
46387
46417
  } catch (e) {
46388
46418
  console.error(`\u9886\u53F7\u5931\u8D25\uFF1A${e?.message || e}`);
46389
46419
  process.exit(1);
@@ -46506,7 +46536,7 @@ async function main() {
46506
46536
  console.log(" \u4E0D\u91CD\u542F\u5F15\u64CE\u4F1A\u628A\u5B57\u9762\u91CF env:7YI_API_KEY \u5F53 key \u53D1\u51FA\u53BB \u2192 401\u3002");
46507
46537
  console.log(" engine7 restart");
46508
46538
  }
46509
- process.exit(0);
46539
+ await exitCli(0);
46510
46540
  }
46511
46541
  if (channel === "discord") {
46512
46542
  console.log("\u{1F527} Discord \u91CD\u914D\uFF08\u5F00\u53D1\u4E2D\uFF09");
@@ -46518,28 +46548,28 @@ async function main() {
46518
46548
  const { createEmitter: createEmitter2 } = await Promise.resolve().then(() => (init_cli_events(), cli_events_exports));
46519
46549
  if (events) redirectConsoleToStderr();
46520
46550
  const code = await doReconfigFeishu2({ stateDir, configName, events, emit: events ? createEmitter2() : void 0 });
46521
- process.exit(code);
46551
+ await exitCli(code);
46522
46552
  }
46523
46553
  if (channel === "wechat") {
46524
46554
  const { doReconfigWechat: doReconfigWechat2 } = await Promise.resolve().then(() => (init_cli_reconfig(), cli_reconfig_exports));
46525
46555
  const { createEmitter: createEmitter2 } = await Promise.resolve().then(() => (init_cli_events(), cli_events_exports));
46526
46556
  if (events) redirectConsoleToStderr();
46527
46557
  const code = await doReconfigWechat2({ stateDir, configName, events, emit: events ? createEmitter2() : void 0 });
46528
- process.exit(code);
46558
+ await exitCli(code);
46529
46559
  }
46530
46560
  if (channel === "dingtalk") {
46531
46561
  const { doReconfigDingtalk: doReconfigDingtalk2 } = await Promise.resolve().then(() => (init_cli_dingtalk_auth(), cli_dingtalk_auth_exports));
46532
46562
  const { createEmitter: createEmitter2 } = await Promise.resolve().then(() => (init_cli_events(), cli_events_exports));
46533
46563
  if (events) redirectConsoleToStderr();
46534
46564
  const code = await doReconfigDingtalk2({ stateDir, configName, events, emit: events ? createEmitter2() : void 0 });
46535
- process.exit(code);
46565
+ await exitCli(code);
46536
46566
  }
46537
46567
  if (channel === "wecom") {
46538
46568
  const { doReconfigWecom: doReconfigWecom2 } = await Promise.resolve().then(() => (init_cli_wecom_auth(), cli_wecom_auth_exports));
46539
46569
  const { createEmitter: createEmitter2 } = await Promise.resolve().then(() => (init_cli_events(), cli_events_exports));
46540
46570
  if (events) redirectConsoleToStderr();
46541
46571
  const code = await doReconfigWecom2({ stateDir, configName, events, emit: events ? createEmitter2() : void 0 });
46542
- process.exit(code);
46572
+ await exitCli(code);
46543
46573
  }
46544
46574
  console.error(`\u672A\u77E5\u76EE\u6807: ${channel || "(\u7A7A)"}\u3002\u652F\u6301: wechat / feishu / dingtalk / wecom / discord / llm / channels`);
46545
46575
  console.error("\u7528\u6CD5: engine7 reconfig <\u76EE\u6807> [--state-dir <path>] [--config <file>]");
@@ -46548,7 +46578,7 @@ async function main() {
46548
46578
  if (subcommand === "cc-run") {
46549
46579
  const { doCcRun: doCcRun2 } = await Promise.resolve().then(() => (init_cli_ccrun(), cli_ccrun_exports));
46550
46580
  const code = await doCcRun2(args.slice(1));
46551
- process.exit(code);
46581
+ await exitCli(code);
46552
46582
  }
46553
46583
  if (subcommand === "export") {
46554
46584
  const { doExport: doExport2 } = await Promise.resolve().then(() => (init_cli_travel(), cli_travel_exports));
@@ -47416,10 +47446,10 @@ function readHomePointer() {
47416
47446
  return null;
47417
47447
  }
47418
47448
  }
47419
- main().catch((err) => {
47449
+ main().catch(async (err) => {
47420
47450
  if (headlessEmit) headlessEmit({ event: "error", message: err.message });
47421
47451
  console.error(`
47422
47452
  \u274C \u5931\u8D25: ${err.message}`);
47423
47453
  console.error(err.stack);
47424
- process.exit(1);
47454
+ await exitCli(1);
47425
47455
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "engine7",
3
3
  "license": "Apache-2.0",
4
- "version": "7.1.122",
4
+ "version": "7.1.123",
5
5
  "type": "module",
6
6
  "description": "Engine 7 — 给助手一个家 / A home for your AI assistant",
7
7
  "main": "dist/main.mjs",