@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
package/dist/cli/cli.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
import { basename, extname } from "node:path";
|
|
1
|
+
import { basename, extname, isAbsolute } from "node:path";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
+
import { deflateSync } from "node:zlib";
|
|
4
|
+
import { PackError, ReadMisuse, readNumber, readPack, wroteLine, } from "@skillcdn/cli";
|
|
5
|
+
import { BROWSE_MAX_LIMIT, FIND_MAX_LIMIT, READ_FILE_MAX_LIMIT, } from "@skillcdn/core";
|
|
6
|
+
import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
|
|
3
7
|
import { ApiError, createClient, } from "../client.js";
|
|
4
8
|
import { CLIENT_RANGE_HEADER, CONSOLE_AT_LEAST, consoleRange, formatRange, judgeClient, judgeConsole, parseVersion, VERSION_HEADER, formatVersion as versionText, } from "../compat.js";
|
|
9
|
+
import { normalizeConnectCode } from "../connect.js";
|
|
5
10
|
import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
|
|
6
|
-
import { DEFAULT_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MIN_OPTIONS, } from "../limits.js";
|
|
11
|
+
import { DEFAULT_PAGE_LIMIT, EVENTS_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, MIN_OPTIONS, } from "../limits.js";
|
|
7
12
|
import { capabilityWords } from "../plugin/capabilities.js";
|
|
8
13
|
import { PLUGIN_LIST_LIMIT } from "../plugin/limits.js";
|
|
14
|
+
import { checkRecords, RECORDS_DIR, RECORDS_INDEX_FILE } from "../records.js";
|
|
15
|
+
import { decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
|
|
9
16
|
import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
|
|
17
|
+
import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
|
|
18
|
+
import { DESK_FOLDER, deskFiles, deskServicesOf, deskWebTitleOf, personDeskFiles, } from "../runner/desk.js";
|
|
19
|
+
import { ownRunnerModules } from "../runner/modules.js";
|
|
20
|
+
import { createRunner, GIT_TOKEN_SECRET } from "../runner/runner.js";
|
|
10
21
|
import { hostOfLogin, } from "../schemas.js";
|
|
11
|
-
import {
|
|
22
|
+
import { agentLoginOf, deskRemoteOf } from "../services.js";
|
|
23
|
+
import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
|
|
24
|
+
import { COLOR_NAMES, CONSOLE_LANGUAGES, GOAL_STATES, PEOPLE_VISIBILITIES, PERSON_ROLES, PROJECT_ROLES, PROJECT_VISIBILITIES, PROVIDER_KEYS, SERVICE_ROLES, TASK_PRIORITIES, TASK_STATES, WEEK_STARTS, } from "../vocabulary.js";
|
|
12
25
|
import { loadWebRoot, WebRootError } from "../web.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
26
|
+
import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
|
|
27
|
+
import { CredentialsError, EMPTY_CREDENTIALS, fitsFile, keepsNothing, lasts, loginsAt, pendingAt, resolveLogin, withLogin, withoutLogin, withoutPending, withPending, } from "./credentials.js";
|
|
28
|
+
import { DIRECTORY_FILE, THE_SENTENCE, } from "./directory.js";
|
|
29
|
+
import { calledOf, deciderLogins, formatAgent, formatAgentLine, formatAnswer, formatCategoryLine, formatComment, formatDecision, formatDecisionLine, formatDocument, formatDocuments, formatGoal, formatGoalLine, formatInvocation, formatListingLine, formatMemberLine, formatMore, formatOptions, formatPersonLine, formatPersonWork, formatPlugin, formatPluginAsks, formatPluginEvents, formatPluginGrantLine, formatPluginHelp, formatPluginRecord, formatPluginRecords, formatPluginRecordVersions, formatPluginSettingLine, formatPlugins, formatProject, formatProjectLine, formatRules, formatRulesChanged, formatRulesLeftOut, formatRun, formatRunLine, formatSecretLine, formatSignalLine, formatTask, formatTaskLine, formatTeamLine, formatVersion, formatVersionLine, formatWork, formatWorkspace, localized, moment, pageLine, rulesMark, setMomentZone, } from "./format.js";
|
|
16
30
|
import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
|
|
17
31
|
import { describeInstall, updateCommandFor } from "./install.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
32
|
+
import { consolePack, formatSkills, holdsNothing, ORGANIZATION_PACK_LINE, PackRefusal, packWords, refusalWords, skillPathIn, } from "./pack.js";
|
|
33
|
+
import { workPath } from "./runner-host.js";
|
|
34
|
+
import { createServeHandler, DEFAULT_SERVE_PORT, loadRecordsRoot, RecordsRootError, } from "./serve.js";
|
|
20
35
|
// The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
|
|
21
36
|
// the REST API with no logic of its own: every command is one or two requests and the words to
|
|
22
37
|
// say what came back. It takes what it needs from `CliIo`, so that tests run it whole, against
|
|
@@ -29,7 +44,7 @@ export const EXIT = {
|
|
|
29
44
|
failed: 1,
|
|
30
45
|
/** The command was not understood. */
|
|
31
46
|
usage: 2,
|
|
32
|
-
/**
|
|
47
|
+
/** What was waited for still waits for a person: a decision's answer, or a connection's approval. */
|
|
33
48
|
waiting: 3,
|
|
34
49
|
/** The command and the console do not go together (ADR-0025): stderr says which to update, and how. */
|
|
35
50
|
incompatible: 4,
|
|
@@ -44,6 +59,12 @@ const WAIT_PAUSE_MS = 500;
|
|
|
44
59
|
const DEFAULT_ASK_WAIT_SECONDS = 60;
|
|
45
60
|
/** The longest wait a person may ask for: a day. */
|
|
46
61
|
const MAX_WAIT_SECONDS = 86_400;
|
|
62
|
+
/**
|
|
63
|
+
* How long `login` waits for the approval of a connection a call before it began, where no
|
|
64
|
+
* terminal shows its words as they are printed (ADR-0129): within the two minutes an agent's
|
|
65
|
+
* host gives a command before it cuts it off.
|
|
66
|
+
*/
|
|
67
|
+
const DEFAULT_LOGIN_WAIT_SECONDS = 90;
|
|
47
68
|
/** The command stops with an exit code and a word on stderr. */
|
|
48
69
|
class CliExit extends Error {
|
|
49
70
|
exit;
|
|
@@ -94,6 +115,79 @@ const texts = (values, name) => {
|
|
|
94
115
|
}
|
|
95
116
|
return typeof value === "string" ? [value] : [];
|
|
96
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* What is said of a project the console does not have, or does not show the member: the key,
|
|
120
|
+
* the console and what named the key, then the two things a person can do about it, each
|
|
121
|
+
* something to ask for or to do. An agent that reads only "not found" guesses at causes; one of
|
|
122
|
+
* these two is always the one. `login` is the member's, where the command knows it. Both are
|
|
123
|
+
* said as what is done and by whom, never as a command to whoever reads: an agent told to do
|
|
124
|
+
* as it saw fit took "bind this directory anew" for its own step, bound the checkout to another
|
|
125
|
+
* project and went on with no task. Which key is right is the repository's agreement's to say,
|
|
126
|
+
* or the person's.
|
|
127
|
+
*/
|
|
128
|
+
function unseenProjectWords(url, named, login) {
|
|
129
|
+
const right = "the right one, the key the repository's agreement names or the one the person says";
|
|
130
|
+
const mend = named.source.kind === "directory"
|
|
131
|
+
? `the directory is bound to ${right}, with console use <key>`
|
|
132
|
+
: named.source.kind === "environment"
|
|
133
|
+
? `CONSOLE_PROJECT is set to ${right}, or unset`
|
|
134
|
+
: `--project is given ${right}`;
|
|
135
|
+
return [
|
|
136
|
+
`project.not_found: ${url} has no project ${named.key}, or it is not yours to see. The key is named by ${sourceWords(named.source)}.`,
|
|
137
|
+
`Where the project is there and you are not in it, one of its owners lists you: console member add ${login ?? "<your login>"} --project ${named.key}. Where the key is wrong, ${mend}; console projects lists the projects you may work in at this console.`,
|
|
138
|
+
].join("\n");
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The console's refusal of the project a directory or the environment names, with the words
|
|
142
|
+
* above: still the refusal it was, for the code that reads one (a decision is looked for
|
|
143
|
+
* elsewhere when its project is not found), and said in full where the command ends on it.
|
|
144
|
+
*/
|
|
145
|
+
class UnseenProject extends ApiError {
|
|
146
|
+
words;
|
|
147
|
+
constructor(refusal, words) {
|
|
148
|
+
super(refusal.status, refusal.code, refusal.message);
|
|
149
|
+
this.name = "UnseenProject";
|
|
150
|
+
this.words = words;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A project's client whose refusals as `project.not_found` carry `words`: every command that
|
|
155
|
+
* works in the directory's project goes through one, so that the refusal names the key, the
|
|
156
|
+
* console and what named it wherever it is met, and no command says it for itself.
|
|
157
|
+
*/
|
|
158
|
+
function namingUnseen(project, words) {
|
|
159
|
+
return new Proxy(project, {
|
|
160
|
+
get(target, property, receiver) {
|
|
161
|
+
const member = Reflect.get(target, property, receiver);
|
|
162
|
+
if (typeof member !== "function") {
|
|
163
|
+
return member;
|
|
164
|
+
}
|
|
165
|
+
return (...args) => {
|
|
166
|
+
const result = Reflect.apply(member, target, args);
|
|
167
|
+
return result instanceof Promise
|
|
168
|
+
? result.catch((error) => {
|
|
169
|
+
throw error instanceof ApiError && error.code === "project.not_found"
|
|
170
|
+
? new UnseenProject(error, words())
|
|
171
|
+
: error;
|
|
172
|
+
})
|
|
173
|
+
: result;
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/** Where a project's key came from, as `whoami` and its refusal say it. */
|
|
179
|
+
function sourceWords(source) {
|
|
180
|
+
switch (source.kind) {
|
|
181
|
+
case "flag":
|
|
182
|
+
return "--project";
|
|
183
|
+
case "environment":
|
|
184
|
+
return "CONSOLE_PROJECT";
|
|
185
|
+
case "directory":
|
|
186
|
+
return source.directory === undefined
|
|
187
|
+
? DIRECTORY_FILE
|
|
188
|
+
: `${DIRECTORY_FILE} in ${source.directory}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
97
191
|
const NO_PROJECT = "Say which project: --project <key>, CONSOLE_PROJECT in the environment, or console use <key> once in this directory. console projects lists the projects you may work in.";
|
|
98
192
|
/** What the command keeps, or nothing; a file that cannot be read stops the command, and is never written over. */
|
|
99
193
|
async function loadCredentials(io) {
|
|
@@ -107,6 +201,18 @@ async function loadCredentials(io) {
|
|
|
107
201
|
throw error;
|
|
108
202
|
}
|
|
109
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* What is about to be kept, where the credentials file would read it back; else the command
|
|
206
|
+
* stops, and nothing is written. What a console answered comes to rest in that file, and
|
|
207
|
+
* anything at an address may answer to nobody: kept beyond the file's own bounds, it would have
|
|
208
|
+
* every later command stop on a file it cannot read, at every console.
|
|
209
|
+
*/
|
|
210
|
+
function fitting(next, url) {
|
|
211
|
+
if (!fitsFile(next)) {
|
|
212
|
+
throw failed(`${url} answered what the command cannot keep: a code, a token or a name beyond the bounds a console's have. Nothing was kept. Check that the address is the console's, and sign in again.`);
|
|
213
|
+
}
|
|
214
|
+
return next;
|
|
215
|
+
}
|
|
110
216
|
/** The console a directory is bound to, as an origin, when it names one. */
|
|
111
217
|
function directoryOrigin(settings) {
|
|
112
218
|
if (settings?.url === undefined) {
|
|
@@ -167,7 +273,19 @@ async function open(io, values) {
|
|
|
167
273
|
?.timeZone
|
|
168
274
|
: undefined);
|
|
169
275
|
const client = clientOf(io, url, token);
|
|
170
|
-
const
|
|
276
|
+
const projectNamed = () => {
|
|
277
|
+
const flagged = text(values, "project");
|
|
278
|
+
if (flagged !== undefined) {
|
|
279
|
+
return { key: flagged, source: { kind: "flag" } };
|
|
280
|
+
}
|
|
281
|
+
if (io.env.CONSOLE_PROJECT !== undefined) {
|
|
282
|
+
return { key: io.env.CONSOLE_PROJECT, source: { kind: "environment" } };
|
|
283
|
+
}
|
|
284
|
+
return directory === undefined
|
|
285
|
+
? undefined
|
|
286
|
+
: { key: directory.project, source: { kind: "directory", directory: directory.directory } };
|
|
287
|
+
};
|
|
288
|
+
const projectKey = async () => projectNamed()?.key;
|
|
171
289
|
return {
|
|
172
290
|
client,
|
|
173
291
|
url,
|
|
@@ -177,12 +295,17 @@ async function open(io, values) {
|
|
|
177
295
|
credentials,
|
|
178
296
|
json: on(values, "json"),
|
|
179
297
|
projectKey,
|
|
298
|
+
projectNamed,
|
|
180
299
|
async project() {
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
300
|
+
const named = projectNamed();
|
|
301
|
+
if (named === undefined) {
|
|
183
302
|
throw failed(NO_PROJECT);
|
|
184
303
|
}
|
|
185
|
-
|
|
304
|
+
// A key typed on the command is in front of whoever typed it; one the directory or the
|
|
305
|
+
// environment named is not, and is said with the refusal.
|
|
306
|
+
return named.source.kind === "flag"
|
|
307
|
+
? client.project(named.key)
|
|
308
|
+
: namingUnseen(client.project(named.key), () => unseenProjectWords(url, named, resolved.account));
|
|
186
309
|
},
|
|
187
310
|
};
|
|
188
311
|
}
|
|
@@ -191,21 +314,57 @@ function answer(io, session, value, words) {
|
|
|
191
314
|
io.stdout(session.json ? `${JSON.stringify(value, null, 2)}\n` : `${words()}\n`);
|
|
192
315
|
}
|
|
193
316
|
/** The run a command on a run means: the one named, else the one open run of this token in the project. */
|
|
194
|
-
async function currentRun(project, values) {
|
|
317
|
+
async function currentRun(session, project, values) {
|
|
195
318
|
const given = text(values, "run");
|
|
196
319
|
if (given !== undefined) {
|
|
197
320
|
return given;
|
|
198
321
|
}
|
|
199
|
-
|
|
322
|
+
// The brief form: a command on a run asks which run is open every time, and needs no report
|
|
323
|
+
// of it, where a long run has many.
|
|
324
|
+
const { items } = await project.runBriefs({ open: true, mine: true });
|
|
200
325
|
const [only] = items;
|
|
201
326
|
if (only !== undefined && items.length === 1) {
|
|
202
327
|
return only.id;
|
|
203
328
|
}
|
|
204
329
|
if (items.length === 0) {
|
|
330
|
+
// A run is its person's, and `mine` is this token's: a run begun through another of the
|
|
331
|
+
// person's agents, or before the command was signed in again, is open all the same, and
|
|
332
|
+
// goes on by its id. It is named before any word of taking, since taking its task again
|
|
333
|
+
// would end it, a run that waits for a decision included.
|
|
334
|
+
const theirs = await openRunsOfThePerson(session, project);
|
|
335
|
+
if (theirs.length > 0) {
|
|
336
|
+
const one = theirs.length === 1;
|
|
337
|
+
throw failed([
|
|
338
|
+
`run.none: no run begun through this agent is open in this project; ${theirs.length} of yours begun through another agent, or before a new sign-in, ${one ? "is" : "are"} open:`,
|
|
339
|
+
...theirs.map((run) => ` ${formatRunLine(run)}`),
|
|
340
|
+
`Go on with ${one ? "it" : "one of them"}: add --run <id> to the command. A run is its person's, whichever of their agents began it; taking its task again would end it and begin another.`,
|
|
341
|
+
].join("\n"));
|
|
342
|
+
}
|
|
205
343
|
throw failed("run.none: no run of yours is open in this project. Take a task first: console take <number>; or name a run: --run <id>");
|
|
206
344
|
}
|
|
207
345
|
throw failed(`run.ambiguous: several runs of yours are open in this project; say which with --run <id>:\n${items.map((run) => ` ${formatRunLine(run)}`).join("\n")}`);
|
|
208
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* The open runs of the project that are for the person the command acts as, whichever of their
|
|
349
|
+
* agents began them: what a command on a run looks through when none was begun with its own
|
|
350
|
+
* token. A courtesy before a refusal: where the console does not answer it, there are none.
|
|
351
|
+
*/
|
|
352
|
+
async function openRunsOfThePerson(session, project) {
|
|
353
|
+
try {
|
|
354
|
+
const [me, open] = await Promise.all([
|
|
355
|
+
session.client.me(),
|
|
356
|
+
project.runBriefs({ open: true, limit: LIST_LIMIT }),
|
|
357
|
+
]);
|
|
358
|
+
const person = me.person;
|
|
359
|
+
return person === null ? [] : open.items.filter((run) => run.person.id === person.id);
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (error instanceof ApiError) {
|
|
363
|
+
return [];
|
|
364
|
+
}
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
209
368
|
/** A Markdown body: from `--file`, from standard input for `-`, or as given. */
|
|
210
369
|
async function bodyOf(io, values, given) {
|
|
211
370
|
const file = text(values, "file");
|
|
@@ -400,7 +559,9 @@ const stillWaiting = (id) => `Decision ${id} still waits for a person; the run w
|
|
|
400
559
|
* Waits for the answer and says what it is, or that it is still to come. On `--json`, a decision
|
|
401
560
|
* printed already as it was raised (`shown`) is printed again only with its answer.
|
|
402
561
|
*/
|
|
403
|
-
async function settle(io, session, project, decision, seconds, shown = false
|
|
562
|
+
async function settle(io, session, project, decision, seconds, shown = false,
|
|
563
|
+
/** What is said where the decision still waits, in place of how an attended agent waits on. */
|
|
564
|
+
waiting) {
|
|
404
565
|
const outcome = decision.answer === null && seconds > 0
|
|
405
566
|
? await waitForAnswer(io, project, decision, seconds)
|
|
406
567
|
: decision;
|
|
@@ -410,42 +571,102 @@ async function settle(io, session, project, decision, seconds, shown = false) {
|
|
|
410
571
|
}
|
|
411
572
|
}
|
|
412
573
|
else {
|
|
413
|
-
io.stdout(`${outcome.answer === null ? stillWaiting(outcome.id) : formatAnswer(outcome)}\n`);
|
|
574
|
+
io.stdout(`${outcome.answer === null ? (waiting ?? stillWaiting(outcome.id)) : formatAnswer(outcome)}\n`);
|
|
414
575
|
}
|
|
415
576
|
return outcome.answer === null ? EXIT.waiting : EXIT.ok;
|
|
416
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Whether the command is signed in as the account itself (ADR-0084), which is how an agent
|
|
580
|
+
* account's own command is: what the login kept says, and nothing the environment's pair does.
|
|
581
|
+
*/
|
|
582
|
+
function signedInAsItself(session) {
|
|
583
|
+
return (session.via === "login" &&
|
|
584
|
+
session.credentials?.logins.find((kept) => kept.url === session.url && kept.account === session.account)?.self === true);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* The address of a task's page at the console the command talks to: the console's origin and
|
|
588
|
+
* the path the pages route a task by (ADR-0010), made here and asked of no console. An agent
|
|
589
|
+
* that tells a person of a task links this, and not the console's front page; nothing where
|
|
590
|
+
* the command works in no project.
|
|
591
|
+
*/
|
|
592
|
+
async function taskPage(session, number) {
|
|
593
|
+
const key = await session.projectKey();
|
|
594
|
+
return key === undefined ? undefined : `${session.url}${taskHref(key, number)}`;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* The address of a decision's page: in the project the command reached it in, else the
|
|
598
|
+
* decision's own (ADR-0068), which whoever it reaches may open, in that project or not.
|
|
599
|
+
*/
|
|
600
|
+
async function decisionPage(session, id, atItsAddress = false) {
|
|
601
|
+
const key = atItsAddress ? undefined : await session.projectKey();
|
|
602
|
+
return `${session.url}${key === undefined ? myDecisionHref(id) : decisionHref(key, id)}`;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Who the command is, in a few words: the login and the role, and an agent account by its
|
|
606
|
+
* handle first, which is what it is called by everywhere and what its setup's guide says the
|
|
607
|
+
* command names.
|
|
608
|
+
*/
|
|
609
|
+
function whoOf(person) {
|
|
610
|
+
return person.kind === "agent" && typeof person.handle === "string" && person.handle.length > 0
|
|
611
|
+
? `@${person.handle} (${person.login}, ${person.role})`
|
|
612
|
+
: `${person.login} (${person.role})`;
|
|
613
|
+
}
|
|
417
614
|
/**
|
|
418
615
|
* Checks a token against the console, keeps it as the login at that console for that account,
|
|
419
616
|
* and says who it is. A token the login replaces is given up at the console on the way.
|
|
420
617
|
*/
|
|
421
|
-
async function keep(io, url, token, agent, asDefault
|
|
618
|
+
async function keep(io, url, token, agent, asDefault,
|
|
619
|
+
/** Whether what is kept is the command's own session, signed in as the account itself (ADR-0084). */
|
|
620
|
+
self = false,
|
|
621
|
+
/** Where the words go: nowhere, for a command that says its own. */
|
|
622
|
+
say = io.stdout) {
|
|
422
623
|
const me = await clientOf(io, url, token).me();
|
|
423
624
|
const person = me.person;
|
|
424
625
|
if (person === null) {
|
|
425
626
|
throw failed("The console does not know this token. Make one on your Agents page and try again.");
|
|
426
627
|
}
|
|
427
628
|
const credentials = (await loadCredentials(io)) ?? EMPTY_CREDENTIALS;
|
|
428
|
-
const replaced = loginsAt(credentials, url).find((login) => login.account === person.login);
|
|
429
|
-
if (replaced !== undefined && replaced.token !== token) {
|
|
430
|
-
await clientOf(io, url, replaced.token)
|
|
431
|
-
.giveUpToken()
|
|
432
|
-
.catch(() => undefined);
|
|
433
|
-
}
|
|
434
629
|
const next = withLogin(credentials, {
|
|
435
630
|
url,
|
|
436
631
|
account: person.login,
|
|
437
632
|
token,
|
|
438
633
|
agent,
|
|
439
634
|
since: new Date(io.now()).toISOString(),
|
|
635
|
+
...(self ? { self: true } : {}),
|
|
440
636
|
timeZone: me.workspace.timeZone ?? undefined,
|
|
441
|
-
}, { default: asDefault });
|
|
442
|
-
|
|
637
|
+
}, io.now(), { default: asDefault });
|
|
638
|
+
// A login kept at a console ends the connection that waited there (ADR-0129): its secret
|
|
639
|
+
// is spent, and is kept no longer. Asked whether it can be kept before the token it replaces
|
|
640
|
+
// is given up, so that none is given up for one that never was.
|
|
641
|
+
const keeping = fitting(withoutPending(next, url, io.now()), url);
|
|
642
|
+
const replaced = loginsAt(credentials, url).find((login) => login.account === person.login);
|
|
643
|
+
if (replaced !== undefined && replaced.token !== token) {
|
|
644
|
+
await clientOf(io, url, replaced.token)
|
|
645
|
+
.giveUpToken()
|
|
646
|
+
.catch(() => undefined);
|
|
647
|
+
}
|
|
648
|
+
const kept = await io.store.save(keeping);
|
|
443
649
|
const standing = next.default === url ? ", the default console here" : "";
|
|
444
|
-
|
|
650
|
+
// Last, what holds where, never a next step: the line once said to bind this directory
|
|
651
|
+
// next, and a folder that is no checkout of a project's repository, a desk or a home
|
|
652
|
+
// directory, was bound to a project because it said so.
|
|
653
|
+
const binding = "Only a project's checkout is bound to it: console use <key> (console projects lists them).";
|
|
654
|
+
// Where it is kept: the file, for a person at a terminal. Where no terminal shows the words,
|
|
655
|
+
// an agent reads them, and the path of the one file it must never open is not handed to it.
|
|
656
|
+
const where = io.terminal === false ? "on this machine by the command, and never shown" : `in ${kept}`;
|
|
657
|
+
say(self
|
|
658
|
+
? `Signed in to ${me.workspace.name} at ${url} as ${whoOf(person)}, the account itself${standing}: what this command does, ${person.login} does, and no agent is named beside it. The session is kept while it is used; its secret is kept ${where}.\n${binding}\n`
|
|
659
|
+
: `${agent === undefined ? "Signed in" : `Connected as "${agent}"`} to ${me.workspace.name} at ${url} as ${whoOf(person)}${standing}. The token is kept ${where}.\n${binding}\n`);
|
|
445
660
|
return EXIT.ok;
|
|
446
661
|
}
|
|
447
662
|
const login = async (args, io) => {
|
|
448
|
-
const { values } = parse(args, {
|
|
663
|
+
const { values } = parse(args, {
|
|
664
|
+
"token-stdin": { type: "boolean" },
|
|
665
|
+
agent: { type: "string" },
|
|
666
|
+
self: { type: "boolean" },
|
|
667
|
+
default: { type: "boolean" },
|
|
668
|
+
wait: { type: "string" },
|
|
669
|
+
}, false);
|
|
449
670
|
const credentials = await loadCredentials(io);
|
|
450
671
|
const wanted = text(values, "url") ?? io.env.CONSOLE_URL ?? credentials?.default;
|
|
451
672
|
if (wanted === undefined) {
|
|
@@ -463,27 +684,150 @@ const login = async (args, io) => {
|
|
|
463
684
|
// A connection (ADR-0011): a code a person approves on the console's own pages, and the token
|
|
464
685
|
// handed over here once, never shown.
|
|
465
686
|
const client = clientOf(io, url);
|
|
466
|
-
//
|
|
467
|
-
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
687
|
+
// With --self the command asks to be the account itself (ADR-0084): whoever approves says
|
|
688
|
+
// "this is me", and what is handed over is a session of the command's, in place of a token.
|
|
689
|
+
const self = on(values, "self");
|
|
690
|
+
// Where no terminal shows the command's words as they are printed, whoever runs it sees them
|
|
691
|
+
// when it ends: an agent's host held the address and the code back until its own limit, two
|
|
692
|
+
// minutes on, while a person waited for them. There the call that begins a connection says
|
|
693
|
+
// them and ends, and the next call waits for the approval (ADR-0129).
|
|
694
|
+
const attended = io.terminal !== false;
|
|
695
|
+
const wait = text(values, "wait");
|
|
696
|
+
const waitGiven = wait === undefined ? undefined : secondsOf(wait, 0);
|
|
697
|
+
// The end of the wait is a moment as any other the command prints (ADR-0035): in the
|
|
698
|
+
// workspace's time zone where a login at this console kept it, which is one zone whoever
|
|
699
|
+
// signed in; on a first sign-in, when none is known yet, in the machine's own, since an agent
|
|
700
|
+
// relays the moment to a person; as the API gave it where the machine says none.
|
|
701
|
+
setMomentZone(credentials?.logins.find((login) => login.url === url)?.timeZone ?? io.timeZone);
|
|
702
|
+
const again = `console login --url ${url}${self ? " --self" : ""}`;
|
|
703
|
+
/** Whom the code is shown to, and what they do with it. */
|
|
704
|
+
const asked = (page, code) => self
|
|
705
|
+
? `To sign this command in as an account itself, open ${page} signed in as that account, check that the page shows the code ${code}, and say that it is you.`
|
|
706
|
+
: `To connect this agent, a person opens ${page} signed in, checks that the page shows the code ${code}, names the agent and approves.`;
|
|
707
|
+
/** Forgets the connection kept for this console, and any whose code ran out; writes nothing where none was kept. */
|
|
708
|
+
const forget = async () => {
|
|
709
|
+
const kept = await loadCredentials(io);
|
|
710
|
+
if (kept === undefined || (kept.pending ?? []).length === 0) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const next = withoutPending(kept, url, io.now());
|
|
714
|
+
if (keepsNothing(next)) {
|
|
715
|
+
await io.store.clear();
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
await io.store.save(next);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
// A connection a call before this one began at this console, of the kind this call asks for:
|
|
722
|
+
// it is gone on with, and no new code is made while its code lasts.
|
|
723
|
+
let waiting = pendingAt(credentials, url);
|
|
724
|
+
if (waiting !== undefined && ((waiting.self === true) !== self || !lasts(waiting, io.now()))) {
|
|
725
|
+
const ranOut = !lasts(waiting, io.now());
|
|
726
|
+
await forget();
|
|
727
|
+
if (ranOut) {
|
|
728
|
+
io.stdout(`The code ${waiting.code} ran out before a person approved it. A new one:\n`);
|
|
729
|
+
}
|
|
730
|
+
waiting = undefined;
|
|
731
|
+
}
|
|
472
732
|
for (;;) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
733
|
+
const resumed = waiting !== undefined;
|
|
734
|
+
if (waiting === undefined) {
|
|
735
|
+
// "<agent> on <machine>": the pages say the agent and keep the machine for a hover.
|
|
736
|
+
const agent = text(values, "agent") ?? agentOf(io.env) ?? "An agent";
|
|
737
|
+
const begun = await client.connect({
|
|
738
|
+
agent: io.hostname === undefined ? agent : `${agent} on ${io.hostname}`,
|
|
739
|
+
...(self ? { as: "self" } : {}),
|
|
740
|
+
});
|
|
741
|
+
waiting = {
|
|
742
|
+
url,
|
|
743
|
+
secret: begun.secret,
|
|
744
|
+
code: begun.code,
|
|
745
|
+
page: begun.url,
|
|
746
|
+
expiresAt: begun.expiresAt,
|
|
747
|
+
interval: begun.interval,
|
|
748
|
+
...(self ? { self: true } : {}),
|
|
749
|
+
...(asDefault ? { default: true } : {}),
|
|
750
|
+
};
|
|
751
|
+
// Kept only where this call may end before the approval: at a terminal, with no wait
|
|
752
|
+
// said, the secret stays in the process as it always did.
|
|
753
|
+
if (!attended || waitGiven !== undefined) {
|
|
754
|
+
await io.store.save(fitting(withPending((await loadCredentials(io)) ?? EMPTY_CREDENTIALS, waiting, io.now()), url));
|
|
755
|
+
}
|
|
477
756
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
757
|
+
const pending = waiting;
|
|
758
|
+
const until = moment(pending.expiresAt);
|
|
759
|
+
const end = Date.parse(pending.expiresAt);
|
|
760
|
+
const seconds = waitGiven ?? (attended ? MAX_WAIT_SECONDS : resumed ? DEFAULT_LOGIN_WAIT_SECONDS : 0);
|
|
761
|
+
// A call that begins a connection and waits for nothing says what a person does and ends:
|
|
762
|
+
// the words reach whoever ran it now, and the next call waits. A call that goes on with a
|
|
763
|
+
// connection says nothing before its wait where no terminal would show it.
|
|
764
|
+
const told = !resumed && seconds === 0;
|
|
765
|
+
if (!resumed || attended) {
|
|
766
|
+
// The telling is a sentence of its own, before the one that names the command: read in
|
|
767
|
+
// one sentence, an agent ran the command first and told its person after. And the wait
|
|
768
|
+
// of the next call is said apart from the code's end, which an agent took for how long
|
|
769
|
+
// that call waits, and gave it half an hour. At a terminal, told not to wait, the next
|
|
770
|
+
// call there waits while the code lasts, and says so.
|
|
771
|
+
const next = attended
|
|
772
|
+
? `it waits for the approval while the code lasts, until ${until}`
|
|
773
|
+
: `it waits for the approval up to ${DEFAULT_LOGIN_WAIT_SECONDS} seconds a call, and the code lasts until ${until}`;
|
|
774
|
+
io.stdout(told
|
|
775
|
+
? `${asked(pending.page, pending.code)}\n${self ? "Have that done now" : "Tell the person that address and that code now, in a message of its own"}, before you run the command again.\nThen run ${again} again: ${next}.\n`
|
|
776
|
+
: `${asked(pending.page, pending.code)}\nWaiting for that, until ${until}.\n`);
|
|
777
|
+
}
|
|
778
|
+
if (told) {
|
|
779
|
+
return EXIT.ok;
|
|
780
|
+
}
|
|
781
|
+
// Where the call may end before the approval, it waits no longer than it was given, and no
|
|
782
|
+
// longer than the code lasts; at a terminal with no wait said, until the console says how
|
|
783
|
+
// the connection ended, as before.
|
|
784
|
+
const bounded = waitGiven !== undefined || !attended;
|
|
785
|
+
const deadline = Math.min(io.now() + seconds * 1000, Number.isFinite(end) ? end : Number.POSITIVE_INFINITY);
|
|
786
|
+
// A connection gone on with is claimed at once, since its person may have approved between
|
|
787
|
+
// the two calls; one begun now, after the breath the console asked for, as before.
|
|
788
|
+
let first = resumed;
|
|
789
|
+
let gone = false;
|
|
790
|
+
for (;;) {
|
|
791
|
+
if (!first) {
|
|
792
|
+
if (bounded && io.now() + pending.interval * 1000 > deadline) {
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
await io.sleep(pending.interval * 1000);
|
|
796
|
+
}
|
|
797
|
+
first = false;
|
|
798
|
+
let claim;
|
|
799
|
+
try {
|
|
800
|
+
claim = await client.claimConnection(pending.secret);
|
|
801
|
+
}
|
|
802
|
+
catch (error) {
|
|
803
|
+
if (error instanceof ApiError && error.code === "connect.not_found") {
|
|
804
|
+
gone = true;
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
throw error;
|
|
808
|
+
}
|
|
809
|
+
if (claim.status === "connected") {
|
|
810
|
+
return keep(io, url, claim.secret, claim.token.name, asDefault || pending.default === true);
|
|
811
|
+
}
|
|
812
|
+
if (claim.status === "signed_in") {
|
|
813
|
+
return keep(io, url, claim.secret, undefined, asDefault || pending.default === true, true);
|
|
481
814
|
}
|
|
482
|
-
throw error;
|
|
483
815
|
}
|
|
484
|
-
if (
|
|
485
|
-
|
|
816
|
+
if (gone) {
|
|
817
|
+
await forget();
|
|
818
|
+
if (!resumed) {
|
|
819
|
+
throw failed("The connection was not approved in time, or the person said it was not theirs. Run console login again for a new code.");
|
|
820
|
+
}
|
|
821
|
+
// A connection kept from a call before, which the console no longer knows: its code ran
|
|
822
|
+
// out there, or a person said it was not theirs. It is forgotten, and a new one begun.
|
|
823
|
+
io.stdout(`The code ${pending.code} is good no longer: it ran out, or a person said the connection was not theirs. A new one:\n`);
|
|
824
|
+
waiting = undefined;
|
|
825
|
+
continue;
|
|
486
826
|
}
|
|
827
|
+
// The wait this call was given is over and the code still lasts: the connection stays kept,
|
|
828
|
+
// and the same command goes on waiting for it.
|
|
829
|
+
io.stdout(`${self ? "Not signed in yet" : "Not approved yet"}. ${asked(pending.page, pending.code)}\nKeep waiting with: ${again}, as often as needed until ${until}.\n`);
|
|
830
|
+
return EXIT.waiting;
|
|
487
831
|
}
|
|
488
832
|
};
|
|
489
833
|
const logout = async (args, io) => {
|
|
@@ -496,7 +840,15 @@ const logout = async (args, io) => {
|
|
|
496
840
|
}
|
|
497
841
|
};
|
|
498
842
|
if (credentials === undefined || credentials.logins.length === 0) {
|
|
499
|
-
|
|
843
|
+
// Nobody is signed in; a connection that waited for a person is forgotten all the same
|
|
844
|
+
// (ADR-0129), with its secret.
|
|
845
|
+
if (credentials !== undefined && (credentials.pending ?? []).length > 0) {
|
|
846
|
+
await io.store.clear();
|
|
847
|
+
io.stdout("Not signed in here; the connection that waited for a person is forgotten.\n");
|
|
848
|
+
}
|
|
849
|
+
else {
|
|
850
|
+
io.stdout("Not signed in here: nothing to forget.\n");
|
|
851
|
+
}
|
|
500
852
|
envNote();
|
|
501
853
|
return EXIT.ok;
|
|
502
854
|
}
|
|
@@ -517,7 +869,16 @@ const logout = async (args, io) => {
|
|
|
517
869
|
const chosen = account === undefined ? at : at.filter((login) => login.account === account);
|
|
518
870
|
const [login] = chosen;
|
|
519
871
|
if (login === undefined) {
|
|
520
|
-
|
|
872
|
+
const whom = account === undefined ? "" : ` as ${account}`;
|
|
873
|
+
// Nobody to sign out there; a connection that waits for a person at that console is
|
|
874
|
+
// forgotten all the same (ADR-0129): signing out of a console leaves no secret of it here.
|
|
875
|
+
if (pendingAt(credentials, url) !== undefined) {
|
|
876
|
+
await io.store.save(withoutPending(credentials, url, io.now()));
|
|
877
|
+
io.stdout(`Nobody is signed in here at ${url}${whom}; the connection that waited for a person there is forgotten.\n`);
|
|
878
|
+
envNote();
|
|
879
|
+
return EXIT.ok;
|
|
880
|
+
}
|
|
881
|
+
throw failed(`Nobody is signed in here at ${url}${whom}: nothing to forget. console logins lists the consoles signed in.`);
|
|
521
882
|
}
|
|
522
883
|
if (chosen.length > 1) {
|
|
523
884
|
throw failed(`Several accounts are signed in at ${url} (${chosen.map((kept) => kept.account ?? "?").join(", ")}); say which: console logout --url ${url} --account <login>`);
|
|
@@ -539,8 +900,10 @@ const logout = async (args, io) => {
|
|
|
539
900
|
outcome = "left";
|
|
540
901
|
}
|
|
541
902
|
}
|
|
542
|
-
|
|
543
|
-
|
|
903
|
+
// A connection that waited at this console goes with its login (ADR-0129), as does any
|
|
904
|
+
// whose code ran out: signing out leaves no secret of the console here.
|
|
905
|
+
const next = withoutPending(withoutLogin(credentials, url, io.now(), login.account), url, io.now());
|
|
906
|
+
if (keepsNothing(next)) {
|
|
544
907
|
await io.store.clear();
|
|
545
908
|
}
|
|
546
909
|
else {
|
|
@@ -563,20 +926,41 @@ const logins = async (args, io) => {
|
|
|
563
926
|
url: login.url,
|
|
564
927
|
account: login.account ?? null,
|
|
565
928
|
agent: login.agent ?? null,
|
|
929
|
+
// The command's own session, signed in as the account itself (ADR-0084), where so.
|
|
930
|
+
self: login.self === true,
|
|
566
931
|
since: login.since ?? null,
|
|
567
932
|
default: credentials?.default === login.url,
|
|
568
933
|
}));
|
|
934
|
+
// The connections that wait for a person while their codes last (ADR-0129): the console, the
|
|
935
|
+
// code and its end, never the secret; one whose code ran out is not shown.
|
|
936
|
+
const waiting = (credentials?.pending ?? [])
|
|
937
|
+
.filter((pending) => lasts(pending, io.now()))
|
|
938
|
+
.map((pending) => ({
|
|
939
|
+
url: pending.url,
|
|
940
|
+
code: pending.code,
|
|
941
|
+
expiresAt: pending.expiresAt,
|
|
942
|
+
self: pending.self === true,
|
|
943
|
+
}));
|
|
569
944
|
if (on(values, "json")) {
|
|
570
|
-
io.stdout(`${JSON.stringify({
|
|
945
|
+
io.stdout(`${JSON.stringify({
|
|
946
|
+
default: credentials?.default ?? null,
|
|
947
|
+
logins: kept,
|
|
948
|
+
...(waiting.length === 0 ? {} : { waiting }),
|
|
949
|
+
}, null, 2)}\n`);
|
|
571
950
|
return EXIT.ok;
|
|
572
951
|
}
|
|
952
|
+
const lines = [
|
|
953
|
+
...kept.map((login) => `${login.url} ${login.account ?? "(account unknown)"}${login.agent === null ? "" : ` ${login.agent}`}${login.self ? " as the account itself" : ""}${login.since === null ? "" : ` since ${login.since.slice(0, 10)}`}${login.default ? " (default)" : ""}`),
|
|
954
|
+
];
|
|
955
|
+
for (const pending of waiting) {
|
|
956
|
+
// The code's end as login printed it: in the zone a login at that console kept, else the machine's.
|
|
957
|
+
setMomentZone(credentials?.logins.find((login) => login.url === pending.url)?.timeZone ?? io.timeZone);
|
|
958
|
+
lines.push(`${pending.url} waits for a person to approve the code ${pending.code}, until ${moment(pending.expiresAt)}: console login --url ${pending.url}${pending.self ? " --self" : ""}`);
|
|
959
|
+
}
|
|
573
960
|
if (kept.length === 0) {
|
|
574
|
-
|
|
575
|
-
return EXIT.ok;
|
|
961
|
+
lines.unshift("Not signed in anywhere here: console login --url <the console's origin>");
|
|
576
962
|
}
|
|
577
|
-
io.stdout(`${
|
|
578
|
-
.map((login) => `${login.url} ${login.account ?? "(account unknown)"}${login.agent === null ? "" : ` ${login.agent}`}${login.since === null ? "" : ` since ${login.since.slice(0, 10)}`}${login.default ? " (default)" : ""}`)
|
|
579
|
-
.join("\n")}\n`);
|
|
963
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
580
964
|
return EXIT.ok;
|
|
581
965
|
};
|
|
582
966
|
/** The agent the command runs under, where its environment says so: what a connection is named by default. */
|
|
@@ -602,7 +986,8 @@ async function rememberZone(io, session, zone) {
|
|
|
602
986
|
if (kept === undefined || kept.timeZone === zone) {
|
|
603
987
|
return;
|
|
604
988
|
}
|
|
605
|
-
|
|
989
|
+
// Kept anew, and so without a connection whose code ran out (ADR-0129).
|
|
990
|
+
await io.store.save(fitting(withLogin(session.credentials, { ...kept, timeZone: zone }, io.now()), session.url));
|
|
606
991
|
}
|
|
607
992
|
const whoami = async (args, io) => {
|
|
608
993
|
const { values } = parse(args, {}, false);
|
|
@@ -613,7 +998,29 @@ const whoami = async (args, io) => {
|
|
|
613
998
|
throw failed("The console does not know this token. Sign in again: console login");
|
|
614
999
|
}
|
|
615
1000
|
await rememberZone(io, session, me.workspace.timeZone ?? undefined);
|
|
616
|
-
|
|
1001
|
+
// The project the directory names is asked of the console (ADR-0112): a key repeated from a
|
|
1002
|
+
// file says nothing of whether this console has the project, or shows it to this member, and
|
|
1003
|
+
// an agreement has its agents check the binding with this command before the first one on
|
|
1004
|
+
// the board. Where the key came from is said either way, since that is where it is mended.
|
|
1005
|
+
const named = session.projectNamed();
|
|
1006
|
+
const key = named?.key;
|
|
1007
|
+
let projectName;
|
|
1008
|
+
if (named !== undefined) {
|
|
1009
|
+
try {
|
|
1010
|
+
projectName = (await session.client.project(named.key).get()).name;
|
|
1011
|
+
}
|
|
1012
|
+
catch (error) {
|
|
1013
|
+
if (!(error instanceof ApiError && error.code === "project.not_found")) {
|
|
1014
|
+
throw error;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const missing = named !== undefined && projectName === undefined;
|
|
1019
|
+
const projectWords = named === undefined
|
|
1020
|
+
? "; no project named here"
|
|
1021
|
+
: projectName === undefined
|
|
1022
|
+
? `; project ${named.key}, named by ${sourceWords(named.source)}, which this console does not have or does not show you`
|
|
1023
|
+
: `; project ${named.key} (${projectName}), named by ${sourceWords(named.source)}`;
|
|
617
1024
|
const command = parseVersion(io.version);
|
|
618
1025
|
const server = parseVersion(me.console?.version);
|
|
619
1026
|
const verdict = command === undefined || server === undefined
|
|
@@ -630,15 +1037,21 @@ const whoami = async (args, io) => {
|
|
|
630
1037
|
...me,
|
|
631
1038
|
console: me.console ?? null,
|
|
632
1039
|
project: key ?? null,
|
|
1040
|
+
projectName: projectName ?? null,
|
|
1041
|
+
projectSource: named?.source ?? null,
|
|
633
1042
|
command: { version: io.version ?? null, install: io.install ?? null },
|
|
634
1043
|
}, () => [
|
|
635
|
-
`${
|
|
636
|
-
// The
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
1044
|
+
`${whoOf(person)} at ${me.workspace.name}, ${session.url}${projectWords}${me.session?.kind === "command" ? "; signed in as the account itself" : ""}`,
|
|
1045
|
+
// The sentence of a checkout's agreement sends an agent here first and says that this
|
|
1046
|
+
// answer says how: so it says what is read before the first task, the rules and the
|
|
1047
|
+
// skill, and that one command's flags are read from that command's help, since an agent
|
|
1048
|
+
// that has the skill was reading the whole help beside it. In a directory that names
|
|
1049
|
+
// no project too: an agent account's desk names none, the command's help sends an
|
|
1050
|
+
// agent here for where the skill is, and the workspace has rules whatever the project.
|
|
1051
|
+
// The skill's path stands last, with nothing after it, to be copied as it is.
|
|
1052
|
+
io.skillsDir === undefined
|
|
1053
|
+
? "Before the first task, read console rules and the skill working-the-board (console skills says where it is); for one command's flags, console help <command>."
|
|
1054
|
+
: `Before the first task, read console rules and the skill working-the-board; for one command's flags, console help <command>. The skill: ${ownSkillPath(io.skillsDir)}`,
|
|
642
1055
|
`This command is ${io.version ?? "of a version it does not know"}${io.install === undefined ? "" : `, ${describeInstall(io.install)}`}; ${consoleWords}.`,
|
|
643
1056
|
...(verdict === "behind"
|
|
644
1057
|
? [`A newer command exists. Update it: ${updateWords(io, me.console?.version)}`]
|
|
@@ -648,6 +1061,11 @@ const whoami = async (args, io) => {
|
|
|
648
1061
|
]
|
|
649
1062
|
: []),
|
|
650
1063
|
].join("\n"));
|
|
1064
|
+
if (missing && named !== undefined) {
|
|
1065
|
+
// Who and where are said above, which is what mends it; the command still ends as refused,
|
|
1066
|
+
// so that a check of the binding never passes on a key alone.
|
|
1067
|
+
throw failed(unseenProjectWords(session.url, named, person.login));
|
|
1068
|
+
}
|
|
651
1069
|
return EXIT.ok;
|
|
652
1070
|
};
|
|
653
1071
|
const projects = async (args, io) => {
|
|
@@ -664,23 +1082,21 @@ const use = async (args, io) => {
|
|
|
664
1082
|
const key = theOne(positionals, "Say which project: console use <key> [--url <origin>] [--account <login>]");
|
|
665
1083
|
const session = await open(io, values);
|
|
666
1084
|
const project = await session.client.project(key).get();
|
|
667
|
-
// The directory names the console
|
|
668
|
-
//
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const pinAccount =
|
|
673
|
-
(
|
|
1085
|
+
// The directory names the console every time (ADR-0112): what is the default login on this
|
|
1086
|
+
// machine is another console's on the next, and a file that said only the project would
|
|
1087
|
+
// follow it there. The account only when asked, or where the directory named it before, so
|
|
1088
|
+
// that a file to be committed never carries somebody's account unasked; never a token.
|
|
1089
|
+
const before = await io.directory.load();
|
|
1090
|
+
const pinAccount = session.account !== undefined &&
|
|
1091
|
+
(text(values, "account") !== undefined || before?.account === session.account);
|
|
674
1092
|
const kept = await io.directory.save({
|
|
675
1093
|
project: project.key,
|
|
676
|
-
|
|
677
|
-
...(pinAccount
|
|
1094
|
+
url: session.url,
|
|
1095
|
+
...(pinAccount ? { account: session.account } : {}),
|
|
678
1096
|
});
|
|
679
|
-
const bound =
|
|
680
|
-
? ` at ${session.url}${pinAccount && session.account !== undefined ? ` as ${session.account}` : ""}`
|
|
681
|
-
: "";
|
|
1097
|
+
const bound = ` at ${session.url}${pinAccount ? ` as ${session.account}` : ""}`;
|
|
682
1098
|
answer(io, session, project, () => [
|
|
683
|
-
`Working in ${project.name} (${project.key})${bound} from this directory on: kept in ${kept}, which is meant to be committed in a private repository and left out of a public one. What its people ask of agents: console rules.`,
|
|
1099
|
+
`Working in ${project.name} (${project.key})${bound} from this directory on: kept in ${kept}, which names the project and the console, never a token, and is meant to be committed in a private repository and left out of a public one. What its people ask of agents: console rules.`,
|
|
684
1100
|
// Nothing sends an agent to the console until the checkout says so; the sentence is the
|
|
685
1101
|
// skill's (references/the-sentence.md), printed here as `skillcdn use` prints its own.
|
|
686
1102
|
"Then put this sentence into the checkout's agreement (AGENTS.md, or CLAUDE.md where that is the file agents read), as it is, so that every agent working here is sent to the console:",
|
|
@@ -740,7 +1156,7 @@ const tasks = async (args, io) => {
|
|
|
740
1156
|
if (search === "") {
|
|
741
1157
|
throw misuse("Say what to search for: console tasks --search <words>");
|
|
742
1158
|
}
|
|
743
|
-
const
|
|
1159
|
+
const filter = {
|
|
744
1160
|
...(state === undefined ? {} : { state }),
|
|
745
1161
|
...(on(values, "open") || due === "overdue" ? { open: true } : {}),
|
|
746
1162
|
...(worker === undefined ? {} : { worker }),
|
|
@@ -751,9 +1167,20 @@ const tasks = async (args, io) => {
|
|
|
751
1167
|
...(search === undefined ? {} : { q: search }),
|
|
752
1168
|
...(on(values, "archived") ? { archived: true } : {}),
|
|
753
1169
|
...page,
|
|
754
|
-
}
|
|
755
|
-
|
|
1170
|
+
};
|
|
1171
|
+
// A line a task and no body: the listing is asked for in the brief form, without the bodies,
|
|
1172
|
+
// which weigh more than the rest of a page together. --json is the console's own answer, whole.
|
|
1173
|
+
const found = session.json ? await project.tasks(filter) : await project.taskBriefs(filter);
|
|
1174
|
+
// A search that finds nothing says how it looked: every word must be in a title, so three
|
|
1175
|
+
// words find nothing where one of them finds the task, and an agent that read "No tasks."
|
|
1176
|
+
// wrote the same work a second time.
|
|
1177
|
+
const none = search === undefined
|
|
756
1178
|
? "No tasks."
|
|
1179
|
+
: /\s/.test(search.trim())
|
|
1180
|
+
? `No tasks: no title holds every word of "${search.trim()}". Fewer words find more: one word of the thing's name, in the language the board is written in.`
|
|
1181
|
+
: `No tasks: no title holds "${search.trim()}".`;
|
|
1182
|
+
answer(io, session, found, () => found.items.length === 0
|
|
1183
|
+
? none
|
|
757
1184
|
: found.items.map(formatTaskLine).join("\n") +
|
|
758
1185
|
formatMore(found.more, page.limit, page.offset));
|
|
759
1186
|
return EXIT.ok;
|
|
@@ -780,199 +1207,378 @@ const categories = async (args, io) => {
|
|
|
780
1207
|
answer(io, session, found, () => found.items.length === 0 ? "No categories." : found.items.map(formatCategoryLine).join("\n"));
|
|
781
1208
|
return EXIT.ok;
|
|
782
1209
|
};
|
|
783
|
-
/** How many pages of a skill, of a file or of a folder the command follows before it stops: far above what one holds. */
|
|
784
|
-
const MAX_SKILL_PAGES = 64;
|
|
785
|
-
/** How many results a search answers at most: what the deployment allows on one page. */
|
|
786
|
-
const MAX_FIND_LIMIT = 25;
|
|
787
|
-
/** The pack of the project as the console lists it, and what its reads are rendered at; none when the pack did not answer. */
|
|
788
|
-
async function packOf(reader) {
|
|
789
|
-
const listing = await reader.skills();
|
|
790
|
-
return { listing, summary: summaryOf(listing) };
|
|
791
|
-
}
|
|
792
1210
|
const SKILLS_OPTIONS = {
|
|
793
1211
|
search: { type: "string" },
|
|
1212
|
+
path: { type: "string" },
|
|
794
1213
|
limit: { type: "string" },
|
|
795
1214
|
cursor: { type: "string" },
|
|
1215
|
+
rows: { type: "boolean" },
|
|
1216
|
+
code: { type: "boolean" },
|
|
1217
|
+
heading: { type: "string" },
|
|
1218
|
+
format: { type: "string" },
|
|
1219
|
+
grep: { type: "string" },
|
|
1220
|
+
out: { type: "string" },
|
|
796
1221
|
};
|
|
1222
|
+
/**
|
|
1223
|
+
* A read the pack refused, as the command ends on it (ADR-0118): the words on standard error
|
|
1224
|
+
* and the exit of a refusal, as the skillcdn command ends one, where the pack's answer was once
|
|
1225
|
+
* printed as if it were the read. `--json` still prints what the console answered, which says
|
|
1226
|
+
* the status. Thrown by the caller, so that nothing follows it.
|
|
1227
|
+
*/
|
|
1228
|
+
function refusedRead(io, session, owner, answered, words) {
|
|
1229
|
+
if (session.json) {
|
|
1230
|
+
io.stdout(`${JSON.stringify(answered, null, 2)}\n`);
|
|
1231
|
+
}
|
|
1232
|
+
return failed(owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words}` : words);
|
|
1233
|
+
}
|
|
1234
|
+
/** A whole number a flag carries, within its bounds; nothing when it is not given. */
|
|
1235
|
+
function countOf(given, name, bounds) {
|
|
1236
|
+
if (given === undefined) {
|
|
1237
|
+
return undefined;
|
|
1238
|
+
}
|
|
1239
|
+
const count = /^\d{1,9}$/.test(given) ? Number(given) : Number.NaN;
|
|
1240
|
+
if (Number.isNaN(count) ||
|
|
1241
|
+
count < bounds.least ||
|
|
1242
|
+
(bounds.most !== undefined && count > bounds.most)) {
|
|
1243
|
+
throw misuse(`--${name} takes an integer ${bounds.most === undefined ? `from ${bounds.least}` : `between ${bounds.least} and ${bounds.most}`}: ${given}`);
|
|
1244
|
+
}
|
|
1245
|
+
return count;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* A number a read of a pack takes, checked as the skillcdn command checks it and said in its
|
|
1249
|
+
* words, before anything is asked of the console.
|
|
1250
|
+
*/
|
|
1251
|
+
function checkedNumber(given, name, most) {
|
|
1252
|
+
try {
|
|
1253
|
+
readNumber(given, name, most);
|
|
1254
|
+
}
|
|
1255
|
+
catch (error) {
|
|
1256
|
+
throw error instanceof ReadMisuse ? misuse(error.message) : error;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* The flags that say where a pack is read, as they were given, for the command that reads the
|
|
1261
|
+
* next part of a skill (ADR-0124): it is asked as this part was.
|
|
1262
|
+
*/
|
|
1263
|
+
function whereGiven(values) {
|
|
1264
|
+
return ["project", "url", "account"].flatMap((name) => {
|
|
1265
|
+
const value = values[name];
|
|
1266
|
+
return typeof value === "string" ? [`--${name}`, value] : [];
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* One read of a pack as the skillcdn command makes it (ADR-0124): `readPack` of @skillcdn/cli
|
|
1271
|
+
* over the pack made of the console's answers, in the words of the command the pack is read
|
|
1272
|
+
* with. What the pack refused ends the command as refused (ADR-0118): of one read, in the
|
|
1273
|
+
* pack's own code and words, as that command prints them; of the pack as a whole, in the
|
|
1274
|
+
* console's. A read not asked right is a command not understood. With `data`, nothing is
|
|
1275
|
+
* printed for a refusal even with `--json`: what a program takes is never one.
|
|
1276
|
+
*/
|
|
1277
|
+
async function readThrough(io, session, owner, pack, read, options) {
|
|
1278
|
+
try {
|
|
1279
|
+
return await readPack(pack, read, {
|
|
1280
|
+
words: options.words,
|
|
1281
|
+
json: session.json,
|
|
1282
|
+
nextPart: options.nextPart,
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
catch (error) {
|
|
1286
|
+
if (error instanceof ReadMisuse) {
|
|
1287
|
+
throw misuse(error.message);
|
|
1288
|
+
}
|
|
1289
|
+
const refusal = error instanceof PackRefusal
|
|
1290
|
+
? { answer: error.answer, words: refusalWords(error.what, error.answer, owner) }
|
|
1291
|
+
: error instanceof PackError
|
|
1292
|
+
? { answer: pack.answered(), words: `${error.code}: ${error.message}` }
|
|
1293
|
+
: undefined;
|
|
1294
|
+
if (refusal === undefined) {
|
|
1295
|
+
throw error;
|
|
1296
|
+
}
|
|
1297
|
+
throw options.data === true || refusal.answer === undefined
|
|
1298
|
+
? failed(refusal.words)
|
|
1299
|
+
: refusedRead(io, session, owner, refusal.answer, refusal.words);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* What `--json` prints for a read: the console's answer, with the pack's own in it as the
|
|
1304
|
+
* skillcdn command's `--json` prints it, the pages of a skill or of a read of data joined.
|
|
1305
|
+
*/
|
|
1306
|
+
function jsonOfRead(session, pack, output) {
|
|
1307
|
+
return session.json ? { ...pack.answered(), read: JSON.parse(output.text) } : undefined;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* The tables, or the code blocks, of a document or of every document under a folder, as data
|
|
1311
|
+
* (ADR-0100): read and printed as the skillcdn command prints them, one CSV or an array of rows,
|
|
1312
|
+
* the blocks as written, or written to a file with `--out`. What a program takes is never a
|
|
1313
|
+
* refusal: a read the pack refused fails with why.
|
|
1314
|
+
*/
|
|
1315
|
+
async function readData(io, session, pack, asked) {
|
|
1316
|
+
const { read } = asked;
|
|
1317
|
+
const output = await readThrough(io, session, asked.owner, pack, read, {
|
|
1318
|
+
words: asked.words,
|
|
1319
|
+
data: true,
|
|
1320
|
+
});
|
|
1321
|
+
// Nothing is printed for nothing, which a program takes as it is; a line beside it says so.
|
|
1322
|
+
if (holdsNothing(output.holds) && asked.out === undefined && !session.json) {
|
|
1323
|
+
io.stderr(`No ${read.read === "rows" ? "tables" : "code blocks"} in ${read.path ?? "the pack"}${read.heading === undefined ? "" : " under that heading"}.\n`);
|
|
1324
|
+
}
|
|
1325
|
+
const made = session.json
|
|
1326
|
+
? JSON.stringify(jsonOfRead(session, pack, output), null, 2)
|
|
1327
|
+
: output.text;
|
|
1328
|
+
const whole = made.endsWith("\n") || made.length === 0 ? made : `${made}\n`;
|
|
1329
|
+
if (asked.out === undefined) {
|
|
1330
|
+
io.stdout(whole);
|
|
1331
|
+
return EXIT.ok;
|
|
1332
|
+
}
|
|
1333
|
+
const name = read.read === "code" ? "code.txt" : read.format === "json" ? "rows.json" : "rows.csv";
|
|
1334
|
+
let saved;
|
|
1335
|
+
try {
|
|
1336
|
+
saved = await io.writeBytes(asked.out, new TextEncoder().encode(whole), name);
|
|
1337
|
+
}
|
|
1338
|
+
catch {
|
|
1339
|
+
throw failed(`The file could not be written at ${asked.out}.`);
|
|
1340
|
+
}
|
|
1341
|
+
io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
|
|
1342
|
+
return EXIT.ok;
|
|
1343
|
+
}
|
|
797
1344
|
const SKILL_OPTIONS = {
|
|
798
1345
|
file: { type: "string" },
|
|
799
1346
|
offset: { type: "string" },
|
|
800
1347
|
limit: { type: "string" },
|
|
1348
|
+
cursor: { type: "string" },
|
|
801
1349
|
};
|
|
802
1350
|
/** The line `console skills` ends with: where the plugins' own skills are. */
|
|
803
1351
|
const PLUGIN_SKILLS_LINE = "The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
|
|
804
1352
|
/**
|
|
805
|
-
* The pack as the words say: whole, a folder of
|
|
806
|
-
* the project's pack as `console skills`, and for a plugin's as
|
|
1353
|
+
* The pack as the words say: whole, a page of a folder or of a file's outline, or what words
|
|
1354
|
+
* find; for the project's pack as `console skills`, and for a plugin's as
|
|
1355
|
+
* `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
|
|
1356
|
+
* (ADR-0124).
|
|
807
1357
|
*/
|
|
808
1358
|
async function readSkills(io, session, reader, values, positionals, extras) {
|
|
1359
|
+
const owner = extras.owner ?? "project";
|
|
1360
|
+
const say = (value, words) => answerPack(io, session, owner, value, words);
|
|
1361
|
+
// The reads by the names of this pack's own commands: a plugin's are not the project's.
|
|
1362
|
+
const skillCommand = extras.command.replace(/skills$/, "skill");
|
|
1363
|
+
const toolWords = packWords(extras.command, skillCommand);
|
|
1364
|
+
// How a skill is loaded, said after a listing and after what a search found: the pack's own
|
|
1365
|
+
// words there name how a section is read, and a skill read as a file comes without its rules.
|
|
1366
|
+
const loading = `A skill is loaded, its rules first, with ${skillCommand} <the path of its SKILL.md>, a long one in parts; --file reads a file of the pack as it is, without the rules.`;
|
|
809
1367
|
if (positionals.length > 1) {
|
|
810
1368
|
throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
|
|
811
1369
|
}
|
|
812
1370
|
// The root of the pack is the mounted folder, which the deployment reads as no path at all.
|
|
813
1371
|
const given = positionals[0];
|
|
814
|
-
const folder = given === undefined || given === "/" || given === "." ? undefined : given;
|
|
815
1372
|
const words = text(values, "search");
|
|
1373
|
+
const within = text(values, "path");
|
|
816
1374
|
const limit = text(values, "limit");
|
|
817
1375
|
const cursor = text(values, "cursor");
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
if (
|
|
829
|
-
|
|
1376
|
+
const rows = on(values, "rows");
|
|
1377
|
+
const code = on(values, "code");
|
|
1378
|
+
const heading = text(values, "heading");
|
|
1379
|
+
const out = text(values, "out");
|
|
1380
|
+
const format = text(values, "format");
|
|
1381
|
+
const grep = text(values, "grep");
|
|
1382
|
+
const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
|
|
1383
|
+
if (rows && code) {
|
|
1384
|
+
throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
|
|
1385
|
+
}
|
|
1386
|
+
if ((rows || code) &&
|
|
1387
|
+
(words !== undefined || within !== undefined || limit !== undefined || cursor !== undefined)) {
|
|
1388
|
+
throw misuse(`--rows and --code read a folder or a file whole, and go without --search: ${dataUsage}`);
|
|
1389
|
+
}
|
|
1390
|
+
if (!rows && !code && (heading !== undefined || out !== undefined)) {
|
|
1391
|
+
throw misuse(`--heading and --out go with --rows or --code: ${dataUsage}`);
|
|
1392
|
+
}
|
|
1393
|
+
if (format !== undefined && !rows) {
|
|
1394
|
+
throw misuse(`--format goes with --rows: ${extras.command} --rows [<folder|file>] [--format csv|json]`);
|
|
1395
|
+
}
|
|
1396
|
+
if (grep !== undefined && !code) {
|
|
1397
|
+
throw misuse(`--grep goes with --code: ${extras.command} --code [<folder|file>] [--grep <pattern>]`);
|
|
1398
|
+
}
|
|
1399
|
+
// The folder a search keeps to is said once: after the words, or with --path as the
|
|
1400
|
+
// skillcdn command takes it.
|
|
1401
|
+
if (within !== undefined && words === undefined) {
|
|
1402
|
+
throw misuse(`--path goes with --search; a folder is read with ${extras.command} <folder>: ${extras.command} --search <words> [--path <folder>]`);
|
|
1403
|
+
}
|
|
1404
|
+
if (within !== undefined && given !== undefined) {
|
|
1405
|
+
throw misuse(`Say the folder once: after the words, or with --path: ${extras.command} --search <words> [<folder>]`);
|
|
1406
|
+
}
|
|
1407
|
+
const named = given ?? within;
|
|
1408
|
+
const folder = named === undefined || named === "/" || named === "." ? undefined : named;
|
|
1409
|
+
if (words === undefined && given === undefined && (limit !== undefined || cursor !== undefined)) {
|
|
1410
|
+
throw misuse(`--limit and --cursor go with a folder or with --search: ${extras.command} <folder> [--limit <n>] [--cursor <cursor>]`);
|
|
1411
|
+
}
|
|
1412
|
+
// A page of what words find, or of what a folder holds: the bounds of each, as the pack has them.
|
|
1413
|
+
checkedNumber(limit, "limit", words === undefined ? BROWSE_MAX_LIMIT : FIND_MAX_LIMIT);
|
|
1414
|
+
const listing = await reader.skills();
|
|
1415
|
+
// With --json the console's own addresses stay in a document's outline; in words, the
|
|
1416
|
+
// commands that read its tables and its code blocks.
|
|
1417
|
+
const pack = consolePack(reader, listing, {
|
|
1418
|
+
url: session.url,
|
|
1419
|
+
dataCommand: session.json ? undefined : extras.command,
|
|
1420
|
+
});
|
|
1421
|
+
// As data: a read the pack refused fails with why, and nothing is printed.
|
|
1422
|
+
if (rows || code) {
|
|
1423
|
+
if (pack === undefined) {
|
|
1424
|
+
throw failed(refusalWords(rows ? "tables" : "code blocks", listing, owner));
|
|
1425
|
+
}
|
|
1426
|
+
return readData(io, session, pack, {
|
|
1427
|
+
read: rows
|
|
1428
|
+
? { read: "rows", path: folder, heading, format }
|
|
1429
|
+
: { read: "code", path: folder, heading, grep },
|
|
1430
|
+
out,
|
|
1431
|
+
owner,
|
|
1432
|
+
words: toolWords,
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
// A pack that does not answer: said as that, which a folder or a search would meet too.
|
|
1436
|
+
if (pack === undefined) {
|
|
1437
|
+
throw refusedRead(io, session, owner, listing, [formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
|
|
1438
|
+
.filter((part) => part !== undefined)
|
|
1439
|
+
.join("\n"));
|
|
1440
|
+
}
|
|
1441
|
+
if (words === undefined && given === undefined) {
|
|
1442
|
+
// --json is the console's listing as it answered it; the words are the pack's own, read once more from that answer.
|
|
1443
|
+
const told = session.json
|
|
1444
|
+
? undefined
|
|
1445
|
+
: await readThrough(io, session, owner, pack, { read: "skills" }, { words: toolWords });
|
|
1446
|
+
say(listing, () => [formatSkills(listing, told?.text, extras.own, owner, toolWords), loading, extras.afterwards]
|
|
830
1447
|
.filter((part) => part !== undefined)
|
|
831
1448
|
.join("\n"));
|
|
832
1449
|
return EXIT.ok;
|
|
833
1450
|
}
|
|
834
1451
|
if (words !== undefined) {
|
|
835
1452
|
// One page of what the words find; more is said, and asked for with --cursor.
|
|
836
|
-
const found = await
|
|
837
|
-
|
|
1453
|
+
const found = await readThrough(io, session, owner, pack, { read: "find", words, path: folder, cursor, limit }, { words: toolWords });
|
|
1454
|
+
say(jsonOfRead(session, pack, found), () => `${found.text}\n${loading}`);
|
|
838
1455
|
return EXIT.ok;
|
|
839
1456
|
}
|
|
840
|
-
//
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}
|
|
1457
|
+
// One page of the folder, or of a file's outline, as the skillcdn command browses: a page
|
|
1458
|
+
// that ends before the folder does names the cursor that continues it.
|
|
1459
|
+
const browsed = await readThrough(io, session, owner, pack, { read: "browse", path: folder, cursor, limit }, { words: toolWords });
|
|
1460
|
+
say(jsonOfRead(session, pack, browsed), () => browsed.text);
|
|
1461
|
+
return EXIT.ok;
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* The pack a command reads (ADR-0113): the project's where one is named; else the
|
|
1465
|
+
* organization's, which a desk and a folder a repository is about to be made in read, since
|
|
1466
|
+
* neither names a project and the skill that sets one up is in that pack.
|
|
1467
|
+
*/
|
|
1468
|
+
async function packNamed(session) {
|
|
1469
|
+
return (await session.projectKey()) === undefined
|
|
1470
|
+
? { reader: session.client.organizationPack(), owner: "organization" }
|
|
1471
|
+
: { reader: await session.project(), owner: "project" };
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* A read of the organization's pack at a console from before ADR-0113, which has no such
|
|
1475
|
+
* routes and answers that nothing is at the path: said as what it is, with what still reads a
|
|
1476
|
+
* pack there, where the console's own words would read as a missing skill.
|
|
1477
|
+
*/
|
|
1478
|
+
async function readingPack(owner, read) {
|
|
1479
|
+
try {
|
|
1480
|
+
return await read();
|
|
854
1481
|
}
|
|
855
|
-
|
|
856
|
-
|
|
1482
|
+
catch (error) {
|
|
1483
|
+
if (owner === "organization" && error instanceof ApiError && error.code === "not_found") {
|
|
1484
|
+
throw failed(`This console does not read the organization's pack where no project is named: it is older than the command. ${NO_PROJECT}`);
|
|
1485
|
+
}
|
|
1486
|
+
throw error;
|
|
857
1487
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Prints a read of a pack: as `answer` does, and, where the pack is the organization's, under
|
|
1491
|
+
* the line that says so. `--json` stays what the console answered.
|
|
1492
|
+
*/
|
|
1493
|
+
function answerPack(io, session, owner, value, words) {
|
|
1494
|
+
answer(io, session, value, () => owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words()}` : words());
|
|
862
1495
|
}
|
|
863
1496
|
const skills = async (args, io) => {
|
|
864
1497
|
const { values, positionals } = parse(args, SKILLS_OPTIONS);
|
|
865
1498
|
const session = await open(io, values);
|
|
866
|
-
const
|
|
867
|
-
return readSkills(io, session,
|
|
1499
|
+
const { reader, owner } = await packNamed(session);
|
|
1500
|
+
return readingPack(owner, () => readSkills(io, session, reader, values, positionals, {
|
|
868
1501
|
command: "console skills",
|
|
869
1502
|
own: io.skillsDir,
|
|
870
1503
|
afterwards: PLUGIN_SKILLS_LINE,
|
|
871
|
-
|
|
1504
|
+
owner,
|
|
1505
|
+
}));
|
|
872
1506
|
};
|
|
873
|
-
/** The most characters one read of a file asks for: what the console's API allows on one page. */
|
|
874
|
-
const MAX_FILE_LIMIT = 100_000;
|
|
875
|
-
/** A count given as a flag, within its bounds, or nothing; anything else is not understood. */
|
|
876
|
-
function countOf(given, name, bounds) {
|
|
877
|
-
if (given === undefined) {
|
|
878
|
-
return undefined;
|
|
879
|
-
}
|
|
880
|
-
const count = Number(given);
|
|
881
|
-
if (!Number.isInteger(count) ||
|
|
882
|
-
count < bounds.least ||
|
|
883
|
-
(bounds.most !== undefined && count > bounds.most)) {
|
|
884
|
-
const range = bounds.most === undefined ? `${bounds.least} or more` : `${bounds.least} to ${bounds.most}`;
|
|
885
|
-
throw misuse(`Not a number for --${name}, ${range}: ${given}`);
|
|
886
|
-
}
|
|
887
|
-
return count;
|
|
888
|
-
}
|
|
889
1507
|
/**
|
|
890
|
-
* One skill of the pack
|
|
891
|
-
*
|
|
1508
|
+
* One skill of the pack, or a page of a file of it; for the project's pack as `console skill`,
|
|
1509
|
+
* and for a plugin's as `console plugin <key> skill`. Each as the skillcdn command reads it,
|
|
1510
|
+
* through its own reads (ADR-0124): a skill whole where a host shows it whole, else in parts,
|
|
1511
|
+
* each ending with the command that reads the next; a file a page at a time. `again` is what
|
|
1512
|
+
* that command says after the cursor, its words: where the pack is read, as it was said for this
|
|
1513
|
+
* part.
|
|
892
1514
|
*/
|
|
893
|
-
async function readSkill(io, session, reader, values, positionals, command) {
|
|
1515
|
+
async function readSkill(io, session, reader, values, positionals, command, owner = "project", again = []) {
|
|
1516
|
+
const say = (value, words) => answerPack(io, session, owner, value, words);
|
|
1517
|
+
const toolWords = packWords(`${command}s`, command);
|
|
894
1518
|
const file = text(values, "file");
|
|
1519
|
+
const cursor = text(values, "cursor");
|
|
895
1520
|
// A file is read by its own path from the repository's root; a skill's path beside it would be
|
|
896
1521
|
// ignored, which reads as if it mattered, so the two together are not understood.
|
|
897
1522
|
if (file !== undefined && positionals.length > 0) {
|
|
898
1523
|
throw misuse(`Say one: ${command} <path of its SKILL.md> for a skill, or ${command} --file <path> for a file of the pack.`);
|
|
899
1524
|
}
|
|
900
|
-
// A
|
|
1525
|
+
// A page of a file is asked for by where it begins and how long it is: the flags mean nothing without one.
|
|
901
1526
|
if (file === undefined &&
|
|
902
1527
|
(text(values, "offset") !== undefined || text(values, "limit") !== undefined)) {
|
|
903
1528
|
throw misuse(`--offset and --limit go with --file: ${command} --file <path> [--offset <n>] [--limit <n>]`);
|
|
904
1529
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
if (summary === undefined) {
|
|
909
|
-
answer(io, session, listing, () => formatSkills(listing, io.skillsDir));
|
|
910
|
-
return EXIT.ok;
|
|
1530
|
+
// The next part of a skill is asked for by the cursor its part ended with; a file reads on from an offset.
|
|
1531
|
+
if (file !== undefined && cursor !== undefined) {
|
|
1532
|
+
throw misuse(`--cursor reads the next part of a skill; a file reads on from --offset: ${command} --file <path> [--offset <n>] [--limit <n>]`);
|
|
911
1533
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
return EXIT.ok;
|
|
1534
|
+
checkedNumber(text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
|
|
1535
|
+
checkedNumber(text(values, "limit"), "limit", READ_FILE_MAX_LIMIT);
|
|
1536
|
+
const listing = await reader.skills();
|
|
1537
|
+
const pack = consolePack(reader, listing, { url: session.url });
|
|
1538
|
+
if (pack === undefined) {
|
|
1539
|
+
throw refusedRead(io, session, owner, listing, formatSkills(listing, undefined, io.skillsDir, owner, toolWords));
|
|
919
1540
|
}
|
|
920
1541
|
if (file !== undefined) {
|
|
921
|
-
//
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
|
|
926
|
-
last = await reader.skillFile(file, offset === undefined ? {} : { offset });
|
|
927
|
-
if (last.read === null) {
|
|
928
|
-
break;
|
|
929
|
-
}
|
|
930
|
-
pages.push(last);
|
|
931
|
-
if (last.read.kind !== "file" || last.read.nextOffset === null) {
|
|
932
|
-
break;
|
|
933
|
-
}
|
|
934
|
-
offset = last.read.nextOffset;
|
|
935
|
-
}
|
|
936
|
-
if (last === undefined) {
|
|
937
|
-
throw failed("The file could not be read.");
|
|
938
|
-
}
|
|
939
|
-
const fileRead = last;
|
|
940
|
-
const whole = joinFile(pages, summary);
|
|
941
|
-
answer(io, session, { ...fileRead, read: whole === undefined ? null : bodyOfFile(whole) }, () => formatSkillFile(fileRead, whole));
|
|
1542
|
+
// A page of the file, as the skillcdn command reads one: from --offset, as long as a host
|
|
1543
|
+
// shows whole where --limit says nothing, and where the next begins when the file goes on.
|
|
1544
|
+
const page = await readThrough(io, session, owner, pack, { read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") }, { words: toolWords });
|
|
1545
|
+
say(jsonOfRead(session, pack, page), () => page.text);
|
|
942
1546
|
return EXIT.ok;
|
|
943
1547
|
}
|
|
944
|
-
const
|
|
1548
|
+
const given = theOne(positionals, `Say which skill: ${command} <path of its SKILL.md>, or ${command} --file <path> for a file of the pack`);
|
|
1549
|
+
const wanted = skillPathIn(given, listing.address);
|
|
945
1550
|
if ("error" in wanted) {
|
|
946
1551
|
throw misuse(wanted.error);
|
|
947
1552
|
}
|
|
948
|
-
// The skill
|
|
949
|
-
|
|
950
|
-
let
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
}
|
|
966
|
-
const loaded = last;
|
|
967
|
-
const whole = joinSkill(pages, summary);
|
|
968
|
-
answer(io, session, { ...loaded, read: whole === undefined ? null : bodyOfSkill(whole) }, () => formatSkillLoad(loaded, whole));
|
|
1553
|
+
// The skill, its rules first, as load_skill lays them out: whole, or the part that begins at
|
|
1554
|
+
// the cursor, ending with the command that reads the next, asked as this one was.
|
|
1555
|
+
let continues = false;
|
|
1556
|
+
const loaded = await readThrough(io, session, owner, pack, { read: "skill", path: wanted.path, cursor }, {
|
|
1557
|
+
words: toolWords,
|
|
1558
|
+
// Spelled so that bash and PowerShell run it as it is; where a word has no such spelling,
|
|
1559
|
+
// the command that was run is run again, with the cursor, and the line says why.
|
|
1560
|
+
nextPart: (next) => {
|
|
1561
|
+
continues = true;
|
|
1562
|
+
return (commandLine(command, [given, "--cursor", next, ...again]) ??
|
|
1563
|
+
`the command you ran, with --cursor ${commandWord(next) ?? JSON.stringify(next)} in place of any it had, each word quoted for your shell. ${NO_LINE_TO_RUN}`);
|
|
1564
|
+
},
|
|
1565
|
+
});
|
|
1566
|
+
// A part that is not the last ends with the console's own words after the library's line: a
|
|
1567
|
+
// fresh agent read one part of four, saw that the skill continued, and planned from that part,
|
|
1568
|
+
// since "before using it" did not read as now to a session that meant only to plan.
|
|
1569
|
+
say(jsonOfRead(session, pack, loaded), () => continues ? `${loaded.text}\n${PART_ENDS_HERE}` : loaded.text);
|
|
969
1570
|
return EXIT.ok;
|
|
970
1571
|
}
|
|
1572
|
+
/**
|
|
1573
|
+
* What a part of a skill ends with where another follows: that the instructions stop here,
|
|
1574
|
+
* what the rest holds, and that the command above is run now.
|
|
1575
|
+
*/
|
|
1576
|
+
const PART_ENDS_HERE = "This part stops in the middle of the skill: its later steps, its checkpoints and its rules are in the parts that follow, and nothing above is complete without them. Run that command now, before a plan, an answer or any other step, and each next one, until a part ends without these lines.";
|
|
971
1577
|
const skill = async (args, io) => {
|
|
972
1578
|
const { values, positionals } = parse(args, SKILL_OPTIONS);
|
|
973
1579
|
const session = await open(io, values);
|
|
974
|
-
const
|
|
975
|
-
return readSkill(io, session,
|
|
1580
|
+
const { reader, owner } = await packNamed(session);
|
|
1581
|
+
return readingPack(owner, () => readSkill(io, session, reader, values, positionals, "console skill", owner, whereGiven(values)));
|
|
976
1582
|
};
|
|
977
1583
|
// ---- The plugins (docs/specs/plugins.md, "The command") ----
|
|
978
1584
|
// `console plugins` and `console plugin <key> ...` are the two entries: the command sends the
|
|
@@ -1038,7 +1644,7 @@ function splitWords(args, own) {
|
|
|
1038
1644
|
}
|
|
1039
1645
|
return { values, words };
|
|
1040
1646
|
}
|
|
1041
|
-
const PLUGIN_USAGE = "console plugin <key> [help [<command>] | <command> [args] | records <collection> | skills | skill <path> | enable | disable | settings | secret <name> | grant <role> | revoke <id>]. console plugins lists the plugins.";
|
|
1647
|
+
const PLUGIN_USAGE = "console plugin <key> [help [<command>] | <command> [args] | records <collection> | events [--kind <kind>] | skills | skill <path> | enable | disable | settings | secret <name> [--key <key>] | grant <role> | revoke <id>]. console plugins lists the plugins.";
|
|
1042
1648
|
const plugin = async (args, io) => {
|
|
1043
1649
|
const { values, words } = splitWords(args, PLUGIN_GLOBAL_FLAGS);
|
|
1044
1650
|
const [key, verb, ...rest] = words;
|
|
@@ -1070,6 +1676,8 @@ const plugin = async (args, io) => {
|
|
|
1070
1676
|
}
|
|
1071
1677
|
case "records":
|
|
1072
1678
|
return pluginRecords(io, session, client, rest, text(values, "project"));
|
|
1679
|
+
case "events":
|
|
1680
|
+
return pluginEvents(io, session, client, rest);
|
|
1073
1681
|
case "skills": {
|
|
1074
1682
|
const parsed = parse(rest, SKILLS_OPTIONS);
|
|
1075
1683
|
return readSkills(io, session, client, parsed.values, parsed.positionals, {
|
|
@@ -1078,7 +1686,7 @@ const plugin = async (args, io) => {
|
|
|
1078
1686
|
}
|
|
1079
1687
|
case "skill": {
|
|
1080
1688
|
const parsed = parse(rest, SKILL_OPTIONS);
|
|
1081
|
-
return readSkill(io, session, client, parsed.values, parsed.positionals, `console plugin ${key} skill
|
|
1689
|
+
return readSkill(io, session, client, parsed.values, parsed.positionals, `console plugin ${key} skill`, "project", whereGiven(values));
|
|
1082
1690
|
}
|
|
1083
1691
|
case "enable":
|
|
1084
1692
|
return pluginEnable(io, session, client, rest);
|
|
@@ -1212,6 +1820,37 @@ function whereValueOf(word) {
|
|
|
1212
1820
|
return word;
|
|
1213
1821
|
}
|
|
1214
1822
|
/** The records of a collection one may read, a page of them; or one record, or its versions. */
|
|
1823
|
+
/**
|
|
1824
|
+
* A plugin's events, newest first (ADR-0128): what it did and what went wrong in it, as far as
|
|
1825
|
+
* the caller may read it, which the console decides (every event for an administrator; for
|
|
1826
|
+
* anyone else those of the projects they may see, their own commands and the console's word of
|
|
1827
|
+
* the plugin); the failures alone with `--kind plugin.failed`, whether or not it has a board
|
|
1828
|
+
* project. A console before 0.5.1 takes no kind and answers every one: the page is narrowed
|
|
1829
|
+
* here, and that is said, since a page narrowed after it was read may hold fewer than were
|
|
1830
|
+
* asked for.
|
|
1831
|
+
*/
|
|
1832
|
+
async function pluginEvents(io, session, client, rest) {
|
|
1833
|
+
const usage = `console plugin ${client.key} events [--kind <kind>] [--limit <n>] [--offset <n>]`;
|
|
1834
|
+
const { values, positionals } = parse(rest, { kind: { type: "string" }, ...PAGE_OPTIONS });
|
|
1835
|
+
if (positionals.length > 0) {
|
|
1836
|
+
throw misuse(`Events take no word but their flags: ${usage}`);
|
|
1837
|
+
}
|
|
1838
|
+
const kind = text(values, "kind");
|
|
1839
|
+
if (kind !== undefined && !/^[a-z_]{1,40}\.[a-z_]{1,40}$/.test(kind)) {
|
|
1840
|
+
throw misuse(`Not a kind of event: ${kind}. A kind is two words with a dot between, as plugin.failed or plugin.command: ${usage}`);
|
|
1841
|
+
}
|
|
1842
|
+
const limit = countOf(text(values, "limit"), "limit", { least: 1, most: EVENTS_PAGE_LIMIT });
|
|
1843
|
+
const offset = countOf(text(values, "offset"), "offset", { least: 0, most: 1_000_000 });
|
|
1844
|
+
const asked = { kind, limit: limit ?? DEFAULT_PAGE_LIMIT, offset: offset ?? 0 };
|
|
1845
|
+
const read = await client.events(asked);
|
|
1846
|
+
const items = kind === undefined ? read.items : read.items.filter((one) => one.kind === kind);
|
|
1847
|
+
const narrowedHere = items.length !== read.items.length;
|
|
1848
|
+
const page = { items, more: read.more };
|
|
1849
|
+
answer(io, session, page, () => `${formatPluginEvents(client.key, page, asked)}${narrowedHere
|
|
1850
|
+
? `\nThis console is older than 0.5.1 and does not narrow events by kind: of the ${read.items.length} newest read, the ${kind} ones are shown. Read further back with --offset.`
|
|
1851
|
+
: ""}`);
|
|
1852
|
+
return EXIT.ok;
|
|
1853
|
+
}
|
|
1215
1854
|
async function pluginRecords(io, session, client, rest, project) {
|
|
1216
1855
|
const { values, positionals } = parse(rest, {
|
|
1217
1856
|
where: { type: "string", multiple: true },
|
|
@@ -1461,19 +2100,26 @@ async function pluginSettings(io, session, client, rest) {
|
|
|
1461
2100
|
* shown never; or takes it away.
|
|
1462
2101
|
*/
|
|
1463
2102
|
async function pluginSecret(io, session, client, rest) {
|
|
1464
|
-
const { values, positionals } = parse(rest, {
|
|
1465
|
-
|
|
2103
|
+
const { values, positionals } = parse(rest, {
|
|
2104
|
+
remove: { type: "boolean" },
|
|
2105
|
+
key: { type: "string" },
|
|
2106
|
+
});
|
|
2107
|
+
const name = theOne(positionals, `Say which secret: console plugin ${client.key} secret <name> [--key <key>] [--remove]; the value is typed at the prompt, unseen, or piped in.`);
|
|
2108
|
+
// A secret kept per key (ADR-0111) is set and removed one key at a time.
|
|
2109
|
+
const key = text(values, "key");
|
|
2110
|
+
const which = key === undefined ? `the secret ${name}` : `the secret ${name} under ${key}`;
|
|
2111
|
+
const data = key === undefined ? { name } : { name, key };
|
|
1466
2112
|
if (on(values, "remove")) {
|
|
1467
|
-
await client.removeSecret(name);
|
|
1468
|
-
answer(io, session, {
|
|
2113
|
+
await client.removeSecret(name, key);
|
|
2114
|
+
answer(io, session, { ...data, set: false }, () => `Removed ${which} of ${client.key}.`);
|
|
1469
2115
|
return EXIT.ok;
|
|
1470
2116
|
}
|
|
1471
|
-
const value = await secretGiven(io, `Secret ${name} of ${client.key} (typed unseen; Enter ends it): `);
|
|
2117
|
+
const value = await secretGiven(io, `Secret ${name}${key === undefined ? "" : ` under ${key}`} of ${client.key} (typed unseen; Enter ends it): `);
|
|
1472
2118
|
if (value.length === 0) {
|
|
1473
|
-
throw misuse(`Type the value at the prompt, or redirect a file into it: console plugin ${client.key} secret ${name} < file. Never give it on the command line or through echo, which a shell keeps; the console seals it and shows it never.`);
|
|
2119
|
+
throw misuse(`Type the value at the prompt, or redirect a file into it: console plugin ${client.key} secret ${name}${key === undefined ? "" : ` --key ${key}`} < file. Never give it on the command line or through echo, which a shell keeps; the console seals it and shows it never.`);
|
|
1474
2120
|
}
|
|
1475
|
-
await client.setSecret(name, value);
|
|
1476
|
-
answer(io, session, {
|
|
2121
|
+
await client.setSecret(name, value, key);
|
|
2122
|
+
answer(io, session, { ...data, set: true }, () => `Set ${which} of ${client.key}: sealed, and shown by nothing from now on.`);
|
|
1477
2123
|
return EXIT.ok;
|
|
1478
2124
|
}
|
|
1479
2125
|
/**
|
|
@@ -1537,8 +2183,9 @@ function versionOf(given) {
|
|
|
1537
2183
|
}
|
|
1538
2184
|
return version;
|
|
1539
2185
|
}
|
|
1540
|
-
// The rules of the board (ADR-0023):
|
|
1541
|
-
//
|
|
2186
|
+
// The rules of the board (ADR-0023, ADR-0120): the console's, which always hold, with what the
|
|
2187
|
+
// organization and the project add to them; read before a task is taken, and added to by an
|
|
2188
|
+
// owner for the project and by an administrator for the organization, on the page each keeps.
|
|
1542
2189
|
const rules = async (args, io) => {
|
|
1543
2190
|
const [verb, ...rest] = args;
|
|
1544
2191
|
if (verb === "write") {
|
|
@@ -1555,36 +2202,44 @@ const rules = async (args, io) => {
|
|
|
1555
2202
|
const none = given === "none";
|
|
1556
2203
|
const body = none ? undefined : await bodyOf(io, values, given);
|
|
1557
2204
|
if (!none && body === undefined) {
|
|
1558
|
-
throw misuse("Say what
|
|
2205
|
+
throw misuse("Say what is added to the rules: --body <markdown>, --file <path>, - to read standard input, or none to put what was added away.");
|
|
1559
2206
|
}
|
|
1560
2207
|
const baseVersion = versionOf(text(values, "base"));
|
|
1561
2208
|
const session = await open(io, values);
|
|
1562
2209
|
if (on(values, "workspace")) {
|
|
1563
2210
|
if (none) {
|
|
1564
2211
|
const put = await session.client.archiveRules();
|
|
1565
|
-
answer(io, session, put, () => "
|
|
2212
|
+
answer(io, session, put, () => "What this organization adds to the rules is put away: the console's stand alone.");
|
|
1566
2213
|
return EXIT.ok;
|
|
1567
2214
|
}
|
|
2215
|
+
// A console of before 0.5.1 keeps what is written here as the organization's whole rules,
|
|
2216
|
+
// in the place of its own (ADR-0120): what is added would be all that holds there. Its
|
|
2217
|
+
// answer tells, since it says the workspace's rules whole and no parts, and it is asked
|
|
2218
|
+
// before anything is written.
|
|
2219
|
+
const held = await session.client.rules();
|
|
2220
|
+
if (held.own === undefined) {
|
|
2221
|
+
throw failed("This console is older than 0.5.1 and keeps the organization's rules whole: what is written here would replace the console's rules, not add to them. Update the console first.");
|
|
2222
|
+
}
|
|
1568
2223
|
const written = await session.client.writeRules({
|
|
1569
2224
|
body: body ?? "",
|
|
1570
2225
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
1571
2226
|
});
|
|
1572
2227
|
answer(io, session, written, () => written.page === null
|
|
1573
|
-
? "Nothing written:
|
|
1574
|
-
: `Wrote the
|
|
2228
|
+
? "Nothing written: that adds nothing to the console's rules, which hold as they stand."
|
|
2229
|
+
: `Wrote what this organization adds to the rules, version ${written.page.version}.`);
|
|
1575
2230
|
return EXIT.ok;
|
|
1576
2231
|
}
|
|
1577
2232
|
const project = await session.project();
|
|
1578
2233
|
if (none) {
|
|
1579
2234
|
try {
|
|
1580
2235
|
const put = await project.archiveDocument(RULES_PATH);
|
|
1581
|
-
answer(io, session, put, () => "
|
|
2236
|
+
answer(io, session, put, () => "What this project adds to the rules is put away: it adds nothing now.");
|
|
1582
2237
|
}
|
|
1583
2238
|
catch (error) {
|
|
1584
2239
|
if (!(error instanceof ApiError) || error.code !== "document.not_found") {
|
|
1585
2240
|
throw error;
|
|
1586
2241
|
}
|
|
1587
|
-
answer(io, session, null, () => "This project
|
|
2242
|
+
answer(io, session, null, () => "This project adds nothing to the rules: nothing to put away.");
|
|
1588
2243
|
}
|
|
1589
2244
|
return EXIT.ok;
|
|
1590
2245
|
}
|
|
@@ -1593,14 +2248,14 @@ const rules = async (args, io) => {
|
|
|
1593
2248
|
body: body ?? "",
|
|
1594
2249
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
1595
2250
|
});
|
|
1596
|
-
answer(io, session, written, () => `Wrote this project
|
|
2251
|
+
answer(io, session, written, () => `Wrote what this project adds to the rules, version ${written.version}.`);
|
|
1597
2252
|
return EXIT.ok;
|
|
1598
2253
|
}
|
|
1599
2254
|
const { values } = parse(args, {}, false);
|
|
1600
2255
|
const session = await open(io, values);
|
|
1601
2256
|
const key = await session.projectKey();
|
|
1602
2257
|
const [found, me] = await Promise.all([
|
|
1603
|
-
key === undefined ? session.client.rules() : session.
|
|
2258
|
+
key === undefined ? session.client.rules() : (await session.project()).rules(),
|
|
1604
2259
|
session.client.me(),
|
|
1605
2260
|
]);
|
|
1606
2261
|
const read = "workspace" in found
|
|
@@ -1610,15 +2265,24 @@ const rules = async (args, io) => {
|
|
|
1610
2265
|
...(found.plugins === undefined ? {} : { plugins: found.plugins }),
|
|
1611
2266
|
}
|
|
1612
2267
|
: forPerson(found, readingLanguage(me));
|
|
1613
|
-
|
|
2268
|
+
// The mark of what is printed goes with --json too, for a program that takes a task next.
|
|
2269
|
+
answer(io, session, { ...read, mark: rulesMark(read, readingLanguage(me)) }, () => formatRules(read, readingLanguage(me)));
|
|
1614
2270
|
return EXIT.ok;
|
|
1615
2271
|
};
|
|
1616
2272
|
/**
|
|
1617
2273
|
* The rules as they read for the person whose token the command holds: `{language}` filled
|
|
1618
|
-
* with the language they read in, or with the task's while they have none
|
|
2274
|
+
* with the language they read in, or with the task's while they have none; in the whole and,
|
|
2275
|
+
* where the console says them apart (ADR-0120), in the console's own and in what is added.
|
|
1619
2276
|
*/
|
|
1620
2277
|
function forPerson(half, language) {
|
|
1621
|
-
return
|
|
2278
|
+
return {
|
|
2279
|
+
...half,
|
|
2280
|
+
...(half.body === null ? {} : { body: fillRules(half.body, language) }),
|
|
2281
|
+
...(half.own === undefined ? {} : { own: fillRules(half.own, language) }),
|
|
2282
|
+
...(half.added == null
|
|
2283
|
+
? {}
|
|
2284
|
+
: { added: { ...half.added, body: fillRules(half.added.body, language) } }),
|
|
2285
|
+
};
|
|
1622
2286
|
}
|
|
1623
2287
|
/** The flags that set a task's fields, shared by writing one and changing one. */
|
|
1624
2288
|
const TASK_FIELDS = {
|
|
@@ -1686,8 +2350,24 @@ const newTask = async (args, io) => {
|
|
|
1686
2350
|
...TASK_FIELDS,
|
|
1687
2351
|
body: { type: "string" },
|
|
1688
2352
|
file: { type: "string" },
|
|
2353
|
+
take: { type: "boolean" },
|
|
2354
|
+
agent: { type: "string" },
|
|
2355
|
+
rules: { type: "string" },
|
|
1689
2356
|
});
|
|
1690
2357
|
const title = theOne(positionals, 'Say the title: console task new "<title>"');
|
|
2358
|
+
// Written and taken in one command (--take): work given in chat is both at once, and a
|
|
2359
|
+
// session that sends its commands together cannot read the number between two of them,
|
|
2360
|
+
// on a board where another agent may have written a task in the meantime.
|
|
2361
|
+
const taken = on(values, "take");
|
|
2362
|
+
if (!taken && (text(values, "rules") !== undefined || text(values, "agent") !== undefined)) {
|
|
2363
|
+
throw misuse('--rules and --agent go with --take, which takes the task as it is written: console task new "<title>" --take [--rules <mark>] [--agent <name>]');
|
|
2364
|
+
}
|
|
2365
|
+
// Refused before anything is written: a task that is done or dropped is not taken, and
|
|
2366
|
+
// written first it would stand on the board as the half of a command that failed.
|
|
2367
|
+
const said = stateOf(text(values, "state"));
|
|
2368
|
+
if (taken && (said === "done" || said === "dropped")) {
|
|
2369
|
+
throw misuse(`A task written as ${said} is not taken. Leave --state out, for ready; or leave --take out.`);
|
|
2370
|
+
}
|
|
1691
2371
|
const body = await bodyOf(io, values, text(values, "body"));
|
|
1692
2372
|
const session = await open(io, values);
|
|
1693
2373
|
const project = await session.project();
|
|
@@ -1695,12 +2375,44 @@ const newTask = async (args, io) => {
|
|
|
1695
2375
|
const made = await project.createTask({
|
|
1696
2376
|
title,
|
|
1697
2377
|
...(body === undefined ? {} : { body }),
|
|
2378
|
+
// An idea is not taken: what is written to be taken is ready, where no state is said.
|
|
2379
|
+
...(taken && said === undefined ? { state: "ready" } : {}),
|
|
1698
2380
|
...fields,
|
|
1699
2381
|
});
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
2382
|
+
const written = `Task #${made.number} written: ${made.title}\ntask id: ${made.id}`;
|
|
2383
|
+
if (!taken) {
|
|
2384
|
+
// With the address of its page, for a person told of the task; a task taken at once says
|
|
2385
|
+
// it in the task's own lines below, once.
|
|
2386
|
+
const page = await taskPage(session, made.number);
|
|
2387
|
+
answer(io, session, made, () => page === undefined ? written : `${written}\n${pageLine(page)}`);
|
|
2388
|
+
return EXIT.ok;
|
|
2389
|
+
}
|
|
2390
|
+
// The number first, before the take is asked for: whatever becomes of the take, the task is
|
|
2391
|
+
// on the board, and the session must know it by its number so as not to write it twice.
|
|
2392
|
+
if (!session.json) {
|
|
2393
|
+
io.stdout(`${written}\n`);
|
|
2394
|
+
}
|
|
2395
|
+
let run;
|
|
2396
|
+
let took;
|
|
2397
|
+
try {
|
|
2398
|
+
run = await runOn(project, made, values);
|
|
2399
|
+
took = await taking(session, project, made, made.id, run, values);
|
|
2400
|
+
}
|
|
2401
|
+
catch (error) {
|
|
2402
|
+
// Said before the console's own words for what failed, which follow as on any command:
|
|
2403
|
+
// which half stands, by the task's number, so that nothing is written or taken twice.
|
|
2404
|
+
if (session.json) {
|
|
2405
|
+
io.stdout(`${JSON.stringify({ written: made, ...(run === undefined ? {} : { run }) }, null, 2)}\n`);
|
|
2406
|
+
}
|
|
2407
|
+
io.stderr(run === undefined
|
|
2408
|
+
? `Task #${made.number} is written and was not taken: it stands on the board as written. Take it with console take ${made.number}, and do not write it again. What the take ended on:\n`
|
|
2409
|
+
: `Task #${made.number} is written and taken, run ${run.id}, and what a take prints of it was not read. Do not write it or take it again: console task ${made.number} shows the task, console rules the rules. What the reading ended on:\n`);
|
|
2410
|
+
throw error;
|
|
2411
|
+
}
|
|
2412
|
+
answer(io, session, { written: made, ...took.value }, took.words);
|
|
2413
|
+
return EXIT.ok;
|
|
2414
|
+
};
|
|
2415
|
+
const editTask = async (args, io) => {
|
|
1704
2416
|
const { values, positionals } = parse(args, {
|
|
1705
2417
|
...TASK_FIELDS,
|
|
1706
2418
|
title: { type: "string" },
|
|
@@ -1722,7 +2434,8 @@ const editTask = async (args, io) => {
|
|
|
1722
2434
|
}
|
|
1723
2435
|
const found = await project.task(ref);
|
|
1724
2436
|
const changed = await project.updateTask(found.id, patch);
|
|
1725
|
-
|
|
2437
|
+
const page = await taskPage(session, changed.number);
|
|
2438
|
+
answer(io, session, changed, () => formatTask(changed, undefined, undefined, undefined, page));
|
|
1726
2439
|
return EXIT.ok;
|
|
1727
2440
|
};
|
|
1728
2441
|
/** Puts a task away, or every done or dropped task of a goal (ADR-0029); the task by its number or its id. */
|
|
@@ -1775,10 +2488,13 @@ const task = async (args, io) => {
|
|
|
1775
2488
|
const found = await project.task(ref);
|
|
1776
2489
|
const [decisions, runs, comments] = await Promise.all([
|
|
1777
2490
|
project.decisions({ task: found.id }),
|
|
1778
|
-
|
|
2491
|
+
// The runs are a line each, with their reports counted: the brief form, unless --json asks
|
|
2492
|
+
// for the console's own answer.
|
|
2493
|
+
session.json ? project.runs({ task: found.id }) : project.runBriefs({ task: found.id }),
|
|
1779
2494
|
project.comments(found.id),
|
|
1780
2495
|
]);
|
|
1781
|
-
|
|
2496
|
+
const page = await taskPage(session, found.number);
|
|
2497
|
+
answer(io, session, { task: found, decisions: decisions.items, runs: runs.items, comments: comments.items }, () => formatTask(found, decisions.items, runs.items, comments.items, page));
|
|
1782
2498
|
return EXIT.ok;
|
|
1783
2499
|
};
|
|
1784
2500
|
/**
|
|
@@ -1866,17 +2582,21 @@ const file = async (args, io) => {
|
|
|
1866
2582
|
}, () => `Saved ${read.name} (${read.bytes.byteLength} bytes, ${read.contentType}) at ${saved}`);
|
|
1867
2583
|
return EXIT.ok;
|
|
1868
2584
|
};
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
const ref = theOne(positionals, "Say which task: console take <number|id>");
|
|
1872
|
-
const session = await open(io, values);
|
|
1873
|
-
const project = await session.project();
|
|
1874
|
-
const found = await project.task(ref);
|
|
2585
|
+
/** Begins a run on a task, as the agent `--agent` names where it is said: the take itself. */
|
|
2586
|
+
function runOn(project, found, values) {
|
|
1875
2587
|
const agent = text(values, "agent");
|
|
1876
|
-
|
|
2588
|
+
return project.startRun({
|
|
1877
2589
|
taskId: found.id,
|
|
1878
2590
|
...(agent === undefined ? {} : { agent }),
|
|
1879
2591
|
});
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* What a take answers, once its run began: the task as it stands taken, its comments and the
|
|
2595
|
+
* rules under their mark, or left out by it (`--rules`, ADR-0119). `take` takes a task that
|
|
2596
|
+
* was read by what the person said, `task new --take` the one it has just written; `ref` is
|
|
2597
|
+
* what the task is read again by, now that it is taken.
|
|
2598
|
+
*/
|
|
2599
|
+
async function taking(session, project, found, ref, run, values) {
|
|
1880
2600
|
// The rules come with the run, as they read for the person: everything from here acts
|
|
1881
2601
|
// within them (ADR-0023); the task is read again, as it stands now that it is taken.
|
|
1882
2602
|
const [ruling, me, taken, comments, openRuns] = await Promise.all([
|
|
@@ -1884,7 +2604,7 @@ const take = async (args, io) => {
|
|
|
1884
2604
|
session.client.me(),
|
|
1885
2605
|
project.task(ref),
|
|
1886
2606
|
project.comments(found.id),
|
|
1887
|
-
project.
|
|
2607
|
+
project.runBriefs({ open: true, mine: true }),
|
|
1888
2608
|
]);
|
|
1889
2609
|
// Taking a task with a run open on it ends that run (ADR-0020): said when it happened.
|
|
1890
2610
|
const tookOver = found.openRuns > 0
|
|
@@ -1901,19 +2621,48 @@ const take = async (args, io) => {
|
|
|
1901
2621
|
project: forPerson(ruling.project, readingLanguage(me)),
|
|
1902
2622
|
...(ruling.plugins === undefined ? {} : { plugins: ruling.plugins }),
|
|
1903
2623
|
};
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2624
|
+
// A take gives the rules, whole, unless the session says the mark they have (ADR-0119): a
|
|
2625
|
+
// mark is known only from having been shown them, so a session that never was, a fresh one
|
|
2626
|
+
// or a subagent, gets them whatever it does. A mark that is not theirs, since they changed
|
|
2627
|
+
// or it is of another project's, gets them whole again, and is told so first. The line that
|
|
2628
|
+
// answers a mark stands directly after the run's ids, before the task: a take is cut at its
|
|
2629
|
+
// head by a session that holds the rules, and a rule that changed is what such a cut must
|
|
2630
|
+
// not lose. Without a mark nothing is said there, and the rules follow the task as before.
|
|
2631
|
+
const language = readingLanguage(me);
|
|
2632
|
+
const mark = rulesMark(rules, language);
|
|
2633
|
+
const held = text(values, "rules")?.trim().toLowerCase();
|
|
2634
|
+
const answered = held === undefined ? [] : [held === mark ? formatRulesLeftOut(mark) : formatRulesChanged(held)];
|
|
2635
|
+
const ruled = held === mark ? [] : [formatRules(rules, language), ""];
|
|
2636
|
+
const page = await taskPage(session, taken.number);
|
|
2637
|
+
return {
|
|
2638
|
+
value: { run, task: taken, comments: comments.items, rules: { ...rules, mark } },
|
|
2639
|
+
words: () => [
|
|
2640
|
+
`Run ${run.id} began on #${found.number} ${found.title}, as "${run.agent}" for ${calledOf(run.person)}. The task is in progress and theirs.${tookOver}${elsewhere}`,
|
|
2641
|
+
// The ids on a line of their own, each named: a run's and a task's begin alike, and a
|
|
2642
|
+
// task has a number for people as well.
|
|
2643
|
+
`run id: ${run.id} task id: ${found.id} (task #${found.number})`,
|
|
2644
|
+
...answered,
|
|
2645
|
+
"",
|
|
2646
|
+
formatTask(taken, undefined, undefined, comments.items, page),
|
|
2647
|
+
"",
|
|
2648
|
+
...ruled,
|
|
2649
|
+
'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
|
|
2650
|
+
'Ask when a person must decide: console ask "<question>" --option "..." --option "...". A word for the task\'s people that is not a report: console comment <number> "<markdown>". End with: console finish --summary "<what was done, what is left>".',
|
|
2651
|
+
].join("\n"),
|
|
2652
|
+
};
|
|
2653
|
+
}
|
|
2654
|
+
const take = async (args, io) => {
|
|
2655
|
+
const { values, positionals } = parse(args, {
|
|
2656
|
+
agent: { type: "string" },
|
|
2657
|
+
rules: { type: "string" },
|
|
2658
|
+
});
|
|
2659
|
+
const ref = theOne(positionals, "Say which task: console take <number|id> [--rules <mark>]");
|
|
2660
|
+
const session = await open(io, values);
|
|
2661
|
+
const project = await session.project();
|
|
2662
|
+
const found = await project.task(ref);
|
|
2663
|
+
const run = await runOn(project, found, values);
|
|
2664
|
+
const took = await taking(session, project, found, ref, run, values);
|
|
2665
|
+
answer(io, session, took.value, took.words);
|
|
1917
2666
|
return EXIT.ok;
|
|
1918
2667
|
};
|
|
1919
2668
|
const report = async (args, io) => {
|
|
@@ -1930,7 +2679,7 @@ const report = async (args, io) => {
|
|
|
1930
2679
|
}
|
|
1931
2680
|
const session = await open(io, values);
|
|
1932
2681
|
const project = await session.project();
|
|
1933
|
-
const runId = await currentRun(project, values);
|
|
2682
|
+
const runId = await currentRun(session, project, values);
|
|
1934
2683
|
const run = await project.report(runId, { body });
|
|
1935
2684
|
answer(io, session, run, () => `Reported on run ${run.id}: ${run.reports.length} report${run.reports.length === 1 ? "" : "s"} so far.`);
|
|
1936
2685
|
return EXIT.ok;
|
|
@@ -1964,7 +2713,7 @@ const handIn = async (args, io) => {
|
|
|
1964
2713
|
const label = text(values, "label");
|
|
1965
2714
|
const session = await open(io, values);
|
|
1966
2715
|
const project = await session.project();
|
|
1967
|
-
const runId = await currentRun(project, values);
|
|
2716
|
+
const runId = await currentRun(session, project, values);
|
|
1968
2717
|
// A URL is handed in as a link, and the console says whether it takes it; anything else
|
|
1969
2718
|
// names a file on this machine.
|
|
1970
2719
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(what)) {
|
|
@@ -2021,7 +2770,7 @@ const ask = async (args, io) => {
|
|
|
2021
2770
|
const files = await attachmentsOf(io, texts(values, "attach"));
|
|
2022
2771
|
const session = await open(io, values);
|
|
2023
2772
|
const project = await session.project();
|
|
2024
|
-
const runId = await currentRun(project, values);
|
|
2773
|
+
const runId = await currentRun(session, project, values);
|
|
2025
2774
|
// Whom the decision is for (ADR-0042, ADR-0057): the person the agent works for, unless --to
|
|
2026
2775
|
// names others of the project, each once; several, and any of them may answer.
|
|
2027
2776
|
const deciderIds = [];
|
|
@@ -2043,11 +2792,25 @@ const ask = async (args, io) => {
|
|
|
2043
2792
|
: { deciderId: deciderIds[0], deciderIds }),
|
|
2044
2793
|
}, files);
|
|
2045
2794
|
const withFiles = files.length === 0 ? "" : `, with ${files.length} file${files.length === 1 ? "" : "s"}`;
|
|
2046
|
-
// The id is printed before any waiting, so that a wait cut short loses nothing
|
|
2795
|
+
// The id is printed before any waiting, so that a wait cut short loses nothing; and the
|
|
2796
|
+
// address of its page, which is what a person told of the decision is given to open.
|
|
2047
2797
|
io.stdout(session.json
|
|
2048
2798
|
? `${JSON.stringify(raised, null, 2)}\n`
|
|
2049
|
-
: `Decision ${raised.id} raised on run ${runId}${withFiles}; the run waits for ${deciderLogins(raised)}.\ndecision id: ${raised.id}\n${formatOptions(raised)}\n`);
|
|
2050
|
-
|
|
2799
|
+
: `Decision ${raised.id} raised on run ${runId}${withFiles}; the run waits for ${deciderLogins(raised)}.\ndecision id: ${raised.id}\n${pageLine(await decisionPage(session, raised.id))}\n${formatOptions(raised)}\n`);
|
|
2800
|
+
// An agent account is attended by nobody, and the answer wakes it (ADR-0085): it waits at no
|
|
2801
|
+
// terminal unless it asked to, and is told to go on with other work, where an attended
|
|
2802
|
+
// agent is told how to keep waiting. A wait it asked for that runs out ends in the same
|
|
2803
|
+
// words: waiting on is not what it is told to do then either.
|
|
2804
|
+
const wakes = raised.raisedBy.kind === "agent"
|
|
2805
|
+
? `The answer wakes you: go on with other work meanwhile, and with this run when it comes (--run ${runId}). The run stays open while the decision waits.`
|
|
2806
|
+
: undefined;
|
|
2807
|
+
if (wakes !== undefined && text(values, "wait") === undefined) {
|
|
2808
|
+
if (!session.json) {
|
|
2809
|
+
io.stdout(`${wakes}\n`);
|
|
2810
|
+
}
|
|
2811
|
+
return EXIT.waiting;
|
|
2812
|
+
}
|
|
2813
|
+
return settle(io, session, project, raised, seconds, true, wakes);
|
|
2051
2814
|
};
|
|
2052
2815
|
/**
|
|
2053
2816
|
* Writes a person's answer on a decision, in their name through the agent (ADR-0021): the
|
|
@@ -2073,7 +2836,8 @@ const answering = async (args, io) => {
|
|
|
2073
2836
|
...(own === undefined ? { option } : { own }),
|
|
2074
2837
|
...(note === undefined ? {} : { note }),
|
|
2075
2838
|
});
|
|
2076
|
-
|
|
2839
|
+
const page = await decisionPage(session, answered.id, atItsAddress);
|
|
2840
|
+
answer(io, session, answered, () => formatDecision(answered, { atItsAddress, page }));
|
|
2077
2841
|
return EXIT.ok;
|
|
2078
2842
|
};
|
|
2079
2843
|
/** Whether a refusal says the decision is not in the project the command works in, or the project is not the person's. */
|
|
@@ -2116,6 +2880,27 @@ async function reachDecision(session, id) {
|
|
|
2116
2880
|
throw error;
|
|
2117
2881
|
}
|
|
2118
2882
|
}
|
|
2883
|
+
/**
|
|
2884
|
+
* The project a write on a decision goes to: the one the command works in; where none is named,
|
|
2885
|
+
* the decision's own, as the console says it of the decision wherever it is (ADR-0068). A desk
|
|
2886
|
+
* names no project, and the wake that brings an answer names the decision alone: what followed
|
|
2887
|
+
* is written from there as the decision was read from there. With a project named nothing is
|
|
2888
|
+
* looked up, and the console answers for that project as before.
|
|
2889
|
+
*/
|
|
2890
|
+
async function projectOfDecision(session, id) {
|
|
2891
|
+
if ((await session.projectKey()) !== undefined) {
|
|
2892
|
+
return session.project();
|
|
2893
|
+
}
|
|
2894
|
+
try {
|
|
2895
|
+
return session.client.project((await session.client.decision(id)).project.key);
|
|
2896
|
+
}
|
|
2897
|
+
catch (error) {
|
|
2898
|
+
if (error instanceof ApiError && error.status === 404) {
|
|
2899
|
+
throw new ApiError(404, "decision.not_found", "The decision was not found.");
|
|
2900
|
+
}
|
|
2901
|
+
throw error;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2119
2904
|
/** Writes an answer on a decision as the command reaches it (ADR-0068): in the project, else wherever it is. */
|
|
2120
2905
|
async function answerReached(session, id, input) {
|
|
2121
2906
|
if ((await session.projectKey()) !== undefined) {
|
|
@@ -2146,24 +2931,61 @@ const decision = async (args, io) => {
|
|
|
2146
2931
|
wait: { type: "string" },
|
|
2147
2932
|
outcome: { type: "string" },
|
|
2148
2933
|
file: { type: "string" },
|
|
2934
|
+
to: { type: "string", multiple: true },
|
|
2149
2935
|
});
|
|
2150
|
-
const id = theOne(positionals, "Say which decision: console decision <id> [--wait <seconds>] [--outcome <markdown>|--file <path>]");
|
|
2936
|
+
const id = theOne(positionals, "Say which decision: console decision <id> [--wait <seconds>] [--outcome <markdown>|--file <path>] [--to <login|me>]...");
|
|
2151
2937
|
const seconds = secondsOf(text(values, "wait"), 0);
|
|
2938
|
+
const tos = texts(values, "to");
|
|
2939
|
+
if (tos.includes("none")) {
|
|
2940
|
+
throw misuse("Say whom the decision is for: --to <login|me>, given again for several.");
|
|
2941
|
+
}
|
|
2942
|
+
if (tos.length > MAX_DECIDERS) {
|
|
2943
|
+
throw misuse(`Name up to ${MAX_DECIDERS} people with --to.`);
|
|
2944
|
+
}
|
|
2152
2945
|
const outcome = await bodyOf(io, values, text(values, "outcome"));
|
|
2946
|
+
if (tos.length > 0 && outcome !== undefined) {
|
|
2947
|
+
throw misuse("Say one thing at a time: whom the decision is for (--to), or what followed it.");
|
|
2948
|
+
}
|
|
2153
2949
|
const session = await open(io, values);
|
|
2950
|
+
if (tos.length > 0) {
|
|
2951
|
+
// Whom a decision that waits is for, said anew (ADR-0096): the people named take the place
|
|
2952
|
+
// of those it was for, each once in the order named.
|
|
2953
|
+
const project = await projectOfDecision(session, id);
|
|
2954
|
+
const deciderIds = [];
|
|
2955
|
+
for (const to of tos) {
|
|
2956
|
+
const named = await personIdOf(session, to);
|
|
2957
|
+
if (typeof named === "string" && !deciderIds.includes(named)) {
|
|
2958
|
+
deciderIds.push(named);
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
const addressed = await project.addressDecision(id, deciderIds);
|
|
2962
|
+
const page = await decisionPage(session, addressed.id);
|
|
2963
|
+
answer(io, session, addressed, () => formatDecision(addressed, { page }));
|
|
2964
|
+
return EXIT.ok;
|
|
2965
|
+
}
|
|
2154
2966
|
if (outcome !== undefined) {
|
|
2155
2967
|
// What followed the decision: the record grows, and is printed as it stands.
|
|
2156
|
-
const project = await session
|
|
2968
|
+
const project = await projectOfDecision(session, id);
|
|
2157
2969
|
const grown = await project.updateDecision(id, { outcome });
|
|
2158
|
-
|
|
2970
|
+
const page = await decisionPage(session, grown.id);
|
|
2971
|
+
answer(io, session, grown, () => formatDecision(grown, { page }));
|
|
2159
2972
|
return EXIT.ok;
|
|
2160
2973
|
}
|
|
2161
2974
|
const { decision: found, waiter, atItsAddress } = await reachDecision(session, id);
|
|
2162
2975
|
if (seconds === 0) {
|
|
2163
|
-
|
|
2976
|
+
const page = await decisionPage(session, found.id, atItsAddress);
|
|
2977
|
+
answer(io, session, found, () => formatDecision(found, { atItsAddress, page }));
|
|
2164
2978
|
return EXIT.ok;
|
|
2165
2979
|
}
|
|
2166
|
-
|
|
2980
|
+
// An agent account is attended by nobody, and the answer to a decision it raised wakes it
|
|
2981
|
+
// (ADR-0085): a wait of its own that runs out ends in the account's words, as ask's does, and
|
|
2982
|
+
// not in how an attended agent waits on. Whether the command is the account is what the
|
|
2983
|
+
// login kept says (`login --self`), since the decision alone does not: a person's agent may
|
|
2984
|
+
// wait for a decision an account raised, and is told how to keep waiting.
|
|
2985
|
+
const wakes = signedInAsItself(session) && found.raisedBy.login === session.account
|
|
2986
|
+
? `Decision ${found.id} still waits for a person. The answer wakes you: go on with other work meanwhile, and with its run when it comes${found.run === null ? "" : ` (--run ${found.run.id})`}. The run stays open while the decision waits.`
|
|
2987
|
+
: undefined;
|
|
2988
|
+
return settle(io, session, waiter, found, seconds, false, wakes);
|
|
2167
2989
|
};
|
|
2168
2990
|
const docs = async (args, io) => {
|
|
2169
2991
|
const { values, positionals } = parse(args, {
|
|
@@ -2176,8 +2998,10 @@ const docs = async (args, io) => {
|
|
|
2176
2998
|
const search = text(values, "search");
|
|
2177
2999
|
const session = await open(io, values);
|
|
2178
3000
|
const project = await session.project();
|
|
3001
|
+
// A folder is taken as the listing prints it, `guides/`, and as it is named, `guides`.
|
|
3002
|
+
const folder = positionals[0]?.replace(/\/+$/, "");
|
|
2179
3003
|
const found = await project.documents({
|
|
2180
|
-
...(
|
|
3004
|
+
...(folder === undefined || folder === "" ? {} : { folder }),
|
|
2181
3005
|
...(search === undefined ? {} : { q: search }),
|
|
2182
3006
|
...(on(values, "archived") ? { archived: true } : {}),
|
|
2183
3007
|
});
|
|
@@ -2248,7 +3072,10 @@ const write = async (args, io) => {
|
|
|
2248
3072
|
body,
|
|
2249
3073
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
2250
3074
|
});
|
|
2251
|
-
|
|
3075
|
+
// The page's address, as a task's and a decision's: what an agent tells a person and hands in.
|
|
3076
|
+
const key = await session.projectKey();
|
|
3077
|
+
const page = key === undefined ? undefined : `${session.url}${docHref(key, written.path)}`;
|
|
3078
|
+
answer(io, session, written, () => `Wrote ${written.path} (${written.title}), version ${written.version}${written.links.length === 0 ? "" : `; refers to ${written.links.map((link) => link.path).join(", ")}`}${page === undefined ? "" : `\n${pageLine(page)}`}`);
|
|
2252
3079
|
return EXIT.ok;
|
|
2253
3080
|
};
|
|
2254
3081
|
const attach = async (args, io) => {
|
|
@@ -2397,7 +3224,9 @@ const goal = async (args, io) => {
|
|
|
2397
3224
|
const session = await open(io, values);
|
|
2398
3225
|
const project = await session.project();
|
|
2399
3226
|
const found = await project.goal(id);
|
|
2400
|
-
const towards =
|
|
3227
|
+
const towards = session.json
|
|
3228
|
+
? await project.tasks({ goal: found.id })
|
|
3229
|
+
: await project.taskBriefs({ goal: found.id });
|
|
2401
3230
|
answer(io, session, { goal: found, tasks: towards.items }, () => formatGoal(found, towards.items));
|
|
2402
3231
|
return EXIT.ok;
|
|
2403
3232
|
};
|
|
@@ -2433,19 +3262,40 @@ const decisions = async (args, io) => {
|
|
|
2433
3262
|
formatMore(found.more, page.limit, page.offset));
|
|
2434
3263
|
return EXIT.ok;
|
|
2435
3264
|
};
|
|
3265
|
+
/**
|
|
3266
|
+
* Says how a run ended, and where that left its task (ADR-0114). The console places the task,
|
|
3267
|
+
* and where is not the command's to know: a finished run leaves it at work where another run is
|
|
3268
|
+
* open on it, and a run that failed or was given up does that too, and on a console of before
|
|
3269
|
+
* 0.5.1 always, or where a person moved it meanwhile. So the task is read once the run is over, and its state said as it stands. On
|
|
3270
|
+
* `--json` the answer is the run as the console gave it, and nothing more is asked.
|
|
3271
|
+
*/
|
|
3272
|
+
async function sayEnded(io, session, project, run, status) {
|
|
3273
|
+
let words = "";
|
|
3274
|
+
if (!session.json) {
|
|
3275
|
+
try {
|
|
3276
|
+
const task = await project.task(run.taskId);
|
|
3277
|
+
words = `Run ${run.id} ${status}; task #${task.number} is ${task.state} now.`;
|
|
3278
|
+
}
|
|
3279
|
+
catch (error) {
|
|
3280
|
+
// Said before the console's own words for what failed, which follow as on any command:
|
|
3281
|
+
// the run is over whatever became of the reading, and is not to be ended again.
|
|
3282
|
+
io.stderr(`Run ${run.id} ${status}, and where that left task #${run.taskNumber} was not read. The run is over: do not end it again. console task ${run.taskNumber} shows the task. What the reading ended on:\n`);
|
|
3283
|
+
throw error;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
answer(io, session, run, () => words);
|
|
3287
|
+
}
|
|
2436
3288
|
const ending = (status) => async (args, io) => {
|
|
2437
3289
|
const { values } = parse(args, { summary: { type: "string" }, file: { type: "string" }, run: { type: "string" } }, false);
|
|
2438
3290
|
const summary = await bodyOf(io, values, text(values, "summary"));
|
|
2439
3291
|
const session = await open(io, values);
|
|
2440
3292
|
const project = await session.project();
|
|
2441
|
-
const runId = await currentRun(project, values);
|
|
3293
|
+
const runId = await currentRun(session, project, values);
|
|
2442
3294
|
const run = await project.endRun(runId, {
|
|
2443
3295
|
status,
|
|
2444
3296
|
...(summary === undefined ? {} : { summary }),
|
|
2445
3297
|
});
|
|
2446
|
-
|
|
2447
|
-
? `Run ${run.id} finished; the task is up for review.`
|
|
2448
|
-
: `Run ${run.id} failed; the task stays as it is.`);
|
|
3298
|
+
await sayEnded(io, session, project, run, status);
|
|
2449
3299
|
return EXIT.ok;
|
|
2450
3300
|
};
|
|
2451
3301
|
const abandon = async (args, io) => {
|
|
@@ -2460,12 +3310,12 @@ const abandon = async (args, io) => {
|
|
|
2460
3310
|
const summary = await bodyOf(io, values, text(values, "summary"));
|
|
2461
3311
|
const session = await open(io, values);
|
|
2462
3312
|
const project = await session.project();
|
|
2463
|
-
const runId = positionals[0] ?? (await currentRun(project, values));
|
|
3313
|
+
const runId = positionals[0] ?? (await currentRun(session, project, values));
|
|
2464
3314
|
const run = await project.endRun(runId, {
|
|
2465
3315
|
status: "abandoned",
|
|
2466
3316
|
...(summary === undefined ? {} : { summary }),
|
|
2467
3317
|
});
|
|
2468
|
-
|
|
3318
|
+
await sayEnded(io, session, project, run, "abandoned");
|
|
2469
3319
|
return EXIT.ok;
|
|
2470
3320
|
};
|
|
2471
3321
|
const runs = async (args, io) => {
|
|
@@ -2480,17 +3330,46 @@ const runs = async (args, io) => {
|
|
|
2480
3330
|
const project = await session.project();
|
|
2481
3331
|
const ref = text(values, "task");
|
|
2482
3332
|
const taskId = ref === undefined ? undefined : (await project.task(ref)).id;
|
|
2483
|
-
const
|
|
3333
|
+
const mine = on(values, "mine");
|
|
3334
|
+
const filter = {
|
|
2484
3335
|
...(taskId === undefined ? {} : { task: taskId }),
|
|
2485
3336
|
...(on(values, "open") ? { open: true } : {}),
|
|
2486
|
-
...(
|
|
3337
|
+
...(mine ? { mine: true } : {}),
|
|
2487
3338
|
...page,
|
|
3339
|
+
};
|
|
3340
|
+
const [found, agent] = await Promise.all([
|
|
3341
|
+
// A line a run, its reports counted: the brief form, unless --json asks for the console's own.
|
|
3342
|
+
session.json ? project.runs(filter) : project.runBriefs(filter),
|
|
3343
|
+
// With a token, --mine is the runs begun with that token, one agent's, and a person may
|
|
3344
|
+
// have more: an empty listing would read as if they had none, so whose these are is said.
|
|
3345
|
+
mine && !session.json ? tokenNameOf(session) : undefined,
|
|
3346
|
+
]);
|
|
3347
|
+
const others = "A run of yours begun through another agent, or before a new sign-in, is listed without --mine, where each line says whom it is for and through which agent.";
|
|
3348
|
+
answer(io, session, found, () => {
|
|
3349
|
+
if (found.items.length === 0) {
|
|
3350
|
+
return agent === undefined
|
|
3351
|
+
? "No runs."
|
|
3352
|
+
: `No runs begun through this agent (${agent}). ${others}`;
|
|
3353
|
+
}
|
|
3354
|
+
const listed = found.items.map(formatRunLine).join("\n") + formatMore(found.more, page.limit, page.offset);
|
|
3355
|
+
return agent === undefined
|
|
3356
|
+
? listed
|
|
3357
|
+
: `${listed}\nThese are the runs begun through this agent (${agent}). ${others}`;
|
|
2488
3358
|
});
|
|
2489
|
-
answer(io, session, found, () => found.items.length === 0
|
|
2490
|
-
? "No runs."
|
|
2491
|
-
: found.items.map(formatRunLine).join("\n") + formatMore(found.more, page.limit, page.offset));
|
|
2492
3359
|
return EXIT.ok;
|
|
2493
3360
|
};
|
|
3361
|
+
/** What the token the command acts with is called, or nothing where it acts on a session or cannot be asked. */
|
|
3362
|
+
async function tokenNameOf(session) {
|
|
3363
|
+
try {
|
|
3364
|
+
return (await session.client.me()).agent ?? undefined;
|
|
3365
|
+
}
|
|
3366
|
+
catch (error) {
|
|
3367
|
+
if (error instanceof ApiError) {
|
|
3368
|
+
return undefined;
|
|
3369
|
+
}
|
|
3370
|
+
throw error;
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
2494
3373
|
const run = async (args, io) => {
|
|
2495
3374
|
const { values, positionals } = parse(args, {});
|
|
2496
3375
|
const id = theOne(positionals, "Say which run: console run <id>");
|
|
@@ -2513,12 +3392,16 @@ function portOf(value) {
|
|
|
2513
3392
|
}
|
|
2514
3393
|
/**
|
|
2515
3394
|
* A console of the person's own, served from this machine (ADR-0014): the build's pages here,
|
|
2516
|
-
* and everything under /api/ carried to the console with the token, which the pages never see
|
|
3395
|
+
* and everything under /api/ carried to the console with the token, which the pages never see;
|
|
3396
|
+
* and, with --records, what a desk keeps under /records/ (ADR-0117), for the desk's pages.
|
|
2517
3397
|
*/
|
|
2518
3398
|
const serve = async (args, io) => {
|
|
2519
|
-
const { values, positionals } = parse(args, {
|
|
3399
|
+
const { values, positionals } = parse(args, {
|
|
3400
|
+
port: { type: "string" },
|
|
3401
|
+
records: { type: "string" },
|
|
3402
|
+
});
|
|
2520
3403
|
if (positionals.length > 1) {
|
|
2521
|
-
throw misuse("Say at most one directory: console serve [<dir>] [--port <n>]");
|
|
3404
|
+
throw misuse("Say at most one directory: console serve [<dir>] [--port <n>] [--records <dir>]");
|
|
2522
3405
|
}
|
|
2523
3406
|
const [dir] = positionals;
|
|
2524
3407
|
const port = portOf(text(values, "port"));
|
|
@@ -2544,19 +3427,207 @@ const serve = async (args, io) => {
|
|
|
2544
3427
|
throw error;
|
|
2545
3428
|
}
|
|
2546
3429
|
}
|
|
3430
|
+
const kept = text(values, "records");
|
|
3431
|
+
let records;
|
|
3432
|
+
if (kept !== undefined) {
|
|
3433
|
+
try {
|
|
3434
|
+
records = await loadRecordsRoot(kept);
|
|
3435
|
+
}
|
|
3436
|
+
catch (error) {
|
|
3437
|
+
if (error instanceof RecordsRootError) {
|
|
3438
|
+
throw failed(`No records to serve: ${error.message}. Name the records/ of a desk: console serve <dir> --records <desk>/records`);
|
|
3439
|
+
}
|
|
3440
|
+
throw error;
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
2547
3443
|
const listening = await listen((bound) => createServeHandler({
|
|
2548
3444
|
upstream: session.url,
|
|
2549
3445
|
token: session.token,
|
|
2550
3446
|
fetch: io.fetch,
|
|
2551
3447
|
port: bound,
|
|
2552
3448
|
web,
|
|
3449
|
+
records,
|
|
2553
3450
|
}), port);
|
|
3451
|
+
// A desk has its records/ once it keeps something (ADR-0122): until then the line says that
|
|
3452
|
+
// nothing is kept there, and that what comes to be is served with no restart.
|
|
3453
|
+
const served = kept === undefined || records === undefined
|
|
3454
|
+
? ""
|
|
3455
|
+
: (await records.there())
|
|
3456
|
+
? ` The records in ${kept} are at ${listening.url}records/, read as they are when they are asked for.`
|
|
3457
|
+
: ` Nothing is kept in ${kept} yet: what comes to be kept there is at ${listening.url}records/ from then on, with no restart.`;
|
|
2554
3458
|
io.stdout(web === undefined
|
|
2555
|
-
? `Serving the API of ${me.workspace.name} (${session.url}) at ${listening.url}api/ as ${person.login}, for a development server to send its /api/ requests to
|
|
2556
|
-
: `Serving ${dir} at ${listening.url} as ${person.login}: the pages are there, and everything under /api/ goes to ${me.workspace.name} (${session.url}) with your token, which the pages never see
|
|
3459
|
+
? `Serving the API of ${me.workspace.name} (${session.url}) at ${listening.url}api/ as ${person.login}, for a development server to send its /api/ requests to.${served} Stop with Ctrl+C.\n`
|
|
3460
|
+
: `Serving ${dir} at ${listening.url} as ${person.login}: the pages are there, and everything under /api/ goes to ${me.workspace.name} (${session.url}) with your token, which the pages never see.${served} Stop with Ctrl+C.\n`);
|
|
2557
3461
|
await listening.closed;
|
|
2558
3462
|
return EXIT.ok;
|
|
2559
3463
|
};
|
|
3464
|
+
/** What the runner keeps between its own restarts, as its file says it; nothing for a file that does not read. */
|
|
3465
|
+
function runnerStateOf(text) {
|
|
3466
|
+
if (text === undefined) {
|
|
3467
|
+
return undefined;
|
|
3468
|
+
}
|
|
3469
|
+
let json;
|
|
3470
|
+
try {
|
|
3471
|
+
json = JSON.parse(text);
|
|
3472
|
+
}
|
|
3473
|
+
catch {
|
|
3474
|
+
return undefined;
|
|
3475
|
+
}
|
|
3476
|
+
if (typeof json !== "object" || json === null) {
|
|
3477
|
+
return undefined;
|
|
3478
|
+
}
|
|
3479
|
+
const delivered = "delivered" in json ? json.delivered : undefined;
|
|
3480
|
+
const conversation = "conversation" in json ? json.conversation : undefined;
|
|
3481
|
+
const driver = "driver" in json ? json.driver : undefined;
|
|
3482
|
+
if (typeof delivered !== "number" || !Number.isSafeInteger(delivered) || delivered < 0) {
|
|
3483
|
+
return undefined;
|
|
3484
|
+
}
|
|
3485
|
+
return {
|
|
3486
|
+
delivered,
|
|
3487
|
+
conversation: typeof conversation === "string" && conversation.length > 0 && conversation.length <= 200
|
|
3488
|
+
? conversation
|
|
3489
|
+
: undefined,
|
|
3490
|
+
// The driver the conversation was begun under, as a registry spells one.
|
|
3491
|
+
driver: typeof driver === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(driver) ? driver : undefined,
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
/** A line a runner says of its machine, within what the console takes one in. */
|
|
3495
|
+
const machineLine = (text) => {
|
|
3496
|
+
const line = [...text]
|
|
3497
|
+
.map((character) => {
|
|
3498
|
+
const code = character.codePointAt(0) ?? 0;
|
|
3499
|
+
return code < 0x20 || code === 0x7f ? " " : character;
|
|
3500
|
+
})
|
|
3501
|
+
.join("")
|
|
3502
|
+
.trim()
|
|
3503
|
+
.slice(0, MAX_RUNNER_LINE_LENGTH);
|
|
3504
|
+
return line.length === 0 ? "unknown" : line;
|
|
3505
|
+
};
|
|
3506
|
+
// The runner of an agent account (ADR-0085, docs/specs/runner.md): started in the account's
|
|
3507
|
+
// desk, on the command signed in as the account itself. It keeps the agent's session going,
|
|
3508
|
+
// feeds it what the console sends and reports what it does, until it is stopped.
|
|
3509
|
+
const runner = async (args, io) => {
|
|
3510
|
+
const { values, positionals } = parse(args, {});
|
|
3511
|
+
if (positionals.length > 0) {
|
|
3512
|
+
throw misuse("console runner takes nothing: it is started in the agent's desk.");
|
|
3513
|
+
}
|
|
3514
|
+
const host = io.runner;
|
|
3515
|
+
if (host === undefined) {
|
|
3516
|
+
throw failed("A runner cannot be started here.");
|
|
3517
|
+
}
|
|
3518
|
+
const session = await open(io, values);
|
|
3519
|
+
const me = await session.client.me();
|
|
3520
|
+
if (me.person === null) {
|
|
3521
|
+
throw failed("The console does not know this sign-in. Sign in again: console login --self");
|
|
3522
|
+
}
|
|
3523
|
+
if (me.person.kind !== "agent" || me.session?.kind !== "command") {
|
|
3524
|
+
throw failed("A runner is an agent account's own, on the command signed in as the account itself: console login --self, approved in a browser signed in as the account.");
|
|
3525
|
+
}
|
|
3526
|
+
const written = await host.readText("runner.json");
|
|
3527
|
+
const read = written === undefined
|
|
3528
|
+
? { ok: true, config: DEFAULT_RUNNER_CONFIG }
|
|
3529
|
+
: parseRunnerConfig(written);
|
|
3530
|
+
if (!read.ok) {
|
|
3531
|
+
throw failed(`${read.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`);
|
|
3532
|
+
}
|
|
3533
|
+
const modules = ownRunnerModules({ user: host.user });
|
|
3534
|
+
const driverOf = modules.drivers.get(read.config.driver);
|
|
3535
|
+
if (driverOf === undefined) {
|
|
3536
|
+
throw failed(`runner.json names the driver ${read.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}.`);
|
|
3537
|
+
}
|
|
3538
|
+
const unknown = read.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
|
|
3539
|
+
if (unknown !== undefined) {
|
|
3540
|
+
throw failed(`runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}.`);
|
|
3541
|
+
}
|
|
3542
|
+
// A header says the hour and the minute in the workspace's zone, or the machine's where it has none.
|
|
3543
|
+
const zone = me.workspace.timeZone ?? undefined;
|
|
3544
|
+
let clock;
|
|
3545
|
+
try {
|
|
3546
|
+
clock = new Intl.DateTimeFormat("en-GB", {
|
|
3547
|
+
hour: "2-digit",
|
|
3548
|
+
minute: "2-digit",
|
|
3549
|
+
hourCycle: "h23",
|
|
3550
|
+
...(zone === undefined ? {} : { timeZone: zone }),
|
|
3551
|
+
});
|
|
3552
|
+
}
|
|
3553
|
+
catch {
|
|
3554
|
+
clock = new Intl.DateTimeFormat("en-GB", {
|
|
3555
|
+
hour: "2-digit",
|
|
3556
|
+
minute: "2-digit",
|
|
3557
|
+
hourCycle: "h23",
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
const statePath = workPath("runner-state.json");
|
|
3561
|
+
const running = createRunner({
|
|
3562
|
+
client: session.client,
|
|
3563
|
+
driver: driverOf({
|
|
3564
|
+
spawn: host.spawn,
|
|
3565
|
+
cwd: host.cwd,
|
|
3566
|
+
command: read.config.product?.command,
|
|
3567
|
+
args: read.config.product?.args,
|
|
3568
|
+
version: io.version,
|
|
3569
|
+
}),
|
|
3570
|
+
config: read.config,
|
|
3571
|
+
cwd: host.cwd,
|
|
3572
|
+
machine: {
|
|
3573
|
+
name: machineLine(io.hostname ?? ""),
|
|
3574
|
+
os: machineLine(host.os),
|
|
3575
|
+
user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
|
|
3576
|
+
},
|
|
3577
|
+
version: io.version ?? "0.0.0",
|
|
3578
|
+
// A runner whose own version is not known has nothing to hold the package's against.
|
|
3579
|
+
installed: io.version === undefined ? undefined : io.installedVersion,
|
|
3580
|
+
// What installs the console's version here, the way this command was installed.
|
|
3581
|
+
updateCommand: () => updateWords(io, io.consoleVersion?.()),
|
|
3582
|
+
now: io.now,
|
|
3583
|
+
random: host.random,
|
|
3584
|
+
time: (iso) => clock.format(new Date(iso)),
|
|
3585
|
+
files: {
|
|
3586
|
+
write: (path, text) => host.writePrivate(workPath(path), text),
|
|
3587
|
+
remove: (path) => host.remove(workPath(path)),
|
|
3588
|
+
},
|
|
3589
|
+
state: {
|
|
3590
|
+
load: async () => runnerStateOf(await host.readText(statePath)),
|
|
3591
|
+
save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
|
|
3592
|
+
},
|
|
3593
|
+
log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
|
|
3594
|
+
// The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
|
|
3595
|
+
// A step that reaches the git host is handed the account's token for it, as the clone of
|
|
3596
|
+
// the desk was: answered from the environment of that one command, and only to the host
|
|
3597
|
+
// the workspace keeps its desks at.
|
|
3598
|
+
git: async (args, handed) => {
|
|
3599
|
+
const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
|
|
3600
|
+
const child = host.spawn("git", args, {
|
|
3601
|
+
cwd: host.cwd,
|
|
3602
|
+
env: handed?.token === undefined || origin === undefined
|
|
3603
|
+
? { GIT_TERMINAL_PROMPT: "0" }
|
|
3604
|
+
: gitTokenEnv(handed.token, origin),
|
|
3605
|
+
});
|
|
3606
|
+
child.end();
|
|
3607
|
+
for await (const _ of child.lines) {
|
|
3608
|
+
// Nothing of what git prints is kept.
|
|
3609
|
+
}
|
|
3610
|
+
return (await child.exited).code;
|
|
3611
|
+
},
|
|
3612
|
+
// The wake sources the desk names beside the console's own stream, which the runner listens to itself.
|
|
3613
|
+
wakes: {
|
|
3614
|
+
sources: read.config.wake.flatMap((name) => {
|
|
3615
|
+
const source = modules.wakeSources.get(name);
|
|
3616
|
+
return source === undefined || source.run === undefined ? [] : [source];
|
|
3617
|
+
}),
|
|
3618
|
+
fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
|
|
3619
|
+
socket: (url) => host.socket(url),
|
|
3620
|
+
},
|
|
3621
|
+
});
|
|
3622
|
+
io.stdout(`The runner of @${me.person.handle ?? me.person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`);
|
|
3623
|
+
void host.untilStopped().then(() => running.stop());
|
|
3624
|
+
if ((await running.run()) === "updated") {
|
|
3625
|
+
// The service that keeps a runner starts it again whenever it ends; one started by hand is
|
|
3626
|
+
// started again by hand.
|
|
3627
|
+
io.stdout("The command was updated: the runner ended, and the service that keeps it starts it again with the new one. Started by hand: console runner\n");
|
|
3628
|
+
}
|
|
3629
|
+
return EXIT.ok;
|
|
3630
|
+
};
|
|
2560
3631
|
// Configuring, as the person (ADR-0021): what an administrator or an owner does on the pages,
|
|
2561
3632
|
// their agent does here, attributed to them as the agent. The console decides on every request
|
|
2562
3633
|
// with the same roles; what the person may not, the agent may not (auth.forbidden). The tokens
|
|
@@ -2565,7 +3636,7 @@ const people = async (args, io) => {
|
|
|
2565
3636
|
const { values } = parse(args, {}, false);
|
|
2566
3637
|
const session = await open(io, values);
|
|
2567
3638
|
const found = await session.client.people();
|
|
2568
|
-
const loginOf = new Map(found.items.map((person) => [person.id, person
|
|
3639
|
+
const loginOf = new Map(found.items.map((person) => [person.id, calledOf(person)]));
|
|
2569
3640
|
answer(io, session, found, () => [
|
|
2570
3641
|
...found.items.map((person) => formatPersonLine(person, person.managerId === null || person.managerId === undefined
|
|
2571
3642
|
? undefined
|
|
@@ -2574,12 +3645,998 @@ const people = async (args, io) => {
|
|
|
2574
3645
|
].join("\n"));
|
|
2575
3646
|
return EXIT.ok;
|
|
2576
3647
|
};
|
|
3648
|
+
// Whom whoever asks reports to (ADR-0084), for a person as for an agent account: whom to turn to
|
|
3649
|
+
// first where one does not know whom to ask, and the administrators where there is nobody.
|
|
3650
|
+
const manager = async (args, io) => {
|
|
3651
|
+
const { values } = parse(args, {}, false);
|
|
3652
|
+
const session = await open(io, values);
|
|
3653
|
+
const found = await session.client.manager();
|
|
3654
|
+
answer(io, session, found, () => {
|
|
3655
|
+
const lines = [];
|
|
3656
|
+
if (found.manager === null) {
|
|
3657
|
+
lines.push("You report to nobody.");
|
|
3658
|
+
}
|
|
3659
|
+
else {
|
|
3660
|
+
lines.push(`You report to: ${formatPersonLine(found.manager)}`);
|
|
3661
|
+
}
|
|
3662
|
+
// The administrators stand in where there is no manager, or the manager is out.
|
|
3663
|
+
if (found.manager === null || found.manager.status !== "active") {
|
|
3664
|
+
lines.push(found.administrators.length === 0
|
|
3665
|
+
? "No administrator is in."
|
|
3666
|
+
: "The administrators, who stand in:", ...found.administrators.map((person) => ` ${formatPersonLine(person)}`));
|
|
3667
|
+
}
|
|
3668
|
+
return lines.join("\n");
|
|
3669
|
+
});
|
|
3670
|
+
return EXIT.ok;
|
|
3671
|
+
};
|
|
3672
|
+
/** A handle as the command takes one: with the `@` people call it by, or without. */
|
|
3673
|
+
const handleOf = (word) => (word.startsWith("@") ? word.slice(1) : word);
|
|
3674
|
+
/** The agent accounts of the workspace (ADR-0084), by handle. */
|
|
3675
|
+
const agents = async (args, io) => {
|
|
3676
|
+
const { values } = parse(args, {}, false);
|
|
3677
|
+
const session = await open(io, values);
|
|
3678
|
+
const found = await session.client.agents();
|
|
3679
|
+
answer(io, session, found, () => found.items.length === 0
|
|
3680
|
+
? "No agent accounts that you see. An administrator makes one on the Agents page."
|
|
3681
|
+
: found.items.map(formatAgentLine).join("\n"));
|
|
3682
|
+
return EXIT.ok;
|
|
3683
|
+
};
|
|
3684
|
+
const AGENT_USAGE = 'Say what to do: console agent <handle> [--avatar <file>] | console agent new <handle> [--login <login>] [--project <key>] [--name "<name>"] [--title "<title>"] [--manager <login|me>] [--host gh|google] [--seed <seed>] [--convert]';
|
|
3685
|
+
// An administrator makes an agent account with flags, where the pages make one from a form
|
|
3686
|
+
// (ADR-0084): the member's row at once, its login let in. What is left out is proposed: the
|
|
3687
|
+
// name is the handle's, capitalized, and the console rolls the avatar from the seed, or from one
|
|
3688
|
+
// of its own.
|
|
3689
|
+
const agentNew = async (args, io) => {
|
|
3690
|
+
const { values, positionals } = parse(args, {
|
|
3691
|
+
login: { type: "string" },
|
|
3692
|
+
name: { type: "string" },
|
|
3693
|
+
title: { type: "string" },
|
|
3694
|
+
manager: { type: "string" },
|
|
3695
|
+
host: { type: "string" },
|
|
3696
|
+
seed: { type: "string" },
|
|
3697
|
+
convert: { type: "boolean" },
|
|
3698
|
+
});
|
|
3699
|
+
const handle = handleOf(theOne(positionals, AGENT_USAGE));
|
|
3700
|
+
const session = await open(io, values);
|
|
3701
|
+
// The account it signs in with: said, or what the workspace's identity service makes of the
|
|
3702
|
+
// two handles and the domain (ADR-0089).
|
|
3703
|
+
// A console that does not say its workspace's services names no login: one is asked for.
|
|
3704
|
+
const asked = text(values, "login") === undefined
|
|
3705
|
+
? await session.client.me().catch(() => undefined)
|
|
3706
|
+
: undefined;
|
|
3707
|
+
const derived = asked === undefined ? undefined : agentLoginOf(asked.workspace, handle);
|
|
3708
|
+
const login = text(values, "login") ?? derived?.login;
|
|
3709
|
+
if (login === undefined) {
|
|
3710
|
+
throw misuse(`Say the account it will sign in with: console agent new ${handle} --login <login> --project <key>`);
|
|
3711
|
+
}
|
|
3712
|
+
const chosen = text(values, "host");
|
|
3713
|
+
const host = chosen === undefined ? (derived?.host ?? hostOfLogin(login)) : providerOf(chosen);
|
|
3714
|
+
const project = await session.projectKey();
|
|
3715
|
+
if (project === undefined) {
|
|
3716
|
+
throw misuse(`Say the project it starts in: console agent new ${handle} --login ${login} --project <key>`);
|
|
3717
|
+
}
|
|
3718
|
+
const manager = text(values, "manager");
|
|
3719
|
+
const seed = text(values, "seed");
|
|
3720
|
+
const title = text(values, "title");
|
|
3721
|
+
const made = await session.client.createAgent({
|
|
3722
|
+
host,
|
|
3723
|
+
login,
|
|
3724
|
+
handle,
|
|
3725
|
+
name: text(values, "name") ?? `${handle.slice(0, 1).toUpperCase()}${handle.slice(1)}`,
|
|
3726
|
+
...(title === undefined ? {} : { title }),
|
|
3727
|
+
...(seed === undefined ? {} : { avatarSeed: seed }),
|
|
3728
|
+
...(manager === undefined || manager === "me"
|
|
3729
|
+
? {}
|
|
3730
|
+
: { managerId: (await personOf(session, manager)).id }),
|
|
3731
|
+
project,
|
|
3732
|
+
// A member who carries the login becomes the account only where that is said (ADR-0104).
|
|
3733
|
+
...(on(values, "convert") ? { convert: true } : {}),
|
|
3734
|
+
});
|
|
3735
|
+
answer(io, session, made, () => [
|
|
3736
|
+
formatAgentLine(made),
|
|
3737
|
+
made.person.invited === true
|
|
3738
|
+
? host === "gh"
|
|
3739
|
+
? // A login at a git host goes to whoever registers it: what the first sign-in is held
|
|
3740
|
+
// to is said (ADR-0126), and by a console older than the answer, the login alone.
|
|
3741
|
+
made.firstSignIn === "account"
|
|
3742
|
+
? `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: confirmed at the git host, so that account alone is let in as it, whatever it is called by then.`
|
|
3743
|
+
: made.firstSignIn === "member"
|
|
3744
|
+
? `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: not confirmed, since the organization at the git host has no member called so, or could not be asked. It is let in once it is a member there, and nobody else is under that login.`
|
|
3745
|
+
: `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: ${made.firstSignIn === "login" ? "not confirmed, since this console reads no organization at the git host. That" : "that"} account has to be the organization's own at the git host already, since until its first sign-in binds it here the console lets in whoever holds that login.`
|
|
3746
|
+
: `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: that account is made at the provider before its machine is set up, and its first sign-in with it binds it here.`
|
|
3747
|
+
: `${made.person.login} is an agent account from now on, with everything it did.`,
|
|
3748
|
+
...(made.onboarding === null || made.onboarding === undefined
|
|
3749
|
+
? []
|
|
3750
|
+
: [
|
|
3751
|
+
`Its first task is #${made.onboarding.number} in ${made.onboarding.project}, with what setting it up takes; its runner is woken with it when it first starts.`,
|
|
3752
|
+
]),
|
|
3753
|
+
`Next, a machine: console agent invite ${handle} makes the invitation that leads one to it.`,
|
|
3754
|
+
].join("\n"));
|
|
3755
|
+
return EXIT.ok;
|
|
3756
|
+
};
|
|
3757
|
+
/** A day a secret's value ends on, as the flag gives one: a calendar day, or `none`. */
|
|
3758
|
+
function expiryOf(io, values) {
|
|
3759
|
+
return dayOf(io, text(values, "expires"), true);
|
|
3760
|
+
}
|
|
3761
|
+
/**
|
|
3762
|
+
* The value of a secret being set: typed unseen at the terminal, or all of standard input where
|
|
3763
|
+
* that is a pipe, or a file's whole text with --file; never an argument, which a shell would
|
|
3764
|
+
* keep and a process list show.
|
|
3765
|
+
*/
|
|
3766
|
+
async function secretValue(io, values, prompt) {
|
|
3767
|
+
const file = text(values, "file");
|
|
3768
|
+
const value = file === undefined
|
|
3769
|
+
? await secretGiven(io, prompt)
|
|
3770
|
+
: (await io.readFile(file)).replace(/\r?\n$/, "");
|
|
3771
|
+
if (value.length === 0) {
|
|
3772
|
+
throw failed("No value was given.");
|
|
3773
|
+
}
|
|
3774
|
+
return value;
|
|
3775
|
+
}
|
|
3776
|
+
const SECRET_FLAGS = {
|
|
3777
|
+
set: { type: "boolean" },
|
|
3778
|
+
remove: { type: "boolean" },
|
|
3779
|
+
file: { type: "string" },
|
|
3780
|
+
expires: { type: "string" },
|
|
3781
|
+
};
|
|
3782
|
+
// An agent account's own secret store (ADR-0087): the names it keeps, for the account itself,
|
|
3783
|
+
// signed in as itself.
|
|
3784
|
+
const secrets = async (args, io) => {
|
|
3785
|
+
const { values } = parse(args, {}, false);
|
|
3786
|
+
const session = await open(io, values);
|
|
3787
|
+
const found = await session.client.secrets();
|
|
3788
|
+
answer(io, session, found, () => found.items.length === 0
|
|
3789
|
+
? "No secret is kept yet: console secret <name> --set keeps one."
|
|
3790
|
+
: found.items.map((item) => formatSecretLine(item)).join("\n"));
|
|
3791
|
+
return EXIT.ok;
|
|
3792
|
+
};
|
|
3793
|
+
const SECRET_USAGE = "Say which secret: console secret <name> | secret <name> --set [--file <path>] [--expires <day|none>] | secret <name> --remove";
|
|
3794
|
+
// One secret of the account's own: its value, read and noted; or set, typed unseen; or removed.
|
|
3795
|
+
const secret = async (args, io) => {
|
|
3796
|
+
const { values, positionals } = parse(args, SECRET_FLAGS);
|
|
3797
|
+
const name = theOne(positionals, SECRET_USAGE);
|
|
3798
|
+
const session = await open(io, values);
|
|
3799
|
+
if (on(values, "remove")) {
|
|
3800
|
+
await session.client.removeSecret(name);
|
|
3801
|
+
answer(io, session, { removed: name }, () => `The secret ${name} is removed.`);
|
|
3802
|
+
return EXIT.ok;
|
|
3803
|
+
}
|
|
3804
|
+
if (on(values, "set")) {
|
|
3805
|
+
const expiresOn = expiryOf(io, values);
|
|
3806
|
+
const value = await secretValue(io, values, `Value of ${name} (typed unseen; Enter ends it): `);
|
|
3807
|
+
const kept = await session.client.setSecret(name, {
|
|
3808
|
+
value,
|
|
3809
|
+
...(expiresOn === undefined ? {} : { expiresOn }),
|
|
3810
|
+
});
|
|
3811
|
+
answer(io, session, kept, () => `Kept: ${formatSecretLine(kept)}`);
|
|
3812
|
+
return EXIT.ok;
|
|
3813
|
+
}
|
|
3814
|
+
// The value alone, for whatever reads it next; the reading is on the account's record.
|
|
3815
|
+
const found = await session.client.secret(name);
|
|
3816
|
+
io.stdout(session.json ? `${JSON.stringify(found, null, 2)}\n` : `${found.value}\n`);
|
|
3817
|
+
return EXIT.ok;
|
|
3818
|
+
};
|
|
3819
|
+
// A supervisor's part of an agent account's store (ADR-0087): the names; a secret seeded,
|
|
3820
|
+
// write-only, which only the account reads back; one removed. Never a value.
|
|
3821
|
+
const agentSecrets = async (args, io) => {
|
|
3822
|
+
const { values, positionals } = parse(args, {});
|
|
3823
|
+
const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle>"));
|
|
3824
|
+
const session = await open(io, values);
|
|
3825
|
+
let found;
|
|
3826
|
+
try {
|
|
3827
|
+
found = await session.client.agentSecrets(handle);
|
|
3828
|
+
}
|
|
3829
|
+
catch (error) {
|
|
3830
|
+
// An account that asks for its own secrets by the supervisor's command is told which
|
|
3831
|
+
// command is its own, where the console's refusal says only whose this one is.
|
|
3832
|
+
if (error instanceof ApiError && error.code === "auth.forbidden") {
|
|
3833
|
+
const me = await session.client.me().catch(() => undefined);
|
|
3834
|
+
if (me?.person?.kind === "agent" && me.person.handle === handle) {
|
|
3835
|
+
throw failed(`auth.forbidden: console agent secrets is a supervisor's command, and you are @${handle} yourself. Your own store is read with console secrets, and one secret of it with console secret <name>.`);
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
throw error;
|
|
3839
|
+
}
|
|
3840
|
+
answer(io, session, found, () => found.items.length === 0
|
|
3841
|
+
? `@${handle} keeps no secret yet.`
|
|
3842
|
+
: found.items.map((item) => formatSecretLine(item)).join("\n"));
|
|
3843
|
+
return EXIT.ok;
|
|
3844
|
+
};
|
|
3845
|
+
const agentSecret = async (args, io) => {
|
|
3846
|
+
const { values, positionals } = parse(args, SECRET_FLAGS);
|
|
3847
|
+
const [given, name] = theTwo(positionals, "Say whose and which: console agent secret <handle> <name> [--file <path>] [--expires <day|none>] | agent secret <handle> <name> --remove");
|
|
3848
|
+
const handle = handleOf(given);
|
|
3849
|
+
const session = await open(io, values);
|
|
3850
|
+
if (on(values, "remove")) {
|
|
3851
|
+
await session.client.removeAgentSecret(handle, name);
|
|
3852
|
+
answer(io, session, { handle, removed: name }, () => `The secret ${name} of @${handle} is removed.`);
|
|
3853
|
+
return EXIT.ok;
|
|
3854
|
+
}
|
|
3855
|
+
const expiresOn = expiryOf(io, values);
|
|
3856
|
+
const value = await secretValue(io, values, `Value of ${name} for @${handle} (typed unseen; Enter ends it): `);
|
|
3857
|
+
const kept = await session.client.seedAgentSecret(handle, name, {
|
|
3858
|
+
value,
|
|
3859
|
+
...(expiresOn === undefined ? {} : { expiresOn }),
|
|
3860
|
+
});
|
|
3861
|
+
answer(io, session, kept, () => `Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`);
|
|
3862
|
+
return EXIT.ok;
|
|
3863
|
+
};
|
|
3864
|
+
/** The kinds of signal a supervisor sends with words: which need them, and which take them. */
|
|
3865
|
+
const WORDED_SIGNALS = {
|
|
3866
|
+
tell: { needs: true },
|
|
3867
|
+
// Without words it stops the turn so that what the agent was sent and has not taken is read now.
|
|
3868
|
+
interrupt: { needs: false },
|
|
3869
|
+
stop: { needs: false },
|
|
3870
|
+
restart: { needs: false },
|
|
3871
|
+
reset: { needs: false },
|
|
3872
|
+
wake: { needs: false },
|
|
3873
|
+
};
|
|
3874
|
+
// A supervisor's signal to an agent account (ADR-0085): a tell, an interruption, a stop, a start
|
|
3875
|
+
// with the same conversation or with a new one, a wake; in their own name, on the account's
|
|
3876
|
+
// record. What it says is given as words, or with --file, or on standard input as `-`.
|
|
3877
|
+
const agentSignal = async (kind, args, io) => {
|
|
3878
|
+
const { values, positionals } = parse(args, { file: { type: "string" } });
|
|
3879
|
+
const [given, words, ...rest] = positionals;
|
|
3880
|
+
const needs = WORDED_SIGNALS[kind]?.needs === true;
|
|
3881
|
+
const usage = `Say whom${needs ? " and what" : ""}: console agent ${kind} <handle> ${needs ? '"<words>"' : '["<words>"]'} [--file <path>]`;
|
|
3882
|
+
if (given === undefined || rest.length > 0) {
|
|
3883
|
+
throw misuse(usage);
|
|
3884
|
+
}
|
|
3885
|
+
const said = ((await bodyOf(io, values, words)) ?? "").trim();
|
|
3886
|
+
if (needs && said.length === 0) {
|
|
3887
|
+
throw misuse(usage);
|
|
3888
|
+
}
|
|
3889
|
+
const handle = handleOf(given);
|
|
3890
|
+
const session = await open(io, values);
|
|
3891
|
+
const sent = await session.client.sendSignal(handle, {
|
|
3892
|
+
kind,
|
|
3893
|
+
...(said.length === 0 ? {} : { text: said }),
|
|
3894
|
+
});
|
|
3895
|
+
answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
|
|
3896
|
+
return EXIT.ok;
|
|
3897
|
+
};
|
|
3898
|
+
// The model and the level of effort an agent account runs with (ADR-0085): a supervisor's
|
|
3899
|
+
// choice, kept with the account and applied by its runner.
|
|
3900
|
+
const agentSet = async (args, io) => {
|
|
3901
|
+
const { values, positionals } = parse(args, {
|
|
3902
|
+
model: { type: "string" },
|
|
3903
|
+
effort: { type: "string" },
|
|
3904
|
+
});
|
|
3905
|
+
const usage = "Say whom and what: console agent set <handle> [--model <name|none>] [--effort <level|none>]";
|
|
3906
|
+
const handle = handleOf(theOne(positionals, usage));
|
|
3907
|
+
const model = orNone(text(values, "model"));
|
|
3908
|
+
const effort = orNone(text(values, "effort"));
|
|
3909
|
+
if (model === undefined && effort === undefined) {
|
|
3910
|
+
throw misuse(usage);
|
|
3911
|
+
}
|
|
3912
|
+
const session = await open(io, values);
|
|
3913
|
+
const sent = await session.client.sendSignal(handle, {
|
|
3914
|
+
kind: "set",
|
|
3915
|
+
set: {
|
|
3916
|
+
...(model === undefined ? {} : { model }),
|
|
3917
|
+
...(effort === undefined ? {} : { effort }),
|
|
3918
|
+
},
|
|
3919
|
+
});
|
|
3920
|
+
answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
|
|
3921
|
+
return EXIT.ok;
|
|
3922
|
+
};
|
|
3923
|
+
// The record of what an agent account was told (ADR-0085), the newest first: for its
|
|
3924
|
+
// supervisors, and for the account itself as `console agent signals me`.
|
|
3925
|
+
const agentSignals = async (args, io) => {
|
|
3926
|
+
const { values, positionals } = parse(args, {
|
|
3927
|
+
limit: { type: "string" },
|
|
3928
|
+
before: { type: "string" },
|
|
3929
|
+
});
|
|
3930
|
+
const handle = handleOf(theOne(positionals, "Say whose: console agent signals <handle|me> [--limit <n>] [--before <number>]"));
|
|
3931
|
+
const limit = text(values, "limit");
|
|
3932
|
+
const before = text(values, "before");
|
|
3933
|
+
if (limit !== undefined &&
|
|
3934
|
+
!(Number.isInteger(Number(limit)) &&
|
|
3935
|
+
Number(limit) >= 1 &&
|
|
3936
|
+
Number(limit) <= MAX_SIGNALS_PAGE_LIMIT)) {
|
|
3937
|
+
throw misuse(`Not a number of signals, 1 to ${MAX_SIGNALS_PAGE_LIMIT}: ${limit}`);
|
|
3938
|
+
}
|
|
3939
|
+
if (before !== undefined && !(Number.isSafeInteger(Number(before)) && Number(before) >= 1)) {
|
|
3940
|
+
throw misuse(`Not a signal's number: ${before}`);
|
|
3941
|
+
}
|
|
3942
|
+
const session = await open(io, values);
|
|
3943
|
+
const found = await session.client.signals(handle, {
|
|
3944
|
+
...(limit === undefined ? {} : { limit: Number(limit) }),
|
|
3945
|
+
...(before === undefined ? {} : { before: Number(before) }),
|
|
3946
|
+
});
|
|
3947
|
+
answer(io, session, found, () => found.items.length === 0
|
|
3948
|
+
? "No signal yet."
|
|
3949
|
+
: [
|
|
3950
|
+
...found.items.map(formatSignalLine),
|
|
3951
|
+
...(found.more
|
|
3952
|
+
? [
|
|
3953
|
+
`More before: console agent signals ${handle} --before ${found.items.at(-1)?.number}`,
|
|
3954
|
+
]
|
|
3955
|
+
: []),
|
|
3956
|
+
].join("\n"));
|
|
3957
|
+
return EXIT.ok;
|
|
3958
|
+
};
|
|
3959
|
+
// The invitation that leads a machine to an agent account (ADR-0088): made, made again in place
|
|
3960
|
+
// of the one before, or taken away, by a supervisor. Its code is no credential: it says which
|
|
3961
|
+
// account a setup is for and opens the guide, and the account is entered through its own sign-in.
|
|
3962
|
+
const agentInvite = async (args, io) => {
|
|
3963
|
+
const { values, positionals } = parse(args, { revoke: { type: "boolean" } });
|
|
3964
|
+
const handle = handleOf(theOne(positionals, "Say whose: console agent invite <handle> [--revoke]"));
|
|
3965
|
+
const session = await open(io, values);
|
|
3966
|
+
if (on(values, "revoke")) {
|
|
3967
|
+
await session.client.revokeAgentInvitation(handle);
|
|
3968
|
+
answer(io, session, { handle, revoked: true }, () => `The invitation of @${handle} is taken away: its code opens nothing now.`);
|
|
3969
|
+
return EXIT.ok;
|
|
3970
|
+
}
|
|
3971
|
+
const made = await session.client.inviteAgent(handle);
|
|
3972
|
+
answer(io, session, made, () => [
|
|
3973
|
+
`An invitation for @${handle}, good until ${moment(made.invitation.expiresAt)} or until its command has signed in. The code is shown this once. It is no credential: it says which account a setup is for, and gives nobody the account.`,
|
|
3974
|
+
"On the agent's machine, in its own OS account, say to its product:",
|
|
3975
|
+
` ${setupSentenceOf(made.command)}`,
|
|
3976
|
+
`or run the command there yourself. A person reads the same guide at ${session.url}/setup/${made.code}`,
|
|
3977
|
+
].join("\n"));
|
|
3978
|
+
return EXIT.ok;
|
|
3979
|
+
};
|
|
3980
|
+
const SETUP_USAGE = "Say which setup: console agent setup --console <origin> --code <code>, as the invitation's line has it. A supervisor of the account makes one: console agent invite <handle>";
|
|
3981
|
+
/** The secret of an agent account's store that its git host is read with. */
|
|
3982
|
+
const DESK_TOKEN = GIT_TOKEN_SECRET;
|
|
3983
|
+
/** How often, and how many times, a setup looks whether the runner it started is heard from. */
|
|
3984
|
+
const RUNNER_HEARD_PAUSE_MS = 2000;
|
|
3985
|
+
const RUNNER_HEARD_TRIES = 15;
|
|
3986
|
+
/** How long a command of the service that is tried again waits between its tries. */
|
|
3987
|
+
const SERVICE_TRY_PAUSE_MS = 1000;
|
|
3988
|
+
const SETUP_FLAGS = {
|
|
3989
|
+
console: { type: "string" },
|
|
3990
|
+
code: { type: "string" },
|
|
3991
|
+
desk: { type: "string" },
|
|
3992
|
+
guide: { type: "boolean" },
|
|
3993
|
+
refresh: { type: "boolean" },
|
|
3994
|
+
"new-desk": { type: "boolean" },
|
|
3995
|
+
"no-service": { type: "boolean" },
|
|
3996
|
+
};
|
|
3997
|
+
/** The end of what a program said, for a refusal to carry: one line, bounded. */
|
|
3998
|
+
function lastWords(ran) {
|
|
3999
|
+
const line = ran.err.trim().split(/\r?\n/).at(-1) ?? "";
|
|
4000
|
+
return line.length === 0 ? "it said nothing" : line.slice(0, 300);
|
|
4001
|
+
}
|
|
4002
|
+
/**
|
|
4003
|
+
* The origin of a remote that git reaches over the web, `https://host`, which is what a
|
|
4004
|
+
* credential is asked for; nothing for any other address, which takes no token this way.
|
|
4005
|
+
*/
|
|
4006
|
+
function gitOriginOf(remote) {
|
|
4007
|
+
if (remote === undefined) {
|
|
4008
|
+
return undefined;
|
|
4009
|
+
}
|
|
4010
|
+
try {
|
|
4011
|
+
const url = new URL(remote);
|
|
4012
|
+
return url.protocol === "https:" || url.protocol === "http:"
|
|
4013
|
+
? `${url.protocol}//${url.host}`
|
|
4014
|
+
: undefined;
|
|
4015
|
+
}
|
|
4016
|
+
catch {
|
|
4017
|
+
return undefined;
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
/**
|
|
4021
|
+
* What git is handed a token by, for one command: a credential helper named in the environment,
|
|
4022
|
+
* which answers with the token from the environment. The token is on no command line, which a
|
|
4023
|
+
* process list shows, and in no file of the repository. The helper is named for one origin, the
|
|
4024
|
+
* remote's own: a redirect, or a repository inside the one cloned, at another host is answered
|
|
4025
|
+
* nothing of it.
|
|
4026
|
+
*/
|
|
4027
|
+
function gitTokenEnv(token, origin) {
|
|
4028
|
+
return {
|
|
4029
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
4030
|
+
GIT_CONFIG_COUNT: "2",
|
|
4031
|
+
// An empty helper first: whatever the machine has configured for that origin is left out of this command.
|
|
4032
|
+
GIT_CONFIG_KEY_0: `credential.${origin}.helper`,
|
|
4033
|
+
GIT_CONFIG_VALUE_0: "",
|
|
4034
|
+
GIT_CONFIG_KEY_1: `credential.${origin}.helper`,
|
|
4035
|
+
GIT_CONFIG_VALUE_1: '!f() { test "$1" = get && printf "username=x-access-token\\npassword=%s\\n" "$CONSOLE_DESK_TOKEN"; }; f',
|
|
4036
|
+
CONSOLE_DESK_TOKEN: token,
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
/**
|
|
4040
|
+
* A word of a line a person runs in a shell, as that shell takes it whole: quoted where it holds
|
|
4041
|
+
* anything a shell reads as more than a word, in single quotes, which neither a POSIX shell nor
|
|
4042
|
+
* PowerShell reads into.
|
|
4043
|
+
*/
|
|
4044
|
+
function shellWord(text, platform) {
|
|
4045
|
+
const plain = platform === "win32" ? /^[A-Za-z0-9_@%+=:,./\\-]+$/ : /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
4046
|
+
if (plain.test(text)) {
|
|
4047
|
+
return text;
|
|
4048
|
+
}
|
|
4049
|
+
return platform === "win32"
|
|
4050
|
+
? `'${text.replaceAll("'", "''")}'`
|
|
4051
|
+
: `'${text.replaceAll("'", "'\\''")}'`;
|
|
4052
|
+
}
|
|
4053
|
+
/**
|
|
4054
|
+
* The line that starts the runner by hand, in the desk, for a person or an agent to run. On
|
|
4055
|
+
* Windows its two commands are joined by `;`: the PowerShell every Windows has takes no `&&`,
|
|
4056
|
+
* which came with PowerShell 7, and the words are quoted as PowerShell takes them.
|
|
4057
|
+
*/
|
|
4058
|
+
function runnerByHand(desk, url, login, platform) {
|
|
4059
|
+
const then = platform === "win32" ? ";" : " &&";
|
|
4060
|
+
return `cd ${shellWord(desk, platform)}${then} console runner --url ${shellWord(url, platform)} --account ${shellWord(login, platform)}`;
|
|
4061
|
+
}
|
|
4062
|
+
/** The desk a setup is for: the place named, else this directory where it is a desk, else `desk` in the OS account's home. */
|
|
4063
|
+
async function deskOf(machine, values) {
|
|
4064
|
+
const named = text(values, "desk");
|
|
4065
|
+
if (named !== undefined) {
|
|
4066
|
+
return machine.path(named);
|
|
4067
|
+
}
|
|
4068
|
+
const here = machine.path(".");
|
|
4069
|
+
return (await machine.exists(machine.path(here, "runner.json")))
|
|
4070
|
+
? here
|
|
4071
|
+
: machine.path(machine.home, "desk");
|
|
4072
|
+
}
|
|
4073
|
+
/**
|
|
4074
|
+
* The desk on this machine (ADR-0088): left as it is where there is one; cloned from the git
|
|
4075
|
+
* host where the account keeps the token that reads it there, which is an account that pushed a
|
|
4076
|
+
* desk before; written from the template otherwise, and no file that is there is written over.
|
|
4077
|
+
*/
|
|
4078
|
+
async function settleDesk(io, machine, client, person, workspace, url, values) {
|
|
4079
|
+
const desk = await deskOf(machine, values);
|
|
4080
|
+
const handle = person.handle ?? "";
|
|
4081
|
+
if ((await machine.exists(machine.path(desk, "runner.json"))) ||
|
|
4082
|
+
(await machine.exists(machine.path(desk, "AGENTS.md")))) {
|
|
4083
|
+
io.stdout(`The desk at ${desk} is there already, and is left as it is.\n`);
|
|
4084
|
+
return desk;
|
|
4085
|
+
}
|
|
4086
|
+
const remote = on(values, "new-desk") ? undefined : deskRemoteOf(workspace, handle);
|
|
4087
|
+
if (remote !== undefined &&
|
|
4088
|
+
(await client.secrets()).items.some((secret) => secret.name === DESK_TOKEN)) {
|
|
4089
|
+
if (await machine.holds(desk)) {
|
|
4090
|
+
throw failed(`${desk} holds something that is no desk, and a desk is cloned into an empty place. Name another with --desk <dir>.`);
|
|
4091
|
+
}
|
|
4092
|
+
const token = (await client.secret(DESK_TOKEN)).value;
|
|
4093
|
+
const origin = gitOriginOf(remote);
|
|
4094
|
+
const cloned = await machine.run("git", ["clone", "--quiet", remote, desk], {
|
|
4095
|
+
env: origin === undefined ? { GIT_TERMINAL_PROMPT: "0" } : gitTokenEnv(token, origin),
|
|
4096
|
+
});
|
|
4097
|
+
if (cloned.code !== 0) {
|
|
4098
|
+
throw failed(`The desk could not be cloned from ${remote}: ${lastWords(cloned)}. Put that right and run this again; or begin a new desk here with --new-desk, where the account never pushed one.`);
|
|
4099
|
+
}
|
|
4100
|
+
io.stdout(`The desk is cloned from ${remote} into ${desk}.\n`);
|
|
4101
|
+
return desk;
|
|
4102
|
+
}
|
|
4103
|
+
const written = [];
|
|
4104
|
+
for (const [path, body] of deskFiles({
|
|
4105
|
+
agent: { name: person.name ?? handle, handle, title: person.title ?? null },
|
|
4106
|
+
console: { url, workspace: workspace.name },
|
|
4107
|
+
services: deskServicesOf(workspace, handle),
|
|
4108
|
+
})) {
|
|
4109
|
+
const file = machine.path(desk, path);
|
|
4110
|
+
if (!(await machine.exists(file))) {
|
|
4111
|
+
await machine.write(file, body, 0o644);
|
|
4112
|
+
written.push(path);
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4115
|
+
io.stdout(`A new desk is written at ${desk} (${written.join(", ")}). It is the agent's from now on: to edit, to make a repository of, and to push to its git host.\n`);
|
|
4116
|
+
return desk;
|
|
4117
|
+
}
|
|
4118
|
+
/**
|
|
4119
|
+
* The service that keeps the runner running (ADR-0085), by the module of this platform: its
|
|
4120
|
+
* files written and, for a first setup, its commands run; answers where the runner's own lines
|
|
4121
|
+
* are once it is loaded. A refresh runs none of them and never unloads a service, since it may
|
|
4122
|
+
* be running under it: what it wrote again is read when the service is next loaded.
|
|
4123
|
+
*/
|
|
4124
|
+
async function settleService(io, machine, desk, url, login, how) {
|
|
4125
|
+
const byHand = runnerByHand(desk, url, login, machine.platform);
|
|
4126
|
+
const modules = ownRunnerModules({ user: machine.user });
|
|
4127
|
+
const service = modules.services
|
|
4128
|
+
.names()
|
|
4129
|
+
.map((name) => modules.services.get(name))
|
|
4130
|
+
.find((one) => one?.platforms.includes(machine.platform) === true);
|
|
4131
|
+
if (service === undefined || machine.self === undefined) {
|
|
4132
|
+
io.stdout(`${service === undefined ? `No service keeps a runner running on ${machine.platform} yet` : "This command does not know how it was started, so it writes no service"}. Start the runner yourself and keep it running: ${byHand}\n`);
|
|
4133
|
+
return undefined;
|
|
4134
|
+
}
|
|
4135
|
+
const plan = service.plan({
|
|
4136
|
+
desk,
|
|
4137
|
+
home: machine.home,
|
|
4138
|
+
uid: machine.uid,
|
|
4139
|
+
user: machine.user,
|
|
4140
|
+
program: [...machine.self, "runner", "--url", url, "--account", login],
|
|
4141
|
+
path: machine.searchPath,
|
|
4142
|
+
});
|
|
4143
|
+
if ("problem" in plan) {
|
|
4144
|
+
throw failed(`The ${service.name} service is not written: ${plan.problem}. Start the runner yourself and keep it running: ${byHand}`);
|
|
4145
|
+
}
|
|
4146
|
+
let changed = false;
|
|
4147
|
+
for (const file of plan.files) {
|
|
4148
|
+
if ((await machine.read(file.path)) !== file.text) {
|
|
4149
|
+
await machine.write(file.path, file.text, file.mode);
|
|
4150
|
+
changed = true;
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
const where = plan.files.map((file) => file.path).join(", ");
|
|
4154
|
+
const said = (step) => `${step.command} ${step.args.join(" ")}`;
|
|
4155
|
+
// A command of the service's, tried as often as it says, a second apart.
|
|
4156
|
+
const run = async (step) => {
|
|
4157
|
+
let ran = await machine.run(step.command, step.args, { env: step.env });
|
|
4158
|
+
for (let tried = 1; ran.code !== 0 && tried < (step.tries ?? 1); tried += 1) {
|
|
4159
|
+
await io.sleep(SERVICE_TRY_PAUSE_MS);
|
|
4160
|
+
ran = await machine.run(step.command, step.args, { env: step.env });
|
|
4161
|
+
}
|
|
4162
|
+
return ran;
|
|
4163
|
+
};
|
|
4164
|
+
if (how === "write") {
|
|
4165
|
+
if (!changed) {
|
|
4166
|
+
io.stdout(`The ${service.name} service is as it was (${where}).\n`);
|
|
4167
|
+
return undefined;
|
|
4168
|
+
}
|
|
4169
|
+
// What has the system read the file anew ends nothing that runs: a refresh runs that much.
|
|
4170
|
+
const unread = [];
|
|
4171
|
+
for (const step of plan.reread ?? []) {
|
|
4172
|
+
if ((await run(step)).code !== 0) {
|
|
4173
|
+
unread.push(said(step));
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
io.stdout(`The ${service.name} service is written again (${where}). It is read ${plan.reload}${unread.length === 0 ? "" : ` Run this first, which did not succeed here: ${unread.join("; ")}.`}\n`);
|
|
4177
|
+
return undefined;
|
|
4178
|
+
}
|
|
4179
|
+
const left = [];
|
|
4180
|
+
for (const step of plan.commands) {
|
|
4181
|
+
const ran = await run(step);
|
|
4182
|
+
if (ran.code === 0) {
|
|
4183
|
+
continue;
|
|
4184
|
+
}
|
|
4185
|
+
if (step.mayFail !== true) {
|
|
4186
|
+
throw failed(`The ${service.name} service is written (${where}) and was not loaded: ${said(step)} said: ${lastWords(ran)}. ${plan.failing} Or start the runner yourself and keep it running: ${byHand}`);
|
|
4187
|
+
}
|
|
4188
|
+
if (step.otherwise !== undefined) {
|
|
4189
|
+
left.push(step.otherwise);
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
io.stdout(`The ${service.name} service is written (${where}) and loaded: the runner starts with the OS account ${machine.user}, and is started again when it ends. Its own lines are in ${plan.log}.\n${left.map((line) => `${line}\n`).join("")}`);
|
|
4193
|
+
return plan.log;
|
|
4194
|
+
}
|
|
4195
|
+
/**
|
|
4196
|
+
* Signs the command in as the account a setup is for (ADR-0088, point 5), unless it is already:
|
|
4197
|
+
* a connection that asks to be the account itself, opened in the machine's browser and approved
|
|
4198
|
+
* there by the account. A sign-in that turns out to be anybody else's is given up at once:
|
|
4199
|
+
* nobody answers for the account but the account.
|
|
4200
|
+
*/
|
|
4201
|
+
async function signInAsAccount(io, machine, url, setup) {
|
|
4202
|
+
const { handle, login } = setup.account;
|
|
4203
|
+
const isAccount = (me) => me.person?.kind === "agent" && me.person.handle === handle && me.session?.kind === "command";
|
|
4204
|
+
const credentials = (await loadCredentials(io)) ?? EMPTY_CREDENTIALS;
|
|
4205
|
+
for (const kept of loginsAt(credentials, url)) {
|
|
4206
|
+
if (kept.self !== true) {
|
|
4207
|
+
continue;
|
|
4208
|
+
}
|
|
4209
|
+
const client = clientOf(io, url, kept.token);
|
|
4210
|
+
const me = await client.me().catch(() => undefined);
|
|
4211
|
+
if (me !== undefined && isAccount(me)) {
|
|
4212
|
+
io.stdout(`This command is signed in as @${handle} here already.\n`);
|
|
4213
|
+
return client;
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
const anonymous = clientOf(io, url);
|
|
4217
|
+
// What the account's page shows beside the session: the OS account, and the machine.
|
|
4218
|
+
const label = `console as ${machine.user}`;
|
|
4219
|
+
const begun = await anonymous.connect({
|
|
4220
|
+
agent: io.hostname === undefined ? label : `${label} on ${io.hostname}`,
|
|
4221
|
+
as: "self",
|
|
4222
|
+
});
|
|
4223
|
+
// The address is the console's own, or it is not opened: what a console answers is not run.
|
|
4224
|
+
const opened = URL.canParse(begun.url) && new URL(begun.url).origin === url
|
|
4225
|
+
? await machine.open(begun.url)
|
|
4226
|
+
: false;
|
|
4227
|
+
// The end of the wait is a moment as any other the command prints (ADR-0035), as a login's
|
|
4228
|
+
// is: in the workspace's time zone where a login at this console kept it, as the API gave it
|
|
4229
|
+
// where none has.
|
|
4230
|
+
setMomentZone(credentials.logins.find((kept) => kept.url === url)?.timeZone);
|
|
4231
|
+
io.stdout(`${opened ? `The page is opened in this machine's browser: ${begun.url}` : `Open ${begun.url} in this machine's browser`}. Sign in there as ${login}, check that the page shows the code ${begun.code}, and say that it is you. On a machine without a screen, open the address in any browser that is signed in as the account.\nWaiting for that, until ${moment(begun.expiresAt)}.\n`);
|
|
4232
|
+
let secret;
|
|
4233
|
+
for (;;) {
|
|
4234
|
+
await io.sleep(begun.interval * 1000);
|
|
4235
|
+
let claim;
|
|
4236
|
+
try {
|
|
4237
|
+
claim = await anonymous.claimConnection(begun.secret);
|
|
4238
|
+
}
|
|
4239
|
+
catch (error) {
|
|
4240
|
+
if (error instanceof ApiError && error.code === "connect.not_found") {
|
|
4241
|
+
throw failed("Nobody said in time that this command is the account, or someone said it is not theirs. Nothing was set up. Run the line again for a new code.");
|
|
4242
|
+
}
|
|
4243
|
+
throw error;
|
|
4244
|
+
}
|
|
4245
|
+
if (claim.status === "signed_in" || claim.status === "connected") {
|
|
4246
|
+
secret = claim.secret;
|
|
4247
|
+
break;
|
|
4248
|
+
}
|
|
4249
|
+
}
|
|
4250
|
+
const client = clientOf(io, url, secret);
|
|
4251
|
+
const me = await client.me();
|
|
4252
|
+
if (!isAccount(me)) {
|
|
4253
|
+
await client.giveUpToken().catch(() => undefined);
|
|
4254
|
+
throw failed(`The page said that this command is ${me.person?.login ?? "nobody"}, who is not @${handle}. That sign-in is given up, and nothing was set up. Sign out of the console in that browser, sign in as ${login}, and run the line again.`);
|
|
4255
|
+
}
|
|
4256
|
+
await keep(io, url, secret, undefined, true, true, () => undefined);
|
|
4257
|
+
io.stdout(`Signed in as @${handle}: what this command does from now on, the account does. The session is kept while it is used.\n`);
|
|
4258
|
+
return client;
|
|
4259
|
+
}
|
|
4260
|
+
/** Looks for a little while whether the runner that was started is heard from, and says how it stands. */
|
|
4261
|
+
async function awaitRunner(io, client, handle, heardBefore, log) {
|
|
4262
|
+
for (let tries = 0; tries < RUNNER_HEARD_TRIES; tries += 1) {
|
|
4263
|
+
await io.sleep(RUNNER_HEARD_PAUSE_MS);
|
|
4264
|
+
const found = await client.agent(handle).catch(() => undefined);
|
|
4265
|
+
const heard = found?.state?.heardAt ?? null;
|
|
4266
|
+
const said = found?.runner?.machine ?? null;
|
|
4267
|
+
if (heard !== null && heard !== heardBefore && said !== null) {
|
|
4268
|
+
io.stdout(`The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine, and its page shows it.\n`);
|
|
4269
|
+
return;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
io.stdout(`The runner is not heard from yet. Its own lines are in ${log}; the account's page says when it is.\n`);
|
|
4273
|
+
}
|
|
4274
|
+
// Derives a machine again (ADR-0088): by the account's own command, in its desk, when the
|
|
4275
|
+
// services or the account changed. It writes what is missing of the desk and the service where
|
|
4276
|
+
// it changed, and says the services as they are now; what the agent wrote stays the agent's.
|
|
4277
|
+
const agentRefresh = async (values, io) => {
|
|
4278
|
+
const machine = io.machine;
|
|
4279
|
+
if (machine === undefined) {
|
|
4280
|
+
throw failed("A machine cannot be set up from here.");
|
|
4281
|
+
}
|
|
4282
|
+
const session = await open(io, values);
|
|
4283
|
+
const me = await session.client.me();
|
|
4284
|
+
const person = me.person;
|
|
4285
|
+
if (person === null || person.kind !== "agent" || me.session?.kind !== "command") {
|
|
4286
|
+
throw failed("A machine is refreshed by the agent account's own command, signed in as the account. One is set up from an invitation a supervisor makes: console agent setup --console <origin> --code <code>.");
|
|
4287
|
+
}
|
|
4288
|
+
const handle = person.handle ?? person.login;
|
|
4289
|
+
const desk = await settleDesk(io, machine, session.client, person, me.workspace, session.url, values);
|
|
4290
|
+
if (!on(values, "no-service")) {
|
|
4291
|
+
await settleService(io, machine, desk, session.url, person.login, "write");
|
|
4292
|
+
}
|
|
4293
|
+
const services = deskServicesOf(me.workspace, handle);
|
|
4294
|
+
io.stdout(services.length === 0
|
|
4295
|
+
? `${me.workspace.name} names no service for its agents.\n`
|
|
4296
|
+
: `The services ${me.workspace.name} names now, with what @${handle} is called at each:\n${services
|
|
4297
|
+
.map((one) => ` ${one.role}: ${one.name}${one.account === undefined ? "" : `, as ${one.account}`}`)
|
|
4298
|
+
.join("\n")}\nWhere the desk says otherwise, put its AGENTS.md right: it is yours.\n`);
|
|
4299
|
+
return EXIT.ok;
|
|
4300
|
+
};
|
|
4301
|
+
// Sets a machine up for an agent account (ADR-0088), from the line of its invitation: prints the
|
|
4302
|
+
// guide the code opens, which is asked of the console the line names without a sign-in, since
|
|
4303
|
+
// the command is signed in nowhere there yet; then signs the command in as the account, settles
|
|
4304
|
+
// the desk and the service that keeps the runner running, and says how the runner stands.
|
|
4305
|
+
const agentSetup = async (args, io) => {
|
|
4306
|
+
const { values } = parse(args, SETUP_FLAGS, false);
|
|
4307
|
+
if (on(values, "refresh")) {
|
|
4308
|
+
return agentRefresh(values, io);
|
|
4309
|
+
}
|
|
4310
|
+
const wanted = text(values, "console") ?? text(values, "url");
|
|
4311
|
+
const given = text(values, "code");
|
|
4312
|
+
if (wanted === undefined || given === undefined) {
|
|
4313
|
+
throw misuse(SETUP_USAGE);
|
|
4314
|
+
}
|
|
4315
|
+
const code = normalizeConnectCode(given);
|
|
4316
|
+
if (code === undefined) {
|
|
4317
|
+
throw misuse("Not a code. An invitation's code is eight letters and digits, as ABCD-EFGH; copy it from the line you were given.");
|
|
4318
|
+
}
|
|
4319
|
+
const url = originOf(wanted);
|
|
4320
|
+
let setup;
|
|
4321
|
+
try {
|
|
4322
|
+
setup = await clientOf(io, url).agentSetup(code);
|
|
4323
|
+
}
|
|
4324
|
+
catch (error) {
|
|
4325
|
+
if (error instanceof ApiError && error.code === "setup.not_found") {
|
|
4326
|
+
throw failed(`No setup has that code at ${url}: it was never made, its day has passed, or the account's command has signed in already. A supervisor of the account makes a new one: console agent invite <handle>.`);
|
|
4327
|
+
}
|
|
4328
|
+
throw error;
|
|
4329
|
+
}
|
|
4330
|
+
const guide = setupGuideOf(setup, code);
|
|
4331
|
+
if (on(values, "json")) {
|
|
4332
|
+
io.stdout(`${JSON.stringify({ setup, guide }, null, 2)}\n`);
|
|
4333
|
+
return EXIT.ok;
|
|
4334
|
+
}
|
|
4335
|
+
io.stdout(`${setupGuideText(guide, moment)}\n`);
|
|
4336
|
+
if (on(values, "guide")) {
|
|
4337
|
+
return EXIT.ok;
|
|
4338
|
+
}
|
|
4339
|
+
const machine = io.machine;
|
|
4340
|
+
if (machine === undefined) {
|
|
4341
|
+
throw failed("A machine cannot be set up from here. The guide above says what a setup takes.");
|
|
4342
|
+
}
|
|
4343
|
+
const { handle } = setup.account;
|
|
4344
|
+
io.stdout(`\nSetting this machine up for @${handle}, in the OS account ${machine.user}${io.hostname === undefined ? "" : ` on ${io.hostname}`}.\n`);
|
|
4345
|
+
const client = await signInAsAccount(io, machine, url, setup);
|
|
4346
|
+
const me = await client.me();
|
|
4347
|
+
if (me.person === null) {
|
|
4348
|
+
throw failed("The console does not know this sign-in any more. Run the line again.");
|
|
4349
|
+
}
|
|
4350
|
+
const heardBefore = (await client.agent(handle).catch(() => undefined))?.state?.heardAt ?? null;
|
|
4351
|
+
const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values);
|
|
4352
|
+
if (on(values, "no-service")) {
|
|
4353
|
+
io.stdout(`No service is written, as asked. Start the runner yourself and keep it running: ${runnerByHand(desk, url, me.person.login, machine.platform)}\n`);
|
|
4354
|
+
return EXIT.ok;
|
|
4355
|
+
}
|
|
4356
|
+
const log = await settleService(io, machine, desk, url, me.person.login, "load");
|
|
4357
|
+
if (log !== undefined) {
|
|
4358
|
+
await awaitRunner(io, client, handle, heardBefore, log);
|
|
4359
|
+
}
|
|
4360
|
+
return EXIT.ok;
|
|
4361
|
+
};
|
|
4362
|
+
const DESK_USAGE = "Say at most one directory: console desk [<directory>] [--web]";
|
|
4363
|
+
/**
|
|
4364
|
+
* What is next in a new desk, in order, as a person says it to their agent there (ADR-0115,
|
|
4365
|
+
* ADR-0122): first the desk is set up as a repository, by the skill for that in the
|
|
4366
|
+
* organization's pack; then the person is asked what they want to keep and to see, and the
|
|
4367
|
+
* desk is shaped to it, by the skill the command ships, named with its place.
|
|
4368
|
+
*/
|
|
4369
|
+
function deskNext(web, skillsDir) {
|
|
4370
|
+
return [
|
|
4371
|
+
`Set this desk up as a repository of mine${web ? " and bring its pages up" : ""}, with the skill for it in the organization's pack where it has one: console skills --search "desk setup" --limit 5`,
|
|
4372
|
+
`Ask me what I want to keep and to see here, and shape the desk to it, as the skill keeping-a-desk says, shipped with the console command${skillsDir === undefined ? " (console skills says where it is)" : `: ${ownSkillPath(skillsDir, "keeping-a-desk")}`}`,
|
|
4373
|
+
];
|
|
4374
|
+
}
|
|
4375
|
+
/** The files of the shell of a desk's pages as they are written: the two words the template leaves filled in. */
|
|
4376
|
+
function deskWebFiles(template, version, title) {
|
|
4377
|
+
return [...template]
|
|
4378
|
+
.filter(([path]) => !path.split("/").some((part) => part === ".." || part.length === 0))
|
|
4379
|
+
.map(([path, body]) => [
|
|
4380
|
+
path,
|
|
4381
|
+
body.replaceAll("__VERSION__", version).replaceAll("__TITLE__", title),
|
|
4382
|
+
]);
|
|
4383
|
+
}
|
|
4384
|
+
/** A count with its word, the word in the plural where the count is not one. */
|
|
4385
|
+
const counted = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
4386
|
+
// The check of a desk's records (ADR-0117): every file under `records/` read as the format's
|
|
4387
|
+
// schemas read it, and each problem said with its file. It asks nothing of the console and
|
|
4388
|
+
// needs no sign-in: an agent that wrote a record runs it before it commits, and nobody needs
|
|
4389
|
+
// a page to know that the records are right.
|
|
4390
|
+
const deskCheck = async (args, io) => {
|
|
4391
|
+
const { values, positionals } = parse(args, {});
|
|
4392
|
+
if (positionals.length > 1) {
|
|
4393
|
+
throw misuse("Say at most one directory: console desk check [<directory>]");
|
|
4394
|
+
}
|
|
4395
|
+
const at = io.recordsAt?.(positionals[0] ?? ".");
|
|
4396
|
+
if (at === undefined) {
|
|
4397
|
+
throw failed("A desk's records cannot be read from here.");
|
|
4398
|
+
}
|
|
4399
|
+
const found = await checkRecords(at.files);
|
|
4400
|
+
if (on(values, "json")) {
|
|
4401
|
+
io.stdout(`${JSON.stringify({ directory: at.directory, ...found }, null, 2)}\n`);
|
|
4402
|
+
}
|
|
4403
|
+
else if (!found.found) {
|
|
4404
|
+
io.stdout(`No collection is kept in ${at.directory}: ${RECORDS_DIR}/${RECORDS_INDEX_FILE} is not there. What else is under ${RECORDS_DIR}/ is the desk's own shape, and not this check's to read. Where a collection is wanted, the skill keeping-a-desk says how one is kept (collections.md).\n`);
|
|
4405
|
+
}
|
|
4406
|
+
else {
|
|
4407
|
+
const kept = found.collections.map((one) => ` ${one.key}: ${counted(one.items, "item")}, ${counted(one.uses, "use")}, ${counted(one.metricRows, "row of figures", "rows of figures")}`);
|
|
4408
|
+
io.stdout([
|
|
4409
|
+
...found.problems.map((one) => `${one.file}: ${one.problem}`),
|
|
4410
|
+
...found.notes.map((one) => `note: ${one.file}: ${one.problem}`),
|
|
4411
|
+
...(found.problems.length === 0
|
|
4412
|
+
? [
|
|
4413
|
+
`The records in ${at.directory} read right: ${counted(found.collections.length, "collection")}.`,
|
|
4414
|
+
]
|
|
4415
|
+
: found.collections.length === 0
|
|
4416
|
+
? []
|
|
4417
|
+
: ["What reads:"]),
|
|
4418
|
+
...kept,
|
|
4419
|
+
"",
|
|
4420
|
+
].join("\n"));
|
|
4421
|
+
}
|
|
4422
|
+
if (found.problems.length > 0) {
|
|
4423
|
+
throw failed(`${counted(found.problems.length, "problem")} in the records of ${at.directory}. Mend the files and run this again.`);
|
|
4424
|
+
}
|
|
4425
|
+
return EXIT.ok;
|
|
4426
|
+
};
|
|
4427
|
+
// A person's desk (ADR-0115): its files, the least (ADR-0122), each only where no file of that
|
|
4428
|
+
// name is there, in `desk` here, as an agent account's is called, or the directory named; with
|
|
4429
|
+
// --web, the shell of the desk's pages in `web/`, where that holds nothing yet. The command
|
|
4430
|
+
// writes and stops, and its last lines say what is next, in order, for an agent to go on with:
|
|
4431
|
+
// making the desk a repository is a skill's, of the organization's pack, and shaping it to what
|
|
4432
|
+
// the person asks to keep and to see is the skill keeping-a-desk's, which the command ships.
|
|
4433
|
+
// An agent account's desk is setup's: for one, the command writes the shell alone, with --web,
|
|
4434
|
+
// into the desk it names.
|
|
4435
|
+
const desk = async (args, io) => {
|
|
4436
|
+
if (args[0] === "check") {
|
|
4437
|
+
return deskCheck(args.slice(1), io);
|
|
4438
|
+
}
|
|
4439
|
+
const { values, positionals } = parse(args, { web: { type: "boolean" } });
|
|
4440
|
+
if (positionals.length > 1) {
|
|
4441
|
+
throw misuse(DESK_USAGE);
|
|
4442
|
+
}
|
|
4443
|
+
const session = await open(io, values);
|
|
4444
|
+
const me = await session.client.me();
|
|
4445
|
+
const person = me.person;
|
|
4446
|
+
if (person === null) {
|
|
4447
|
+
throw failed("The console does not know this token. Sign in again: console login");
|
|
4448
|
+
}
|
|
4449
|
+
// An agent account's desk is setup's, and none of its own files is written here (ADR-0115).
|
|
4450
|
+
// The shell of its pages is the one thing this command writes for it, into the desk it names
|
|
4451
|
+
// (ADR-0122): a desk's pages are its member's, whichever kind of member that is.
|
|
4452
|
+
const ofAgent = person.kind === "agent";
|
|
4453
|
+
if (ofAgent && !on(values, "web")) {
|
|
4454
|
+
throw failed(`${whoOf(person)} is an agent account: its desk is settled by console agent setup, on its own machine, and nothing is written here. In that desk, console agent setup --refresh derives it again, and console desk . --web writes the shell of its pages.`);
|
|
4455
|
+
}
|
|
4456
|
+
const machine = io.machine;
|
|
4457
|
+
if (machine === undefined) {
|
|
4458
|
+
throw failed("A desk cannot be written from here.");
|
|
4459
|
+
}
|
|
4460
|
+
const [named] = positionals;
|
|
4461
|
+
// A desk made under a directory that works in a project would work in it too, and every
|
|
4462
|
+
// checkout under its work/ with it: what the folder above says, a desk must not inherit.
|
|
4463
|
+
const above = named === undefined || !isAbsolute(named) ? await io.directory.load() : undefined;
|
|
4464
|
+
if (above !== undefined) {
|
|
4465
|
+
throw failed(`This directory works in the project ${above.project} (${DIRECTORY_FILE} here or in a directory above), and a desk made inside it would work there too. A desk is bound to no project: make it elsewhere, console desk <directory>.`);
|
|
4466
|
+
}
|
|
4467
|
+
const dir = machine.path(named ?? DESK_FOLDER);
|
|
4468
|
+
if (ofAgent && !(await machine.exists(machine.path(dir, "AGENTS.md")))) {
|
|
4469
|
+
throw failed(`${dir} holds no AGENTS.md, so it is no desk, and nothing is written. An agent account's desk is settled by console agent setup; in it: console desk . --web`);
|
|
4470
|
+
}
|
|
4471
|
+
const input = {
|
|
4472
|
+
person: { name: person.name ?? person.login, login: person.login },
|
|
4473
|
+
console: { url: session.url, workspace: me.workspace.name },
|
|
4474
|
+
// The language to write to them in (A-F6): theirs, else the workspace's, else none is said.
|
|
4475
|
+
language: readingLanguage(me) ?? undefined,
|
|
4476
|
+
};
|
|
4477
|
+
// The shell of the pages is settled before anything is written, so that a command that cannot
|
|
4478
|
+
// write it writes nothing.
|
|
4479
|
+
const webDir = machine.path(dir, "web");
|
|
4480
|
+
const webKept = on(values, "web") && (await machine.holds(webDir));
|
|
4481
|
+
let shell;
|
|
4482
|
+
if (on(values, "web") && !webKept) {
|
|
4483
|
+
const template = await io.deskWebTemplate?.();
|
|
4484
|
+
if (template === undefined || template.size === 0) {
|
|
4485
|
+
throw failed(`This command's package carries no shell of a desk's pages (template/desk-web): nothing is written.${ofAgent ? "" : " Without --web, the desk alone is written."}`);
|
|
4486
|
+
}
|
|
4487
|
+
if (io.version === undefined) {
|
|
4488
|
+
throw failed(`This command does not know its version, so it cannot say which package the desk's pages are built on: nothing is written.${ofAgent ? "" : " Without --web, the desk alone is written."}`);
|
|
4489
|
+
}
|
|
4490
|
+
shell = deskWebFiles(template, io.version, deskWebTitleOf(input.person));
|
|
4491
|
+
}
|
|
4492
|
+
const written = [];
|
|
4493
|
+
const kept = [];
|
|
4494
|
+
for (const [path, body] of ofAgent ? [] : personDeskFiles(input)) {
|
|
4495
|
+
const file = machine.path(dir, path);
|
|
4496
|
+
if (await machine.exists(file)) {
|
|
4497
|
+
kept.push(path);
|
|
4498
|
+
}
|
|
4499
|
+
else {
|
|
4500
|
+
await machine.write(file, body, 0o644);
|
|
4501
|
+
written.push(path);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
const lines = ofAgent
|
|
4505
|
+
? []
|
|
4506
|
+
: [
|
|
4507
|
+
written.length === 0
|
|
4508
|
+
? `The desk at ${dir} is there already, and is left as it is.`
|
|
4509
|
+
: kept.length === 0
|
|
4510
|
+
? `A new desk is written at ${dir} (${written.join(", ")}), for ${person.login}. It is yours from now on: to edit, and to make a repository of.`
|
|
4511
|
+
: `The desk at ${dir} gains ${written.join(", ")}; ${kept.join(", ")} ${kept.length === 1 ? "was there and is left as it is" : "were there and are left as they are"}.`,
|
|
4512
|
+
];
|
|
4513
|
+
const shellNames = (shell ?? []).map(([path]) => path);
|
|
4514
|
+
for (const [path, body] of shell ?? []) {
|
|
4515
|
+
await machine.write(machine.path(webDir, ...path.split("/")), body, 0o644);
|
|
4516
|
+
}
|
|
4517
|
+
if (shell !== undefined) {
|
|
4518
|
+
lines.push(`The shell of its pages is written in ${webDir} (${shellNames.join(", ")}), on @skillcdn/console ${io.version}: one empty page of your own until you say what you want to see, served from this machine by console serve once it is built${shellNames.includes("README.md") ? "; its README.md says how" : ""}.`);
|
|
4519
|
+
}
|
|
4520
|
+
else if (webKept) {
|
|
4521
|
+
lines.push(`${webDir} holds something already, and is left as it is.`);
|
|
4522
|
+
}
|
|
4523
|
+
const web = on(values, "web")
|
|
4524
|
+
? { directory: webDir, written: shellNames, version: shell === undefined ? null : io.version }
|
|
4525
|
+
: null;
|
|
4526
|
+
// An agent account that asked for the shell is shaping its desk already: nothing is next.
|
|
4527
|
+
// So is a person who asked for the shell in a desk that was there: the two lines printed
|
|
4528
|
+
// again sent a fresh agent back to the repository's setup in the middle of building a page.
|
|
4529
|
+
const shaping = ofAgent || (web !== null && written.length === 0);
|
|
4530
|
+
const next = shaping ? [] : deskNext(web !== null, io.skillsDir);
|
|
4531
|
+
answer(io, session, { directory: dir, written, kept, web, next }, () => (next.length === 0
|
|
4532
|
+
? lines
|
|
4533
|
+
: [
|
|
4534
|
+
...lines,
|
|
4535
|
+
"Next, in that folder, say these to your agent in order; an agent that ran this command goes on with them there:",
|
|
4536
|
+
"",
|
|
4537
|
+
...next.map((line, index) => `${index + 1}. ${line}`),
|
|
4538
|
+
]).join("\n"));
|
|
4539
|
+
return EXIT.ok;
|
|
4540
|
+
};
|
|
4541
|
+
// One agent account by its handle; with --avatar, its picture written as a file (ADR-0084): the
|
|
4542
|
+
// parts are drawn here, by the package's own function, and the console sends no picture.
|
|
4543
|
+
const agent = async (args, io) => {
|
|
4544
|
+
if (args[0] === "new") {
|
|
4545
|
+
return agentNew(args.slice(1), io);
|
|
4546
|
+
}
|
|
4547
|
+
if (args[0] === "tell" ||
|
|
4548
|
+
args[0] === "interrupt" ||
|
|
4549
|
+
args[0] === "stop" ||
|
|
4550
|
+
args[0] === "restart" ||
|
|
4551
|
+
args[0] === "reset" ||
|
|
4552
|
+
args[0] === "wake") {
|
|
4553
|
+
return agentSignal(args[0], args.slice(1), io);
|
|
4554
|
+
}
|
|
4555
|
+
if (args[0] === "set") {
|
|
4556
|
+
return agentSet(args.slice(1), io);
|
|
4557
|
+
}
|
|
4558
|
+
if (args[0] === "signals") {
|
|
4559
|
+
return agentSignals(args.slice(1), io);
|
|
4560
|
+
}
|
|
4561
|
+
if (args[0] === "invite") {
|
|
4562
|
+
return agentInvite(args.slice(1), io);
|
|
4563
|
+
}
|
|
4564
|
+
if (args[0] === "setup") {
|
|
4565
|
+
return agentSetup(args.slice(1), io);
|
|
4566
|
+
}
|
|
4567
|
+
if (args[0] === "secrets") {
|
|
4568
|
+
return agentSecrets(args.slice(1), io);
|
|
4569
|
+
}
|
|
4570
|
+
if (args[0] === "secret") {
|
|
4571
|
+
return agentSecret(args.slice(1), io);
|
|
4572
|
+
}
|
|
4573
|
+
const { values, positionals } = parse(args, {
|
|
4574
|
+
avatar: { type: "string" },
|
|
4575
|
+
account: { type: "string", multiple: true },
|
|
4576
|
+
"day-start": { type: "string" },
|
|
4577
|
+
"day-end": { type: "string" },
|
|
4578
|
+
});
|
|
4579
|
+
const handle = handleOf(theOne(positionals, AGENT_USAGE));
|
|
4580
|
+
const session = await open(io, values);
|
|
4581
|
+
const held = texts(values, "account");
|
|
4582
|
+
// The hours of its day (ADR-0085): an hour as 09:00, or none for the usual start and no end.
|
|
4583
|
+
const hourOf = (flag) => {
|
|
4584
|
+
const word = text(values, flag);
|
|
4585
|
+
if (word === undefined) {
|
|
4586
|
+
return undefined;
|
|
4587
|
+
}
|
|
4588
|
+
if (word === "none") {
|
|
4589
|
+
return null;
|
|
4590
|
+
}
|
|
4591
|
+
if (!/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/.test(word)) {
|
|
4592
|
+
throw misuse(`Not an hour: ${word}. Say one as 09:00 or 18:30, or none.`);
|
|
4593
|
+
}
|
|
4594
|
+
return word;
|
|
4595
|
+
};
|
|
4596
|
+
const dayStart = hourOf("day-start");
|
|
4597
|
+
const dayEnd = hourOf("day-end");
|
|
4598
|
+
if (held.length > 0 || dayStart !== undefined || dayEnd !== undefined) {
|
|
4599
|
+
// The accounts it holds elsewhere (ADR-0089), each as <service>=<name>, or =none to take
|
|
4600
|
+
// one away: what it is called there, and never a secret.
|
|
4601
|
+
const accounts = {};
|
|
4602
|
+
for (const word of held) {
|
|
4603
|
+
const at = word.indexOf("=");
|
|
4604
|
+
const service = at === -1 ? "" : word.slice(0, at).trim();
|
|
4605
|
+
const name = at === -1 ? "" : word.slice(at + 1).trim();
|
|
4606
|
+
if (service.length === 0 || name.length === 0) {
|
|
4607
|
+
throw misuse(`Not an account: ${word}. Say the service and what the agent is called there, as --account github=acme-mira, or --account github=none to take one away.`);
|
|
4608
|
+
}
|
|
4609
|
+
accounts[service] = name === "none" ? null : name;
|
|
4610
|
+
}
|
|
4611
|
+
const kept = await session.client.updateAgent(handle, {
|
|
4612
|
+
...(held.length === 0 ? {} : { accounts }),
|
|
4613
|
+
...(dayStart === undefined ? {} : { dayStart }),
|
|
4614
|
+
...(dayEnd === undefined ? {} : { dayEnd }),
|
|
4615
|
+
});
|
|
4616
|
+
answer(io, session, kept, () => formatAgent(kept));
|
|
4617
|
+
return EXIT.ok;
|
|
4618
|
+
}
|
|
4619
|
+
const found = await session.client.agent(handle);
|
|
4620
|
+
const file = text(values, "avatar");
|
|
4621
|
+
if (file === undefined) {
|
|
4622
|
+
answer(io, session, found, () => formatAgent(found));
|
|
4623
|
+
return EXIT.ok;
|
|
4624
|
+
}
|
|
4625
|
+
const parts = found.person.avatarParts;
|
|
4626
|
+
if (parts === null || parts === undefined) {
|
|
4627
|
+
throw failed(`The console answered no avatar for @${handle}.`);
|
|
4628
|
+
}
|
|
4629
|
+
const png = pngFile(MAX_AVATAR_PIXELS, deflateSync(avatarScanlines(parts, MAX_AVATAR_PIXELS)));
|
|
4630
|
+
const written = await io.writeBytes(file, png, `${handle}.png`);
|
|
4631
|
+
answer(io, session, { handle, file: written, pixels: MAX_AVATAR_PIXELS, bytes: png.length }, () => `The avatar of @${handle} is written to ${written}: a PNG of ${MAX_AVATAR_PIXELS} pixels a side, for its profile elsewhere.`);
|
|
4632
|
+
return EXIT.ok;
|
|
4633
|
+
};
|
|
2577
4634
|
/** The teams of the workspace (ADR-0073): each with who is in it, by login. */
|
|
2578
4635
|
const teams = async (args, io) => {
|
|
2579
4636
|
const { values } = parse(args, {}, false);
|
|
2580
4637
|
const session = await open(io, values);
|
|
2581
4638
|
const [found, everyone] = await Promise.all([session.client.teams(), session.client.people()]);
|
|
2582
|
-
const loginOf = new Map(everyone.items.map((person) => [person.id, person
|
|
4639
|
+
const loginOf = new Map(everyone.items.map((person) => [person.id, calledOf(person)]));
|
|
2583
4640
|
answer(io, session, found, () => found.items.length === 0
|
|
2584
4641
|
? "No teams yet. console team new <key> <name> makes one."
|
|
2585
4642
|
: found.items.map((team) => formatTeamLine(team, loginOf)).join("\n"));
|
|
@@ -2622,14 +4679,42 @@ const team = async (args, io) => {
|
|
|
2622
4679
|
? await session.client.addTeamMember(key, person.id)
|
|
2623
4680
|
: await session.client.removeTeamMember(key, person.id);
|
|
2624
4681
|
const everyone = await session.client.people();
|
|
2625
|
-
answer(io, session, changed, () => formatTeamLine(changed, new Map(everyone.items.map((one) => [one.id, one
|
|
4682
|
+
answer(io, session, changed, () => formatTeamLine(changed, new Map(everyone.items.map((one) => [one.id, calledOf(one)]))));
|
|
2626
4683
|
return EXIT.ok;
|
|
2627
4684
|
}
|
|
2628
4685
|
throw misuse(TEAM_USAGE);
|
|
2629
4686
|
};
|
|
2630
4687
|
// The workspace's settings (ADR-0035): read by everyone, changed by an administrator, themselves
|
|
2631
4688
|
// on the Settings page or through their agent here (ADR-0021).
|
|
2632
|
-
const WORKSPACE_FLAGS = "--people-visibility <everyone|shared-projects>, --week-start <auto|monday|sunday>, --time-zone <zone|none>, --language <en|ko|none>";
|
|
4689
|
+
const WORKSPACE_FLAGS = "--people-visibility <everyone|shared-projects>, --week-start <auto|monday|sunday>, --time-zone <zone|none>, --language <en|ko|none>, --handle <name|none>, --domain <domain|none>, --service <role>=<kind|none>[,<parameter>=<value>]...";
|
|
4690
|
+
/**
|
|
4691
|
+
* A service as `--service` names one (ADR-0089): `git=github,organization=acme`, or `git=none`
|
|
4692
|
+
* to take it away. The role is one of the three; the kind and its parameters are the console's
|
|
4693
|
+
* to judge.
|
|
4694
|
+
*/
|
|
4695
|
+
function serviceOf(word) {
|
|
4696
|
+
const [first = "", ...rest] = word.split(",");
|
|
4697
|
+
const equals = first.indexOf("=");
|
|
4698
|
+
const role = equals === -1 ? "" : first.slice(0, equals).trim();
|
|
4699
|
+
const kind = equals === -1 ? "" : first.slice(equals + 1).trim();
|
|
4700
|
+
if (!SERVICE_ROLES.some((known) => known === role) || kind.length === 0) {
|
|
4701
|
+
throw misuse(`Not a service: ${word}. Say --service <${SERVICE_ROLES.join("|")}>=<kind|none>[,<parameter>=<value>]...`);
|
|
4702
|
+
}
|
|
4703
|
+
if (kind === "none") {
|
|
4704
|
+
return { role: role, service: null };
|
|
4705
|
+
}
|
|
4706
|
+
const service = { kind };
|
|
4707
|
+
for (const pair of rest) {
|
|
4708
|
+
const at = pair.indexOf("=");
|
|
4709
|
+
const name = at === -1 ? "" : pair.slice(0, at).trim();
|
|
4710
|
+
const value = at === -1 ? "" : pair.slice(at + 1).trim();
|
|
4711
|
+
if (name.length === 0 || value.length === 0 || name === "kind") {
|
|
4712
|
+
throw misuse(`Not a parameter of a service: ${pair}. Say <parameter>=<value>.`);
|
|
4713
|
+
}
|
|
4714
|
+
service[name] = value;
|
|
4715
|
+
}
|
|
4716
|
+
return { role: role, service };
|
|
4717
|
+
}
|
|
2633
4718
|
const WORKSPACE_USAGE = `Say what to do: console workspace | console workspace edit [${WORKSPACE_FLAGS.replaceAll(", ", "] [")}] | console workspace pack-token --connect|--stdin|--remove`;
|
|
2634
4719
|
const workspace = async (args, io) => {
|
|
2635
4720
|
const [verb, ...rest] = args;
|
|
@@ -2647,15 +4732,25 @@ const workspace = async (args, io) => {
|
|
|
2647
4732
|
"week-start": { type: "string" },
|
|
2648
4733
|
"time-zone": { type: "string" },
|
|
2649
4734
|
language: { type: "string" },
|
|
4735
|
+
handle: { type: "string" },
|
|
4736
|
+
domain: { type: "string" },
|
|
4737
|
+
service: { type: "string", multiple: true },
|
|
2650
4738
|
}, false);
|
|
2651
4739
|
const visibility = text(values, "people-visibility");
|
|
2652
4740
|
const weekStart = text(values, "week-start");
|
|
2653
4741
|
const zone = text(values, "time-zone");
|
|
2654
4742
|
const language = text(values, "language");
|
|
4743
|
+
const handle = text(values, "handle");
|
|
4744
|
+
const domain = text(values, "domain");
|
|
4745
|
+
const named = values.service;
|
|
4746
|
+
const services = (Array.isArray(named) ? named : []).map((word) => serviceOf(String(word)));
|
|
2655
4747
|
if (visibility === undefined &&
|
|
2656
4748
|
weekStart === undefined &&
|
|
2657
4749
|
zone === undefined &&
|
|
2658
|
-
language === undefined
|
|
4750
|
+
language === undefined &&
|
|
4751
|
+
handle === undefined &&
|
|
4752
|
+
domain === undefined &&
|
|
4753
|
+
services.length === 0) {
|
|
2659
4754
|
throw misuse(`Say what to change: ${WORKSPACE_FLAGS}`);
|
|
2660
4755
|
}
|
|
2661
4756
|
const session = await open(io, values);
|
|
@@ -2672,6 +4767,13 @@ const workspace = async (args, io) => {
|
|
|
2672
4767
|
? null
|
|
2673
4768
|
: wordOf(language, CONSOLE_LANGUAGES, "a language the console speaks, or none"),
|
|
2674
4769
|
}),
|
|
4770
|
+
...(handle === undefined ? {} : { handle: handle === "none" ? null : handleOf(handle) }),
|
|
4771
|
+
...(domain === undefined ? {} : { domain: domain === "none" ? null : domain.toLowerCase() }),
|
|
4772
|
+
...(services.length === 0
|
|
4773
|
+
? {}
|
|
4774
|
+
: {
|
|
4775
|
+
services: Object.fromEntries(services.map((one) => [one.role, one.service])),
|
|
4776
|
+
}),
|
|
2675
4777
|
});
|
|
2676
4778
|
await rememberZone(io, session, changed.timeZone ?? undefined);
|
|
2677
4779
|
answer(io, session, changed, () => formatWorkspace(changed));
|
|
@@ -2699,7 +4801,7 @@ const workspace = async (args, io) => {
|
|
|
2699
4801
|
}
|
|
2700
4802
|
throw misuse(WORKSPACE_USAGE);
|
|
2701
4803
|
};
|
|
2702
|
-
const PERSON_USAGE =
|
|
4804
|
+
const PERSON_USAGE = 'Say what to do: console person role <login> <admin|member> | person manager <login> <manager login|none> | person email <login> <address|none> | person title <login> "<title>"|none | person add <login> [--host gh|google] | person remove <login> | person deactivate <login> | person reactivate <login>';
|
|
2703
4805
|
const person = async (args, io) => {
|
|
2704
4806
|
const what = args[0];
|
|
2705
4807
|
if (what === "role") {
|
|
@@ -2723,6 +4825,17 @@ const person = async (args, io) => {
|
|
|
2723
4825
|
answer(io, session, changed, () => formatPersonLine(changed));
|
|
2724
4826
|
return EXIT.ok;
|
|
2725
4827
|
}
|
|
4828
|
+
if (what === "title") {
|
|
4829
|
+
const { values, positionals } = parse(args.slice(1), {});
|
|
4830
|
+
const [login, title] = theTwo(positionals, 'Say whom and what they do: console person title <login> "<title>"|none');
|
|
4831
|
+
const session = await open(io, values);
|
|
4832
|
+
const found = await personOf(session, login);
|
|
4833
|
+
const changed = await session.client.updatePerson(found.id, {
|
|
4834
|
+
title: title === "none" ? null : title,
|
|
4835
|
+
});
|
|
4836
|
+
answer(io, session, changed, () => formatPersonLine(changed));
|
|
4837
|
+
return EXIT.ok;
|
|
4838
|
+
}
|
|
2726
4839
|
if (what === "manager") {
|
|
2727
4840
|
const { values, positionals } = parse(args.slice(1), {});
|
|
2728
4841
|
const [login, manager] = theTwo(positionals, "Say whom and whom they report to: console person manager <login> <manager login|none>");
|
|
@@ -3063,6 +5176,8 @@ const COMMANDS = {
|
|
|
3063
5176
|
logout,
|
|
3064
5177
|
whoami,
|
|
3065
5178
|
serve,
|
|
5179
|
+
runner,
|
|
5180
|
+
desk,
|
|
3066
5181
|
projects,
|
|
3067
5182
|
use,
|
|
3068
5183
|
work,
|
|
@@ -3078,6 +5193,11 @@ const COMMANDS = {
|
|
|
3078
5193
|
plugin,
|
|
3079
5194
|
people,
|
|
3080
5195
|
person,
|
|
5196
|
+
manager,
|
|
5197
|
+
agents,
|
|
5198
|
+
agent,
|
|
5199
|
+
secrets,
|
|
5200
|
+
secret,
|
|
3081
5201
|
teams,
|
|
3082
5202
|
team,
|
|
3083
5203
|
workspace,
|
|
@@ -3111,7 +5231,7 @@ function help(io, name) {
|
|
|
3111
5231
|
io.stdout(usage(io.version, io.skillsDir));
|
|
3112
5232
|
return EXIT.ok;
|
|
3113
5233
|
}
|
|
3114
|
-
const found = helpFor(name);
|
|
5234
|
+
const found = helpFor(name, io.skillsDir);
|
|
3115
5235
|
if (found === undefined) {
|
|
3116
5236
|
throw misuse(`Not a command: ${name}. The commands: ${Object.keys(COMMAND_HELP).join(", ")}`);
|
|
3117
5237
|
}
|
|
@@ -3132,7 +5252,8 @@ function clientOf(io, url, token) {
|
|
|
3132
5252
|
}
|
|
3133
5253
|
/** The command that puts the console's version where this command is installed. */
|
|
3134
5254
|
function updateWords(io, version) {
|
|
3135
|
-
|
|
5255
|
+
// What a console says its version is goes into a line someone runs: a version, or `latest`.
|
|
5256
|
+
const wanted = version !== undefined && parseVersion(version) !== undefined ? version : "latest";
|
|
3136
5257
|
if (io.install === undefined) {
|
|
3137
5258
|
return `npm install -g @skillcdn/console@${wanted}`;
|
|
3138
5259
|
}
|
|
@@ -3270,6 +5391,8 @@ function hintFor(error, io, seen) {
|
|
|
3270
5391
|
return "The board keeps at least one administrator in. Make another one first.\n";
|
|
3271
5392
|
case "person.of_organization":
|
|
3272
5393
|
return "The organization says who is in: a person it let in comes and goes with it, and is listed by login to stay.\n";
|
|
5394
|
+
case "agent.login_is_member":
|
|
5395
|
+
return "A member carries that login already, and nothing was changed. Name the login of the agent's own account with --login; or, to make that member the agent account for good, with everything they did, say so with --convert.\n";
|
|
3273
5396
|
case "listing.exists":
|
|
3274
5397
|
return "The login is let in already, or is a person's who is in. console people lists both.\n";
|
|
3275
5398
|
case "listing.not_found":
|
|
@@ -3292,6 +5415,7 @@ export async function runCli(argv, io) {
|
|
|
3292
5415
|
const seen = {};
|
|
3293
5416
|
const watched = {
|
|
3294
5417
|
...io,
|
|
5418
|
+
consoleVersion: () => seen.version,
|
|
3295
5419
|
fetch: async (input, init) => {
|
|
3296
5420
|
const response = await io.fetch(input, init);
|
|
3297
5421
|
seen.version = response.headers.get(VERSION_HEADER) ?? seen.version;
|
|
@@ -3329,6 +5453,10 @@ export async function runCli(argv, io) {
|
|
|
3329
5453
|
io.stderr(`${error.message}\n`);
|
|
3330
5454
|
return error.exit;
|
|
3331
5455
|
}
|
|
5456
|
+
if (error instanceof UnseenProject) {
|
|
5457
|
+
io.stderr(`${error.words}\n`);
|
|
5458
|
+
return EXIT.failed;
|
|
5459
|
+
}
|
|
3332
5460
|
if (error instanceof ApiError) {
|
|
3333
5461
|
io.stderr(`${error.code}: ${error.message}\n${hintFor(error, io, seen)}`);
|
|
3334
5462
|
return error.code === "client.outdated" ||
|