@h-rig/pi-rig 0.0.6-alpha.0 → 0.0.6-alpha.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.
@@ -6,6 +6,13 @@ import { dirname, resolve } from "path";
6
6
  function cleanString(value) {
7
7
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
8
8
  }
9
+ function cleanNonNegativeInteger(value) {
10
+ const text = cleanString(value);
11
+ if (!text)
12
+ return null;
13
+ const parsed = Number.parseInt(text, 10);
14
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
15
+ }
9
16
  function readJson(path) {
10
17
  if (!existsSync(path))
11
18
  return null;
@@ -38,7 +45,9 @@ function resolveGlobalConnectionsPath(env) {
38
45
  return resolve(homedir(), ".rig", "connections.json");
39
46
  }
40
47
  function discoverRigContext(env) {
41
- const cwd = cleanString(env.PWD) ?? process.cwd();
48
+ const cwd = cleanString(env.PWD);
49
+ if (!cwd)
50
+ return {};
42
51
  const projectRoot = findRigProjectRoot(cwd);
43
52
  if (!projectRoot)
44
53
  return {};
@@ -71,6 +80,7 @@ function createRigContextFromEnv(env = process.env) {
71
80
  const serverUrl = env.RIG_SERVER_URL ?? env.RIG_SERVER_BASE_URL ?? discovered.serverUrl;
72
81
  const projectRoot = env.RIG_PROJECT_ROOT ?? env.PROJECT_RIG_ROOT ?? discovered.projectRoot;
73
82
  const authToken = env.RIG_AUTH_TOKEN ?? env.RIG_GITHUB_TOKEN ?? env.GITHUB_TOKEN ?? env.GH_TOKEN ?? discovered.authToken;
83
+ const steeringPollMs = cleanNonNegativeInteger(env.RIG_STEERING_POLL_MS);
74
84
  const active = Boolean(runId || taskId || serverUrl || projectRoot);
75
85
  if (!active)
76
86
  return { active: false };
@@ -80,7 +90,8 @@ function createRigContextFromEnv(env = process.env) {
80
90
  ...taskId ? { taskId } : {},
81
91
  ...serverUrl ? { serverUrl } : {},
82
92
  ...projectRoot ? { projectRoot } : {},
83
- ...authToken ? { authToken } : {}
93
+ ...authToken ? { authToken } : {},
94
+ ...steeringPollMs !== null ? { steeringPollMs } : {}
84
95
  };
85
96
  }
86
97
  function joinUrl(baseUrl, pathname) {
package/dist/src/index.js CHANGED
@@ -6,6 +6,13 @@ import { dirname, resolve } from "path";
6
6
  function cleanString(value) {
7
7
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
8
8
  }
9
+ function cleanNonNegativeInteger(value) {
10
+ const text = cleanString(value);
11
+ if (!text)
12
+ return null;
13
+ const parsed = Number.parseInt(text, 10);
14
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
15
+ }
9
16
  function readJson(path) {
10
17
  if (!existsSync(path))
11
18
  return null;
@@ -38,7 +45,9 @@ function resolveGlobalConnectionsPath(env) {
38
45
  return resolve(homedir(), ".rig", "connections.json");
39
46
  }
40
47
  function discoverRigContext(env) {
41
- const cwd = cleanString(env.PWD) ?? process.cwd();
48
+ const cwd = cleanString(env.PWD);
49
+ if (!cwd)
50
+ return {};
42
51
  const projectRoot = findRigProjectRoot(cwd);
43
52
  if (!projectRoot)
44
53
  return {};
@@ -71,6 +80,7 @@ function createRigContextFromEnv(env = process.env) {
71
80
  const serverUrl = env.RIG_SERVER_URL ?? env.RIG_SERVER_BASE_URL ?? discovered.serverUrl;
72
81
  const projectRoot = env.RIG_PROJECT_ROOT ?? env.PROJECT_RIG_ROOT ?? discovered.projectRoot;
73
82
  const authToken = env.RIG_AUTH_TOKEN ?? env.RIG_GITHUB_TOKEN ?? env.GITHUB_TOKEN ?? env.GH_TOKEN ?? discovered.authToken;
83
+ const steeringPollMs = cleanNonNegativeInteger(env.RIG_STEERING_POLL_MS);
74
84
  const active = Boolean(runId || taskId || serverUrl || projectRoot);
75
85
  if (!active)
76
86
  return { active: false };
@@ -80,7 +90,8 @@ function createRigContextFromEnv(env = process.env) {
80
90
  ...taskId ? { taskId } : {},
81
91
  ...serverUrl ? { serverUrl } : {},
82
92
  ...projectRoot ? { projectRoot } : {},
83
- ...authToken ? { authToken } : {}
93
+ ...authToken ? { authToken } : {},
94
+ ...steeringPollMs !== null ? { steeringPollMs } : {}
84
95
  };
85
96
  }
86
97
  function joinUrl(baseUrl, pathname) {
@@ -333,6 +344,25 @@ async function consumeQueuedSteering(pi, state, ctx) {
333
344
  notify(ctx, `Rig steering sync failed: ${error instanceof Error ? error.message : String(error)}`, "error");
334
345
  }
335
346
  }
347
+ function startLiveSteeringPoll(pi, state, ctx) {
348
+ if (!state.active || !state.runId || typeof pi.sendUserMessage !== "function")
349
+ return;
350
+ const intervalMs = state.steeringPollMs ?? 1000;
351
+ if (intervalMs <= 0)
352
+ return;
353
+ let inFlight = false;
354
+ const timer = setInterval(() => {
355
+ if (inFlight)
356
+ return;
357
+ inFlight = true;
358
+ consumeQueuedSteering(pi, state, ctx).finally(() => {
359
+ inFlight = false;
360
+ });
361
+ }, intervalMs);
362
+ if (typeof timer.unref === "function") {
363
+ timer.unref();
364
+ }
365
+ }
336
366
  function createPiRigExtension(pi, options = {}) {
337
367
  const state = options.state ?? createPiRigExtensionState();
338
368
  const commands = createRigSlashCommands({
@@ -357,6 +387,7 @@ function createPiRigExtension(pi, options = {}) {
357
387
  for (const tool of createRigTools({ context: state, client: state.client })) {
358
388
  pi.registerTool?.(tool);
359
389
  }
390
+ startLiveSteeringPoll(pi, state, globalThis);
360
391
  }
361
392
  pi.on?.("session_start", async (_event, ctx) => {
362
393
  if (!state.active || !state.runId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/pi-rig",
3
- "version": "0.0.6-alpha.0",
3
+ "version": "0.0.6-alpha.2",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",