@corenel/cli 0.2.1 → 0.3.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 (2) hide show
  1. package/dist/cli.js +98 -7
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -13261,7 +13261,7 @@ var require_filters = __commonJS({
13261
13261
  return r.copySafeness(str5, res);
13262
13262
  }
13263
13263
  _exports.indent = indent;
13264
- function join4(arr, del, attr) {
13264
+ function join5(arr, del, attr) {
13265
13265
  del = del || "";
13266
13266
  if (attr) {
13267
13267
  arr = lib.map(arr, function(v) {
@@ -13270,7 +13270,7 @@ var require_filters = __commonJS({
13270
13270
  }
13271
13271
  return arr.join(del);
13272
13272
  }
13273
- _exports.join = join4;
13273
+ _exports.join = join5;
13274
13274
  function last(arr) {
13275
13275
  return arr[arr.length - 1];
13276
13276
  }
@@ -15708,7 +15708,7 @@ function reconcileDanglingToolCalls(messages) {
15708
15708
  }
15709
15709
 
15710
15710
  // src/cli.ts
15711
- import { join as join3 } from "node:path";
15711
+ import { join as join4 } from "node:path";
15712
15712
 
15713
15713
  // ../harness/tools/registry.ts
15714
15714
  var registry = /* @__PURE__ */ new Map();
@@ -16436,14 +16436,14 @@ var spawnAgentsTool = {
16436
16436
  },
16437
16437
  async run(args, ctx) {
16438
16438
  if (!ctx.spawn) return "Sub-agents are not available here (depth limit reached or unsupported context).";
16439
- const spawn = ctx.spawn;
16439
+ const spawn2 = ctx.spawn;
16440
16440
  const raw = Array.isArray(args.tasks) ? args.tasks : [];
16441
16441
  const reqs = raw.map((t) => spawnReq(t && typeof t === "object" ? t : {})).filter((r) => r !== null);
16442
16442
  if (!reqs.length) return "Error: `tasks` must contain at least one task with a non-empty `task` string.";
16443
16443
  const results = await Promise.all(
16444
16444
  reqs.map(async (req, i) => {
16445
16445
  try {
16446
- const r = await spawn(req);
16446
+ const r = await spawn2(req);
16447
16447
  return `### Sub-agent ${i + 1}
16448
16448
  ${r.text}${spawnFooter(r)}`;
16449
16449
  } catch (e) {
@@ -20698,6 +20698,89 @@ ${extra}` : base;
20698
20698
  }
20699
20699
  }
20700
20700
 
20701
+ // src/sidecar.ts
20702
+ import { spawn } from "node:child_process";
20703
+ import { createRequire } from "node:module";
20704
+ import { existsSync, readFileSync } from "node:fs";
20705
+ import { dirname as dirname2, join as join3 } from "node:path";
20706
+ import { fileURLToPath } from "node:url";
20707
+ function sidecarArgs(rest) {
20708
+ return rest[0] === "start" ? rest.slice(1) : rest;
20709
+ }
20710
+ function findSidecarEntry(look = {}) {
20711
+ const exists = look.exists ?? existsSync;
20712
+ const req = look.resolve ?? createRequire(import.meta.url).resolve;
20713
+ try {
20714
+ const direct = req("@corenel/sidecar/dist/cli.js");
20715
+ if (exists(direct)) return direct;
20716
+ } catch {
20717
+ }
20718
+ let dir = look.fromDir ?? dirname2(fileURLToPath(import.meta.url));
20719
+ for (let up = 0; up < 8; up++) {
20720
+ const candidate = join3(dir, "node_modules", "@corenel", "sidecar", "dist", "cli.js");
20721
+ if (exists(candidate)) return candidate;
20722
+ const parent = dirname2(dir);
20723
+ if (parent === dir) break;
20724
+ dir = parent;
20725
+ }
20726
+ return null;
20727
+ }
20728
+ function versionAt(entry, read = readFileSyncUtf8) {
20729
+ try {
20730
+ const parsed = JSON.parse(read(join3(dirname2(dirname2(entry)), "package.json")));
20731
+ const v = parsed.version;
20732
+ return typeof v === "string" ? v : "?";
20733
+ } catch {
20734
+ return "?";
20735
+ }
20736
+ }
20737
+ function readFileSyncUtf8(p) {
20738
+ return readFileSync(p, "utf8");
20739
+ }
20740
+ var SIDECAR_MISSING = [
20741
+ "the sidecar is not installed.",
20742
+ "",
20743
+ " npm install -g @corenel/sidecar",
20744
+ " pnpm add -g @corenel/sidecar",
20745
+ "",
20746
+ "It ships separately because it is a server with its own release line.",
20747
+ "Once installed, `corenel sidecar \u2026` and `corenel-sidecar \u2026` are the same thing."
20748
+ ].join("\n");
20749
+ async function proxyToSidecar(rest, look = {}) {
20750
+ const entry = findSidecarEntry(look);
20751
+ if (!entry) {
20752
+ process.stderr.write(`corenel: ${SIDECAR_MISSING}
20753
+ `);
20754
+ return 127;
20755
+ }
20756
+ process.stderr.write(`corenel: sidecar ${versionAt(entry)} (${entry})
20757
+ `);
20758
+ const child = spawn(process.execPath, [entry, ...sidecarArgs(rest)], {
20759
+ stdio: "inherit",
20760
+ // So `corenel sidecar --help` prints `corenel sidecar …` in its usage rather
20761
+ // than the standalone name the user did not type.
20762
+ env: { ...process.env, CORENEL_ARGV0: "corenel sidecar" }
20763
+ });
20764
+ const forward = (sig) => () => {
20765
+ if (!child.killed) child.kill(sig);
20766
+ };
20767
+ const onInt = forward("SIGINT");
20768
+ const onTerm = forward("SIGTERM");
20769
+ process.on("SIGINT", onInt);
20770
+ process.on("SIGTERM", onTerm);
20771
+ try {
20772
+ return await new Promise((resolve2, reject) => {
20773
+ child.on("error", reject);
20774
+ child.on("exit", (code, signal) => {
20775
+ resolve2(code ?? (signal === "SIGINT" ? 130 : signal ? 143 : 1));
20776
+ });
20777
+ });
20778
+ } finally {
20779
+ process.off("SIGINT", onInt);
20780
+ process.off("SIGTERM", onTerm);
20781
+ }
20782
+ }
20783
+
20701
20784
  // src/cli.ts
20702
20785
  function flag(argv, name, fallback) {
20703
20786
  const i = argv.indexOf(`--${name}`);
@@ -20740,7 +20823,7 @@ async function run(argv) {
20740
20823
  registerGuard(tokenGuard(() => token));
20741
20824
  const client = createChatClient({ getToken: async () => token });
20742
20825
  const tools = allTools();
20743
- setPromptHost(nodePromptHost(new NodeFileService(join3(corenelDir(), "config"))));
20826
+ setPromptHost(nodePromptHost(new NodeFileService(join4(corenelDir(), "config"))));
20744
20827
  let system = "You are corenel, a concise CLI assistant.";
20745
20828
  try {
20746
20829
  system = await composeAgentSystem({ mode: "auto", tools: tools.map((t) => ({ name: t.name, description: t.description })) });
@@ -20784,6 +20867,10 @@ async function main() {
20784
20867
  process.exitCode = code;
20785
20868
  break;
20786
20869
  }
20870
+ case "sidecar": {
20871
+ process.exitCode = await proxyToSidecar(rest);
20872
+ break;
20873
+ }
20787
20874
  case "login": {
20788
20875
  const base = flag(rest, "base", process.env.CORENEL_API_BASE || "https://api.corenel.ai/api");
20789
20876
  await deviceLogin({ base, store: writeAuthToken });
@@ -20799,8 +20886,12 @@ Logged in. Token saved to ${authTokenPath()}
20799
20886
  " corenel login [--base URL] OAuth device flow -> ~/.corenel/token",
20800
20887
  ' corenel run "<prompt>" [--model M] [--base URL] one-shot turn (needs a login or CORENEL_TOKEN)',
20801
20888
  ' corenel run-agent <name> --input "<text>" run a crew agent; events as JSON Lines on stdout',
20889
+ " corenel sidecar [start] [flags] run the sidecar on this machine (needs @corenel/sidecar)",
20890
+ "",
20891
+ " `corenel sidecar --help` lists its flags. It is also installed standalone",
20892
+ " as `corenel-sidecar`, for machines that run only the sidecar.",
20802
20893
  "",
20803
- " (ask/chat + start --sidecar to follow.)",
20894
+ " (ask/chat to follow.)",
20804
20895
  ""
20805
20896
  ].join("\n"));
20806
20897
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corenel/cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Corenel CLI — runs the harness in node, in-proc, no transport. The headless proof the kernel is host-agnostic. (corenel run/ask/chat/login + start --sidecar to follow.)",
6
6
  "bin": {