@damian87/omp 0.6.0 → 0.8.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.
Files changed (60) hide show
  1. package/.github/skills/team/SKILL.md +82 -57
  2. package/.github/skills/team/scripts/team-launch.sh +140 -42
  3. package/README.md +31 -0
  4. package/catalog/skills-general.json +2 -2
  5. package/dist/src/cli.d.ts +1 -7
  6. package/dist/src/cli.js +355 -1
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/commands/registry.d.ts +3 -0
  9. package/dist/src/commands/registry.js +11 -0
  10. package/dist/src/commands/registry.js.map +1 -0
  11. package/dist/src/commands/suggest.d.ts +19 -0
  12. package/dist/src/commands/suggest.js +158 -0
  13. package/dist/src/commands/suggest.js.map +1 -0
  14. package/dist/src/commands/types.d.ts +16 -0
  15. package/dist/src/commands/types.js +2 -0
  16. package/dist/src/commands/types.js.map +1 -0
  17. package/dist/src/env/dotenv.d.ts +41 -0
  18. package/dist/src/env/dotenv.js +112 -0
  19. package/dist/src/env/dotenv.js.map +1 -0
  20. package/dist/src/env/init.d.ts +50 -0
  21. package/dist/src/env/init.js +276 -0
  22. package/dist/src/env/init.js.map +1 -0
  23. package/dist/src/gateway/connector.d.ts +37 -0
  24. package/dist/src/gateway/connector.js +12 -0
  25. package/dist/src/gateway/connector.js.map +1 -0
  26. package/dist/src/gateway/connectors/slack.d.ts +69 -0
  27. package/dist/src/gateway/connectors/slack.js +159 -0
  28. package/dist/src/gateway/connectors/slack.js.map +1 -0
  29. package/dist/src/gateway/registry.d.ts +29 -0
  30. package/dist/src/gateway/registry.js +37 -0
  31. package/dist/src/gateway/registry.js.map +1 -0
  32. package/dist/src/gateway/runtime.d.ts +58 -0
  33. package/dist/src/gateway/runtime.js +105 -0
  34. package/dist/src/gateway/runtime.js.map +1 -0
  35. package/dist/src/instructions-memory.js +8 -15
  36. package/dist/src/instructions-memory.js.map +1 -1
  37. package/dist/src/jira.js +2 -14
  38. package/dist/src/jira.js.map +1 -1
  39. package/dist/src/slack/config.d.ts +32 -0
  40. package/dist/src/slack/config.js +52 -0
  41. package/dist/src/slack/config.js.map +1 -0
  42. package/dist/src/slack/handler.d.ts +48 -0
  43. package/dist/src/slack/handler.js +68 -0
  44. package/dist/src/slack/handler.js.map +1 -0
  45. package/dist/src/slack/serve.d.ts +8 -0
  46. package/dist/src/slack/serve.js +7 -0
  47. package/dist/src/slack/serve.js.map +1 -0
  48. package/dist/src/team/index.d.ts +1 -0
  49. package/dist/src/team/index.js +1 -0
  50. package/dist/src/team/index.js.map +1 -1
  51. package/dist/src/team/pane-monitor.d.ts +39 -0
  52. package/dist/src/team/pane-monitor.js +128 -0
  53. package/dist/src/team/pane-monitor.js.map +1 -0
  54. package/dist/src/team/runtime.js +12 -1
  55. package/dist/src/team/runtime.js.map +1 -1
  56. package/dist/src/team/tmux.d.ts +13 -0
  57. package/dist/src/team/tmux.js +47 -0
  58. package/dist/src/team/tmux.js.map +1 -1
  59. package/docs/slack-setup.md +144 -0
  60. package/package.json +4 -2
package/dist/src/cli.js CHANGED
@@ -2,6 +2,8 @@
2
2
  import { realpathSync } from "node:fs";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { findCapability, loadCatalogBundle, validateCatalogBundle } from "./catalog.js";
