@skillcdn/console 0.6.0 → 0.6.2
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 +7 -7
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +58 -35
- package/dist/agent-page.js.map +1 -1
- package/dist/agent-usage.d.ts +51 -0
- package/dist/agent-usage.d.ts.map +1 -0
- package/dist/agent-usage.js +77 -0
- package/dist/agent-usage.js.map +1 -0
- package/dist/api.d.ts +4 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +4 -2
- package/dist/api.js.map +1 -1
- package/dist/cli/cli.d.ts +9 -2
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +491 -125
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/format.d.ts +46 -4
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +163 -45
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +62 -13
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/machine-check.d.ts +24 -5
- package/dist/cli/machine-check.d.ts.map +1 -1
- package/dist/cli/machine-check.js +128 -16
- package/dist/cli/machine-check.js.map +1 -1
- package/dist/cli/pack.d.ts +11 -8
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +63 -28
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/runner-host.d.ts +2 -0
- package/dist/cli/runner-host.d.ts.map +1 -1
- package/dist/cli/runner-host.js +1 -0
- package/dist/cli/runner-host.js.map +1 -1
- package/dist/cli/secret-notes.d.ts.map +1 -1
- package/dist/cli/secret-notes.js +9 -1
- package/dist/cli/secret-notes.js.map +1 -1
- package/dist/cli/terminal.d.ts +10 -2
- package/dist/cli/terminal.d.ts.map +1 -1
- package/dist/cli/terminal.js +16 -4
- package/dist/cli/terminal.js.map +1 -1
- package/dist/client.d.ts +30 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +13 -1
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +76 -18
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +183 -53
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/agents.d.ts +2 -0
- package/dist/components/agents.d.ts.map +1 -1
- package/dist/components/agents.js +6 -5
- 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 +79 -36
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/categories.js +2 -2
- package/dist/components/categories.js.map +1 -1
- package/dist/components/comments.js +2 -2
- package/dist/components/comments.js.map +1 -1
- package/dist/components/decision-list.d.ts.map +1 -1
- package/dist/components/decision-list.js +5 -5
- package/dist/components/decision-list.js.map +1 -1
- package/dist/components/documents.d.ts.map +1 -1
- package/dist/components/documents.js +4 -4
- package/dist/components/documents.js.map +1 -1
- package/dist/components/event-feed.d.ts +2 -3
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +4 -184
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/goals.d.ts.map +1 -1
- package/dist/components/goals.js +3 -3
- package/dist/components/goals.js.map +1 -1
- package/dist/components/home.js +9 -9
- package/dist/components/home.js.map +1 -1
- package/dist/components/icon.d.ts.map +1 -1
- package/dist/components/icon.js +11 -2
- package/dist/components/icon.js.map +1 -1
- package/dist/components/notifications.d.ts +65 -0
- package/dist/components/notifications.d.ts.map +1 -0
- package/dist/components/notifications.js +162 -0
- package/dist/components/notifications.js.map +1 -0
- package/dist/components/pack-connect.js +1 -1
- package/dist/components/pack-connect.js.map +1 -1
- package/dist/components/pack-token.js +1 -1
- package/dist/components/pack-token.js.map +1 -1
- package/dist/components/people.js +2 -2
- package/dist/components/people.js.map +1 -1
- package/dist/components/pictures.js +1 -1
- package/dist/components/pictures.js.map +1 -1
- package/dist/components/plugin-settings.d.ts +22 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +63 -11
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.js +1 -1
- package/dist/components/projects.js.map +1 -1
- package/dist/components/roadmap.js +2 -2
- package/dist/components/roadmap.js.map +1 -1
- package/dist/components/rules.js +2 -2
- package/dist/components/rules.js.map +1 -1
- package/dist/components/runs.d.ts.map +1 -1
- package/dist/components/runs.js +1 -1
- package/dist/components/runs.js.map +1 -1
- package/dist/components/sessions.js +1 -1
- package/dist/components/sessions.js.map +1 -1
- package/dist/components/shell.d.ts +2 -0
- package/dist/components/shell.d.ts.map +1 -1
- package/dist/components/shell.js +1 -1
- package/dist/components/shell.js.map +1 -1
- package/dist/components/sign-in.js +2 -2
- package/dist/components/sign-in.js.map +1 -1
- package/dist/components/skills.d.ts.map +1 -1
- package/dist/components/skills.js +1 -1
- package/dist/components/skills.js.map +1 -1
- package/dist/components/task-view.d.ts +6 -0
- package/dist/components/task-view.d.ts.map +1 -1
- package/dist/components/task-view.js +3 -2
- package/dist/components/task-view.js.map +1 -1
- package/dist/components/tokens.js +1 -1
- package/dist/components/tokens.js.map +1 -1
- package/dist/components/ui.d.ts +21 -2
- package/dist/components/ui.d.ts.map +1 -1
- package/dist/components/ui.js +24 -3
- package/dist/components/ui.js.map +1 -1
- package/dist/components/work.js +1 -1
- package/dist/components/work.js.map +1 -1
- package/dist/console.css +506 -289
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +193 -16
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +17 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +31 -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 +5 -0
- package/dist/feed-words.d.ts.map +1 -0
- package/dist/feed-words.js +193 -0
- package/dist/feed-words.js.map +1 -0
- package/dist/i18n/en.d.ts +93 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +103 -15
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +105 -22
- package/dist/i18n/ko.js.map +1 -1
- package/dist/icons/glyphs.d.ts +370 -104
- package/dist/icons/glyphs.d.ts.map +1 -1
- package/dist/icons/glyphs.js +72 -66
- package/dist/icons/glyphs.js.map +1 -1
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/index.js +9 -1
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +7 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +7 -0
- package/dist/limits.js.map +1 -1
- package/dist/notifications.d.ts +124 -0
- package/dist/notifications.d.ts.map +1 -0
- package/dist/notifications.js +147 -0
- package/dist/notifications.js.map +1 -0
- package/dist/onboarding.d.ts.map +1 -1
- package/dist/onboarding.js +7 -12
- package/dist/onboarding.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 +10 -0
- package/dist/plugin/capabilities.js.map +1 -1
- package/dist/plugin/context.d.ts +85 -1
- 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/manifest.d.ts +8 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +13 -0
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +22 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +19 -3
- package/dist/plugin/rest-schemas.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/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/router.d.ts +6 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +5 -0
- package/dist/router.js.map +1 -1
- package/dist/routes.d.ts +2 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +2 -0
- package/dist/routes.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 +12 -97
- package/dist/runner/acp.js.map +1 -1
- package/dist/runner/browser.d.ts +50 -0
- package/dist/runner/browser.d.ts.map +1 -0
- package/dist/runner/browser.js +104 -0
- package/dist/runner/browser.js.map +1 -0
- package/dist/runner/claude.d.ts +1 -2
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +352 -13
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts +9 -10
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +809 -346
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/config.d.ts +14 -3
- package/dist/runner/config.d.ts.map +1 -1
- package/dist/runner/config.js +27 -7
- package/dist/runner/config.js.map +1 -1
- package/dist/runner/desk.d.ts +3 -1
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +17 -5
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/message.d.ts +53 -3
- package/dist/runner/message.d.ts.map +1 -1
- package/dist/runner/message.js +201 -20
- package/dist/runner/message.js.map +1 -1
- package/dist/runner/registry.d.ts +6 -0
- package/dist/runner/registry.d.ts.map +1 -1
- package/dist/runner/registry.js.map +1 -1
- package/dist/runner/rpc.d.ts +31 -0
- package/dist/runner/rpc.d.ts.map +1 -0
- package/dist/runner/rpc.js +102 -0
- package/dist/runner/rpc.js.map +1 -0
- package/dist/runner/runner.d.ts +41 -1
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +695 -52
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/slack.d.ts +17 -8
- package/dist/runner/slack.d.ts.map +1 -1
- package/dist/runner/slack.js +1250 -78
- package/dist/runner/slack.js.map +1 -1
- package/dist/runner/types.d.ts +160 -8
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js.map +1 -1
- package/dist/runner/usage.d.ts +105 -0
- package/dist/runner/usage.d.ts.map +1 -0
- package/dist/runner/usage.js +218 -0
- package/dist/runner/usage.js.map +1 -0
- 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 +673 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +205 -1
- package/dist/schemas.js.map +1 -1
- package/dist/services.js +3 -3
- package/dist/services.js.map +1 -1
- package/dist/setup-guide.d.ts +4 -3
- package/dist/setup-guide.d.ts.map +1 -1
- package/dist/setup-guide.js +11 -13
- package/dist/setup-guide.js.map +1 -1
- package/dist/text.d.ts +7 -0
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +18 -0
- package/dist/text.js.map +1 -1
- package/dist/vocabulary.d.ts +4 -2
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +4 -1
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +26 -19
- package/docs/specs/plugins.md +16 -10
- package/docs/specs/rest.md +28 -10
- package/docs/specs/runner.md +132 -44
- package/package.json +4 -4
- package/skills/building-a-console/SKILL.md +2 -2
- package/skills/building-a-console/references/configuring.md +1 -1
- package/skills/building-a-plugin/SKILL.md +4 -4
- package/skills/planning-the-board/SKILL.md +1 -1
- package/skills/planning-the-board/references/setting-up.md +2 -2
- package/skills/running-an-agent/SKILL.md +15 -64
- package/skills/running-an-agent/references/preparing-the-machine.md +17 -0
- package/skills/running-an-agent/references/several-tasks.md +37 -0
- package/skills/running-an-agent/references/slack-app.md +70 -13
- 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 +14 -0
- package/skills/working-the-board/SKILL.md +9 -12
- 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 +2 -2
- 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 +76 -47
- package/src/agent-usage.ts +113 -0
- package/src/api.ts +62 -0
- package/src/cli/cli.ts +634 -162
- package/src/cli/format.ts +190 -47
- package/src/cli/help.ts +77 -12
- package/src/cli/machine-check.ts +182 -29
- package/src/cli/pack.ts +81 -40
- package/src/cli/runner-host.ts +3 -0
- package/src/cli/secret-notes.ts +9 -1
- package/src/cli/terminal.ts +20 -4
- package/src/client.ts +94 -6
- package/src/components/agent-page.tsx +280 -63
- package/src/components/agents.tsx +23 -3
- package/src/components/calendar.tsx +93 -37
- package/src/components/categories.tsx +2 -2
- package/src/components/comments.tsx +5 -5
- package/src/components/decision-list.tsx +13 -10
- package/src/components/documents.tsx +13 -8
- package/src/components/event-feed.tsx +4 -203
- package/src/components/goals.tsx +6 -4
- package/src/components/home.tsx +12 -12
- package/src/components/icon.tsx +16 -3
- package/src/components/notifications.tsx +419 -0
- package/src/components/pack-connect.tsx +1 -1
- package/src/components/pack-token.tsx +5 -5
- package/src/components/people.tsx +3 -3
- package/src/components/pictures.tsx +1 -1
- package/src/components/plugin-settings.tsx +128 -23
- package/src/components/projects.tsx +1 -1
- package/src/components/roadmap.tsx +2 -2
- package/src/components/rules.tsx +2 -2
- package/src/components/runs.tsx +6 -3
- package/src/components/sessions.tsx +2 -2
- package/src/components/shell.tsx +3 -0
- package/src/components/sign-in.tsx +3 -3
- package/src/components/skills.tsx +5 -3
- package/src/components/task-view.tsx +18 -7
- package/src/components/tokens.tsx +2 -2
- package/src/components/ui.tsx +70 -5
- package/src/components/work.tsx +2 -2
- package/src/console.tsx +269 -12
- package/src/data.ts +54 -0
- package/src/desk-page.tsx +5 -5
- package/src/feed-words.ts +214 -0
- package/src/i18n/en.ts +114 -15
- package/src/i18n/ko.ts +115 -22
- package/src/icons/glyphs.ts +74 -68
- package/src/icons/index.ts +9 -1
- package/src/index.ts +11 -0
- package/src/limits.ts +7 -0
- package/src/notifications.ts +205 -0
- package/src/onboarding.ts +10 -14
- package/src/plugin/capabilities.ts +13 -0
- package/src/plugin/context.ts +87 -0
- package/src/plugin/limits.ts +7 -0
- package/src/plugin/manifest.ts +14 -0
- package/src/plugin/rest-schemas.ts +27 -3
- package/src/plugin/testing.ts +4 -0
- package/src/plugin.ts +2 -0
- package/src/router.ts +7 -0
- package/src/routes.ts +2 -0
- package/src/rules.ts +1 -1
- package/src/runner/acp.ts +12 -118
- package/src/runner/browser.ts +128 -0
- package/src/runner/claude.ts +399 -12
- package/src/runner/codex.ts +904 -400
- package/src/runner/config.ts +30 -7
- package/src/runner/desk.ts +22 -6
- package/src/runner/message.ts +251 -21
- package/src/runner/registry.ts +6 -0
- package/src/runner/rpc.ts +140 -0
- package/src/runner/runner.ts +863 -53
- package/src/runner/slack.ts +1535 -85
- package/src/runner/types.ts +150 -5
- package/src/runner/usage.ts +299 -0
- package/src/runner.ts +16 -1
- package/src/schemas.ts +249 -0
- package/src/services.ts +3 -3
- package/src/setup-guide.ts +12 -14
- package/src/styles/README.md +11 -7
- package/src/styles/console.css +2 -0
- package/src/styles/drawn-by-pages.json +7 -82
- package/src/styles/pages/agents.css +46 -35
- package/src/styles/pages/calendar.css +0 -1
- package/src/styles/pages/connect.css +0 -14
- package/src/styles/pages/decisions.css +2 -43
- package/src/styles/pages/documents.css +0 -29
- package/src/styles/pages/home.css +4 -16
- package/src/styles/pages/people.css +2 -17
- package/src/styles/pages/plugins.css +9 -12
- package/src/styles/pages/roadmap.css +0 -16
- package/src/styles/pages/settings.css +0 -28
- package/src/styles/pages/sign-in.css +2 -17
- package/src/styles/pages/thread.css +4 -50
- package/src/styles/pages/work.css +0 -5
- package/src/styles/parts/button.css +31 -0
- package/src/styles/parts/count.css +10 -0
- package/src/styles/parts/divider.css +17 -0
- package/src/styles/parts/frame.css +12 -0
- package/src/styles/parts/icon.css +39 -0
- package/src/styles/parts/menu.css +184 -0
- package/src/styles/parts/panel.css +7 -0
- package/src/styles/parts/progress.css +63 -0
- package/src/styles/parts/settings.css +2 -0
- package/src/styles/parts/sheet.css +28 -0
- package/src/styles/parts/text.css +34 -0
- package/src/text.ts +19 -0
- package/src/vocabulary.ts +4 -1
- package/template/plugin/package.json +1 -1
package/src/runner/types.ts
CHANGED
|
@@ -49,15 +49,66 @@ export type DriverEvent =
|
|
|
49
49
|
| { readonly type: "taken" }
|
|
50
50
|
/** A turn completed: the agent is done with what it was sent, and waits for more. */
|
|
51
51
|
| { readonly type: "turn_completed" }
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* How many sub-agents are at work in the background of the session, as the product lists
|
|
54
|
+
* them (ADR-0162): said as that changes, from the first that is. A driver whose product lists
|
|
55
|
+
* none says it never, and its sessions are waited for by their turns alone.
|
|
56
|
+
*/
|
|
57
|
+
| { readonly type: "background"; readonly agents: number }
|
|
58
|
+
/**
|
|
59
|
+
* The product began a turn, one it starts by itself to hand the agent what a sub-agent in
|
|
60
|
+
* the background did among them. Said once a sub-agent was said to be at work there.
|
|
61
|
+
*/
|
|
62
|
+
| { readonly type: "turn_started" }
|
|
63
|
+
/**
|
|
64
|
+
* The agent cannot go on: the model refused, or the product failed; with why, in the
|
|
65
|
+
* heartbeat's words. For a usage limit (`usage_limit`), `until` is when the product says the
|
|
66
|
+
* limit resets, where it says: the runner brings the agent back then by itself.
|
|
67
|
+
*/
|
|
53
68
|
| {
|
|
54
69
|
readonly type: "cannot_go_on";
|
|
55
70
|
readonly state: "refused" | "failed";
|
|
56
71
|
readonly reason: AgentStateReason;
|
|
72
|
+
readonly until?: number | undefined;
|
|
57
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* How much of what the product's subscription allows is used, as the product said it: a
|
|
76
|
+
* window each. Said whenever the product says so, and never by a driver whose product says
|
|
77
|
+
* nothing of it, of which the runner then knows nothing.
|
|
78
|
+
*/
|
|
79
|
+
| { readonly type: "usage"; readonly windows: readonly UsageWindow[] }
|
|
58
80
|
/** The product's process is gone: by itself, or mid-turn. Always the last. */
|
|
59
81
|
| { readonly type: "ended"; readonly how: "exited" | "crashed" };
|
|
60
82
|
|
|
83
|
+
/**
|
|
84
|
+
* A window of what a product's subscription allows, which resets: the short one and the week
|
|
85
|
+
* of Claude Code, say. Everything signed in with the subscription draws on it, a session and
|
|
86
|
+
* each of its sub-agents alike.
|
|
87
|
+
*/
|
|
88
|
+
export interface UsageWindow {
|
|
89
|
+
/** What the window is called, in a few plain words of the driver's for the product's own. */
|
|
90
|
+
readonly name: string;
|
|
91
|
+
/** How much of it is used, from 0 to 1; nothing where the product does not say. */
|
|
92
|
+
readonly used: number | undefined;
|
|
93
|
+
/** When it resets, in milliseconds since the epoch; nothing where the product does not say. */
|
|
94
|
+
readonly resetsAt: number | undefined;
|
|
95
|
+
/** Whether the product itself says the window is near its limit, whatever the share used. */
|
|
96
|
+
readonly near?: boolean | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the window is of a part of the allowance and not of the plan whole, one model's
|
|
99
|
+
* week say: the agent is told of it in words of its own, since its limit is that part's,
|
|
100
|
+
* and what it does about it is its own to decide.
|
|
101
|
+
*/
|
|
102
|
+
readonly part?: boolean | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the window is of a quota kept apart from the one the session draws on, another
|
|
105
|
+
* model's say, as the Codex driver reads a bucket other than the plan's: said on to the
|
|
106
|
+
* console as every window is, and told to the agent at no share of it, since nothing here
|
|
107
|
+
* knows that the session's requests are counted on it.
|
|
108
|
+
*/
|
|
109
|
+
readonly apart?: boolean | undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
61
112
|
/** A message for the agent: `now` stops the turn first, `next` goes after the tool call under way. */
|
|
62
113
|
export interface DriverMessage {
|
|
63
114
|
readonly text: string;
|
|
@@ -102,8 +153,8 @@ export interface StartOptions {
|
|
|
102
153
|
*/
|
|
103
154
|
readonly permissions?: string | undefined;
|
|
104
155
|
/**
|
|
105
|
-
* The
|
|
106
|
-
*
|
|
156
|
+
* The agent's browser, as `runner.json` names it; a driver that starts its product with none
|
|
157
|
+
* takes nothing of it.
|
|
107
158
|
*/
|
|
108
159
|
readonly browser?: string | undefined;
|
|
109
160
|
/**
|
|
@@ -236,12 +287,80 @@ export interface WakeSocket {
|
|
|
236
287
|
close(): void;
|
|
237
288
|
}
|
|
238
289
|
|
|
290
|
+
/**
|
|
291
|
+
* A part of a wake a source raises (ADR-0163): a line of the source's own, or what someone else
|
|
292
|
+
* wrote. The runner hands the agent each line under the session's mark and the words in a block
|
|
293
|
+
* of their own, so that nothing a message holds reads as a line of the source's. A line holds
|
|
294
|
+
* what the source says itself, an id and a moment among it, and never a word someone else wrote.
|
|
295
|
+
*/
|
|
296
|
+
export type WakePart = { readonly says: string } | { readonly words: string };
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* A wake as a wake source raises one: `parts` where the source says something itself, who wrote
|
|
300
|
+
* and where say, beside what was written; `text` where all of it is someone else's words.
|
|
301
|
+
*/
|
|
302
|
+
export type RaisedWake =
|
|
303
|
+
| { readonly key: string; readonly parts: readonly WakePart[] }
|
|
304
|
+
| { readonly key: string; readonly text: string };
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* What a source read of where one of its wakes was raised, for the account's own command
|
|
308
|
+
* (`console agent messages`): the parts to print, as a wake carries them, or why it read
|
|
309
|
+
* nothing, in a short name: `no_token` where the account keeps nothing to read with,
|
|
310
|
+
* `not_a_conversation` and `not_a_moment` where what was named is none, and otherwise the
|
|
311
|
+
* messenger's own word.
|
|
312
|
+
*/
|
|
313
|
+
export type WakeRead =
|
|
314
|
+
| { readonly ok: true; readonly parts: readonly WakePart[] }
|
|
315
|
+
| { readonly ok: false; readonly why: string };
|
|
316
|
+
|
|
317
|
+
/** An account at a source's messenger, as a message names whoever wrote it: by the messenger's ids for the workspace and the account. */
|
|
318
|
+
export interface WakeAccount {
|
|
319
|
+
readonly workspace: string;
|
|
320
|
+
readonly account: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Who an account at a messenger is to the agent, as the console says it (ADR-0164): `told` where
|
|
325
|
+
* the console is told the accounts of that workspace at all, and the member the account is, by
|
|
326
|
+
* their login, with what kind of member they are and whether they supervise the agent; `null`
|
|
327
|
+
* for an account that is no member's as far as the console is told. `administrator` and `line`
|
|
328
|
+
* say how: an administrator, and where in the agent's reporting line the member stands, its
|
|
329
|
+
* `manager`, anyone further `above`, a `report` of its own or anyone further `below`.
|
|
330
|
+
*/
|
|
331
|
+
export interface WakeWriter extends WakeAccount {
|
|
332
|
+
readonly told: boolean;
|
|
333
|
+
readonly member: {
|
|
334
|
+
readonly login: string | null;
|
|
335
|
+
readonly kind: "person" | "agent";
|
|
336
|
+
readonly supervisor: boolean;
|
|
337
|
+
readonly administrator?: boolean | undefined;
|
|
338
|
+
readonly line?: "manager" | "above" | "report" | "below" | null | undefined;
|
|
339
|
+
} | null;
|
|
340
|
+
}
|
|
341
|
+
|
|
239
342
|
/** What a wake source is given of the runner and of the machine. */
|
|
240
343
|
export interface WakeHost {
|
|
241
344
|
/** A secret of the account's store, by name; nothing where it keeps none. */
|
|
242
345
|
secret(name: string): Promise<string | undefined>;
|
|
243
|
-
/**
|
|
244
|
-
|
|
346
|
+
/**
|
|
347
|
+
* The channels `runner.json` names as ones the agent listens to, by the ids of the messenger
|
|
348
|
+
* they are of: what a person says in one wakes the agent, named or not.
|
|
349
|
+
*/
|
|
350
|
+
readonly channels: readonly string[];
|
|
351
|
+
/**
|
|
352
|
+
* Raises a wake: the console records it, and it reaches the agent in order, the source's own
|
|
353
|
+
* lines under the session's mark and everything else as someone else's words. Answers
|
|
354
|
+
* whether the console took it: a wake raised past what the console takes within an hour is
|
|
355
|
+
* let go, and reaches nobody.
|
|
356
|
+
*/
|
|
357
|
+
raise(wake: RaisedWake): Promise<boolean>;
|
|
358
|
+
/**
|
|
359
|
+
* What the source keeps from one run of its own to the next, under names of its own, for as
|
|
360
|
+
* long as the runner runs: a runner started again begins with nothing. Never a secret, and
|
|
361
|
+
* never a word of a message.
|
|
362
|
+
*/
|
|
363
|
+
readonly kept: Map<string, string>;
|
|
245
364
|
/** A line for whoever reads the runner's own output: never what a message says. */
|
|
246
365
|
log(line: string): void;
|
|
247
366
|
/**
|
|
@@ -260,6 +379,14 @@ export interface WakeHost {
|
|
|
260
379
|
socket(url: string): WakeSocket;
|
|
261
380
|
/** Waits so long, or less where the signal ends the wait. */
|
|
262
381
|
wait(ms: number, signal: AbortSignal): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Who accounts at the source's messenger are, as the console knows them (ADR-0164), in the
|
|
384
|
+
* order asked: the one way a source learns that an account is a member's, or a supervisor's.
|
|
385
|
+
* It is the console's answer to the account's own sign-in, and nothing a message, a name or
|
|
386
|
+
* the messenger says stands in for it. Left out, or rejecting, where the console says nothing
|
|
387
|
+
* of it, one older than this say: the source then says of an account what the messenger does.
|
|
388
|
+
*/
|
|
389
|
+
writers?(accounts: readonly WakeAccount[], signal: AbortSignal): Promise<readonly WakeWriter[]>;
|
|
263
390
|
}
|
|
264
391
|
|
|
265
392
|
/** A module that raises wakes from outside the console. `console`, the console's own stream of signals, is the runner's own. */
|
|
@@ -270,6 +397,24 @@ export interface WakeSource {
|
|
|
270
397
|
* source that ended is started again by the runner, after a while. `console` has none.
|
|
271
398
|
*/
|
|
272
399
|
run?(host: WakeHost, signal: AbortSignal): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Reads the latest of what was said where a wake of the source's was raised, named as the
|
|
402
|
+
* wake's key names it after the source's own name: for the account's own command, where a wake
|
|
403
|
+
* carried less than the agent needs. Left out by a source that reads nothing.
|
|
404
|
+
*/
|
|
405
|
+
read?(
|
|
406
|
+
host: Pick<WakeHost, "secret" | "fetch" | "writers">,
|
|
407
|
+
where: string,
|
|
408
|
+
options: {
|
|
409
|
+
/** How many of the latest messages are asked for, held to the source's own bounds; its own number where none is said. */
|
|
410
|
+
readonly limit?: number | undefined;
|
|
411
|
+
/** The moment of a message, as the messenger spells one: what was written after it alone is read. */
|
|
412
|
+
readonly after?: string | undefined;
|
|
413
|
+
/** The moment the read is asked at, in milliseconds since the epoch: how long ago a message was written is said by it. */
|
|
414
|
+
readonly now: number;
|
|
415
|
+
readonly signal: AbortSignal;
|
|
416
|
+
},
|
|
417
|
+
): Promise<WakeRead>;
|
|
273
418
|
}
|
|
274
419
|
|
|
275
420
|
/** What a service is told of the runner it keeps running. */
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { USAGE_KEPT_MS } from "../agent-usage.js";
|
|
2
|
+
import { MAX_RUNNER_USAGE_WINDOWS, MAX_USAGE_WINDOW_NAME_LENGTH } from "../limits.js";
|
|
3
|
+
import type { UsageWindow } from "./types.js";
|
|
4
|
+
|
|
5
|
+
// What the runner makes of its product's allowance (ADR-0150, docs/specs/runner.md, "A usage
|
|
6
|
+
// limit"): a subscription allows so much within a window that resets, and a product that has
|
|
7
|
+
// used it up answers nobody until then. The runner tells its agent before, at a share of the
|
|
8
|
+
// window it decides, and brings the agent back after, by itself. What a driver says of the
|
|
9
|
+
// allowance is the product's own, read by shape and bounded there; here it is numbers and a
|
|
10
|
+
// few words, and nothing of it is run.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The shares of a window at which the agent is told how much of it is used: with a fifth left,
|
|
14
|
+
* when there is still room to end what is under way in order, and with a tenth left, when what
|
|
15
|
+
* is said to people is said now. Each once for a window, until it resets.
|
|
16
|
+
*/
|
|
17
|
+
export const USAGE_MARKS = [0.8, 0.9] as const;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* How long after the moment a product says its limit resets the runner brings its agent back:
|
|
21
|
+
* the machine's clock and the product's differ by less.
|
|
22
|
+
*/
|
|
23
|
+
export const RESET_MARGIN_MS = 60_000;
|
|
24
|
+
|
|
25
|
+
/** How many windows the runner keeps what it told of: more than any product names. */
|
|
26
|
+
const MAX_WINDOWS = 16;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What a product's own error says when what its subscription allows is used up until a window
|
|
30
|
+
* resets. Its words are its own and no contract: read by pattern, of an error of the product
|
|
31
|
+
* alone and never of what a model or a tool wrote, and held by the fixtures of the drivers.
|
|
32
|
+
* Narrow on purpose: a request the server throttles for a moment and a conversation that
|
|
33
|
+
* reached its length are limits too, and neither is this one.
|
|
34
|
+
*/
|
|
35
|
+
const USAGE_LIMIT =
|
|
36
|
+
/\byou['\u2019]?ve (?:hit|reached) your ((?:[\w-]+ ){0,3})limit\b|\b(?:hit|reached) your (?:[\w-]+ ){0,2}usage limit\b|\busage limit (?:has been )?(?:reached|exceeded)\b|\busage_limit_reached\b/i;
|
|
37
|
+
/** What stands before "limit" in a limit that is another: a throttle, or a conversation's length. */
|
|
38
|
+
const ANOTHER_LIMIT = /\b(?:rate|request|context|token|output|length|size|message)\b/i;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether an error of a product's own says its usage limit is reached. Under a driver whose
|
|
42
|
+
* product names no reason, these words alone decide, and a limit read wrongly would be waited
|
|
43
|
+
* out for hours: "you've hit your rate limit" and "your context window limit" are not it.
|
|
44
|
+
*/
|
|
45
|
+
export const saysUsageLimit = (text: string): boolean => {
|
|
46
|
+
const found = USAGE_LIMIT.exec(text.slice(0, 2000));
|
|
47
|
+
return found !== null && !(found[1] !== undefined && ANOTHER_LIMIT.test(found[1]));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** What the agent was told of a window: the mark it had reached, and when that window resets. */
|
|
51
|
+
export interface ToldOfUsage {
|
|
52
|
+
readonly mark: number;
|
|
53
|
+
readonly resetsAt: number | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A window the agent is to be told of, with the mark it reached. */
|
|
57
|
+
export interface UsageTelling {
|
|
58
|
+
readonly window: UsageWindow;
|
|
59
|
+
readonly mark: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The mark a window has reached: the highest of `USAGE_MARKS` its share used is at or past; the
|
|
64
|
+
* first where the product says no share and says itself that the window is near its limit;
|
|
65
|
+
* none below the first, and none for a window used up, which the limit itself says.
|
|
66
|
+
*/
|
|
67
|
+
function markOf(window: UsageWindow): number | undefined {
|
|
68
|
+
if (window.used === undefined) {
|
|
69
|
+
return window.near === true ? USAGE_MARKS[0] : undefined;
|
|
70
|
+
}
|
|
71
|
+
if (window.used >= 1) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
let reached: number | undefined;
|
|
75
|
+
for (const mark of USAGE_MARKS) {
|
|
76
|
+
if (window.used >= mark) {
|
|
77
|
+
reached = mark;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return reached ?? (window.near === true ? USAGE_MARKS[0] : undefined);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Of what a product says of its windows, what the agent is to be told now, and what it then
|
|
85
|
+
* was told. A window is told once at each mark it reaches, at the highest alone where it passed
|
|
86
|
+
* several between two looks. What was told of a window stands until that window resets: until
|
|
87
|
+
* the moment it named has come and the product names a later one, or none, or its share is
|
|
88
|
+
* below the first mark again, so that a product whose reset moves with every look is told of
|
|
89
|
+
* once all the same. A moment that is past and named again is the same window still, a clock
|
|
90
|
+
* that runs ahead of the product's say: told of at every look, each telling would be a turn
|
|
91
|
+
* that spends the allowance it speaks of.
|
|
92
|
+
*/
|
|
93
|
+
export function usageToTell(
|
|
94
|
+
windows: readonly UsageWindow[],
|
|
95
|
+
told: ReadonlyMap<string, ToldOfUsage>,
|
|
96
|
+
now: number,
|
|
97
|
+
): { readonly tell: readonly UsageTelling[]; readonly told: Map<string, ToldOfUsage> } {
|
|
98
|
+
const next = new Map(told);
|
|
99
|
+
const tell: UsageTelling[] = [];
|
|
100
|
+
for (const window of windows) {
|
|
101
|
+
// A quota kept apart from the session's own is shown and tells nothing: see `UsageWindow.apart`.
|
|
102
|
+
if (window.apart === true) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const before = next.get(window.name);
|
|
106
|
+
const mark = markOf(window);
|
|
107
|
+
const reset =
|
|
108
|
+
before !== undefined &&
|
|
109
|
+
((before.resetsAt !== undefined &&
|
|
110
|
+
now >= before.resetsAt &&
|
|
111
|
+
(window.resetsAt === undefined || window.resetsAt > before.resetsAt)) ||
|
|
112
|
+
(window.used !== undefined && window.used < USAGE_MARKS[0] && window.near !== true));
|
|
113
|
+
if (reset) {
|
|
114
|
+
next.delete(window.name);
|
|
115
|
+
}
|
|
116
|
+
if (mark === undefined) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const stands = reset ? undefined : before;
|
|
120
|
+
if (stands !== undefined && stands.mark >= mark) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// The oldest is let go where a driver names more windows than any product has.
|
|
124
|
+
if (!next.has(window.name) && next.size >= MAX_WINDOWS) {
|
|
125
|
+
const oldest = next.keys().next().value;
|
|
126
|
+
if (oldest !== undefined) {
|
|
127
|
+
next.delete(oldest);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
next.set(window.name, { mark, resetsAt: window.resetsAt });
|
|
131
|
+
tell.push({ window, mark });
|
|
132
|
+
}
|
|
133
|
+
return { tell, told: next };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface NoticeOptions {
|
|
137
|
+
/** The session's mark. */
|
|
138
|
+
readonly mark: string;
|
|
139
|
+
/** A moment with its day: a window may reset, and a limit end, on another day. */
|
|
140
|
+
readonly moment: (iso: string) => string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What the runner says of its own, under a header that carries the session's mark. */
|
|
144
|
+
export const runnerSays = (mark: string, words: string): string =>
|
|
145
|
+
`[console ${mark} · runner]\n${words}`;
|
|
146
|
+
|
|
147
|
+
/** A name of a window on one line, with nothing in it that ends a header or a line. */
|
|
148
|
+
const plain = (text: string): string =>
|
|
149
|
+
text
|
|
150
|
+
.replaceAll(/[^\p{L}\p{N}._-]+/gu, " ")
|
|
151
|
+
.trim()
|
|
152
|
+
.slice(0, MAX_USAGE_WINDOW_NAME_LENGTH)
|
|
153
|
+
// Cut by its length in units, a letter of two may be cut in half: half a letter is no text.
|
|
154
|
+
.replace(/[\uD800-\uDBFF]$/u, "")
|
|
155
|
+
.trim();
|
|
156
|
+
|
|
157
|
+
/** A share as a whole number of hundredths, never more than was said: 0.899 is 89%. */
|
|
158
|
+
const percentOf = (share: number): number => Math.floor(Math.max(0, Math.min(1, share)) * 100);
|
|
159
|
+
|
|
160
|
+
/** One window as a line says it: how much of it is used, and when it resets where that is known. */
|
|
161
|
+
function windowWords(window: UsageWindow, moment: (iso: string) => string): string {
|
|
162
|
+
const share = window.used === undefined ? "near its limit" : `${percentOf(window.used)}% used`;
|
|
163
|
+
const resets =
|
|
164
|
+
window.resetsAt === undefined
|
|
165
|
+
? ""
|
|
166
|
+
: `, which resets ${moment(new Date(window.resetsAt).toISOString())}`;
|
|
167
|
+
return `${share} in its ${plain(window.name)} window${resets}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* What the agent is told of its product's allowance before the limit (ADR-0150): how much of
|
|
172
|
+
* which window is used, when it resets, and what the limit does, which is what there is to
|
|
173
|
+
* plan by. A window of a part of the allowance, one model's week, is said in a sentence of its
|
|
174
|
+
* own: what it counts is said, and nothing of what to do, since that limit is the model's and
|
|
175
|
+
* what the agent makes of it is its own to decide. The words of the line, without its header.
|
|
176
|
+
*/
|
|
177
|
+
export function usageWords(tell: readonly UsageTelling[], moment: (iso: string) => string): string {
|
|
178
|
+
const said = (which: readonly UsageTelling[]): string =>
|
|
179
|
+
which.map((one) => windowWords(one.window, moment)).join("; and ");
|
|
180
|
+
const whole = tell.filter((one) => one.window.part !== true);
|
|
181
|
+
const parts = tell.filter((one) => one.window.part === true);
|
|
182
|
+
const words: string[] = [];
|
|
183
|
+
if (whole.length > 0) {
|
|
184
|
+
words.push(
|
|
185
|
+
`Your product's allowance is ${said(whole)}. Everything signed in with it draws on it, each sub-agent you start too. At the limit your turn ends where it is and you answer nobody until the reset; the runner brings you back then by itself, with what reached you meanwhile. Nothing is asked of you now. Plan by it: where someone waits on you, or work would be cut in the middle, say so and leave it where you can pick it up, before then.`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (parts.length > 0) {
|
|
189
|
+
words.push(
|
|
190
|
+
`Your product's allowance for one model is ${said(parts)}. Requests to that model alone are counted on it, beside the plan's own windows. What you do about it is yours to decide.`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return words.join(" ");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A stretch a usage limit stopped the agent for: since when, and until when where the product said. */
|
|
197
|
+
export interface Limited {
|
|
198
|
+
readonly since: number;
|
|
199
|
+
readonly until: number | undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* What the agent is told when it is handed something again after a usage limit stopped it
|
|
204
|
+
* (ADR-0150), ahead of what reached it meanwhile: that it was stopped and from when, that its
|
|
205
|
+
* turn and its sub-agents ended where they were, and whether the limit is over. The words,
|
|
206
|
+
* without a header.
|
|
207
|
+
*/
|
|
208
|
+
export function limitWords(
|
|
209
|
+
limited: Limited,
|
|
210
|
+
options: {
|
|
211
|
+
readonly now: number;
|
|
212
|
+
readonly moment: (iso: string) => string;
|
|
213
|
+
/** How many signals follow in the message. */
|
|
214
|
+
readonly follow: number;
|
|
215
|
+
/** Whether this is a supervisor's signal tried before the runner's own try, with what else is kept left for then. */
|
|
216
|
+
readonly early?: boolean | undefined;
|
|
217
|
+
},
|
|
218
|
+
): string {
|
|
219
|
+
const at = (ms: number): string => options.moment(new Date(ms).toISOString());
|
|
220
|
+
const early = options.early === true;
|
|
221
|
+
const stopped = `Your product's usage limit stopped you at ${at(limited.since)}: your turn ended where it was, and so did every sub-agent it had started, since they draw on the one allowance.`;
|
|
222
|
+
const now = early
|
|
223
|
+
? `${limited.until === undefined ? "The product did not say when the limit resets" : `The product said the limit resets ${at(limited.until)}`}, and a supervisor's message is tried now all the same: where the limit still stands this is not read, and the runner hands it to you again when it brings you back.`
|
|
224
|
+
: limited.until === undefined
|
|
225
|
+
? `The product did not say when the limit resets, so the runner tries now, ${at(options.now)}, by itself.`
|
|
226
|
+
: `The limit reset ${at(limited.until)}, and the runner brings you back by itself.`;
|
|
227
|
+
const meanwhile = early
|
|
228
|
+
? "The message follows; what else reached you meanwhile is kept, and handed to you then."
|
|
229
|
+
: options.follow === 0
|
|
230
|
+
? "Nothing reached you meanwhile."
|
|
231
|
+
: "What reached you meanwhile follows, in the order it came, what you were handed as the limit was reached and had not read among it.";
|
|
232
|
+
return `${stopped} ${now} Go on with what you were doing: look at what each sub-agent left before you start it again. ${meanwhile}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** What the product last said of each window of its allowance, by the window's name, and when (ADR-0156). */
|
|
236
|
+
export type UsageSeen = Map<string, { readonly window: UsageWindow; readonly at: number }>;
|
|
237
|
+
|
|
238
|
+
/** A window as the console is told of it with the heartbeat. */
|
|
239
|
+
export interface UsageSaid {
|
|
240
|
+
readonly name: string;
|
|
241
|
+
readonly used: number | null;
|
|
242
|
+
readonly resetsAt: string | null;
|
|
243
|
+
readonly near?: true;
|
|
244
|
+
readonly at: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The first moment a console no longer reads as one: the year 10000, which a moment written out has no place for. */
|
|
248
|
+
const MOMENTS_END = Date.UTC(10_000, 0, 1);
|
|
249
|
+
|
|
250
|
+
/** A moment the console takes, or nothing: what a product says is its own, and one number out of range would cost the heartbeat. */
|
|
251
|
+
const momentOf = (ms: number | undefined): number | undefined =>
|
|
252
|
+
ms !== undefined && Number.isFinite(ms) && ms > 0 && ms < MOMENTS_END
|
|
253
|
+
? Math.floor(ms)
|
|
254
|
+
: undefined;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Notes what the product says of its windows, for the console to be told (ADR-0156). What a
|
|
258
|
+
* product says is sparse: a window it says nothing of this time stands as it was last said. As
|
|
259
|
+
* many windows are kept as a heartbeat carries, the first said, and one without a name is none.
|
|
260
|
+
*/
|
|
261
|
+
export function noteUsage(seen: UsageSeen, windows: readonly UsageWindow[], now: number): void {
|
|
262
|
+
for (const window of windows) {
|
|
263
|
+
const name = plain(window.name);
|
|
264
|
+
if (name.length === 0 || (!seen.has(name) && seen.size >= MAX_RUNNER_USAGE_WINDOWS)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
seen.set(name, { window, at: now });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The windows as the console is told of them with the heartbeat. One whose reset has passed is
|
|
273
|
+
* let go: what was said of it is of a window that is over, and the product says the next one
|
|
274
|
+
* when it is next asked. And so is one that names no reset and was last said longer ago than
|
|
275
|
+
* any window lasts: a product that changed what it counts, a plan without the short window
|
|
276
|
+
* say, says the old window no more, and what it once said of it would stand for good.
|
|
277
|
+
*/
|
|
278
|
+
export function usageSaid(seen: UsageSeen, now: number): UsageSaid[] {
|
|
279
|
+
const said: UsageSaid[] = [];
|
|
280
|
+
for (const [name, { window, at }] of [...seen]) {
|
|
281
|
+
const resetsAt = momentOf(window.resetsAt);
|
|
282
|
+
if (resetsAt === undefined ? now - at > USAGE_KEPT_MS : resetsAt <= now) {
|
|
283
|
+
seen.delete(name);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const used =
|
|
287
|
+
window.used === undefined || !Number.isFinite(window.used)
|
|
288
|
+
? null
|
|
289
|
+
: Math.max(0, Math.min(1, window.used));
|
|
290
|
+
said.push({
|
|
291
|
+
name,
|
|
292
|
+
used,
|
|
293
|
+
resetsAt: resetsAt === undefined ? null : new Date(resetsAt).toISOString(),
|
|
294
|
+
...(window.near === true ? { near: true as const } : {}),
|
|
295
|
+
at: new Date(at).toISOString(),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return said;
|
|
299
|
+
}
|
package/src/runner.ts
CHANGED
|
@@ -35,6 +35,8 @@ export {
|
|
|
35
35
|
MAX_GROUP_LENGTH,
|
|
36
36
|
MAX_GROUP_SIGNALS,
|
|
37
37
|
makeMark,
|
|
38
|
+
wakePartsOf,
|
|
39
|
+
wakeTextOf,
|
|
38
40
|
} from "./runner/message.js";
|
|
39
41
|
export { ownRunnerModules } from "./runner/modules.js";
|
|
40
42
|
export { createSpawn } from "./runner/process.js";
|
|
@@ -63,12 +65,20 @@ export {
|
|
|
63
65
|
HOLD_MS,
|
|
64
66
|
MAX_COOL_DOWN_MS,
|
|
65
67
|
MAX_HOLD_MS,
|
|
68
|
+
REPORT_MS,
|
|
66
69
|
type Runner,
|
|
67
70
|
type RunnerClient,
|
|
68
71
|
type RunnerOptions,
|
|
69
72
|
type RunnerState,
|
|
73
|
+
SUBAGENTS_MS,
|
|
70
74
|
} from "./runner/runner.js";
|
|
71
|
-
export {
|
|
75
|
+
export {
|
|
76
|
+
SLACK_APP_TOKEN,
|
|
77
|
+
SLACK_USER_TOKEN,
|
|
78
|
+
type SlackWake,
|
|
79
|
+
slack,
|
|
80
|
+
slackWakeOf,
|
|
81
|
+
} from "./runner/slack.js";
|
|
72
82
|
export { SYSTEMD_UNIT, systemdUnit, systemdUser } from "./runner/systemd-user.js";
|
|
73
83
|
export {
|
|
74
84
|
KEPT_LOGS,
|
|
@@ -91,15 +101,20 @@ export type {
|
|
|
91
101
|
Fact,
|
|
92
102
|
Picture,
|
|
93
103
|
Probe,
|
|
104
|
+
RaisedWake,
|
|
94
105
|
Service,
|
|
95
106
|
ServiceCommand,
|
|
96
107
|
ServiceInput,
|
|
97
108
|
ServicePlan,
|
|
98
109
|
Spawn,
|
|
99
110
|
StartOptions,
|
|
111
|
+
WakeAccount,
|
|
100
112
|
WakeHost,
|
|
113
|
+
WakePart,
|
|
114
|
+
WakeRead,
|
|
101
115
|
WakeSocket,
|
|
102
116
|
WakeSource,
|
|
117
|
+
WakeWriter,
|
|
103
118
|
} from "./runner/types.js";
|
|
104
119
|
export {
|
|
105
120
|
errorsShown,
|