@damian87/omp 0.7.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.
- package/README.md +29 -0
- package/dist/src/cli.js +310 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/env/dotenv.d.ts +41 -0
- package/dist/src/env/dotenv.js +112 -0
- package/dist/src/env/dotenv.js.map +1 -0
- package/dist/src/env/init.d.ts +50 -0
- package/dist/src/env/init.js +276 -0
- package/dist/src/env/init.js.map +1 -0
- package/dist/src/gateway/connector.d.ts +37 -0
- package/dist/src/gateway/connector.js +12 -0
- package/dist/src/gateway/connector.js.map +1 -0
- package/dist/src/gateway/connectors/slack.d.ts +69 -0
- package/dist/src/gateway/connectors/slack.js +159 -0
- package/dist/src/gateway/connectors/slack.js.map +1 -0
- package/dist/src/gateway/registry.d.ts +29 -0
- package/dist/src/gateway/registry.js +37 -0
- package/dist/src/gateway/registry.js.map +1 -0
- package/dist/src/gateway/runtime.d.ts +58 -0
- package/dist/src/gateway/runtime.js +105 -0
- package/dist/src/gateway/runtime.js.map +1 -0
- package/dist/src/jira.js +2 -14
- package/dist/src/jira.js.map +1 -1
- package/dist/src/slack/config.d.ts +32 -0
- package/dist/src/slack/config.js +52 -0
- package/dist/src/slack/config.js.map +1 -0
- package/dist/src/slack/handler.d.ts +48 -0
- package/dist/src/slack/handler.js +68 -0
- package/dist/src/slack/handler.js.map +1 -0
- package/dist/src/slack/serve.d.ts +8 -0
- package/dist/src/slack/serve.js +7 -0
- package/dist/src/slack/serve.js.map +1 -0
- package/dist/src/team/tmux.d.ts +1 -0
- package/dist/src/team/tmux.js +9 -0
- package/dist/src/team/tmux.js.map +1 -1
- package/docs/slack-setup.md +144 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -192,6 +192,12 @@ omp ralph start "<task>" [--max-iterations N]
|
|
|
192
192
|
omp ultrawork start "<objective>" [--task-count N]
|
|
193
193
|
omp ultraqa start "<goal>" [--max-cycles N]
|
|
194
194
|
omp council "<question>" [--models a,b,c] [--context @file] [--json] # multi-model council
|
|
195
|
+
omp comms status | send | recv | ask # drive a running copilot tmux session
|
|
196
|
+
omp gateway serve [--only slack] # run chat connectors (today: slack)
|
|
197
|
+
omp gateway status [--json] # per-connector readiness (no sockets)
|
|
198
|
+
omp slack serve # deprecated alias of `gateway serve --only slack`
|
|
199
|
+
omp slack doctor [--json] # deprecated alias of `gateway status --only slack`
|
|
200
|
+
omp env init [--force] # write ~/.omp/.env (interactive Slack token setup)
|
|
195
201
|
omp schedule add --id <id> --cron "*/15 * * * *" --prompt "<text>" [--allow-all-tools] [--cwd <dir>] [--model <m>] [--timeout <ms>] [--max-runs N] [--ttl-hours H] [--dry-run]
|
|
196
202
|
omp schedule list # registered jobs + OS-install status
|
|
197
203
|
omp schedule status <id> # last run + result summary
|
|
@@ -219,6 +225,29 @@ run results are surfaced automatically at the start of new Copilot sessions. Alw
|
|
|
219
225
|
`omp schedule remove`, never delete `.omp/state/schedule/` by hand, so the OS entry is
|
|
220
226
|
uninstalled cleanly.
|
|
221
227
|
|
|
228
|
+
### Chat bridge: drive Copilot from Slack
|
|
229
|
+
|
|
230
|
+
`omp gateway` runs long-lived chat connectors that forward messages into a running
|
|
231
|
+
Copilot CLI session (via tmux) and post replies back. Today's connector is `slack`
|
|
232
|
+
(WebSocket Socket Mode — no public URL needed); the runtime is generic so future
|
|
233
|
+
connectors (Telegram, Discord, webhooks) drop in as one file each.
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# 1. a Copilot tmux session is running (any `omp-<digits>` name)
|
|
237
|
+
tmux new-session -d -s omp-9999
|
|
238
|
+
|
|
239
|
+
# 2. interactive setup — explains where to grab each token and writes
|
|
240
|
+
# ~/.omp/.env (chmod 600). Re-runnable; masks existing values.
|
|
241
|
+
# `omp` auto-loads ~/.omp/.env every invocation; shell exports still win.
|
|
242
|
+
omp env init
|
|
243
|
+
|
|
244
|
+
# 3. preflight, then run
|
|
245
|
+
omp gateway status # ready=true means tokens + session look good
|
|
246
|
+
omp gateway serve # blocks; ^C stops cleanly
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Full Slack-app setup (manifest + scopes) lives in [`docs/slack-setup.md`](docs/slack-setup.md).
|
|
250
|
+
|
|
222
251
|
---
|
|
223
252
|
|
|
224
253
|
## Roadmap
|
package/dist/src/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { realpathSync } from "node:fs";
|
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { findCapability, loadCatalogBundle, validateCatalogBundle } from "./catalog.js";
|
|
5
5
|
import { findRegisteredCommand, registeredCommandHelpLines } from "./commands/registry.js";
|
|
6
|
+
import { loadOmpEnv } from "./env/dotenv.js";
|
|
6
7
|
import { inspectProject } from "./project.js";
|
|
7
8
|
function hasFlag(args, flag) {
|
|
8
9
|
return args.includes(flag);
|
|
@@ -23,7 +24,7 @@ function printResult(result, json) {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
function help() {
|
|
26
|
-
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${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`;
|
|
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`;
|
|
27
28
|
}
|
|
28
29
|
async function resolveExistingInputPath(value) {
|
|
29
30
|
const { existsSync } = await import("node:fs");
|
|
@@ -48,6 +49,10 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
48
49
|
const info = getVersionInfo({ importMetaUrl: import.meta.url });
|
|
49
50
|
return json ? { ok: true, output: info } : { ok: true, message: formatVersionInfo(info) };
|
|
50
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();
|
|
51
56
|
// Bare `omp` (no subcommand) launches copilot directly with permissions
|
|
52
57
|
// bypass OFF; `omp --madmax`/`--yolo` launch with bypass ON. For the bare
|
|
53
58
|
// case argv is empty, so normalizeCopilotLaunchArgs emits no --yolo.
|
|
@@ -122,6 +127,18 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
122
127
|
if (group === "council") {
|
|
123
128
|
return await handleCouncilCommand(argv, json);
|
|
124
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
|
+
}
|
|
125
142
|
if (group === "ralph") {
|
|
126
143
|
return await handleModeCommand("ralph", argv, json);
|
|
127
144
|
}
|
|
@@ -575,6 +592,298 @@ async function handleCouncilCommand(argv, json) {
|
|
|
575
592
|
lines.push(`Artifacts: ${result.tmpDir}`);
|
|
576
593
|
return { ok: result.ok, exitCode: result.ok ? 0 : 1, message: lines.join("\n") };
|
|
577
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
|
+
}
|
|
578
887
|
const TEAM_SPEC_RE = /^(\d+):([\w-]+)$/;
|
|
579
888
|
async function handleTeamCommand(argv, json) {
|
|
580
889
|
const [, command, value, extra] = argv;
|