5
+ import { findRegisteredCommand, registeredCommandHelpLines } from "./commands/registry.js";
6
+ import { loadOmpEnv } from "./env/dotenv.js";
5
7
  import { inspectProject } from "./project.js";
6
8
  function hasFlag(args, flag) {
7
9
  return args.includes(flag);
@@ -22,7 +24,7 @@ function printResult(result, json) {
22
24
  }
23
25
  }
24
26
  function help() {
25
- return `oh-my-copilot\n\nRun \`omp\` with no arguments to launch copilot (permissions bypass OFF).\nUse \`omp help\` to show this list.\n\nCommands:\n (no args) launch copilot (bypass OFF by default)\n version [--json]\n list [--json]\n setup [--dry-run] [--scope project|user] [--plugin-root <dir>] [--json]\n doctor [--json] [--copilot-bin <path>] [--skip-copilot]\n launch -- <args...>\n --madmax [args...] (bare-flag launch with permissions bypass; alias of --yolo)\n team <N:role> "<task>" [--name <name>] [--json]\n team status <name> [--json]\n team shutdown <name> [--json]\n team api claim-task --input '<json>' [--json]\n team api transition-task-status --input '<json>' [--json]\n team api send-message --input '<json>' [--json]\n team api broadcast --input '<json>' [--json]\n team api mailbox-list --input '<json>' [--json]\n team api mailbox-mark-delivered --input '<json>' [--json]\n council "<question>" [--models a,b,c|m:role:weight] [--context <text|@file>] [--rubric <text|@file>] [--synth <model>] [--probe] [--timeout <ms>] [--synth-timeout <ms>] [--min-survivors <n>] [--max-concurrency <n>] [--tmp-dir <dir>] [--json]\n ralph start "<task>" [--max-iterations <n>] [--session-id <id>] [--json]\n ralph status [--json]\n ralph tick [--json]\n ralph cancel [--json]\n ultrawork start "<objective>" [--task-count <n>] [--summary <s>] [--json]\n ultrawork status [--json]\n ultrawork cancel [--json]\n ultraqa start "<goal>" [--max-cycles <n>] [--json]\n ultraqa cycle pass|fail|pending [--json]\n ultraqa status [--json]\n ultraqa cancel [--json]\n schedule add --id <id> --cron \"<expr>\" --prompt \"<text>\" [--bin copilot] [--model <m>] [--cwd <dir>] [--timeout <ms>] [--max-runs <n>] [--ttl-hours <h>] [--allow-all-tools] [--dry-run] [--json]\n schedule list [--json]\n schedule status <id> [--json]\n schedule run-now <id> [--json]\n schedule remove <id> [--json]\n goal set "<objective>" [--json]\n goal read [--json]\n memory sync [--json] (render goal+directives into copilot-instructions.md)\n daily-log set-goal "<text>" [--json]\n daily-log add "<text>" [--json]\n daily-log read [--days <n>] [--json]\n daily-log prune [--keep-days <n>] [--json]\n state write <key> <val> [--ttl <s>] | read|delete|status <key> | list | cleanup [--json]\n project-memory read [<id>] | index | add-note "<title>" [--body "<text>"] | add-directive "<rule>" [--json]\n trace timeline [<sessionId>] [--limit <n>] | summary [<sessionId>] | add <sessionId> <event> [<json>] [--json]\n catalog list [--json]\n catalog validate [--json]\n catalog capability <id> [--json]\n project inspect [--json]\n skill install <skill-dir> [--root <repo>] [--scope project|user] [--dry-run] [--json]\n lint:skills [--root <repo>]\n sync:dry-run [--root <repo>]\n jira:dry-run [--root <repo>]\n jira render <plan-file> [--root <repo>] [--json]\n jira apply <ticket-key-or-plan-file> --comment|--update|--transition|--link [--dry-run] [--json]\n`;
27
+ return `oh-my-copilot\n\nRun \`omp\` with no arguments to launch copilot (permissions bypass OFF).\nUse \`omp help\` to show this list.\n\nCommands:\n (no args) launch copilot (bypass OFF by default)\n version [--json]\n list [--json]\n setup [--dry-run] [--scope project|user] [--plugin-root <dir>] [--json]\n doctor [--json] [--copilot-bin <path>] [--skip-copilot]\n launch -- <args...>\n --madmax [args...] (bare-flag launch with permissions bypass; alias of --yolo)\n team <N:role> "<task>" [--name <name>] [--json]\n team status <name> [--json]\n team shutdown <name> [--json]\n team api claim-task --input '<json>' [--json]\n team api transition-task-status --input '<json>' [--json]\n team api send-message --input '<json>' [--json]\n team api broadcast --input '<json>' [--json]\n team api mailbox-list --input '<json>' [--json]\n team api mailbox-mark-delivered --input '<json>' [--json]\n council "<question>" [--models a,b,c|m:role:weight] [--context <text|@file>] [--rubric <text|@file>] [--synth <model>] [--probe] [--timeout <ms>] [--synth-timeout <ms>] [--min-survivors <n>] [--max-concurrency <n>] [--tmp-dir <dir>] [--json]\n comms status [--session <name>] [--json] (is copilot on + online? auto-discovers session)\n comms send --text "<prompt>" [--force] [--session <name>] [--json]\n comms recv [--wait] [--lines <n>] [--timeout <ms>] [--session <name>] [--json]\n comms ask --text "<prompt>" [--force] [--lines <n>] [--timeout <ms>] [--session <name>] [--json]\n gateway serve [--only <name>[,<name>]] (run all configured connectors; today: slack)\n gateway status [--json] [--only <name>[,...]] (per-connector readiness; no sockets opened)\n gateway doctor [--json] [--only <name>[,...]] (alias for 'gateway status')\n slack serve (deprecated alias for 'gateway serve --only slack')\n slack doctor [--json] (deprecated alias for 'gateway status --only slack')\n env init [--force] (interactive: write ~/.omp/.env with Slack tokens)\n non-interactive: set OMP_INIT_BOT_TOKEN/OMP_INIT_APP_TOKEN\n (env vars preferred over --bot-token/--app-token flags)\n (--session is optional when exactly one omp-<digits> tmux session is running)\n${registeredCommandHelpLines().join("\n")}\n ralph start "<task>" [--max-iterations <n>] [--session-id <id>] [--json]\n ralph status [--json]\n ralph tick [--json]\n ralph cancel [--json]\n ultrawork start "<objective>" [--task-count <n>] [--summary <s>] [--json]\n ultrawork status [--json]\n ultrawork cancel [--json]\n ultraqa start "<goal>" [--max-cycles <n>] [--json]\n ultraqa cycle pass|fail|pending [--json]\n ultraqa status [--json]\n ultraqa cancel [--json]\n schedule add --id <id> --cron "<expr>" --prompt "<text>" [--bin copilot] [--model <m>] [--cwd <dir>] [--timeout <ms>] [--max-runs <n>] [--ttl-hours <h>] [--allow-all-tools] [--dry-run] [--json]\n schedule list [--json]\n schedule status <id> [--json]\n schedule run-now <id> [--json]\n schedule remove <id> [--json]\n goal set "<objective>" [--json]\n goal read [--json]\n memory sync [--json] (render goal+directives into copilot-instructions.md)\n daily-log set-goal "<text>" [--json]\n daily-log add "<text>" [--json]\n daily-log read [--days <n>] [--json]\n daily-log prune [--keep-days <n>] [--json]\n state write <key> <val> [--ttl <s>] | read|delete|status <key> | list | cleanup [--json]\n project-memory read [<id>] | index | add-note "<title>" [--body "<text>"] | add-directive "<rule>" [--json]\n trace timeline [<sessionId>] [--limit <n>] | summary [<sessionId>] | add <sessionId> <event> [<json>] [--json]\n catalog list [--json]\n catalog validate [--json]\n catalog capability <id> [--json]\n project inspect [--json]\n skill install <skill-dir> [--root <repo>] [--scope project|user] [--dry-run] [--json]\n lint:skills [--root <repo>]\n sync:dry-run [--root <repo>]\n jira:dry-run [--root <repo>]\n jira render <plan-file> [--root <repo>] [--json]\n jira apply <ticket-key-or-plan-file> --comment|--update|--transition|--link [--dry-run] [--json]\n`;
26
28
  }
