bpmax-cli 0.1.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.
- package/README.md +33 -0
- package/dist/bin.js +1258 -0
- package/dist/bin.js.map +1 -0
- package/package.json +39 -0
- package/scripts/install-skills.mjs +128 -0
- package/skills/bpmax-auth/SKILL.md +53 -0
- package/skills/bpmax-cli/SKILL.md +27 -0
- package/skills/bpmax-flow/SKILL.md +39 -0
- package/skills/bpmax-project/SKILL.md +51 -0
- package/skills/bpmax-schema/SKILL.md +32 -0
- package/skills/bpmax-shared/SKILL.md +103 -0
- package/skills/bpmax-user/SKILL.md +31 -0
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bin.ts","../src/core/config.ts","../src/core/http.ts","../src/core/output.ts","../src/commands/api.ts","../src/core/auth.ts","../src/commands/auth.ts","../src/commands/config.ts","../src/commands/flow.ts","../src/commands/project.ts","../src/core/manifest.ts","../src/commands/schema.ts","../package.json","../src/core/build.ts","../src/core/skills.ts","../src/core/process.ts","../src/core/update.ts","../src/commands/update.ts","../src/commands/user.ts","../src/core/notices.ts"],"sourcesContent":["import { Command } from 'commander';\n\nimport { registerApiCommands } from './commands/api.js';\nimport { registerAuthCommands } from './commands/auth.js';\nimport { registerConfigCommands } from './commands/config.js';\nimport { registerFlowCommands } from './commands/flow.js';\nimport { registerProjectCommands } from './commands/project.js';\nimport { registerSchemaCommands } from './commands/schema.js';\nimport { registerUpdateCommands } from './commands/update.js';\nimport { registerUserCommands } from './commands/user.js';\nimport { CLI_NAME, VERSION } from './core/build.js';\nimport { setupNotices } from './core/notices.js';\n\nconst program = new Command();\n\nprogram\n .name(CLI_NAME)\n .description('BPMAX multi-environment CLI')\n .version(VERSION);\n\nregisterConfigCommands(program);\nregisterAuthCommands(program);\nregisterApiCommands(program);\nregisterSchemaCommands(program);\nregisterUserCommands(program);\nregisterFlowCommands(program);\nregisterProjectCommands(program);\nregisterUpdateCommands(program);\n\nconst isCompletion = process.argv.includes('completion') || process.argv.includes('__complete');\n\n(isCompletion ? Promise.resolve() : setupNotices())\n .then(() => program.parseAsync(process.argv))\n .catch((error) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n });\n","import { homedir } from 'node:os';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport type {\n AnyConfigFile,\n ConfigFileV2,\n LegacyConfigFile,\n ProfileConfig,\n ResolvedProfile,\n} from './types.js';\n\nexport const DEFAULT_WORKSPACE = 'default';\nexport const DEFAULT_LANGUAGE = 'zhCN';\n\nconst CONFIG_DIR = path.join(homedir(), '.bpmax');\nconst CONFIG_PATH = path.join(CONFIG_DIR, 'config.json');\n\nconst defaultConfig = (): ConfigFileV2 => ({\n version: 2,\n current_profile: 'default',\n profiles: {\n default: {\n origin: '',\n workspace: DEFAULT_WORKSPACE,\n language: DEFAULT_LANGUAGE,\n },\n },\n});\n\nconst normalizeOrigin = (origin: string): string => origin.trim().replace(/\\/+$/, '');\n\nconst isV2Config = (input: AnyConfigFile): input is ConfigFileV2 =>\n typeof input === 'object' &&\n input !== null &&\n 'version' in input &&\n (input as ConfigFileV2).version === 2 &&\n 'profiles' in input;\n\nconst toV2Config = (input: AnyConfigFile): ConfigFileV2 => {\n if (isV2Config(input)) {\n return {\n version: 2,\n current_profile: input.current_profile || 'default',\n profiles: Object.fromEntries(\n Object.entries(input.profiles || {}).map(([name, profile]) => [\n name,\n {\n ...profile,\n origin: normalizeOrigin(profile.origin || ''),\n workspace: profile.workspace || DEFAULT_WORKSPACE,\n language: profile.language || DEFAULT_LANGUAGE,\n },\n ]),\n ),\n };\n }\n\n const legacy = input as LegacyConfigFile;\n const migrated = defaultConfig();\n migrated.profiles.default = {\n origin: normalizeOrigin(legacy.host || ''),\n api_key: legacy.api_key || '',\n workspace: DEFAULT_WORKSPACE,\n language: DEFAULT_LANGUAGE,\n };\n return migrated;\n};\n\nexport async function loadConfig(): Promise<ConfigFileV2> {\n try {\n const raw = await readFile(CONFIG_PATH, 'utf8');\n const parsed = JSON.parse(raw) as AnyConfigFile;\n return toV2Config(parsed);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return defaultConfig();\n }\n throw error;\n }\n}\n\nexport async function saveConfig(config: ConfigFileV2): Promise<void> {\n await mkdir(CONFIG_DIR, { recursive: true });\n await writeFile(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\\n`, 'utf8');\n}\n\nexport function getConfigPath(): string {\n return CONFIG_PATH;\n}\n\nexport function getConfigDir(): string {\n return CONFIG_DIR;\n}\n\nexport function maskApiKey(apiKey?: string): string {\n if (!apiKey) {\n return '(unset)';\n }\n if (apiKey.length <= 10) {\n return apiKey;\n }\n return `${apiKey.slice(0, 8)}****${apiKey.slice(-4)}`;\n}\n\nexport function ensureProfile(config: ConfigFileV2, profileName: string): ProfileConfig {\n const profile = config.profiles[profileName];\n if (!profile) {\n throw new Error(`Profile \"${profileName}\" not found.`);\n }\n return profile;\n}\n\nexport function resolveProfile(config: ConfigFileV2, profileName?: string): ResolvedProfile {\n const name = profileName || config.current_profile || 'default';\n const profile = ensureProfile(config, name);\n\n if (!profile.origin) {\n throw new Error(`Profile \"${name}\" has no origin configured.`);\n }\n\n return {\n name,\n config: {\n origin: normalizeOrigin(profile.origin),\n api_key: profile.api_key,\n workspace: profile.workspace || DEFAULT_WORKSPACE,\n language: profile.language || DEFAULT_LANGUAGE,\n user: profile.user,\n },\n };\n}\n\nexport async function upsertProfile(name: string, nextProfile: ProfileConfig): Promise<ConfigFileV2> {\n const config = await loadConfig();\n config.profiles[name] = {\n ...config.profiles[name],\n ...nextProfile,\n origin: normalizeOrigin(nextProfile.origin || config.profiles[name]?.origin || ''),\n workspace: nextProfile.workspace || config.profiles[name]?.workspace || DEFAULT_WORKSPACE,\n language: nextProfile.language || config.profiles[name]?.language || DEFAULT_LANGUAGE,\n };\n if (!config.current_profile) {\n config.current_profile = name;\n }\n await saveConfig(config);\n return config;\n}\n","import axios, { AxiosHeaders, type AxiosInstance } from 'axios';\n\nimport type { ApiEnvelope, ResolvedProfile } from './types.js';\n\nconst ensureApiPath = (path: string): string => {\n if (!path.startsWith('/')) {\n path = `/${path}`;\n }\n if (path.startsWith('/api/')) {\n return path;\n }\n return `/api${path}`;\n};\n\nexport function createApiClient(profile: ResolvedProfile): AxiosInstance {\n const instance = axios.create({\n baseURL: profile.config.origin,\n withCredentials: false,\n });\n\n instance.interceptors.request.use((config) => {\n config.params = {\n ...(config.params || {}),\n $workspace: config.params?.$workspace ?? profile.config.workspace,\n $language: config.params?.$language ?? profile.config.language,\n };\n if (profile.config.api_key) {\n const headers = AxiosHeaders.from(config.headers || {});\n headers.set('Authorization', `Bearer ${profile.config.api_key}`);\n config.headers = headers;\n }\n return config;\n });\n\n return instance;\n}\n\nexport async function apiRequest<T>(\n client: AxiosInstance,\n method: string,\n path: string,\n options: {\n params?: Record<string, unknown>;\n data?: unknown;\n } = {},\n): Promise<T> {\n const response = await client.request<ApiEnvelope<T>>({\n method,\n url: ensureApiPath(path),\n params: options.params,\n data: options.data,\n });\n const body = response.data;\n if (body.code !== 0) {\n throw new Error(body.msg || `Request failed with code ${body.code}`);\n }\n return (body.data ?? body) as T;\n}\n","import type { OutputFormat } from './types.js';\n\ntype NoticeValue = Record<string, unknown>;\ntype NoticeProvider = () => Record<string, NoticeValue> | null;\n\nlet noticeProvider: NoticeProvider | null = null;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport function setNoticeProvider(provider: NoticeProvider): void {\n noticeProvider = provider;\n}\n\nexport function clearNoticeProvider(): void {\n noticeProvider = null;\n}\n\nfunction currentNotice(): Record<string, NoticeValue> | null {\n return noticeProvider?.() || null;\n}\n\nfunction withJsonNotice(value: unknown): unknown {\n const notice = currentNotice();\n if (!notice || Object.keys(notice).length === 0) {\n return value;\n }\n if (isRecord(value)) {\n return { ...value, _notice: notice };\n }\n return value;\n}\n\nfunction emitTextNotice(): void {\n const notice = currentNotice();\n if (!notice) {\n return;\n }\n Object.values(notice).forEach((entry) => {\n if (typeof entry.message === 'string') {\n console.error(entry.message);\n }\n });\n}\n\nexport function printResult(format: OutputFormat, value: unknown): void {\n switch (format) {\n case 'json':\n console.log(JSON.stringify(withJsonNotice(value), null, 2));\n return;\n case 'ndjson':\n if (Array.isArray(value)) {\n value.forEach((item) => {\n console.log(JSON.stringify(item));\n });\n } else {\n console.log(JSON.stringify(value));\n }\n return;\n case 'table':\n if (Array.isArray(value)) {\n console.table(value);\n } else if (isRecord(value)) {\n console.table([value]);\n } else {\n console.log(value);\n }\n return;\n case 'pretty':\n default:\n emitTextNotice();\n if (typeof value === 'string') {\n console.log(value);\n return;\n }\n console.log(JSON.stringify(value, null, 2));\n }\n}\n","import type { Command } from 'commander';\n\nimport { loadConfig, resolveProfile } from '../core/config.js';\nimport { createApiClient, apiRequest } from '../core/http.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat } from '../core/types.js';\n\nfunction parseJson(input?: string): unknown {\n if (!input) {\n return undefined;\n }\n return JSON.parse(input);\n}\n\nexport function registerApiCommands(program: Command): void {\n program\n .command('api <method> <path>')\n .description('Call an arbitrary BPMAX /api endpoint')\n .option('--profile <profile>', 'Profile name')\n .option('--params <json>', 'Query params JSON')\n .option('--data <json>', 'Request body JSON')\n .option('--format <format>', 'Output format', 'json')\n .action(async (method: string, path: string, options: {\n profile?: string;\n params?: string;\n data?: string;\n format: OutputFormat;\n }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<unknown>(createApiClient(profile), method, path, {\n params: parseJson(options.params) as Record<string, unknown> | undefined,\n data: parseJson(options.data),\n });\n printResult(options.format, result);\n });\n}\n","import { createServer } from 'node:http';\nimport { randomBytes } from 'node:crypto';\n\nimport open from 'open';\n\nimport type { CallbackPayload, ProfileConfig, UserSummary } from './types.js';\n\nexport interface LoginResult {\n apiKey: string;\n user?: UserSummary;\n}\n\nfunction buildBridgeUrl(\n origin: string,\n workspace: string,\n params: Record<string, string>,\n): string {\n const query = new URLSearchParams(params);\n return `${origin}/${encodeURIComponent(workspace)}/cli-login?${query.toString()}`;\n}\n\nexport async function runBrowserLogin(options: {\n origin: string;\n workspace: string;\n profileName: string;\n apiKeyName: string;\n timeoutMs?: number;\n}): Promise<LoginResult & { state: string }> {\n const state = randomBytes(16).toString('hex');\n const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;\n\n return await new Promise((resolve, reject) => {\n const server = createServer(async (req, res) => {\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n res.statusCode = 204;\n res.end();\n return;\n }\n\n if (req.method !== 'POST' || req.url !== '/callback') {\n res.statusCode = 404;\n res.end(JSON.stringify({ ok: false, message: 'Not found' }));\n return;\n }\n\n let raw = '';\n req.on('data', (chunk) => {\n raw += chunk.toString();\n });\n req.on('end', () => {\n try {\n const payload = JSON.parse(raw) as CallbackPayload;\n if (payload.state !== state) {\n res.statusCode = 400;\n res.end(JSON.stringify({ ok: false, message: 'Invalid state' }));\n return;\n }\n if (!payload.api_key) {\n res.statusCode = 400;\n res.end(JSON.stringify({ ok: false, message: 'Missing api_key' }));\n return;\n }\n res.statusCode = 200;\n res.end(JSON.stringify({ ok: true }));\n clearTimeout(timer);\n server.close();\n resolve({ apiKey: payload.api_key, user: payload.user, state });\n } catch (error) {\n res.statusCode = 400;\n res.end(\n JSON.stringify({\n ok: false,\n message: error instanceof Error ? error.message : 'Invalid callback payload',\n }),\n );\n }\n });\n req.on('error', reject);\n });\n\n server.listen(0, '127.0.0.1', async () => {\n const address = server.address();\n if (!address || typeof address === 'string') {\n reject(new Error('Failed to allocate local callback port.'));\n return;\n }\n const callbackUrl = `http://127.0.0.1:${address.port}/callback`;\n const bridgeUrl = buildBridgeUrl(options.origin, options.workspace, {\n callback: callbackUrl,\n state,\n profile: options.profileName,\n key_name: options.apiKeyName,\n });\n await open(bridgeUrl);\n });\n\n server.on('error', reject);\n\n const timer = setTimeout(() => {\n server.close();\n reject(new Error('Timed out waiting for browser login callback.'));\n }, timeoutMs);\n });\n}\n\nexport function updateProfileAuth(profile: ProfileConfig, result: LoginResult): ProfileConfig {\n return {\n ...profile,\n api_key: result.apiKey,\n user: result.user,\n };\n}\n","import type { Command } from 'commander';\n\nimport { loadConfig, maskApiKey, resolveProfile, saveConfig } from '../core/config.js';\nimport { runBrowserLogin, updateProfileAuth } from '../core/auth.js';\nimport { createApiClient, apiRequest } from '../core/http.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat } from '../core/types.js';\n\nexport function registerAuthCommands(program: Command): void {\n const auth = program.command('auth').description('Authenticate and manage API key state');\n\n auth\n .command('login')\n .description('Open the hpt-frontend bridge page and persist the returned API key')\n .option('--profile <profile>', 'Profile name')\n .option('--key-name <keyName>', 'Target API key name', 'bpmax-cli')\n .action(async (options: { profile?: string; keyName: string }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await runBrowserLogin({\n origin: profile.config.origin,\n workspace: profile.config.workspace,\n profileName: profile.name,\n apiKeyName: options.keyName,\n });\n config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);\n await saveConfig(config);\n console.log(`Saved API key for profile \"${profile.name}\".`);\n });\n\n auth\n .command('status')\n .description('Show saved auth state and validate /api/user/current')\n .option('--profile <profile>', 'Profile name')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (options: { profile?: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const output: Record<string, unknown> = {\n profile: profile.name,\n origin: profile.config.origin,\n workspace: profile.config.workspace,\n language: profile.config.language,\n api_key: maskApiKey(profile.config.api_key),\n };\n\n if (profile.config.api_key) {\n try {\n const currentUser = await apiRequest<Record<string, unknown>>(\n createApiClient(profile),\n 'GET',\n '/user/current',\n );\n output.user = currentUser;\n output.authenticated = true;\n } catch (error) {\n output.authenticated = false;\n output.error = error instanceof Error ? error.message : String(error);\n }\n } else {\n output.authenticated = false;\n }\n\n printResult(options.format, output);\n });\n\n auth\n .command('logout')\n .description('Clear the stored API key for the selected profile')\n .option('--profile <profile>', 'Profile name')\n .action(async (options: { profile?: string }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n config.profiles[profile.name] = {\n ...config.profiles[profile.name],\n api_key: '',\n user: undefined,\n };\n await saveConfig(config);\n console.log(`Cleared API key for profile \"${profile.name}\".`);\n });\n}\n","import { text } from '@clack/prompts';\nimport type { Command } from 'commander';\n\nimport {\n DEFAULT_LANGUAGE,\n DEFAULT_WORKSPACE,\n getConfigPath,\n loadConfig,\n maskApiKey,\n saveConfig,\n upsertProfile,\n} from '../core/config.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat, ProfileConfig } from '../core/types.js';\n\nasync function ensureValue(current: string | undefined, label: string, placeholder?: string): Promise<string> {\n if (current) {\n return current;\n }\n const result = await text({\n message: label,\n placeholder,\n });\n if (typeof result !== 'string' || !result.trim()) {\n throw new Error(`${label} is required.`);\n }\n return result.trim();\n}\n\nexport function registerConfigCommands(program: Command): void {\n const config = program.command('config').description('Manage local bpmax-cli profiles');\n const profile = config.command('profile').description('Manage named environment profiles');\n\n profile\n .command('add')\n .description('Add or update a profile')\n .option('--name <name>', 'Profile name')\n .option('--origin <origin>', 'Profile origin')\n .option('--api-key <apiKey>', 'API key')\n .option('--workspace <workspace>', 'Default workspace', DEFAULT_WORKSPACE)\n .option('--language <language>', 'Default language', DEFAULT_LANGUAGE)\n .action(async (options) => {\n const name = await ensureValue(options.name, 'Profile name', 'default');\n const origin = await ensureValue(options.origin, 'Origin', 'https://example.com');\n await upsertProfile(name, {\n origin,\n api_key: options.apiKey,\n workspace: options.workspace,\n language: options.language,\n });\n console.log(`Saved profile \"${name}\" to ${getConfigPath()}.`);\n });\n\n profile\n .command('list')\n .description('List profiles')\n .option('--format <format>', 'Output format', 'table')\n .action(async (options: { format: OutputFormat }) => {\n const configData = await loadConfig();\n const rows = Object.entries(configData.profiles).map(([name, profileConfig]) => ({\n name,\n current: configData.current_profile === name,\n origin: profileConfig.origin,\n workspace: profileConfig.workspace || DEFAULT_WORKSPACE,\n language: profileConfig.language || DEFAULT_LANGUAGE,\n api_key: maskApiKey(profileConfig.api_key),\n }));\n printResult(options.format, rows);\n });\n\n profile\n .command('use <name>')\n .description('Set the active profile')\n .action(async (name: string) => {\n const configData = await loadConfig();\n if (!configData.profiles[name]) {\n throw new Error(`Profile \"${name}\" not found.`);\n }\n configData.current_profile = name;\n await saveConfig(configData);\n console.log(`Current profile set to \"${name}\".`);\n });\n\n profile\n .command('remove <name>')\n .description('Remove a profile')\n .action(async (name: string) => {\n const configData = await loadConfig();\n if (!configData.profiles[name]) {\n throw new Error(`Profile \"${name}\" not found.`);\n }\n delete configData.profiles[name];\n if (configData.current_profile === name) {\n const [nextProfile] = Object.keys(configData.profiles);\n configData.current_profile = nextProfile || 'default';\n }\n await saveConfig(configData);\n console.log(`Removed profile \"${name}\".`);\n });\n\n profile\n .command('show')\n .description('Show a profile')\n .option('--profile <profile>', 'Profile name')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (options: { profile?: string; format: OutputFormat }) => {\n const configData = await loadConfig();\n const name = options.profile || configData.current_profile;\n const target = configData.profiles[name];\n if (!target) {\n throw new Error(`Profile \"${name}\" not found.`);\n }\n printResult(options.format, {\n name,\n config_path: getConfigPath(),\n origin: target.origin,\n workspace: target.workspace || DEFAULT_WORKSPACE,\n language: target.language || DEFAULT_LANGUAGE,\n api_key: maskApiKey(target.api_key),\n user: target.user || null,\n });\n });\n}\n","import type { Command } from 'commander';\n\nimport { loadConfig, resolveProfile } from '../core/config.js';\nimport { createApiClient, apiRequest } from '../core/http.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat } from '../core/types.js';\n\nexport function registerFlowCommands(program: Command): void {\n const flow = program.command('flow').description('Flow commands');\n\n flow\n .command('list')\n .description('List flows')\n .option('--profile <profile>', 'Profile name')\n .option('--draft <draft>', 'Draft flag', '1')\n .option('--format <format>', 'Output format', 'table')\n .action(async (options: { profile?: string; draft: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<unknown[]>(\n createApiClient(profile),\n 'GET',\n '/flow/flow_type',\n {\n params: {\n draft: options.draft,\n skip_i18n: 'true',\n },\n },\n );\n printResult(options.format, result);\n });\n\n flow\n .command('options')\n .description('List flow options')\n .option('--profile <profile>', 'Profile name')\n .option('--name <name>', 'Flow name filter')\n .option('--format <format>', 'Output format', 'table')\n .action(async (options: { profile?: string; name?: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<unknown[]>(\n createApiClient(profile),\n 'GET',\n '/flow/options',\n {\n params: options.name ? { name: options.name } : undefined,\n },\n );\n printResult(options.format, result);\n });\n\n flow\n .command('get')\n .description('Get flow detail by id')\n .requiredOption('--id <id>', 'Flow id')\n .option('--profile <profile>', 'Profile name')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (options: { id: string; profile?: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<unknown[]>(\n createApiClient(profile),\n 'POST',\n '/flow/batch_get',\n {\n data: {\n ids: [Number(options.id)],\n },\n },\n );\n printResult(options.format, result[0] ?? null);\n });\n}\n","import type { Command } from 'commander';\n\nimport { loadConfig, resolveProfile } from '../core/config.js';\nimport { createApiClient, apiRequest } from '../core/http.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat } from '../core/types.js';\n\nfunction parseJson(input?: string): Record<string, unknown> {\n if (!input) {\n return {};\n }\n return JSON.parse(input) as Record<string, unknown>;\n}\n\nasync function resolveFlowIdentifiers(\n client: ReturnType<typeof createApiClient>,\n options: { flowId?: string; flowType?: string; flowKey?: string },\n): Promise<{ flow_type: string; flow_key: string }> {\n if (options.flowType && options.flowKey !== undefined) {\n return {\n flow_type: options.flowType,\n flow_key: options.flowKey,\n };\n }\n\n if (!options.flowId) {\n throw new Error('Either --flow-id or both --flow-type and --flow-key are required.');\n }\n\n const flows = await apiRequest<Array<Record<string, unknown>>>(\n client,\n 'POST',\n '/flow/batch_get',\n {\n data: { ids: [Number(options.flowId)] },\n },\n );\n const flow = flows[0];\n if (!flow) {\n throw new Error(`Flow ${options.flowId} not found.`);\n }\n return {\n flow_type: String(flow.flow_type || 'default'),\n flow_key: String(flow.key || ''),\n };\n}\n\nexport function registerProjectCommands(program: Command): void {\n const project = program.command('project').description('Project commands');\n\n project\n .command('list')\n .description('List projects')\n .option('--profile <profile>', 'Profile name')\n .option('--page <page>', 'Page number', '1')\n .option('--page-size <pageSize>', 'Page size', '20')\n .option('--body <json>', 'Project list body JSON', '{}')\n .option('--format <format>', 'Output format', 'table')\n .action(async (options: {\n profile?: string;\n page: string;\n pageSize: string;\n body: string;\n format: OutputFormat;\n }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<Record<string, unknown>>(\n createApiClient(profile),\n 'POST',\n '/project/list',\n {\n params: {\n page: Number(options.page),\n page_size: Number(options.pageSize),\n },\n data: parseJson(options.body),\n },\n );\n printResult(options.format, result);\n });\n\n project\n .command('get <id>')\n .description('Get project detail')\n .option('--profile <profile>', 'Profile name')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (id: string, options: { profile?: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<Record<string, unknown>>(\n createApiClient(profile),\n 'GET',\n `/project/${id}`,\n );\n printResult(options.format, result);\n });\n\n project\n .command('my-step')\n .description('List my pending project steps')\n .option('--profile <profile>', 'Profile name')\n .option('--finished <finished>', 'Finished flag', '0')\n .option('--page <page>', 'Page number', '1')\n .option('--page-size <pageSize>', 'Page size', '20')\n .option('--format <format>', 'Output format', 'table')\n .action(async (options: {\n profile?: string;\n finished: string;\n page: string;\n pageSize: string;\n format: OutputFormat;\n }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<Record<string, unknown>>(\n createApiClient(profile),\n 'GET',\n '/project/my_step',\n {\n params: {\n finished: options.finished,\n page: Number(options.page),\n page_size: Number(options.pageSize),\n },\n },\n );\n printResult(options.format, result);\n });\n\n project\n .command('create')\n .description('Minimal project create shortcut')\n .option('--profile <profile>', 'Profile name')\n .option('--flow-id <flowId>', 'Flow id')\n .option('--flow-type <flowType>', 'Flow type')\n .option('--flow-key <flowKey>', 'Flow key')\n .option('--name <name>', 'Project name')\n .option('--json <json>', 'Additional request JSON')\n .option('--body <body>', 'Full request body JSON override')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (options: {\n profile?: string;\n flowId?: string;\n flowType?: string;\n flowKey?: string;\n name?: string;\n json?: string;\n body?: string;\n format: OutputFormat;\n }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const client = createApiClient(profile);\n\n let payload = parseJson(options.body);\n if (!options.body) {\n if (!options.name) {\n throw new Error('--name is required unless --body is provided.');\n }\n const flow = await resolveFlowIdentifiers(client, options);\n const extra = parseJson(options.json);\n const form =\n typeof extra.form === 'object' && extra.form !== null && !Array.isArray(extra.form)\n ? (extra.form as Record<string, unknown>)\n : {};\n payload = {\n ...extra,\n ...flow,\n name: options.name,\n workspace: profile.config.workspace,\n form,\n };\n }\n\n const result = await apiRequest<Record<string, unknown>>(\n client,\n 'POST',\n '/project/open-api/create',\n {\n data: payload,\n },\n );\n printResult(options.format, result);\n });\n}\n","import type { SchemaEntry } from './types.js';\n\nexport const schemaEntries: SchemaEntry[] = [\n { name: 'auth.login', description: 'Open hpt-frontend bridge page and persist API key locally.' },\n { name: 'auth.status', description: 'Show current profile status and validate /api/user/current.' },\n { name: 'auth.logout', description: 'Clear the saved API key for the selected profile.' },\n { name: 'user.current', description: 'Get current user.', method: 'GET', path: '/api/user/current' },\n { name: 'flow.list', description: 'List flows.', method: 'GET', path: '/api/flow/flow_type' },\n { name: 'flow.options', description: 'List flow options.', method: 'GET', path: '/api/flow/options' },\n { name: 'flow.get', description: 'Fetch flow details by id.', method: 'POST', path: '/api/flow/batch_get' },\n { name: 'project.list', description: 'List projects.', method: 'POST', path: '/api/project/list' },\n { name: 'project.get', description: 'Get project detail.', method: 'GET', path: '/api/project/:id' },\n { name: 'project.my-step', description: 'List my pending steps.', method: 'GET', path: '/api/project/my_step' },\n { name: 'project.create', description: 'Minimal project create shortcut.', method: 'POST', path: '/api/project/open-api/create' },\n];\n","import type { Command } from 'commander';\n\nimport { printResult } from '../core/output.js';\nimport { schemaEntries } from '../core/manifest.js';\nimport type { OutputFormat } from '../core/types.js';\n\nexport function registerSchemaCommands(program: Command): void {\n const schema = program.command('schema').description('Inspect built-in bpmax-cli schema metadata');\n\n schema\n .command('list')\n .description('List known command and endpoint mappings')\n .option('--format <format>', 'Output format', 'table')\n .action((options: { format: OutputFormat }) => {\n printResult(options.format, schemaEntries);\n });\n\n schema\n .command('show <name>')\n .description('Show a single schema entry')\n .option('--format <format>', 'Output format', 'pretty')\n .action((name: string, options: { format: OutputFormat }) => {\n const entry = schemaEntries.find((item) => item.name === name);\n if (!entry) {\n throw new Error(`Schema entry \"${name}\" not found.`);\n }\n printResult(options.format, entry);\n });\n}\n","{\n \"name\": \"bpmax-cli\",\n \"version\": \"0.1.0\",\n \"description\": \"CLI for BPMAX environments with multi-profile config and local login callback flow\",\n \"type\": \"module\",\n \"bin\": {\n \"bpmax-cli\": \"dist/bin.js\"\n },\n \"files\": [\n \"dist\",\n \"scripts/install-skills.mjs\",\n \"skills\",\n \"README.md\"\n ],\n \"scripts\": {\n \"postinstall\": \"node scripts/install-skills.mjs\",\n \"build\": \"tsup\",\n \"dev\": \"tsx src/bin.ts\",\n \"install:skills\": \"node scripts/install-skills.mjs\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"engines\": {\n \"node\": \">=18\"\n },\n \"dependencies\": {\n \"@clack/prompts\": \"^1.2.0\",\n \"axios\": \"^1.9.0\",\n \"commander\": \"^14.0.0\",\n \"open\": \"^10.1.2\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.15.17\",\n \"tsup\": \"^8.5.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.8.3\",\n \"vitest\": \"^3.1.3\"\n }\n}\n","import packageJson from '../../package.json' with { type: 'json' };\n\nexport const CLI_NAME = 'bpmax-cli';\nexport const VERSION = packageJson.version;\nexport const NPM_PACKAGE = 'bpmax-cli';\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { getConfigDir } from './config.js';\nimport { runCommand, type CommandRunner, type RunResult } from './process.js';\n\nconst SKILLS_STAMP_FILE = 'skills.stamp';\nconst SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1000;\n\nexport interface SkillsStatus {\n current: string;\n target: string;\n inSync: boolean;\n}\n\nfunction stampPath(configDir = getConfigDir()): string {\n return path.join(configDir, SKILLS_STAMP_FILE);\n}\n\nexport async function readSkillsStamp(configDir = getConfigDir()): Promise<string> {\n try {\n return (await readFile(stampPath(configDir), 'utf8')).trim();\n } catch {\n return '';\n }\n}\n\nexport async function writeSkillsStamp(version: string, configDir = getConfigDir()): Promise<void> {\n await mkdir(configDir, { recursive: true });\n await writeFile(stampPath(configDir), version, 'utf8');\n}\n\nexport async function checkSkillsSync(currentVersion: string, configDir = getConfigDir()): Promise<SkillsStatus> {\n if (process.env.BPMAX_CLI_NO_SKILLS_NOTIFIER) {\n return { current: currentVersion, target: currentVersion, inSync: true };\n }\n const current = await readSkillsStamp(configDir);\n return { current, target: currentVersion, inSync: current === currentVersion };\n}\n\nfunction defaultPackageRoot(): string {\n return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');\n}\n\nexport async function runSkillsInstall(\n options: { packageRoot?: string; runner?: CommandRunner } = {},\n): Promise<RunResult> {\n const runner = options.runner || runCommand;\n return runner(process.execPath, [path.join(options.packageRoot || defaultPackageRoot(), 'scripts', 'install-skills.mjs')], {\n timeoutMs: SKILLS_INSTALL_TIMEOUT_MS,\n });\n}\n\nexport async function syncSkills(\n version: string,\n options: { force?: boolean; configDir?: string; packageRoot?: string; runner?: CommandRunner } = {},\n): Promise<{ action: 'in_sync' | 'synced' | 'failed'; result?: RunResult }> {\n if (!options.force) {\n const status = await checkSkillsSync(version, options.configDir);\n if (status.inSync) {\n return { action: 'in_sync' };\n }\n }\n const result = await runSkillsInstall({ packageRoot: options.packageRoot, runner: options.runner });\n if (result.exitCode === 0) {\n await writeSkillsStamp(version, options.configDir);\n return { action: 'synced', result };\n }\n return { action: 'failed', result };\n}\n","import { spawn } from 'node:child_process';\n\nexport interface RunResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\nexport interface RunOptions {\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n timeoutMs?: number;\n}\n\nexport type CommandRunner = (command: string, args: string[], options?: RunOptions) => Promise<RunResult>;\n\nexport const runCommand: CommandRunner = (command, args, options = {}) =>\n new Promise((resolve) => {\n const child = spawn(command, args, {\n cwd: options.cwd,\n env: options.env,\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n let stdout = '';\n let stderr = '';\n let settled = false;\n const timer =\n options.timeoutMs && options.timeoutMs > 0\n ? setTimeout(() => {\n if (settled) {\n return;\n }\n settled = true;\n child.kill('SIGTERM');\n resolve({\n stdout,\n stderr: `${stderr}${stderr ? '\\n' : ''}Timed out after ${options.timeoutMs}ms`,\n exitCode: 124,\n });\n }, options.timeoutMs)\n : undefined;\n\n child.stdout?.on('data', (chunk) => {\n stdout += String(chunk);\n });\n child.stderr?.on('data', (chunk) => {\n stderr += String(chunk);\n });\n child.on('error', (error) => {\n if (settled) {\n return;\n }\n settled = true;\n if (timer) {\n clearTimeout(timer);\n }\n resolve({ stdout, stderr: `${stderr}${stderr ? '\\n' : ''}${error.message}`, exitCode: 1 });\n });\n child.on('close', (code) => {\n if (settled) {\n return;\n }\n settled = true;\n if (timer) {\n clearTimeout(timer);\n }\n resolve({ stdout, stderr, exitCode: code ?? 1 });\n });\n });\n","import { access, mkdir, readFile, realpath, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { NPM_PACKAGE } from './build.js';\nimport { getConfigDir } from './config.js';\nimport { runCommand, type CommandRunner, type RunResult } from './process.js';\n\nconst DEFAULT_REGISTRY_URL = 'https://registry.npmjs.org/';\nconst UPDATE_STATE_FILE = 'update-state.json';\nconst CACHE_TTL_MS = 24 * 60 * 60 * 1000;\nconst FETCH_TIMEOUT_MS = 5_000;\nconst NPM_INSTALL_TIMEOUT_MS = 10 * 60 * 1000;\n\nexport interface UpdateInfo {\n current: string;\n latest: string;\n}\n\ninterface UpdateState {\n latest_version: string;\n checked_at: number;\n}\n\ninterface FetchLatestOptions {\n packageName?: string;\n env?: NodeJS.ProcessEnv;\n fetchImpl?: typeof fetch;\n}\n\nexport interface DetectInstallInput {\n executablePath?: string;\n npmPath?: string | null;\n}\n\nexport interface InstallDetection {\n method: 'npm' | 'manual';\n resolvedPath: string;\n npmAvailable: boolean;\n}\n\nexport function buildRegistryUrl(packageName = NPM_PACKAGE, env: NodeJS.ProcessEnv = process.env): string {\n const base = env.BPMAX_CLI_REGISTRY_URL || DEFAULT_REGISTRY_URL;\n const normalizedBase = base.endsWith('/') ? base : `${base}/`;\n return new URL(`${encodeURIComponent(packageName).replace('%40', '@')}/latest`, normalizedBase).toString();\n}\n\ninterface ParsedVersion {\n core: [number, number, number];\n prerelease: string[];\n}\n\nfunction parseVersion(version: string): ParsedVersion | null {\n const clean = version.trim().replace(/^v/, '').split('+')[0];\n const [coreText, prereleaseText = ''] = clean.split('-', 2);\n const coreParts = coreText.split('.');\n if (coreParts.length !== 3) {\n return null;\n }\n const core = coreParts.map((part) => {\n if (!/^(0|[1-9]\\d*)$/.test(part)) {\n return Number.NaN;\n }\n return Number(part);\n }) as [number, number, number];\n if (core.some((part) => Number.isNaN(part))) {\n return null;\n }\n if (prereleaseText && !/^(?:0|[1-9]\\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*$/.test(prereleaseText)) {\n return null;\n }\n return { core, prerelease: prereleaseText ? prereleaseText.split('.') : [] };\n}\n\nfunction comparePrerelease(left: string[], right: string[]): number {\n if (left.length === 0 && right.length === 0) {\n return 0;\n }\n if (left.length === 0) {\n return 1;\n }\n if (right.length === 0) {\n return -1;\n }\n const max = Math.max(left.length, right.length);\n for (let index = 0; index < max; index += 1) {\n const a = left[index];\n const b = right[index];\n if (a === undefined) {\n return -1;\n }\n if (b === undefined) {\n return 1;\n }\n const aNumber = /^(0|[1-9]\\d*)$/.test(a) ? Number(a) : null;\n const bNumber = /^(0|[1-9]\\d*)$/.test(b) ? Number(b) : null;\n if (aNumber !== null && bNumber !== null) {\n if (aNumber !== bNumber) {\n return aNumber > bNumber ? 1 : -1;\n }\n continue;\n }\n if (aNumber !== null) {\n return -1;\n }\n if (bNumber !== null) {\n return 1;\n }\n if (a !== b) {\n return a > b ? 1 : -1;\n }\n }\n return 0;\n}\n\nexport function isNewerVersion(candidate: string, current: string): boolean {\n const next = parseVersion(candidate);\n if (!next) {\n return false;\n }\n const existing = parseVersion(current);\n if (!existing) {\n return true;\n }\n for (let index = 0; index < 3; index += 1) {\n if (next.core[index] > existing.core[index]) {\n return true;\n }\n if (next.core[index] < existing.core[index]) {\n return false;\n }\n }\n return comparePrerelease(next.prerelease, existing.prerelease) > 0;\n}\n\nexport async function fetchLatestVersion(options: FetchLatestOptions = {}): Promise<string> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n const fetchImpl = options.fetchImpl || fetch;\n const response = await fetchImpl(buildRegistryUrl(options.packageName, options.env), {\n signal: controller.signal,\n });\n if (!response.ok) {\n throw new Error(`npm registry returned HTTP ${response.status}`);\n }\n const body = (await response.json()) as { version?: unknown };\n if (typeof body.version !== 'string' || !body.version.trim()) {\n throw new Error('npm registry returned an empty version');\n }\n return body.version.trim();\n } finally {\n clearTimeout(timer);\n }\n}\n\nfunction updateStatePath(configDir = getConfigDir()): string {\n return path.join(configDir, UPDATE_STATE_FILE);\n}\n\nasync function readUpdateState(configDir?: string): Promise<UpdateState | null> {\n try {\n const raw = await readFile(updateStatePath(configDir), 'utf8');\n const parsed = JSON.parse(raw) as Partial<UpdateState>;\n if (typeof parsed.latest_version !== 'string' || typeof parsed.checked_at !== 'number') {\n return null;\n }\n return { latest_version: parsed.latest_version, checked_at: parsed.checked_at };\n } catch {\n return null;\n }\n}\n\nasync function writeUpdateState(state: UpdateState, configDir = getConfigDir()): Promise<void> {\n await mkdir(configDir, { recursive: true });\n await writeFile(updateStatePath(configDir), JSON.stringify(state), 'utf8');\n}\n\nexport async function checkCachedUpdate(currentVersion: string, configDir = getConfigDir()): Promise<UpdateInfo | null> {\n if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {\n return null;\n }\n const state = await readUpdateState(configDir);\n if (!state) {\n return null;\n }\n const checkedAtMs = state.checked_at * 1000;\n if (Date.now() - checkedAtMs > CACHE_TTL_MS) {\n return null;\n }\n if (!isNewerVersion(state.latest_version, currentVersion)) {\n return null;\n }\n return { current: currentVersion, latest: state.latest_version };\n}\n\nexport async function refreshUpdateCache(\n currentVersion: string,\n configDir = getConfigDir(),\n options: FetchLatestOptions = {},\n): Promise<UpdateInfo | null> {\n if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {\n return null;\n }\n const state = await readUpdateState(configDir);\n if (state && Date.now() - state.checked_at * 1000 < CACHE_TTL_MS) {\n return isNewerVersion(state.latest_version, currentVersion)\n ? { current: currentVersion, latest: state.latest_version }\n : null;\n }\n const latest = await fetchLatestVersion(options);\n await writeUpdateState({ latest_version: latest, checked_at: Math.floor(Date.now() / 1000) }, configDir);\n return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest } : null;\n}\n\nasync function executablePath(): Promise<string> {\n const candidate = process.argv[1] || '';\n if (!candidate) {\n return '';\n }\n try {\n return await realpath(candidate);\n } catch {\n return candidate;\n }\n}\n\nasync function findNpmPath(): Promise<string | null> {\n const command = process.platform === 'win32' ? 'where' : 'which';\n const result = await runCommand(command, ['npm'], { timeoutMs: 10_000 });\n if (result.exitCode !== 0) {\n return null;\n }\n return result.stdout.split(/\\r?\\n/).find(Boolean)?.trim() || null;\n}\n\nexport function detectInstallMethod(input: DetectInstallInput): InstallDetection {\n const resolvedPath = input.executablePath || '';\n const method = resolvedPath.includes(`node_modules${path.sep}`) || resolvedPath.includes('node_modules/')\n ? 'npm'\n : 'manual';\n return {\n method,\n resolvedPath,\n npmAvailable: method === 'npm' && Boolean(input.npmPath),\n };\n}\n\nexport async function detectCurrentInstallMethod(): Promise<InstallDetection> {\n return detectInstallMethod({\n executablePath: await executablePath(),\n npmPath: await findNpmPath(),\n });\n}\n\nexport async function runNpmInstall(\n version: string,\n options: { packageName?: string; runner?: CommandRunner } = {},\n): Promise<RunResult> {\n const runner = options.runner || runCommand;\n return runner('npm', ['install', '-g', `${options.packageName || NPM_PACKAGE}@${version}`], {\n timeoutMs: NPM_INSTALL_TIMEOUT_MS,\n });\n}\n\nexport async function canAccess(targetPath: string): Promise<boolean> {\n try {\n await access(targetPath);\n return true;\n } catch {\n return false;\n }\n}\n","import type { Command } from 'commander';\n\nimport { NPM_PACKAGE, VERSION } from '../core/build.js';\nimport { checkSkillsSync, syncSkills as syncSkillsDefault, type SkillsStatus } from '../core/skills.js';\nimport {\n detectCurrentInstallMethod,\n fetchLatestVersion,\n isNewerVersion,\n runNpmInstall,\n type InstallDetection,\n} from '../core/update.js';\n\nconst MAX_DETAIL = 2_000;\n\ninterface UpdateCommandDeps {\n fetchLatest?: () => Promise<string>;\n detectInstall?: () => Promise<InstallDetection>;\n install?: (version: string) => Promise<{ stdout: string; stderr: string; exitCode: number }>;\n syncSkills?: (version: string, options: { force: boolean }) => Promise<{ action: 'in_sync' | 'synced' | 'failed'; result?: { stderr: string } }>;\n getSkillsStatus?: () => Promise<SkillsStatus>;\n}\n\ninterface UpdateOptions {\n json?: boolean;\n check?: boolean;\n force?: boolean;\n}\n\nfunction printJson(value: unknown): void {\n console.log(JSON.stringify(value, null, 2));\n}\n\nfunction truncate(value: string): string {\n if (value.length <= MAX_DETAIL) {\n return value;\n }\n return value.slice(value.length - MAX_DETAIL);\n}\n\nfunction manualReason(detect: InstallDetection): string {\n if (detect.method === 'npm' && !detect.npmAvailable) {\n return 'installed via npm, but npm is not available in PATH';\n }\n return 'not installed via npm';\n}\n\nfunction skillsAction(result: Awaited<ReturnType<NonNullable<UpdateCommandDeps['syncSkills']>>>): Record<string, unknown> {\n if (result.action !== 'failed') {\n return { skills_action: result.action };\n }\n return {\n skills_action: 'failed',\n skills_warning: 'skills update failed',\n ...(result.result?.stderr ? { skills_detail: truncate(result.result.stderr.trim()) } : {}),\n };\n}\n\nexport function registerUpdateCommands(program: Command, deps: UpdateCommandDeps = {}): void {\n const fetchLatest = deps.fetchLatest || (() => fetchLatestVersion({ packageName: NPM_PACKAGE }));\n const detectInstall = deps.detectInstall || detectCurrentInstallMethod;\n const install = deps.install || ((version: string) => runNpmInstall(version, { packageName: NPM_PACKAGE }));\n const runSkills = deps.syncSkills || ((version: string, options: { force: boolean }) => syncSkillsDefault(version, options));\n const getSkillsStatus = deps.getSkillsStatus || (() => checkSkillsSync(VERSION));\n\n program\n .command('update')\n .description('Update bpmax-cli to the latest version')\n .option('--check', 'only check for updates, do not install')\n .option('--force', 'force reinstall even if already up to date')\n .option('--json', 'structured JSON output')\n .action(async (options: UpdateOptions) => {\n let latest: string;\n try {\n latest = await fetchLatest();\n } catch (error) {\n const message = `failed to check latest version: ${error instanceof Error ? error.message : String(error)}`;\n if (options.json) {\n printJson({ ok: false, error: { type: 'network', message } });\n process.exitCode = 1;\n return;\n }\n throw new Error(message);\n }\n\n const detect = await detectInstall();\n const updateAvailable = isNewerVersion(latest, VERSION);\n\n if (options.check) {\n const status = await getSkillsStatus();\n const body = {\n ok: true,\n previous_version: VERSION,\n current_version: VERSION,\n latest_version: latest,\n action: updateAvailable ? 'update_available' : 'already_up_to_date',\n auto_update: detect.method === 'npm' && detect.npmAvailable,\n skills_status: {\n current: status.current,\n target: status.target,\n in_sync: status.inSync,\n },\n };\n if (options.json) {\n printJson(body);\n } else if (updateAvailable) {\n console.error(`Update available: ${VERSION} -> ${latest}`);\n console.error(`Run: bpmax-cli update`);\n } else {\n console.error(`bpmax-cli ${VERSION} is already up to date`);\n }\n return;\n }\n\n if (!options.force && !updateAvailable) {\n const synced = await runSkills(VERSION, { force: false });\n const body = {\n ok: true,\n previous_version: VERSION,\n current_version: VERSION,\n latest_version: latest,\n action: 'already_up_to_date',\n ...skillsAction(synced),\n };\n if (options.json) {\n printJson(body);\n } else {\n console.error(`bpmax-cli ${VERSION} is already up to date`);\n if (synced.action === 'failed') {\n console.error('Skills update failed. Run manually: npm run install:skills');\n } else if (synced.action === 'synced') {\n console.error('Skills updated');\n }\n }\n return;\n }\n\n if (detect.method !== 'npm' || !detect.npmAvailable) {\n const synced = await runSkills(VERSION, { force: Boolean(options.force) });\n const body = {\n ok: true,\n previous_version: VERSION,\n current_version: VERSION,\n latest_version: latest,\n action: 'manual_required',\n message: `Automatic update unavailable: ${manualReason(detect)} (path: ${detect.resolvedPath})`,\n manual_command: `npm install -g ${NPM_PACKAGE}@${latest}`,\n ...skillsAction(synced),\n };\n if (options.json) {\n printJson(body);\n } else {\n console.error(body.message);\n console.error(`Run manually: ${body.manual_command}`);\n }\n return;\n }\n\n if (!options.json) {\n console.error(`Updating bpmax-cli ${VERSION} -> ${latest} via npm ...`);\n }\n const installResult = await install(latest);\n if (installResult.exitCode !== 0) {\n const detail = truncate(`${installResult.stdout}${installResult.stderr}`.trim());\n if (options.json) {\n printJson({\n ok: false,\n error: {\n type: 'update_error',\n message: `npm install failed with exit code ${installResult.exitCode}`,\n detail,\n },\n });\n process.exitCode = 1;\n return;\n }\n throw new Error(`npm install failed with exit code ${installResult.exitCode}${detail ? `\\n${detail}` : ''}`);\n }\n\n const synced = await runSkills(latest, { force: Boolean(options.force) });\n const body = {\n ok: true,\n previous_version: VERSION,\n current_version: latest,\n latest_version: latest,\n action: 'updated',\n ...skillsAction(synced),\n };\n if (options.json) {\n printJson(body);\n } else {\n console.error(`Successfully updated bpmax-cli from ${VERSION} to ${latest}`);\n if (synced.action === 'failed') {\n console.error('Skills update failed. Run manually: npm run install:skills');\n } else if (synced.action === 'synced') {\n console.error('Skills updated');\n }\n }\n });\n}\n","import type { Command } from 'commander';\n\nimport { loadConfig, resolveProfile } from '../core/config.js';\nimport { createApiClient, apiRequest } from '../core/http.js';\nimport { printResult } from '../core/output.js';\nimport type { OutputFormat } from '../core/types.js';\n\nexport function registerUserCommands(program: Command): void {\n const user = program.command('user').description('User commands');\n\n user\n .command('current')\n .description('Get current user')\n .option('--profile <profile>', 'Profile name')\n .option('--format <format>', 'Output format', 'pretty')\n .action(async (options: { profile?: string; format: OutputFormat }) => {\n const config = await loadConfig();\n const profile = resolveProfile(config, options.profile);\n const result = await apiRequest<Record<string, unknown>>(\n createApiClient(profile),\n 'GET',\n '/user/current',\n );\n printResult(options.format, result);\n });\n}\n","import { VERSION } from './build.js';\nimport { checkSkillsSync } from './skills.js';\nimport { setNoticeProvider } from './output.js';\nimport { checkCachedUpdate, refreshUpdateCache, type UpdateInfo } from './update.js';\n\ninterface SkillsNotice {\n current: string;\n target: string;\n}\n\nlet pendingUpdate: UpdateInfo | null = null;\nlet pendingSkills: SkillsNotice | null = null;\n\nfunction updateMessage(info: UpdateInfo): string {\n return `bpmax-cli ${info.latest} available, current ${info.current}, run: bpmax-cli update`;\n}\n\nfunction skillsMessage(info: SkillsNotice): string {\n if (!info.current) {\n return 'bpmax-cli skills not installed, run: bpmax-cli update';\n }\n return `bpmax-cli skills ${info.current} out of sync with binary ${info.target}, run: bpmax-cli update`;\n}\n\nexport async function setupNotices(): Promise<void> {\n pendingUpdate = await checkCachedUpdate(VERSION);\n const skills = await checkSkillsSync(VERSION);\n pendingSkills = skills.inSync ? null : { current: skills.current, target: skills.target };\n\n setNoticeProvider(() => {\n const notice: Record<string, Record<string, unknown>> = {};\n if (pendingUpdate) {\n notice.update = {\n current: pendingUpdate.current,\n latest: pendingUpdate.latest,\n message: updateMessage(pendingUpdate),\n };\n }\n if (pendingSkills) {\n notice.skills = {\n current: pendingSkills.current,\n target: pendingSkills.target,\n message: skillsMessage(pendingSkills),\n };\n }\n return Object.keys(notice).length > 0 ? notice : null;\n });\n\n void refreshUpdateCache(VERSION)\n .then((info) => {\n if (info) {\n pendingUpdate = info;\n }\n })\n .catch(() => {\n // Update notices are best-effort and must never block CLI commands.\n });\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;;;ACAxB,SAAS,eAAe;AACxB,SAAS,OAAO,UAAU,iBAAiB;AAC3C,OAAO,UAAU;AAUV,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAEhC,IAAM,aAAa,KAAK,KAAK,QAAQ,GAAG,QAAQ;AAChD,IAAM,cAAc,KAAK,KAAK,YAAY,aAAa;AAEvD,IAAM,gBAAgB,OAAqB;AAAA,EACzC,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,UAAU;AAAA,IACR,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,UAAU;AAAA,IACZ;AAAA,EACF;AACF;AAEA,IAAM,kBAAkB,CAAC,WAA2B,OAAO,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAEpF,IAAM,aAAa,CAAC,UAClB,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACZ,MAAuB,YAAY,KACpC,cAAc;AAEhB,IAAM,aAAa,CAAC,UAAuC;AACzD,MAA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AS,QAAQ,OAAO,OAAO;AAExF,oBAAkB,MAAM;AACtB,UAAM,SAAkD,CAAC;AACzD,QAAI,eAAe;AACjB,aAAO,SAAS;AAAA,QACd,SAAS,cAAc;AAAA,QACvB,QAAQ,cAAc;AAAA,QACtB,SAAS,cAAc,aAAa;AAAA,MACtC;AAAA,IACF;AACA,QAAI,eAAe;AACjB,aAAO,SAAS;AAAA,QACd,SAAS,cAAc;AAAA,QACvB,QAAQ,cAAc;AAAA,QACtB,SAAS,cAAc,aAAa;AAAA,MACtC;AAAA,IACF;AACA,WAAO,OAAO,KAAK,MAAM,EAAE,SAAS,IAAI,SAAS;AAAA,EACnD,CAAC;AAED,OAAK,mBAAmB,OAAO,EAC5B,KAAK,CAAC,SAAS;AACd,QAAI,MAAM;AACR,sBAAgB;AAAA,IAClB;AAAA,EACF,CAAC,EACA,MAAM,MAAM;AAAA,EAEb,CAAC;AACL;;;AnB5CA,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,QAAQ,EACb,YAAY,6BAA6B,EACzC,QAAQ,OAAO;AAElB,uBAAuB,OAAO;AAC9B,qBAAqB,OAAO;AAC5B,oBAAoB,OAAO;AAC3B,uBAAuB,OAAO;AAC9B,qBAAqB,OAAO;AAC5B,qBAAqB,OAAO;AAC5B,wBAAwB,OAAO;AAC/B,uBAAuB,OAAO;AAE9B,IAAM,eAAe,QAAQ,KAAK,SAAS,YAAY,KAAK,QAAQ,KAAK,SAAS,YAAY;AAAA,CAE7F,eAAe,QAAQ,QAAQ,IAAI,aAAa,GAC9C,KAAK,MAAM,QAAQ,WAAW,QAAQ,IAAI,CAAC,EAC3C,MAAM,CAAC,UAAU;AAClB,UAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE,UAAQ,WAAW;AACnB,CAAC;","names":["path","program","path","program","program","program","parseJson","program","program","mkdir","readFile","writeFile","path","path","readFile","mkdir","writeFile","mkdir","readFile","writeFile","path","path","readFile","mkdir","writeFile","program","body","synced","program"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bpmax-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bpmax-cli": "dist/bin.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"scripts/install-skills.mjs",
|
|
12
|
+
"skills",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node scripts/install-skills.mjs",
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"dev": "tsx src/bin.ts",
|
|
19
|
+
"install:skills": "node scripts/install-skills.mjs",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@clack/prompts": "^1.2.0",
|
|
28
|
+
"axios": "^1.9.0",
|
|
29
|
+
"commander": "^14.0.0",
|
|
30
|
+
"open": "^10.1.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.15.17",
|
|
34
|
+
"tsup": "^8.5.0",
|
|
35
|
+
"tsx": "^4.19.4",
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"vitest": "^3.1.3"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { cp, mkdir, readdir, rm, stat } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
|
|
6
|
+
const projectRoot = path.resolve(import.meta.dirname, '..');
|
|
7
|
+
const sourceSkillsDir = path.join(projectRoot, 'skills');
|
|
8
|
+
const jsonOutput = process.argv.includes('--json');
|
|
9
|
+
|
|
10
|
+
const targetRoots = [
|
|
11
|
+
path.join(homedir(), '.codex', 'skills'),
|
|
12
|
+
path.join(homedir(), '.claude', 'skills'),
|
|
13
|
+
path.join(homedir(), '.cc-switch', 'skills'),
|
|
14
|
+
path.join(homedir(), '.agents', 'skills'),
|
|
15
|
+
path.join(homedir(), '.gemini', 'skills'),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
async function exists(targetPath) {
|
|
19
|
+
try {
|
|
20
|
+
await stat(targetPath);
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function installSkillDir(skillName, sourceDir) {
|
|
28
|
+
const installed = [];
|
|
29
|
+
|
|
30
|
+
for (const root of targetRoots) {
|
|
31
|
+
const parentExists = await exists(path.dirname(root));
|
|
32
|
+
const rootExists = await exists(root);
|
|
33
|
+
if (!rootExists && !parentExists) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await mkdir(root, { recursive: true });
|
|
38
|
+
const destination = path.join(root, skillName);
|
|
39
|
+
await rm(destination, { recursive: true, force: true });
|
|
40
|
+
await cp(sourceDir, destination, { recursive: true });
|
|
41
|
+
installed.push(destination);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return installed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function listSkillNames() {
|
|
48
|
+
const entries = await readdir(sourceSkillsDir, { withFileTypes: true });
|
|
49
|
+
const skillNames = [];
|
|
50
|
+
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (!entry.isDirectory()) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const skillDir = path.join(sourceSkillsDir, entry.name);
|
|
57
|
+
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
58
|
+
if (await exists(skillFile)) {
|
|
59
|
+
skillNames.push(entry.name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return skillNames.sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
if (!(await exists(sourceSkillsDir))) {
|
|
68
|
+
const result = { ok: true, action: 'skipped', installed: [], message: 'No project skills directory found.' };
|
|
69
|
+
if (jsonOutput) {
|
|
70
|
+
console.log(JSON.stringify(result, null, 2));
|
|
71
|
+
} else {
|
|
72
|
+
console.log('[bpmax-cli] No project skills directory found, skipping skill install.');
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const skillNames = await listSkillNames();
|
|
78
|
+
if (skillNames.length === 0) {
|
|
79
|
+
const result = { ok: true, action: 'skipped', installed: [], message: 'No skill directories with SKILL.md found.' };
|
|
80
|
+
if (jsonOutput) {
|
|
81
|
+
console.log(JSON.stringify(result, null, 2));
|
|
82
|
+
} else {
|
|
83
|
+
console.log('[bpmax-cli] No skill directories with SKILL.md found, skipping skill install.');
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
const allInstalled = [];
|
|
88
|
+
|
|
89
|
+
for (const skillName of skillNames) {
|
|
90
|
+
const sourceDir = path.join(sourceSkillsDir, skillName);
|
|
91
|
+
if (!(await exists(sourceDir))) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const installed = await installSkillDir(skillName, sourceDir);
|
|
95
|
+
installed.forEach((target) => allInstalled.push(target));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (allInstalled.length === 0) {
|
|
99
|
+
const result = {
|
|
100
|
+
ok: true,
|
|
101
|
+
action: 'skipped',
|
|
102
|
+
installed: [],
|
|
103
|
+
message: 'No compatible local agent skill directories detected.',
|
|
104
|
+
};
|
|
105
|
+
if (jsonOutput) {
|
|
106
|
+
console.log(JSON.stringify(result, null, 2));
|
|
107
|
+
} else {
|
|
108
|
+
console.log('[bpmax-cli] No compatible local agent skill directories detected. Nothing installed.');
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const result = { ok: true, action: 'installed', installed: allInstalled };
|
|
114
|
+
if (jsonOutput) {
|
|
115
|
+
console.log(JSON.stringify(result, null, 2));
|
|
116
|
+
} else {
|
|
117
|
+
console.log('[bpmax-cli] Installed skills to:');
|
|
118
|
+
allInstalled.forEach((target) => {
|
|
119
|
+
console.log(`- ${target}`);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
main().catch((error) => {
|
|
126
|
+
console.error('[bpmax-cli] Failed to install skills:', error);
|
|
127
|
+
process.exitCode = 1;
|
|
128
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-auth
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Use when the user needs BPMAX browser login, API key setup, auth status checks, logout, or diagnosis of localhost callback and permission issues around bpmax-cli authentication.
|
|
5
|
+
metadata:
|
|
6
|
+
requires:
|
|
7
|
+
bins: ["bpmax-cli"]
|
|
8
|
+
cliHelp: "bpmax-cli auth --help"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# auth
|
|
12
|
+
|
|
13
|
+
> **前置条件:** 先阅读 `../bpmax-shared/SKILL.md`。
|
|
14
|
+
> **登录约束:** 登录只通过 `hpt-frontend` 页面完成,不依赖 `bpmax-server`。
|
|
15
|
+
|
|
16
|
+
## 何时使用
|
|
17
|
+
|
|
18
|
+
- 用户要登录 BPMAX
|
|
19
|
+
- 用户要检查当前 API Key 是否有效
|
|
20
|
+
- 用户要清空当前环境的登录状态
|
|
21
|
+
- 用户遇到浏览器桥接、权限不足、localhost 回调失败
|
|
22
|
+
|
|
23
|
+
## 命令
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bpmax-cli auth login
|
|
27
|
+
bpmax-cli auth status
|
|
28
|
+
bpmax-cli auth logout
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 路由规则
|
|
32
|
+
|
|
33
|
+
- 首次接入某个环境:先 `config profile add/use`,再 `auth login`
|
|
34
|
+
- 只想确认当前身份和连通性:`auth status`
|
|
35
|
+
- 只清空当前 profile 的本地 API Key:`auth logout`
|
|
36
|
+
|
|
37
|
+
## 登录流程理解
|
|
38
|
+
|
|
39
|
+
`auth login` 的固定链路:
|
|
40
|
+
|
|
41
|
+
1. CLI 读取目标 profile 的 `origin`
|
|
42
|
+
2. CLI 启动本地一次性 `localhost` 回调服务
|
|
43
|
+
3. CLI 打开 `hpt-frontend` 的 CLI 登录桥接页
|
|
44
|
+
4. 页面复用 `huanpingtong-server` 现有 `/api/user_api_key` 机制获取或创建 `bpmax-cli` API Key
|
|
45
|
+
5. 页面通过 `POST /callback` 把 API Key 回传本地 CLI
|
|
46
|
+
6. CLI 校验 `state` 后落盘
|
|
47
|
+
|
|
48
|
+
## 常见问题
|
|
49
|
+
|
|
50
|
+
- 401/403:先检查 `origin`、`api_key`、当前 profile 是否正确
|
|
51
|
+
- 页面提示无权限:优先怀疑缺少 `user.api_key.manage`
|
|
52
|
+
- 浏览器已登录但 CLI 一直等待:检查本机 `localhost` 回调端口是否可达
|
|
53
|
+
- 需要切环境登录:显式传 `--profile <name>`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-cli
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Use when the user asks generally about BPMAX CLI capabilities and you need to route to the right bpmax-* skill instead of choosing auth, flow, project, user, or schema directly.
|
|
5
|
+
metadata:
|
|
6
|
+
requires:
|
|
7
|
+
bins: ["bpmax-cli"]
|
|
8
|
+
cliHelp: "bpmax-cli --help"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# bpmax-cli
|
|
12
|
+
|
|
13
|
+
这是总入口 skill,只负责分流,不承载具体业务规则。
|
|
14
|
+
|
|
15
|
+
## 路由规则
|
|
16
|
+
|
|
17
|
+
- 环境配置、全局参数、命令发现、原始 API 降级:先读 `../bpmax-shared/SKILL.md`
|
|
18
|
+
- 浏览器登录、API Key、认证状态:读 `../bpmax-auth/SKILL.md`
|
|
19
|
+
- 当前用户:读 `../bpmax-user/SKILL.md`
|
|
20
|
+
- 流程列表、流程选项、流程详情:读 `../bpmax-flow/SKILL.md`
|
|
21
|
+
- 项目列表、项目详情、我的待办、最小创建:读 `../bpmax-project/SKILL.md`
|
|
22
|
+
- 本地 schema manifest:读 `../bpmax-schema/SKILL.md`
|
|
23
|
+
|
|
24
|
+
## 规则
|
|
25
|
+
|
|
26
|
+
- 不要在这里只停留并直接执行命令;必须继续进入更具体的 bpmax-* skill
|
|
27
|
+
- 若任务跨多个 BPMAX 场景,先读 `bpmax-shared`,再按需进入具体 skill
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-flow
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Use when the user needs BPMAX flow type lists, flow options, flow detail lookup, or minimal flow resolution work before project creation through bpmax-cli.
|
|
5
|
+
metadata:
|
|
6
|
+
requires:
|
|
7
|
+
bins: ["bpmax-cli"]
|
|
8
|
+
cliHelp: "bpmax-cli flow --help"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# flow
|
|
12
|
+
|
|
13
|
+
> **前置条件:** 先阅读 `../bpmax-shared/SKILL.md`。
|
|
14
|
+
|
|
15
|
+
## 命令
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bpmax-cli flow list --format table
|
|
19
|
+
bpmax-cli flow options --flow-id 123 --format json
|
|
20
|
+
bpmax-cli flow get --flow-id 123 --format json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 何时使用
|
|
24
|
+
|
|
25
|
+
- 用户要看流程列表
|
|
26
|
+
- 用户要查某个流程的选项
|
|
27
|
+
- 用户要解析流程详情
|
|
28
|
+
- 为 `project create` 做最小前置解析
|
|
29
|
+
|
|
30
|
+
## 路由规则
|
|
31
|
+
|
|
32
|
+
- 流程枚举优先 `flow list`
|
|
33
|
+
- 只在需要单流程细节时才用 `flow get`
|
|
34
|
+
- 需要读取创建选项或流程相关参数时,再用 `flow options`
|
|
35
|
+
|
|
36
|
+
## 输出建议
|
|
37
|
+
|
|
38
|
+
- 用户只是浏览流程概览时可用 `--format table`
|
|
39
|
+
- 需要后续程序判断时优先 `--format json`
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-project
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Use when the user needs BPMAX project lists, project detail lookup, current-user steps, or minimal project creation through bpmax-cli before falling back to raw API requests.
|
|
5
|
+
metadata:
|
|
6
|
+
requires:
|
|
7
|
+
bins: ["bpmax-cli"]
|
|
8
|
+
cliHelp: "bpmax-cli project --help"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# project
|
|
12
|
+
|
|
13
|
+
> **前置条件:** 先阅读 `../bpmax-shared/SKILL.md`。
|
|
14
|
+
> **依赖关系:** 若创建前需要确认流程,先读 `../bpmax-flow/SKILL.md`。
|
|
15
|
+
|
|
16
|
+
## 命令
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bpmax-cli project list --format table
|
|
20
|
+
bpmax-cli project get --project-id 1001 --format json
|
|
21
|
+
bpmax-cli project my-step --format table
|
|
22
|
+
bpmax-cli project create --flow-id 123 --name "Demo" --format json
|
|
23
|
+
bpmax-cli project create --flow-id 123 --name "Demo" --json '{"priority":"P1"}' --format json
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 何时使用
|
|
27
|
+
|
|
28
|
+
- 用户要看项目列表
|
|
29
|
+
- 用户要查单个项目详情
|
|
30
|
+
- 用户要看“我的待办步骤”
|
|
31
|
+
- 用户要用最小参数创建项目
|
|
32
|
+
|
|
33
|
+
## 路由规则
|
|
34
|
+
|
|
35
|
+
- 概览优先 `project list`
|
|
36
|
+
- 单项目详情走 `project get`
|
|
37
|
+
- 待办相关优先 `project my-step`
|
|
38
|
+
- 创建优先 `project create`
|
|
39
|
+
|
|
40
|
+
## 创建规则
|
|
41
|
+
|
|
42
|
+
- V1 的 `project create` 只承诺最小可用路径
|
|
43
|
+
- 必填优先只保留 `--flow-id` 和 `--name`
|
|
44
|
+
- 需要补充字段时,用 `--json`
|
|
45
|
+
- 若 payload 已经超出 shortcut 覆盖范围,再降级到 `bpmax-cli api`
|
|
46
|
+
|
|
47
|
+
## 异常处理
|
|
48
|
+
|
|
49
|
+
- 本地参数校验失败:先修正 `--flow-id`、`--name` 或 JSON
|
|
50
|
+
- 服务端校验失败:保留错误原文
|
|
51
|
+
- 创建路径不满足业务变体:改走 `project create --json ...` 或原始 `api POST`
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bpmax-schema
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Use when the user needs to inspect bpmax-cli's local endpoint manifest, discover supported shortcuts, or decide whether a task should stay on a shortcut or fall back to raw API mode.
|
|
5
|
+
metadata:
|
|
6
|
+
requires:
|
|
7
|
+
bins: ["bpmax-cli"]
|
|
8
|
+
cliHelp: "bpmax-cli schema --help"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# schema
|
|
12
|
+
|
|
13
|
+
> **前置条件:** 先阅读 `../bpmax-shared/SKILL.md`。
|
|
14
|
+
|
|
15
|
+
## 命令
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bpmax-cli schema list
|
|
19
|
+
bpmax-cli schema show project.create
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 何时使用
|
|
23
|
+
|
|
24
|
+
- 用户想知道 CLI 封装了哪些能力
|
|
25
|
+
- 不确定某个需求是否已有 shortcut
|
|
26
|
+
- 决定是否需要从 shortcut 降级到 `bpmax-cli api`
|
|
27
|
+
|
|
28
|
+
## 规则
|
|
29
|
+
|
|
30
|
+
- 先 `schema list` 看命令地图
|
|
31
|
+
- 需要具体 shortcut 说明时,再 `schema show <name>`
|
|
32
|
+
- `schema` 只看本地 manifest,不依赖远端 Swagger
|