@ganglion/xacpx 0.17.0-beta.3 → 0.17.0-beta.5

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 (26) hide show
  1. package/dist/bridge/bridge-main.js +148 -96
  2. package/dist/cli.js +5833 -4891
  3. package/dist/config/types.d.ts +11 -0
  4. package/dist/control/control-service.d.ts +6 -17
  5. package/dist/control/session-turn-runner.d.ts +35 -0
  6. package/dist/control/terminal-service.d.ts +23 -0
  7. package/dist/control/turn-queue.d.ts +57 -0
  8. package/dist/control/turn-support.d.ts +28 -0
  9. package/dist/orchestration/orchestration-service.d.ts +14 -101
  10. package/dist/orchestration/orchestration-types.d.ts +2 -0
  11. package/dist/orchestration/service/coordinator-registry-service.d.ts +25 -0
  12. package/dist/orchestration/service/group-service.d.ts +25 -0
  13. package/dist/orchestration/service/human-delegation-service.d.ts +16 -0
  14. package/dist/orchestration/service/human-question-service.d.ts +57 -0
  15. package/dist/orchestration/service/notice-delivery-service.d.ts +25 -0
  16. package/dist/orchestration/service/orchestration-state-kernel.d.ts +58 -0
  17. package/dist/orchestration/service/question-flow-core.d.ts +52 -0
  18. package/dist/orchestration/service/rpc-delegation-service.d.ts +18 -0
  19. package/dist/orchestration/service/task-approval-service.d.ts +17 -0
  20. package/dist/orchestration/service/task-cancellation-service.d.ts +26 -0
  21. package/dist/orchestration/service/task-lifecycle-service.d.ts +21 -0
  22. package/dist/orchestration/service/worker-session-manager.d.ts +65 -0
  23. package/dist/orchestration/task-watch-timeouts.d.ts +2 -0
  24. package/dist/weixin/util/weixin-log.d.ts +14 -0
  25. package/package.json +1 -1
  26. package/dist/weixin/util/logger.d.ts +0 -14
@@ -3426,18 +3426,6 @@ var init_acpx_queue_owner_launcher = __esm(() => {
3426
3426
  init_i18n();
3427
3427
  });
3428
3428
 
3429
- // src/transport/permission-mode-flag.ts
3430
- function permissionModeToFlag(permissionMode) {
3431
- switch (permissionMode) {
3432
- case "approve-reads":
3433
- return "--approve-reads";
3434
- case "deny-all":
3435
- return "--deny-all";
3436
- case "approve-all":
3437
- return "--approve-all";
3438
- }
3439
- }
3440
-
3441
3429
  // src/util/path.ts
3442
3430
  import path2 from "node:path";
3443
3431
  import { homedir as homedir3 } from "node:os";
@@ -3698,6 +3686,97 @@ async function deleteAcpxSessionFiles(options) {
3698
3686
  }
3699
3687
  var init_acpx_session_files = () => {};
3700
3688
 
