pi-crew 0.2.21 → 0.2.23

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": "pi-crew",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "description": "Pi extension for coordinated AI teams, workflows, worktrees, and async task orchestration",
5
5
  "author": "baphuongna",
6
6
  "license": "MIT",
@@ -71,13 +71,18 @@ export async function resolveCrewRuntime(config: PiTeamsConfig, env: NodeJS.Proc
71
71
  if (requestedMode === "child-process") return childCaps(requestedMode);
72
72
  // When a child-process mock is active (tests), force auto-mode to child-process where the mock is active.
73
73
  if (requestedMode === "auto" && env.PI_TEAMS_MOCK_CHILD_PI) return childCaps(requestedMode, "PI_TEAMS_MOCK_CHILD_PI mock forces child-process runtime in auto mode.");
74
- if (requestedMode === "live-session" || requestedMode === "auto") {
74
+ if (requestedMode === "live-session") {
75
75
  const live = await isLiveSessionRuntimeAvailable(1500, env);
76
76
  if (live.available) return liveCaps(requestedMode);
77
- if (requestedMode === "live-session" && config.runtime?.allowChildProcessFallback === false)
77
+ if (config.runtime?.allowChildProcessFallback === false)
78
78
  return scaffoldCaps(requestedMode, live.reason, "blocked");
79
79
  return { ...childCaps(requestedMode), fallback: "child-process", reason: live.reason };
80
80
  }
81
+ // auto mode: use child-process unless preferLiveSession is explicitly enabled
82
+ if (requestedMode === "auto" && config.runtime?.preferLiveSession === true) {
83
+ const live = await isLiveSessionRuntimeAvailable(1500, env);
84
+ if (live.available) return liveCaps(requestedMode);
85
+ }
81
86
  return childCaps(requestedMode);
82
87
  }
83
88
 
@@ -7,6 +7,8 @@ import { loadRunManifestById } from "../../state/state-store.ts";
7
7
  import type { ArtifactDescriptor, TeamRunManifest, TeamTaskState } from "../../state/types.ts";
8
8
  import type { WorkflowStep } from "../../workflows/workflow-config.ts";
9
9
  import { appendCrewAgentEvent, appendCrewAgentOutput, emptyCrewAgentProgress, recordFromTask, upsertCrewAgent } from "../crew-agent-records.ts";
10
+ import { createWorkerHeartbeat, touchWorkerHeartbeat } from "../worker-heartbeat.ts";
11
+ import { loadRunManifestById, saveRunTasks } from "../../state/state-store.ts";
10
12
  import { createStartupEvidence, type WorkerStartupEvidence } from "../worker-startup.ts";
11
13
  import { runLiveSessionTask } from "../live-session-runtime.ts";
12
14
  import { shouldAppendProgressEventUpdate, type ProgressEventSummary } from "../progress-event-coalescer.ts";
@@ -64,6 +66,7 @@ export async function runLiveTask(input: RunLiveTaskInput): Promise<RunLiveTaskO
64
66
  });
65
67
  let lastAgentRecordPersistedAt = 0;
66
68
  let lastRunProgressPersistedAt = 0;
69
+ let lastHeartbeatPersistedAt = 0;
67
70
  let lastRunProgressSummary: ProgressEventSummary | undefined;
68
71
  const persistLiveProgress = (event: unknown, force = false): void => {
69
72
  if (!isCurrent()) return;
@@ -72,6 +75,15 @@ export async function runLiveTask(input: RunLiveTaskInput): Promise<RunLiveTaskO
72
75
  upsertCrewAgent(manifest, recordFromTask(manifest, task, "live-session"));
73
76
  lastAgentRecordPersistedAt = now;
74
77
  }
78
+ // Bug #5 fix: also persist heartbeat to tasks.json so heartbeat-watcher can detect live-session activity
79
+ if (force || now - lastHeartbeatPersistedAt >= 1000) {
80
+ task = {
81
+ ...task,
82
+ heartbeat: touchWorkerHeartbeat(task.heartbeat ?? createWorkerHeartbeat(task.id)),
83
+ };
84
+ tasks = persistSingleTaskUpdate(manifest, tasks, task);
85
+ lastHeartbeatPersistedAt = now;
86
+ }
75
87
  const summary = progressEventSummary(task, event);
76
88
  const decision = shouldAppendProgressEventUpdate({ previous: lastRunProgressSummary, next: summary, nowMs: now, lastAppendMs: lastRunProgressPersistedAt || undefined, minIntervalMs: 1000, force });
77
89
  if (decision.shouldAppend) {