issue-flow 0.11.1 → 0.12.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/dist/{analyze-XV3K25K3.js → analyze-OEET7KGE.js} +15 -10
- package/dist/{analyze-XV3K25K3.js.map → analyze-OEET7KGE.js.map} +1 -1
- package/dist/{apply-WUJHDD7A.js → apply-ZIA3C52S.js} +6 -4
- package/dist/{apply-WUJHDD7A.js.map → apply-ZIA3C52S.js.map} +1 -1
- package/dist/{chunk-6N7LZZ5U.js → chunk-3QHK4YQA.js} +204 -107
- package/dist/chunk-3QHK4YQA.js.map +1 -0
- package/dist/chunk-42PJFMAR.js +605 -0
- package/dist/chunk-42PJFMAR.js.map +1 -0
- package/dist/{chunk-EWDJENFW.js → chunk-4JSOYE4G.js} +77 -12
- package/dist/chunk-4JSOYE4G.js.map +1 -0
- package/dist/chunk-56KS3TFQ.js +703 -0
- package/dist/chunk-56KS3TFQ.js.map +1 -0
- package/dist/{chunk-AAY6KM7N.js → chunk-73ATPIYX.js} +160 -154
- package/dist/chunk-73ATPIYX.js.map +1 -0
- package/dist/{chunk-KQ4JQN7T.js → chunk-A4SLHOW7.js} +68 -12
- package/dist/chunk-A4SLHOW7.js.map +1 -0
- package/dist/chunk-BAUPQXPE.js +173 -0
- package/dist/chunk-BAUPQXPE.js.map +1 -0
- package/dist/{chunk-HC2MT7BX.js → chunk-BYZDPR7N.js} +14 -581
- package/dist/chunk-BYZDPR7N.js.map +1 -0
- package/dist/chunk-CD5ULRVC.js +615 -0
- package/dist/chunk-CD5ULRVC.js.map +1 -0
- package/dist/chunk-DIDUVL6O.js +1365 -0
- package/dist/chunk-DIDUVL6O.js.map +1 -0
- package/dist/{chunk-47VIN33V.js → chunk-EZATO3DW.js} +7 -5
- package/dist/{chunk-47VIN33V.js.map → chunk-EZATO3DW.js.map} +1 -1
- package/dist/{chunk-BXCPXRBR.js → chunk-FADTCQGM.js} +46 -11
- package/dist/chunk-FADTCQGM.js.map +1 -0
- package/dist/{chunk-GANSDJV7.js → chunk-FJP3UQGD.js} +15 -13
- package/dist/chunk-FJP3UQGD.js.map +1 -0
- package/dist/chunk-KMMASOA6.js +134 -0
- package/dist/chunk-KMMASOA6.js.map +1 -0
- package/dist/{chunk-HQYXVIH6.js → chunk-LAFNLLQP.js} +3 -3
- package/dist/chunk-LWRSMTTZ.js +18 -0
- package/dist/chunk-LWRSMTTZ.js.map +1 -0
- package/dist/{chunk-IVHZEYAX.js → chunk-M5UCXTIT.js} +13 -11
- package/dist/{chunk-IVHZEYAX.js.map → chunk-M5UCXTIT.js.map} +1 -1
- package/dist/chunk-M66SJHQQ.js +206 -0
- package/dist/chunk-M66SJHQQ.js.map +1 -0
- package/dist/{chunk-OBLVLIUS.js → chunk-MJULIKQU.js} +42 -6
- package/dist/chunk-MJULIKQU.js.map +1 -0
- package/dist/{chunk-RKTEV6EG.js → chunk-NS6R37II.js} +4 -4
- package/dist/{run-DBF2VWUN.js → chunk-NTMMF5UD.js} +515 -544
- package/dist/chunk-NTMMF5UD.js.map +1 -0
- package/dist/{chunk-EY6WMHV2.js → chunk-QCPGHBSZ.js} +14 -12
- package/dist/{chunk-EY6WMHV2.js.map → chunk-QCPGHBSZ.js.map} +1 -1
- package/dist/{chunk-LVKQ2AKT.js → chunk-TSOLWK7Y.js} +8 -6
- package/dist/chunk-TSOLWK7Y.js.map +1 -0
- package/dist/{chunk-34WNTK3K.js → chunk-XQUSIEKA.js} +11 -9
- package/dist/{chunk-34WNTK3K.js.map → chunk-XQUSIEKA.js.map} +1 -1
- package/dist/chunk-Y5ZDJ4PJ.js +76 -0
- package/dist/chunk-Y5ZDJ4PJ.js.map +1 -0
- package/dist/cli.js +156 -26
- package/dist/cli.js.map +1 -1
- package/dist/{config-4THHOXNN.js → config-PRJGWW7J.js} +15 -3
- package/dist/execute-XBNVL753.js +18 -0
- package/dist/{generate-TBVTLMOP.js → generate-EGB4KV2B.js} +16 -10
- package/dist/{generate-TBVTLMOP.js.map → generate-EGB4KV2B.js.map} +1 -1
- package/dist/init-AJHCXJBP.js +10 -0
- package/dist/operations-BYT626KQ.js +365 -0
- package/dist/operations-BYT626KQ.js.map +1 -0
- package/dist/plan-QOZ3RIO6.js +21 -0
- package/dist/{policy-XQW5NUIE.js → policy-6S4GFC76.js} +6 -4
- package/dist/{policy-XQW5NUIE.js.map → policy-6S4GFC76.js.map} +1 -1
- package/dist/pr-EBBHD2ZX.js +26 -0
- package/dist/pr-review-VVMW5PO4.js +20 -0
- package/dist/prd-JQSZF7PR.js +21 -0
- package/dist/resume-PPCNQVVV.js +221 -0
- package/dist/resume-PPCNQVVV.js.map +1 -0
- package/dist/review-3F6MARWH.js +19 -0
- package/dist/run-RXE5GDQO.js +36 -0
- package/dist/run-RXE5GDQO.js.map +1 -0
- package/dist/state-manager-2EDVDBAR.js +34 -0
- package/dist/state-manager-2EDVDBAR.js.map +1 -0
- package/dist/{web-ANQQTTRD.js → web-EF5WIIGG.js} +13 -8
- package/dist/{web-ANQQTTRD.js.map → web-EF5WIIGG.js.map} +1 -1
- package/package.json +1 -1
- package/prompts/pr.md +11 -4
- package/web/public/app.js +12 -0
- package/dist/chunk-3BOHTH4V.js +0 -58
- package/dist/chunk-3BOHTH4V.js.map +0 -1
- package/dist/chunk-6N7LZZ5U.js.map +0 -1
- package/dist/chunk-AAY6KM7N.js.map +0 -1
- package/dist/chunk-BXCPXRBR.js.map +0 -1
- package/dist/chunk-EWDJENFW.js.map +0 -1
- package/dist/chunk-GANSDJV7.js.map +0 -1
- package/dist/chunk-HC2MT7BX.js.map +0 -1
- package/dist/chunk-HDV3YDTG.js +0 -52
- package/dist/chunk-HDV3YDTG.js.map +0 -1
- package/dist/chunk-KQ4JQN7T.js.map +0 -1
- package/dist/chunk-LVKQ2AKT.js.map +0 -1
- package/dist/chunk-OBLVLIUS.js.map +0 -1
- package/dist/chunk-VQ5VN7DF.js +0 -1018
- package/dist/chunk-VQ5VN7DF.js.map +0 -1
- package/dist/execute-5OEKLM5X.js +0 -15
- package/dist/init-PRMOTQ7N.js +0 -9
- package/dist/plan-Y2BYZD24.js +0 -17
- package/dist/pr-H6GLOSXF.js +0 -21
- package/dist/pr-review-CK5FR6WX.js +0 -17
- package/dist/prd-4PWLCGH5.js +0 -17
- package/dist/review-QGVAHEZF.js +0 -15
- package/dist/run-DBF2VWUN.js.map +0 -1
- /package/dist/{chunk-HQYXVIH6.js.map → chunk-LAFNLLQP.js.map} +0 -0
- /package/dist/{chunk-RKTEV6EG.js.map → chunk-NS6R37II.js.map} +0 -0
- /package/dist/{config-4THHOXNN.js.map → config-PRJGWW7J.js.map} +0 -0
- /package/dist/{execute-5OEKLM5X.js.map → execute-XBNVL753.js.map} +0 -0
- /package/dist/{init-PRMOTQ7N.js.map → init-AJHCXJBP.js.map} +0 -0
- /package/dist/{plan-Y2BYZD24.js.map → plan-QOZ3RIO6.js.map} +0 -0
- /package/dist/{pr-H6GLOSXF.js.map → pr-EBBHD2ZX.js.map} +0 -0
- /package/dist/{pr-review-CK5FR6WX.js.map → pr-review-VVMW5PO4.js.map} +0 -0
- /package/dist/{prd-4PWLCGH5.js.map → prd-JQSZF7PR.js.map} +0 -0
- /package/dist/{review-QGVAHEZF.js.map → review-3F6MARWH.js.map} +0 -0
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/cli-options.ts","../src/issues/cli-flags.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { Command, InvalidArgumentError } from 'commander';\nimport {\n CliFlagError,\n resolveQueueScopeFlags,\n resolveRunPhaseFlags,\n resolveUserStoryNumberingFlags,\n} from './cli-options.js';\nimport { setIssuesCliOverrides, setWebCliOverrides } from './config.js';\nimport { setGlobalTimeout, setVerbose } from './core/verbose.js';\nimport {\n IssueFlagError,\n resolveGenerateTarget,\n resolveIssuesOverrides,\n} from './issues/cli-flags.js';\nimport type { IssueGenerateTarget } from './issues/types.js';\nimport type { WebConfig } from './schemas.js';\nimport { printError } from './ui/logger.js';\n\nconst require = createRequire(import.meta.url);\nconst { version } = require('../package.json') as { version: string };\n\n/**\n * Parse a numeric string, throwing InvalidArgumentError if not a valid number.\n */\nfunction parseInteger(value: string): number {\n const parsed = parseInt(value, 10);\n if (Number.isNaN(parsed) || parsed < 0) {\n throw new InvalidArgumentError('Must be a non-negative integer.');\n }\n return parsed;\n}\n\n/**\n * Parse `--start-us <n>`: a User Story number is 1-based, so 0 is rejected\n * along with everything `parseInteger` already rejects.\n */\nfunction parseStartUs(value: string): number {\n const parsed = parseInteger(value);\n if (parsed < 1) {\n throw new InvalidArgumentError('Must be a positive integer (US-001 is the first story).');\n }\n return parsed;\n}\n\n/**\n * Add the User Story numbering override options to a subcommand that\n * triggers `plan` (`run` and `plan` itself) — see issue #36.\n */\nfunction withUserStoryNumberingOptions(cmd: Command): Command {\n return cmd\n .option('--continue', 'Continue User Story numbering from the last used in this project')\n .option(\n '--start-us <n>',\n 'Force User Story numbering to start at a specific number, ignoring history',\n parseStartUs,\n );\n}\n\n/**\n * Add shared options (--verbose) to a subcommand.\n */\nfunction withGlobalOptions(cmd: Command): Command {\n return cmd\n .option('-v, --verbose', 'Show Claude progress output in real time')\n .option(\n '-t, --timeout <seconds>',\n 'Override headless timeout in seconds (0 = no limit)',\n parseInteger,\n );\n}\n\n/**\n * Add web monitoring options to a subcommand (run and execute only).\n * The values are resolved into CLI overrides by the preAction hook below;\n * loadWebConfig() applies the flag > env > file > defaults precedence.\n */\nfunction withWebOptions(cmd: Command): Command {\n return cmd\n .option('--web', 'Enable the web monitoring server')\n .option('--serve', 'Alias for --web')\n .option('--port <n>', 'Web server port (default: 3737)', parseInteger)\n .option('--host <h>', 'Web server host (default: 0.0.0.0)')\n .option('--refresh <s>', 'Suggested UI polling interval in seconds', parseInteger)\n .option('--web-log-limit <n>', 'Max log entries kept in the snapshot', parseInteger)\n .option('--web-no-logs', 'Exclude logs from the published snapshot');\n}\n\n/**\n * Add the Issue provider options to a subcommand.\n *\n * Declared once here (like withWebOptions) so no command repeats the flag\n * list; the preAction hook below turns them into config overrides, and\n * loadIssuesConfig() applies the flag > .issue-flow.json > defaults precedence.\n */\nfunction withIssueOptions(cmd: Command): Command {\n return cmd\n .option('--local', 'Prefer the local file Issue provider')\n .option('--github', 'Prefer the GitHub Issue provider')\n .option('--prefer-local', 'On divergence, use the local version without asking')\n .option('--prefer-github', 'On divergence, use the GitHub version without asking')\n .option('--ask', 'On divergence, ask which version to use (interactive only)');\n}\n\n/**\n * Extract the web-related CLI flags from a command's options, keeping only\n * the ones the user actually set.\n */\nfunction resolveWebOverrides(opts: Record<string, unknown>): Partial<WebConfig> {\n const overrides: Partial<WebConfig> = {};\n if (opts.web === true || opts.serve === true) {\n overrides.enabled = true;\n }\n if (opts.port !== undefined) {\n overrides.port = opts.port as number;\n }\n if (opts.host !== undefined) {\n overrides.host = opts.host as string;\n }\n if (opts.refresh !== undefined) {\n overrides.refreshSeconds = opts.refresh as number;\n }\n if (opts.webLogLimit !== undefined) {\n overrides.logLimit = opts.webLogLimit as number;\n }\n if (opts.webNoLogs === true) {\n overrides.includeLogs = false;\n }\n return overrides;\n}\n\nconst program = new Command();\n\nprogram\n .name('issue-flow')\n .description(\n 'Unified CLI for orchestrating the full issue-flow pipeline via Claude Code Headless.',\n )\n .version(version);\n\nprogram.hook('preAction', (_thisCommand, actionCommand) => {\n const opts = actionCommand.opts();\n if (opts.verbose) {\n setVerbose(true);\n }\n if (opts.timeout !== undefined) {\n setGlobalTimeout(opts.timeout * 1000);\n }\n setWebCliOverrides(resolveWebOverrides(opts));\n try {\n setIssuesCliOverrides(resolveIssuesOverrides(opts));\n } catch (error) {\n if (error instanceof IssueFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n});\n\n// ── init ────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('init')\n .description(\n 'Check prerequisites and report (or create) the conventions this repository is missing',\n )\n .option('--apply', 'Create the missing files instead of only reporting them')\n .option('--json', 'Emit the plan as JSON')\n .option('--scope <dir>', 'Resolve the conventions for a subdirectory (monorepo)')\n .option('--check-only', 'Only verify prerequisites, as earlier releases did'),\n ),\n).action(\n async (options: { apply?: boolean; json?: boolean; scope?: string; checkOnly?: boolean }) => {\n const { loadIssuesConfig } = await import('./config.js');\n const { runInit } = await import('./commands/init.js');\n const { preferredProvider } = await loadIssuesConfig();\n const code = await runInit(preferredProvider, options);\n process.exit(code);\n },\n);\n\n// ── generate ────────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('generate')\n .description('Draft an issue via Claude Code Headless and create it')\n .requiredOption('--prompt <text>', 'Issue description text')\n .option('--github', 'Create the issue on GitHub')\n .option('--local', 'Create the issue under issues/<n>/ only')\n .option('--both', 'Create the issue on GitHub and mirror it locally'),\n).action(async (options: { prompt: string; github?: boolean; local?: boolean; both?: boolean }) => {\n let target: IssueGenerateTarget | undefined;\n try {\n target = resolveGenerateTarget(options);\n } catch (error) {\n if (error instanceof IssueFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runGenerate } = await import('./commands/generate.js');\n const code = await runGenerate(options.prompt, target);\n process.exit(code);\n});\n\n// ── run ─────────────────────────────────────────────────────────────────────\nwithUserStoryNumberingOptions(\n withWebOptions(\n withIssueOptions(\n withGlobalOptions(\n program\n .command('run')\n .description(\n 'Execute the full pipeline: prd → plan → execute → review → pr (→ pr-review, optional)',\n )\n .argument('<issues...>', 'Issue number(s): 42, \"42,43\" or 42 43')\n .option('--mode <mode>', 'Execution mode: auto | manual', 'auto')\n .option('--from <phase>', 'Resume from a specific phase')\n .option(\n '--no-branch',\n 'Run pipeline on current branch without creating a new branch or PR',\n )\n .option('--pr-review', 'Review the created Pull Request after the pr phase')\n .option('-y, --yes', 'Run the whole discovered hierarchy without confirmation')\n .option('--only', 'Run just the issues informed, without their hierarchy'),\n ),\n ),\n ),\n).action(\n async (\n issues: string[],\n options: {\n mode: string;\n from?: string;\n branch?: boolean;\n prReview?: boolean;\n yes?: boolean;\n only?: boolean;\n continue?: boolean;\n startUs?: number;\n },\n ) => {\n let phases: ReturnType<typeof resolveRunPhaseFlags>;\n let scope: ReturnType<typeof resolveQueueScopeFlags>;\n let numbering: ReturnType<typeof resolveUserStoryNumberingFlags>;\n try {\n phases = resolveRunPhaseFlags(options);\n scope = resolveQueueScopeFlags(options);\n numbering = resolveUserStoryNumberingFlags(options);\n } catch (error) {\n if (error instanceof CliFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runPipeline } = await import('./commands/run.js');\n const code = await runPipeline(\n issues,\n options.mode,\n options.from,\n phases.noBranch,\n phases.prReview,\n {\n yes: scope.yes,\n only: scope.only,\n continueNumbering: numbering.continueFlag,\n startUs: numbering.startUs,\n },\n );\n process.exit(code);\n },\n);\n\n// ── analyze ─────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('analyze')\n .description('Analyze an issue via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runAnalyze } = await import('./commands/analyze.js');\n const code = await runAnalyze(issue);\n process.exit(code);\n});\n\n// ── prd ─────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('prd')\n .description('Generate a PRD from an analyzed issue via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runPrd } = await import('./commands/prd.js');\n const code = await runPrd(issue);\n process.exit(code);\n});\n\n// ── plan ────────────────────────────────────────────────────────────────────\nwithUserStoryNumberingOptions(\n withIssueOptions(\n withGlobalOptions(\n program\n .command('plan')\n .description('Convert a PRD to a tasks.json task plan via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n ),\n).action(async (issue: string, options: { continue?: boolean; startUs?: number }) => {\n let numbering: ReturnType<typeof resolveUserStoryNumberingFlags>;\n try {\n numbering = resolveUserStoryNumberingFlags(options);\n } catch (error) {\n if (error instanceof CliFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runPlan } = await import('./commands/plan.js');\n const code = await runPlan(issue, undefined, numbering);\n process.exit(code);\n});\n\n// ── execute ─────────────────────────────────────────────────────────────────\nwithWebOptions(\n withGlobalOptions(\n program\n .command('execute')\n .description('Run the iterative story execution loop (issue-flow engine)')\n .option('--issue <number>', 'Issue number — reads artifacts from issues/N/')\n .option('--max-iterations <number>', 'Stop after N iterations', parseInteger)\n .option(\n '--retry-limit <number>',\n 'Retry transient Claude failures up to N consecutive times',\n parseInteger,\n )\n .option('--retry-forever', 'Retry transient Claude failures indefinitely')\n .argument(\n '[max-iterations]',\n 'Backward-compatible alias for --max-iterations N',\n parseInteger,\n ),\n ),\n).action(\n async (\n positionalMaxIter: number | undefined,\n options: {\n issue?: string;\n maxIterations?: number;\n retryLimit?: number;\n retryForever?: boolean;\n },\n ) => {\n try {\n const { runExecute } = await import('./commands/execute.js');\n const code = await runExecute(positionalMaxIter, options);\n process.exit(code);\n } catch (error) {\n printError(error instanceof Error ? error.message : String(error));\n process.exit(1);\n }\n },\n);\n\n// ── review ──────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('review')\n .description('Validate an issue resolution via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runReview } = await import('./commands/review.js');\n const code = await runReview(issue);\n process.exit(code);\n});\n\n// ── pr ──────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('pr')\n .description('Create a pull request via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runPr } = await import('./commands/pr.js');\n const code = await runPr(issue);\n process.exit(code);\n});\n\n// ── web ─────────────────────────────────────────────────────────────────────\nconst webCommand = program.command('web').description('Manage the web monitoring server');\n\nwebCommand\n .command('serve')\n .description(\n 'Run the web monitor server in the foreground (internal — spawned detached by --web)',\n )\n .option('--port <n>', 'Web server port (default: 3737)', parseInteger)\n .option('--host <h>', 'Web server host (default: 0.0.0.0)')\n .option('--refresh <s>', 'Suggested UI polling interval in seconds', parseInteger)\n .action(async (options: { port?: number; host?: string; refresh?: number }) => {\n const { runWebServe } = await import('./commands/web.js');\n const code = await runWebServe(options);\n // On success this process stays alive for as long as the server is bound\n // (server.ts binds it with unref: false) — only a failure exits here.\n if (code !== 0) {\n process.exit(code);\n }\n });\n\nwebCommand\n .command('stop')\n .description('Stop the running web monitor server')\n .action(async () => {\n const { runWebStop } = await import('./commands/web.js');\n const code = await runWebStop();\n process.exit(code);\n });\n\n// ── policy ──────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('policy')\n .description('Inspect the policies discovered in this repository and their provenance')\n .option('--scope <dir>', 'Resolve the policy for a subdirectory (monorepo)')\n .option('--json', 'Emit the resolved policy as JSON'),\n).action(async (options: { scope?: string; json?: boolean }) => {\n const { runPolicy } = await import('./commands/policy.js');\n const code = await runPolicy(options);\n process.exit(code);\n});\n\n// ── pr-review ───────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('pr-review')\n .description('Review a Pull Request as a whole via Claude Code Headless')\n .argument('[pr]', 'Pull Request number (discovered from the session when omitted)')\n .option('--issue <n>', 'Issue the Pull Request belongs to')\n .option('--round <n>', 'Rewrite a specific review round instead of appending a new one')\n .option('--yes', 'Skip the confirmation of the discovered Pull Request')\n .option(\n '--fail-on <level>',\n 'Verdict that fails the command: request-changes | suggestions | none',\n ),\n).action(\n async (\n pr: string | undefined,\n options: { issue?: string; round?: string; yes?: boolean; failOn?: string },\n ) => {\n const { runPrReview } = await import('./commands/pr-review.js');\n const code = await runPrReview(pr, options);\n process.exit(code);\n },\n);\n\nprogram.parse();\n","/**\n * Pure mappings from parsed CLI options to command arguments.\n *\n * They live outside cli.ts because that module runs `program.parse()` on\n * import, so anything defined there is untestable.\n */\n\n/** Shape commander produces for a negated boolean option (`--no-branch`). */\nexport interface BranchFlagOptions {\n branch?: boolean;\n}\n\n/**\n * Translate commander's `--no-branch` into the tri-state `runPipeline` expects.\n *\n * Commander stores a negated option under its positive name: `--no-branch`\n * yields `{ branch: false }` and never a `noBranch` key. Reading `noBranch`\n * silently dropped the flag, so the pipeline always created a branch and opened\n * a PR.\n *\n * `undefined` (flag absent) is preserved on purpose: `runPipeline` uses it to\n * tell \"the user said nothing, keep the mode persisted in tasks.json\" apart\n * from an explicit choice.\n */\nexport function resolveNoBranch(options: BranchFlagOptions): boolean | undefined {\n return options.branch === false ? true : undefined;\n}\n\n/** Invalid flag combination on a command, reported as a CLI error. */\nexport class CliFlagError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CliFlagError';\n }\n}\n\n/** Options `run` accepts that select which phases the pipeline executes. */\nexport interface RunPhaseFlagOptions extends BranchFlagOptions {\n prReview?: boolean;\n}\n\n/** Phase selection `runPipeline` expects, both entries tri-state. */\nexport interface RunPhaseFlags {\n noBranch: boolean | undefined;\n prReview: boolean | undefined;\n}\n\n/** Scope flags of `run`, deciding what a discovered hierarchy does. */\nexport interface QueueScopeFlagOptions {\n yes?: boolean;\n only?: boolean;\n}\n\n/** Resolved scope answer; both absent means \"ask, when the terminal allows it\". */\nexport interface QueueScopeFlags {\n yes: boolean | undefined;\n only: boolean | undefined;\n}\n\n/**\n * Resolve `--yes` / `--only`, rejecting the combination that has no meaning.\n *\n * They answer the same question in opposite ways — run everything that was\n * discovered, or run only what was asked for — so passing both is a mistake\n * worth naming rather than silently resolving by precedence.\n *\n * @throws CliFlagError when both are present.\n */\nexport function resolveQueueScopeFlags(options: QueueScopeFlagOptions): QueueScopeFlags {\n if (options.yes === true && options.only === true) {\n throw new CliFlagError(\n '--yes cannot be combined with --only: --yes runs the whole discovered hierarchy, ' +\n '--only runs just the issues you informed.',\n );\n }\n\n return {\n yes: options.yes === true ? true : undefined,\n only: options.only === true ? true : undefined,\n };\n}\n\n/**\n * Resolve the phase-selection flags of `run`, rejecting the one combination\n * that cannot work.\n *\n * `--no-branch` skips the `pr` phase, so there is no Pull Request for\n * `--pr-review` to review. Failing here — before any phase runs — beats\n * discovering it at the end of a full pipeline.\n *\n * Both values stay `undefined` when the user passed nothing: `runPipeline`\n * uses that to tell \"no opinion, keep what tasks.json persisted\" apart from an\n * explicit choice.\n *\n * @throws CliFlagError when `--pr-review` is combined with `--no-branch`.\n */\nexport function resolveRunPhaseFlags(options: RunPhaseFlagOptions): RunPhaseFlags {\n const noBranch = resolveNoBranch(options);\n const prReview = options.prReview === true ? true : undefined;\n\n if (prReview === true && noBranch === true) {\n throw new CliFlagError(\n '--pr-review cannot be combined with --no-branch: --no-branch skips the pr phase, ' +\n 'so there is no Pull Request to review.',\n );\n }\n\n return { noBranch, prReview };\n}\n\n/** Options `run` and `plan` accept to override User Story numbering (issue #36). */\nexport interface UserStoryNumberingFlagOptions {\n continue?: boolean;\n startUs?: number;\n}\n\n/** Resolved User Story numbering override, ready for `determineUserStoryNumbering()`. */\nexport interface UserStoryNumberingFlags {\n continueFlag: boolean;\n startUs: number | undefined;\n}\n\n/**\n * Resolve the `--continue` / `--start-us <n>` override of the User Story\n * numbering cascade (issue #36), rejecting the one combination that cannot\n * work: the two disagree about whether history should be consulted at all.\n *\n * @throws CliFlagError when both flags are passed together.\n */\nexport function resolveUserStoryNumberingFlags(\n options: UserStoryNumberingFlagOptions,\n): UserStoryNumberingFlags {\n const continueFlag = options.continue === true;\n const startUs = options.startUs;\n\n if (continueFlag && startUs !== undefined) {\n throw new CliFlagError(\n '--continue and --start-us cannot be combined: choose either the last known numbering ' +\n '(--continue) or an explicit override (--start-us).',\n );\n }\n\n return { continueFlag, startUs };\n}\n","import type { IssueGenerateTarget, IssuesConfig } from './types.js';\n\n/**\n * Mapping from the Issue provider CLI flags to configuration overrides.\n *\n * Kept out of cli.ts (which runs `program.parse()` on import) so the\n * precedence rules stay unit-testable. Only the keys the user actually passed\n * are returned: a key present with `undefined` would override .issue-flow.json\n * when the layers are merged.\n */\n\nexport interface IssueCliFlags {\n local?: boolean;\n github?: boolean;\n preferLocal?: boolean;\n preferGithub?: boolean;\n ask?: boolean;\n}\n\n/** Invalid flag combination, reported to the user as a CLI error. */\nexport class IssueFlagError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'IssueFlagError';\n }\n}\n\n/**\n * Translate the parsed options of a command into `IssuesConfig` overrides.\n *\n * @throws IssueFlagError when mutually exclusive flags are combined.\n */\nexport function resolveIssuesOverrides(opts: IssueCliFlags): Partial<IssuesConfig> {\n const overrides: Partial<IssuesConfig> = {};\n\n if (opts.local === true && opts.github === true) {\n throw new IssueFlagError('--local and --github are mutually exclusive; pass only one.');\n }\n if (opts.local === true) {\n overrides.preferredProvider = 'local';\n }\n if (opts.github === true) {\n overrides.preferredProvider = 'github';\n }\n\n const conflictFlags = [\n opts.preferLocal === true ? '--prefer-local' : null,\n opts.preferGithub === true ? '--prefer-github' : null,\n opts.ask === true ? '--ask' : null,\n ].filter((flag): flag is string => flag !== null);\n\n if (conflictFlags.length > 1) {\n throw new IssueFlagError(\n `${conflictFlags.join(', ')} are mutually exclusive; pass only one conflict policy.`,\n );\n }\n if (opts.preferLocal === true) {\n overrides.conflictPolicy = 'prefer-local';\n }\n if (opts.preferGithub === true) {\n overrides.conflictPolicy = 'prefer-github';\n }\n if (opts.ask === true) {\n overrides.conflictPolicy = 'ask';\n }\n\n return overrides;\n}\n\n/** Destination flags accepted by `generate`. */\nexport interface GenerateTargetFlags {\n github?: boolean;\n local?: boolean;\n both?: boolean;\n}\n\n/**\n * Destination the generated Issue is created in, or `undefined` when the user\n * passed no flag (the caller then falls back to `defaultGenerateTarget`).\n *\n * @throws IssueFlagError when more than one destination is requested.\n */\nexport function resolveGenerateTarget(opts: GenerateTargetFlags): IssueGenerateTarget | undefined {\n const selected: IssueGenerateTarget[] = [];\n if (opts.github === true) selected.push('github');\n if (opts.local === true) selected.push('local');\n if (opts.both === true) selected.push('both');\n\n if (selected.length > 1) {\n throw new IssueFlagError(\n `${selected.map((target) => `--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AAO,iBAAiB,4CAA4C,YAAY,EAChF,OAAO,OAAO,YAAgE;AAC7E,QAAM,EAAE,YAAY,IAAI,MAAM,OAAO,mBAAmB;AACxD,QAAM,OAAO,MAAM,YAAY,OAAO;AAGtC,MAAI,SAAS,GAAG;AACd,YAAQ,KAAK,IAAI;AAAA,EACnB;AACF,CAAC;AAEH,WACG,QAAQ,MAAM,EACd,YAAY,qCAAqC,EACjD,OAAO,YAAY;AAClB,QAAM,EAAE,WAAW,IAAI,MAAM,OAAO,mBAAmB;AACvD,QAAM,OAAO,MAAM,WAAW;AAC9B,UAAQ,KAAK,IAAI;AACnB,CAAC;AAGH;AAAA,EACE,QACG,QAAQ,QAAQ,EAChB,YAAY,yEAAyE,EACrF,OAAO,iBAAiB,kDAAkD,EAC1E,OAAO,UAAU,kCAAkC;AACxD,EAAE,OAAO,OAAO,YAAgD;AAC9D,QAAM,EAAE,UAAU,IAAI,MAAM,OAAO,sBAAsB;AACzD,QAAM,OAAO,MAAM,UAAU,OAAO;AACpC,UAAQ,KAAK,IAAI;AACnB,CAAC;AAGD;AAAA,EACE,QACG,QAAQ,WAAW,EACnB,YAAY,2DAA2D,EACvE,SAAS,QAAQ,gEAAgE,EACjF,OAAO,eAAe,mCAAmC,EACzD,OAAO,eAAe,gEAAgE,EACtF,OAAO,SAAS,sDAAsD,EACtE;AAAA,IACC;AAAA,IACA;AAAA,EACF;AACJ,EAAE;AAAA,EACA,OACE,IACA,YACG;AACH,UAAM,EAAE,YAAY,IAAI,MAAM,OAAO,yBAAyB;AAC9D,UAAM,OAAO,MAAM,YAAY,IAAI,OAAO;AAC1C,YAAQ,KAAK,IAAI;AAAA,EACnB;AACF;AAEA,QAAQ,MAAM;","names":["require"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/cli-options.ts","../src/issues/cli-flags.ts","../src/resilience/cli-flags.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { Command, InvalidArgumentError } from 'commander';\nimport {\n CliFlagError,\n resolveQueueScopeFlags,\n resolveRunPhaseFlags,\n resolveUserStoryNumberingFlags,\n} from './cli-options.js';\nimport { setIssuesCliOverrides, setResilienceCliOverrides, setWebCliOverrides } from './config.js';\nimport { installShutdownHandlers } from './core/shutdown.js';\nimport { setGlobalTimeout, setInactivityTimeout, setVerbose } from './core/verbose.js';\nimport {\n IssueFlagError,\n resolveGenerateTarget,\n resolveIssuesOverrides,\n} from './issues/cli-flags.js';\nimport type { IssueGenerateTarget } from './issues/types.js';\nimport { resolveResilienceOverrides } from './resilience/cli-flags.js';\nimport type { WebConfig } from './schemas.js';\nimport { printError } from './ui/logger.js';\n\nconst require = createRequire(import.meta.url);\nconst { version } = require('../package.json') as { version: string };\n\n/**\n * Parse a numeric string, throwing InvalidArgumentError if not a valid number.\n */\nfunction parseInteger(value: string): number {\n const parsed = parseInt(value, 10);\n if (Number.isNaN(parsed) || parsed < 0) {\n throw new InvalidArgumentError('Must be a non-negative integer.');\n }\n return parsed;\n}\n\n/** Parse `--on-issue-failure <mode>`, rejecting anything but the three modes. */\nfunction parseQueueFailureMode(value: string): 'stop' | 'skip' | 'block' {\n if (value === 'stop' || value === 'skip' || value === 'block') return value;\n throw new InvalidArgumentError('Must be one of: stop, skip, block.');\n}\n\n/**\n * Parse `--start-us <n>`: a User Story number is 1-based, so 0 is rejected\n * along with everything `parseInteger` already rejects.\n */\nfunction parseStartUs(value: string): number {\n const parsed = parseInteger(value);\n if (parsed < 1) {\n throw new InvalidArgumentError('Must be a positive integer (US-001 is the first story).');\n }\n return parsed;\n}\n\n/**\n * Add the User Story numbering override options to a subcommand that\n * triggers `plan` (`run` and `plan` itself) — see issue #36.\n */\nfunction withUserStoryNumberingOptions(cmd: Command): Command {\n return cmd\n .option('--continue', 'Continue User Story numbering from the last used in this project')\n .option(\n '--start-us <n>',\n 'Force User Story numbering to start at a specific number, ignoring history',\n parseStartUs,\n );\n}\n\n/**\n * Add shared options (--verbose) to a subcommand.\n */\nfunction withGlobalOptions(cmd: Command): Command {\n return (\n cmd\n .option('-v, --verbose', 'Show Claude progress output in real time')\n .option(\n '-t, --timeout <seconds>',\n 'Override headless timeout in seconds (0 = no limit)',\n parseInteger,\n )\n // The second, tighter instrument beside the absolute timeout: a phase that\n // has said nothing for this long is stuck, not slow. `0` turns it off.\n .option(\n '--inactivity-timeout <seconds>',\n 'Stop the agent after this many seconds with no output (0 = no watchdog)',\n parseInteger,\n )\n );\n}\n\n/**\n * Add the resilience options to a subcommand, in the shape `--web` and\n * `--pr-review` already follow: declared here, resolved into configuration\n * overrides by the preAction hook, and applied through the same ladder every\n * other key climbs.\n */\nfunction withResilienceOptions(cmd: Command): Command {\n return cmd\n .option('--continuous', 'Long-running profile: keep going without supervision')\n .option('--resilient', 'Alias of --continuous')\n .option('--no-failover', 'Never migrate a phase to another agent provider')\n .option('--auto-decompose', 'Act on a decomposition report instead of only writing it');\n}\n\n/**\n * Add web monitoring options to a subcommand (run and execute only).\n * The values are resolved into CLI overrides by the preAction hook below;\n * loadWebConfig() applies the flag > env > file > defaults precedence.\n */\nfunction withWebOptions(cmd: Command): Command {\n return cmd\n .option('--web', 'Enable the web monitoring server')\n .option('--serve', 'Alias for --web')\n .option('--port <n>', 'Web server port (default: 3737)', parseInteger)\n .option('--host <h>', 'Web server host (default: 0.0.0.0)')\n .option('--refresh <s>', 'Suggested UI polling interval in seconds', parseInteger)\n .option('--web-log-limit <n>', 'Max log entries kept in the snapshot', parseInteger)\n .option('--web-no-logs', 'Exclude logs from the published snapshot');\n}\n\n/**\n * Add the Issue provider options to a subcommand.\n *\n * Declared once here (like withWebOptions) so no command repeats the flag\n * list; the preAction hook below turns them into config overrides, and\n * loadIssuesConfig() applies the flag > .issue-flow.json > defaults precedence.\n */\nfunction withIssueOptions(cmd: Command): Command {\n return cmd\n .option('--local', 'Prefer the local file Issue provider')\n .option('--github', 'Prefer the GitHub Issue provider')\n .option('--prefer-local', 'On divergence, use the local version without asking')\n .option('--prefer-github', 'On divergence, use the GitHub version without asking')\n .option('--ask', 'On divergence, ask which version to use (interactive only)');\n}\n\n/**\n * Extract the web-related CLI flags from a command's options, keeping only\n * the ones the user actually set.\n */\nfunction resolveWebOverrides(opts: Record<string, unknown>): Partial<WebConfig> {\n const overrides: Partial<WebConfig> = {};\n if (opts.web === true || opts.serve === true) {\n overrides.enabled = true;\n }\n if (opts.port !== undefined) {\n overrides.port = opts.port as number;\n }\n if (opts.host !== undefined) {\n overrides.host = opts.host as string;\n }\n if (opts.refresh !== undefined) {\n overrides.refreshSeconds = opts.refresh as number;\n }\n if (opts.webLogLimit !== undefined) {\n overrides.logLimit = opts.webLogLimit as number;\n }\n if (opts.webNoLogs === true) {\n overrides.includeLogs = false;\n }\n return overrides;\n}\n\nconst program = new Command();\n\nprogram\n .name('issue-flow')\n .description(\n 'Unified CLI for orchestrating the full issue-flow pipeline via Claude Code Headless.',\n )\n .version(version);\n\nprogram.hook('preAction', (_thisCommand, actionCommand) => {\n // Installed once, before any command runs: a `Ctrl+C` during a six-hour run\n // has to write a checkpoint and stop the agent, not kill the process\n // mid-phase and leave `session.json` on `running` forever.\n installShutdownHandlers();\n\n const opts = actionCommand.opts();\n if (opts.verbose) {\n setVerbose(true);\n }\n if (opts.timeout !== undefined) {\n setGlobalTimeout(opts.timeout * 1000);\n }\n if (opts.inactivityTimeout !== undefined) {\n setInactivityTimeout(opts.inactivityTimeout * 1000);\n }\n setWebCliOverrides(resolveWebOverrides(opts));\n // The CLI rung of the `resilience` ladder. `--continuous` expands here into\n // the settings it implies, with every granular flag applied on top of it.\n setResilienceCliOverrides(\n resolveResilienceOverrides({\n continuous: opts.continuous,\n resilient: opts.resilient,\n failover: opts.failover,\n autoDecompose: opts.autoDecompose,\n inactivityTimeout: opts.inactivityTimeout,\n onIssueFailure: opts.onIssueFailure,\n }),\n );\n try {\n setIssuesCliOverrides(resolveIssuesOverrides(opts));\n } catch (error) {\n if (error instanceof IssueFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n});\n\n// ── init ────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('init')\n .description(\n 'Check prerequisites and report (or create) the conventions this repository is missing',\n )\n .option('--apply', 'Create the missing files instead of only reporting them')\n .option('--json', 'Emit the plan as JSON')\n .option('--scope <dir>', 'Resolve the conventions for a subdirectory (monorepo)')\n .option('--check-only', 'Only verify prerequisites, as earlier releases did'),\n ),\n).action(\n async (options: { apply?: boolean; json?: boolean; scope?: string; checkOnly?: boolean }) => {\n const { loadIssuesConfig } = await import('./config.js');\n const { runInit } = await import('./commands/init.js');\n const { preferredProvider } = await loadIssuesConfig();\n const code = await runInit(preferredProvider, options);\n process.exit(code);\n },\n);\n\n// ── generate ────────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('generate')\n .description('Draft an issue via Claude Code Headless and create it')\n .requiredOption('--prompt <text>', 'Issue description text')\n .option('--github', 'Create the issue on GitHub')\n .option('--local', 'Create the issue under issues/<n>/ only')\n .option('--both', 'Create the issue on GitHub and mirror it locally'),\n).action(async (options: { prompt: string; github?: boolean; local?: boolean; both?: boolean }) => {\n let target: IssueGenerateTarget | undefined;\n try {\n target = resolveGenerateTarget(options);\n } catch (error) {\n if (error instanceof IssueFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runGenerate } = await import('./commands/generate.js');\n const code = await runGenerate(options.prompt, target);\n process.exit(code);\n});\n\n// ── run ─────────────────────────────────────────────────────────────────────\nwithUserStoryNumberingOptions(\n withResilienceOptions(\n withWebOptions(\n withIssueOptions(\n withGlobalOptions(\n program\n .command('run')\n .description(\n 'Execute the full pipeline: prd → plan → execute → review → pr (→ pr-review, optional)',\n )\n .argument('<issues...>', 'Issue number(s): 42, \"42,43\" or 42 43')\n .option('--mode <mode>', 'Execution mode: auto | manual', 'auto')\n .option('--from <phase>', 'Resume from a specific phase')\n .option(\n '--no-branch',\n 'Run pipeline on current branch without creating a new branch or PR',\n )\n .option('--pr-review', 'Review the created Pull Request after the pr phase')\n .option('-y, --yes', 'Run the whole discovered hierarchy without confirmation')\n .option('--only', 'Run just the issues informed, without their hierarchy')\n // Same two flags `execute` has always had, forwarded to the execute\n // phase of the pipeline: a `run` is the only way most users reach that\n // loop, and had no way to widen its retry budget.\n .option(\n '--retry-limit <number>',\n 'Retry transient Claude failures up to N consecutive times',\n parseInteger,\n )\n .option('--retry-forever', 'Retry transient Claude failures indefinitely')\n // What one failing issue does to the rest of a queue. `stop` is what\n // every release before this flag did, and stays the default.\n .option(\n '--on-issue-failure <mode>',\n 'In a queue, on a failing issue: stop | skip | block',\n parseQueueFailureMode,\n ),\n ),\n ),\n ),\n ),\n).action(\n async (\n issues: string[],\n options: {\n mode: string;\n from?: string;\n branch?: boolean;\n prReview?: boolean;\n yes?: boolean;\n only?: boolean;\n continue?: boolean;\n startUs?: number;\n retryLimit?: number;\n retryForever?: boolean;\n onIssueFailure?: 'stop' | 'skip' | 'block';\n },\n ) => {\n let phases: ReturnType<typeof resolveRunPhaseFlags>;\n let scope: ReturnType<typeof resolveQueueScopeFlags>;\n let numbering: ReturnType<typeof resolveUserStoryNumberingFlags>;\n try {\n phases = resolveRunPhaseFlags(options);\n scope = resolveQueueScopeFlags(options);\n numbering = resolveUserStoryNumberingFlags(options);\n } catch (error) {\n if (error instanceof CliFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runPipeline } = await import('./commands/run.js');\n const code = await runPipeline(\n issues,\n options.mode,\n options.from,\n phases.noBranch,\n phases.prReview,\n {\n yes: scope.yes,\n only: scope.only,\n continueNumbering: numbering.continueFlag,\n startUs: numbering.startUs,\n retryLimit: options.retryLimit,\n retryForever: options.retryForever,\n onIssueFailure: options.onIssueFailure,\n },\n );\n process.exit(code);\n },\n);\n\n// ── resume ──────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('resume')\n .description('Resume an interrupted pipeline from the phase it stopped at')\n .argument('[issue]', 'Issue to resume. Omitted: the most recently attempted one')\n .option('--all', 'Resume every unfinished issue of this project, in order')\n .option('--mode <mode>', 'Execution mode: auto | manual', 'auto'),\n ),\n).action(async (issue: string | undefined, options: { all?: boolean; mode?: string }) => {\n const { runResume } = await import('./commands/resume.js');\n const code = await runResume(issue, {\n ...(options.all === undefined ? {} : { all: options.all }),\n ...(options.mode === undefined ? {} : { mode: options.mode }),\n });\n process.exit(code);\n});\n\n// ── status / runs / logs / pause / cancel ───────────────────────────────────\n// The operation surface of a long run. Every one of them reads state that\n// already exists; only pause and cancel write anything, and what they write is\n// a signal to the process that owns the run.\nwithGlobalOptions(\n program\n .command('status')\n .description('What is running right now, in which phase, and since when')\n .argument('[issue]', 'Restrict the report to one issue')\n .option('--json', 'Emit the assembled state as JSON'),\n).action(async (issue: string | undefined, options: { json?: boolean }) => {\n const { runStatus } = await import('./commands/operations.js');\n process.exit(\n await runStatus(issue, { ...(options.json === undefined ? {} : { json: options.json }) }),\n );\n});\n\nwithGlobalOptions(\n program.command('runs').description('History of the runs of this project, with how each ended'),\n).action(async () => {\n const { runRuns } = await import('./commands/operations.js');\n process.exit(await runRuns());\n});\n\nwithGlobalOptions(\n program\n .command('logs')\n .description('Read the execution journal (events.jsonl), filtered and readable')\n .argument('[issue]', 'Issue to read. Omitted: the most recently attempted one')\n .option('--issue <issue>', 'Same as the positional argument')\n .option('--follow', 'Keep reading as the journal grows')\n .option('--tail <n>', 'How many entries to show first (default 50)', parseInteger)\n .option('--kind <kinds>', 'Only these event types, comma separated (retry, phase:end, …)'),\n).action(\n async (\n issue: string | undefined,\n options: { issue?: string; follow?: boolean; tail?: number; kind?: string },\n ) => {\n const { runLogs } = await import('./commands/operations.js');\n const kinds =\n options.kind === undefined\n ? undefined\n : options.kind\n .split(',')\n .map((kind) => kind.trim())\n .filter((kind) => kind !== '');\n process.exit(\n await runLogs(issue ?? options.issue, {\n ...(kinds === undefined ? {} : { kind: kinds }),\n ...(options.follow === undefined ? {} : { follow: options.follow }),\n ...(options.tail === undefined ? {} : { tail: options.tail }),\n }),\n );\n },\n);\n\nwithGlobalOptions(\n program\n .command('pause')\n .description('Ask the running pipeline to stop after writing a checkpoint'),\n).action(async () => {\n const { runPause } = await import('./commands/operations.js');\n process.exit(await runPause());\n});\n\nwithGlobalOptions(\n program\n .command('cancel')\n .description('Stop the run and mark the issue so a resume does not pick it up')\n .argument('[issue]', 'Issue to cancel. Omitted: the most recently attempted one'),\n).action(async (issue: string | undefined) => {\n const { runCancel } = await import('./commands/operations.js');\n process.exit(await runCancel(issue));\n});\n\n// ── analyze ─────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('analyze')\n .description('Analyze an issue via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runAnalyze } = await import('./commands/analyze.js');\n const code = await runAnalyze(issue);\n process.exit(code);\n});\n\n// ── prd ─────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('prd')\n .description('Generate a PRD from an analyzed issue via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runPrd } = await import('./commands/prd.js');\n const code = await runPrd(issue);\n process.exit(code);\n});\n\n// ── plan ────────────────────────────────────────────────────────────────────\nwithUserStoryNumberingOptions(\n withIssueOptions(\n withGlobalOptions(\n program\n .command('plan')\n .description('Convert a PRD to a tasks.json task plan via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n ),\n).action(async (issue: string, options: { continue?: boolean; startUs?: number }) => {\n let numbering: ReturnType<typeof resolveUserStoryNumberingFlags>;\n try {\n numbering = resolveUserStoryNumberingFlags(options);\n } catch (error) {\n if (error instanceof CliFlagError) {\n printError(error.message);\n process.exit(1);\n }\n throw error;\n }\n\n const { runPlan } = await import('./commands/plan.js');\n const code = await runPlan(issue, undefined, numbering);\n process.exit(code);\n});\n\n// ── execute ─────────────────────────────────────────────────────────────────\nwithWebOptions(\n withGlobalOptions(\n program\n .command('execute')\n .description('Run the iterative story execution loop (issue-flow engine)')\n .option('--issue <number>', 'Issue number — reads artifacts from issues/N/')\n .option('--max-iterations <number>', 'Stop after N iterations', parseInteger)\n .option(\n '--retry-limit <number>',\n 'Retry transient Claude failures up to N consecutive times',\n parseInteger,\n )\n .option('--retry-forever', 'Retry transient Claude failures indefinitely')\n .argument(\n '[max-iterations]',\n 'Backward-compatible alias for --max-iterations N',\n parseInteger,\n ),\n ),\n).action(\n async (\n positionalMaxIter: number | undefined,\n options: {\n issue?: string;\n maxIterations?: number;\n retryLimit?: number;\n retryForever?: boolean;\n },\n ) => {\n try {\n const { runExecute } = await import('./commands/execute.js');\n const code = await runExecute(positionalMaxIter, options);\n process.exit(code);\n } catch (error) {\n printError(error instanceof Error ? error.message : String(error));\n process.exit(1);\n }\n },\n);\n\n// ── review ──────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('review')\n .description('Validate an issue resolution via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runReview } = await import('./commands/review.js');\n const code = await runReview(issue);\n process.exit(code);\n});\n\n// ── pr ──────────────────────────────────────────────────────────────────────\nwithIssueOptions(\n withGlobalOptions(\n program\n .command('pr')\n .description('Create a pull request via Claude Code Headless')\n .argument('<issue>', 'Issue number'),\n ),\n).action(async (issue: string) => {\n const { runPr } = await import('./commands/pr.js');\n const code = await runPr(issue);\n process.exit(code);\n});\n\n// ── web ─────────────────────────────────────────────────────────────────────\nconst webCommand = program.command('web').description('Manage the web monitoring server');\n\nwebCommand\n .command('serve')\n .description(\n 'Run the web monitor server in the foreground (internal — spawned detached by --web)',\n )\n .option('--port <n>', 'Web server port (default: 3737)', parseInteger)\n .option('--host <h>', 'Web server host (default: 0.0.0.0)')\n .option('--refresh <s>', 'Suggested UI polling interval in seconds', parseInteger)\n .action(async (options: { port?: number; host?: string; refresh?: number }) => {\n const { runWebServe } = await import('./commands/web.js');\n const code = await runWebServe(options);\n // On success this process stays alive for as long as the server is bound\n // (server.ts binds it with unref: false) — only a failure exits here.\n if (code !== 0) {\n process.exit(code);\n }\n });\n\nwebCommand\n .command('stop')\n .description('Stop the running web monitor server')\n .action(async () => {\n const { runWebStop } = await import('./commands/web.js');\n const code = await runWebStop();\n process.exit(code);\n });\n\n// ── policy ──────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('policy')\n .description('Inspect the policies discovered in this repository and their provenance')\n .option('--scope <dir>', 'Resolve the policy for a subdirectory (monorepo)')\n .option('--json', 'Emit the resolved policy as JSON'),\n).action(async (options: { scope?: string; json?: boolean }) => {\n const { runPolicy } = await import('./commands/policy.js');\n const code = await runPolicy(options);\n process.exit(code);\n});\n\n// ── pr-review ───────────────────────────────────────────────────────────────\nwithGlobalOptions(\n program\n .command('pr-review')\n .description('Review a Pull Request as a whole via Claude Code Headless')\n .argument('[pr]', 'Pull Request number (discovered from the session when omitted)')\n .option('--issue <n>', 'Issue the Pull Request belongs to')\n .option('--round <n>', 'Rewrite a specific review round instead of appending a new one')\n .option('--yes', 'Skip the confirmation of the discovered Pull Request')\n .option(\n '--fail-on <level>',\n 'Verdict that fails the command: request-changes | suggestions | none',\n ),\n).action(\n async (\n pr: string | undefined,\n options: { issue?: string; round?: string; yes?: boolean; failOn?: string },\n ) => {\n const { runPrReview } = await import('./commands/pr-review.js');\n const code = await runPrReview(pr, options);\n process.exit(code);\n },\n);\n\nprogram.parse();\n","/**\n * Pure mappings from parsed CLI options to command arguments.\n *\n * They live outside cli.ts because that module runs `program.parse()` on\n * import, so anything defined there is untestable.\n */\n\n/** Shape commander produces for a negated boolean option (`--no-branch`). */\nexport interface BranchFlagOptions {\n branch?: boolean;\n}\n\n/**\n * Translate commander's `--no-branch` into the tri-state `runPipeline` expects.\n *\n * Commander stores a negated option under its positive name: `--no-branch`\n * yields `{ branch: false }` and never a `noBranch` key. Reading `noBranch`\n * silently dropped the flag, so the pipeline always created a branch and opened\n * a PR.\n *\n * `undefined` (flag absent) is preserved on purpose: `runPipeline` uses it to\n * tell \"the user said nothing, keep the mode persisted in tasks.json\" apart\n * from an explicit choice.\n */\nexport function resolveNoBranch(options: BranchFlagOptions): boolean | undefined {\n return options.branch === false ? true : undefined;\n}\n\n/** Invalid flag combination on a command, reported as a CLI error. */\nexport class CliFlagError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CliFlagError';\n }\n}\n\n/** Options `run` accepts that select which phases the pipeline executes. */\nexport interface RunPhaseFlagOptions extends BranchFlagOptions {\n prReview?: boolean;\n}\n\n/** Phase selection `runPipeline` expects, both entries tri-state. */\nexport interface RunPhaseFlags {\n noBranch: boolean | undefined;\n prReview: boolean | undefined;\n}\n\n/** Scope flags of `run`, deciding what a discovered hierarchy does. */\nexport interface QueueScopeFlagOptions {\n yes?: boolean;\n only?: boolean;\n}\n\n/** Resolved scope answer; both absent means \"ask, when the terminal allows it\". */\nexport interface QueueScopeFlags {\n yes: boolean | undefined;\n only: boolean | undefined;\n}\n\n/**\n * Resolve `--yes` / `--only`, rejecting the combination that has no meaning.\n *\n * They answer the same question in opposite ways — run everything that was\n * discovered, or run only what was asked for — so passing both is a mistake\n * worth naming rather than silently resolving by precedence.\n *\n * @throws CliFlagError when both are present.\n */\nexport function resolveQueueScopeFlags(options: QueueScopeFlagOptions): QueueScopeFlags {\n if (options.yes === true && options.only === true) {\n throw new CliFlagError(\n '--yes cannot be combined with --only: --yes runs the whole discovered hierarchy, ' +\n '--only runs just the issues you informed.',\n );\n }\n\n return {\n yes: options.yes === true ? true : undefined,\n only: options.only === true ? true : undefined,\n };\n}\n\n/**\n * Resolve the phase-selection flags of `run`, rejecting the one combination\n * that cannot work.\n *\n * `--no-branch` skips the `pr` phase, so there is no Pull Request for\n * `--pr-review` to review. Failing here — before any phase runs — beats\n * discovering it at the end of a full pipeline.\n *\n * Both values stay `undefined` when the user passed nothing: `runPipeline`\n * uses that to tell \"no opinion, keep what tasks.json persisted\" apart from an\n * explicit choice.\n *\n * @throws CliFlagError when `--pr-review` is combined with `--no-branch`.\n */\nexport function resolveRunPhaseFlags(options: RunPhaseFlagOptions): RunPhaseFlags {\n const noBranch = resolveNoBranch(options);\n const prReview = options.prReview === true ? true : undefined;\n\n if (prReview === true && noBranch === true) {\n throw new CliFlagError(\n '--pr-review cannot be combined with --no-branch: --no-branch skips the pr phase, ' +\n 'so there is no Pull Request to review.',\n );\n }\n\n return { noBranch, prReview };\n}\n\n/** Options `run` and `plan` accept to override User Story numbering (issue #36). */\nexport interface UserStoryNumberingFlagOptions {\n continue?: boolean;\n startUs?: number;\n}\n\n/** Resolved User Story numbering override, ready for `determineUserStoryNumbering()`. */\nexport interface UserStoryNumberingFlags {\n continueFlag: boolean;\n startUs: number | undefined;\n}\n\n/**\n * Resolve the `--continue` / `--start-us <n>` override of the User Story\n * numbering cascade (issue #36), rejecting the one combination that cannot\n * work: the two disagree about whether history should be consulted at all.\n *\n * @throws CliFlagError when both flags are passed together.\n */\nexport function resolveUserStoryNumberingFlags(\n options: UserStoryNumberingFlagOptions,\n): UserStoryNumberingFlags {\n const continueFlag = options.continue === true;\n const startUs = options.startUs;\n\n if (continueFlag && startUs !== undefined) {\n throw new CliFlagError(\n '--continue and --start-us cannot be combined: choose either the last known numbering ' +\n '(--continue) or an explicit override (--start-us).',\n );\n }\n\n return { continueFlag, startUs };\n}\n","import type { IssueGenerateTarget, IssuesConfig } from './types.js';\n\n/**\n * Mapping from the Issue provider CLI flags to configuration overrides.\n *\n * Kept out of cli.ts (which runs `program.parse()` on import) so the\n * precedence rules stay unit-testable. Only the keys the user actually passed\n * are returned: a key present with `undefined` would override .issue-flow.json\n * when the layers are merged.\n */\n\nexport interface IssueCliFlags {\n local?: boolean;\n github?: boolean;\n preferLocal?: boolean;\n preferGithub?: boolean;\n ask?: boolean;\n}\n\n/** Invalid flag combination, reported to the user as a CLI error. */\nexport class IssueFlagError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'IssueFlagError';\n }\n}\n\n/**\n * Translate the parsed options of a command into `IssuesConfig` overrides.\n *\n * @throws IssueFlagError when mutually exclusive flags are combined.\n */\nexport function resolveIssuesOverrides(opts: IssueCliFlags): Partial<IssuesConfig> {\n const overrides: Partial<IssuesConfig> = {};\n\n if (opts.local === true && opts.github === true) {\n throw new IssueFlagError('--local and --github are mutually exclusive; pass only one.');\n }\n if (opts.local === true) {\n overrides.preferredProvider = 'local';\n }\n if (opts.github === true) {\n overrides.preferredProvider = 'github';\n }\n\n const conflictFlags = [\n opts.preferLocal === true ? '--prefer-local' : null,\n opts.preferGithub === true ? '--prefer-github' : null,\n opts.ask === true ? '--ask' : null,\n ].filter((flag): flag is string => flag !== null);\n\n if (conflictFlags.length > 1) {\n throw new IssueFlagError(\n `${conflictFlags.join(', ')} are mutually exclusive; pass only one conflict policy.`,\n );\n }\n if (opts.preferLocal === true) {\n overrides.conflictPolicy = 'prefer-local';\n }\n if (opts.preferGithub === true) {\n overrides.conflictPolicy = 'prefer-github';\n }\n if (opts.ask === true) {\n overrides.conflictPolicy = 'ask';\n }\n\n return overrides;\n}\n\n/** Destination flags accepted by `generate`. */\nexport interface GenerateTargetFlags {\n github?: boolean;\n local?: boolean;\n both?: boolean;\n}\n\n/**\n * Destination the generated Issue is created in, or `undefined` when the user\n * passed no flag (the caller then falls back to `defaultGenerateTarget`).\n *\n * @throws IssueFlagError when more than one destination is requested.\n */\nexport function resolveGenerateTarget(opts: GenerateTargetFlags): IssueGenerateTarget | undefined {\n const selected: IssueGenerateTarget[] = [];\n if (opts.github === true) selected.push('github');\n if (opts.local === true) selected.push('local');\n if (opts.both === true) selected.push('both');\n\n if (selected.length > 1) {\n throw new IssueFlagError(\n `${selected.map((target) => `--${target}`).join(', ')} are mutually exclusive; ` +\n 'pass only one destination.',\n );\n }\n\n return selected[0];\n}\n","import { DEFAULT_INACTIVITY_TIMEOUT_MS } from '../core/watchdog.js';\nimport type { ResilienceConfig } from '../storage/schemas.js';\n\n/**\n * The resilience flags, turned into the CLI rung of the configuration ladder.\n *\n * Kept out of `cli.ts` (which runs `program.parse()` on import) so the mapping\n * is testable on its own, the same reason `cli-options.ts` and\n * `issues/cli-flags.ts` live outside it.\n *\n * **`--continuous` is a profile, not a mechanism.** Long autonomous work needs\n * about six behaviours turned on at once, and asking for six flags is asking\n * for five of them to be forgotten. So the profile names the *intent* — \"keep\n * going without me\" — and expands to the settings that intent implies, every\n * one of which stays adjustable on its own.\n */\n\nexport interface ResilienceFlags {\n /** `--continuous` / `--resilient`: the long-running profile. */\n continuous?: boolean;\n resilient?: boolean;\n /** `--no-failover`: never migrate a phase to another provider. */\n failover?: boolean;\n /** `--auto-decompose`: act on a decomposition report instead of reporting. */\n autoDecompose?: boolean;\n /** `--inactivity-timeout <seconds>`: the watchdog budget. */\n inactivityTimeout?: number;\n /** `--on-issue-failure <mode>`: what a failing issue does to the queue. */\n onIssueFailure?: 'stop' | 'skip' | 'block';\n}\n\n/**\n * What `--continuous` turns on.\n *\n * The retry side is the `continuous` **profile** of `resolvePolicy()` — network\n * and rate limits retried forever, wider budgets for the rest — rather than a\n * list of numbers repeated here, so the two cannot drift. The rest is what the\n * profile implies at the pipeline level: keep the queue moving, keep a journal\n * of what happened, and notice an agent that has gone quiet.\n */\nfunction continuousProfile(): ResilienceConfig {\n return {\n profile: 'continuous',\n providers: { failover: true },\n queue: { onIssueFailure: 'skip' },\n journal: { enabled: true },\n watchdog: { inactivityTimeoutMs: DEFAULT_INACTIVITY_TIMEOUT_MS },\n };\n}\n\n/**\n * Resolve the flags into one `resilience` object.\n *\n * The profile is applied first and the granular flags on top of it, which is\n * the whole precedence rule: **an explicit flag always beats the profile**.\n * `--continuous --no-failover` is a coherent thing to ask for and means exactly\n * what it says.\n */\nexport function resolveResilienceOverrides(flags: ResilienceFlags): ResilienceConfig {\n const continuous = flags.continuous === true || flags.resilient === true;\n const overrides: ResilienceConfig = continuous ? continuousProfile() : {};\n\n // Commander maps `--no-failover` to `failover: false`, and leaves the field\n // absent when the flag was not passed — so `false` here is always explicit.\n if (flags.failover === false) {\n overrides.providers = { ...overrides.providers, failover: false };\n }\n if (flags.autoDecompose === true) {\n overrides.decompose = { ...overrides.decompose, auto: true };\n }\n if (flags.inactivityTimeout !== undefined) {\n overrides.watchdog = {\n ...overrides.watchdog,\n inactivityTimeoutMs: flags.inactivityTimeout * 1000,\n };\n }\n if (flags.onIssueFailure !== undefined) {\n overrides.queue = { ...overrides.queue, onIssueFailure: flags.onIssueFailure };\n }\n\n return overrides;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,SAAS,4BAA4B;;;ACuBvC,SAAS,gBAAgB,SAAiD;AAC/E,SAAO,QAAQ,WAAW,QAAQ,OAAO;AAC3C;AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAkCO,SAAS,uBAAuB,SAAiD;AACtF,MAAI,QAAQ,QAAQ,QAAQ,QAAQ,SAAS,MAAM;AACjD,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,KAAK,QAAQ,QAAQ,OAAO,OAAO;AAAA,IACnC,MAAM,QAAQ,SAAS,OAAO,OAAO;AAAA,EACvC;AACF;AAgBO,SAAS,qBAAqB,SAA6C;AAChF,QAAM,WAAW,gBAAgB,OAAO;AACxC,QAAM,WAAW,QAAQ,aAAa,OAAO,OAAO;AAEpD,MAAI,aAAa,QAAQ,aAAa,MAAM;AAC1C,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,SAAS;AAC9B;AAqBO,SAAS,+BACd,SACyB;AACzB,QAAM,eAAe,QAAQ,aAAa;AAC1C,QAAM,UAAU,QAAQ;AAExB,MAAI,gBAAgB,YAAY,QAAW;AACzC,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO,EAAE,cAAc,QAAQ;AACj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E;AAAA,EACA,OACE,IACA,YACG;AACH,UAAM,EAAE,YAAY,IAAI,MAAM,OAAO,yBAAyB;AAC9D,UAAM,OAAO,MAAM,YAAY,IAAI,OAAO;AAC1C,YAAQ,KAAK,IAAI;AAAA,EACnB;AACF;AAEA,QAAQ,MAAM;","names":["require"]}
|
|
@@ -5,37 +5,49 @@ import {
|
|
|
5
5
|
PROJECT_CONFIG_FILENAME,
|
|
6
6
|
WEB_CONFIG_FILENAME,
|
|
7
7
|
createConfig,
|
|
8
|
+
getActiveResilienceConfig,
|
|
8
9
|
getInstallHint,
|
|
10
|
+
initResilienceConfig,
|
|
9
11
|
loadGlobalConfig,
|
|
10
12
|
loadIssuesConfig,
|
|
11
13
|
loadPolicyConfig,
|
|
12
14
|
loadPrReviewConfig,
|
|
15
|
+
loadResilienceConfig,
|
|
13
16
|
loadWebConfig,
|
|
14
17
|
mergeConfigLayers,
|
|
15
18
|
resolvePaths,
|
|
19
|
+
setActiveResilienceConfig,
|
|
16
20
|
setIssuesCliOverrides,
|
|
17
21
|
setPolicyCliOverrides,
|
|
22
|
+
setResilienceCliOverrides,
|
|
18
23
|
setWebCliOverrides,
|
|
19
24
|
validateDependencies
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-42PJFMAR.js";
|
|
26
|
+
import "./chunk-DIDUVL6O.js";
|
|
27
|
+
import "./chunk-BYZDPR7N.js";
|
|
28
|
+
import "./chunk-CD5ULRVC.js";
|
|
22
29
|
export {
|
|
23
30
|
DEFAULTS,
|
|
24
31
|
GLOBAL_CONFIG_FILENAME,
|
|
25
32
|
PROJECT_CONFIG_FILENAME,
|
|
26
33
|
WEB_CONFIG_FILENAME,
|
|
27
34
|
createConfig,
|
|
35
|
+
getActiveResilienceConfig,
|
|
28
36
|
getInstallHint,
|
|
37
|
+
initResilienceConfig,
|
|
29
38
|
loadGlobalConfig,
|
|
30
39
|
loadIssuesConfig,
|
|
31
40
|
loadPolicyConfig,
|
|
32
41
|
loadPrReviewConfig,
|
|
42
|
+
loadResilienceConfig,
|
|
33
43
|
loadWebConfig,
|
|
34
44
|
mergeConfigLayers,
|
|
35
45
|
resolvePaths,
|
|
46
|
+
setActiveResilienceConfig,
|
|
36
47
|
setIssuesCliOverrides,
|
|
37
48
|
setPolicyCliOverrides,
|
|
49
|
+
setResilienceCliOverrides,
|
|
38
50
|
setWebCliOverrides,
|
|
39
51
|
validateDependencies
|
|
40
52
|
};
|
|
41
|
-
//# sourceMappingURL=config-
|
|
53
|
+
//# sourceMappingURL=config-PRJGWW7J.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
runExecute
|
|
4
|
+
} from "./chunk-3QHK4YQA.js";
|
|
5
|
+
import "./chunk-TSOLWK7Y.js";
|
|
6
|
+
import "./chunk-LWRSMTTZ.js";
|
|
7
|
+
import "./chunk-MJULIKQU.js";
|
|
8
|
+
import "./chunk-LAFNLLQP.js";
|
|
9
|
+
import "./chunk-M66SJHQQ.js";
|
|
10
|
+
import "./chunk-EZATO3DW.js";
|
|
11
|
+
import "./chunk-42PJFMAR.js";
|
|
12
|
+
import "./chunk-DIDUVL6O.js";
|
|
13
|
+
import "./chunk-BYZDPR7N.js";
|
|
14
|
+
import "./chunk-CD5ULRVC.js";
|
|
15
|
+
export {
|
|
16
|
+
runExecute
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=execute-XBNVL753.js.map
|
|
@@ -4,36 +4,42 @@ import {
|
|
|
4
4
|
ensureProvidersRegistered,
|
|
5
5
|
getProvider,
|
|
6
6
|
localIssueRef
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-73ATPIYX.js";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_HEADLESS_TIMEOUT_MS,
|
|
10
10
|
runHeadless
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-4JSOYE4G.js";
|
|
12
|
+
import "./chunk-KMMASOA6.js";
|
|
12
13
|
import {
|
|
13
14
|
publishPhaseMetrics,
|
|
14
15
|
resolvePolicyPlaceholders
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-MJULIKQU.js";
|
|
16
17
|
import {
|
|
17
18
|
applyPlaceholders,
|
|
18
19
|
loadPrompt
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LAFNLLQP.js";
|
|
21
|
+
import "./chunk-M66SJHQQ.js";
|
|
20
22
|
import {
|
|
21
23
|
loadRepositoryPolicy
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-EZATO3DW.js";
|
|
23
25
|
import {
|
|
24
26
|
loadIssuesConfig,
|
|
25
|
-
loadPolicyConfig
|
|
27
|
+
loadPolicyConfig
|
|
28
|
+
} from "./chunk-42PJFMAR.js";
|
|
29
|
+
import {
|
|
26
30
|
resolveProjectPaths,
|
|
27
31
|
run
|
|
28
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-DIDUVL6O.js";
|
|
29
33
|
import {
|
|
30
34
|
getGlobalTimeout,
|
|
31
|
-
isoNow,
|
|
32
35
|
printError,
|
|
33
36
|
printInfo,
|
|
34
37
|
printSuccess,
|
|
35
38
|
printWarning
|
|
36
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-BYZDPR7N.js";
|
|
40
|
+
import {
|
|
41
|
+
isoNow
|
|
42
|
+
} from "./chunk-CD5ULRVC.js";
|
|
37
43
|
|
|
38
44
|
// src/issues/draft.ts
|
|
39
45
|
var DRAFT_TAG = "issue-draft";
|
|
@@ -241,4 +247,4 @@ async function runGenerate(promptText, target) {
|
|
|
241
247
|
export {
|
|
242
248
|
runGenerate
|
|
243
249
|
};
|
|
244
|
-
//# sourceMappingURL=generate-
|
|
250
|
+
//# sourceMappingURL=generate-EGB4KV2B.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/issues/draft.ts","../src/issues/label-policy.ts","../src/commands/generate.ts"],"sourcesContent":["import type { IssueDraft } from './types.js';\n\n/**\n * Structured Issue draft emitted by the `generate` prompt.\n *\n * The agent no longer creates the Issue itself: it returns the content and the\n * providers persist it, so the same draft can reach GitHub, the local files, or\n * both. Capturing the result therefore has to be exact — the old approach of\n * fishing an issue URL out of free-form prose only ever worked for GitHub.\n *\n * The block mirrors the `<issue-body>` convention already used by the phase\n * templates, which keeps a multi-line markdown body readable and free of the\n * escaping a JSON payload would demand.\n */\n\n/** Wrapper the agent must emit around the draft. */\nexport const DRAFT_TAG = 'issue-draft';\n\n/** Failure to capture a draft from the agent output. */\nexport class IssueDraftParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'IssueDraftParseError';\n }\n}\n\n/**\n * Last occurrence of `<tag>...</tag>` in `source`, or `null`.\n *\n * The last one wins: an agent that shows the format before filling it in (or\n * restates the draft after a correction) would otherwise have its first,\n * throwaway attempt captured. The closing tag is searched from the end for the\n * same reason a body may legitimately quote one.\n */\nfunction extractTag(source: string, tag: string): string | null {\n const open = `<${tag}>`;\n const close = `</${tag}>`;\n\n const start = source.lastIndexOf(open);\n if (start === -1) return null;\n\n const end = source.lastIndexOf(close);\n if (end === -1 || end < start) return null;\n\n return source.slice(start + open.length, end);\n}\n\nfunction parseLabels(raw: string | null): string[] {\n if (raw === null) return [];\n return raw\n .split(',')\n .map((label) => label.trim())\n .filter((label) => label.length > 0 && label.toLowerCase() !== '(none)');\n}\n\n/**\n * Read the draft the agent produced.\n *\n * @throws IssueDraftParseError when the block is absent or has no usable\n * title/body, so a malformed answer fails loudly instead of creating an empty\n * Issue.\n */\nexport function parseIssueDraft(output: string): IssueDraft {\n const normalized = output.replace(/\\r\\n?/g, '\\n');\n const block = extractTag(normalized, DRAFT_TAG);\n\n if (block === null) {\n throw new IssueDraftParseError(\n `The agent did not emit an <${DRAFT_TAG}> block, so there is no Issue to create. ` +\n `Output was: ${normalized.trim().slice(0, 300) || '(empty)'}`,\n );\n }\n\n const title = (extractTag(block, 'title') ?? '').trim();\n const body = (extractTag(block, 'body') ?? '').trim();\n\n if (title.length === 0) {\n throw new IssueDraftParseError(`The <${DRAFT_TAG}> block has no <title>.`);\n }\n if (body.length === 0) {\n throw new IssueDraftParseError(`The <${DRAFT_TAG}> block has no <body>.`);\n }\n\n // Optional, and deliberately so: a repository with no Issue Types and no\n // templates emits neither, and the draft is exactly what it was before.\n const type = (extractTag(block, 'type') ?? '').trim();\n const template = (extractTag(block, 'template') ?? '').trim();\n\n return {\n title,\n body,\n labels: parseLabels(extractTag(block, 'labels')),\n ...(type === '' || type.toLowerCase() === '(none)' ? {} : { type }),\n ...(template === '' || template.toLowerCase() === '(none)' ? {} : { template }),\n };\n}\n","import type { LabelDefinition } from '../policy/types.js';\nimport { run } from '../utils/shell.js';\n\n/**\n * Reconciling the labels an agent suggested with the ones the repository\n * actually has.\n *\n * A workflow tool has no business changing a repository's taxonomy. Labels are\n * governance: a team that deleted `high`/`medium`/`low` in favour of a native\n * priority field, or `bug`/`enhancement` in favour of Issue Types, made a\n * decision — and a generator that silently recreates them undoes it, quietly and\n * repository-wide.\n *\n * So the default is to **validate, never create**. `policy.issues.allowLabelCreation`\n * restores the old behaviour for repositories that want it.\n */\n\nexport interface LabelReconciliation {\n /** Labels to apply, in the repository's own casing. */\n labels: string[];\n /** Suggested labels the repository does not have. */\n missing: string[];\n}\n\n/**\n * Intersect the suggested labels with the repository's real ones.\n *\n * Matching is case-insensitive and the result carries the **repository's**\n * casing: `gh issue create --label Bug` fails on a repository whose label is\n * `bug`, and an agent has no way to know which one it is.\n *\n * An empty `known` means the labels could not be read at all — no policy, no\n * `gh`, no network. That is not evidence the labels do not exist, so the\n * suggestions pass through untouched and the behaviour is the one that shipped\n * before this layer. Refusing to label an issue because discovery was offline\n * would be the wrong failure.\n */\nexport function reconcileLabels(\n suggested: string[],\n known: LabelDefinition[],\n): LabelReconciliation {\n if (known.length === 0) {\n return { labels: [...suggested], missing: [] };\n }\n\n const canonical = new Map(known.map((label) => [label.name.toLowerCase(), label.name]));\n\n const labels: string[] = [];\n const missing: string[] = [];\n for (const suggestion of suggested) {\n const match = canonical.get(suggestion.trim().toLowerCase());\n if (match === undefined) {\n if (!missing.includes(suggestion)) missing.push(suggestion);\n continue;\n }\n if (!labels.includes(match)) labels.push(match);\n }\n\n return { labels, missing };\n}\n\n/**\n * Create the labels the repository is missing, for\n * `policy.issues.allowLabelCreation: true`.\n *\n * Best-effort per label: one that cannot be created is reported and skipped, so\n * a single failure does not cost the Issue. Returns the labels that now exist.\n */\nexport async function createMissingLabels(\n names: string[],\n warn: (message: string) => void,\n): Promise<string[]> {\n const created: string[] = [];\n\n for (const name of names) {\n const result = await run('gh', ['label', 'create', name]);\n if (result.exitCode === 0) {\n created.push(name);\n continue;\n }\n // gh answers \"already exists\" when a label was created between the\n // discovery and now, which is a success for our purposes.\n const detail = (result.stderr || result.stdout).trim();\n if (/already exists/i.test(detail)) {\n created.push(name);\n continue;\n }\n warn(`Could not create label \"${name}\": ${detail || 'gh label create failed'}`);\n }\n\n return created;\n}\n","import { loadIssuesConfig, loadPolicyConfig } from '../config.js';\nimport { DEFAULT_HEADLESS_TIMEOUT_MS, runHeadless } from '../core/headless.js';\nimport { applyPlaceholders, loadPrompt } from '../core/prompt-resolver.js';\nimport { publishPhaseMetrics } from '../core/session-metrics.js';\nimport { isoNow } from '../core/state-manager.js';\nimport { getGlobalTimeout } from '../core/verbose.js';\nimport { ensureProvidersRegistered } from '../issues/bootstrap.js';\nimport { localIssueRef } from '../issues/context.js';\nimport { IssueDraftParseError, parseIssueDraft } from '../issues/draft.js';\nimport { createMissingLabels, reconcileLabels } from '../issues/label-policy.js';\nimport { getProvider } from '../issues/registry.js';\nimport type { Issue, IssueDraft, IssueGenerateTarget } from '../issues/types.js';\nimport { loadRepositoryPolicy } from '../policy/index.js';\nimport { resolvePolicyPlaceholders } from '../policy/placeholders.js';\nimport { resolveProjectPaths } from '../storage/resolve.js';\nimport { printError, printInfo, printSuccess, printWarning } from '../ui/logger.js';\n\n/** Human-readable pointer to a created Issue. */\nfunction issueLocation(issue: Issue): string {\n return issue.remoteRef ?? localIssueRef(issue.id);\n}\n\n/**\n * Ask the agent for the Issue content.\n *\n * The agent only drafts: creation belongs to the providers, so the same draft\n * can be persisted to GitHub, to the local files, or to both.\n */\nasync function draftIssue(promptText: string): Promise<IssueDraft> {\n // The duplicate check reads the local issues, which live in the global\n // storage: the path has to be handed over (and allowed) explicitly, since it\n // is outside the working directory the agent is started in.\n const { issuesDir } = await resolveProjectPaths();\n\n const template = await loadPrompt('generate');\n const prompt = applyPlaceholders(template, {\n // The repository's own conventions. Empty when it declares none, which is\n // what keeps the rendered prompt identical to the pre-policy one.\n ...(await resolvePolicyPlaceholders()),\n __USER_PROMPT__: promptText,\n __LOCAL_ISSUES_DIR__: issuesDir,\n });\n\n const startedAtMs = Date.now();\n const result = await runHeadless({\n prompt,\n maxTurns: 15,\n timeout: getGlobalTimeout() ?? DEFAULT_HEADLESS_TIMEOUT_MS,\n // json (not text) so the CLI reports usage: the envelope's `result` field\n // carries the same assistant text parseIssueDraft() already consumed.\n outputFormat: 'json',\n allowedTools: ['Bash', 'Read', 'Glob', 'Grep'],\n addDirs: [issuesDir],\n statusMessage: 'Drafting issue...',\n });\n // Before the success check: the tokens were spent either way.\n publishPhaseMetrics('generate', result.cost, startedAtMs);\n\n if (!result.success) {\n throw new Error(`Issue creation failed: ${result.error}`);\n }\n\n return parseIssueDraft(result.result);\n}\n\n/**\n * Create the GitHub Issue and mirror it locally.\n *\n * The remote comes first on purpose: it owns the identifier, and the mirror has\n * to reuse it so both copies describe one demand. A remote failure therefore\n * leaves nothing behind, and a mirror failure is reported with the remote\n * reference that already exists.\n */\nasync function createBoth(draft: IssueDraft): Promise<Issue[]> {\n const remote = await getProvider('github').create(draft);\n\n try {\n const mirror = await getProvider('local').create({\n ...draft,\n id: remote.id,\n ...(remote.remoteRef\n ? {\n remote: {\n provider: 'github' as const,\n ref: remote.remoteRef,\n syncedAt: isoNow(),\n syncedContentHash: remote.contentHash,\n },\n }\n : {}),\n });\n return [remote, mirror];\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(\n `GitHub issue created at ${issueLocation(remote)}, but the local mirror was not written: ` +\n `${message}. Nothing else was persisted; re-run with --local to create the mirror.`,\n );\n }\n}\n\nasync function createIssues(target: IssueGenerateTarget, draft: IssueDraft): Promise<Issue[]> {\n if (target === 'both') {\n return createBoth(draft);\n }\n return [await getProvider(target).create(draft)];\n}\n\n/**\n * Reconcile the draft's labels with the ones the repository really has.\n *\n * Two failures are being prevented here, and only one of them is cosmetic.\n * GitHub rejects an issue whose label does not exist, so an invented label costs\n * the whole Issue. And a tool that creates the label instead rewrites a taxonomy\n * the team may have curated deliberately — which is worse, because it succeeds.\n *\n * Never throws: a policy that could not be resolved leaves the draft untouched.\n */\nasync function applyLabelPolicy(draft: IssueDraft): Promise<IssueDraft> {\n let known: Awaited<ReturnType<typeof loadRepositoryPolicy>>['issues']['labels'];\n let allowCreation: boolean;\n try {\n const policy = await loadRepositoryPolicy();\n known = policy.issues.labels;\n const config = await loadPolicyConfig({ projectRoot: policy.root });\n allowCreation = config.issues.allowLabelCreation ?? false;\n } catch {\n return draft;\n }\n\n const { labels, missing } = reconcileLabels(draft.labels, known);\n if (missing.length === 0) {\n return { ...draft, labels };\n }\n\n if (!allowCreation) {\n printWarning(\n `Dropping ${missing.length} label(s) this repository does not have: ${missing.join(', ')}. ` +\n 'Issue Flow does not create labels; set policy.issues.allowLabelCreation to change that.',\n );\n return { ...draft, labels };\n }\n\n const created = await createMissingLabels(missing, printWarning);\n return { ...draft, labels: [...labels, ...created] };\n}\n\nexport async function runGenerate(\n promptText: string,\n target?: IssueGenerateTarget,\n): Promise<number> {\n const config = await loadIssuesConfig();\n const destination = target ?? config.defaultGenerateTarget;\n\n ensureProvidersRegistered();\n\n let draft: IssueDraft;\n try {\n draft = await draftIssue(promptText);\n } catch (err) {\n if (err instanceof IssueDraftParseError) {\n printError(`Could not read the generated Issue draft: ${err.message}`);\n } else {\n printError(err instanceof Error ? err.message : String(err));\n }\n return 1;\n }\n\n const finalDraft = await applyLabelPolicy(draft);\n if (finalDraft.template !== undefined) {\n printInfo(`Following the repository's Issue Template: ${finalDraft.template}`);\n }\n if (finalDraft.type !== undefined) {\n printInfo(`Issue Type: ${finalDraft.type}`);\n }\n\n let created: Issue[];\n try {\n created = await createIssues(destination, finalDraft);\n } catch (err) {\n printError(err instanceof Error ? err.message : String(err));\n return 1;\n }\n\n for (const issue of created) {\n printSuccess(`Issue created (${issue.source}): ${issueLocation(issue)}`);\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,IAAM,YAAY;AAGlB,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAUA,SAAS,WAAW,QAAgB,KAA4B;AAC9D,QAAM,OAAO,IAAI,GAAG;AACpB,QAAM,QAAQ,KAAK,GAAG;AAEtB,QAAM,QAAQ,OAAO,YAAY,IAAI;AACrC,MAAI,UAAU,GAAI,QAAO;AAEzB,QAAM,MAAM,OAAO,YAAY,KAAK;AACpC,MAAI,QAAQ,MAAM,MAAM,MAAO,QAAO;AAEtC,SAAO,OAAO,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9C;AAEA,SAAS,YAAY,KAA8B;AACjD,MAAI,QAAQ,KAAM,QAAO,CAAC;AAC1B,SAAO,IACJ,MAAM,GAAG,EACT,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAC3B,OAAO,CAAC,UAAU,MAAM,SAAS,KAAK,MAAM,YAAY,MAAM,QAAQ;AAC3E;AASO,SAAS,gBAAgB,QAA4B;AAC1D,QAAM,aAAa,OAAO,QAAQ,UAAU,IAAI;AAChD,QAAM,QAAQ,WAAW,YAAY,SAAS;AAE9C,MAAI,UAAU,MAAM;AAClB,UAA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"sourcesContent":["import type { IssueDraft } from './types.js';\n\n/**\n * Structured Issue draft emitted by the `generate` prompt.\n *\n * The agent no longer creates the Issue itself: it returns the content and the\n * providers persist it, so the same draft can reach GitHub, the local files, or\n * both. Capturing the result therefore has to be exact — the old approach of\n * fishing an issue URL out of free-form prose only ever worked for GitHub.\n *\n * The block mirrors the `<issue-body>` convention already used by the phase\n * templates, which keeps a multi-line markdown body readable and free of the\n * escaping a JSON payload would demand.\n */\n\n/** Wrapper the agent must emit around the draft. */\nexport const DRAFT_TAG = 'issue-draft';\n\n/** Failure to capture a draft from the agent output. */\nexport class IssueDraftParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'IssueDraftParseError';\n }\n}\n\n/**\n * Last occurrence of `<tag>...</tag>` in `source`, or `null`.\n *\n * The last one wins: an agent that shows the format before filling it in (or\n * restates the draft after a correction) would otherwise have its first,\n * throwaway attempt captured. The closing tag is searched from the end for the\n * same reason a body may legitimately quote one.\n */\nfunction extractTag(source: string, tag: string): string | null {\n const open = `<${tag}>`;\n const close = `</${tag}>`;\n\n const start = source.lastIndexOf(open);\n if (start === -1) return null;\n\n const end = source.lastIndexOf(close);\n if (end === -1 || end < start) return null;\n\n return source.slice(start + open.length, end);\n}\n\nfunction parseLabels(raw: string | null): string[] {\n if (raw === null) return [];\n return raw\n .split(',')\n .map((label) => label.trim())\n .filter((label) => label.length > 0 && label.toLowerCase() !== '(none)');\n}\n\n/**\n * Read the draft the agent produced.\n *\n * @throws IssueDraftParseError when the block is absent or has no usable\n * title/body, so a malformed answer fails loudly instead of creating an empty\n * Issue.\n */\nexport function parseIssueDraft(output: string): IssueDraft {\n const normalized = output.replace(/\\r\\n?/g, '\\n');\n const block = extractTag(normalized, DRAFT_TAG);\n\n if (block === null) {\n throw new IssueDraftParseError(\n `The agent did not emit an <${DRAFT_TAG}> block, so there is no Issue to create. ` +\n `Output was: ${normalized.trim().slice(0, 300) || '(empty)'}`,\n );\n }\n\n const title = (extractTag(block, 'title') ?? '').trim();\n const body = (extractTag(block, 'body') ?? '').trim();\n\n if (title.length === 0) {\n throw new IssueDraftParseError(`The <${DRAFT_TAG}> block has no <title>.`);\n }\n if (body.length === 0) {\n throw new IssueDraftParseError(`The <${DRAFT_TAG}> block has no <body>.`);\n }\n\n // Optional, and deliberately so: a repository with no Issue Types and no\n // templates emits neither, and the draft is exactly what it was before.\n const type = (extractTag(block, 'type') ?? '').trim();\n const template = (extractTag(block, 'template') ?? '').trim();\n\n return {\n title,\n body,\n labels: parseLabels(extractTag(block, 'labels')),\n ...(type === '' || type.toLowerCase() === '(none)' ? {} : { type }),\n ...(template === '' || template.toLowerCase() === '(none)' ? {} : { template }),\n };\n}\n","import type { LabelDefinition } from '../policy/types.js';\nimport { run } from '../utils/shell.js';\n\n/**\n * Reconciling the labels an agent suggested with the ones the repository\n * actually has.\n *\n * A workflow tool has no business changing a repository's taxonomy. Labels are\n * governance: a team that deleted `high`/`medium`/`low` in favour of a native\n * priority field, or `bug`/`enhancement` in favour of Issue Types, made a\n * decision — and a generator that silently recreates them undoes it, quietly and\n * repository-wide.\n *\n * So the default is to **validate, never create**. `policy.issues.allowLabelCreation`\n * restores the old behaviour for repositories that want it.\n */\n\nexport interface LabelReconciliation {\n /** Labels to apply, in the repository's own casing. */\n labels: string[];\n /** Suggested labels the repository does not have. */\n missing: string[];\n}\n\n/**\n * Intersect the suggested labels with the repository's real ones.\n *\n * Matching is case-insensitive and the result carries the **repository's**\n * casing: `gh issue create --label Bug` fails on a repository whose label is\n * `bug`, and an agent has no way to know which one it is.\n *\n * An empty `known` means the labels could not be read at all — no policy, no\n * `gh`, no network. That is not evidence the labels do not exist, so the\n * suggestions pass through untouched and the behaviour is the one that shipped\n * before this layer. Refusing to label an issue because discovery was offline\n * would be the wrong failure.\n */\nexport function reconcileLabels(\n suggested: string[],\n known: LabelDefinition[],\n): LabelReconciliation {\n if (known.length === 0) {\n return { labels: [...suggested], missing: [] };\n }\n\n const canonical = new Map(known.map((label) => [label.name.toLowerCase(), label.name]));\n\n const labels: string[] = [];\n const missing: string[] = [];\n for (const suggestion of suggested) {\n const match = canonical.get(suggestion.trim().toLowerCase());\n if (match === undefined) {\n if (!missing.includes(suggestion)) missing.push(suggestion);\n continue;\n }\n if (!labels.includes(match)) labels.push(match);\n }\n\n return { labels, missing };\n}\n\n/**\n * Create the labels the repository is missing, for\n * `policy.issues.allowLabelCreation: true`.\n *\n * Best-effort per label: one that cannot be created is reported and skipped, so\n * a single failure does not cost the Issue. Returns the labels that now exist.\n */\nexport async function createMissingLabels(\n names: string[],\n warn: (message: string) => void,\n): Promise<string[]> {\n const created: string[] = [];\n\n for (const name of names) {\n const result = await run('gh', ['label', 'create', name]);\n if (result.exitCode === 0) {\n created.push(name);\n continue;\n }\n // gh answers \"already exists\" when a label was created between the\n // discovery and now, which is a success for our purposes.\n const detail = (result.stderr || result.stdout).trim();\n if (/already exists/i.test(detail)) {\n created.push(name);\n continue;\n }\n warn(`Could not create label \"${name}\": ${detail || 'gh label create failed'}`);\n }\n\n return created;\n}\n","import { loadIssuesConfig, loadPolicyConfig } from '../config.js';\nimport { DEFAULT_HEADLESS_TIMEOUT_MS, runHeadless } from '../core/headless.js';\nimport { applyPlaceholders, loadPrompt } from '../core/prompt-resolver.js';\nimport { publishPhaseMetrics } from '../core/session-metrics.js';\nimport { isoNow } from '../core/state-manager.js';\nimport { getGlobalTimeout } from '../core/verbose.js';\nimport { ensureProvidersRegistered } from '../issues/bootstrap.js';\nimport { localIssueRef } from '../issues/context.js';\nimport { IssueDraftParseError, parseIssueDraft } from '../issues/draft.js';\nimport { createMissingLabels, reconcileLabels } from '../issues/label-policy.js';\nimport { getProvider } from '../issues/registry.js';\nimport type { Issue, IssueDraft, IssueGenerateTarget } from '../issues/types.js';\nimport { loadRepositoryPolicy } from '../policy/index.js';\nimport { resolvePolicyPlaceholders } from '../policy/placeholders.js';\nimport { resolveProjectPaths } from '../storage/resolve.js';\nimport { printError, printInfo, printSuccess, printWarning } from '../ui/logger.js';\n\n/** Human-readable pointer to a created Issue. */\nfunction issueLocation(issue: Issue): string {\n return issue.remoteRef ?? localIssueRef(issue.id);\n}\n\n/**\n * Ask the agent for the Issue content.\n *\n * The agent only drafts: creation belongs to the providers, so the same draft\n * can be persisted to GitHub, to the local files, or to both.\n */\nasync function draftIssue(promptText: string): Promise<IssueDraft> {\n // The duplicate check reads the local issues, which live in the global\n // storage: the path has to be handed over (and allowed) explicitly, since it\n // is outside the working directory the agent is started in.\n const { issuesDir } = await resolveProjectPaths();\n\n const template = await loadPrompt('generate');\n const prompt = applyPlaceholders(template, {\n // The repository's own conventions. Empty when it declares none, which is\n // what keeps the rendered prompt identical to the pre-policy one.\n ...(await resolvePolicyPlaceholders()),\n __USER_PROMPT__: promptText,\n __LOCAL_ISSUES_DIR__: issuesDir,\n });\n\n const startedAtMs = Date.now();\n const result = await runHeadless({\n prompt,\n maxTurns: 15,\n timeout: getGlobalTimeout() ?? DEFAULT_HEADLESS_TIMEOUT_MS,\n // json (not text) so the CLI reports usage: the envelope's `result` field\n // carries the same assistant text parseIssueDraft() already consumed.\n outputFormat: 'json',\n allowedTools: ['Bash', 'Read', 'Glob', 'Grep'],\n addDirs: [issuesDir],\n statusMessage: 'Drafting issue...',\n });\n // Before the success check: the tokens were spent either way.\n publishPhaseMetrics('generate', result.cost, startedAtMs);\n\n if (!result.success) {\n throw new Error(`Issue creation failed: ${result.error}`);\n }\n\n return parseIssueDraft(result.result);\n}\n\n/**\n * Create the GitHub Issue and mirror it locally.\n *\n * The remote comes first on purpose: it owns the identifier, and the mirror has\n * to reuse it so both copies describe one demand. A remote failure therefore\n * leaves nothing behind, and a mirror failure is reported with the remote\n * reference that already exists.\n */\nasync function createBoth(draft: IssueDraft): Promise<Issue[]> {\n const remote = await getProvider('github').create(draft);\n\n try {\n const mirror = await getProvider('local').create({\n ...draft,\n id: remote.id,\n ...(remote.remoteRef\n ? {\n remote: {\n provider: 'github' as const,\n ref: remote.remoteRef,\n syncedAt: isoNow(),\n syncedContentHash: remote.contentHash,\n },\n }\n : {}),\n });\n return [remote, mirror];\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(\n `GitHub issue created at ${issueLocation(remote)}, but the local mirror was not written: ` +\n `${message}. Nothing else was persisted; re-run with --local to create the mirror.`,\n );\n }\n}\n\nasync function createIssues(target: IssueGenerateTarget, draft: IssueDraft): Promise<Issue[]> {\n if (target === 'both') {\n return createBoth(draft);\n }\n return [await getProvider(target).create(draft)];\n}\n\n/**\n * Reconcile the draft's labels with the ones the repository really has.\n *\n * Two failures are being prevented here, and only one of them is cosmetic.\n * GitHub rejects an issue whose label does not exist, so an invented label costs\n * the whole Issue. And a tool that creates the label instead rewrites a taxonomy\n * the team may have curated deliberately — which is worse, because it succeeds.\n *\n * Never throws: a policy that could not be resolved leaves the draft untouched.\n */\nasync function applyLabelPolicy(draft: IssueDraft): Promise<IssueDraft> {\n let known: Awaited<ReturnType<typeof loadRepositoryPolicy>>['issues']['labels'];\n let allowCreation: boolean;\n try {\n const policy = await loadRepositoryPolicy();\n known = policy.issues.labels;\n const config = await loadPolicyConfig({ projectRoot: policy.root });\n allowCreation = config.issues.allowLabelCreation ?? false;\n } catch {\n return draft;\n }\n\n const { labels, missing } = reconcileLabels(draft.labels, known);\n if (missing.length === 0) {\n return { ...draft, labels };\n }\n\n if (!allowCreation) {\n printWarning(\n `Dropping ${missing.length} label(s) this repository does not have: ${missing.join(', ')}. ` +\n 'Issue Flow does not create labels; set policy.issues.allowLabelCreation to change that.',\n );\n return { ...draft, labels };\n }\n\n const created = await createMissingLabels(missing, printWarning);\n return { ...draft, labels: [...labels, ...created] };\n}\n\nexport async function runGenerate(\n promptText: string,\n target?: IssueGenerateTarget,\n): Promise<number> {\n const config = await loadIssuesConfig();\n const destination = target ?? config.defaultGenerateTarget;\n\n ensureProvidersRegistered();\n\n let draft: IssueDraft;\n try {\n draft = await draftIssue(promptText);\n } catch (err) {\n if (err instanceof IssueDraftParseError) {\n printError(`Could not read the generated Issue draft: ${err.message}`);\n } else {\n printError(err instanceof Error ? err.message : String(err));\n }\n return 1;\n }\n\n const finalDraft = await applyLabelPolicy(draft);\n if (finalDraft.template !== undefined) {\n printInfo(`Following the repository's Issue Template: ${finalDraft.template}`);\n }\n if (finalDraft.type !== undefined) {\n printInfo(`Issue Type: ${finalDraft.type}`);\n }\n\n let created: Issue[];\n try {\n created = await createIssues(destination, finalDraft);\n } catch (err) {\n printError(err instanceof Error ? err.message : String(err));\n return 1;\n }\n\n for (const issue of created) {\n printSuccess(`Issue created (${issue.source}): ${issueLocation(issue)}`);\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,IAAM,YAAY;AAGlB,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAUA,SAAS,WAAW,QAAgB,KAA4B;AAC9D,QAAM,OAAO,IAAI,GAAG;AACpB,QAAM,QAAQ,KAAK,GAAG;AAEtB,QAAM,QAAQ,OAAO,YAAY,IAAI;AACrC,MAAI,UAAU,GAAI,QAAO;AAEzB,QAAM,MAAM,OAAO,YAAY,KAAK;AACpC,MAAI,QAAQ,MAAM,MAAM,MAAO,QAAO;AAEtC,SAAO,OAAO,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9C;AAEA,SAAS,YAAY,KAA8B;AACjD,MAAI,QAAQ,KAAM,QAAO,CAAC;AAC1B,SAAO,IACJ,MAAM,GAAG,EACT,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAC3B,OAAO,CAAC,UAAU,MAAM,SAAS,KAAK,MAAM,YAAY,MAAM,QAAQ;AAC3E;AASO,SAAS,gBAAgB,QAA4B;AAC1D,QAAM,aAAa,OAAO,QAAQ,UAAU,IAAI;AAChD,QAAM,QAAQ,WAAW,YAAY,SAAS;AAE9C,MAAI,UAAU,MAAM;AAClB,UAAM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