3689
+ // src/transport/command-timeouts.ts
3690
+ var DEFAULT_MANAGEMENT_COMMAND_TIMEOUT_MS = 30000, DEFAULT_SESSION_INIT_TIMEOUT_MS = 120000, BRIDGE_REQUEST_TIMEOUT_GRACE_MS = 15000;
3691
+
3692
+ // src/transport/permission-mode-flag.ts
3693
+ function permissionModeToFlag(permissionMode) {
3694
+ switch (permissionMode) {
3695
+ case "approve-reads":
3696
+ return "--approve-reads";
3697
+ case "deny-all":
3698
+ return "--deny-all";
3699
+ case "approve-all":
3700
+ return "--approve-all";
3701
+ }
3702
+ }
3703
+
3704
+ // src/transport/acpx-command-builder.ts
3705
+ function buildPermissionArgs(input) {
3706
+ const args = [permissionModeToFlag(input.permissionMode), "--non-interactive-permissions", input.nonInteractivePermissions];
3707
+ if (typeof input.permissionPolicy === "string" && input.permissionPolicy.trim().length > 0) {
3708
+ args.push("--permission-policy", input.permissionPolicy);
3709
+ }
3710
+ return args;
3711
+ }
3712
+ function buildQueueOwnerTtlArgs(queueOwnerTtlSeconds) {
3713
+ if (typeof queueOwnerTtlSeconds !== "number" || !Number.isFinite(queueOwnerTtlSeconds))
3714
+ return [];
3715
+ return ["--ttl", String(queueOwnerTtlSeconds)];
3716
+ }
3717
+ function buildModelArgs(model) {
3718
+ const trimmed = model?.trim();
3719
+ return trimmed ? ["--model", trimmed] : [];
3720
+ }
3721
+ function appendAgentAndTail(prefix, input, tail) {
3722
+ if (input.agentCommand)
3723
+ return [...prefix, "--agent", input.agentCommand, ...tail];
3724
+ return [...prefix, input.agent, ...tail];
3725
+ }
3726
+ function buildSessionArgs(input, tail, options = {}) {
3727
+ const prefix = [
3728
+ "--format",
3729
+ options.format ?? "quiet",
3730
+ "--cwd",
3731
+ input.cwd,
3732
+ ...buildPermissionArgs(input.permission),
3733
+ ...buildModelArgs(input.model)
3734
+ ];
3735
+ if (options.verbose)
3736
+ prefix.push("--verbose");
3737
+ return appendAgentAndTail(prefix, input, tail);
3738
+ }
3739
+ function buildPromptArgs(input, tail) {
3740
+ const prefix = [
3741
+ "--format",
3742
+ "json",
3743
+ "--json-strict",
3744
+ "--cwd",
3745
+ input.cwd,
3746
+ ...buildPermissionArgs(input.permission),
3747
+ ...buildModelArgs(input.model),
3748
+ ...buildQueueOwnerTtlArgs(input.queueOwnerTtlSeconds)
3749
+ ];
3750
+ return appendAgentAndTail(prefix, input, tail);
3751
+ }
3752
+ function buildAgentQueryArgs(input, format, tail) {
3753
+ const prefix = ["--format", format, "--cwd", input.cwd, ...buildPermissionArgs(input.permission)];
3754
+ return appendAgentAndTail(prefix, input, tail);
3755
+ }
3756
+ function isMissingAcpxSessionError(stderr, stdout) {
3757
+ const combined = `${stderr}
3758
+ ${stdout}`.toLowerCase();
3759
+ return combined.includes("no named session") || combined.includes("no cwd session") || combined.includes("session not found") || combined.includes("unknown session") || combined.includes("no acpx session found");
3760
+ }
3761
+ function parseAcpxSessionRecordId(stdout) {
3762
+ try {
3763
+ const parsed = JSON.parse(stdout);
3764
+ const acpxRecordId = typeof parsed.acpxRecordId === "string" ? parsed.acpxRecordId : typeof parsed.id === "string" ? parsed.id : undefined;
3765
+ const agentSessionId = typeof parsed.agentSessionId === "string" ? parsed.agentSessionId : undefined;
3766
+ if (acpxRecordId && /^[\w.:-]+$/.test(acpxRecordId) && acpxRecordId.length >= 8) {
3767
+ return { acpxRecordId, agentSessionId };
3768
+ }
3769
+ } catch {
3770
+ const firstLine = stdout.trim().split(/\r?\n/, 1)[0];
3771
+ if (firstLine && /^[\w.:-]+$/.test(firstLine) && firstLine.length >= 8) {
3772
+ return { acpxRecordId: firstLine };
3773
+ }
3774
+ }
3775
+ return;
3776
+ }
3777
+ var DEFAULT_PERMISSION_MODE = "approve-all", DEFAULT_NON_INTERACTIVE = "deny";
3778
+ var init_acpx_command_builder = () => {};
3779
+
3701
3780
  // src/bridge/bridge-main.ts
3702
3781
  import { createInterface } from "node:readline";
3703
3782
 
@@ -3794,6 +3873,7 @@ init_acpx_queue_owner_launcher();
3794
3873
  init_agent_session_list();
