File size: 1,801 Bytes
a861001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node

import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
// Importing the rsih entry sets PI_PACKAGE_DIR, RSIH_CODING_AGENT_DIR and the
// version-check opt-out in one place. `gee` must not duplicate that setup.
import { runCli } from "../cli.ts";
import { expandGenomeShorthand } from "../cli/genome-shorthand.ts";

const GENOME = "harness-rsi";

/**
 * `gee` is `rsih --genome harness-rsi`. It starts the same interactive session,
 * whose job is to author a Genome from the user's own session history.
 *
 * The historical `harness-rsi` subcommand is accepted and dropped, since it is
 * now the only thing `gee` does. An explicit `--genome` wins — including the
 * `:name` / `+name` shorthand, which is expanded first — so `gee` stays usable
 * as a plain rsih alias.
 */
export function geeArgs(argv) {
  const stripped = argv[0] === "harness-rsi" ? argv.slice(1) : [...argv];
  const args = expandGenomeShorthand(stripped);
  const spec = args.findIndex(
    (arg) => arg === "--spec" || arg.startsWith("--spec="),
  );
  if (spec !== -1) {
    throw new Error(
      "gee no longer takes --spec. Genome authoring is interactive now: run `gee` (or `rsih --genome harness-rsi`) and answer the questions.",
    );
  }
  const hasGenome = args.some(
    (arg) => arg === "--genome" || arg.startsWith("--genome="),
  );
  return hasGenome ? args : ["--genome", GENOME, ...args];
}

export async function runGeeCli(argv = process.argv.slice(2)) {
  return runCli(geeArgs(argv));
}

const isMain =
  process.argv[1] &&
  import.meta.url === pathToFileURL(resolve(process.argv[1])).href;

if (isMain) {
  runGeeCli().catch((error) => {
    console.error(`gee: ${error instanceof Error ? error.message : String(error)}`);
    process.exitCode = 1;
  });
}