pi-suite 0.3.3 → 0.3.6
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 +22 -3
- package/README.zh-CN.md +22 -3
- package/package.json +1 -1
- package/src/agents/index.ts +7 -4
- package/src/agents/registry.ts +8 -0
- package/src/agents/render.ts +10 -4
- package/src/agents/tools.ts +7 -6
- package/src/agents/viewer-info.ts +1 -1
- package/src/agents/viewer.ts +4 -2
- package/src/agents/workflow/index.ts +2 -2
- package/src/agents/workflow/manager.ts +0 -6
- package/src/agents/workflow/render.ts +1 -1
- package/src/ask/index.ts +4 -2
- package/src/ask/view.ts +7 -3
- package/src/goal/manager.ts +8 -0
- package/src/goal/render.ts +4 -3
- package/src/jobs/index.ts +11 -9
- package/src/jobs/launch/name.ts +5 -0
- package/src/jobs/manager-record.ts +23 -0
- package/src/jobs/manager.ts +6 -17
- package/src/jobs/output.ts +19 -7
- package/src/jobs/query.ts +27 -20
- package/src/jobs/registry.ts +36 -0
- package/src/jobs/render.ts +37 -24
- package/src/jobs/runtime.ts +6 -19
- package/src/jobs/terminal/session.ts +73 -27
- package/src/jobs/tools.ts +10 -7
- package/src/jobs/viewer/component.ts +3 -1
- package/src/jobs/viewer.ts +1 -1
- package/src/notify/index.ts +85 -0
- package/src/runtime/config.ts +5 -0
- package/src/runtime/display-name.ts +10 -0
- package/src/runtime/notifications.ts +6 -1
- package/src/runtime/read.ts +163 -25
- package/src/runtime/suite.ts +17 -6
- package/src/runtime/tools.ts +7 -2
- package/src/runtime/wait-render.ts +10 -11
- package/src/tasks/presentation.ts +5 -0
- package/src/tasks/query.ts +16 -8
- package/src/tasks/viewer.ts +18 -9
- package/src/ui/browser.ts +14 -10
- package/src/ui/details.ts +6 -3
- package/src/ui/dock.ts +6 -1
- package/src/ui/rendering/read-page.ts +2 -1
- package/src/ui/working.ts +11 -0
- package/third-party/UPSTREAM.md +17 -66
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
2
|
+
import type { ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
3
|
+
import { isKeyRelease, parseKey, StdinBuffer, type TUI } from '@earendil-works/pi-tui';
|
|
4
|
+
import type { SuiteConfig } from '../runtime/config.ts';
|
|
5
|
+
|
|
6
|
+
export type FocusInput = Pick<EventEmitter, 'on' | 'off'> & { readonly readableFlowing: boolean | null };
|
|
7
|
+
type Focus = 'unknown' | 'focused' | 'unfocused';
|
|
8
|
+
const WIDGET = 'pi-suite:notify-terminal';
|
|
9
|
+
|
|
10
|
+
/** Writes one BEL when Pi waits for the user while the terminal is known to be in the background. */
|
|
11
|
+
export class CompletionNotifier {
|
|
12
|
+
private focus: Focus = 'unknown';
|
|
13
|
+
private ctx?: ExtensionContext;
|
|
14
|
+
private input?: FocusInput;
|
|
15
|
+
private tui?: TUI;
|
|
16
|
+
private buffer?: StdinBuffer;
|
|
17
|
+
private ownsFocusReporting = false;
|
|
18
|
+
|
|
19
|
+
constructor(private config: () => SuiteConfig['notify'], private source?: FocusInput) {}
|
|
20
|
+
|
|
21
|
+
bind(ctx: ExtensionContext): void {
|
|
22
|
+
this.detach();
|
|
23
|
+
if (ctx.mode !== 'tui') return;
|
|
24
|
+
const input = this.source ?? (process.stdin.isTTY ? process.stdin : undefined);
|
|
25
|
+
if (!input) return;
|
|
26
|
+
this.ctx = ctx; this.input = input;
|
|
27
|
+
input.on('pause', this.stop).on('resume', this.start);
|
|
28
|
+
this.start();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private start = (): void => {
|
|
32
|
+
const { ctx, input } = this;
|
|
33
|
+
if (!ctx || input?.readableFlowing !== true || this.buffer) return;
|
|
34
|
+
// The public widget factory receives the current renderer synchronously. Pi replaces
|
|
35
|
+
// that object on mode changes, so reacquire it after every stdin handoff.
|
|
36
|
+
ctx.ui.setWidget(WIDGET, tui => { this.tui = tui; return { render: () => [], invalidate() {} }; }, { placement: 'belowEditor' });
|
|
37
|
+
ctx.ui.setWidget(WIDGET, undefined);
|
|
38
|
+
if (!this.tui) return;
|
|
39
|
+
this.buffer = new StdinBuffer();
|
|
40
|
+
this.buffer.on('data', this.sequence); // A bracketed paste is emitted separately; its payload is not terminal input events.
|
|
41
|
+
input.on('data', this.observe);
|
|
42
|
+
if (this.tui.mode === 'regular') this.ownsFocusReporting = this.write('\x1b[?1004h');
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
private stop = (): void => {
|
|
46
|
+
this.input?.off('data', this.observe);
|
|
47
|
+
this.buffer?.destroy(); this.buffer = undefined;
|
|
48
|
+
this.focus = 'unknown';
|
|
49
|
+
if (this.ownsFocusReporting && this.tui?.mode === 'regular') this.write('\x1b[?1004l');
|
|
50
|
+
this.ownsFocusReporting = false; this.tui = undefined;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
detach(): void {
|
|
54
|
+
this.input?.off('pause', this.stop).off('resume', this.start);
|
|
55
|
+
this.stop(); this.ctx = undefined; this.input = undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private observe = (chunk: string | Buffer): void => {
|
|
59
|
+
try { this.buffer?.process(chunk); }
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.focus = 'unknown';
|
|
62
|
+
process.emitWarning(`pi-suite focus input: ${String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
private sequence = (data: string): void => {
|
|
67
|
+
if (data === '\x1b[O') { this.focus = 'unfocused'; return; }
|
|
68
|
+
// Ignore mouse/terminal replies and Kitty key releases. Plain Unicode text may
|
|
69
|
+
// have no key identifier, but StdinBuffer still emits it as a single code unit.
|
|
70
|
+
if (data === '\x1b[I' || (!isKeyRelease(data) && (parseKey(data) || data.length === 1 && data.charCodeAt(0) >= 0x80))) {
|
|
71
|
+
this.focus = 'focused';
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Rings once when enabled and the terminal has reported that it lost focus. How it shows is up to the terminal. */
|
|
76
|
+
show(): void {
|
|
77
|
+
if (!this.tui || this.focus !== 'unfocused' || !this.config().enabled) return;
|
|
78
|
+
this.write('\x07');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private write(sequence: string): boolean {
|
|
82
|
+
try { this.tui!.terminal.write(sequence); return true; }
|
|
83
|
+
catch (error) { process.emitWarning(`pi-suite terminal output: ${String(error)}`); return false; }
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/runtime/config.ts
CHANGED
|
@@ -32,6 +32,9 @@ export const configSchema = Type.Object({
|
|
|
32
32
|
}, { additionalProperties: false })),
|
|
33
33
|
goal: Type.Optional(Type.Object({ display: Type.Optional(display) }, { additionalProperties: false })),
|
|
34
34
|
tasks: Type.Optional(Type.Object({ reminders: Type.Optional(Type.Boolean()) }, { additionalProperties: false })),
|
|
35
|
+
notify: Type.Optional(Type.Object({
|
|
36
|
+
enabled: Type.Optional(Type.Boolean()),
|
|
37
|
+
}, { additionalProperties: false })),
|
|
35
38
|
agents: Type.Optional(Type.Object({
|
|
36
39
|
display: Type.Optional(display), maxConcurrent: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
37
40
|
maxConcurrentForeground: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
@@ -63,6 +66,7 @@ export interface SuiteConfig {
|
|
|
63
66
|
ask: { timeout: number; historyKey: KeyId };
|
|
64
67
|
goal: { display: DisplayMode };
|
|
65
68
|
tasks: { reminders: boolean };
|
|
69
|
+
notify: { enabled: boolean };
|
|
66
70
|
agents: { display: DisplayMode; maxConcurrent: number; maxConcurrentForeground: number;
|
|
67
71
|
maxDepth: number; persistSessions: boolean; defaultModel?: string;
|
|
68
72
|
types: Record<string, AgentTypeSettings>; packageAgents?: boolean | string[];
|
|
@@ -79,6 +83,7 @@ export const defaults: SuiteConfig = {
|
|
|
79
83
|
goal: { display: "status" }, agents: { display: "status", maxConcurrent: 10, maxConcurrentForeground: 0,
|
|
80
84
|
maxDepth: 3, persistSessions: true, types: {}, mentions: true, scheduling: true, workflows: true },
|
|
81
85
|
tasks: { reminders: true },
|
|
86
|
+
notify: { enabled: true },
|
|
82
87
|
// tmux intercepts Ctrl+B as its default prefix before the terminal view can see it.
|
|
83
88
|
jobs: { display: "status", detachKey: Key.ctrl(Key.rightbracket), returnKey: "ctrl+g", transferKey: "ctrl+t",
|
|
84
89
|
agents: mergePresets() },
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { agentDisplayName, findWorkflowTask } from '../agents/registry.ts';
|
|
2
|
+
import { jobDisplayName } from '../jobs/registry.ts';
|
|
3
|
+
|
|
4
|
+
/** Renderer-only lookup: consult loaded records without importing execution managers. */
|
|
5
|
+
export function displayNameOf(id: string, runId?: string): string {
|
|
6
|
+
if (id.startsWith('agent_')) return agentDisplayName(id, runId);
|
|
7
|
+
if (id.startsWith('job_')) return jobDisplayName(id);
|
|
8
|
+
if (id.startsWith('wf_')) return findWorkflowTask(id)?.workflowName ?? id;
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
@@ -16,7 +16,9 @@ export class Notifications {
|
|
|
16
16
|
private blockers = new Set<symbol>();
|
|
17
17
|
private admission: (requestIds: string[]) => boolean = () => true;
|
|
18
18
|
private idleTimer?: NodeJS.Timeout;
|
|
19
|
+
private deliveries = 0;
|
|
19
20
|
constructor(private pi: ExtensionAPI, private binding: SessionBinding) {}
|
|
21
|
+
get deliverySequence(): number { return this.deliveries; }
|
|
20
22
|
// Goal checks request IDs so a queued child question can be distinguished from a result.
|
|
21
23
|
setAdmission(admission: (requestIds: string[]) => boolean): void { this.admission = admission; }
|
|
22
24
|
private admitted(sessionId: string): boolean {
|
|
@@ -68,8 +70,10 @@ export class Notifications {
|
|
|
68
70
|
// the next boundary instead of adding another request or changing its ordering.
|
|
69
71
|
if (event.continue || event.context.pendingMessages.length) return;
|
|
70
72
|
if (!this.admitted(active.sessionId)) return;
|
|
73
|
+
const message = this.take(active.sessionId);
|
|
74
|
+
++this.deliveries;
|
|
71
75
|
return { continue: true, entries: [...event.entries, { type: "custom_message", customType: "pi-suite:notification",
|
|
72
|
-
...
|
|
76
|
+
...message, display: false }] };
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
afterHostOperation(): void {
|
|
@@ -91,6 +95,7 @@ export class Notifications {
|
|
|
91
95
|
if (!active || this.blockers.size || !active.ctx.isIdle() || active.ctx.hasPendingMessages()) return;
|
|
92
96
|
if (!this.admitted(active.sessionId)) return;
|
|
93
97
|
const message = this.take(active.sessionId);
|
|
98
|
+
++this.deliveries;
|
|
94
99
|
this.pi.sendMessage({ customType: "pi-suite:notification", ...message,
|
|
95
100
|
display: message.details.segments.some(segment => segment.source !== "goal-continuation") },
|
|
96
101
|
{ triggerTurn: true, deliverAs: "followUp" });
|
package/src/runtime/read.ts
CHANGED
|
@@ -7,13 +7,18 @@ import { ToolError } from './errors.ts';
|
|
|
7
7
|
* only changes the returned text.
|
|
8
8
|
*/
|
|
9
9
|
export type ReadSource = { size: number; read(offset: number, length: number): Promise<Buffer>; close(): Promise<void> };
|
|
10
|
-
export type ReadRequest = { offset?: number; limitBytes?: number; search?: string; context?: number };
|
|
10
|
+
export type ReadRequest = { offset?: number; limitBytes?: number; search?: string; context?: number; line?: number; lines?: number };
|
|
11
11
|
export type ReadPage = {
|
|
12
12
|
text: string; offset: number; nextOffset: number; totalBytes: number; endOfStream: boolean;
|
|
13
13
|
truncated?: { head: [number, number]; keys: [number, number][]; tail: [number, number]; omittedBytes: number; keyLines: number };
|
|
14
14
|
matches?: number;
|
|
15
|
+
/** Line numbers of the raw log (newline-separated); the total is unknown beyond READ_LIMITS.lineCountBytes. */
|
|
16
|
+
firstLine?: number; lastLine?: number; totalLines?: number;
|
|
17
|
+
/** Search line numbers count from the start offset because the lines before it were not counted. */
|
|
18
|
+
relativeLines?: boolean;
|
|
15
19
|
};
|
|
16
|
-
export const READ_LIMITS = { defaultBytes: 4096, maxBytes: 65536, maxMatches: 50, defaultContext: 2, maxContext: 20, chunk: 65536
|
|
20
|
+
export const READ_LIMITS = { defaultBytes: 4096, maxBytes: 65536, maxMatches: 50, defaultContext: 2, maxContext: 20, chunk: 65536,
|
|
21
|
+
maxLines: 2000, lineCountBytes: 64 << 20 };
|
|
17
22
|
// Lines worth surfacing from an omitted middle section; matched case-insensitively.
|
|
18
23
|
const KEY_LINE = /\b(error|errors|fail(?:ed|ure|s)?|fatal|exception|traceback|panic|denied|not found|warn(?:ing)?|exit code|segmentation fault|assert(?:ion)?)\b/i;
|
|
19
24
|
|
|
@@ -53,6 +58,17 @@ export function boundedText(text: string, budget: number): string {
|
|
|
53
58
|
const marker = '... [truncated]'.slice(0, budget);
|
|
54
59
|
return bytes.subarray(0, utf8End(bytes, budget - marker.length)).toString('utf8') + marker;
|
|
55
60
|
}
|
|
61
|
+
// Rendering can expand raw bytes (e.g. terminal padding). Keep the newest text
|
|
62
|
+
// rather than applying the prefix-oriented boundedText to a summary's tail.
|
|
63
|
+
function boundedTail(text: string, budget: number): string {
|
|
64
|
+
if (Buffer.byteLength(text) <= budget) return text;
|
|
65
|
+
if (budget === 0) return '';
|
|
66
|
+
const marker = '[…]\n', markerBytes = Buffer.byteLength(marker);
|
|
67
|
+
const prefix = budget > markerBytes ? marker : '';
|
|
68
|
+
const bytes = Buffer.from(text.slice(-budget));
|
|
69
|
+
const suffix = bytes.subarray(bytes.length - budget + Buffer.byteLength(prefix));
|
|
70
|
+
return prefix + suffix.subarray(utf8Start(suffix)).toString('utf8');
|
|
71
|
+
}
|
|
56
72
|
/** Keep the same read mode and caller's limits when the model follows a continuation hint. */
|
|
57
73
|
export function readContinuation(request: ReadRequest, offset: number): ReadRequest {
|
|
58
74
|
return { offset, search: request.search, context: request.context, limitBytes: request.limitBytes };
|
|
@@ -70,6 +86,100 @@ export function compileSearch(search: string): RegExp {
|
|
|
70
86
|
catch (error) { throw new ToolError('INVALID_ARGS', `Invalid search pattern: ${error instanceof Error ? error.message : String(error)}. Check the regex and flags.`); }
|
|
71
87
|
}
|
|
72
88
|
|
|
89
|
+
/** Newlines in a buffer. */
|
|
90
|
+
function newlinesIn(buffer: Buffer): number {
|
|
91
|
+
let count = 0;
|
|
92
|
+
for (let index = buffer.indexOf(10); index >= 0; index = buffer.indexOf(10, index + 1)) count++;
|
|
93
|
+
return count;
|
|
94
|
+
}
|
|
95
|
+
/** Newlines in [from, to) of the raw log. */
|
|
96
|
+
async function countNewlines(source: ReadSource, from: number, to: number): Promise<number> {
|
|
97
|
+
let count = 0;
|
|
98
|
+
for (let position = from; position < to;) {
|
|
99
|
+
const chunk = await source.read(position, Math.min(READ_LIMITS.chunk, to - position));
|
|
100
|
+
if (!chunk.length) break;
|
|
101
|
+
count += newlinesIn(chunk); position += chunk.length;
|
|
102
|
+
}
|
|
103
|
+
return count;
|
|
104
|
+
}
|
|
105
|
+
/** Position just after the count-th newline at or after from; the log size when there are fewer. */
|
|
106
|
+
async function skipLines(source: ReadSource, from: number, count: number): Promise<number> {
|
|
107
|
+
if (count <= 0) return from;
|
|
108
|
+
let remaining = count;
|
|
109
|
+
for (let position = from; position < source.size;) {
|
|
110
|
+
const chunk = await source.read(position, Math.min(READ_LIMITS.chunk, source.size - position));
|
|
111
|
+
if (!chunk.length) break;
|
|
112
|
+
for (let index = chunk.indexOf(10); index >= 0; index = chunk.indexOf(10, index + 1)) {
|
|
113
|
+
if (--remaining === 0) return position + index + 1;
|
|
114
|
+
}
|
|
115
|
+
position += chunk.length;
|
|
116
|
+
}
|
|
117
|
+
return source.size;
|
|
118
|
+
}
|
|
119
|
+
/** Start of the last count lines; a final newline ends the last line instead of opening an empty one. */
|
|
120
|
+
async function lastLinesStart(source: ReadSource, count: number): Promise<number> {
|
|
121
|
+
let end = source.size;
|
|
122
|
+
if (end > 0 && (await source.read(end - 1, 1))[0] === 10) end--;
|
|
123
|
+
for (let remaining = count; end > 0;) {
|
|
124
|
+
const from = Math.max(0, end - READ_LIMITS.chunk), chunk = await source.read(from, end - from);
|
|
125
|
+
if (!chunk.length) break;
|
|
126
|
+
for (let index = chunk.lastIndexOf(10); index >= 0; index = index > 0 ? chunk.lastIndexOf(10, index - 1) : -1) {
|
|
127
|
+
if (--remaining === 0) return from + index + 1;
|
|
128
|
+
}
|
|
129
|
+
end = from;
|
|
130
|
+
}
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
/** Total lines of the raw log, unknown beyond READ_LIMITS.lineCountBytes. */
|
|
134
|
+
async function totalLines(source: ReadSource): Promise<number | undefined> {
|
|
135
|
+
if (source.size > READ_LIMITS.lineCountBytes) return undefined;
|
|
136
|
+
if (!source.size) return 0;
|
|
137
|
+
const last = await source.read(source.size - 1, 1);
|
|
138
|
+
return await countNewlines(source, 0, source.size) + (last[0] === 10 ? 0 : 1);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Read by line: line counts from 1, or from the end when negative. offset then moves forward from the
|
|
142
|
+
* start of that line in raw bytes. Lines are the newline-separated lines of the raw log, before rendering.
|
|
143
|
+
*/
|
|
144
|
+
async function readLines(source: ReadSource, request: ReadRequest, render: (raw: string) => string, limit: number): Promise<ReadPage> {
|
|
145
|
+
const line = request.line!, size = source.size;
|
|
146
|
+
if (!Number.isInteger(line) || line === 0) throw new ToolError('INVALID_ARGS', 'line starts at 1; use a negative line to count from the end, e.g. -50 for the last 50 lines.');
|
|
147
|
+
const total = await totalLines(source);
|
|
148
|
+
const start = line > 0 ? await skipLines(source, 0, line - 1) : await lastLinesStart(source, -line);
|
|
149
|
+
const startLine = line > 0 ? line : total === undefined ? undefined : Math.max(1, total + line + 1);
|
|
150
|
+
const from = Math.min(start + (request.offset ?? 0), size);
|
|
151
|
+
const preceding = startLine === undefined ? undefined : startLine - 1 + await countNewlines(source, start, from);
|
|
152
|
+
if (request.search !== undefined) return { ...await search(source, request, render, limit, from, preceding), totalLines: total };
|
|
153
|
+
if (from >= size) {
|
|
154
|
+
return { text: size ? `Nothing to read there: the log has ${total ?? 'an unknown number of'} lines` : '', offset: size, nextOffset: size,
|
|
155
|
+
totalBytes: size, endOfStream: true, totalLines: total };
|
|
156
|
+
}
|
|
157
|
+
const stop = request.lines === undefined ? size : Math.max(from, await skipLines(source, start, request.lines));
|
|
158
|
+
let begin = from;
|
|
159
|
+
if (line < 0 && request.lines === undefined && request.offset === undefined && stop - begin > limit) {
|
|
160
|
+
// Too long for limitBytes: keep the newest lines, starting on a line boundary.
|
|
161
|
+
const probe = await source.read(stop - limit, limit), newline = probe.indexOf(10);
|
|
162
|
+
begin = newline >= 0 && newline + 1 < probe.length ? stop - limit + newline + 1 : stop - limit;
|
|
163
|
+
}
|
|
164
|
+
const length = Math.min(limit, stop - begin), buffer = await source.read(begin, length + 3);
|
|
165
|
+
// A start inside a character moves to the next boundary; a snapshot may end inside one.
|
|
166
|
+
const first = utf8Start(buffer), end = utf8End(buffer, Math.min(length, buffer.length)), used = Math.max(first, end);
|
|
167
|
+
const raw = buffer.subarray(first, used), nextOffset = begin + used;
|
|
168
|
+
const firstLine = startLine === undefined ? undefined : startLine + await countNewlines(source, start, begin + first);
|
|
169
|
+
const lastLine = firstLine === undefined || !raw.length ? undefined : firstLine + newlinesIn(raw) - (raw[raw.length - 1] === 10 ? 1 : 0);
|
|
170
|
+
return { text: render(raw.toString('utf8')), offset: begin + first, nextOffset, totalBytes: size, endOfStream: nextOffset >= stop,
|
|
171
|
+
firstLine, lastLine, totalLines: total };
|
|
172
|
+
}
|
|
173
|
+
/** Header suffix: line range, an omitted middle, and whether the match count is complete. */
|
|
174
|
+
export function pageNote(page: ReadPage): string {
|
|
175
|
+
const parts: string[] = [];
|
|
176
|
+
if (page.firstLine !== undefined && page.lastLine !== undefined) parts.push(`lines ${page.firstLine}-${page.lastLine}${page.totalLines !== undefined ? ` of ${page.totalLines}` : ''}`);
|
|
177
|
+
else if (page.totalLines !== undefined) parts.push(`${page.totalLines} lines`);
|
|
178
|
+
if (page.truncated) parts.push(`middle omitted ${formatBytes(page.truncated.omittedBytes)}`);
|
|
179
|
+
if (page.matches !== undefined) parts.push(`${page.matches}${page.endOfStream ? '' : '+'} matches${page.relativeLines ? ', line numbers count from offset' : ''}`);
|
|
180
|
+
return parts.map(part => ` · ${part}`).join('');
|
|
181
|
+
}
|
|
182
|
+
|
|
73
183
|
/** Streams complete lines with their starting byte offsets from [from, to). */
|
|
74
184
|
async function* lines(source: ReadSource, from: number, to: number): AsyncGenerator<{ offset: number; bytes: Buffer }> {
|
|
75
185
|
let pending: Buffer[] = [], pendingBytes = 0, pendingAt = from;
|
|
@@ -96,7 +206,11 @@ async function* lines(source: ReadSource, from: number, to: number): AsyncGenera
|
|
|
96
206
|
export async function readBounded(source: ReadSource, request: ReadRequest, render: (raw: string) => string): Promise<ReadPage> {
|
|
97
207
|
const limit = request.limitBytes ?? READ_LIMITS.defaultBytes;
|
|
98
208
|
const size = source.size;
|
|
99
|
-
if (request.
|
|
209
|
+
if (request.line !== undefined) return readLines(source, request, render, limit);
|
|
210
|
+
if (request.search !== undefined) {
|
|
211
|
+
const from = Math.min(request.offset ?? 0, size);
|
|
212
|
+
return search(source, request, render, limit, from, from <= READ_LIMITS.lineCountBytes ? await countNewlines(source, 0, from) : undefined);
|
|
213
|
+
}
|
|
100
214
|
if (request.offset !== undefined) {
|
|
101
215
|
const offset = Math.min(request.offset, size);
|
|
102
216
|
const buffer = await source.read(offset, limit + 3);
|
|
@@ -108,16 +222,33 @@ export async function readBounded(source: ReadSource, request: ReadRequest, rend
|
|
|
108
222
|
}
|
|
109
223
|
if (size <= limit) {
|
|
110
224
|
const buffer = await source.read(0, size);
|
|
111
|
-
return { text: render(buffer.toString('utf8')), offset: 0, nextOffset: size, totalBytes: size, endOfStream: true };
|
|
225
|
+
return { text: boundedTail(render(buffer.toString('utf8')), limit), offset: 0, nextOffset: size, totalBytes: size, endOfStream: true };
|
|
112
226
|
}
|
|
113
|
-
// Smart default: head
|
|
227
|
+
// Smart default: align the head and tail to lines, then give the middle what is left after formatting.
|
|
114
228
|
const headBuffer = await source.read(0, Math.floor(limit * 0.2));
|
|
115
229
|
const headEnd = headBuffer.lastIndexOf(10) + 1 || utf8End(headBuffer, headBuffer.length);
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
230
|
+
const head = boundedText(render(headBuffer.subarray(0, headEnd).toString('utf8')).replace(/\n$/, ''), headEnd);
|
|
231
|
+
const headBytes = Buffer.byteLength(head), tailBudget = Math.floor(limit * 0.5);
|
|
232
|
+
const marker = (end: number, count: number, omitted = formatBytes(end - headEnd)) =>
|
|
233
|
+
`[… ${omitted} omitted (bytes ${headEnd}–${end}), ${count} matching lines; use offset or search …]`;
|
|
234
|
+
// Offsets and match counts cannot exceed size. Just below 1 MiB the formatted
|
|
235
|
+
// byte count may be longer than it is in MiB, so bound both representations.
|
|
236
|
+
const maxOmitted = [formatBytes(size), formatBytes(Math.min(size, (1 << 20) - 1))];
|
|
237
|
+
const shortMarker = '[…]', shortBytes = Buffer.byteLength(shortMarker) + 2;
|
|
238
|
+
const markerBudget = (count: number) => {
|
|
239
|
+
const bytes = Math.max(...maxOmitted.map(omitted => Buffer.byteLength(marker(size, count, omitted)))) + 2;
|
|
240
|
+
const available = limit - headBytes - tailBudget;
|
|
241
|
+
return bytes <= available ? { bytes, detailed: true } : { bytes: Math.min(available, shortBytes), detailed: false };
|
|
242
|
+
};
|
|
243
|
+
const readTail = async (budget: number) => {
|
|
244
|
+
const raw = await source.read(size - budget, budget), newline = raw.indexOf(10);
|
|
245
|
+
const cut = newline >= 0 && newline + 1 < raw.length ? newline + 1 : utf8Start(raw);
|
|
246
|
+
return { start: size - budget + cut, raw: raw.subarray(cut) };
|
|
247
|
+
};
|
|
248
|
+
let tail = await readTail(tailBudget), omission = markerBudget(size);
|
|
249
|
+
const gap = ' …', keysEnd = '[… end of matching lines …]';
|
|
250
|
+
const keyBudget = limit - headBytes - tail.raw.length - omission.bytes - Buffer.byteLength(`${gap}\n${keysEnd}\n`);
|
|
251
|
+
const allocation = Math.floor(keyBudget / 2) - 1, contextBudget = Math.floor(allocation / 4);
|
|
121
252
|
// Each key line carries its adjacent lines for context. Keep the earliest blocks within half
|
|
122
253
|
// of the budget and a rolling window of the latest blocks in the rest.
|
|
123
254
|
type Line = { text: string; start: number; end: number };
|
|
@@ -126,7 +257,6 @@ export async function readBounded(source: ReadSource, request: ReadRequest, rend
|
|
|
126
257
|
let keyLines = 0, firstBytes = 0, recentBytes = 0, previous: Line | undefined;
|
|
127
258
|
let pending: { before?: Line; match: Line } | undefined;
|
|
128
259
|
const collect = (before: Line | undefined, match: Line, after?: Line) => {
|
|
129
|
-
const allocation = Math.floor(keyBudget / 2) - 1, contextBudget = Math.floor(allocation / 4);
|
|
130
260
|
const preceding = before ? boundedText(` ${before.text}`, contextBudget) : undefined;
|
|
131
261
|
const following = after ? boundedText(` ${after.text}`, contextBudget) : undefined;
|
|
132
262
|
// The match retains half the block even when both context lines exceed the budget.
|
|
@@ -139,32 +269,40 @@ export async function readBounded(source: ReadSource, request: ReadRequest, rend
|
|
|
139
269
|
while (recent.length > 1 && recentBytes > keyBudget - firstBytes) recentBytes -= recent.shift()!.bytes;
|
|
140
270
|
}
|
|
141
271
|
};
|
|
142
|
-
for await (const line of lines(source, headEnd,
|
|
272
|
+
for await (const line of lines(source, headEnd, tail.start)) {
|
|
143
273
|
const text = render(line.bytes.toString('utf8')), matched = KEY_LINE.test(text);
|
|
274
|
+
if (matched) keyLines++;
|
|
275
|
+
if (allocation < 4) continue; // No room for a match prefix and context separators.
|
|
144
276
|
// Match against the complete line, then retain only what can reach the page.
|
|
145
|
-
const current = { text: boundedText(text, keyBudget), start: line.offset, end: Math.min(
|
|
277
|
+
const current = { text: boundedText(text, keyBudget), start: line.offset, end: Math.min(tail.start, line.offset + line.bytes.length + 1) };
|
|
146
278
|
if (pending) collect(pending.before, pending.match, current);
|
|
147
279
|
pending = matched ? { before: previous, match: current } : undefined;
|
|
148
|
-
if (pending) keyLines++;
|
|
149
280
|
previous = current;
|
|
150
281
|
}
|
|
151
282
|
if (pending) collect(pending.before, pending.match);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
283
|
+
const keys = [...first, ...recent];
|
|
284
|
+
if (keyLines === 0) {
|
|
285
|
+
// Nothing to show from the middle: its share goes to the tail, where a failure usually ends.
|
|
286
|
+
omission = markerBudget(keyLines);
|
|
287
|
+
const wide = limit - headBytes - omission.bytes;
|
|
288
|
+
// Rendering may shrink the head, but the wider tail must not overlap its raw range.
|
|
289
|
+
tail = await readTail(Math.min(wide, size - headEnd));
|
|
290
|
+
}
|
|
291
|
+
const omitted = tail.start - headEnd;
|
|
292
|
+
const note = omission.detailed ? marker(tail.start, keyLines) : omission.bytes === shortBytes ? shortMarker : '';
|
|
293
|
+
const text = [head, note, ...first.map(item => item.text), ...(keys.length && keyLines > keys.length ? [gap] : []),
|
|
294
|
+
...recent.map(item => item.text), ...(keys.length ? [keysEnd] : []), boundedTail(render(tail.raw.toString('utf8')), tail.raw.length)]
|
|
295
|
+
.filter(Boolean).join('\n');
|
|
157
296
|
return { text, offset: 0, nextOffset: size, totalBytes: size, endOfStream: true,
|
|
158
|
-
truncated: { head: [0, headEnd], keys:
|
|
297
|
+
truncated: { head: [0, headEnd], keys: keys.map(item => item.range), tail: [tail.start, size], omittedBytes: omitted, keyLines } };
|
|
159
298
|
}
|
|
160
299
|
|
|
161
|
-
/** Line numbers
|
|
162
|
-
async function search(source: ReadSource, request: ReadRequest, render: (raw: string) => string, limit: number): Promise<ReadPage> {
|
|
300
|
+
/** Line numbers are absolute (base = lines before from) unless that count is unknown; matched lines also show their byte offset for resuming. */
|
|
301
|
+
async function search(source: ReadSource, request: ReadRequest, render: (raw: string) => string, limit: number, from: number, base: number | undefined): Promise<ReadPage> {
|
|
163
302
|
const pattern = compileSearch(request.search!);
|
|
164
303
|
const context = Math.min(request.context ?? READ_LIMITS.defaultContext, READ_LIMITS.maxContext);
|
|
165
|
-
const from = Math.min(request.offset ?? 0, source.size);
|
|
166
304
|
const out: string[] = [], before: string[] = [];
|
|
167
|
-
let matches = 0, lineNumber = 0, after = 0, bytes = 0, nextOffset = source.size, lastPrinted = -1;
|
|
305
|
+
let matches = 0, lineNumber = base ?? 0, after = 0, bytes = 0, nextOffset = source.size, lastPrinted = -1;
|
|
168
306
|
const append = (text: string, allocation = limit - bytes) => {
|
|
169
307
|
const separator = Number(out.length > 0);
|
|
170
308
|
const line = boundedText(text, Math.max(0, Math.min(allocation, limit - bytes - separator)));
|
|
@@ -196,5 +334,5 @@ async function search(source: ReadSource, request: ReadRequest, render: (raw: st
|
|
|
196
334
|
else { before.push(boundedText(text, limit)); if (before.length > context) before.shift(); }
|
|
197
335
|
}
|
|
198
336
|
return { text: out.join('\n') || boundedText(`No lines match ${request.search}`, limit), offset: from, nextOffset, totalBytes: source.size,
|
|
199
|
-
endOfStream: nextOffset >= source.size, matches };
|
|
337
|
+
endOfStream: nextOffset >= source.size, matches, relativeLines: base === undefined ? true : undefined };
|
|
200
338
|
}
|
package/src/runtime/suite.ts
CHANGED
|
@@ -10,9 +10,10 @@ import { recordsIn } from '../agents/records.ts';
|
|
|
10
10
|
import { visibleAgent, type AgentType } from '../agents/types.ts';
|
|
11
11
|
import { registerSuiteCommand } from './settings/index.ts';
|
|
12
12
|
import { prepareClipboard } from './clipboard.ts';
|
|
13
|
+
import { CompletionNotifier, type FocusInput } from '../notify/index.ts';
|
|
13
14
|
import type { SubagentsDeps } from '../agents/commands.ts';
|
|
14
15
|
|
|
15
|
-
export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext) {
|
|
16
|
+
export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext, focusInput?: FocusInput) {
|
|
16
17
|
let config = loadConfig(initial.cwd);
|
|
17
18
|
// Pi uses Jiti with shared dependency graphs: concurrent imports can expose unfinished
|
|
18
19
|
// exports. Load admitted stacks in order and finish registration before session_start returns.
|
|
@@ -54,7 +55,9 @@ export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext) {
|
|
|
54
55
|
}
|
|
55
56
|
const waits = new WaitRegistry();
|
|
56
57
|
const goal = config.modules.goal ? new goalApi![0].GoalManager(pi, binding, notifications, status, waits) : undefined;
|
|
57
|
-
const
|
|
58
|
+
const notifier = new CompletionNotifier(() => config.notify, focusInput);
|
|
59
|
+
const ask = config.modules.ask ? new AskManager(binding, notifications, dock, (status, ctx) => goal?.askResult(status, ctx),
|
|
60
|
+
() => notifier.show()) : undefined;
|
|
58
61
|
if (ask) registerAsk(pi, ask, () => config);
|
|
59
62
|
const creatorRoots = () => {
|
|
60
63
|
const ctx = binding.current?.ctx;
|
|
@@ -131,13 +134,15 @@ export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext) {
|
|
|
131
134
|
const bindSession = async (ctx: Parameters<SessionBinding["bind"]>[0], reason: "startup" | "reload" | "new" | "resume" | "fork", previousSessionFile?: string) => {
|
|
132
135
|
// Tree navigation has no shutdown event. Revoke the old readers and timers before
|
|
133
136
|
// rebinding, without appending their state into the branch the host just selected.
|
|
134
|
-
dock.detach(binding.current?.ctx);
|
|
137
|
+
notifier.detach(); dock.detach(binding.current?.ctx);
|
|
135
138
|
schedules?.stop(); ask?.cancel(); goal?.detach(); jobs?.detach(); workflows?.detach(); agents?.detach(); notifications.detach();
|
|
139
|
+
binding.revoke();
|
|
136
140
|
if (!firstBinding) config = loadConfig(ctx.cwd);
|
|
137
141
|
const goalReason = firstBinding ? reason : "tree";
|
|
138
142
|
firstBinding = false; cachedTypes = undefined;
|
|
139
143
|
await prepareClipboard(pi, ctx);
|
|
140
144
|
binding.bind(ctx);
|
|
145
|
+
notifier.bind(ctx);
|
|
141
146
|
recovery?.reset(ctx);
|
|
142
147
|
dock.bind(ctx, config.ui.maxRows);
|
|
143
148
|
status.bind(ctx.ui, { goal: config.goal.display, agents: config.agents.display, jobs: config.jobs.display }, goal !== undefined);
|
|
@@ -153,6 +158,7 @@ export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext) {
|
|
|
153
158
|
pi.on("session_tree", async (_event, ctx) => { await bindSession(ctx, "resume"); notifications.afterHostOperation(); });
|
|
154
159
|
pi.on("session_shutdown", async event => {
|
|
155
160
|
agentRpc?.detach();
|
|
161
|
+
notifier.detach();
|
|
156
162
|
schedules?.stop();
|
|
157
163
|
ask?.cancel(); await goal?.shutdown(event.reason);
|
|
158
164
|
tasks?.detach();
|
|
@@ -178,11 +184,16 @@ export async function createSuite(pi: ExtensionAPI, initial: ExtensionContext) {
|
|
|
178
184
|
await goal?.beforeSettle(proposed);
|
|
179
185
|
return notifications.beforeSettle(proposed) ?? repair;
|
|
180
186
|
});
|
|
181
|
-
pi.on("agent_settled", async event => {
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
pi.on("agent_settled", async (event, ctx) => {
|
|
188
|
+
const captured = binding.current, delivery = notifications.deliverySequence;
|
|
189
|
+
recovery?.settled(); waits.steeringDelivered();
|
|
190
|
+
await goal?.settled(event.aborted);
|
|
184
191
|
if (event.aborted) jobs?.pauseWakes();
|
|
185
192
|
notifications.flush();
|
|
193
|
+
if (!captured || !binding.isCurrent(captured) || ctx.sessionManager.getSessionId() !== captured.sessionId) return;
|
|
194
|
+
// Goal's own commits may release the queue while settled() is awaited. By this
|
|
195
|
+
// boundary Pi has also finished any native retries, even on a final request error.
|
|
196
|
+
if (ctx.mode === 'tui' && !event.aborted && delivery === notifications.deliverySequence && !goal?.unattended) notifier.show();
|
|
186
197
|
});
|
|
187
198
|
registerSuiteCommand(pi, dock, notifications, () => config, subagentsDeps ? async ctx => {
|
|
188
199
|
const { showSubagents } = await import('../agents/ui/index.ts');
|
package/src/runtime/tools.ts
CHANGED
|
@@ -112,13 +112,18 @@ export function paginate<T>(items: T[], position: (item: T) => Position, cursor:
|
|
|
112
112
|
|
|
113
113
|
/** Byte-offset paging, regex search and default smart truncation; shared by job_read and agent_read. */
|
|
114
114
|
export const readFields = {
|
|
115
|
-
|
|
115
|
+
line: Type.Optional(Type.Integer({ description: '1-based start line; negative counts from the end (-50 = the last 50 lines). Lines are newline-separated lines of the raw log' })),
|
|
116
|
+
lines: Type.Optional(Type.Integer({ minimum: 1, maximum: READ_LIMITS.maxLines, description: 'With line: how many lines to read; default as many as limitBytes allows' })),
|
|
117
|
+
offset: Type.Optional(Type.Integer({ minimum: 0, description: 'Raw byte offset; returns nextOffset. With line: bytes after the start of that line' })),
|
|
116
118
|
limitBytes: Type.Optional(Type.Integer({ minimum: 64, maximum: READ_LIMITS.maxBytes, description: `Default ${READ_LIMITS.defaultBytes}` })),
|
|
117
119
|
search: Type.Optional(Type.String({ minLength: 1, maxLength: 500, description: 'Regex, /re/flags; case-insensitive by default' })),
|
|
118
120
|
context: Type.Optional(Type.Integer({ minimum: 0, maximum: READ_LIMITS.maxContext, description: `Lines around matches, default ${READ_LIMITS.defaultContext}` })),
|
|
119
121
|
};
|
|
120
|
-
export function rejectContextWithoutSearch(params: { search?: string; context?: number }): void {
|
|
122
|
+
export function rejectContextWithoutSearch(params: { search?: string; context?: number; line?: number; lines?: number }): void {
|
|
121
123
|
if (params.context !== undefined && params.search === undefined) throw new ToolError('INVALID_ARGS', 'context requires search. Add search or omit context.');
|
|
124
|
+
if (params.line === 0) throw new ToolError('INVALID_ARGS', 'line starts at 1; use a negative line to count from the end, e.g. -50 for the last 50 lines.');
|
|
125
|
+
if (params.lines !== undefined && params.line === undefined) throw new ToolError('INVALID_ARGS', 'lines requires line. Add line or omit lines.');
|
|
126
|
+
if (params.lines !== undefined && params.search !== undefined) throw new ToolError('INVALID_ARGS', 'lines cannot be combined with search; use limitBytes or context to bound a search.');
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
/** stop result shared by job_stop and agent_stop; affected lists every cascaded object's real state. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { displayNameOf } from './display-name.ts';
|
|
2
2
|
import { sanitizeText } from './text.ts';
|
|
3
3
|
import { toolRenderers, stateLine } from '../ui/tool-render.ts';
|
|
4
4
|
import { elapsedText } from '../ui/format.ts';
|
|
@@ -16,18 +16,17 @@ export const waitRenderers = toolRenderers<{ ids: string[] }, WaitResult>({
|
|
|
16
16
|
expanded: (data, _args, text) => {
|
|
17
17
|
// Only rewrite the rendered identity; result bodies and read/send arguments keep their IDs.
|
|
18
18
|
let display = text;
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
const items = [...data.results, ...data.others].map(item => {
|
|
20
|
+
const title = displayNameOf(item.id, item.runId), summary = sanitizeText(item.summary);
|
|
21
|
+
const label = title === item.id ? summary : summary.replace(item.id, () => sanitizeText(title));
|
|
22
|
+
if (label !== summary) display = display.replace(summary, () => label);
|
|
23
|
+
return { title, label, state: item.state };
|
|
24
|
+
});
|
|
25
25
|
if (data.pending.length && data.reason !== 'condition') {
|
|
26
26
|
display = display.replace(`pending: ${data.pending.join(', ')}`,
|
|
27
|
-
() => `pending: ${data.pending.map(id => sanitizeText(
|
|
27
|
+
() => `pending: ${data.pending.map(id => sanitizeText(displayNameOf(id))).join(', ')}`);
|
|
28
28
|
}
|
|
29
|
-
return [...
|
|
30
|
-
|
|
31
|
-
...[...data.results, ...data.others].filter(item => item.state === 'failed').map(item => ({ label: 'error', value: item.summary, tone: 'error' as const })), display];
|
|
29
|
+
return [...items.map(({ title, state }) => ({ ...stateLine(state), title, meta: [{ text: state, tone: stateLine(state).tone! }] })),
|
|
30
|
+
...items.filter(item => item.state === 'failed').map(item => ({ label: 'error', value: item.label, tone: 'error' as const })), display];
|
|
32
31
|
},
|
|
33
32
|
}, { timing: elapsedText });
|
|
@@ -2,6 +2,7 @@ import type { Theme } from '@earendil-works/pi-coding-agent';
|
|
|
2
2
|
import type { DerivedChange, EditReceipt, EditResult, TaskView } from './types.ts';
|
|
3
3
|
import { taskTitle } from './query.ts';
|
|
4
4
|
import { sanitizeText } from '../runtime/text.ts';
|
|
5
|
+
import { executionRow } from '../ui/dock/line.ts';
|
|
5
6
|
|
|
6
7
|
export const taskIcon = (state: string): string => ({ doing: '⟳', blocked: '⚠', done: '☑' })[state] ?? '☐';
|
|
7
8
|
// Reuse the Dock heading's accent for pending work across every task view.
|
|
@@ -11,6 +12,10 @@ export function taskRow(task: Pick<TaskView, 'id' | 'title' | 'parentId' | 'stat
|
|
|
11
12
|
const text = `${taskIcon(task.status)} ${taskHeading(task)}`;
|
|
12
13
|
return taskStyle(task, text, theme);
|
|
13
14
|
}
|
|
15
|
+
/** Reserve progress at the actual SelectList width, including in a split pane. */
|
|
16
|
+
export const taskBrowserRow = (label: string, task: TaskView, width: number): string =>
|
|
17
|
+
executionRow(label, task.progress ? `${task.progress.done}/${task.progress.total}` : '', undefined, width);
|
|
18
|
+
|
|
14
19
|
/** Apply trusted theme styling after readers have sanitized/truncated task data. */
|
|
15
20
|
export function taskStyle(task: Pick<TaskView, 'status'>, text: string, theme?: Theme): string {
|
|
16
21
|
if (!theme) return text;
|
package/src/tasks/query.ts
CHANGED
|
@@ -26,13 +26,21 @@ const taskHeading = (task: TaskView) => [part(task.id, 'id'), part(' '), part(ta
|
|
|
26
26
|
export const taskLabel = (task: TaskView): string => taskHeading(task).map(({text}) => text).join('');
|
|
27
27
|
export const taskTitle = (task: Pick<TaskView, 'title'>) => sanitizeText(task.title).replace(/[\r\n\t]/g, ' ').trim();
|
|
28
28
|
export const openBlockers = (task: TaskView, views: Map<string, TaskView>) => task.blockedBy.filter(id => views.get(id)?.status !== 'done');
|
|
29
|
-
export function taskDetailsView(task: TaskView, views: Map<string, TaskView>): StructuredDetails
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
export function taskDetailsView(task: TaskView, views: Map<string, TaskView>): StructuredDetails;
|
|
30
|
+
export function taskDetailsView(task: TaskView, views: Map<string, TaskView>, display: 'browser'): StructuredDetails | undefined;
|
|
31
|
+
export function taskDetailsView(task: TaskView, views: Map<string, TaskView>, display?: 'browser'): StructuredDetails | undefined {
|
|
32
|
+
// Only the interactive preview changes labels and omits records without a detail body.
|
|
33
|
+
const browser = display === 'browser';
|
|
34
|
+
const detailText = (text?: string) => text && (!browser || sanitizeText(text).trim()) ? text : undefined;
|
|
35
|
+
const reason = detailText(task.blockedReason), open = openBlockers(task, views);
|
|
36
|
+
const satisfied = browser ? task.blockedBy.filter(id => views.get(id)?.status === 'done') : [];
|
|
37
|
+
const body = [detailText(task.description), reason ? field(browser ? 'Blocked reason:' : 'blocked:', part(reason, 'error')) : undefined, null,
|
|
38
|
+
open.length ? field(browser ? 'Blocked by:' : 'blockedBy:', part(open.join(', '), 'id')) : undefined,
|
|
39
|
+
...satisfied.length ? [field('Depends on:', part(satisfied.join(', '), 'id'))] : [],
|
|
40
|
+
task.blocks.length ? field(browser ? 'Blocks:' : 'blocks:', part(task.blocks.join(', '), 'id')) : undefined,
|
|
41
|
+
task.owner ? field(browser ? 'Agent:' : 'agent:', part(task.owner, 'id')) : undefined,
|
|
42
|
+
task.jobIds.length ? field(browser ? 'Jobs:' : 'jobs:', part(task.jobIds.join(', '), 'id')) : undefined];
|
|
43
|
+
if (browser && !body.some(Boolean)) return;
|
|
44
|
+
return { rows: [taskHeading(task), ...browser ? [] : [task.parentId ? field('parent', part(task.parentId, 'id')) : undefined], null, ...body] };
|
|
37
45
|
}
|
|
38
46
|
export const taskDetails = (task: TaskView, views: Map<string, TaskView>): string[] => plainDetailLines(taskDetailsView(task, views));
|