3795
3874
  init_codex_subagent_filter();
3796
3875
  init_acpx_session_files();
3876
+ init_acpx_command_builder();
3797
3877
  class EnsureSessionFailedError extends Error {
3798
3878
  kind;
3799
3879
  data;
@@ -3804,7 +3884,6 @@ class EnsureSessionFailedError extends Error {
3804
3884
  this.data = data;
3805
3885
  }
3806
3886
  }
3807
- var DEFAULT_SESSION_INIT_TIMEOUT_MS = 120000;
3808
3887
 
3809
3888
  class CommandTimeoutError extends Error {
3810
3889
  timeoutMs;
@@ -3814,10 +3893,6 @@ class CommandTimeoutError extends Error {
3814
3893
  this.name = "CommandTimeoutError";
3815
3894
  }
3816
3895
  }
3817
- function modelArgs(model) {
3818
- const trimmed = model?.trim();
3819
- return trimmed ? ["--model", trimmed] : [];
3820
- }
3821
3896
 
3822
3897
  class BridgeRuntime {
3823
3898
  command;
@@ -3856,7 +3931,7 @@ class BridgeRuntime {
3856
3931
  ...includeFilterCwd && input.filterCwd ? ["--filter-cwd", input.filterCwd] : [],
3857
3932
  ...input.cursor ? ["--cursor", input.cursor] : []
3858
3933
  ], { format: "json" }));
3859
- return await this.run(spec.command, spec.args);
3934
+ return await this.run(spec.command, spec.args, { timeoutMs: this.sessionInitTimeoutMs() });
3860
3935
  },
3861
3936
  formatError: (result) => result.stderr || result.stdout || `sessions list failed with exit code ${result.code}`,
3862
3937
  isSubagentSession: (input.driver ?? input.agent) === CODEX_AGENT_NAME ? codexSubagentPredicate() : undefined
@@ -3890,13 +3965,19 @@ class BridgeRuntime {
3890
3965
  const value = this.options.sessionInitTimeoutMs;
3891
3966
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : DEFAULT_SESSION_INIT_TIMEOUT_MS;
3892
3967
  }
3968
+ managementCommandTimeoutMs() {
3969
+ const value = this.options.managementCommandTimeoutMs;
3970
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : DEFAULT_MANAGEMENT_COMMAND_TIMEOUT_MS;
3971
+ }
3893
3972
  async hasSession(input) {
3894
3973
  const spawnSpec = resolveSpawnCommand(this.command, this.buildSessionArgs(input, [
3895
3974
  "sessions",
3896
3975
  "show",
3897
3976
  input.name
3898
3977
  ]));
3899
- const result = await this.run(spawnSpec.command, spawnSpec.args);
3978
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
3979
+ timeoutMs: this.managementCommandTimeoutMs()
3980
+ });
3900
3981
  return { exists: result.code === 0 };
3901
3982
  }
3902
3983
  async tailSessionHistory(input) {
@@ -3907,10 +3988,13 @@ class BridgeRuntime {
3907
3988
  ["sessions", "history", input.name, "--tail", String(input.lines)],
3908
3989
  ["sessions", "history", "--name", input.name, "--tail", String(input.lines)]
3909
3990
  ];
3991
+ const deadline = Date.now() + this.managementCommandTimeoutMs();
3910
3992
  let lastResult;
3911
3993
  for (const tailArgs of candidates) {
3912
3994
  const spawnSpec = resolveSpawnCommand(this.command, this.buildSessionArgs(input, tailArgs));
3913
- const result = await this.run(spawnSpec.command, spawnSpec.args);
3995
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
3996
+ timeoutMs: Math.max(deadline - Date.now(), 1)
3997
+ });
3914
3998
  if (result.code === 0) {
3915
3999
  return { text: result.stdout.trimEnd() };
3916
4000
  }
@@ -4077,28 +4161,15 @@ class BridgeRuntime {
4077
4161
  "show",
4078
4162
  input.name
4079
4163
  ]));
