pi-spine 2.7.0 → 2.9.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.
@@ -3,6 +3,8 @@
3
3
  * Thin assembly: `buildDashboardSnapshot` composes snapshot-lanes and snapshot-waves.
4
4
  */
5
5
 
6
+ import fs from "node:fs";
7
+ import path from "node:path";
6
8
  import { deriveMacroPhase, macroPhaseLabel } from "../batch/macro-phase.mjs";
7
9
  import {
8
10
  classifyTasks,
@@ -28,6 +30,7 @@ import {
28
30
  readMetricsLines,
29
31
  } from "../batch/metrics.mjs";
30
32
  import { consumeDashboardInvalidateSignal } from "./cache-invalidate.mjs";
33
+ import { parsePrompt } from "../tasks/packet/parse-prompt.mjs";
31
34
  import { buildLaneRows } from "./snapshot-lanes.mjs";
32
35
  import {
33
36
  buildDefaultViewStatus,
@@ -109,6 +112,97 @@ export function enrichLaneRowsWithSubprocessHeartbeat(lanes, journalEvents, now
109
112
  });
110
113
  }
111
114
 
115
+ /**
116
+ * In-memory cache of parsed task titles keyed by absolute PROMPT.md path.
117
+ * Titles are immutable per file; mtime invalidates the entry so edits show up.
118
+ * Keyed by path (not taskId) so distinct project roots never cross-contaminate.
119
+ * @type {Map<string, { mtimeMs: number, title: string | null }>}
120
+ */
121
+ const taskTitleCache = new Map();
122
+
123
+ /**
124
+ * Read and parse a single PROMPT.md title with mtime-aware caching.
125
+ * Any read/parse failure degrades gracefully to null (PRD: graceful fallback).
126
+ *
127
+ * @param {string} promptPath Absolute path to a task PROMPT.md
128
+ * @returns {string | null}
129
+ */
130
+ function readTaskTitleFromPrompt(promptPath) {
131
+ try {
132
+ const stat = fs.statSync(promptPath);
133
+ const cached = taskTitleCache.get(promptPath);
134
+ if (cached && cached.mtimeMs === stat.mtimeMs) return cached.title;
135
+ const title = parsePrompt(fs.readFileSync(promptPath, "utf-8")).title ?? null;
136
+ taskTitleCache.set(promptPath, { mtimeMs: stat.mtimeMs, title });
137
+ return title;
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Resolve the absolute PROMPT.md path for a task. Uses the batch's `taskFolder`
145
+ * when present, falling back to scanning the tasks root for `${taskId}-*`.
146
+ *
147
+ * @param {string} tasksRootPath Absolute tasks root directory
148
+ * @param {string} taskId
149
+ * @param {string | null | undefined} taskFolder
150
+ * @returns {string | null}
151
+ */
152
+ function resolveTaskPromptPath(tasksRootPath, taskId, taskFolder) {
153
+ if (taskFolder) {
154
+ return path.join(tasksRootPath, taskFolder, "PROMPT.md");
155
+ }
156
+ try {
157
+ for (const name of fs.readdirSync(tasksRootPath)) {
158
+ if (name.startsWith(`${taskId}-`)) {
159
+ return path.join(tasksRootPath, name, "PROMPT.md");
160
+ }
161
+ }
162
+ } catch {
163
+ // Tasks root missing or unreadable — degrade to no title.
164
+ }
165
+ return null;
166
+ }
167
+
168
+ /**
169
+ * Build a taskId → title map by parsing each task's PROMPT.md.
170
+ *
171
+ * @param {string} projectRoot
172
+ * @param {string | null | undefined} tasksRoot Configured tasks root (relative to projectRoot)
173
+ * @param {Array<{ taskId?: unknown, taskFolder?: string | null }> | null | undefined} tasks
174
+ * @returns {Map<string, string | null>}
175
+ */
176
+ export function resolveRunningTaskTitles(projectRoot, tasksRoot, tasks) {
177
+ const titles = new Map();
178
+ if (!projectRoot || !tasksRoot || !Array.isArray(tasks)) return titles;
179
+ const tasksRootPath = path.join(projectRoot, tasksRoot);
180
+ for (const task of tasks) {
181
+ const taskId = task?.taskId != null ? String(task.taskId) : "";
182
+ if (!taskId || titles.has(taskId)) continue;
183
+ const promptPath = resolveTaskPromptPath(tasksRootPath, taskId, task?.taskFolder ?? null);
184
+ titles.set(taskId, promptPath ? readTaskTitleFromPrompt(promptPath) : null);
185
+ }
186
+ return titles;
187
+ }
188
+
189
+ /**
190
+ * Attach `runningTaskTitle` to each lane row from the resolved title map.
191
+ * Lanes without a running task (or an unresolvable title) get null.
192
+ *
193
+ * @param {object[]} lanes
194
+ * @param {Map<string, string | null>} taskTitles
195
+ */
196
+ export function enrichLaneRowsWithRunningTaskTitle(lanes, taskTitles) {
197
+ return (lanes ?? []).map((lane) => {
198
+ const title =
199
+ lane?.runningTaskId != null
200
+ ? (taskTitles.get(String(lane.runningTaskId)) ?? null)
201
+ : null;
202
+ return { ...lane, runningTaskTitle: title };
203
+ });
204
+ }
205
+
112
206
  /**
113
207
  * @param {string} projectRoot
114
208
  */
@@ -176,19 +270,22 @@ export function buildDashboardSnapshot(projectRoot) {
176
270
  }
177
271
 
178
272
  const lanes = enrichLaneRowsWithSubprocessHeartbeat(
179
- buildLaneRows({
180
- lanes: batch?.lanes ?? [],
181
- classifiedTasks,
182
- stallConfig,
183
- currentWaveTaskIds,
184
- journalTail,
185
- journalEvents,
186
- metricsLines,
187
- projectRoot,
188
- batchId: reconciliation.batchId,
189
- now,
190
- diagnosis: reconciliation.diagnosis,
191
- }),
273
+ enrichLaneRowsWithRunningTaskTitle(
274
+ buildLaneRows({
275
+ lanes: batch?.lanes ?? [],
276
+ classifiedTasks,
277
+ stallConfig,
278
+ currentWaveTaskIds,
279
+ journalTail,
280
+ journalEvents,
281
+ metricsLines,
282
+ projectRoot,
283
+ batchId: reconciliation.batchId,
284
+ now,
285
+ diagnosis: reconciliation.diagnosis,
286
+ }),
287
+ resolveRunningTaskTitles(projectRoot, config?.paths?.tasksRoot ?? null, batch?.tasks),
288
+ ),
192
289
  journalEvents,
193
290
  now,
194
291
  );
@@ -1,42 +1,67 @@
1
1
  // @ts-nocheck
2
2
  /**
3
3
  * Doctor check: validate that all agent model pins use canonical provider/model format (SP-422 / #76).
4
+ * Extended in SP-664 / #216 to also validate every named `agents.profiles.<name>` entry.
4
5
  */
5
6
 
6
7
  import { validateModelIdFormat } from "../config/model-id.mjs";
7
-
8
- /** @type {ReadonlyArray<{ path: string, get: (c: object) => unknown }>} */
9
- const MODEL_PATHS = Object.freeze([
10
- { path: "agents.worker.model", get: (c) => c?.agents?.worker?.model },
11
- { path: "agents.reviewer.model", get: (c) => c?.agents?.reviewer?.model },
12
- { path: "agents.reviewer.plan.model", get: (c) => c?.agents?.reviewer?.plan?.model },
13
- { path: "agents.reviewer.code.model", get: (c) => c?.agents?.reviewer?.code?.model },
14
- { path: "agents.reviewer.final.model", get: (c) => c?.agents?.reviewer?.final?.model },
15
- { path: "agents.supervisor.model", get: (c) => c?.agents?.supervisor?.model },
16
- ]);
8
+ import { AGENT_MODEL_ACCESSORS } from "../config/spine-config-schema.mjs";
17
9
 
18
10
  /**
19
- * @param {object} params
20
- * @param {object} [params.config]
21
- * @returns {{ label: string, ok: boolean, detail: string, suggestedCommand?: string }}
11
+ * @param {unknown} value
12
+ * @returns {value is Record<string, unknown>}
22
13
  */
23
- export function buildAgentModelIdsDoctorCheck({ config = {} } = {}) {
24
- /** @type {Array<{ path: string, error: string, suggestedCommand?: string }>} */
25
- const failures = [];
14
+ function isPlainObject(value) {
15
+ return typeof value === "object" && value !== null && !Array.isArray(value);
16
+ }
26
17
 
27
- for (const { path, get } of MODEL_PATHS) {
28
- const value = get(config);
18
+ /**
19
+ * Collect canonical-format failures for every model pin reachable from an
20
+ * agents-shaped object. Used for both the base `agents` section and each named
21
+ * profile entry, which share the worker/reviewer/supervisor shape.
22
+ *
23
+ * @param {unknown} agentsRoot Agents-shaped object (base section or a profile).
24
+ * @param {string} pathPrefix Dotted prefix for messages (e.g. `agents` or `agents.profiles.hard`).
25
+ * @param {Array<{ path: string, error: string, suggestedCommand?: string }>} failures Accumulator.
26
+ */
27
+ function collectModelFailures(agentsRoot, pathPrefix, failures) {
28
+ for (const { rel, get } of AGENT_MODEL_ACCESSORS) {
29
+ const value = get(agentsRoot);
29
30
  if (value == null || value === "" || value === "inherit") continue;
30
31
  if (typeof value !== "string") continue;
31
32
 
32
33
  const result = validateModelIdFormat(value);
33
34
  if (!result.ok) {
35
+ const path = `${pathPrefix}.${rel}`;
34
36
  const suggested = result.canonical
35
37
  ? `spine settings set ${path} ${result.canonical}`
36
38
  : undefined;
37
39
  failures.push({ path, error: result.error, suggestedCommand: suggested });
38
40
  }
39
41
  }
42
+ }
43
+
44
+ /**
45
+ * @param {object} params
46
+ * @param {object} [params.config]
47
+ * @returns {{ label: string, ok: boolean, detail: string, suggestedCommand?: string }}
48
+ */
49
+ export function buildAgentModelIdsDoctorCheck({ config = {} } = {}) {
50
+ /** @type {Array<{ path: string, error: string, suggestedCommand?: string }>} */
51
+ const failures = [];
52
+
53
+ // Base agent pins — already reflect the active profile after load-time resolution.
54
+ collectModelFailures(config?.agents, "agents", failures);
55
+
56
+ // Validate each named profile independently so a misconfigured-but-inactive profile
57
+ // is still flagged before an operator can activate it (SP-664 / #216).
58
+ const profiles = config?.agents?.profiles;
59
+ if (isPlainObject(profiles)) {
60
+ for (const [name, profile] of Object.entries(profiles)) {
61
+ if (!isPlainObject(profile)) continue;
62
+ collectModelFailures(profile, `agents.profiles.${name}`, failures);
63
+ }
64
+ }
40
65
 
41
66
  if (failures.length === 0) {
42
67
  return {