@glrs-dev/harness-plugin-opencode 2.3.0 → 2.4.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.
@@ -1,117 +0,0 @@
1
- import {
2
- createSession,
3
- sendAndWait,
4
- startServer
5
- } from "./chunk-GCWHRUOK.js";
6
-
7
- // src/autopilot/plan-session.ts
8
- import * as fs from "fs";
9
- import * as path from "path";
10
- var DEFAULT_PLAN_TIMEOUT_MS = 10 * 60 * 1e3;
11
- async function runPlanSession(opts) {
12
- const timeoutMs = opts.timeoutMs ?? DEFAULT_PLAN_TIMEOUT_MS;
13
- const _startServer = opts._deps?.startServer ?? startServer;
14
- const _createSession = opts._deps?.createSession ?? createSession;
15
- const _sendAndWait = opts._deps?.sendAndWait ?? sendAndWait;
16
- const _existsSync = opts._deps?.existsSync ?? fs.existsSync;
17
- const server = await _startServer({ cwd: opts.planDir });
18
- try {
19
- const sessionId = await _createSession(server.client, {
20
- cwd: opts.planDir,
21
- agentName: "plan"
22
- });
23
- const multiFileDir = path.join(opts.planDir, opts.slug);
24
- const multiFileMain = path.join(multiFileDir, "main.md");
25
- const singleFilePlan = path.join(opts.planDir, `${opts.slug}.md`);
26
- const prompt = `Read the scope at ${opts.scopePath} and produce a plan. Use slug ${opts.slug} for the plan file(s). If the scope warrants multiple phases, produce a multi-file plan at ${multiFileDir}/main.md + phase_N.md files. Otherwise produce a single-file plan at ${singleFilePlan}.`;
27
- const result = await _sendAndWait(server.client, {
28
- sessionId,
29
- message: prompt,
30
- agentName: "plan",
31
- stallMs: timeoutMs,
32
- autoRejectPermissions: true,
33
- serverUrl: server.url
34
- });
35
- if (result.kind === "abort") {
36
- throw new Error(
37
- `Plan session aborted (timeout after ${timeoutMs}ms).`
38
- );
39
- }
40
- if (result.kind === "stall") {
41
- throw new Error(
42
- `Plan session stalled for ${result.stallMs}ms with no idle signal.`
43
- );
44
- }
45
- if (result.kind === "error") {
46
- throw new Error(`Plan session error: ${result.message}`);
47
- }
48
- if (result.kind === "question_rejected") {
49
- process.stderr.write(
50
- `
51
- \u26A0 @plan tried to ask a question (rejected). Checking if plan was written anyway...
52
- `
53
- );
54
- }
55
- if (_existsSync(multiFileMain)) {
56
- return { planPath: multiFileDir };
57
- }
58
- if (_existsSync(singleFilePlan)) {
59
- return { planPath: singleFilePlan };
60
- }
61
- process.stderr.write(
62
- `
63
- \u26A0 @plan didn't write a plan file. Re-sending with explicit instructions...
64
- `
65
- );
66
- const retryPrompt = `You did not write a plan file. Write the plan NOW. Read the scope at ${opts.scopePath}. Write the plan to ${singleFilePlan} (single-file) or ${multiFileDir}/main.md (multi-file). Do NOT ask questions. Just write the plan.`;
67
- const retryResult = await _sendAndWait(server.client, {
68
- sessionId,
69
- message: retryPrompt,
70
- agentName: "plan",
71
- stallMs: timeoutMs,
72
- autoRejectPermissions: true,
73
- serverUrl: server.url
74
- });
75
- if (retryResult.kind !== "idle" && retryResult.kind !== "question_rejected") {
76
- throw new Error(`@plan retry failed: ${retryResult.kind}`);
77
- }
78
- if (_existsSync(multiFileMain)) {
79
- return { planPath: multiFileDir };
80
- }
81
- if (_existsSync(singleFilePlan)) {
82
- return { planPath: singleFilePlan };
83
- }
84
- process.stderr.write(
85
- `
86
- \u26A0 @plan still didn't write a plan. Constructing minimal plan from scope.
87
- `
88
- );
89
- const scopeContent = fs.existsSync(opts.scopePath) ? fs.readFileSync(opts.scopePath, "utf-8") : `# Plan
90
-
91
- Scope file not found at ${opts.scopePath}.`;
92
- const minimalPlan = [
93
- `# Plan (auto-generated from scope)`,
94
- "",
95
- "This plan was auto-generated because @plan did not produce a plan file.",
96
- "Review and refine before executing.",
97
- "",
98
- scopeContent,
99
- "",
100
- "## Acceptance criteria",
101
- "",
102
- "- [ ] Review and refine this auto-generated plan",
103
- "",
104
- "## File-level changes",
105
- "",
106
- "- To be determined after plan review."
107
- ].join("\n");
108
- fs.mkdirSync(path.dirname(singleFilePlan), { recursive: true });
109
- fs.writeFileSync(singleFilePlan, minimalPlan);
110
- return { planPath: singleFilePlan };
111
- } finally {
112
- await server.shutdown();
113
- }
114
- }
115
- export {
116
- runPlanSession
117
- };
@@ -1,326 +0,0 @@
1
- import {
2
- createSession,
3
- getLastAssistantMessage,
4
- sendAndWait,
5
- startServer
6
- } from "./chunk-GCWHRUOK.js";
7
-
8
- // src/autopilot/scoper.ts
9
- import * as fs from "fs";
10
- import * as path from "path";
11
- var ANSI_RESET = "\x1B[0m\x1B[2K\r";
12
- var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
13
- function createSpinner() {
14
- let timer = null;
15
- let frame = 0;
16
- return {
17
- start(label = "Thinking") {
18
- if (timer) return;
19
- frame = 0;
20
- const isTTY = process.stderr.isTTY ?? false;
21
- if (!isTTY) return;
22
- timer = setInterval(() => {
23
- const f = SPINNER_FRAMES[frame % SPINNER_FRAMES.length];
24
- process.stderr.write(`\x1B[2K\r\x1B[36m${f}\x1B[0m ${label}...`);
25
- frame++;
26
- }, 80);
27
- },
28
- stop() {
29
- if (!timer) return;
30
- clearInterval(timer);
31
- timer = null;
32
- process.stderr.write("\x1B[2K\r");
33
- }
34
- };
35
- }
36
- function parseQuestion(response) {
37
- const match = response.match(/^([^\n]{1,199}\?)\s*$/);
38
- return match ? match[1] ?? null : null;
39
- }
40
- function parseScopeSummary(response) {
41
- const match = response.match(/^SCOPE_SUMMARY:\s*\n?([\s\S]+)$/);
42
- return match ? match[1]?.trim() ?? null : null;
43
- }
44
- function extractScopeCompletePath(output) {
45
- const lines = output.split("\n");
46
- let lastMatch = null;
47
- for (const line of lines) {
48
- const trimmed = line.trim();
49
- if (trimmed.startsWith("SCOPE_COMPLETE:")) {
50
- const rest = trimmed.slice("SCOPE_COMPLETE:".length).trim();
51
- if (rest.length > 0) {
52
- lastMatch = rest;
53
- }
54
- }
55
- }
56
- return lastMatch;
57
- }
58
- var DEFAULT_SCOPER_TIMEOUT_MS = 5 * 60 * 1e3;
59
- var MAX_QUESTIONS = 8;
60
- var FORCED_FINALIZE_MESSAGE = "You have asked enough questions. Present a SCOPE_SUMMARY for user approval, then write scope.md and emit SCOPE_COMPLETE.";
61
- var PARSE_RETRY_REMINDER = "Your last response did not follow the strict contract. Respond with EXACTLY one of: (a) a single question (\u2264200 chars, ending with '?'), (b) a scope summary starting with 'SCOPE_SUMMARY:', or (c) the sentinel 'SCOPE_COMPLETE: <absolute-path>'. Nothing else.";
62
- async function runScoperSession(opts) {
63
- const timeoutMs = opts.timeoutMs ?? DEFAULT_SCOPER_TIMEOUT_MS;
64
- const _startServer = opts._deps?.startServer ?? startServer;
65
- const _createSession = opts._deps?.createSession ?? createSession;
66
- const _sendAndWait = opts._deps?.sendAndWait ?? sendAndWait;
67
- const _getLastAssistantMessage = opts._deps?.getLastAssistantMessage ?? getLastAssistantMessage;
68
- const _existsSync = opts._deps?.existsSync ?? fs.existsSync;
69
- const _promptUser = opts._deps?.promptUser ?? (async (question) => {
70
- const { input } = await import("@inquirer/prompts");
71
- return input({ message: question });
72
- });
73
- const server = await _startServer({ cwd: opts.planDir });
74
- const spinner = createSpinner();
75
- try {
76
- const sessionId = await _createSession(server.client, {
77
- cwd: opts.planDir,
78
- agentName: "scoper"
79
- });
80
- const initialPrompt = [
81
- "You are running in an inquirer-driven wizard. Follow the strict response contract:",
82
- "- Every response must be EXACTLY one of:",
83
- " (a) A single question (\u2264200 chars, ending with '?')",
84
- " (b) A scope summary starting with 'SCOPE_SUMMARY:' for user approval",
85
- " (c) The sentinel 'SCOPE_COMPLETE: <absolute-path>'",
86
- "- Do NOT call the question tool. Emit questions as plain assistant text.",
87
- "- Start with first-principles questions (WHAT and WHY), not implementation details.",
88
- "",
89
- `The user wants to build: ${opts.initialGoal}`,
90
- "",
91
- "Begin by asking your first clarifying question about the problem being solved."
92
- ].join("\n");
93
- spinner.start("Scoper is thinking");
94
- const firstResult = await _sendAndWait(server.client, {
95
- sessionId,
96
- message: initialPrompt,
97
- agentName: "scoper",
98
- stallMs: timeoutMs,
99
- autoRejectPermissions: true
100
- });
101
- if (firstResult.kind === "abort") {
102
- throw new Error(`Scoper session aborted (timeout after ${timeoutMs}ms).`);
103
- }
104
- if (firstResult.kind === "stall") {
105
- throw new Error(
106
- `Scoper session stalled for ${firstResult.stallMs}ms with no idle signal.`
107
- );
108
- }
109
- if (firstResult.kind === "error") {
110
- throw new Error(`Scoper session error: ${firstResult.message}`);
111
- }
112
- let questionsAsked = 0;
113
- let parseRetryPending = false;
114
- while (true) {
115
- const lastMessage = await _getLastAssistantMessage(
116
- server.client,
117
- sessionId
118
- );
119
- const scopePath = extractScopeCompletePath(lastMessage);
120
- if (scopePath) {
121
- spinner.stop();
122
- if (!_existsSync(scopePath)) {
123
- throw new Error(
124
- `Scoper emitted SCOPE_COMPLETE but scope.md does not exist at: ${scopePath}`
125
- );
126
- }
127
- return { scopePath };
128
- }
129
- if (questionsAsked >= MAX_QUESTIONS) {
130
- spinner.start("Finalizing scope");
131
- const finalResult = await _sendAndWait(server.client, {
132
- sessionId,
133
- message: FORCED_FINALIZE_MESSAGE,
134
- stallMs: timeoutMs,
135
- autoRejectPermissions: true
136
- });
137
- if (finalResult.kind !== "idle") {
138
- throw new Error(
139
- `Scoper session failed during forced finalize: ${finalResult.kind}`
140
- );
141
- }
142
- const finalMessage = await _getLastAssistantMessage(
143
- server.client,
144
- sessionId
145
- );
146
- const finalScopePath = extractScopeCompletePath(finalMessage);
147
- if (finalScopePath) {
148
- spinner.stop();
149
- if (!_existsSync(finalScopePath)) {
150
- throw new Error(
151
- `Scoper emitted SCOPE_COMPLETE after forced finalize but scope.md does not exist at: ${finalScopePath}`
152
- );
153
- }
154
- return { scopePath: finalScopePath };
155
- }
156
- const expectedScopePath = path.join(opts.planDir, opts.slug, "scope.md");
157
- if (_existsSync(expectedScopePath)) {
158
- spinner.stop();
159
- process.stderr.write(
160
- `
161
- \u26A0 Scoper didn't emit sentinel, but scope.md exists at ${expectedScopePath}. Using it.
162
-
163
- `
164
- );
165
- return { scopePath: expectedScopePath };
166
- }
167
- spinner.stop();
168
- process.stderr.write(
169
- `
170
- \u26A0 Scoper didn't write scope.md. Constructing from conversation.
171
-
172
- `
173
- );
174
- const scopeDir = path.join(opts.planDir, opts.slug);
175
- if (!_existsSync(scopeDir)) {
176
- fs.mkdirSync(scopeDir, { recursive: true });
177
- }
178
- const constructedScope = [
179
- `# ${opts.initialGoal}`,
180
- "",
181
- "## Goal",
182
- "",
183
- opts.initialGoal,
184
- "",
185
- "## Scoper conversation summary",
186
- "",
187
- "The scoper agent asked 8 questions and the user provided answers,",
188
- "but the agent did not produce a formal scope.md. The last agent",
189
- "response is included below for the plan agent to work from.",
190
- "",
191
- "### Last agent response",
192
- "",
193
- finalMessage || "(no response captured)",
194
- "",
195
- "## Acceptance criteria",
196
- "",
197
- "- To be determined by the plan agent based on the conversation above.",
198
- "",
199
- "## Constraints",
200
- "",
201
- "- To be determined by the plan agent.",
202
- "",
203
- "## Out of scope",
204
- "",
205
- "- To be determined by the plan agent.",
206
- "",
207
- "## Open questions for the plan agent",
208
- "",
209
- "- The scoper did not complete formally. Review the conversation summary above and fill in the missing sections."
210
- ].join("\n");
211
- const constructedPath = path.join(scopeDir, "scope.md");
212
- fs.writeFileSync(constructedPath, constructedScope);
213
- return { scopePath: constructedPath };
214
- }
215
- const summary = parseScopeSummary(lastMessage);
216
- if (summary) {
217
- spinner.stop();
218
- parseRetryPending = false;
219
- process.stderr.write(ANSI_RESET);
220
- process.stderr.write(`
221
- \x1B[1m\u{1F4CB} Scope summary:\x1B[0m
222
-
223
- ${summary}
224
-
225
- `);
226
- const approval = await _promptUser("Approve this scope? (yes / or describe what to change)");
227
- if (approval.toLowerCase().startsWith("yes") || approval.toLowerCase() === "y" || approval.toLowerCase() === "approve") {
228
- spinner.start("Writing scope.md");
229
- const writeResult = await _sendAndWait(server.client, {
230
- sessionId,
231
- message: "The user approved the scope. Write scope.md now and emit SCOPE_COMPLETE.",
232
- stallMs: timeoutMs,
233
- autoRejectPermissions: true
234
- });
235
- if (writeResult.kind !== "idle") {
236
- throw new Error(
237
- `Scoper session failed after scope approval: ${writeResult.kind}`
238
- );
239
- }
240
- continue;
241
- } else {
242
- spinner.start("Scoper is revising");
243
- const reviseResult = await _sendAndWait(server.client, {
244
- sessionId,
245
- message: approval,
246
- stallMs: timeoutMs,
247
- autoRejectPermissions: true
248
- });
249
- if (reviseResult.kind !== "idle") {
250
- throw new Error(
251
- `Scoper session failed during revision: ${reviseResult.kind}`
252
- );
253
- }
254
- continue;
255
- }
256
- }
257
- const question = parseQuestion(lastMessage);
258
- if (question) {
259
- parseRetryPending = false;
260
- spinner.stop();
261
- process.stderr.write(ANSI_RESET);
262
- questionsAsked++;
263
- const userAnswer = await _promptUser(question);
264
- spinner.start("Scoper is thinking");
265
- const nextResult = await _sendAndWait(server.client, {
266
- sessionId,
267
- message: userAnswer,
268
- stallMs: timeoutMs,
269
- autoRejectPermissions: true
270
- });
271
- if (nextResult.kind === "abort") {
272
- throw new Error(
273
- `Scoper session aborted (timeout after ${timeoutMs}ms).`
274
- );
275
- }
276
- if (nextResult.kind === "stall") {
277
- throw new Error(
278
- `Scoper session stalled for ${nextResult.stallMs}ms with no idle signal.`
279
- );
280
- }
281
- if (nextResult.kind === "error") {
282
- throw new Error(`Scoper session error: ${nextResult.message}`);
283
- }
284
- continue;
285
- }
286
- if (parseRetryPending) {
287
- spinner.stop();
288
- throw new Error(
289
- `Scoper response did not follow the strict contract after retry. Last response: ${lastMessage.slice(0, 200)}`
290
- );
291
- }
292
- parseRetryPending = true;
293
- spinner.start("Retrying");
294
- const retryResult = await _sendAndWait(server.client, {
295
- sessionId,
296
- message: PARSE_RETRY_REMINDER,
297
- stallMs: timeoutMs,
298
- autoRejectPermissions: true
299
- });
300
- if (retryResult.kind === "abort") {
301
- throw new Error(
302
- `Scoper session aborted during parse retry (timeout after ${timeoutMs}ms).`
303
- );
304
- }
305
- if (retryResult.kind === "stall") {
306
- throw new Error(
307
- `Scoper session stalled during parse retry for ${retryResult.stallMs}ms.`
308
- );
309
- }
310
- if (retryResult.kind === "error") {
311
- throw new Error(
312
- `Scoper session error during parse retry: ${retryResult.message}`
313
- );
314
- }
315
- }
316
- } finally {
317
- spinner.stop();
318
- await server.shutdown();
319
- }
320
- }
321
- export {
322
- extractScopeCompletePath,
323
- parseQuestion,
324
- parseScopeSummary,
325
- runScoperSession
326
- };