@itpay/cli 2.1.55 → 2.1.56

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/src/main.js CHANGED
@@ -7673,6 +7673,46 @@ var require_commander = __commonJS({
7673
7673
  }
7674
7674
  });
7675
7675
 
7676
+ // src/state/agent_type.ts
7677
+ function declaredAgentType(env = process.env, argv = process.argv) {
7678
+ if (env.ITPAY_AGENT_TYPE) return canonicalAgentType(env.ITPAY_AGENT_TYPE);
7679
+ for (let index = 0; index < argv.length; index += 1) {
7680
+ const value = argv[index];
7681
+ if (value === "--agent-type") return canonicalAgentType(argv[index + 1]);
7682
+ if (value?.startsWith("--agent-type=")) return canonicalAgentType(value.slice("--agent-type=".length));
7683
+ }
7684
+ return void 0;
7685
+ }
7686
+ __name(declaredAgentType, "declaredAgentType");
7687
+ function canonicalAgentType(value) {
7688
+ const normalized = value?.trim().toLowerCase();
7689
+ if (!normalized) return void 0;
7690
+ return normalized === "codex" ? "codex-desktop" : normalized;
7691
+ }
7692
+ __name(canonicalAgentType, "canonicalAgentType");
7693
+ function qualifyItPayCommand(command, agentType) {
7694
+ if (!agentType || !/^[a-z0-9-]+$/.test(agentType)) return command;
7695
+ if (!command.startsWith("itpay ") || /^itpay\s+--agent-type(?:=|\s)/.test(command)) return command;
7696
+ return `itpay --agent-type ${agentType} ${command.slice("itpay ".length)}`;
7697
+ }
7698
+ __name(qualifyItPayCommand, "qualifyItPayCommand");
7699
+ var AgentTypeRequiredError = class extends Error {
7700
+ static {
7701
+ __name(this, "AgentTypeRequiredError");
7702
+ }
7703
+ code = "agent_type_required";
7704
+ constructor() {
7705
+ super("Declare the actual Agent Type with --agent-type or ITPAY_AGENT_TYPE; no authorization request was sent");
7706
+ this.name = "AgentTypeRequiredError";
7707
+ }
7708
+ };
7709
+ function requireAgentType(value) {
7710
+ const type = canonicalAgentType(value);
7711
+ if (!type) throw new AgentTypeRequiredError();
7712
+ return type;
7713
+ }
7714
+ __name(requireAgentType, "requireAgentType");
7715
+
7676
7716
  // src/services/shared/purchase_contract.generated.ts
