@h-rig/pi-rig 0.0.6-alpha.1 → 0.0.6-alpha.10

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;
@@ -73,6 +80,7 @@ function createRigContextFromEnv(env = process.env) {
73
80
  const serverUrl = env.RIG_SERVER_URL ?? env.RIG_SERVER_BASE_URL ?? discovered.serverUrl;
74
81
  const projectRoot = env.RIG_PROJECT_ROOT ?? env.PROJECT_RIG_ROOT ?? discovered.projectRoot;
75
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);
76
84
  const active = Boolean(runId || taskId || serverUrl || projectRoot);
77
85
  if (!active)
78
86
  return { active: false };
@@ -82,7 +90,8 @@ function createRigContextFromEnv(env = process.env) {
82
90
  ...taskId ? { taskId } : {},
83
91
  ...serverUrl ? { serverUrl } : {},
84
92
  ...projectRoot ? { projectRoot } : {},
85
- ...authToken ? { authToken } : {}
93
+ ...authToken ? { authToken } : {},
94
+ ...steeringPollMs !== null ? { steeringPollMs } : {}
86
95
  };
87
96
  }
88
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;
@@ -73,6 +80,7 @@ function createRigContextFromEnv(env = process.env) {
73
80
  const serverUrl = env.RIG_SERVER_URL ?? env.RIG_SERVER_BASE_URL ?? discovered.serverUrl;
74
81
  const projectRoot = env.RIG_PROJECT_ROOT ?? env.PROJECT_RIG_ROOT ?? discovered.projectRoot;
75
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);
76
84
  const active = Boolean(runId || taskId || serverUrl || projectRoot);
77
85
  if (!active)
78
86
  return { active: false };
@@ -82,7 +90,8 @@ function createRigContextFromEnv(env = process.env) {
82
90
  ...taskId ? { taskId } : {},
83
91
  ...serverUrl ? { serverUrl } : {},
84
92
  ...projectRoot ? { projectRoot } : {},
85
- ...authToken ? { authToken } : {}
93
+ ...authToken ? { authToken } : {},
94
+ ...steeringPollMs !== null ? { steeringPollMs } : {}
86
95
  };
87
96
  }
88
97
  function joinUrl(baseUrl, pathname) {
@@ -335,6 +344,25 @@ async function consumeQueuedSteering(pi, state, ctx) {
335
344
  notify(ctx, `Rig steering sync failed: ${error instanceof Error ? error.message : String(error)}`, "error");
336
345
  }
337
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
+ }
338
366
  function createPiRigExtension(pi, options = {}) {
339
367
  const state = options.state ?? createPiRigExtensionState();
340
368
  const commands = createRigSlashCommands({
@@ -359,6 +387,7 @@ function createPiRigExtension(pi, options = {}) {
359
387
  for (const tool of createRigTools({ context: state, client: state.client })) {
360
388
  pi.registerTool?.(tool);
361
389
  }
390
+ startLiveSteeringPoll(pi, state, globalThis);
362
391
  }
363
392
  pi.on?.("session_start", async (_event, ctx) => {
364
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.1",
3
+ "version": "0.0.6-alpha.10",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",