@zhuxixi/pi-agent-board 0.13.0 → 0.14.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.
- package/CHANGELOG.md +65 -0
- package/README.md +37 -12
- package/docs/SECTION_FOLDING.md +53 -0
- package/docs/superpowers/plans/2026-10-23-issue-222-attach-ready.md +290 -0
- package/docs/superpowers/plans/2026-10-26-issue-245-key-hints-doc-sync.md +244 -0
- package/docs/superpowers/plans/2026-10-27-issue-172-fullscreen-selection-clear.md +344 -0
- package/docs/superpowers/plans/2026-10-27-issue-252-select-key-hints.md +209 -0
- package/docs/superpowers/plans/2026-10-28-issue-255-coordinator-endpoint-zombie.md +442 -0
- package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
- package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
- package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
- package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
- package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
- package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
- package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
- package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
- package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
- package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
- package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
- package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
- package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
- package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
- package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
- package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
- package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
- package/docs/superpowers/specs/2026-10-26-issue-245-key-hints-doc-sync-design.md +72 -0
- package/docs/superpowers/specs/2026-10-27-issue-172-fullscreen-selection-clear-design.md +248 -0
- package/docs/superpowers/specs/2026-10-27-issue-252-select-key-hints-design.md +95 -0
- package/docs/superpowers/specs/2026-10-28-issue-255-coordinator-endpoint-zombie-design.md +380 -0
- package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
- package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
- package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
- package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
- package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
- package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
- package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
- package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
- package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
- package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
- package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
- package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
- package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
- package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
- package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
- package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
- package/package.json +1 -1
- package/runner/pty-runner.mjs +526 -63
- package/runner/state-coordinator.mjs +62 -5
- package/runner/title-runner.mjs +33 -24
- package/src/commands/agent-board.ts +5 -1
- package/src/core/attach-detach.mjs +27 -0
- package/src/core/attach-frame-proof.mjs +897 -0
- package/src/core/attach-frame-reporter.mjs +738 -0
- package/src/core/attach-frame-stream.mjs +266 -0
- package/src/core/attach-pr-label.mjs +12 -0
- package/src/core/attach-recovery.mjs +239 -0
- package/src/core/attach-screen-owner.mjs +55 -0
- package/src/core/attach-view-proof.mjs +709 -0
- package/src/core/auto-state.mjs +6 -1
- package/src/core/cwd-stats.mjs +3 -1
- package/src/core/dashboard-prefs.mjs +31 -0
- package/src/core/derive.mjs +8 -1
- package/src/core/events.mjs +127 -1
- package/src/core/foreground-projection-cache.mjs +1 -0
- package/src/core/frame-witness-update.mjs +35 -0
- package/src/core/fullscreen-selection.mjs +60 -0
- package/src/core/host-coordination.mjs +48 -0
- package/src/core/host-protocol.mjs +13 -2
- package/src/core/hosted-frame-witness.mjs +60 -0
- package/src/core/paths.mjs +10 -3
- package/src/core/pty-attach-render.mjs +239 -0
- package/src/core/pty-kitty-images.mjs +237 -0
- package/src/core/pty-scroll.mjs +8 -8
- package/src/core/rows.mjs +43 -7
- package/src/core/session-entries.mjs +82 -0
- package/src/core/session-launch-prefs.mjs +45 -0
- package/src/core/session-view.mjs +3 -63
- package/src/core/store.mjs +1 -0
- package/src/core/terminal-attach-client.mjs +199 -20
- package/src/core/terminal-attach-protocol.mjs +221 -7
- package/src/core/terminal-model.mjs +24 -3
- package/src/core/terminal-snapshot.mjs +10 -0
- package/src/core/title-flow.mjs +66 -0
- package/src/core/title.mjs +101 -0
- package/src/core/types.mjs +17 -0
- package/src/index.ts +85 -0
- package/src/runtime/service.mjs +87 -18
- package/src/ui/dashboard.ts +206 -49
- package/src/ui/pty-attach.ts +1472 -99
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
# Greeting-Aware Title Generation Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** A session whose first message is a bare greeting gets its title generated from the first substantive user message (polled from the session JSONL) instead of being frozen as "Simple greeting".
|
|
6
|
+
|
|
7
|
+
**Architecture:** Pure classifier/resolver/projection functions in `src/core/title.mjs`; a new orchestration module `src/core/title-flow.mjs` with every effect injected; `runner/title-runner.mjs` becomes a thin shell that resolves env settings, early-exits on `off`, and wires real deps. `service.mjs` is untouched.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** Node ESM (`.mjs`), `node:test` + `assert/strict`, JSDoc types checked by `tsc --noEmit` (allowJs, checkJs off — JSDoc typedefs required for exported `.mjs` signatures).
|
|
10
|
+
|
|
11
|
+
**Spec:** `docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md` (issue #295). Every task lists the acceptance IDs it implements. A1–A8 are automated; U1 is the post-merge manual check (Task 9).
|
|
12
|
+
|
|
13
|
+
## Global Constraints
|
|
14
|
+
|
|
15
|
+
- Tabs for indentation; English comments and commit messages; conventional commit subjects (`feat`/`fix`/`test`/`refactor`/`docs`), PR number appended as `(#N)` only at merge time — do not invent one.
|
|
16
|
+
- Never touch `src/runtime/service.mjs` (spec non-goal).
|
|
17
|
+
- Preserve the write-back guard semantics exactly: re-read meta, `meta.name !== config.fallbackName` → no write (manual rename wins, including during polling and during a pending one-shot).
|
|
18
|
+
- Preserve the last-line-only extraction: `out.trim().split("\n").slice(-1)[0]?.trim()`.
|
|
19
|
+
- The flow module (`title-flow.mjs`) must not read `process.env`; the shell must not regain decision logic (testability split is a hard constraint).
|
|
20
|
+
- No new env knobs; keep `AGENT_BOARD_TITLE_MODEL ?? AGENT_VIEW_TITLE_MODEL` precedence and `off` semantics verbatim.
|
|
21
|
+
- Do not `git add -A`; stage files explicitly.
|
|
22
|
+
- Work from: `/home/elling/git-repo/github/pi-agent-board/.pi/worktrees/issue-295-greeting-title-poll` (all paths below are repo-relative).
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
### Task 1: Lift `contentText` into session-entries [A3]
|
|
27
|
+
|
|
28
|
+
**Files:**
|
|
29
|
+
- Modify: `src/core/session-entries.mjs`
|
|
30
|
+
- Modify: `src/core/session-view.mjs`
|
|
31
|
+
- Test: existing suite (no new tests; behavior must be identical)
|
|
32
|
+
|
|
33
|
+
**Interfaces:**
|
|
34
|
+
- Consumes: nothing new.
|
|
35
|
+
- Produces: `export function contentText(content)` in `src/core/session-entries.mjs` — `contentText(content: string|any[]|unknown): string`, returns trimmed text-block projection (verbatim from session-view).
|
|
36
|
+
|
|
37
|
+
- [ ] **Step 1: Move the function**
|
|
38
|
+
|
|
39
|
+
Cut this block from `src/core/session-view.mjs` (bottom of file):
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
/**
|
|
43
|
+
* Convert Pi message/content blocks to plain text.
|
|
44
|
+
* @param {any} content
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
function contentText(content) {
|
|
48
|
+
if (typeof content === "string") return content.trim();
|
|
49
|
+
if (!Array.isArray(content)) return "";
|
|
50
|
+
return content
|
|
51
|
+
.filter((b) => b && b.type === "text" && typeof b.text === "string")
|
|
52
|
+
.map((b) => b.text)
|
|
53
|
+
.join("\n")
|
|
54
|
+
.trim();
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Paste it into `src/core/session-entries.mjs` with `export function contentText(content)` (same JSDoc, same body, unchanged). In `src/core/session-view.mjs`, extend the existing import:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import { activeBranchEntries, contentText, parseSessionEntries } from "./session-entries.mjs";
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- [ ] **Step 2: Run the affected suites**
|
|
65
|
+
|
|
66
|
+
Run: `node --test test/session-view.test.mjs test/service.test.mjs 2>&1 | tail -5` (use `ls test/ | grep -E 'session|title'` to pick the exact existing session-view test file name if different; if none exists, run `npm test`).
|
|
67
|
+
Expected: PASS (zero behavior change).
|
|
68
|
+
|
|
69
|
+
- [ ] **Step 3: Commit**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git add src/core/session-entries.mjs src/core/session-view.mjs
|
|
73
|
+
git commit -m "refactor: lift contentText into session-entries (issue #295)"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### Task 2: `isGreetingPrompt` classifier [A1]
|
|
79
|
+
|
|
80
|
+
**Files:**
|
|
81
|
+
- Modify: `src/core/title.mjs`
|
|
82
|
+
- Test: `test/title.test.mjs`
|
|
83
|
+
|
|
84
|
+
**Interfaces:**
|
|
85
|
+
- Consumes: nothing.
|
|
86
|
+
- Produces: `export function isGreetingPrompt(text)` — `isGreetingPrompt(text: string|null|undefined): boolean`.
|
|
87
|
+
|
|
88
|
+
- [ ] **Step 1: Write the failing tests** (append to `test/title.test.mjs`; add `isGreetingPrompt` to the existing import from `../src/core/title.mjs`):
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
test("isGreetingPrompt matches pure greetings", () => {
|
|
92
|
+
const en = ["hello", "Hello!", "HI", "hey", "hiya", "yo", "sup", "howdy", "greetings", "morning",
|
|
93
|
+
"good morning", "Good Morning!", "good afternoon", "good evening", "good day"];
|
|
94
|
+
const zh = ["你好", "您好", "嗨", "哈喽", "哈啰", "在吗", "在么", "早上好", "上午好", "早安", "下午好", "晚上好", "晚安"];
|
|
95
|
+
const variants = ["hello hello", "嗨嗨", "hi there", "你好呀", " hello? ", "hello!!!", "hello,hello", "hi呀"];
|
|
96
|
+
for (const s of [...en, ...zh, ...variants]) assert.equal(isGreetingPrompt(s), true, s);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("isGreetingPrompt rejects non-greetings", () => {
|
|
100
|
+
const cases = ["hello, please fix X", "helloX", "你好请修复", "there", "呀", "there hello",
|
|
101
|
+
"good", "fix the bug", "", " ", "hi, what is the cache hit rate for redis"];
|
|
102
|
+
for (const s of cases) assert.equal(isGreetingPrompt(s), false, JSON.stringify(s));
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- [ ] **Step 2: Run test to verify it fails**
|
|
107
|
+
|
|
108
|
+
Run: `node --test test/title.test.mjs`
|
|
109
|
+
Expected: FAIL — `isGreetingPrompt` is not exported.
|
|
110
|
+
|
|
111
|
+
- [ ] **Step 3: Implement** (append to `src/core/title.mjs`):
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
/** Characters stripped from the edges of a message before greeting matching. */
|
|
115
|
+
const GREETING_EDGE_PUNCT = "!!??。.,,、~~…;;::";
|
|
116
|
+
|
|
117
|
+
/** Multi-word/multi-char greeting vocabulary (greedy longest-match units). */
|
|
118
|
+
const GREETINGS = [
|
|
119
|
+
"good morning", "good afternoon", "good evening", "good day",
|
|
120
|
+
"hello", "hi", "hey", "hiya", "yo", "sup", "howdy", "greetings", "morning",
|
|
121
|
+
"你好", "您好", "嗨", "哈喽", "哈啰", "在吗", "在么",
|
|
122
|
+
"早上好", "上午好", "早安", "下午好", "晚上好", "晚安",
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
/** Particles that may only appear after a greeting unit (suffix fillers). */
|
|
126
|
+
const GREETING_PARTICLES = ["there", "呀", "啊", "哦"];
|
|
127
|
+
|
|
128
|
+
const GREETING_SEPARATOR = new Set([" ", ...GREETING_EDGE_PUNCT.split("")]);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* True iff the ENTIRE message is greeting material: a greeting-first greedy
|
|
132
|
+
* longest-match consume over the normalized string (issue #295). The first
|
|
133
|
+
* consumed unit must be a GREETINGS entry; later units may be GREETINGS or
|
|
134
|
+
* particles; adjacent duplicates need no separator.
|
|
135
|
+
* @param {string|null|undefined} text
|
|
136
|
+
* @returns {boolean}
|
|
137
|
+
*/
|
|
138
|
+
export function isGreetingPrompt(text) {
|
|
139
|
+
const normalized = String(text ?? "")
|
|
140
|
+
.trim()
|
|
141
|
+
.toLowerCase()
|
|
142
|
+
.replace(/\s+/g, " ")
|
|
143
|
+
.replace(new RegExp(`^[${escapeForCharClass(GREETING_EDGE_PUNCT)} ]+|[${escapeForCharClass(GREETING_EDGE_PUNCT)} ]+$`, "g"), "");
|
|
144
|
+
if (!normalized) return false;
|
|
145
|
+
let i = 0;
|
|
146
|
+
let consumedGreeting = false;
|
|
147
|
+
let first = true;
|
|
148
|
+
while (i < normalized.length) {
|
|
149
|
+
if (GREETING_SEPARATOR.has(normalized[i])) {
|
|
150
|
+
i++;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const unit = longestUnitAt(normalized, i, first);
|
|
154
|
+
if (!unit) return false;
|
|
155
|
+
if (unit.fromGreetings) consumedGreeting = true;
|
|
156
|
+
first = false;
|
|
157
|
+
i += unit.text.length;
|
|
158
|
+
}
|
|
159
|
+
return consumedGreeting;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** @param {string} s @param {number} i @param {boolean} first */
|
|
163
|
+
function longestUnitAt(s, i, first) {
|
|
164
|
+
const pool = first ? GREETINGS : [...GREETINGS, ...GREETING_PARTICLES];
|
|
165
|
+
const sorted = [...pool].sort((a, b) => b.length - a.length);
|
|
166
|
+
for (const candidate of sorted) {
|
|
167
|
+
if (s.startsWith(candidate, i)) return { text: candidate, fromGreetings: GREETINGS.includes(candidate) };
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @param {string} chars */
|
|
173
|
+
function escapeForCharClass(chars) {
|
|
174
|
+
return chars.replace(/[\\\]^-]/g, "\\$&");
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Note: sort inside `longestUnitAt` runs per position — fine at greeting lengths; if you prefer, precompute the sorted pools once at module level (recommended: `const GREETINGS_BY_LENGTH = [...]`, `const UNITS_BY_LENGTH = [...]`).
|
|
179
|
+
|
|
180
|
+
- [ ] **Step 4: Run test to verify it passes**
|
|
181
|
+
|
|
182
|
+
Run: `node --test test/title.test.mjs`
|
|
183
|
+
Expected: PASS (all, including the pre-existing three tests).
|
|
184
|
+
|
|
185
|
+
- [ ] **Step 5: Commit**
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
git add src/core/title.mjs test/title.test.mjs
|
|
189
|
+
git commit -m "feat: add isGreetingPrompt greeting classifier (issue #295)"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### Task 3: `resolveTitleSettings` env resolver [A5]
|
|
195
|
+
|
|
196
|
+
**Files:**
|
|
197
|
+
- Modify: `src/core/title.mjs`
|
|
198
|
+
- Test: `test/title.test.mjs`
|
|
199
|
+
|
|
200
|
+
**Interfaces:**
|
|
201
|
+
- Consumes: `DEFAULT_TITLE_MODEL`, `DEFAULT_TITLE_THINKING_LEVEL` (already in `title.mjs`).
|
|
202
|
+
- Produces: `export function resolveTitleSettings(env, configModel)` — `resolveTitleSettings(env: Record<string, string|undefined>, configModel: string|null|undefined): { enabled: boolean, model: string, thinking: string }`.
|
|
203
|
+
|
|
204
|
+
- [ ] **Step 1: Write the failing tests** (append; import `resolveTitleSettings`):
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
test("resolveTitleSettings keeps env precedence and off semantics", () => {
|
|
208
|
+
assert.deepEqual(resolveTitleSettings({}, null), { enabled: true, model: DEFAULT_TITLE_MODEL, thinking: DEFAULT_TITLE_THINKING_LEVEL });
|
|
209
|
+
assert.equal(resolveTitleSettings({ AGENT_BOARD_TITLE_MODEL: "off" }, "x/y").enabled, false);
|
|
210
|
+
assert.equal(resolveTitleSettings({ AGENT_VIEW_TITLE_MODEL: "off" }, null).enabled, false);
|
|
211
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_BOARD_TITLE_MODEL: "a/b", AGENT_VIEW_TITLE_MODEL: "c/d" }, null).model, "a/b");
|
|
212
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_VIEW_TITLE_MODEL: "c/d" }, null).model, "c/d");
|
|
213
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_VIEW_TITLE_MODEL: "c/d" }, "cfg/m").model, "cfg/m");
|
|
214
|
+
assert.deepEqual(resolveTitleSettings({}, null).thinking, DEFAULT_TITLE_THINKING_LEVEL);
|
|
215
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_BOARD_TITLE_THINKING_LEVEL: "high" }, null).thinking, "high");
|
|
216
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_VIEW_TITLE_THINKING_LEVEL: "low" }, null).thinking, "low");
|
|
217
|
+
assert.deepEqual(resolveTitleSettings({ AGENT_BOARD_TITLE_THINKING_LEVEL: "off" }, null).thinking, "off");
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Add `DEFAULT_TITLE_MODEL`/`DEFAULT_TITLE_THINKING_LEVEL` to the import from `../src/core/title.mjs`.
|
|
222
|
+
|
|
223
|
+
- [ ] **Step 2: Run test to verify it fails**
|
|
224
|
+
|
|
225
|
+
Run: `node --test test/title.test.mjs`
|
|
226
|
+
Expected: FAIL — `resolveTitleSettings` not exported.
|
|
227
|
+
|
|
228
|
+
- [ ] **Step 3: Implement** (append to `src/core/title.mjs`):
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
/**
|
|
232
|
+
* Resolve title-generation settings from env, preserving the runner's
|
|
233
|
+
* historical precedence exactly (issue #295): board var wins over the legacy
|
|
234
|
+
* view var; `off` disables even when a config model is set.
|
|
235
|
+
* @param {Record<string, string|undefined>} env
|
|
236
|
+
* @param {string|null|undefined} configModel
|
|
237
|
+
* @returns {{ enabled: boolean, model: string, thinking: string }}
|
|
238
|
+
*/
|
|
239
|
+
export function resolveTitleSettings(env, configModel) {
|
|
240
|
+
const configured = env.AGENT_BOARD_TITLE_MODEL ?? env.AGENT_VIEW_TITLE_MODEL;
|
|
241
|
+
const thinking = env.AGENT_BOARD_TITLE_THINKING_LEVEL ?? env.AGENT_VIEW_TITLE_THINKING_LEVEL ?? DEFAULT_TITLE_THINKING_LEVEL;
|
|
242
|
+
if (configured === "off") return { enabled: false, model: "", thinking };
|
|
243
|
+
return { enabled: true, model: configModel ?? configured ?? DEFAULT_TITLE_MODEL, thinking };
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
- [ ] **Step 4: Run test to verify it passes**
|
|
248
|
+
|
|
249
|
+
Run: `node --test test/title.test.mjs`
|
|
250
|
+
Expected: PASS.
|
|
251
|
+
|
|
252
|
+
- [ ] **Step 5: Commit**
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
git add src/core/title.mjs test/title.test.mjs
|
|
256
|
+
git commit -m "feat: add resolveTitleSettings env resolver for titles (issue #295)"
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### Task 4: `firstSubstantiveUserPrompt` projection [A2]
|
|
262
|
+
|
|
263
|
+
**Files:**
|
|
264
|
+
- Modify: `src/core/title.mjs` (add `import { activeBranchEntries, contentText, parseSessionEntries } from "./session-entries.mjs";` at top)
|
|
265
|
+
- Test: `test/title.test.mjs`
|
|
266
|
+
|
|
267
|
+
**Interfaces:**
|
|
268
|
+
- Consumes: `parseSessionEntries`, `activeBranchEntries`, `contentText` (Task 1), `isGreetingPrompt` (Task 2).
|
|
269
|
+
- Produces: `export function firstSubstantiveUserPrompt(sessionJsonlText)` — `firstSubstantiveUserPrompt(sessionJsonlText: string): string|null`.
|
|
270
|
+
|
|
271
|
+
- [ ] **Step 1: Write the failing tests** (append; import `firstSubstantiveUserPrompt`; local fixture builder):
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
/** @param {{id: string, role: string, text: string, parentId?: string, contentKind?: string}[]} msgs */
|
|
275
|
+
function sessionJsonl(msgs) {
|
|
276
|
+
const lines = [JSON.stringify({ type: "session", id: "s1", cwd: "/tmp" })];
|
|
277
|
+
for (const m of msgs) {
|
|
278
|
+
const content = m.contentKind === "tool_result"
|
|
279
|
+
? [{ type: "tool_result", id: "tr", content: "ignored" }]
|
|
280
|
+
: [{ type: "text", text: m.text }];
|
|
281
|
+
lines.push(JSON.stringify({ type: "message", id: m.id, parentId: m.parentId ?? null, message: { role: m.role, content } }));
|
|
282
|
+
}
|
|
283
|
+
return lines.join("\n") + "\n";
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
test("firstSubstantiveUserPrompt picks the first substantive user message on the active branch", () => {
|
|
287
|
+
const jsonl = sessionJsonl([
|
|
288
|
+
{ id: "m1", role: "user", text: "hello", parentId: null },
|
|
289
|
+
{ id: "m2", role: "assistant", text: "Hi!", parentId: "m1" },
|
|
290
|
+
{ id: "m3", role: "user", text: "", contentKind: "tool_result", parentId: "m2" },
|
|
291
|
+
{ id: "m4", role: "user", text: "deploy api", parentId: "m3" },
|
|
292
|
+
]);
|
|
293
|
+
assert.equal(firstSubstantiveUserPrompt(jsonl), "deploy api");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("firstSubstantiveUserPrompt returns null when nothing substantive exists", () => {
|
|
297
|
+
assert.equal(firstSubstantiveUserPrompt(sessionJsonl([{ id: "m1", role: "user", text: "hi", parentId: null }])), null);
|
|
298
|
+
assert.equal(firstSubstantiveUserPrompt(""), null);
|
|
299
|
+
assert.equal(firstSubstantiveUserPrompt("{}\n"), null);
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
- [ ] **Step 2: Run test to verify it fails**
|
|
304
|
+
|
|
305
|
+
Run: `node --test test/title.test.mjs`
|
|
306
|
+
Expected: FAIL — not exported.
|
|
307
|
+
|
|
308
|
+
- [ ] **Step 3: Implement** (append to `src/core/title.mjs`):
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
/**
|
|
312
|
+
* First substantive (non-greeting, non-empty) user message on the active
|
|
313
|
+
* branch of a session JSONL, or null (issue #295). Tool-result user entries
|
|
314
|
+
* project to empty text and are skipped by contentText.
|
|
315
|
+
* @param {string} sessionJsonlText
|
|
316
|
+
* @returns {string|null}
|
|
317
|
+
*/
|
|
318
|
+
export function firstSubstantiveUserPrompt(sessionJsonlText) {
|
|
319
|
+
const { entries, byId } = parseSessionEntries(sessionJsonlText);
|
|
320
|
+
for (const entry of activeBranchEntries(entries, byId)) {
|
|
321
|
+
if (entry?.type !== "message" || entry.message?.role !== "user") continue;
|
|
322
|
+
const text = contentText(entry.message?.content);
|
|
323
|
+
if (!text || isGreetingPrompt(text)) continue;
|
|
324
|
+
return text;
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
- [ ] **Step 4: Run test to verify it passes**
|
|
331
|
+
|
|
332
|
+
Run: `node --test test/title.test.mjs`
|
|
333
|
+
Expected: PASS.
|
|
334
|
+
|
|
335
|
+
- [ ] **Step 5: Commit**
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
git add src/core/title.mjs test/title.test.mjs
|
|
339
|
+
git commit -m "feat: add firstSubstantiveUserPrompt session projection (issue #295)"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
### Task 5: `runTitleFlow` orchestration [A4]
|
|
345
|
+
|
|
346
|
+
**Files:**
|
|
347
|
+
- Create: `src/core/title-flow.mjs`
|
|
348
|
+
- Test: `test/title-flow.test.mjs` (new)
|
|
349
|
+
|
|
350
|
+
**Interfaces:**
|
|
351
|
+
- Consumes: `isGreetingPrompt`, `firstSubstantiveUserPrompt`, `titlePrompt`, `normalizeGeneratedTitle` (all from `./title.mjs`).
|
|
352
|
+
- Produces:
|
|
353
|
+
- `export const TITLE_POLL_INTERVAL_MS = 15_000;`
|
|
354
|
+
- `export const TITLE_POLL_BUDGET_MS = 300_000;`
|
|
355
|
+
- `export async function runTitleFlow(config, deps)` where `config` is `TitleConfig` (with optional `pollIntervalMs`/`pollBudgetMs`) and `deps = { now(): number, sleep(ms: number): Promise<void>, readMeta(root: string, viewId: string): any|null, commitMeta(meta: any): void, readSessionText(config: any): string|null, runOneShot(prompt: string): Promise<string|null> }`.
|
|
356
|
+
|
|
357
|
+
- [ ] **Step 1: Write the failing tests** (`test/title-flow.test.mjs`, new file):
|
|
358
|
+
|
|
359
|
+
```js
|
|
360
|
+
import assert from "node:assert/strict";
|
|
361
|
+
import { test } from "node:test";
|
|
362
|
+
import { runTitleFlow, TITLE_POLL_INTERVAL_MS, TITLE_POLL_BUDGET_MS } from "../src/core/title-flow.mjs";
|
|
363
|
+
|
|
364
|
+
const baseConfig = () => ({ root: "/r", viewId: "v1", cwd: "/r", prompt: "hello", fallbackName: "slug-name", piCommand: "pi", piArgsPrefix: [], model: null });
|
|
365
|
+
|
|
366
|
+
/** Deterministic deps: clock advances only via sleep; meta lives in a store. */
|
|
367
|
+
function makeDeps(overrides = {}) {
|
|
368
|
+
const state = { now: 0, meta: { id: "v1", name: "slug-name" }, sessionText: null, oneShotImpl: null, sleeps: 0 };
|
|
369
|
+
const pending = [];
|
|
370
|
+
const deps = {
|
|
371
|
+
now: () => state.now,
|
|
372
|
+
sleep: async (ms) => { state.now += ms; state.sleeps++; },
|
|
373
|
+
readMeta: () => (state.meta ? { ...state.meta } : null),
|
|
374
|
+
commitMeta: (meta) => { state.meta = { ...meta }; state.committed = meta.name; },
|
|
375
|
+
readSessionText: () => state.sessionText,
|
|
376
|
+
runOneShot: (prompt) => {
|
|
377
|
+
state.prompts = [...(state.prompts ?? []), prompt];
|
|
378
|
+
if (state.oneShotImpl) return state.oneShotImpl(prompt);
|
|
379
|
+
return Promise.resolve("Generated Title");
|
|
380
|
+
},
|
|
381
|
+
...overrides,
|
|
382
|
+
};
|
|
383
|
+
return { deps, state };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
test("A4① greeting → poll hit → generates from substantive message and commits", async () => {
|
|
387
|
+
const { deps, state } = makeDeps();
|
|
388
|
+
// substantive message appears before the first tick
|
|
389
|
+
deps.readSessionText = () => '{"type":"session","id":"s","cwd":"/r"}\n' +
|
|
390
|
+
'{"type":"message","id":"m1","parentId":null,"message":{"role":"user","content":[{"type":"text","text":"hello"}]}}\n' +
|
|
391
|
+
'{"type":"message","id":"m2","parentId":"m1","message":{"role":"user","content":[{"type":"text","text":"deploy api"}]}}\n';
|
|
392
|
+
await runTitleFlow(baseConfig(), deps);
|
|
393
|
+
assert.equal(state.prompts?.[0], "deploy api");
|
|
394
|
+
assert.equal(state.meta.name, "Generated Title");
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("A4② manual rename during polling wins", async () => {
|
|
398
|
+
const { deps, state } = makeDeps();
|
|
399
|
+
let ticks = 0;
|
|
400
|
+
deps.sleep = async (ms) => { state.now += ms; ticks++; if (ticks === 1) state.meta.name = "My Own Name"; };
|
|
401
|
+
deps.readSessionText = () => '{"type":"message","id":"m2","parentId":null,"message":{"role":"user","content":[{"type":"text","text":"deploy api"}]}}\n';
|
|
402
|
+
await runTitleFlow(baseConfig(), deps);
|
|
403
|
+
assert.equal(state.committed, undefined);
|
|
404
|
+
assert.equal(state.meta.name, "My Own Name");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("A4③ budget exhausted → no model call, no commit, quiet return", async () => {
|
|
408
|
+
const { deps, state } = makeDeps();
|
|
409
|
+
state.sessionText = null;
|
|
410
|
+
const cfg = { ...baseConfig(), pollIntervalMs: 100, pollBudgetMs: 250 };
|
|
411
|
+
await runTitleFlow(cfg, deps);
|
|
412
|
+
assert.equal(state.sleeps, 3); // ticks at 100/200/(250 stop) — 3 sleeps before deadline check fails
|
|
413
|
+
assert.equal(state.prompts, undefined);
|
|
414
|
+
assert.equal(state.committed, undefined);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("A4④ non-greeting → immediate generation, no polling", async () => {
|
|
418
|
+
const { deps, state } = makeDeps();
|
|
419
|
+
await runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps);
|
|
420
|
+
assert.equal(state.sleeps, 0);
|
|
421
|
+
assert.equal(state.prompts?.[0], "fix bug now");
|
|
422
|
+
assert.equal(state.meta.name, "Generated Title");
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test("A4⑤ empty / null / fallback-equal one-shot output → no commit", async () => {
|
|
426
|
+
for (const out of ["", null, "slug-name"]) {
|
|
427
|
+
const { deps, state } = makeDeps();
|
|
428
|
+
state.oneShotImpl = () => Promise.resolve(out);
|
|
429
|
+
await runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps);
|
|
430
|
+
assert.equal(state.committed, undefined, `out=${JSON.stringify(out)}`);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("A4⑥ readMeta null at write time → no commit", async () => {
|
|
435
|
+
const { deps, state } = makeDeps();
|
|
436
|
+
state.meta = null;
|
|
437
|
+
await runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps);
|
|
438
|
+
assert.equal(state.committed, undefined);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("A4⑦ manual rename while one-shot pending still wins", async () => {
|
|
442
|
+
const { deps, state } = makeDeps();
|
|
443
|
+
let release;
|
|
444
|
+
state.oneShotImpl = () => new Promise((resolve) => { release = () => resolve("Late Title"); });
|
|
445
|
+
const flowing = runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps);
|
|
446
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
447
|
+
state.meta.name = "Renamed Mid Flight";
|
|
448
|
+
release();
|
|
449
|
+
await flowing;
|
|
450
|
+
assert.equal(state.committed, undefined);
|
|
451
|
+
assert.equal(state.meta.name, "Renamed Mid Flight");
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("A4⑧ runOneShot rejection propagates out of the flow", async () => {
|
|
455
|
+
const { deps, state } = makeDeps();
|
|
456
|
+
state.oneShotImpl = () => Promise.reject(new Error("spawn fail"));
|
|
457
|
+
await assert.rejects(() => runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps), /spawn fail/);
|
|
458
|
+
assert.equal(state.committed, undefined);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("A4⑨ multiline one-shot output uses only the last line (both paths)", async () => {
|
|
462
|
+
{
|
|
463
|
+
const { deps, state } = makeDeps();
|
|
464
|
+
state.oneShotImpl = () => Promise.resolve("Thinking…\nLast Line Wins");
|
|
465
|
+
await runTitleFlow({ ...baseConfig(), prompt: "fix bug now" }, deps);
|
|
466
|
+
assert.equal(state.meta.name, "Last Line Wins");
|
|
467
|
+
}
|
|
468
|
+
{
|
|
469
|
+
const { deps, state } = makeDeps();
|
|
470
|
+
state.oneShotImpl = () => Promise.resolve("Thinking…\nLast Line Wins");
|
|
471
|
+
deps.readSessionText = () => '{"type":"message","id":"m2","parentId":null,"message":{"role":"user","content":[{"type":"text","text":"deploy api"}]}}\n';
|
|
472
|
+
await runTitleFlow(baseConfig(), deps);
|
|
473
|
+
assert.equal(state.meta.name, "Last Line Wins");
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test("poll constants match the spec", () => {
|
|
478
|
+
assert.equal(TITLE_POLL_INTERVAL_MS, 15000);
|
|
479
|
+
assert.equal(TITLE_POLL_BUDGET_MS, 300000);
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
- [ ] **Step 2: Run test to verify it fails**
|
|
484
|
+
|
|
485
|
+
Run: `node --test test/title-flow.test.mjs`
|
|
486
|
+
Expected: FAIL — module not found.
|
|
487
|
+
|
|
488
|
+
**Binding seam decision:** `deps.runOneShot(prompt)` receives the **raw user prompt**; `titlePrompt()` wrapping happens in the shell's real wiring (Task 6). The flow module does not import `titlePrompt`.
|
|
489
|
+
|
|
490
|
+
- [ ] **Step 3: Implement `src/core/title-flow.mjs`** (new file):
|
|
491
|
+
|
|
492
|
+
```js
|
|
493
|
+
/**
|
|
494
|
+
* Title-generation orchestration with fully injected effects (issue #295).
|
|
495
|
+
* The runner shell owns env resolution and real I/O; this module owns
|
|
496
|
+
* sequencing and the write-back guard so it is unit-testable with a fake clock.
|
|
497
|
+
*/
|
|
498
|
+
import { firstSubstantiveUserPrompt, isGreetingPrompt, normalizeGeneratedTitle } from "./title.mjs";
|
|
499
|
+
|
|
500
|
+
/** Default poll interval while waiting for a substantive user message. */
|
|
501
|
+
export const TITLE_POLL_INTERVAL_MS = 15_000;
|
|
502
|
+
|
|
503
|
+
/** Default total budget for the greeting poll loop. */
|
|
504
|
+
export const TITLE_POLL_BUDGET_MS = 300_000;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @typedef {Object} TitleFlowDeps
|
|
508
|
+
* @property {() => number} now
|
|
509
|
+
* @property {(ms: number) => Promise<void>} sleep
|
|
510
|
+
* @property {(root: string, viewId: string) => any|null} readMeta
|
|
511
|
+
* @property {(meta: any) => void} commitMeta
|
|
512
|
+
* @property {(config: any) => string|null} readSessionText
|
|
513
|
+
* @property {(prompt: string) => Promise<string|null>} runOneShot
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Generate a title for a view. Non-greeting prompts generate immediately
|
|
518
|
+
* (today's behavior). Greeting prompts poll the session file for the first
|
|
519
|
+
* substantive user message until the budget runs out, then exit quietly.
|
|
520
|
+
* @param {import("./types.mjs").TitleConfig} config
|
|
521
|
+
* @param {TitleFlowDeps} deps
|
|
522
|
+
*/
|
|
523
|
+
export async function runTitleFlow(config, deps) {
|
|
524
|
+
if (!isGreetingPrompt(config.prompt)) {
|
|
525
|
+
await generateOnce(config, deps, config.prompt);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const interval = config.pollIntervalMs ?? TITLE_POLL_INTERVAL_MS;
|
|
529
|
+
const deadline = deps.now() + (config.pollBudgetMs ?? TITLE_POLL_BUDGET_MS);
|
|
530
|
+
while (deps.now() < deadline) {
|
|
531
|
+
await deps.sleep(interval);
|
|
532
|
+
const text = deps.readSessionText(config);
|
|
533
|
+
const prompt = text ? firstSubstantiveUserPrompt(text) : null;
|
|
534
|
+
if (prompt) {
|
|
535
|
+
await generateOnce(config, deps, prompt);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* One guarded title generation: last-line extraction, normalize, fallback-only
|
|
543
|
+
* write (manual renames always win — meta is re-read right before the guard).
|
|
544
|
+
* @param {import("./types.mjs").TitleConfig} config
|
|
545
|
+
* @param {TitleFlowDeps} deps
|
|
546
|
+
* @param {string} prompt
|
|
547
|
+
*/
|
|
548
|
+
async function generateOnce(config, deps, prompt) {
|
|
549
|
+
const out = await deps.runOneShot(prompt);
|
|
550
|
+
const last = out?.trim().split("\n").slice(-1)[0]?.trim() ?? "";
|
|
551
|
+
const title = normalizeGeneratedTitle(last, config.fallbackName);
|
|
552
|
+
if (!title || title === config.fallbackName) return;
|
|
553
|
+
const meta = deps.readMeta(config.root, config.viewId);
|
|
554
|
+
if (!meta) return;
|
|
555
|
+
if (meta.name !== config.fallbackName) return;
|
|
556
|
+
meta.name = title;
|
|
557
|
+
deps.commitMeta(meta);
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
- [ ] **Step 4: Run test to verify it passes**
|
|
562
|
+
|
|
563
|
+
Run: `node --test test/title-flow.test.mjs`
|
|
564
|
+
Expected: PASS (10 tests).
|
|
565
|
+
|
|
566
|
+
- [ ] **Step 5: Commit**
|
|
567
|
+
|
|
568
|
+
```bash
|
|
569
|
+
git add src/core/title-flow.mjs test/title-flow.test.mjs
|
|
570
|
+
git commit -m "feat: add greeting-aware title flow with injected effects (issue #295)"
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
### Task 6: Runner shell rewiring + hermetic smoke [A6]
|
|
576
|
+
|
|
577
|
+
**Files:**
|
|
578
|
+
- Modify: `runner/title-runner.mjs`
|
|
579
|
+
- Modify: `src/core/types.mjs` (TitleConfig JSDoc: optional `pollIntervalMs`/`pollBudgetMs`)
|
|
580
|
+
- Create: `test-support/fake-title-pi.mjs`
|
|
581
|
+
- Create: `test/title-runner-smoke.test.mjs`
|
|
582
|
+
|
|
583
|
+
**Interfaces:**
|
|
584
|
+
- Consumes: `runTitleFlow` (+constants) from `../src/core/title-flow.mjs`; `resolveTitleSettings`, `titlePrompt` from `../src/core/title.mjs`; `readMeta`/`writeMeta` from `../src/core/store.mjs`.
|
|
585
|
+
- Produces: `TitleConfig` gains `pollIntervalMs?: number` and `pollBudgetMs?: number` (JSDoc, optional, test-only setters — service never sets them).
|
|
586
|
+
|
|
587
|
+
- [ ] **Step 1: Create the fixture `test-support/fake-title-pi.mjs`**
|
|
588
|
+
|
|
589
|
+
```js
|
|
590
|
+
#!/usr/bin/env node
|
|
591
|
+
/**
|
|
592
|
+
* Hermetic stand-in for `pi --mode json -p` in title-runner smoke tests
|
|
593
|
+
* (issue #295). Prints one assistant message_end whose text echoes the task
|
|
594
|
+
* from the titlePrompt payload ("T: <task>"), writes a marker file when
|
|
595
|
+
* invoked, then exits 0.
|
|
596
|
+
*/
|
|
597
|
+
import { appendFileSync } from "node:fs";
|
|
598
|
+
|
|
599
|
+
const argv = process.argv.slice(2);
|
|
600
|
+
const taskIdx = argv.lastIndexOf("--");
|
|
601
|
+
const payload = argv[argv.length - 1] ?? "";
|
|
602
|
+
const match = /Task: (.*)$/m.exec(payload);
|
|
603
|
+
const task = match ? match[1].trim() : "unknown";
|
|
604
|
+
if (process.env.FAKE_TITLE_PI_MARKER) {
|
|
605
|
+
try { appendFileSync(process.env.FAKE_TITLE_PI_MARKER, "called\n"); } catch { /* best effort */ }
|
|
606
|
+
}
|
|
607
|
+
console.log(JSON.stringify({ type: "message_end", message: { role: "assistant", content: [{ type: "text", text: `T: ${task}` }] } }));
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
(`taskIdx` is unused — drop that line.)
|
|
611
|
+
|
|
612
|
+
- [ ] **Step 2: Write the failing smoke tests `test/title-runner-smoke.test.mjs`**
|
|
613
|
+
|
|
614
|
+
```js
|
|
615
|
+
import assert from "node:assert/strict";
|
|
616
|
+
import { spawnSync } from "node:child_process";
|
|
617
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
618
|
+
import { tmpdir } from "node:os";
|
|
619
|
+
import { join } from "node:path";
|
|
620
|
+
import test from "node:test";
|
|
621
|
+
import { atomicWriteJson } from "../src/core/atomic.mjs";
|
|
622
|
+
import { metaPath, sessionFilePath, titleConfigPath, viewDir } from "../src/core/paths.mjs";
|
|
623
|
+
|
|
624
|
+
const ROOT_DIR = join(import.meta.dirname, "..");
|
|
625
|
+
const RUNNER = join(ROOT_DIR, "runner", "title-runner.mjs");
|
|
626
|
+
const FAKE_PI = join(ROOT_DIR, "test-support", "fake-title-pi.mjs");
|
|
627
|
+
|
|
628
|
+
function freshRoot() { return mkdtempSync(join(tmpdir(), "agentview-title-smoke-")); }
|
|
629
|
+
|
|
630
|
+
function seedView(root, { prompt, name, sessionLines, extra = {} }) {
|
|
631
|
+
const viewId = "view_smoke";
|
|
632
|
+
mkdirSync(viewDir(root, viewId), { recursive: true });
|
|
633
|
+
writeFileSync(metaPath(root, viewId), JSON.stringify({ id: viewId, name, cwd: root, sessionFile: sessionFilePath(root, viewId) }));
|
|
634
|
+
if (sessionLines) {
|
|
635
|
+
mkdirSync(join(root, "sessions"), { recursive: true });
|
|
636
|
+
writeFileSync(sessionFilePath(root, viewId), sessionLines);
|
|
637
|
+
}
|
|
638
|
+
atomicWriteJson(titleConfigPath(root, viewId), {
|
|
639
|
+
root, viewId, cwd: root, prompt, fallbackName: name,
|
|
640
|
+
piCommand: process.execPath, piArgsPrefix: [FAKE_PI], model: null, ...extra,
|
|
641
|
+
});
|
|
642
|
+
return viewId;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function runRunner(root, viewId, env = {}) {
|
|
646
|
+
return spawnSync(process.execPath, [RUNNER, titleConfigPath(root, viewId)], {
|
|
647
|
+
env: { ...process.env, FAKE_TITLE_PI_MARKER: join(root, "marker"), ...env },
|
|
648
|
+
timeout: 20000,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const substantiveJsonl = [
|
|
653
|
+
JSON.stringify({ type: "session", id: "s", cwd: "/r" }),
|
|
654
|
+
JSON.stringify({ type: "message", id: "m1", parentId: null, message: { role: "user", content: [{ type: "text", text: "hello" }] } }),
|
|
655
|
+
JSON.stringify({ type: "message", id: "m2", parentId: "m1", message: { role: "user", content: [{ type: "text", text: "deploy api" }] } }),
|
|
656
|
+
].join("\n") + "\n";
|
|
657
|
+
|
|
658
|
+
test("A6① non-greeting prompt generates immediately via the real runner", () => {
|
|
659
|
+
const root = freshRoot();
|
|
660
|
+
try {
|
|
661
|
+
const viewId = seedView(root, { prompt: "fix bug now", name: "fix-bug-now" });
|
|
662
|
+
const res = runRunner(root, viewId);
|
|
663
|
+
assert.equal(res.status, 0);
|
|
664
|
+
const meta = JSON.parse(readFileSync(metaPath(root, viewId), "utf8"));
|
|
665
|
+
assert.equal(meta.name, "T: fix bug now");
|
|
666
|
+
assert.ok(existsSync(join(root, "marker")));
|
|
667
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
test("A6② greeting prompt polls and titles from the substantive message", () => {
|
|
671
|
+
const root = freshRoot();
|
|
672
|
+
try {
|
|
673
|
+
const viewId = seedView(root, { prompt: "hello", name: "slug-name", sessionLines: substantiveJsonl, extra: { pollIntervalMs: 50, pollBudgetMs: 5000 } });
|
|
674
|
+
const res = runRunner(root, viewId);
|
|
675
|
+
assert.equal(res.status, 0);
|
|
676
|
+
const meta = JSON.parse(readFileSync(metaPath(root, viewId), "utf8"));
|
|
677
|
+
assert.equal(meta.name, "T: deploy api");
|
|
678
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
test("A6③ off (board and legacy) exits without model call or rename", () => {
|
|
682
|
+
for (const env of [{ AGENT_BOARD_TITLE_MODEL: "off" }, { AGENT_VIEW_TITLE_MODEL: "off" }]) {
|
|
683
|
+
const root = freshRoot();
|
|
684
|
+
try {
|
|
685
|
+
const viewId = seedView(root, { prompt: "fix bug now", name: "keep-me" });
|
|
686
|
+
const res = runRunner(root, viewId, env);
|
|
687
|
+
assert.equal(res.status, 0);
|
|
688
|
+
const meta = JSON.parse(readFileSync(metaPath(root, viewId), "utf8"));
|
|
689
|
+
assert.equal(meta.name, "keep-me");
|
|
690
|
+
assert.equal(existsSync(join(root, "marker")), false, JSON.stringify(env));
|
|
691
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
- [ ] **Step 3: Run to verify A6② fails on the old runner**
|
|
697
|
+
|
|
698
|
+
Run: `node --test test/title-runner-smoke.test.mjs`
|
|
699
|
+
Expected: A6① and A6③ PASS; **A6② FAIL** — the old runner titles the greeting itself (`meta.name === "T: hello"`).
|
|
700
|
+
|
|
701
|
+
- [ ] **Step 4: Rewire `runner/title-runner.mjs`**
|
|
702
|
+
|
|
703
|
+
Replace the body (keep the header comment, update it to mention the greeting poll) with:
|
|
704
|
+
|
|
705
|
+
```js
|
|
706
|
+
#!/usr/bin/env node
|
|
707
|
+
/**
|
|
708
|
+
* Detached title-runner shim (issue #295): non-greeting prompts generate a
|
|
709
|
+
* title immediately (previous behavior); greeting prompts poll the session
|
|
710
|
+
* file for the first substantive user message. Best-effort only — the manual
|
|
711
|
+
* rename always wins. All orchestration lives in src/core/title-flow.mjs.
|
|
712
|
+
*/
|
|
713
|
+
import { spawn } from "node:child_process";
|
|
714
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
715
|
+
import { readJson } from "../src/core/atomic.mjs";
|
|
716
|
+
import { readMeta, writeMeta } from "../src/core/store.mjs";
|
|
717
|
+
import { runTitleFlow } from "../src/core/title-flow.mjs";
|
|
718
|
+
import { resolveTitleSettings, titlePrompt } from "../src/core/title.mjs";
|
|
719
|
+
|
|
720
|
+
function main() {
|
|
721
|
+
const configPath = process.argv[2];
|
|
722
|
+
if (!configPath) process.exit(2);
|
|
723
|
+
/** @type {import("../src/core/types.mjs").TitleConfig|null} */
|
|
724
|
+
const config = readJson(configPath, null);
|
|
725
|
+
if (!config?.viewId || !config.prompt) process.exit(2);
|
|
726
|
+
|
|
727
|
+
const settings = resolveTitleSettings(process.env, config.model);
|
|
728
|
+
if (!settings.enabled) return;
|
|
729
|
+
|
|
730
|
+
runTitleFlow(config, realDeps(config, settings))
|
|
731
|
+
.catch(() => {})
|
|
732
|
+
.finally(() => process.exit(0));
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* @param {import("../src/core/types.mjs").TitleConfig} config
|
|
737
|
+
* @param {{ enabled: boolean, model: string, thinking: string }} settings
|
|
738
|
+
*/
|
|
739
|
+
function realDeps(config, settings) {
|
|
740
|
+
return {
|
|
741
|
+
now: () => Date.now(),
|
|
742
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
743
|
+
readMeta: (root, viewId) => readMeta(root, viewId),
|
|
744
|
+
commitMeta: (meta) => writeMeta(config.root, meta),
|
|
745
|
+
readSessionText: () => {
|
|
746
|
+
const meta = readMeta(config.root, config.viewId);
|
|
747
|
+
if (!meta?.sessionFile) return null;
|
|
748
|
+
return existsSync(meta.sessionFile) ? readFileSync(meta.sessionFile, "utf8") : null;
|
|
749
|
+
},
|
|
750
|
+
runOneShot: (prompt) => {
|
|
751
|
+
const args = [...(config.piArgsPrefix ?? []), "--mode", "json", "-p", "--no-session", "--model", settings.model];
|
|
752
|
+
if (settings.thinking && settings.thinking !== "off") args.push("--thinking", settings.thinking);
|
|
753
|
+
args.push(titlePrompt(prompt));
|
|
754
|
+
return runOneShot(config.piCommand, args, 15000);
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function runOneShot(command, args, timeoutMs = 20000) {
|
|
760
|
+
// … keep the existing implementation verbatim (spawn, JSON line scan, timeout) …
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
main();
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
Keep the existing `runOneShot` function exactly as it is today. Delete the old `maybeGenerateTitle`. Also update `src/core/types.mjs` `TitleConfig` JSDoc: add
|
|
767
|
+
|
|
768
|
+
```js
|
|
769
|
+
* Optional poll tuning for tests; production never sets these (issue #295).
|
|
770
|
+
* @property {number} [pollIntervalMs]
|
|
771
|
+
* @property {number} [pollBudgetMs]
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
inside the existing `@typedef {Object} TitleConfig` block.
|
|
775
|
+
|
|
776
|
+
- [ ] **Step 5: Run all title tests**
|
|
777
|
+
|
|
778
|
+
Run: `node --test test/title.test.mjs test/title-flow.test.mjs test/title-runner-smoke.test.mjs`
|
|
779
|
+
Expected: PASS.
|
|
780
|
+
|
|
781
|
+
- [ ] **Step 6: Commit**
|
|
782
|
+
|
|
783
|
+
```bash
|
|
784
|
+
git add runner/title-runner.mjs src/core/types.mjs test-support/fake-title-pi.mjs test/title-runner-smoke.test.mjs
|
|
785
|
+
git commit -m "feat: greeting-aware title runner with hermetic smoke tests (issue #295)"
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
---
|
|
789
|
+
|
|
790
|
+
### Task 7: Full verification [A7, A8]
|
|
791
|
+
|
|
792
|
+
**Files:** none (verification only; fix fallout if any)
|
|
793
|
+
|
|
794
|
+
- [ ] **Step 1: Typecheck**
|
|
795
|
+
|
|
796
|
+
Run: `npm run typecheck`
|
|
797
|
+
Expected: 0 errors. If TS complains about the new `.mjs` exports (allowJs inference), add JSDoc `@typedef`/`@param` annotations per the existing files' style (known repo gotcha: `.mjs` option-object params only infer destructured-with-default properties — annotate explicitly).
|
|
798
|
+
|
|
799
|
+
- [ ] **Step 2: Full suite**
|
|
800
|
+
|
|
801
|
+
Run: `npm test`
|
|
802
|
+
Expected: all green (includes the new files and every pre-existing test).
|
|
803
|
+
|
|
804
|
+
- [ ] **Step 3: Verify gate (worktree has node_modules symlinked to the main checkout)**
|
|
805
|
+
|
|
806
|
+
Run: `npm run verify`
|
|
807
|
+
Expected: typecheck + perf gate + tests + coverage (lines 85 / funcs 80 / branches 70) + pack:dry all pass. If coverage dips on new branches, add cases in the existing new test files (not new files).
|
|
808
|
+
|
|
809
|
+
- [ ] **Step 4: Commit any fixes** (conventional subject, e.g. `fix: ...` or `test: ...`).
|
|
810
|
+
|
|
811
|
+
---
|
|
812
|
+
|
|
813
|
+
### Task 8 (post-merge, user-executed): U1 manual verification [U1]
|
|
814
|
+
|
|
815
|
+
Not implementable in the worktree — U1 verifies the deployed checkout. When the PR is merged:
|
|
816
|
+
|
|
817
|
+
1. `git -C ~/.pi/agent/git/github.com/zhuxixi/pi-agent-board pull --ff-only` (the checkout Pi actually loads; record SHA).
|
|
818
|
+
2. Fully exit and restart Pi.
|
|
819
|
+
3. Title-model health check: `pi --mode json -p --no-session --model openai-codex/gpt-5.5 'Reply with: ok'` → exit 0, assistant `message_end`, then `agent_end`, no auth errors.
|
|
820
|
+
4. The four U1 scenarios from the spec (greeting→substantive→~30s title; immediate non-greeting; rename-during-window wins; greeting-only keeps slug).
|
|
821
|
+
|
|
822
|
+
Record results back on issue #295.
|
|
823
|
+
|
|
824
|
+
---
|
|
825
|
+
|
|
826
|
+
## Acceptance ↔ Task traceability
|
|
827
|
+
|
|
828
|
+
| ID | Task(s) |
|
|
829
|
+
|---|---|
|
|
830
|
+
| A1 | Task 2 |
|
|
831
|
+
| A2 | Task 4 |
|
|
832
|
+
| A3 | Task 1 |
|
|
833
|
+
| A4 | Task 5 |
|
|
834
|
+
| A5 | Task 3 |
|
|
835
|
+
| A6 | Task 6 |
|
|
836
|
+
| A7 | Task 7 |
|
|
837
|
+
| A8 | Task 7 |
|
|
838
|
+
| U1 | Task 8 (post-merge) |
|