7677
7717
  var purchaseContract = {
7678
7718
  "version": "itpay.purchase-confirmation.v1",
@@ -7991,30 +8031,6 @@ function resolveOutput(sink) {
7991
8031
  }
7992
8032
  __name(resolveOutput, "resolveOutput");
7993
8033
 
7994
- // src/state/agent_type.ts
7995
- function declaredAgentType(env = process.env, argv = process.argv) {
7996
- if (env.ITPAY_AGENT_TYPE) return canonicalAgentType(env.ITPAY_AGENT_TYPE);
7997
- for (let index = 0; index < argv.length; index += 1) {
7998
- const value = argv[index];
7999
- if (value === "--agent-type") return canonicalAgentType(argv[index + 1]);
8000
- if (value?.startsWith("--agent-type=")) return canonicalAgentType(value.slice("--agent-type=".length));
8001
- }
8002
- return void 0;
8003
- }
8004
- __name(declaredAgentType, "declaredAgentType");
8005
- function canonicalAgentType(value) {
8006
- const normalized = value?.trim().toLowerCase();
8007
- if (!normalized) return void 0;
8008
- return normalized === "codex" ? "codex-desktop" : normalized;
8009
- }
8010
- __name(canonicalAgentType, "canonicalAgentType");
8011
- function qualifyItPayCommand(command, agentType) {
8012
- if (!agentType || !/^[a-z0-9-]+$/.test(agentType)) return command;
8013
- if (!command.startsWith("itpay ") || /^itpay\s+--agent-type(?:=|\s)/.test(command)) return command;
8014
- return `itpay --agent-type ${agentType} ${command.slice("itpay ".length)}`;
8015
- }
8016
- __name(qualifyItPayCommand, "qualifyItPayCommand");
8017
-
8018
8034
  // src/state/config.ts
8019
8035
  import { CLI_VERSION, API_CONTRACT_REVISION } from "./state/config.js";
8020
8036
  import { CLI_VERSION as CLI_VERSION2, API_CONTRACT_REVISION as API_CONTRACT_REVISION2 } from "./state/config.js";
@@ -8608,7 +8624,7 @@ var DeviceAuthority = class {
8608
8624
  return this.pending;
8609
8625
  }
8610
8626
  cache(privateKey, agentType = this.requestedAgentType) {
8611
- if (!agentType) throw new Error("agent type is required for ItPay commerce; pass --agent-type <type> or set ITPAY_AGENT_TYPE");
8627
+ agentType = requireAgentType(agentType);
8612
8628
  return new DeviceSessionCache(resolve(dirname2(this.statePath), "sessions"), {
8613
8629
  backend: this.backendKey,
8614
8630
  agentType,
@@ -8661,9 +8677,8 @@ var DeviceAuthority = class {
8661
8677
  }
8662
8678
  async prepareAuthorization(options) {
8663
8679
  checkAuthorizationBudget(options);
8680
+ const agentType = requireAgentType(this.requestedAgentType);
8664
8681
  const state = this.readState();
8665
- const agentType = this.requestedAgentType;
8666
- if (!agentType) throw new Error("agent type is required for ItPay commerce; pass --agent-type <type> or set ITPAY_AGENT_TYPE");
8667
8682
  let privateKey;
8668
8683
  checkAuthorizationBudget(options);
8669
8684
  try {
@@ -9262,7 +9277,7 @@ function writeCommandEnvelope(value, options = {}) {
9262
9277
  if (options.plainResult) {
9263
9278
  for (const line of options.plainResult) {
9264
9279
  const command = line.match(/^(\s*(?:command|reader|entry): )(itpay .*)$/);
9265
- out(`${command ? command[1] + qualifyBackendCommand(qualifyItPayCommand(command[2], agentType)) : line}
9280
+ out(`${command ? command[1] + qualifyCommand(command[2], agentType) : line}
9266
9281
  `);
9267
9282
  }
9268
9283
  } else {
@@ -9314,17 +9329,17 @@ function qualifyEnvelope(value, agentType) {
9314
9329
  ..."handoff" in value && value.handoff ? { handoff: qualifyCommandsDeep(value.handoff, agentType) } : {},
9315
9330
  ..."interaction" in value && value.interaction ? { interaction: qualifyCommandsDeep(value.interaction, agentType) } : {},
9316
9331
  ..."communication" in value && value.communication ? { communication: qualifyCommandsDeep(value.communication, agentType) } : {},
9317
- next: value.next ? { ...value.next, command: qualifyBackendCommand(qualifyItPayCommand(value.next.command, agentType)) } : null,
9332
+ next: value.next ? { ...value.next, command: qualifyCommand(value.next.command, agentType) } : null,
9318
9333
  recovery: value.recovery.map((action) => ({
9319
9334
  ...action,
9320
- command: qualifyBackendCommand(qualifyItPayCommand(action.command, agentType))
9335
+ command: qualifyCommand(action.command, agentType)
9321
9336
  }))
9322
9337
  };
9323
9338
  }
9324
9339
  __name(qualifyEnvelope, "qualifyEnvelope");
9325
9340
  function qualifyCommandsDeep(value, agentType) {
9326
9341
  if (typeof value === "string") {
9327
- return value.startsWith("itpay ") ? qualifyBackendCommand(qualifyItPayCommand(value, agentType)) : value;
9342
+ return value.startsWith("itpay ") ? qualifyCommand(value, agentType) : value;
9328
9343
  }
9329
9344
  if (Array.isArray(value)) return value.map((item) => qualifyCommandsDeep(item, agentType));
9330
9345
  if (value && typeof value === "object") {
@@ -9397,6 +9412,11 @@ function printErrorRecovery(error, output) {
9397
9412
  }
9398
9413
  }
9399
9414
  __name(printErrorRecovery, "printErrorRecovery");
9415
+ function qualifyCommand(command, agentType) {
9416
+ const qualified = qualifyBackendCommand(qualifyItPayCommand(command, agentType));
9417
+ return command.startsWith("itpay ") && process.env.ITPAY_STATE_DIR ? `ITPAY_STATE_DIR=${shellArgument(process.env.ITPAY_STATE_DIR)} ${qualified}` : qualified;
9418
+ }
9419
+ __name(qualifyCommand, "qualifyCommand");
9400
9420
 
9401
9421
  // src/services/shared/purchase.ts
9402
9422
  function purchaseEnvelope(state) {
@@ -17861,7 +17881,7 @@ var AuthRequestError = class extends Error {
17861
17881
  }
17862
17882
  };
17863
17883
  function authStatusUnknown(sessionID, error, failureStage = "authorization_status_read") {
17864
- if (error instanceof HttpError && error.status < 500 || error instanceof AuthRequestError && error.httpStatus < 500 || error instanceof DeviceAuthorizationError || error instanceof DeviceStateError)
17884
+ if (error instanceof HttpError && error.status < 500 || error instanceof AuthRequestError && error.httpStatus < 500 || error instanceof DeviceAuthorizationError || error instanceof DeviceStateError || error instanceof AgentTypeRequiredError)
17865
17885
  throw error;
17866
17886
  const hostFailure = error && typeof error === "object" && "code" in error && (error.code === "CODEBUDDY_BROKER_DENY" || error.code === "CODEBUDDY_BROKER_OUTCOME_UNKNOWN");
17867
17887
  const failure = error instanceof HttpTransportError ? { category: error.code, attempts: error.attempts, source: "network_transport" } : error instanceof HttpError || error instanceof AuthRequestError ? { category: "http_server_error", http_status: error instanceof HttpError ? error.status : error.httpStatus, source: "http_response" } : hostFailure ? { category: "host_operation_unavailable", source: "host_broker" } : { category: "authorization_status_unavailable", source: "unclassified" };
@@ -17919,7 +17939,7 @@ async function accountAuth(action, baseURL, env, fetcher, backend, readOnlyStatu
17919
17939
  if (current.status === "authenticated")
17920
17940
  return authenticatedEnvelope(env, current.phone_verified === true);
17921
17941
  } catch (error) {
17922
- if (error instanceof AuthRequestError)
17942
+ if (error instanceof AuthRequestError || error instanceof AgentTypeRequiredError)
17923
17943
  throw error;
17924
17944
  return authStatusUnknown(readOnlyStatus ? void 0 : readAuthState(baseURL, env, purpose)?.sessionID, error, "account_binding_probe");
17925
17945
  }
@@ -19409,7 +19429,7 @@ __name(installDefinition, "installDefinition");
19409
19429
  import { createHash as createHash9 } from "node:crypto";
19410
19430
 
19411
19431
  // src/state/skill_identity.generated.ts
19412
- var CANONICAL_SKILL_SHA256 = "9e36b56ef726cd1c7db603474fb977fa3cc5b84ef6b005d007e9f322ac534ce7";
19432
+ var CANONICAL_SKILL_SHA256 = "f4aaace4d39abd9c8f91307305f9ac0e2c8630802a545a3a555a89b45b670524";
19413
19433
 
19414
19434
  // src/commands/skill.ts
19415
19435
  import { existsSync as existsSync7, readFileSync as readFileSync11 } from "node:fs";
@@ -19574,12 +19594,18 @@ async function runSetup(backend, config, skillPath, options = {}) {
19574
19594
  device_status: "ready",
19575
19595
  account_status: account.status,
19576
19596
  skill_path: skillPath,
19577
- skill_version: CLI_VERSION2
19597
+ skill_version: CLI_VERSION2,
19598
+ ...account.status === "login_required" ? { account_action: {
19599
+ optional: true,
19600
+ condition: "\u4EC5\u5F53\u7528\u6237\u8981\u6C42\u767B\u5F55\u6216\u5F53\u524D\u529F\u80FD\u9700\u8981\u8D26\u53F7\u65F6\u4F7F\u7528\uFF1B\u514D\u8D39\u67E5\u8BE2\u4E0D\u5F3A\u5236\u7ED1\u5B9A\u3002",
19601
+ command: "itpay auth login --json",
19602
+ reason: "\u7531\u672C\u4EBA\u5B8C\u6210\u5B98\u65B9\u8D26\u53F7\u6388\u6743\uFF0C\u4E0D\u81EA\u52A8\u767B\u5F55"
19603
+ } } : {}
19578
19604
  },
19579
19605
  instruction: account.status === "authenticated" ? "\u8BBE\u5907\u5DF2\u51C6\u5907\u597D\uFF0C\u5DF2\u6709\u8D26\u53F7\u6388\u6743\u53EF\u7EE7\u7EED\u4F7F\u7528\u3002\u8BFB\u53D6\u5E76\u542F\u7528\u4E0B\u65B9 Skill \u540E\uFF0C\u6309\u7528\u6237\u9700\u6C42\u5F00\u59CB\u3002" : "\u8BBE\u5907\u5DF2\u51C6\u5907\u597D\u3002\u8BFB\u53D6\u5E76\u542F\u7528\u4E0B\u65B9 Skill \u540E\u5373\u53EF\u5F00\u59CB\uFF1B\u9700\u8981\u8D26\u53F7\u7684\u529F\u80FD\u4F1A\u518D\u8BF7\u7528\u6237\u6388\u6743\u3002",
19580
19606
  next: null,
19581
19607
  recovery: []
19582
- }, options);
19608
+ }, { ...options, ...config.agentType ? { agentType: config.agentType } : {} });
19583
19609
  }
19584
19610
  __name(runSetup, "runSetup");
19585
19611
 
@@ -21878,7 +21904,18 @@ function resolveCheckoutPresentationArgs(input) {
21878
21904
  }
21879
21905
  __name(resolveCheckoutPresentationArgs, "resolveCheckoutPresentationArgs");
21880
21906
  function reportCLIError(error, contract) {
21881
- const commandError = error instanceof CommandContractError ? error : void 0;
21907
+ const commandError = error instanceof CommandContractError ? error : error instanceof AgentTypeRequiredError ? new CommandContractError(
21908
+ error.code,
21909
+ error.message,
21910
+ "\u672C\u6B21\u6CA1\u6709\u53D1\u9001\u6388\u6743\u8BF7\u6C42\u3002Agent\u6CBF\u7528\u5B9E\u9645\u5BBF\u4E3B\u7C7B\u578B\u8865\u9F50 --agent-type \u6216 ITPAY_AGENT_TYPE\uFF0C\u4FDD\u7559\u539FBackend\u548C\u79C1\u6709\u72B6\u6001\u76EE\u5F55\uFF1B\u4E0D\u8981\u8BA9\u7528\u6237\u731C\u6280\u672F\u53C2\u6570\u3001\u6362\u8EAB\u4EFD\u6216\u65B0\u5EFA\u6388\u6743\u3002",
21911
+ [],
21912
+ void 0,
21913
+ {
21914
+ failure_stage: "local_agent_declaration",
21915
+ request_sent: false,
21916
+ input_template: { executable: false, required_field: "agent_type", source: "actual_host", preserve: ["Backend", "ITPAY_STATE_DIR", "device_identity"] }
21917
+ }
21918
+ ) : void 0;
21882
21919
  const backendOverrideError = error instanceof BackendOverrideError ? error : void 0;
21883
21920
  const deviceError = error instanceof DeviceAuthorizationError ? error : void 0;
21884
21921
  const stateError = error instanceof DeviceStateError ? error : void 0;
@@ -1,4 +1,4 @@
1
- const CLI_VERSION = "2.1.55";
1
+ const CLI_VERSION = "2.1.56";
2
2
  const API_CONTRACT_REVISION = "sha256:f20af3780a0e12a79a6ca9507ba65167a4018338495af66d87931e55619b618a";
3
3
  export {
4
4
  API_CONTRACT_REVISION,
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "current_flow": [
27
27
  "One verified supported identity can log in: phone is recommended, wallets follow, email is a separate choice. Bind another only on request or current service need.",
28
- "Display the current official authorization entry; after completion use its same-task recovery command.",
28
+ "Display the current official authorization entry; after completion use its same-task recovery command. Retain the actual Agent Type, Backend, launcher/PATH and any custom private ITPAY_STATE_DIR for auth login/status, waiting, expired-request recovery and original-task recovery. A setup-only flag does not persist the type; exported values may be inherited. Do not start login automatically for free queries.",
29
29
  "Account merging requires proof of both accounts and explicit confirmation on the official page. Login permission is separate from purchase consent.",
30
30
  "Keep the device identity and actual Agent Type. Current errors supply an action or explicit stop; do not delete keys, change identity or repeat installation."
31
31
  ]
@@ -33,10 +33,11 @@
33
33
  ],
34
34
  "current_flow": [
35
35
  "Use the authorized channel/Backend and host-permitted tool prefix/cache/state directories. Use real dot or muse in those hosts, never codex spoofing. Retain one launcher and its Backend, Agent Type and ITPAY_STATE_DIR for every next/recovery command. Do not change HOME.",
36
- "Run itpay setup --agent-type <actual_type> --json once after installation/upgrade. setup_ready means device preparation; login_required can be a valid separate account status.",
36
+ "Declare the actual host type via ITPAY_AGENT_TYPE or the global --agent-type option, then run itpay setup --json once after installation/upgrade. Preserve that real declaration, launcher/PATH, Backend and any custom private ITPAY_STATE_DIR for all later commands. Exported values can be inherited by child processes; a new shell may need them again. A one-time setup flag is not persistent configuration. setup_ready means device preparation; login_required is a separate valid account status.",
37
37
  "Read itpay skill show itpay --json and enable that exact package Skill via the host mechanism. Record the actual path and limitation if the host cannot enable it.",
38
38
  "Do not repeat setup, installation or login for ordinary tasks. A nonzero install is not ready; keep the actual error and follow its current recovery.",
39
39
  "ITPAY_STATE_DIR selects the private state directory; choose an allowed directory before first enrollment and preserve it. If an existing identity lacks its key or becomes inaccessible, recover access; never rotate identity to regain quota.",
40
- "Check install prefix, npm cache, state and receipt writes independently. A writable directory is not proof of persistence across sessions. setup reports Skill readability separately from writing, host discovery and version; do not reinstall during normal tasks."
40
+ "Check install prefix, npm cache, state and receipt writes independently. A writable directory is not proof of persistence across sessions. setup reports Skill readability separately from writing, host discovery and version; do not reinstall during normal tasks.",
41
+ "When login_required, the returned account_action is optional: use it only for a user-requested login or an account-required feature; do not auto-login or bind for free queries. Missing host declaration is technical input the Agent restores from actual context, not an unknown server authorization or a reason to ask the human to guess a type."
41
42
  ]
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itpay/cli",
3
- "version": "2.1.55",
3
+ "version": "2.1.56",
4
4
  "description": "The ItPay CLI for services, orders, and human-authorized purchased content.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -140,6 +140,5 @@
140
140
  "type": "git",
141
141
  "url": "git+https://github.com/itpay-ai/cli.git"
142
142
  },
143
- "itpayBundleFormat": "buyer-esm-v1",
144
- "gitHead": "d2b0eaaafcd7918edb84f9d004cfa09652b914fa"
143
+ "itpayBundleFormat": "buyer-esm-v1"
145
144
  }
@@ -11,7 +11,7 @@ If this Skill is supplied with `references/itpay-cli-invocation.md`, read it onc
11
11
 
12
12
  ## Runtime and state
13
13
 
14
- Use real `dot` or `muse` in those hosts; never impersonate codex-desktop. Keep the same permitted launcher, Backend, Agent Type and private `ITPAY_STATE_DIR` through every continuation. npm prefix/cache, receipt and state must all use host-permitted paths; do not change HOME, clear identity or rotate keys to recover quota. Current write access does not prove cross-session persistence. Skill readability, writing, host discovery and version are separate facts; normal tasks need no reinstall. Cloud execution and user-visible presentation are separate; unknown visibility remains unknown.
14
+ Use real `dot` or `muse` in those hosts; never impersonate codex-desktop. Keep the same permitted launcher/PATH, Backend, actual `ITPAY_AGENT_TYPE` (or explicit global `--agent-type`) and private `ITPAY_STATE_DIR` through every command and returned continuation, including auth login/status. Exported values can be inherited; a separate shell may need the same declarations again. A setup-only flag does not persist them. Missing declarations are technical input for the Agent to restore from its real host context, never a reason to guess another host or reset identity. npm prefix/cache, receipt and state must all use host-permitted paths; do not change HOME, clear identity or rotate keys to recover quota. Current write access does not prove cross-session persistence. Skill readability, writing, host discovery and version are separate facts; normal tasks need no reinstall. Cloud execution and user-visible presentation are separate; unknown visibility remains unknown.
15
15
 
16
16
  ## One current flow
17
17