4080
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4164
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4165
+ timeoutMs: this.managementCommandTimeoutMs()
4166
+ });
4081
4167
  if (result.code !== 0) {
4082
4168
  throw new Error(result.stderr || result.stdout || "sessions show failed");
4083
4169
  }
4084
- try {
4085
- const parsed = JSON.parse(result.stdout);
4086
- let acpxRecordId;
4087
- if (typeof parsed.acpxRecordId === "string") {
4088
- acpxRecordId = parsed.acpxRecordId;
4089
- } else if (typeof parsed.id === "string") {
4090
- acpxRecordId = parsed.id;
4091
- }
4092
- const agentSessionId = typeof parsed.agentSessionId === "string" ? parsed.agentSessionId : undefined;
4093
- if (acpxRecordId && /^[\w.:-]+$/.test(acpxRecordId) && acpxRecordId.length >= 8) {
4094
- return { acpxRecordId, agentSessionId };
4095
- }
4096
- } catch {
4097
- const firstLine = result.stdout.trim().split(/\r?\n/, 1)[0];
4098
- if (firstLine && /^[\w.:-]+$/.test(firstLine) && firstLine.length >= 8) {
4099
- return { acpxRecordId: firstLine };
4100
- }
4101
- }
4170
+ const record = parseAcpxSessionRecordId(result.stdout);
4171
+ if (record)
4172
+ return record;
4102
4173
  throw new Error("failed to resolve acpx session record id");
4103
4174
  }
4104
4175
  async getAgentSessionId(input) {
@@ -4112,7 +4183,9 @@ class BridgeRuntime {
4112
4183
  input.name,
4113
4184
  input.modeId
4114
4185
  ]));
4115
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4186
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4187
+ timeoutMs: this.managementCommandTimeoutMs()
4188
+ });
4116
4189
  if (result.code !== 0) {
4117
4190
  throw new Error(result.stderr || result.stdout || "set-mode failed");
4118
4191
  }
@@ -4126,7 +4199,9 @@ class BridgeRuntime {
4126
4199
  "model",
4127
4200
  input.modelId
4128
4201
  ]));
4129
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4202
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4203
+ timeoutMs: this.managementCommandTimeoutMs()
4204
+ });
4130
4205
  if (result.code !== 0) {
4131
4206
  throw new Error(result.stderr || result.stdout || "set-model failed");
4132
4207
  }
@@ -4138,7 +4213,9 @@ class BridgeRuntime {
4138
4213
  "-s",
4139
4214
  input.name
4140
4215
  ], { format: "json" }));
4141
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4216
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4217
+ timeoutMs: this.managementCommandTimeoutMs()
4218
+ });
4142
4219
  if (result.code !== 0) {
4143
4220
  throw new Error(result.stderr || result.stdout || "status failed");
4144
4221
  }
@@ -4158,7 +4235,9 @@ class BridgeRuntime {
4158
4235
  "-s",
4159
4236
  input.name
4160
4237
  ]));
4161
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4238
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4239
+ timeoutMs: this.managementCommandTimeoutMs()
4240
+ });
4162
4241
  if (result.code !== 0) {
4163
4242
  throw new Error(result.stderr || result.stdout || "cancel failed");
4164
4243
  }
@@ -4173,11 +4252,13 @@ class BridgeRuntime {
4173
4252
  "close",
4174
4253
  input.name
4175
4254
  ]));
4176
- const result = await this.run(spawnSpec.command, spawnSpec.args);
4255
+ const result = await this.run(spawnSpec.command, spawnSpec.args, {
4256
+ timeoutMs: this.managementCommandTimeoutMs()
4257
+ });
4177
4258
  if (result.code === 0) {
4178
4259
  return {};
4179
4260
  }
