poe-code 3.0.181 → 3.0.182

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 (117) hide show
  1. package/dist/cli/commands/config.js +3 -4
  2. package/dist/cli/commands/config.js.map +1 -1
  3. package/dist/cli/commands/configure.js +12 -3
  4. package/dist/cli/commands/configure.js.map +1 -1
  5. package/dist/cli/commands/dashboard-loop-shared.d.ts +7 -0
  6. package/dist/cli/commands/dashboard-loop-shared.js +15 -0
  7. package/dist/cli/commands/dashboard-loop-shared.js.map +1 -1
  8. package/dist/cli/commands/experiment.js +41 -32
  9. package/dist/cli/commands/experiment.js.map +1 -1
  10. package/dist/cli/commands/mcp.js +7 -2
  11. package/dist/cli/commands/mcp.js.map +1 -1
  12. package/dist/cli/commands/pipeline.js +55 -44
  13. package/dist/cli/commands/pipeline.js.map +1 -1
  14. package/dist/cli/commands/plan.js +195 -38
  15. package/dist/cli/commands/plan.js.map +1 -1
  16. package/dist/cli/commands/ralph.js +24 -24
  17. package/dist/cli/commands/ralph.js.map +1 -1
  18. package/dist/cli/commands/shared.d.ts +3 -0
  19. package/dist/cli/commands/shared.js +27 -1
  20. package/dist/cli/commands/shared.js.map +1 -1
  21. package/dist/cli/commands/skill.js +21 -10
  22. package/dist/cli/commands/skill.js.map +1 -1
  23. package/dist/cli/commands/spawn-poe-agent.d.ts +2 -0
  24. package/dist/cli/commands/spawn-poe-agent.js +47 -0
  25. package/dist/cli/commands/spawn-poe-agent.js.map +1 -0
  26. package/dist/cli/commands/spawn.js +21 -1
  27. package/dist/cli/commands/spawn.js.map +1 -1
  28. package/dist/cli/commands/utils-symlink-agents.d.ts +6 -0
  29. package/dist/cli/commands/utils-symlink-agents.js +78 -0
  30. package/dist/cli/commands/utils-symlink-agents.js.map +1 -0
  31. package/dist/cli/commands/utils-symlink-ops.d.ts +29 -0
  32. package/dist/cli/commands/utils-symlink-ops.js +76 -0
  33. package/dist/cli/commands/utils-symlink-ops.js.map +1 -0
  34. package/dist/cli/commands/utils-symlink-skills.d.ts +15 -0
  35. package/dist/cli/commands/utils-symlink-skills.js +136 -0
  36. package/dist/cli/commands/utils-symlink-skills.js.map +1 -0
  37. package/dist/cli/commands/utils-symlink.d.ts +3 -0
  38. package/dist/cli/commands/utils-symlink.js +40 -0
  39. package/dist/cli/commands/utils-symlink.js.map +1 -0
  40. package/dist/cli/commands/utils.js +2 -0
  41. package/dist/cli/commands/utils.js.map +1 -1
  42. package/dist/cli/constants.d.ts +2 -2
  43. package/dist/cli/constants.js +1 -1
  44. package/dist/cli/constants.js.map +1 -1
  45. package/dist/cli/program.js +8 -1
  46. package/dist/cli/program.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +23269 -18158
  49. package/dist/index.js.map +4 -4
  50. package/dist/plan/document-schema.d.ts +21 -0
  51. package/dist/plan/document-schema.js +16 -0
  52. package/dist/plan/document-schema.js.map +1 -0
  53. package/dist/providers/claude-code.js +31 -13
  54. package/dist/providers/claude-code.js.map +4 -4
  55. package/dist/providers/codex.js +31 -13
  56. package/dist/providers/codex.js.map +4 -4
  57. package/dist/providers/goose.js +32 -14
  58. package/dist/providers/goose.js.map +4 -4
  59. package/dist/providers/kimi.js +31 -13
  60. package/dist/providers/kimi.js.map +4 -4
  61. package/dist/providers/opencode.js +32 -14
  62. package/dist/providers/opencode.js.map +4 -4
  63. package/dist/providers/poe-agent.d.ts +5 -0
  64. package/dist/providers/poe-agent.js +19812 -4438
  65. package/dist/providers/poe-agent.js.map +4 -4
  66. package/dist/sdk/container.js +4 -0
  67. package/dist/sdk/container.js.map +1 -1
  68. package/dist/sdk/spawn.js +8 -2
  69. package/dist/sdk/spawn.js.map +1 -1
  70. package/dist/sdk/types.d.ts +5 -1
  71. package/dist/services/config.d.ts +29 -44
  72. package/dist/services/config.js +16 -25
  73. package/dist/services/config.js.map +1 -1
  74. package/dist/templates/pipeline/SKILL_plan.md +22 -8
  75. package/dist/templates/pipeline/steps.yaml.mustache +1 -1
  76. package/dist/templates/skill/poe-generate.md +47 -0
  77. package/dist/templates/skill/terminal-pilot.md +45 -0
  78. package/dist/utils/dry-run.d.ts +8 -0
  79. package/dist/utils/dry-run.js +16 -0
  80. package/dist/utils/dry-run.js.map +1 -1
  81. package/dist/utils/file-system.d.ts +4 -0
  82. package/package.json +16 -9
  83. package/packages/cmdkit/dist/cli.js +42 -22
  84. package/packages/cmdkit/dist/cli.js.map +3 -3
  85. package/packages/cmdkit/dist/index.js +52 -9
  86. package/packages/cmdkit/dist/index.js.map +2 -2
  87. package/packages/cmdkit/dist/mcp.d.ts +15 -0
  88. package/packages/cmdkit/dist/mcp.js +121 -20
  89. package/packages/cmdkit/dist/mcp.js.map +3 -3
  90. package/packages/cmdkit/dist/number-schema.d.ts +3 -0
  91. package/packages/cmdkit/dist/number-schema.js +8 -0
  92. package/packages/cmdkit/dist/schema-scope.d.ts +4 -0
  93. package/packages/cmdkit/dist/schema-scope.js +34 -0
  94. package/packages/cmdkit/dist/sdk.js +58 -3
  95. package/packages/cmdkit/dist/sdk.js.map +3 -3
  96. package/packages/cmdkit-schema/dist/index.compile-check.js +1 -0
  97. package/packages/cmdkit-schema/dist/index.d.ts +59 -16
  98. package/packages/cmdkit-schema/dist/index.js +53 -8
  99. package/packages/design-system/dist/dashboard/components/footer.js +2 -3
  100. package/packages/design-system/dist/dashboard/components/output-pane.d.ts +1 -10
  101. package/packages/design-system/dist/dashboard/components/output-pane.js +5 -74
  102. package/packages/design-system/dist/dashboard/dashboard.js +6 -26
  103. package/packages/design-system/dist/dashboard/keymap.js +4 -19
  104. package/packages/design-system/dist/dashboard/snapshot.js +1 -5
  105. package/packages/design-system/dist/dashboard/store.d.ts +1 -2
  106. package/packages/design-system/dist/dashboard/store.js +6 -62
  107. package/packages/design-system/dist/dashboard/terminal.d.ts +2 -0
  108. package/packages/design-system/dist/dashboard/terminal.js +18 -0
  109. package/packages/design-system/dist/dashboard/types.d.ts +1 -11
  110. package/packages/design-system/dist/terminal-markdown/ast.d.ts +10 -2
  111. package/packages/design-system/dist/terminal-markdown/parser/block.d.ts +2 -1
  112. package/packages/design-system/dist/terminal-markdown/parser/block.js +400 -110
  113. package/packages/design-system/dist/terminal-markdown/parser/frontmatter.d.ts +2 -0
  114. package/packages/design-system/dist/terminal-markdown/parser/frontmatter.js +28 -11
  115. package/packages/design-system/dist/terminal-markdown/parser/inline.d.ts +4 -0
  116. package/packages/design-system/dist/terminal-markdown/parser/inline.js +134 -55
  117. package/packages/design-system/dist/terminal-markdown/parser.js +36 -7
@@ -9,8 +9,50 @@ function withMetadata(schema, jsonSchema) {
9
9
  if (schema.default !== void 0) {
10
10
  jsonSchema.default = schema.default;
11
11
  }
12
+ if (schema.nullable === true) {
13
+ jsonSchema.nullable = true;
14
+ }
12
15
  return jsonSchema;
13
16
  }
