@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/chats.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import type { AgentSession, ExtensionAPI, ExtensionContext, ExtensionFactory
|
|
1
|
+
import type { AgentSession, ExtensionAPI, ExtensionContext, ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { type ChatScope } from "./chat-scope.ts";
|
|
3
3
|
import { type RunRecord } from "./chat-records.ts";
|
|
4
|
-
import { type ChatUi } from "./chat-ui.ts";
|
|
5
|
-
import { TerminalNotifications } from "./notifications.ts";
|
|
6
4
|
import { type SentinelSetting } from "./config.ts";
|
|
7
5
|
import type { AskUserIO } from "./ask.ts";
|
|
8
|
-
import {
|
|
6
|
+
import type { Job, JobRegistry } from "./regenerate/jobs.ts";
|
|
9
7
|
import type { Launch } from "./launch-track.ts";
|
|
10
8
|
import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
11
9
|
import { type ChatRole, type Conclusion, type Notice, type NoticeAnswer, type NoticeInput, type SentinelCheck } from "./notice.ts";
|
|
12
|
-
import type
|
|
13
|
-
import type { SessionEvent } from "./session-events.ts";
|
|
10
|
+
import { type SessionEvent } from "./session-events.ts";
|
|
14
11
|
import { createSessionSpending, type SessionSpending } from "./session-spending.ts";
|
|
12
|
+
import type { ModelOutOfReach } from "./chat-model.ts";
|
|
15
13
|
/**
|
|
16
14
|
* The chats of a turri session.
|
|
17
15
|
*
|
|
@@ -25,7 +23,7 @@ import { createSessionSpending, type SessionSpending } from "./session-spending.
|
|
|
25
23
|
* which chat asked for it, and is reported back there when it ends - to the chat shown, when that one is closed.
|
|
26
24
|
*
|
|
27
25
|
* Where the chats live is a driver's: the terminal's (chat-terminal.ts) swaps which one pi's screen shows; a host's
|
|
28
|
-
*
|
|
26
|
+
* makes a session for each through `createTurri` (session.ts) and shows them in its own way.
|
|
29
27
|
*
|
|
30
28
|
* With the project's sentinel on (sentinel.ts), every finished pulse goes to the sentinel - a chat of the session's own,
|
|
31
29
|
* opened in the background with the first, and again after it is closed - and the chat the person looks at shows only
|
|
@@ -69,7 +67,7 @@ export interface TurriHost {
|
|
|
69
67
|
* The last word on the whole system prompt, as turri has built it for this turn - after its own before_agent_start
|
|
70
68
|
* work: what it returns is what is sent. For a host that needs to change anything else.
|
|
71
69
|
*/
|
|
72
|
-
systemPrompt?(prompt: string): string;
|
|
70
|
+
systemPrompt?(prompt: string, chat: string): string;
|
|
73
71
|
/**
|
|
74
72
|
* A chat's session replaced by a new one, under the same id: the sentinel's, a fresh conversation for each pulse it
|
|
75
73
|
* checks - told before the pulse is put to it. The host follows this session in place of the one it had.
|
|
@@ -92,8 +90,27 @@ export interface TurriHost {
|
|
|
92
90
|
* request comes again, `stopped`.
|
|
93
91
|
*/
|
|
94
92
|
onLaunch?(launch: Launch): void;
|
|
93
|
+
/** A launch's agent said more, as it streams. */
|
|
94
|
+
onLaunchOutput?(launch: Launch, text: string): void;
|
|
95
95
|
/** What the sentinel puts to the person - and, `kind: "sentinel-start"`, whether to start it: the host draws it in the chat it names, and answers it with `answer`. */
|
|
96
96
|
onNotice?(notice: Notice): void;
|
|
97
|
+
/**
|
|
98
|
+
* The front end puts notices to the person itself - its cards and buttons, answered with `answer` - so a chat does not
|
|
99
|
+
* put one as a question once it is idle. Unset, a chat with a screen does.
|
|
100
|
+
*/
|
|
101
|
+
noticesShown?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* The person asked to see something the front end shows - `/pulses` - in the chat named: true when it shows it. Unset
|
|
104
|
+
* or false, the chat lists it in text.
|
|
105
|
+
*/
|
|
106
|
+
reveal?(target: {
|
|
107
|
+
kind: "pulses" | "pulse" | "map";
|
|
108
|
+
id?: string;
|
|
109
|
+
}, context: {
|
|
110
|
+
chat: string;
|
|
111
|
+
}): boolean;
|
|
112
|
+
/** pi's own settings, the last entry of /settings: opened where the front end has them. False or unset: said to open only there. */
|
|
113
|
+
openPiSettings?(): boolean;
|
|
97
114
|
/** A notice is over - answered, dismissed, or superseded by a newer one about its module: the host takes its card down. */
|
|
98
115
|
onNoticeOver?(notice: Notice): void;
|
|
99
116
|
/**
|
|
@@ -108,12 +125,6 @@ export interface TurriHost {
|
|
|
108
125
|
}
|
|
109
126
|
/** What a chat's extension does for its chat when the session asks. */
|
|
110
127
|
export interface ChatInstance {
|
|
111
|
-
/** The terminal header's toggle. Visibility is independent of which side has the keys. */
|
|
112
|
-
plainPanel?: {
|
|
113
|
-
open(): boolean;
|
|
114
|
-
busy(): boolean;
|
|
115
|
-
toggle(): void;
|
|
116
|
-
};
|
|
117
128
|
/** A pulse it asked for ended: said in the chat, and its agent told, to react to it. */
|
|
118
129
|
announce(job: Job): void;
|
|
119
130
|
/**
|
|
@@ -155,6 +166,10 @@ export interface ChatInstance {
|
|
|
155
166
|
thinkingLevel(): string | undefined;
|
|
156
167
|
/** The chat's context, as its tools get it - for its model and its providers. */
|
|
157
168
|
context(): ExtensionContext | undefined;
|
|
169
|
+
/** A person's chat: put on harness-model if it is not on it as the config has it now - or why it cannot be kept. */
|
|
170
|
+
onHarnessModel?(): Promise<void>;
|
|
171
|
+
/** A person's chat: harness-model as it cannot be reached now - none while the chat is on it. */
|
|
172
|
+
outOfReach?(): ModelOutOfReach | undefined;
|
|
158
173
|
}
|
|
159
174
|
/** A chat's extension, linked to its chat. */
|
|
160
175
|
export interface ChatLink {
|
|
@@ -169,10 +184,8 @@ export interface ChatLink {
|
|
|
169
184
|
/** The extension built for the chat - again, when pi rebuilds it - and what it does for it. */
|
|
170
185
|
live(instance: ChatInstance): void;
|
|
171
186
|
}
|
|
172
|
-
/** Where chats live:
|
|
187
|
+
/** Where chats live: a session's own pi sessions, or a front end's. */
|
|
173
188
|
export interface ChatDriver {
|
|
174
|
-
/** pi's terminal: the chats are switched between with its keys and /chat. */
|
|
175
|
-
terminal?: boolean;
|
|
176
189
|
/** A session for the chat - its saved one, when `sessionFile` - with the session's extension built for it. */
|
|
177
190
|
create(chat: ChatState, sessionFile: string | undefined): Promise<void>;
|
|
178
191
|
/** Put the chat on the screen. */
|
|
@@ -188,10 +201,6 @@ export interface ChatState {
|
|
|
188
201
|
/** Its title as recorded, until it says one of its own. */
|
|
189
202
|
recordedTitle?: string;
|
|
190
203
|
session?: AgentSession;
|
|
191
|
-
/** pi's services the session was made with - the terminal's driver hands them to pi with it. */
|
|
192
|
-
services?: unknown;
|
|
193
|
-
/** What it draws on, in the terminal. */
|
|
194
|
-
ui?: ChatUi;
|
|
195
204
|
instance?: ChatInstance;
|
|
196
205
|
dialogs?: AskUserIO;
|
|
197
206
|
working: boolean;
|
|
@@ -201,8 +210,6 @@ export interface ChatState {
|
|
|
201
210
|
export interface TurriCore {
|
|
202
211
|
/** What this run has spent, across every chat and pulse. */
|
|
203
212
|
spending(): SessionSpending;
|
|
204
|
-
/** Shared by all the terminal's chats. */
|
|
205
|
-
readonly notifications: TerminalNotifications;
|
|
206
213
|
readonly cwd: string;
|
|
207
214
|
readonly host: TurriHost;
|
|
208
215
|
readonly jobs: JobRegistry;
|
|
@@ -210,18 +217,15 @@ export interface TurriCore {
|
|
|
210
217
|
readonly extension: ExtensionFactory;
|
|
211
218
|
/** Whether chats can be opened beside the one there is - with a driver that has somewhere to put them. */
|
|
212
219
|
readonly canOpen: boolean;
|
|
213
|
-
/** Whether the chats are the terminal's, switched between with /chat and its keys. */
|
|
214
|
-
readonly terminal: boolean;
|
|
215
|
-
/** What a front-end draws of the session that the core does not (view.ts) - undefined for a host and a headless run. */
|
|
216
|
-
readonly view: TurriView | undefined;
|
|
217
|
-
/** Only the first terminal chat shows the welcome, until a non-empty submission anywhere in the session. */
|
|
218
|
-
welcomeVisible(chat: string): boolean;
|
|
219
|
-
dismissWelcome(): void;
|
|
220
220
|
chats(): ChatInfo[];
|
|
221
221
|
/** The chat's pi session. */
|
|
222
222
|
session(id: string): AgentSession | undefined;
|
|
223
223
|
/** The questions the chat asks now declined, as ctrl+c at one declines it - `none` when it asks nothing. */
|
|
224
224
|
decline(id: string): "declined" | "none" | "missing";
|
|
225
|
+
/** Each of the person's chats put on harness-model as the config has it now - after a sign-in, or a change to it. */
|
|
226
|
+
onHarnessModel(): Promise<void>;
|
|
227
|
+
/** harness-model as the chat cannot be on it now - none while it is, or for the sentinel's. */
|
|
228
|
+
outOfReach(id: string): ModelOutOfReach | undefined;
|
|
225
229
|
/** The chat shown now. */
|
|
226
230
|
shown(): string | undefined;
|
|
227
231
|
/** Open a chat - fresh, or the saved one `sessionFile` is - shown at once unless `hidden`; the sentinel with `role`. */
|
|
@@ -237,8 +241,13 @@ export interface TurriCore {
|
|
|
237
241
|
onChats(listener: () => void): () => void;
|
|
238
242
|
/** For a driver: something about the chats changed - a question waiting, one shown - and those listening are told. */
|
|
239
243
|
changed(): void;
|
|
240
|
-
/**
|
|
241
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Said in the chat shown - or the first one shown, when none is yet - and to every front end as a `notification`,
|
|
246
|
+
* unless `notification: false`: an event of its own tells them, and the same said twice is one too many.
|
|
247
|
+
*/
|
|
248
|
+
notify(message: string, level: "info" | "warning" | "error", options?: {
|
|
249
|
+
notification?: boolean;
|
|
250
|
+
}): void;
|
|
242
251
|
/** Every chat let go, but the one pi is letting go itself. */
|
|
243
252
|
dispose(options?: {
|
|
244
253
|
except?: AgentSession;
|
|
@@ -249,8 +258,8 @@ export interface TurriCore {
|
|
|
249
258
|
chatOfSession(session: AgentSession): ChatState | undefined;
|
|
250
259
|
/** For a driver: the chat shown now, as the session keeps it. */
|
|
251
260
|
shownChat(): ChatState | undefined;
|
|
252
|
-
/**
|
|
253
|
-
adopt(session: AgentSession
|
|
261
|
+
/** A pi session the front end made with turri's extension in it - pi's first, one it rebuilt or forked - as a chat. */
|
|
262
|
+
adopt(session: AgentSession): ChatState;
|
|
254
263
|
/** For a driver: `chat` is on the screen now. */
|
|
255
264
|
showing(chat: ChatState): void;
|
|
256
265
|
/** For the extension: a pulse ended - told to the chat that asked for it, or, with the sentinel on, to the sentinel. */
|
|
@@ -289,10 +298,8 @@ export interface TurriCore {
|
|
|
289
298
|
/** The chat whose work this is, else the one shown: its instance. */
|
|
290
299
|
instanceInScope(): ChatInstance | undefined;
|
|
291
300
|
setDriver(driver: ChatDriver): void;
|
|
292
|
-
/** Reopen a run's chats - `--continue` -
|
|
293
|
-
restore(run: RunRecord
|
|
294
|
-
skipFirst?: boolean;
|
|
295
|
-
}): Promise<void>;
|
|
301
|
+
/** Reopen a run's chats - `--continue` - those not open already, each hidden, in their order. */
|
|
302
|
+
restore(run: RunRecord): Promise<void>;
|
|
296
303
|
}
|
|
297
304
|
export interface CoreOptions {
|
|
298
305
|
spending?: ReturnType<typeof createSessionSpending>;
|
|
@@ -316,8 +323,6 @@ export interface CoreOptions {
|
|
|
316
323
|
ignored?: (notice: Notice) => void;
|
|
317
324
|
/** The launch track, as the sentinel waits on it (docs/sentinel.md). Not given: the sentinel waits for nothing. */
|
|
318
325
|
launches?: SentinelLaunches;
|
|
319
|
-
/** What a front-end draws of the session that the core does not - the terminal's. Not given: a host's or a headless run's. */
|
|
320
|
-
view?: TurriView;
|
|
321
326
|
}
|
|
322
327
|
/**
|
|
323
328
|
* What the sentinel waits on of the launch track: a pulse is tested only in a launch whose commit holds the pulse's, and
|
|
@@ -332,6 +337,15 @@ export interface SentinelLaunches {
|
|
|
332
337
|
settled(codebase: string): Promise<void>;
|
|
333
338
|
/** The codebases whose launches a launch replaces - what they started stopped: its own, and the modules below it. Default: its own. */
|
|
334
339
|
replacing?(launch: Launch): string[];
|
|
340
|
+
/**
|
|
341
|
+
* How the person tries what the sentinel tested a pulse or a check in, as its launch said it - where it runs, or the
|
|
342
|
+
* commands to run it from `dist/<module>`. Nothing when that did not come up, or said nothing.
|
|
343
|
+
*/
|
|
344
|
+
tryIt?(work: {
|
|
345
|
+
job: Job;
|
|
346
|
+
} | {
|
|
347
|
+
check: SentinelCheck;
|
|
348
|
+
}): string | undefined;
|
|
335
349
|
}
|
|
336
350
|
/** A chat's session, as stopping what it does reaches it. */
|
|
337
351
|
export type Stoppable = Pick<AgentSession, "isStreaming" | "isCompacting" | "isRetrying" | "isBashRunning" | "abort" | "abortBash">;
|
|
@@ -355,5 +369,3 @@ export declare function createChats(options: CoreOptions): TurriCore;
|
|
|
355
369
|
* chat's scope - its id on what it starts.
|
|
356
370
|
*/
|
|
357
371
|
export declare function scopedToChat(pi: ExtensionAPI, scope: ChatScope): ExtensionAPI;
|
|
358
|
-
/** A chat's stand-in for the screen, for the terminal's driver. */
|
|
359
|
-
export declare function terminalUi(chat: ChatState, screen: () => ExtensionUIContext | undefined, onChange: () => void): ChatUi;
|
package/dist/chats.js
CHANGED
|
@@ -2,12 +2,10 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { currentChat, inChat } from "./chat-scope.js";
|
|
4
4
|
import { adoptRun, forgetChat, forgetSessionFile, recordRun } from "./chat-records.js";
|
|
5
|
-
import { createChatUi } from "./chat-ui.js";
|
|
6
|
-
import { TerminalNotifications } from "./notifications.js";
|
|
7
5
|
import { debugMode } from "./config.js";
|
|
8
6
|
import { firstLine, record } from "./regenerate/ledger.js";
|
|
9
|
-
import { pulseName, formatDuration } from "./regenerate/jobs.js";
|
|
10
7
|
import { newNotice, noticeTask, SENTINEL, sentinelStartChoice, wentWrong } from "./notice.js";
|
|
8
|
+
import { emitSessionEvent } from "./session-events.js";
|
|
11
9
|
import { createSessionSpending } from "./session-spending.js";
|
|
12
10
|
/**
|
|
13
11
|
* The chats of a turri session.
|
|
@@ -22,7 +20,7 @@ import { createSessionSpending } from "./session-spending.js";
|
|
|
22
20
|
* which chat asked for it, and is reported back there when it ends - to the chat shown, when that one is closed.
|
|
23
21
|
*
|
|
24
22
|
* Where the chats live is a driver's: the terminal's (chat-terminal.ts) swaps which one pi's screen shows; a host's
|
|
25
|
-
*
|
|
23
|
+
* makes a session for each through `createTurri` (session.ts) and shows them in its own way.
|
|
26
24
|
*
|
|
27
25
|
* With the project's sentinel on (sentinel.ts), every finished pulse goes to the sentinel - a chat of the session's own,
|
|
28
26
|
* opened in the background with the first, and again after it is closed - and the chat the person looks at shows only
|
|
@@ -81,6 +79,24 @@ function titleOf(session) {
|
|
|
81
79
|
return undefined;
|
|
82
80
|
}
|
|
83
81
|
const TITLE_CHARS = 32;
|
|
82
|
+
/** A chat's open questions: `onChange` told as each opens and closes - the chat's "question" status. */
|
|
83
|
+
function watchedQuestions(onChange) {
|
|
84
|
+
const questions = new Set();
|
|
85
|
+
const add = questions.add.bind(questions);
|
|
86
|
+
const remove = questions.delete.bind(questions);
|
|
87
|
+
questions.add = (decline) => {
|
|
88
|
+
add(decline);
|
|
89
|
+
onChange();
|
|
90
|
+
return questions;
|
|
91
|
+
};
|
|
92
|
+
questions.delete = (decline) => {
|
|
93
|
+
const had = remove(decline);
|
|
94
|
+
if (had)
|
|
95
|
+
onChange();
|
|
96
|
+
return had;
|
|
97
|
+
};
|
|
98
|
+
return questions;
|
|
99
|
+
}
|
|
84
100
|
export function createChats(options) {
|
|
85
101
|
const { cwd, host, jobs } = options;
|
|
86
102
|
const spending = options.spending ?? createSessionSpending();
|
|
@@ -88,13 +104,25 @@ export function createChats(options) {
|
|
|
88
104
|
const listeners = new Set();
|
|
89
105
|
let driver;
|
|
90
106
|
let shownId;
|
|
91
|
-
let welcomeChat;
|
|
92
|
-
let welcomeDismissed = false;
|
|
93
107
|
/** The chat whose extension pi is building now. */
|
|
94
108
|
let attaching;
|
|
95
109
|
/** Chats are opened one at a time: each one's extension is built while it is the one attaching. */
|
|
96
110
|
let opening = Promise.resolve();
|
|
97
111
|
let notices = [];
|
|
112
|
+
/** Said in the chat shown, as pi says what an extension says - kept for the next chat shown while none can say it. */
|
|
113
|
+
const say = (message, level) => {
|
|
114
|
+
const ui = core.shownChat()?.session?.extensionRunner.getUIContext();
|
|
115
|
+
if (ui === undefined) {
|
|
116
|
+
notices = [...notices, [message, level]].slice(-10);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
ui.notify(message, level);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* a chat let go says nothing */
|
|
124
|
+
}
|
|
125
|
+
};
|
|
98
126
|
/** What the sentinel put to the person, and turri itself, this session: open until answered or superseded. */
|
|
99
127
|
const open = [];
|
|
100
128
|
/** The work the sentinel's conversation is on, from its brief until its agent is done - `concluded` once it said so. */
|
|
@@ -150,7 +178,8 @@ export function createChats(options) {
|
|
|
150
178
|
return shown;
|
|
151
179
|
return fallback?.instance !== undefined && fallback.role !== SENTINEL ? fallback : people().find((chat) => chat.instance !== undefined);
|
|
152
180
|
};
|
|
153
|
-
|
|
181
|
+
// A question turri asks in it waits for the person - whatever front end shows it.
|
|
182
|
+
const statusOf = (chat) => chat.scope.asking.size > 0 ? "question" : chat.working ? "working" : chat.unread ? "unread" : "idle";
|
|
154
183
|
/** What the session keeps of its chats on disk: those with something said in them, in order. */
|
|
155
184
|
const persist = () => {
|
|
156
185
|
if (options.persist !== true)
|
|
@@ -164,11 +193,9 @@ export function createChats(options) {
|
|
|
164
193
|
};
|
|
165
194
|
const newChat = (title, role) => {
|
|
166
195
|
const id = randomUUID().slice(0, 8);
|
|
167
|
-
if (role === undefined)
|
|
168
|
-
welcomeChat ??= id;
|
|
169
196
|
const chat = {
|
|
170
197
|
id,
|
|
171
|
-
scope: { id, asking:
|
|
198
|
+
scope: { id, asking: watchedQuestions(() => changed()) },
|
|
172
199
|
...(title !== undefined ? { recordedTitle: title } : {}),
|
|
173
200
|
...(role !== undefined ? { role } : {}),
|
|
174
201
|
working: false,
|
|
@@ -214,25 +241,13 @@ export function createChats(options) {
|
|
|
214
241
|
};
|
|
215
242
|
const core = {
|
|
216
243
|
spending: () => spending.snapshot(jobs.list()),
|
|
217
|
-
notifications: new TerminalNotifications(),
|
|
218
244
|
cwd,
|
|
219
245
|
host,
|
|
220
246
|
jobs,
|
|
221
|
-
view: options.view,
|
|
222
247
|
extension: (pi) => options.extension(pi, core.attach(pi)),
|
|
223
248
|
get canOpen() {
|
|
224
249
|
return driver !== undefined;
|
|
225
250
|
},
|
|
226
|
-
get terminal() {
|
|
227
|
-
return driver?.terminal === true;
|
|
228
|
-
},
|
|
229
|
-
welcomeVisible: (id) => !core.terminal || (!welcomeDismissed && welcomeChat === id),
|
|
230
|
-
dismissWelcome() {
|
|
231
|
-
if (!core.terminal || welcomeDismissed)
|
|
232
|
-
return;
|
|
233
|
-
welcomeDismissed = true;
|
|
234
|
-
changed();
|
|
235
|
-
},
|
|
236
251
|
chats: () => chats.map((chat) => ({ id: chat.id, title: titleFor(chat), status: statusOf(chat), shown: chat.id === shownId, ...(chat.role !== undefined ? { role: chat.role } : {}) })),
|
|
237
252
|
session: (id) => chats.find((chat) => chat.id === id)?.session,
|
|
238
253
|
decline(id) {
|
|
@@ -244,6 +259,17 @@ export function createChats(options) {
|
|
|
244
259
|
decline();
|
|
245
260
|
return asking.length > 0 ? "declined" : "none";
|
|
246
261
|
},
|
|
262
|
+
async onHarnessModel() {
|
|
263
|
+
for (const chat of [...chats]) {
|
|
264
|
+
try {
|
|
265
|
+
await chat.instance?.onHarnessModel?.();
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
/* a chat let go as it was put on it */
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
outOfReach: (id) => chats.find((chat) => chat.id === id)?.instance?.outOfReach?.(),
|
|
247
273
|
shown: () => shownId,
|
|
248
274
|
shownChat: () => chats.find((chat) => chat.id === shownId),
|
|
249
275
|
chatOfSession: (session) => chats.find((chat) => chat.session === session),
|
|
@@ -312,7 +338,6 @@ export function createChats(options) {
|
|
|
312
338
|
if (asking?.chat === id)
|
|
313
339
|
askAgain();
|
|
314
340
|
chat.unsubscribe?.();
|
|
315
|
-
chat.ui?.close();
|
|
316
341
|
inChat(chat.scope, () => record({ kind: "chat.closed" }, { project: cwd }));
|
|
317
342
|
try {
|
|
318
343
|
await driver?.dispose(chat);
|
|
@@ -340,8 +365,9 @@ export function createChats(options) {
|
|
|
340
365
|
showing(chat) {
|
|
341
366
|
shownId = chat.id;
|
|
342
367
|
chat.unread = false;
|
|
368
|
+
// What was said while no chat could show it: shown now - every front end heard it as it was said.
|
|
343
369
|
for (const [message, level] of notices.splice(0))
|
|
344
|
-
|
|
370
|
+
say(message, level);
|
|
345
371
|
changed();
|
|
346
372
|
},
|
|
347
373
|
onChats(listener) {
|
|
@@ -349,25 +375,17 @@ export function createChats(options) {
|
|
|
349
375
|
return () => listeners.delete(listener);
|
|
350
376
|
},
|
|
351
377
|
changed,
|
|
352
|
-
notify(message, level) {
|
|
378
|
+
notify(message, level, options = {}) {
|
|
353
379
|
const chat = core.shownChat();
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
try {
|
|
360
|
-
ui.notify(message, level);
|
|
361
|
-
}
|
|
362
|
-
catch {
|
|
363
|
-
/* a chat let go says nothing */
|
|
364
|
-
}
|
|
380
|
+
// Heard by every front end as it is said, and said in the chat shown as pi says what an extension says.
|
|
381
|
+
if (options.notification !== false)
|
|
382
|
+
emitSessionEvent(host, { type: "notification", ...(chat !== undefined ? { chat: chat.id } : {}), text: message, level });
|
|
383
|
+
say(message, level);
|
|
365
384
|
},
|
|
366
385
|
async dispose(asked = {}) {
|
|
367
386
|
options.onDispose?.();
|
|
368
387
|
for (const chat of chats.splice(0)) {
|
|
369
388
|
chat.unsubscribe?.();
|
|
370
|
-
chat.ui?.close();
|
|
371
389
|
try {
|
|
372
390
|
if (chat.session !== asked.except)
|
|
373
391
|
await driver?.dispose(chat);
|
|
@@ -397,13 +415,12 @@ export function createChats(options) {
|
|
|
397
415
|
},
|
|
398
416
|
};
|
|
399
417
|
},
|
|
400
|
-
adopt(session
|
|
418
|
+
adopt(session) {
|
|
401
419
|
const chat = core.chatOfSession(session) ?? core.shownChat() ?? chats.find((candidate) => candidate.session === undefined) ?? newChat();
|
|
402
420
|
if (chat.session !== session) {
|
|
403
421
|
if (chat.session)
|
|
404
422
|
spending.closed(chat.session);
|
|
405
423
|
chat.session = session;
|
|
406
|
-
chat.services = services;
|
|
407
424
|
follow(chat);
|
|
408
425
|
if (shownId === undefined)
|
|
409
426
|
inChat(chat.scope, () => record({ kind: "chat.opened", reopened: session.messages.length > 0 }, { project: cwd }));
|
|
@@ -412,12 +429,6 @@ export function createChats(options) {
|
|
|
412
429
|
},
|
|
413
430
|
sentinelOn: () => driver !== undefined && wantsSentinel(),
|
|
414
431
|
jobFinished(job) {
|
|
415
|
-
if (core.terminal) {
|
|
416
|
-
const didNotPass = job.status === "succeeded" && wentWrong(job);
|
|
417
|
-
const result = job.status === "succeeded" ? didNotPass ? "did not pass" : "finished" : job.status;
|
|
418
|
-
core.notifications.add(`${pulseName(job)} · ${result} after ${formatDuration(job)}`, job.error ?? job.report ?? job.note ?? "", { warning: job.status === "failed" || didNotPass });
|
|
419
|
-
changed();
|
|
420
|
-
}
|
|
421
432
|
// The question was settled in config.turri.yaml while it was open: what it held goes as the file now says.
|
|
422
433
|
if (consent === "asking" && setting() !== "ask")
|
|
423
434
|
settleStart(setting() === true ? "given" : "declined", "superseded");
|
|
@@ -500,15 +511,12 @@ export function createChats(options) {
|
|
|
500
511
|
}
|
|
501
512
|
// Only the sentinel's own may be ignored: never the question whether to start it.
|
|
502
513
|
const { ignorable, ...rest } = input;
|
|
503
|
-
|
|
514
|
+
// notify_person may leave out what it is about: the sentinel checks one pulse, or one check, at a time - the notice says which.
|
|
515
|
+
const work = checking?.work;
|
|
516
|
+
const checkingNow = input.job === undefined && input.check === undefined && work !== undefined && currentChat()?.id === sentinelChat()?.id ? ("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }) : {};
|
|
517
|
+
const notice = newNotice({ ...(ignorable === true && input.kind === undefined ? input : rest), ...checkingNow }, target.id);
|
|
504
518
|
open.push(notice);
|
|
505
|
-
if (
|
|
506
|
-
// notify_person may omit the id; the sentinel still has exactly one review in progress.
|
|
507
|
-
const work = checking?.work;
|
|
508
|
-
const about = work && currentChat()?.id === sentinelChat()?.id ? ("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }) : undefined;
|
|
509
|
-
core.notifications.put(notice, about);
|
|
510
|
-
}
|
|
511
|
-
else if (target.id !== shownId)
|
|
519
|
+
if (target.id !== shownId)
|
|
512
520
|
target.unread = true;
|
|
513
521
|
inChat(target.scope, () => record({ kind: "notice.put", notice: notice.id, severity: notice.severity, ...(notice.module !== undefined ? { module: notice.module } : {}) }, { project: cwd }));
|
|
514
522
|
try {
|
|
@@ -539,10 +547,18 @@ export function createChats(options) {
|
|
|
539
547
|
return undefined;
|
|
540
548
|
const module = conclusion.module ?? job?.module ?? check?.module;
|
|
541
549
|
const pulse = conclusion.pulse ?? job?.pulse;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
550
|
+
// How the person tries it themselves, as the launch the sentinel tested in said it: they hear it whoever tested it.
|
|
551
|
+
let tryIt;
|
|
552
|
+
if (conclusion.verdict !== "unchecked" && conclusion.tryIt === undefined) {
|
|
553
|
+
try {
|
|
554
|
+
tryIt = job !== undefined ? options.launches?.tryIt?.({ job }) : check !== undefined ? options.launches?.tryIt?.({ check }) : undefined;
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
/* what runs no longer holds it: nothing to say of it */
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const told = { ...conclusion, ...(module !== undefined ? { module } : {}), ...(pulse !== undefined ? { pulse } : {}), ...(tryIt !== undefined ? { tryIt } : {}) };
|
|
561
|
+
if (target.id !== shownId)
|
|
546
562
|
target.unread = true;
|
|
547
563
|
inChat(target.scope, () => record({ kind: "sentinel.concluded", verdict: told.verdict, ...(module !== undefined ? { module } : {}), ...(told.check !== undefined ? { check: told.check } : {}) }, { project: cwd, ...(told.job !== undefined ? { job: told.job } : {}) }));
|
|
548
564
|
try {
|
|
@@ -596,16 +612,15 @@ export function createChats(options) {
|
|
|
596
612
|
setDriver(given) {
|
|
597
613
|
driver = given;
|
|
598
614
|
},
|
|
599
|
-
async restore(saved
|
|
615
|
+
async restore(saved) {
|
|
600
616
|
adoptRun(cwd, saved.run);
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
for (const kept of asked.skipFirst === true ? saved.chats.filter((other) => other !== first) : saved.chats) {
|
|
617
|
+
for (const kept of saved.chats) {
|
|
618
|
+
// Open already - reopened by the front end itself, say pi from its own --session: it keeps its recorded title.
|
|
619
|
+
const already = chats.find((chat) => chat.session?.sessionFile === kept.sessionFile);
|
|
620
|
+
if (already !== undefined) {
|
|
621
|
+
already.recordedTitle ??= kept.title;
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
609
624
|
try {
|
|
610
625
|
await core.open({ sessionFile: kept.sessionFile, hidden: true, title: kept.title, ...(kept.role !== undefined ? { role: kept.role } : {}) });
|
|
611
626
|
}
|
|
@@ -634,8 +649,7 @@ export function createChats(options) {
|
|
|
634
649
|
}
|
|
635
650
|
if (chat !== undefined)
|
|
636
651
|
inChat(chat.scope, () => record({ kind: "notice.over", notice: notice.id, state }, { project: cwd }));
|
|
637
|
-
|
|
638
|
-
changed();
|
|
652
|
+
changed();
|
|
639
653
|
}
|
|
640
654
|
/** A pulse ended, told to the chat that asked for it - as without a sentinel - or the chat shown, when that one is closed. */
|
|
641
655
|
function toAsker(job) {
|
|
@@ -737,7 +751,7 @@ export function createChats(options) {
|
|
|
737
751
|
const asked = chats.find((chat) => chat.id === job.chat && chat.role !== SENTINEL);
|
|
738
752
|
const where = personFacing(asked);
|
|
739
753
|
if (where !== undefined) {
|
|
740
|
-
if (where.id !== shownId
|
|
754
|
+
if (where.id !== shownId)
|
|
741
755
|
where.unread = true;
|
|
742
756
|
try {
|
|
743
757
|
where.instance?.landed(job, { tell: !wentWrong(job) });
|
|
@@ -784,10 +798,7 @@ export function createChats(options) {
|
|
|
784
798
|
core.concluded({ check: check.id, module: check.module, verdict: "unchecked", summary: `Not checked: ${why}.` });
|
|
785
799
|
}
|
|
786
800
|
function sentinelMessage(message, level) {
|
|
787
|
-
|
|
788
|
-
return core.notify(message, level);
|
|
789
|
-
core.notifications.add(message, "");
|
|
790
|
-
changed();
|
|
801
|
+
core.notify(message, level);
|
|
791
802
|
}
|
|
792
803
|
/** The sentinel's work, after what it was given before. */
|
|
793
804
|
function toSentinel(work) {
|
|
@@ -827,7 +838,7 @@ export function createChats(options) {
|
|
|
827
838
|
async function refuse(sentinel, work, why) {
|
|
828
839
|
const module = codebaseOf(work);
|
|
829
840
|
inChat(sentinel.scope, () => record({ kind: "sentinel.refused", ...(module !== undefined ? { module } : {}), ...("check" in work ? { check: work.check.id } : {}), why: firstLine(why, 300) }, { project: cwd, ...("pulse" in work ? { job: work.pulse.id } : {}) }));
|
|
830
|
-
if ("pulse" in work
|
|
841
|
+
if ("pulse" in work)
|
|
831
842
|
core.notify(`The sentinel cannot check pulse ${work.pulse.id}: ${why}`, "error");
|
|
832
843
|
core.concluded({
|
|
833
844
|
...("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }),
|
|
@@ -943,7 +954,7 @@ export function createChats(options) {
|
|
|
943
954
|
* the one it had.
|
|
944
955
|
*/
|
|
945
956
|
async function freshConversation(chat) {
|
|
946
|
-
const old = { session: chat.session,
|
|
957
|
+
const old = { session: chat.session, instance: chat.instance };
|
|
947
958
|
chat.unsubscribe?.();
|
|
948
959
|
chat.unsubscribe = undefined;
|
|
949
960
|
try {
|
|
@@ -1029,8 +1040,3 @@ export function scopedToChat(pi, scope) {
|
|
|
1029
1040
|
},
|
|
1030
1041
|
});
|
|
1031
1042
|
}
|
|
1032
|
-
/** A chat's stand-in for the screen, for the terminal's driver. */
|
|
1033
|
-
export function terminalUi(chat, screen, onChange) {
|
|
1034
|
-
chat.ui ??= createChatUi({ screen, onChange });
|
|
1035
|
-
return chat.ui;
|
|
1036
|
-
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who runs turri: the front end's own name and version - turri's CLI, a desktop app, an editor's extension - as it says
|
|
3
|
+
* it when it opens a session. The banner shows it, and the ledger and a run's report record it. Without one, it is the
|
|
4
|
+
* core itself.
|
|
5
|
+
*/
|
|
6
|
+
export interface ClientInfo {
|
|
7
|
+
/** The front end's name: `turri`, `turri desktop`. */
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
/** The commit it runs from, when it runs from a clone - and whether the clone has changes on it. */
|
|
11
|
+
commit?: string;
|
|
12
|
+
changed?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* How it runs turri this time, in its own word - the ledger's `run.started` records it as the run's `mode`: `chat`
|
|
15
|
+
* for a conversation in a terminal, `regenerate` for a command run unattended, `host` for a desktop app. Without one,
|
|
16
|
+
* `frontend` - or `unattended`, with no front end.
|
|
17
|
+
*/
|
|
18
|
+
mode?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What is recorded of who ran turri. */
|
|
21
|
+
export interface Identity {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string | null;
|
|
24
|
+
git_commit: string | null;
|
|
25
|
+
git_dirty: boolean | null;
|
|
26
|
+
}
|
|
27
|
+
/** The session's front end, said as it opens - undefined as it closes. */
|
|
28
|
+
export declare function setClient(info: ClientInfo | undefined): void;
|
|
29
|
+
/** Who runs turri now: the session's front end, else the core. */
|
|
30
|
+
export declare function clientIdentity(): Identity;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { coreIdentity } from "./environment.js";
|
|
2
|
+
let client;
|
|
3
|
+
/** The session's front end, said as it opens - undefined as it closes. */
|
|
4
|
+
export function setClient(info) {
|
|
5
|
+
client = info;
|
|
6
|
+
}
|
|
7
|
+
/** Who runs turri now: the session's front end, else the core. */
|
|
8
|
+
export function clientIdentity() {
|
|
9
|
+
if (client !== undefined)
|
|
10
|
+
return { name: client.name, version: client.version, git_commit: client.commit ?? null, git_dirty: client.changed ?? null };
|
|
11
|
+
return { name: "@turri-dev/core", ...coreIdentity() };
|
|
12
|
+
}
|