pi-odd-worktree 3.13.0 → 3.15.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/README.md +1 -0
- package/extensions/odd-worktree-tools.ts +217 -28
- package/lib/alert-mode.js +82 -0
- package/lib/alert-rows.js +82 -0
- package/lib/odd-rail-section.js +21 -0
- package/lib/odd-view.js +85 -21
- package/lib/opencode-usage.js +256 -0
- package/lib/peak-labels.js +64 -0
- package/lib/peak-providers.js +63 -0
- package/lib/peak-schedule.js +242 -0
- package/lib/session-auto-name.js +144 -160
- package/package.json +1 -1
- package/tools/alert-mode.test.js +140 -0
- package/tools/alert-rows.test.js +196 -0
- package/tools/commands.test.js +4 -3
- package/tools/odd-panel-wiring.test.js +71 -33
- package/tools/odd-rail-section.test.js +66 -4
- package/tools/odd-view.test.js +119 -31
- package/tools/opencode-usage-alert.test.js +252 -0
- package/tools/opencode-usage-lifecycle.test.js +110 -0
- package/tools/opencode-usage.test.js +321 -0
- package/tools/peak-labels.test.js +111 -0
- package/tools/peak-providers.test.js +109 -0
- package/tools/peak-schedule.test.js +423 -0
- package/tools/session-auto-name-wiring.test.js +159 -0
- package/tools/session-auto-name.test.js +342 -0
package/lib/session-auto-name.js
CHANGED
|
@@ -1,66 +1,82 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// Automatic session naming from the ODD document being written
|
|
3
|
-
// (odd/tasks/session-auto-name.md, D2-D7).
|
|
2
|
+
// Automatic session naming from the ODD document being written.
|
|
4
3
|
//
|
|
5
|
-
// Pure derivation, no I/O: the caller passes what a tool call touched,
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// session alone".
|
|
4
|
+
// Pure derivation, no I/O: the caller passes what a tool call touched, whether that
|
|
5
|
+
// call was a write, and the names the session already wrote, and gets back either the
|
|
6
|
+
// label to write or `null` for "leave the session alone".
|
|
9
7
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
// may later update.
|
|
8
|
+
// THE NAME IS THE ODD'S OWN NAME (D2). Writing `odd/tasks/prompt-card-fix.md` names
|
|
9
|
+
// the session `Prompt card fix`: the separators a feature name uses (`-`, `_`, and
|
|
10
|
+
// the `/` of a nested feature) become spaces, the first letter is capitalized, the
|
|
11
|
+
// rest of the name is left exactly as the document named it, and the result is cut
|
|
12
|
+
// at a word boundary when it is too long to read at a glance. Prose INSIDE the
|
|
13
|
+
// document never names the session: a document's own heading is its author's
|
|
14
|
+
// sentence, not the ODD's identity, and reading it made the name depend on a file
|
|
15
|
+
// read that a not-yet-created document does not have.
|
|
19
16
|
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
17
|
+
// EVERY WRITE RE-NAMES (D3): the label is derived on each `write`/`edit` that lands on
|
|
18
|
+
// an `odd/tasks/*.md` document, so a session that moves on to another ODD is renamed
|
|
19
|
+
// to that ODD. Reading is context gathering and never renames (D6).
|
|
20
|
+
//
|
|
21
|
+
// NEVER CLOBBER A HUMAN (D4). The channel is the session NAME (`setSessionName`); a
|
|
22
|
+
// name the plugin cannot account for was typed by a person and is untouchable. The
|
|
23
|
+
// plugin may write only an empty name, or one it can PROVE it produced:
|
|
24
|
+
// (a) the label this session already applied (in-memory, per session);
|
|
25
|
+
// (b) the label of the document being written right now;
|
|
26
|
+
// (c) the label of any ODD this session already wrote — the durable record of
|
|
27
|
+
// touches (`odd-worktree.odd-touch`) hands those names in, which is what makes
|
|
28
|
+
// the proof survive a resume (D5) without storing a second thing; or
|
|
29
|
+
// (d) a name an earlier version of this plugin wrote: the plain dashed slug
|
|
30
|
+
// (`prompt-card-fix`) or the same slug with a branch suffix
|
|
31
|
+
// (`prompt-card-fix @ feat/prompt-card-fix`).
|
|
32
|
+
// Anything else is a human's name. The admitted consequence is that a human who names
|
|
33
|
+
// a session exactly like an ODD they themselves wrote stops owning that name.
|
|
34
|
+
//
|
|
35
|
+
// There is no branch in the name (the user's decision): two forks of the same ODD
|
|
36
|
+
// share a label, and the session file, not the name, is what tells them apart.
|
|
23
37
|
//
|
|
24
38
|
// Input rels are the canonical `odd/<rel>` names the worktree capture already
|
|
25
|
-
// produces, never raw filesystem paths: mapping a path to a document is path
|
|
26
|
-
//
|
|
39
|
+
// produces, never raw filesystem paths: mapping a path to a document is path logic
|
|
40
|
+
// that lives in one place already.
|
|
27
41
|
|
|
28
|
-
// Document shape that names a session: `odd/tasks/<feature>.md`, where the
|
|
29
|
-
//
|
|
42
|
+
// Document shape that names a session: `odd/tasks/<feature>.md`, where the feature
|
|
43
|
+
// may be nested (`odd/tasks/perf/plan.md`).
|
|
30
44
|
const ODD_TASKS_PREFIX = 'odd/tasks/';
|
|
31
45
|
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
// they are what distinguishes the label from a human `fix@home`.
|
|
35
|
-
const BRANCH_SEPARATOR = ' @ ';
|
|
36
|
-
|
|
37
|
-
// A heading-sized label beyond this loses the rest of the words, cut at the
|
|
38
|
-
// last word boundary so the name stays readable at a glance.
|
|
46
|
+
// A label beyond this loses the rest of the words, cut at the last word boundary so
|
|
47
|
+
// the name stays readable at a glance.
|
|
39
48
|
const LABEL_MAX_CHARS = 48;
|
|
40
49
|
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
50
|
+
// The separator the branch suffix of an EARLIER version used. It is never written any
|
|
51
|
+
// more; it is recognized so a resumed session renamed by that version is still
|
|
52
|
+
// adoptable (D4d).
|
|
53
|
+
const LEGACY_BRANCH_SEPARATOR = ' @ ';
|
|
54
|
+
|
|
55
|
+
// gentle-pi's ODD phase tool. Its result says WHICH phase the session moved to, never
|
|
56
|
+
// WHICH feature it is about, so the phase trigger cannot derive anything: it
|
|
57
|
+
// re-applies what the session last derived from a write. It is observable only as a
|
|
58
|
+
// `tool_result`, not a host event.
|
|
45
59
|
const ODD_PHASE_TOOL_NAME = 'gentle_odd_phase';
|
|
46
60
|
|
|
47
|
-
// A
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
// unusual-but-legal character
|
|
51
|
-
// label on the next event, or a resumed session would freeze on it forever.
|
|
61
|
+
// A feature is one or more `/`-separated segments using the characters a document
|
|
62
|
+
// filename can carry, without whitespace. A branch is any whitespace-free token —
|
|
63
|
+
// permissive on purpose, because a branch of an earlier version's suffix may carry an
|
|
64
|
+
// unusual-but-legal character and must still be recognized as OUR label.
|
|
52
65
|
const FEATURE_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
53
66
|
const BRANCH_TOKEN = /^\S+$/;
|
|
54
67
|
|
|
55
|
-
// The
|
|
56
|
-
//
|
|
57
|
-
|
|
68
|
+
// The separators a feature name uses as word boundaries. `/` is the nested-feature
|
|
69
|
+
// separator and reads as a word break like the others.
|
|
70
|
+
const WORD_SEPARATORS = /[/_-]+/g;
|
|
71
|
+
|
|
72
|
+
// The tools whose call WRITES a document. Reading is context gathering: it would make
|
|
73
|
+
// the name jump to whatever was opened last (D6), so `read` is deliberately absent.
|
|
58
74
|
const WRITE_TOOL_NAMES = new Set(['write', 'edit']);
|
|
59
75
|
|
|
60
|
-
// The last
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
76
|
+
// The last label each session applied, keyed by session id. In-module so the phase
|
|
77
|
+
// trigger stays testable without the extension, and bounded so a long-lived process
|
|
78
|
+
// that sees many sessions cannot grow without limit; only the most recent sessions
|
|
79
|
+
// can still be alive and resumed.
|
|
64
80
|
const SESSION_MEMORY_LIMIT = 100;
|
|
65
81
|
const lastLabelBySession = new Map();
|
|
66
82
|
|
|
@@ -68,13 +84,13 @@ function sessionKey(sessionId) {
|
|
|
68
84
|
return typeof sessionId === 'string' && sessionId.length > 0 ? sessionId : null;
|
|
69
85
|
}
|
|
70
86
|
|
|
71
|
-
function rememberLabel(sessionId,
|
|
87
|
+
function rememberLabel(sessionId, label) {
|
|
72
88
|
const key = sessionKey(sessionId);
|
|
73
89
|
if (key === null) return;
|
|
74
|
-
// Re-inserting moves the session to the young end of the insertion order,
|
|
75
|
-
//
|
|
90
|
+
// Re-inserting moves the session to the young end of the insertion order, so
|
|
91
|
+
// eviction always drops the least recently written session.
|
|
76
92
|
lastLabelBySession.delete(key);
|
|
77
|
-
lastLabelBySession.set(key,
|
|
93
|
+
lastLabelBySession.set(key, label);
|
|
78
94
|
while (lastLabelBySession.size > SESSION_MEMORY_LIMIT) {
|
|
79
95
|
const oldest = lastLabelBySession.keys().next().value;
|
|
80
96
|
lastLabelBySession.delete(oldest);
|
|
@@ -91,9 +107,9 @@ function isWriteToolName(name) {
|
|
|
91
107
|
return typeof name === 'string' && WRITE_TOOL_NAMES.has(name);
|
|
92
108
|
}
|
|
93
109
|
|
|
94
|
-
// `<feature>` for an `odd/tasks/<feature>.md` rel, else null. Rejects empty
|
|
95
|
-
//
|
|
96
|
-
//
|
|
110
|
+
// `<feature>` for an `odd/tasks/<feature>.md` rel, else null. Rejects empty segments,
|
|
111
|
+
// nested `.`/`..`, and any name carrying whitespace or characters a feature document
|
|
112
|
+
// cannot have.
|
|
97
113
|
function featureFromOddRel(rel) {
|
|
98
114
|
if (typeof rel !== 'string' || rel.length === 0) return null;
|
|
99
115
|
if (!rel.startsWith(ODD_TASKS_PREFIX)) return null;
|
|
@@ -108,8 +124,8 @@ function featureFromOddRel(rel) {
|
|
|
108
124
|
return feature;
|
|
109
125
|
}
|
|
110
126
|
|
|
111
|
-
// The first `odd/tasks/<feature>.md` document of the call, or null. The
|
|
112
|
-
//
|
|
127
|
+
// The first `odd/tasks/<feature>.md` document of the call, or null. The first one wins
|
|
128
|
+
// because a multi-document write has no natural order.
|
|
113
129
|
function firstTaskDocument(rels) {
|
|
114
130
|
if (!Array.isArray(rels)) return null;
|
|
115
131
|
for (const rel of rels) {
|
|
@@ -119,9 +135,9 @@ function firstTaskDocument(rels) {
|
|
|
119
135
|
return null;
|
|
120
136
|
}
|
|
121
137
|
|
|
122
|
-
// Cut to `max` characters at the last word boundary inside the cut, so a
|
|
123
|
-
//
|
|
124
|
-
//
|
|
138
|
+
// Cut to `max` characters at the last word boundary inside the cut, so a truncated
|
|
139
|
+
// label ends with a whole word. A single word longer than `max` has no boundary and is
|
|
140
|
+
// cut hard; anything short stays untouched.
|
|
125
141
|
function truncateLabel(text, max) {
|
|
126
142
|
if (text.length <= max) return text;
|
|
127
143
|
const slice = text.slice(0, max);
|
|
@@ -129,54 +145,30 @@ function truncateLabel(text, max) {
|
|
|
129
145
|
return lastSpace > 0 ? slice.slice(0, lastSpace) : slice;
|
|
130
146
|
}
|
|
131
147
|
|
|
132
|
-
// The
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
function
|
|
137
|
-
if (typeof
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (!/^#[ \t]/.test(line)) continue;
|
|
143
|
-
const body = line.slice(1).trim();
|
|
144
|
-
if (body.length === 0) continue;
|
|
145
|
-
return truncateLabel(body.replace(/\s+/g, ' '), LABEL_MAX_CHARS);
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// The label head for a document: its heading when there is one, else the
|
|
151
|
-
// filename slug. Deterministic for the same document, which is what keeps
|
|
152
|
-
// repeated events idempotent.
|
|
153
|
-
function labelHeadForDocument(feature, text) {
|
|
154
|
-
const heading = headingFromText(text);
|
|
155
|
-
return heading !== null ? heading : feature;
|
|
148
|
+
// The session label for an ODD feature name (D2): separators become spaces, the run
|
|
149
|
+
// of spaces collapses, the first letter is capitalized and the rest is left exactly
|
|
150
|
+
// as the document named it. `perf/plan` -> `Perf plan`, `prompt-card-fix` ->
|
|
151
|
+
// `Prompt card fix`. An empty name yields no label; nothing is invented.
|
|
152
|
+
function labelFromFeature(feature) {
|
|
153
|
+
if (typeof feature !== 'string' || feature.length === 0) return null;
|
|
154
|
+
const words = feature.replace(WORD_SEPARATORS, ' ').replace(/\s+/g, ' ').trim();
|
|
155
|
+
if (words.length === 0) return null;
|
|
156
|
+
const sentence = words.charAt(0).toUpperCase() + words.slice(1);
|
|
157
|
+
return truncateLabel(sentence, LABEL_MAX_CHARS);
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// D4: the branch suffix is what keeps two concurrent forks of the same
|
|
172
|
-
// feature apart, since the worktree branch is already unique. A branch the
|
|
173
|
-
// caller cannot supply (an odd registry entry without one) degrades to the
|
|
174
|
-
// bare label head, which is still a label the plugin owns.
|
|
175
|
-
function sessionNameForFeature(feature, branch) {
|
|
176
|
-
if (typeof branch === 'string' && BRANCH_TOKEN.test(branch)) {
|
|
177
|
-
return `${feature}${BRANCH_SEPARATOR}${branch}`;
|
|
160
|
+
// The labels of the ODDs this session already wrote, as handed in from the durable
|
|
161
|
+
// touch record (`oddSession.touched()` names). Malformed and unusable entries are
|
|
162
|
+
// skipped: a durable record that cannot be read leaves the ownership test with less
|
|
163
|
+
// evidence, never with a wrong answer.
|
|
164
|
+
function sessionLabelsFrom(touchedNames) {
|
|
165
|
+
if (!Array.isArray(touchedNames)) return [];
|
|
166
|
+
const out = [];
|
|
167
|
+
for (const name of touchedNames) {
|
|
168
|
+
const label = labelFromFeature(name);
|
|
169
|
+
if (label !== null && !out.includes(label)) out.push(label);
|
|
178
170
|
}
|
|
179
|
-
return
|
|
171
|
+
return out;
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
function isFeatureName(name) {
|
|
@@ -185,108 +177,100 @@ function isFeatureName(name) {
|
|
|
185
177
|
return segments.every((segment) => segment !== '.' && segment !== '..' && FEATURE_SEGMENT.test(segment));
|
|
186
178
|
}
|
|
187
179
|
|
|
188
|
-
// The ownership test (
|
|
189
|
-
//
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
// (
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
// versions wrote before heading labels existed;
|
|
197
|
-
// (d) it is the document's current heading.
|
|
198
|
-
// Called with no context it keeps the original contract: exactly the two
|
|
199
|
-
// shapes earlier versions wrote (`<feature>` and `<feature> @ <branch>`).
|
|
180
|
+
// The ownership test (D4). A name counts as the plugin's own when ANY of these holds:
|
|
181
|
+
// (a) it is the label this session already applied — what lets the phase trigger
|
|
182
|
+
// reuse it;
|
|
183
|
+
// (b) it is the label of the document being written;
|
|
184
|
+
// (c) it is the label of an ODD this session already wrote (the durable record);
|
|
185
|
+
// (d) an earlier version wrote it: the plain feature slug, or `<slug> @ <branch>`.
|
|
186
|
+
// Anything else was typed by a human. Called with no context it answers exactly what
|
|
187
|
+
// earlier versions of this test answered for those legacy shapes.
|
|
200
188
|
function isPluginSessionName(name, context) {
|
|
201
189
|
if (typeof name !== 'string' || name.length === 0) return false;
|
|
202
|
-
const {
|
|
190
|
+
const { feature, appliedLabel, sessionLabels } = context || {};
|
|
203
191
|
if (typeof appliedLabel === 'string' && appliedLabel.length > 0 && name === appliedLabel) return true;
|
|
204
|
-
if (typeof
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return isFeatureName(name);
|
|
209
|
-
}
|
|
192
|
+
if (typeof feature === 'string' && feature.length > 0 && name === labelFromFeature(feature)) return true;
|
|
193
|
+
if (Array.isArray(sessionLabels) && sessionLabels.includes(name)) return true;
|
|
194
|
+
const at = name.indexOf(LEGACY_BRANCH_SEPARATOR);
|
|
195
|
+
if (at === -1) return isFeatureName(name);
|
|
210
196
|
const head = name.slice(0, at);
|
|
211
|
-
const tail = name.slice(at +
|
|
197
|
+
const tail = name.slice(at + LEGACY_BRANCH_SEPARATOR.length);
|
|
212
198
|
if (head.length === 0 || !BRANCH_TOKEN.test(tail)) return false;
|
|
213
|
-
if (typeof branch === 'string' && branch.length > 0 && tail === branch) return true;
|
|
214
199
|
return isFeatureName(head);
|
|
215
200
|
}
|
|
216
201
|
|
|
217
|
-
// May the plugin write over `name`? An unnamed session (empty, or no name
|
|
218
|
-
//
|
|
219
|
-
//
|
|
202
|
+
// May the plugin write over `name`? An unnamed session (empty, or no name entry at
|
|
203
|
+
// all — `getSessionName()` returns undefined) is adoptable; every other name must be
|
|
204
|
+
// the plugin's own.
|
|
220
205
|
function canAdoptSessionName(name, context) {
|
|
221
206
|
if (name === undefined || name === null) return true;
|
|
222
207
|
if (typeof name !== 'string') return false;
|
|
223
208
|
return name.length === 0 || isPluginSessionName(name, context);
|
|
224
209
|
}
|
|
225
210
|
|
|
226
|
-
// The label for a tool call that touched `rels`, or null when the call is
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
function autoNameForToolCall({ rels, isWrite
|
|
211
|
+
// The label for a tool call that touched `rels`, or null when the call is not a WRITE
|
|
212
|
+
// to an `odd/tasks/<feature>.md` document. No ownership is decided here;
|
|
213
|
+
// `planSessionRename` owns that.
|
|
214
|
+
function autoNameForToolCall({ rels, isWrite } = {}) {
|
|
230
215
|
if (isWrite !== true) return null;
|
|
231
216
|
const match = firstTaskDocument(rels);
|
|
232
217
|
if (match === null) return null;
|
|
233
|
-
|
|
234
|
-
return sessionNameForFeature(head, branch);
|
|
218
|
+
return labelFromFeature(match.feature);
|
|
235
219
|
}
|
|
236
220
|
|
|
237
|
-
// The single decision the write wiring needs. Returns the name to write, or
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
function planSessionRename({ rels, isWrite, branch, currentName, sessionId, readDocument } = {}) {
|
|
221
|
+
// The single decision the write wiring needs. Returns the name to write, or null for
|
|
222
|
+
// "touch nothing", which covers three cases: the call did not write an ODD task
|
|
223
|
+
// document, the current name was chosen by a human, and the derived label is already
|
|
224
|
+
// the current name — the last one is what makes running this on every pipeline event
|
|
225
|
+
// idempotent instead of a stream of host writes. The derived label is remembered per
|
|
226
|
+
// session whether or not it was written, so a later phase transition can re-apply it.
|
|
227
|
+
function planSessionRename({ rels, isWrite, currentName, sessionId, touchedNames } = {}) {
|
|
245
228
|
if (isWrite !== true) return null;
|
|
246
229
|
const match = firstTaskDocument(rels);
|
|
247
230
|
if (match === null) return null;
|
|
248
|
-
const
|
|
249
|
-
|
|
231
|
+
const label = labelFromFeature(match.feature);
|
|
232
|
+
if (label === null) return null;
|
|
250
233
|
const previous = rememberedLabel(sessionId);
|
|
251
234
|
const adoptable = canAdoptSessionName(currentName, {
|
|
252
|
-
branch,
|
|
253
235
|
feature: match.feature,
|
|
254
|
-
|
|
255
|
-
|
|
236
|
+
appliedLabel: previous === null ? undefined : previous,
|
|
237
|
+
sessionLabels: sessionLabelsFrom(touchedNames),
|
|
256
238
|
});
|
|
257
|
-
rememberLabel(sessionId,
|
|
239
|
+
rememberLabel(sessionId, label);
|
|
258
240
|
if (!adoptable || label === currentName) return null;
|
|
259
241
|
return label;
|
|
260
242
|
}
|
|
261
243
|
|
|
262
|
-
// The phase trigger: an ODD phase transition with no feature of its own
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
|
|
244
|
+
// The phase trigger: an ODD phase transition with no feature of its own re-applies the
|
|
245
|
+
// label this session last derived from a write. After a resume there is no in-memory
|
|
246
|
+
// memory, so the newest ODD of the durable touch record stands in — it is the same
|
|
247
|
+
// fact, read from where it survives. Returns null for "touch nothing" when the session
|
|
248
|
+
// never wrote an ODD document, when the current name is a human's, or when the label
|
|
249
|
+
// is already applied.
|
|
250
|
+
function planPhaseSessionRename({ sessionId, currentName, touchedNames } = {}) {
|
|
251
|
+
const sessionLabels = sessionLabelsFrom(touchedNames);
|
|
267
252
|
const previous = rememberedLabel(sessionId);
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
253
|
+
const label = previous !== null ? previous : sessionLabels.length > 0 ? sessionLabels[0] : null;
|
|
254
|
+
if (label === null) return null;
|
|
255
|
+
if (!canAdoptSessionName(currentName, { appliedLabel: previous === null ? undefined : previous, sessionLabels })) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
272
258
|
if (label === currentName) return null;
|
|
273
|
-
rememberLabel(sessionId,
|
|
259
|
+
rememberLabel(sessionId, label);
|
|
274
260
|
return label;
|
|
275
261
|
}
|
|
276
262
|
|
|
277
263
|
module.exports = {
|
|
278
264
|
ODD_TASKS_PREFIX,
|
|
279
|
-
BRANCH_SEPARATOR,
|
|
280
265
|
LABEL_MAX_CHARS,
|
|
266
|
+
LEGACY_BRANCH_SEPARATOR,
|
|
281
267
|
ODD_PHASE_TOOL_NAME,
|
|
282
268
|
autoNameForToolCall,
|
|
283
269
|
featureFromOddRel,
|
|
284
|
-
headingFromText,
|
|
285
270
|
isPluginSessionName,
|
|
286
271
|
canAdoptSessionName,
|
|
287
272
|
isWriteToolName,
|
|
288
|
-
|
|
273
|
+
labelFromFeature,
|
|
289
274
|
planSessionRename,
|
|
290
275
|
planPhaseSessionRename,
|
|
291
|
-
sessionNameForFeature,
|
|
292
276
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S5/S8 (opencode-usage-alert): the stored booleans behind the `Alert` page. ONE boolean
|
|
3
|
+
// per peak provider, all Off by default, in this package's own bridge store
|
|
4
|
+
// (`odd-worktree` → `alerts` → `{ peaks: { [providerId]: boolean } }`). An absent or
|
|
5
|
+
// unparsable document, a missing or throwing store, no bridge at all and an id that was
|
|
6
|
+
// never written all answer Off, and nothing is written until a line is touched. Nothing
|
|
7
|
+
// here loads the extension.
|
|
8
|
+
const { test, describe } = require('node:test');
|
|
9
|
+
const assert = require('node:assert/strict');
|
|
10
|
+
|
|
11
|
+
const alertMode = require('../lib/alert-mode.js');
|
|
12
|
+
|
|
13
|
+
// The two providers the registry declares today; this module is keyed by plain ids and
|
|
14
|
+
// does not import the registry itself.
|
|
15
|
+
const DEEPSEEK = 'deepseek';
|
|
16
|
+
const CLAUDE = 'claude';
|
|
17
|
+
|
|
18
|
+
// A bridge whose `createStore` keeps one in-memory file per plugin id, like the real one.
|
|
19
|
+
function fakeBridge(initial = {}) {
|
|
20
|
+
const files = new Map(Object.entries(initial));
|
|
21
|
+
const writes = [];
|
|
22
|
+
const createStore = (id) => ({
|
|
23
|
+
get: (key, fallback) => (files.get(id)?.[key] !== undefined ? files.get(id)[key] : fallback),
|
|
24
|
+
set: (key, value) => {
|
|
25
|
+
files.set(id, { ...(files.get(id) ?? {}), [key]: value });
|
|
26
|
+
writes.push([id, key, value]);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return { api: { createStore }, files, writes };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('the default', () => {
|
|
33
|
+
test('is Off, exported, and is what a first run reads for every provider', () => {
|
|
34
|
+
assert.equal(alertMode.DEFAULT_PEAK, false);
|
|
35
|
+
const { api } = fakeBridge();
|
|
36
|
+
assert.equal(alertMode.readPeakAlert(api, DEEPSEEK), false);
|
|
37
|
+
assert.equal(alertMode.readPeakAlert(api, CLAUDE), false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('the store key is exported and is the bridge document the switches share', () => {
|
|
41
|
+
assert.equal(alertMode.ALERTS_KEY, 'alerts');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('reading one provider', () => {
|
|
46
|
+
test('Off for an absent document, for every malformed one, and for a document without `peaks`', () => {
|
|
47
|
+
assert.equal(alertMode.readPeakAlert(fakeBridge({ 'odd-worktree': {} }).api, DEEPSEEK), false);
|
|
48
|
+
for (const bad of [null, 42, 'off', [], { peaks: 'no' }, { peaks: 7 }, { peaks: [] }, { peaks: null }]) {
|
|
49
|
+
const { api } = fakeBridge({ 'odd-worktree': { alerts: bad } });
|
|
50
|
+
assert.equal(alertMode.readPeakAlert(api, DEEPSEEK), false, JSON.stringify(bad));
|
|
51
|
+
assert.equal(alertMode.readPeakAlert(api, CLAUDE), false, JSON.stringify(bad));
|
|
52
|
+
}
|
|
53
|
+
assert.equal(alertMode.readPeakAlert(fakeBridge({ 'odd-worktree': { alerts: { other: 1 } } }).api, DEEPSEEK), false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('an id that was never written is Off even when a sibling is On', () => {
|
|
57
|
+
const { api } = fakeBridge({ 'odd-worktree': { alerts: { peaks: { [DEEPSEEK]: true } } } });
|
|
58
|
+
assert.equal(alertMode.readPeakAlert(api, DEEPSEEK), true);
|
|
59
|
+
assert.equal(alertMode.readPeakAlert(api, CLAUDE), false);
|
|
60
|
+
assert.equal(alertMode.readPeakAlert(api, 'anthropic'), false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('each provider answers its own stored boolean', () => {
|
|
64
|
+
for (const peaks of [{ [DEEPSEEK]: false, [CLAUDE]: true }, { [DEEPSEEK]: true, [CLAUDE]: false }]) {
|
|
65
|
+
const { api } = fakeBridge({ 'odd-worktree': { alerts: { peaks } } });
|
|
66
|
+
assert.equal(alertMode.readPeakAlert(api, DEEPSEEK), peaks[DEEPSEEK], JSON.stringify(peaks));
|
|
67
|
+
assert.equal(alertMode.readPeakAlert(api, CLAUDE), peaks[CLAUDE], JSON.stringify(peaks));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('no bridge, no createStore and a throwing store all read Off and never throw', () => {
|
|
72
|
+
for (const api of [null, undefined, {}, 42, { createStore: () => { throw new Error('disk'); } }]) {
|
|
73
|
+
assert.equal(alertMode.readPeakAlert(api, DEEPSEEK), false);
|
|
74
|
+
assert.equal(alertMode.readPeakAlert(api, CLAUDE), false);
|
|
75
|
+
}
|
|
76
|
+
const throwing = { createStore: () => ({ get: () => { throw new Error('disk'); }, set: () => {} }) };
|
|
77
|
+
assert.equal(alertMode.readPeakAlert(throwing, DEEPSEEK), false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('nothing is written on a read, not even the default', () => {
|
|
81
|
+
const bridge = fakeBridge();
|
|
82
|
+
alertMode.readPeakAlert(bridge.api, DEEPSEEK);
|
|
83
|
+
alertMode.readPeakAlert(bridge.api, CLAUDE);
|
|
84
|
+
assert.deepEqual(bridge.writes, []);
|
|
85
|
+
assert.equal(bridge.files.has('odd-worktree'), false, 'no document appears at load');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('writing one provider', () => {
|
|
90
|
+
test('On then Off round-trips under `peaks`, and every read answers the value just written', () => {
|
|
91
|
+
const bridge = fakeBridge();
|
|
92
|
+
assert.equal(alertMode.writePeakAlert(bridge.api, DEEPSEEK, true), true);
|
|
93
|
+
assert.equal(alertMode.readPeakAlert(bridge.api, DEEPSEEK), true);
|
|
94
|
+
assert.deepEqual(bridge.files.get('odd-worktree'), { alerts: { peaks: { [DEEPSEEK]: true } } });
|
|
95
|
+
assert.equal(alertMode.writePeakAlert(bridge.api, DEEPSEEK, false), true);
|
|
96
|
+
assert.equal(alertMode.readPeakAlert(bridge.api, DEEPSEEK), false);
|
|
97
|
+
assert.deepEqual(bridge.files.get('odd-worktree'), { alerts: { peaks: { [DEEPSEEK]: false } } });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('one provider\'s write leaves its sibling id exactly as it was', () => {
|
|
101
|
+
const bridge = fakeBridge({ 'odd-worktree': { alerts: { peaks: { [CLAUDE]: true } } } });
|
|
102
|
+
assert.equal(alertMode.writePeakAlert(bridge.api, DEEPSEEK, true), true);
|
|
103
|
+
assert.equal(alertMode.readPeakAlert(bridge.api, DEEPSEEK), true);
|
|
104
|
+
assert.equal(alertMode.readPeakAlert(bridge.api, CLAUDE), true);
|
|
105
|
+
assert.deepEqual(bridge.files.get('odd-worktree'), {
|
|
106
|
+
alerts: { peaks: { [CLAUDE]: true, [DEEPSEEK]: true } },
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('keeps every sibling key of the store and of the alerts document', () => {
|
|
111
|
+
const bridge = fakeBridge({ 'odd-worktree': { modules: { worktrees: false }, alerts: { other: 7 } } });
|
|
112
|
+
assert.equal(alertMode.writePeakAlert(bridge.api, CLAUDE, true), true);
|
|
113
|
+
assert.deepEqual(bridge.files.get('odd-worktree'), {
|
|
114
|
+
modules: { worktrees: false },
|
|
115
|
+
alerts: { other: 7, peaks: { [CLAUDE]: true } },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('a malformed document is replaced rather than thrown at', () => {
|
|
120
|
+
const bridge = fakeBridge({ 'odd-worktree': { alerts: 'nope', other: 1 } });
|
|
121
|
+
assert.equal(alertMode.writePeakAlert(bridge.api, DEEPSEEK, true), true);
|
|
122
|
+
assert.deepEqual(bridge.files.get('odd-worktree'), { alerts: { peaks: { [DEEPSEEK]: true } }, other: 1 });
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('a write that cannot be kept', () => {
|
|
127
|
+
test('reports false and never throws — a missing bridge, a throwing store, a throwing set', () => {
|
|
128
|
+
for (const api of [null, undefined, {}, 42, { createStore: () => { throw new Error('disk'); } }]) {
|
|
129
|
+
assert.equal(alertMode.writePeakAlert(api, DEEPSEEK, true), false);
|
|
130
|
+
}
|
|
131
|
+
const throwing = { createStore: () => ({ get: (_key, fallback) => fallback, set: () => { throw new Error('read-only'); } }) };
|
|
132
|
+
assert.equal(alertMode.writePeakAlert(throwing, CLAUDE, true), false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('a read after a refused write still answers Off, the way it read before the press', () => {
|
|
136
|
+
const throwing = { createStore: () => ({ get: (_key, fallback) => fallback, set: () => { throw new Error('read-only'); } }) };
|
|
137
|
+
assert.equal(alertMode.writePeakAlert(throwing, DEEPSEEK, true), false);
|
|
138
|
+
assert.equal(alertMode.readPeakAlert(throwing, DEEPSEEK), false);
|
|
139
|
+
});
|
|
140
|
+
});
|