From ca9d87e13f1584d685ca3af5e27408746b1d6b3c Mon Sep 17 00:00:00 2001 From: yunyingk Date: Thu, 19 Nov 2026 16:38:14 +0800 Subject: [PATCH] Group CLI modules into parse, run, output, and help Move parser, tokenize, and area-aliases under cli/parse; runner and read-only under cli/run; printer under cli/output; help plus the docs/naming contract tests under cli/help. types.ts and helpers.ts stay at the cli root. Update imports, the app-root depth calculation, test fixtures, and the CLI doc generator path. No behavior change. --- .agents/rules/cli-protocol.md | 8 +- AGENTS.md | 4 +- scripts/generate-cli-md.mjs | 2 +- scripts/generators.test.ts | 5 +- src/cli.ts | 2 +- src/cli/commands/analytics.ts | 4 +- src/cli/commands/approval-runs-export.test.ts | 6 +- src/cli/commands/approval-runs-export.ts | 4 +- src/cli/commands/approval-runs.test.ts | 2 +- src/cli/commands/approval-runs.ts | 4 +- src/cli/commands/auth.test.ts | 2 +- src/cli/commands/auth.ts | 4 +- src/cli/commands/billing.ts | 2 +- src/cli/commands/config.ts | 4 +- src/cli/commands/contacts.ts | 2 +- src/cli/commands/context.ts | 4 +- src/cli/commands/corps-bind.test.ts | 2 +- src/cli/commands/corps.test.ts | 4 +- src/cli/commands/corps/active.ts | 4 +- src/cli/commands/corps/bindings.ts | 4 +- src/cli/commands/corps/onboarding.ts | 4 +- src/cli/commands/corps/overview.ts | 4 +- src/cli/commands/corps/sync.ts | 4 +- src/cli/commands/corps/tenant-active.test.ts | 2 +- src/cli/commands/deploy.test.ts | 2 +- src/cli/commands/deploy.ts | 4 +- src/cli/commands/doctor.test.ts | 2 +- src/cli/commands/doctor.ts | 8 +- src/cli/commands/documents.test.ts | 2 +- src/cli/commands/documents.ts | 4 +- src/cli/commands/dry-run-gates.test.ts | 2 +- src/cli/commands/expenses.test.ts | 2 +- src/cli/commands/expenses.ts | 4 +- src/cli/commands/hose-ebot.test.ts | 2 +- src/cli/commands/hose-ebot.ts | 4 +- src/cli/commands/invoices.ts | 4 +- src/cli/commands/langfuse.ts | 4 +- src/cli/commands/llm.ts | 2 +- src/cli/commands/mcp.ts | 2 +- src/cli/commands/permissions.ts | 2 +- src/cli/commands/preference.ts | 4 +- src/cli/commands/probe.ts | 4 +- src/cli/commands/report-review-cli.test.ts | 2 +- src/cli/commands/report.ts | 4 +- src/cli/commands/rules.ts | 4 +- src/cli/commands/simulation.test.ts | 2 +- src/cli/commands/simulation.ts | 4 +- src/cli/commands/skill.ts | 4 +- src/cli/commands/source.ts | 2 +- src/cli/commands/test.test.ts | 2 +- src/cli/commands/test.ts | 4 +- src/cli/commands/update.ts | 2 +- src/cli/commands/users.test.ts | 2 +- src/cli/commands/users.ts | 4 +- src/cli/commands/webhook-replay.test.ts | 2 +- .../commands/webhook-resource-pack.test.ts | 2 +- src/cli/commands/webhook.ts | 4 +- src/cli/{ => help}/docs-commands.test.ts | 6 +- src/cli/{ => help}/help.test.ts | 2 +- src/cli/{ => help}/help.ts | 6 +- src/cli/{ => help}/naming-charter.test.ts | 8 +- src/cli/helpers.ts | 2 +- src/cli/{ => output}/printer.ts | 10 +- src/cli/{ => parse}/area-aliases.test.ts | 2 +- src/cli/{ => parse}/area-aliases.ts | 0 src/cli/{ => parse}/parser.test.ts | 2 +- src/cli/{ => parse}/parser.ts | 10 +- src/cli/{ => parse}/tokenize.ts | 2 +- src/cli/{ => run}/read-only.test.ts | 8 +- src/cli/{ => run}/read-only.ts | 4 +- src/cli/{ => run}/runner.test.ts | 4 +- src/cli/{ => run}/runner.ts | 116 +++++++++--------- src/core/util/redact.ts | 2 +- src/domains/seal/reports/export/files.test.ts | 2 +- src/domains/seal/rules/push.test.ts | 2 +- src/domains/seal/rules/recode.test.ts | 2 +- src/probe.test.ts | 2 +- src/probe.ts | 2 +- src/server.ts | 6 +- src/streams.test.ts | 2 +- 80 files changed, 196 insertions(+), 195 deletions(-) rename src/cli/{ => help}/docs-commands.test.ts (96%) rename src/cli/{ => help}/help.test.ts (99%) rename src/cli/{ => help}/help.ts (99%) rename src/cli/{ => help}/naming-charter.test.ts (96%) rename src/cli/{ => output}/printer.ts (90%) rename src/cli/{ => parse}/area-aliases.test.ts (98%) rename src/cli/{ => parse}/area-aliases.ts (100%) rename src/cli/{ => parse}/parser.test.ts (99%) rename src/cli/{ => parse}/parser.ts (98%) rename src/cli/{ => parse}/tokenize.ts (97%) rename src/cli/{ => run}/read-only.test.ts (97%) rename src/cli/{ => run}/read-only.ts (98%) rename src/cli/{ => run}/runner.test.ts (97%) rename src/cli/{ => run}/runner.ts (64%) diff --git a/.agents/rules/cli-protocol.md b/.agents/rules/cli-protocol.md index a5fb1b6..15bf60d 100644 --- a/.agents/rules/cli-protocol.md +++ b/.agents/rules/cli-protocol.md @@ -13,7 +13,7 @@ When developing or refactoring CLI commands under `src/cli/`: - **Machine Channel (`stdout`)**: - Data commands **MUST** output pure, parseable JSON on `stdout`. - **NEVER** output human text, logs, spinners, progress banners, or update notices to `stdout`. The Agent Harness parses `stdout` directly into typed payloads. - - **Documented exceptions**: `seal-use --help` / `seal-use help ` (`src/cli/printer.ts`), `seal-use doctor guide` (`src/cli/commands/doctor.ts`), and `seal-use skill dump` (`src/cli/commands/skill.ts`) intentionally output Markdown documents on `stdout` because their output *is* the requested document payload (e.g. `seal-use skill dump > SKILL.md`). Never add new stdout-prose commands outside this list. + - **Documented exceptions**: `seal-use --help` / `seal-use help ` (`src/cli/output/printer.ts`), `seal-use doctor guide` (`src/cli/commands/doctor.ts`), and `seal-use skill dump` (`src/cli/commands/skill.ts`) intentionally output Markdown documents on `stdout` because their output *is* the requested document payload (e.g. `seal-use skill dump > SKILL.md`). Never add new stdout-prose commands outside this list. - **Diagnostics & Guidance Channel (`stderr`)**: - Use `stderr` for runtime logs, network probing status, self-healing notifications, and human tips. - Explicit **Next-Step Command Suggestions** MUST follow the format: @@ -27,7 +27,7 @@ When developing or refactoring CLI commands under `src/cli/`: - **Sub-70ms Local Execution**: - Read-only discovery commands (e.g. `seal-use version`, `seal-use doctor paths`, `seal-use corps list`) MUST return in under 70ms wall clock (Bun interpreter startup is ~7ms on its own, so this leaves ~60ms for the module graph). - - Achieved by keeping `src/cli/runner.ts` free of static command-module imports: dispatch branches load their handler with `await import("./commands/.js")` on demand, so `seal-use version` never loads the Excel/zip tool chain. + - Achieved by keeping `src/cli/run/runner.ts` free of static command-module imports: dispatch branches load their handler with `await import("./commands/.js")` on demand, so `seal-use version` never loads the Excel/zip tool chain. - Never trigger synchronous external HTTP requests during routine discovery or inspection invocations. Measured on the maintainer's machine (2026-09): version 45ms, help 41ms, corps list 41ms, bare `bun -e` 7ms. - **Stale-While-Revalidate (SWR) Pattern**: 1. Synchronously read local cache from `~/.config/seal-use/*.json` (<0.2ms). @@ -74,13 +74,13 @@ When developing or refactoring CLI commands under `src/cli/`: | `13` | **Config / Input Validation** | Well-formed command with an unusable value: missing `--corp` in stateless mode, unparseable enterprise JSON, missing required parameter (Chinese-language usage wording), Zod/schema validation failure | | `14` | **Safety Guard Block** | Target environment forbids the action: replay into a production tenant, regression matrix outside a test tenant. Requires a different target or an explicit override flag | -**Rule**: Never call `process.exit()` deep in domain functions. Throw structured errors (`usageError` → 2, `validationError` → 13, `safetyBlocked` → 14, `confirmationRequired` → 10) and let `src/cli/runner.ts` handle error classification, stream routing, and exit code assignment. Domain failures and quality gates stay at `1`. +**Rule**: Never call `process.exit()` deep in domain functions. Throw structured errors (`usageError` → 2, `validationError` → 13, `safetyBlocked` → 14, `confirmationRequired` → 10) and let `src/cli/run/runner.ts` handle error classification, stream routing, and exit code assignment. Domain failures and quality gates stay at `1`. --- ## 5. Argument Parsing Conventions -- Use helpers from `src/cli/parser.ts`: +- Use helpers from `src/cli/parse/parser.ts`: - `booleanOption(args.options.flag)` - `stringOption(args.options.param)` - `numberOption(args.options.limit)` diff --git a/AGENTS.md b/AGENTS.md index fe5abe8..1d5d02a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,7 +38,7 @@ Prefer small domain functions over broad utility modules. ## CLI & Agent Harness Protocol Guidelines - **Machine Channel (`stdout`)**: Data commands MUST output clean, parseable JSON on `stdout`. Never dump human prose, raw logs, or progress banners into `stdout`. The Agent Harness parses `stdout` directly into typed payloads. - - **Documented exception — document-output commands**: `seal-use --help` / `seal-use help ` (`src/cli/printer.ts`), `seal-use doctor guide` (`src/cli/commands/doctor.ts`), and `seal-use skill dump` (`src/cli/commands/skill.ts`) intentionally write Markdown to `stdout`, because their output *is* the payload the caller redirects or reads (e.g. `seal-use doctor guide > guide.md`, `seal-use skill dump > SKILL.md`). Never add a new prose-on-stdout command outside this list: return structured JSON and put the readable rendering on `stderr` instead. `src/probe.ts` is a local developer probe script rather than a `bin` entry point, so its `[probe] …` lines are outside this contract. + - **Documented exception — document-output commands**: `seal-use --help` / `seal-use help ` (`src/cli/output/printer.ts`), `seal-use doctor guide` (`src/cli/commands/doctor.ts`), and `seal-use skill dump` (`src/cli/commands/skill.ts`) intentionally write Markdown to `stdout`, because their output *is* the payload the caller redirects or reads (e.g. `seal-use doctor guide > guide.md`, `seal-use skill dump > SKILL.md`). Never add a new prose-on-stdout command outside this list: return structured JSON and put the readable rendering on `stderr` instead. `src/probe.ts` is a local developer probe script rather than a `bin` entry point, so its `[probe] …` lines are outside this contract. - **Guidance & Diagnostic Channel (`stderr`)**: Use `stderr` for runtime logs, network probing status, self-healing notifications, and explicit **Next-Step Command Suggestions** (e.g. `👉 Next action: seal-use deploy hosecloud sync `). - **Performance Contract & SWR Architecture**: Read-only discovery and version commands (`seal-use version`, `seal-use doctor`, `seal-use corps list`) MUST execute in under 70ms wall clock (Bun startup alone is ~7ms; runner dispatch uses lazy `await import()` per command area, so the version path never loads the Excel/zip tool chain). Never block on external network I/O during routine invocations. Use the Stale-While-Revalidate (SWR) pattern: read local cache from `~/.config/seal-use/*.json` synchronously (<0.2ms), and refresh stale/missing data via detached, unref'd child processes (`triggerBackgroundUpdateCheck`, `unref()`). - **Safety Guardrail & Mutation Preview (`--dry-run`)**: All potentially destructive or state-mutating commands (e.g. `rules push/clear`, `corps sync-test`, `preference update`, `webhook create/update`) MUST support `--dry-run` returning structured JSON previews with `preview: true` and a clean diff, without executing mutations. Live execution requires explicit `--yes` or `--confirm`. @@ -51,7 +51,7 @@ Prefer small domain functions over broad utility modules. - `12`: Output protection — response exceeds the size limit; use `--summary`/`--fields`/`--count`/`--output-file` (or `--full` when the full payload is genuinely required). - `13`: Local configuration or input-data validation failure — well-formed command, but the value or config file is unusable (missing `--corp`, unparseable enterprise JSON, missing required parameter named in a Chinese-language error). - `14`: Safety guard block — the target environment forbids the action (replay into production, regression outside a test tenant); requires a different target or an explicit override. - - Never call `process.exit()` deep in domain functions; throw structured errors and let `src/cli/runner.ts` handle stream routing and exit code assignment. + - Never call `process.exit()` deep in domain functions; throw structured errors and let `src/cli/run/runner.ts` handle stream routing and exit code assignment. ## Testing Guidelines diff --git a/scripts/generate-cli-md.mjs b/scripts/generate-cli-md.mjs index 5488496..636f27f 100644 --- a/scripts/generate-cli-md.mjs +++ b/scripts/generate-cli-md.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env bun import { readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; -import { HELP_REGISTRY } from "../src/cli/help.ts"; +import { HELP_REGISTRY } from "../src/cli/help/help.ts"; export const cliDocPath = resolve(import.meta.dirname, "../skills/seal-use/references/cli.md"); const begin = ""; diff --git a/scripts/generators.test.ts b/scripts/generators.test.ts index a757cf9..4c30fd0 100644 --- a/scripts/generators.test.ts +++ b/scripts/generators.test.ts @@ -52,12 +52,13 @@ describe("generated documentation contracts", () => { const core = join(dir, "src/core") const coreSkill = join(core, "skill") const cli = join(dir, "src/cli") + const cliHelp = join(cli, "help") const skill = join(dir, "skills/seal-use") - for (const path of [scripts, core, coreSkill, cli, join(skill, "references")]) mkdirSync(path, { recursive: true }) + for (const path of [scripts, core, coreSkill, cli, cliHelp, join(skill, "references")]) mkdirSync(path, { recursive: true }) for (const name of ["generate-embedded-skill.mjs", "check-embedded-skill.mjs", "generate-cli-md.mjs", "check-cli-md.mjs"]) { copyFileSync(join(import.meta.dir, name), join(scripts, name)) } - writeFileSync(join(cli, "help.ts"), 'export const HELP_REGISTRY = [{ commands: [{ usage: ["seal-use fixture list"] }] }];') + writeFileSync(join(cliHelp, "help.ts"), 'export const HELP_REGISTRY = [{ commands: [{ usage: ["seal-use fixture list"] }] }];') writeFileSync(join(skill, "SKILL.md"), "fixture skill") const embeddedPath = join(coreSkill, "embedded-skill.generated.ts") const markdownPath = join(skill, "references/cli.md") diff --git a/src/cli.ts b/src/cli.ts index 880fd91..1c0cd7f 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,7 +1,7 @@ #!/usr/bin/env bun import { fileURLToPath } from "node:url"; -import { runCli } from "./cli/runner.js"; +import { runCli } from "./cli/run/runner.js"; import { isCompiledBinary, performRuntimeSelfHealing, resolveAppRoot, resolveDefaultLauncher } from "./core/util/runtime.js"; process.stdout.on("error", (err: any) => { diff --git a/src/cli/commands/analytics.ts b/src/cli/commands/analytics.ts index 6aed4c0..796708b 100644 --- a/src/cli/commands/analytics.ts +++ b/src/cli/commands/analytics.ts @@ -3,8 +3,8 @@ import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { exportInsightReportToExcel } from "../../domains/seal/insight/export.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, dryRunOption, numberOption, stringOption } from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +import { booleanOption, dryRunOption, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleAnalyticsCommand( diff --git a/src/cli/commands/approval-runs-export.test.ts b/src/cli/commands/approval-runs-export.test.ts index 6d82a95..d654fa2 100644 --- a/src/cli/commands/approval-runs-export.test.ts +++ b/src/cli/commands/approval-runs-export.test.ts @@ -4,9 +4,9 @@ import { tmpdir } from "node:os" import { fileURLToPath } from "node:url" import { join } from "node:path" import ExcelJS from "exceljs" -import { parseArgs } from "../parser.js" -import { runCli } from "../runner.js" -import { isReadOnlyCliCommand } from "../read-only.js" +import { parseArgs } from "../parse/parser.js" +import { runCli } from "../run/runner.js" +import { isReadOnlyCliCommand } from "../run/read-only.js" import { getExportTask, startExportTask, waitForExportTask, writeExportTask } from "../../domains/seal/approval-runs/export-task.js" import { resolveExportOptions } from "./approval-runs-export.js" import type { CorpConfig } from "../../core/config/types.js" diff --git a/src/cli/commands/approval-runs-export.ts b/src/cli/commands/approval-runs-export.ts index 840a61c..100e09d 100644 --- a/src/cli/commands/approval-runs-export.ts +++ b/src/cli/commands/approval-runs-export.ts @@ -12,8 +12,8 @@ import { type ExportTaskOptions } from "../../domains/seal/approval-runs/export-task.js" import { selectCorp } from "../helpers.js" -import { booleanOption, dryRunOption, numberOption, stringOption } from "../parser.js" -import { formatConsoleOutput, printJson, redactSensitiveText } from "../printer.js" +import { booleanOption, dryRunOption, numberOption, stringOption } from "../parse/parser.js" +import { formatConsoleOutput, printJson, redactSensitiveText } from "../output/printer.js" import type { CliRuntime, ParsedArgs } from "../types.js" import { approvalRunsExportOptions } from "./approval-runs.js" import type { CorpConfig } from "../../core/config/types.js" diff --git a/src/cli/commands/approval-runs.test.ts b/src/cli/commands/approval-runs.test.ts index 6fdb8d8..8584f0d 100644 --- a/src/cli/commands/approval-runs.test.ts +++ b/src/cli/commands/approval-runs.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test" import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { runCli } from "../runner.js" +import { runCli } from "../run/runner.js" const envKeys = ["SEAL_USE_ENTERPRISES_DIR", "SEAL_USE_CONFIG_FILE", "SEAL_USE_TOKEN_STORE", "SEAL_USE_USAGE_FILE", "SEAL_DISABLE_BG_UPDATE"] as const const oldEnv = Object.fromEntries(envKeys.map(key => [key, process.env[key]])) diff --git a/src/cli/commands/approval-runs.ts b/src/cli/commands/approval-runs.ts index 952e1ce..da75494 100644 --- a/src/cli/commands/approval-runs.ts +++ b/src/cli/commands/approval-runs.ts @@ -8,8 +8,8 @@ import { extractApprovalRunAttachments } from "../../domains/seal/approval-runs/attachments.js"; import { runCapability, runCapabilityResult } from "../helpers.js"; -import { booleanOption, numberOption, stringOption } from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +import { booleanOption, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import { handleWebhookCommand } from "./webhook.js"; diff --git a/src/cli/commands/auth.test.ts b/src/cli/commands/auth.test.ts index ef4e0d3..8f88e98 100644 --- a/src/cli/commands/auth.test.ts +++ b/src/cli/commands/auth.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/auth.ts b/src/cli/commands/auth.ts index 23c35db..e832cc9 100644 --- a/src/cli/commands/auth.ts +++ b/src/cli/commands/auth.ts @@ -19,8 +19,8 @@ import { parseDelegationExpireHours, parseHoseExpireSeconds, stringOption -} from "../parser.js"; -import { outputOptions, printJson, redactSensitiveText } from "../printer.js"; +} from "../parse/parser.js"; +import { outputOptions, printJson, redactSensitiveText } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import { runCapability, runCapabilityResult } from "../helpers.js"; import { extractKeysFromLinkAction, showCorpKeysAction } from "./corps.js"; diff --git a/src/cli/commands/billing.ts b/src/cli/commands/billing.ts index 312da16..1f63931 100644 --- a/src/cli/commands/billing.ts +++ b/src/cli/commands/billing.ts @@ -2,7 +2,7 @@ import { usageError } from "../../core/errors.js"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { outputOptions } from "../printer.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleBillingCommand( diff --git a/src/cli/commands/config.ts b/src/cli/commands/config.ts index e2a1bd4..0e429c1 100644 --- a/src/cli/commands/config.ts +++ b/src/cli/commands/config.ts @@ -8,8 +8,8 @@ import { } from "../../core/config/loader.js"; import { resolveCorpConfig } from "../../core/config/manager.js"; import { globalConfigSummary } from "../helpers.js"; -import { parseStateMode, stringOption } from "../parser.js"; -import { printJson } from "../printer.js"; +import { parseStateMode, stringOption } from "../parse/parser.js"; +import { printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export function handleConfigCommand(action: string | undefined, maybeName: string | undefined, args: ParsedArgs) { diff --git a/src/cli/commands/contacts.ts b/src/cli/commands/contacts.ts index 836cf86..4814c90 100644 --- a/src/cli/commands/contacts.ts +++ b/src/cli/commands/contacts.ts @@ -2,7 +2,7 @@ import { usageError } from "../../core/errors.js"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { outputOptions } from "../printer.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleContactsCommand( diff --git a/src/cli/commands/context.ts b/src/cli/commands/context.ts index 6785e12..c65058e 100644 --- a/src/cli/commands/context.ts +++ b/src/cli/commands/context.ts @@ -1,8 +1,8 @@ import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { numberOption, ruleVersionContextOptions, stringOption } from "../parser.js"; -import { outputOptions } from "../printer.js"; +import { numberOption, ruleVersionContextOptions, stringOption } from "../parse/parser.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleContextCommand( diff --git a/src/cli/commands/corps-bind.test.ts b/src/cli/commands/corps-bind.test.ts index b3b35c5..a024325 100644 --- a/src/cli/commands/corps-bind.test.ts +++ b/src/cli/commands/corps-bind.test.ts @@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "nod import { tmpdir } from "node:os"; import { join } from "node:path"; import type { CorpConfig } from "../../core/config/types.js"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/corps.test.ts b/src/cli/commands/corps.test.ts index a89cf65..b7bb498 100644 --- a/src/cli/commands/corps.test.ts +++ b/src/cli/commands/corps.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, @@ -1140,7 +1140,7 @@ describe("Hose OpenAPI key extraction from assistance link", () => { }); test("RULE_SUMMARY_FIELDS excludes raw internal UUID and prioritizes business fields", async () => { - const { RULE_SUMMARY_FIELDS } = await import("../printer.js"); + const { RULE_SUMMARY_FIELDS } = await import("../output/printer.js"); expect(RULE_SUMMARY_FIELDS).not.toContain("id"); expect(RULE_SUMMARY_FIELDS).toContain("code"); expect(RULE_SUMMARY_FIELDS).toContain("status"); diff --git a/src/cli/commands/corps/active.ts b/src/cli/commands/corps/active.ts index 998c3c1..1627164 100644 --- a/src/cli/commands/corps/active.ts +++ b/src/cli/commands/corps/active.ts @@ -1,7 +1,7 @@ import { updateCorpConfig } from "../../../core/config/loader.js"; import { confirmationRequired, usageError } from "../../../core/errors.js"; -import { booleanOption, dryRunOption, stringOption } from "../../parser.js"; -import { printJson } from "../../printer.js"; +import { booleanOption, dryRunOption, stringOption } from "../../parse/parser.js"; +import { printJson } from "../../output/printer.js"; import type { ParsedArgs } from "../../types.js"; /** diff --git a/src/cli/commands/corps/bindings.ts b/src/cli/commands/corps/bindings.ts index d9d31d5..6c464ad 100644 --- a/src/cli/commands/corps/bindings.ts +++ b/src/cli/commands/corps/bindings.ts @@ -1,8 +1,8 @@ import { updateCorpConfig } from "../../../core/config/loader.js"; import { selectCorp } from "../../helpers.js"; import { confirmationRequired, usageError } from "../../../core/errors.js"; -import { booleanOption, stringOption } from "../../parser.js"; -import { printJson } from "../../printer.js"; +import { booleanOption, stringOption } from "../../parse/parser.js"; +import { printJson } from "../../output/printer.js"; import type { ParsedArgs } from "../../types.js"; export async function handleCorpBindings( diff --git a/src/cli/commands/corps/onboarding.ts b/src/cli/commands/corps/onboarding.ts index cf033bb..11e0efd 100644 --- a/src/cli/commands/corps/onboarding.ts +++ b/src/cli/commands/corps/onboarding.ts @@ -23,8 +23,8 @@ import { optionalString, requiredString, stringOption -} from "../../parser.js"; -import { printJson } from "../../printer.js"; +} from "../../parse/parser.js"; +import { printJson } from "../../output/printer.js"; import type { ParsedArgs } from "../../types.js"; import { maskCellphone } from "./shared.js"; diff --git a/src/cli/commands/corps/overview.ts b/src/cli/commands/corps/overview.ts index 92b2562..5c93efb 100644 --- a/src/cli/commands/corps/overview.ts +++ b/src/cli/commands/corps/overview.ts @@ -11,8 +11,8 @@ import { } from "../../../core/stats/usage-tracker.js"; import type { CorpEnvironment } from "../../../core/config/types.js"; import { confirmationRequired, usageError } from "../../../core/errors.js"; -import { booleanOption, dryRunOption, numberOption, stringOption } from "../../parser.js"; -import { printJson } from "../../printer.js"; +import { booleanOption, dryRunOption, numberOption, stringOption } from "../../parse/parser.js"; +import { printJson } from "../../output/printer.js"; import type { ParsedArgs } from "../../types.js"; export async function handleCorpOverview( diff --git a/src/cli/commands/corps/sync.ts b/src/cli/commands/corps/sync.ts index 80c44de..22f7388 100644 --- a/src/cli/commands/corps/sync.ts +++ b/src/cli/commands/corps/sync.ts @@ -4,8 +4,8 @@ import { syncTestEnterprise } from "../../../domains/seal/testing/sync.js"; import { executeApprovalRunsReplay, type ReplayRecordsQuery } from "../../../domains/seal/replay/webhook.js"; import { selectCorp } from "../../helpers.js"; import { CliError, confirmationRequired, usageError } from "../../../core/errors.js"; -import { booleanOption, numberOption, stringOption } from "../../parser.js"; -import { outputOptions, printJson } from "../../printer.js"; +import { booleanOption, numberOption, stringOption } from "../../parse/parser.js"; +import { outputOptions, printJson } from "../../output/printer.js"; import type { ParsedArgs } from "../../types.js"; export { buildTestHosecloudOutboundName } from "../../../domains/seal/testing/sync.js"; diff --git a/src/cli/commands/corps/tenant-active.test.ts b/src/cli/commands/corps/tenant-active.test.ts index 353ea92..02ebbdf 100644 --- a/src/cli/commands/corps/tenant-active.test.ts +++ b/src/cli/commands/corps/tenant-active.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../../runner.js"; +import { runCli } from "../../run/runner.js"; import { selectCorp } from "../../helpers.js"; import { getEnterprisesDirCandidates, loadCorpConfigs, loadGlobalConfig } from "../../../core/config/loader.js"; import { resolveCorpConfig } from "../../../core/config/manager.js"; diff --git a/src/cli/commands/deploy.test.ts b/src/cli/commands/deploy.test.ts index 43cd6ea..c595169 100644 --- a/src/cli/commands/deploy.test.ts +++ b/src/cli/commands/deploy.test.ts @@ -1,7 +1,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import type { KyInstance } from "ky"; import { CorpConfigSchema } from "../../core/config/types.js"; -import { parseArgs } from "../parser.js"; +import { parseArgs } from "../parse/parser.js"; import { runCapabilityResult } from "../helpers.js"; import { handleDeployCommand } from "./deploy.js"; diff --git a/src/cli/commands/deploy.ts b/src/cli/commands/deploy.ts index f69b140..3ffe4f2 100644 --- a/src/cli/commands/deploy.ts +++ b/src/cli/commands/deploy.ts @@ -2,8 +2,8 @@ import { readFileSync } from "node:fs"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, jsonObject, numberOption, stringOption } from "../parser.js"; -import { outputOptions } from "../printer.js"; +import { booleanOption, jsonObject, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import * as api from "../../domains/seal/api.js"; import { listHoseIntegrations } from "../../domains/seal/outbound/push.js"; diff --git a/src/cli/commands/doctor.test.ts b/src/cli/commands/doctor.test.ts index 97ec26d..6cb4cdb 100644 --- a/src/cli/commands/doctor.test.ts +++ b/src/cli/commands/doctor.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; describe("seal-use doctor CLI", () => { test("runs full system diagnosis and outputs JSON to stdout and dashboard to stderr", async () => { diff --git a/src/cli/commands/doctor.ts b/src/cli/commands/doctor.ts index e5114be..787f14b 100644 --- a/src/cli/commands/doctor.ts +++ b/src/cli/commands/doctor.ts @@ -1,7 +1,7 @@ import { diagnoseSystem, formatDoctorDashboard } from "../../core/doctor/diagnose.js"; import { getEmbeddedGuideMarkdown } from "../../core/doctor/knowledge.js"; -import { booleanOption } from "../parser.js"; -import { printJson } from "../printer.js"; +import { booleanOption } from "../parse/parser.js"; +import { printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleDoctorCommand( @@ -28,7 +28,7 @@ export async function handleDoctorCommand( // 2.5. Output auth session diagnostics (seal-use doctor auth) if (subAction === "auth") { const { selectCorp } = await import("../helpers.js"); - const { stringOption } = await import("../parser.js"); + const { stringOption } = await import("../parse/parser.js"); const { handleAuthCommand } = await import("./auth.js"); const corpSelector = stringOption(args.options.corp) ?? @@ -43,7 +43,7 @@ export async function handleDoctorCommand( if (subAction === "tenant" || subAction === "corp" || subAction === "enterprise") { const { selectCorp } = await import("../helpers.js"); const { createSealClient } = await import("../../core/http/factory.js"); - const { stringOption } = await import("../parser.js"); + const { stringOption } = await import("../parse/parser.js"); const { diagnoseTenantContract, formatTenantDoctorDashboard } = await import("../../domains/seal/doctor/tenant-diagnose.js"); const corpSelector = diff --git a/src/cli/commands/documents.test.ts b/src/cli/commands/documents.test.ts index f9f436b..0ba430f 100644 --- a/src/cli/commands/documents.test.ts +++ b/src/cli/commands/documents.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test" import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { runCli } from "../runner.js" +import { runCli } from "../run/runner.js" const envKeys = ["SEAL_USE_ENTERPRISES_DIR", "SEAL_USE_CONFIG_FILE", "SEAL_USE_TOKEN_STORE", "SEAL_USE_USAGE_FILE"] as const const oldEnv = Object.fromEntries(envKeys.map(key => [key, process.env[key]])) diff --git a/src/cli/commands/documents.ts b/src/cli/commands/documents.ts index d5d2174..8065b46 100644 --- a/src/cli/commands/documents.ts +++ b/src/cli/commands/documents.ts @@ -12,8 +12,8 @@ import { numberOption, splitOption, stringOption -} from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +} from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; function contentFilePath(args: ParsedArgs): string | undefined { diff --git a/src/cli/commands/dry-run-gates.test.ts b/src/cli/commands/dry-run-gates.test.ts index 4e0857a..62ca209 100644 --- a/src/cli/commands/dry-run-gates.test.ts +++ b/src/cli/commands/dry-run-gates.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; /** * Mutation-preview (`--dry-run`) gates for commands that previously mutated diff --git a/src/cli/commands/expenses.test.ts b/src/cli/commands/expenses.test.ts index 4ef964b..8aa27cf 100644 --- a/src/cli/commands/expenses.test.ts +++ b/src/cli/commands/expenses.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test" import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { runCli } from "../runner.js" +import { runCli } from "../run/runner.js" const envKeys = ["SEAL_USE_CONFIG_FILE", "SEAL_USE_ENTERPRISES_DIR", "SEAL_USE_TOKEN_STORE", "SEAL_USE_USAGE_FILE"] as const const oldEnv = Object.fromEntries(envKeys.map(key => [key, process.env[key]])) diff --git a/src/cli/commands/expenses.ts b/src/cli/commands/expenses.ts index 25cdccd..ca57230 100644 --- a/src/cli/commands/expenses.ts +++ b/src/cli/commands/expenses.ts @@ -3,8 +3,8 @@ import type { createSealClient } from "../../core/http/factory.js" import { usageError } from "../../core/errors.js" import { ExpenseLookupError } from "../../domains/seal/expenses/lookup.js" import { runCapabilityResult } from "../helpers.js" -import { numberOption, stringOption } from "../parser.js" -import { outputOptions, printJson } from "../printer.js" +import { numberOption, stringOption } from "../parse/parser.js" +import { outputOptions, printJson } from "../output/printer.js" import type { ParsedArgs } from "../types.js" export async function handleExpensesCommand(action: string | undefined, client: Awaited>, corp: CorpConfig, args: ParsedArgs) { diff --git a/src/cli/commands/hose-ebot.test.ts b/src/cli/commands/hose-ebot.test.ts index 86e4733..0bbe8fe 100644 --- a/src/cli/commands/hose-ebot.test.ts +++ b/src/cli/commands/hose-ebot.test.ts @@ -5,7 +5,7 @@ import { join } from "node:path"; import type { KyInstance } from "ky"; import { CorpConfigSchema } from "../../core/config/types.js"; import { classifyCliError } from "../../core/errors.js"; -import { parseArgs } from "../parser.js"; +import { parseArgs } from "../parse/parser.js"; import { handleHoseEbotCommand } from "./hose-ebot.js"; const ORIGINAL_ENV = { diff --git a/src/cli/commands/hose-ebot.ts b/src/cli/commands/hose-ebot.ts index c76c9d5..98e8733 100644 --- a/src/cli/commands/hose-ebot.ts +++ b/src/cli/commands/hose-ebot.ts @@ -2,8 +2,8 @@ import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { CliError } from "../../core/errors.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, numberOption, stringOption } from "../parser.js"; -import { outputOptions } from "../printer.js"; +import { booleanOption, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; const USAGE = diff --git a/src/cli/commands/invoices.ts b/src/cli/commands/invoices.ts index f8e280b..2f48cac 100644 --- a/src/cli/commands/invoices.ts +++ b/src/cli/commands/invoices.ts @@ -2,8 +2,8 @@ import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { traceInvoice } from "../../domains/seal/approval-runs/invoices.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, numberOption, stringOption } from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +import { booleanOption, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleInvoicesCommand( diff --git a/src/cli/commands/langfuse.ts b/src/cli/commands/langfuse.ts index 77e184e..d7f7491 100644 --- a/src/cli/commands/langfuse.ts +++ b/src/cli/commands/langfuse.ts @@ -1,7 +1,7 @@ import { validationError, usageError } from "../../core/errors.js"; -import { booleanOption, numberOption, splitOption, stringOption } from "../parser.js"; +import { booleanOption, numberOption, splitOption, stringOption } from "../parse/parser.js"; import { runLangfuseCapability } from "../helpers.js"; -import { outputOptions } from "../printer.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; /** diff --git a/src/cli/commands/llm.ts b/src/cli/commands/llm.ts index 96eddc3..b8265b4 100644 --- a/src/cli/commands/llm.ts +++ b/src/cli/commands/llm.ts @@ -2,7 +2,7 @@ import { usageError } from "../../core/errors.js"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { outputOptions } from "../printer.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleLlmCommand( diff --git a/src/cli/commands/mcp.ts b/src/cli/commands/mcp.ts index 789ec86..11b6979 100644 --- a/src/cli/commands/mcp.ts +++ b/src/cli/commands/mcp.ts @@ -1,4 +1,4 @@ -import { printJson } from "../printer.js"; +import { printJson } from "../output/printer.js"; export async function handleMcpCommand(action: string | undefined) { if (action === "config" || action === "json") { diff --git a/src/cli/commands/permissions.ts b/src/cli/commands/permissions.ts index 00ee8fa..bad054a 100644 --- a/src/cli/commands/permissions.ts +++ b/src/cli/commands/permissions.ts @@ -2,7 +2,7 @@ import { usageError } from "../../core/errors.js"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { outputOptions } from "../printer.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handlePermissionsCommand( diff --git a/src/cli/commands/preference.ts b/src/cli/commands/preference.ts index 15598f0..10cb493 100644 --- a/src/cli/commands/preference.ts +++ b/src/cli/commands/preference.ts @@ -3,8 +3,8 @@ import { readFileSync } from "node:fs"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, jsonObject, stringOption } from "../parser.js"; -import { outputOptions } from "../printer.js"; +import { booleanOption, jsonObject, stringOption } from "../parse/parser.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handlePreferenceCommand( diff --git a/src/cli/commands/probe.ts b/src/cli/commands/probe.ts index 4b2b3f8..a1536cd 100644 --- a/src/cli/commands/probe.ts +++ b/src/cli/commands/probe.ts @@ -1,6 +1,6 @@ import { runProbe } from "../../probe.js"; -import { stringOption } from "../parser.js"; -import { printJson } from "../printer.js"; +import { stringOption } from "../parse/parser.js"; +import { printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleProbeCommand(action: string | undefined, maybeName: string | undefined, args: ParsedArgs) { diff --git a/src/cli/commands/report-review-cli.test.ts b/src/cli/commands/report-review-cli.test.ts index 6c8ec22..70803b7 100644 --- a/src/cli/commands/report-review-cli.test.ts +++ b/src/cli/commands/report-review-cli.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; import { saveCorpConfig } from "../../core/config/repository.js"; import { closeReviewsDb, diff --git a/src/cli/commands/report.ts b/src/cli/commands/report.ts index b8c1ec0..2a4fb90 100644 --- a/src/cli/commands/report.ts +++ b/src/cli/commands/report.ts @@ -3,8 +3,8 @@ import { resolve } from "node:path"; import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { runCapabilityResult } from "../helpers.js"; -import { booleanOption, numberOption, stringOption } from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +import { booleanOption, numberOption, stringOption } from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import { CliError, usageError } from "../../core/errors.js"; import { isCorpDisabledError } from "../../core/config/active.js"; import { diff --git a/src/cli/commands/rules.ts b/src/cli/commands/rules.ts index 55136fa..33ffeb7 100644 --- a/src/cli/commands/rules.ts +++ b/src/cli/commands/rules.ts @@ -20,13 +20,13 @@ import { ruleVersionSearchOptions, splitOption, stringOption -} from "../parser.js"; +} from "../parse/parser.js"; import { outputOptions, printJson, protectLargeRuleListOutput, RULE_SUMMARY_FIELDS -} from "../printer.js"; +} from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; function readDescriptionInput(args: ParsedArgs, payload: Record): string | undefined { diff --git a/src/cli/commands/simulation.test.ts b/src/cli/commands/simulation.test.ts index c08509f..6804db2 100644 --- a/src/cli/commands/simulation.test.ts +++ b/src/cli/commands/simulation.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/simulation.ts b/src/cli/commands/simulation.ts index 69e4350..9e23ef9 100644 --- a/src/cli/commands/simulation.ts +++ b/src/cli/commands/simulation.ts @@ -10,8 +10,8 @@ import { numberOption, splitOption, stringOption -} from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +} from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleSimulationCommand( diff --git a/src/cli/commands/skill.ts b/src/cli/commands/skill.ts index 6e381dd..39c4093 100644 --- a/src/cli/commands/skill.ts +++ b/src/cli/commands/skill.ts @@ -11,8 +11,8 @@ import { getSkillContent, installSkillFiles } from "../../core/skill/embedded-skill.js"; -import { booleanOption, stringOption } from "../parser.js"; -import { printJson } from "../printer.js"; +import { booleanOption, stringOption } from "../parse/parser.js"; +import { printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import { getSkillVersionStatus } from "../../core/skill/skill-version.js"; import { VERSION } from "../../version.js"; diff --git a/src/cli/commands/source.ts b/src/cli/commands/source.ts index aa1ec86..befc448 100644 --- a/src/cli/commands/source.ts +++ b/src/cli/commands/source.ts @@ -1,7 +1,7 @@ import { usageError } from "../../core/errors.js"; import type { CorpConfig } from "../../core/config/types.js"; import { resolveLiveSealEnterpriseConfig } from "../../domains/seal/enterprise/source.js"; -import { printJson } from "../printer.js"; +import { printJson } from "../output/printer.js"; export async function handleSourceCommand(action: string | undefined, corp: CorpConfig) { if (action === "config") { diff --git a/src/cli/commands/test.test.ts b/src/cli/commands/test.test.ts index 1681afe..947e65e 100644 --- a/src/cli/commands/test.test.ts +++ b/src/cli/commands/test.test.ts @@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import type { CorpConfig } from "../../core/config/types.js"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/test.ts b/src/cli/commands/test.ts index 4ced3b5..1c162c8 100644 --- a/src/cli/commands/test.ts +++ b/src/cli/commands/test.ts @@ -1,7 +1,7 @@ import { CliError } from "../../core/errors.js"; import { selectCorp } from "../helpers.js"; -import { booleanOption, numberOption, stringOption } from "../parser.js"; -import { printJson } from "../printer.js"; +import { booleanOption, numberOption, stringOption } from "../parse/parser.js"; +import { printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import { createSealClient } from "../../core/http/factory.js"; import { diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 617102c..5600bb8 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -7,7 +7,7 @@ import { normalizeBeijingIso } from "../../core/config/timestamps.js"; import { readInstalledSkillVersion } from "../../core/skill/embedded-skill.js"; import { saveUpdateCache } from "../../core/update/update-cache.js"; import { VERSION, IS_RELEASE } from "../../version.js"; -import { printJson } from "../printer.js"; +import { printJson } from "../output/printer.js"; import { validationError } from "../../core/errors.js"; import type { CliRuntime } from "../types.js"; diff --git a/src/cli/commands/users.test.ts b/src/cli/commands/users.test.ts index 762294f..a40551c 100644 --- a/src/cli/commands/users.test.ts +++ b/src/cli/commands/users.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/users.ts b/src/cli/commands/users.ts index e631f21..2b62d4e 100644 --- a/src/cli/commands/users.ts +++ b/src/cli/commands/users.ts @@ -2,8 +2,8 @@ import type { CorpConfig } from "../../core/config/types.js"; import type { createSealClient } from "../../core/http/factory.js"; import { confirmationRequired, usageError } from "../../core/errors.js"; import { runCapability } from "../helpers.js"; -import { booleanOption, dryRunOption, parseDelegationExpireHours, stringOption } from "../parser.js"; -import { outputOptions } from "../printer.js"; +import { booleanOption, dryRunOption, parseDelegationExpireHours, stringOption } from "../parse/parser.js"; +import { outputOptions } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; export async function handleUsersCommand( diff --git a/src/cli/commands/webhook-replay.test.ts b/src/cli/commands/webhook-replay.test.ts index e089027..beaf871 100644 --- a/src/cli/commands/webhook-replay.test.ts +++ b/src/cli/commands/webhook-replay.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; const ORIGINAL_ENV = { enterprises: process.env.SEAL_USE_ENTERPRISES_DIR, diff --git a/src/cli/commands/webhook-resource-pack.test.ts b/src/cli/commands/webhook-resource-pack.test.ts index a67fc3b..022ea92 100644 --- a/src/cli/commands/webhook-resource-pack.test.ts +++ b/src/cli/commands/webhook-resource-pack.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync, existsSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "../runner.js"; +import { runCli } from "../run/runner.js"; import { exportApprovalRunsToResourcePack } from "../../domains/seal/material-pack/export.js"; import { previewResourcePack } from "../../domains/seal/material-pack/service.js"; diff --git a/src/cli/commands/webhook.ts b/src/cli/commands/webhook.ts index 37d1d37..832c32a 100644 --- a/src/cli/commands/webhook.ts +++ b/src/cli/commands/webhook.ts @@ -28,8 +28,8 @@ import { stringOption, webhookRateOption, webhookShowSecretOption -} from "../parser.js"; -import { outputOptions, printJson } from "../printer.js"; +} from "../parse/parser.js"; +import { outputOptions, printJson } from "../output/printer.js"; import type { ParsedArgs } from "../types.js"; import type { MaterialPackFilePolicyPatch } from "../../domains/seal/material-pack/policy.js"; import { CliError, confirmationRequired, usageError, validationError } from "../../core/errors.js"; diff --git a/src/cli/docs-commands.test.ts b/src/cli/help/docs-commands.test.ts similarity index 96% rename from src/cli/docs-commands.test.ts rename to src/cli/help/docs-commands.test.ts index 96fb31d..520f549 100644 --- a/src/cli/docs-commands.test.ts +++ b/src/cli/help/docs-commands.test.ts @@ -1,8 +1,8 @@ import { describe, expect, test } from "bun:test"; import { readFileSync, readdirSync } from "node:fs"; import { join } from "node:path"; -import { parseArgs } from "./parser.js"; -import { KNOWN_AREAS, UPDATE_ALIASES } from "./runner.js"; +import { parseArgs } from "../parse/parser.js"; +import { KNOWN_AREAS, UPDATE_ALIASES } from "../run/runner.js"; /** * Documentation cross-check: every command a maintained doc shows a reader must @@ -21,7 +21,7 @@ import { KNOWN_AREAS, UPDATE_ALIASES } from "./runner.js"; * like "the seal-use wrapped API" is not a command and is not matched. */ -const REPO_ROOT = join(import.meta.dir, "..", ".."); +const REPO_ROOT = join(import.meta.dir, "..", "..", ".."); const DOC_FILES = [ "README.md", diff --git a/src/cli/help.test.ts b/src/cli/help/help.test.ts similarity index 99% rename from src/cli/help.test.ts rename to src/cli/help/help.test.ts index 575ae33..337e7d1 100644 --- a/src/cli/help.test.ts +++ b/src/cli/help/help.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import { extractHelpRequest, HELP_REGISTRY, renderHelp } from "./help.js"; -import { KNOWN_AREAS, runCli } from "./runner.js"; +import { KNOWN_AREAS, runCli } from "../run/runner.js"; describe("extractHelpRequest", () => { test("detects global help from empty command or help option", () => { diff --git a/src/cli/help.ts b/src/cli/help/help.ts similarity index 99% rename from src/cli/help.ts rename to src/cli/help/help.ts index cfaecb8..6891a3d 100644 --- a/src/cli/help.ts +++ b/src/cli/help/help.ts @@ -1,6 +1,6 @@ -import { normalizeCliArea } from "./area-aliases.js"; -import type { ParsedArgs } from "./types.js"; -import { usageError } from "../core/errors.js"; +import { normalizeCliArea } from "../parse/area-aliases.js"; +import type { ParsedArgs } from "../types.js"; +import { usageError } from "../../core/errors.js"; export interface CommandOptionHelp { flag: string; diff --git a/src/cli/naming-charter.test.ts b/src/cli/help/naming-charter.test.ts similarity index 96% rename from src/cli/naming-charter.test.ts rename to src/cli/help/naming-charter.test.ts index 123a391..fb7819c 100644 --- a/src/cli/naming-charter.test.ts +++ b/src/cli/help/naming-charter.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test"; import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { HELP_REGISTRY } from "./help.js"; -import { parseArgs } from "./parser.js"; +import { parseArgs } from "../parse/parser.js"; /** * Naming charter guard (.agents/rules/cli-protocol.md "Naming Charter"). @@ -110,20 +110,20 @@ describe("naming charter: canonical accept-sets are wired in commands", () => { const read = (path: string) => readFileSync(fileURLToPath(new URL(path, import.meta.url)), "utf8"); test("webhook resource-pack export reads --out and --downloads (no silent ignore)", () => { - const source = read("./commands/webhook.ts"); + const source = read("../commands/webhook.ts"); expect(source).toContain("stringOption(args.options.out) ??"); expect(source).toContain("booleanOption(args.options.downloads) ??"); expect(source).toContain("booleanOption(args.options.download) ??"); }); test("webhook secret reveal accepts --reveal alongside legacy --show-secret", () => { - const source = read("./parser.ts"); + const source = read("../parse/parser.ts"); expect(source).toContain("booleanOption(options.reveal)"); expect(source).toContain('booleanOption(options["show-secret"])'); }); test("approval-runs reads canonical --start-date/--end-date everywhere", () => { - const source = read("./commands/approval-runs.ts"); + const source = read("../commands/approval-runs.ts"); const startDateReads = source.match(/args\.options\["start-date"\]/g)?.length ?? 0; const endDateReads = source.match(/args\.options\["end-date"\]/g)?.length ?? 0; expect(startDateReads).toBeGreaterThanOrEqual(3); diff --git a/src/cli/helpers.ts b/src/cli/helpers.ts index 2e34d92..0927776 100644 --- a/src/cli/helpers.ts +++ b/src/cli/helpers.ts @@ -7,7 +7,7 @@ import { createLangfuseService, findLangfuseCapability } from "../domains/langfu import type { LangfuseService } from "../domains/langfuse/service.js"; import { validationError } from "../core/errors.js"; import type { CorpConfig, GlobalConfig } from "../core/config/types.js"; -import { printJson } from "./printer.js"; +import { printJson } from "./output/printer.js"; import type { OutputOptions } from "./types.js"; export function selectCorp(corpId?: string, options: { allowDisabled?: boolean } = {}): CorpConfig { diff --git a/src/cli/printer.ts b/src/cli/output/printer.ts similarity index 90% rename from src/cli/printer.ts rename to src/cli/output/printer.ts index 7ead0b0..1ba4a20 100644 --- a/src/cli/printer.ts +++ b/src/cli/output/printer.ts @@ -1,8 +1,8 @@ import { writeFileSync } from "node:fs"; -import { booleanOption, stringOption } from "./parser.js"; -import { PayloadTooLargeError } from "../core/errors.js"; -import { redactSensitiveText } from "../core/util/redact.js"; -import type { OutputOptions } from "./types.js"; +import { booleanOption, stringOption } from "../parse/parser.js"; +import { PayloadTooLargeError } from "../../core/errors.js"; +import { redactSensitiveText } from "../../core/util/redact.js"; +import type { OutputOptions } from "../types.js"; export { redactSensitiveText }; @@ -68,7 +68,7 @@ export function outputOptions(options: Record): Output }; } -import { renderHelp } from "./help.js"; +import { renderHelp } from "../help/help.js"; export function printHelp(target: string[] = []) { console.log(renderHelp(target)); diff --git a/src/cli/area-aliases.test.ts b/src/cli/parse/area-aliases.test.ts similarity index 98% rename from src/cli/area-aliases.test.ts rename to src/cli/parse/area-aliases.test.ts index 904cb1c..9068a70 100644 --- a/src/cli/area-aliases.test.ts +++ b/src/cli/parse/area-aliases.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import { AREA_ALIASES, UPDATE_ALIASES, normalizeCliArea } from "./area-aliases.js"; -import { KNOWN_AREAS } from "./runner.js"; +import { KNOWN_AREAS } from "../run/runner.js"; /** * Drift guard for the shared alias table. diff --git a/src/cli/area-aliases.ts b/src/cli/parse/area-aliases.ts similarity index 100% rename from src/cli/area-aliases.ts rename to src/cli/parse/area-aliases.ts diff --git a/src/cli/parser.test.ts b/src/cli/parse/parser.test.ts similarity index 99% rename from src/cli/parser.test.ts rename to src/cli/parse/parser.test.ts index ba039cf..bd5f601 100644 --- a/src/cli/parser.test.ts +++ b/src/cli/parse/parser.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import { HELP_REGISTRY } from "./help.js"; +import { HELP_REGISTRY } from "../help/help.js"; import { booleanOption, BOOLEAN_FLAGS, diff --git a/src/cli/parser.ts b/src/cli/parse/parser.ts similarity index 98% rename from src/cli/parser.ts rename to src/cli/parse/parser.ts index 3834857..a1cf947 100644 --- a/src/cli/parser.ts +++ b/src/cli/parse/parser.ts @@ -1,8 +1,8 @@ -import type { WebhookMode } from "../domains/seal/types.js"; -import type { MaterialPackFilePolicyPatch } from "../domains/seal/material-pack/policy.js"; -import type { ParsedArgs } from "./types.js"; -import { type DurationToken, EXPIRE_UNITS, expireSeconds, tokenizeDuration } from "../core/util/duration.js"; -import { usageError, validationError } from "../core/errors.js"; +import type { WebhookMode } from "../../domains/seal/types.js"; +import type { MaterialPackFilePolicyPatch } from "../../domains/seal/material-pack/policy.js"; +import type { ParsedArgs } from "../types.js"; +import { type DurationToken, EXPIRE_UNITS, expireSeconds, tokenizeDuration } from "../../core/util/duration.js"; +import { usageError, validationError } from "../../core/errors.js"; /** * Flag metadata for argv parsing, derived from how the code reads each flag: diff --git a/src/cli/tokenize.ts b/src/cli/parse/tokenize.ts similarity index 97% rename from src/cli/tokenize.ts rename to src/cli/parse/tokenize.ts index f787e7b..7f3d12c 100644 --- a/src/cli/tokenize.ts +++ b/src/cli/parse/tokenize.ts @@ -3,7 +3,7 @@ * reach the CLI intact. Lives in its own module because both the MCP server and the HTTP routes * need it; importing it from the server entry would make the CLI graph circular. */ -import { usageError } from "../core/errors.js"; +import { usageError } from "../../core/errors.js"; export function tokenizeCommand(command: string): string[] { const tokens: string[] = []; let token = ""; diff --git a/src/cli/read-only.test.ts b/src/cli/run/read-only.test.ts similarity index 97% rename from src/cli/read-only.test.ts rename to src/cli/run/read-only.test.ts index 30be9e7..60f8990 100644 --- a/src/cli/read-only.test.ts +++ b/src/cli/run/read-only.test.ts @@ -1,9 +1,9 @@ import { describe, expect, test } from "bun:test"; import { readFileSync, readdirSync } from "node:fs"; import { join } from "node:path"; -import { HELP_REGISTRY } from "./help.js"; +import { HELP_REGISTRY } from "../help/help.js"; import { KNOWN_AREAS } from "./runner.js"; -import { SEAL_MUTATING_CAPABILITIES, SEAL_READ_ONLY_CAPABILITIES, sealCapabilities } from "../domains/seal/capabilities.js"; +import { SEAL_MUTATING_CAPABILITIES, SEAL_READ_ONLY_CAPABILITIES, sealCapabilities } from "../../domains/seal/capabilities.js"; import { isReadOnlyCliCommand, listReadOnlyCommands } from "./read-only.js"; describe("CLI read-only classification", () => { @@ -177,14 +177,14 @@ describe("CLI allow-list agrees with the tool registry", () => { ]); test("every CLI verb dispatching to a read-only tool is itself read-only, and mutating tools are not read-only", () => { - const files = readdirSync(join(import.meta.dir, "commands")).filter( + const files = readdirSync(join(import.meta.dir, "../commands")).filter( (f) => f.endsWith(".ts") && !f.endsWith(".test.ts") ); const pairs: Array<{ area: string; action: string; tool: string }> = []; for (const file of files) { const area = file.replace(/\.ts$/, ""); - const source = readFileSync(join(import.meta.dir, "commands", file), "utf8"); + const source = readFileSync(join(import.meta.dir, "../commands", file), "utf8"); const pattern = /if\s*\(\s*action === "([a-z0-9-]+)"(?:(?!\bif\s*\(\s*action\b)[\s\S]){0,600}?runCapability(?:Result)?\(\s*"(seal[A-Z][A-Za-z0-9]*)"/g; let match; diff --git a/src/cli/read-only.ts b/src/cli/run/read-only.ts similarity index 98% rename from src/cli/read-only.ts rename to src/cli/run/read-only.ts index bcb3c25..43d4643 100644 --- a/src/cli/read-only.ts +++ b/src/cli/run/read-only.ts @@ -1,5 +1,5 @@ -import { normalizeCliArea } from "./area-aliases.js"; -import { parseArgs } from "./parser.js"; +import { normalizeCliArea } from "../parse/area-aliases.js"; +import { parseArgs } from "../parse/parser.js"; /** * Read-only classification for CLI commands, used to decide whether a command may be executed diff --git a/src/cli/runner.test.ts b/src/cli/run/runner.test.ts similarity index 97% rename from src/cli/runner.test.ts rename to src/cli/run/runner.test.ts index e222efa..170d50e 100644 --- a/src/cli/runner.test.ts +++ b/src/cli/run/runner.test.ts @@ -3,8 +3,8 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import { runCli } from "./runner.js"; -import { saveUpdateCache, UPDATE_CACHE_FILE_ENV } from "../core/update/update-cache.js"; -import { GLOBAL_SKILL_DIR_ENV } from "../core/skill/skill-version.js"; +import { saveUpdateCache, UPDATE_CACHE_FILE_ENV } from "../../core/update/update-cache.js"; +import { GLOBAL_SKILL_DIR_ENV } from "../../core/skill/skill-version.js"; describe("CLI runner", () => { let tempSkillDir: string; diff --git a/src/cli/runner.ts b/src/cli/run/runner.ts similarity index 64% rename from src/cli/runner.ts rename to src/cli/run/runner.ts index a57e8b7..be5cfb3 100755 --- a/src/cli/runner.ts +++ b/src/cli/run/runner.ts @@ -2,34 +2,34 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; -import type { CorpConfig } from "../core/config/types.js"; -import { VERSION_INFO } from "../version.js"; -import { isUpdateCacheExpired, loadUpdateCache, triggerBackgroundUpdateCheck } from "../core/update/update-cache.js"; -import { classifyCliError, usageError, validationError } from "../core/errors.js"; -import { isCorpDisabledError } from "../core/config/active.js"; +import type { CorpConfig } from "../../core/config/types.js"; +import { VERSION_INFO } from "../../version.js"; +import { isUpdateCacheExpired, loadUpdateCache, triggerBackgroundUpdateCheck } from "../../core/update/update-cache.js"; +import { classifyCliError, usageError, validationError } from "../../core/errors.js"; +import { isCorpDisabledError } from "../../core/config/active.js"; import { booleanOption, materialPackFilePolicyOptions, numberOption, parseArgs, stringOption -} from "./parser.js"; -import { extractHelpRequest } from "./help.js"; -import { isNewerVersion } from "../core/util/semver.js"; -import { getSkillVersionStatus } from "../core/skill/skill-version.js"; +} from "../parse/parser.js"; +import { extractHelpRequest } from "../help/help.js"; +import { isNewerVersion } from "../../core/util/semver.js"; +import { getSkillVersionStatus } from "../../core/skill/skill-version.js"; import { formatConsoleOutput, joinOutput, printHelp, printJson, redactSensitiveText -} from "./printer.js"; +} from "../output/printer.js"; import type { KyInstance } from "ky"; -import type { ParsedArgs, CliResult, CliRunOptions, CliRuntime } from "./types.js"; +import type { ParsedArgs, CliResult, CliRunOptions, CliRuntime } from "../types.js"; -const DEFAULT_APP_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url)))); -export { UPDATE_ALIASES } from "./area-aliases.js"; -import { AREA_ALIASES, normalizeCliArea, UPDATE_ALIASES } from "./area-aliases.js"; +const DEFAULT_APP_ROOT = dirname(dirname(dirname(dirname(fileURLToPath(import.meta.url))))); +export { UPDATE_ALIASES } from "../parse/area-aliases.js"; +import { AREA_ALIASES, normalizeCliArea, UPDATE_ALIASES } from "../parse/area-aliases.js"; type LocalCommand = (args: ParsedArgs, runtime: CliRuntime) => Promise; type CorpCommand = (args: ParsedArgs, corp: CorpConfig) => Promise; @@ -38,56 +38,56 @@ type ClientCommand = (args: ParsedArgs, corp: CorpConfig, client: KyInstance) => // Handler tables also define the known command surface. Imports stay lazy so // local discovery never loads the tenant, Excel, or zip implementation graphs. const LOCAL_COMMANDS: Record = { - "mcp-config": async () => (await import("./commands/mcp.js")).printMcpConfig(), - skill: async (args) => (await import("./commands/skill.js")).handleSkillCommand(args.command[1], args.command[2], args), - mcp: async (args) => (await import("./commands/mcp.js")).handleMcpCommand(args.command[1]), - probe: async (args) => (await import("./commands/probe.js")).handleProbeCommand(args.command[1], args.command[2], args), - doctor: async (args) => (await import("./commands/doctor.js")).handleDoctorCommand(args.command[1], args.command[2], args), - langfuse: async (args) => (await import("./commands/langfuse.js")).handleLangfuseCommand(args.command[1], args.command[2], args), - test: async (args) => (await import("./commands/test.js")).handleTestCommand(args.command[1], args.command[2], args), - config: async (args) => (await import("./commands/config.js")).handleConfigCommand(args.command[1], args.command[2], args), + "mcp-config": async () => (await import("../commands/mcp.js")).printMcpConfig(), + skill: async (args) => (await import("../commands/skill.js")).handleSkillCommand(args.command[1], args.command[2], args), + mcp: async (args) => (await import("../commands/mcp.js")).handleMcpCommand(args.command[1]), + probe: async (args) => (await import("../commands/probe.js")).handleProbeCommand(args.command[1], args.command[2], args), + doctor: async (args) => (await import("../commands/doctor.js")).handleDoctorCommand(args.command[1], args.command[2], args), + langfuse: async (args) => (await import("../commands/langfuse.js")).handleLangfuseCommand(args.command[1], args.command[2], args), + test: async (args) => (await import("../commands/test.js")).handleTestCommand(args.command[1], args.command[2], args), + config: async (args) => (await import("../commands/config.js")).handleConfigCommand(args.command[1], args.command[2], args), update: dispatchUpdate, changelog: dispatchUpdate, corps: async (args) => { const action = args.command[1]; // Local discovery must not initialize onboarding, sync or the capability registry. if (!action || ["list", "search", "find"].includes(action)) { - await (await import("./commands/corps/overview.js")).handleCorpOverview(action, args.command[2], args); + await (await import("../commands/corps/overview.js")).handleCorpOverview(action, args.command[2], args); return; } if (action === "regression" || action === "test-regression") { - await (await import("./commands/test.js")).handleTestCommand("regression", args.command[2], args); + await (await import("../commands/test.js")).handleTestCommand("regression", args.command[2], args); return; } - await (await import("./commands/corps.js")).handleCorpsCommand(action, args.command[2], args); + await (await import("../commands/corps.js")).handleCorpsCommand(action, args.command[2], args); } }; const CORP_COMMANDS: Record = { - source: async (args, corp) => (await import("./commands/source.js")).handleSourceCommand(args.command[1], corp), - auth: async (args, corp) => (await import("./commands/auth.js")).handleAuthCommand(args.command[1], corp, args) + source: async (args, corp) => (await import("../commands/source.js")).handleSourceCommand(args.command[1], corp), + auth: async (args, corp) => (await import("../commands/auth.js")).handleAuthCommand(args.command[1], corp, args) }; const CLIENT_COMMANDS: Record = { - "users": async (args, corp, client) => (await import("./commands/users.js")).handleUsersCommand(args.command[1], args.command[2], client, corp, args), - "contacts": async (args, corp, client) => (await import("./commands/contacts.js")).handleContactsCommand(args.command[1], args.command[2], client, corp, args), - "data": async (args, corp, client) => (await import("./commands/data.js")).handleDataCommand(args.command[1], client, corp, args), - "invoices": async (args, corp, client) => (await import("./commands/invoices.js")).handleInvoicesCommand(args.command[1], args.command[2], client, corp, args), - "expenses": async (args, corp, client) => (await import("./commands/expenses.js")).handleExpensesCommand(args.command[1], client, corp, args), - "llm": async (args, corp, client) => (await import("./commands/llm.js")).handleLlmCommand(args.command[1], client, corp, args), - "permissions": async (args, corp, client) => (await import("./commands/permissions.js")).handlePermissionsCommand(args.command[1], client, corp, args), - "billing": async (args, corp, client) => (await import("./commands/billing.js")).handleBillingCommand(args.command[1], client, corp, args), - "webhook": async (args, corp, client) => (await import("./commands/webhook.js")).handleWebhookCommand(args.command[1], args.command[2], client, corp, args), - "context": async (args, corp, client) => (await import("./commands/context.js")).handleContextCommand(client, corp, args), - "documents": async (args, corp, client) => (await import("./commands/documents.js")).handleDocumentsCommand(args.command[1], args.command[2], client, corp, args), - "rules": async (args, corp, client) => (await import("./commands/rules.js")).handleRulesCommand(args.command[1], args.command[2], client, corp, args), - "approval-runs": async (args, corp, client) => (await import("./commands/approval-runs.js")).handleApprovalRunsCommand(args.command[1], args.command[2], client, corp, args), - "analytics": async (args, corp, client) => (await import("./commands/analytics.js")).handleAnalyticsCommand(args.command[1], args.command[2], client, corp, args), - "report": async (args, corp, client) => (await import("./commands/report.js")).handleReportCommand(args.command[1], client, corp, args), - "simulation": async (args, corp, client) => (await import("./commands/simulation.js")).handleSimulationCommand(args.command[1], args.command[2], client, corp, args), - "deploy": async (args, corp, client) => (await import("./commands/deploy.js")).handleDeployCommand(args.command[1], args.command[2], args.command[3], client, corp, args), - "hose-ebot": async (args, corp, client) => (await import("./commands/hose-ebot.js")).handleHoseEbotCommand(args.command[1], args.command[2], client, corp, args), - "preference": async (args, corp, client) => (await import("./commands/preference.js")).handlePreferenceCommand(args.command[1], args.command[2], args.command[3], args.command[4], client, corp, args), + "users": async (args, corp, client) => (await import("../commands/users.js")).handleUsersCommand(args.command[1], args.command[2], client, corp, args), + "contacts": async (args, corp, client) => (await import("../commands/contacts.js")).handleContactsCommand(args.command[1], args.command[2], client, corp, args), + "data": async (args, corp, client) => (await import("../commands/data.js")).handleDataCommand(args.command[1], client, corp, args), + "invoices": async (args, corp, client) => (await import("../commands/invoices.js")).handleInvoicesCommand(args.command[1], args.command[2], client, corp, args), + "expenses": async (args, corp, client) => (await import("../commands/expenses.js")).handleExpensesCommand(args.command[1], client, corp, args), + "llm": async (args, corp, client) => (await import("../commands/llm.js")).handleLlmCommand(args.command[1], client, corp, args), + "permissions": async (args, corp, client) => (await import("../commands/permissions.js")).handlePermissionsCommand(args.command[1], client, corp, args), + "billing": async (args, corp, client) => (await import("../commands/billing.js")).handleBillingCommand(args.command[1], client, corp, args), + "webhook": async (args, corp, client) => (await import("../commands/webhook.js")).handleWebhookCommand(args.command[1], args.command[2], client, corp, args), + "context": async (args, corp, client) => (await import("../commands/context.js")).handleContextCommand(client, corp, args), + "documents": async (args, corp, client) => (await import("../commands/documents.js")).handleDocumentsCommand(args.command[1], args.command[2], client, corp, args), + "rules": async (args, corp, client) => (await import("../commands/rules.js")).handleRulesCommand(args.command[1], args.command[2], client, corp, args), + "approval-runs": async (args, corp, client) => (await import("../commands/approval-runs.js")).handleApprovalRunsCommand(args.command[1], args.command[2], client, corp, args), + "analytics": async (args, corp, client) => (await import("../commands/analytics.js")).handleAnalyticsCommand(args.command[1], args.command[2], client, corp, args), + "report": async (args, corp, client) => (await import("../commands/report.js")).handleReportCommand(args.command[1], client, corp, args), + "simulation": async (args, corp, client) => (await import("../commands/simulation.js")).handleSimulationCommand(args.command[1], args.command[2], client, corp, args), + "deploy": async (args, corp, client) => (await import("../commands/deploy.js")).handleDeployCommand(args.command[1], args.command[2], args.command[3], client, corp, args), + "hose-ebot": async (args, corp, client) => (await import("../commands/hose-ebot.js")).handleHoseEbotCommand(args.command[1], args.command[2], client, corp, args), + "preference": async (args, corp, client) => (await import("../commands/preference.js")).handlePreferenceCommand(args.command[1], args.command[2], args.command[3], args.command[4], client, corp, args), }; export const KNOWN_AREAS = new Set([ @@ -97,7 +97,7 @@ export const KNOWN_AREAS = new Set([ ...Object.keys(AREA_ALIASES) ]); -export type { CliResult, CliRunOptions } from "./types.js"; +export type { CliResult, CliRunOptions } from "../types.js"; const STANDING_COMMANDS = new Set(["server", "mcp"]); @@ -210,7 +210,7 @@ async function dispatchUpdate(args: ParsedArgs, runtime: CliRuntime): Promise"); - await (await import("./commands/webhook.js")).handleWebhookResourcePackPreview(filePath, materialPackFilePolicyOptions(args.options)); + await (await import("../commands/webhook.js")).handleWebhookResourcePackPreview(filePath, materialPackFilePolicyOptions(args.options)); return; } @@ -298,7 +298,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) { action === "review" || Boolean(args.options.ledger)) ) { - await (await import("./commands/report.js")).handleLocalReportCommand(action, args); + await (await import("../commands/report.js")).handleLocalReportCommand(action, args); return; } @@ -313,7 +313,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) { if (area === "rules" && action === "lint" && ("file" in args.options || "f" in args.options)) { let corp: CorpConfig; try { - corp = (await import("./helpers.js")).selectCorp(stringOption(args.options.corp)); + corp = (await import("../helpers.js")).selectCorp(stringOption(args.options.corp)); } catch (error) { // Local lint tolerates a missing enterprise config, but a disabled tenant // is an explicit block: never degrade into the synthetic workspace corp. @@ -324,7 +324,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) { source: { type: "native" } } as any; } - await (await import("./commands/rules.js")).handleRulesCommand(action, maybeName, null, corp, args); + await (await import("../commands/rules.js")).handleRulesCommand(action, maybeName, null, corp, args); return; } @@ -332,7 +332,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) { area === "auth" && (action === "extract-keys" || action === "extract-key" || action === "extract-hose-keys" || action === "hose-extract-keys") ) { - await (await import("./commands/auth.js")).handleAuthExtractKeysCommand(maybeName, args); + await (await import("../commands/auth.js")).handleAuthExtractKeysCommand(maybeName, args); return; } @@ -341,23 +341,23 @@ async function dispatch(argv: string[], runtime: CliRuntime) { (action === "link" || action === "seal-link") && ("from-link" in args.options || maybeName === "from-link") ) { - await (await import("./commands/auth.js")).handleAuthCommand(action, null, args); + await (await import("../commands/auth.js")).handleAuthCommand(action, null, args); return; } // Local task observation and previews must not authenticate or contact a tenant. if (area === "approval-runs" && (action === "export" || action === "export-worker")) { - await (await import("./commands/approval-runs-export.js")).handleApprovalRunsExportCommand(args, runtime); + await (await import("../commands/approval-runs-export.js")).handleApprovalRunsExportCommand(args, runtime); return; } - const corp = (await import("./helpers.js")).selectCorp(stringOption(args.options.corp)); + const corp = (await import("../helpers.js")).selectCorp(stringOption(args.options.corp)); const maybePromptDivergences = async () => { if (area === "report" && action === "review") return; try { const { countUnreviewedDivergences, shouldPromptDivergence } = await import( - "../domains/seal/reports/pipeline/review-store.js" + "../../domains/seal/reports/pipeline/review-store.js" ); const count = countUnreviewedDivergences(corp.id, 30); if (count > 0 && shouldPromptDivergence(corp.id)) { @@ -379,7 +379,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) { const clientCommand = CLIENT_COMMANDS[area]; if (clientCommand) { - const client = await (await import("../core/http/factory.js")).createSealClient(corp); + const client = await (await import("../../core/http/factory.js")).createSealClient(corp); await clientCommand(args, corp, client); await maybePromptDivergences(); return; diff --git a/src/core/util/redact.ts b/src/core/util/redact.ts index e04e9e7..c4ea515 100644 --- a/src/core/util/redact.ts +++ b/src/core/util/redact.ts @@ -2,7 +2,7 @@ * Redacts credential-bearing patterns from free text before it reaches an * output channel. * - * Applied to: error messages surfaced by the CLI runner (`src/cli/runner.ts`) and + * Applied to: error messages surfaced by the CLI runner (`src/cli/run/runner.ts`) and * HTTP error responses (`src/http/routes.ts`). * * NOT applied to successful stdout payloads: those are redacted where they are diff --git a/src/domains/seal/reports/export/files.test.ts b/src/domains/seal/reports/export/files.test.ts index 13309ba..7e08ca4 100644 --- a/src/domains/seal/reports/export/files.test.ts +++ b/src/domains/seal/reports/export/files.test.ts @@ -3,7 +3,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync import { tmpdir } from "node:os"; import { join } from "node:path"; import { PNG } from "pngjs"; -import { runCli } from "../../../../cli/runner.js"; +import { runCli } from "../../../../cli/run/runner.js"; import { buildMonthlyReport } from "../pipeline/index.js"; import { renderReportFile, saveReportMarkdown, validateReportFile } from "./files.js"; import { BUILTIN_MONTHLY_TEMPLATE, BUILTIN_TEMPLATE_PATH } from "../templates/resources.js"; diff --git a/src/domains/seal/rules/push.test.ts b/src/domains/seal/rules/push.test.ts index 9a8df0b..d864ff5 100644 --- a/src/domains/seal/rules/push.test.ts +++ b/src/domains/seal/rules/push.test.ts @@ -6,7 +6,7 @@ import type { KyInstance } from "ky"; import type { CorpConfig } from "../../../core/config/types.js"; import { classifyCliError } from "../../../core/errors.js"; import { handleRulesCommand } from "../../../cli/commands/rules.js"; -import { parseArgs } from "../../../cli/parser.js"; +import { parseArgs } from "../../../cli/parse/parser.js"; import type { ApprovalRule } from "../types.js"; import { executeRulePush, diff --git a/src/domains/seal/rules/recode.test.ts b/src/domains/seal/rules/recode.test.ts index 3a720a1..d2b941e 100644 --- a/src/domains/seal/rules/recode.test.ts +++ b/src/domains/seal/rules/recode.test.ts @@ -10,7 +10,7 @@ import { recodeApprovalRules } from "../api.js" import type { ApprovalRulesData } from "../types.js" import { runCapabilityResult } from "../../../cli/helpers.js" import { handleRulesCommand } from "../../../cli/commands/rules.js" -import { parseArgs } from "../../../cli/parser.js" +import { parseArgs } from "../../../cli/parse/parser.js" const originalStore = process.env.SEAL_USE_RECODE_STORE const dirs: string[] = [] diff --git a/src/probe.test.ts b/src/probe.test.ts index dc97f97..d630b81 100644 --- a/src/probe.test.ts +++ b/src/probe.test.ts @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { runCli } from "./cli/runner.js"; +import { runCli } from "./cli/run/runner.js"; const ENV_KEYS = ["SEAL_USE_ENTERPRISES_DIR", "SEAL_USE_CONFIG_FILE", "SEAL_USE_TOKEN_STORE", "SEAL_DISABLE_BG_UPDATE"] as const; const ORIGINAL_ENV: Record = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]])); diff --git a/src/probe.ts b/src/probe.ts index 8b7f6a8..7a6c383 100644 --- a/src/probe.ts +++ b/src/probe.ts @@ -4,7 +4,7 @@ import { createSealClient } from "./core/http/factory.js"; import type { SealEnterpriseConfig } from "./core/auth/types.js"; import { resolveLiveSealEnterpriseConfig } from "./domains/seal/enterprise/source.js"; import { getApprovalContext } from "./domains/seal/api.js"; -import { printJson } from "./cli/printer.js"; +import { printJson } from "./cli/output/printer.js"; /** One probe run's payload — the entire stdout of `seal-use probe`. */ export type ProbeResult = { diff --git a/src/server.ts b/src/server.ts index e0bc5ce..2365509 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3,9 +3,9 @@ import { fileURLToPath } from "node:url"; import { McpServer, type CallToolResult } from "@modelcontextprotocol/server"; import { serveStdio, type StdioServerHandle } from "@modelcontextprotocol/server/stdio"; import { z } from "zod"; -import { runCli } from "./cli/runner.js"; -import { isReadOnlyCliCommand } from "./cli/read-only.js"; -import { normalizeCliArgs, tokenizeCommand } from "./cli/tokenize.js"; +import { runCli } from "./cli/run/runner.js"; +import { isReadOnlyCliCommand } from "./cli/run/read-only.js"; +import { normalizeCliArgs, tokenizeCommand } from "./cli/parse/tokenize.js"; import { classifyCliError } from "./core/errors.js"; import { VERSION } from "./version.js"; import { isCompiledBinary, resolveAppRoot, resolveDefaultLauncher } from "./core/util/runtime.js"; diff --git a/src/streams.test.ts b/src/streams.test.ts index 4325ecd..321337b 100644 --- a/src/streams.test.ts +++ b/src/streams.test.ts @@ -22,7 +22,7 @@ import { join, relative } from "node:path"; const SRC_DIR = join(import.meta.dir); const STDOUT_WRITERS = new Set([ - "cli/printer.ts", + "cli/output/printer.ts", "cli/commands/doctor.ts", "cli/commands/skill.ts", "cli.ts",