@preapexis/honeycomb 0.0.0-stage → 1.1.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/LICENSE +15 -0
- package/README.md +443 -2
- package/bin/bee.js +18 -0
- package/package.json +66 -4
- package/plan/tools/tool-parity.md +61 -0
- package/src/commands/btw.ts +95 -0
- package/src/commands/claude-migrate.ts +63 -0
- package/src/commands/diff.ts +119 -0
- package/src/commands/discovery.ts +112 -0
- package/src/commands/doctor.ts +80 -0
- package/src/commands/goal/index.ts +254 -0
- package/src/commands/goal/report.ts +66 -0
- package/src/commands/goal/state.ts +74 -0
- package/src/commands/hooks.ts +38 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/init.ts +66 -0
- package/src/commands/memory.ts +70 -0
- package/src/commands/plan.ts +36 -0
- package/src/commands/review-report.ts +23 -0
- package/src/commands/review.ts +21 -0
- package/src/commands/rewind-history.ts +40 -0
- package/src/commands/security-review.ts +138 -0
- package/src/commands/simplify.ts +21 -0
- package/src/commands/stats.ts +125 -0
- package/src/commands/tasks.ts +87 -0
- package/src/commands/verify.ts +21 -0
- package/src/commands/worktree.ts +138 -0
- package/src/config/bi.config.json +77 -0
- package/src/config/index.ts +47 -0
- package/src/config/limits.ts +12 -0
- package/src/config/path-rules.ts +19 -0
- package/src/config/project.ts +133 -0
- package/src/extension/ask-user.ts +52 -0
- package/src/extension/index.ts +4 -0
- package/src/extension/lsp-install.ts +95 -0
- package/src/extension/lsp-menu.ts +90 -0
- package/src/extension/permission-modes/index.ts +337 -0
- package/src/extension/permission-modes/mcp-resources.ts +21 -0
- package/src/extension/permission-modes/metadata.ts +18 -0
- package/src/extension/permission-modes/paths.ts +44 -0
- package/src/extension/permission-modes/plan-note.ts +58 -0
- package/src/extension/permission-modes/policy.ts +236 -0
- package/src/extension/permission-modes/preview.ts +104 -0
- package/src/extension/permission-modes/rules.ts +67 -0
- package/src/extension/permission-modes/shell.ts +183 -0
- package/src/extension/permission-modes/state.ts +6 -0
- package/src/extension/quiet-startup.ts +25 -0
- package/src/extension/register-tools.ts +312 -0
- package/src/extension/scoped-rules.ts +91 -0
- package/src/extension/system-instruction.ts +74 -0
- package/src/index.ts +71 -0
- package/src/tools/advanced.ts +133 -0
- package/src/tools/agent.ts +379 -0
- package/src/tools/dispatcher.ts +80 -0
- package/src/tools/executable.ts +15 -0
- package/src/tools/execution.ts +289 -0
- package/src/tools/filesystem.ts +662 -0
- package/src/tools/git.ts +196 -0
- package/src/tools/glob.ts +81 -0
- package/src/tools/grep.ts +203 -0
- package/src/tools/image-read.ts +71 -0
- package/src/tools/index.ts +52 -0
- package/src/tools/lsp-client.ts +104 -0
- package/src/tools/lsp.ts +172 -0
- package/src/tools/memory-store.ts +77 -0
- package/src/tools/notebook.ts +169 -0
- package/src/tools/registry.ts +31 -0
- package/src/tools/shells.ts +63 -0
- package/src/tools/todo.ts +119 -0
- package/src/tools/undo-journal.ts +46 -0
- package/src/tools/web-fetch.ts +119 -0
- package/src/tools/web-search.ts +76 -0
- package/src/tools/write-file.ts +14 -0
- package/src/tui/editor.ts +65 -0
- package/src/tui/footer-stats.ts +35 -0
- package/src/tui/header.ts +81 -0
- package/src/tui/index.ts +124 -0
- package/src/tui/mascot.ts +59 -0
- package/src/tui/permission-dialog.ts +94 -0
- package/src/tui/permission-rules.ts +64 -0
- package/src/tui/tasks-panel.ts +84 -0
- package/src/tui/text.ts +55 -0
- package/src/tui/tool-renderer.ts +42 -0
- package/src/tui/working-feedback.ts +220 -0
- package/src/types/agent.ts +54 -0
- package/src/types/common.ts +1 -0
- package/src/types/execution.ts +24 -0
- package/src/types/index.ts +4 -0
- package/src/types/tools.ts +61 -0
- package/themes/catppuccin-mocha.json +80 -0
- package/themes/github-dark.json +80 -0
- package/themes/honeycomb-dark.json +81 -0
- package/themes/honeycomb-light.json +81 -0
- package/themes/tokyo-day.json +80 -0
- package/themes/tokyo-night.json +80 -0
- package/themes/vercel-black.json +80 -0
- package/themes/vercel-light.json +80 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { registerGoalReportTool } from './report.ts';
|
|
3
|
+
import {
|
|
4
|
+
buildGoalPrompt,
|
|
5
|
+
DEFAULT_GOAL_ITERATIONS,
|
|
6
|
+
GOAL_STATE_ENTRY,
|
|
7
|
+
goalStatusText,
|
|
8
|
+
MAX_GOAL_ITERATIONS,
|
|
9
|
+
readGoalState,
|
|
10
|
+
saveGoalState,
|
|
11
|
+
saveGoalStateDraft,
|
|
12
|
+
type GoalState,
|
|
13
|
+
} from './state.ts';
|
|
14
|
+
|
|
15
|
+
export function registerGoalCommand(pi: ExtensionAPI): void {
|
|
16
|
+
registerGoalReportTool(pi);
|
|
17
|
+
registerGoalLifecycle(pi);
|
|
18
|
+
|
|
19
|
+
pi.registerCommand('goal', {
|
|
20
|
+
description: 'Start or manage a persistent, bounded goal for this session',
|
|
21
|
+
handler: async (args, ctx) => {
|
|
22
|
+
const input = args.trim();
|
|
23
|
+
const [command, ...rest] = input.split(/\s+/);
|
|
24
|
+
const argument = rest.join(' ').trim();
|
|
25
|
+
const goal = readGoalState(ctx.sessionManager.getBranch());
|
|
26
|
+
|
|
27
|
+
switch (command) {
|
|
28
|
+
case undefined:
|
|
29
|
+
case 'status':
|
|
30
|
+
ctx.ui.notify(goal ? goalStatusText(goal) : 'No goal is saved for this session. Start one with /goal <objective>.', 'info');
|
|
31
|
+
return;
|
|
32
|
+
case 'pause':
|
|
33
|
+
if (!goal || goal.status !== 'active') {
|
|
34
|
+
ctx.ui.notify('There is no active goal to pause.', 'warning');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
saveGoalState(pi, { ...goal, status: 'paused', updatedAt: Date.now() });
|
|
38
|
+
ctx.ui.notify('Goal paused. The current turn may finish; no further goal iterations will be scheduled.', 'info');
|
|
39
|
+
return;
|
|
40
|
+
case 'resume':
|
|
41
|
+
if (!goal || goal.status === 'completed') {
|
|
42
|
+
ctx.ui.notify('There is no resumable goal. Start one with /goal <objective>.', 'warning');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (goal.status === 'active') {
|
|
46
|
+
ctx.ui.notify('The goal is already active.', 'info');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!ctx.isIdle()) {
|
|
50
|
+
ctx.ui.notify('Wait for the current run to finish before resuming the goal.', 'warning');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
{
|
|
54
|
+
const resumed: GoalState = {
|
|
55
|
+
...goal,
|
|
56
|
+
status: 'active',
|
|
57
|
+
iteration: goal.status === 'budget_exceeded' ? 0 : goal.iteration,
|
|
58
|
+
reportCount: 0,
|
|
59
|
+
updatedAt: Date.now(),
|
|
60
|
+
};
|
|
61
|
+
saveGoalState(pi, resumed);
|
|
62
|
+
ctx.ui.notify('Resuming goal.', 'info');
|
|
63
|
+
pi.sendUserMessage(buildGoalPrompt(resumed));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
case 'clear':
|
|
67
|
+
if (!goal) {
|
|
68
|
+
ctx.ui.notify('There is no saved goal to clear.', 'info');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
pi.appendEntry(GOAL_STATE_ENTRY, null);
|
|
72
|
+
ctx.ui.notify('Saved goal cleared. The current turn, if any, is not cancelled.', 'info');
|
|
73
|
+
return;
|
|
74
|
+
case 'edit':
|
|
75
|
+
if (!argument) {
|
|
76
|
+
ctx.ui.notify('Usage: /goal edit <new objective>', 'warning');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!goal || goal.status === 'completed') {
|
|
80
|
+
ctx.ui.notify('There is no editable goal. Start one with /goal <objective>.', 'warning');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (!ctx.isIdle()) {
|
|
84
|
+
ctx.ui.notify('Wait for the current run to finish before editing the goal.', 'warning');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
{
|
|
88
|
+
const edited = {
|
|
89
|
+
...goal,
|
|
90
|
+
objective: argument,
|
|
91
|
+
progress: 'Objective updated. Reassess the plan and acceptance criteria.',
|
|
92
|
+
verification: undefined,
|
|
93
|
+
iteration: 0,
|
|
94
|
+
reportCount: 0,
|
|
95
|
+
status: goal.status === 'paused' ? 'paused' as const : 'active' as const,
|
|
96
|
+
updatedAt: Date.now(),
|
|
97
|
+
};
|
|
98
|
+
saveGoalState(pi, edited);
|
|
99
|
+
ctx.ui.notify('Goal objective updated.', 'info');
|
|
100
|
+
if (edited.status === 'active') pi.sendUserMessage(buildGoalPrompt(edited));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
case 'budget': {
|
|
104
|
+
const budget = Number(argument);
|
|
105
|
+
if (!goal || !Number.isInteger(budget) || budget < 1 || budget > MAX_GOAL_ITERATIONS) {
|
|
106
|
+
ctx.ui.notify(`Usage: /goal budget <1-${MAX_GOAL_ITERATIONS}> (requires a saved goal)`, 'warning');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const updated: GoalState = {
|
|
110
|
+
...goal,
|
|
111
|
+
maxIterations: budget,
|
|
112
|
+
status: (goal.status === 'active' || goal.status === 'paused') && goal.iteration >= budget
|
|
113
|
+
? 'budget_exceeded'
|
|
114
|
+
: goal.status,
|
|
115
|
+
updatedAt: Date.now(),
|
|
116
|
+
};
|
|
117
|
+
saveGoalState(pi, updated);
|
|
118
|
+
ctx.ui.notify(`Goal iteration budget set to ${budget}.`, 'info');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
if (!ctx.isIdle()) {
|
|
123
|
+
ctx.ui.notify('Wait for the current run to finish before starting a goal.', 'warning');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (goal?.status === 'active' || goal?.status === 'paused') {
|
|
127
|
+
ctx.ui.notify('A goal is already in progress. Use /goal status, /goal pause, or /goal clear first.', 'warning');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
await startGoal(pi, ctx, input);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function startGoal(pi: ExtensionAPI, ctx: ExtensionCommandContext, objective: string): Promise<void> {
|
|
137
|
+
if (!objective) {
|
|
138
|
+
ctx.ui.notify('Usage: /goal <objective>', 'warning');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const now = Date.now();
|
|
142
|
+
const goal: GoalState = {
|
|
143
|
+
version: 1,
|
|
144
|
+
objective,
|
|
145
|
+
status: 'active',
|
|
146
|
+
progress: '',
|
|
147
|
+
iteration: 0,
|
|
148
|
+
reportCount: 0,
|
|
149
|
+
maxIterations: DEFAULT_GOAL_ITERATIONS,
|
|
150
|
+
createdAt: now,
|
|
151
|
+
updatedAt: now,
|
|
152
|
+
};
|
|
153
|
+
saveGoalState(pi, goal);
|
|
154
|
+
ctx.ui.notify(`Starting goal (up to ${goal.maxIterations} automatic iterations): ${objective}`, 'info');
|
|
155
|
+
pi.sendUserMessage(buildGoalPrompt(goal, true));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function registerGoalLifecycle(pi: ExtensionAPI): void {
|
|
159
|
+
pi.on('agent_before_settle', (event, ctx) => {
|
|
160
|
+
const goal = readGoalState([...ctx.sessionManager.getBranch(), ...event.entries]);
|
|
161
|
+
if (!goal || goal.status !== 'active') return;
|
|
162
|
+
|
|
163
|
+
if (event.outcome === 'error') {
|
|
164
|
+
const blocked: GoalState = {
|
|
165
|
+
...goal,
|
|
166
|
+
status: 'blocked',
|
|
167
|
+
progress: 'The agent turn ended with an error. Inspect the error before resuming.',
|
|
168
|
+
updatedAt: Date.now(),
|
|
169
|
+
};
|
|
170
|
+
ctx.ui.notify('Goal stopped because the agent turn failed. Use /goal status, then /goal resume after resolving the issue.', 'warning');
|
|
171
|
+
return { entries: [...event.entries, saveGoalStateDraft(blocked)] };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (event.outcome === 'aborted') return;
|
|
175
|
+
|
|
176
|
+
if (ctx.hasPendingMessages() || event.context.pendingMessages.length > 0) {
|
|
177
|
+
if (goal.reportCount === 0) return;
|
|
178
|
+
return {
|
|
179
|
+
entries: [
|
|
180
|
+
...event.entries,
|
|
181
|
+
saveGoalStateDraft({ ...goal, reportCount: 0, updatedAt: Date.now() }),
|
|
182
|
+
],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (goal.reportCount !== 1) {
|
|
187
|
+
const unreported: GoalState = {
|
|
188
|
+
...goal,
|
|
189
|
+
status: 'blocked',
|
|
190
|
+
progress: 'The agent turn ended without exactly one goal_report for this iteration.',
|
|
191
|
+
updatedAt: Date.now(),
|
|
192
|
+
};
|
|
193
|
+
ctx.ui.notify('Goal stopped because this turn did not produce exactly one progress report. Use /goal status, then /goal resume to continue.', 'warning');
|
|
194
|
+
return { entries: [...event.entries, saveGoalStateDraft(unreported)] };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (goal.iteration >= goal.maxIterations) {
|
|
198
|
+
const exhausted: GoalState = {
|
|
199
|
+
...goal,
|
|
200
|
+
status: 'budget_exceeded',
|
|
201
|
+
updatedAt: Date.now(),
|
|
202
|
+
};
|
|
203
|
+
ctx.ui.notify(`Goal iteration budget (${goal.maxIterations}) reached. Use /goal resume for another bounded run.`, 'warning');
|
|
204
|
+
return { entries: [...event.entries, saveGoalStateDraft(exhausted)] };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const next: GoalState = { ...goal, iteration: goal.iteration + 1, reportCount: 0, updatedAt: Date.now() };
|
|
208
|
+
return {
|
|
209
|
+
entries: [
|
|
210
|
+
...event.entries,
|
|
211
|
+
saveGoalStateDraft(next),
|
|
212
|
+
{
|
|
213
|
+
type: 'custom_message',
|
|
214
|
+
customType: 'bi.goal-continuation',
|
|
215
|
+
content: buildGoalPrompt(next),
|
|
216
|
+
display: false,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
continue: true,
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// An Escape/abort skips agent_before_settle in Pi. Persist a pause here so the
|
|
224
|
+
// goal never resumes automatically after an intentional interruption.
|
|
225
|
+
pi.on('agent_settled', (event, ctx) => {
|
|
226
|
+
if (!event.aborted) return;
|
|
227
|
+
const goal = readGoalState(ctx.sessionManager.getBranch());
|
|
228
|
+
if (!goal || goal.status !== 'active') return;
|
|
229
|
+
saveGoalState(pi, { ...goal, status: 'paused', updatedAt: Date.now() });
|
|
230
|
+
ctx.ui.notify('Goal paused after interruption. Use /goal resume to continue.', 'info');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// Recover active goals on restart/fork, but never auto-run on a new session or
|
|
234
|
+
// extension reload. Reconcile a report saved just before a process restart.
|
|
235
|
+
pi.on('session_start', (event, ctx) => {
|
|
236
|
+
const saved = readGoalState(ctx.sessionManager.getBranch());
|
|
237
|
+
if (!saved || saved.status !== 'active') return;
|
|
238
|
+
let goal = saved;
|
|
239
|
+
if (goal.reportCount > 0) {
|
|
240
|
+
if (goal.iteration >= goal.maxIterations) {
|
|
241
|
+
goal = { ...goal, status: 'budget_exceeded', reportCount: 0, updatedAt: Date.now() };
|
|
242
|
+
saveGoalState(pi, goal);
|
|
243
|
+
ctx.ui.notify(`Goal iteration budget (${goal.maxIterations}) reached before session recovery.`, 'warning');
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
goal = { ...goal, iteration: goal.iteration + 1, reportCount: 0, updatedAt: Date.now() };
|
|
247
|
+
saveGoalState(pi, goal);
|
|
248
|
+
}
|
|
249
|
+
if (event.reason !== 'startup' && event.reason !== 'resume' && event.reason !== 'fork') return;
|
|
250
|
+
if (!ctx.isIdle() || ctx.hasPendingMessages()) return;
|
|
251
|
+
ctx.ui.notify(`Resuming saved goal: ${goal.objective}`, 'info');
|
|
252
|
+
pi.sendUserMessage(buildGoalPrompt(goal));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { Type } from 'typebox';
|
|
3
|
+
import { readGoalState, saveGoalState } from './state.ts';
|
|
4
|
+
|
|
5
|
+
const parameters = Type.Object({
|
|
6
|
+
status: Type.Union([
|
|
7
|
+
Type.Literal('continue'),
|
|
8
|
+
Type.Literal('completed'),
|
|
9
|
+
Type.Literal('blocked'),
|
|
10
|
+
]),
|
|
11
|
+
summary: Type.String({ minLength: 1, maxLength: 4_000 }),
|
|
12
|
+
verification: Type.Optional(Type.Object({
|
|
13
|
+
status: Type.Union([Type.Literal('passed'), Type.Literal('failed'), Type.Literal('not_run')]),
|
|
14
|
+
summary: Type.String({ minLength: 1, maxLength: 1000 }),
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export function registerGoalReportTool(pi: ExtensionAPI): void {
|
|
19
|
+
pi.registerTool({
|
|
20
|
+
name: 'goal_report',
|
|
21
|
+
label: 'Report goal progress',
|
|
22
|
+
description: 'Record verified progress on the active /goal and tell Honeycomb whether to continue, stop as completed, or report a blocker.',
|
|
23
|
+
promptSnippet: 'Record progress and completion/blocker status for the active /goal',
|
|
24
|
+
promptGuidelines: ['Call only while a persistent /goal is active. Include verification status and the checks actually run, or report not_run.'],
|
|
25
|
+
parameters,
|
|
26
|
+
execute: async (_toolCallId, args, _signal, _onUpdate, ctx) => {
|
|
27
|
+
const goal = readGoalState(ctx.sessionManager.getBranch());
|
|
28
|
+
if (!goal || goal.status !== 'active') {
|
|
29
|
+
return {
|
|
30
|
+
content: [{ type: 'text', text: 'There is no active goal to report progress for.' }],
|
|
31
|
+
details: {},
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (goal.reportCount !== 0) {
|
|
36
|
+
saveGoalState(pi, {
|
|
37
|
+
...goal,
|
|
38
|
+
status: 'blocked',
|
|
39
|
+
progress: 'More than one goal_report was submitted for this iteration.',
|
|
40
|
+
reportCount: goal.reportCount + 1,
|
|
41
|
+
updatedAt: Date.now(),
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: 'text', text: 'A progress report was already recorded for this iteration; the goal is now blocked.' }],
|
|
45
|
+
details: {},
|
|
46
|
+
isError: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const summary = args.summary.trim();
|
|
50
|
+
if (!summary) {
|
|
51
|
+
return {
|
|
52
|
+
content: [{ type: 'text', text: 'The progress summary must not be empty.' }],
|
|
53
|
+
details: {},
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const status = args.status === 'continue' ? 'active' : args.status;
|
|
59
|
+
saveGoalState(pi, { ...goal, status, progress: summary, verification: args.verification, reportCount: goal.reportCount + 1, updatedAt: Date.now() });
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: 'text', text: `Goal progress saved (${status}).` }],
|
|
62
|
+
details: {},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
|
|
3
|
+
export const GOAL_STATE_ENTRY = 'bi.goal-state';
|
|
4
|
+
export const DEFAULT_GOAL_ITERATIONS = 8;
|
|
5
|
+
export const MAX_GOAL_ITERATIONS = 50;
|
|
6
|
+
|
|
7
|
+
export type GoalStatus = 'active' | 'paused' | 'completed' | 'blocked' | 'budget_exceeded';
|
|
8
|
+
|
|
9
|
+
export interface GoalState {
|
|
10
|
+
version: 1;
|
|
11
|
+
objective: string;
|
|
12
|
+
status: GoalStatus;
|
|
13
|
+
progress: string;
|
|
14
|
+
verification?: { status: 'passed' | 'failed' | 'not_run'; summary: string };
|
|
15
|
+
iteration: number;
|
|
16
|
+
reportCount: number;
|
|
17
|
+
maxIterations: number;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function readGoalState(entries: readonly unknown[]): GoalState | undefined {
|
|
23
|
+
const entry = [...entries].reverse().find((candidate) => {
|
|
24
|
+
if (candidate === null || typeof candidate !== 'object') return false;
|
|
25
|
+
const value = candidate as { type?: unknown; customType?: unknown };
|
|
26
|
+
return value.type === 'custom' && value.customType === GOAL_STATE_ENTRY;
|
|
27
|
+
}) as { data?: unknown } | undefined;
|
|
28
|
+
if (!entry || entry.data === null) return undefined;
|
|
29
|
+
return isGoalState(entry.data) ? entry.data : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isGoalState(value: unknown): value is GoalState {
|
|
33
|
+
if (value === null || typeof value !== 'object') return false;
|
|
34
|
+
const state = value as Record<string, unknown>;
|
|
35
|
+
return state.version === 1 &&
|
|
36
|
+
typeof state.objective === 'string' &&
|
|
37
|
+
['active', 'paused', 'completed', 'blocked', 'budget_exceeded'].includes(String(state.status)) &&
|
|
38
|
+
typeof state.progress === 'string' &&
|
|
39
|
+
typeof state.iteration === 'number' && Number.isInteger(state.iteration) && state.iteration >= 0 &&
|
|
40
|
+
typeof state.reportCount === 'number' && Number.isInteger(state.reportCount) && state.reportCount >= 0 &&
|
|
41
|
+
typeof state.maxIterations === 'number' && Number.isInteger(state.maxIterations) && state.maxIterations >= 1 &&
|
|
42
|
+
state.maxIterations <= MAX_GOAL_ITERATIONS &&
|
|
43
|
+
typeof state.createdAt === 'number' && Number.isFinite(state.createdAt) &&
|
|
44
|
+
typeof state.updatedAt === 'number' && Number.isFinite(state.updatedAt);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function saveGoalState(pi: ExtensionAPI, state: GoalState): void {
|
|
48
|
+
pi.appendEntry(GOAL_STATE_ENTRY, state);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function saveGoalStateDraft(state: GoalState) {
|
|
52
|
+
return { type: 'custom' as const, customType: GOAL_STATE_ENTRY, data: state };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function goalStatusText(state: GoalState): string {
|
|
56
|
+
const label = state.status.replace('_', ' ');
|
|
57
|
+
const progress = state.progress ? `\nProgress: ${state.progress}` : '';
|
|
58
|
+
return `Goal (${label}) — ${state.objective}\nIterations: ${state.iteration}/${state.maxIterations}${progress}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function buildGoalPrompt(state: GoalState, firstRun = false): string {
|
|
62
|
+
const context = firstRun
|
|
63
|
+
? 'Inspect the project instructions and relevant code first. Make a concise plan with concrete, verifiable acceptance criteria, then work through it step by step.'
|
|
64
|
+
: `Continue from the current project state. This is automatic iteration ${Math.max(1, state.iteration)} of ${state.maxIterations}. Use this latest progress report as your checkpoint: ${state.progress || 'No progress report was recorded yet.'}`;
|
|
65
|
+
|
|
66
|
+
return [
|
|
67
|
+
`Persistent goal: ${state.objective}`,
|
|
68
|
+
'',
|
|
69
|
+
context,
|
|
70
|
+
'Make concrete progress toward the goal in this turn. Follow project conventions and existing tool approval/safety boundaries. Run relevant checks and inspect their results.',
|
|
71
|
+
`Before ending this turn, call the goal_report tool exactly once with a concise progress summary and status: use "continue" if work remains, "completed" only after checking the acceptance criteria and relevant verification, or "blocked" if user input or an unavailable capability prevents safe progress. Do not guess when blocked; ask one focused clarifying question in your visible response. Do not mark completed based only on a plan or an unverified claim.`,
|
|
72
|
+
'If work remains, describe what is done, what remains, and the latest checks in the report so the next iteration can continue from evidence.',
|
|
73
|
+
].join('\n');
|
|
74
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { PermissionController } from '../extension/permission-modes/index.ts';
|
|
3
|
+
import { decidePermission } from '../extension/permission-modes/policy.ts';
|
|
4
|
+
import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
|
|
5
|
+
import type { ProcessManager } from '../tools/execution.ts';
|
|
6
|
+
import { jobLabel } from '../tui/tasks-panel.ts';
|
|
7
|
+
|
|
8
|
+
/** A built-in notification only; repository settings cannot run code at lifecycle events. */
|
|
9
|
+
export function registerHooksCommand(pi: ExtensionAPI, permissions: PermissionController, jobs?: Pick<ProcessManager, 'onJobFinished'>): void {
|
|
10
|
+
let unsubscribe: (() => void) | undefined;
|
|
11
|
+
const clear = () => { unsubscribe?.(); unsubscribe = undefined; };
|
|
12
|
+
pi.on('session_start', clear);
|
|
13
|
+
pi.on('session_tree', clear);
|
|
14
|
+
pi.on('session_shutdown', clear);
|
|
15
|
+
pi.registerCommand('hooks', {
|
|
16
|
+
description: 'View or toggle session-local background job completion notifications',
|
|
17
|
+
async handler(args, ctx) {
|
|
18
|
+
if (ctx.mode !== 'tui' || !ctx.hasUI) return;
|
|
19
|
+
const input = args.trim();
|
|
20
|
+
if (!input) return ctx.ui.notify(`Job completion notifications: ${!jobs ? 'unavailable' : unsubscribe ? 'on' : 'off'}. Use /hooks jobs on|off.`, 'info');
|
|
21
|
+
if (input === 'jobs off') { clear(); return ctx.ui.notify('Job completion notifications off.', 'info'); }
|
|
22
|
+
if (input !== 'jobs on') return ctx.ui.notify('Usage: /hooks [jobs on|off]', 'warning');
|
|
23
|
+
if (!jobs || !ctx.isProjectTrusted() || !ctx.isIdle() || ctx.hasPendingMessages() || ['plan', 'dontAsk'].includes(permissions.mode)) {
|
|
24
|
+
return ctx.ui.notify('Job notifications require an idle, trusted terminal with managed jobs enabled, outside Plan and No prompts.', 'warning');
|
|
25
|
+
}
|
|
26
|
+
clear();
|
|
27
|
+
const owner = ctx.sessionManager.getSessionId();
|
|
28
|
+
unsubscribe = jobs.onJobFinished((session, job) => {
|
|
29
|
+
if (owner !== session || ctx.sessionManager.getSessionId() !== owner || !ctx.isProjectTrusted() || ['plan', 'dontAsk'].includes(permissions.mode)) return;
|
|
30
|
+
const config = loadPermissionRules(ctx.cwd, () => {});
|
|
31
|
+
if (!config.invalid && decidePermission(permissions.mode, 'process', { processId: job.id }, ctx.cwd, config.rules).action === 'allow') {
|
|
32
|
+
ctx.ui.notify(`Job ${jobLabel(job)} · /tasks jobs`, 'info');
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
ctx.ui.notify('Job completion notifications on for this session branch.', 'info');
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { registerBtwCommand } from './btw.ts';
|
|
2
|
+
export { registerDiffCommand } from './diff.ts';
|
|
3
|
+
export { registerDiscoveryCommands } from './discovery.ts';
|
|
4
|
+
export { registerDoctorCommand } from './doctor.ts';
|
|
5
|
+
export { registerGoalCommand } from './goal/index.ts';
|
|
6
|
+
export { registerInitCommand } from './init.ts';
|
|
7
|
+
export { registerPlanCommand } from './plan.ts';
|
|
8
|
+
export { registerReviewCommand } from './review.ts';
|
|
9
|
+
export { registerSecurityReviewCommand } from './security-review.ts';
|
|
10
|
+
export { registerSimplifyCommand } from './simplify.ts';
|
|
11
|
+
export { registerTasksCommand } from './tasks.ts';
|
|
12
|
+
export { registerVerifyCommand } from './verify.ts';
|
|
13
|
+
export { registerWorktreeCommand } from './worktree.ts';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
4
|
+
|
|
5
|
+
export function registerInitCommand(pi: ExtensionAPI) {
|
|
6
|
+
// /init — analyze the codebase and generate AGENTS.md
|
|
7
|
+
pi.registerCommand('init', {
|
|
8
|
+
description: 'Analyze the codebase and generate AGENTS.md',
|
|
9
|
+
handler: async (_args, ctx) => {
|
|
10
|
+
const agentsPath = join(ctx.cwd, 'AGENTS.md');
|
|
11
|
+
|
|
12
|
+
// Don't queue the prompt while the agent is mid-run
|
|
13
|
+
if (!ctx.isIdle()) {
|
|
14
|
+
ctx.ui.notify(
|
|
15
|
+
'Agent is busy — wait for the current run to finish, then run /init again.',
|
|
16
|
+
'warning',
|
|
17
|
+
);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// AGENTS.md already exists? Ask before overwriting.
|
|
22
|
+
if (existsSync(agentsPath) && ctx.hasUI) {
|
|
23
|
+
const regenerate = await ctx.ui.confirm(
|
|
24
|
+
'AGENTS.md exists',
|
|
25
|
+
'Start analyzing the project to propose an update? The actual file change may still require approval.',
|
|
26
|
+
);
|
|
27
|
+
if (!regenerate) {
|
|
28
|
+
ctx.ui.notify('/init cancelled', 'info');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const prompt = [
|
|
34
|
+
'Analyze this repository and create or update only the root AGENTS.md for future coding agents.)',
|
|
35
|
+
'',
|
|
36
|
+
'Inspect:',
|
|
37
|
+
'- README.md, CONTRIBUTING.md, relevant docs/.',
|
|
38
|
+
'- CI workflows, Makefile/justfile, scripts/.',
|
|
39
|
+
'- Manifests, lockfiles, runtime/toolchain version files.',
|
|
40
|
+
'- Lint/format/type configs and .env.example.',
|
|
41
|
+
'- Root/nested AGENTS.md, CLAUDE.md, .cursorrules, .github/copilot-instructions.md.',
|
|
42
|
+
'- Relevant source files and tests.',
|
|
43
|
+
'',
|
|
44
|
+
'Cross-check sources; distinguish local commands from CI-only commands. Report unresolved conflicts. Preserve accurate existing guidance and unrelated user edits; correct demonstrably stale instructions. Keep nested instructions scoped to their directories.',
|
|
45
|
+
'',
|
|
46
|
+
'Include only relevant sections:',
|
|
47
|
+
'1. Overview: purpose and main languages/frameworks.',
|
|
48
|
+
'2. Commands: supported install, dev, build, full/single-test, lint, format, typecheck; include working directories and prerequisites. Never invent commands or syntax.',
|
|
49
|
+
'3. Architecture: entry points, main modules, data/control flow; no directory dumps.',
|
|
50
|
+
'4. Conventions: important patterns not already enforced by tooling.',
|
|
51
|
+
'5. Gotchas: generated files, codegen, required environment variables/services, workspace quirks, version constraints.',
|
|
52
|
+
'',
|
|
53
|
+
'Validate commands against inspected scripts/configs. Execute only safe, non-mutating checks after reviewing definitions and prerequisites. Without permission, do not install dependencies, run auto-fix/format-write or destructive commands, or access external services. Skip commands with unclear effects.',
|
|
54
|
+
'',
|
|
55
|
+
'Distinguish successful execution, observed failure, and configuration-supported commands not run. Claim a command works only after successful execution; failure does not necessarily mean the command is incorrect.',
|
|
56
|
+
'',
|
|
57
|
+
'Use verified facts and concise bullets; aim for under 100 lines without losing essential guidance. Omit speculation, generic advice, and duplicated tooling rules. Never include secrets or real .env values. Do not modify other files or fix unrelated issues.',
|
|
58
|
+
'',
|
|
59
|
+
'Finish by confirming the path and created/updated status, summarizing changes in 2-3 bullets, and separately listing failed/unexecuted commands, unresolved conflicts, and verification limits.',
|
|
60
|
+
].join('\n');
|
|
61
|
+
|
|
62
|
+
ctx.ui.notify('Analyzing codebase — /init prompt sent to agent', 'info');
|
|
63
|
+
pi.sendUserMessage(prompt);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { PermissionController } from '../extension/permission-modes/index.ts';
|
|
3
|
+
import { decidePermission } from '../extension/permission-modes/policy.ts';
|
|
4
|
+
import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
|
|
5
|
+
import { MAX_MEMORY_NOTE, memoryPath, memoryRelativePath, readMemory, writeMemory } from '../tools/memory-store.ts';
|
|
6
|
+
import { show } from './discovery.ts';
|
|
7
|
+
|
|
8
|
+
export function registerMemoryCommands(pi: ExtensionAPI, permissions: PermissionController): void {
|
|
9
|
+
let busy = false;
|
|
10
|
+
let epoch = 0;
|
|
11
|
+
let active: AbortController | undefined;
|
|
12
|
+
const retire = () => { epoch++; active?.abort(); };
|
|
13
|
+
pi.on('session_start', retire);
|
|
14
|
+
pi.on('session_tree', retire);
|
|
15
|
+
pi.on('session_shutdown', retire);
|
|
16
|
+
|
|
17
|
+
async function run(args: string, ctx: ExtensionCommandContext, write: boolean) {
|
|
18
|
+
if (ctx.mode !== 'tui' || !ctx.hasUI) return;
|
|
19
|
+
const mode = permissions.mode, session = ctx.sessionManager.getSessionId(), leaf = ctx.sessionManager.getLeafId(), started = epoch;
|
|
20
|
+
const current = () => started === epoch && !ctx.signal?.aborted && ctx.isProjectTrusted() &&
|
|
21
|
+
ctx.isIdle() && !ctx.hasPendingMessages() && !['plan', 'dontAsk'].includes(mode) && permissions.mode === mode &&
|
|
22
|
+
ctx.sessionManager.getSessionId() === session && ctx.sessionManager.getLeafId() === leaf;
|
|
23
|
+
if (busy || !current()) return ctx.ui.notify('Memory requires an idle, trusted terminal outside Plan and No prompts modes.', 'warning');
|
|
24
|
+
const input = args.trim();
|
|
25
|
+
if (write && (!input || input.length > MAX_MEMORY_NOTE)) {
|
|
26
|
+
return ctx.ui.notify(`Usage: /remember <note> (1–${MAX_MEMORY_NOTE} characters).`, 'warning');
|
|
27
|
+
}
|
|
28
|
+
if (!write && input && !/^[1-9][0-9]{0,2}$/.test(input)) return ctx.ui.notify('Usage: /memory [note-number]', 'warning');
|
|
29
|
+
busy = true;
|
|
30
|
+
const stop = active = new AbortController();
|
|
31
|
+
const unsubscribe = permissions.subscribe(() => stop.abort());
|
|
32
|
+
const signal = ctx.signal ? AbortSignal.any([ctx.signal, stop.signal]) : stop.signal;
|
|
33
|
+
try {
|
|
34
|
+
const target = memoryPath(ctx.cwd);
|
|
35
|
+
const allowed = () => {
|
|
36
|
+
if (signal.aborted || !current() || memoryPath(ctx.cwd) !== target) return false;
|
|
37
|
+
const { invalid, rules } = loadPermissionRules(ctx.cwd, () => {});
|
|
38
|
+
const memory = decidePermission(mode, 'memory', write ? { action: 'append', content: input } : { action: 'read' }, ctx.cwd, rules);
|
|
39
|
+
return !invalid && memory.action !== 'deny' && (write || memory.source !== 'rule' || memory.action === 'allow') &&
|
|
40
|
+
decidePermission(mode, 'read', { path: target }, ctx.cwd, rules).action === 'allow' &&
|
|
41
|
+
(!write || decidePermission(mode, 'write', { path: target, content: input }, ctx.cwd, rules).action !== 'deny');
|
|
42
|
+
};
|
|
43
|
+
if (!allowed()) return ctx.ui.notify('Memory access is not permitted by the current rules.', 'warning');
|
|
44
|
+
const snapshot = await readMemory(ctx.cwd, target);
|
|
45
|
+
if (!allowed()) return;
|
|
46
|
+
if (!write) {
|
|
47
|
+
if (!input) {
|
|
48
|
+
const rows = snapshot.entries.map((note, i) => `${i + 1}. ${note.split(/\r?\n/)[0].slice(0, 160) || '(blank first line)'}`);
|
|
49
|
+
await show(ctx, 'Project memory', rows.length ? ['Use /memory <number> to view a note.', ...rows] : ['No saved project notes.']);
|
|
50
|
+
} else {
|
|
51
|
+
const note = snapshot.entries[Number(input) - 1];
|
|
52
|
+
if (note === undefined) return ctx.ui.notify('Memory note not found.', 'warning');
|
|
53
|
+
const rows = note.slice(0, MAX_MEMORY_NOTE).split(/\r?\n/).flatMap(line => line.match(/.{1,160}/gu) ?? ['']);
|
|
54
|
+
await show(ctx, `Project memory — note ${input}`, [
|
|
55
|
+
...rows.slice(0, 190), ...(note.length > MAX_MEMORY_NOTE || rows.length > 190 ? ['… Note preview truncated.'] : []),
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!await permissions.prompter.confirm(ctx, 'Remember this project note?', `Append to ${memoryRelativePath} (local, plain text):\n\n${input}`, signal) || !allowed()) return;
|
|
61
|
+
await writeMemory(ctx.cwd, snapshot, [...snapshot.entries, input], allowed);
|
|
62
|
+
if (current()) ctx.ui.notify('Project memory note saved.', 'info');
|
|
63
|
+
} catch {
|
|
64
|
+
if (current()) ctx.ui.notify(write ? 'Memory note not saved: state was invalid, unsafe, full, or changed.' : 'Unable to read project memory safely.', 'warning');
|
|
65
|
+
} finally { unsubscribe(); active = undefined; busy = false; }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
pi.registerCommand('memory', { description: 'Browse local project memory without a model call', handler: (args, ctx) => run(args, ctx, false) });
|
|
69
|
+
pi.registerCommand('remember', { description: 'Append a local project note after preview and confirmation', handler: (args, ctx) => run(args, ctx, true) });
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { PermissionController } from '../extension/permission-modes/index.ts';
|
|
3
|
+
import { planNotePath, readPlanNote } from '../extension/permission-modes/plan-note.ts';
|
|
4
|
+
import { loadPermissionRules } from '../extension/permission-modes/rules.ts';
|
|
5
|
+
import { decidePermission } from '../extension/permission-modes/policy.ts';
|
|
6
|
+
import { show } from './discovery.ts';
|
|
7
|
+
|
|
8
|
+
export function registerPlanCommand(pi: ExtensionAPI, permissions: PermissionController): void {
|
|
9
|
+
pi.registerCommand('plan', {
|
|
10
|
+
description: 'Enter Plan mode, start planning a request, or show the session note',
|
|
11
|
+
async handler(args, ctx) {
|
|
12
|
+
if (ctx.mode !== 'tui' || !ctx.hasUI) return;
|
|
13
|
+
if (!ctx.isIdle() || ctx.hasPendingMessages()) return ctx.ui.notify('Wait for the current run and queued input before /plan.', 'warning');
|
|
14
|
+
const request = args.trim();
|
|
15
|
+
if (request === 'show' || (!request && permissions.mode === 'plan')) {
|
|
16
|
+
try {
|
|
17
|
+
const session = ctx.sessionManager.getSessionId();
|
|
18
|
+
const leaf = ctx.sessionManager.getLeafId();
|
|
19
|
+
const path = planNotePath(ctx.cwd, session);
|
|
20
|
+
const rules = loadPermissionRules(ctx.cwd, () => {});
|
|
21
|
+
if (rules.invalid || decidePermission(permissions.mode, 'read', { path }, ctx.cwd, rules.rules).action !== 'allow') {
|
|
22
|
+
return ctx.ui.notify('Plan note cannot be displayed under the current permission rules.', 'warning');
|
|
23
|
+
}
|
|
24
|
+
const note = await readPlanNote(ctx.cwd, session);
|
|
25
|
+
const currentRules = loadPermissionRules(ctx.cwd, () => {});
|
|
26
|
+
if (ctx.sessionManager.getSessionId() !== session || ctx.sessionManager.getLeafId() !== leaf || !ctx.isIdle() || ctx.hasPendingMessages() || currentRules.invalid || decidePermission(permissions.mode, 'read', { path }, ctx.cwd, currentRules.rules).action !== 'allow') return;
|
|
27
|
+
await show(ctx, 'Session plan', note ? note.split('\n') : ['No saved plan note.']);
|
|
28
|
+
} catch { ctx.ui.notify('Unable to read the session plan note safely.', 'warning'); }
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!permissions.enterPlan()) return ctx.ui.notify('Cannot enter Plan from the current permission mode.', 'warning');
|
|
32
|
+
if (request) pi.sendUserMessage(`Create a plan for the following request. Inspect relevant context and save the plan with plan_note. Do not implement it.\n\n${request}`);
|
|
33
|
+
else ctx.ui.notify('Plan mode enabled.', 'info');
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Type } from 'typebox';
|
|
2
|
+
import { Value } from 'typebox/value';
|
|
3
|
+
|
|
4
|
+
const report = Type.Object({
|
|
5
|
+
summary: Type.String({ minLength: 1, maxLength: 500 }),
|
|
6
|
+
findings: Type.Array(Type.Object({
|
|
7
|
+
severity: Type.Union([Type.Literal('high'), Type.Literal('medium'), Type.Literal('low')]),
|
|
8
|
+
file: Type.String({ minLength: 1, maxLength: 512 }),
|
|
9
|
+
line: Type.Union([Type.Integer({ minimum: 1, maximum: 10_000_000 }), Type.Null()]),
|
|
10
|
+
message: Type.String({ minLength: 1, maxLength: 750 }),
|
|
11
|
+
}, { additionalProperties: false }), { maxItems: 12 }),
|
|
12
|
+
limitations: Type.String({ minLength: 1, maxLength: 500 }),
|
|
13
|
+
}, { additionalProperties: false });
|
|
14
|
+
|
|
15
|
+
export const reviewReportFormat = `Return a single JSON object that matches this schema (no Markdown or extra text):\n${JSON.stringify(report)}`;
|
|
16
|
+
|
|
17
|
+
export function validatedReviewReport(text: string): string | undefined {
|
|
18
|
+
if (!text || text.length > 16_000) return;
|
|
19
|
+
try {
|
|
20
|
+
const parsed: unknown = JSON.parse(text);
|
|
21
|
+
if (Value.Check(report, parsed)) return JSON.stringify(parsed, null, 2);
|
|
22
|
+
} catch { /* Do not show malformed provider responses as valid data. */ }
|
|
23
|
+
}
|