@baryonlabs/cli 0.2.1 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baryonlabs/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Baryon CLI — AI 코딩·학습 에이전트. baryon.ai API에 기본 연결된 pi 코딩 에이전트 래퍼. 한 줄 설치, 상용·로컬 모델 전환.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/config.js CHANGED
@@ -11,6 +11,8 @@ import {
11
11
  PI_AGENT_DIR,
12
12
  PI_MODELS_JSON,
13
13
  PROVIDER,
14
+ SESSION_HEADER,
15
+ SESSION_ID_ENV,
14
16
  } from "./constants.js";
15
17
 
16
18
  function readJson(file, fallback) {
@@ -69,6 +71,9 @@ export function syncPiModels({ baseUrl, models }) {
69
71
  api: "openai-completions",
70
72
  apiKey: `$${API_KEY_ENV}`,
71
73
  authHeader: true,
74
+ // Per-launch session id (resolved by pi from the env at request time) so the
75
+ // gateway can group a run's turns into one session. Gateway requires it.
76
+ headers: { [SESSION_HEADER]: `$${SESSION_ID_ENV}` },
72
77
  models:
73
78
  Array.isArray(models) && models.length ? models : DEFAULT_MODELS,
74
79
  };
@@ -83,4 +88,19 @@ export function piProviderConfigured() {
83
88
  return Boolean(root?.providers?.[PROVIDER]);
84
89
  }
85
90
 
91
+ /**
92
+ * Auto-heal older installs: ensure the baryon provider sends the session
93
+ * header. Safe to call on every launch — only writes when something changed.
94
+ * Returns true if the provider exists (after any patch).
95
+ */
96
+ export function ensurePiSessionHeader() {
97
+ const root = readJson(PI_MODELS_JSON, {});
98
+ const p = root?.providers?.[PROVIDER];
99
+ if (!p) return false;
100
+ if (p.headers?.[SESSION_HEADER] === `$${SESSION_ID_ENV}`) return true;
101
+ p.headers = { ...(p.headers || {}), [SESSION_HEADER]: `$${SESSION_ID_ENV}` };
102
+ writeJson(PI_MODELS_JSON, root);
103
+ return true;
104
+ }
105
+
86
106
  export { PI_MODELS_JSON, BARYON_CONFIG };
package/src/constants.js CHANGED
@@ -11,6 +11,14 @@ export const DEFAULT_BASE_URL =
11
11
  /** Env var pi resolves at request time (apiKey: "$BARYON_API_KEY"). */
12
12
  export const API_KEY_ENV = "BARYON_API_KEY";
13
13
 
14
+ /**
15
+ * Session id env var. The baryon provider sends it as `X-Baryon-Session` so the
16
+ * gateway can group every turn of one `baryon` run into a single session. A
17
+ * fresh id is minted per launch (see pi.js). The gateway requires it.
18
+ */
19
+ export const SESSION_ID_ENV = "BARYON_SESSION_ID";
20
+ export const SESSION_HEADER = "X-Baryon-Session";
21
+
14
22
  /** Underlying coding agent package + binary. */
15
23
  export const PI_PACKAGE = "@earendil-works/pi-coding-agent";
16
24
  export const PI_BIN = "pi";
package/src/pi.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { spawn } from "node:child_process";
4
4
  import { createRequire } from "node:module";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { randomUUID } from "node:crypto";
6
7
  import fs from "node:fs";
7
8
  import path from "node:path";
8
9
  import {
@@ -10,7 +11,9 @@ import {
10
11
  PI_BIN,
11
12
  PI_PACKAGE,
12
13
  PROVIDER,
14
+ SESSION_ID_ENV,
13
15
  } from "./constants.js";
16
+ import { ensurePiSessionHeader } from "./config.js";
14
17
 
15
18
  const require = createRequire(import.meta.url);
16
19
 
@@ -98,6 +101,11 @@ export function runPi(args, config, { injectTargeting = true } = {}) {
98
101
  if (config.apiKey) env[API_KEY_ENV] = config.apiKey;
99
102
  if (config.baseUrl) env.BARYON_BASE_URL = config.baseUrl;
100
103
 
104
+ // One session per launch: mint an id (unless the caller pinned one) and make
105
+ // sure the provider forwards it. The gateway requires a session id.
106
+ if (!env[SESSION_ID_ENV]) env[SESSION_ID_ENV] = `cli_${randomUUID()}`;
107
+ ensurePiSessionHeader();
108
+
101
109
  return new Promise((resolve, reject) => {
102
110
  const child = spawn(process.execPath, [entry, ...finalArgs], {
103
111
  stdio: "inherit",