@turri-dev/core 0.1.1-next.35d4c49 → 0.1.1-next.ad4aa8f
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/CHANGELOG.md +56 -0
- package/README.md +17 -11
- package/dist/api/models.d.ts +9 -0
- package/dist/api/models.js +15 -0
- package/dist/api/plain.d.ts +6 -6
- package/dist/api/plain.js +4 -7
- package/dist/api/project.d.ts +35 -0
- package/dist/api/project.js +47 -0
- package/dist/api/session.d.ts +48 -0
- package/dist/api/session.js +17 -0
- package/dist/api/system.d.ts +18 -0
- package/dist/api/system.js +23 -0
- package/dist/btw.d.ts +1 -1
- package/dist/capture/capture.js +11 -8
- package/dist/capture/chat.d.ts +0 -11
- package/dist/capture/chat.js +0 -29
- package/dist/capture/config.d.ts +4 -5
- package/dist/capture/config.js +34 -20
- package/dist/capture/models.d.ts +2 -1
- package/dist/capture/models.js +1 -0
- package/dist/chat-entries.d.ts +81 -39
- package/dist/chat-entries.js +125 -11
- package/dist/chat-model.d.ts +37 -0
- package/dist/chat-model.js +61 -0
- package/dist/chats.d.ts +54 -42
- package/dist/chats.js +86 -80
- package/dist/client.d.ts +30 -0
- package/dist/client.js +12 -0
- package/dist/config-edit.d.ts +54 -1
- package/dist/config-edit.js +103 -33
- package/dist/config.d.ts +12 -9
- package/dist/config.js +38 -9
- package/dist/doctor-checks.d.ts +42 -0
- package/dist/doctor-checks.js +39 -0
- package/dist/environment.d.ts +2 -23
- package/dist/environment.js +5 -68
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +24 -0
- package/dist/extension.d.ts +23 -16
- package/dist/extension.js +170 -234
- package/dist/identity.d.ts +1 -1
- package/dist/identity.js +13 -9
- package/dist/init-config.d.ts +11 -9
- package/dist/init-config.js +15 -7
- package/dist/launch-session.d.ts +2 -0
- package/dist/launch-session.js +17 -1
- package/dist/loop-tools.js +11 -10
- package/dist/module-check.d.ts +13 -0
- package/dist/module-check.js +117 -0
- package/dist/notice.d.ts +5 -0
- package/dist/parse-tool.js +3 -2
- package/dist/plain/check.d.ts +27 -13
- package/dist/plain/check.js +51 -116
- package/dist/plain/files.d.ts +2 -0
- package/dist/plain/files.js +13 -0
- package/dist/plain/graph.js +2 -2
- package/dist/plain/highlight.d.ts +4 -20
- package/dist/plain/highlight.js +7 -5
- package/dist/project.d.ts +19 -0
- package/dist/project.js +34 -0
- package/dist/quiet.d.ts +0 -2
- package/dist/quiet.js +0 -14
- package/dist/regenerate/command-check.d.ts +0 -8
- package/dist/regenerate/command-check.js +133 -53
- package/dist/regenerate/conversation-writes.d.ts +5 -1
- package/dist/regenerate/conversation-writes.js +7 -3
- package/dist/regenerate/jobs.d.ts +25 -2
- package/dist/regenerate/jobs.js +3 -0
- package/dist/regenerate/launch.d.ts +1 -0
- package/dist/regenerate/launch.js +9 -0
- package/dist/regenerate/ledger-view.d.ts +14 -14
- package/dist/regenerate/ledger.d.ts +1 -0
- package/dist/regenerate/ledger.js +4 -2
- package/dist/regenerate/loop.d.ts +2 -1
- package/dist/regenerate/loop.js +9 -1
- package/dist/regenerate/os-sandbox.d.ts +4 -2
- package/dist/regenerate/os-sandbox.js +0 -1
- package/dist/regenerate/regenerate.js +2 -1
- package/dist/regenerate/requires-chain.d.ts +44 -0
- package/dist/regenerate/requires-chain.js +174 -0
- package/dist/regenerate/requires.d.ts +2 -40
- package/dist/regenerate/requires.js +14 -171
- package/dist/regenerate/resources.d.ts +0 -2
- package/dist/regenerate/resources.js +2 -14
- package/dist/regenerate/shell.js +20 -9
- package/dist/regenerate/spec-map.d.ts +2 -0
- package/dist/regenerate/spec-map.js +4 -0
- package/dist/regenerate/standing.d.ts +5 -2
- package/dist/run-report.js +2 -2
- package/dist/self-invocation.d.ts +1 -1
- package/dist/self-invocation.js +2 -3
- package/dist/sentinel-chat.js +7 -11
- package/dist/sentinel.d.ts +1 -1
- package/dist/sentinel.js +12 -5
- package/dist/session-events.d.ts +14 -0
- package/dist/session.d.ts +594 -0
- package/dist/session.js +672 -0
- package/dist/settings.d.ts +28 -2
- package/dist/settings.js +92 -56
- package/dist/setup.d.ts +6 -30
- package/dist/setup.js +28 -105
- package/dist/stack.d.ts +25 -12
- package/dist/stack.js +77 -12
- package/dist/surface.d.ts +2 -2
- package/dist/surface.js +4 -5
- package/dist/work.d.ts +125 -0
- package/dist/work.js +250 -0
- package/docs/README.md +2 -3
- package/docs/capture.md +4 -4
- package/docs/chats.md +5 -3
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +4 -4
- package/docs/core.md +105 -128
- package/docs/development.md +9 -9
- package/docs/headless.md +1 -1
- package/docs/installation.md +4 -2
- package/docs/launch.md +2 -2
- package/docs/parser.md +1 -1
- package/docs/regenerating.md +1 -1
- package/docs/sandbox.md +4 -4
- package/docs/sentinel.md +4 -4
- package/docs/skills-and-gates.md +1 -1
- package/docs/using.md +2 -2
- package/genome/rules/integration-embedded-testing.md +3 -3
- package/genome/rules/integration-embedded.md +3 -3
- package/genome/skills/implement-conformance-testing-script/SKILL.md +6 -4
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +13 -11
- package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +8 -7
- package/genome/skills/implement-unit-testing-script/SKILL.md +7 -5
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +9 -13
- package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +1 -1
- package/package.json +19 -32
- package/dist/api/commands.d.ts +0 -45
- package/dist/api/commands.js +0 -54
- package/dist/api/config.d.ts +0 -8
- package/dist/api/config.js +0 -8
- package/dist/api/ledger.d.ts +0 -3
- package/dist/api/ledger.js +0 -3
- package/dist/api/startup.d.ts +0 -8
- package/dist/api/startup.js +0 -8
- package/dist/api/terminal.d.ts +0 -18
- package/dist/api/terminal.js +0 -16
- package/dist/chat-models.d.ts +0 -11
- package/dist/chat-models.js +0 -11
- package/dist/chat-ui.d.ts +0 -33
- package/dist/chat-ui.js +0 -192
- package/dist/headless.d.ts +0 -99
- package/dist/headless.js +0 -226
- package/dist/host-session.d.ts +0 -136
- package/dist/host-session.js +0 -139
- package/dist/host.d.ts +0 -8
- package/dist/host.js +0 -17
- package/dist/index.d.ts +0 -16
- package/dist/index.js +0 -7
- package/dist/notifications.d.ts +0 -21
- package/dist/notifications.js +0 -44
- package/dist/reopen.d.ts +0 -29
- package/dist/reopen.js +0 -47
- package/dist/turri-versions.d.ts +0 -71
- package/dist/turri-versions.js +0 -276
- package/dist/view.d.ts +0 -78
- package/dist/view.js +0 -1
- package/docs/hosting.md +0 -284
package/dist/session.js
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { createAgentSession, DefaultResourceLoader, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { runAsk } from "./ask.js";
|
|
5
|
+
import { inChat } from "./chat-scope.js";
|
|
6
|
+
import { isChatEntry } from "./chat-entries.js";
|
|
7
|
+
import { lastRun } from "./chat-records.js";
|
|
8
|
+
import { interruptChat } from "./chats.js";
|
|
9
|
+
import { modelSpec, projectModels, readProjectConfig, setConfigOverrides, splitModelSpec } from "./config.js";
|
|
10
|
+
import { readSetting, settingOf } from "./config-edit.js";
|
|
11
|
+
import { createTurriCore, parallelJobs, plannedLoop, sessionLaunchesOf, sessionLoop, turnOnConformance } from "./extension.js";
|
|
12
|
+
import { PACKAGE_ROOT } from "./environment.js";
|
|
13
|
+
import { isTurriError, TurriError } from "./errors.js";
|
|
14
|
+
import { runSkill } from "./genome.js";
|
|
15
|
+
import { LOADING_PROVIDERS } from "./installed-providers.js";
|
|
16
|
+
import { haltLaunched, stopJob } from "./loop-tools.js";
|
|
17
|
+
import { lookAhead, nextPulses } from "./preview.js";
|
|
18
|
+
import { followLaunchedLogs, runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
19
|
+
import { onLedgerEvent } from "./regenerate/ledger.js";
|
|
20
|
+
import { earlierPulses, ledgerProjects } from "./regenerate/ledger-view.js";
|
|
21
|
+
import { skillRunDir } from "./regenerate/paths.js";
|
|
22
|
+
import { createSpecMapSource, defaultMapFiles } from "./regenerate/spec-map.js";
|
|
23
|
+
import { projectStanding } from "./regenerate/standing.js";
|
|
24
|
+
import { prepareCheck } from "./sentinel-check.js";
|
|
25
|
+
import { changeSetting, givenValue, reachable, ruleNames, settingCandidates } from "./settings.js";
|
|
26
|
+
import { discoverSkills } from "./skills.js";
|
|
27
|
+
import { loadSkill } from "./skill.js";
|
|
28
|
+
import { runWork } from "./work.js";
|
|
29
|
+
/** How often a shown spec map's files are looked at for a change. */
|
|
30
|
+
const MAP_EVERY_MS = 1000;
|
|
31
|
+
/** The session open in this process, if one is. */
|
|
32
|
+
let current;
|
|
33
|
+
/** Open turri's session on the project in the process's working folder. One a process: a second throws `session-open`. */
|
|
34
|
+
export async function createTurri(options = {}) {
|
|
35
|
+
if (current !== undefined)
|
|
36
|
+
throw new TurriError("session-open", "A turri session is open in this process already: dispose it first.");
|
|
37
|
+
const { frontend, client, overrides, agentDir = getAgentDir(), sessionDir, captured } = options;
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
setConfigOverrides(cwd, sessionConfigOverrides(overrides));
|
|
40
|
+
// The events, to every listener in the order they came, each listener's throw kept from turri.
|
|
41
|
+
const listeners = new Set();
|
|
42
|
+
if (options.onEvent !== undefined)
|
|
43
|
+
listeners.add((event) => options.onEvent(event));
|
|
44
|
+
const emit = (event) => {
|
|
45
|
+
for (const listener of [...listeners]) {
|
|
46
|
+
try {
|
|
47
|
+
listener(event);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
listenerThrew(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const fromCore = (event) => {
|
|
55
|
+
switch (event.type) {
|
|
56
|
+
case "agentCost":
|
|
57
|
+
return emit({ type: "spending", spending: core.spending() });
|
|
58
|
+
case "captureEnded": {
|
|
59
|
+
const { type: _type, ...rest } = event;
|
|
60
|
+
return emit({ type: "captureEnded", ...rest });
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
return emit(event);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
let disposed = false;
|
|
67
|
+
const closed = new AbortController();
|
|
68
|
+
const map = createSpecMapSource({ files: () => defaultMapFiles(cwd), plan: () => plannedLoop(core.jobs)?.mapPlan() ?? { files: [], codebases: [] } });
|
|
69
|
+
// The spec map, watched while the front end shows it: sent as it changes - its files looked at each second, and the
|
|
70
|
+
// marks laid again as the work moves.
|
|
71
|
+
let mapShown = "";
|
|
72
|
+
let mapSoon;
|
|
73
|
+
const sendMap = () => {
|
|
74
|
+
mapSoon = undefined;
|
|
75
|
+
if (disposed)
|
|
76
|
+
return;
|
|
77
|
+
const pages = map.read();
|
|
78
|
+
const print = JSON.stringify(pages);
|
|
79
|
+
if (print === mapShown)
|
|
80
|
+
return;
|
|
81
|
+
mapShown = print;
|
|
82
|
+
emit({ type: "map", pages: snapshot(pages) });
|
|
83
|
+
};
|
|
84
|
+
const mapTimer = frontend?.shows?.map === true ? setInterval(sendMap, MAP_EVERY_MS) : undefined;
|
|
85
|
+
mapTimer?.unref();
|
|
86
|
+
// Where chats live: none without a front end, or with one that has none; else turri's own sessions, or the front end's.
|
|
87
|
+
const given = frontend === undefined ? undefined : (frontend.sessions ?? { kind: "managed" });
|
|
88
|
+
const sessions = given?.kind === "none" ? undefined : given;
|
|
89
|
+
const ask = frontend?.ask;
|
|
90
|
+
const dialogsFor = ask !== undefined ? (chat) => frontendDialogs(ask, chat) : undefined;
|
|
91
|
+
const host = {
|
|
92
|
+
onEvent: fromCore,
|
|
93
|
+
onJobChange: (job) => {
|
|
94
|
+
emit({ type: "job", job: snapshot(job), final: job.replacedBy === undefined && (job.status === "succeeded" || job.status === "failed" || job.status === "stopped") });
|
|
95
|
+
mapMoved();
|
|
96
|
+
},
|
|
97
|
+
onPlanChange: () => {
|
|
98
|
+
emit({ type: "plan" });
|
|
99
|
+
mapMoved();
|
|
100
|
+
},
|
|
101
|
+
onLaunch: (launch) => emit({ type: "launch", launch: snapshot(launch) }),
|
|
102
|
+
onLaunchOutput: (launch, text) => emit({ type: "launchOutput", launch: launch.id, codebase: launch.codebase, text }),
|
|
103
|
+
onNotice: (notice) => emit({ type: "notice", notice: snapshot(notice) }),
|
|
104
|
+
onNoticeOver: (notice) => emit({ type: "noticeOver", notice: snapshot(notice) }),
|
|
105
|
+
onConcluded: ({ chat, ...conclusion }) => emit({ type: "concluded", chat, conclusion }),
|
|
106
|
+
onChatSession: (chat) => emit({ type: "chatSession", chat }),
|
|
107
|
+
...(frontend?.surface !== undefined ? { surface: frontend.surface } : {}),
|
|
108
|
+
...(frontend?.systemPrompt !== undefined ? { systemPrompt: (prompt, chat) => frontend.systemPrompt(prompt, { chat }) } : {}),
|
|
109
|
+
...(frontend?.sentinel !== undefined ? { sentinel: frontend.sentinel } : {}),
|
|
110
|
+
pulseEndsShown: frontend?.shows?.pulseEnds === true,
|
|
111
|
+
noticesShown: frontend?.shows?.notices === true,
|
|
112
|
+
...(frontend?.reveal !== undefined ? { reveal: frontend.reveal } : {}),
|
|
113
|
+
...(frontend?.openPiSettings !== undefined ? { openPiSettings: frontend.openPiSettings } : {}),
|
|
114
|
+
};
|
|
115
|
+
const core = createTurriCore(host, {
|
|
116
|
+
// How the run is recorded in the ledger: in the front end's own word - the core cannot tell a terminal from an app.
|
|
117
|
+
mode: client?.mode ?? (frontend !== undefined ? "frontend" : "unattended"),
|
|
118
|
+
persist: options.persist ?? sessions !== undefined,
|
|
119
|
+
...(dialogsFor !== undefined ? { dialogs: dialogsFor } : {}),
|
|
120
|
+
...(client !== undefined ? { client } : {}),
|
|
121
|
+
...(frontend?.openProject !== undefined ? { openProject: frontend.openProject } : {}),
|
|
122
|
+
...(captured !== undefined ? { captured } : {}),
|
|
123
|
+
});
|
|
124
|
+
const stopLedger = onLedgerEvent((entry, project) => {
|
|
125
|
+
if (resolve(project) !== cwd)
|
|
126
|
+
return;
|
|
127
|
+
if (entry.kind === "loop.renamed")
|
|
128
|
+
emit({ type: "renamed", what: entry.what, from: entry.from, to: entry.to, spec: entry.spec });
|
|
129
|
+
else if (entry.kind === "healer.failed")
|
|
130
|
+
emit({ type: "failure", what: "healer", text: `${entry.healer}: ${entry.error}` });
|
|
131
|
+
else if (entry.kind === "provider.error")
|
|
132
|
+
emit({ type: "failure", what: "provider", text: entry.error });
|
|
133
|
+
else if (entry.kind === "history.failed")
|
|
134
|
+
emit({ type: "failure", what: "history", text: `${entry.subject}: ${entry.said}` });
|
|
135
|
+
else if (entry.kind === "planner.failed")
|
|
136
|
+
emit({ type: "failure", what: "planner", text: `${entry.step}: ${entry.error}` });
|
|
137
|
+
});
|
|
138
|
+
core.onChats(() => emit({ type: "chats", chats: core.chats() }));
|
|
139
|
+
// turri, and the front end's own extensions after it, for every chat - the same factory pi builds into its own sessions.
|
|
140
|
+
const extensions = frontend?.extensions ?? [];
|
|
141
|
+
const extension = async (pi) => {
|
|
142
|
+
// Loaded only for a person's providers (installed-providers.ts): nothing of turri starts.
|
|
143
|
+
if (process.env[LOADING_PROVIDERS] === "1")
|
|
144
|
+
return;
|
|
145
|
+
await core.extension(pi);
|
|
146
|
+
for (const own of extensions)
|
|
147
|
+
await own(pi);
|
|
148
|
+
};
|
|
149
|
+
if (sessions?.kind === "managed") {
|
|
150
|
+
core.setDriver({
|
|
151
|
+
async create(chat, sessionFile) {
|
|
152
|
+
const resourceLoader = new DefaultResourceLoader({ cwd, agentDir, extensionFactories: [core.extension, ...extensions] });
|
|
153
|
+
await resourceLoader.reload();
|
|
154
|
+
const sessionManager = sessionFile !== undefined ? SessionManager.open(sessionFile, sessionDir) : SessionManager.create(cwd, sessionDir);
|
|
155
|
+
const { session } = await createAgentSession({ cwd, agentDir, resourceLoader, sessionManager });
|
|
156
|
+
chat.session = session;
|
|
157
|
+
follow(chat.id, session);
|
|
158
|
+
try {
|
|
159
|
+
await session.bindExtensions({ uiContext: sessions.ui?.(chat.id), mode: "tui" });
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
session.dispose();
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
async dispose(chat) {
|
|
167
|
+
const session = chat.session;
|
|
168
|
+
if (session === undefined)
|
|
169
|
+
return;
|
|
170
|
+
try {
|
|
171
|
+
await session.abort();
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
session.dispose();
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (sessions?.kind === "external") {
|
|
180
|
+
core.setDriver({
|
|
181
|
+
async create(chat, sessionFile) {
|
|
182
|
+
const session = await sessions.create({ chat: chat.id, ...(sessionFile !== undefined ? { sessionFile } : {}), persisted: options.persist ?? true });
|
|
183
|
+
if (chat.instance === undefined)
|
|
184
|
+
throw new TurriError("extension-not-built", "The front end's session was made without turri's extension: build Turri.extension into it before create resolves.");
|
|
185
|
+
chat.session = session;
|
|
186
|
+
follow(chat.id, session);
|
|
187
|
+
},
|
|
188
|
+
...(sessions.show !== undefined ? { show: async (chat) => { await sessions.show(chat.id); core.showing(chat); } } : {}),
|
|
189
|
+
async dispose(chat) {
|
|
190
|
+
if (chat.session !== undefined)
|
|
191
|
+
await sessions.release?.(chat.id, chat.session);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** The work moved: the map, while it is shown, marked again and sent if that changed it - once for a burst of changes. */
|
|
196
|
+
function mapMoved() {
|
|
197
|
+
if (frontend?.shows?.map !== true || disposed || mapSoon !== undefined)
|
|
198
|
+
return;
|
|
199
|
+
map.remark();
|
|
200
|
+
mapSoon = setTimeout(sendMap, 50);
|
|
201
|
+
mapSoon.unref();
|
|
202
|
+
}
|
|
203
|
+
/** A chat's entries and messages, as each is appended or delivered. */
|
|
204
|
+
function follow(chat, session) {
|
|
205
|
+
session.subscribe((event) => {
|
|
206
|
+
// pi announces a custom entry as entry_appended but a delivered custom message as message_end.
|
|
207
|
+
const entry = event.type === "entry_appended" ? event.entry : event.type === "message_end" && event.message.role === "custom"
|
|
208
|
+
? { type: "custom_message", customType: event.message.customType, content: event.message.content, details: event.message.details, display: event.message.display } : undefined;
|
|
209
|
+
if (entry !== undefined && isChatEntry(entry))
|
|
210
|
+
emit({ type: "entry", chat, entry: snapshot(entry) });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const stateOf = (id) => {
|
|
214
|
+
const session = core.session(id);
|
|
215
|
+
return session !== undefined ? core.chatOfSession(session) : undefined;
|
|
216
|
+
};
|
|
217
|
+
const handle = (id) => ({
|
|
218
|
+
id,
|
|
219
|
+
info() {
|
|
220
|
+
const info = core.chats().find((chat) => chat.id === id);
|
|
221
|
+
if (info === undefined)
|
|
222
|
+
throw new TurriError("chat-closed", `The chat ${id} is closed.`);
|
|
223
|
+
return info;
|
|
224
|
+
},
|
|
225
|
+
get session() {
|
|
226
|
+
const session = core.session(id);
|
|
227
|
+
if (session === undefined)
|
|
228
|
+
throw new TurriError("chat-closed", `The chat ${id} is closed.`);
|
|
229
|
+
return session;
|
|
230
|
+
},
|
|
231
|
+
entries: () => core.session(id)?.sessionManager.getBranch().filter(isChatEntry) ?? [],
|
|
232
|
+
async stop() {
|
|
233
|
+
const session = core.session(id);
|
|
234
|
+
if (session === undefined)
|
|
235
|
+
throw new TurriError("chat-closed", `The chat ${id} is closed.`);
|
|
236
|
+
return interruptChat(session, { lastStop: 0, idle: () => "idle" }) === "stopped" ? "stopped" : "idle";
|
|
237
|
+
},
|
|
238
|
+
async decline() {
|
|
239
|
+
const said = core.decline(id);
|
|
240
|
+
if (said === "missing")
|
|
241
|
+
throw new TurriError("chat-closed", `The chat ${id} is closed.`);
|
|
242
|
+
return said;
|
|
243
|
+
},
|
|
244
|
+
outOfReach() {
|
|
245
|
+
if (core.session(id) === undefined)
|
|
246
|
+
throw new TurriError("chat-closed", `The chat ${id} is closed.`);
|
|
247
|
+
const outOfReach = core.outOfReach(id);
|
|
248
|
+
return outOfReach !== undefined ? snapshot(outOfReach) : undefined;
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
const chatOrThrow = (id) => {
|
|
252
|
+
const state = stateOf(id);
|
|
253
|
+
if (state === undefined)
|
|
254
|
+
throw new TurriError("not-found", `There is no chat ${id}.`);
|
|
255
|
+
return state;
|
|
256
|
+
};
|
|
257
|
+
const job = (id) => core.jobs.get(id);
|
|
258
|
+
const work = (kind) => async (request) => {
|
|
259
|
+
const { chat, ...asked } = request;
|
|
260
|
+
const plainFile = resolve(cwd, asked.plainFile ?? readProjectConfig(cwd).module ?? "");
|
|
261
|
+
if (asked.plainFile === undefined && readProjectConfig(cwd).module === undefined)
|
|
262
|
+
throw new TurriError("refused", "Name the module's .plain file: config.turri.yaml names no module.");
|
|
263
|
+
// Each pulse's end, as the session's events tell it - for the run's report.
|
|
264
|
+
const finished = new Set();
|
|
265
|
+
const hear = (event) => {
|
|
266
|
+
if (event.type === "job" && event.final)
|
|
267
|
+
for (const each of finished)
|
|
268
|
+
each(event.job);
|
|
269
|
+
};
|
|
270
|
+
listeners.add(hear);
|
|
271
|
+
const stop = () => void listeners.delete(hear);
|
|
272
|
+
const start = () => runWork({
|
|
273
|
+
loop: sessionLoop(core),
|
|
274
|
+
jobs: core.jobs,
|
|
275
|
+
onFinish: (listener) => (finished.add(listener), () => void finished.delete(listener)),
|
|
276
|
+
...(ask !== undefined ? { ask: (title, body) => askYesNo(ask, chat ?? core.shown(), title, body) } : {}),
|
|
277
|
+
}, kind, { ...asked, plainFile });
|
|
278
|
+
try {
|
|
279
|
+
const run = chat !== undefined ? await inChat(chatOrThrow(chat).scope, start) : await start();
|
|
280
|
+
return { planned: run.planned, done: run.done.finally(stop) };
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
stop();
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const turri = {
|
|
288
|
+
cwd,
|
|
289
|
+
extension,
|
|
290
|
+
on(...args) {
|
|
291
|
+
const [first, second, third] = args;
|
|
292
|
+
const listener = typeof first === "function" ? first : (event) => { if (event.type === first)
|
|
293
|
+
second(event); };
|
|
294
|
+
const { signal } = ((typeof first === "function" ? second : third) ?? {});
|
|
295
|
+
if (signal?.aborted === true)
|
|
296
|
+
return () => { };
|
|
297
|
+
listeners.add(listener);
|
|
298
|
+
const off = () => listeners.delete(listener);
|
|
299
|
+
signal?.addEventListener("abort", off, { once: true });
|
|
300
|
+
return off;
|
|
301
|
+
},
|
|
302
|
+
events(options = {}) {
|
|
303
|
+
return eventStream((listener) => {
|
|
304
|
+
listeners.add(listener);
|
|
305
|
+
return () => listeners.delete(listener);
|
|
306
|
+
}, options.signal, closed);
|
|
307
|
+
},
|
|
308
|
+
chats: {
|
|
309
|
+
list: () => core.chats(),
|
|
310
|
+
get: (id) => (core.session(id) !== undefined ? handle(id) : undefined),
|
|
311
|
+
focused: () => core.shown(),
|
|
312
|
+
focus: (id) => core.show(id),
|
|
313
|
+
async open(asked = {}) {
|
|
314
|
+
if (sessions === undefined)
|
|
315
|
+
throw new TurriError("no-chat", frontend === undefined ? "A session with no front end has no chats: open it with a frontend." : "This front end has no chats (sessions: none).");
|
|
316
|
+
try {
|
|
317
|
+
const info = await core.open({ ...(asked.sessionFile !== undefined ? { sessionFile: asked.sessionFile } : {}), ...(asked.title !== undefined ? { title: asked.title } : {}), ...(asked.focus === false ? { hidden: true } : {}) });
|
|
318
|
+
return handle(info.id);
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
throw isTurriError(error) ? error : new TurriError(/the most there can be/.test(String(error)) ? "chat-limit" : "refused", error instanceof Error ? error.message : String(error), { cause: error });
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
adopt: (session) => handle(core.adopt(session).id),
|
|
325
|
+
async restore(run = "last") {
|
|
326
|
+
const saved = run === "last" ? lastRun(cwd) : run;
|
|
327
|
+
if (saved === undefined)
|
|
328
|
+
return [];
|
|
329
|
+
const before = new Set(core.chats().map((chat) => chat.id));
|
|
330
|
+
await core.restore(saved);
|
|
331
|
+
return core.chats().filter((chat) => !before.has(chat.id)).map((chat) => handle(chat.id));
|
|
332
|
+
},
|
|
333
|
+
close: (id) => core.close(id),
|
|
334
|
+
onHarnessModel: () => core.onHarnessModel(),
|
|
335
|
+
},
|
|
336
|
+
work: {
|
|
337
|
+
status() {
|
|
338
|
+
const loop = plannedLoop(core.jobs);
|
|
339
|
+
const planned = loop?.planned() ?? [];
|
|
340
|
+
const held = new Set(planned.filter((row) => row.lookedAhead).map((row) => row.module));
|
|
341
|
+
const jobs = core.jobs.list().filter((each) => each.replacedBy === undefined);
|
|
342
|
+
const busy = planned.some((row) => row.planning !== undefined) || jobs.some((each) => each.status === "running" && (each.kind === "regenerate" || each.kind === "conformance"));
|
|
343
|
+
return snapshot({ modules: (loop?.status() ?? []).map((row) => (held.has(row.module) ? { ...row, lookedAhead: true } : row)), jobs, planned, busy });
|
|
344
|
+
},
|
|
345
|
+
jobs: () => snapshot(core.jobs.list()),
|
|
346
|
+
job: (id) => { const found = job(id); return found !== undefined ? snapshot(found) : undefined; },
|
|
347
|
+
standing: (files) => projectStanding(cwd, { ...(files !== undefined ? { files } : {}), loop: plannedLoop(core.jobs) }),
|
|
348
|
+
map(asked = {}) {
|
|
349
|
+
if (asked.refresh === true)
|
|
350
|
+
map.refresh();
|
|
351
|
+
return map.read();
|
|
352
|
+
},
|
|
353
|
+
history(asked = {}) {
|
|
354
|
+
return earlierPulses(ledgerProjects(cwd), new Set(core.jobs.list().map((each) => each.id)), asked.runs);
|
|
355
|
+
},
|
|
356
|
+
async lookAhead(plainFile) {
|
|
357
|
+
const loop = sessionLoop(core);
|
|
358
|
+
const statuses = await lookAhead(loop, resolve(cwd, plainFile));
|
|
359
|
+
const next = [];
|
|
360
|
+
for await (const pulse of nextPulses(loop, statuses))
|
|
361
|
+
next.push(pulse);
|
|
362
|
+
return { statuses, next };
|
|
363
|
+
},
|
|
364
|
+
regenerate: work("regenerate"),
|
|
365
|
+
conform: work("conform"),
|
|
366
|
+
async halt(target) {
|
|
367
|
+
if ("pulse" in target)
|
|
368
|
+
return stopJob(core.jobs, target.pulse, target.reason, plannedLoop(core.jobs));
|
|
369
|
+
return haltLaunched(target.launched, sessionLaunchesOf(core.jobs)?.track);
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
launches: {
|
|
373
|
+
list: () => snapshot(sessionLaunchesOf(core.jobs)?.track.list() ?? []),
|
|
374
|
+
running: () => runningLaunched(),
|
|
375
|
+
async launch(plainFile, asked = {}) {
|
|
376
|
+
const track = sessionLaunchesOf(core.jobs)?.track;
|
|
377
|
+
const file = plainFile ?? readProjectConfig(cwd).module;
|
|
378
|
+
if (file === undefined)
|
|
379
|
+
throw new TurriError("refused", "Name the module's .plain file: config.turri.yaml names no module.");
|
|
380
|
+
if (track === undefined)
|
|
381
|
+
throw new TurriError("refused", "This session has no launch track.");
|
|
382
|
+
if (asked.signal?.aborted === true)
|
|
383
|
+
throw new TurriError("aborted", "The launch was stopped before it was asked for.");
|
|
384
|
+
let request;
|
|
385
|
+
try {
|
|
386
|
+
request = track.request({
|
|
387
|
+
plainFile: resolve(cwd, file),
|
|
388
|
+
cause: asked.chat !== undefined ? { chat: asked.chat } : {},
|
|
389
|
+
...(asked.guidance !== undefined ? { guidance: asked.guidance } : {}),
|
|
390
|
+
...(asked.inModule !== undefined ? { inModule: asked.inModule } : {}),
|
|
391
|
+
...(asked.again === true ? { again: true } : {}),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
throw new TurriError("refused", error instanceof Error ? error.message : String(error), { cause: error });
|
|
396
|
+
}
|
|
397
|
+
const { launch, already } = request;
|
|
398
|
+
if (already)
|
|
399
|
+
return snapshot(launch);
|
|
400
|
+
// Its output, and the output of each launch that takes its place, to `onOutput` - until it ends.
|
|
401
|
+
const ours = new Set([launch.id]);
|
|
402
|
+
const follow = (id) => void track.replaced(id).then((next) => (ours.add(next.id), follow(next.id)));
|
|
403
|
+
follow(launch.id);
|
|
404
|
+
const onOutput = asked.onOutput;
|
|
405
|
+
const off = onOutput !== undefined ? turri.on("launchOutput", (event) => { if (ours.has(event.launch))
|
|
406
|
+
onOutput(event.text); }) : () => { };
|
|
407
|
+
const stop = () => void track.stop(launch.codebase);
|
|
408
|
+
asked.signal?.addEventListener("abort", stop, { once: true });
|
|
409
|
+
try {
|
|
410
|
+
return snapshot(await track.done(launch.id));
|
|
411
|
+
}
|
|
412
|
+
finally {
|
|
413
|
+
off();
|
|
414
|
+
asked.signal?.removeEventListener("abort", stop);
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
followLogs: (onLine, asked = {}) => followLaunchedLogs(onLine, asked.signal !== undefined ? { signal: asked.signal } : {}),
|
|
418
|
+
},
|
|
419
|
+
notices: {
|
|
420
|
+
list: () => snapshot(core.notices()),
|
|
421
|
+
answer: async (id, answer) => core.answer(id, answer),
|
|
422
|
+
},
|
|
423
|
+
sentinel: {
|
|
424
|
+
check: (request) => core.check(() => prepareCheck(cwd, request)),
|
|
425
|
+
},
|
|
426
|
+
settings: {
|
|
427
|
+
get: (key, asked = {}) => readSetting(cwd, key, asked),
|
|
428
|
+
async set(key, value, asked = {}) {
|
|
429
|
+
const setting = settingOf(key, ruleNames());
|
|
430
|
+
if (setting === undefined)
|
|
431
|
+
throw new TurriError("not-found", `There is no setting ${String(key)}.`);
|
|
432
|
+
if (asked.module !== undefined && setting.projectOnly === true)
|
|
433
|
+
throw new TurriError("refused", `${setting.key} is the whole project's: it is set in config.turri.yaml alone, never in a module's file.`);
|
|
434
|
+
const known = reachableModels();
|
|
435
|
+
const written = givenValue(cwd, setting, value, known.length > 0 ? (model) => known.includes(model) : undefined);
|
|
436
|
+
return changeSetting(cwd, setting, written, asked.module, {
|
|
437
|
+
harnessChanged: () => core.onHarnessModel(),
|
|
438
|
+
parallelJobs: (count) => {
|
|
439
|
+
const limit = count ?? parallelJobs(cwd);
|
|
440
|
+
core.jobs.setMaxRunning(limit);
|
|
441
|
+
return `Up to ${limit} pulse${limit === 1 ? "" : "s"} run at once now.`;
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
choices(key, typed = "") {
|
|
446
|
+
const setting = settingOf(key, ruleNames());
|
|
447
|
+
if (setting === undefined)
|
|
448
|
+
return [];
|
|
449
|
+
return settingCandidates(setting, typed, { cwd, models: reachableModels });
|
|
450
|
+
},
|
|
451
|
+
turnOnConformanceTests: (plainFile) => turnOnConformance(core, plainFile),
|
|
452
|
+
},
|
|
453
|
+
skills: {
|
|
454
|
+
list: () => discoverSkills(PACKAGE_ROOT, cwd).skills.map((skill) => ({ name: skill.name, description: skill.description, steps: stepsOf(skill) })),
|
|
455
|
+
run: (which, asked = {}) => runSkillOutsideChats(core, which, asked, ask, (progress) => emit({ type: "skillProgress", progress })),
|
|
456
|
+
},
|
|
457
|
+
spending: () => core.spending(),
|
|
458
|
+
async dispose() {
|
|
459
|
+
if (disposed)
|
|
460
|
+
return;
|
|
461
|
+
disposed = true;
|
|
462
|
+
closed.abort();
|
|
463
|
+
if (mapTimer !== undefined)
|
|
464
|
+
clearInterval(mapTimer);
|
|
465
|
+
if (mapSoon !== undefined)
|
|
466
|
+
clearTimeout(mapSoon);
|
|
467
|
+
stopLedger();
|
|
468
|
+
await core.dispose();
|
|
469
|
+
await stopLaunched();
|
|
470
|
+
setConfigOverrides(cwd, undefined);
|
|
471
|
+
listeners.clear();
|
|
472
|
+
if (current === turri)
|
|
473
|
+
current = undefined;
|
|
474
|
+
},
|
|
475
|
+
[Symbol.asyncDispose]: () => turri.dispose(),
|
|
476
|
+
};
|
|
477
|
+
/** The models of every provider signed in to, from a chat's own registry - the one shown, else any open. */
|
|
478
|
+
function reachableModels() {
|
|
479
|
+
for (const id of [core.shown(), ...core.chats().map((chat) => chat.id)]) {
|
|
480
|
+
try {
|
|
481
|
+
const context = id !== undefined ? stateOf(id)?.instance?.context() : undefined;
|
|
482
|
+
if (context !== undefined)
|
|
483
|
+
return reachable(context);
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
/* a context let go: the next one */
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return [];
|
|
490
|
+
}
|
|
491
|
+
current = turri;
|
|
492
|
+
return turri;
|
|
493
|
+
}
|
|
494
|
+
/** The session's overrides as the config's keys. */
|
|
495
|
+
function sessionConfigOverrides(overrides) {
|
|
496
|
+
if (overrides === undefined)
|
|
497
|
+
return undefined;
|
|
498
|
+
const model = (spec) => (spec !== undefined ? splitModelSpec(spec) : undefined);
|
|
499
|
+
return {
|
|
500
|
+
...(overrides.harnessModel !== undefined ? { harnessModel: model(overrides.harnessModel) } : {}),
|
|
501
|
+
...(overrides.codingModel !== undefined ? { codingModel: model(overrides.codingModel) } : {}),
|
|
502
|
+
...(overrides.judgeModel !== undefined ? { judgeModel: model(overrides.judgeModel) } : {}),
|
|
503
|
+
...(overrides.review !== undefined ? { review: overrides.review } : {}),
|
|
504
|
+
...(overrides.mutationTesting !== undefined ? { mutationTesting: overrides.mutationTesting } : {}),
|
|
505
|
+
...(overrides.debug !== undefined ? { debug: overrides.debug } : {}),
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* A front end's listener threw: a warning coded `TURRI_LISTENER`, its stack the detail - never turri's own error. Given
|
|
510
|
+
* an Error, Node drops the code, so the warning is the message.
|
|
511
|
+
*/
|
|
512
|
+
function listenerThrew(error) {
|
|
513
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
514
|
+
process.emitWarning(message, { code: "TURRI_LISTENER", ...(error instanceof Error && error.stack !== undefined ? { detail: error.stack } : {}) });
|
|
515
|
+
}
|
|
516
|
+
/** The front end's `ask` as the dialogs turri's questions are put in, for one chat - or none, outside any. */
|
|
517
|
+
function frontendDialogs(ask, chat) {
|
|
518
|
+
const asking = (asked) => ({ ...(chat !== undefined ? { chat } : {}), signal: asked?.signal ?? new AbortController().signal });
|
|
519
|
+
return {
|
|
520
|
+
select: (title, options, context, at, asked) => ask({ kind: "select", title, options, ...(context !== undefined ? { context } : {}), ...(at !== undefined ? { at } : {}) }, asking(asked)),
|
|
521
|
+
input: (title, context, asked) => ask({ kind: "input", title, ...(context !== undefined ? { context } : {}) }, asking(asked)),
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
const YES = "Yes";
|
|
525
|
+
/** A yes or no put to the person through the front end: true for yes; undefined when they gave no answer. */
|
|
526
|
+
async function askYesNo(ask, chat, title, body) {
|
|
527
|
+
const answer = await ask({ kind: "select", title, options: [YES, "No"], context: body }, { ...(chat !== undefined ? { chat } : {}), signal: new AbortController().signal });
|
|
528
|
+
return answer === undefined ? undefined : answer === YES;
|
|
529
|
+
}
|
|
530
|
+
/** Plain data of what turri keeps live: a copy a front end may keep, send or change. */
|
|
531
|
+
function snapshot(value) {
|
|
532
|
+
try {
|
|
533
|
+
return structuredClone(value);
|
|
534
|
+
}
|
|
535
|
+
catch {
|
|
536
|
+
return JSON.parse(JSON.stringify(value));
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/** The events from now on as an async iterable, until `signal` or `closed` is aborted. */
|
|
540
|
+
function eventStream(subscribe, signal, closed) {
|
|
541
|
+
return {
|
|
542
|
+
[Symbol.asyncIterator]() {
|
|
543
|
+
const queue = [];
|
|
544
|
+
let wake;
|
|
545
|
+
let ended = false;
|
|
546
|
+
const unsubscribe = subscribe((event) => {
|
|
547
|
+
queue.push(event);
|
|
548
|
+
wake?.();
|
|
549
|
+
});
|
|
550
|
+
const end = () => {
|
|
551
|
+
ended = true;
|
|
552
|
+
unsubscribe();
|
|
553
|
+
wake?.();
|
|
554
|
+
};
|
|
555
|
+
signal?.addEventListener("abort", end, { once: true });
|
|
556
|
+
closed.signal.addEventListener("abort", end, { once: true });
|
|
557
|
+
if (signal?.aborted === true || closed.signal.aborted)
|
|
558
|
+
end();
|
|
559
|
+
return {
|
|
560
|
+
async next() {
|
|
561
|
+
while (queue.length === 0 && !ended)
|
|
562
|
+
await new Promise((resolve) => (wake = resolve));
|
|
563
|
+
wake = undefined;
|
|
564
|
+
const event = queue.shift();
|
|
565
|
+
return event !== undefined ? { value: event, done: false } : { value: undefined, done: true };
|
|
566
|
+
},
|
|
567
|
+
async return() {
|
|
568
|
+
end();
|
|
569
|
+
return { value: undefined, done: true };
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
/** A skill's steps, each with its gate, as a front end shows them. */
|
|
576
|
+
function stepsOf(skill) {
|
|
577
|
+
return skill.steps.map((step) => {
|
|
578
|
+
const gate = step.gate;
|
|
579
|
+
const review = gate?.review;
|
|
580
|
+
return {
|
|
581
|
+
name: step.name,
|
|
582
|
+
...(step.about !== undefined ? { about: step.about } : {}),
|
|
583
|
+
...(review !== undefined
|
|
584
|
+
? {
|
|
585
|
+
gate: {
|
|
586
|
+
rubric: review.rubric,
|
|
587
|
+
judges: review.judges,
|
|
588
|
+
quorum: review.quorum,
|
|
589
|
+
onFail: review.onFail,
|
|
590
|
+
maxRetries: review.maxRetries,
|
|
591
|
+
...(gate.continuous !== undefined ? { continuous: { rubric: gate.continuous.rubric, judges: gate.continuous.judges } } : {}),
|
|
592
|
+
},
|
|
593
|
+
}
|
|
594
|
+
: {}),
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
/** The skill `skills.run` is asked for: one of the catalogue's by name, or the one in a folder. */
|
|
599
|
+
function skillAsked(cwd, which) {
|
|
600
|
+
if (typeof which === "string") {
|
|
601
|
+
const skill = discoverSkills(PACKAGE_ROOT, cwd).skills.find((each) => each.name === which);
|
|
602
|
+
if (skill === undefined)
|
|
603
|
+
throw new TurriError("not-found", `There is no skill ${which}.`);
|
|
604
|
+
return skill;
|
|
605
|
+
}
|
|
606
|
+
const dir = resolve(cwd, which.dir);
|
|
607
|
+
if (!existsSync(join(dir, "SKILL.md")))
|
|
608
|
+
throw new TurriError("not-found", `There is no SKILL.md in ${dir}.`);
|
|
609
|
+
try {
|
|
610
|
+
return loadSkill(dir);
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
throw new TurriError("refused", error instanceof Error ? error.message : String(error), { cause: error });
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/** A skill run outside any chat: its questions and escalations put through the front end, its progress as events. */
|
|
617
|
+
async function runSkillOutsideChats(core, which, options, ask, progress) {
|
|
618
|
+
const { cwd } = core;
|
|
619
|
+
const skill = skillAsked(cwd, which);
|
|
620
|
+
const phases = skill.steps.map((step) => step.name);
|
|
621
|
+
const models = projectModels(readProjectConfig(cwd));
|
|
622
|
+
const model = options.model ?? modelSpec(skill.model === "coding" ? models.coding : models.harness);
|
|
623
|
+
const io = ask !== undefined ? frontendDialogs(ask, undefined) : undefined;
|
|
624
|
+
const runDir = skillRunDir(cwd, skill.name);
|
|
625
|
+
// What the run says, to the caller as it says it: a caller's throw is a warning, never the run's end.
|
|
626
|
+
const tell = (report) => {
|
|
627
|
+
try {
|
|
628
|
+
options.onReport?.(report);
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
listenerThrew(error);
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
// A step's artifact comes as it ends, and the judges' verdicts after the gate that asked them: the last step's, the last gate's.
|
|
635
|
+
let stepping = "";
|
|
636
|
+
let gating = "";
|
|
637
|
+
progress({ skill: skill.name, phases, current: -1, attempt: 1 });
|
|
638
|
+
tell({ kind: "start", skill: skill.name, steps: stepsOf(skill) });
|
|
639
|
+
try {
|
|
640
|
+
const result = await runSkill({
|
|
641
|
+
skillDir: skill.dir,
|
|
642
|
+
cwd,
|
|
643
|
+
runDir,
|
|
644
|
+
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
645
|
+
...(options.context !== undefined ? { context: options.context } : {}),
|
|
646
|
+
...(model !== undefined ? { model } : {}),
|
|
647
|
+
renderQueue: sessionLoop(core),
|
|
648
|
+
report: {
|
|
649
|
+
step: (step, attempt) => {
|
|
650
|
+
stepping = step;
|
|
651
|
+
progress({ skill: skill.name, phases, current: phases.indexOf(step), attempt });
|
|
652
|
+
tell({ kind: "step", step, attempt });
|
|
653
|
+
},
|
|
654
|
+
artifact: (path, body) => tell({ kind: "artifact", step: stepping, path, body }),
|
|
655
|
+
livePass: (step, scope, findings) => tell({ kind: "livePass", step, scope, findings }),
|
|
656
|
+
liveReview: (step, passes, findings) => tell({ kind: "liveReview", step, passes, findings }),
|
|
657
|
+
gate: (step, judges) => {
|
|
658
|
+
gating = step;
|
|
659
|
+
tell({ kind: "gate", step, judges });
|
|
660
|
+
},
|
|
661
|
+
judge: (index, model, verdict, violations) => tell({ kind: "judge", step: gating, judge: index, model, verdict: verdict === "pass" || verdict === "fail" ? verdict : "none", violations }),
|
|
662
|
+
outcome: (step, decision, critique) => tell({ kind: "outcome", step, decision, critique }),
|
|
663
|
+
},
|
|
664
|
+
...(io !== undefined ? { askUser: (request) => runAsk(request, io) } : {}),
|
|
665
|
+
escalate: async ({ question, critique }) => (ask !== undefined ? (await askYesNo(ask, undefined, `Review gate: ${skill.name} - ${question}`, critique)) === true : false),
|
|
666
|
+
});
|
|
667
|
+
return { ok: result.ok, artifacts: result.artifacts, output: result.output, runDir };
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
progress(null);
|
|
671
|
+
}
|
|
672
|
+
}
|