17
+ function withStringMetadata(schema, jsonSchema) {
18
+ if (schema.minLength !== void 0) {
19
+ jsonSchema.minLength = schema.minLength;
20
+ }
21
+ if (schema.maxLength !== void 0) {
22
+ jsonSchema.maxLength = schema.maxLength;
23
+ }
24
+ if (schema.pattern !== void 0) {
25
+ jsonSchema.pattern = schema.pattern;
26
+ }
27
+ if (schema.format !== void 0) {
28
+ jsonSchema.format = schema.format;
29
+ }
30
+ return withMetadata(schema, jsonSchema);
31
+ }
32
+ function withNumberMetadata(schema, jsonSchema) {
33
+ if (schema.minimum !== void 0) {
34
+ jsonSchema.minimum = schema.minimum;
35
+ }
36
+ if (schema.maximum !== void 0) {
37
+ jsonSchema.maximum = schema.maximum;
38
+ }
39
+ return withMetadata(schema, jsonSchema);
40
+ }
41
+ function withArrayMetadata(schema, jsonSchema) {
42
+ if (schema.minItems !== void 0) {
43
+ jsonSchema.minItems = schema.minItems;
44
+ }
45
+ if (schema.maxItems !== void 0) {
46
+ jsonSchema.maxItems = schema.maxItems;
47
+ }
48
+ return withMetadata(schema, jsonSchema);
49
+ }
50
+ function withObjectMetadata(schema, jsonSchema) {
51
+ if (schema.additionalProperties !== void 0) {
52
+ jsonSchema.additionalProperties = schema.additionalProperties;
53
+ }
54
+ return withMetadata(schema, jsonSchema);
55
+ }
14
56
  function getEnumJsonType(values) {
15
57
  const [firstValue] = values;
16
58
  if (firstValue === void 0) {
@@ -78,10 +120,11 @@ var S = {
78
120
  ...options
79
121
  };
80
122
  },
81
- Object(shape) {
123
+ Object(shape, options = {}) {
82
124
  return {
83
125
  kind: "object",
84
- shape
126
+ shape,
127
+ ...options
85
128
  };
86
129
  },
87
130
  Optional(inner) {
@@ -95,23 +138,23 @@ function toJsonSchema(schema) {
95
138
  const unwrappedSchema = unwrapOptional(schema);
96
139
  switch (unwrappedSchema.kind) {
97
140
  case "string":
98
- return withMetadata(unwrappedSchema, { type: "string" });
141
+ return withStringMetadata(unwrappedSchema, { type: "string" });
99
142
  case "number":
100
- return withMetadata(unwrappedSchema, { type: "number" });
143
+ return withNumberMetadata(unwrappedSchema, { type: unwrappedSchema.jsonType ?? "number" });
101
144
  case "boolean":
102
145
  return withMetadata(unwrappedSchema, { type: "boolean" });
103
146
  case "enum": {
104
147
  const jsonSchema = {
105
- enum: [...unwrappedSchema.values]
148
+ enum: unwrappedSchema.nullable === true ? [...unwrappedSchema.values, null] : [...unwrappedSchema.values]
106
149
  };
107
- const enumType = getEnumJsonType(unwrappedSchema.values);
150
+ const enumType = unwrappedSchema.jsonType ?? getEnumJsonType(unwrappedSchema.values);
108
151
  if (enumType !== void 0) {
109
152
  jsonSchema.type = enumType;
110
153
  }
111
154
  return withMetadata(unwrappedSchema, jsonSchema);
112
155
  }
113
156
  case "array":
114
- return withMetadata(unwrappedSchema, {
157
+ return withArrayMetadata(unwrappedSchema, {
115
158
  type: "array",
116
159
  items: toJsonSchema(unwrappedSchema.item)
117
160
  });
@@ -124,11 +167,11 @@ function toJsonSchema(schema) {
124
167
  required.push(key);
125
168
  }
126
169
  }
127
- return {
170
+ return withObjectMetadata(unwrappedSchema, {
128
171
  type: "object",
129
172
  properties,
130
173
  required
131
- };
174
+ });
132
175
  }
133
176
  }
134
177
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../../cmdkit-schema/src/index.ts"],
4
- "sourcesContent": ["import { fileURLToPath } from \"node:url\";\nimport type { ObjectSchema, Static } from \"@poe-code/cmdkit-schema\";\nimport type { LoggerOutput, RenderTableOptions, ThemePalette } from \"@poe-code/design-system\";\n\nconst commandConfigSymbol = Symbol(\"cmdkit.command.config\");\nconst groupConfigSymbol = Symbol(\"cmdkit.group.config\");\nconst commandSourcePathSymbol = Symbol(\"cmdkit.command.sourcePath\");\n\ntype ScopeValue = \"cli\" | \"mcp\" | \"sdk\";\ntype AnyObjectSchema = ObjectSchema<Record<string, never>>;\ntype EmptyServices = Record<string, never>;\ntype ScopeInput = readonly Scope[] | undefined;\n\nexport type Scope = ScopeValue;\n\nexport interface SecretDefinition {\n env: string;\n description?: string;\n optional?: boolean;\n}\n\nexport type SecretDeclarations = Record<string, SecretDefinition>;\n\ntype OptionalSecretKeys<TSecrets extends SecretDeclarations> = {\n [TKey in keyof TSecrets]: TSecrets[TKey] extends { optional: true } ? TKey : never;\n}[keyof TSecrets];\n\ntype RequiredSecretKeys<TSecrets extends SecretDeclarations> = Exclude<\n keyof TSecrets,\n OptionalSecretKeys<TSecrets>\n>;\n\nexport type InferSecrets<TSecrets extends SecretDeclarations | undefined> =\n TSecrets extends SecretDeclarations\n ? { [TKey in RequiredSecretKeys<TSecrets>]: string } & {\n [TKey in OptionalSecretKeys<TSecrets>]?: string;\n }\n : Record<string, never>;\n\nexport interface HandlerFs {\n readFile(path: string, encoding?: BufferEncoding): Promise<string>;\n writeFile(path: string, contents: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n}\n\nexport interface HandlerEnv {\n get(key: string): string | undefined;\n}\n\nexport interface RenderPrimitives {\n logger: LoggerOutput;\n renderTable(options: RenderTableOptions): string;\n getTheme(): ThemePalette;\n note(message: string, title?: string): void;\n}\n\nexport interface CheckResult {\n ok: boolean;\n message?: string;\n}\n\nexport type GroupCheckContext<TServices extends object = EmptyServices> = TServices & {\n params?: unknown;\n secrets?: Record<string, string | undefined>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport type CommandCheckContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params?: Static<TParamsSchema>;\n secrets?: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface Requires<TContext = unknown> {\n auth?: boolean;\n apiVersion?: string;\n check?: (ctx: TContext) => Promise<CheckResult>;\n}\n\nexport interface Renderers<TResult> {\n rich?: (result: TResult, primitives: RenderPrimitives) => void;\n markdown?: (result: TResult, primitives: RenderPrimitives) => string;\n json?: (result: TResult, primitives: RenderPrimitives) => unknown;\n}\n\nexport type HandlerContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params: Static<TParamsSchema>;\n secrets: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface CommandConfig<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n> {\n name: string;\n description?: string;\n aliases?: string[];\n positional?: string[];\n params: TParamsSchema;\n secrets?: TSecrets;\n scope?: Scope[];\n confirm?: boolean;\n requires?: Requires<CommandCheckContext<TParamsSchema, TSecrets, TServices>>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface Command<\n TServices extends object = EmptyServices,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n> {\n kind: \"command\";\n name: string;\n description?: string;\n aliases: string[];\n positional: string[];\n params: TParamsSchema;\n secrets: SecretDeclarations;\n scope: Scope[];\n confirm: boolean;\n requires?: Requires<any>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface GroupConfig<TServices extends object> {\n name: string;\n description?: string;\n aliases?: string[];\n scope?: Scope[];\n secrets?: SecretDeclarations;\n requires?: Requires<GroupCheckContext<TServices>>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport interface Group<TServices extends object = EmptyServices> {\n kind: \"group\";\n name: string;\n description?: string;\n aliases: string[];\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport type CommandNode<TServices extends object = EmptyServices> =\n | Command<TServices, any, any, any>\n | Group<TServices>;\n\nexport interface CommandTypeInfo<\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TResult = unknown,\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n params: TParamsSchema;\n result: TResult;\n ownScope: TOwnScope;\n}\n\nexport interface GroupTypeInfo<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n children: TChildren;\n ownScope: TOwnScope;\n}\n\ntype TypedCommandMetadata<\n TName extends string,\n TParamsSchema extends ObjectSchema<any>,\n TResult,\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitCommandTypeInfo: CommandTypeInfo<TName, TParamsSchema, TResult, TOwnScope>;\n};\n\ntype TypedGroupMetadata<\n TServices extends object,\n TName extends string,\n TChildren extends readonly unknown[],\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitGroupTypeInfo: GroupTypeInfo<TServices, TName, TChildren, TOwnScope>;\n};\n\ninterface InternalCommandConfig {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n sourcePath?: string;\n}\n\ninterface InternalGroupConfig<TServices extends object> {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\ninterface InheritedMetadata {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n}\n\nexport class UserError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"UserError\";\n }\n}\n\nexport interface CommandRequirementOptions {\n apiVersion?: string;\n authEnvVar?: string;\n env?: Record<string, string | undefined>;\n}\n\nfunction cloneScope(scope: Scope[] | undefined): Scope[] | undefined {\n return scope === undefined ? undefined : [...scope];\n}\n\nfunction cloneSecretDefinition(secret: SecretDefinition): SecretDefinition {\n return {\n env: secret.env,\n description: secret.description,\n optional: secret.optional,\n };\n}\n\nfunction cloneSecrets(secrets: SecretDeclarations | undefined): SecretDeclarations {\n if (secrets === undefined) {\n return {};\n }\n\n return Object.fromEntries(\n Object.entries(secrets).map(([key, secret]) => [key, cloneSecretDefinition(secret)])\n );\n}\n\nfunction cloneRequires<TContext>(requires: Requires<TContext> | undefined): Requires<TContext> | undefined {\n if (requires === undefined) {\n return undefined;\n }\n\n return {\n auth: requires.auth,\n apiVersion: requires.apiVersion,\n check: requires.check,\n };\n}\n\nfunction parseStackPath(candidate: string): string | undefined {\n if (candidate.startsWith(\"file://\")) {\n try {\n return fileURLToPath(candidate);\n } catch {\n return undefined;\n }\n }\n\n if (candidate.startsWith(\"/\")) {\n return candidate;\n }\n\n return undefined;\n}\n\nfunction extractStackPath(line: string): string | undefined {\n const trimmed = line.trim();\n const fileIndex = trimmed.indexOf(\"file://\");\n\n if (fileIndex >= 0) {\n const location = trimmed.slice(fileIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n }\n\n const slashIndex = trimmed.indexOf(\"/\");\n if (slashIndex < 0) {\n return undefined;\n }\n\n const location = trimmed.slice(slashIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n}\n\nfunction inferCommandSourcePath(): string | undefined {\n const stack = new Error().stack;\n\n if (typeof stack !== \"string\") {\n return undefined;\n }\n\n for (const line of stack.split(\"\\n\").slice(1)) {\n const candidate = extractStackPath(line);\n\n if (candidate === undefined) {\n continue;\n }\n\n if (\n candidate.includes(\"/packages/cmdkit/src/index.ts\") ||\n candidate.includes(\"/packages/cmdkit/dist/index.js\")\n ) {\n continue;\n }\n\n return candidate;\n }\n\n return undefined;\n}\n\nfunction composeChecks(\n parentCheck: Requires<any>[\"check\"] | undefined,\n childCheck: Requires<any>[\"check\"] | undefined\n): Requires<any>[\"check\"] | undefined {\n if (parentCheck === undefined) {\n return childCheck;\n }\n\n if (childCheck === undefined) {\n return parentCheck;\n }\n\n return async (ctx) => {\n const parentResult = await parentCheck(ctx);\n if (!parentResult.ok) {\n return parentResult;\n }\n\n return childCheck(ctx);\n };\n}\n\nfunction mergeRequires(parent: Requires<any> | undefined, child: Requires<any> | undefined): Requires<any> | undefined {\n if (parent === undefined && child === undefined) {\n return undefined;\n }\n\n const merged: Requires<any> = {\n auth: child?.auth ?? parent?.auth,\n apiVersion: child?.apiVersion ?? parent?.apiVersion,\n check: composeChecks(parent?.check, child?.check),\n };\n\n if (\n merged.auth === undefined &&\n merged.apiVersion === undefined &&\n merged.check === undefined\n ) {\n return undefined;\n }\n\n return merged;\n}\n\nfunction parseSimpleSemver(value: string): [number, number, number] | undefined {\n const parts = value.split(\".\");\n if (parts.length !== 3) {\n return undefined;\n }\n\n const parsed = parts.map((part) => {\n if (part.length === 0) {\n return Number.NaN;\n }\n\n for (const char of part) {\n if (char < \"0\" || char > \"9\") {\n return Number.NaN;\n }\n }\n\n return Number(part);\n });\n\n if (parsed.some((part) => !Number.isInteger(part) || part < 0)) {\n return undefined;\n }\n\n return parsed as [number, number, number];\n}\n\nfunction parseMinimumApiVersion(requirement: string): [number, number, number] | undefined {\n if (!requirement.startsWith(\">=\")) {\n return undefined;\n }\n\n return parseSimpleSemver(requirement.slice(2).trim());\n}\n\nfunction compareSemver(left: [number, number, number], right: [number, number, number]): number {\n for (let index = 0; index < left.length; index += 1) {\n if (left[index] === right[index]) {\n continue;\n }\n\n return left[index]! > right[index]! ? 1 : -1;\n }\n\n return 0;\n}\n\nexport function resolveCommandSecrets(\n command: Command<any, any, any, any>,\n env: Record<string, string | undefined> = process.env\n): Record<string, string | undefined> {\n const secrets: Record<string, string | undefined> = {};\n\n for (const [name, secret] of Object.entries(command.secrets)) {\n const value = env[secret.env];\n\n if (value === undefined && secret.optional !== true) {\n const details = secret.description ? `\\n ${secret.description}` : \"\";\n throw new UserError(`Error: Missing required secret ${secret.env}${details}`);\n }\n\n secrets[name] = value;\n }\n\n return secrets;\n}\n\nexport async function assertCommandRequirements(\n command: Command<any, any, any, any>,\n context: GroupCheckContext<any>,\n options: CommandRequirementOptions = {}\n): Promise<void> {\n const requires = command.requires;\n if (requires === undefined) {\n return;\n }\n\n const env = options.env ?? process.env;\n const authEnvVar = options.authEnvVar ?? \"POE_API_KEY\";\n\n if (requires.auth === true && env[authEnvVar] === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires authentication.\\n Run 'poe-code login' first.`\n );\n }\n\n if (requires.apiVersion !== undefined) {\n const minimumVersion = parseMinimumApiVersion(requires.apiVersion);\n if (minimumVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" has invalid apiVersion requirement \"${requires.apiVersion}\". Expected format \">=X.Y.Z\".`\n );\n }\n\n if (options.apiVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but no runner API version was provided.`\n );\n }\n\n const runnerVersion = parseSimpleSemver(options.apiVersion);\n if (runnerVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version \"${options.apiVersion}\" is not valid semver.`\n );\n }\n\n if (compareSemver(runnerVersion, minimumVersion) < 0) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version is ${options.apiVersion}.`\n );\n }\n }\n\n const checkResult = await requires.check?.(context);\n if (checkResult && !checkResult.ok) {\n throw new UserError(checkResult.message ?? \"Command precondition failed.\");\n }\n}\n\nfunction mergeSecrets(parent: SecretDeclarations, child: SecretDeclarations): SecretDeclarations {\n return cloneSecrets({\n ...parent,\n ...child,\n });\n}\n\nfunction resolveCommandScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] {\n return cloneScope(ownScope ?? inheritedScope) ?? [\"cli\", \"sdk\"];\n}\n\nfunction resolveGroupScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] | undefined {\n return cloneScope(ownScope ?? inheritedScope);\n}\n\nfunction createBaseCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n config: CommandConfig<TServices, TParamsSchema, TSecrets, TResult>\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const command: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n positional: [...(config.positional ?? [])],\n params: config.params,\n secrets: cloneSecrets(config.secrets),\n scope: resolveCommandScope(config.scope, undefined),\n confirm: config.confirm ?? false,\n requires: cloneRequires(config.requires),\n handler: config.handler,\n render: config.render,\n };\n\n Object.defineProperty(command, commandConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n sourcePath: inferCommandSourcePath(),\n } satisfies InternalCommandConfig,\n });\n\n return command;\n}\n\nfunction createBaseGroup<TServices extends object>(config: GroupConfig<TServices>): Group<TServices> {\n const group: Group<TServices> = {\n kind: \"group\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n scope: resolveGroupScope(config.scope, undefined),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [],\n default: undefined,\n };\n\n Object.defineProperty(group, groupConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [...config.children],\n default: config.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return group;\n}\n\nfunction getInternalCommandConfig(command: Command<any, any, any, any>): InternalCommandConfig {\n return (command as Command<any, any, any, any> & { [commandConfigSymbol]: InternalCommandConfig })[\n commandConfigSymbol\n ];\n}\n\nfunction getInternalGroupConfig<TServices extends object>(group: Group<TServices>): InternalGroupConfig<TServices> {\n return (group as Group<TServices> & { [groupConfigSymbol]: InternalGroupConfig<TServices> })[\n groupConfigSymbol\n ];\n}\n\nfunction materializeCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n command: Command<TServices, TParamsSchema, TSecrets, TResult>,\n inherited: InheritedMetadata\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const internal = getInternalCommandConfig(command);\n\n const materialized: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: command.name,\n description: command.description,\n aliases: [...command.aliases],\n positional: [...command.positional],\n params: command.params,\n secrets: mergeSecrets(inherited.secrets, internal.secrets),\n scope: resolveCommandScope(internal.scope, inherited.scope),\n confirm: command.confirm,\n requires: mergeRequires(inherited.requires, internal.requires),\n handler: command.handler,\n render: command.render,\n };\n\n Object.defineProperty(materialized, commandConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n sourcePath: internal.sourcePath,\n } satisfies InternalCommandConfig,\n });\n\n Object.defineProperty(materialized, commandSourcePathSymbol, {\n value: internal.sourcePath,\n });\n\n return materialized;\n}\n\nfunction materializeGroup<TServices extends object>(\n group: Group<TServices>,\n inherited: InheritedMetadata\n): Group<TServices> {\n const internal = getInternalGroupConfig(group);\n const scope = resolveGroupScope(internal.scope, inherited.scope);\n const secrets = mergeSecrets(inherited.secrets, internal.secrets);\n const requires = mergeRequires(inherited.requires, internal.requires);\n const materializedChildren = internal.children.map((child) =>\n materializeNode(child, {\n scope,\n secrets,\n requires,\n })\n );\n\n let defaultChild: Command<TServices, any, any, any> | undefined;\n\n if (internal.default !== undefined) {\n const defaultIndex = internal.children.indexOf(internal.default);\n\n if (defaultIndex === -1) {\n throw new UserError(`Default command \"${internal.default.name}\" must be listed in children.`);\n }\n\n const resolvedDefault = materializedChildren[defaultIndex];\n if (resolvedDefault?.kind !== \"command\") {\n throw new UserError(`Default child \"${internal.default.name}\" must be a command.`);\n }\n\n defaultChild = resolvedDefault;\n }\n\n const materialized: Group<TServices> = {\n kind: \"group\",\n name: group.name,\n description: group.description,\n aliases: [...group.aliases],\n scope,\n secrets,\n requires,\n children: materializedChildren,\n default: defaultChild,\n };\n\n Object.defineProperty(materialized, groupConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n children: [...internal.children],\n default: internal.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return materialized;\n}\n\nfunction materializeNode<TServices extends object>(\n node: CommandNode<TServices>,\n inherited: InheritedMetadata\n): CommandNode<TServices> {\n if (node.kind === \"command\") {\n return materializeCommand(node, inherited);\n }\n\n return materializeGroup(node, inherited);\n}\n\nexport function defineCommand<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<CommandConfig<TServices, TParamsSchema, TSecrets, TResult>, \"name\" | \"scope\"> & {\n name: TName;\n scope?: TOwnScope;\n }\n): Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope> {\n return materializeCommand(createBaseCommand(config as CommandConfig<TServices, TParamsSchema, TSecrets, TResult>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope>;\n}\n\nexport function defineGroup<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<GroupConfig<TServices>, \"name\" | \"children\" | \"scope\"> & {\n name: TName;\n children: TChildren & readonly CommandNode<TServices>[];\n scope?: TOwnScope;\n }\n): Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope> {\n return materializeGroup(createBaseGroup(config as unknown as GroupConfig<TServices>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope>;\n}\n\nexport function getCommandSourcePath(command: Command<any, any, any, any>): string | undefined {\n return (command as Command<any, any, any, any> & { [commandSourcePathSymbol]?: string })[\n commandSourcePathSymbol\n ];\n}\n\nexport { S, toJsonSchema } from \"@poe-code/cmdkit-schema\";\nexport type { AnySchema, ArraySchema, BooleanSchema, EnumSchema, JsonSchema, NumberSchema, ObjectSchema, OptionalSchema, Static, StringSchema } from \"@poe-code/cmdkit-schema\";\n", "type JsonSchemaType = \"string\" | \"number\" | \"boolean\" | \"array\" | \"object\";\ntype SchemaKind =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"enum\"\n | \"array\"\n | \"object\"\n | \"optional\";\ntype EnumValue = string | number | boolean;\ntype NonEmptyReadonlyArray<T> = readonly [T, ...T[]];\ntype ObjectShape = Record<string, AnySchema>;\ntype OptionalKeys<TShape extends ObjectShape> = {\n [TKey in keyof TShape]: TShape[TKey] extends OptionalSchema<any> ? TKey : never;\n}[keyof TShape];\ntype RequiredKeys<TShape extends ObjectShape> = Exclude<keyof TShape, OptionalKeys<TShape>>;\n\ntype PropertyStatic<TSchema extends AnySchema> = TSchema extends OptionalSchema<infer TInner>\n ? Static<TInner>\n : Static<TSchema>;\n\ntype InferObject<TShape extends ObjectShape> = {\n [TKey in RequiredKeys<TShape>]: PropertyStatic<TShape[TKey]>;\n} & {\n [TKey in OptionalKeys<TShape>]?: PropertyStatic<TShape[TKey]>;\n};\n\ntype SchemaOptions<TDefault> = {\n description?: string;\n default?: TDefault;\n short?: string;\n};\n\ninterface SchemaBase<TKind extends SchemaKind, TStatic> {\n readonly kind: TKind;\n readonly description?: string;\n readonly default?: TStatic;\n readonly short?: string;\n readonly __static?: TStatic;\n}\n\nexport interface JsonSchema {\n type?: JsonSchemaType;\n description?: string;\n default?: unknown;\n enum?: ReadonlyArray<EnumValue>;\n items?: JsonSchema;\n properties?: Record<string, JsonSchema>;\n required?: string[];\n}\n\nexport type StringSchema = SchemaBase<\"string\", string>;\n\nexport type NumberSchema = SchemaBase<\"number\", number>;\n\nexport type BooleanSchema = SchemaBase<\"boolean\", boolean>;\n\nexport interface EnumSchema<TValues extends NonEmptyReadonlyArray<EnumValue>>\n extends SchemaBase<\"enum\", TValues[number]> {\n readonly values: TValues;\n readonly labels?: Partial<Record<string, string>>;\n readonly loadOptions?: () => Array<{ label: string; value: string }> | Promise<Array<{ label: string; value: string }>>;\n}\n\nexport interface ArraySchema<TItem extends AnySchema>\n extends SchemaBase<\"array\", Array<Static<TItem>>> {\n readonly item: TItem;\n}\n\nexport interface ObjectSchema<TShape extends ObjectShape>\n extends SchemaBase<\"object\", InferObject<TShape>> {\n readonly shape: TShape;\n}\n\nexport interface OptionalSchema<TInner extends AnySchema>\n extends SchemaBase<\"optional\", Static<TInner> | undefined> {\n readonly inner: TInner;\n}\n\nexport type AnySchema =\n | StringSchema\n | NumberSchema\n | BooleanSchema\n | EnumSchema<NonEmptyReadonlyArray<EnumValue>>\n | ArraySchema<AnySchema>\n | ObjectSchema<ObjectShape>\n | OptionalSchema<AnySchema>;\n\nexport type Static<TSchema extends AnySchema> = TSchema extends SchemaBase<any, infer TStatic>\n ? TStatic\n : never;\n\nfunction withMetadata<TSchema extends AnySchema>(\n schema: TSchema,\n jsonSchema: JsonSchema\n): JsonSchema {\n if (schema.description !== undefined) {\n jsonSchema.description = schema.description;\n }\n\n if (schema.default !== undefined) {\n jsonSchema.default = schema.default;\n }\n\n return jsonSchema;\n}\n\nfunction getEnumJsonType(values: ReadonlyArray<EnumValue>): JsonSchemaType | undefined {\n const [firstValue] = values;\n\n if (firstValue === undefined) {\n return undefined;\n }\n\n const firstType = typeof firstValue;\n const isSinglePrimitiveType = values.every((value) => typeof value === firstType);\n\n if (!isSinglePrimitiveType) {\n return undefined;\n }\n\n if (firstType === \"string\" || firstType === \"number\" || firstType === \"boolean\") {\n return firstType;\n }\n\n return undefined;\n}\n\nfunction isOptionalSchema(schema: AnySchema): schema is OptionalSchema<AnySchema> {\n return schema.kind === \"optional\";\n}\n\nfunction assertValidEnumValues(values: ReadonlyArray<EnumValue>): void {\n if (values.length === 0) {\n throw new Error(\"Enum schema requires at least one value\");\n }\n\n const uniqueValues = new Set(values);\n\n if (uniqueValues.size !== values.length) {\n throw new Error(\"Enum schema values must be unique\");\n }\n}\n\nfunction unwrapOptional(schema: AnySchema): Exclude<AnySchema, OptionalSchema<AnySchema>> {\n if (isOptionalSchema(schema)) {\n return unwrapOptional(schema.inner);\n }\n\n return schema;\n}\n\nexport const S = {\n String(options: SchemaOptions<string> = {}): StringSchema {\n return {\n kind: \"string\",\n ...options,\n };\n },\n\n Number(options: SchemaOptions<number> = {}): NumberSchema {\n return {\n kind: \"number\",\n ...options,\n };\n },\n\n Boolean(options: SchemaOptions<boolean> = {}): BooleanSchema {\n return {\n kind: \"boolean\",\n ...options,\n };\n },\n\n Enum<const TValues extends NonEmptyReadonlyArray<EnumValue>>(\n values: TValues,\n options: SchemaOptions<TValues[number]> & {\n labels?: Partial<Record<string, string>>;\n loadOptions?: () => Array<{ label: string; value: string }> | Promise<Array<{ label: string; value: string }>>;\n } = {}\n ): EnumSchema<TValues> {\n assertValidEnumValues(values);\n\n return {\n kind: \"enum\",\n values,\n ...options,\n };\n },\n\n Array<TItem extends AnySchema>(\n item: TItem,\n options: SchemaOptions<Array<Static<TItem>>> = {}\n ): ArraySchema<TItem> {\n return {\n kind: \"array\",\n item,\n ...options,\n };\n },\n\n Object<const TShape extends ObjectShape>(shape: TShape): ObjectSchema<TShape> {\n return {\n kind: \"object\",\n shape,\n };\n },\n\n Optional<TInner extends AnySchema>(inner: TInner): OptionalSchema<TInner> {\n return {\n kind: \"optional\",\n inner,\n };\n },\n} as const;\n\nexport function toJsonSchema(schema: AnySchema): JsonSchema {\n const unwrappedSchema = unwrapOptional(schema);\n\n switch (unwrappedSchema.kind) {\n case \"string\":\n return withMetadata(unwrappedSchema, { type: \"string\" });\n\n case \"number\":\n return withMetadata(unwrappedSchema, { type: \"number\" });\n\n case \"boolean\":\n return withMetadata(unwrappedSchema, { type: \"boolean\" });\n\n case \"enum\": {\n const jsonSchema: JsonSchema = {\n enum: [...unwrappedSchema.values],\n };\n const enumType = getEnumJsonType(unwrappedSchema.values);\n\n if (enumType !== undefined) {\n jsonSchema.type = enumType;\n }\n\n return withMetadata(unwrappedSchema, jsonSchema);\n }\n\n case \"array\":\n return withMetadata(unwrappedSchema, {\n type: \"array\",\n items: toJsonSchema(unwrappedSchema.item),\n });\n\n case \"object\": {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, propertySchema] of Object.entries(unwrappedSchema.shape)) {\n properties[key] = toJsonSchema(propertySchema);\n\n if (!isOptionalSchema(propertySchema)) {\n required.push(key);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n }\n}\n"],
5
- "mappings": ";AAAA,SAAS,qBAAqB;;;AC4F9B,SAAS,aACP,QACA,YACY;AACZ,MAAI,OAAO,gBAAgB,QAAW;AACpC,eAAW,cAAc,OAAO;AAAA,EAClC;AAEA,MAAI,OAAO,YAAY,QAAW;AAChC,eAAW,UAAU,OAAO;AAAA,EAC9B;AAEA,SAAO;AACT;AAEA,SAAS,gBAAgB,QAA8D;AACrF,QAAM,CAAC,UAAU,IAAI;AAErB,MAAI,eAAe,QAAW;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO;AACzB,QAAM,wBAAwB,OAAO,MAAM,CAAC,UAAU,OAAO,UAAU,SAAS;AAEhF,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,MAAI,cAAc,YAAY,cAAc,YAAY,cAAc,WAAW;AAC/E,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,iBAAiB,QAAwD;AAChF,SAAO,OAAO,SAAS;AACzB;AAEA,SAAS,sBAAsB,QAAwC;AACrE,MAAI,OAAO,WAAW,GAAG;AACvB,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAEA,QAAM,eAAe,IAAI,IAAI,MAAM;AAEnC,MAAI,aAAa,SAAS,OAAO,QAAQ;AACvC,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AACF;AAEA,SAAS,eAAe,QAAkE;AACxF,MAAI,iBAAiB,MAAM,GAAG;AAC5B,WAAO,eAAe,OAAO,KAAK;AAAA,EACpC;AAEA,SAAO;AACT;AAEO,IAAM,IAAI;AAAA,EACf,OAAO,UAAiC,CAAC,GAAiB;AACxD,WAAO;AAAA,MACL,MAAM;AAAA,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AA0D;AAC7F,SAAQ,QACN,uBACF;AACF;",
4
+ "sourcesContent": ["import { fileURLToPath } from \"node:url\";\nimport type { ObjectSchema, Static } from \"@poe-code/cmdkit-schema\";\nimport type { LoggerOutput, RenderTableOptions, ThemePalette } from \"@poe-code/design-system\";\n\nconst commandConfigSymbol = Symbol(\"cmdkit.command.config\");\nconst groupConfigSymbol = Symbol(\"cmdkit.group.config\");\nconst commandSourcePathSymbol = Symbol(\"cmdkit.command.sourcePath\");\n\ntype ScopeValue = \"cli\" | \"mcp\" | \"sdk\";\ntype AnyObjectSchema = ObjectSchema<Record<string, never>>;\ntype EmptyServices = Record<string, never>;\ntype ScopeInput = readonly Scope[] | undefined;\n\nexport type Scope = ScopeValue;\n\nexport interface SecretDefinition {\n env: string;\n description?: string;\n optional?: boolean;\n}\n\nexport type SecretDeclarations = Record<string, SecretDefinition>;\n\ntype OptionalSecretKeys<TSecrets extends SecretDeclarations> = {\n [TKey in keyof TSecrets]: TSecrets[TKey] extends { optional: true } ? TKey : never;\n}[keyof TSecrets];\n\ntype RequiredSecretKeys<TSecrets extends SecretDeclarations> = Exclude<\n keyof TSecrets,\n OptionalSecretKeys<TSecrets>\n>;\n\nexport type InferSecrets<TSecrets extends SecretDeclarations | undefined> =\n TSecrets extends SecretDeclarations\n ? { [TKey in RequiredSecretKeys<TSecrets>]: string } & {\n [TKey in OptionalSecretKeys<TSecrets>]?: string;\n }\n : Record<string, never>;\n\nexport interface HandlerFs {\n readFile(path: string, encoding?: BufferEncoding): Promise<string>;\n writeFile(path: string, contents: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n}\n\nexport interface HandlerEnv {\n get(key: string): string | undefined;\n}\n\nexport interface RenderPrimitives {\n logger: LoggerOutput;\n renderTable(options: RenderTableOptions): string;\n getTheme(): ThemePalette;\n note(message: string, title?: string): void;\n}\n\nexport interface CheckResult {\n ok: boolean;\n message?: string;\n}\n\nexport type GroupCheckContext<TServices extends object = EmptyServices> = TServices & {\n params?: unknown;\n secrets?: Record<string, string | undefined>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport type CommandCheckContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params?: Static<TParamsSchema>;\n secrets?: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface Requires<TContext = unknown> {\n auth?: boolean;\n apiVersion?: string;\n check?: (ctx: TContext) => Promise<CheckResult>;\n}\n\nexport interface Renderers<TResult> {\n rich?: (result: TResult, primitives: RenderPrimitives) => void;\n markdown?: (result: TResult, primitives: RenderPrimitives) => string;\n json?: (result: TResult, primitives: RenderPrimitives) => unknown;\n}\n\nexport type HandlerContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params: Static<TParamsSchema>;\n secrets: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface CommandConfig<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n> {\n name: string;\n description?: string;\n aliases?: string[];\n positional?: string[];\n params: TParamsSchema;\n secrets?: TSecrets;\n scope?: Scope[];\n confirm?: boolean;\n requires?: Requires<CommandCheckContext<TParamsSchema, TSecrets, TServices>>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface Command<\n TServices extends object = EmptyServices,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n> {\n kind: \"command\";\n name: string;\n description?: string;\n aliases: string[];\n positional: string[];\n params: TParamsSchema;\n secrets: SecretDeclarations;\n scope: Scope[];\n confirm: boolean;\n requires?: Requires<any>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface GroupConfig<TServices extends object> {\n name: string;\n description?: string;\n aliases?: string[];\n scope?: Scope[];\n secrets?: SecretDeclarations;\n requires?: Requires<GroupCheckContext<TServices>>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport interface Group<TServices extends object = EmptyServices> {\n kind: \"group\";\n name: string;\n description?: string;\n aliases: string[];\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport type CommandNode<TServices extends object = EmptyServices> =\n | Command<TServices, any, any, any>\n | Group<TServices>;\n\nexport interface CommandTypeInfo<\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TResult = unknown,\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n params: TParamsSchema;\n result: TResult;\n ownScope: TOwnScope;\n}\n\nexport interface GroupTypeInfo<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n children: TChildren;\n ownScope: TOwnScope;\n}\n\ntype TypedCommandMetadata<\n TName extends string,\n TParamsSchema extends ObjectSchema<any>,\n TResult,\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitCommandTypeInfo: CommandTypeInfo<TName, TParamsSchema, TResult, TOwnScope>;\n};\n\ntype TypedGroupMetadata<\n TServices extends object,\n TName extends string,\n TChildren extends readonly unknown[],\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitGroupTypeInfo: GroupTypeInfo<TServices, TName, TChildren, TOwnScope>;\n};\n\ninterface InternalCommandConfig {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n sourcePath?: string;\n}\n\ninterface InternalGroupConfig<TServices extends object> {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\ninterface InheritedMetadata {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n}\n\nexport class UserError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"UserError\";\n }\n}\n\nexport interface CommandRequirementOptions {\n apiVersion?: string;\n authEnvVar?: string;\n env?: Record<string, string | undefined>;\n}\n\nfunction cloneScope(scope: Scope[] | undefined): Scope[] | undefined {\n return scope === undefined ? undefined : [...scope];\n}\n\nfunction cloneSecretDefinition(secret: SecretDefinition): SecretDefinition {\n return {\n env: secret.env,\n description: secret.description,\n optional: secret.optional,\n };\n}\n\nfunction cloneSecrets(secrets: SecretDeclarations | undefined): SecretDeclarations {\n if (secrets === undefined) {\n return {};\n }\n\n return Object.fromEntries(\n Object.entries(secrets).map(([key, secret]) => [key, cloneSecretDefinition(secret)])\n );\n}\n\nfunction cloneRequires<TContext>(requires: Requires<TContext> | undefined): Requires<TContext> | undefined {\n if (requires === undefined) {\n return undefined;\n }\n\n return {\n auth: requires.auth,\n apiVersion: requires.apiVersion,\n check: requires.check,\n };\n}\n\nfunction parseStackPath(candidate: string): string | undefined {\n if (candidate.startsWith(\"file://\")) {\n try {\n return fileURLToPath(candidate);\n } catch {\n return undefined;\n }\n }\n\n if (candidate.startsWith(\"/\")) {\n return candidate;\n }\n\n return undefined;\n}\n\nfunction extractStackPath(line: string): string | undefined {\n const trimmed = line.trim();\n const fileIndex = trimmed.indexOf(\"file://\");\n\n if (fileIndex >= 0) {\n const location = trimmed.slice(fileIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n }\n\n const slashIndex = trimmed.indexOf(\"/\");\n if (slashIndex < 0) {\n return undefined;\n }\n\n const location = trimmed.slice(slashIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n}\n\nfunction inferCommandSourcePath(): string | undefined {\n const stack = new Error().stack;\n\n if (typeof stack !== \"string\") {\n return undefined;\n }\n\n for (const line of stack.split(\"\\n\").slice(1)) {\n const candidate = extractStackPath(line);\n\n if (candidate === undefined) {\n continue;\n }\n\n if (\n candidate.includes(\"/packages/cmdkit/src/index.ts\") ||\n candidate.includes(\"/packages/cmdkit/dist/index.js\")\n ) {\n continue;\n }\n\n return candidate;\n }\n\n return undefined;\n}\n\nfunction composeChecks(\n parentCheck: Requires<any>[\"check\"] | undefined,\n childCheck: Requires<any>[\"check\"] | undefined\n): Requires<any>[\"check\"] | undefined {\n if (parentCheck === undefined) {\n return childCheck;\n }\n\n if (childCheck === undefined) {\n return parentCheck;\n }\n\n return async (ctx) => {\n const parentResult = await parentCheck(ctx);\n if (!parentResult.ok) {\n return parentResult;\n }\n\n return childCheck(ctx);\n };\n}\n\nfunction mergeRequires(parent: Requires<any> | undefined, child: Requires<any> | undefined): Requires<any> | undefined {\n if (parent === undefined && child === undefined) {\n return undefined;\n }\n\n const merged: Requires<any> = {\n auth: child?.auth ?? parent?.auth,\n apiVersion: child?.apiVersion ?? parent?.apiVersion,\n check: composeChecks(parent?.check, child?.check),\n };\n\n if (\n merged.auth === undefined &&\n merged.apiVersion === undefined &&\n merged.check === undefined\n ) {\n return undefined;\n }\n\n return merged;\n}\n\nfunction parseSimpleSemver(value: string): [number, number, number] | undefined {\n const parts = value.split(\".\");\n if (parts.length !== 3) {\n return undefined;\n }\n\n const parsed = parts.map((part) => {\n if (part.length === 0) {\n return Number.NaN;\n }\n\n for (const char of part) {\n if (char < \"0\" || char > \"9\") {\n return Number.NaN;\n }\n }\n\n return Number(part);\n });\n\n if (parsed.some((part) => !Number.isInteger(part) || part < 0)) {\n return undefined;\n }\n\n return parsed as [number, number, number];\n}\n\nfunction parseMinimumApiVersion(requirement: string): [number, number, number] | undefined {\n if (!requirement.startsWith(\">=\")) {\n return undefined;\n }\n\n return parseSimpleSemver(requirement.slice(2).trim());\n}\n\nfunction compareSemver(left: [number, number, number], right: [number, number, number]): number {\n for (let index = 0; index < left.length; index += 1) {\n if (left[index] === right[index]) {\n continue;\n }\n\n return left[index]! > right[index]! ? 1 : -1;\n }\n\n return 0;\n}\n\nexport function resolveCommandSecrets(\n command: Command<any, any, any, any>,\n env: Record<string, string | undefined> = process.env\n): Record<string, string | undefined> {\n const secrets: Record<string, string | undefined> = {};\n\n for (const [name, secret] of Object.entries(command.secrets)) {\n const value = env[secret.env];\n\n if (value === undefined && secret.optional !== true) {\n const details = secret.description ? `\\n ${secret.description}` : \"\";\n throw new UserError(`Error: Missing required secret ${secret.env}${details}`);\n }\n\n secrets[name] = value;\n }\n\n return secrets;\n}\n\nexport async function assertCommandRequirements(\n command: Command<any, any, any, any>,\n context: GroupCheckContext<any>,\n options: CommandRequirementOptions = {}\n): Promise<void> {\n const requires = command.requires;\n if (requires === undefined) {\n return;\n }\n\n const env = options.env ?? process.env;\n const authEnvVar = options.authEnvVar ?? \"POE_API_KEY\";\n\n if (requires.auth === true && env[authEnvVar] === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires authentication.\\n Run 'poe-code login' first.`\n );\n }\n\n if (requires.apiVersion !== undefined) {\n const minimumVersion = parseMinimumApiVersion(requires.apiVersion);\n if (minimumVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" has invalid apiVersion requirement \"${requires.apiVersion}\". Expected format \">=X.Y.Z\".`\n );\n }\n\n if (options.apiVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but no runner API version was provided.`\n );\n }\n\n const runnerVersion = parseSimpleSemver(options.apiVersion);\n if (runnerVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version \"${options.apiVersion}\" is not valid semver.`\n );\n }\n\n if (compareSemver(runnerVersion, minimumVersion) < 0) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version is ${options.apiVersion}.`\n );\n }\n }\n\n const checkResult = await requires.check?.(context);\n if (checkResult && !checkResult.ok) {\n throw new UserError(checkResult.message ?? \"Command precondition failed.\");\n }\n}\n\nfunction mergeSecrets(parent: SecretDeclarations, child: SecretDeclarations): SecretDeclarations {\n return cloneSecrets({\n ...parent,\n ...child,\n });\n}\n\nfunction resolveCommandScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] {\n return cloneScope(ownScope ?? inheritedScope) ?? [\"cli\", \"sdk\"];\n}\n\nfunction resolveGroupScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] | undefined {\n return cloneScope(ownScope ?? inheritedScope);\n}\n\nfunction createBaseCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n config: CommandConfig<TServices, TParamsSchema, TSecrets, TResult>\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const command: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n positional: [...(config.positional ?? [])],\n params: config.params,\n secrets: cloneSecrets(config.secrets),\n scope: resolveCommandScope(config.scope, undefined),\n confirm: config.confirm ?? false,\n requires: cloneRequires(config.requires),\n handler: config.handler,\n render: config.render,\n };\n\n Object.defineProperty(command, commandConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n sourcePath: inferCommandSourcePath(),\n } satisfies InternalCommandConfig,\n });\n\n return command;\n}\n\nfunction createBaseGroup<TServices extends object>(config: GroupConfig<TServices>): Group<TServices> {\n const group: Group<TServices> = {\n kind: \"group\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n scope: resolveGroupScope(config.scope, undefined),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [],\n default: undefined,\n };\n\n Object.defineProperty(group, groupConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [...config.children],\n default: config.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return group;\n}\n\nfunction getInternalCommandConfig(command: Command<any, any, any, any>): InternalCommandConfig {\n return (command as Command<any, any, any, any> & { [commandConfigSymbol]: InternalCommandConfig })[\n commandConfigSymbol\n ];\n}\n\nfunction getInternalGroupConfig<TServices extends object>(group: Group<TServices>): InternalGroupConfig<TServices> {\n return (group as Group<TServices> & { [groupConfigSymbol]: InternalGroupConfig<TServices> })[\n groupConfigSymbol\n ];\n}\n\nfunction materializeCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n command: Command<TServices, TParamsSchema, TSecrets, TResult>,\n inherited: InheritedMetadata\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const internal = getInternalCommandConfig(command);\n\n const materialized: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: command.name,\n description: command.description,\n aliases: [...command.aliases],\n positional: [...command.positional],\n params: command.params,\n secrets: mergeSecrets(inherited.secrets, internal.secrets),\n scope: resolveCommandScope(internal.scope, inherited.scope),\n confirm: command.confirm,\n requires: mergeRequires(inherited.requires, internal.requires),\n handler: command.handler,\n render: command.render,\n };\n\n Object.defineProperty(materialized, commandConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n sourcePath: internal.sourcePath,\n } satisfies InternalCommandConfig,\n });\n\n Object.defineProperty(materialized, commandSourcePathSymbol, {\n value: internal.sourcePath,\n });\n\n return materialized;\n}\n\nfunction materializeGroup<TServices extends object>(\n group: Group<TServices>,\n inherited: InheritedMetadata\n): Group<TServices> {\n const internal = getInternalGroupConfig(group);\n const scope = resolveGroupScope(internal.scope, inherited.scope);\n const secrets = mergeSecrets(inherited.secrets, internal.secrets);\n const requires = mergeRequires(inherited.requires, internal.requires);\n const materializedChildren = internal.children.map((child) =>\n materializeNode(child, {\n scope,\n secrets,\n requires,\n })\n );\n\n let defaultChild: Command<TServices, any, any, any> | undefined;\n\n if (internal.default !== undefined) {\n const defaultIndex = internal.children.indexOf(internal.default);\n\n if (defaultIndex === -1) {\n throw new UserError(`Default command \"${internal.default.name}\" must be listed in children.`);\n }\n\n const resolvedDefault = materializedChildren[defaultIndex];\n if (resolvedDefault?.kind !== \"command\") {\n throw new UserError(`Default child \"${internal.default.name}\" must be a command.`);\n }\n\n defaultChild = resolvedDefault;\n }\n\n const materialized: Group<TServices> = {\n kind: \"group\",\n name: group.name,\n description: group.description,\n aliases: [...group.aliases],\n scope,\n secrets,\n requires,\n children: materializedChildren,\n default: defaultChild,\n };\n\n Object.defineProperty(materialized, groupConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n children: [...internal.children],\n default: internal.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return materialized;\n}\n\nfunction materializeNode<TServices extends object>(\n node: CommandNode<TServices>,\n inherited: InheritedMetadata\n): CommandNode<TServices> {\n if (node.kind === \"command\") {\n return materializeCommand(node, inherited);\n }\n\n return materializeGroup(node, inherited);\n}\n\nexport function defineCommand<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<CommandConfig<TServices, TParamsSchema, TSecrets, TResult>, \"name\" | \"scope\"> & {\n name: TName;\n scope?: TOwnScope;\n }\n): Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope> {\n return materializeCommand(createBaseCommand(config as CommandConfig<TServices, TParamsSchema, TSecrets, TResult>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope>;\n}\n\nexport function defineGroup<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<GroupConfig<TServices>, \"name\" | \"children\" | \"scope\"> & {\n name: TName;\n children: TChildren & readonly CommandNode<TServices>[];\n scope?: TOwnScope;\n }\n): Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope> {\n return materializeGroup(createBaseGroup(config as unknown as GroupConfig<TServices>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope>;\n}\n\nexport function getCommandSourcePath(command: Command<any, any, any, any>): string | undefined {\n return (command as Command<any, any, any, any> & { [commandSourcePathSymbol]?: string })[\n commandSourcePathSymbol\n ];\n}\n\nexport { S, toJsonSchema } from \"@poe-code/cmdkit-schema\";\nexport type { AnySchema, ArraySchema, BooleanSchema, EnumSchema, JsonSchema, NumberSchema, ObjectSchema, OptionalSchema, Static, StringSchema } from \"@poe-code/cmdkit-schema\";\n", "type JsonSchemaType = \"string\" | \"number\" | \"integer\" | \"boolean\" | \"array\" | \"object\";\ntype SchemaKind =\n | \"string\"\n | \"number\"\n | \"boolean\"\n | \"enum\"\n | \"array\"\n | \"object\"\n | \"optional\";\ntype EnumValue = string | number | boolean;\ntype JsonSchemaEnumValue = EnumValue | null;\ntype NumberJsonType = \"number\" | \"integer\";\ntype NonEmptyReadonlyArray<T> = readonly [T, ...T[]];\ntype ObjectShape = Record<string, AnySchema>;\ntype SchemaScope = \"cli\" | \"mcp\" | \"sdk\";\ntype StringMetadata = {\n format?: string;\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n};\ntype NumberMetadata = {\n maximum?: number;\n minimum?: number;\n};\ntype ArrayMetadata = {\n maxItems?: number;\n minItems?: number;\n};\ntype ObjectMetadata = {\n additionalProperties?: boolean;\n};\ntype OptionalKeys<TShape extends ObjectShape> = {\n [TKey in keyof TShape]: TShape[TKey] extends OptionalSchema<any> ? TKey : never;\n}[keyof TShape];\ntype RequiredKeys<TShape extends ObjectShape> = Exclude<keyof TShape, OptionalKeys<TShape>>;\n\ntype PropertyStatic<TSchema extends AnySchema> = TSchema extends OptionalSchema<infer TInner>\n ? Static<TInner>\n : Static<TSchema>;\n\ntype InferObject<TShape extends ObjectShape> = {\n [TKey in RequiredKeys<TShape>]: PropertyStatic<TShape[TKey]>;\n} & {\n [TKey in OptionalKeys<TShape>]?: PropertyStatic<TShape[TKey]>;\n};\n\ntype SchemaOptions<TDefault> = {\n description?: string;\n default?: TDefault;\n nullable?: boolean;\n requiredScopes?: readonly SchemaScope[];\n short?: string;\n scope?: readonly SchemaScope[];\n};\n\ninterface SchemaBase<TKind extends SchemaKind, TStatic> {\n readonly kind: TKind;\n readonly description?: string;\n readonly default?: TStatic;\n readonly nullable?: boolean;\n readonly requiredScopes?: readonly SchemaScope[];\n readonly short?: string;\n readonly scope?: readonly SchemaScope[];\n readonly __static?: TStatic;\n}\n\nexport interface JsonSchema {\n additionalProperties?: boolean;\n type?: JsonSchemaType;\n description?: string;\n default?: unknown;\n enum?: ReadonlyArray<JsonSchemaEnumValue>;\n format?: string;\n items?: JsonSchema;\n maxItems?: number;\n maximum?: number;\n maxLength?: number;\n minItems?: number;\n minimum?: number;\n minLength?: number;\n nullable?: boolean;\n pattern?: string;\n properties?: Record<string, JsonSchema>;\n required?: string[];\n}\n\nexport interface StringSchema extends SchemaBase<\"string\", string>, StringMetadata {}\n\nexport interface NumberSchema extends SchemaBase<\"number\", number>, NumberMetadata {\n readonly jsonType?: NumberJsonType;\n}\n\nexport type BooleanSchema = SchemaBase<\"boolean\", boolean>;\n\nexport interface EnumSchema<TValues extends NonEmptyReadonlyArray<EnumValue>>\n extends SchemaBase<\"enum\", TValues[number]> {\n readonly values: TValues;\n readonly jsonType?: \"integer\";\n readonly labels?: Partial<Record<string, string>>;\n readonly loadOptions?:\n | (() => Array<{ label: string; value: string }>)\n | (() => Promise<Array<{ label: string; value: string }>>);\n}\n\nexport interface ArraySchema<TItem extends AnySchema>\n extends SchemaBase<\"array\", Array<Static<TItem>>>, ArrayMetadata {\n readonly item: TItem;\n}\n\nexport interface ObjectSchema<TShape extends ObjectShape>\n extends SchemaBase<\"object\", InferObject<TShape>>, ObjectMetadata {\n readonly shape: TShape;\n}\n\nexport interface OptionalSchema<TInner extends AnySchema>\n extends SchemaBase<\"optional\", Static<TInner> | undefined> {\n readonly inner: TInner;\n}\n\nexport type AnySchema =\n | StringSchema\n | NumberSchema\n | BooleanSchema\n | EnumSchema<NonEmptyReadonlyArray<EnumValue>>\n | ArraySchema<AnySchema>\n | ObjectSchema<ObjectShape>\n | OptionalSchema<AnySchema>;\n\nexport type Static<TSchema extends AnySchema> = TSchema extends SchemaBase<any, infer TStatic>\n ? TStatic\n : never;\n\nfunction withMetadata<TSchema extends AnySchema>(\n schema: TSchema,\n jsonSchema: JsonSchema\n): JsonSchema {\n if (schema.description !== undefined) {\n jsonSchema.description = schema.description;\n }\n\n if (schema.default !== undefined) {\n jsonSchema.default = schema.default;\n }\n\n if (schema.nullable === true) {\n jsonSchema.nullable = true;\n }\n\n return jsonSchema;\n}\n\nfunction withStringMetadata(schema: StringSchema, jsonSchema: JsonSchema): JsonSchema {\n if (schema.minLength !== undefined) {\n jsonSchema.minLength = schema.minLength;\n }\n\n if (schema.maxLength !== undefined) {\n jsonSchema.maxLength = schema.maxLength;\n }\n\n if (schema.pattern !== undefined) {\n jsonSchema.pattern = schema.pattern;\n }\n\n if (schema.format !== undefined) {\n jsonSchema.format = schema.format;\n }\n\n return withMetadata(schema, jsonSchema);\n}\n\nfunction withNumberMetadata(schema: NumberSchema, jsonSchema: JsonSchema): JsonSchema {\n if (schema.minimum !== undefined) {\n jsonSchema.minimum = schema.minimum;\n }\n\n if (schema.maximum !== undefined) {\n jsonSchema.maximum = schema.maximum;\n }\n\n return withMetadata(schema, jsonSchema);\n}\n\nfunction withArrayMetadata(schema: ArraySchema<any>, jsonSchema: JsonSchema): JsonSchema {\n if (schema.minItems !== undefined) {\n jsonSchema.minItems = schema.minItems;\n }\n\n if (schema.maxItems !== undefined) {\n jsonSchema.maxItems = schema.maxItems;\n }\n\n return withMetadata(schema, jsonSchema);\n}\n\nfunction withObjectMetadata(schema: ObjectSchema<any>, jsonSchema: JsonSchema): JsonSchema {\n if (schema.additionalProperties !== undefined) {\n jsonSchema.additionalProperties = schema.additionalProperties;\n }\n\n return withMetadata(schema, jsonSchema);\n}\n\nfunction getEnumJsonType(values: ReadonlyArray<EnumValue>): JsonSchemaType | undefined {\n const [firstValue] = values;\n\n if (firstValue === undefined) {\n return undefined;\n }\n\n const firstType = typeof firstValue;\n const isSinglePrimitiveType = values.every((value) => typeof value === firstType);\n\n if (!isSinglePrimitiveType) {\n return undefined;\n }\n\n if (firstType === \"string\" || firstType === \"number\" || firstType === \"boolean\") {\n return firstType;\n }\n\n return undefined;\n}\n\nfunction isOptionalSchema(schema: AnySchema): schema is OptionalSchema<AnySchema> {\n return schema.kind === \"optional\";\n}\n\nfunction assertValidEnumValues(values: ReadonlyArray<EnumValue>): void {\n if (values.length === 0) {\n throw new Error(\"Enum schema requires at least one value\");\n }\n\n const uniqueValues = new Set(values);\n\n if (uniqueValues.size !== values.length) {\n throw new Error(\"Enum schema values must be unique\");\n }\n}\n\nfunction unwrapOptional(schema: AnySchema): Exclude<AnySchema, OptionalSchema<AnySchema>> {\n if (isOptionalSchema(schema)) {\n return unwrapOptional(schema.inner);\n }\n\n return schema;\n}\n\nexport const S = {\n String(options: SchemaOptions<string> & StringMetadata = {}): StringSchema {\n return {\n kind: \"string\",\n ...options,\n };\n },\n\n Number(\n options: SchemaOptions<number> & NumberMetadata & { jsonType?: NumberJsonType } = {}\n ): NumberSchema {\n return {\n kind: \"number\",\n ...options,\n };\n },\n\n Boolean(options: SchemaOptions<boolean> = {}): BooleanSchema {\n return {\n kind: \"boolean\",\n ...options,\n };\n },\n\n Enum<const TValues extends NonEmptyReadonlyArray<EnumValue>>(\n values: TValues,\n options: SchemaOptions<TValues[number]> & {\n jsonType?: \"integer\";\n labels?: Partial<Record<string, string>>;\n loadOptions?:\n | (() => Array<{ label: string; value: string }>)\n | (() => Promise<Array<{ label: string; value: string }>>);\n } = {}\n ): EnumSchema<TValues> {\n assertValidEnumValues(values);\n\n return {\n kind: \"enum\",\n values,\n ...options,\n };\n },\n\n Array<TItem extends AnySchema>(\n item: TItem,\n options: SchemaOptions<Array<Static<TItem>>> & ArrayMetadata = {}\n ): ArraySchema<TItem> {\n return {\n kind: \"array\",\n item,\n ...options,\n };\n },\n\n Object<const TShape extends ObjectShape>(\n shape: TShape,\n options: SchemaOptions<InferObject<TShape>> & ObjectMetadata = {}\n ): ObjectSchema<TShape> {\n return {\n kind: \"object\",\n shape,\n ...options,\n };\n },\n\n Optional<TInner extends AnySchema>(inner: TInner): OptionalSchema<TInner> {\n return {\n kind: \"optional\",\n inner,\n };\n },\n} as const;\n\nexport function toJsonSchema(schema: AnySchema): JsonSchema {\n const unwrappedSchema = unwrapOptional(schema);\n\n switch (unwrappedSchema.kind) {\n case \"string\":\n return withStringMetadata(unwrappedSchema, { type: \"string\" });\n\n case \"number\":\n return withNumberMetadata(unwrappedSchema, { type: unwrappedSchema.jsonType ?? \"number\" });\n\n case \"boolean\":\n return withMetadata(unwrappedSchema, { type: \"boolean\" });\n\n case \"enum\": {\n const jsonSchema: JsonSchema = {\n enum:\n unwrappedSchema.nullable === true\n ? [...unwrappedSchema.values, null]\n : [...unwrappedSchema.values],\n };\n const enumType = unwrappedSchema.jsonType ?? getEnumJsonType(unwrappedSchema.values);\n\n if (enumType !== undefined) {\n jsonSchema.type = enumType;\n }\n\n return withMetadata(unwrappedSchema, jsonSchema);\n }\n\n case \"array\":\n return withArrayMetadata(unwrappedSchema, {\n type: \"array\",\n items: toJsonSchema(unwrappedSchema.item),\n });\n\n case \"object\": {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, propertySchema] of Object.entries(unwrappedSchema.shape)) {\n properties[key] = toJsonSchema(propertySchema);\n\n if (!isOptionalSchema(propertySchema)) {\n required.push(key);\n }\n }\n\n return withObjectMetadata(unwrappedSchema, {\n type: \"object\",\n properties,\n required,\n });\n }\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,qBAAqB;;;ACqI9B,SAAS,aACP,QACA,YACY;AACZ,MAAI,OAAO,gBAAgB,QAAW;AACpC,eAAW,cAAc,OAAO;AAAA,EAClC;AAEA,MAAI,OAAO,YAAY,QAAW;AAChC,eAAW,UAAU,OAAO;AAAA,EAC9B;AAEA,MAAI,OAAO,aAAa,MAAM;AAC5B,eAAW,WAAW;AAAA,EACxB;AAEA,SAAO;AACT;AAEA,SAAS,mBAAmB,QAAsB,YAAoC;AACpF,MAAI,OAAO,cAAc,QAAW;AAClC,eAAW,YAAY,OAAO;AAAA,EAChC;AAEA,MAAI,OAAO,cAAc,QAAW;AAClC,eAAW,YAAY,OAAO;AAAA,EAChC;AAEA,MAAI,OAAO,YAAY,QAAW;AAChC,eAAW,UAAU,OAAO;AAAA,EAC9B;AAEA,MAAI,OAAO,WAAW,QAAW;AAC/B,eAAW,SAAS,OAAO;AAAA,EAC7B;AAEA,SAAO,aAAa,QAAQ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AAS,cAQd,QAK+D;AAC/D,SAAO,mBAAmB,kBAAkB,MAAoE,GAAG;AAAA,IACjH,OAAO;AAAA,IACP,SAAS,CAAC;AAAA,IACV,UAAU;AAAA,EACZ,CAAC;AAEH;AAEO,SAAS,YAMd,QAK+E;AAC/E,SAAO,iBAAiB,gBAAgB,MAA2C,GAAG;AAAA,IACpF,OAAO;AAAA,IACP,SAAS,CAAC;AAAA,IACV,UAAU;AAAA,EACZ,CAAC;AACH;AAEO,SAAS,qBAAqB,SAA0D;AAC7F,SAAQ,QACN,uBACF;AACF;",
6
6
  "names": ["location", "separatorIndex", "previousSeparatorIndex", "candidate"]
7
7
  }
@@ -7,8 +7,23 @@ type CmdkitServer = Omit<TinyServer, "connect"> & {
7
7
  export interface RunMCPOptions<TServices extends object = Record<string, unknown>> {
8
8
  name: string;
9
9
  version: string;
10
+ /**
11
+ * Optional allowlist of MCP tool names or group prefixes.
12
+ *
13
+ * Tool names always use `__`-joined snake_case path segments, for example
14
+ * `root__bot__create`.
15
+ *
16
+ * Passing a group prefix like `root__bot` includes every descendant tool in
17
+ * that subtree.
18
+ */
10
19
  tools?: string[];
11
20
  services?: TServices;
21
+ /**
22
+ * Controls MCP input-schema key casing and accepted argument-key casing.
23
+ *
24
+ * This does not change tool names. Tool names always stay `__`-joined
25
+ * snake_case path segments.
26
+ */
12
27
  casing?: Casing;
13
28
  }
14
29
  export declare function createMCPServer<TServices extends object = Record<string, unknown>>(roots: Group<TServices> | Group<TServices>[], options: RunMCPOptions<TServices>): CmdkitServer;
@@ -636,8 +636,50 @@ function withMetadata(schema, jsonSchema) {
636
636
  if (schema.default !== void 0) {
637
637
  jsonSchema.default = schema.default;
638
638
  }
639
+ if (schema.nullable === true) {
640
+ jsonSchema.nullable = true;
641
+ }
639
642
  return jsonSchema;
640
643
  }
644
+ function withStringMetadata(schema, jsonSchema) {
645
+ if (schema.minLength !== void 0) {
646
+ jsonSchema.minLength = schema.minLength;
647
+ }
648
+ if (schema.maxLength !== void 0) {
649
+ jsonSchema.maxLength = schema.maxLength;
650
+ }
651
+ if (schema.pattern !== void 0) {
652
+ jsonSchema.pattern = schema.pattern;
653
+ }
654
+ if (schema.format !== void 0) {
655
+ jsonSchema.format = schema.format;
656
+ }
657
+ return withMetadata(schema, jsonSchema);
658
+ }
659
+ function withNumberMetadata(schema, jsonSchema) {
660
+ if (schema.minimum !== void 0) {
661
+ jsonSchema.minimum = schema.minimum;
662
+ }
663
+ if (schema.maximum !== void 0) {
664
+ jsonSchema.maximum = schema.maximum;
665
+ }
666
+ return withMetadata(schema, jsonSchema);
667
+ }
668
+ function withArrayMetadata(schema, jsonSchema) {
669
+ if (schema.minItems !== void 0) {
670
+ jsonSchema.minItems = schema.minItems;
671
+ }
672
+ if (schema.maxItems !== void 0) {
673
+ jsonSchema.maxItems = schema.maxItems;
674
+ }
675
+ return withMetadata(schema, jsonSchema);
676
+ }
677
+ function withObjectMetadata(schema, jsonSchema) {
678
+ if (schema.additionalProperties !== void 0) {
679
+ jsonSchema.additionalProperties = schema.additionalProperties;
680
+ }
681
+ return withMetadata(schema, jsonSchema);
682
+ }
641
683
  function getEnumJsonType(values) {
642
684
  const [firstValue] = values;
643
685
  if (firstValue === void 0) {
@@ -666,23 +708,23 @@ function toJsonSchema(schema) {
666
708
  const unwrappedSchema = unwrapOptional(schema);
667
709
  switch (unwrappedSchema.kind) {
668
710
  case "string":
669
- return withMetadata(unwrappedSchema, { type: "string" });
711
+ return withStringMetadata(unwrappedSchema, { type: "string" });
670
712
  case "number":
671
- return withMetadata(unwrappedSchema, { type: "number" });
713
+ return withNumberMetadata(unwrappedSchema, { type: unwrappedSchema.jsonType ?? "number" });
672
714
  case "boolean":
673
715
  return withMetadata(unwrappedSchema, { type: "boolean" });
674
716
  case "enum": {
675
717
  const jsonSchema = {
676
- enum: [...unwrappedSchema.values]
718
+ enum: unwrappedSchema.nullable === true ? [...unwrappedSchema.values, null] : [...unwrappedSchema.values]
677
719
  };
678
- const enumType = getEnumJsonType(unwrappedSchema.values);
720
+ const enumType = unwrappedSchema.jsonType ?? getEnumJsonType(unwrappedSchema.values);
679
721
  if (enumType !== void 0) {
680
722
  jsonSchema.type = enumType;
681
723
  }
682
724
  return withMetadata(unwrappedSchema, jsonSchema);
683
725
  }
684
726
  case "array":
685
- return withMetadata(unwrappedSchema, {
727
+ return withArrayMetadata(unwrappedSchema, {
686
728
  type: "array",
687
729
  items: toJsonSchema(unwrappedSchema.item)
688
730
  });
@@ -695,11 +737,11 @@ function toJsonSchema(schema) {
695
737
  required.push(key);
696
738
  }
697
739
  }
698
- return {
740
+ return withObjectMetadata(unwrappedSchema, {
699
741
  type: "object",
700
742
  properties,
701
743
  required
702
- };
744
+ });
703
745
  }
704
746
  }
705
747
  }
@@ -804,6 +846,52 @@ async function assertCommandRequirements(command, context, options = {}) {
804
846
  }
805
847
  }
806
848
 
849
+ // packages/cmdkit/src/number-schema.ts
850
+ function isValidNumberSchemaValue(value, schema) {
851
+ return typeof value === "number" && Number.isFinite(value) && (schema.jsonType !== "integer" || Number.isInteger(value));
852
+ }
853
+ function getExpectedNumberDescription(schema) {
854
+ return schema.jsonType === "integer" ? "an integer" : "a number";
855
+ }
856
+
857
+ // packages/cmdkit/src/schema-scope.ts
858
+ function filterSchemaForScope(schema, scope) {
859
+ if (schema.scope !== void 0 && !schema.scope.includes(scope)) {
860
+ return void 0;
861
+ }
862
+ switch (schema.kind) {
863
+ case "optional": {
864
+ const inner = filterSchemaForScope(schema.inner, scope);
865
+ if (inner === void 0) {
866
+ return void 0;
867
+ }
868
+ if (inner.requiredScopes?.includes(scope)) {
869
+ return inner;
870
+ }
871
+ return { ...schema, inner };
872
+ }
873
+ case "array": {
874
+ const item = filterSchemaForScope(schema.item, scope);
875
+ return item === void 0 ? void 0 : { ...schema, item };
876
+ }
877
+ case "string":
878
+ case "number":
879
+ case "boolean":
880
+ case "enum":
881
+ return schema;
882
+ case "object":
883
+ return {
884
+ ...schema,
885
+ shape: Object.fromEntries(
886
+ Object.entries(schema.shape).flatMap(([key, childSchema]) => {
887
+ const filtered = filterSchemaForScope(childSchema, scope);
888
+ return filtered === void 0 ? [] : [[key, filtered]];
889
+ })
890
+ )
891
+ };
892
+ }
893
+ }
894
+
807
895
  // packages/cmdkit/src/mcp.ts
808
896
  var RESERVED_SERVICE_NAMES = /* @__PURE__ */ new Set(["params", "secrets", "fetch", "fs", "env", "progress"]);
809
897
  function normalizeRoots(roots) {
@@ -938,25 +1026,28 @@ function collectParamSummaries(schema, casing, path = [], inheritedOptional = fa
938
1026
  }
939
1027
  return summaries;
940
1028
  }
941
- function buildToolDescription(command, casing) {
942
- const summary = collectParamSummaries(command.params, casing);
1029
+ function buildToolDescription(description, params, casing) {
1030
+ const summary = collectParamSummaries(params, casing);
943
1031
  const parameterSummary = summary.length === 0 ? "" : `Parameters: ${summary.join(", ")}.`;
944
- if (command.description === void 0) {
1032
+ if (description === void 0) {
945
1033
  return parameterSummary;
946
1034
  }
947
1035
  if (parameterSummary.length === 0) {
948
- return command.description;
1036
+ return description;
949
1037
  }
950
- return `${command.description} ${parameterSummary}`;
1038
+ return `${description} ${parameterSummary}`;
951
1039
  }
952
1040
  function matchesAllowlist(toolName, allowlist) {
953
1041
  if (allowlist === void 0) {
954
1042
  return true;
955
1043
  }
956
- const segments = toolName.split(".");
957
- const candidates = segments.map((_segment, index) => segments.slice(0, index + 1).join("."));
1044
+ const segments = toolName.split("__");
1045
+ const candidates = segments.map((_segment, index) => segments.slice(0, index + 1).join("__"));
958
1046
  return candidates.some((candidate) => allowlist.includes(candidate));
959
1047
  }
1048
+ function formatToolName(path) {
1049
+ return path.map((segment) => formatSegment(segment, "snake")).join("__");
1050
+ }
960
1051
  function enumerateTools(root, casing, allowlist) {
961
1052
  const tools = [];
962
1053
  function visit(node, path) {
@@ -964,15 +1055,19 @@ function enumerateTools(root, casing, allowlist) {
964
1055
  if (!node.scope.includes("mcp")) {
965
1056
  return;
966
1057
  }
967
- const name = [...path, node.name].join(".");
1058
+ const name = formatToolName([...path, node.name]);
1059
+ const params = filterSchemaForScope(node.params, "mcp");
968
1060
  if (!matchesAllowlist(name, allowlist)) {
969
1061
  return;
970
1062
  }
1063
+ if (params === void 0 || params.kind !== "object") {
1064
+ throw new Error(`Bug: command "${name}" must define an object params schema for MCP.`);
1065
+ }
971
1066
  tools.push({
972
1067
  command: node,
973
1068
  name,
974
- description: buildToolDescription(node, casing),
975
- inputSchema: applySchemaCasing(toJsonSchema(node.params), casing)
1069
+ description: buildToolDescription(node.description, params, casing),
1070
+ inputSchema: applySchemaCasing(toJsonSchema(params), casing)
976
1071
  });
977
1072
  return;
978
1073
  }
@@ -981,8 +1076,9 @@ function enumerateTools(root, casing, allowlist) {
981
1076
  visit(child, nextPath);
982
1077
  }
983
1078
  }
1079
+ const rootPath = root.name.length === 0 ? [] : [root.name];
984
1080
  for (const child of root.children) {
985
- visit(child, []);
1081
+ visit(child, rootPath);
986
1082
  }
987
1083
  return tools;
988
1084
  }
@@ -996,6 +1092,9 @@ function validateEnum(value, schema, label) {
996
1092
  }
997
1093
  function validateSchemaValue(schema, value, casing, label) {
998
1094
  const unwrappedSchema = unwrapOptional2(schema);
1095
+ if (value === null && unwrappedSchema.nullable === true) {
1096
+ return null;
1097
+ }
999
1098
  switch (unwrappedSchema.kind) {
1000
1099
  case "string":
1001
1100
  if (typeof value !== "string") {
@@ -1003,8 +1102,10 @@ function validateSchemaValue(schema, value, casing, label) {
1003
1102
  }
1004
1103
  return value;
1005
1104
  case "number":
1006
- if (typeof value !== "number" || !Number.isFinite(value)) {
1007
- throw new UserError(`Invalid value for "${label}". Expected a number.`);
1105
+ if (!isValidNumberSchemaValue(value, unwrappedSchema)) {
1106
+ throw new UserError(
1107
+ `Invalid value for "${label}". Expected ${getExpectedNumberDescription(unwrappedSchema)}.`
1108
+ );
1008
1109
  }
1009
1110
  return value;
1010
1111
  case "boolean":