@skillcdn/console 0.6.1 → 0.6.3
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 +14 -7
- package/SKILLCDN.md +3 -2
- package/dist/agent-page.d.ts +2 -0
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +77 -30
- package/dist/agent-page.js.map +1 -1
- package/dist/agent-state.d.ts +9 -0
- package/dist/agent-state.d.ts.map +1 -0
- package/dist/agent-state.js +28 -0
- package/dist/agent-state.js.map +1 -0
- package/dist/agent-usage.d.ts +9 -6
- package/dist/agent-usage.d.ts.map +1 -1
- package/dist/agent-usage.js +38 -8
- package/dist/agent-usage.js.map +1 -1
- package/dist/api.d.ts +4 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +4 -3
- package/dist/api.js.map +1 -1
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +369 -130
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/format.d.ts +13 -4
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +43 -9
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +82 -9
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +780 -318
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/pack.d.ts +2 -2
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +6 -4
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/runner-files.d.ts +16 -0
- package/dist/cli/runner-files.d.ts.map +1 -0
- package/dist/cli/runner-files.js +110 -0
- package/dist/cli/runner-files.js.map +1 -0
- package/dist/cli/runner-host.d.ts +7 -0
- package/dist/cli/runner-host.d.ts.map +1 -1
- package/dist/cli/runner-host.js +40 -2
- package/dist/cli/runner-host.js.map +1 -1
- package/dist/client.d.ts +22 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -1
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +61 -11
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +146 -35
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/agents.d.ts +3 -2
- package/dist/components/agents.d.ts.map +1 -1
- package/dist/components/agents.js +9 -3
- package/dist/components/agents.js.map +1 -1
- package/dist/components/calendar.d.ts +24 -4
- package/dist/components/calendar.d.ts.map +1 -1
- package/dist/components/calendar.js +78 -35
- package/dist/components/calendar.js.map +1 -1
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +40 -12
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +2 -0
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +4 -0
- package/dist/data.js.map +1 -1
- package/dist/desk-page.js +5 -5
- package/dist/desk-page.js.map +1 -1
- package/dist/feed-words.d.ts.map +1 -1
- package/dist/feed-words.js +18 -1
- package/dist/feed-words.js.map +1 -1
- package/dist/i18n/en.d.ts +51 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +44 -2
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +52 -17
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +10 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +10 -0
- package/dist/limits.js.map +1 -1
- package/dist/plugin/capabilities.d.ts +1 -1
- package/dist/plugin/capabilities.d.ts.map +1 -1
- package/dist/plugin/capabilities.js +6 -1
- package/dist/plugin/capabilities.js.map +1 -1
- package/dist/plugin/context.d.ts +101 -8
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +7 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +7 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/testing.d.ts +2 -0
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +2 -0
- package/dist/plugin/testing.js.map +1 -1
- package/dist/rules.js +1 -1
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts.map +1 -1
- package/dist/runner/acp.js +9 -3
- package/dist/runner/acp.js.map +1 -1
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +143 -10
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +14 -2
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/config.d.ts +18 -0
- package/dist/runner/config.d.ts.map +1 -1
- package/dist/runner/config.js +77 -1
- package/dist/runner/config.js.map +1 -1
- package/dist/runner/desk.d.ts +7 -0
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +20 -4
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/message.d.ts +26 -2
- package/dist/runner/message.d.ts.map +1 -1
- package/dist/runner/message.js +120 -32
- package/dist/runner/message.js.map +1 -1
- package/dist/runner/runner.d.ts +40 -2
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +533 -32
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/slack-status.d.ts +19 -0
- package/dist/runner/slack-status.d.ts.map +1 -0
- package/dist/runner/slack-status.js +332 -0
- package/dist/runner/slack-status.js.map +1 -0
- package/dist/runner/slack.d.ts +17 -11
- package/dist/runner/slack.d.ts.map +1 -1
- package/dist/runner/slack.js +1199 -109
- package/dist/runner/slack.js.map +1 -1
- package/dist/runner/types.d.ts +205 -6
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js.map +1 -1
- package/dist/runner/usage.d.ts +6 -1
- package/dist/runner/usage.d.ts.map +1 -1
- package/dist/runner/usage.js +9 -2
- package/dist/runner/usage.js.map +1 -1
- package/dist/runner.d.ts +4 -4
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +3 -3
- package/dist/runner.js.map +1 -1
- package/dist/schemas.d.ts +263 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +137 -5
- package/dist/schemas.js.map +1 -1
- package/dist/vocabulary.d.ts +7 -0
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +6 -0
- package/dist/vocabulary.js.map +1 -1
- package/dist/wake-text.d.ts +43 -0
- package/dist/wake-text.d.ts.map +1 -0
- package/dist/wake-text.js +115 -0
- package/dist/wake-text.js.map +1 -0
- package/docs/specs/cli.md +21 -12
- package/docs/specs/plugins.md +12 -7
- package/docs/specs/rest.md +14 -5
- package/docs/specs/runner.md +133 -26
- package/docs/start.md +26 -5
- package/package.json +3 -3
- package/skills/building-a-plugin/SKILL.md +3 -3
- package/skills/deploying-a-console/SKILL.md +3 -3
- package/skills/deploying-a-console/references/access.md +15 -1
- package/skills/deploying-a-console/references/resources.md +2 -2
- package/skills/deploying-a-console/scripts/github-app.mjs +593 -0
- package/skills/planning-the-board/references/setting-up.md +1 -1
- package/skills/running-an-agent/SKILL.md +18 -72
- package/skills/running-an-agent/references/preparing-the-machine.md +17 -0
- package/skills/running-an-agent/references/several-tasks.md +1 -1
- package/skills/running-an-agent/references/slack-app.md +55 -8
- package/skills/running-an-agent/references/the-account-and-the-invitation.md +5 -0
- package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -0
- package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +16 -0
- package/skills/running-an-agent/references/your-first-task.md +19 -0
- package/skills/trying-a-console/SKILL.md +136 -0
- package/skills/trying-a-console/references/when-it-does-not-go.md +30 -0
- package/skills/working-the-board/SKILL.md +11 -15
- package/skills/working-the-board/references/a-pack-skills-questions.md +3 -0
- package/skills/working-the-board/references/a-plugins-commands.md +3 -0
- package/skills/working-the-board/references/a-review.md +3 -0
- package/skills/working-the-board/references/an-open-run.md +3 -0
- package/skills/working-the-board/references/requirements.md +7 -0
- package/skills/working-the-board/references/the-pack.md +3 -3
- package/skills/working-the-board/references/what-they-were-told.md +3 -0
- package/skills/working-the-board/references/work-given-in-chat.md +5 -0
- package/src/agent-page.tsx +133 -41
- package/src/agent-state.ts +33 -0
- package/src/agent-usage.ts +55 -12
- package/src/api.ts +23 -0
- package/src/cli/cli.ts +443 -137
- package/src/cli/format.ts +49 -9
- package/src/cli/help.ts +904 -359
- package/src/cli/pack.ts +6 -4
- package/src/cli/runner-files.ts +120 -0
- package/src/cli/runner-host.ts +48 -2
- package/src/client.ts +64 -0
- package/src/components/agent-page.tsx +264 -39
- package/src/components/agents.tsx +20 -5
- package/src/components/calendar.tsx +92 -36
- package/src/console.tsx +47 -10
- package/src/data.ts +6 -0
- package/src/desk-page.tsx +5 -5
- package/src/feed-words.ts +20 -1
- package/src/i18n/en.ts +50 -2
- package/src/i18n/ko.ts +62 -17
- package/src/index.ts +2 -0
- package/src/limits.ts +10 -0
- package/src/plugin/capabilities.ts +8 -1
- package/src/plugin/context.ts +103 -7
- package/src/plugin/limits.ts +7 -0
- package/src/plugin/testing.ts +4 -0
- package/src/rules.ts +1 -1
- package/src/runner/acp.ts +9 -3
- package/src/runner/claude.ts +159 -10
- package/src/runner/codex.ts +14 -2
- package/src/runner/config.ts +114 -1
- package/src/runner/desk.ts +23 -4
- package/src/runner/message.ts +144 -35
- package/src/runner/runner.ts +658 -35
- package/src/runner/slack-status.ts +423 -0
- package/src/runner/slack.ts +1509 -128
- package/src/runner/types.ts +200 -5
- package/src/runner/usage.ts +16 -3
- package/src/runner.ts +20 -1
- package/src/schemas.ts +161 -3
- package/src/vocabulary.ts +9 -0
- package/src/wake-text.ts +133 -0
package/dist/runner/runner.js
CHANGED
|
@@ -2,7 +2,8 @@ import { ApiError } from "../client.js";
|
|
|
2
2
|
import { MAX_RUNNER_LINE_LENGTH, MAX_RUNNER_OFFERS, MAX_TRANSCRIPT_ATTACHMENTS, MAX_TRANSCRIPT_BATCH, MAX_TRANSCRIPT_BATCH_BYTES, MAX_TRANSCRIPT_FACT_LENGTH, MAX_TRANSCRIPT_FACT_NAME_LENGTH, MAX_TRANSCRIPT_FACTS, MAX_TRANSCRIPT_TEXT_BYTES, } from "../limits.js";
|
|
3
3
|
import { RUNNER_CHOICE } from "../schemas.js";
|
|
4
4
|
import { hasForbiddenCodePoint } from "../text.js";
|
|
5
|
-
import {
|
|
5
|
+
import { STATUS_AFTER } from "./config.js";
|
|
6
|
+
import { composeSignals, deskName, GROUP_WINDOW_MS, introOf, makeMark, sleptOf, wakeTextOf, } from "./message.js";
|
|
6
7
|
import { cutShown, cutShownEnd, redactorOf } from "./redact.js";
|
|
7
8
|
import { limitWords, noteUsage, RESET_MARGIN_MS, runnerSays, usageSaid, usageToTell, usageWords, } from "./usage.js";
|
|
8
9
|
// The runner (ADR-0085, docs/specs/runner.md): one process per agent account on its machine. It
|
|
@@ -18,6 +19,14 @@ import { limitWords, noteUsage, RESET_MARGIN_MS, runnerSays, usageSaid, usageToT
|
|
|
18
19
|
// a signal received, a word of the driver's, a timer that fired. What the product prints is
|
|
19
20
|
// numbered and kept for the next batch as it arrives, so that nothing of a session is left
|
|
20
21
|
// behind when the session ends.
|
|
22
|
+
/** How long a wake a source raised is waited for on the stream before the source is shown nothing of it. */
|
|
23
|
+
const RAISED_MS = 60_000;
|
|
24
|
+
/** From how far away a moment is said with its day in a status. */
|
|
25
|
+
const FAR_MS = 20 * 60 * 60_000;
|
|
26
|
+
/** How long the runner's end waits for the wake sources to take back what they showed. */
|
|
27
|
+
const SHOWN_END_MS = 3000;
|
|
28
|
+
/** What the wake sources are said as the runner ends. */
|
|
29
|
+
const LAST_STATUS = { state: "idle", last: true };
|
|
21
30
|
/** How often the runner says it is there. */
|
|
22
31
|
export const HEARTBEAT_MS = 30_000;
|
|
23
32
|
/** How often what the product did is sent, while there is something to send. */
|
|
@@ -25,6 +34,18 @@ export const BATCH_MS = 1000;
|
|
|
25
34
|
/** How long what arrives by itself waits after the agent could not go on: at first, and at most, twice as long after each try that ends the same way. */
|
|
26
35
|
export const COOL_DOWN_MS = 15 * 60_000;
|
|
27
36
|
export const MAX_COOL_DOWN_MS = 4 * 60 * 60_000;
|
|
37
|
+
/**
|
|
38
|
+
* How long the runner holds an ending that waits for the agent's turn, a model chosen, the
|
|
39
|
+
* account's own reset, an update or a `runner.json` that changed, for the sub-agents at work
|
|
40
|
+
* in the background of the session (ADR-0162): counted from when it first held one for them.
|
|
41
|
+
*/
|
|
42
|
+
export const SUBAGENTS_MS = 60 * 60_000;
|
|
43
|
+
/**
|
|
44
|
+
* How long a session that had sub-agents in the background is not taken for idle after one
|
|
45
|
+
* ended or a turn did: the product hands the agent a sub-agent's report in a turn it starts
|
|
46
|
+
* itself, a moment after.
|
|
47
|
+
*/
|
|
48
|
+
export const REPORT_MS = 10_000;
|
|
28
49
|
/** How long the runner waits before it asks for its stream of signals again. */
|
|
29
50
|
export const RECONNECT_MS = 5000;
|
|
30
51
|
/** What an autosave's commit says: the runner's, and never the agent's own words. */
|
|
@@ -48,6 +69,12 @@ const SOURCE_HELD_MS = 60_000;
|
|
|
48
69
|
const SLEPT_MS = 60_000;
|
|
49
70
|
/** The kinds of event that are the agent's own answer: what it said, thought or called. */
|
|
50
71
|
const ANSWERS = new Set(["assistant", "thinking", "tool_call"]);
|
|
72
|
+
/**
|
|
73
|
+
* How long before its wake is on the record a message may have been written (ADR-0166): what a
|
|
74
|
+
* wake source reads for a wake, and the wakes ahead of it, are waited for half a minute at the
|
|
75
|
+
* most, and the messenger's clock and the console's differ by less than the rest.
|
|
76
|
+
*/
|
|
77
|
+
const RAISED_AFTER_MS = 60_000;
|
|
51
78
|
/** How many signals the runner writes down as kept for the agent beside what the record sends again. */
|
|
52
79
|
const MAX_KEPT = 50;
|
|
53
80
|
/** How long before its moment a timer may ring: a delivery asked for at a moment is taken within it. */
|
|
@@ -82,6 +109,11 @@ const FILE_ID_BYTES = 48;
|
|
|
82
109
|
const LEAST_CUT_BYTES = 1024;
|
|
83
110
|
/** The name of the secret an account keeps its git host's token under (ADR-0088): what the autosave's push is handed. */
|
|
84
111
|
export const GIT_TOKEN_SECRET = "git.token";
|
|
112
|
+
/** What an ending is for, as the record says it of one that waits for sub-agents (ADR-0162). */
|
|
113
|
+
const FOR_UPDATE = "for an update of the command the runner runs from";
|
|
114
|
+
const FOR_CHANGE = "for the desk's runner.json, which changed";
|
|
115
|
+
const FOR_CHOICE = "for the model or the effort chosen";
|
|
116
|
+
const FOR_RESET = "for the account's own reset";
|
|
85
117
|
/** What an event takes of a batch as the console counts one: its JSON, and the ids of its pictures. */
|
|
86
118
|
const sentBytes = (event) => Buffer.byteLength(JSON.stringify({
|
|
87
119
|
n: event.n,
|
|
@@ -147,6 +179,19 @@ const lineOf = (value) => {
|
|
|
147
179
|
const line = (value ?? "").trim().slice(0, MAX_RUNNER_LINE_LENGTH).trim();
|
|
148
180
|
return line.length === 0 || hasForbiddenCodePoint(line) ? null : line;
|
|
149
181
|
};
|
|
182
|
+
/** What a wake source keeps, which says whether it changed since it was last written down. */
|
|
183
|
+
class Kept extends Map {
|
|
184
|
+
changed = false;
|
|
185
|
+
set(name, value) {
|
|
186
|
+
this.changed = true;
|
|
187
|
+
return super.set(name, value);
|
|
188
|
+
}
|
|
189
|
+
delete(name) {
|
|
190
|
+
const had = super.delete(name);
|
|
191
|
+
this.changed ||= had;
|
|
192
|
+
return had;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
150
195
|
export function createRunner(options) {
|
|
151
196
|
const { client, driver, config, log } = options;
|
|
152
197
|
const timing = {
|
|
@@ -159,6 +204,8 @@ export function createRunner(options) {
|
|
|
159
204
|
holdMs: HOLD_MS,
|
|
160
205
|
maxHoldMs: MAX_HOLD_MS,
|
|
161
206
|
resetMarginMs: RESET_MARGIN_MS,
|
|
207
|
+
subagentsMs: SUBAGENTS_MS,
|
|
208
|
+
reportMs: REPORT_MS,
|
|
162
209
|
...options.timing,
|
|
163
210
|
};
|
|
164
211
|
/** How long what an hour's bound refused is held back: the first time, and twice as long each time after. */
|
|
@@ -219,9 +266,34 @@ export function createRunner(options) {
|
|
|
219
266
|
let received = 0;
|
|
220
267
|
let handled = 0;
|
|
221
268
|
let conversation;
|
|
269
|
+
/**
|
|
270
|
+
* When the conversation the agent goes on with began (ADR-0166), 0 where nothing says, and
|
|
271
|
+
* whether that moment is of a conversation no session has begun yet: the session that begins
|
|
272
|
+
* it then leaves the moment as it stands.
|
|
273
|
+
*/
|
|
274
|
+
let began = 0;
|
|
275
|
+
let renewed = false;
|
|
276
|
+
/**
|
|
277
|
+
* The signals the conversation holds already, by number (ADR-0166): the product of the open
|
|
278
|
+
* session took them there as a usage limit was reached, its driver vouching that what it
|
|
279
|
+
* took stands (`can.holdsTaken`), and the agent never answered. Handed over again in that
|
|
280
|
+
* session, they are named and not said a second time. Until a turn completes, the
|
|
281
|
+
* conversation is let go or put in fewer words, or the session ends: nothing says before a
|
|
282
|
+
* session's first message whether its product went on with the conversation, so a session
|
|
283
|
+
* begun after is said them whole.
|
|
284
|
+
*/
|
|
285
|
+
const above = new Set();
|
|
286
|
+
/** What each wake source keeps, by its name, and whether it changed since it was last written. */
|
|
287
|
+
const keeps = new Map();
|
|
288
|
+
/**
|
|
289
|
+
* How the agent stands and why, with when the runner said so (`at`): the console is told that
|
|
290
|
+
* moment with the reason, since a reason is said again the same under a state that stays, a
|
|
291
|
+
* turn that completed after another say, and nothing else tells the two apart.
|
|
292
|
+
*/
|
|
222
293
|
let stands = {
|
|
223
294
|
state: "running",
|
|
224
295
|
reason: "started",
|
|
296
|
+
at: options.now(),
|
|
225
297
|
};
|
|
226
298
|
let said = "";
|
|
227
299
|
let settings = { model: null, effort: null };
|
|
@@ -297,6 +369,25 @@ export function createRunner(options) {
|
|
|
297
369
|
let slept;
|
|
298
370
|
/** How each wake source stands, by its name: what the heartbeat says of them. */
|
|
299
371
|
const sources = new Map();
|
|
372
|
+
/**
|
|
373
|
+
* The wake sources that show how the agent stands (ADR-0170), by name: the host each runs
|
|
374
|
+
* with, and what it was last said and when.
|
|
375
|
+
*/
|
|
376
|
+
const shows = new Map();
|
|
377
|
+
/**
|
|
378
|
+
* What `runner.json` says of how the agent stands is shown: `false` for not at all, and the
|
|
379
|
+
* sources' own way where it says nothing, a desk of before and a config put together by hand
|
|
380
|
+
* among them.
|
|
381
|
+
*/
|
|
382
|
+
const shownAs = config.status ?? {};
|
|
383
|
+
/** Since when the agent is at work without a pause: a turn under way, or something that goes on in its session with none. */
|
|
384
|
+
let atWorkSince;
|
|
385
|
+
/**
|
|
386
|
+
* What each wake source raised that the stream has not brought back yet: when it was raised,
|
|
387
|
+
* and its number once the console took it. A message that reached the runner is on its way
|
|
388
|
+
* to the agent from then on, which its source shows.
|
|
389
|
+
*/
|
|
390
|
+
const raising = new Map();
|
|
300
391
|
/**
|
|
301
392
|
* The signals a product was handed and never took, since it did not start or was not signed
|
|
302
393
|
* in, which are kept to be sent again; and, of those, the ones a reset gave one more try: a
|
|
@@ -332,14 +423,103 @@ export function createRunner(options) {
|
|
|
332
423
|
? {}
|
|
333
424
|
: { limited: { since: limited.since, until: limited.until } }),
|
|
334
425
|
...(kept.length === 0 ? {} : { kept }),
|
|
426
|
+
...(began === 0 ? {} : { began }),
|
|
335
427
|
});
|
|
336
428
|
}
|
|
337
429
|
catch {
|
|
338
430
|
log("the runner's state could not be written; it goes on from the console's record");
|
|
339
431
|
}
|
|
340
432
|
};
|
|
433
|
+
/**
|
|
434
|
+
* When a conversation that begins now is taken to have begun (ADR-0166): now, or, where wakes
|
|
435
|
+
* of a wake source wait to be handed over, a little before the oldest of them was raised.
|
|
436
|
+
* They are handed over in the new conversation, which holds them from then on: counted as
|
|
437
|
+
* from before it, their messages would be carried once more with the next wake. `handed` is
|
|
438
|
+
* what the conversation holds beside what waits: what a session was handed in it already,
|
|
439
|
+
* where the moment is set once the session is under way.
|
|
440
|
+
*/
|
|
441
|
+
const beginsAt = (handed = []) => {
|
|
442
|
+
let at = options.now();
|
|
443
|
+
for (const signal of [...pending, ...handed]) {
|
|
444
|
+
const raised = signal.source === "messenger" ? Date.parse(signal.at) : Number.NaN;
|
|
445
|
+
if (Number.isFinite(raised)) {
|
|
446
|
+
at = Math.min(at, raised - RAISED_AFTER_MS);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return at;
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* The driver named the conversation its session runs in. Where it began one in place of the
|
|
453
|
+
* one it was asked to go on with (`anew`), the agent's conversation began with the session
|
|
454
|
+
* (ADR-0166): it holds what the session was handed, and nothing from before.
|
|
455
|
+
*/
|
|
456
|
+
const converses = (target, event) => {
|
|
457
|
+
conversation = event.id;
|
|
458
|
+
if (event.anew === true) {
|
|
459
|
+
began = beginsAt([...target.sent, ...target.handed.flatMap((message) => message.signals)]);
|
|
460
|
+
above.clear();
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* The product put the conversation in fewer words (ADR-0166): what the agent was handed
|
|
465
|
+
* before is a summary at best, so what a wake source brought before counts no more, and what
|
|
466
|
+
* the product took is not named as standing there. What it was handed and has not taken yet
|
|
467
|
+
* it reads after, whole: the conversation is taken to hold that.
|
|
468
|
+
*/
|
|
469
|
+
const summarized = (target) => {
|
|
470
|
+
began = beginsAt(target.handed.flatMap((message) => message.signals));
|
|
471
|
+
above.clear();
|
|
472
|
+
for (const signal of target.taken.flat()) {
|
|
473
|
+
target.summarized.add(signal.number);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* When the agent's conversation began, as a wake source is told it (ADR-0166): never after
|
|
478
|
+
* now. A moment ahead of the clock, kept by a runner whose machine's clock ran ahead or set
|
|
479
|
+
* back since, is none a message was written before: counted from, every wake of a place
|
|
480
|
+
* would carry again what the last one carried, for as long as the clock is behind it. It is
|
|
481
|
+
* taken as now, and kept so.
|
|
482
|
+
*/
|
|
483
|
+
const beganBy = () => {
|
|
484
|
+
const now = options.now();
|
|
485
|
+
if (began > now) {
|
|
486
|
+
began = now;
|
|
487
|
+
void persist();
|
|
488
|
+
}
|
|
489
|
+
return began;
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Lets go of the conversation kept: the next session begins a new one, which holds nothing
|
|
493
|
+
* the agent was handed before this moment (ADR-0166), but for what waits to be handed over.
|
|
494
|
+
*/
|
|
495
|
+
const letGo = () => {
|
|
496
|
+
conversation = undefined;
|
|
497
|
+
began = beginsAt();
|
|
498
|
+
renewed = true;
|
|
499
|
+
above.clear();
|
|
500
|
+
};
|
|
501
|
+
/** Writes what the wake sources keep where it changed since it was last written. */
|
|
502
|
+
const keepKept = async () => {
|
|
503
|
+
const store = options.wakes?.kept;
|
|
504
|
+
if (store === undefined) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
for (const [name, kept] of keeps) {
|
|
508
|
+
if (!kept.changed) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
kept.changed = false;
|
|
512
|
+
try {
|
|
513
|
+
await store.save(name, [...kept]);
|
|
514
|
+
}
|
|
515
|
+
catch {
|
|
516
|
+
// Kept in memory still, and written with the next change.
|
|
517
|
+
sayOnce(`kept ${name}`, `what the wake source ${name} keeps could not be written; it is kept while the runner runs`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
341
521
|
const setState = (state, reason) => {
|
|
342
|
-
stands = { state, reason };
|
|
522
|
+
stands = { state, reason, at: options.now() };
|
|
343
523
|
push({ t: "heartbeat" });
|
|
344
524
|
};
|
|
345
525
|
/** Asks for a delivery after the window that groups what arrives together, or at a moment. */
|
|
@@ -588,6 +768,43 @@ export function createRunner(options) {
|
|
|
588
768
|
flushing = false;
|
|
589
769
|
}
|
|
590
770
|
};
|
|
771
|
+
/** Whether something goes on in a session with no turn of the runner's under way: sub-agents in the background, or a turn the product started or is about to. */
|
|
772
|
+
const goesOn = (target) => target.background > 0 || target.own || options.now() < target.reportBy;
|
|
773
|
+
/**
|
|
774
|
+
* Whether an ending is held still for what goes on in the session (ADR-0162): for as long as
|
|
775
|
+
* the runner waits for it, counted from when it first held an ending so, and said on the
|
|
776
|
+
* record once where sub-agents are what it waits for, and once more where it waited in vain.
|
|
777
|
+
*/
|
|
778
|
+
const within = (target, why) => {
|
|
779
|
+
const now = options.now();
|
|
780
|
+
target.heldSince ??= now;
|
|
781
|
+
const waits = now - target.heldSince < timing.subagentsMs;
|
|
782
|
+
const word = waits ? "waits" : "over";
|
|
783
|
+
if (target.background > 0 && target.heldSaid !== word) {
|
|
784
|
+
target.heldSaid = word;
|
|
785
|
+
const many = `${target.background} ${target.background === 1 ? "sub-agent" : "sub-agents"} at work in the background`;
|
|
786
|
+
const most = `${Math.round(timing.subagentsMs / 60_000)} minutes`;
|
|
787
|
+
record(target, "status", waits
|
|
788
|
+
? `The session is to end ${why}, with ${many}: the runner waits until none is at work, ${most} at most.`
|
|
789
|
+
: `The runner waited ${most} for the sub-agents in the background, and waits no longer: the session ends ${why}, with ${many}.`);
|
|
790
|
+
log(`session ${target.id} is to end ${why}, with ${many}: the runner ${waits ? "waits for them" : "waited for long enough"}`);
|
|
791
|
+
}
|
|
792
|
+
return waits;
|
|
793
|
+
};
|
|
794
|
+
/**
|
|
795
|
+
* Whether a session is at work, for an ending that waits until it is not: a turn is under
|
|
796
|
+
* way, or sub-agents work on in the background, or the product started a turn of its own,
|
|
797
|
+
* the last two for as long as the runner waits for them. What a supervisor ends, a stop, a
|
|
798
|
+
* restart or a reset, asks nothing of it.
|
|
799
|
+
*/
|
|
800
|
+
const busy = (target, why) => target !== undefined && (target.turn || (goesOn(target) && within(target, why)));
|
|
801
|
+
/**
|
|
802
|
+
* Whether the runner is to end for an update and hands nothing more over (ADR-0101). Not
|
|
803
|
+
* while it waits for sub-agents in the background: that may take an hour, in which the agent
|
|
804
|
+
* goes on reading what it is sent.
|
|
805
|
+
*/
|
|
806
|
+
const closing = () => updatedTo !== undefined &&
|
|
807
|
+
!(session !== undefined && session.background > 0 && within(session, FOR_UPDATE));
|
|
591
808
|
/** Reads what the product does: the blocks are numbered and kept as they arrive, its own words go to the queue. */
|
|
592
809
|
const pump = async (target) => {
|
|
593
810
|
try {
|
|
@@ -604,7 +821,15 @@ export function createRunner(options) {
|
|
|
604
821
|
}
|
|
605
822
|
record(target, event.kind, event.text, event.data, event.pictures);
|
|
606
823
|
}
|
|
824
|
+
else if (event.type === "background") {
|
|
825
|
+
target.background = event.agents;
|
|
826
|
+
target.reportBy = options.now() + timing.reportMs;
|
|
827
|
+
}
|
|
828
|
+
else if (event.type === "turn_started") {
|
|
829
|
+
target.own = true;
|
|
830
|
+
}
|
|
607
831
|
else if (event.type === "cannot_go_on") {
|
|
832
|
+
target.own = false;
|
|
608
833
|
// Counted here, in the order the product wrote: the queue is behind what is read.
|
|
609
834
|
push({ t: "driver", session: target, event, unread: target.unread });
|
|
610
835
|
}
|
|
@@ -614,6 +839,11 @@ export function createRunner(options) {
|
|
|
614
839
|
}
|
|
615
840
|
else if (event.type === "turn_completed") {
|
|
616
841
|
target.unread = 0;
|
|
842
|
+
target.own = false;
|
|
843
|
+
// A report that came while the turn was under way is read in the next.
|
|
844
|
+
if (target.reportBy > 0) {
|
|
845
|
+
target.reportBy = options.now() + timing.reportMs;
|
|
846
|
+
}
|
|
617
847
|
}
|
|
618
848
|
push({ t: "driver", session: target, event });
|
|
619
849
|
}
|
|
@@ -705,7 +935,11 @@ export function createRunner(options) {
|
|
|
705
935
|
took: false,
|
|
706
936
|
taken: [],
|
|
707
937
|
unread: 0,
|
|
938
|
+
summarized: new Set(),
|
|
708
939
|
returning: false,
|
|
940
|
+
background: 0,
|
|
941
|
+
own: false,
|
|
942
|
+
reportBy: 0,
|
|
709
943
|
n: 0,
|
|
710
944
|
outbox: [],
|
|
711
945
|
waiting: 0,
|
|
@@ -717,6 +951,16 @@ export function createRunner(options) {
|
|
|
717
951
|
started.pumped = pump(started);
|
|
718
952
|
session = started;
|
|
719
953
|
renew = false;
|
|
954
|
+
if (resume === undefined) {
|
|
955
|
+
// A conversation of its own: it holds nothing the agent was handed before (ADR-0166).
|
|
956
|
+
// Where it was let go a moment ago, at a reset say, it began then, and what was kept
|
|
957
|
+
// for it since is handed over in it.
|
|
958
|
+
if (!renewed) {
|
|
959
|
+
began = beginsAt();
|
|
960
|
+
}
|
|
961
|
+
above.clear();
|
|
962
|
+
}
|
|
963
|
+
renewed = false;
|
|
720
964
|
log(`session ${started.id} began${resume === undefined ? "" : ", going on with the conversation before"}`);
|
|
721
965
|
push({ t: "heartbeat" });
|
|
722
966
|
return started;
|
|
@@ -733,6 +977,9 @@ export function createRunner(options) {
|
|
|
733
977
|
}
|
|
734
978
|
await target.pumped;
|
|
735
979
|
await hearLast(target);
|
|
980
|
+
// What was named as standing in the conversation was taken by this session's product: a
|
|
981
|
+
// session begun after is said it whole (ADR-0166).
|
|
982
|
+
above.clear();
|
|
736
983
|
// What the product was handed and never took is sent again, by the console where the
|
|
737
984
|
// runner itself ends and by the runner where the product had not started; else it is on
|
|
738
985
|
// the record as never read.
|
|
@@ -828,7 +1075,7 @@ export function createRunner(options) {
|
|
|
828
1075
|
deliverAt = undefined;
|
|
829
1076
|
// Nothing more is handed over once the runner is to end for an update: what waits is sent
|
|
830
1077
|
// again by the console, in order, to the runner started after.
|
|
831
|
-
if (held ||
|
|
1078
|
+
if (held || closing()) {
|
|
832
1079
|
return;
|
|
833
1080
|
}
|
|
834
1081
|
// An agent its usage limit stopped is brought back by the runner itself, with nothing to
|
|
@@ -861,9 +1108,14 @@ export function createRunner(options) {
|
|
|
861
1108
|
(config.conversation !== "continuous" && signal.key === "week")));
|
|
862
1109
|
// An agent that is back from a usage limit goes on in the conversation it was stopped in:
|
|
863
1110
|
// what it was doing is there, and the day after begins the next one.
|
|
864
|
-
|
|
1111
|
+
// Not with sub-agents at work in its background either (ADR-0162): the conversation they
|
|
1112
|
+
// report to goes on, as it does under a turn.
|
|
1113
|
+
if (anew &&
|
|
1114
|
+
session?.turn !== true &&
|
|
1115
|
+
(session === undefined || !goesOn(session)) &&
|
|
1116
|
+
limited === undefined) {
|
|
865
1117
|
await end("restarted");
|
|
866
|
-
|
|
1118
|
+
letGo();
|
|
867
1119
|
}
|
|
868
1120
|
const target = session ?? (await begin());
|
|
869
1121
|
if (target === undefined) {
|
|
@@ -896,6 +1148,11 @@ export function createRunner(options) {
|
|
|
896
1148
|
// what the driver says of its product.
|
|
897
1149
|
const takesPictures = target.driver.images?.() ?? driver.can.images;
|
|
898
1150
|
for (const signal of batch) {
|
|
1151
|
+
// What is only named is handed over with nothing: its files stand in the desk and its
|
|
1152
|
+
// pictures in the conversation, with the message the product took (ADR-0166).
|
|
1153
|
+
if (above.has(signal.number)) {
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
899
1156
|
const taken = new Set();
|
|
900
1157
|
for (const file of signal.attachments) {
|
|
901
1158
|
const picture = PICTURE_TYPES.has(file.contentType);
|
|
@@ -943,10 +1200,15 @@ export function createRunner(options) {
|
|
|
943
1200
|
]);
|
|
944
1201
|
}
|
|
945
1202
|
}
|
|
1203
|
+
// What the conversation holds already, the product having taken it there as the limit was
|
|
1204
|
+
// reached, is named and not said again (ADR-0166).
|
|
1205
|
+
const named = batch.filter((signal) => above.has(signal.number)).length;
|
|
946
1206
|
const composed = composeSignals(batch, {
|
|
947
1207
|
mark: target.mark,
|
|
948
1208
|
time: options.time,
|
|
949
1209
|
attached: (signal) => attached.get(signal.number) ?? [],
|
|
1210
|
+
own: options.account,
|
|
1211
|
+
above: (signal) => above.has(signal.number),
|
|
950
1212
|
});
|
|
951
1213
|
const intro = target.first ? introOf(target.mark, resetBy) : undefined;
|
|
952
1214
|
// What the runner says of its own goes ahead of the signals, under its own header: that
|
|
@@ -960,7 +1222,13 @@ export function createRunner(options) {
|
|
|
960
1222
|
intro,
|
|
961
1223
|
returned === undefined
|
|
962
1224
|
? undefined
|
|
963
|
-
: runnerSays(target.mark, limitWords(returned, {
|
|
1225
|
+
: runnerSays(target.mark, limitWords(returned, {
|
|
1226
|
+
now: options.now(),
|
|
1227
|
+
moment,
|
|
1228
|
+
follow: batch.length - named,
|
|
1229
|
+
above: named,
|
|
1230
|
+
early,
|
|
1231
|
+
})),
|
|
964
1232
|
told === undefined ? undefined : sleptOf(told, { mark: target.mark, moment }),
|
|
965
1233
|
composed.text,
|
|
966
1234
|
]
|
|
@@ -1079,7 +1347,9 @@ export function createRunner(options) {
|
|
|
1079
1347
|
* Hears what the product said as its session was ended. Its words wait in the queue behind
|
|
1080
1348
|
* whatever ended the session, and are let go there once the session is no longer the open
|
|
1081
1349
|
* one: a message it said it took then is taken, and not sent again, and the conversation it
|
|
1082
|
-
* named is the one to go on with, where that message is.
|
|
1350
|
+
* named is the one to go on with, where that message is. That it began that conversation
|
|
1351
|
+
* anew, or put it in fewer words, moves the moment the conversation began as it does in a
|
|
1352
|
+
* session that goes on (ADR-0166): the next session goes on with what was said here.
|
|
1083
1353
|
*/
|
|
1084
1354
|
const hearLast = async (target) => {
|
|
1085
1355
|
let named = false;
|
|
@@ -1089,7 +1359,11 @@ export function createRunner(options) {
|
|
|
1089
1359
|
}
|
|
1090
1360
|
const { event } = message;
|
|
1091
1361
|
if (event.type === "conversation") {
|
|
1092
|
-
|
|
1362
|
+
converses(target, event);
|
|
1363
|
+
named = true;
|
|
1364
|
+
}
|
|
1365
|
+
else if (event.type === "compacted") {
|
|
1366
|
+
summarized(target);
|
|
1093
1367
|
named = true;
|
|
1094
1368
|
}
|
|
1095
1369
|
else if (event.type === "taken") {
|
|
@@ -1280,7 +1554,7 @@ export function createRunner(options) {
|
|
|
1280
1554
|
limited = undefined;
|
|
1281
1555
|
await end(signal.kind === "reset" ? "reset" : "restarted");
|
|
1282
1556
|
if (signal.kind === "reset") {
|
|
1283
|
-
|
|
1557
|
+
letGo();
|
|
1284
1558
|
resetBy = { by, ...(signal.text.trim().length > 0 ? { number: signal.number } : {}) };
|
|
1285
1559
|
// What a product was handed and never took is tried once more, in the new
|
|
1286
1560
|
// conversation: a product that does not start with it again is not sent it a
|
|
@@ -1311,9 +1585,9 @@ export function createRunner(options) {
|
|
|
1311
1585
|
}
|
|
1312
1586
|
await account(signal);
|
|
1313
1587
|
if (session !== undefined && !(await session.driver.set(settings))) {
|
|
1314
|
-
// Taken when the product starts: the session ends when
|
|
1588
|
+
// Taken when the product starts: the session ends when it is not at work, and the next has it.
|
|
1315
1589
|
renew = true;
|
|
1316
|
-
if (!session
|
|
1590
|
+
if (!busy(session, FOR_CHOICE)) {
|
|
1317
1591
|
await end("restarted");
|
|
1318
1592
|
}
|
|
1319
1593
|
}
|
|
@@ -1332,7 +1606,7 @@ export function createRunner(options) {
|
|
|
1332
1606
|
}
|
|
1333
1607
|
// Nothing is handed over once the runner is to end for an update: the turn is
|
|
1334
1608
|
// stopped all the same, and what waits is sent again to the runner started after.
|
|
1335
|
-
if (pending.length > 0 &&
|
|
1609
|
+
if (pending.length > 0 && !closing()) {
|
|
1336
1610
|
if (stops) {
|
|
1337
1611
|
await deliver("now");
|
|
1338
1612
|
}
|
|
@@ -1347,7 +1621,7 @@ export function createRunner(options) {
|
|
|
1347
1621
|
return;
|
|
1348
1622
|
}
|
|
1349
1623
|
pending.push(signal);
|
|
1350
|
-
if (stops &&
|
|
1624
|
+
if (stops && closing() && session !== undefined) {
|
|
1351
1625
|
// Its words are not handed to a runner that is to end: the turn is stopped, the
|
|
1352
1626
|
// runner ends for the update, and the console sends them again to the one after.
|
|
1353
1627
|
await stopTurn(session);
|
|
@@ -1387,6 +1661,17 @@ export function createRunner(options) {
|
|
|
1387
1661
|
for (const signal of untaken) {
|
|
1388
1662
|
owed.delete(signal.number);
|
|
1389
1663
|
}
|
|
1664
|
+
// What the product took stands in the conversation, which the agent goes on in: handed
|
|
1665
|
+
// over again in this session, it is named and not said a second time (ADR-0166). Only
|
|
1666
|
+
// where the driver vouches that what it said was taken stands there, and not for what was
|
|
1667
|
+
// taken before the product put the conversation in fewer words.
|
|
1668
|
+
if (driver.can.holdsTaken === true) {
|
|
1669
|
+
for (const signal of unanswered) {
|
|
1670
|
+
if (!target.summarized.has(signal.number)) {
|
|
1671
|
+
above.add(signal.number);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1390
1675
|
target.taken = [];
|
|
1391
1676
|
target.sent = [];
|
|
1392
1677
|
target.returning = false;
|
|
@@ -1491,7 +1776,7 @@ export function createRunner(options) {
|
|
|
1491
1776
|
return;
|
|
1492
1777
|
}
|
|
1493
1778
|
await end("reset");
|
|
1494
|
-
|
|
1779
|
+
letGo();
|
|
1495
1780
|
// Where a supervisor reset the agent meanwhile, the first message says so: the account's
|
|
1496
1781
|
// words are read under their own header all the same.
|
|
1497
1782
|
resetBy ??= {
|
|
@@ -1520,7 +1805,7 @@ export function createRunner(options) {
|
|
|
1520
1805
|
return;
|
|
1521
1806
|
}
|
|
1522
1807
|
case "conversation": {
|
|
1523
|
-
|
|
1808
|
+
converses(target, event);
|
|
1524
1809
|
await persist();
|
|
1525
1810
|
return;
|
|
1526
1811
|
}
|
|
@@ -1540,6 +1825,8 @@ export function createRunner(options) {
|
|
|
1540
1825
|
}
|
|
1541
1826
|
target.sent = [];
|
|
1542
1827
|
target.returning = false;
|
|
1828
|
+
// The agent is done with all it was handed: nothing of it is owed a second saying.
|
|
1829
|
+
above.clear();
|
|
1543
1830
|
if (limited !== undefined) {
|
|
1544
1831
|
// A turn completed: whatever stopped the agent is over.
|
|
1545
1832
|
limited = undefined;
|
|
@@ -1549,7 +1836,7 @@ export function createRunner(options) {
|
|
|
1549
1836
|
waits = undefined;
|
|
1550
1837
|
setState("running", "completed");
|
|
1551
1838
|
}
|
|
1552
|
-
if (renew) {
|
|
1839
|
+
if (renew && !busy(target, FOR_CHOICE)) {
|
|
1553
1840
|
await end("restarted");
|
|
1554
1841
|
}
|
|
1555
1842
|
if (pending.length > 0) {
|
|
@@ -1557,6 +1844,11 @@ export function createRunner(options) {
|
|
|
1557
1844
|
}
|
|
1558
1845
|
return;
|
|
1559
1846
|
}
|
|
1847
|
+
case "compacted": {
|
|
1848
|
+
summarized(target);
|
|
1849
|
+
await persist();
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1560
1852
|
case "usage": {
|
|
1561
1853
|
noteUsage(usageSeen, event.windows, options.now());
|
|
1562
1854
|
await onUsage(target, event.windows);
|
|
@@ -1712,22 +2004,142 @@ export function createRunner(options) {
|
|
|
1712
2004
|
push({ t: "heartbeat" });
|
|
1713
2005
|
}
|
|
1714
2006
|
};
|
|
2007
|
+
/**
|
|
2008
|
+
* Whether the agent is thinking over what a wake source raised (ADR-0170): the turn a wake
|
|
2009
|
+
* of that source's was handed over in is under way, or one is on its way to the agent,
|
|
2010
|
+
* raised and not back on the stream yet or waiting to be handed over. What waits is nothing
|
|
2011
|
+
* the agent thinks over while nothing is handed over at all, a supervisor's stop standing
|
|
2012
|
+
* or the agent unable to go on.
|
|
2013
|
+
*/
|
|
2014
|
+
const thinksOf = (name, now) => {
|
|
2015
|
+
const own = (signal) => signal.kind === "wake" &&
|
|
2016
|
+
signal.source === "messenger" &&
|
|
2017
|
+
signal.key?.startsWith(`${name}:`) === true;
|
|
2018
|
+
if (session?.turn === true && session.sent.some(own)) {
|
|
2019
|
+
return true;
|
|
2020
|
+
}
|
|
2021
|
+
if (held || waits !== undefined) {
|
|
2022
|
+
return false;
|
|
2023
|
+
}
|
|
2024
|
+
const raised = raising.get(name);
|
|
2025
|
+
for (const one of raised ?? []) {
|
|
2026
|
+
// Back on the stream, and among what waits from then on; or never to come, for all the
|
|
2027
|
+
// runner waits for it.
|
|
2028
|
+
if ((one.number !== undefined && one.number <= handled) || now - one.at >= RAISED_MS) {
|
|
2029
|
+
raised?.delete(one);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return (raised?.size ?? 0) > 0 || pending.some(own);
|
|
2033
|
+
};
|
|
2034
|
+
/**
|
|
2035
|
+
* How the agent stands to whoever waits for it at a wake source (ADR-0170). Its usage limit
|
|
2036
|
+
* first, until the moment the product named where it named one: nothing is answered before
|
|
2037
|
+
* it, whatever else goes on, and past it the runner brings the agent back in a turn as any
|
|
2038
|
+
* other. Then that it has been at work for longer than `runner.json` gives a turn, whatever
|
|
2039
|
+
* woke it; then that it thinks over what this source raised.
|
|
2040
|
+
*/
|
|
2041
|
+
const statusFor = (name, now) => {
|
|
2042
|
+
if (limited !== undefined && (limited.until === undefined || now < limited.until)) {
|
|
2043
|
+
return limited.until === undefined
|
|
2044
|
+
? { state: "limited" }
|
|
2045
|
+
: { state: "limited", until: limited.until };
|
|
2046
|
+
}
|
|
2047
|
+
if (atWorkSince !== undefined &&
|
|
2048
|
+
shownAs !== false &&
|
|
2049
|
+
now - atWorkSince >= (shownAs.after ?? STATUS_AFTER) * 1000) {
|
|
2050
|
+
return { state: "working" };
|
|
2051
|
+
}
|
|
2052
|
+
return { state: thinksOf(name, now) ? "thinking" : "idle" };
|
|
2053
|
+
};
|
|
2054
|
+
/**
|
|
2055
|
+
* A moment as a status says one: the hour and the minute in the workspace's zone, and with
|
|
2056
|
+
* its day where it is most of a day away, as the command writes a moment's.
|
|
2057
|
+
*/
|
|
2058
|
+
const statusTime = (at) => {
|
|
2059
|
+
const iso = new Date(at).toISOString();
|
|
2060
|
+
const written = moment(iso);
|
|
2061
|
+
const day = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(written);
|
|
2062
|
+
return at - options.now() < FAR_MS || day === null
|
|
2063
|
+
? options.time(iso)
|
|
2064
|
+
: `${day[1]} ${day[2]}${written.endsWith("Z") ? " UTC" : ""}`;
|
|
2065
|
+
};
|
|
2066
|
+
/** Says to a wake source how the agent stands. What the source cannot show costs the agent nothing. */
|
|
2067
|
+
const say = (one, status, signal) => Promise.resolve()
|
|
2068
|
+
.then(() => one.source.show?.(one.host, status, {
|
|
2069
|
+
words: shownAs === false ? {} : shownAs,
|
|
2070
|
+
language: options.language,
|
|
2071
|
+
now: options.now,
|
|
2072
|
+
time: statusTime,
|
|
2073
|
+
signal,
|
|
2074
|
+
}))
|
|
2075
|
+
.catch((error) => {
|
|
2076
|
+
sayOnce(`status ${one.source.name}`, `the wake source ${one.source.name} could not show how the agent stands (${codeOf(error)})`);
|
|
2077
|
+
});
|
|
2078
|
+
/**
|
|
2079
|
+
* Has the wake sources show how the agent stands (ADR-0170): each is said when that changed,
|
|
2080
|
+
* and again every heartbeat while it stands, so that a source keeps what it shows from
|
|
2081
|
+
* lapsing. Nothing is said where `runner.json` turned it off.
|
|
2082
|
+
*/
|
|
2083
|
+
const showStatus = () => {
|
|
2084
|
+
if (shownAs === false) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
const now = options.now();
|
|
2088
|
+
const active = session !== undefined && (session.turn || goesOn(session));
|
|
2089
|
+
atWorkSince = active ? (atWorkSince ?? now) : undefined;
|
|
2090
|
+
for (const [name, one] of shows) {
|
|
2091
|
+
const status = statusFor(name, now);
|
|
2092
|
+
const word = `${status.state} ${status.state === "limited" ? (status.until ?? "") : ""}`;
|
|
2093
|
+
if (word === one.said && now - one.at < timing.heartbeatMs) {
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
one.said = word;
|
|
2097
|
+
one.at = now;
|
|
2098
|
+
void say(one, status, abort.signal);
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
/**
|
|
2102
|
+
* The last thing the sources are said: nothing to show, as the runner ends, so that what they
|
|
2103
|
+
* showed is taken back. Waited for a few seconds and no longer: a messenger that does not
|
|
2104
|
+
* answer holds no runner's end, and what stays there ends by itself.
|
|
2105
|
+
*/
|
|
2106
|
+
const showLast = async () => {
|
|
2107
|
+
if (shownAs === false || shows.size === 0) {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
const ending = new AbortController();
|
|
2111
|
+
const over = new Promise((resolve) => {
|
|
2112
|
+
ending.signal.addEventListener("abort", () => resolve(), { once: true });
|
|
2113
|
+
});
|
|
2114
|
+
const timer = setTimeout(() => ending.abort(), SHOWN_END_MS);
|
|
2115
|
+
await Promise.race([
|
|
2116
|
+
Promise.all([...shows.values()].map((one) => say(one, LAST_STATUS, ending.signal))),
|
|
2117
|
+
over,
|
|
2118
|
+
]);
|
|
2119
|
+
clearTimeout(timer);
|
|
2120
|
+
ending.abort();
|
|
2121
|
+
};
|
|
1715
2122
|
/**
|
|
1716
2123
|
* Why the agent stands as it does, and until when where the runner knows: when its usage
|
|
1717
2124
|
* limit resets. A console of before the word `usage_limit` refuses a heartbeat that says it,
|
|
1718
2125
|
* and with it everything else the heartbeat carries: such a console is said `crashed`, the
|
|
1719
|
-
* nearest word it takes, and no moment.
|
|
2126
|
+
* nearest word it takes, and no moment. With it, when the runner said so, which a console of
|
|
2127
|
+
* before reads past.
|
|
1720
2128
|
*/
|
|
1721
2129
|
const saidOfState = () => {
|
|
2130
|
+
// A moment kept by a runner before this one is taken as it reads; one that is no moment is now.
|
|
2131
|
+
const at = Number.isFinite(stands.at) && Math.abs(stands.at) <= 8.64e15 ? stands.at : options.now();
|
|
2132
|
+
const reasonAt = new Date(at).toISOString();
|
|
1722
2133
|
if (stands.reason !== "usage_limit") {
|
|
1723
|
-
return { reason: stands.reason };
|
|
2134
|
+
return { reason: stands.reason, reasonAt };
|
|
1724
2135
|
}
|
|
1725
2136
|
if (plainWords) {
|
|
1726
|
-
return { reason: "crashed" };
|
|
2137
|
+
return { reason: "crashed", reasonAt };
|
|
1727
2138
|
}
|
|
1728
2139
|
return {
|
|
1729
2140
|
reason: stands.reason,
|
|
1730
2141
|
until: limited?.until === undefined ? null : new Date(limited.until).toISOString(),
|
|
2142
|
+
reasonAt,
|
|
1731
2143
|
};
|
|
1732
2144
|
};
|
|
1733
2145
|
/**
|
|
@@ -1776,7 +2188,7 @@ export function createRunner(options) {
|
|
|
1776
2188
|
if (answer.state === "stopped" && !held && answer.latest <= handled) {
|
|
1777
2189
|
held = true;
|
|
1778
2190
|
await end("stopped");
|
|
1779
|
-
stands = { state: "stopped", reason: "stop" };
|
|
2191
|
+
stands = { state: "stopped", reason: "stop", at: options.now() };
|
|
1780
2192
|
}
|
|
1781
2193
|
}
|
|
1782
2194
|
catch (error) {
|
|
@@ -1917,6 +2329,20 @@ export function createRunner(options) {
|
|
|
1917
2329
|
if (source.run === undefined || wakes === undefined) {
|
|
1918
2330
|
return;
|
|
1919
2331
|
}
|
|
2332
|
+
// What the source kept under a runner before this one, where the machine keeps it
|
|
2333
|
+
// (ADR-0166): the ids and the moments of what it brought, so that a runner started again
|
|
2334
|
+
// says nothing a second time. What does not read is nothing kept.
|
|
2335
|
+
const kept = new Kept();
|
|
2336
|
+
try {
|
|
2337
|
+
for (const [name, value] of (await wakes.kept?.load(source.name)) ?? []) {
|
|
2338
|
+
kept.set(name, value);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
catch {
|
|
2342
|
+
log(`what the wake source ${source.name} kept could not be read; it begins with nothing`);
|
|
2343
|
+
}
|
|
2344
|
+
kept.changed = false;
|
|
2345
|
+
keeps.set(source.name, kept);
|
|
1920
2346
|
const host = {
|
|
1921
2347
|
secret: async (name) => secretValues.get(name),
|
|
1922
2348
|
channels: options.config.channels ?? [],
|
|
@@ -1925,35 +2351,65 @@ export function createRunner(options) {
|
|
|
1925
2351
|
// past that, what the sources raise is let go for a while, longer each time, and said
|
|
1926
2352
|
// once, so that a source that repeats itself costs the console nothing more.
|
|
1927
2353
|
if (wakesHeld !== undefined && options.now() < wakesHeld.until) {
|
|
1928
|
-
return;
|
|
2354
|
+
return false;
|
|
1929
2355
|
}
|
|
2356
|
+
// Written in parts whatever the source handed over (ADR-0163): its own lines apart from
|
|
2357
|
+
// what someone else wrote, and a text with no line of the source's as words whole, so
|
|
2358
|
+
// that no word of a message reads as a line of the source's when the signal returns.
|
|
2359
|
+
const text = wakeTextOf("parts" in raised ? raised.parts : [{ words: raised.text }]);
|
|
2360
|
+
// On its way to the agent from here, which the source shows (ADR-0170): until the
|
|
2361
|
+
// stream brings it back, or the console did not take it.
|
|
2362
|
+
const underWay = {
|
|
2363
|
+
at: options.now(),
|
|
2364
|
+
number: undefined,
|
|
2365
|
+
};
|
|
2366
|
+
const others = raising.get(source.name) ?? new Set();
|
|
2367
|
+
raising.set(source.name, others.add(underWay));
|
|
2368
|
+
push({ t: "shown" });
|
|
1930
2369
|
try {
|
|
1931
|
-
await client.raiseWake({ source: "messenger", key: raised.key, text
|
|
2370
|
+
underWay.number = (await client.raiseWake({ source: "messenger", key: raised.key, text })).number;
|
|
1932
2371
|
}
|
|
1933
2372
|
catch (error) {
|
|
2373
|
+
others.delete(underWay);
|
|
2374
|
+
push({ t: "shown" });
|
|
1934
2375
|
if (codeOf(error) !== "signal.too_many") {
|
|
1935
2376
|
throw error;
|
|
1936
2377
|
}
|
|
1937
2378
|
const pause = heldFor(wakesHeld);
|
|
1938
2379
|
wakesHeld = { until: options.now() + pause, pause };
|
|
1939
2380
|
sayOnce("wakes", "the console takes no more wakes of this runner's within the hour (signal.too_many); what its wake sources raise is let go for a while");
|
|
1940
|
-
return;
|
|
2381
|
+
return false;
|
|
1941
2382
|
}
|
|
1942
2383
|
if (wakesHeld !== undefined) {
|
|
1943
2384
|
wakesHeld = undefined;
|
|
1944
2385
|
sayOver("wakes", "the console takes the wakes of this runner's wake sources again");
|
|
1945
2386
|
}
|
|
2387
|
+
return true;
|
|
1946
2388
|
},
|
|
2389
|
+
kept,
|
|
2390
|
+
began: beganBy,
|
|
1947
2391
|
log,
|
|
1948
2392
|
stands: (state, why) => sourceStands(source.name, state, why),
|
|
1949
2393
|
fetch: wakes.fetch,
|
|
1950
2394
|
socket: wakes.socket,
|
|
1951
2395
|
wait: pause,
|
|
2396
|
+
// Who wrote, as the console answers the account's own sign-in (ADR-0164), of the
|
|
2397
|
+
// messenger the source is named for. A console that does not know the question, or does
|
|
2398
|
+
// not answer, says nothing, and the source says of an account what the messenger does.
|
|
2399
|
+
...(client.writers === undefined
|
|
2400
|
+
? {}
|
|
2401
|
+
: {
|
|
2402
|
+
writers: async (accounts, signal) => (await client.writers?.({ messenger: source.name, accounts: [...accounts] }, signal))
|
|
2403
|
+
?.items ?? [],
|
|
2404
|
+
}),
|
|
1952
2405
|
};
|
|
1953
2406
|
sourceStands(source.name, "waiting");
|
|
2407
|
+
if (source.show !== undefined) {
|
|
2408
|
+
shows.set(source.name, { source, host, said: "", at: 0 });
|
|
2409
|
+
}
|
|
1954
2410
|
let wait = timing.reconnectMs;
|
|
1955
2411
|
while (!stopped) {
|
|
1956
|
-
const
|
|
2412
|
+
const startedAt = options.now();
|
|
1957
2413
|
try {
|
|
1958
2414
|
await source.run(host, abort.signal);
|
|
1959
2415
|
// Ended with no error, a connection the other side closed say: it listens no more
|
|
@@ -1969,7 +2425,7 @@ export function createRunner(options) {
|
|
|
1969
2425
|
}
|
|
1970
2426
|
}
|
|
1971
2427
|
wait =
|
|
1972
|
-
options.now() -
|
|
2428
|
+
options.now() - startedAt >= SOURCE_HELD_MS
|
|
1973
2429
|
? timing.reconnectMs
|
|
1974
2430
|
: Math.min(wait * 2, MAX_SOURCE_PAUSE_MS);
|
|
1975
2431
|
await pause(wait);
|
|
@@ -2011,10 +2467,13 @@ export function createRunner(options) {
|
|
|
2011
2467
|
const kept = await options.state.load().catch(() => undefined);
|
|
2012
2468
|
delivered = kept?.delivered ?? 0;
|
|
2013
2469
|
conversation = kept?.conversation;
|
|
2470
|
+
// A moment after now is none the conversation began at: held to the clock here, and
|
|
2471
|
+
// wherever a wake source asks.
|
|
2472
|
+
began = Math.min(kept?.began ?? 0, options.now());
|
|
2014
2473
|
if (conversation !== undefined && kept?.driver !== undefined && kept.driver !== driver.name) {
|
|
2015
2474
|
// Another product's conversation is nothing this one can go on with: asked to, it fails
|
|
2016
2475
|
// at every turn until a supervisor resets it.
|
|
2017
|
-
|
|
2476
|
+
letGo();
|
|
2018
2477
|
log(`the conversation kept was begun under the driver ${kept.driver}: a new one begins under ${driver.name}`);
|
|
2019
2478
|
}
|
|
2020
2479
|
// What a runner before this one held for the agent alone is taken from the stream once
|
|
@@ -2036,9 +2495,14 @@ export function createRunner(options) {
|
|
|
2036
2495
|
tries: 1,
|
|
2037
2496
|
until: known === undefined ? now + timing.coolDownMs : known + timing.resetMarginMs,
|
|
2038
2497
|
};
|
|
2039
|
-
|
|
2498
|
+
// Said as of when the limit was reached, which the runner before this one kept.
|
|
2499
|
+
stands = { state: "failed", reason: "usage_limit", at: kept.limited.since };
|
|
2040
2500
|
log(`the product's usage limit stopped the agent before this runner started: tried again at ${new Date(waits.until).toISOString()}`);
|
|
2041
2501
|
}
|
|
2502
|
+
if ((kept?.began ?? 0) > began) {
|
|
2503
|
+
// Kept as it is taken, once everything else the file said is in place again.
|
|
2504
|
+
await persist();
|
|
2505
|
+
}
|
|
2042
2506
|
probe = await driver.probe();
|
|
2043
2507
|
const left = probe.models.length +
|
|
2044
2508
|
probe.efforts.length -
|
|
@@ -2066,7 +2530,7 @@ export function createRunner(options) {
|
|
|
2066
2530
|
delivered = Math.max(delivered, first.delivered);
|
|
2067
2531
|
if (first.state === "stopped") {
|
|
2068
2532
|
held = true;
|
|
2069
|
-
stands = { state: "stopped", reason: "stop" };
|
|
2533
|
+
stands = { state: "stopped", reason: "stop", at: options.now() };
|
|
2070
2534
|
}
|
|
2071
2535
|
break;
|
|
2072
2536
|
}
|
|
@@ -2105,8 +2569,10 @@ export function createRunner(options) {
|
|
|
2105
2569
|
try {
|
|
2106
2570
|
for (;;) {
|
|
2107
2571
|
// An update is taken between two turns, and at once where none is under way; so is
|
|
2108
|
-
// a runner.json that changed.
|
|
2109
|
-
|
|
2572
|
+
// a runner.json that changed. Neither while sub-agents work on in the background of
|
|
2573
|
+
// the session, for as long as the runner waits for them (ADR-0162).
|
|
2574
|
+
if ((updatedTo !== undefined || reconfigure) &&
|
|
2575
|
+
!busy(session, updatedTo !== undefined ? FOR_UPDATE : FOR_CHANGE)) {
|
|
2110
2576
|
how = updatedTo !== undefined ? "updated" : "changed";
|
|
2111
2577
|
if (session !== undefined) {
|
|
2112
2578
|
record(session, "status", updatedTo !== undefined
|
|
@@ -2139,6 +2605,10 @@ export function createRunner(options) {
|
|
|
2139
2605
|
if (session !== undefined) {
|
|
2140
2606
|
await flush(session);
|
|
2141
2607
|
}
|
|
2608
|
+
await keepKept();
|
|
2609
|
+
}
|
|
2610
|
+
else if (message.t === "shown") {
|
|
2611
|
+
// Looked at below, as after anything else.
|
|
2142
2612
|
}
|
|
2143
2613
|
else {
|
|
2144
2614
|
// A timer counts no time the machine sleeps in, and rings late by as much: what
|
|
@@ -2160,15 +2630,40 @@ export function createRunner(options) {
|
|
|
2160
2630
|
// model having refused or a usage limit standing, waits as it would without it,
|
|
2161
2631
|
// and the reset is taken once a turn completed again.
|
|
2162
2632
|
if (ownReset !== undefined &&
|
|
2163
|
-
session?.turn !== true &&
|
|
2164
2633
|
waits === undefined &&
|
|
2165
|
-
limited === undefined
|
|
2634
|
+
limited === undefined &&
|
|
2635
|
+
!busy(session, FOR_RESET)) {
|
|
2166
2636
|
await beginAnew(ownReset);
|
|
2167
2637
|
}
|
|
2638
|
+
// A model or an effort the product takes only when it starts, held for what went
|
|
2639
|
+
// on in the session: it ends once nothing does. Not where the agent could not go
|
|
2640
|
+
// on, which keeps its session as it does under a turn.
|
|
2641
|
+
if (renew &&
|
|
2642
|
+
session !== undefined &&
|
|
2643
|
+
stands.state === "running" &&
|
|
2644
|
+
!busy(session, FOR_CHOICE)) {
|
|
2645
|
+
await end("restarted");
|
|
2646
|
+
if (pending.length > 0) {
|
|
2647
|
+
scheduleDeliver();
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
// Nothing waits to end the session: the next thing that does counts from its own
|
|
2651
|
+
// moment how long it waits for the sub-agents.
|
|
2652
|
+
if (session !== undefined &&
|
|
2653
|
+
!renew &&
|
|
2654
|
+
ownReset === undefined &&
|
|
2655
|
+
updatedTo === undefined &&
|
|
2656
|
+
!reconfigure) {
|
|
2657
|
+
session.heldSince = undefined;
|
|
2658
|
+
session.heldSaid = undefined;
|
|
2659
|
+
}
|
|
2168
2660
|
}
|
|
2169
2661
|
catch (error) {
|
|
2170
2662
|
log(`the runner could not do what it was about to (${codeOf(error)}); it goes on`);
|
|
2171
2663
|
}
|
|
2664
|
+
// Whatever was done may have changed how the agent stands to whoever waits for it,
|
|
2665
|
+
// and so does the time that passed: looked at once a second at the least.
|
|
2666
|
+
showStatus();
|
|
2172
2667
|
}
|
|
2173
2668
|
}
|
|
2174
2669
|
finally {
|
|
@@ -2178,12 +2673,18 @@ export function createRunner(options) {
|
|
|
2178
2673
|
for (const timer of timers) {
|
|
2179
2674
|
clearTimeout(timer);
|
|
2180
2675
|
}
|
|
2676
|
+
// What the wake sources showed of the agent is taken back while its session ends
|
|
2677
|
+
// (ADR-0170): a runner that is gone shows nothing.
|
|
2678
|
+
const shown = showLast();
|
|
2181
2679
|
// A session ended for an update goes on, in the runner started after, as one a
|
|
2182
2680
|
// supervisor restarted does: with the same conversation.
|
|
2183
2681
|
await end(how === "stopped" ? "exited" : "restarted");
|
|
2682
|
+
await shown;
|
|
2184
2683
|
abort.abort();
|
|
2185
2684
|
await listening;
|
|
2186
2685
|
await Promise.all(sourcing);
|
|
2686
|
+
// What the sources raised as they ended is kept too.
|
|
2687
|
+
await keepKept();
|
|
2187
2688
|
log(how === "updated"
|
|
2188
2689
|
? "the runner ended, for the update"
|
|
2189
2690
|
: how === "changed"
|