@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/dist/runner/codex.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { connectionOf, METHOD_NOT_FOUND, RpcError } from "./rpc.js";
|
|
1
3
|
import { errorsShown, notStarted, plainCut, plainCutEnd, } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
import { saysUsageLimit } from "./usage.js";
|
|
5
|
+
// The `codex` driver (docs/specs/runner.md, ADR-0153): the Codex binary, unmodified, run as its
|
|
6
|
+
// app server, `codex app-server`: one process a session, spoken to over its standard input and
|
|
7
|
+
// output, a JSON-RPC message a line. A conversation is a thread of the product's, begun or gone
|
|
8
|
+
// on with when the session opens. A message starts a turn, and one that arrives while a turn
|
|
9
|
+
// runs is put into that turn (`turn/steer`), where the product reads it after the step under
|
|
10
|
+
// way; one that is to be read now stops the turn first.
|
|
7
11
|
//
|
|
8
|
-
// Written from
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// Written from the protocol as the binary itself writes it out (`codex app-server
|
|
13
|
+
// generate-ts`, 0.172.0), from the product's own source at that build, and from what the binary
|
|
14
|
+
// answered when it was spoken to signed out, 0.139.0, 0.167.0 and 0.172.0: a thread begun and
|
|
15
|
+
// gone on with, a turn started, a message put into it and said back, a turn stopped, a turn
|
|
16
|
+
// that failed for the sign-in, and what it refuses. A turn of a signed-in product, with its
|
|
17
|
+
// tools, is in the shapes of that protocol and was not seen run. Everything the product writes
|
|
18
|
+
// is data: read by shape, never run, and bounded by the runner before it is sent on.
|
|
19
|
+
/** The words the product is started with: its app server, on its standard input and output. */
|
|
20
|
+
const ARGUMENTS = ["app-server"];
|
|
21
|
+
/**
|
|
22
|
+
* The oldest build the driver speaks to: the first whose app server says a message back under
|
|
23
|
+
* the id it was handed over with, which is how the driver knows a message put into a turn was
|
|
24
|
+
* read. An older one has the app server and no such id: a message put into a turn there would
|
|
25
|
+
* be read and, never said back, handed over once more with the next turn.
|
|
26
|
+
*/
|
|
27
|
+
const OLDEST = [0, 139, 0];
|
|
28
|
+
/** How long a session that is stopped is given to end by itself, then after it was asked to. */
|
|
29
|
+
const STOP_GRACE_MS = 5000;
|
|
30
|
+
const KILL_GRACE_MS = 2000;
|
|
31
|
+
/** How long the product is given to open a conversation. */
|
|
32
|
+
const START_TIMEOUT_MS = 120_000;
|
|
14
33
|
/** How much of a tool's input a tool call shows. */
|
|
15
34
|
const MAX_INPUT_LENGTH = 4000;
|
|
16
35
|
/** How many models, and how many levels of effort, are read from the product's own list. */
|
|
@@ -18,17 +37,113 @@ const MAX_OFFERED = 50;
|
|
|
18
37
|
/** How much of its list of models is read: it carries each model's own instructions. */
|
|
19
38
|
const MAX_CATALOG_LENGTH = 8 * 1024 * 1024;
|
|
20
39
|
/**
|
|
21
|
-
* A word
|
|
22
|
-
*
|
|
23
|
-
* product's, or a setting beside the one it was meant for.
|
|
40
|
+
* A word the product is handed as one: a model, a level of effort, a conversation's id.
|
|
41
|
+
* Anything else is no such word, and is left out.
|
|
24
42
|
*/
|
|
25
43
|
const WORD = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
26
44
|
const word = (value) => typeof value === "string" && WORD.test(value) ? value : undefined;
|
|
27
45
|
/**
|
|
28
|
-
* What an error says when the product is not signed in or its login ran out
|
|
29
|
-
*
|
|
46
|
+
* What an error says when the product is not signed in or its login ran out, beside the status
|
|
47
|
+
* the service answered with. Seen signed out (0.172.0): `unexpected status 401 Unauthorized:
|
|
48
|
+
* Missing bearer or basic authentication in header`. The rest is read by pattern, and no contract.
|
|
30
49
|
*/
|
|
31
50
|
const SIGN_IN = /not (?:logged|signed) in|codex login|log ?in again|sign in again|\b401\b|unauthorized|token (?:has )?(?:expired|been revoked)|invalid (?:api )?key/i;
|
|
51
|
+
/**
|
|
52
|
+
* The build that answered, from what it calls itself when it is greeted: the client's name, a
|
|
53
|
+
* stroke, and its own version (`skillcdn-console-runner/0.171.0-alpha.13.2 (Windows ...)`, seen
|
|
54
|
+
* with that build). Nothing where it says none that reads as one.
|
|
55
|
+
*/
|
|
56
|
+
export function codexBuild(userAgent) {
|
|
57
|
+
const found = typeof userAgent === "string"
|
|
58
|
+
? /^[^/\s]{1,80}\/((\d{1,4})\.(\d{1,5})\.(\d{1,6})[0-9A-Za-z.+-]{0,40})(?:\s|$)/.exec(userAgent)
|
|
59
|
+
: null;
|
|
60
|
+
return found === null
|
|
61
|
+
? undefined
|
|
62
|
+
: { text: found[1] ?? "", numbers: [Number(found[2]), Number(found[3]), Number(found[4])] };
|
|
63
|
+
}
|
|
64
|
+
/** Whether a build is older than the oldest the driver speaks to. */
|
|
65
|
+
const tooOld = (numbers) => {
|
|
66
|
+
for (const [at, least] of OLDEST.entries()) {
|
|
67
|
+
const has = numbers[at] ?? 0;
|
|
68
|
+
if (has !== least) {
|
|
69
|
+
return has < least;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
/** The product's sandboxes, from the one that allows the least to the one that allows the most, by its word for each in an answer. */
|
|
75
|
+
const SANDBOXES = [
|
|
76
|
+
["readOnly", "read-only"],
|
|
77
|
+
["workspaceWrite", "workspace-write"],
|
|
78
|
+
["dangerFullAccess", "danger-full-access"],
|
|
79
|
+
];
|
|
80
|
+
/** The sandbox a mode asks for, in the product's word for it. */
|
|
81
|
+
const sandboxOf = (mode) => {
|
|
82
|
+
const asked = modeSettings(mode).sandbox;
|
|
83
|
+
return typeof asked === "string" ? asked : LEAST_MODE;
|
|
84
|
+
};
|
|
85
|
+
/** The bucket of the plan's own allowance, by the product's id for it (seen with 0.171.0). */
|
|
86
|
+
const PLAN_BUCKET = "codex";
|
|
87
|
+
/** How much of a bucket's name is said after a window's own. */
|
|
88
|
+
const MAX_BUCKET_NAME = 24;
|
|
89
|
+
/**
|
|
90
|
+
* The windows of the product's allowance, as it says them (`account/rateLimits/updated`): each
|
|
91
|
+
* with the share used and when it resets, named by how long it lasts. Seen with 0.171.0, asked
|
|
92
|
+
* of a signed-in product with no turn: a share in hundredths, a length in minutes and a moment
|
|
93
|
+
* in seconds (`{ usedPercent: 4, windowDurationMins: 10080, resetsAt: 1795927747 }`). An
|
|
94
|
+
* update is sparse: a window it says nothing of is not one that reset. An update is of one
|
|
95
|
+
* bucket, which it names (`limitId`): the plan's own is `codex`, and any other is a quota kept
|
|
96
|
+
* apart, one model's say, whose windows are said with the bucket's name after their own, so
|
|
97
|
+
* that an update of one is never read as the plan's.
|
|
98
|
+
*/
|
|
99
|
+
function allowanceOf(limits) {
|
|
100
|
+
const said = isObject(limits) ? limits : {};
|
|
101
|
+
const bucket = textOf(said.limitId);
|
|
102
|
+
const apart = bucket !== undefined && bucket !== PLAN_BUCKET;
|
|
103
|
+
// By the name the product shows for the bucket, or its id where it gives none: one line,
|
|
104
|
+
// and short, since the window's own name stands before it.
|
|
105
|
+
const called = (textOf(said.limitName) ?? "").replaceAll(/\s+/g, " ").trim();
|
|
106
|
+
const of = apart ? (called === "" ? bucket : called).slice(0, MAX_BUCKET_NAME) : "";
|
|
107
|
+
const windows = [];
|
|
108
|
+
for (const [place, one] of [
|
|
109
|
+
["primary", said.primary],
|
|
110
|
+
["secondary", said.secondary],
|
|
111
|
+
]) {
|
|
112
|
+
if (!isObject(one) || typeof one.usedPercent !== "number" || !(one.usedPercent >= 0)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const minutes = typeof one.windowDurationMins === "number" && one.windowDurationMins > 0
|
|
116
|
+
? Math.round(one.windowDurationMins)
|
|
117
|
+
: undefined;
|
|
118
|
+
const name = minutes === undefined
|
|
119
|
+
? place
|
|
120
|
+
: minutes === 10_080
|
|
121
|
+
? "weekly"
|
|
122
|
+
: minutes % 1440 === 0
|
|
123
|
+
? `${minutes / 1440}-day`
|
|
124
|
+
: minutes % 60 === 0
|
|
125
|
+
? `${minutes / 60}-hour`
|
|
126
|
+
: `${minutes}-minute`;
|
|
127
|
+
const resets = typeof one.resetsAt === "number" && one.resetsAt > 0 && one.resetsAt < 1e11
|
|
128
|
+
? Math.floor(one.resetsAt * 1000)
|
|
129
|
+
: undefined;
|
|
130
|
+
windows.push({
|
|
131
|
+
name: of === "" ? name : `${name} ${of}`,
|
|
132
|
+
used: Math.min(1, one.usedPercent / 100),
|
|
133
|
+
resetsAt: resets,
|
|
134
|
+
...(apart ? { apart } : {}),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return windows;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether a turn's error says that what the subscription allows is used up: the product's own
|
|
141
|
+
* word for it (`usageLimitExceeded`, as its protocol has it, not seen said), or its words.
|
|
142
|
+
*/
|
|
143
|
+
function usageLimited(error) {
|
|
144
|
+
const info = isObject(error) ? error.codexErrorInfo : undefined;
|
|
145
|
+
return info === "usageLimitExceeded" || saysUsageLimit(errorOf(error));
|
|
146
|
+
}
|
|
32
147
|
/** The product's words for what runs without asking: its three sandboxes, and the flag by which its own reviewer answers what a sandbox would ask. */
|
|
33
148
|
const MODES = ["read-only", "workspace-write", "approve-for-me", "danger-full-access"];
|
|
34
149
|
/**
|
|
@@ -51,72 +166,74 @@ export function codexMode(named) {
|
|
|
51
166
|
? UNATTENDED_MODE
|
|
52
167
|
: (MODES.find((mode) => mode === named) ?? LEAST_MODE);
|
|
53
168
|
}
|
|
169
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
170
|
+
const textOf = (value) => typeof value === "string" ? value : undefined;
|
|
54
171
|
/**
|
|
55
|
-
* A mode as the settings
|
|
56
|
-
*
|
|
57
|
-
* is asked of nobody: refused, or answered by the product's
|
|
172
|
+
* A mode as the settings a conversation is begun or gone on with, each said whole: a thread
|
|
173
|
+
* keeps what it last ran with, and one gone on with ran in whatever the desk named then.
|
|
174
|
+
* Whatever a mode does not allow is asked of nobody: refused, or answered by the product's
|
|
175
|
+
* reviewer.
|
|
58
176
|
*/
|
|
59
|
-
function
|
|
60
|
-
const set = (key, value) => ["-c", `${key}="${value}"`];
|
|
177
|
+
function modeSettings(mode) {
|
|
61
178
|
switch (mode) {
|
|
62
179
|
case "approve-for-me":
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
180
|
+
return {
|
|
181
|
+
sandbox: "workspace-write",
|
|
182
|
+
approvalPolicy: "on-request",
|
|
183
|
+
approvalsReviewer: "auto_review",
|
|
184
|
+
};
|
|
68
185
|
case "workspace-write":
|
|
69
186
|
case "danger-full-access":
|
|
70
|
-
return
|
|
187
|
+
return { sandbox: mode, approvalPolicy: "never", approvalsReviewer: "user" };
|
|
71
188
|
default:
|
|
72
|
-
return
|
|
189
|
+
return { sandbox: "read-only", approvalPolicy: "never", approvalsReviewer: "user" };
|
|
73
190
|
}
|
|
74
191
|
}
|
|
75
|
-
/** The arguments one turn of the product is started with. */
|
|
76
|
-
export function codexArguments(turn) {
|
|
77
|
-
const model = word(turn.model);
|
|
78
|
-
const effort = word(turn.effort);
|
|
79
|
-
const conversation = word(turn.conversation);
|
|
80
|
-
return [
|
|
81
|
-
"exec",
|
|
82
|
-
...(conversation === undefined ? [] : ["resume"]),
|
|
83
|
-
// A picture each under its own option, and before an option that takes nothing: the
|
|
84
|
-
// product's option takes several values, and would take what follows it for one.
|
|
85
|
-
...(turn.images ?? []).filter(isPicturePath).flatMap((path) => ["-i", path]),
|
|
86
|
-
"--json",
|
|
87
|
-
// The desk is the agent's own, a repository or not one yet.
|
|
88
|
-
"--skip-git-repo-check",
|
|
89
|
-
...modeArguments(codexMode(turn.permissions)),
|
|
90
|
-
...(model === undefined ? [] : ["-m", model]),
|
|
91
|
-
...(effort === undefined ? [] : ["-c", `model_reasoning_effort="${effort}"`]),
|
|
92
|
-
...(conversation === undefined ? [] : [conversation]),
|
|
93
|
-
// The message is read from the standard input.
|
|
94
|
-
"-",
|
|
95
|
-
];
|
|
96
|
-
}
|
|
97
192
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
193
|
+
* What the product is asked to keep to itself: a block as it grows, a piece at a time, where
|
|
194
|
+
* the driver reads whole blocks, and counts nobody asked for.
|
|
195
|
+
*/
|
|
196
|
+
const UNREAD = [
|
|
197
|
+
"thread/started",
|
|
198
|
+
"item/agentMessage/delta",
|
|
199
|
+
"item/reasoning/summaryTextDelta",
|
|
200
|
+
"item/reasoning/summaryPartAdded",
|
|
201
|
+
"item/reasoning/textDelta",
|
|
202
|
+
"item/commandExecution/outputDelta",
|
|
203
|
+
"item/fileChange/outputDelta",
|
|
204
|
+
"item/plan/delta",
|
|
205
|
+
"thread/tokenUsage/updated",
|
|
206
|
+
];
|
|
207
|
+
/** What the runner says of itself when it begins: nothing of the product's that is still an experiment is asked for. */
|
|
208
|
+
const hello = (version) => ({
|
|
209
|
+
clientInfo: {
|
|
210
|
+
name: "skillcdn-console-runner",
|
|
211
|
+
title: "SkillCDN Console runner",
|
|
212
|
+
version: version ?? "0.0.0",
|
|
213
|
+
},
|
|
214
|
+
capabilities: { experimentalApi: false, optOutNotificationMethods: UNREAD },
|
|
215
|
+
});
|
|
216
|
+
/**
|
|
217
|
+
* A path the product is handed as a picture: one the runner wrote under the desk's
|
|
218
|
+
* `work/inbox/`, and no other file of the machine.
|
|
100
219
|
*/
|
|
101
220
|
const PICTURE_PATH = /^work\/inbox\/[1-9]\d{0,15}\/([^/\\]{1,200})$/;
|
|
102
221
|
const isPicturePath = (path) => {
|
|
103
222
|
const name = PICTURE_PATH.exec(path)?.[1];
|
|
104
223
|
return name !== undefined && !/^\.+$/.test(name);
|
|
105
224
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
225
|
+
/**
|
|
226
|
+
* Messages as the input of a turn: what arrived together is read together, each under its own
|
|
227
|
+
* header, and every picture of it goes with it, as a file by its path in the desk.
|
|
228
|
+
*/
|
|
229
|
+
function inputOf(messages, desk) {
|
|
230
|
+
const root = desk.replace(/[\\/]+$/, "");
|
|
231
|
+
return [
|
|
232
|
+
{ type: "text", text: messages.map((message) => message.text).join("\n\n"), text_elements: [] },
|
|
233
|
+
...messages.flatMap((message) => message.images.flatMap((picture) => picture.path !== undefined && isPicturePath(picture.path)
|
|
234
|
+
? [{ type: "localImage", path: `${root}/${picture.path}` }]
|
|
235
|
+
: [])),
|
|
236
|
+
];
|
|
120
237
|
}
|
|
121
238
|
/** Anything as a line of text a person reads, bounded. */
|
|
122
239
|
function shown(value, cut) {
|
|
@@ -131,44 +248,62 @@ function shown(value, cut) {
|
|
|
131
248
|
}
|
|
132
249
|
}
|
|
133
250
|
/**
|
|
134
|
-
* What an error of the product says
|
|
135
|
-
*
|
|
251
|
+
* What an error of the product says: its message, with what it carries beside it. It may write
|
|
252
|
+
* the message as the answer of the service it asked, a line of JSON, where the service
|
|
253
|
+
* answered; the words are read out of it.
|
|
136
254
|
*/
|
|
137
|
-
function errorOf(
|
|
138
|
-
const
|
|
255
|
+
function errorOf(error) {
|
|
256
|
+
const said = isObject(error) ? error : {};
|
|
257
|
+
let message = textOf(said.message)?.trim() ?? "";
|
|
139
258
|
try {
|
|
140
|
-
const parsed = JSON.parse(
|
|
259
|
+
const parsed = JSON.parse(message);
|
|
141
260
|
if (isObject(parsed) && isObject(parsed.error) && typeof parsed.error.message === "string") {
|
|
142
|
-
|
|
261
|
+
message = parsed.error.message;
|
|
143
262
|
}
|
|
144
263
|
}
|
|
145
264
|
catch {
|
|
146
265
|
// Words, and not an answer of the service: said as they are.
|
|
147
266
|
}
|
|
148
|
-
|
|
267
|
+
const more = textOf(said.additionalDetails)?.trim() ?? "";
|
|
268
|
+
if (more.length === 0 || message.includes(more)) {
|
|
269
|
+
return message;
|
|
270
|
+
}
|
|
271
|
+
return message.length === 0 ? more : `${message}\n${more}`;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Whether an error says that the product is not signed in: in the product's own word for it,
|
|
275
|
+
* by the status the service refused it with, or in its words.
|
|
276
|
+
*/
|
|
277
|
+
function signedOut(error) {
|
|
278
|
+
const info = isObject(error) ? error.codexErrorInfo : undefined;
|
|
279
|
+
const refused = isObject(info) &&
|
|
280
|
+
Object.values(info).some((one) => isObject(one) && one.httpStatusCode === 401);
|
|
281
|
+
return info === "unauthorized" || refused || SIGN_IN.test(errorOf(error));
|
|
149
282
|
}
|
|
150
283
|
/** A tool call of the product, by the kind of item it writes for one: its name and its input as a line. */
|
|
151
284
|
function callOf(item, cut) {
|
|
152
285
|
switch (item.type) {
|
|
153
|
-
case "
|
|
286
|
+
case "commandExecution":
|
|
154
287
|
return { tool: "command_execution", text: shown(item.command ?? "", cut) };
|
|
155
|
-
case "
|
|
288
|
+
case "fileChange": {
|
|
156
289
|
const changes = Array.isArray(item.changes) ? item.changes : [];
|
|
157
290
|
return {
|
|
158
291
|
tool: "file_change",
|
|
159
292
|
text: cut(changes
|
|
160
293
|
.filter(isObject)
|
|
161
|
-
.map((change) =>
|
|
294
|
+
.map((change) => {
|
|
295
|
+
const kind = isObject(change.kind) ? textOf(change.kind.type) : textOf(change.kind);
|
|
296
|
+
return `${kind ?? "change"} ${textOf(change.path) ?? ""}`;
|
|
297
|
+
})
|
|
162
298
|
.join("\n"), MAX_INPUT_LENGTH),
|
|
163
299
|
};
|
|
164
300
|
}
|
|
165
|
-
|
|
166
|
-
case "mcp_tool_call":
|
|
301
|
+
case "mcpToolCall":
|
|
167
302
|
return {
|
|
168
303
|
tool: `${textOf(item.server) ?? "mcp"}.${textOf(item.tool) ?? "tool"}`,
|
|
169
304
|
text: item.arguments === undefined ? "" : shown(item.arguments, cut),
|
|
170
305
|
};
|
|
171
|
-
case "
|
|
306
|
+
case "webSearch":
|
|
172
307
|
return { tool: "web_search", text: shown(item.query ?? "", cut) };
|
|
173
308
|
default:
|
|
174
309
|
return undefined;
|
|
@@ -176,10 +311,10 @@ function callOf(item, cut) {
|
|
|
176
311
|
}
|
|
177
312
|
/** What came back from a tool call, where the product says: a command's output, or what a tool answered. */
|
|
178
313
|
function resultOf(item, cut) {
|
|
179
|
-
if (item.type === "
|
|
180
|
-
return textOf(item.
|
|
314
|
+
if (item.type === "commandExecution") {
|
|
315
|
+
return textOf(item.aggregatedOutput) ?? "";
|
|
181
316
|
}
|
|
182
|
-
if (item.type === "
|
|
317
|
+
if (item.type === "mcpToolCall") {
|
|
183
318
|
if (isObject(item.error) && typeof item.error.message === "string") {
|
|
184
319
|
return item.error.message;
|
|
185
320
|
}
|
|
@@ -187,146 +322,20 @@ function resultOf(item, cut) {
|
|
|
187
322
|
}
|
|
188
323
|
return "";
|
|
189
324
|
}
|
|
190
|
-
/** The events of one line of the product's output. `read` is what the lines before it left. */
|
|
191
|
-
function eventsOf(line, read, runs) {
|
|
192
|
-
const events = [];
|
|
193
|
-
const item = isObject(line.item) ? line.item : undefined;
|
|
194
|
-
switch (line.type) {
|
|
195
|
-
case "thread.started": {
|
|
196
|
-
// Written at the start of every turn: said on once, and again where it is something else.
|
|
197
|
-
const said = JSON.stringify([runs.model, runs.effort]);
|
|
198
|
-
const conversation = textOf(line.thread_id);
|
|
199
|
-
if (said !== read.runs) {
|
|
200
|
-
// The product names neither its model nor its version here: what it was asked for.
|
|
201
|
-
events.push({ type: "running", model: runs.model, effort: runs.effort, version: null });
|
|
202
|
-
}
|
|
203
|
-
if (conversation !== undefined && conversation !== read.conversation) {
|
|
204
|
-
events.push({ type: "conversation", id: conversation });
|
|
205
|
-
}
|
|
206
|
-
if (!read.began) {
|
|
207
|
-
events.push({
|
|
208
|
-
type: "event",
|
|
209
|
-
kind: "status",
|
|
210
|
-
text: "The product started.",
|
|
211
|
-
data: { model: runs.model, effort: runs.effort, version: null, mode: runs.mode },
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
read.began = true;
|
|
215
|
-
read.runs = said;
|
|
216
|
-
read.conversation = conversation ?? read.conversation;
|
|
217
|
-
return events;
|
|
218
|
-
}
|
|
219
|
-
case "item.started": {
|
|
220
|
-
const call = item === undefined ? undefined : callOf(item, read.cut);
|
|
221
|
-
const id = textOf(item?.id);
|
|
222
|
-
if (call !== undefined) {
|
|
223
|
-
events.push({
|
|
224
|
-
type: "event",
|
|
225
|
-
kind: "tool_call",
|
|
226
|
-
text: call.text,
|
|
227
|
-
data: { tool: call.tool, id: id ?? null },
|
|
228
|
-
});
|
|
229
|
-
if (id !== undefined) {
|
|
230
|
-
read.called.add(id);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return events;
|
|
234
|
-
}
|
|
235
|
-
case "item.completed": {
|
|
236
|
-
if (item === undefined) {
|
|
237
|
-
return events;
|
|
238
|
-
}
|
|
239
|
-
const id = textOf(item.id);
|
|
240
|
-
if (item.type === "agent_message" && typeof item.text === "string") {
|
|
241
|
-
events.push({ type: "event", kind: "assistant", text: item.text });
|
|
242
|
-
}
|
|
243
|
-
else if (item.type === "reasoning" && typeof item.text === "string") {
|
|
244
|
-
// As the product's documentation has it: none was written in the runs it was tried in.
|
|
245
|
-
events.push({ type: "event", kind: "thinking", text: item.text });
|
|
246
|
-
}
|
|
247
|
-
else if (item.type === "error") {
|
|
248
|
-
// A word of warning inside a turn: the turn goes on.
|
|
249
|
-
events.push({ type: "event", kind: "error", text: errorOf(item.message) });
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
const call = callOf(item, read.cut);
|
|
253
|
-
if (call === undefined) {
|
|
254
|
-
return events;
|
|
255
|
-
}
|
|
256
|
-
// A call the product wrote no beginning of is said with its end.
|
|
257
|
-
if (id === undefined || !read.called.delete(id)) {
|
|
258
|
-
events.push({
|
|
259
|
-
type: "event",
|
|
260
|
-
kind: "tool_call",
|
|
261
|
-
text: call.text,
|
|
262
|
-
data: { tool: call.tool, id: id ?? null },
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
if (item.type === "web_search") {
|
|
266
|
-
return events;
|
|
267
|
-
}
|
|
268
|
-
const exit = typeof item.exit_code === "number" ? item.exit_code : null;
|
|
269
|
-
const data = {
|
|
270
|
-
id: id ?? null,
|
|
271
|
-
error: item.status === "failed" || (exit !== null && exit !== 0),
|
|
272
|
-
};
|
|
273
|
-
if (exit !== null) {
|
|
274
|
-
data.exit = exit;
|
|
275
|
-
}
|
|
276
|
-
events.push({
|
|
277
|
-
type: "event",
|
|
278
|
-
kind: "tool_result",
|
|
279
|
-
text: resultOf(item, read.cut),
|
|
280
|
-
data,
|
|
281
|
-
pictures: [],
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return events;
|
|
285
|
-
}
|
|
286
|
-
case "turn.started":
|
|
287
|
-
// The turn's messages are the product's from here on: said once for each.
|
|
288
|
-
if (!read.turned) {
|
|
289
|
-
for (let taken = 0; taken < read.messages; taken += 1) {
|
|
290
|
-
events.push({ type: "taken" });
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
read.turned = true;
|
|
294
|
-
return events;
|
|
295
|
-
case "turn.completed":
|
|
296
|
-
read.completed = true;
|
|
297
|
-
return events;
|
|
298
|
-
case "turn.failed":
|
|
299
|
-
case "error": {
|
|
300
|
-
const said = errorOf(line.type === "error" ? line.message : isObject(line.error) ? line.error.message : "");
|
|
301
|
-
if (line.type === "turn.failed") {
|
|
302
|
-
read.failed = said;
|
|
303
|
-
}
|
|
304
|
-
// The product writes what failed a turn twice: as an error, and as the turn's failing.
|
|
305
|
-
if (said !== read.error) {
|
|
306
|
-
events.push({
|
|
307
|
-
type: "event",
|
|
308
|
-
kind: "error",
|
|
309
|
-
text: said.length === 0 ? "The turn ended with an error." : said,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
read.error = said;
|
|
313
|
-
return events;
|
|
314
|
-
}
|
|
315
|
-
default:
|
|
316
|
-
return events;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
325
|
const wait = (ms) => new Promise((resolve) => {
|
|
320
326
|
setTimeout(() => resolve("timeout"), ms).unref?.();
|
|
321
327
|
});
|
|
322
|
-
/** Ends a process:
|
|
328
|
+
/** Ends a process: its input closed first, then asked, then made to. */
|
|
323
329
|
async function endOf(child) {
|
|
324
|
-
child.
|
|
325
|
-
if ((await Promise.race([child.exited, wait(
|
|
326
|
-
child.kill("
|
|
330
|
+
child.end();
|
|
331
|
+
if ((await Promise.race([child.exited, wait(STOP_GRACE_MS)])) === "timeout") {
|
|
332
|
+
child.kill("SIGTERM");
|
|
333
|
+
if ((await Promise.race([child.exited, wait(KILL_GRACE_MS)])) === "timeout") {
|
|
334
|
+
child.kill("SIGKILL");
|
|
335
|
+
}
|
|
327
336
|
}
|
|
328
337
|
}
|
|
329
|
-
function sessionOf(host, options) {
|
|
338
|
+
function sessionOf(child, host, options) {
|
|
330
339
|
// What the session says, in order, for whoever reads it: until it ends.
|
|
331
340
|
const said = [];
|
|
332
341
|
let reader;
|
|
@@ -350,154 +359,607 @@ function sessionOf(host, options) {
|
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
361
|
}
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
runs: undefined,
|
|
356
|
-
conversation: undefined,
|
|
357
|
-
called: new Set(),
|
|
358
|
-
error: undefined,
|
|
359
|
-
completed: false,
|
|
360
|
-
failed: undefined,
|
|
361
|
-
turned: false,
|
|
362
|
-
messages: 0,
|
|
363
|
-
cut: options.cut ?? plainCut,
|
|
364
|
-
};
|
|
362
|
+
const cut = options.cut ?? plainCut;
|
|
363
|
+
const connection = connectionOf(child, { cut, header: false });
|
|
365
364
|
const mode = codexMode(options.permissions);
|
|
366
|
-
let conversation = word(options.resume);
|
|
367
365
|
let choice = { model: options.model, effort: options.effort };
|
|
368
|
-
/**
|
|
366
|
+
/** What the conversation runs with, as the product said it or as it was last asked. */
|
|
367
|
+
let runs = { model: null, effort: null };
|
|
368
|
+
let version = null;
|
|
369
|
+
/** The conversation, once it is open. */
|
|
370
|
+
let thread;
|
|
371
|
+
/** Whether the product answered at all, whether the conversation is open, and whether the session gave up or is being stopped. */
|
|
372
|
+
let began = false;
|
|
373
|
+
let ready = false;
|
|
374
|
+
let gaveUp = false;
|
|
375
|
+
let stopping = false;
|
|
376
|
+
/** Whether the product's output closed: nothing more reaches a process that is gone. */
|
|
377
|
+
let over = false;
|
|
369
378
|
let turn;
|
|
370
|
-
/** The messages
|
|
379
|
+
/** The messages the product was not handed yet: the next turn's, or the next put into the one under way. */
|
|
371
380
|
let waiting = [];
|
|
372
|
-
let
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
381
|
+
let handed = [];
|
|
382
|
+
/** Whether a request that hands messages over is on its way: they are handed over one request at a time, in order. */
|
|
383
|
+
let busy = false;
|
|
384
|
+
/** The tool calls said already, by the product's id for each. */
|
|
385
|
+
const called = new Set();
|
|
386
|
+
/** The last error said, which the product writes twice where a turn fails of it. */
|
|
387
|
+
let lastError;
|
|
388
|
+
/**
|
|
389
|
+
* Whether the product says a message back under the id it was handed over with: a build
|
|
390
|
+
* known to, or one that did. Until then none is put into a turn, since one that is read and
|
|
391
|
+
* never said back would be handed over again with the next turn.
|
|
392
|
+
*/
|
|
393
|
+
let saysBack = false;
|
|
394
|
+
/** The windows of the allowance as the product last said them, by name: an update says some of them. */
|
|
395
|
+
const allowance = new Map();
|
|
396
|
+
const taken = (count) => Array.from({ length: count }, () => ({ type: "taken" }));
|
|
397
|
+
const sayError = (words) => {
|
|
398
|
+
if (words !== lastError) {
|
|
399
|
+
emit({
|
|
400
|
+
type: "event",
|
|
401
|
+
kind: "error",
|
|
402
|
+
text: words.length === 0 ? "The turn ended with an error." : words,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
lastError = words;
|
|
406
|
+
};
|
|
407
|
+
/** Asks the product to stop a turn: once it said which turn it is. */
|
|
408
|
+
const interruptOf = (one) => {
|
|
409
|
+
if (one.id === undefined || thread === undefined) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
// Answered when the turn is over, which the product says by itself too.
|
|
413
|
+
void connection
|
|
414
|
+
.request("turn/interrupt", { threadId: thread, turnId: one.id })
|
|
415
|
+
.catch(() => undefined);
|
|
416
|
+
};
|
|
417
|
+
const stopTurn = (why) => {
|
|
418
|
+
if (turn === undefined || turn.cut !== undefined) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
turn.cut = why;
|
|
422
|
+
interruptOf(turn);
|
|
423
|
+
};
|
|
424
|
+
/** Starts a turn with what waited: one message, each part under its own header. */
|
|
425
|
+
const start = async (messages) => {
|
|
426
|
+
const mine = { id: undefined, cut: undefined, steers: true };
|
|
427
|
+
const entry = { id: host.uuid(), messages, steered: false };
|
|
393
428
|
turn = mine;
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
429
|
+
handed.push(entry);
|
|
430
|
+
lastError = undefined;
|
|
431
|
+
// Said with the turn, and kept by the conversation from then on. A choice left at the
|
|
432
|
+
// product's own is not said: the conversation goes on with what it ran with.
|
|
433
|
+
const model = word(choice.model);
|
|
434
|
+
const effort = word(choice.effort);
|
|
435
|
+
if ((model !== undefined && model !== runs.model) ||
|
|
436
|
+
(effort !== undefined && effort !== runs.effort)) {
|
|
437
|
+
runs = { model: model ?? runs.model, effort: effort ?? runs.effort };
|
|
438
|
+
emit({ type: "running", model: runs.model, effort: runs.effort, version });
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const result = await connection.request("turn/start", {
|
|
442
|
+
threadId: thread ?? "",
|
|
443
|
+
clientUserMessageId: entry.id,
|
|
444
|
+
input: inputOf(messages, options.cwd),
|
|
445
|
+
...(model === undefined ? {} : { model }),
|
|
446
|
+
...(effort === undefined ? {} : { effort }),
|
|
447
|
+
});
|
|
448
|
+
if (turn === mine) {
|
|
449
|
+
mine.id ??= isObject(result) && isObject(result.turn) ? textOf(result.turn.id) : undefined;
|
|
450
|
+
// A stop that was asked before the product named the turn is said now.
|
|
451
|
+
if (mine.cut !== undefined) {
|
|
452
|
+
interruptOf(mine);
|
|
409
453
|
}
|
|
410
454
|
}
|
|
411
|
-
|
|
412
|
-
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
if (turn === mine) {
|
|
458
|
+
turn = undefined;
|
|
413
459
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
460
|
+
handed = handed.filter((one) => one !== entry);
|
|
461
|
+
if (!(error instanceof RpcError)) {
|
|
462
|
+
// The process is gone: how it ended is said where its output ends.
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
emit({
|
|
466
|
+
type: "event",
|
|
467
|
+
kind: "error",
|
|
468
|
+
text: `The product refused the turn: ${error.message}`,
|
|
469
|
+
});
|
|
470
|
+
if (SIGN_IN.test(error.message)) {
|
|
471
|
+
// Nothing was taken: the runner sends again what it sent.
|
|
472
|
+
waiting = [];
|
|
473
|
+
handed = [];
|
|
474
|
+
emit({ type: "cannot_go_on", state: "failed", reason: "sign_in" });
|
|
418
475
|
return;
|
|
419
476
|
}
|
|
420
|
-
|
|
477
|
+
// A turn the product itself refused is a turn that ended: it takes the next message.
|
|
478
|
+
emit(...taken(messages.length));
|
|
479
|
+
done();
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Puts a message into the turn under way. The product answers that it was put in, and says
|
|
484
|
+
* the message back when it reads it, after the step under way: that is when it is taken.
|
|
485
|
+
*/
|
|
486
|
+
const steer = async (message, into) => {
|
|
487
|
+
const entry = { id: host.uuid(), messages: [message], steered: true };
|
|
488
|
+
handed.push(entry);
|
|
489
|
+
try {
|
|
490
|
+
await connection.request("turn/steer", {
|
|
491
|
+
threadId: thread ?? "",
|
|
492
|
+
expectedTurnId: into.id ?? "",
|
|
493
|
+
clientUserMessageId: entry.id,
|
|
494
|
+
input: inputOf([message], options.cwd),
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
catch {
|
|
498
|
+
// Not put in: the turn is over, or is one a message is put into none of. It waits for
|
|
499
|
+
// the turn's end, first of what waits, unless that end came first and has it wait already.
|
|
500
|
+
into.steers = false;
|
|
501
|
+
if (handed.includes(entry)) {
|
|
502
|
+
handed = handed.filter((one) => one !== entry);
|
|
503
|
+
waiting.unshift(message);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
/** Hands over what waits, one request at a time: a turn started, or a message put into the one under way. */
|
|
508
|
+
const pump = () => {
|
|
509
|
+
if (busy || !ready || gaveUp || stopping || over) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const head = waiting[0];
|
|
513
|
+
if (head === undefined) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const after = () => {
|
|
517
|
+
busy = false;
|
|
518
|
+
pump();
|
|
519
|
+
};
|
|
520
|
+
if (turn === undefined) {
|
|
521
|
+
busy = true;
|
|
522
|
+
void start(waiting.splice(0)).finally(after);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
// A turn that is being stopped, or takes no message, is waited for: its end hands over.
|
|
526
|
+
// So is a turn of a product that has not yet said a message back.
|
|
527
|
+
if (turn.cut !== undefined || !turn.steers || turn.id === undefined || !saysBack) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
busy = true;
|
|
531
|
+
waiting.shift();
|
|
532
|
+
void steer(head, turn).finally(after);
|
|
533
|
+
};
|
|
534
|
+
/** A turn ended: the agent is done when nothing it was sent still waits. */
|
|
535
|
+
const done = () => {
|
|
536
|
+
// A session that is being stopped says nothing more of a turn: what it was handed and
|
|
537
|
+
// did not take is the runner's to settle, and a turn said completed here would have the
|
|
538
|
+
// runner count as read what the product never got.
|
|
539
|
+
if (stopping) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (waiting.length > 0) {
|
|
543
|
+
pump();
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
emit({ type: "turn_completed" });
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
/** The product said a message back: it read it, and the message is taken. */
|
|
550
|
+
const took = (id) => {
|
|
551
|
+
const entry = handed.find((one) => one.id === id);
|
|
552
|
+
if (entry !== undefined) {
|
|
553
|
+
saysBack = true;
|
|
554
|
+
handed = handed.filter((one) => one !== entry);
|
|
555
|
+
emit(...taken(entry.messages.length));
|
|
556
|
+
}
|
|
557
|
+
// The message a turn began with, said back: the turn is under way, and what waited for
|
|
558
|
+
// the product to say one back is put into it now.
|
|
559
|
+
pump();
|
|
560
|
+
};
|
|
561
|
+
const onItem = (params, completed) => {
|
|
562
|
+
const item = isObject(params.item) ? params.item : undefined;
|
|
563
|
+
if (item === undefined) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const id = textOf(item.id);
|
|
567
|
+
if (item.type === "userMessage") {
|
|
568
|
+
took(textOf(item.clientId));
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (!completed) {
|
|
572
|
+
const call = callOf(item, cut);
|
|
573
|
+
if (call !== undefined) {
|
|
421
574
|
emit({
|
|
422
575
|
type: "event",
|
|
423
|
-
kind: "
|
|
424
|
-
text:
|
|
425
|
-
|
|
426
|
-
: "The turn was stopped.",
|
|
576
|
+
kind: "tool_call",
|
|
577
|
+
text: call.text,
|
|
578
|
+
data: { tool: call.tool, id: id ?? null },
|
|
427
579
|
});
|
|
580
|
+
if (id !== undefined) {
|
|
581
|
+
called.add(id);
|
|
582
|
+
}
|
|
428
583
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
if (item.type === "agentMessage") {
|
|
587
|
+
if (typeof item.text === "string" && item.text.length > 0) {
|
|
588
|
+
emit({ type: "event", kind: "assistant", text: item.text });
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (item.type === "reasoning") {
|
|
593
|
+
const parts = [item.summary, item.content].flatMap((one) => Array.isArray(one) ? one.filter((part) => typeof part === "string") : []);
|
|
594
|
+
if (parts.length > 0) {
|
|
595
|
+
emit({ type: "event", kind: "thinking", text: parts.join("\n\n") });
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const call = callOf(item, cut);
|
|
600
|
+
if (call === undefined) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
// A call the product wrote no beginning of is said with its end.
|
|
604
|
+
if (id === undefined || !called.delete(id)) {
|
|
605
|
+
emit({
|
|
606
|
+
type: "event",
|
|
607
|
+
kind: "tool_call",
|
|
608
|
+
text: call.text,
|
|
609
|
+
data: { tool: call.tool, id: id ?? null },
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (item.type === "webSearch") {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const exit = typeof item.exitCode === "number" ? item.exitCode : null;
|
|
616
|
+
const data = {
|
|
617
|
+
id: id ?? null,
|
|
618
|
+
// Declined is the product's word for a call its sandbox or its reviewer did not let run.
|
|
619
|
+
error: item.status === "failed" || item.status === "declined" || (exit !== null && exit !== 0),
|
|
620
|
+
};
|
|
621
|
+
if (exit !== null) {
|
|
622
|
+
data.exit = exit;
|
|
623
|
+
}
|
|
624
|
+
emit({ type: "event", kind: "tool_result", text: resultOf(item, cut), data, pictures: [] });
|
|
625
|
+
};
|
|
626
|
+
const onTurnCompleted = (params) => {
|
|
627
|
+
const ended = isObject(params.turn) ? params.turn : {};
|
|
628
|
+
const id = textOf(ended.id);
|
|
629
|
+
if (turn === undefined || (turn.id !== undefined && id !== undefined && turn.id !== id)) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
const mine = turn;
|
|
633
|
+
turn = undefined;
|
|
634
|
+
called.clear();
|
|
635
|
+
if (stopping) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
// What the product did not say it took. A turn began with its first message, which is the
|
|
639
|
+
// product's from then on. One put into the turn and never said back was not read: the
|
|
640
|
+
// product lets go of it where the turn is stopped first (seen with 0.139.0), so it is the
|
|
641
|
+
// next turn's, before whatever else waits.
|
|
642
|
+
const again = [];
|
|
643
|
+
for (const one of handed) {
|
|
644
|
+
if (one.steered) {
|
|
645
|
+
again.push(...one.messages);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
emit(...taken(one.messages.length));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
handed = [];
|
|
652
|
+
waiting = [...again, ...waiting];
|
|
653
|
+
if (ended.status === "failed") {
|
|
654
|
+
sayError(errorOf(ended.error));
|
|
655
|
+
if (signedOut(ended.error)) {
|
|
656
|
+
// The runner sends again what it sent, once the product is signed in.
|
|
432
657
|
waiting = [];
|
|
658
|
+
emit({ type: "cannot_go_on", state: "failed", reason: "sign_in" });
|
|
433
659
|
return;
|
|
434
660
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
661
|
+
if (usageLimited(ended.error)) {
|
|
662
|
+
// Nothing goes better before a window resets: the runner waits, brings the agent back
|
|
663
|
+
// by itself, and hands over again what was not answered. Until when is the reset of
|
|
664
|
+
// the window the product last said is used up, where it said one.
|
|
665
|
+
const resets = [...allowance.values()]
|
|
666
|
+
.filter((window) => window.used !== undefined && window.used >= 1)
|
|
667
|
+
.flatMap((window) => (window.resetsAt === undefined ? [] : [window.resetsAt]));
|
|
668
|
+
waiting = [];
|
|
669
|
+
emit({
|
|
670
|
+
type: "cannot_go_on",
|
|
671
|
+
state: "failed",
|
|
672
|
+
reason: "usage_limit",
|
|
673
|
+
...(resets.length === 0 ? {} : { until: Math.max(...resets) }),
|
|
674
|
+
});
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
// A turn the product itself said failed is a turn that ended: the agent takes the next message.
|
|
678
|
+
}
|
|
679
|
+
else if (ended.status === "interrupted") {
|
|
680
|
+
emit({
|
|
681
|
+
type: "event",
|
|
682
|
+
kind: "status",
|
|
683
|
+
text: mine.cut === "message" ? "The turn was stopped for a message." : "The turn was stopped.",
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
done();
|
|
687
|
+
};
|
|
688
|
+
const onNotification = (method, params) => {
|
|
689
|
+
// The allowance is the account's, and of no thread: said on as the product says it, for
|
|
690
|
+
// the runner to tell its agent by.
|
|
691
|
+
if (method === "account/rateLimits/updated") {
|
|
692
|
+
// Said on where it says something new: the product writes it several times a turn
|
|
693
|
+
// (seen with 0.171.0, six times in a turn of one command, the same each time).
|
|
694
|
+
const windows = allowanceOf(params.rateLimits).filter((window) => {
|
|
695
|
+
const before = allowance.get(window.name);
|
|
696
|
+
return before?.used !== window.used || before?.resetsAt !== window.resetsAt;
|
|
697
|
+
});
|
|
698
|
+
for (const window of windows) {
|
|
699
|
+
allowance.set(window.name, window);
|
|
700
|
+
}
|
|
701
|
+
if (windows.length > 0 && !stopping) {
|
|
702
|
+
emit({ type: "usage", windows });
|
|
703
|
+
}
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
// A thread of the product's other than the conversation's is none of the session's: what
|
|
707
|
+
// an agent it started does there is that agent's, and its turns are not this one's.
|
|
708
|
+
if (thread === undefined || params.threadId !== thread) {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
switch (method) {
|
|
712
|
+
case "turn/started": {
|
|
713
|
+
const id = isObject(params.turn) ? textOf(params.turn.id) : undefined;
|
|
714
|
+
if (turn === undefined) {
|
|
715
|
+
// A turn the product began by itself: a message that arrives now is put into it.
|
|
716
|
+
turn = { id, cut: undefined, steers: true };
|
|
717
|
+
pump();
|
|
450
718
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
// goes better, a conversation it cannot find again say (seen with 0.164.0), so the
|
|
454
|
-
// agent cannot go on by itself. Before a turn started nothing was taken, and the
|
|
455
|
-
// runner sends again what it sent; after, what the turn was at is not known.
|
|
456
|
-
emit({
|
|
457
|
-
type: "cannot_go_on",
|
|
458
|
-
state: "failed",
|
|
459
|
-
reason: read.turned ? "crashed" : "start",
|
|
460
|
-
});
|
|
461
|
-
waiting = [];
|
|
462
|
-
return;
|
|
719
|
+
else {
|
|
720
|
+
turn.id ??= id;
|
|
463
721
|
}
|
|
464
|
-
|
|
722
|
+
return;
|
|
465
723
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
724
|
+
case "turn/completed":
|
|
725
|
+
onTurnCompleted(params);
|
|
726
|
+
return;
|
|
727
|
+
case "item/started":
|
|
728
|
+
onItem(params, false);
|
|
729
|
+
return;
|
|
730
|
+
case "item/completed":
|
|
731
|
+
onItem(params, true);
|
|
732
|
+
return;
|
|
733
|
+
case "error":
|
|
734
|
+
// A word of warning inside a turn, a try that is made again say: the turn goes on, and
|
|
735
|
+
// says by itself where it ends of one.
|
|
736
|
+
sayError(errorOf(params.error));
|
|
737
|
+
return;
|
|
738
|
+
default:
|
|
739
|
+
// Whatever else it writes, how the thread stands, what it plans, what its reviewer
|
|
740
|
+
// found, is left where it is.
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
/** What the product asks of whoever is at its terminal: nobody is, so it is refused and recorded. */
|
|
745
|
+
const onRequest = (id, method, params) => {
|
|
746
|
+
const denied = (tool, what, answer) => {
|
|
747
|
+
const data = { tool, answer: "denied" };
|
|
748
|
+
const item = textOf(params.itemId);
|
|
749
|
+
if (item !== undefined) {
|
|
750
|
+
data.id = item;
|
|
471
751
|
}
|
|
472
|
-
|
|
473
|
-
|
|
752
|
+
emit({
|
|
753
|
+
type: "event",
|
|
754
|
+
kind: "permission",
|
|
755
|
+
text: `Denied, with nobody at the terminal to ask: ${cut(what, MAX_INPUT_LENGTH)}`,
|
|
756
|
+
data,
|
|
757
|
+
});
|
|
758
|
+
void connection.answer(id, answer).catch(() => undefined);
|
|
759
|
+
};
|
|
760
|
+
const reason = textOf(params.reason)?.trim();
|
|
761
|
+
switch (method) {
|
|
762
|
+
case "item/commandExecution/requestApproval":
|
|
763
|
+
denied("command_execution", textOf(params.command) ?? reason ?? "a command", {
|
|
764
|
+
decision: "decline",
|
|
765
|
+
});
|
|
766
|
+
return;
|
|
767
|
+
case "item/fileChange/requestApproval":
|
|
768
|
+
denied("file_change", reason ?? "a change to files", { decision: "decline" });
|
|
769
|
+
return;
|
|
770
|
+
case "item/permissions/requestApproval":
|
|
771
|
+
// Leave to do more than the mode allows: none is given.
|
|
772
|
+
denied("permissions", reason ?? "more than the mode allows", {
|
|
773
|
+
permissions: {},
|
|
774
|
+
scope: "turn",
|
|
775
|
+
});
|
|
776
|
+
return;
|
|
777
|
+
case "item/tool/requestUserInput":
|
|
778
|
+
denied("request_user_input", "a question for a person", { answers: {} });
|
|
779
|
+
return;
|
|
780
|
+
case "mcpServer/elicitation/request":
|
|
781
|
+
denied(`${textOf(params.serverName) ?? "mcp"}.elicitation`, textOf(params.message) ?? "a question for a person", { action: "decline", content: null, _meta: null });
|
|
782
|
+
return;
|
|
783
|
+
default:
|
|
784
|
+
// No tool and no sign-in of the runner's own was offered: a product that asks for one
|
|
785
|
+
// all the same is told.
|
|
786
|
+
void connection
|
|
787
|
+
.refuse(id, METHOD_NOT_FOUND, `${method} is not offered`)
|
|
788
|
+
.catch(() => undefined);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
/** Why the conversation could not open, said once; the process is ended, and nothing more is said of it. */
|
|
792
|
+
const cannotStart = (text, reason) => {
|
|
793
|
+
gaveUp = true;
|
|
794
|
+
waiting = [];
|
|
795
|
+
emit({ type: "event", kind: "error", text }, { type: "cannot_go_on", state: "failed", reason });
|
|
796
|
+
void endOf(child);
|
|
797
|
+
};
|
|
798
|
+
const open = async () => {
|
|
799
|
+
const greeted = await connection.request("initialize", hello(host.version));
|
|
800
|
+
began = true;
|
|
801
|
+
// The build that runs, from what it calls itself: a conversation says the build that began
|
|
802
|
+
// it, which is another once the product was updated.
|
|
803
|
+
const build = codexBuild(isObject(greeted) ? greeted.userAgent : undefined);
|
|
804
|
+
version = build?.text ?? null;
|
|
805
|
+
if (build !== undefined && tooOld(build.numbers)) {
|
|
806
|
+
cannotStart(`This Codex is ${build.text}, and the driver speaks to ${OLDEST.join(".")} or later, whose app server says a message back when it reads it. Update it, as it was installed.`, "start");
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
// A build that says which it is, and is none of the old ones, says a message back; one
|
|
810
|
+
// that says nothing of itself is believed once it did.
|
|
811
|
+
saysBack = build !== undefined;
|
|
812
|
+
await connection.notify("initialized");
|
|
813
|
+
const model = word(choice.model);
|
|
814
|
+
const settings = {
|
|
815
|
+
cwd: options.cwd,
|
|
816
|
+
...modeSettings(mode),
|
|
817
|
+
...(model === undefined ? {} : { model }),
|
|
818
|
+
};
|
|
819
|
+
let opened;
|
|
820
|
+
const resume = word(options.resume);
|
|
821
|
+
if (resume !== undefined) {
|
|
822
|
+
try {
|
|
823
|
+
// Gone on with, without its history said again: nobody reads it here.
|
|
824
|
+
opened = await connection
|
|
825
|
+
.request("thread/resume", { threadId: resume, ...settings, excludeTurns: true })
|
|
826
|
+
.catch((error) => {
|
|
827
|
+
// A build that takes that word only as an experiment (0.139.0) is asked without it.
|
|
828
|
+
if (error instanceof RpcError && error.message.includes("excludeTurns")) {
|
|
829
|
+
return connection.request("thread/resume", { threadId: resume, ...settings });
|
|
830
|
+
}
|
|
831
|
+
throw error;
|
|
832
|
+
});
|
|
474
833
|
}
|
|
475
|
-
|
|
834
|
+
catch (error) {
|
|
835
|
+
// Not signed in is said as that, and a process that is gone where its output ends.
|
|
836
|
+
if (!(error instanceof RpcError) || SIGN_IN.test(error.message)) {
|
|
837
|
+
throw error;
|
|
838
|
+
}
|
|
839
|
+
// A conversation the product has no more: said, and a new one begun, as the runner
|
|
840
|
+
// begins one where the conversation kept was another product's.
|
|
841
|
+
emit({
|
|
842
|
+
type: "event",
|
|
843
|
+
kind: "status",
|
|
844
|
+
text: `The product could not go on with the conversation it had (${error.message}): a new one begins.`,
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
opened ??= await connection.request("thread/start", settings);
|
|
849
|
+
const said = isObject(opened) ? opened : {};
|
|
850
|
+
const named = isObject(said.thread) ? said.thread : {};
|
|
851
|
+
thread = word(textOf(named.id));
|
|
852
|
+
if (thread === undefined) {
|
|
853
|
+
cannotStart("The product opened a conversation and did not say which.", "start");
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
// The sandbox the product says the conversation runs in. More than was asked is never
|
|
857
|
+
// gone on with; less is said, since it is what the agent does without asking: a product
|
|
858
|
+
// whose own sandbox is not set up on the machine answers its read-only one (seen on
|
|
859
|
+
// Windows with 0.171.0, with a home it had set nothing up in).
|
|
860
|
+
const asked = sandboxOf(mode);
|
|
861
|
+
const answered = isObject(said.sandbox) ? textOf(said.sandbox.type) : undefined;
|
|
862
|
+
const width = (name, at) => SANDBOXES.findIndex((one) => one[at] === name);
|
|
863
|
+
const sandbox = SANDBOXES[width(answered, 0)]?.[1];
|
|
864
|
+
// One the driver does not know by its word is said as it came: how much it allows is not
|
|
865
|
+
// known here, and saying nothing would read as the sandbox that was asked for.
|
|
866
|
+
const unknown = sandbox === undefined ? word(answered) : undefined;
|
|
867
|
+
if (sandbox !== undefined && width(sandbox, 1) > width(asked, 1)) {
|
|
868
|
+
cannotStart(`The product opened the conversation in its sandbox ${sandbox}, which allows more than ${asked}, the one it was asked for.`, "start");
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
runs = {
|
|
872
|
+
model: word(textOf(said.model)) ?? model ?? null,
|
|
873
|
+
effort: word(textOf(said.reasoningEffort)) ?? null,
|
|
874
|
+
};
|
|
875
|
+
emit({ type: "conversation", id: thread }, { type: "running", model: runs.model, effort: runs.effort, version }, {
|
|
876
|
+
type: "event",
|
|
877
|
+
kind: "status",
|
|
878
|
+
text: unknown !== undefined
|
|
879
|
+
? `The product started, in a sandbox the driver does not know, ${unknown}, and not in ${asked}, which it was asked for.`
|
|
880
|
+
: sandbox === undefined || sandbox === asked
|
|
881
|
+
? "The product started."
|
|
882
|
+
: `The product started, in its sandbox ${sandbox} and not in ${asked}, which it was asked for.`,
|
|
883
|
+
data: {
|
|
884
|
+
model: runs.model,
|
|
885
|
+
effort: runs.effort,
|
|
886
|
+
version,
|
|
887
|
+
mode,
|
|
888
|
+
...(unknown !== undefined
|
|
889
|
+
? { sandbox: unknown }
|
|
890
|
+
: sandbox === undefined || sandbox === asked
|
|
891
|
+
? {}
|
|
892
|
+
: { sandbox }),
|
|
893
|
+
},
|
|
894
|
+
});
|
|
895
|
+
ready = true;
|
|
896
|
+
pump();
|
|
476
897
|
};
|
|
898
|
+
void (async () => {
|
|
899
|
+
const reading = connection.read({ notification: onNotification, request: onRequest });
|
|
900
|
+
const opening = open().catch((error) => {
|
|
901
|
+
if (gaveUp || stopping) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (error instanceof RpcError) {
|
|
905
|
+
const signIn = SIGN_IN.test(error.message);
|
|
906
|
+
cannotStart(signIn
|
|
907
|
+
? `The product is not signed in: ${error.message}`
|
|
908
|
+
: `The product did not open a conversation: ${error.message}`, signIn ? "sign_in" : "start");
|
|
909
|
+
}
|
|
910
|
+
// Anything else is a process that is gone: how it ended is said where its output ends.
|
|
911
|
+
});
|
|
912
|
+
void wait(START_TIMEOUT_MS).then(() => {
|
|
913
|
+
if (!ready && !gaveUp && !stopping) {
|
|
914
|
+
cannotStart("The product did not open a conversation in time.", "start");
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
await reading;
|
|
918
|
+
over = true;
|
|
919
|
+
await opening;
|
|
920
|
+
const exit = await child.exited;
|
|
921
|
+
const clean = stopping || (exit.code === 0 && exit.signal === null && exit.error === undefined);
|
|
922
|
+
if (!clean && !gaveUp) {
|
|
923
|
+
const errors = child.errors().trim();
|
|
924
|
+
// Its end, cut after the secrets are out, so that none stands at the cut.
|
|
925
|
+
const shown = errorsShown(errors, options.cutEnd ?? plainCutEnd);
|
|
926
|
+
const how = exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`;
|
|
927
|
+
emit({
|
|
928
|
+
type: "event",
|
|
929
|
+
kind: "error",
|
|
930
|
+
text: exit.error !== undefined
|
|
931
|
+
? notStarted(exit.error, host.command)
|
|
932
|
+
: `The product's process ended${how}${began ? "" : " before it answered as its app server, which this driver speaks to (codex app-server)"}.${shown.length === 0 ? "" : `\n${shown}`}`,
|
|
933
|
+
}, {
|
|
934
|
+
type: "cannot_go_on",
|
|
935
|
+
state: "failed",
|
|
936
|
+
// Before the conversation was open nothing was taken, and the runner sends again
|
|
937
|
+
// what it sent; after, what a turn was at is not known.
|
|
938
|
+
// What it wrote of a sign-in counts before the conversation opened alone: after, a
|
|
939
|
+
// turn says so itself, and a line written long before is no reason for this end.
|
|
940
|
+
reason: ready ? "crashed" : SIGN_IN.test(errors) ? "sign_in" : "start",
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
emit({ type: "ended", how: clean ? "exited" : "crashed" });
|
|
944
|
+
})();
|
|
477
945
|
return {
|
|
478
946
|
events: events(),
|
|
479
947
|
async send(message) {
|
|
480
|
-
|
|
948
|
+
// Kept by the runner, where it is not handed over: a product that is gone takes nothing.
|
|
949
|
+
if (stopping || gaveUp || over) {
|
|
481
950
|
throw new Error("the session takes no more input");
|
|
482
951
|
}
|
|
483
|
-
if (turn === undefined) {
|
|
484
|
-
run([message]);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
952
|
waiting.push(message);
|
|
488
|
-
//
|
|
489
|
-
if (message.priority === "now"
|
|
490
|
-
|
|
491
|
-
void endOf(turn.child);
|
|
953
|
+
// One that is to be read now stops the turn under way, and is the turn after.
|
|
954
|
+
if (message.priority === "now") {
|
|
955
|
+
stopTurn("message");
|
|
492
956
|
}
|
|
957
|
+
pump();
|
|
493
958
|
},
|
|
494
959
|
async interrupt() {
|
|
495
|
-
|
|
496
|
-
turn.cut = "stopped";
|
|
497
|
-
void endOf(turn.child);
|
|
498
|
-
}
|
|
960
|
+
stopTurn("stopped");
|
|
499
961
|
},
|
|
500
|
-
//
|
|
962
|
+
// Said with the next turn that is started, and the conversation's from then on.
|
|
501
963
|
async set(next) {
|
|
502
964
|
choice = {
|
|
503
965
|
model: next.model === undefined ? choice.model : next.model,
|
|
@@ -506,18 +968,12 @@ function sessionOf(host, options) {
|
|
|
506
968
|
return true;
|
|
507
969
|
},
|
|
508
970
|
async stop() {
|
|
509
|
-
if (
|
|
971
|
+
if (stopping) {
|
|
510
972
|
return;
|
|
511
973
|
}
|
|
512
|
-
|
|
974
|
+
stopping = true;
|
|
513
975
|
waiting = [];
|
|
514
|
-
|
|
515
|
-
if (open !== undefined) {
|
|
516
|
-
open.cut = "ended";
|
|
517
|
-
await endOf(open.child);
|
|
518
|
-
await open.done;
|
|
519
|
-
}
|
|
520
|
-
emit({ type: "ended", how: "exited" });
|
|
976
|
+
await endOf(child);
|
|
521
977
|
},
|
|
522
978
|
};
|
|
523
979
|
}
|
|
@@ -553,10 +1009,17 @@ function offeredOf(text) {
|
|
|
553
1009
|
}
|
|
554
1010
|
return { models, efforts };
|
|
555
1011
|
}
|
|
556
|
-
/**
|
|
557
|
-
|
|
1012
|
+
/**
|
|
1013
|
+
* The builds of the binary the driver ran a turn of a signed-in product against, on Windows
|
|
1014
|
+
* (2026-11-24): a turn with a command and a file written in the desk, a message put into a turn
|
|
1015
|
+
* while a command ran, a turn stopped for a message, and the allowance as the product says it.
|
|
1016
|
+
* The app server was spoken to signed out with 0.139.0, 0.167.0 and 0.172.0, which is where the
|
|
1017
|
+
* shapes of the tests that say so were written down from.
|
|
1018
|
+
*/
|
|
1019
|
+
const TRIED = ["0.171.0-alpha.13.2"];
|
|
558
1020
|
export function createCodexDriver(host) {
|
|
559
1021
|
const command = host.command ?? "codex";
|
|
1022
|
+
const uuid = host.uuid ?? randomUUID;
|
|
560
1023
|
/** What the product prints for a command that asks it something, or nothing where it could not be asked. */
|
|
561
1024
|
const asked = async (args) => {
|
|
562
1025
|
try {
|
|
@@ -578,9 +1041,9 @@ export function createCodexDriver(host) {
|
|
|
578
1041
|
return {
|
|
579
1042
|
name: "codex",
|
|
580
1043
|
product: { name: "Codex", tried: TRIED },
|
|
581
|
-
//
|
|
582
|
-
//
|
|
583
|
-
can: { steer:
|
|
1044
|
+
// A message is put into the turn under way. A picture is taken as a file, by its path in
|
|
1045
|
+
// the desk. The model and the effort are said with a turn, and taken from the next one on.
|
|
1046
|
+
can: { steer: true, images: true, imageFiles: true, resume: true, set: true },
|
|
584
1047
|
permissions: { modes: MODES, unattended: UNATTENDED_MODE, least: LEAST_MODE },
|
|
585
1048
|
async probe() {
|
|
586
1049
|
// One line: what the command is called, then its version.
|
|
@@ -590,7 +1053,7 @@ export function createCodexDriver(host) {
|
|
|
590
1053
|
return { version, models: offered.models, efforts: offered.efforts };
|
|
591
1054
|
},
|
|
592
1055
|
start(options) {
|
|
593
|
-
return sessionOf({
|
|
1056
|
+
return sessionOf(host.spawn(command, ARGUMENTS, { cwd: options.cwd, env: options.env }), { command, version: host.version, uuid }, options);
|
|
594
1057
|
},
|
|
595
1058
|
};
|
|
596
1059
|
}
|