@turri-dev/cli 0.1.3-next.f74e98a → 0.1.4-next.073df25
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 -1
- package/dist/ask.js +34 -15
- package/dist/cli-options.js +12 -6
- package/dist/config-edit.js +1 -0
- package/dist/config.js +5 -2
- package/dist/extension.js +86 -25
- package/dist/genome.js +1 -1
- package/dist/init-config.js +5 -0
- package/dist/loop-cli.js +13 -1
- package/dist/loop-tools.js +31 -12
- package/dist/pi-launch.js +5 -0
- package/dist/pi.js +76 -19
- package/dist/question-dialog.js +9 -3
- package/dist/questioning.js +1 -1
- package/dist/regenerate/activity.js +23 -0
- package/dist/regenerate/conform.js +5 -5
- package/dist/regenerate/conformance-agents.js +28 -8
- package/dist/regenerate/conformance.js +24 -10
- package/dist/regenerate/list-arguments.js +121 -0
- package/dist/regenerate/loop.js +137 -18
- package/dist/regenerate/notes.js +66 -17
- package/dist/regenerate/prompt.js +3 -1
- package/dist/regenerate/regenerate.js +16 -10
- package/dist/regenerate/regression.js +2 -1
- package/dist/regenerate/requires.js +55 -2
- package/dist/regenerate/self-check.js +13 -6
- package/dist/regenerate/test-scripts.js +54 -10
- package/dist/regenerate/unit-review.js +12 -1
- package/dist/regenerate-cli.js +11 -5
- package/dist/release-tools.js +1 -1
- package/dist/resume-line.js +4 -0
- package/dist/review/live.js +2 -1
- package/dist/run-report.js +39 -1
- package/dist/spec-tools.js +10 -45
- package/docs/authoring-plain.md +12 -7
- package/docs/config.md +3 -2
- package/docs/headless.md +33 -3
- package/docs/installation.md +3 -0
- package/docs/regenerating.md +70 -20
- package/docs/skills-and-gates.md +5 -3
- package/docs/using.md +24 -9
- package/genome/rules/func-specs.md +1 -0
- package/genome/rules/project-model.md +5 -3
- package/genome/rules/turri-regeneration.md +76 -0
- package/genome/skills/bud/SKILL.md +67 -36
- package/genome/skills/bud/references/intent.md +4 -0
- package/genome/skills/refactor-module/SKILL.md +24 -2
- package/package.json +3 -3
- package/genome/skills/bud/references/checklist.md +0 -44
package/dist/loop-tools.js
CHANGED
|
@@ -70,7 +70,11 @@ export async function loopReply(loop, statuses, wait) {
|
|
|
70
70
|
return { content: [{ type: "text", text }], details: { jobIds } };
|
|
71
71
|
}
|
|
72
72
|
/** Halt a pulse by its id, or the start of it: what it was, and what moves up behind it. `reason`: why, kept with it. */
|
|
73
|
-
export function stopJob(jobs, named, reason) {
|
|
73
|
+
export function stopJob(jobs, named, reason, loop) {
|
|
74
|
+
// A planned row, or a module by its name: the module is halted - its rows are planned again from the spec each look.
|
|
75
|
+
const module = /^planned-/.test(named.trim()) || !jobs.list().some((job) => job.id.startsWith(named.trim())) ? loop?.halt(named, reason) : undefined;
|
|
76
|
+
if (module !== undefined)
|
|
77
|
+
return module;
|
|
74
78
|
const matches = jobs.list().filter((job) => job.id.startsWith(named.trim()));
|
|
75
79
|
if (matches.length === 0)
|
|
76
80
|
return `No pulse ${named}. /pulses shows them.`;
|
|
@@ -106,6 +110,10 @@ function plainFileOf(cwd, given, what) {
|
|
|
106
110
|
export function asksFromScratch(words) {
|
|
107
111
|
return FROM_SCRATCH.test(words);
|
|
108
112
|
}
|
|
113
|
+
/** Whether a /regenerate asking for its module from scratch asks for its whole requires chain with it. */
|
|
114
|
+
export function asksWholeChain(words) {
|
|
115
|
+
return /\bchain\b|\bevery module\b|\ball (the )?modules\b/i.test(words);
|
|
116
|
+
}
|
|
109
117
|
const FROM_SCRATCH = /\b(from (scratch|nothing|zero|the (start|beginning|ground up))|start(ing)? (it )?(over|afresh)|afresh|anew|clean slate|(delete|wipe|remove|drop|throw away)\b.{0,30}\b(module|code|codebase|everything|all of it))/i;
|
|
110
118
|
/** regenerate: regenerate a module's code up to its spec as it is now. */
|
|
111
119
|
export function regenerateTool(options) {
|
|
@@ -127,6 +135,7 @@ export function regenerateTool(options) {
|
|
|
127
135
|
"A change to a file the spec links - an API surface, a mapping document - is a change to the spec: regenerate sees it by itself, and regenerates every functional spec that uses what links it.",
|
|
128
136
|
"Never stop pulses and start them again yourself to follow a spec change: regenerate does it.",
|
|
129
137
|
"Set from_scratch only when the user asks for the module to be regenerated from scratch - started over, its code deleted - in this conversation, or agrees to it when a module's status says it has to start over: never to fix a pulse that did not land.",
|
|
138
|
+
'from_scratch "module" takes out the code where the module is built; the modules below keep theirs, and the module starts from a copy of the code below it. "chain" takes out every codebase of its requires chain, the base\'s too, and builds all of it again from the bottom: use it after modules were split, merged or moved (refactor-module), or when the user asks for the whole chain.',
|
|
130
139
|
],
|
|
131
140
|
parameters: Type.Object({
|
|
132
141
|
plain_file: Type.Optional(Type.String({ description: "Path to the .plain file. Omitted: the module the project's config.turri.yaml names" })),
|
|
@@ -135,8 +144,9 @@ export function regenerateTool(options) {
|
|
|
135
144
|
functionalities: Type.Optional(Type.Array(Type.String(), {
|
|
136
145
|
description: "Functional specs already built, by id, to regenerate though their spec did not change. Omitted: what the spec now differs from the code in",
|
|
137
146
|
})),
|
|
138
|
-
from_scratch: Type.Optional(Type.
|
|
139
|
-
description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec"
|
|
147
|
+
from_scratch: Type.Optional(Type.Union([Type.Literal("module"), Type.Literal("chain")], {
|
|
148
|
+
description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec. " +
|
|
149
|
+
'"chain": every module of its requires chain too, built again from the bottom',
|
|
140
150
|
})),
|
|
141
151
|
model: MODEL_PARAM,
|
|
142
152
|
wait: WAIT_PARAM,
|
|
@@ -147,15 +157,15 @@ export function regenerateTool(options) {
|
|
|
147
157
|
if (!check.ok)
|
|
148
158
|
throw new Error(`${relative(options.cwd, plainFile) || plainFile} does not parse, so nothing can be regenerated from it yet: ${check.error}`);
|
|
149
159
|
const again = given.functionalities ?? [];
|
|
150
|
-
if (again.length > 0 && given.from_scratch
|
|
160
|
+
if (again.length > 0 && given.from_scratch !== undefined)
|
|
151
161
|
throw new Error("Name functionalities or set from_scratch, not both: from scratch regenerates every one of them.");
|
|
152
162
|
// Named functionalities are work on functionalities, as engine chooses a model for it; the rest, spec changes.
|
|
153
163
|
const work = again.length > 0 ? "functionalities" : "spec_changes";
|
|
154
164
|
const model = options.model !== undefined ? options.model(ctx, plainFile, given.model, work) : given.model;
|
|
155
165
|
const loop = options.loop(ctx);
|
|
156
166
|
const request = { ...(model !== undefined ? { model } : {}), ...(given.guidance !== undefined ? { guidance: given.guidance } : {}) };
|
|
157
|
-
const statuses = given.from_scratch
|
|
158
|
-
? await loop.fromScratch(plainFile, request)
|
|
167
|
+
const statuses = given.from_scratch !== undefined
|
|
168
|
+
? await loop.fromScratch(plainFile, { ...request, chain: given.from_scratch === "chain" })
|
|
159
169
|
: again.length > 0
|
|
160
170
|
? await loop.regenerateAgain(plainFile, again, request)
|
|
161
171
|
: await loop.bringUp(plainFile, request);
|
|
@@ -188,7 +198,7 @@ export function driftTool(options) {
|
|
|
188
198
|
}
|
|
189
199
|
const ACTIVATED_PARAM = Type.Optional(Type.String({ description: 'What activate started, by name - or "all" for every one' }));
|
|
190
200
|
const HALT_PULSE_PARAMS = Type.Object({
|
|
191
|
-
job_id: Type.Optional(Type.String({ description: "The pulse's id, or the start of it" })),
|
|
201
|
+
job_id: Type.Optional(Type.String({ description: "The pulse's id, or the start of it; a planned row's id (planned-<module>-...), or a module's name, halts the module" })),
|
|
192
202
|
reason: Type.Optional(Type.String({ description: "Why it is halted, kept with it - what the spec now says that it did not, say" })),
|
|
193
203
|
activated: ACTIVATED_PARAM,
|
|
194
204
|
});
|
|
@@ -201,12 +211,21 @@ export function haltTool(options) {
|
|
|
201
211
|
name: "halt",
|
|
202
212
|
label: "Halt",
|
|
203
213
|
description: jobs !== undefined
|
|
204
|
-
? "Halt a pulse, or what activate started. A pulse: a queued one never starts, a running one has its
|
|
205
|
-
"and the pulses queued behind it move up - what a running pulse already changed is rolled back, and what
|
|
206
|
-
"counts as not regenerated.
|
|
214
|
+
? "Halt a pulse, a module's planned pulses, or what activate started. A pulse: a queued one never starts, a running one has its " +
|
|
215
|
+
"agent stopped at once, and the pulses queued behind it move up - what a running pulse already changed is rolled back, and what " +
|
|
216
|
+
"it was regenerating counts as not regenerated. A planned row (planned-<module>-...) or a module's name halts the module: its " +
|
|
217
|
+
"running pulse stopped, none of its planned pulses started, and the modules built on it waiting - until it is asked for again " +
|
|
218
|
+
"with regenerate; a spec change does not start it. A module whose .plain file is gone is dropped. What activate started: the " +
|
|
219
|
+
"one named, or every one."
|
|
207
220
|
: "Stop what activate started: the one named, or every one.",
|
|
208
221
|
promptSnippet: jobs !== undefined ? "halt a pulse, or what activate started" : "stop a deployed server, or all of them",
|
|
209
|
-
promptGuidelines: jobs !== undefined
|
|
222
|
+
promptGuidelines: jobs !== undefined
|
|
223
|
+
? [
|
|
224
|
+
"Halt a pulse only when the user asks, or your instructions say to. Name which one, and say which pulses were queued behind it - they will now run.",
|
|
225
|
+
"Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To build some of it later, or cut it differently, use steer; to drop work, change the spec.",
|
|
226
|
+
"A planned row for a module that is no longer in the project is halted the same way, and dropped.",
|
|
227
|
+
]
|
|
228
|
+
: [],
|
|
210
229
|
parameters: (jobs !== undefined ? HALT_PULSE_PARAMS : HALT_ACTIVATED_PARAMS),
|
|
211
230
|
async execute(_id, params) {
|
|
212
231
|
if (params.job_id === undefined && params.activated === undefined) {
|
|
@@ -214,7 +233,7 @@ export function haltTool(options) {
|
|
|
214
233
|
}
|
|
215
234
|
const lines = [];
|
|
216
235
|
if (params.job_id !== undefined && jobs !== undefined)
|
|
217
|
-
lines.push(stopJob(jobs, params.job_id, params.reason));
|
|
236
|
+
lines.push(stopJob(jobs, params.job_id, params.reason, options.workLoop?.()));
|
|
218
237
|
if (params.activated !== undefined) {
|
|
219
238
|
const stopped = await stopDeployed(params.activated === "all" ? {} : { name: params.activated });
|
|
220
239
|
lines.push(stopped.length > 0 ? `Halted ${stopped.join(", ")}.` : `Nothing activate started is running${params.activated === "all" ? "" : ` as ${params.activated}`}.`);
|
package/dist/pi-launch.js
CHANGED
|
@@ -11,6 +11,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
11
11
|
import { main, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import { ProcessTerminal } from "@earendil-works/pi-tui";
|
|
13
13
|
import "./terminal-images.js";
|
|
14
|
+
import { resumeLine } from "./resume-line.js";
|
|
14
15
|
/**
|
|
15
16
|
* pi, started the way its own CLI starts it, for `turri`.
|
|
16
17
|
*
|
|
@@ -31,6 +32,10 @@ const setTitle = ProcessTerminal.prototype.setTitle;
|
|
|
31
32
|
ProcessTerminal.prototype.setTitle = function (title) {
|
|
32
33
|
setTitle.call(this, title.replace(/^π(?= |$)/, "🪼 turri"));
|
|
33
34
|
};
|
|
35
|
+
// What pi prints on the way out to resume the session names pi - its APP_NAME, a constant - which may not be on the
|
|
36
|
+
// PATH at all: turri takes the same flags, so it is turri the line names.
|
|
37
|
+
const write = process.stdout.write.bind(process.stdout);
|
|
38
|
+
process.stdout.write = ((chunk, ...rest) => write(typeof chunk === "string" ? resumeLine(chunk) : chunk, ...rest));
|
|
34
39
|
// pi's own keys stand: a new line is shift+enter or ctrl+j. turri's side panel is on ctrl+h (job-panel.ts PANEL_KEY).
|
|
35
40
|
// What pi's CLI does before main: the process title, pi's environment markers, the HTTP
|
|
36
41
|
// dispatcher. Not exported, so loaded from the file - beside pi's entry point, wherever npm put it.
|
package/dist/pi.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createAgentSession, DefaultResourceLoader, getAgentDir, ModelRegistry,
|
|
|
4
4
|
import { loadRules, renderRulesBlock } from "./rules.js";
|
|
5
5
|
import { inheritModel, stackOf, readProjectConfig, ROLE_THINKING, roleModel, roleTurnLimitMs, splitModelSpec } from "./config.js";
|
|
6
6
|
import { maskToolResults } from "./regenerate/masking.js";
|
|
7
|
+
import { withListArguments } from "./regenerate/list-arguments.js";
|
|
7
8
|
import { checkAgainstScript, ENVIRONMENT_ERROR_TOOL, EnvironmentError, environmentErrorTool, sandboxGapOf } from "./regenerate/environment-error.js";
|
|
8
9
|
import { MODULES_DIR, projectRootOf, sessionsDir } from "./regenerate/paths.js";
|
|
9
10
|
import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, shownName, reportActivity, reportNow, reportAgent, reportTranscript, reportModelEvent, reportUsage, } from "./regenerate/activity.js";
|
|
@@ -146,6 +147,19 @@ export class ProviderError extends Error {
|
|
|
146
147
|
this.name = "ProviderError";
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
/** Why turri itself ended a session's turn under way: the abort that comes back is its own, not the provider failing. */
|
|
151
|
+
const harnessStops = new WeakMap();
|
|
152
|
+
/**
|
|
153
|
+
* End the agent's turn, turri's own doing - it is going round in a circle, its time is up. The turn ends as any turn
|
|
154
|
+
* does: what the agent said stands, and the harness goes on from there. Never a provider error.
|
|
155
|
+
*/
|
|
156
|
+
export function stopTurn(session, reason) {
|
|
157
|
+
if (session === undefined || harnessStops.has(session))
|
|
158
|
+
return;
|
|
159
|
+
harnessStops.set(session, reason);
|
|
160
|
+
reportModelEvent({ kind: "stopped", ...modelEventOf(session), reason });
|
|
161
|
+
void session.abort();
|
|
162
|
+
}
|
|
149
163
|
/**
|
|
150
164
|
* Run one turn and return the assistant's text, streaming deltas to `onDelta`.
|
|
151
165
|
*
|
|
@@ -212,17 +226,32 @@ async function askUnrestricted(session, text, onDelta) {
|
|
|
212
226
|
catch (error) {
|
|
213
227
|
if (!(error instanceof ProviderError) || !TRANSIENT_PROVIDER_ERROR.test(error.message) || attempt >= PROVIDER_RETRIES)
|
|
214
228
|
throw error;
|
|
215
|
-
const wait =
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
const wait = providerRetryDelay(attempt);
|
|
230
|
+
const shown = `${Math.round(wait / 1000)}s (${attempt + 1} of ${PROVIDER_RETRIES})`;
|
|
231
|
+
reportActivity(` the model provider is failing for now - trying again in ${shown}`);
|
|
232
|
+
reportNow(`the model provider is failing - trying again in ${shown}`);
|
|
233
|
+
reportModelEvent({ kind: "provider_retry", ...modelEventOf(session), error: error.message, attempt: attempt + 1, of: PROVIDER_RETRIES, waitMs: wait });
|
|
234
|
+
debugLogOf(session)?.note(`provider failing - trying again in ${shown}: ${error.message.slice(0, 200)}`);
|
|
218
235
|
await waitOrStop(wait);
|
|
236
|
+
reportNow(undefined);
|
|
219
237
|
prompt = "Carry on where you were: the model provider failed part-way through your last turn.";
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
240
|
}
|
|
223
|
-
/**
|
|
224
|
-
|
|
241
|
+
/**
|
|
242
|
+
* How many times, after pi's own retries, a turn whose provider failed for a moment is tried again; the first wait,
|
|
243
|
+
* doubled each time up to the longest - 15s, 30s, 1m, 2m, 4m, 5m: an outage of about 13 minutes is waited out.
|
|
244
|
+
*/
|
|
245
|
+
export const PROVIDER_RETRIES = 6;
|
|
225
246
|
export const PROVIDER_RETRY_DELAY_MS = Number(process.env.TURRI_PROVIDER_RETRY_DELAY ?? 15) * 1000;
|
|
247
|
+
export const PROVIDER_RETRY_MAX_DELAY_MS = 20 * PROVIDER_RETRY_DELAY_MS;
|
|
248
|
+
/** The wait before try `attempt + 1`: doubled each time, up to the longest, with a tenth either way so parallel jobs do not all come back at once. */
|
|
249
|
+
export function providerRetryDelay(attempt, random = Math.random) {
|
|
250
|
+
const base = Math.min(PROVIDER_RETRY_DELAY_MS * 2 ** attempt, PROVIDER_RETRY_MAX_DELAY_MS);
|
|
251
|
+
return Math.round(base * (0.9 + 0.2 * random()));
|
|
252
|
+
}
|
|
253
|
+
/** How long a request to the model may go without anything coming back before the provider is said to be stalling; 0 never. */
|
|
254
|
+
export const PROVIDER_STALL_MS = Number(process.env.TURRI_PROVIDER_STALL ?? 120) * 1000;
|
|
226
255
|
/** A provider error that passes: overloaded, rate limited, unreachable, timed out. */
|
|
227
256
|
const TRANSIENT_PROVIDER_ERROR = /\b(429|500|502|503|504|529)\b|overloaded|high demand|rate.?limit|too many requests|unavailable|fetch failed|network|connection|timed? ?out|ECONNRESET|socket|terminated/i;
|
|
228
257
|
/** Wait, unless the job is stopped first. */
|
|
@@ -251,7 +280,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
251
280
|
// Calls to one tool failing one after another - arguments it refuses, or errors - with nothing going through.
|
|
252
281
|
let failing = 0;
|
|
253
282
|
let failingTool;
|
|
254
|
-
|
|
283
|
+
harnessStops.delete(session);
|
|
255
284
|
reportNow("waiting for the model");
|
|
256
285
|
// Every entry says which agent it is from, and what it runs on - for reading one agent at a time.
|
|
257
286
|
const agent = agentOf(session);
|
|
@@ -263,7 +292,30 @@ async function askOnce(session, text, onDelta) {
|
|
|
263
292
|
if (agent !== undefined)
|
|
264
293
|
reportAgent({ label: agent.label, ...(agent.model !== undefined ? { model: agent.model } : {}), turns: 1 });
|
|
265
294
|
reportModelEvent({ kind: "turn", ...modelEventOf(session) });
|
|
295
|
+
// The provider stalling: a request to the model that nothing has come back on - not a token, not an error - for
|
|
296
|
+
// long. Said once for each silence; the turn goes on waiting, its own time limit ending it if it must.
|
|
297
|
+
let toolsRunning = 0;
|
|
298
|
+
let stall;
|
|
299
|
+
const watchForStall = (afterMs = PROVIDER_STALL_MS) => {
|
|
300
|
+
if (stall !== undefined)
|
|
301
|
+
clearTimeout(stall);
|
|
302
|
+
stall = toolsRunning > 0 || PROVIDER_STALL_MS <= 0 ? undefined : setTimeout(() => {
|
|
303
|
+
reportModelEvent({ kind: "provider_stall", ...modelEventOf(session), waitMs: PROVIDER_STALL_MS });
|
|
304
|
+
debugLogOf(session)?.note(`the provider has sent nothing back for ${seconds(PROVIDER_STALL_MS)}`);
|
|
305
|
+
}, afterMs);
|
|
306
|
+
};
|
|
266
307
|
const unsubscribe = session.subscribe((event) => {
|
|
308
|
+
if (event.type === "tool_execution_start")
|
|
309
|
+
toolsRunning += 1;
|
|
310
|
+
if (event.type === "tool_execution_end")
|
|
311
|
+
toolsRunning = Math.max(0, toolsRunning - 1);
|
|
312
|
+
// pi tries a failed request again itself first: the provider failing is said then, not only once pi gives up.
|
|
313
|
+
if (event.type === "auto_retry_start") {
|
|
314
|
+
reportModelEvent({ kind: "provider_retry", ...modelEventOf(session), error: event.errorMessage, attempt: event.attempt, of: event.maxAttempts, waitMs: event.delayMs });
|
|
315
|
+
watchForStall(event.delayMs + PROVIDER_STALL_MS);
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
watchForStall();
|
|
267
319
|
if (event.type === "message_update") {
|
|
268
320
|
const update = event.assistantMessageEvent;
|
|
269
321
|
if (update.type === "text_delta") {
|
|
@@ -308,14 +360,13 @@ async function askOnce(session, text, onDelta) {
|
|
|
308
360
|
if (event.type === "tool_execution_end") {
|
|
309
361
|
failing = event.isError ? (event.toolName === failingTool ? failing + 1 : 1) : 0;
|
|
310
362
|
failingTool = event.isError ? event.toolName : undefined;
|
|
311
|
-
if (failing >= FAILURES_BEFORE_STOP && !
|
|
363
|
+
if (failing >= FAILURES_BEFORE_STOP && !harnessStops.has(session)) {
|
|
312
364
|
// A call its tool refuses never reaches the tool, so no guard on the tools sees it: an agent can
|
|
313
365
|
// make the same bad call, worded a little differently, thousands of times. Its turn ends here, and
|
|
314
366
|
// the harness goes on from there, as after any turn.
|
|
315
|
-
stoppedFailing = true;
|
|
316
367
|
reportActivity(` stopped the agent's turn: ${failing} ${shownName(event.toolName)} calls failed in a row`);
|
|
317
368
|
debugLogOf(session)?.note(`turn stopped: ${failing} ${event.toolName} calls failed in a row`);
|
|
318
|
-
|
|
369
|
+
stopTurn(session, `${failing} ${shownName(event.toolName)} calls failed in a row`);
|
|
319
370
|
}
|
|
320
371
|
const output = resultText(event.result);
|
|
321
372
|
transcript({ kind: "result", text: clipText(output, MAX_TOOL_RESULT), error: event.isError, full: output });
|
|
@@ -376,7 +427,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
376
427
|
stopped = true;
|
|
377
428
|
reportActivity(` stopped the agent's turn: its ${formatLimit(limitMs)} are up`);
|
|
378
429
|
debug?.note(`turn stopped: its ${formatLimit(limitMs)} are up${how}`);
|
|
379
|
-
|
|
430
|
+
stopTurn(session, `its ${formatLimit(limitMs)} were up`);
|
|
380
431
|
};
|
|
381
432
|
const atNextRequest = timed
|
|
382
433
|
? session.subscribe((event) => {
|
|
@@ -392,6 +443,7 @@ async function askOnce(session, text, onDelta) {
|
|
|
392
443
|
}
|
|
393
444
|
// What the model is sent, and only that: its task is its system prompt, which the log already holds whole.
|
|
394
445
|
debug?.prompt(text);
|
|
446
|
+
watchForStall();
|
|
395
447
|
try {
|
|
396
448
|
// Its images, when its conversation does not hold them: the first turn, and the first after a compaction.
|
|
397
449
|
const images = sessionImages.get(session);
|
|
@@ -412,19 +464,24 @@ async function askOnce(session, text, onDelta) {
|
|
|
412
464
|
clearTimeout(timer);
|
|
413
465
|
if (backstop !== undefined)
|
|
414
466
|
clearTimeout(backstop);
|
|
467
|
+
if (stall !== undefined)
|
|
468
|
+
clearTimeout(stall);
|
|
415
469
|
atNextRequest?.();
|
|
416
470
|
unsubscribe();
|
|
417
471
|
stop?.removeEventListener("abort", onStop);
|
|
418
472
|
reportNow(undefined);
|
|
419
473
|
}
|
|
420
|
-
|
|
421
|
-
|
|
474
|
+
// turri ended the turn itself - its time was up, the agent went round in a circle: the abort that ended it is its own.
|
|
475
|
+
const stoppedFor = harnessStops.get(session);
|
|
476
|
+
harnessStops.delete(session);
|
|
477
|
+
if (stoppedFor !== undefined)
|
|
478
|
+
out = `${out.trim()}\n\n[the turn was stopped: ${stoppedFor}]`.trim();
|
|
422
479
|
if (stop?.aborted) {
|
|
423
480
|
debug?.note(`turn stopped on request after ${seconds(Date.now() - turnStarted)}`);
|
|
424
481
|
throw new JobStoppedError();
|
|
425
482
|
}
|
|
426
|
-
// A turn ended
|
|
427
|
-
if (providerError !== undefined &&
|
|
483
|
+
// A turn turri ended is ended, whatever the provider was doing then: what comes back of the abort is not the provider failing.
|
|
484
|
+
if (providerError !== undefined && stoppedFor === undefined) {
|
|
428
485
|
debug?.note(`turn ended with a provider error after ${seconds(Date.now() - turnStarted)}: ${providerError}`);
|
|
429
486
|
throw new ProviderError(`${session.model?.id ?? "model"}: ${providerError}`);
|
|
430
487
|
}
|
|
@@ -614,7 +671,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
614
671
|
refused += 1;
|
|
615
672
|
if (refused > REFUSED_BEFORE_STOP) {
|
|
616
673
|
reportActivity(` stopped the agent's turn: ${refused} calls to tools this turn does not have`);
|
|
617
|
-
|
|
674
|
+
stopTurn(current, `${refused} calls to tools this turn does not have`);
|
|
618
675
|
throw new Error(`Stopped: ${refused} calls to tools this turn does not have.`);
|
|
619
676
|
}
|
|
620
677
|
throw new Error(`Not run: your work is done and checked - this turn is for ${[...only].join(" and ")} alone, and nothing else is ` +
|
|
@@ -624,7 +681,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
624
681
|
if (budget !== undefined && !budget.finish.includes(tool.name) && calls > budget.calls) {
|
|
625
682
|
if (calls > budget.calls * 2) {
|
|
626
683
|
reportActivity(` stopped the agent's turn: ${calls} tool calls, past its budget of ${budget.calls}`);
|
|
627
|
-
|
|
684
|
+
stopTurn(session(), `${calls} tool calls, past its budget of ${budget.calls}`);
|
|
628
685
|
throw new Error(`Stopped: ${calls} tool calls, past the budget of ${budget.calls}.`);
|
|
629
686
|
}
|
|
630
687
|
throw new Error(`Not run: you have made ${budget.calls} tool calls, which is all you have. Decide now with what you know: call ` +
|
|
@@ -652,7 +709,7 @@ export function guardRepeats(tools, session, budget) {
|
|
|
652
709
|
}
|
|
653
710
|
if (repeats > REPEATS_BEFORE_STOP) {
|
|
654
711
|
reportActivity(` stopped the agent's turn: it made the same ${tool.name} call ${repeats} times with nothing changed`);
|
|
655
|
-
|
|
712
|
+
stopTurn(session(), `the same ${tool.name} call ${repeats} times with nothing changed`);
|
|
656
713
|
throw new Error(`Stopped: the same ${tool.name} call ${repeats} times with nothing changed.`);
|
|
657
714
|
}
|
|
658
715
|
if (repeats > REPEATS_ALLOWED) {
|
|
@@ -695,7 +752,7 @@ export async function createExecutor(opts) {
|
|
|
695
752
|
modelRuntime: await subAgentModelRuntime(),
|
|
696
753
|
tools: hasShell ? [...opts.tools, ENVIRONMENT_ERROR_TOOL] : opts.tools,
|
|
697
754
|
// What an agent is shown never holds a credential the project passed: each value is its name (masking.ts).
|
|
698
|
-
customTools: guardRepeats(maskToolResults(withEnvironmentErrors), () => session, opts.budget),
|
|
755
|
+
customTools: guardRepeats(maskToolResults(withListArguments(withEnvironmentErrors)), () => session, opts.budget),
|
|
699
756
|
sessionManager,
|
|
700
757
|
resourceLoader: await subAgentResources(opts.cwd, opts.rules === true, [opts.system, opts.task].filter((part) => part !== undefined && part !== "").join("\n\n") || undefined),
|
|
701
758
|
});
|
|
@@ -814,7 +871,7 @@ export async function createJudge(opts) {
|
|
|
814
871
|
model,
|
|
815
872
|
modelRuntime,
|
|
816
873
|
tools: [...(opts.extraTools ?? []), "submit_verdict"],
|
|
817
|
-
customTools: [opts.verdictTool],
|
|
874
|
+
customTools: withListArguments([opts.verdictTool]),
|
|
818
875
|
sessionManager: SessionManager.inMemory(opts.cwd),
|
|
819
876
|
// Judges assess specs against the rules, so they have them too.
|
|
820
877
|
resourceLoader: await subAgentResources(opts.cwd, true, opts.task),
|
package/dist/question-dialog.js
CHANGED
|
@@ -25,6 +25,7 @@ export class QuestionDialog {
|
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
this.input = undefined;
|
|
28
|
+
this.selected = Math.min(Math.max(0, options.selected ?? 0), options.options.length - 1);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
get focused() {
|
|
@@ -58,18 +59,23 @@ export class QuestionDialog {
|
|
|
58
59
|
const choices = this.options.options ?? [];
|
|
59
60
|
const body = this.input !== undefined
|
|
60
61
|
? this.input.render(inner)
|
|
61
|
-
:
|
|
62
|
+
: // A long option wraps, its lines under its first, rather than cut off where the person cannot read it.
|
|
63
|
+
choices.flatMap((choice, index) => wrapTextWithAnsi(choice, Math.max(1, inner - 2)).map((line, at) => {
|
|
64
|
+
const shown = `${at === 0 && index === this.selected ? "›" : " "} ${line}`;
|
|
65
|
+
return index === this.selected ? style.accent(shown) : shown;
|
|
66
|
+
}));
|
|
62
67
|
const hint = this.input !== undefined
|
|
63
68
|
? "enter answers · esc dismisses"
|
|
64
69
|
: "↑↓ choose · enter picks · esc dismisses";
|
|
65
70
|
// The brief gets what the question, the options and the hints leave of the screen.
|
|
66
|
-
const fixed = question.length + body.length +
|
|
71
|
+
const fixed = question.length + body.length + 5;
|
|
67
72
|
const room = Math.max(3, this.options.rows() - KEPT_ABOVE - fixed);
|
|
68
73
|
const scrolls = brief.length > room;
|
|
69
74
|
this.window = scrolls ? room - 1 : brief.length;
|
|
70
75
|
this.maxScroll = scrolls ? brief.length - this.window : 0;
|
|
71
76
|
this.scroll = Math.min(this.scroll, this.maxScroll);
|
|
72
|
-
|
|
77
|
+
// Set apart from what is drawn above it - the job panel's hints.
|
|
78
|
+
const lines = [""];
|
|
73
79
|
if (brief.length > 0) {
|
|
74
80
|
lines.push(...brief.slice(this.scroll, this.scroll + this.window).map(pad));
|
|
75
81
|
if (scrolls) {
|
package/dist/questioning.js
CHANGED
|
@@ -43,7 +43,7 @@ export function questioningQuestion(phases) {
|
|
|
43
43
|
return {
|
|
44
44
|
question: `How many questions should I ask you in ${named}?`,
|
|
45
45
|
options: QUESTIONING_LEVELS.map((level) => level.option),
|
|
46
|
-
context: `Light, medium and thorough cap each of ${named} at 3, 5 and 10 questions - broader with fewer, so every level ` +
|
|
46
|
+
context: `Light, medium and thorough cap ${phases.length === 1 ? named : `each of ${named}`} at 3, 5 and 10 questions - broader with fewer, so every level ` +
|
|
47
47
|
"covers the same ground, only in less or more depth. What the questions leave open, turri decides itself and " +
|
|
48
48
|
"says what it chose. With best judgement, turri asks as much as it judges each phase needs. Each phase still " +
|
|
49
49
|
"ends with your confirmation of its summary.",
|
|
@@ -90,6 +90,27 @@ export function onModelEvent(listener) {
|
|
|
90
90
|
modelListeners.add(listener);
|
|
91
91
|
return () => modelListeners.delete(listener);
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The model provider failing or stalling, in a line for the person: the chat's notification, a headless run's console.
|
|
95
|
+
* A turn turri stopped itself is the work going its normal course - kept in the activity, the pulse's log and the run
|
|
96
|
+
* report, not said.
|
|
97
|
+
*/
|
|
98
|
+
export function describeTurnIncident(event) {
|
|
99
|
+
const who = event.role ?? event.label ?? "an agent";
|
|
100
|
+
const model = event.model !== undefined ? ` (${event.model})` : "";
|
|
101
|
+
if (event.kind === "provider_retry") {
|
|
102
|
+
const wait = Math.round((event.waitMs ?? 0) / 1000);
|
|
103
|
+
return `The model provider failed${model}: ${(event.error ?? "").slice(0, 160)} - trying ${who}'s request again in ${wait}s (${event.attempt} of ${event.of}).`;
|
|
104
|
+
}
|
|
105
|
+
if (event.kind === "provider_stall") {
|
|
106
|
+
return `The model provider has sent nothing back to ${who}${model} for ${formatSilence(event.waitMs ?? 0)} - still waiting.`;
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
function formatSilence(ms) {
|
|
111
|
+
const seconds = Math.round(ms / 1000);
|
|
112
|
+
return seconds >= 60 && seconds % 60 === 0 ? `${seconds / 60}m` : seconds >= 60 ? `${Math.floor(seconds / 60)}m ${seconds % 60}s` : `${seconds}s`;
|
|
113
|
+
}
|
|
93
114
|
export function reportModelEvent(event) {
|
|
94
115
|
if (modelListeners.size === 0)
|
|
95
116
|
return;
|
|
@@ -183,6 +204,8 @@ export function describeToolCall(name, args) {
|
|
|
183
204
|
return `± my_diff`;
|
|
184
205
|
case "update_notes":
|
|
185
206
|
return `✐ update_notes`;
|
|
207
|
+
case "report_spec_gap":
|
|
208
|
+
return `? spec gap: ${text("question") ?? ""}`.trimEnd();
|
|
186
209
|
case "copy_resource":
|
|
187
210
|
return `⎘ copy_resource ${path ?? text("to") ?? ""}`.trimEnd();
|
|
188
211
|
case "can_it_fail":
|
|
@@ -7,7 +7,7 @@ import { abandonWork, startWork } from "./lineage.js";
|
|
|
7
7
|
import { ensureRegressionPasses } from "./regression.js";
|
|
8
8
|
import { modulesRoot, projectDirOf } from "./paths.js";
|
|
9
9
|
import { applySpecDiff, snapshotSpec, specGapsText } from "./regenerate.js";
|
|
10
|
-
import {
|
|
10
|
+
import { gapMark, gapsSince } from "./notes.js";
|
|
11
11
|
import { sectionsOf } from "./state.js";
|
|
12
12
|
import { describeStop } from "./stop-report.js";
|
|
13
13
|
import { missingTestLabels } from "./test-kinds.js";
|
|
@@ -41,8 +41,8 @@ export async function renderSpecDiffConformance(options) {
|
|
|
41
41
|
// state, not to what an interrupted run left half-written. The tests and the whole suite are
|
|
42
42
|
// one unit, landed whole or undone whole.
|
|
43
43
|
const unit = startWork([buildDir, conformanceDir], moduleName);
|
|
44
|
-
// The
|
|
45
|
-
const
|
|
44
|
+
// The spec gaps its agents report from here on are told with the result.
|
|
45
|
+
const gapsFrom = gapMark();
|
|
46
46
|
const conformance = await renderConformanceTests({
|
|
47
47
|
plainFile: tip.plainFile,
|
|
48
48
|
frid: lastFrid,
|
|
@@ -58,8 +58,8 @@ export async function renderSpecDiffConformance(options) {
|
|
|
58
58
|
});
|
|
59
59
|
// What the codebase now has conformance tests for, as their labels say.
|
|
60
60
|
const tested = () => frids.filter((frid) => missingTestLabels(conformanceDir, frid, []).length === 0);
|
|
61
|
-
//
|
|
62
|
-
const base = { moduleName, buildDir, conformanceDir, diff: applied, conformance, specGaps:
|
|
61
|
+
// A gap is the person's to decide, whether the tests passed or not.
|
|
62
|
+
const base = { moduleName, buildDir, conformanceDir, diff: applied, conformance, specGaps: gapsSince(gapsFrom, [buildDir, conformanceDir]) };
|
|
63
63
|
if (!conformance.passed) {
|
|
64
64
|
abandonWork(unit, moduleName, notLandedWhy("for the spec change", conformance.unlabelled));
|
|
65
65
|
return { ...base, tested: tested(), passed: false, stoppedAt: "conformance" };
|
|
@@ -7,7 +7,7 @@ import { confinedTools } from "./confine.js";
|
|
|
7
7
|
import { ensureInModulesScratch, modulesScratchDir } from "./paths.js";
|
|
8
8
|
import { workspaceBlock } from "./workspace.js";
|
|
9
9
|
import { reportActivity } from "./activity.js";
|
|
10
|
-
import { runTiming } from "./test-scripts.js";
|
|
10
|
+
import { runTiming, withTestingScripts } from "./test-scripts.js";
|
|
11
11
|
import { createWebTools, WEB_TOOLS } from "./web.js";
|
|
12
12
|
import { diffFiles, digestFiles } from "./codebase.js";
|
|
13
13
|
import { ERROR_CAUSE_RULES, fixMethod, INTEGRITY_RULES, specPrimer } from "./prompt.js";
|
|
@@ -378,9 +378,17 @@ export function explorePrompt(buildDir, spec, scope, testingScripts, question, p
|
|
|
378
378
|
...(testingScripts !== undefined && testingScripts.length > 0
|
|
379
379
|
? [
|
|
380
380
|
"",
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
...(testingScripts.some((script) => script.prepare === true)
|
|
382
|
+
? [
|
|
383
|
+
"These are the project's prepare script, which the harness runs on the build first, and its conformance testing",
|
|
384
|
+
"script, which runs only once the prepare script passes and decides whether the tests pass - read both for what",
|
|
385
|
+
"they build or install before the tests run, and so what the tests can depend on:",
|
|
386
|
+
]
|
|
387
|
+
: [
|
|
388
|
+
"This is the project's conformance testing script, which the harness runs to decide whether the",
|
|
389
|
+
"tests pass - read it for what it builds or installs before the tests run, and so what the tests can depend on:",
|
|
390
|
+
]),
|
|
391
|
+
...testingScripts.flatMap((script) => ["", `<script${script.prepare === true ? ' kind="prepare environment"' : ""} path="${script.path}" run-as="${script.runs}">`, script.content.trimEnd(), "</script>"]),
|
|
384
392
|
]
|
|
385
393
|
: []),
|
|
386
394
|
...(previous !== undefined && question === undefined
|
|
@@ -704,7 +712,7 @@ export function unfoundedEvidence(evidence, opened) {
|
|
|
704
712
|
"opened, the testing script, or the failing run - each with where. What <how to invoke it> says is not evidence: it " +
|
|
705
713
|
"may be wrong, so check it against the testing script and the files.");
|
|
706
714
|
}
|
|
707
|
-
const inPrompt = (source) => /^(the )?(conformance )?testing script$|^(the )?failing run$/i.test(source.trim());
|
|
715
|
+
const inPrompt = (source) => /^(the )?(conformance )?testing script$|^(the )?prepare script$|^(the )?failing run$/i.test(source.trim());
|
|
708
716
|
const unread = given.filter((item) => !inPrompt(item.source) && !opened(item.source.trim()));
|
|
709
717
|
if (unread.length > 0) {
|
|
710
718
|
return (`Your evidence cites ${unread.map((item) => item.source.trim()).join(", ")}, which you did not open. Open each file you cite ` +
|
|
@@ -735,7 +743,7 @@ export async function judgeFailure(options) {
|
|
|
735
743
|
description: "For code: the conformance testing script's own words for what it needs the build to have - the file, entry point or module the run failed on - copied exactly from the script",
|
|
736
744
|
})),
|
|
737
745
|
evidence: Type.Optional(Type.Array(Type.Object({
|
|
738
|
-
source: Type.String({ description: "Where: the path of a file you opened, `testing script`, or `failing run`" }),
|
|
746
|
+
source: Type.String({ description: "Where: the path of a file you opened, `testing script`, `prepare script` where there is one, or `failing run`" }),
|
|
739
747
|
shows: Type.String({ description: "What it shows, e.g. `the script runs node dist/cli.js` or `tsconfig.json emits src/cli.ts as dist/src/cli.js`" }),
|
|
740
748
|
}), { description: "What you found yourself, each with where - never what <how to invoke it> claims unchecked" })),
|
|
741
749
|
functionalities: Type.Optional(Type.Array(Type.Object({
|
|
@@ -900,6 +908,12 @@ export function judgePrompt(options) {
|
|
|
900
908
|
"what is wrong. What it does with the tests, the tests have to fit; what it needs of the code - a file it runs or",
|
|
901
909
|
"checks for, a command it builds with - the code has to provide. A verdict that the script is wrong is neither",
|
|
902
910
|
"code nor tests: say which of the two has to change to get past it.",
|
|
911
|
+
...(scripts.some((script) => script.prepare === true)
|
|
912
|
+
? [
|
|
913
|
+
"The prepare script below it runs on the build before every run, and the conformance testing script only once it",
|
|
914
|
+
"passes: it binds the same way - neither agent can change it, and what it needs of the code the code provides.",
|
|
915
|
+
]
|
|
916
|
+
: []),
|
|
903
917
|
"",
|
|
904
918
|
]
|
|
905
919
|
: []),
|
|
@@ -929,7 +943,10 @@ export function judgePrompt(options) {
|
|
|
929
943
|
"",
|
|
930
944
|
`<how to invoke it>\n${options.invocation.trim()}\n</how to invoke it>`,
|
|
931
945
|
"",
|
|
932
|
-
...scripts.flatMap((script) =>
|
|
946
|
+
...scripts.flatMap((script) => {
|
|
947
|
+
const tag = script.prepare === true ? "prepare script" : "conformance testing script";
|
|
948
|
+
return [`<${tag} path="${script.path}" run-as="${script.runs}">`, script.content.trimEnd(), `</${tag}>`, ""];
|
|
949
|
+
}),
|
|
933
950
|
...(options.run.timedOut === true ? [...timedOutBlock(options.run), ""] : []),
|
|
934
951
|
`<failing run exit="${options.run.exitCode}" command="${options.run.command}">`,
|
|
935
952
|
runTiming(options.run),
|
|
@@ -1004,7 +1021,10 @@ export async function createCodeFixer(options) {
|
|
|
1004
1021
|
model: options.model,
|
|
1005
1022
|
label: `${options.label} coding agent`, role: "coding",
|
|
1006
1023
|
system: `${fence.note}\n\n${workspaceBlock({ dir: options.buildDir, hasMyDiff: options.toolNames.includes("my_diff") })}`,
|
|
1007
|
-
|
|
1024
|
+
// What the conformance testing script needs of the build, the code provides: the fixer reads it, not only a judge's quote of it.
|
|
1025
|
+
task: options.testingScripts !== undefined
|
|
1026
|
+
? withTestingScripts(codeFixerTask(options), options.testingScripts.scripts, ["conformance", "unit"], options.testingScripts.root)
|
|
1027
|
+
: codeFixerTask(options),
|
|
1008
1028
|
compaction: { instructions: CODER_COMPACTION },
|
|
1009
1029
|
...(options.checkEnvironment !== undefined ? { checkEnvironment: options.checkEnvironment } : {}),
|
|
1010
1030
|
});
|