@skillcdn/console 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -14
- package/SKILLCDN.md +5 -3
- package/dist/agent-page.d.ts +44 -0
- package/dist/agent-page.d.ts.map +1 -0
- package/dist/agent-page.js +415 -0
- package/dist/agent-page.js.map +1 -0
- package/dist/agent-stream.d.ts +52 -0
- package/dist/agent-stream.d.ts.map +1 -0
- package/dist/agent-stream.js +155 -0
- package/dist/agent-stream.js.map +1 -0
- package/dist/api.d.ts +12 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +11 -5
- package/dist/api.js.map +1 -1
- package/dist/avatar.d.ts +137 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +1216 -0
- package/dist/avatar.js.map +1 -0
- package/dist/charts.d.ts +103 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +182 -0
- package/dist/charts.js.map +1 -0
- package/dist/cli/cli.d.ts +39 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +2424 -296
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command-words.d.ts +20 -0
- package/dist/cli/command-words.d.ts.map +1 -0
- package/dist/cli/command-words.js +51 -0
- package/dist/cli/command-words.js.map +1 -0
- package/dist/cli/credentials.d.ts +59 -5
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +128 -16
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/directory.d.ts +19 -4
- package/dist/cli/directory.d.ts.map +1 -1
- package/dist/cli/directory.js +16 -8
- package/dist/cli/directory.js.map +1 -1
- package/dist/cli/format.d.ts +91 -8
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +386 -57
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +13 -4
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +202 -62
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +94 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/pack.d.ts +69 -36
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +241 -188
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +42 -0
- package/dist/cli/plugin-check.d.ts.map +1 -1
- package/dist/cli/plugin-check.js +221 -36
- package/dist/cli/plugin-check.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts +6 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +21 -4
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/plugin-main.js +1 -0
- package/dist/cli/plugin-main.js.map +1 -1
- package/dist/cli/runner-host.d.ts +36 -0
- package/dist/cli/runner-host.d.ts.map +1 -0
- package/dist/cli/runner-host.js +154 -0
- package/dist/cli/runner-host.js.map +1 -0
- package/dist/cli/serve.d.ts +33 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +275 -6
- package/dist/cli/serve.js.map +1 -1
- package/dist/cli/setup-machine.d.ts +36 -0
- package/dist/cli/setup-machine.d.ts.map +1 -0
- package/dist/cli/setup-machine.js +109 -0
- package/dist/cli/setup-machine.js.map +1 -0
- package/dist/client.d.ts +189 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +192 -57
- package/dist/client.js.map +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +2 -2
- package/dist/components/agent-page.d.ts +384 -0
- package/dist/components/agent-page.d.ts.map +1 -0
- package/dist/components/agent-page.js +985 -0
- package/dist/components/agent-page.js.map +1 -0
- package/dist/components/agents.d.ts +102 -0
- package/dist/components/agents.d.ts.map +1 -0
- package/dist/components/agents.js +246 -0
- package/dist/components/agents.js.map +1 -0
- package/dist/components/calendar.d.ts +17 -17
- package/dist/components/calendar.d.ts.map +1 -1
- package/dist/components/calendar.js +7 -2
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/charts.d.ts +157 -0
- package/dist/components/charts.d.ts.map +1 -0
- package/dist/components/charts.js +182 -0
- package/dist/components/charts.js.map +1 -0
- package/dist/components/comments.d.ts +2 -0
- package/dist/components/comments.d.ts.map +1 -1
- package/dist/components/comments.js +1 -1
- package/dist/components/comments.js.map +1 -1
- package/dist/components/connect.d.ts.map +1 -1
- package/dist/components/connect.js +7 -2
- package/dist/components/connect.js.map +1 -1
- package/dist/components/decision-form.d.ts +21 -0
- package/dist/components/decision-form.d.ts.map +1 -1
- package/dist/components/decision-form.js +20 -6
- package/dist/components/decision-form.js.map +1 -1
- package/dist/components/decision-list.d.ts +24 -0
- package/dist/components/decision-list.d.ts.map +1 -1
- package/dist/components/decision-list.js +54 -5
- package/dist/components/decision-list.js.map +1 -1
- package/dist/components/desk-records.d.ts +102 -0
- package/dist/components/desk-records.d.ts.map +1 -0
- package/dist/components/desk-records.js +221 -0
- package/dist/components/desk-records.js.map +1 -0
- package/dist/components/desk.d.ts +85 -0
- package/dist/components/desk.d.ts.map +1 -0
- package/dist/components/desk.js +135 -0
- package/dist/components/desk.js.map +1 -0
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +26 -1
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/home.d.ts +12 -1
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +175 -16
- package/dist/components/home.js.map +1 -1
- package/dist/components/my-decisions.d.ts +5 -0
- package/dist/components/my-decisions.d.ts.map +1 -1
- package/dist/components/my-decisions.js +3 -3
- package/dist/components/my-decisions.js.map +1 -1
- package/dist/components/people.d.ts +17 -0
- package/dist/components/people.d.ts.map +1 -1
- package/dist/components/people.js +55 -19
- package/dist/components/people.js.map +1 -1
- package/dist/components/picker.d.ts +2 -0
- package/dist/components/picker.d.ts.map +1 -1
- package/dist/components/picker.js +1 -1
- package/dist/components/picker.js.map +1 -1
- package/dist/components/pictures.d.ts +38 -10
- package/dist/components/pictures.d.ts.map +1 -1
- package/dist/components/pictures.js +195 -40
- package/dist/components/pictures.js.map +1 -1
- package/dist/components/plugin-events.d.ts +29 -0
- package/dist/components/plugin-events.d.ts.map +1 -0
- package/dist/components/plugin-events.js +139 -0
- package/dist/components/plugin-events.js.map +1 -0
- package/dist/components/plugin-frame.d.ts.map +1 -1
- package/dist/components/plugin-frame.js +14 -37
- package/dist/components/plugin-frame.js.map +1 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +58 -7
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.d.ts.map +1 -1
- package/dist/components/projects.js +30 -10
- package/dist/components/projects.js.map +1 -1
- package/dist/components/rules.d.ts +8 -10
- package/dist/components/rules.d.ts.map +1 -1
- package/dist/components/rules.js +36 -14
- package/dist/components/rules.js.map +1 -1
- package/dist/components/sessions.d.ts.map +1 -1
- package/dist/components/sessions.js +8 -4
- package/dist/components/sessions.js.map +1 -1
- package/dist/components/setup.d.ts +59 -0
- package/dist/components/setup.d.ts.map +1 -0
- package/dist/components/setup.js +93 -0
- package/dist/components/setup.js.map +1 -0
- package/dist/components/sign-in.js +1 -1
- package/dist/components/sign-in.js.map +1 -1
- package/dist/components/task-form.d.ts.map +1 -1
- package/dist/components/task-form.js +2 -2
- package/dist/components/task-form.js.map +1 -1
- package/dist/components/task-list.d.ts +7 -6
- package/dist/components/task-list.d.ts.map +1 -1
- package/dist/components/task-list.js.map +1 -1
- package/dist/components/task-view.d.ts +3 -0
- package/dist/components/task-view.d.ts.map +1 -1
- package/dist/components/task-view.js +1 -1
- package/dist/components/task-view.js.map +1 -1
- package/dist/components/ui.d.ts +78 -8
- package/dist/components/ui.d.ts.map +1 -1
- package/dist/components/ui.js +88 -9
- package/dist/components/ui.js.map +1 -1
- package/dist/components/work.d.ts +5 -5
- package/dist/components/work.d.ts.map +1 -1
- package/dist/components/work.js.map +1 -1
- package/dist/components/workspace.d.ts +17 -0
- package/dist/components/workspace.d.ts.map +1 -1
- package/dist/components/workspace.js +129 -2
- package/dist/components/workspace.js.map +1 -1
- package/dist/connect-page.d.ts.map +1 -1
- package/dist/connect-page.js +5 -2
- package/dist/connect-page.js.map +1 -1
- package/dist/console.css +7551 -4580
- package/dist/console.d.ts +20 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +331 -57
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +22 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +62 -34
- package/dist/data.js.map +1 -1
- package/dist/desk-page.d.ts +38 -0
- package/dist/desk-page.d.ts.map +1 -0
- package/dist/desk-page.js +184 -0
- package/dist/desk-page.js.map +1 -0
- package/dist/desk-records-page.d.ts +18 -0
- package/dist/desk-records-page.d.ts.map +1 -0
- package/dist/desk-records-page.js +130 -0
- package/dist/desk-records-page.js.map +1 -0
- package/dist/desk-records.d.ts +247 -0
- package/dist/desk-records.d.ts.map +1 -0
- package/dist/desk-records.js +543 -0
- package/dist/desk-records.js.map +1 -0
- package/dist/desk.d.ts +122 -0
- package/dist/desk.d.ts.map +1 -0
- package/dist/desk.js +211 -0
- package/dist/desk.js.map +1 -0
- package/dist/feed-stream.d.ts +39 -0
- package/dist/feed-stream.d.ts.map +1 -0
- package/dist/feed-stream.js +117 -0
- package/dist/feed-stream.js.map +1 -0
- package/dist/glances.d.ts +39 -0
- package/dist/glances.d.ts.map +1 -0
- package/dist/glances.js +94 -0
- package/dist/glances.js.map +1 -0
- package/dist/home-tiles.d.ts +69 -5
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +347 -9
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +773 -3
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +770 -9
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +736 -9
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +67 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +67 -0
- package/dist/limits.js.map +1 -1
- package/dist/onboarding.d.ts +21 -0
- package/dist/onboarding.d.ts.map +1 -0
- package/dist/onboarding.js +43 -0
- package/dist/onboarding.js.map +1 -0
- package/dist/persona.d.ts +34 -0
- package/dist/persona.d.ts.map +1 -0
- package/dist/persona.js +71 -0
- package/dist/persona.js.map +1 -0
- package/dist/plugin/context.d.ts +42 -11
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +2 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +2 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/manifest.d.ts +13 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +34 -4
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +56 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +42 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +4 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/testing.d.ts +6 -2
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +52 -10
- package/dist/plugin/testing.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/records.d.ts +283 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +543 -0
- package/dist/records.js.map +1 -0
- package/dist/router.d.ts +50 -3
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +78 -7
- package/dist/router.js.map +1 -1
- package/dist/routes.d.ts +12 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +14 -1
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +30 -11
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +99 -42
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts +20 -0
- package/dist/runner/acp.d.ts.map +1 -0
- package/dist/runner/acp.js +1132 -0
- package/dist/runner/acp.js.map +1 -0
- package/dist/runner/claude.d.ts +13 -0
- package/dist/runner/claude.d.ts.map +1 -0
- package/dist/runner/claude.js +615 -0
- package/dist/runner/claude.js.map +1 -0
- package/dist/runner/codex.d.ts +19 -0
- package/dist/runner/codex.d.ts.map +1 -0
- package/dist/runner/codex.js +597 -0
- package/dist/runner/codex.js.map +1 -0
- package/dist/runner/config.d.ts +35 -0
- package/dist/runner/config.d.ts.map +1 -0
- package/dist/runner/config.js +74 -0
- package/dist/runner/config.js.map +1 -0
- package/dist/runner/desk.d.ts +81 -0
- package/dist/runner/desk.d.ts.map +1 -0
- package/dist/runner/desk.js +303 -0
- package/dist/runner/desk.js.map +1 -0
- package/dist/runner/launchd.d.ts +7 -0
- package/dist/runner/launchd.d.ts.map +1 -0
- package/dist/runner/launchd.js +78 -0
- package/dist/runner/launchd.js.map +1 -0
- package/dist/runner/message.d.ts +66 -0
- package/dist/runner/message.d.ts.map +1 -0
- package/dist/runner/message.js +181 -0
- package/dist/runner/message.js.map +1 -0
- package/dist/runner/modules.d.ts +13 -0
- package/dist/runner/modules.d.ts.map +1 -0
- package/dist/runner/modules.js +30 -0
- package/dist/runner/modules.js.map +1 -0
- package/dist/runner/process.d.ts +7 -0
- package/dist/runner/process.d.ts.map +1 -0
- package/dist/runner/process.js +65 -0
- package/dist/runner/process.js.map +1 -0
- package/dist/runner/redact.d.ts +48 -0
- package/dist/runner/redact.d.ts.map +1 -0
- package/dist/runner/redact.js +214 -0
- package/dist/runner/redact.js.map +1 -0
- package/dist/runner/registry.d.ts +37 -0
- package/dist/runner/registry.d.ts.map +1 -0
- package/dist/runner/registry.js +26 -0
- package/dist/runner/registry.js.map +1 -0
- package/dist/runner/runner.d.ts +130 -0
- package/dist/runner/runner.d.ts.map +1 -0
- package/dist/runner/runner.js +1551 -0
- package/dist/runner/runner.js.map +1 -0
- package/dist/runner/slack.d.ts +16 -0
- package/dist/runner/slack.d.ts.map +1 -0
- package/dist/runner/slack.js +157 -0
- package/dist/runner/slack.js.map +1 -0
- package/dist/runner/systemd-user.d.ts +7 -0
- package/dist/runner/systemd-user.d.ts.map +1 -0
- package/dist/runner/systemd-user.js +93 -0
- package/dist/runner/systemd-user.js.map +1 -0
- package/dist/runner/task-scheduler.d.ts +38 -0
- package/dist/runner/task-scheduler.d.ts.map +1 -0
- package/dist/runner/task-scheduler.js +216 -0
- package/dist/runner/task-scheduler.js.map +1 -0
- package/dist/runner/types.d.ts +315 -0
- package/dist/runner/types.d.ts.map +1 -0
- package/dist/runner/types.js +24 -0
- package/dist/runner/types.js.map +1 -0
- package/dist/runner.d.ts +18 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +20 -0
- package/dist/runner.js.map +1 -0
- package/dist/schemas.d.ts +6082 -1295
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +930 -31
- package/dist/schemas.js.map +1 -1
- package/dist/services.d.ts +110 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +305 -0
- package/dist/services.js.map +1 -0
- package/dist/setup-guide.d.ts +64 -0
- package/dist/setup-guide.d.ts.map +1 -0
- package/dist/setup-guide.js +256 -0
- package/dist/setup-guide.js.map +1 -0
- package/dist/setup-page.d.ts +6 -0
- package/dist/setup-page.d.ts.map +1 -0
- package/dist/setup-page.js +29 -0
- package/dist/setup-page.js.map +1 -0
- package/dist/sse.d.ts +15 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +73 -0
- package/dist/sse.js.map +1 -0
- package/dist/tab-title.d.ts +6 -0
- package/dist/tab-title.d.ts.map +1 -0
- package/dist/tab-title.js +22 -0
- package/dist/tab-title.js.map +1 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +3 -0
- package/dist/tokens.js.map +1 -1
- package/dist/use-action.d.ts +5 -2
- package/dist/use-action.d.ts.map +1 -1
- package/dist/use-action.js +6 -1
- package/dist/use-action.js.map +1 -1
- package/dist/vocabulary.d.ts +84 -4
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +115 -3
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +147 -41
- package/docs/specs/plugins.md +37 -27
- package/docs/specs/records.md +113 -0
- package/docs/specs/rest.md +155 -20
- package/docs/specs/runner.md +347 -0
- package/package.json +12 -3
- package/skills/building-a-console/SKILL.md +4 -4
- package/skills/building-a-console/references/configuring.md +1 -0
- package/skills/building-a-plugin/SKILL.md +7 -7
- package/skills/deploying-a-console/SKILL.md +4 -4
- package/skills/deploying-a-console/references/resources.md +48 -8
- package/skills/deploying-a-console/references/running-it-again.md +3 -2
- package/skills/keeping-a-desk/SKILL.md +133 -0
- package/skills/keeping-a-desk/collections.md +96 -0
- package/skills/planning-the-board/SKILL.md +14 -18
- package/skills/planning-the-board/references/a-task.md +2 -2
- package/skills/planning-the-board/references/project-rules.md +13 -14
- package/skills/planning-the-board/references/setting-up.md +22 -9
- package/skills/running-an-agent/SKILL.md +107 -0
- package/skills/running-an-agent/references/slack-app.md +61 -0
- package/skills/working-the-board/SKILL.md +66 -39
- package/skills/working-the-board/references/terms.md +9 -5
- package/skills/working-the-board/references/the-pack.md +14 -9
- package/skills/working-the-board/references/the-sentence.md +2 -2
- package/src/agent-page.tsx +1039 -0
- package/src/agent-stream.ts +199 -0
- package/src/api.ts +317 -2
- package/src/avatar.ts +1506 -0
- package/src/charts.ts +250 -0
- package/src/cli/cli.ts +3210 -503
- package/src/cli/command-words.ts +56 -0
- package/src/cli/credentials.ts +188 -16
- package/src/cli/directory.ts +28 -10
- package/src/cli/format.ts +470 -67
- package/src/cli/help.ts +233 -61
- package/src/cli/main.ts +89 -0
- package/src/cli/pack.ts +332 -263
- package/src/cli/plugin-check.ts +275 -34
- package/src/cli/plugin-cli.ts +28 -4
- package/src/cli/plugin-main.ts +1 -0
- package/src/cli/runner-host.ts +188 -0
- package/src/cli/serve.ts +320 -5
- package/src/cli/setup-machine.ts +153 -0
- package/src/client.ts +711 -126
- package/src/compat.ts +2 -2
- package/src/components/agent-page.tsx +1946 -0
- package/src/components/agents.tsx +638 -0
- package/src/components/calendar.tsx +74 -53
- package/src/components/charts.tsx +680 -0
- package/src/components/comments.tsx +3 -0
- package/src/components/connect.tsx +37 -2
- package/src/components/decision-form.tsx +89 -51
- package/src/components/decision-list.tsx +140 -4
- package/src/components/desk-records.tsx +724 -0
- package/src/components/desk.tsx +471 -0
- package/src/components/event-feed.tsx +30 -1
- package/src/components/home.tsx +353 -12
- package/src/components/my-decisions.tsx +8 -2
- package/src/components/people.tsx +300 -203
- package/src/components/picker.tsx +3 -1
- package/src/components/pictures.tsx +256 -44
- package/src/components/plugin-events.ts +159 -0
- package/src/components/plugin-frame.tsx +14 -38
- package/src/components/plugin-settings.tsx +178 -22
- package/src/components/projects.tsx +33 -15
- package/src/components/rules.tsx +96 -36
- package/src/components/sessions.tsx +7 -4
- package/src/components/setup.tsx +252 -0
- package/src/components/sign-in.tsx +1 -1
- package/src/components/task-form.tsx +11 -2
- package/src/components/task-list.tsx +7 -6
- package/src/components/task-view.tsx +4 -0
- package/src/components/ui.tsx +169 -25
- package/src/components/work.tsx +9 -9
- package/src/components/workspace.tsx +345 -4
- package/src/connect-page.tsx +15 -2
- package/src/console.tsx +657 -83
- package/src/data.ts +109 -43
- package/src/desk-page.tsx +332 -0
- package/src/desk-records-page.tsx +256 -0
- package/src/desk-records.ts +808 -0
- package/src/desk.ts +329 -0
- package/src/feed-stream.ts +144 -0
- package/src/glances.ts +132 -0
- package/src/home-tiles.ts +411 -9
- package/src/i18n/en.ts +828 -10
- package/src/i18n/ko.ts +792 -10
- package/src/index.ts +172 -3
- package/src/limits.ts +67 -0
- package/src/onboarding.ts +84 -0
- package/src/persona.ts +100 -0
- package/src/plugin/context.ts +55 -12
- package/src/plugin/limits.ts +2 -0
- package/src/plugin/manifest.ts +42 -3
- package/src/plugin/rest-schemas.ts +46 -0
- package/src/plugin/sandbox.ts +4 -1
- package/src/plugin/testing.ts +63 -12
- package/src/plugin.ts +2 -0
- package/src/records.ts +702 -0
- package/src/router.ts +120 -10
- package/src/routes.ts +17 -1
- package/src/rules.ts +109 -44
- package/src/runner/acp.ts +1267 -0
- package/src/runner/claude.ts +695 -0
- package/src/runner/codex.ts +691 -0
- package/src/runner/config.ts +97 -0
- package/src/runner/desk.ts +377 -0
- package/src/runner/launchd.ts +86 -0
- package/src/runner/message.ts +232 -0
- package/src/runner/modules.ts +30 -0
- package/src/runner/process.ts +72 -0
- package/src/runner/redact.ts +242 -0
- package/src/runner/registry.ts +67 -0
- package/src/runner/runner.ts +1879 -0
- package/src/runner/slack.ts +180 -0
- package/src/runner/systemd-user.ts +103 -0
- package/src/runner/task-scheduler.ts +236 -0
- package/src/runner/types.ts +334 -0
- package/src/runner.ts +110 -0
- package/src/schemas.ts +1183 -30
- package/src/services.ts +424 -0
- package/src/setup-guide.ts +336 -0
- package/src/setup-page.tsx +46 -0
- package/src/sse.ts +84 -0
- package/src/styles/README.md +111 -0
- package/src/styles/base.css +130 -0
- package/src/styles/console.css +85 -7095
- package/src/styles/drawn-by-pages.json +256 -0
- package/src/styles/pages/agents.css +1195 -0
- package/src/styles/pages/board.css +380 -0
- package/src/styles/pages/calendar.css +214 -0
- package/src/styles/pages/connect.css +182 -0
- package/src/styles/pages/decisions.css +370 -0
- package/src/styles/pages/desk.css +126 -0
- package/src/styles/pages/documents.css +273 -0
- package/src/styles/pages/feed.css +118 -0
- package/src/styles/pages/home.css +718 -0
- package/src/styles/pages/people.css +90 -0
- package/src/styles/pages/plugins.css +212 -0
- package/src/styles/pages/roadmap.css +377 -0
- package/src/styles/pages/settings.css +171 -0
- package/src/styles/pages/shell.css +208 -0
- package/src/styles/pages/sign-in.css +178 -0
- package/src/styles/pages/task.css +108 -0
- package/src/styles/pages/thread.css +331 -0
- package/src/styles/pages/work.css +68 -0
- package/src/styles/parts/avatar.css +82 -0
- package/src/styles/parts/badge.css +227 -0
- package/src/styles/parts/bars.css +80 -0
- package/src/styles/parts/button.css +99 -0
- package/src/styles/parts/calendar.css +547 -0
- package/src/styles/parts/callout.css +41 -0
- package/src/styles/parts/category.css +8 -0
- package/src/styles/parts/chart.css +173 -0
- package/src/styles/parts/chip.css +90 -0
- package/src/styles/parts/code.css +48 -0
- package/src/styles/parts/count.css +27 -0
- package/src/styles/parts/crumbs.css +61 -0
- package/src/styles/parts/detail.css +110 -0
- package/src/styles/parts/empty.css +21 -0
- package/src/styles/parts/eyebrow.css +9 -0
- package/src/styles/parts/facts.css +147 -0
- package/src/styles/parts/figures.css +65 -0
- package/src/styles/parts/files.css +38 -0
- package/src/styles/parts/filters.css +42 -0
- package/src/styles/parts/form.css +109 -0
- package/src/styles/parts/frame.css +45 -0
- package/src/styles/parts/input.css +243 -0
- package/src/styles/parts/legend.css +48 -0
- package/src/styles/parts/links.css +37 -0
- package/src/styles/parts/mark.css +79 -0
- package/src/styles/parts/menu.css +147 -0
- package/src/styles/parts/page.css +174 -0
- package/src/styles/parts/pager.css +19 -0
- package/src/styles/parts/panel.css +33 -0
- package/src/styles/parts/person.css +257 -0
- package/src/styles/parts/picker.css +185 -0
- package/src/styles/parts/progress.css +25 -0
- package/src/styles/parts/prose.css +128 -0
- package/src/styles/parts/rows.css +63 -0
- package/src/styles/parts/series.css +32 -0
- package/src/styles/parts/settings.css +101 -0
- package/src/styles/parts/share.css +25 -0
- package/src/styles/parts/spark.css +23 -0
- package/src/styles/parts/spinner.css +29 -0
- package/src/styles/parts/stat.css +69 -0
- package/src/styles/parts/steps.css +68 -0
- package/src/styles/parts/tabs.css +175 -0
- package/src/styles/parts/text.css +61 -0
- package/src/styles/parts/toggle.css +71 -0
- package/src/styles/parts/workers.css +37 -0
- package/src/styles/tokens.css +295 -0
- package/src/tab-title.ts +25 -0
- package/src/tokens.ts +3 -0
- package/src/use-action.ts +7 -2
- package/src/vocabulary.ts +151 -3
- package/template/desk-web/README.md +8 -0
- package/template/desk-web/index.html +13 -0
- package/template/desk-web/package.json +25 -0
- package/template/desk-web/src/main.tsx +24 -0
- package/template/desk-web/src/page.tsx +51 -0
- package/template/desk-web/tsconfig.json +16 -0
- package/template/desk-web/vite.config.ts +15 -0
|
@@ -0,0 +1,1132 @@
|
|
|
1
|
+
import { MAX_FILE_BYTES } from "../limits.js";
|
|
2
|
+
import { TRANSCRIPT_PICTURE_TYPES } from "../vocabulary.js";
|
|
3
|
+
import { errorsShown, plainCut, plainCutEnd, } from "./types.js";
|
|
4
|
+
// The driver for any product that speaks the Agent Client Protocol (ADR-0085): the product's
|
|
5
|
+
// command, which `runner.json` names, started once for a session and spoken to over its standard
|
|
6
|
+
// input and output, a JSON-RPC message a line. The runner is the protocol's client. It offers
|
|
7
|
+
// the agent no file and no terminal of its own, so the agent works with its own tools in the
|
|
8
|
+
// desk; it answers what the agent asks leave for, since nobody is at a terminal to ask; and it
|
|
9
|
+
// reads what the agent does as whole blocks, where the protocol sends a message in pieces.
|
|
10
|
+
// Written from the protocol's documentation, version 1, and read against the types the protocol
|
|
11
|
+
// publishes and the source of one agent that speaks it, and run against that agent since.
|
|
12
|
+
/** The protocol's version this driver speaks. */
|
|
13
|
+
const PROTOCOL_VERSION = 1;
|
|
14
|
+
/** How long a session that is stopped is given to end by itself, then after it was asked to. */
|
|
15
|
+
const STOP_GRACE_MS = 5000;
|
|
16
|
+
const KILL_GRACE_MS = 2000;
|
|
17
|
+
/** How long the product is given to say what it is and to open a session. */
|
|
18
|
+
const START_TIMEOUT_MS = 120_000;
|
|
19
|
+
/** How long it is given to say what it is and offers, asked without a session to run. */
|
|
20
|
+
const PROBE_TIMEOUT_MS = 30_000;
|
|
21
|
+
/**
|
|
22
|
+
* How long an agent is given to take a model or a level of effort in a running session. The
|
|
23
|
+
* runner handles one thing at a time: an agent that answers nothing while it works would hold
|
|
24
|
+
* every signal behind the choice, a stop among them.
|
|
25
|
+
*/
|
|
26
|
+
const SET_TIMEOUT_MS = 5000;
|
|
27
|
+
/** The most of a tool's input that is shown. */
|
|
28
|
+
const MAX_INPUT_LENGTH = 4000;
|
|
29
|
+
/** The most that is shown of what a command printed while it ran, where an agent sends it in pieces. */
|
|
30
|
+
const MAX_PRINTED_LENGTH = 200_000;
|
|
31
|
+
/**
|
|
32
|
+
* How much more of it is kept than is shown: what is printed is cut once the account's secrets
|
|
33
|
+
* are out of it, and a secret that stands at the cut is whole only where what follows the cut
|
|
34
|
+
* was kept. More than the longest form a secret is looked for in.
|
|
35
|
+
*/
|
|
36
|
+
const PRINTED_BEYOND = 64 * 1024;
|
|
37
|
+
/** The most that is shown of what an error carries beside its message. */
|
|
38
|
+
const MAX_DETAIL_LENGTH = 1000;
|
|
39
|
+
/** The protocol's code for a request the agent takes only once the product is signed in. */
|
|
40
|
+
const AUTH_REQUIRED = -32000;
|
|
41
|
+
/** The answer to a request for a method this client does not offer. */
|
|
42
|
+
const METHOD_NOT_FOUND = -32601;
|
|
43
|
+
/**
|
|
44
|
+
* What an error says when the product is not signed in. The products' words for it are their
|
|
45
|
+
* own: read by pattern, beside the protocol's own code for it.
|
|
46
|
+
*/
|
|
47
|
+
const SIGN_IN = /not (?:logged|signed) in|logged out|(?:log|sign) ?in (?:is )?required|authentication (?:is )?required|auth_required|invalid (?:x-)?api[- ]key|token (?:has )?expired|unauthorized/i;
|
|
48
|
+
/**
|
|
49
|
+
* What the runner answers where the agent asks leave for a tool call, in the driver's own two
|
|
50
|
+
* words. `allow` lets it, once each: a run nobody attends has nobody to ask, and an agent that
|
|
51
|
+
* is refused everything does no work. `deny` refuses each, for an agent that is to do only what
|
|
52
|
+
* its own mode lets it without asking. Beside the two, the desk may name one of the agent's own
|
|
53
|
+
* modes, which the protocol has a session say and set: the agent then runs in it, and what it
|
|
54
|
+
* still asks is refused, since the mode is what it may do with nobody there.
|
|
55
|
+
*/
|
|
56
|
+
const MODES = ["allow", "deny"];
|
|
57
|
+
/**
|
|
58
|
+
* The mode an agent has for a run nobody attends, by what the agent calls itself: the one in
|
|
59
|
+
* which it works without asking and asks leave only for what its own review holds back. The
|
|
60
|
+
* driver names it where the desk names none, as the other drivers name their product's, and
|
|
61
|
+
* refuses what the agent still asks. Seen with the adapters that put Codex and Claude Code
|
|
62
|
+
* behind the protocol, whose words for it are `agent` and `auto`. An agent the driver does not
|
|
63
|
+
* know runs in its own mode and is allowed what it asks: the desk names its mode for such a run.
|
|
64
|
+
*/
|
|
65
|
+
const UNATTENDED_MODES = {
|
|
66
|
+
Codex: "agent",
|
|
67
|
+
"Claude Agent": "auto",
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The agents the driver was run against, each by what it calls itself, with the versions it said
|
|
71
|
+
* of itself: the adapters that put Codex and Claude Code behind the protocol, each run on
|
|
72
|
+
* Windows with a real account.
|
|
73
|
+
*/
|
|
74
|
+
const TRIED = {
|
|
75
|
+
Codex: ["2.6.0"],
|
|
76
|
+
"Claude Agent": ["0.106.0"],
|
|
77
|
+
};
|
|
78
|
+
const UNATTENDED_MODE = "allow";
|
|
79
|
+
const LEAST_MODE = "deny";
|
|
80
|
+
/** The mode a session answers in: the one named where it is one of the two, the least where it is not, `allow` where none is named. */
|
|
81
|
+
export function acpMode(named) {
|
|
82
|
+
if (named === undefined) {
|
|
83
|
+
return UNATTENDED_MODE;
|
|
84
|
+
}
|
|
85
|
+
return named === "allow" || named === "deny" ? named : LEAST_MODE;
|
|
86
|
+
}
|
|
87
|
+
const PICTURE_TYPES = new Set(TRANSCRIPT_PICTURE_TYPES);
|
|
88
|
+
const EXTENSIONS = {
|
|
89
|
+
"image/png": "png",
|
|
90
|
+
"image/jpeg": "jpg",
|
|
91
|
+
"image/gif": "gif",
|
|
92
|
+
"image/webp": "webp",
|
|
93
|
+
};
|
|
94
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
95
|
+
const textOf = (value) => typeof value === "string" ? value : undefined;
|
|
96
|
+
const listOf = (value) => (Array.isArray(value) ? value : []);
|
|
97
|
+
const wait = (ms) => new Promise((resolve) => {
|
|
98
|
+
setTimeout(() => resolve("timeout"), ms).unref?.();
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* What an error carries beside its message, as words: an agent may say "Internal error" and put
|
|
102
|
+
* why under `data`, as text or as an object with a message of its own.
|
|
103
|
+
*/
|
|
104
|
+
function detailOf(data, cut) {
|
|
105
|
+
const words = isObject(data)
|
|
106
|
+
? (textOf(data.message) ?? textOf(data.details) ?? textOf(data.error))
|
|
107
|
+
: textOf(data);
|
|
108
|
+
const detail = words?.trim();
|
|
109
|
+
return detail === undefined || detail.length === 0 ? undefined : cut(detail, MAX_DETAIL_LENGTH);
|
|
110
|
+
}
|
|
111
|
+
/** What a request was refused with, as the protocol says it: the message, with what it carries beside it. */
|
|
112
|
+
class RpcError extends Error {
|
|
113
|
+
code;
|
|
114
|
+
constructor(code, message, data, cut = plainCut) {
|
|
115
|
+
const detail = detailOf(data, cut);
|
|
116
|
+
super(detail === undefined || message.includes(detail) ? message : `${message}: ${detail}`);
|
|
117
|
+
this.code = code;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function connectionOf(child, cut = plainCut) {
|
|
121
|
+
let next = 0;
|
|
122
|
+
const pending = new Map();
|
|
123
|
+
const write = (message) => child.write(JSON.stringify({ jsonrpc: "2.0", ...message }));
|
|
124
|
+
return {
|
|
125
|
+
request(method, params) {
|
|
126
|
+
const id = next;
|
|
127
|
+
next += 1;
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
pending.set(id, { resolve, reject });
|
|
130
|
+
write({ id, method, params }).catch((error) => {
|
|
131
|
+
pending.delete(id);
|
|
132
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
notify: (method, params) => write({ method, params }),
|
|
137
|
+
answer: (id, result) => write({ id, result }),
|
|
138
|
+
refuse: (id, code, message) => write({ id, error: { code, message } }),
|
|
139
|
+
async read(on) {
|
|
140
|
+
try {
|
|
141
|
+
for await (const text of child.lines) {
|
|
142
|
+
if (text.trim().length === 0) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
let line;
|
|
146
|
+
try {
|
|
147
|
+
line = JSON.parse(text);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// What is no message of the protocol is none of the runner's: a line a product
|
|
151
|
+
// printed beside it, say.
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!isObject(line)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const method = textOf(line.method);
|
|
158
|
+
if (method !== undefined) {
|
|
159
|
+
const params = isObject(line.params) ? line.params : {};
|
|
160
|
+
if (line.id === undefined || line.id === null) {
|
|
161
|
+
on.notification(method, params);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
on.request(line.id, method, params);
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const waiting = typeof line.id === "number" ? pending.get(line.id) : undefined;
|
|
169
|
+
if (waiting === undefined || typeof line.id !== "number") {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
pending.delete(line.id);
|
|
173
|
+
if (isObject(line.error)) {
|
|
174
|
+
waiting.reject(new RpcError(typeof line.error.code === "number" ? line.error.code : 0, textOf(line.error.message) ?? "the request was refused", line.error.data, cut));
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
waiting.resolve(line.result);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// The output closed in the middle of a line: how the process ended says the rest.
|
|
183
|
+
}
|
|
184
|
+
// Nothing answers what was asked of a process that is gone.
|
|
185
|
+
for (const waiting of pending.values()) {
|
|
186
|
+
waiting.reject(new Error("the product's process ended"));
|
|
187
|
+
}
|
|
188
|
+
pending.clear();
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** The choice of a category among a session's configuration: the model, or the level of thought. */
|
|
193
|
+
function choiceOf(options, category) {
|
|
194
|
+
for (const option of listOf(options)) {
|
|
195
|
+
if (!isObject(option) || option.category !== category || option.type !== "select") {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const id = textOf(option.id);
|
|
199
|
+
if (id === undefined) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const values = [];
|
|
203
|
+
for (const entry of listOf(option.options)) {
|
|
204
|
+
if (!isObject(entry)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
// A flat list of values, or groups of them.
|
|
208
|
+
for (const one of Array.isArray(entry.options) ? entry.options : [entry]) {
|
|
209
|
+
const value = isObject(one) ? textOf(one.value) : undefined;
|
|
210
|
+
if (value !== undefined && value.length > 0 && value.length <= 200) {
|
|
211
|
+
values.push(value);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return { id, current: textOf(option.currentValue) ?? null, values: values.slice(0, 100) };
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
function standingOf(opened) {
|
|
220
|
+
if (!isObject(opened)) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
const configured = choiceOf(opened.configOptions, "mode");
|
|
224
|
+
if (configured !== undefined) {
|
|
225
|
+
return { choice: configured, by: "option" };
|
|
226
|
+
}
|
|
227
|
+
if (!isObject(opened.modes)) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
const values = listOf(opened.modes.availableModes)
|
|
231
|
+
.map((one) => (isObject(one) ? textOf(one.id) : undefined))
|
|
232
|
+
.filter((id) => id !== undefined && id.length > 0 && id.length <= 200)
|
|
233
|
+
.slice(0, 100);
|
|
234
|
+
return values.length === 0
|
|
235
|
+
? undefined
|
|
236
|
+
: {
|
|
237
|
+
choice: { id: "", current: textOf(opened.modes.currentModeId) ?? null, values },
|
|
238
|
+
by: "mode",
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** A tool's input as a person reads it: the command of a shell, the path of a file, or the input whole and bounded. */
|
|
242
|
+
function inputOf(input, cut) {
|
|
243
|
+
if (input === undefined || input === null) {
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
246
|
+
if (isObject(input)) {
|
|
247
|
+
// An input with nothing in it yet is none: an agent may open a call before it is whole.
|
|
248
|
+
if (Object.keys(input).length === 0) {
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
const line = textOf(input.command) ??
|
|
252
|
+
textOf(input.file_path) ??
|
|
253
|
+
textOf(input.path) ??
|
|
254
|
+
textOf(input.abs_path);
|
|
255
|
+
if (line !== undefined && Object.keys(input).length <= 3) {
|
|
256
|
+
return line;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
let whole;
|
|
260
|
+
try {
|
|
261
|
+
whole = typeof input === "string" ? input : (JSON.stringify(input) ?? "");
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
whole = "";
|
|
265
|
+
}
|
|
266
|
+
return cut(whole, MAX_INPUT_LENGTH);
|
|
267
|
+
}
|
|
268
|
+
/** The text and the pictures of what a tool call holds: blocks of content, a change to a file, a terminal. */
|
|
269
|
+
function contentOf(content, name) {
|
|
270
|
+
const texts = [];
|
|
271
|
+
const pictures = [];
|
|
272
|
+
for (const item of listOf(content)) {
|
|
273
|
+
if (!isObject(item)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (item.type === "diff") {
|
|
277
|
+
const path = textOf(item.path) ?? "a file";
|
|
278
|
+
// What became of the file: as the agent says it beside the protocol where it does, read
|
|
279
|
+
// from the text before where it does not. A file changed in several places is said once.
|
|
280
|
+
const said = isObject(item._meta) ? textOf(item._meta.kind) : undefined;
|
|
281
|
+
const fresh = item.oldText === null || item.oldText === undefined;
|
|
282
|
+
const what = said === "delete"
|
|
283
|
+
? "Removed"
|
|
284
|
+
: said === "add" || (said === undefined && fresh)
|
|
285
|
+
? "Wrote"
|
|
286
|
+
: "Changed";
|
|
287
|
+
if (!texts.includes(`${what} ${path}`)) {
|
|
288
|
+
texts.push(`${what} ${path}`);
|
|
289
|
+
}
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (item.type !== "content" || !isObject(item.content)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const block = item.content;
|
|
296
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
297
|
+
texts.push(block.text);
|
|
298
|
+
}
|
|
299
|
+
else if (block.type === "image") {
|
|
300
|
+
const type = textOf(block.mimeType) ?? "";
|
|
301
|
+
const data = textOf(block.data);
|
|
302
|
+
// A picture of a kind a transcript keeps, within the bound on a file; anything else is said and left.
|
|
303
|
+
if (data !== undefined &&
|
|
304
|
+
PICTURE_TYPES.has(type) &&
|
|
305
|
+
data.length <= Math.ceil((MAX_FILE_BYTES * 4) / 3) + 4) {
|
|
306
|
+
const bytes = Buffer.from(data, "base64");
|
|
307
|
+
if (bytes.byteLength > 0 && bytes.byteLength <= MAX_FILE_BYTES) {
|
|
308
|
+
pictures.push({
|
|
309
|
+
name: `${name}-${pictures.length + 1}.${EXTENSIONS[type] ?? "png"}`,
|
|
310
|
+
contentType: type,
|
|
311
|
+
bytes,
|
|
312
|
+
});
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
texts.push("[a picture the transcript does not keep]");
|
|
317
|
+
}
|
|
318
|
+
else if (block.type === "resource_link") {
|
|
319
|
+
texts.push(textOf(block.uri) ?? "");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return { text: texts.filter((text) => text.length > 0).join("\n"), pictures };
|
|
323
|
+
}
|
|
324
|
+
/** What the agent says it is: its name as people read it, and its version. */
|
|
325
|
+
function agentOf(initialized) {
|
|
326
|
+
const info = isObject(initialized) && isObject(initialized.agentInfo) ? initialized.agentInfo : {};
|
|
327
|
+
const short = (value) => {
|
|
328
|
+
const text = textOf(value)?.trim();
|
|
329
|
+
return text === undefined || text.length === 0 ? undefined : text.slice(0, 80);
|
|
330
|
+
};
|
|
331
|
+
return { name: short(info.title) ?? short(info.name), version: short(info.version) };
|
|
332
|
+
}
|
|
333
|
+
/** What the runner says of itself when it begins: no file and no terminal of its own, so that the agent works with its own tools. */
|
|
334
|
+
const hello = (version) => ({
|
|
335
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
336
|
+
// What the agent has to tell beside its work, a warning say, is taken as a notice: an agent
|
|
337
|
+
// that is offered none says it as its own words, in the middle of its answer.
|
|
338
|
+
clientCapabilities: {
|
|
339
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
340
|
+
terminal: false,
|
|
341
|
+
session: { notices: {} },
|
|
342
|
+
},
|
|
343
|
+
// The protocol has a client say its version: the command's, or none that it knows.
|
|
344
|
+
clientInfo: {
|
|
345
|
+
name: "skillcdn-console-runner",
|
|
346
|
+
title: "SkillCDN Console runner",
|
|
347
|
+
version: version ?? "0.0.0",
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
/** Ends a process: its input closed first, then asked, then made to. */
|
|
351
|
+
async function endOf(child) {
|
|
352
|
+
child.end();
|
|
353
|
+
if ((await Promise.race([child.exited, wait(STOP_GRACE_MS)])) === "timeout") {
|
|
354
|
+
child.kill("SIGTERM");
|
|
355
|
+
if ((await Promise.race([child.exited, wait(KILL_GRACE_MS)])) === "timeout") {
|
|
356
|
+
child.kill("SIGKILL");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function sessionOf(child, options,
|
|
361
|
+
/** The version of the command the runner is, said to the product. */
|
|
362
|
+
own,
|
|
363
|
+
/** How long a choice set in the running session is waited for. */
|
|
364
|
+
setMs = SET_TIMEOUT_MS) {
|
|
365
|
+
/** What cuts a text to what is shown of it: the runner's, which takes the account's secrets out first. */
|
|
366
|
+
const cut = options.cut ?? plainCut;
|
|
367
|
+
const connection = connectionOf(child, cut);
|
|
368
|
+
/** How what the agent asks leave for is answered: settled once the session says its modes. */
|
|
369
|
+
let mode = acpMode(options.permissions);
|
|
370
|
+
// What the session says, in order, for whoever reads it: until it ends.
|
|
371
|
+
const said = [];
|
|
372
|
+
let reader;
|
|
373
|
+
/**
|
|
374
|
+
* The tool calls under way, by id: what each is called and was called with, what it holds so
|
|
375
|
+
* far, what its command printed, and whether it and its end were said.
|
|
376
|
+
*/
|
|
377
|
+
const calls = new Map();
|
|
378
|
+
/**
|
|
379
|
+
* The calls that began and are not said yet, in order: an agent may open a call before what
|
|
380
|
+
* it is called with is whole, and say that in an update. A call is said once its input is
|
|
381
|
+
* known, and before anything else is, so that the transcript keeps the order of what happened.
|
|
382
|
+
*/
|
|
383
|
+
const held = [];
|
|
384
|
+
const emit = (...events) => {
|
|
385
|
+
for (const id of held.splice(0)) {
|
|
386
|
+
const call = calls.get(id);
|
|
387
|
+
if (call === undefined || call.said) {
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
call.said = true;
|
|
391
|
+
said.push({
|
|
392
|
+
type: "event",
|
|
393
|
+
kind: "tool_call",
|
|
394
|
+
text: call.input.length === 0 || call.title.includes(call.input)
|
|
395
|
+
? call.title
|
|
396
|
+
: `${call.title}\n${call.input}`.trim(),
|
|
397
|
+
data: { tool: call.tool, id },
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
said.push(...events);
|
|
401
|
+
reader?.();
|
|
402
|
+
reader = undefined;
|
|
403
|
+
};
|
|
404
|
+
async function* events() {
|
|
405
|
+
for (;;) {
|
|
406
|
+
const next = said.shift();
|
|
407
|
+
if (next === undefined) {
|
|
408
|
+
await new Promise((resolve) => {
|
|
409
|
+
reader = resolve;
|
|
410
|
+
});
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
yield next;
|
|
414
|
+
if (next.type === "ended") {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
let stopping = false;
|
|
420
|
+
/** Whether the product answered at all: a process that ends before is one that did not start. */
|
|
421
|
+
let began = false;
|
|
422
|
+
/** Whether the session cannot go on, as was said: nothing more is said of how the process ends. */
|
|
423
|
+
let gaveUp = false;
|
|
424
|
+
let session;
|
|
425
|
+
let takesImages = false;
|
|
426
|
+
/** Whether the agent has said what it takes: before that, nothing is known of pictures. */
|
|
427
|
+
let saidWhatItTakes = false;
|
|
428
|
+
let model;
|
|
429
|
+
let effort;
|
|
430
|
+
/** The agent's version, and what the session was last said to run with. */
|
|
431
|
+
let product = null;
|
|
432
|
+
let ran;
|
|
433
|
+
/**
|
|
434
|
+
* Says what the session runs with, where that is not what was said last: when it opens, when
|
|
435
|
+
* a choice is taken in it, and when the agent changes one itself. The runner tells the
|
|
436
|
+
* console from it, so a choice that is taken and not said stays the old one on every page.
|
|
437
|
+
*/
|
|
438
|
+
const runs = () => {
|
|
439
|
+
const now = { model: model?.current ?? null, effort: effort?.current ?? null };
|
|
440
|
+
if (ran !== undefined && ran.model === now.model && ran.effort === now.effort) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
ran = now;
|
|
444
|
+
emit({ type: "running", ...now, version: product });
|
|
445
|
+
};
|
|
446
|
+
/** While a conversation is loaded, what the agent replays of it is none of this session's. */
|
|
447
|
+
let replaying = false;
|
|
448
|
+
/** The turn under way: why it was stopped where it was, and whether the agent was refused leave in it. */
|
|
449
|
+
let turn;
|
|
450
|
+
/** The messages that wait for the session to open, or for the turn under way to end. */
|
|
451
|
+
let waiting = [];
|
|
452
|
+
let ready = false;
|
|
453
|
+
let results = 0;
|
|
454
|
+
/** What the agent says in pieces, kept until it is whole: a block of the transcript. */
|
|
455
|
+
let piece;
|
|
456
|
+
const flush = () => {
|
|
457
|
+
// A block is its words: an agent may begin one with empty lines, which are none of it.
|
|
458
|
+
const words = piece?.text.trim() ?? "";
|
|
459
|
+
if (piece !== undefined && words.length > 0) {
|
|
460
|
+
emit({ type: "event", kind: piece.kind, text: words });
|
|
461
|
+
}
|
|
462
|
+
piece = undefined;
|
|
463
|
+
};
|
|
464
|
+
const chunk = (kind, content) => {
|
|
465
|
+
const text = isObject(content) && content.type === "text" ? textOf(content.text) : undefined;
|
|
466
|
+
if (text === undefined) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (piece !== undefined && piece.kind !== kind) {
|
|
470
|
+
flush();
|
|
471
|
+
}
|
|
472
|
+
piece = { kind, text: `${piece?.text ?? ""}${text}` };
|
|
473
|
+
};
|
|
474
|
+
const toolUpdate = (update, first) => {
|
|
475
|
+
const id = textOf(update.toolCallId);
|
|
476
|
+
if (id === undefined) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
let call = calls.get(id);
|
|
480
|
+
// A call opened under an id whose call is done is another call: an agent that numbers its
|
|
481
|
+
// calls anew at every turn has each of them on the record.
|
|
482
|
+
if (first && call?.done === true) {
|
|
483
|
+
call = undefined;
|
|
484
|
+
}
|
|
485
|
+
const known = call !== undefined;
|
|
486
|
+
if (call === undefined) {
|
|
487
|
+
call = {
|
|
488
|
+
tool: textOf(update.name) ?? textOf(update.kind) ?? "tool",
|
|
489
|
+
title: "",
|
|
490
|
+
input: "",
|
|
491
|
+
said: false,
|
|
492
|
+
done: false,
|
|
493
|
+
content: undefined,
|
|
494
|
+
raw: undefined,
|
|
495
|
+
printed: "",
|
|
496
|
+
};
|
|
497
|
+
calls.set(id, call);
|
|
498
|
+
flush();
|
|
499
|
+
held.push(id);
|
|
500
|
+
}
|
|
501
|
+
if (!call.said && !(known && first)) {
|
|
502
|
+
// What a call is called, and was called with, as it was said last before the call is.
|
|
503
|
+
call.title = textOf(update.title) ?? call.title;
|
|
504
|
+
const input = inputOf(update.rawInput, cut);
|
|
505
|
+
if (input.length > 0) {
|
|
506
|
+
call.input = input;
|
|
507
|
+
}
|
|
508
|
+
// Said once its input is known, or at the next thing said of it: a call may have none.
|
|
509
|
+
if (call.input.length > 0 || known) {
|
|
510
|
+
emit();
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if ((known && first) || call.done) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
// An update says what changed and leaves the rest as it was: what a call holds is what was
|
|
517
|
+
// said of it last, when it began or since.
|
|
518
|
+
if (update.content !== undefined && update.content !== null) {
|
|
519
|
+
call.content = update.content;
|
|
520
|
+
}
|
|
521
|
+
if (update.rawOutput !== undefined && update.rawOutput !== null) {
|
|
522
|
+
call.raw = update.rawOutput;
|
|
523
|
+
}
|
|
524
|
+
// Beside the protocol, an agent may send what a command prints while it runs: whole, or a
|
|
525
|
+
// piece at a time. It is the call's result where the call holds no text of its own.
|
|
526
|
+
const beside = isObject(update._meta) ? update._meta : {};
|
|
527
|
+
const whole = isObject(beside.terminal_output)
|
|
528
|
+
? textOf(beside.terminal_output.data)
|
|
529
|
+
: undefined;
|
|
530
|
+
const more = isObject(beside.terminal_output_delta)
|
|
531
|
+
? textOf(beside.terminal_output_delta.data)
|
|
532
|
+
: undefined;
|
|
533
|
+
if (whole !== undefined) {
|
|
534
|
+
call.printed = whole.slice(0, MAX_PRINTED_LENGTH + PRINTED_BEYOND);
|
|
535
|
+
}
|
|
536
|
+
else if (more !== undefined && call.printed.length < MAX_PRINTED_LENGTH + PRINTED_BEYOND) {
|
|
537
|
+
call.printed = `${call.printed}${more}`.slice(0, MAX_PRINTED_LENGTH + PRINTED_BEYOND);
|
|
538
|
+
}
|
|
539
|
+
const status = textOf(update.status);
|
|
540
|
+
if (status === "completed" || status === "failed") {
|
|
541
|
+
call.done = true;
|
|
542
|
+
flush();
|
|
543
|
+
results += 1;
|
|
544
|
+
const result = contentOf(call.content, `tool-${results}`);
|
|
545
|
+
const output = result.text.length > 0
|
|
546
|
+
? result.text
|
|
547
|
+
: call.printed.trim().length > 0
|
|
548
|
+
? cut(call.printed, MAX_PRINTED_LENGTH,
|
|
549
|
+
// Kept to its bound: what was printed went on, and its end here may begin a secret.
|
|
550
|
+
call.printed.length >= MAX_PRINTED_LENGTH + PRINTED_BEYOND)
|
|
551
|
+
: inputOf(call.raw, cut);
|
|
552
|
+
// Nothing more is read of a call that ended.
|
|
553
|
+
call.content = undefined;
|
|
554
|
+
call.raw = undefined;
|
|
555
|
+
call.printed = "";
|
|
556
|
+
emit({
|
|
557
|
+
type: "event",
|
|
558
|
+
kind: "tool_result",
|
|
559
|
+
text: output,
|
|
560
|
+
data: { id, error: status === "failed" },
|
|
561
|
+
pictures: result.pictures,
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
const onUpdate = (params) => {
|
|
566
|
+
if (replaying || !isObject(params.update)) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const update = params.update;
|
|
570
|
+
switch (update.sessionUpdate) {
|
|
571
|
+
case "agent_message_chunk":
|
|
572
|
+
chunk("assistant", update.content);
|
|
573
|
+
return;
|
|
574
|
+
case "agent_thought_chunk":
|
|
575
|
+
chunk("thinking", update.content);
|
|
576
|
+
return;
|
|
577
|
+
case "tool_call":
|
|
578
|
+
toolUpdate(update, true);
|
|
579
|
+
return;
|
|
580
|
+
case "tool_call_update":
|
|
581
|
+
toolUpdate(update, false);
|
|
582
|
+
return;
|
|
583
|
+
case "plan": {
|
|
584
|
+
flush();
|
|
585
|
+
const lines = listOf(update.entries)
|
|
586
|
+
.filter(isObject)
|
|
587
|
+
.map((entry) => `- [${textOf(entry.status) ?? "pending"}] ${textOf(entry.content) ?? ""}`);
|
|
588
|
+
if (lines.length > 0) {
|
|
589
|
+
emit({ type: "event", kind: "status", text: `Plan:\n${lines.join("\n")}` });
|
|
590
|
+
}
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
case "notice": {
|
|
594
|
+
// What the agent tells beside its work: an error as one, anything else as a status.
|
|
595
|
+
const title = textOf(update.title)?.trim() ?? "";
|
|
596
|
+
const more = textOf(update.description)?.trim() ?? "";
|
|
597
|
+
const words = [title, more].filter((one) => one.length > 0).join("\n");
|
|
598
|
+
if (words.length > 0) {
|
|
599
|
+
flush();
|
|
600
|
+
emit({
|
|
601
|
+
type: "event",
|
|
602
|
+
kind: update.severity === "error" ? "error" : "status",
|
|
603
|
+
text: cut(words, MAX_INPUT_LENGTH),
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
case "config_option_update":
|
|
609
|
+
model = choiceOf(update.configOptions, "model") ?? model;
|
|
610
|
+
effort = choiceOf(update.configOptions, "thought_level") ?? effort;
|
|
611
|
+
runs();
|
|
612
|
+
return;
|
|
613
|
+
default:
|
|
614
|
+
// What the client was not asked to keep: the commands the agent offers, its mode, how
|
|
615
|
+
// much it used, what a person typed, said back.
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
const onRequest = (id, method, params) => {
|
|
620
|
+
if (method !== "session/request_permission") {
|
|
621
|
+
// No file and no terminal were offered: an agent that asks for one all the same is told.
|
|
622
|
+
void connection
|
|
623
|
+
.refuse(id, METHOD_NOT_FOUND, `${method} is not offered`)
|
|
624
|
+
.catch(() => undefined);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const call = isObject(params.toolCall) ? params.toolCall : {};
|
|
628
|
+
const callId = textOf(call.toolCallId);
|
|
629
|
+
const known = callId === undefined ? undefined : calls.get(callId);
|
|
630
|
+
const title = textOf(call.title) ?? known?.tool ?? "a tool call";
|
|
631
|
+
const kinds = mode === "allow" ? ["allow_once", "allow_always"] : ["reject_once", "reject_always"];
|
|
632
|
+
const options = listOf(params.options).filter(isObject);
|
|
633
|
+
const option = kinds
|
|
634
|
+
.map((kind) => options.find((one) => one.kind === kind))
|
|
635
|
+
.find((one) => one !== undefined && typeof one.optionId === "string");
|
|
636
|
+
const data = {
|
|
637
|
+
tool: known?.tool ?? textOf(call.kind) ?? "tool",
|
|
638
|
+
answer: option === undefined ? "cancelled" : mode === "allow" ? "allowed" : "denied",
|
|
639
|
+
};
|
|
640
|
+
if (callId !== undefined) {
|
|
641
|
+
data.id = callId;
|
|
642
|
+
}
|
|
643
|
+
if (turn !== undefined && data.answer !== "allowed") {
|
|
644
|
+
turn.refused = true;
|
|
645
|
+
}
|
|
646
|
+
flush();
|
|
647
|
+
emit({
|
|
648
|
+
type: "event",
|
|
649
|
+
kind: "permission",
|
|
650
|
+
text: option === undefined
|
|
651
|
+
? `Not answered, the agent offered no way to ${mode === "allow" ? "allow" : "refuse"} it: ${title}`
|
|
652
|
+
: mode === "allow"
|
|
653
|
+
? `Allowed, with nobody at the terminal to ask: ${title}`
|
|
654
|
+
: `Denied, with nobody at the terminal to ask: ${title}`,
|
|
655
|
+
data,
|
|
656
|
+
});
|
|
657
|
+
void connection
|
|
658
|
+
.answer(id, {
|
|
659
|
+
outcome: option === undefined
|
|
660
|
+
? { outcome: "cancelled" }
|
|
661
|
+
: { outcome: "selected", optionId: option.optionId },
|
|
662
|
+
})
|
|
663
|
+
.catch(() => undefined);
|
|
664
|
+
};
|
|
665
|
+
/**
|
|
666
|
+
* Sets one of the product's choices; whether it took it. Nothing asked is taken. Within
|
|
667
|
+
* `within` where one is given: an answer that comes later is not waited for, and the choice
|
|
668
|
+
* counts as not taken, which the runner then gives the next session.
|
|
669
|
+
*/
|
|
670
|
+
const choose = async (choice, value, within) => {
|
|
671
|
+
if (value === undefined || value === null) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
if (session === undefined || choice === undefined || !choice.values.includes(value)) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
if (choice.current === value) {
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
try {
|
|
681
|
+
const asked = connection.request("session/set_config_option", {
|
|
682
|
+
sessionId: session,
|
|
683
|
+
configId: choice.id,
|
|
684
|
+
value,
|
|
685
|
+
});
|
|
686
|
+
const result = within === undefined ? await asked : await Promise.race([asked, wait(within)]);
|
|
687
|
+
if (result === "timeout") {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
const options = isObject(result) ? result.configOptions : undefined;
|
|
691
|
+
model = choiceOf(options, "model") ?? model;
|
|
692
|
+
effort = choiceOf(options, "thought_level") ?? effort;
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
catch {
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
/**
|
|
700
|
+
* How the session stands to what the agent may do. The driver's own two words leave the
|
|
701
|
+
* agent's mode as it is. A mode of the agent's own, the one the desk names or, where it names
|
|
702
|
+
* none, the one the agent has for a run nobody attends, is set, and what the agent still asks
|
|
703
|
+
* is refused. A mode named that the agent does not offer is a mistake in the desk's file, and
|
|
704
|
+
* is never read as leave to do more.
|
|
705
|
+
*/
|
|
706
|
+
const stand = async (standing, agent) => {
|
|
707
|
+
const named = options.permissions;
|
|
708
|
+
if (named === "allow" || named === "deny") {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const wanted = named ?? (agent === undefined ? undefined : UNATTENDED_MODES[agent]);
|
|
712
|
+
if (wanted === undefined) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const offered = standing?.choice.values ?? [];
|
|
716
|
+
if (standing === undefined || !offered.includes(wanted)) {
|
|
717
|
+
if (named !== undefined) {
|
|
718
|
+
emit({
|
|
719
|
+
type: "event",
|
|
720
|
+
kind: "status",
|
|
721
|
+
text: `runner.json names the mode ${named}, which this agent does not offer${offered.length === 0 ? "" : ` (it offers ${offered.join(", ")})`}: it runs in its own, and what it asks leave for is refused.`,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
mode = "deny";
|
|
727
|
+
if (standing.choice.current === wanted) {
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
try {
|
|
731
|
+
if (standing.by === "option") {
|
|
732
|
+
await connection.request("session/set_config_option", {
|
|
733
|
+
sessionId: session ?? "",
|
|
734
|
+
configId: standing.choice.id,
|
|
735
|
+
value: wanted,
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
await connection.request("session/set_mode", { sessionId: session ?? "", modeId: wanted });
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
emit({
|
|
744
|
+
type: "event",
|
|
745
|
+
kind: "status",
|
|
746
|
+
text: `The agent did not take the mode ${wanted}${error instanceof Error ? ` (${error.message})` : ""}: it runs in its own, and what it asks leave for is refused.`,
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
/** One turn: what arrived together is read together, each under its own header. */
|
|
751
|
+
const prompt = (messages) => {
|
|
752
|
+
const mine = { cut: undefined, refused: false };
|
|
753
|
+
turn = mine;
|
|
754
|
+
// A turn's messages are the agent's once it is prompted with them: said once for each.
|
|
755
|
+
emit(...messages.map(() => ({ type: "taken" })));
|
|
756
|
+
const blocks = [];
|
|
757
|
+
for (const message of messages) {
|
|
758
|
+
const left = takesImages ? [] : message.images;
|
|
759
|
+
// Where the runner did not know yet that this agent takes no picture, the message says a
|
|
760
|
+
// picture was shown: said here that it was not, with where it is in the desk.
|
|
761
|
+
const where = left.flatMap((image) => (image.path === undefined ? [] : [image.path]));
|
|
762
|
+
blocks.push({
|
|
763
|
+
type: "text",
|
|
764
|
+
text: left.length === 0
|
|
765
|
+
? message.text
|
|
766
|
+
: `${message.text}\n\n(${left.length} picture${left.length === 1 ? "" : "s"} came with this and ${left.length === 1 ? "was" : "were"} not shown to you: this agent takes none as a picture.${where.length === 0 ? "" : ` Open ${where.join(", ")}.`})`,
|
|
767
|
+
});
|
|
768
|
+
for (const image of takesImages ? message.images : []) {
|
|
769
|
+
blocks.push({
|
|
770
|
+
type: "image",
|
|
771
|
+
mimeType: image.contentType,
|
|
772
|
+
data: Buffer.from(image.bytes).toString("base64"),
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
void (async () => {
|
|
777
|
+
let reason;
|
|
778
|
+
let failure;
|
|
779
|
+
try {
|
|
780
|
+
const result = await connection.request("session/prompt", {
|
|
781
|
+
sessionId: session ?? "",
|
|
782
|
+
prompt: blocks,
|
|
783
|
+
});
|
|
784
|
+
reason = isObject(result) ? textOf(result.stopReason) : undefined;
|
|
785
|
+
}
|
|
786
|
+
catch (error) {
|
|
787
|
+
failure = error;
|
|
788
|
+
}
|
|
789
|
+
flush();
|
|
790
|
+
turn = undefined;
|
|
791
|
+
if (gaveUp) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
if (failure !== undefined) {
|
|
795
|
+
const words = failure instanceof Error ? failure.message : String(failure);
|
|
796
|
+
if (failure instanceof RpcError) {
|
|
797
|
+
emit({ type: "event", kind: "error", text: `The agent refused the turn: ${words}` });
|
|
798
|
+
if (failure.code === AUTH_REQUIRED || SIGN_IN.test(words)) {
|
|
799
|
+
gaveUp = true;
|
|
800
|
+
waiting = [];
|
|
801
|
+
emit({ type: "cannot_go_on", state: "failed", reason: "sign_in" });
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
// A turn the agent itself said failed is a turn that ended: it takes the next message.
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
// The process is gone: how it ended is said where its output ends.
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
else if (reason === "refusal") {
|
|
812
|
+
gaveUp = true;
|
|
813
|
+
waiting = [];
|
|
814
|
+
emit({ type: "event", kind: "error", text: "The model refused to answer." }, { type: "cannot_go_on", state: "refused", reason: "model_refused" });
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
else if (reason === "cancelled" || mine.cut !== undefined) {
|
|
818
|
+
emit({
|
|
819
|
+
type: "event",
|
|
820
|
+
kind: "status",
|
|
821
|
+
// An agent may end its turn where it is refused leave: nobody stopped that one.
|
|
822
|
+
text: mine.cut === "message"
|
|
823
|
+
? "The turn was stopped for a message."
|
|
824
|
+
: mine.cut === undefined && mine.refused
|
|
825
|
+
? "The agent ended the turn where it was refused leave."
|
|
826
|
+
: "The turn was stopped.",
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
else if (reason === "max_tokens" || reason === "max_turn_requests") {
|
|
830
|
+
emit({
|
|
831
|
+
type: "event",
|
|
832
|
+
kind: "status",
|
|
833
|
+
text: reason === "max_tokens"
|
|
834
|
+
? "The turn ended at the most the model writes in one."
|
|
835
|
+
: "The turn ended at the most requests the agent makes in one.",
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
// The agent is done when nothing it was sent still waits: what arrived meanwhile is its next turn.
|
|
839
|
+
if (waiting.length > 0) {
|
|
840
|
+
const next = waiting;
|
|
841
|
+
waiting = [];
|
|
842
|
+
prompt(next);
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
emit({ type: "turn_completed" });
|
|
846
|
+
}
|
|
847
|
+
})();
|
|
848
|
+
};
|
|
849
|
+
const stopTurn = (cut) => {
|
|
850
|
+
if (turn === undefined || turn.cut !== undefined || session === undefined) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
turn.cut = cut;
|
|
854
|
+
void connection.notify("session/cancel", { sessionId: session }).catch(() => undefined);
|
|
855
|
+
};
|
|
856
|
+
/** Why the session could not open, said once; the process is ended, and nothing more is said of it. */
|
|
857
|
+
const cannotStart = (text, reason) => {
|
|
858
|
+
gaveUp = true;
|
|
859
|
+
waiting = [];
|
|
860
|
+
emit({ type: "event", kind: "error", text }, { type: "cannot_go_on", state: "failed", reason });
|
|
861
|
+
void endOf(child);
|
|
862
|
+
};
|
|
863
|
+
const open = async () => {
|
|
864
|
+
const initialized = await connection.request("initialize", hello(own));
|
|
865
|
+
began = true;
|
|
866
|
+
const version = isObject(initialized) ? initialized.protocolVersion : undefined;
|
|
867
|
+
if (version !== PROTOCOL_VERSION) {
|
|
868
|
+
cannotStart(`The product speaks version ${String(version)} of the Agent Client Protocol, and this runner version ${PROTOCOL_VERSION}.`, "start");
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
const capabilities = isObject(initialized) && isObject(initialized.agentCapabilities)
|
|
872
|
+
? initialized.agentCapabilities
|
|
873
|
+
: {};
|
|
874
|
+
takesImages =
|
|
875
|
+
isObject(capabilities.promptCapabilities) && capabilities.promptCapabilities.image === true;
|
|
876
|
+
saidWhatItTakes = true;
|
|
877
|
+
const resumes = isObject(capabilities.sessionCapabilities) &&
|
|
878
|
+
capabilities.sessionCapabilities.resume !== undefined &&
|
|
879
|
+
capabilities.sessionCapabilities.resume !== null &&
|
|
880
|
+
capabilities.sessionCapabilities.resume !== false;
|
|
881
|
+
const loads = capabilities.loadSession === true;
|
|
882
|
+
const place = { cwd: options.cwd, mcpServers: [] };
|
|
883
|
+
let opened;
|
|
884
|
+
if (options.resume !== undefined && (resumes || loads)) {
|
|
885
|
+
// Gone on with where the agent can: without its history said again where it resumes, and
|
|
886
|
+
// with it replayed, and left unread, where it only loads.
|
|
887
|
+
replaying = !resumes;
|
|
888
|
+
try {
|
|
889
|
+
opened = await connection.request(resumes ? "session/resume" : "session/load", {
|
|
890
|
+
sessionId: options.resume,
|
|
891
|
+
...place,
|
|
892
|
+
});
|
|
893
|
+
session = options.resume;
|
|
894
|
+
}
|
|
895
|
+
catch (error) {
|
|
896
|
+
// Not signed in is said as that, and a process that is gone where its output ends.
|
|
897
|
+
if (!(error instanceof RpcError) ||
|
|
898
|
+
error.code === AUTH_REQUIRED ||
|
|
899
|
+
SIGN_IN.test(error.message)) {
|
|
900
|
+
throw error;
|
|
901
|
+
}
|
|
902
|
+
// A conversation the agent has no more, or never kept: said, and a new one begun, as
|
|
903
|
+
// the runner begins one where the conversation kept was another product's.
|
|
904
|
+
emit({
|
|
905
|
+
type: "event",
|
|
906
|
+
kind: "status",
|
|
907
|
+
text: `The agent could not go on with the conversation it had (${error.message}): a new one begins.`,
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
finally {
|
|
911
|
+
replaying = false;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
else if (options.resume !== undefined) {
|
|
915
|
+
emit({
|
|
916
|
+
type: "event",
|
|
917
|
+
kind: "status",
|
|
918
|
+
text: "This agent goes on with no conversation from one session to the next: a new one begins.",
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
if (session === undefined) {
|
|
922
|
+
opened = await connection.request("session/new", place);
|
|
923
|
+
session = isObject(opened) ? textOf(opened.sessionId) : undefined;
|
|
924
|
+
if (session === undefined) {
|
|
925
|
+
cannotStart("The product opened a session and did not say which.", "start");
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
const configuration = isObject(opened) ? opened.configOptions : undefined;
|
|
930
|
+
model = choiceOf(configuration, "model");
|
|
931
|
+
effort = choiceOf(configuration, "thought_level");
|
|
932
|
+
await choose(model, options.model);
|
|
933
|
+
await choose(effort, options.effort);
|
|
934
|
+
const agent = agentOf(initialized);
|
|
935
|
+
await stand(standingOf(opened), agent.name);
|
|
936
|
+
product = agent.version ?? null;
|
|
937
|
+
emit({ type: "conversation", id: session });
|
|
938
|
+
runs();
|
|
939
|
+
ready = true;
|
|
940
|
+
if (waiting.length > 0) {
|
|
941
|
+
const next = waiting;
|
|
942
|
+
waiting = [];
|
|
943
|
+
prompt(next);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
void (async () => {
|
|
947
|
+
const reading = connection.read({
|
|
948
|
+
notification: (method, params) => {
|
|
949
|
+
if (method === "session/update") {
|
|
950
|
+
onUpdate(params);
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
request: onRequest,
|
|
954
|
+
});
|
|
955
|
+
const opening = open().catch((error) => {
|
|
956
|
+
if (gaveUp || stopping) {
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (error instanceof RpcError) {
|
|
960
|
+
const signIn = error.code === AUTH_REQUIRED || SIGN_IN.test(error.message);
|
|
961
|
+
cannotStart(signIn
|
|
962
|
+
? `The product is not signed in: ${error.message}`
|
|
963
|
+
: `The product did not open a session: ${error.message}`, signIn ? "sign_in" : "start");
|
|
964
|
+
}
|
|
965
|
+
// Anything else is a process that is gone: how it ended is said where its output ends.
|
|
966
|
+
});
|
|
967
|
+
const late = wait(START_TIMEOUT_MS).then(() => {
|
|
968
|
+
if (!ready && !gaveUp && !stopping) {
|
|
969
|
+
cannotStart("The product did not open a session in time.", "start");
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
void late;
|
|
973
|
+
await reading;
|
|
974
|
+
await opening;
|
|
975
|
+
flush();
|
|
976
|
+
const exit = await child.exited;
|
|
977
|
+
const clean = stopping || (exit.code === 0 && exit.signal === null && exit.error === undefined);
|
|
978
|
+
if (!clean && !gaveUp) {
|
|
979
|
+
const errors = child.errors().trim();
|
|
980
|
+
// Its end, cut after the secrets are out, so that none stands at the cut.
|
|
981
|
+
const shown = errorsShown(errors, options.cutEnd ?? plainCutEnd);
|
|
982
|
+
emit({
|
|
983
|
+
type: "event",
|
|
984
|
+
kind: "error",
|
|
985
|
+
text: exit.error !== undefined
|
|
986
|
+
? `The product could not be started: ${exit.error}`
|
|
987
|
+
: `The product's process ended${exit.signal === null ? ` with code ${exit.code}` : ` on ${exit.signal}`}.${shown.length === 0 ? "" : `\n${shown}`}`,
|
|
988
|
+
}, {
|
|
989
|
+
type: "cannot_go_on",
|
|
990
|
+
state: "failed",
|
|
991
|
+
reason: SIGN_IN.test(errors) ? "sign_in" : began ? "crashed" : "start",
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
emit({ type: "ended", how: clean ? "exited" : "crashed" });
|
|
995
|
+
})();
|
|
996
|
+
return {
|
|
997
|
+
events: events(),
|
|
998
|
+
images: () => (saidWhatItTakes ? takesImages : undefined),
|
|
999
|
+
async send(message) {
|
|
1000
|
+
if (stopping || gaveUp) {
|
|
1001
|
+
throw new Error("the session takes no more input");
|
|
1002
|
+
}
|
|
1003
|
+
if (!ready || turn !== undefined) {
|
|
1004
|
+
waiting.push(message);
|
|
1005
|
+
// The protocol takes no message in a turn: one to be read now stops the turn, and is
|
|
1006
|
+
// the turn after.
|
|
1007
|
+
if (message.priority === "now") {
|
|
1008
|
+
stopTurn("message");
|
|
1009
|
+
}
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
prompt([message]);
|
|
1013
|
+
},
|
|
1014
|
+
async interrupt() {
|
|
1015
|
+
stopTurn("stopped");
|
|
1016
|
+
},
|
|
1017
|
+
async set(next) {
|
|
1018
|
+
const tookModel = await choose(model, next.model, setMs);
|
|
1019
|
+
const tookEffort = await choose(effort, next.effort, setMs);
|
|
1020
|
+
runs();
|
|
1021
|
+
return tookModel && tookEffort;
|
|
1022
|
+
},
|
|
1023
|
+
async stop() {
|
|
1024
|
+
stopping = true;
|
|
1025
|
+
await endOf(child);
|
|
1026
|
+
},
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
/** A session that never began, with why: said once, as an agent that cannot go on. */
|
|
1030
|
+
function unstarted(text) {
|
|
1031
|
+
async function* events() {
|
|
1032
|
+
yield { type: "event", kind: "error", text };
|
|
1033
|
+
yield { type: "cannot_go_on", state: "failed", reason: "start" };
|
|
1034
|
+
yield { type: "ended", how: "crashed" };
|
|
1035
|
+
}
|
|
1036
|
+
return {
|
|
1037
|
+
events: events(),
|
|
1038
|
+
send: async () => {
|
|
1039
|
+
throw new Error("the session takes no more input");
|
|
1040
|
+
},
|
|
1041
|
+
interrupt: async () => undefined,
|
|
1042
|
+
set: async () => false,
|
|
1043
|
+
stop: async () => undefined,
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* What the driver is started with: the command that speaks the protocol and its words, which
|
|
1048
|
+
* `runner.json` names, since there is no one product behind this driver.
|
|
1049
|
+
*/
|
|
1050
|
+
export function createAcpDriver(host) {
|
|
1051
|
+
const command = host.command;
|
|
1052
|
+
const args = host.args ?? [];
|
|
1053
|
+
/** What the product said it is called, once it was asked. */
|
|
1054
|
+
let name;
|
|
1055
|
+
const start = (cwd, env) => host.spawn(command ?? "", args, { cwd, env });
|
|
1056
|
+
return {
|
|
1057
|
+
name: "acp",
|
|
1058
|
+
get product() {
|
|
1059
|
+
return {
|
|
1060
|
+
name: name ?? "An agent over the Agent Client Protocol",
|
|
1061
|
+
tried: (name === undefined ? undefined : TRIED[name]) ?? [],
|
|
1062
|
+
};
|
|
1063
|
+
},
|
|
1064
|
+
// A message waits for the turn under way, or stops it: none is taken in one. Pictures, a
|
|
1065
|
+
// conversation gone on with and the model are the agent's to offer, and are asked of it.
|
|
1066
|
+
can: { steer: false, images: true, resume: true, set: true },
|
|
1067
|
+
permissions: { modes: MODES, unattended: UNATTENDED_MODE, least: LEAST_MODE },
|
|
1068
|
+
async probe() {
|
|
1069
|
+
const nothing = { version: undefined, models: [], efforts: [] };
|
|
1070
|
+
if (command === undefined) {
|
|
1071
|
+
return nothing;
|
|
1072
|
+
}
|
|
1073
|
+
let child;
|
|
1074
|
+
try {
|
|
1075
|
+
child = start(host.cwd, {});
|
|
1076
|
+
}
|
|
1077
|
+
catch {
|
|
1078
|
+
return nothing;
|
|
1079
|
+
}
|
|
1080
|
+
const connection = connectionOf(child);
|
|
1081
|
+
const reading = connection.read({
|
|
1082
|
+
notification: () => undefined,
|
|
1083
|
+
request: (id, method) => {
|
|
1084
|
+
void connection
|
|
1085
|
+
.refuse(id, METHOD_NOT_FOUND, `${method} is not offered`)
|
|
1086
|
+
.catch(() => undefined);
|
|
1087
|
+
},
|
|
1088
|
+
});
|
|
1089
|
+
const asked = (async () => {
|
|
1090
|
+
const initialized = await connection.request("initialize", hello(host.version));
|
|
1091
|
+
const agent = agentOf(initialized);
|
|
1092
|
+
name = agent.name ?? name;
|
|
1093
|
+
try {
|
|
1094
|
+
// What it offers to choose from is a session's to say: one is opened, and closed
|
|
1095
|
+
// again where the agent closes one, so that it keeps nothing of a session nobody had.
|
|
1096
|
+
const opened = await connection.request("session/new", { cwd: host.cwd, mcpServers: [] });
|
|
1097
|
+
const configuration = isObject(opened) ? opened.configOptions : undefined;
|
|
1098
|
+
const capabilities = isObject(initialized) && isObject(initialized.agentCapabilities)
|
|
1099
|
+
? initialized.agentCapabilities
|
|
1100
|
+
: {};
|
|
1101
|
+
const closes = isObject(capabilities.sessionCapabilities) &&
|
|
1102
|
+
isObject(capabilities.sessionCapabilities.close);
|
|
1103
|
+
const opening = isObject(opened) ? textOf(opened.sessionId) : undefined;
|
|
1104
|
+
if (closes && opening !== undefined) {
|
|
1105
|
+
await connection
|
|
1106
|
+
.request("session/close", { sessionId: opening })
|
|
1107
|
+
.catch(() => undefined);
|
|
1108
|
+
}
|
|
1109
|
+
return {
|
|
1110
|
+
version: agent.version,
|
|
1111
|
+
models: choiceOf(configuration, "model")?.values ?? [],
|
|
1112
|
+
efforts: choiceOf(configuration, "thought_level")?.values ?? [],
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
catch {
|
|
1116
|
+
return { version: agent.version, models: [], efforts: [] };
|
|
1117
|
+
}
|
|
1118
|
+
})().catch(() => nothing);
|
|
1119
|
+
const probe = await Promise.race([asked, wait(PROBE_TIMEOUT_MS).then(() => nothing)]);
|
|
1120
|
+
await endOf(child);
|
|
1121
|
+
await reading;
|
|
1122
|
+
return probe;
|
|
1123
|
+
},
|
|
1124
|
+
start(options) {
|
|
1125
|
+
if (command === undefined) {
|
|
1126
|
+
return unstarted("runner.json names the driver acp and no command for it: say which program speaks the protocol, as product.command.");
|
|
1127
|
+
}
|
|
1128
|
+
return sessionOf(start(options.cwd, options.env), options, host.version, host.timing?.setMs);
|
|
1129
|
+
},
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
//# sourceMappingURL=acp.js.map
|