27
29
  async function resolveExistingInputPath(value) {
28
30
  const { existsSync } = await import("node:fs");
@@ -47,6 +49,10 @@ export async function runCli(argv = process.argv.slice(2)) {
47
49
  const info = getVersionInfo({ importMetaUrl: import.meta.url });
48
50
  return json ? { ok: true, output: info } : { ok: true, message: formatVersionInfo(info) };
49
51
  }
52
+ // Auto-load ~/.omp/.env so subcommands that read process.env (slack tokens,
53
+ // OMP_*, COPILOT_TMUX_SESSION, etc.) work from any cwd without `source .env`.
54
+ // Shell exports take precedence — see src/env/dotenv.ts.
55
+ loadOmpEnv();
50
56
  // Bare `omp` (no subcommand) launches copilot directly with permissions
51
57
  // bypass OFF; `omp --madmax`/`--yolo` launch with bypass ON. For the bare
52
58
  // case argv is empty, so normalizeCopilotLaunchArgs emits no --yolo.
@@ -114,9 +120,25 @@ export async function runCli(argv = process.argv.slice(2)) {
114
120
  if (group === "team") {
115
121
  return await handleTeamCommand(argv, json);
116
122
  }
123
+ const registeredCommand = findRegisteredCommand(group);
124
+ if (registeredCommand) {
125
+ return await registeredCommand.run(argv, { cwd: flagValue(argv, "--root") ?? process.cwd(), json });
126
+ }
117
127
  if (group === "council") {
118
128
  return await handleCouncilCommand(argv, json);
119
129
  }
130
+ if (group === "comms") {
131
+ return await handleCommsCommand(argv, json);
132
+ }
133
+ if (group === "slack") {
134
+ return await handleSlackCommand(argv, json);
135
+ }
136
+ if (group === "gateway") {
137
+ return await handleGatewayCommand(argv, json);
138
+ }
139
+ if (group === "env") {
140
+ return await handleEnvCommand(argv, json);
141
+ }
120
142
  if (group === "ralph") {
121
143
  return await handleModeCommand("ralph", argv, json);
122
144
  }
@@ -570,6 +592,298 @@ async function handleCouncilCommand(argv, json) {
570
592
  lines.push(`Artifacts: ${result.tmpDir}`);
571
593
  return { ok: result.ok, exitCode: result.ok ? 0 : 1, message: lines.join("\n") };
572
594
  }
595
+ async function handleCommsCommand(argv, json) {
596
+ const [, command] = argv;
597
+ const { resolveSession } = await import("./comms/resolve-session.js");
598
+ // `--session` present but with a missing/empty/flag-like value must fail loud,
599
+ // never silently fall through to env/discovery and target an unintended session.
600
+ const flagSession = flagValue(argv, "--session");
601
+ if (hasFlag(argv, "--session") &&
602
+ (flagSession === undefined || flagSession === "" || flagSession.startsWith("-"))) {
603
+ return { ok: false, exitCode: 1, message: "invalid or missing --session value" };
604
+ }
605
+ const resolved = resolveSession({
606
+ flag: flagSession,
607
+ env: process.env.COPILOT_TMUX_SESSION,
608
+ });
609
+ if (!resolved.ok) {
610
+ return json
611
+ ? {
612
+ ok: false,
613
+ exitCode: 1,
614
+ output: { ok: false, error: resolved.error, candidates: resolved.candidates },
615
+ }
616
+ : { ok: false, exitCode: 1, message: resolved.error };
617
+ }
618
+ const session = resolved.session;
619
+ const sessionSource = resolved.source;
620
+ // Guard against a --session value that looks like a flag (e.g. --session --foo).
621
+ if (sessionSource === "flag" && session.startsWith("-")) {
622
+ return { ok: false, exitCode: 1, message: `invalid --session name: ${session}` };
623
+ }
624
+ const { commsStatus, commsSend, commsRecv, commsAsk } = await import("./comms/index.js");
625
+ if (command === "status") {
626
+ const r = await commsStatus(session);
627
+ return json
628
+ ? { ok: r.ok, output: { ...r, source: sessionSource } }
629
+ : {
630
+ ok: r.ok,
631
+ message: `session=${session} source=${sessionSource} on=${r.exists} online=${r.online} ready=${r.ready} busy=${r.busy}`,
632
+ };
633
+ }
634
+ if (command === "send") {
635
+ const text = flagValue(argv, "--text");
636
+ if (!text) {
637
+ return { ok: false, exitCode: 1, message: 'comms send requires --text "<prompt>"' };
638
+ }
639
+ const r = await commsSend(session, text, {}, { force: hasFlag(argv, "--force") });
640
+ return json
641
+ ? { ok: r.ok, exitCode: r.ok ? 0 : 1, output: r }
642
+ : {
643
+ ok: r.ok,
644
+ exitCode: r.ok ? 0 : 1,
645
+ message: r.ok ? `sent to ${session}` : `send failed: ${r.error}`,
646
+ };
647
+ }
648
+ if (command === "recv") {
649
+ let lines;
650
+ let timeoutMs;
651
+ try {
652
+ lines = parsePositiveIntFlag(flagValue(argv, "--lines"), "--lines");
653
+ timeoutMs = parsePositiveIntFlag(flagValue(argv, "--timeout"), "--timeout");
654
+ }
655
+ catch (err) {
656
+ return { ok: false, exitCode: 1, message: String(err instanceof Error ? err.message : err) };
657
+ }
658
+ const r = await commsRecv(session, {}, { wait: hasFlag(argv, "--wait"), lines, timeoutMs });
659
+ if (json) {
660
+ return { ok: r.ok && !r.timedOut, exitCode: r.ok && !r.timedOut ? 0 : 1, output: r };
661
+ }
662
+ if (!r.ok) {
663
+ return { ok: false, exitCode: 1, message: `recv failed: ${r.error}` };
664
+ }
665
+ if (r.timedOut) {
666
+ return { ok: false, exitCode: 1, message: `recv timed out waiting for copilot\n${r.text ?? ""}` };
667
+ }
668
+ return { ok: true, exitCode: 0, message: r.text ?? "" };
669
+ }
670
+ if (command === "ask") {
671
+ const text = flagValue(argv, "--text");
672
+ if (!text) {
673
+ return { ok: false, exitCode: 1, message: 'comms ask requires --text "<prompt>"' };
674
+ }
675
+ let lines;
676
+ let timeoutMs;
677
+ try {
678
+ lines = parsePositiveIntFlag(flagValue(argv, "--lines"), "--lines");
679
+ timeoutMs = parsePositiveIntFlag(flagValue(argv, "--timeout"), "--timeout");
680
+ }
681
+ catch (err) {
682
+ return { ok: false, exitCode: 1, message: String(err instanceof Error ? err.message : err) };
683
+ }
684
+ const r = await commsAsk(session, text, {}, { force: hasFlag(argv, "--force"), lines, timeoutMs });
685
+ if (json) {
686
+ return { ok: r.ok && !r.timedOut, exitCode: r.ok && !r.timedOut ? 0 : 1, output: r };
687
+ }
688
+ if (!r.ok) {
689
+ return { ok: false, exitCode: 1, message: `ask failed: ${r.error}` };
690
+ }
691
+ if (r.timedOut) {
692
+ return { ok: false, exitCode: 1, message: `ask timed out waiting for copilot\n${r.text ?? ""}` };
693
+ }
694
+ return { ok: true, exitCode: 0, message: r.text ?? "" };
695
+ }
696
+ return {
697
+ ok: false,
698
+ exitCode: 1,
699
+ message: 'Unknown comms subcommand. Try: comms status | send --text "<prompt>" | recv [--wait] | ask --text "<prompt>"',
700
+ };
701
+ }
702
+ async function handleEnvCommand(argv, json) {
703
+ const [, command] = argv;
704
+ if (command !== "init") {
705
+ return {
706
+ ok: false,
707
+ exitCode: 1,
708
+ message: "Unknown env subcommand. Try: env init [--force] [--bot-token x] [--app-token x]",
709
+ };
710
+ }
711
+ const { runEnvInit } = await import("./env/init.js");
712
+ const readline = await import("node:readline/promises");
713
+ // Preferred non-interactive path: env vars. Putting secrets in argv leaks
714
+ // them to shell history, ps output, and CI logs — so we read the safe
715
+ // input from env vars first, then fall back to flags (with a warning).
716
+ const botEnv = process.env.OMP_INIT_BOT_TOKEN;
717
+ const appEnv = process.env.OMP_INIT_APP_TOKEN;
718
+ const sessionEnv = process.env.OMP_INIT_SESSION;
719
+ const usersEnv = process.env.OMP_INIT_USERS;
720
+ const botFlag = flagValue(argv, "--bot-token");
721
+ const appFlag = flagValue(argv, "--app-token");
722
+ const sessionFlag = flagValue(argv, "--session");
723
+ const usersFlag = flagValue(argv, "--users");
724
+ if ((botFlag !== undefined || appFlag !== undefined) && process.env.OMP_INIT_NO_WARN !== "1") {
725
+ console.error("warning: --bot-token/--app-token leak via shell history and `ps`. " +
726
+ "Prefer OMP_INIT_BOT_TOKEN / OMP_INIT_APP_TOKEN env vars (set OMP_INIT_NO_WARN=1 to silence).");
727
+ }
728
+ const botToken = botEnv ?? botFlag;
729
+ const appToken = appEnv ?? appFlag;
730
+ const session = sessionEnv ?? sessionFlag;
731
+ const users = usersEnv ?? usersFlag;
732
+ // Non-interactive when stdin isn't a TTY OR when any answer is already
733
+ // supplied (via env or flag). Partial answers are allowed; missing required
734
+ // ones will be rejected by runEnvInit's validator.
735
+ const anyAnswer = botToken !== undefined || appToken !== undefined || session !== undefined || users !== undefined;
736
+ const force = hasFlag(argv, "--force");
737
+ let result;
738
+ if (anyAnswer || !process.stdin.isTTY) {
739
+ result = await runEnvInit({
740
+ io: {
741
+ // In non-interactive / --json mode we still must not corrupt stdout
742
+ // with diagnostic prints. Route everything but the JSON result to
743
+ // stderr so callers can pipe stdout safely.
744
+ print: (line) => (json ? console.error(line) : console.log(line)),
745
+ warn: (line) => console.error(line),
746
+ ask: async () => undefined,
747
+ },
748
+ force,
749
+ answers: {
750
+ slackBotToken: botToken ?? "",
751
+ slackAppToken: appToken ?? "",
752
+ copilotTmuxSession: session ?? "",
753
+ slackAllowedUsers: users ?? "",
754
+ },
755
+ });
756
+ }
757
+ else {
758
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
759
+ try {
760
+ result = await runEnvInit({
761
+ io: {
762
+ print: (line) => console.log(line),
763
+ warn: (line) => console.error(line),
764
+ ask: (prompt) => rl.question(prompt),
765
+ },
766
+ force,
767
+ });
768
+ }
769
+ finally {
770
+ rl.close();
771
+ }
772
+ }
773
+ if (json) {
774
+ return {
775
+ ok: result.ok,
776
+ exitCode: result.ok ? 0 : 1,
777
+ output: { ok: result.ok, path: result.path, reason: result.reason },
778
+ };
779
+ }
780
+ return {
781
+ ok: result.ok,
782
+ exitCode: result.ok ? 0 : 1,
783
+ message: result.ok ? `wrote ${result.path}` : (result.reason ?? "env init failed"),
784
+ };
785
+ }
786
+ async function handleSlackCommand(argv, json) {
787
+ // Backwards-compatible alias: `omp slack <cmd>` forwards to the generalized
788
+ // gateway runtime (scoped to slack). `slack doctor --json` keeps its legacy
789
+ // flat output shape so existing scripts that parsed it don't break — see
790
+ // `src/cli.ts` pre-refactor at 5c08a88.
791
+ const [, command, ...rest] = argv;
792
+ if (command === "serve") {
793
+ return await handleGatewayCommand(["gateway", "serve", "--only", "slack", ...rest], json);
794
+ }
795
+ if (command === "doctor" || command === "status") {
796
+ const hasBot = !!process.env.SLACK_BOT_TOKEN;
797
+ const hasApp = !!process.env.SLACK_APP_TOKEN;
798
+ const { resolveSession } = await import("./comms/resolve-session.js");
799
+ const resolved = resolveSession({ env: process.env.COPILOT_TMUX_SESSION });
800
+ const startable = hasBot && hasApp;
801
+ const ready = startable && resolved.ok;
802
+ const output = {
803
+ botToken: hasBot,
804
+ appToken: hasApp,
805
+ copilotSession: resolved.ok ? resolved.session : null,
806
+ copilotError: resolved.ok ? undefined : resolved.error,
807
+ ready,
808
+ };
809
+ return json
810
+ ? { ok: startable, exitCode: startable ? 0 : 1, output }
811
+ : {
812
+ ok: startable,
813
+ exitCode: startable ? 0 : 1,
814
+ message: `bot_token=${hasBot} app_token=${hasApp} copilot_session=${output.copilotSession ?? `(none: ${output.copilotError ?? "unknown"})`} ready=${ready}`,
815
+ };
816
+ }
817
+ return {
818
+ ok: false,
819
+ exitCode: 1,
820
+ message: "Unknown slack subcommand. Try: slack serve | slack doctor",
821
+ };
822
+ }
823
+ async function handleGatewayCommand(argv, json) {
824
+ const [, command] = argv;
825
+ const { buildConnectors, KNOWN_CONNECTORS } = await import("./gateway/registry.js");
826
+ const { runGateway, getGatewayStatus, parseOnlyFlag } = await import("./gateway/runtime.js");
827
+ const only = parseOnlyFlag(flagValue(argv, "--only"));
828
+ if (only) {
829
+ const unknown = only.filter((n) => !KNOWN_CONNECTORS.includes(n));
830
+ if (unknown.length > 0) {
831
+ return {
832
+ ok: false,
833
+ exitCode: 1,
834
+ message: `unknown connector(s): ${unknown.join(", ")} — known: ${KNOWN_CONNECTORS.join(", ")}`,
835
+ };
836
+ }
837
+ }
838
+ if (command === "serve") {
839
+ const built = buildConnectors(only);
840
+ if (built.connectors.length === 0) {
841
+ const reason = built.warnings.length > 0
842
+ ? built.warnings.join("; ")
843
+ : "no connectors configured — set SLACK_BOT_TOKEN+SLACK_APP_TOKEN or pass --only <name>";
844
+ return { ok: false, exitCode: 1, message: reason };
845
+ }
846
+ try {
847
+ await runGateway({ connectors: built.connectors });
848
+ }
849
+ catch (err) {
850
+ return {
851
+ ok: false,
852
+ exitCode: 1,
853
+ message: `gateway failed: ${err instanceof Error ? err.message : String(err)}`,
854
+ };
855
+ }
856
+ return { ok: true, message: "gateway stopped" };
857
+ }
858
+ if (command === "status" || command === "doctor") {
859
+ const built = buildConnectors(only);
860
+ const rows = built.doctors.map((d) => {
861
+ const s = d.doctor();
862
+ return { name: d.name, ready: s.ready, detail: s.detail };
863
+ });
864
+ const ready = rows.length > 0 && rows.every((r) => r.ready);
865
+ if (json) {
866
+ return {
867
+ ok: ready,
868
+ exitCode: ready ? 0 : 1,
869
+ output: { ready, connectors: rows, warnings: built.warnings },
870
+ };
871
+ }
872
+ const lines = [
873
+ `ready=${ready}`,
874
+ ...rows.map((r) => ` ${r.name}: ready=${r.ready}${r.detail ? ` (${r.detail})` : ""}`),
875
+ ...built.warnings.map((w) => ` warning: ${w}`),
876
+ ];
877
+ return { ok: ready, exitCode: ready ? 0 : 1, message: lines.join("\n") };
878
+ }
879
+ // Silence the unused warning emitted when no command path is hit.
880
+ void getGatewayStatus;
881
+ return {
882
+ ok: false,
883
+ exitCode: 1,
884
+ message: "Unknown gateway subcommand. Try: gateway serve | status | doctor",
885
+ };
886
+ }
573
887
  const TEAM_SPEC_RE = /^(\d+):([\w-]+)$/;
574
888
  async function handleTeamCommand(argv, json) {
575
889
  const [, command, value, extra] = argv;
@@ -616,6 +930,46 @@ async function handleTeamCommand(argv, json) {
616
930
  message: `shutdown team ${value} killedPanes=${result.killedPanes} killedSession=${result.killedSession}`,
617
931
  };
618
932
  }
933
+ if (command === "monitor-panes") {
934
+ const leaderPaneId = flagValue(argv, "--leader-pane");
935
+ const workerPaneIds = argv
936
+ .flatMap((arg, index) => (arg === "--worker-pane" ? [argv[index + 1]] : []))
937
+ .filter((value) => Boolean(value));
938
+ if (!leaderPaneId || workerPaneIds.length === 0) {
939
+ return { ok: false, exitCode: 1, message: "team monitor-panes requires --leader-pane and at least one --worker-pane" };
940
+ }
941
+ let pollIntervalMs;
942
+ let readySamples;
943
+ let minObservationMs;
944
+ let timeoutMs;
945
+ let captureLines;
946
+ try {
947
+ pollIntervalMs = parsePositiveIntFlag(flagValue(argv, "--poll-interval-ms"), "--poll-interval-ms");
948
+ readySamples = parsePositiveIntFlag(flagValue(argv, "--ready-samples"), "--ready-samples");
949
+ minObservationMs = parsePositiveIntFlag(flagValue(argv, "--min-observation-ms"), "--min-observation-ms");
950
+ timeoutMs = parsePositiveIntFlag(flagValue(argv, "--timeout-ms"), "--timeout-ms");
951
+ captureLines = parsePositiveIntFlag(flagValue(argv, "--capture-lines"), "--capture-lines");
952
+ }
953
+ catch (err) {
954
+ return { ok: false, exitCode: 1, message: String(err instanceof Error ? err.message : err) };
955
+ }
956
+ const { monitorPanes } = await import("./team/pane-monitor.js");
957
+ const result = await monitorPanes({
958
+ leaderPaneId,
959
+ workerPaneIds,
960
+ sessionLabel: flagValue(argv, "--session-label"),
961
+ config: {
962
+ pollIntervalMs,
963
+ readySamples,
964
+ minObservationMs,
965
+ timeoutMs,
966
+ captureLines,
967
+ },
968
+ });
969
+ return json
970
+ ? { ok: result.ok, exitCode: result.ok ? 0 : 1, output: result }
971
+ : { ok: result.ok, exitCode: result.ok ? 0 : 1, message: `team monitor-panes ${result.reason} events=${result.events.length}` };
972
+ }
619
973
  if (command === "api") {
620
974
  const sub = value;
621
975
  const inputRaw = flagValue(argv, "--input");