4180
- if (isMissingBridgeSessionError(result.stderr, result.stdout)) {
4261
+ if (isMissingAcpxSessionError(result.stderr, result.stdout)) {
4181
4262
  return {};
4182
4263
  }
4183
4264
  throw new Error(result.stderr || result.stdout || "sessions close failed");
@@ -4207,54 +4288,30 @@ class BridgeRuntime {
4207
4288
  return {};
4208
4289
  }
4209
4290
  buildSessionArgs(input, tail, options = {}) {
4210
- const prefix = [
4211
- "--format",
4212
- options.format ?? "quiet",
4213
- "--cwd",
4214
- input.cwd,
4215
- ...this.buildPermissionArgs(),
4216
- ...modelArgs(input.model)
4217
- ];
4218
- if (options.verbose) {
4219
- prefix.push("--verbose");
4220
- }
4221
- if (input.agentCommand) {
4222
- return [...prefix, "--agent", input.agentCommand, ...tail];
4223
- }
4224
- return [...prefix, input.agent, ...tail];
4291
+ return buildSessionArgs({
4292
+ agent: input.agent,
4293
+ agentCommand: input.agentCommand,
4294
+ cwd: input.cwd,
4295
+ model: input.model,
4296
+ permission: this.permissionInput()
4297
+ }, tail, options);
4225
4298
  }
4226
4299
  buildPromptArgs(input, tail) {
4227
- const prefix = [
4228
- "--format",
4229
- "json",
4230
- "--json-strict",
4231
- "--cwd",
4232
- input.cwd,
4233
- ...this.buildPermissionArgs(),
4234
- ...modelArgs(input.model),
4235
- ...this.buildQueueOwnerTtlArgs()
4236
- ];
4237
- if (input.agentCommand) {
4238
- return [...prefix, "--agent", input.agentCommand, ...tail];
4239
- }
4240
- return [...prefix, input.agent, ...tail];
4241
- }
4242
- buildQueueOwnerTtlArgs() {
4243
- const ttl = this.options.queueOwnerTtlSeconds;
4244
- if (typeof ttl !== "number" || !Number.isFinite(ttl)) {
4245
- return [];
4246
- }
4247
- return ["--ttl", String(ttl)];
4248
- }
4249
- buildPermissionArgs() {
4250
- const permissionMode = this.options.permissionMode ?? "approve-all";
4251
- const nonInteractivePermissions = this.options.nonInteractivePermissions ?? "deny";
4252
- const modeFlag = permissionModeToFlag(permissionMode);
4253
- const args = [modeFlag, "--non-interactive-permissions", nonInteractivePermissions];
4254
- if (typeof this.options.permissionPolicy === "string" && this.options.permissionPolicy.trim().length > 0) {
4255
- args.push("--permission-policy", this.options.permissionPolicy);
4256
- }
4257
- return args;
4300
+ return buildPromptArgs({
4301
+ agent: input.agent,
4302
+ agentCommand: input.agentCommand,
4303
+ cwd: input.cwd,
4304
+ model: input.model,
4305
+ permission: this.permissionInput(),
4306
+ queueOwnerTtlSeconds: this.options.queueOwnerTtlSeconds
4307
+ }, tail);
4308
+ }
4309
+ permissionInput() {
4310
+ return {
4311
+ permissionMode: this.options.permissionMode ?? DEFAULT_PERMISSION_MODE,
4312
+ nonInteractivePermissions: this.options.nonInteractivePermissions ?? DEFAULT_NON_INTERACTIVE,
4313
+ permissionPolicy: this.options.permissionPolicy
4314
+ };
4258
4315
  }
4259
4316
  }
4260
4317
  function spawnCapture(command, args, options) {
@@ -4425,11 +4482,6 @@ function isUnknownVerboseOption(stderr, stdout) {
4425
4482
  ${stdout}`;
4426
4483
  return /(unknown|unrecognized)\b[^\n]*--verbose/i.test(combined);
4427
4484
  }
4428
- function isMissingBridgeSessionError(stderr, stdout) {
4429
- const combined = `${stderr}
4430
- ${stdout}`.toLowerCase();
4431
- return combined.includes("no named session") || combined.includes("no cwd session") || combined.includes("session not found") || combined.includes("unknown session") || combined.includes("no acpx session found");
4432
- }
4433
4485
 
4434
4486
  // src/bridge/bridge-server.ts
4435
4487
  class BridgeInvalidRequestError extends Error {