cyber-agentkit 0.7.1 → 1.0.0

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyber-agentkit",
3
- "version": "0.7.1",
3
+ "version": "1.0.0",
4
4
  "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
5
5
  "author": {
6
6
  "name": "unional"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyber-agentkit",
3
- "version": "0.7.1",
3
+ "version": "1.0.0",
4
4
  "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
5
5
  "author": {
6
6
  "name": "unional"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyber-agentkit",
3
- "version": "0.7.1",
3
+ "version": "1.0.0",
4
4
  "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
5
5
  "author": {
6
6
  "name": "unional"
package/dist/index.d.ts CHANGED
@@ -38,7 +38,7 @@ interface PluginDependenciesRead {
38
38
  readonly error?: string;
39
39
  }
40
40
  /**
41
- * Read what the plugin at `pluginRoot` declares: `dependencies` under `extensions["org.spikyuni.plugin-manager"]`,
41
+ * Read what the plugin at `pluginRoot` declares: `dependencies` under `extensions["io.github.cyber-uni.plugin-manager"]`,
42
42
  * else under `extensions["org.cyberuni.universal-plugin"]` in the root `plugin.json`, else `dependencies` in
43
43
  * `.claude-plugin/plugin.json` (E-DEP-1, E-DEP-6, E-DEP-7).
44
44
  */
package/dist/index.js CHANGED
@@ -39,9 +39,9 @@ function declaredPluginDependencies(manifest) {
39
39
  }
40
40
  const nonEmpty = (value) => typeof value === "string" && value !== "" ? value : void 0;
41
41
  /** The extension namespaces a root `plugin.json` may author its dependency list under, newest first (E-DEP-6, E-DEP-7). */
42
- const extensionNamespaces = ["org.spikyuni.plugin-manager", "org.cyberuni.universal-plugin"];
42
+ const extensionNamespaces = ["io.github.cyber-uni.plugin-manager", "org.cyberuni.universal-plugin"];
43
43
  /**
44
- * Read what the plugin at `pluginRoot` declares: `dependencies` under `extensions["org.spikyuni.plugin-manager"]`,
44
+ * Read what the plugin at `pluginRoot` declares: `dependencies` under `extensions["io.github.cyber-uni.plugin-manager"]`,
45
45
  * else under `extensions["org.cyberuni.universal-plugin"]` in the root `plugin.json`, else `dependencies` in
46
46
  * `.claude-plugin/plugin.json` (E-DEP-1, E-DEP-6, E-DEP-7).
47
47
  */
package/package.json CHANGED
@@ -1,93 +1,92 @@
1
1
  {
2
- "name": "cyber-agentkit",
3
- "version": "0.7.1",
4
- "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
5
- "keywords": [
6
- "agent-harness",
7
- "claude-code",
8
- "cursor",
9
- "codex",
10
- "copilot-cli",
11
- "opencode",
12
- "kilo-code",
13
- "gemini-cli",
14
- "qwen-code",
15
- "vscode",
16
- "cline",
17
- "crush",
18
- "openhands",
19
- "auggie"
20
- ],
21
- "homepage": "https://cyber-uni.github.io/cyber-agentkit/",
22
- "bugs": {
23
- "url": "https://github.com/cyber-uni/cyber-agentkit/issues"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/cyber-uni/cyber-agentkit.git",
28
- "directory": "packages/cyber-agentkit"
29
- },
30
- "license": "MIT",
31
- "author": "unional <homawong@gmail.com>",
32
- "type": "module",
33
- "sideEffects": [
34
- "./bin/*.mjs",
35
- "./dist/cli.js",
36
- "./skills/*/scripts/*.mjs"
37
- ],
38
- "exports": {
39
- ".": "./dist/index.js",
40
- "./commands": "./dist/commands.js",
41
- "./worktrees": "./dist/worktrees.js",
42
- "./package.json": "./package.json"
43
- },
44
- "bin": {
45
- "cyber-agentkit": "./bin/cyber-agentkit.mjs"
46
- },
47
- "files": [
48
- "LICENSE",
49
- "bin",
50
- "dist",
51
- "skills",
52
- "references",
53
- "plugin.json",
54
- ".claude-plugin",
55
- ".cursor-plugin",
56
- ".codex-plugin"
57
- ],
58
- "scripts": {
59
- "build": "tsdown",
60
- "generate:references": "tsx scripts/generate-references.ts",
61
- "dev": "tsx src/index.ts",
62
- "lint": "biome check .",
63
- "prepack": "pnpm build",
64
- "test": "pnpm build && vitest run src",
65
- "test:watch": "vitest",
66
- "typecheck": "tsc --noEmit",
67
- "verify": "pnpm typecheck && pnpm lint && pnpm test"
68
- },
69
- "peerDependencies": {
70
- "clibuilder": "^12.0.0"
71
- },
72
- "peerDependenciesMeta": {
73
- "clibuilder": {
74
- "optional": true
75
- }
76
- },
77
- "devDependencies": {
78
- "@types/node": "^24.10.1",
79
- "clibuilder": "^12.0.0",
80
- "tsdown": "^0.23.0",
81
- "tsx": "^4.22.3",
82
- "typescript": "^7.0.0",
83
- "vitest": "^5.0.0",
84
- "yaml": "^2.9.0"
85
- },
86
- "engines": {
87
- "node": ">=22"
88
- },
89
- "publishConfig": {
90
- "access": "public",
91
- "provenance": true
92
- }
93
- }
2
+ "name": "cyber-agentkit",
3
+ "version": "1.0.0",
4
+ "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
5
+ "keywords": [
6
+ "agent-harness",
7
+ "claude-code",
8
+ "cursor",
9
+ "codex",
10
+ "copilot-cli",
11
+ "opencode",
12
+ "kilo-code",
13
+ "gemini-cli",
14
+ "qwen-code",
15
+ "vscode",
16
+ "cline",
17
+ "crush",
18
+ "openhands",
19
+ "auggie"
20
+ ],
21
+ "homepage": "https://cyber-uni.github.io/cyber-agentkit/",
22
+ "bugs": {
23
+ "url": "https://github.com/cyber-uni/cyber-agentkit/issues"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/cyber-uni/cyber-agentkit.git",
28
+ "directory": "packages/cyber-agentkit"
29
+ },
30
+ "license": "MIT",
31
+ "author": "unional <homawong@gmail.com>",
32
+ "type": "module",
33
+ "sideEffects": [
34
+ "./bin/*.mjs",
35
+ "./dist/cli.js",
36
+ "./skills/*/scripts/*.mjs"
37
+ ],
38
+ "exports": {
39
+ ".": "./dist/index.js",
40
+ "./commands": "./dist/commands.js",
41
+ "./worktrees": "./dist/worktrees.js",
42
+ "./package.json": "./package.json"
43
+ },
44
+ "bin": {
45
+ "cyber-agentkit": "bin/cyber-agentkit.mjs"
46
+ },
47
+ "files": [
48
+ "LICENSE",
49
+ "bin",
50
+ "dist",
51
+ "skills",
52
+ "references",
53
+ "plugin.json",
54
+ ".claude-plugin",
55
+ ".cursor-plugin",
56
+ ".codex-plugin"
57
+ ],
58
+ "peerDependencies": {
59
+ "clibuilder": "^12.0.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "clibuilder": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^24.10.1",
68
+ "clibuilder": "^12.0.0",
69
+ "tsdown": "^0.23.0",
70
+ "tsx": "^4.22.3",
71
+ "typescript": "^7.0.0",
72
+ "vitest": "^5.0.0",
73
+ "yaml": "^2.9.0"
74
+ },
75
+ "engines": {
76
+ "node": ">=22"
77
+ },
78
+ "publishConfig": {
79
+ "access": "public",
80
+ "provenance": true
81
+ },
82
+ "scripts": {
83
+ "build": "tsdown",
84
+ "generate:references": "tsx scripts/generate-references.ts",
85
+ "dev": "tsx src/index.ts",
86
+ "lint": "biome check .",
87
+ "test": "pnpm build && vitest run src",
88
+ "test:watch": "vitest",
89
+ "typecheck": "tsc --noEmit",
90
+ "verify": "pnpm typecheck && pnpm lint && pnpm test"
91
+ }
92
+ }
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "cyber-agentkit",
4
- "version": "0.7.1",
4
+ "version": "1.0.0",
5
5
  "description": "An agent-harness-agnostic toolkit: the fundamental features agent tools need, working the same on every harness. Detect the running harness, check plugin dependencies, resolve layered reference documents, and lease git worktrees.",
6
6
  "author": {
7
7
  "name": "unional"
package/readme.md CHANGED
@@ -204,7 +204,7 @@ harness keeps no readable install record). A dependency with no marketplace reso
204
204
  declaring plugin's own marketplace, as Claude Code does, and is `unknown` when that marketplace
205
205
  cannot be found.
206
206
 
207
- `readPluginDependencies(pluginRoot)` reads the list from `extensions["org.spikyuni.plugin-manager"]`
207
+ `readPluginDependencies(pluginRoot)` reads the list from `extensions["io.github.cyber-uni.plugin-manager"]`
208
208
  (or the older `extensions["org.cyberuni.universal-plugin"]`) in the root `plugin.json`, then from
209
209
  `.claude-plugin/plugin.json`. `declaredPluginDependencies(manifest)` parses a manifest you already
210
210
  hold. The how-to for a person or agent, `plugin-dependencies`, ships as a
@@ -377,8 +377,8 @@ you approve it. It runs the command from its bundled `scripts/reference.mjs`, wh
377
377
  `node_modules`.
378
378
 
379
379
  ```text
380
- /plugin marketplace add cyberuni/cyberplace
381
- /plugin install cyber-agentkit@cyberplace
380
+ /plugin marketplace add cyber-uni/marketplace
381
+ /plugin install cyber-agentkit@cyber-uni
382
382
  ```
383
383
 
384
384
  A skill that needs a reference names it in one line, as the skill's
@@ -5,7 +5,7 @@ tags: [plugin, dependencies, install]
5
5
 
6
6
  ## What a plugin declares
7
7
 
8
- Only Claude Code's manifest declares dependencies: a `dependencies` array in `.claude-plugin/plugin.json` whose entries are `"name"`, `"name@marketplace"`, or `{ "name", "marketplace", "version" }` (E-DEP-1). A bare name resolves in the declaring plugin's own marketplace. A plugin can author the same list once in its root `plugin.json`, at `extensions["org.spikyuni.plugin-manager"].dependencies` or, in plugins built before that key, `extensions["org.cyberuni.universal-plugin"].dependencies` (E-DEP-6, E-DEP-7). Read it from there first, then from `.claude-plugin/plugin.json`, whichever harness you run on.
8
+ Only Claude Code's manifest declares dependencies: a `dependencies` array in `.claude-plugin/plugin.json` whose entries are `"name"`, `"name@marketplace"`, or `{ "name", "marketplace", "version" }` (E-DEP-1). A bare name resolves in the declaring plugin's own marketplace. A plugin can author the same list once in its root `plugin.json`, at `extensions["io.github.cyber-uni.plugin-manager"].dependencies` or, in plugins built before that key, `extensions["org.cyberuni.universal-plugin"].dependencies` (E-DEP-6 to E-DEP-8). Read it from there first, then from `.claude-plugin/plugin.json`, whichever harness you run on.
9
9
 
10
10
  ## Check what is missing
11
11
 
@@ -1,6 +1,6 @@
1
1
  # Reference
2
2
 
3
- Loads, creates, updates, selects, deletes, and finds [references](https://cyber-uni.github.io/cyber-agentkit/concepts/reference-documents/): Markdown documents an agent reads on demand by name. It routes each request to the `reference` command, run from a launcher bundled in `scripts/`, and writes or deletes a reference only after the user approves it. Type `/reference` (`/cyber-agentkit:reference` (pnpm install: `pnpm-cyber-agentkit-reference`) in Claude Code) to run it yourself.
3
+ Loads, creates, updates, selects, deletes, and finds [references](https://cyber-uni.github.io/cyber-agentkit/concepts/reference-documents/): Markdown documents an agent reads on demand by name. It routes each request to the `reference` command, run from a launcher bundled in `scripts/`, and writes or deletes a reference only after the user approves it. Type `/reference` to run it yourself. Installed as a Claude Code plugin, it is `/cyber-agentkit:reference` (pnpm install: `pnpm-cyber-agentkit-reference`). Installed with pnpm, it is `pnpm-cyber-agentkit-reference`.
4
4
 
5
5
  | Mode | When |
6
6
  | --- | --- |
@@ -16,8 +16,8 @@ Loads, creates, updates, selects, deletes, and finds [references](https://cyber-
16
16
  It ships in the `cyber-agentkit` plugin:
17
17
 
18
18
  ```text
19
- /plugin marketplace add cyberuni/cyberplace
20
- /plugin install cyber-agentkit@cyberplace
19
+ /plugin marketplace add cyber-uni/marketplace
20
+ /plugin install cyber-agentkit@cyber-uni
21
21
  ```
22
22
 
23
23
  ## Loading a reference from a skill
@@ -35,7 +35,7 @@ node <this skill's folder>/scripts/reference.mjs <subcommand> ... --root <reposi
35
35
 
36
36
  `scripts/reference.mjs` is the package's `reference` command bundled into one file; it needs no `node_modules`. Pass `--root` every time, so the repository's own `.agents/references/` is read. A failure prints `error: <code>: <message>` and a warning `warning: <code>: <message>`, both on stderr.
37
37
 
38
- Outside Load, when it is missing or cannot run, use `pnpm exec cyber-agentkit reference` when the package is a direct dependency, else `npx -y cyber-agentkit@0.7.1 reference`, with the same arguments. Load never falls back to a package runner.
38
+ Outside Load, when it is missing or cannot run, use `pnpm exec cyber-agentkit reference` when the package is a direct dependency, else `npx -y cyber-agentkit@1.0.0 reference`, with the same arguments. Load never falls back to a package runner.
39
39
 
40
40
  ## Load
41
41
 
@@ -1,6 +1,6 @@
1
1
  // Compiled by `universal-plugin plugin build` from src/references/reference.skill-script.ts. Edit the source, not this file.
2
- globalThis.__SKILL_SCRIPT__ = {"package":"cyber-agentkit","bin":"cyber-agentkit","version":"0.7.1","entry":"skills/reference/scripts/reference.mjs","commands":{}};
3
- import{createRequire as e}from"node:module";import{fileURLToPath as t}from"node:url";import{existsSync as n,mkdirSync as r,readFileSync as i,readdirSync as a,realpathSync as o,rmSync as s,rmdirSync as c,statSync as l,writeFileSync as u}from"node:fs";import{basename as d,dirname as f,join as p,posix as m,relative as h,resolve as g,sep as _,win32 as v}from"node:path";import{inspect as y,styleText as b}from"node:util";import{homedir as x}from"node:os";import{readFile as S,readdir as C}from"node:fs/promises";var w=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),T=/* @__PURE__ */ e(import.meta.url),E=`0.7.1`,D=`cyber-agentkit`,ee;const O={success:0,error:1,usage:2},te=Symbol.for(`clibuilder.CliError`),ne=Symbol.for(`clibuilder.CliError.reported`),re=[`error`,`code`,`help`];var ie=class e extends Error{static reported(t=O.error,n=`the error was already reported`){let r=new e(n,{exitCode:t});return r[ne]=!0,r}constructor(e,t){let n=typeof e==`string`?{...t,message:e}:e;super(n.message),this.name=`CliError`,this[ee]=!0,this.exitCode=se(n.exitCode??O.error),this.code=ce(n.code??`error`),this.details=le(n.details??{}),this.help=n.help===void 0?[]:typeof n.help==`string`?[n.help]:[...n.help],this.cause=n.cause}};ee=te;function ae(e){return!!e&&typeof e==`object`&&e[te]===!0}function oe(e){return e[ne]===!0}function se(e){if(Number.isInteger(e)&&e>=1&&e<=255)return e;throw RangeError(`CliError exitCode must be an integer from 1 to 255, received ${e}`)}function ce(e){if(/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))return e;throw RangeError(`CliError code must be a kebab-case string such as "not-found", received "${e}"`)}function le(e){for(let t of re)if(t in e)throw RangeError(`CliError details may not have the key "${t}"`);return{...e}}function k(e){return e}function ue(e){let t=e.kind===`array`?e.element:e;return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function de(e){switch(e.kind){case`string`:return e.pattern?`string ${e.pattern}`:`string`;case`number`:case`int`:return`${e.kind}${fe(e.min,e.max)}`;case`boolean`:case`json`:return e.kind;case`literal`:return String(e.value);case`enum`:return e.values.join(`|`);case`custom`:return`value`;case`array`:return de(e.element)}}function fe(e,t){return e!==void 0&&t!==void 0?` ${e}..${t}`:e===void 0?t===void 0?``:` <=${t}`:` >=${e}`}const pe={optional(){return me({...this,isOptional:!0})},check(e){let t=typeof e==`function`?{type:`fn`,fn:e}:{type:`schema`,schema:e};if(typeof e!=`function`&&!he(e))throw TypeError(`check() takes a function or a Standard Schema`);return me({...this,checks:[...this.checks,t]})}};function me(e){return Object.freeze(Object.assign(Object.create(pe),e))}function A(e){return me({...e,isOptional:!1,checks:Object.freeze([])})}function he(e){let t=e?.[`~standard`];return typeof t==`object`&&!!t&&typeof t.validate==`function`}function ge(e,t,n){let{min:r,max:i}=t??{};for(let[t,a]of[[`min`,r],[`max`,i]])if(a!==void 0){if(typeof a!=`number`||Number.isNaN(a))throw TypeError(`${e}: ${t} must be a number`);if(n&&Number.isFinite(a)&&!Number.isInteger(a))throw RangeError(`${e}: ${t} must be an integer, got ${a}`)}if(r!==void 0&&i!==void 0&&r>i)throw RangeError(`${e}: min (${r}) is greater than max (${i})`);return{...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}}function _e(e){let t=e?.pattern;if(t!==void 0&&!(t instanceof RegExp))throw TypeError(`t.string: pattern must be a RegExp`);return A(t===void 0?{kind:`string`}:{kind:`string`,pattern:t})}function ve(e){if(e===void 0)return A({kind:`json`});if(!he(e))throw TypeError(`t.json: schema must be a Standard Schema`);return A({kind:`json`,schema:e})}const j={string:_e,number(e){return A({kind:`number`,...ge(`t.number`,e,!1)})},int(e){return A({kind:`int`,...ge(`t.int`,e,!0)})},boolean(){return A({kind:`boolean`})},literal(e){let t=typeof e;if(!(t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)))throw TypeError(`t.literal: value must be a string, a finite number or a boolean, got ${String(e)}`);return A({kind:`literal`,value:e})},enum(e){if(!Array.isArray(e)||e.length===0)throw TypeError(`t.enum: values must be a non-empty array`);for(let t of e)if(typeof t!=`string`)throw TypeError(`t.enum: values must be strings, got ${String(t)}`);return A({kind:`enum`,values:Object.freeze([...e])})},array(e){let t=e;if(typeof t?.kind!=`string`||!Object.prototype.isPrototypeOf.call(pe,t))throw TypeError(`t.array: element must be a descriptor`);if(t.kind===`array`)throw TypeError(`t.array: element cannot be an array`);if(t.isOptional)throw TypeError(`t.array: element cannot be optional`);return A({kind:`array`,element:e})},custom(e){if(typeof e!=`function`)throw TypeError(`t.custom: convert must be a function`);return A({kind:`custom`,convert:e})},json:ve};function ye(e){return typeof e==`object`&&!!e&&Object.prototype.isPrototypeOf.call(pe,e)}String.prototype.charCodeAt;const be=String.prototype.slice;Array.prototype.forEach,Array.prototype.map,Array.prototype.reduce;const xe=Array.prototype.slice,Se=Array.prototype.push,Ce={modifiers:`-`,terminator:`--`};function we(e){let t=/* @__PURE__ */ new Set,n=e?.modifiers??Ce.modifiers;for(let e of typeof n==`string`?Array.from(n):n){if(e.length!==1||e===`=`)throw Error(`Invalid modifier '${e}': a modifier must be a single character other than '='`);t.add(e)}if(t.size===0)throw Error(`At least one modifier is required`);let r=e?.terminator??Ce.terminator;if(r===``)throw Error(`The terminator must not be empty`);return{modifiers:t,terminator:r}}function Te(e,t){let n=0;for(;n<e.length&&t.has(e[n]);)n++;return[be.call(e,n),n]}function Ee(e,t){let{modifiers:n,terminator:r}=we(t),i=[],a=0,o=xe.call(e);for(;o.length>0;){let e=o.shift();if(e===r){Se.call(i,{kind:`option-terminator`,index:a}),a++,Se.apply(i,o.map((e,t)=>({kind:`positional`,index:a+t,value:e})));break}let[t,s]=Te(e,n);if(s===0||!t)Se.call(i,{kind:`positional`,index:a,value:t||e});else{let n=t.indexOf(`=`),[r,o]=n===-1?[t,void 0]:[be.call(t,0,n),be.call(t,n+1)];Se.call(i,{kind:`option`,index:a,name:r,dashes:s,raw:e,value:o})}a++}return i}var De=class extends Error{constructor(e,t,n,r={}){super(e),Object.defineProperty(this,"option",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"input",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"kind",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"issues",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"detail",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=`ParseArgsError`,this.kind=r.kind??`invalid-value`,this.index=r.index,this.issues=r.issues,this.value=r.value,this.detail=r.detail??e}};function Oe(e){let t=je(e),n=t.next();for(;!n.done;){let{value:e,option:r}=n.value;if(Ae(e))throw e.then(void 0,()=>{}),t.return(void 0),Error(`Option '${r}' has an asynchronous converter or check: use parseArgsAsync() to parse it`);n=t.next(e)}return n.value}async function ke(e){let t=je(e),n=t.next();for(;!n.done;)n=await Promise.resolve(n.value.value).then(e=>t.next(e),e=>t.throw(e));return n.value}function Ae(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&typeof e.then==`function`}function*je(e){let t=Ee(e.args,e.grammar),n=e.options;Me(n);let r=Pe(n),i=Object.create(null),a=Object.create(null),o=[],s=[],c=t.slice();for(;c.length>0;){let t=c.shift();switch(t.kind){case`positional`:Ne(e,t.value),o.push(t.value);break;case`option`:{let o=t.dashes===1?Array.from(t.name):[t.name];for(let s=0;s<o.length;s++){let l=o[s],u=s===o.length-1,d=r.get(l)??l,f=n?.[d];if(e.strict&&!f)throw new De(`Unknown option '${l}' (from '${t.raw}')`,l,t.raw,{kind:`unknown-option`});if(!u&&f&&Ie(f))throw new De(`Invalid option group '${t.raw}': '${l}' takes a value, so it can only be the last option in a group`,d,t.raw,{kind:`invalid-group`,detail:`takes a value, so it can only be the last option in a group`});let p=u?t.value??Re(f,c):void 0;if(f&&ye(f.type)){let e=f.type;if(e.kind===`array`){let n=i[d]??(i[d]=[]);(a[d]??(a[d]=[])).push(t.raw);let r={name:d,label:`${d}[${n.length}]`,index:n.length,token:t};n.push(yield*Ge(e.element,p,r))}else i[d]=yield*Ge(e,p,{name:d,label:d,index:void 0,token:t});continue}let m=ze(f,d,p,t);f?.multiple?(i[d]??(i[d]=[])).push(m):i[d]=m}break}case`option-terminator`:for(let t of c)Ne(e,t.value);s.push(...c.map(e=>e.value)),c.length=0}}for(let[e,t]of Object.entries(n??{})){let n=ye(t.type)?t.type:void 0;if(i[e]!==void 0){if(n?.kind===`array`){let t=a[e].join(` `);yield*Xe(n,i[e],e,(n,r)=>We(e,e,t,n,{issues:r}))}continue}if(t.default!==void 0)n&&(yield*Qe(t,e)),i[e]=Array.isArray(t.default)?[...t.default]:t.default;else if(n&&!n.isOptional)throw new De(`Missing required option '${e}'`,e,``,{kind:`missing-option`,detail:`a value is required`})}let l={_:o,__:s,options:i};return e.tokens&&(l.tokens=t),l}function Me(e){for(let[t,n]of Object.entries(e??{})){let e=n.type;if(typeof e==`object`&&e&&!ye(e))throw TypeError(`Option '${t}' has a type that is neither a type name nor a descriptor from t`);if(ye(e)&&n.multiple!==void 0)throw TypeError(`Option '${t}' cannot set 'multiple' with a descriptor: use t.array(element)`)}}function Ne(e,t){if(e.allowPositionals===!1)throw new De(`Unexpected positional argument '${t}'`,void 0,t,{kind:`unexpected-positional`})}function Pe(e){let t=/* @__PURE__ */ new Map;if(!e)return t;for(let n of Object.keys(e))t.set(n,n);for(let[n,r]of Object.entries(e)){let e=r.alias;for(let r of e===void 0?[]:Array.isArray(e)?e:[e]){let e=t.get(r);if(e!==void 0&&e!==n)throw Error(`Alias '${r}' of option '${n}' is already used by option '${e}'`);t.set(r,n)}}return t}function Fe(e){return e.kind===`array`?e.element:e}function Ie(e){if(!ye(e.type))return e.type!==`boolean`;let t=Fe(e.type);return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function Le(e){if(!ye(e.type))return e.type===`number`;let t=Fe(e.type);return t.kind===`number`||t.kind===`int`||t.kind===`literal`&&typeof t.value==`number`}function Re(e,t){if(!e||!Ie(e))return;let n=t[0];if(n){if(n.kind===`positional`)return t.shift(),n.value;if(n.kind===`option`&&Le(e)&&Number.isFinite(Ve(n.raw)))return t.shift(),n.raw}}function ze(e,t,n,r){if(!e)return n??!0;switch(e.type){case`boolean`:return Ue(t,n,r);case`number`:return He(t,n,r);default:if(n===void 0)throw Be(t,`a value is required`,r,`missing-value`);return n}}function Be(e,t,n,r,i){return new De(`Invalid value for option '${e}': ${t} (from '${n.raw}')`,e,n.raw,{kind:r,value:i,detail:t})}function Ve(e){return e.trim()===``?NaN:Number(e)}function He(e,t,n){if(t===void 0)throw Be(e,`a number is required`,n,`missing-value`);let r=Ve(t);if(!Number.isFinite(r))throw Be(e,t,n,`invalid-value`,t);return r}function Ue(e,t,n){if(t===void 0)return!0;if(t===`false`||t===`f`||t===`0`)return!1;if(t===`true`||t===`t`)return!0;let r=Ve(t);if(!Number.isNaN(r))return r>0;throw Be(e,t,n,`invalid-value`,t)}function We(e,t,n,r,i,a=r){return new De(`Invalid value for option '${t}': ${a} (from '${n}')`,e,n,{...i,detail:r})}function*Ge(e,t,n){let r=(e,r,i)=>We(n.name,n.label,n.token.raw,e,{index:n.index,issues:r,value:t},i),i=yield*Je(e,t,n,r);return yield*Xe(e,i,n.label,r),i}function Ke(e){return`'${e}'`}function qe(e){switch(e.kind){case`string`:return`a string matching ${e.pattern}`;case`number`:case`int`:{let t=e.kind===`int`?`an integer`:`a number`;return e.min!==void 0&&e.max!==void 0?`${t} from ${e.min} to ${e.max}`:e.min===void 0?e.max===void 0?t:`${t} of at most ${e.max}`:`${t} of at least ${e.min}`}case`boolean`:return`no value, true or false`;case`literal`:return typeof e.value==`string`?Ke(e.value):String(e.value);case`enum`:return`one of ${e.values.map(Ke).join(`, `)}`}}function*Je(e,t,n,r){let i=e=>r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got ${Ke(t)}`);if(e.kind===`boolean`||e.kind===`literal`&&typeof e.value==`boolean`){let n=t===void 0||t===`true`||t!==`false`&&void 0;if(n===void 0||e.kind===`literal`&&n!==e.value)throw t===void 0?r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got no value`):i(e);return n}if(t===void 0)throw We(n.name,n.label,n.token.raw,`a value is required`,{kind:`missing-value`,index:n.index});switch(e.kind){case`string`:if(e.pattern&&(e.pattern.lastIndex=0,!e.pattern.test(t)))throw i(e);return t;case`number`:case`int`:{let n=Ve(t);if(!Number.isFinite(n)||e.kind===`int`&&!Number.isInteger(n)||e.min!==void 0&&n<e.min||e.max!==void 0&&n>e.max)throw i(e);return n}case`literal`:{let n=typeof e.value==`number`?Ve(t):t;if(n!==e.value)throw i(e);return n}case`enum`:if(!e.values.includes(t))throw i(e);return t;case`custom`:try{return yield{value:e.convert(t),option:n.label}}catch(e){throw Ye(e,r)}case`json`:{let i;try{i=JSON.parse(t)}catch{throw r(`not valid JSON`,void 0,`${Ke(t)} is not valid JSON`)}if(!e.schema)return i;let a=yield{value:e.schema[`~standard`].validate(i),option:n.label};if(a.issues)throw r(`does not match the expected shape`,a.issues);return a.value}}}function Ye(e,t){return e instanceof Error&&e.constructor===Error?t(e.message):e}function*Xe(e,t,n,r){for(let i of e.checks)if(i.type===`fn`){let e=yield{value:i.fn(t),option:n};if(e===!1)throw r(`failed a check`);if(typeof e==`string`)throw r(e)}else{let e=yield{value:i.schema[`~standard`].validate(t),option:n};if(e.issues)throw r(`failed a check`,e.issues)}}const Ze=/* @__PURE__ */ new WeakMap;function*Qe(e,t){if(Ze.has(e))return;let n=e.type,r=e=>t=>/* @__PURE__ */ Error(`The default of option '${e}' failed a check${t===`failed a check`?``:`: ${t}`}`);if(n.kind===`array`){let i=e.default;for(let e=0;e<i.length;e++){let a=`${t}[${e}]`;yield*Xe(n.element,i[e],a,r(a))}}yield*Xe(n,e.default,t,r(t)),Ze.set(e,!0)}const $e=/* @__PURE__ */ new WeakMap;function et(e,t,n){let r=tt(e,nt(t,n)),[i,a]=rt(t,r,n);return ct(r,i,a)}function tt(e,t){if(e.commands){let n=e.commands,r=t.peek(e);for(let e=n.length-1;e>=0;e--){let i=n[e];if(!i.name)return i;if(r===i.name||i.alias?.includes(r))return t.consume(),i.commands?tt(i,t):i}}return e}function nt(e,t){let n=$e.get(e)??[],r,i=-1,a=0;return{peek(o){if(r=void 0,i<0){if(a<e._.length)return(r=[e._,a])[0][a];i=0,a=-1}for(;t&&i<n.length;){let e=n[i];if(a<0){let n=M(t,e.key)[1];if(!n)return;a=it(M(o,e.key)[1]??n,e)}if(a<e.following.length)return(r=[e.following,a])[0][a];i++,a=-1}},consume(){r[0].splice(r[1],1)}}}function rt(e,t,n){let r=$e.get(e);if(!r)return[e,void 0];let i={},a=[],o=[];for(let e of r){let r=M(t,e.key)[1],s=it(r??(n&&M(n,e.key)[1]),e),c=e.following.slice(0,s);r&&o.push({key:e.key,tokens:[e.raw,...c]}),a.push(...e.following.slice(s));let l=e.inline.length+c.length>0?[...e.inline,...c]:[`true`];i[e.key]=[...i[e.key]??[],...l]}let s={...e,_:[...e._,...a]};for(let t of Object.keys(i))e[t]&&(s[t]=i[t]);return[s,o]}function it(e,t){return e?t.inline.length===0&&ue(st(e))?1:0:t.following.length}const at=j.boolean().optional(),ot=j.string();function st(e){return e.type??at}function ct(e,t,n){return ft(dt(ut(lt({command:e,rawArgs:t,args:{_:[]},errors:[],descriptors:[]}))),n)}function lt(e){let t=e.command,n=[...e.rawArgs._],r=t.arguments||[];for(let t of r){let r=t.type??ot;if(n.length===0){r.isOptional||e.errors.push({type:`missing-argument`,name:t.name});continue}let i=r.kind===`array`?n.splice(0):[n.shift()];e.descriptors.push({type:`argument`,name:t.name,descriptor:r,values:i})}return n.length>0&&e.errors.push({type:`extra-arguments`,name:t.name,values:n}),e}function ut(e){for(let t of Object.keys(e.rawArgs)){if(t===`_`)continue;if(/^-/.test(t)){e.errors.push({type:`invalid-key`,key:t});continue}let[n,r]=M(e.command,t);if(!n){e.errors.push({type:`invalid-key`,key:t});continue}let i=st(r),a=e.rawArgs[t];i.kind!==`array`&&a.length>1&&e.errors.push({type:`expect-single`,key:t,keyKind:i.kind,value:a})}return e}function dt(e){let t=e.command.options;if(!t)return e;let n=/* @__PURE__ */ new Map;for(let t of Object.keys(e.rawArgs)){let[r]=M(e.command,t);r&&!n.has(r)&&n.set(r,t)}let r=[...n.keys()];for(let i=0;i<r.length;i++)for(let a=i+1;a<r.length;a++){let[o,s]=[r[i],r[a]];if(!t[o].conflicts?.includes(s)&&!t[s].conflicts?.includes(o))continue;let[c,l]=t[o].conflicts?.includes(s)?[o,s]:[s,o];e.errors.push({type:`conflicting-options`,key:n.get(c),conflictsWith:n.get(l)})}return e}function ft(e,t){let n=e.command.options??{};for(let r of Object.keys(n)){let i=n[r],a=Object.keys(e.rawArgs).filter(t=>t!==`_`&&M(e.command,t)[0]===r);e.errors.some(e=>e.type===`expect-single`&&a.includes(e.key))||e.descriptors.push({type:`option`,name:r,entry:{...i,type:st(i)},occurrences:t?t.filter(e=>a.includes(e.key)):a.flatMap(t=>e.rawArgs[t].map(e=>({key:t,tokens:[`--${r}=${e}`]})))})}return e}function M(e,t){let n=e.options;if(!n)return[];let r=n[t];if(r)return[t,r];let i=Object.keys(n).find(e=>{let r=n[e];return r.alias?r.alias.some(e=>e===t||e.alias===t):!1});return i?[i,n[i]]:[]}const pt={comma:`,`,tab:` `,pipe:`|`},mt=pt.comma;function ht(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`).replace(/[\u0000-\u001F]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function gt(e){return e===`true`||e===`false`||e===`null`}function _t(e,t,n){if(t===`__proto__`){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0});return}e[t]=n}const vt=/* @__PURE__ */ RegExp(`(?:^?|\\n) *#`);var yt=class{constructor(e){if(vt.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function bt(e){return e instanceof yt}const xt=/[\uD800-\uDFFF]/;function St(e){if(e===null)return null;if(bt(e))return e;if(typeof e==`object`&&e&&`toJSON`in e&&typeof e.toJSON==`function`){let t=e.toJSON();if(t!==e)return St(t)}if(typeof e==`string`)return Ct(e,`string value`),e;if(typeof e==`boolean`)return e;if(typeof e==`number`)return Object.is(e,-0)?0:Number.isFinite(e)?e:null;if(typeof e==`bigint`)return e>=-(2**53-1)&&e<=2**53-1?Number(e):e.toString();if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(St);if(e instanceof Set)return Array.from(e).map(St);if(e instanceof Map)return Object.fromEntries(Array.from(e,([e,t])=>[String(e),St(t)]));if(Ot(e)){let t={};for(let n in e)Object.hasOwn(e,n)&&(Ct(n,`object key`),_t(t,n,St(e[n])));return t}return null}function Ct(e,t){if(xt.test(e))for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<55296||r>57343)continue;let i=r<=56319,a=e.charCodeAt(n+1);if(i&&a>=56320&&a<=57343){n++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${r.toString(16).toUpperCase()} at index ${n}`)}}function wt(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function Tt(e){return wt(e)||bt(e)}function Et(e){return Array.isArray(e)}function N(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!bt(e)}function Dt(e){return Object.keys(e).length===0}function Ot(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function kt(e){return e.length===0||e.every(e=>Tt(e))}function At(e){return e.length===0||e.every(e=>Et(e))}function jt(e){return e.length===0||e.every(e=>N(e))}const Mt=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Nt(e){if(!Object.values(pt).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Pt(e){return/^[A-Z_][\w.]*$/i.test(e)}function Ft(e,t=mt){return!(!e||/^[ \t]|[ \t]$/.test(e)||gt(e)||It(e)||e.includes(`:`)||e.includes(`"`)||e.includes(`\\`)||/[[\]{}]/.test(e)||/[\u0000-\u001F]/.test(e)||e.includes(t)||e.startsWith(`-`)||e.startsWith(`#`))}function It(e){return Mt.test(e)}function Lt(e,t){return bt(e)?e.value:e===null?`null`:typeof e==`boolean`||typeof e==`number`?String(e):Rt(e,t)}function Rt(e,t=mt){return Ft(e,t)?e:`"${ht(e)}"`}function zt(e){return Pt(e)?e:`"${ht(e)}"`}function Bt(e,t=mt){return e.map(e=>Lt(e,t)).join(t)}function P(e,t){let n=t?.key,r=t?.fields,i=t?.delimiter??`,`,a=``;return n!=null&&(a+=zt(n)),a+=`[${e}${t?.keyed?`:`:``}${i===mt?``:i}]`,r&&(a+=`{${Vt(r,i)}}`),a+=`:`,a}function Vt(e,t){return e.map(e=>zt(e.name)+(e.children?`{${Vt(e.children,t)}}`:``)).join(t)}function Ht(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let e of t)if(!Object.hasOwn(n,e))return}let n=[];for(let r of t){let t=Gt(r,e.map(e=>e[r]));if(!t)return;n.push(t)}return n}function Ut(e){let t=Object.values(e);if(!(t.length<2)&&t.every(e=>N(e)&&!Dt(e)))return Ht(t)}function Wt(e,t){let n=[];return Kt(e,t,n),n}function Gt(e,t){if(t.every(e=>Tt(e)))return{name:e};if(!t.every(e=>N(e)&&!Dt(e)))return;let n=Ht(t);if(n)return{name:e,children:n}}function Kt(e,t,n){for(let r of t){let t=e[r.name];r.children?Kt(t,r.children,n):n.push(t)}}function*qt(e,t,n){if(Tt(e)){let n=Lt(e,t.delimiter);n!==``&&(yield n);return}if(Et(e))yield*Qt(void 0,e,n,t);else if(N(e)){let r=Ut(e);if(r){yield*Xt(void 0,e,r,n,t);return}yield*Jt(e,n,t)}}function*Jt(e,t,n){for(let[r,i]of Object.entries(e))yield*Yt(r,i,t,n)}function*Yt(e,t,n,r){let i=zt(e);if(Tt(t))yield F(n,`${i}: ${Lt(t,r.delimiter)}`,r.indentSize);else if(Et(t))yield*Qt(e,t,n,r);else if(N(t)){let a=Ut(t);if(a){yield*Xt(e,t,a,n,r);return}yield F(n,`${i}:`,r.indentSize),Dt(t)||(yield*Jt(t,n+1,r))}}function*Xt(e,t,n,r,i){let a=Object.entries(t);yield F(r,P(a.length,{key:e,fields:n,delimiter:i.delimiter,keyed:!0}),i.indentSize),yield*Zt(a,n,r+1,i)}function*Zt(e,t,n,r){for(let[i,a]of e){let e=Wt(a,t);yield F(n,`${zt(i)}: ${Bt(e,r.delimiter)}`,r.indentSize)}}function*Qt(e,t,n,r){if(t.length===0){yield F(n,e==null?`[]`:`${zt(e)}: []`,r.indentSize);return}if(kt(t)){yield F(n,en(t,r.delimiter,e),r.indentSize);return}if(At(t)&&t.every(e=>kt(e))){yield*$t(e,t,n,r);return}if(jt(t)){let i=Ht(t);i?yield*tn(e,t,i,n,r):yield*rn(e,t,n,r);return}yield*rn(e,t,n,r)}function*$t(e,t,n,r){yield F(n,P(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)if(kt(e)){let t=en(e,r.delimiter);yield I(n+1,t,r.indentSize)}}function en(e,t,n){let r=P(e.length,{key:n,delimiter:t}),i=Bt(e,t);return e.length===0?r:`${r} ${i}`}function*tn(e,t,n,r,i){yield F(r,P(t.length,{key:e,fields:n,delimiter:i.delimiter}),i.indentSize),yield*nn(t,n,r+1,i)}function*nn(e,t,n,r){for(let i of e)yield F(n,Bt(Wt(i,t),r.delimiter),r.indentSize)}function*rn(e,t,n,r){yield F(n,P(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)yield*on(e,n+1,r)}function*an(e,t,n){if(Dt(e)){yield F(t,`-`,n.indentSize);return}let r=Object.entries(e),[i,a]=r[0],o=r.slice(1);if(Et(a)&&jt(a)){let e=Ht(a);if(e){yield I(t,P(a.length,{key:i,fields:e,delimiter:n.delimiter}),n.indentSize),yield*nn(a,e,t+2,n),o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n));return}}if(N(a)){let e=Ut(a);if(e){let r=Object.entries(a);yield I(t,P(r.length,{key:i,fields:e,delimiter:n.delimiter,keyed:!0}),n.indentSize),yield*Zt(r,e,t+2,n),o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n));return}}let s=zt(i);if(Tt(a))yield I(t,`${s}: ${Lt(a,n.delimiter)}`,n.indentSize);else if(Et(a)){if(a.length===0)yield I(t,`${s}: []`,n.indentSize);else if(kt(a))yield I(t,`${s}${en(a,n.delimiter)}`,n.indentSize);else{yield I(t,`${s}${P(a.length,{delimiter:n.delimiter})}`,n.indentSize);for(let e of a)yield*on(e,t+2,n)}}else N(a)&&(yield I(t,`${s}:`,n.indentSize),Dt(a)||(yield*Jt(a,t+2,n)));o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n))}function*on(e,t,n){if(Tt(e))yield I(t,Lt(e,n.delimiter),n.indentSize);else if(Et(e)){if(kt(e))yield I(t,en(e,n.delimiter),n.indentSize);else{yield I(t,P(e.length,{delimiter:n.delimiter}),n.indentSize);for(let r of e)yield*on(r,t+1,n)}}else N(e)&&(yield*an(e,t,n))}function F(e,t,n){return` `.repeat(n*e)+t}function I(e,t,n){return F(e,`- `+t,n)}function sn(e,t){let n=t(``,e,[]);return n===void 0?ln(e,t,[]):cn(e,n,t,[])}function cn(e,t,n,r){return bt(t)&&!Tt(e)?ln(e,n,r):ln(St(t),n,r)}function ln(e,t,n){return N(e)?un(e,t,n):Et(e)?dn(e,t,n):e}function un(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=[...n,i],o=t(i,a,e);o!==void 0&&_t(r,i,cn(a,o,t,e))}return r}function dn(e,t,n){let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=[...n,i],s=t(String(i),a,o);s!==void 0&&r.push(cn(a,s,t,o))}return r}function fn(e,t){return Array.from(pn(e,t)).join(`
2
+ globalThis.__SKILL_SCRIPT__ = {"package":"cyber-agentkit","bin":"cyber-agentkit","version":"1.0.0","entry":"skills/reference/scripts/reference.mjs","commands":{}};
3
+ import{createRequire as e}from"node:module";import{fileURLToPath as t}from"node:url";import{existsSync as n,mkdirSync as r,readFileSync as i,readdirSync as a,realpathSync as o,rmSync as s,rmdirSync as c,statSync as l,writeFileSync as u}from"node:fs";import{basename as d,dirname as f,join as p,posix as m,relative as h,resolve as g,sep as _,win32 as v}from"node:path";import{inspect as y,styleText as b}from"node:util";import{homedir as x}from"node:os";import{readFile as S,readdir as C}from"node:fs/promises";var w=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),T=/* @__PURE__ */ e(import.meta.url),E=`1.0.0`,D=`cyber-agentkit`,ee;const O={success:0,error:1,usage:2},te=Symbol.for(`clibuilder.CliError`),ne=Symbol.for(`clibuilder.CliError.reported`),re=[`error`,`code`,`help`];var ie=class e extends Error{static reported(t=O.error,n=`the error was already reported`){let r=new e(n,{exitCode:t});return r[ne]=!0,r}constructor(e,t){let n=typeof e==`string`?{...t,message:e}:e;super(n.message),this.name=`CliError`,this[ee]=!0,this.exitCode=se(n.exitCode??O.error),this.code=ce(n.code??`error`),this.details=le(n.details??{}),this.help=n.help===void 0?[]:typeof n.help==`string`?[n.help]:[...n.help],this.cause=n.cause}};ee=te;function ae(e){return!!e&&typeof e==`object`&&e[te]===!0}function oe(e){return e[ne]===!0}function se(e){if(Number.isInteger(e)&&e>=1&&e<=255)return e;throw RangeError(`CliError exitCode must be an integer from 1 to 255, received ${e}`)}function ce(e){if(/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e))return e;throw RangeError(`CliError code must be a kebab-case string such as "not-found", received "${e}"`)}function le(e){for(let t of re)if(t in e)throw RangeError(`CliError details may not have the key "${t}"`);return{...e}}function k(e){return e}function ue(e){let t=e.kind===`array`?e.element:e;return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function de(e){switch(e.kind){case`string`:return e.pattern?`string ${e.pattern}`:`string`;case`number`:case`int`:return`${e.kind}${fe(e.min,e.max)}`;case`boolean`:case`json`:return e.kind;case`literal`:return String(e.value);case`enum`:return e.values.join(`|`);case`custom`:return`value`;case`array`:return de(e.element)}}function fe(e,t){return e!==void 0&&t!==void 0?` ${e}..${t}`:e===void 0?t===void 0?``:` <=${t}`:` >=${e}`}const pe={optional(){return me({...this,isOptional:!0})},check(e){let t=typeof e==`function`?{type:`fn`,fn:e}:{type:`schema`,schema:e};if(typeof e!=`function`&&!he(e))throw TypeError(`check() takes a function or a Standard Schema`);return me({...this,checks:[...this.checks,t]})}};function me(e){return Object.freeze(Object.assign(Object.create(pe),e))}function A(e){return me({...e,isOptional:!1,checks:Object.freeze([])})}function he(e){let t=e?.[`~standard`];return typeof t==`object`&&!!t&&typeof t.validate==`function`}function ge(e,t,n){let{min:r,max:i}=t??{};for(let[t,a]of[[`min`,r],[`max`,i]])if(a!==void 0){if(typeof a!=`number`||Number.isNaN(a))throw TypeError(`${e}: ${t} must be a number`);if(n&&Number.isFinite(a)&&!Number.isInteger(a))throw RangeError(`${e}: ${t} must be an integer, got ${a}`)}if(r!==void 0&&i!==void 0&&r>i)throw RangeError(`${e}: min (${r}) is greater than max (${i})`);return{...r===void 0?{}:{min:r},...i===void 0?{}:{max:i}}}function _e(e){let t=e?.pattern;if(t!==void 0&&!(t instanceof RegExp))throw TypeError(`t.string: pattern must be a RegExp`);return A(t===void 0?{kind:`string`}:{kind:`string`,pattern:t})}function ve(e){if(e===void 0)return A({kind:`json`});if(!he(e))throw TypeError(`t.json: schema must be a Standard Schema`);return A({kind:`json`,schema:e})}const j={string:_e,number(e){return A({kind:`number`,...ge(`t.number`,e,!1)})},int(e){return A({kind:`int`,...ge(`t.int`,e,!0)})},boolean(){return A({kind:`boolean`})},literal(e){let t=typeof e;if(!(t===`string`||t===`boolean`||t===`number`&&Number.isFinite(e)))throw TypeError(`t.literal: value must be a string, a finite number or a boolean, got ${String(e)}`);return A({kind:`literal`,value:e})},enum(e){if(!Array.isArray(e)||e.length===0)throw TypeError(`t.enum: values must be a non-empty array`);for(let t of e)if(typeof t!=`string`)throw TypeError(`t.enum: values must be strings, got ${String(t)}`);return A({kind:`enum`,values:Object.freeze([...e])})},array(e){let t=e;if(typeof t?.kind!=`string`||!Object.prototype.isPrototypeOf.call(pe,t))throw TypeError(`t.array: element must be a descriptor`);if(t.kind===`array`)throw TypeError(`t.array: element cannot be an array`);if(t.isOptional)throw TypeError(`t.array: element cannot be optional`);return A({kind:`array`,element:e})},custom(e){if(typeof e!=`function`)throw TypeError(`t.custom: convert must be a function`);return A({kind:`custom`,convert:e})},json:ve};function ye(e){return typeof e==`object`&&!!e&&Object.prototype.isPrototypeOf.call(pe,e)}String.prototype.charCodeAt;const be=String.prototype.slice;Array.prototype.forEach,Array.prototype.map,Array.prototype.reduce;const xe=Array.prototype.slice,Se=Array.prototype.push,Ce={modifiers:`-`,terminator:`--`};function we(e){let t=/* @__PURE__ */ new Set,n=e?.modifiers??Ce.modifiers;for(let e of typeof n==`string`?Array.from(n):n){if(e.length!==1||e===`=`)throw Error(`Invalid modifier '${e}': a modifier must be a single character other than '='`);t.add(e)}if(t.size===0)throw Error(`At least one modifier is required`);let r=e?.terminator??Ce.terminator;if(r===``)throw Error(`The terminator must not be empty`);return{modifiers:t,terminator:r}}function Te(e,t){let n=0;for(;n<e.length&&t.has(e[n]);)n++;return[be.call(e,n),n]}function Ee(e,t){let{modifiers:n,terminator:r}=we(t),i=[],a=0,o=xe.call(e);for(;o.length>0;){let e=o.shift();if(e===r){Se.call(i,{kind:`option-terminator`,index:a}),a++,Se.apply(i,o.map((e,t)=>({kind:`positional`,index:a+t,value:e})));break}let[t,s]=Te(e,n);if(s===0||!t)Se.call(i,{kind:`positional`,index:a,value:t||e});else{let n=t.indexOf(`=`),[r,o]=n===-1?[t,void 0]:[be.call(t,0,n),be.call(t,n+1)];Se.call(i,{kind:`option`,index:a,name:r,dashes:s,raw:e,value:o})}a++}return i}var De=class extends Error{constructor(e,t,n,r={}){super(e),Object.defineProperty(this,"option",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"input",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"kind",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"issues",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"detail",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=`ParseArgsError`,this.kind=r.kind??`invalid-value`,this.index=r.index,this.issues=r.issues,this.value=r.value,this.detail=r.detail??e}};function Oe(e){let t=je(e),n=t.next();for(;!n.done;){let{value:e,option:r}=n.value;if(Ae(e))throw e.then(void 0,()=>{}),t.return(void 0),Error(`Option '${r}' has an asynchronous converter or check: use parseArgsAsync() to parse it`);n=t.next(e)}return n.value}async function ke(e){let t=je(e),n=t.next();for(;!n.done;)n=await Promise.resolve(n.value.value).then(e=>t.next(e),e=>t.throw(e));return n.value}function Ae(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&typeof e.then==`function`}function*je(e){let t=Ee(e.args,e.grammar),n=e.options;Me(n);let r=Pe(n),i=Object.create(null),a=Object.create(null),o=[],s=[],c=t.slice();for(;c.length>0;){let t=c.shift();switch(t.kind){case`positional`:Ne(e,t.value),o.push(t.value);break;case`option`:{let o=t.dashes===1?Array.from(t.name):[t.name];for(let s=0;s<o.length;s++){let l=o[s],u=s===o.length-1,d=r.get(l)??l,f=n?.[d];if(e.strict&&!f)throw new De(`Unknown option '${l}' (from '${t.raw}')`,l,t.raw,{kind:`unknown-option`});if(!u&&f&&Ie(f))throw new De(`Invalid option group '${t.raw}': '${l}' takes a value, so it can only be the last option in a group`,d,t.raw,{kind:`invalid-group`,detail:`takes a value, so it can only be the last option in a group`});let p=u?t.value??Re(f,c):void 0;if(f&&ye(f.type)){let e=f.type;if(e.kind===`array`){let n=i[d]??(i[d]=[]);(a[d]??(a[d]=[])).push(t.raw);let r={name:d,label:`${d}[${n.length}]`,index:n.length,token:t};n.push(yield*Ge(e.element,p,r))}else i[d]=yield*Ge(e,p,{name:d,label:d,index:void 0,token:t});continue}let m=ze(f,d,p,t);f?.multiple?(i[d]??(i[d]=[])).push(m):i[d]=m}break}case`option-terminator`:for(let t of c)Ne(e,t.value);s.push(...c.map(e=>e.value)),c.length=0}}for(let[e,t]of Object.entries(n??{})){let n=ye(t.type)?t.type:void 0;if(i[e]!==void 0){if(n?.kind===`array`){let t=a[e].join(` `);yield*Xe(n,i[e],e,(n,r)=>We(e,e,t,n,{issues:r}))}continue}if(t.default!==void 0)n&&(yield*Qe(t,e)),i[e]=Array.isArray(t.default)?[...t.default]:t.default;else if(n&&!n.isOptional)throw new De(`Missing required option '${e}'`,e,``,{kind:`missing-option`,detail:`a value is required`})}let l={_:o,__:s,options:i};return e.tokens&&(l.tokens=t),l}function Me(e){for(let[t,n]of Object.entries(e??{})){let e=n.type;if(typeof e==`object`&&e&&!ye(e))throw TypeError(`Option '${t}' has a type that is neither a type name nor a descriptor from t`);if(ye(e)&&n.multiple!==void 0)throw TypeError(`Option '${t}' cannot set 'multiple' with a descriptor: use t.array(element)`)}}function Ne(e,t){if(e.allowPositionals===!1)throw new De(`Unexpected positional argument '${t}'`,void 0,t,{kind:`unexpected-positional`})}function Pe(e){let t=/* @__PURE__ */ new Map;if(!e)return t;for(let n of Object.keys(e))t.set(n,n);for(let[n,r]of Object.entries(e)){let e=r.alias;for(let r of e===void 0?[]:Array.isArray(e)?e:[e]){let e=t.get(r);if(e!==void 0&&e!==n)throw Error(`Alias '${r}' of option '${n}' is already used by option '${e}'`);t.set(r,n)}}return t}function Fe(e){return e.kind===`array`?e.element:e}function Ie(e){if(!ye(e.type))return e.type!==`boolean`;let t=Fe(e.type);return!(t.kind===`boolean`||t.kind===`literal`&&typeof t.value==`boolean`)}function Le(e){if(!ye(e.type))return e.type===`number`;let t=Fe(e.type);return t.kind===`number`||t.kind===`int`||t.kind===`literal`&&typeof t.value==`number`}function Re(e,t){if(!e||!Ie(e))return;let n=t[0];if(n){if(n.kind===`positional`)return t.shift(),n.value;if(n.kind===`option`&&Le(e)&&Number.isFinite(Ve(n.raw)))return t.shift(),n.raw}}function ze(e,t,n,r){if(!e)return n??!0;switch(e.type){case`boolean`:return Ue(t,n,r);case`number`:return He(t,n,r);default:if(n===void 0)throw Be(t,`a value is required`,r,`missing-value`);return n}}function Be(e,t,n,r,i){return new De(`Invalid value for option '${e}': ${t} (from '${n.raw}')`,e,n.raw,{kind:r,value:i,detail:t})}function Ve(e){return e.trim()===``?NaN:Number(e)}function He(e,t,n){if(t===void 0)throw Be(e,`a number is required`,n,`missing-value`);let r=Ve(t);if(!Number.isFinite(r))throw Be(e,t,n,`invalid-value`,t);return r}function Ue(e,t,n){if(t===void 0)return!0;if(t===`false`||t===`f`||t===`0`)return!1;if(t===`true`||t===`t`)return!0;let r=Ve(t);if(!Number.isNaN(r))return r>0;throw Be(e,t,n,`invalid-value`,t)}function We(e,t,n,r,i,a=r){return new De(`Invalid value for option '${t}': ${a} (from '${n}')`,e,n,{...i,detail:r})}function*Ge(e,t,n){let r=(e,r,i)=>We(n.name,n.label,n.token.raw,e,{index:n.index,issues:r,value:t},i),i=yield*Je(e,t,n,r);return yield*Xe(e,i,n.label,r),i}function Ke(e){return`'${e}'`}function qe(e){switch(e.kind){case`string`:return`a string matching ${e.pattern}`;case`number`:case`int`:{let t=e.kind===`int`?`an integer`:`a number`;return e.min!==void 0&&e.max!==void 0?`${t} from ${e.min} to ${e.max}`:e.min===void 0?e.max===void 0?t:`${t} of at most ${e.max}`:`${t} of at least ${e.min}`}case`boolean`:return`no value, true or false`;case`literal`:return typeof e.value==`string`?Ke(e.value):String(e.value);case`enum`:return`one of ${e.values.map(Ke).join(`, `)}`}}function*Je(e,t,n,r){let i=e=>r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got ${Ke(t)}`);if(e.kind===`boolean`||e.kind===`literal`&&typeof e.value==`boolean`){let n=t===void 0||t===`true`||t!==`false`&&void 0;if(n===void 0||e.kind===`literal`&&n!==e.value)throw t===void 0?r(`expected ${qe(e)}`,void 0,`expected ${qe(e)}, got no value`):i(e);return n}if(t===void 0)throw We(n.name,n.label,n.token.raw,`a value is required`,{kind:`missing-value`,index:n.index});switch(e.kind){case`string`:if(e.pattern&&(e.pattern.lastIndex=0,!e.pattern.test(t)))throw i(e);return t;case`number`:case`int`:{let n=Ve(t);if(!Number.isFinite(n)||e.kind===`int`&&!Number.isInteger(n)||e.min!==void 0&&n<e.min||e.max!==void 0&&n>e.max)throw i(e);return n}case`literal`:{let n=typeof e.value==`number`?Ve(t):t;if(n!==e.value)throw i(e);return n}case`enum`:if(!e.values.includes(t))throw i(e);return t;case`custom`:try{return yield{value:e.convert(t),option:n.label}}catch(e){throw Ye(e,r)}case`json`:{let i;try{i=JSON.parse(t)}catch{throw r(`not valid JSON`,void 0,`${Ke(t)} is not valid JSON`)}if(!e.schema)return i;let a=yield{value:e.schema[`~standard`].validate(i),option:n.label};if(a.issues)throw r(`does not match the expected shape`,a.issues);return a.value}}}function Ye(e,t){return e instanceof Error&&e.constructor===Error?t(e.message):e}function*Xe(e,t,n,r){for(let i of e.checks)if(i.type===`fn`){let e=yield{value:i.fn(t),option:n};if(e===!1)throw r(`failed a check`);if(typeof e==`string`)throw r(e)}else{let e=yield{value:i.schema[`~standard`].validate(t),option:n};if(e.issues)throw r(`failed a check`,e.issues)}}const Ze=/* @__PURE__ */ new WeakMap;function*Qe(e,t){if(Ze.has(e))return;let n=e.type,r=e=>t=>/* @__PURE__ */ Error(`The default of option '${e}' failed a check${t===`failed a check`?``:`: ${t}`}`);if(n.kind===`array`){let i=e.default;for(let e=0;e<i.length;e++){let a=`${t}[${e}]`;yield*Xe(n.element,i[e],a,r(a))}}yield*Xe(n,e.default,t,r(t)),Ze.set(e,!0)}const $e=/* @__PURE__ */ new WeakMap;function et(e,t,n){let r=tt(e,nt(t,n)),[i,a]=rt(t,r,n);return ct(r,i,a)}function tt(e,t){if(e.commands){let n=e.commands,r=t.peek(e);for(let e=n.length-1;e>=0;e--){let i=n[e];if(!i.name)return i;if(r===i.name||i.alias?.includes(r))return t.consume(),i.commands?tt(i,t):i}}return e}function nt(e,t){let n=$e.get(e)??[],r,i=-1,a=0;return{peek(o){if(r=void 0,i<0){if(a<e._.length)return(r=[e._,a])[0][a];i=0,a=-1}for(;t&&i<n.length;){let e=n[i];if(a<0){let n=M(t,e.key)[1];if(!n)return;a=it(M(o,e.key)[1]??n,e)}if(a<e.following.length)return(r=[e.following,a])[0][a];i++,a=-1}},consume(){r[0].splice(r[1],1)}}}function rt(e,t,n){let r=$e.get(e);if(!r)return[e,void 0];let i={},a=[],o=[];for(let e of r){let r=M(t,e.key)[1],s=it(r??(n&&M(n,e.key)[1]),e),c=e.following.slice(0,s);r&&o.push({key:e.key,tokens:[e.raw,...c]}),a.push(...e.following.slice(s));let l=e.inline.length+c.length>0?[...e.inline,...c]:[`true`];i[e.key]=[...i[e.key]??[],...l]}let s={...e,_:[...e._,...a]};for(let t of Object.keys(i))e[t]&&(s[t]=i[t]);return[s,o]}function it(e,t){return e?t.inline.length===0&&ue(st(e))?1:0:t.following.length}const at=j.boolean().optional(),ot=j.string();function st(e){return e.type??at}function ct(e,t,n){return ft(dt(ut(lt({command:e,rawArgs:t,args:{_:[]},errors:[],descriptors:[]}))),n)}function lt(e){let t=e.command,n=[...e.rawArgs._],r=t.arguments||[];for(let t of r){let r=t.type??ot;if(n.length===0){r.isOptional||e.errors.push({type:`missing-argument`,name:t.name});continue}let i=r.kind===`array`?n.splice(0):[n.shift()];e.descriptors.push({type:`argument`,name:t.name,descriptor:r,values:i})}return n.length>0&&e.errors.push({type:`extra-arguments`,name:t.name,values:n}),e}function ut(e){for(let t of Object.keys(e.rawArgs)){if(t===`_`)continue;if(/^-/.test(t)){e.errors.push({type:`invalid-key`,key:t});continue}let[n,r]=M(e.command,t);if(!n){e.errors.push({type:`invalid-key`,key:t});continue}let i=st(r),a=e.rawArgs[t];i.kind!==`array`&&a.length>1&&e.errors.push({type:`expect-single`,key:t,keyKind:i.kind,value:a})}return e}function dt(e){let t=e.command.options;if(!t)return e;let n=/* @__PURE__ */ new Map;for(let t of Object.keys(e.rawArgs)){let[r]=M(e.command,t);r&&!n.has(r)&&n.set(r,t)}let r=[...n.keys()];for(let i=0;i<r.length;i++)for(let a=i+1;a<r.length;a++){let[o,s]=[r[i],r[a]];if(!t[o].conflicts?.includes(s)&&!t[s].conflicts?.includes(o))continue;let[c,l]=t[o].conflicts?.includes(s)?[o,s]:[s,o];e.errors.push({type:`conflicting-options`,key:n.get(c),conflictsWith:n.get(l)})}return e}function ft(e,t){let n=e.command.options??{};for(let r of Object.keys(n)){let i=n[r],a=Object.keys(e.rawArgs).filter(t=>t!==`_`&&M(e.command,t)[0]===r);e.errors.some(e=>e.type===`expect-single`&&a.includes(e.key))||e.descriptors.push({type:`option`,name:r,entry:{...i,type:st(i)},occurrences:t?t.filter(e=>a.includes(e.key)):a.flatMap(t=>e.rawArgs[t].map(e=>({key:t,tokens:[`--${r}=${e}`]})))})}return e}function M(e,t){let n=e.options;if(!n)return[];let r=n[t];if(r)return[t,r];let i=Object.keys(n).find(e=>{let r=n[e];return r.alias?r.alias.some(e=>e===t||e.alias===t):!1});return i?[i,n[i]]:[]}const pt={comma:`,`,tab:` `,pipe:`|`},mt=pt.comma;function ht(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`).replace(/[\u0000-\u001F]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}function gt(e){return e===`true`||e===`false`||e===`null`}function _t(e,t,n){if(t===`__proto__`){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0});return}e[t]=n}const vt=/* @__PURE__ */ RegExp(`(?:^?|\\n) *#`);var yt=class{constructor(e){if(vt.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function bt(e){return e instanceof yt}const xt=/[\uD800-\uDFFF]/;function St(e){if(e===null)return null;if(bt(e))return e;if(typeof e==`object`&&e&&`toJSON`in e&&typeof e.toJSON==`function`){let t=e.toJSON();if(t!==e)return St(t)}if(typeof e==`string`)return Ct(e,`string value`),e;if(typeof e==`boolean`)return e;if(typeof e==`number`)return Object.is(e,-0)?0:Number.isFinite(e)?e:null;if(typeof e==`bigint`)return e>=-(2**53-1)&&e<=2**53-1?Number(e):e.toString();if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(St);if(e instanceof Set)return Array.from(e).map(St);if(e instanceof Map)return Object.fromEntries(Array.from(e,([e,t])=>[String(e),St(t)]));if(Ot(e)){let t={};for(let n in e)Object.hasOwn(e,n)&&(Ct(n,`object key`),_t(t,n,St(e[n])));return t}return null}function Ct(e,t){if(xt.test(e))for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r<55296||r>57343)continue;let i=r<=56319,a=e.charCodeAt(n+1);if(i&&a>=56320&&a<=57343){n++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${r.toString(16).toUpperCase()} at index ${n}`)}}function wt(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`}function Tt(e){return wt(e)||bt(e)}function Et(e){return Array.isArray(e)}function N(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!bt(e)}function Dt(e){return Object.keys(e).length===0}function Ot(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function kt(e){return e.length===0||e.every(e=>Tt(e))}function At(e){return e.length===0||e.every(e=>Et(e))}function jt(e){return e.length===0||e.every(e=>N(e))}const Mt=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Nt(e){if(!Object.values(pt).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Pt(e){return/^[A-Z_][\w.]*$/i.test(e)}function Ft(e,t=mt){return!(!e||/^[ \t]|[ \t]$/.test(e)||gt(e)||It(e)||e.includes(`:`)||e.includes(`"`)||e.includes(`\\`)||/[[\]{}]/.test(e)||/[\u0000-\u001F]/.test(e)||e.includes(t)||e.startsWith(`-`)||e.startsWith(`#`))}function It(e){return Mt.test(e)}function Lt(e,t){return bt(e)?e.value:e===null?`null`:typeof e==`boolean`||typeof e==`number`?String(e):Rt(e,t)}function Rt(e,t=mt){return Ft(e,t)?e:`"${ht(e)}"`}function zt(e){return Pt(e)?e:`"${ht(e)}"`}function Bt(e,t=mt){return e.map(e=>Lt(e,t)).join(t)}function P(e,t){let n=t?.key,r=t?.fields,i=t?.delimiter??`,`,a=``;return n!=null&&(a+=zt(n)),a+=`[${e}${t?.keyed?`:`:``}${i===mt?``:i}]`,r&&(a+=`{${Vt(r,i)}}`),a+=`:`,a}function Vt(e,t){return e.map(e=>zt(e.name)+(e.children?`{${Vt(e.children,t)}}`:``)).join(t)}function Ht(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let e of t)if(!Object.hasOwn(n,e))return}let n=[];for(let r of t){let t=Gt(r,e.map(e=>e[r]));if(!t)return;n.push(t)}return n}function Ut(e){let t=Object.values(e);if(!(t.length<2)&&t.every(e=>N(e)&&!Dt(e)))return Ht(t)}function Wt(e,t){let n=[];return Kt(e,t,n),n}function Gt(e,t){if(t.every(e=>Tt(e)))return{name:e};if(!t.every(e=>N(e)&&!Dt(e)))return;let n=Ht(t);if(n)return{name:e,children:n}}function Kt(e,t,n){for(let r of t){let t=e[r.name];r.children?Kt(t,r.children,n):n.push(t)}}function*qt(e,t,n){if(Tt(e)){let n=Lt(e,t.delimiter);n!==``&&(yield n);return}if(Et(e))yield*Qt(void 0,e,n,t);else if(N(e)){let r=Ut(e);if(r){yield*Xt(void 0,e,r,n,t);return}yield*Jt(e,n,t)}}function*Jt(e,t,n){for(let[r,i]of Object.entries(e))yield*Yt(r,i,t,n)}function*Yt(e,t,n,r){let i=zt(e);if(Tt(t))yield F(n,`${i}: ${Lt(t,r.delimiter)}`,r.indentSize);else if(Et(t))yield*Qt(e,t,n,r);else if(N(t)){let a=Ut(t);if(a){yield*Xt(e,t,a,n,r);return}yield F(n,`${i}:`,r.indentSize),Dt(t)||(yield*Jt(t,n+1,r))}}function*Xt(e,t,n,r,i){let a=Object.entries(t);yield F(r,P(a.length,{key:e,fields:n,delimiter:i.delimiter,keyed:!0}),i.indentSize),yield*Zt(a,n,r+1,i)}function*Zt(e,t,n,r){for(let[i,a]of e){let e=Wt(a,t);yield F(n,`${zt(i)}: ${Bt(e,r.delimiter)}`,r.indentSize)}}function*Qt(e,t,n,r){if(t.length===0){yield F(n,e==null?`[]`:`${zt(e)}: []`,r.indentSize);return}if(kt(t)){yield F(n,en(t,r.delimiter,e),r.indentSize);return}if(At(t)&&t.every(e=>kt(e))){yield*$t(e,t,n,r);return}if(jt(t)){let i=Ht(t);i?yield*tn(e,t,i,n,r):yield*rn(e,t,n,r);return}yield*rn(e,t,n,r)}function*$t(e,t,n,r){yield F(n,P(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)if(kt(e)){let t=en(e,r.delimiter);yield I(n+1,t,r.indentSize)}}function en(e,t,n){let r=P(e.length,{key:n,delimiter:t}),i=Bt(e,t);return e.length===0?r:`${r} ${i}`}function*tn(e,t,n,r,i){yield F(r,P(t.length,{key:e,fields:n,delimiter:i.delimiter}),i.indentSize),yield*nn(t,n,r+1,i)}function*nn(e,t,n,r){for(let i of e)yield F(n,Bt(Wt(i,t),r.delimiter),r.indentSize)}function*rn(e,t,n,r){yield F(n,P(t.length,{key:e,delimiter:r.delimiter}),r.indentSize);for(let e of t)yield*on(e,n+1,r)}function*an(e,t,n){if(Dt(e)){yield F(t,`-`,n.indentSize);return}let r=Object.entries(e),[i,a]=r[0],o=r.slice(1);if(Et(a)&&jt(a)){let e=Ht(a);if(e){yield I(t,P(a.length,{key:i,fields:e,delimiter:n.delimiter}),n.indentSize),yield*nn(a,e,t+2,n),o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n));return}}if(N(a)){let e=Ut(a);if(e){let r=Object.entries(a);yield I(t,P(r.length,{key:i,fields:e,delimiter:n.delimiter,keyed:!0}),n.indentSize),yield*Zt(r,e,t+2,n),o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n));return}}let s=zt(i);if(Tt(a))yield I(t,`${s}: ${Lt(a,n.delimiter)}`,n.indentSize);else if(Et(a)){if(a.length===0)yield I(t,`${s}: []`,n.indentSize);else if(kt(a))yield I(t,`${s}${en(a,n.delimiter)}`,n.indentSize);else{yield I(t,`${s}${P(a.length,{delimiter:n.delimiter})}`,n.indentSize);for(let e of a)yield*on(e,t+2,n)}}else N(a)&&(yield I(t,`${s}:`,n.indentSize),Dt(a)||(yield*Jt(a,t+2,n)));o.length>0&&(yield*Jt(Object.fromEntries(o),t+1,n))}function*on(e,t,n){if(Tt(e))yield I(t,Lt(e,n.delimiter),n.indentSize);else if(Et(e)){if(kt(e))yield I(t,en(e,n.delimiter),n.indentSize);else{yield I(t,P(e.length,{delimiter:n.delimiter}),n.indentSize);for(let r of e)yield*on(r,t+1,n)}}else N(e)&&(yield*an(e,t,n))}function F(e,t,n){return` `.repeat(n*e)+t}function I(e,t,n){return F(e,`- `+t,n)}function sn(e,t){let n=t(``,e,[]);return n===void 0?ln(e,t,[]):cn(e,n,t,[])}function cn(e,t,n,r){return bt(t)&&!Tt(e)?ln(e,n,r):ln(St(t),n,r)}function ln(e,t,n){return N(e)?un(e,t,n):Et(e)?dn(e,t,n):e}function un(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=[...n,i],o=t(i,a,e);o!==void 0&&_t(r,i,cn(a,o,t,e))}return r}function dn(e,t,n){let r=[];for(let i=0;i<e.length;i++){let a=e[i],o=[...n,i],s=t(String(i),a,o);s!==void 0&&r.push(cn(a,s,t,o))}return r}function fn(e,t){return Array.from(pn(e,t)).join(`
4
4
  `)}function pn(e,t){let n=St(e),r=mn(t);return qt(r.replacer?sn(n,r.replacer):n,r,0)}function mn(e){let t=e?.delimiter??mt;return Nt(t),{indentSize:e?.indentSize??e?.indent??2,delimiter:t,replacer:e?.replacer}}function hn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gn(e){return e===void 0?``:String(e)}function _n(e){let t=[...new Set(e.flatMap(e=>Object.keys(e)))],n=t.map(t=>Math.max(t.length,...e.map(e=>gn(e[t]).length))),r=e=>` ${e.map((e,t)=>e.padEnd(n[t])).join(` `)}`.trimEnd();return[r(t),...e.map(e=>r(t.map(t=>gn(e[t]))))]}function vn(e){let t=Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>{if(!Array.isArray(t))return[`${e}: ${hn(t)?JSON.stringify(t):String(t)}`];if(!t.length)return[`${e}: (none)`];let n=t.every(hn)?_n(t):t.map(e=>` - ${String(e)}`);return[`${e}:`,...n]});return t.flatMap((e,n)=>{let r=t[n-1];return r&&(r.length>1||e.length>1)?[``,...e]:e}).join(`
5
5
  `)}const yn=[`toon`,`json`,`text`];function L(e,t){return t===`json`?JSON.stringify(e):t===`text`?vn(e):fn(e)}function bn({message:e,code:t,details:n,help:r}){let i={error:e,code:t,...n};return r&&r.length>0&&(i.help=[...r]),i}const xn=Symbol.for(`clibuilder.global-format`),Sn=Symbol.for(`clibuilder.defers-to-global-format`);function Cn(e,t){return k({name:``,description:e,options:{help:{type:j.boolean().optional(),description:`Print help message`,alias:[`h`]},version:{type:j.boolean().optional(),description:`Print the CLI version`,alias:[`v`]},verbose:{type:j.boolean().optional(),description:`Turn on verbose logging`,alias:[`V`]},silent:{type:j.boolean().optional(),description:`Turn off logging`},"debug-cli":{type:j.boolean().optional(),description:`Display clibuilder debug messages`},...t?.options,format:wn(t?.format??`toon`)},commands:[]})}function wn(e){return Object.defineProperty({type:j.enum(yn),description:`Output format: 'toon' for agents, 'json' to pipe, 'text' for humans`,default:e},xn,{value:!0})}function Tn(e){return!!e&&e[xn]===!0}function En(e){let[t,n]=M(e,`format`);if(!t||Tn(n))return e;if(!n[Sn]){let n=e.name?`command '${e.name}'`:`the default command`;throw Error(`${n} declares its own option '${t}', which conflicts with the global --format option. Delete the local declaration and read this.format in run() instead. See docs/rfcs/axi-native.md section 3.4: https://github.com/clibuilder/clibuilder/blob/main/docs/rfcs/axi-native.md#34---format-is-not-first-class-6394`)}let{[t]:r,...i}=e.options;return{...e,options:i}}function Dn(e){return{id:e,kind:`value`}}function On(){let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map;function n(n){return n.kind===`collection`?t.get(n.id)??[]:e.get(n.id)?.value}return{register(n,r,i){if(r.kind===`collection`){let e=t.get(r.id)??[];return e.push({source:n,value:i}),t.set(r.id,e),{accepted:!0}}let a=e.get(r.id);return a?{accepted:!1,source:a.source}:(e.set(r.id,{source:n,value:i}),{accepted:!0})},get:n,has(n){return n.kind===`collection`?t.has(n.id):e.has(n.id)},describe(n){if(n.kind===`collection`)return(t.get(n.id)??[]).map(({source:e})=>e);let r=e.get(n.id)?.source;return r?[r]:[]}}}const kn=Dn(`clibuilder.config`);function An(e){let t=[],n=e.slice(2).reduce((e,n)=>(e.args.__?e.args.__.push(n):Mn(n)?(jn(e)&&(e=Ln(e)),e=Nn(e,n,t)):jn(e)?(e.values.push(n),t[t.length-1].following.push(n)):n===`--`?e.args.__=[]:e.args._.push(n),e),{args:{_:[]},key:``,values:[]}),r=(jn(n)?Ln(n):n).args;return $e.set(r,t),r}function jn(e){return!!e.key}function Mn(e){return e.startsWith(`-`)&&/\w+/.test(e)}function Nn(e,t,n){return e=/^-\w+/.test(t)?Pn(e,t,n):In(e,t),n.push({key:e.key,raw:t,inline:[...e.values],following:[]}),e}function Pn(e,t,n){let r=t.indexOf(`=`),[i,a]=r>0?[t.slice(1,r),[t.slice(r+1)]]:[t.slice(1),[]],o=i.split(``),s=o.pop();for(let e of o)n.push({key:e,raw:t,inline:[`true`],following:[]});return e=Fn(e,o),e.key=s,e.values=a,e}function Fn(e,t){return t.length<=0?e:(e.key=t.pop(),e.values=[`true`],Fn(Ln(e),t))}function In(e,t){let n=t.indexOf(`=`);return n>0?(e.key=t.slice(2,n),e.values=[t.slice(n+1)]):(e.key=t.slice(2),e.values=[]),e}function Ln(e){let{key:t,values:n}=e,r={...e.args};return r[t]||(r[t]=[]),n.length===0?r[t].push(`true`):r[t].push(...n),{args:r,key:``,values:[]}}const Rn=/* @__PURE__ */ new WeakMap;async function zn(e){for(let t of e.descriptors)try{Un(e,t,await ke(Hn(t)))}catch(n){Wn(e,t,n)}}function Bn(e){for(let t of e.descriptors)try{Un(e,t,Oe(Hn(t)))}catch(n){Wn(e,t,n)}}function Vn(e,t){let n={...e,args:{...e.args},errors:[],descriptors:e.descriptors.filter(e=>e.type===`option`&&t.includes(e.name)&&e.entry.type.kind===`boolean`&&e.entry.type.checks.length===0)};return Bn(n),n.args}function Hn(e){return e.type===`option`?{args:e.occurrences.flatMap(e=>e.tokens),options:{[e.name]:Gn(e.entry)}}:{args:e.values.map(t=>`--${e.name}=${t}`),options:{[e.name]:{type:e.descriptor}}}}function Un(e,t,{options:n}){n[t.name]!==void 0&&(e.args[t.name]=n[t.name])}function Wn(e,t,n){if(!(n instanceof De))throw n;e.errors.push(Kn(n,t))}function Gn(e){let t=Rn.get(e);if(!t){let n=e.alias?.map(e=>typeof e==`string`?e:e.alias);t={type:e.type,...n?{alias:n}:{},...e.default===void 0?{}:{default:e.default}},Rn.set(e,t)}return t}function Kn(e,t){if(e.kind===`missing-option`)return{type:`missing-argument`,name:t.name};let n=t.type===`option`?t.entry.type:t.descriptor,r=n.kind===`array`?n.element:n;return{type:`invalid-value`,key:qn(e,t),message:e.detail,value:e.value??(e.kind===`invalid-value`?Jn(t):void 0),keyKind:n.kind,constraint:de(r),...r.kind===`enum`?{allowed:r.values}:{},...e.index===void 0?{}:{index:e.index}}}function qn(e,t){if(t.type===`argument`)return t.name;let n=t.occurrences;return(e.index===void 0?n[n.length-1]:n[e.index])?.key??t.name}function Jn(e){return e.type===`argument`?e.values:e.occurrences.map(e=>e.tokens.join(` `))}const Yn=Symbol.for(`clibuilder.answer`);function R(e,t={}){return{[Yn]:`result`,value:e,help:ir(t.help),render:t.render}}function Xn(e){return{[Yn]:`document`,value:String(e)}}function Zn(e){return typeof e==`object`&&!!e&&typeof e[Yn]==`string`}function Qn(e){return Zn(e)?e.value:e}function $n(e,t){if(e!==void 0){if(!Zn(e))return er(e,[],t);switch(e[Yn]){case`written`:return;case`document`:return ar(e.value);case`empty`:return ar(L(rr({empty:e.value},e.help),t));case`result`:{let n=e.render?.[t];return n?tr(n(e.value),e.help,t):er(e.value,e.help,t)}}}}function er(e,t,n){return typeof e==`string`?tr(e,t,n):ar(L(rr(nr(e),t),n))}function tr(e,t,n){return t.length===0?ar(e):ar(`${e}${e.endsWith(`
6
6
  `)?`