@skillcdn/console 0.5.0 → 0.5.1
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 +68 -11
- package/SKILLCDN.md +3 -3
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +3 -2
- package/dist/agent-page.js.map +1 -1
- package/dist/api.d.ts +7 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +6 -5
- package/dist/api.js.map +1 -1
- package/dist/charts.d.ts +103 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +182 -0
- package/dist/charts.js.map +1 -0
- package/dist/cli/cli.d.ts +26 -2
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +1304 -383
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command-words.d.ts +20 -0
- package/dist/cli/command-words.d.ts.map +1 -0
- package/dist/cli/command-words.js +51 -0
- package/dist/cli/command-words.js.map +1 -0
- package/dist/cli/credentials.d.ts +54 -5
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +126 -20
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/directory.d.ts +19 -4
- package/dist/cli/directory.d.ts.map +1 -1
- package/dist/cli/directory.js +16 -8
- package/dist/cli/directory.js.map +1 -1
- package/dist/cli/format.d.ts +65 -8
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +242 -37
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +13 -4
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +92 -54
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +76 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/pack.d.ts +69 -60
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +241 -270
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +42 -0
- package/dist/cli/plugin-check.d.ts.map +1 -1
- package/dist/cli/plugin-check.js +221 -36
- package/dist/cli/plugin-check.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts +6 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +21 -4
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/plugin-main.js +1 -0
- package/dist/cli/plugin-main.js.map +1 -1
- package/dist/cli/serve.d.ts +33 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +252 -3
- package/dist/cli/serve.js.map +1 -1
- package/dist/client.d.ts +48 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +72 -80
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +64 -1
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +244 -96
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/charts.d.ts +157 -0
- package/dist/components/charts.d.ts.map +1 -0
- package/dist/components/charts.js +182 -0
- package/dist/components/charts.js.map +1 -0
- package/dist/components/desk-records.d.ts +102 -0
- package/dist/components/desk-records.d.ts.map +1 -0
- package/dist/components/desk-records.js +221 -0
- package/dist/components/desk-records.js.map +1 -0
- package/dist/components/desk.d.ts +85 -0
- package/dist/components/desk.d.ts.map +1 -0
- package/dist/components/desk.js +135 -0
- package/dist/components/desk.js.map +1 -0
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +4 -1
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +4 -2
- package/dist/components/home.js.map +1 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +54 -3
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.d.ts.map +1 -1
- package/dist/components/projects.js +27 -7
- package/dist/components/projects.js.map +1 -1
- package/dist/components/rules.d.ts +8 -10
- package/dist/components/rules.d.ts.map +1 -1
- package/dist/components/rules.js +35 -13
- package/dist/components/rules.js.map +1 -1
- package/dist/components/setup.d.ts +9 -3
- package/dist/components/setup.d.ts.map +1 -1
- package/dist/components/setup.js +10 -4
- package/dist/components/setup.js.map +1 -1
- package/dist/console.css +677 -7
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +14 -8
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +32 -33
- package/dist/data.js.map +1 -1
- package/dist/desk-page.d.ts +38 -0
- package/dist/desk-page.d.ts.map +1 -0
- package/dist/desk-page.js +184 -0
- package/dist/desk-page.js.map +1 -0
- package/dist/desk-records-page.d.ts +18 -0
- package/dist/desk-records-page.d.ts.map +1 -0
- package/dist/desk-records-page.js +130 -0
- package/dist/desk-records-page.js.map +1 -0
- package/dist/desk-records.d.ts +247 -0
- package/dist/desk-records.d.ts.map +1 -0
- package/dist/desk-records.js +543 -0
- package/dist/desk-records.js.map +1 -0
- package/dist/desk.d.ts +122 -0
- package/dist/desk.d.ts.map +1 -0
- package/dist/desk.js +211 -0
- package/dist/desk.js.map +1 -0
- package/dist/feed-stream.d.ts +39 -0
- package/dist/feed-stream.d.ts.map +1 -0
- package/dist/feed-stream.js +117 -0
- package/dist/feed-stream.js.map +1 -0
- package/dist/home-tiles.d.ts +10 -3
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +54 -31
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +180 -5
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +184 -7
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +169 -6
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +11 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +11 -0
- package/dist/limits.js.map +1 -1
- package/dist/onboarding.d.ts +6 -0
- package/dist/onboarding.d.ts.map +1 -1
- package/dist/onboarding.js +3 -3
- package/dist/onboarding.js.map +1 -1
- package/dist/plugin/context.d.ts +42 -11
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +2 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +2 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/manifest.d.ts +13 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +30 -3
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +55 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +37 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +4 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/testing.d.ts +6 -2
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +52 -10
- package/dist/plugin/testing.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/records.d.ts +283 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +543 -0
- package/dist/records.js.map +1 -0
- package/dist/routes.d.ts +3 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +3 -1
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +30 -11
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +98 -45
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts +1 -1
- package/dist/runner/acp.d.ts.map +1 -1
- package/dist/runner/acp.js +31 -20
- package/dist/runner/acp.js.map +1 -1
- package/dist/runner/claude.d.ts +1 -1
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +85 -15
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts +1 -1
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +19 -16
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/desk.d.ts +43 -2
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +166 -10
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/process.d.ts.map +1 -1
- package/dist/runner/process.js +11 -4
- package/dist/runner/process.js.map +1 -1
- package/dist/runner/redact.d.ts +39 -4
- package/dist/runner/redact.d.ts.map +1 -1
- package/dist/runner/redact.js +81 -5
- package/dist/runner/redact.js.map +1 -1
- package/dist/runner/runner.d.ts +15 -1
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +231 -33
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/task-scheduler.d.ts +20 -0
- package/dist/runner/task-scheduler.d.ts.map +1 -1
- package/dist/runner/task-scheduler.js +34 -4
- package/dist/runner/task-scheduler.js.map +1 -1
- package/dist/runner/types.d.ts +36 -1
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js +17 -0
- package/dist/runner/types.js.map +1 -1
- package/dist/runner.d.ts +6 -6
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +5 -5
- package/dist/runner.js.map +1 -1
- package/dist/schemas.d.ts +509 -5
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +76 -16
- package/dist/schemas.js.map +1 -1
- package/dist/services.d.ts +22 -5
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +35 -15
- package/dist/services.js.map +1 -1
- package/dist/setup-guide.d.ts +3 -1
- package/dist/setup-guide.d.ts.map +1 -1
- package/dist/setup-guide.js +7 -4
- package/dist/setup-guide.js.map +1 -1
- package/dist/vocabulary.d.ts +14 -3
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +13 -3
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +64 -38
- package/docs/specs/plugins.md +27 -20
- package/docs/specs/records.md +113 -0
- package/docs/specs/rest.md +20 -13
- package/docs/specs/runner.md +23 -17
- package/package.json +7 -2
- package/skills/building-a-console/SKILL.md +4 -4
- package/skills/building-a-plugin/SKILL.md +6 -6
- package/skills/deploying-a-console/SKILL.md +4 -4
- package/skills/deploying-a-console/references/resources.md +41 -4
- package/skills/deploying-a-console/references/running-it-again.md +3 -2
- package/skills/keeping-a-desk/SKILL.md +133 -0
- package/skills/keeping-a-desk/collections.md +96 -0
- package/skills/planning-the-board/SKILL.md +14 -18
- package/skills/planning-the-board/references/a-task.md +2 -2
- package/skills/planning-the-board/references/project-rules.md +13 -14
- package/skills/planning-the-board/references/setting-up.md +15 -13
- package/skills/running-an-agent/SKILL.md +10 -9
- package/skills/working-the-board/SKILL.md +62 -44
- package/skills/working-the-board/references/terms.md +9 -5
- package/skills/working-the-board/references/the-pack.md +12 -10
- package/skills/working-the-board/references/the-sentence.md +2 -2
- package/src/agent-page.tsx +3 -1
- package/src/api.ts +77 -2
- package/src/charts.ts +250 -0
- package/src/cli/cli.ts +1698 -476
- package/src/cli/command-words.ts +56 -0
- package/src/cli/credentials.ts +181 -20
- package/src/cli/directory.ts +28 -10
- package/src/cli/format.ts +301 -46
- package/src/cli/help.ts +102 -54
- package/src/cli/main.ts +72 -2
- package/src/cli/pack.ts +333 -372
- package/src/cli/plugin-check.ts +275 -34
- package/src/cli/plugin-cli.ts +28 -4
- package/src/cli/plugin-main.ts +1 -0
- package/src/cli/serve.ts +295 -2
- package/src/client.ts +192 -177
- package/src/components/agent-page.tsx +489 -243
- package/src/components/charts.tsx +680 -0
- package/src/components/desk-records.tsx +724 -0
- package/src/components/desk.tsx +471 -0
- package/src/components/event-feed.tsx +5 -1
- package/src/components/home.tsx +12 -0
- package/src/components/plugin-settings.tsx +171 -12
- package/src/components/projects.tsx +29 -12
- package/src/components/rules.tsx +94 -34
- package/src/components/setup.tsx +18 -3
- package/src/console.tsx +17 -9
- package/src/data.ts +37 -34
- package/src/desk-page.tsx +332 -0
- package/src/desk-records-page.tsx +256 -0
- package/src/desk-records.ts +808 -0
- package/src/desk.ts +329 -0
- package/src/feed-stream.ts +144 -0
- package/src/home-tiles.ts +55 -35
- package/src/i18n/en.ts +196 -9
- package/src/i18n/ko.ts +178 -8
- package/src/index.ts +118 -0
- package/src/limits.ts +11 -0
- package/src/onboarding.ts +12 -4
- package/src/plugin/context.ts +55 -12
- package/src/plugin/limits.ts +2 -0
- package/src/plugin/manifest.ts +38 -2
- package/src/plugin/rest-schemas.ts +41 -0
- package/src/plugin/sandbox.ts +4 -1
- package/src/plugin/testing.ts +63 -12
- package/src/plugin.ts +2 -0
- package/src/records.ts +702 -0
- package/src/routes.ts +3 -1
- package/src/rules.ts +108 -47
- package/src/runner/acp.ts +47 -29
- package/src/runner/claude.ts +113 -23
- package/src/runner/codex.ts +35 -25
- package/src/runner/desk.ts +198 -12
- package/src/runner/process.ts +11 -4
- package/src/runner/redact.ts +92 -6
- package/src/runner/runner.ts +275 -34
- package/src/runner/task-scheduler.ts +36 -4
- package/src/runner/types.ts +47 -1
- package/src/runner.ts +27 -2
- package/src/schemas.ts +83 -15
- package/src/services.ts +49 -14
- package/src/setup-guide.ts +6 -2
- package/src/styles/README.md +11 -1
- package/src/styles/console.css +9 -0
- package/src/styles/pages/desk.css +126 -0
- package/src/styles/pages/documents.css +5 -0
- package/src/styles/parts/bars.css +80 -0
- package/src/styles/parts/chart.css +173 -0
- package/src/styles/parts/figures.css +65 -0
- package/src/styles/parts/legend.css +48 -0
- package/src/styles/parts/series.css +32 -0
- package/src/styles/parts/share.css +25 -0
- package/src/styles/parts/spark.css +23 -0
- package/src/styles/parts/stat.css +69 -0
- package/src/styles/tokens.css +13 -7
- package/src/vocabulary.ts +16 -3
- package/template/desk-web/README.md +8 -0
- package/template/desk-web/index.html +13 -0
- package/template/desk-web/package.json +25 -0
- package/template/desk-web/src/main.tsx +24 -0
- package/template/desk-web/src/page.tsx +51 -0
- package/template/desk-web/tsconfig.json +16 -0
- package/template/desk-web/vite.config.ts +15 -0
package/src/runner/runner.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
introOf,
|
|
23
23
|
makeMark,
|
|
24
24
|
} from "./message.js";
|
|
25
|
-
import { redactorOf } from "./redact.js";
|
|
25
|
+
import { cutShown, cutShownEnd, type Redactor, redactorOf } from "./redact.js";
|
|
26
26
|
import type {
|
|
27
27
|
Driver,
|
|
28
28
|
DriverEvent,
|
|
@@ -57,6 +57,13 @@ export const MAX_COOL_DOWN_MS = 4 * 60 * 60_000;
|
|
|
57
57
|
export const RECONNECT_MS = 5000;
|
|
58
58
|
/** What an autosave's commit says: the runner's, and never the agent's own words. */
|
|
59
59
|
export const AUTOSAVE_MESSAGE = "Autosave at the end of a session";
|
|
60
|
+
/**
|
|
61
|
+
* How long the runner holds back what the console refused as more than an hour takes
|
|
62
|
+
* (ADR-0132), the events of a session and the wakes of its wake sources: a minute at first,
|
|
63
|
+
* twice as long after each refusal that follows, a quarter of an hour at most.
|
|
64
|
+
*/
|
|
65
|
+
export const HOLD_MS = 60_000;
|
|
66
|
+
export const MAX_HOLD_MS = 15 * 60_000;
|
|
60
67
|
/** The longest the runner waits before it starts a wake source again that keeps ending at once. */
|
|
61
68
|
export const MAX_SOURCE_PAUSE_MS = 5 * 60_000;
|
|
62
69
|
/** How long a wake source holds before the runner takes it to have worked. */
|
|
@@ -103,7 +110,12 @@ export type RunnerClient = Pick<
|
|
|
103
110
|
|
|
104
111
|
/** What the runner keeps between its own restarts. No secret is in it. */
|
|
105
112
|
export interface RunnerState {
|
|
106
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* The number of the last signal that is delivered, every one before it too (ADR-0131): the
|
|
115
|
+
* product said it took it, or the record says it was never read or was let go, or the runner
|
|
116
|
+
* acted on it itself. One handed to a product that has not said so is not delivered yet, and
|
|
117
|
+
* is sent again to a runner started after.
|
|
118
|
+
*/
|
|
107
119
|
readonly delivered: number;
|
|
108
120
|
/** The conversation the next session goes on with, where the product resumes one. */
|
|
109
121
|
readonly conversation: string | undefined;
|
|
@@ -182,6 +194,8 @@ export interface RunnerOptions {
|
|
|
182
194
|
coolDownMs: number;
|
|
183
195
|
maxCoolDownMs: number;
|
|
184
196
|
reconnectMs: number;
|
|
197
|
+
holdMs: number;
|
|
198
|
+
maxHoldMs: number;
|
|
185
199
|
}>;
|
|
186
200
|
/** The bounds, for a test to lower. */
|
|
187
201
|
readonly bounds?: Partial<{ outboxBytes: number }>;
|
|
@@ -252,7 +266,14 @@ interface OpenSession {
|
|
|
252
266
|
written: boolean;
|
|
253
267
|
/** Writes its signals on the record, as never read where so, and only those asked for where some are. */
|
|
254
268
|
readonly write: (unread?: boolean, only?: (signal: RestSignal) => boolean) => void;
|
|
269
|
+
/** Its signals: counted as delivered once the product took the message. */
|
|
270
|
+
readonly signals: readonly RestSignal[];
|
|
255
271
|
}[];
|
|
272
|
+
/**
|
|
273
|
+
* Whether the product took a message of this session, or completed a turn of it. One that
|
|
274
|
+
* has not is still starting, for all the runner knows: it took nothing it was handed.
|
|
275
|
+
*/
|
|
276
|
+
took: boolean;
|
|
256
277
|
/** The number of the last event of it. */
|
|
257
278
|
n: number;
|
|
258
279
|
/** What the product did and the console has not been sent yet, and what that holds of memory. */
|
|
@@ -260,6 +281,10 @@ interface OpenSession {
|
|
|
260
281
|
waiting: number;
|
|
261
282
|
/** Whether the console takes nothing more of it: over there, or its month away. */
|
|
262
283
|
refused: boolean;
|
|
284
|
+
/** The console took as many of its events as an hour takes: until when nothing is sent, and how long that was. */
|
|
285
|
+
hold?: { readonly until: number; readonly pause: number } | undefined;
|
|
286
|
+
/** Why the console did not take what waits, in its code: said where the session ends with it unsent. */
|
|
287
|
+
unsent?: string | undefined;
|
|
263
288
|
running: { model: string | null; effort: string | null };
|
|
264
289
|
/** The files written for it, to remove at its end. */
|
|
265
290
|
readonly written: string[];
|
|
@@ -345,8 +370,13 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
345
370
|
coolDownMs: COOL_DOWN_MS,
|
|
346
371
|
maxCoolDownMs: MAX_COOL_DOWN_MS,
|
|
347
372
|
reconnectMs: RECONNECT_MS,
|
|
373
|
+
holdMs: HOLD_MS,
|
|
374
|
+
maxHoldMs: MAX_HOLD_MS,
|
|
348
375
|
...options.timing,
|
|
349
376
|
};
|
|
377
|
+
/** How long what an hour's bound refused is held back: the first time, and twice as long each time after. */
|
|
378
|
+
const heldFor = (before: { readonly pause: number } | undefined): number =>
|
|
379
|
+
before === undefined ? timing.holdMs : Math.min(before.pause * 2, timing.maxHoldMs);
|
|
350
380
|
const bounds = { outboxBytes: MAX_OUTBOX_BYTES, ...options.bounds };
|
|
351
381
|
|
|
352
382
|
// What keeps failing is said once, and again when what is said of it changes, so that an hour
|
|
@@ -396,7 +426,12 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
396
426
|
};
|
|
397
427
|
|
|
398
428
|
// What the runner holds.
|
|
429
|
+
/** The number of the last signal delivered, every one before it too: what is kept and said to the console. */
|
|
399
430
|
let delivered = 0;
|
|
431
|
+
/** The signals handed to the product that it has not taken yet, by number: not delivered, and not sent twice. */
|
|
432
|
+
const owed = new Set<number>();
|
|
433
|
+
/** The highest number of a signal the product took, or the record says was never read or let go. */
|
|
434
|
+
let settled = 0;
|
|
400
435
|
/** The number of the last signal the stream gave, and of the last one acted on: the second is behind the first while one waits in the queue. */
|
|
401
436
|
let received = 0;
|
|
402
437
|
let handled = 0;
|
|
@@ -427,8 +462,10 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
427
462
|
/** The values of the account's store, by what the store said of them last. */
|
|
428
463
|
let secretsStamp: string | undefined;
|
|
429
464
|
let secretValues = new Map<string, string>();
|
|
430
|
-
let redact:
|
|
465
|
+
let redact: Redactor = redactorOf([]);
|
|
431
466
|
let tooOldSaid = false;
|
|
467
|
+
/** The console took as many wakes of this runner's as an hour takes: until when none is raised, and how long that was. */
|
|
468
|
+
let wakesHeld: { readonly until: number; readonly pause: number } | undefined;
|
|
432
469
|
/**
|
|
433
470
|
* The package the runner runs from, where it is another version than the runner's: the one
|
|
434
471
|
* last seen, and the one seen twice running, which the runner ends for.
|
|
@@ -569,11 +606,18 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
569
606
|
const codeOf = (error: unknown): string =>
|
|
570
607
|
error instanceof ApiError ? error.code : error instanceof Error ? error.name : "error";
|
|
571
608
|
|
|
572
|
-
/**
|
|
573
|
-
|
|
609
|
+
/**
|
|
610
|
+
* Sends what the product did, a batch at a time, the pictures first. What the console has
|
|
611
|
+
* already is left there. Nothing is sent while the console holds the session to its hour
|
|
612
|
+
* (ADR-0132), but at the session's end, which is `last`.
|
|
613
|
+
*/
|
|
614
|
+
const flush = async (target: OpenSession, last = false): Promise<void> => {
|
|
574
615
|
if (flushing) {
|
|
575
616
|
return;
|
|
576
617
|
}
|
|
618
|
+
if (!last && target.hold !== undefined && options.now() < target.hold.until) {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
577
621
|
flushing = true;
|
|
578
622
|
const about = `transcript ${target.id}`;
|
|
579
623
|
try {
|
|
@@ -623,6 +667,8 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
623
667
|
for (const event of target.outbox.splice(0, batch.length)) {
|
|
624
668
|
target.waiting -= event.held;
|
|
625
669
|
}
|
|
670
|
+
target.hold = undefined;
|
|
671
|
+
target.unsent = undefined;
|
|
626
672
|
sayOver(about, `the transcript of session ${target.id} is sent again`);
|
|
627
673
|
sayOver(`outbox ${target.id}`);
|
|
628
674
|
} catch (error) {
|
|
@@ -670,6 +716,22 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
670
716
|
target.waiting += only.held - before;
|
|
671
717
|
continue;
|
|
672
718
|
}
|
|
719
|
+
if (code === "transcript.too_many") {
|
|
720
|
+
// As many events as the console takes of a session within an hour: what waits is
|
|
721
|
+
// kept, within what the runner keeps, and sent again after a while, longer each
|
|
722
|
+
// time, so that the console is not asked every second for what it will refuse.
|
|
723
|
+
const pause = heldFor(target.hold);
|
|
724
|
+
target.hold = { until: options.now() + pause, pause };
|
|
725
|
+
target.unsent = code;
|
|
726
|
+
// Nothing is kept past the session's end: what is let go then is said there.
|
|
727
|
+
if (!last) {
|
|
728
|
+
sayOnce(
|
|
729
|
+
about,
|
|
730
|
+
`the console takes no more events of session ${target.id} within the hour (${code}); they are kept and sent again later`,
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
673
735
|
if (
|
|
674
736
|
code === "transcript.session_over" ||
|
|
675
737
|
code === "transcript.session_not_found" ||
|
|
@@ -685,8 +747,10 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
685
747
|
}
|
|
686
748
|
}
|
|
687
749
|
} catch (error) {
|
|
688
|
-
// Kept, and sent with the next batch. Said once for as long as it lasts, and when it is
|
|
689
|
-
|
|
750
|
+
// Kept, and sent with the next batch. Said once for as long as it lasts, and when it is
|
|
751
|
+
// over; at the session's end there is no next batch, and what is let go is said there.
|
|
752
|
+
target.unsent = codeOf(error);
|
|
753
|
+
if (!stopped && !last) {
|
|
690
754
|
sayOnce(
|
|
691
755
|
about,
|
|
692
756
|
`the transcript of session ${target.id} waits to be sent (${codeOf(error)})`,
|
|
@@ -759,7 +823,12 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
759
823
|
machine: options.machine,
|
|
760
824
|
});
|
|
761
825
|
} catch (error) {
|
|
762
|
-
|
|
826
|
+
const code = codeOf(error);
|
|
827
|
+
log(
|
|
828
|
+
code === "transcript.too_many_sessions"
|
|
829
|
+
? `the console begins no more sessions of this account within the hour (${code}); tried again after the cool-down`
|
|
830
|
+
: `a session could not be begun at the console (${code})`,
|
|
831
|
+
);
|
|
763
832
|
for (const path of handed.written) {
|
|
764
833
|
await options.files.remove(path).catch(() => undefined);
|
|
765
834
|
}
|
|
@@ -775,12 +844,17 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
775
844
|
effort: settings.effort,
|
|
776
845
|
resume,
|
|
777
846
|
permissions: config.permissions,
|
|
847
|
+
// Whatever the driver shows a part of is cut once the secrets, as the store has them
|
|
848
|
+
// now, are out of it: no part of one stands where a text was cut.
|
|
849
|
+
cut: (text, most, more) => cutShown(redact, text, most, more),
|
|
850
|
+
cutEnd: (text, most, more) => cutShownEnd(redact, text, most, more),
|
|
778
851
|
}),
|
|
779
852
|
startedAt: options.now(),
|
|
780
853
|
first: true,
|
|
781
854
|
turn: false,
|
|
782
855
|
sent: [],
|
|
783
856
|
handed: [],
|
|
857
|
+
took: false,
|
|
784
858
|
n: 0,
|
|
785
859
|
outbox: [],
|
|
786
860
|
waiting: 0,
|
|
@@ -813,10 +887,28 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
813
887
|
await target.driver.stop().catch(() => undefined);
|
|
814
888
|
}
|
|
815
889
|
await target.pumped;
|
|
816
|
-
|
|
817
|
-
|
|
890
|
+
await hearLast(target);
|
|
891
|
+
// What the product was handed and never took is sent again, by the console where the
|
|
892
|
+
// runner itself ends and by the runner where the product had not started; else it is on
|
|
893
|
+
// the record as never read.
|
|
894
|
+
await leave(target, stopped ? "after" : already || target.took ? undefined : "next");
|
|
818
895
|
record(target, "status", `The session ended: ${how}.`, { ended: how });
|
|
819
|
-
await flush(target);
|
|
896
|
+
await flush(target, true);
|
|
897
|
+
// What the console did not take by now goes with the session: nothing of it is sent
|
|
898
|
+
// later, and the runner's line says how many, where an earlier one said they were kept.
|
|
899
|
+
const unsent = target.outbox.length;
|
|
900
|
+
if (unsent > 0) {
|
|
901
|
+
const one = unsent === 1;
|
|
902
|
+
log(
|
|
903
|
+
`${unsent} ${one ? "event" : "events"} of session ${target.id} ${one ? "was" : "were"} let go unsent when it ended: ${
|
|
904
|
+
target.unsent === "transcript.too_many"
|
|
905
|
+
? `the console takes no more of it within the hour (${target.unsent})`
|
|
906
|
+
: `the console did not take ${one ? "it" : "them"} (${target.unsent ?? "error"})`
|
|
907
|
+
}`,
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
saidOf.delete(`transcript ${target.id}`);
|
|
911
|
+
saidOf.delete(`outbox ${target.id}`);
|
|
820
912
|
try {
|
|
821
913
|
await client.endAgentSession(target.id, { how });
|
|
822
914
|
} catch (error) {
|
|
@@ -1018,26 +1110,136 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1018
1110
|
if (waited) {
|
|
1019
1111
|
write();
|
|
1020
1112
|
}
|
|
1021
|
-
target.handed.push({ written: waited, write });
|
|
1113
|
+
target.handed.push({ written: waited, write, signals: batch });
|
|
1022
1114
|
target.turn = true;
|
|
1023
1115
|
// Everything handed over since the agent was last done: what a product that took nothing is sent again.
|
|
1024
1116
|
target.sent = [...target.sent, ...batch];
|
|
1025
|
-
|
|
1026
|
-
|
|
1117
|
+
// Handed over, and not delivered until the product says it took it: a product that did
|
|
1118
|
+
// not start took nothing, and a runner that ends then is sent it again when it is back.
|
|
1119
|
+
for (const signal of batch) {
|
|
1120
|
+
owed.add(signal.number);
|
|
1121
|
+
}
|
|
1027
1122
|
await account();
|
|
1028
1123
|
};
|
|
1029
1124
|
|
|
1125
|
+
/** Counts signals as delivered: the product took them, or the record says what became of them. */
|
|
1126
|
+
const count = async (signals: readonly RestSignal[]): Promise<void> => {
|
|
1127
|
+
for (const signal of signals) {
|
|
1128
|
+
owed.delete(signal.number);
|
|
1129
|
+
settled = Math.max(settled, signal.number);
|
|
1130
|
+
}
|
|
1131
|
+
await account();
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* The product took the oldest message it was handed: on the record now, where it was not
|
|
1136
|
+
* written at once, and delivered.
|
|
1137
|
+
*/
|
|
1138
|
+
const take = async (target: OpenSession): Promise<void> => {
|
|
1139
|
+
target.took = true;
|
|
1140
|
+
const message = target.handed.shift();
|
|
1141
|
+
if (message !== undefined) {
|
|
1142
|
+
if (!message.written) {
|
|
1143
|
+
message.write();
|
|
1144
|
+
}
|
|
1145
|
+
await count(message.signals);
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1030
1149
|
/**
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1033
|
-
* over or the agent cannot go on.
|
|
1150
|
+
* The agent is done with what it was sent: what the product was handed and did not say it
|
|
1151
|
+
* took is taken, on the record where the record does not hold it yet, and delivered.
|
|
1034
1152
|
*/
|
|
1035
|
-
const settle = (target: OpenSession
|
|
1153
|
+
const settle = async (target: OpenSession): Promise<void> => {
|
|
1154
|
+
target.took = true;
|
|
1155
|
+
const counted: RestSignal[] = [];
|
|
1036
1156
|
for (const message of target.handed.splice(0)) {
|
|
1037
1157
|
if (!message.written) {
|
|
1038
|
-
message.write(
|
|
1158
|
+
message.write();
|
|
1159
|
+
}
|
|
1160
|
+
counted.push(...message.signals);
|
|
1161
|
+
}
|
|
1162
|
+
await count(counted);
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* Hears what the product said as its session was ended. Its words wait in the queue behind
|
|
1167
|
+
* whatever ended the session, and are let go there once the session is no longer the open
|
|
1168
|
+
* one: a message it said it took then is taken, and not sent again, and the conversation it
|
|
1169
|
+
* named is the one to go on with, where that message is.
|
|
1170
|
+
*/
|
|
1171
|
+
const hearLast = async (target: OpenSession): Promise<void> => {
|
|
1172
|
+
let named = false;
|
|
1173
|
+
for (const message of queue) {
|
|
1174
|
+
if (message.t !== "driver" || message.session !== target) {
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
const { event } = message;
|
|
1178
|
+
if (event.type === "conversation") {
|
|
1179
|
+
conversation = event.id;
|
|
1180
|
+
named = true;
|
|
1181
|
+
} else if (event.type === "taken") {
|
|
1182
|
+
await take(target);
|
|
1183
|
+
} else if (event.type === "turn_completed") {
|
|
1184
|
+
await settle(target);
|
|
1185
|
+
record(target, "status", "The turn completed.", { turn: "completed" });
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (named) {
|
|
1189
|
+
await persist();
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* What becomes of what the product was handed and never took, as its session ends
|
|
1195
|
+
* (ADR-0131). Sent again, it is not delivered, and the record holds nothing more of it than
|
|
1196
|
+
* a line that says so: by the console to the runner started `after` this one, where the
|
|
1197
|
+
* runner itself ends; by this runner in the `next` session, where the product had taken
|
|
1198
|
+
* nothing of this one, and so had not started. Else it is let go: on the record as never
|
|
1199
|
+
* read, which delivers it; what the record holds since it was handed over, to a product that
|
|
1200
|
+
* waited for a message, is said in a line not to have been taken.
|
|
1201
|
+
*/
|
|
1202
|
+
const leave = async (target: OpenSession, again?: "after" | "next"): Promise<void> => {
|
|
1203
|
+
const messages = target.handed.splice(0);
|
|
1204
|
+
const signals = messages.flatMap((message) => message.signals);
|
|
1205
|
+
if (signals.length === 0) {
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const numbersOf = (some: readonly RestSignal[]): string =>
|
|
1209
|
+
some.map((signal) => `#${signal.number}`).join(", ");
|
|
1210
|
+
if (again !== undefined) {
|
|
1211
|
+
const numbers = numbersOf(signals);
|
|
1212
|
+
record(
|
|
1213
|
+
target,
|
|
1214
|
+
"status",
|
|
1215
|
+
`The session ended before the product took what it was sent: ${numbers}. It is sent again.`,
|
|
1216
|
+
);
|
|
1217
|
+
log(`${numbers} not taken when session ${target.id} ended: sent again`);
|
|
1218
|
+
if (again === "next") {
|
|
1219
|
+
for (const signal of signals) {
|
|
1220
|
+
// Waits to be handed over again: owed no word of the product's, and not delivered.
|
|
1221
|
+
owed.delete(signal.number);
|
|
1222
|
+
sentBefore.add(signal.number);
|
|
1223
|
+
}
|
|
1224
|
+
pending = [...signals, ...pending];
|
|
1225
|
+
}
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
const written = messages.filter((message) => message.written).flatMap((one) => one.signals);
|
|
1229
|
+
if (written.length > 0) {
|
|
1230
|
+
record(
|
|
1231
|
+
target,
|
|
1232
|
+
"status",
|
|
1233
|
+
`The session ended before the product took what it was sent: ${numbersOf(written)}. Whoever sent it says it again where it still matters.`,
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
for (const message of messages) {
|
|
1237
|
+
if (!message.written) {
|
|
1238
|
+
message.write(true);
|
|
1039
1239
|
}
|
|
1040
1240
|
}
|
|
1241
|
+
// On the record as never read: delivered.
|
|
1242
|
+
await count(signals);
|
|
1041
1243
|
};
|
|
1042
1244
|
|
|
1043
1245
|
/**
|
|
@@ -1062,13 +1264,24 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1062
1264
|
};
|
|
1063
1265
|
|
|
1064
1266
|
/**
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1267
|
+
* Counts what is delivered: signals in order, up to the last one the product took, the record
|
|
1268
|
+
* says was never read or let go, or the runner acted on itself, a stop or a choice of model
|
|
1269
|
+
* say, and never past one that still waits to be handed to the product or that the product
|
|
1270
|
+
* has not said it took.
|
|
1067
1271
|
*/
|
|
1068
1272
|
const account = async (signal?: RestSignal): Promise<void> => {
|
|
1069
1273
|
acted = Math.max(acted, signal?.number ?? 0);
|
|
1070
|
-
|
|
1071
|
-
|
|
1274
|
+
const most = Math.max(settled, acted);
|
|
1275
|
+
let least = Number.POSITIVE_INFINITY;
|
|
1276
|
+
for (const kept of pending) {
|
|
1277
|
+
least = Math.min(least, kept.number);
|
|
1278
|
+
}
|
|
1279
|
+
for (const number of owed) {
|
|
1280
|
+
least = Math.min(least, number);
|
|
1281
|
+
}
|
|
1282
|
+
const next = Math.min(most, least - 1);
|
|
1283
|
+
if (next > delivered) {
|
|
1284
|
+
delivered = next;
|
|
1072
1285
|
await persist();
|
|
1073
1286
|
}
|
|
1074
1287
|
};
|
|
@@ -1082,7 +1295,11 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1082
1295
|
|
|
1083
1296
|
const onSignal = async (signal: RestSignal): Promise<void> => {
|
|
1084
1297
|
handled = Math.max(handled, signal.number);
|
|
1085
|
-
if (
|
|
1298
|
+
if (
|
|
1299
|
+
signal.number <= delivered ||
|
|
1300
|
+
owed.has(signal.number) ||
|
|
1301
|
+
pending.some((kept) => kept.number === signal.number)
|
|
1302
|
+
) {
|
|
1086
1303
|
return;
|
|
1087
1304
|
}
|
|
1088
1305
|
const by = signal.by?.name ?? signal.by?.login ?? "a supervisor";
|
|
@@ -1090,8 +1307,9 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1090
1307
|
case "stop": {
|
|
1091
1308
|
held = true;
|
|
1092
1309
|
if (session !== undefined) {
|
|
1093
|
-
// What the product had not taken is on the record before the stop that leaves it
|
|
1094
|
-
|
|
1310
|
+
// What the product had not taken is on the record before the stop that leaves it
|
|
1311
|
+
// unread; what a product that had not started was handed waits for the restart.
|
|
1312
|
+
await leave(session, session.took ? undefined : "next");
|
|
1095
1313
|
record(session, "person", signal.text, signalData(signal));
|
|
1096
1314
|
}
|
|
1097
1315
|
await end("stopped");
|
|
@@ -1212,16 +1430,12 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1212
1430
|
return;
|
|
1213
1431
|
}
|
|
1214
1432
|
case "taken": {
|
|
1215
|
-
|
|
1216
|
-
const message = target.handed.shift();
|
|
1217
|
-
if (message !== undefined && !message.written) {
|
|
1218
|
-
message.write();
|
|
1219
|
-
}
|
|
1433
|
+
await take(target);
|
|
1220
1434
|
return;
|
|
1221
1435
|
}
|
|
1222
1436
|
case "turn_completed": {
|
|
1223
1437
|
// The agent is done with everything it was sent: what a product did not say it took is taken.
|
|
1224
|
-
settle(target);
|
|
1438
|
+
await settle(target);
|
|
1225
1439
|
// The record says where a turn ends, so that whoever reads it live knows the agent is done.
|
|
1226
1440
|
record(target, "status", "The turn completed.", { turn: "completed" });
|
|
1227
1441
|
target.turn = false;
|
|
@@ -1274,10 +1488,14 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1274
1488
|
}
|
|
1275
1489
|
for (const signal of again) {
|
|
1276
1490
|
sentBefore.add(signal.number);
|
|
1491
|
+
// Waits to be handed over again: owed no word of the product's, and not delivered.
|
|
1492
|
+
owed.delete(signal.number);
|
|
1277
1493
|
}
|
|
1278
1494
|
pending = [...again, ...pending];
|
|
1279
1495
|
// Sent again, and on the record when it is taken then.
|
|
1280
1496
|
target.handed = [];
|
|
1497
|
+
// What was let go is on the record as that, and is delivered: it is sent no more.
|
|
1498
|
+
await count(gone);
|
|
1281
1499
|
}
|
|
1282
1500
|
target.sent = [];
|
|
1283
1501
|
waits = cooled(waits);
|
|
@@ -1379,7 +1597,7 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1379
1597
|
// the product says it took then is this message, which the record holds nothing
|
|
1380
1598
|
// of, and not the message of a signal that waits behind it.
|
|
1381
1599
|
target.turn = true;
|
|
1382
|
-
target.handed.push({ written: true, write: () => undefined });
|
|
1600
|
+
target.handed.push({ written: true, write: () => undefined, signals: [] });
|
|
1383
1601
|
} catch {
|
|
1384
1602
|
// Not told: the runner's own line above says it to whoever reads its output.
|
|
1385
1603
|
}
|
|
@@ -1453,7 +1671,30 @@ export function createRunner(options: RunnerOptions): Runner {
|
|
|
1453
1671
|
const host: WakeHost = {
|
|
1454
1672
|
secret: async (name) => secretValues.get(name),
|
|
1455
1673
|
raise: async (raised) => {
|
|
1456
|
-
|
|
1674
|
+
// The console takes so many wakes a runner raises itself within an hour (ADR-0132):
|
|
1675
|
+
// past that, what the sources raise is let go for a while, longer each time, and said
|
|
1676
|
+
// once, so that a source that repeats itself costs the console nothing more.
|
|
1677
|
+
if (wakesHeld !== undefined && options.now() < wakesHeld.until) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
try {
|
|
1681
|
+
await client.raiseWake({ source: "messenger", key: raised.key, text: raised.text });
|
|
1682
|
+
} catch (error) {
|
|
1683
|
+
if (codeOf(error) !== "signal.too_many") {
|
|
1684
|
+
throw error;
|
|
1685
|
+
}
|
|
1686
|
+
const pause = heldFor(wakesHeld);
|
|
1687
|
+
wakesHeld = { until: options.now() + pause, pause };
|
|
1688
|
+
sayOnce(
|
|
1689
|
+
"wakes",
|
|
1690
|
+
"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",
|
|
1691
|
+
);
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
if (wakesHeld !== undefined) {
|
|
1695
|
+
wakesHeld = undefined;
|
|
1696
|
+
sayOver("wakes", "the console takes the wakes of this runner's wake sources again");
|
|
1697
|
+
}
|
|
1457
1698
|
},
|
|
1458
1699
|
log,
|
|
1459
1700
|
fetch: wakes.fetch,
|
|
@@ -8,8 +8,9 @@ import { KEEPER_VARIABLE, type Service, type ServiceCommand, type ServiceInput }
|
|
|
8
8
|
// The system starts a task once and in a window, gives it the account's environment and not the
|
|
9
9
|
// one the machine was set up in, keeps none of its words, and ends it by ending the one process
|
|
10
10
|
// it started: so what the task starts is a few lines of the system's own shell, in no window,
|
|
11
|
-
// which start the runner with the setup's `PATH`, keep its lines
|
|
12
|
-
// and tell it which process keeps it. Written from
|
|
11
|
+
// which start the runner with the setup's `PATH`, keep its lines in a log that is put aside
|
|
12
|
+
// when it is full, start it again when it ends and tell it which process keeps it. Written from
|
|
13
|
+
// the system's own documentation, the Task
|
|
13
14
|
// Scheduler's schema and schtasks, and run on Windows 11; the module says what to write and what
|
|
14
15
|
// to run, and whoever sets the machine up does it.
|
|
15
16
|
|
|
@@ -22,6 +23,14 @@ const RESTART_SECONDS = 10;
|
|
|
22
23
|
/** The most a task's command line carries, with room left for the shell's own path. */
|
|
23
24
|
const MAX_COMMAND = 30_000;
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* How large the log is before it is put aside, in bytes, and how many logs put aside are kept:
|
|
28
|
+
* the runner's lines hold a few megabytes at most, on a machine that runs for years. The other
|
|
29
|
+
* services leave it to the system, whose journal keeps to a size of its own.
|
|
30
|
+
*/
|
|
31
|
+
export const MAX_LOG_BYTES = 4 * 1024 * 1024;
|
|
32
|
+
export const KEPT_LOGS = 3;
|
|
33
|
+
|
|
25
34
|
/** What a task's name, and so the name of an OS account in it, cannot hold. */
|
|
26
35
|
const UNNAMEABLE = /[\\/:*?"<>|]/;
|
|
27
36
|
|
|
@@ -76,6 +85,29 @@ const word = (text: string): string => {
|
|
|
76
85
|
return parts.length === 1 ? (parts[0] ?? "''") : `(${parts.join(" + [char]37 + ")})`;
|
|
77
86
|
};
|
|
78
87
|
|
|
88
|
+
/**
|
|
89
|
+
* What keeps a line in the log, as a function of the shell's, `Keep`: the log is put aside
|
|
90
|
+
* first where it is full, as `<log>.1`, the ones put aside before each moved one on and the
|
|
91
|
+
* oldest let go, and the line is added and the log let go of, so that it is read while the
|
|
92
|
+
* runner runs. Whoever writes the log bounds it: a runner that cannot start writes lines too.
|
|
93
|
+
* The log itself is moved first, to a spare name, `<log>.0`, and the ones put aside are
|
|
94
|
+
* touched only once that worked: a log that cannot be moved, read by something that holds it
|
|
95
|
+
* say, is added to as it is and put aside at a later line, and costs none of them, where
|
|
96
|
+
* letting the oldest go first lost one at every line. A spare name left by a step after it
|
|
97
|
+
* that did not work is gone on from, the log after it added to meanwhile. The log is `$log`;
|
|
98
|
+
* no quote and no percent sign is written, as nothing of the task's line may hold one.
|
|
99
|
+
*/
|
|
100
|
+
export function logKeeper(maxBytes: number = MAX_LOG_BYTES, kept: number = KEPT_LOGS): string {
|
|
101
|
+
const aside = [
|
|
102
|
+
"$spare = $log + '.0'",
|
|
103
|
+
"if (-not [IO.File]::Exists($spare)) { [IO.File]::Move($log, $spare) }",
|
|
104
|
+
`$last = $log + '.${kept}'`,
|
|
105
|
+
"if ([IO.File]::Exists($last)) { [IO.File]::Delete($last) }",
|
|
106
|
+
`for ($i = ${kept - 1}; $i -ge 0; $i--) { $from = $log + '.' + $i; if ([IO.File]::Exists($from)) { [IO.File]::Move($from, $log + '.' + ($i + 1)) } }`,
|
|
107
|
+
].join("; ");
|
|
108
|
+
return `function Keep($line) { try { $now = [IO.FileInfo]$log; if ($now.Exists -and $now.Length -ge ${maxBytes}) { ${aside} } } catch { }; [IO.File]::AppendAllText($log, [string]$line + [Environment]::NewLine) }`;
|
|
109
|
+
}
|
|
110
|
+
|
|
79
111
|
/**
|
|
80
112
|
* What the task starts, in the system's own shell and on one line: the runner in the desk with
|
|
81
113
|
* the `PATH` the machine was set up with, its lines added to the log as they come, and the
|
|
@@ -86,13 +118,13 @@ const word = (text: string): string => {
|
|
|
86
118
|
*/
|
|
87
119
|
export function taskScript(input: ServiceInput, log: string): string {
|
|
88
120
|
const [runner = "", ...words] = input.program;
|
|
89
|
-
|
|
90
|
-
const kept = "[IO.File]::AppendAllText($log, [string]$_ + [Environment]::NewLine)";
|
|
121
|
+
const kept = "Keep $_";
|
|
91
122
|
return [
|
|
92
123
|
// A line the runner writes of an error is a line, and what it writes is read as it wrote it.
|
|
93
124
|
"$ErrorActionPreference = 'Continue'",
|
|
94
125
|
"[Console]::OutputEncoding = [Text.Encoding]::UTF8",
|
|
95
126
|
`$log = ${word(log)}`,
|
|
127
|
+
logKeeper(),
|
|
96
128
|
`$runner = ${word(runner)}`,
|
|
97
129
|
`$words = @(${words.map(word).join(", ")})`,
|
|
98
130
|
// A runner left behind is the same program, started with the same words to their end as
|
package/src/runner/types.ts
CHANGED
|
@@ -101,6 +101,49 @@ export interface StartOptions {
|
|
|
101
101
|
* names it; the driver's own for a run nobody attends where nothing names one.
|
|
102
102
|
*/
|
|
103
103
|
readonly permissions?: string | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* What cuts a text to what the transcript shows of it. A driver cuts whatever it shows a
|
|
106
|
+
* part of through this, and never by itself first; left out, a text is cut as it is.
|
|
107
|
+
*/
|
|
108
|
+
readonly cut?: Cut | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* What keeps the end of a text to what the transcript shows of it, the secrets out first: the
|
|
111
|
+
* end of what the product wrote on its standard error, which says why it ended. A driver shows
|
|
112
|
+
* that through this (`errorsShown`); left out, a text is cut as it is.
|
|
113
|
+
*/
|
|
114
|
+
readonly cutEnd?: Cut | undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A text within `most` characters as the transcript shows it, ended by the mark of a cut where
|
|
119
|
+
* it was longer: the account's secrets are taken out first and the text is cut after, so that
|
|
120
|
+
* no part of one stands at the cut. `more` says that the text is itself the beginning of a
|
|
121
|
+
* longer one, which the driver kept to a bound: its last characters may begin a secret, and
|
|
122
|
+
* are not shown.
|
|
123
|
+
*/
|
|
124
|
+
export type Cut = (text: string, most: number, more?: boolean) => string;
|
|
125
|
+
|
|
126
|
+
/** A text cut as it is, with the mark of a cut: what a driver cuts with where it was handed nothing to cut with. */
|
|
127
|
+
export const plainCut: Cut = (text, most) =>
|
|
128
|
+
text.length > most ? `${text.slice(0, most)}…` : text;
|
|
129
|
+
|
|
130
|
+
/** The end of a text kept as it is, begun by the mark of a cut: what a driver keeps the end of a text with where it was handed nothing to. */
|
|
131
|
+
export const plainCutEnd: Cut = (text, most, more = false) =>
|
|
132
|
+
text.length > most || more ? `…${text.slice(Math.max(0, text.length - most))}` : text;
|
|
133
|
+
|
|
134
|
+
/** How much of the end of what a product wrote on its standard error an event shows. */
|
|
135
|
+
export const MAX_ERRORS_SHOWN = 4000;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What a product wrote on its standard error as an event shows it: its end, within
|
|
139
|
+
* `MAX_ERRORS_SHOWN`, kept through `cutEnd`, so that the secrets are out before it is cut. A
|
|
140
|
+
* text whose beginning the child let go begins with the mark of a cut (`Child.errors`), and its
|
|
141
|
+
* first characters may be the end of a secret: they are not shown.
|
|
142
|
+
*/
|
|
143
|
+
export function errorsShown(errors: string, cutEnd: Cut): string {
|
|
144
|
+
const text = errors.trim();
|
|
145
|
+
const more = text.startsWith("…");
|
|
146
|
+
return cutEnd(more ? text.slice(1) : text, MAX_ERRORS_SHOWN, more);
|
|
104
147
|
}
|
|
105
148
|
|
|
106
149
|
/** What the installed product is and offers, asked without starting a session. */
|
|
@@ -149,7 +192,10 @@ export interface Child {
|
|
|
149
192
|
end(): void;
|
|
150
193
|
/** Its standard output, a line at a time, until it closes. Read once. */
|
|
151
194
|
readonly lines: AsyncIterable<string>;
|
|
152
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The end of what it wrote on its standard error, bounded: where its beginning was let go, it
|
|
197
|
+
* begins with the mark of a cut (`…`), since what it begins with may be the end of a secret.
|
|
198
|
+
*/
|
|
153
199
|
errors(): string;
|
|
154
200
|
kill(signal: "SIGINT" | "SIGTERM" | "SIGKILL"): void;
|
|
155
201
|
/** How it ended: its exit code, or the signal that ended it; or why it never started. Never rejects. */
|