@skillcdn/console 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -11
- package/SKILLCDN.md +3 -3
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +3 -2
- package/dist/agent-page.js.map +1 -1
- package/dist/api.d.ts +7 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +6 -5
- package/dist/api.js.map +1 -1
- package/dist/charts.d.ts +103 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +182 -0
- package/dist/charts.js.map +1 -0
- package/dist/cli/cli.d.ts +26 -2
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +1304 -383
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command-words.d.ts +20 -0
- package/dist/cli/command-words.d.ts.map +1 -0
- package/dist/cli/command-words.js +51 -0
- package/dist/cli/command-words.js.map +1 -0
- package/dist/cli/credentials.d.ts +54 -5
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +126 -20
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/directory.d.ts +19 -4
- package/dist/cli/directory.d.ts.map +1 -1
- package/dist/cli/directory.js +16 -8
- package/dist/cli/directory.js.map +1 -1
- package/dist/cli/format.d.ts +65 -8
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +242 -37
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +13 -4
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +92 -54
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +76 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/pack.d.ts +69 -60
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +241 -270
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +42 -0
- package/dist/cli/plugin-check.d.ts.map +1 -1
- package/dist/cli/plugin-check.js +221 -36
- package/dist/cli/plugin-check.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts +6 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +21 -4
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/plugin-main.js +1 -0
- package/dist/cli/plugin-main.js.map +1 -1
- package/dist/cli/serve.d.ts +33 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +252 -3
- package/dist/cli/serve.js.map +1 -1
- package/dist/client.d.ts +48 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +72 -80
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +64 -1
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +244 -96
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/charts.d.ts +157 -0
- package/dist/components/charts.d.ts.map +1 -0
- package/dist/components/charts.js +182 -0
- package/dist/components/charts.js.map +1 -0
- package/dist/components/desk-records.d.ts +102 -0
- package/dist/components/desk-records.d.ts.map +1 -0
- package/dist/components/desk-records.js +221 -0
- package/dist/components/desk-records.js.map +1 -0
- package/dist/components/desk.d.ts +85 -0
- package/dist/components/desk.d.ts.map +1 -0
- package/dist/components/desk.js +135 -0
- package/dist/components/desk.js.map +1 -0
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +4 -1
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +4 -2
- package/dist/components/home.js.map +1 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +54 -3
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.d.ts.map +1 -1
- package/dist/components/projects.js +27 -7
- package/dist/components/projects.js.map +1 -1
- package/dist/components/rules.d.ts +8 -10
- package/dist/components/rules.d.ts.map +1 -1
- package/dist/components/rules.js +35 -13
- package/dist/components/rules.js.map +1 -1
- package/dist/components/setup.d.ts +9 -3
- package/dist/components/setup.d.ts.map +1 -1
- package/dist/components/setup.js +10 -4
- package/dist/components/setup.js.map +1 -1
- package/dist/console.css +677 -7
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +14 -8
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +32 -33
- package/dist/data.js.map +1 -1
- package/dist/desk-page.d.ts +38 -0
- package/dist/desk-page.d.ts.map +1 -0
- package/dist/desk-page.js +184 -0
- package/dist/desk-page.js.map +1 -0
- package/dist/desk-records-page.d.ts +18 -0
- package/dist/desk-records-page.d.ts.map +1 -0
- package/dist/desk-records-page.js +130 -0
- package/dist/desk-records-page.js.map +1 -0
- package/dist/desk-records.d.ts +247 -0
- package/dist/desk-records.d.ts.map +1 -0
- package/dist/desk-records.js +543 -0
- package/dist/desk-records.js.map +1 -0
- package/dist/desk.d.ts +122 -0
- package/dist/desk.d.ts.map +1 -0
- package/dist/desk.js +211 -0
- package/dist/desk.js.map +1 -0
- package/dist/feed-stream.d.ts +39 -0
- package/dist/feed-stream.d.ts.map +1 -0
- package/dist/feed-stream.js +117 -0
- package/dist/feed-stream.js.map +1 -0
- package/dist/home-tiles.d.ts +10 -3
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +54 -31
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +180 -5
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +184 -7
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +169 -6
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +11 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +11 -0
- package/dist/limits.js.map +1 -1
- package/dist/onboarding.d.ts +6 -0
- package/dist/onboarding.d.ts.map +1 -1
- package/dist/onboarding.js +3 -3
- package/dist/onboarding.js.map +1 -1
- package/dist/plugin/context.d.ts +42 -11
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +2 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +2 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/manifest.d.ts +13 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +30 -3
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +55 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +37 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +4 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/testing.d.ts +6 -2
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +52 -10
- package/dist/plugin/testing.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/records.d.ts +283 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +543 -0
- package/dist/records.js.map +1 -0
- package/dist/routes.d.ts +3 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +3 -1
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +30 -11
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +98 -45
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts +1 -1
- package/dist/runner/acp.d.ts.map +1 -1
- package/dist/runner/acp.js +31 -20
- package/dist/runner/acp.js.map +1 -1
- package/dist/runner/claude.d.ts +1 -1
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +85 -15
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts +1 -1
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +19 -16
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/desk.d.ts +43 -2
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +166 -10
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/process.d.ts.map +1 -1
- package/dist/runner/process.js +11 -4
- package/dist/runner/process.js.map +1 -1
- package/dist/runner/redact.d.ts +39 -4
- package/dist/runner/redact.d.ts.map +1 -1
- package/dist/runner/redact.js +81 -5
- package/dist/runner/redact.js.map +1 -1
- package/dist/runner/runner.d.ts +15 -1
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +231 -33
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/task-scheduler.d.ts +20 -0
- package/dist/runner/task-scheduler.d.ts.map +1 -1
- package/dist/runner/task-scheduler.js +34 -4
- package/dist/runner/task-scheduler.js.map +1 -1
- package/dist/runner/types.d.ts +36 -1
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js +17 -0
- package/dist/runner/types.js.map +1 -1
- package/dist/runner.d.ts +6 -6
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +5 -5
- package/dist/runner.js.map +1 -1
- package/dist/schemas.d.ts +509 -5
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +76 -16
- package/dist/schemas.js.map +1 -1
- package/dist/services.d.ts +22 -5
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +35 -15
- package/dist/services.js.map +1 -1
- package/dist/setup-guide.d.ts +3 -1
- package/dist/setup-guide.d.ts.map +1 -1
- package/dist/setup-guide.js +7 -4
- package/dist/setup-guide.js.map +1 -1
- package/dist/vocabulary.d.ts +14 -3
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +13 -3
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +64 -38
- package/docs/specs/plugins.md +27 -20
- package/docs/specs/records.md +113 -0
- package/docs/specs/rest.md +20 -13
- package/docs/specs/runner.md +23 -17
- package/package.json +7 -2
- package/skills/building-a-console/SKILL.md +4 -4
- package/skills/building-a-plugin/SKILL.md +6 -6
- package/skills/deploying-a-console/SKILL.md +4 -4
- package/skills/deploying-a-console/references/resources.md +41 -4
- package/skills/deploying-a-console/references/running-it-again.md +3 -2
- package/skills/keeping-a-desk/SKILL.md +133 -0
- package/skills/keeping-a-desk/collections.md +96 -0
- package/skills/planning-the-board/SKILL.md +14 -18
- package/skills/planning-the-board/references/a-task.md +2 -2
- package/skills/planning-the-board/references/project-rules.md +13 -14
- package/skills/planning-the-board/references/setting-up.md +15 -13
- package/skills/running-an-agent/SKILL.md +10 -9
- package/skills/working-the-board/SKILL.md +62 -44
- package/skills/working-the-board/references/terms.md +9 -5
- package/skills/working-the-board/references/the-pack.md +12 -10
- package/skills/working-the-board/references/the-sentence.md +2 -2
- package/src/agent-page.tsx +3 -1
- package/src/api.ts +77 -2
- package/src/charts.ts +250 -0
- package/src/cli/cli.ts +1698 -476
- package/src/cli/command-words.ts +56 -0
- package/src/cli/credentials.ts +181 -20
- package/src/cli/directory.ts +28 -10
- package/src/cli/format.ts +301 -46
- package/src/cli/help.ts +102 -54
- package/src/cli/main.ts +72 -2
- package/src/cli/pack.ts +333 -372
- package/src/cli/plugin-check.ts +275 -34
- package/src/cli/plugin-cli.ts +28 -4
- package/src/cli/plugin-main.ts +1 -0
- package/src/cli/serve.ts +295 -2
- package/src/client.ts +192 -177
- package/src/components/agent-page.tsx +489 -243
- package/src/components/charts.tsx +680 -0
- package/src/components/desk-records.tsx +724 -0
- package/src/components/desk.tsx +471 -0
- package/src/components/event-feed.tsx +5 -1
- package/src/components/home.tsx +12 -0
- package/src/components/plugin-settings.tsx +171 -12
- package/src/components/projects.tsx +29 -12
- package/src/components/rules.tsx +94 -34
- package/src/components/setup.tsx +18 -3
- package/src/console.tsx +17 -9
- package/src/data.ts +37 -34
- package/src/desk-page.tsx +332 -0
- package/src/desk-records-page.tsx +256 -0
- package/src/desk-records.ts +808 -0
- package/src/desk.ts +329 -0
- package/src/feed-stream.ts +144 -0
- package/src/home-tiles.ts +55 -35
- package/src/i18n/en.ts +196 -9
- package/src/i18n/ko.ts +178 -8
- package/src/index.ts +118 -0
- package/src/limits.ts +11 -0
- package/src/onboarding.ts +12 -4
- package/src/plugin/context.ts +55 -12
- package/src/plugin/limits.ts +2 -0
- package/src/plugin/manifest.ts +38 -2
- package/src/plugin/rest-schemas.ts +41 -0
- package/src/plugin/sandbox.ts +4 -1
- package/src/plugin/testing.ts +63 -12
- package/src/plugin.ts +2 -0
- package/src/records.ts +702 -0
- package/src/routes.ts +3 -1
- package/src/rules.ts +108 -47
- package/src/runner/acp.ts +47 -29
- package/src/runner/claude.ts +113 -23
- package/src/runner/codex.ts +35 -25
- package/src/runner/desk.ts +198 -12
- package/src/runner/process.ts +11 -4
- package/src/runner/redact.ts +92 -6
- package/src/runner/runner.ts +275 -34
- package/src/runner/task-scheduler.ts +36 -4
- package/src/runner/types.ts +47 -1
- package/src/runner.ts +27 -2
- package/src/schemas.ts +83 -15
- package/src/services.ts +49 -14
- package/src/setup-guide.ts +6 -2
- package/src/styles/README.md +11 -1
- package/src/styles/console.css +9 -0
- package/src/styles/pages/desk.css +126 -0
- package/src/styles/pages/documents.css +5 -0
- package/src/styles/parts/bars.css +80 -0
- package/src/styles/parts/chart.css +173 -0
- package/src/styles/parts/figures.css +65 -0
- package/src/styles/parts/legend.css +48 -0
- package/src/styles/parts/series.css +32 -0
- package/src/styles/parts/share.css +25 -0
- package/src/styles/parts/spark.css +23 -0
- package/src/styles/parts/stat.css +69 -0
- package/src/styles/tokens.css +13 -7
- package/src/vocabulary.ts +16 -3
- package/template/desk-web/README.md +8 -0
- package/template/desk-web/index.html +13 -0
- package/template/desk-web/package.json +25 -0
- package/template/desk-web/src/main.tsx +24 -0
- package/template/desk-web/src/page.tsx +51 -0
- package/template/desk-web/tsconfig.json +16 -0
- package/template/desk-web/vite.config.ts +15 -0
package/dist/cli/cli.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { basename, extname } from "node:path";
|
|
1
|
+
import { basename, extname, isAbsolute } from "node:path";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
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";
|
|
4
6
|
import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
|
|
5
7
|
import { ApiError, createClient, } from "../client.js";
|
|
6
8
|
import { CLIENT_RANGE_HEADER, CONSOLE_AT_LEAST, consoleRange, formatRange, judgeClient, judgeConsole, parseVersion, VERSION_HEADER, formatVersion as versionText, } from "../compat.js";
|
|
7
9
|
import { normalizeConnectCode } from "../connect.js";
|
|
8
10
|
import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
|
|
9
|
-
import { DEFAULT_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, 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";
|
|
10
12
|
import { capabilityWords } from "../plugin/capabilities.js";
|
|
11
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";
|
|
12
16
|
import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
|
|
13
17
|
import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
|
|
14
|
-
import { deskFiles, deskServicesOf } from "../runner/desk.js";
|
|
18
|
+
import { DESK_FOLDER, deskFiles, deskServicesOf, deskWebTitleOf, personDeskFiles, } from "../runner/desk.js";
|
|
15
19
|
import { ownRunnerModules } from "../runner/modules.js";
|
|
16
20
|
import { createRunner, GIT_TOKEN_SECRET } from "../runner/runner.js";
|
|
17
21
|
import { hostOfLogin, } from "../schemas.js";
|
|
@@ -19,14 +23,15 @@ import { agentLoginOf, deskRemoteOf } from "../services.js";
|
|
|
19
23
|
import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
|
|
20
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";
|
|
21
25
|
import { loadWebRoot, WebRootError } from "../web.js";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
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";
|
|
25
30
|
import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
|
|
26
31
|
import { describeInstall, updateCommandFor } from "./install.js";
|
|
27
|
-
import {
|
|
32
|
+
import { consolePack, formatSkills, holdsNothing, ORGANIZATION_PACK_LINE, PackRefusal, packWords, refusalWords, skillPathIn, } from "./pack.js";
|
|
28
33
|
import { workPath } from "./runner-host.js";
|
|
29
|
-
import { createServeHandler, DEFAULT_SERVE_PORT } from "./serve.js";
|
|
34
|
+
import { createServeHandler, DEFAULT_SERVE_PORT, loadRecordsRoot, RecordsRootError, } from "./serve.js";
|
|
30
35
|
// The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
|
|
31
36
|
// the REST API with no logic of its own: every command is one or two requests and the words to
|
|
32
37
|
// say what came back. It takes what it needs from `CliIo`, so that tests run it whole, against
|
|
@@ -39,7 +44,7 @@ export const EXIT = {
|
|
|
39
44
|
failed: 1,
|
|
40
45
|
/** The command was not understood. */
|
|
41
46
|
usage: 2,
|
|
42
|
-
/**
|
|
47
|
+
/** What was waited for still waits for a person: a decision's answer, or a connection's approval. */
|
|
43
48
|
waiting: 3,
|
|
44
49
|
/** The command and the console do not go together (ADR-0025): stderr says which to update, and how. */
|
|
45
50
|
incompatible: 4,
|
|
@@ -54,6 +59,12 @@ const WAIT_PAUSE_MS = 500;
|
|
|
54
59
|
const DEFAULT_ASK_WAIT_SECONDS = 60;
|
|
55
60
|
/** The longest wait a person may ask for: a day. */
|
|
56
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;
|
|
57
68
|
/** The command stops with an exit code and a word on stderr. */
|
|
58
69
|
class CliExit extends Error {
|
|
59
70
|
exit;
|
|
@@ -104,6 +115,79 @@ const texts = (values, name) => {
|
|
|
104
115
|
}
|
|
105
116
|
return typeof value === "string" ? [value] : [];
|
|
106
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
|
+
}
|
|
107
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.";
|
|
108
192
|
/** What the command keeps, or nothing; a file that cannot be read stops the command, and is never written over. */
|
|
109
193
|
async function loadCredentials(io) {
|
|
@@ -117,6 +201,18 @@ async function loadCredentials(io) {
|
|
|
117
201
|
throw error;
|
|
118
202
|
}
|
|
119
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
|
+
}
|
|
120
216
|
/** The console a directory is bound to, as an origin, when it names one. */
|
|
121
217
|
function directoryOrigin(settings) {
|
|
122
218
|
if (settings?.url === undefined) {
|
|
@@ -177,7 +273,19 @@ async function open(io, values) {
|
|
|
177
273
|
?.timeZone
|
|
178
274
|
: undefined);
|
|
179
275
|
const client = clientOf(io, url, token);
|
|
180
|
-
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;
|
|
181
289
|
return {
|
|
182
290
|
client,
|
|
183
291
|
url,
|
|
@@ -187,12 +295,17 @@ async function open(io, values) {
|
|
|
187
295
|
credentials,
|
|
188
296
|
json: on(values, "json"),
|
|
189
297
|
projectKey,
|
|
298
|
+
projectNamed,
|
|
190
299
|
async project() {
|
|
191
|
-
const
|
|
192
|
-
if (
|
|
300
|
+
const named = projectNamed();
|
|
301
|
+
if (named === undefined) {
|
|
193
302
|
throw failed(NO_PROJECT);
|
|
194
303
|
}
|
|
195
|
-
|
|
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));
|
|
196
309
|
},
|
|
197
310
|
};
|
|
198
311
|
}
|
|
@@ -201,21 +314,57 @@ function answer(io, session, value, words) {
|
|
|
201
314
|
io.stdout(session.json ? `${JSON.stringify(value, null, 2)}\n` : `${words()}\n`);
|
|
202
315
|
}
|
|
203
316
|
/** The run a command on a run means: the one named, else the one open run of this token in the project. */
|
|
204
|
-
async function currentRun(project, values) {
|
|
317
|
+
async function currentRun(session, project, values) {
|
|
205
318
|
const given = text(values, "run");
|
|
206
319
|
if (given !== undefined) {
|
|
207
320
|
return given;
|
|
208
321
|
}
|
|
209
|
-
|
|
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 });
|
|
210
325
|
const [only] = items;
|
|
211
326
|
if (only !== undefined && items.length === 1) {
|
|
212
327
|
return only.id;
|
|
213
328
|
}
|
|
214
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
|
+
}
|
|
215
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>");
|
|
216
344
|
}
|
|
217
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")}`);
|
|
218
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
|
+
}
|
|
219
368
|
/** A Markdown body: from `--file`, from standard input for `-`, or as given. */
|
|
220
369
|
async function bodyOf(io, values, given) {
|
|
221
370
|
const file = text(values, "file");
|
|
@@ -410,7 +559,9 @@ const stillWaiting = (id) => `Decision ${id} still waits for a person; the run w
|
|
|
410
559
|
* Waits for the answer and says what it is, or that it is still to come. On `--json`, a decision
|
|
411
560
|
* printed already as it was raised (`shown`) is printed again only with its answer.
|
|
412
561
|
*/
|
|
413
|
-
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) {
|
|
414
565
|
const outcome = decision.answer === null && seconds > 0
|
|
415
566
|
? await waitForAnswer(io, project, decision, seconds)
|
|
416
567
|
: decision;
|
|
@@ -420,10 +571,36 @@ async function settle(io, session, project, decision, seconds, shown = false) {
|
|
|
420
571
|
}
|
|
421
572
|
}
|
|
422
573
|
else {
|
|
423
|
-
io.stdout(`${outcome.answer === null ? stillWaiting(outcome.id) : formatAnswer(outcome)}\n`);
|
|
574
|
+
io.stdout(`${outcome.answer === null ? (waiting ?? stillWaiting(outcome.id)) : formatAnswer(outcome)}\n`);
|
|
424
575
|
}
|
|
425
576
|
return outcome.answer === null ? EXIT.waiting : EXIT.ok;
|
|
426
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
|
+
}
|
|
427
604
|
/**
|
|
428
605
|
* Who the command is, in a few words: the login and the role, and an agent account by its
|
|
429
606
|
* handle first, which is what it is called by everywhere and what its setup's guide says the
|
|
@@ -449,12 +626,6 @@ say = io.stdout) {
|
|
|
449
626
|
throw failed("The console does not know this token. Make one on your Agents page and try again.");
|
|
450
627
|
}
|
|
451
628
|
const credentials = (await loadCredentials(io)) ?? EMPTY_CREDENTIALS;
|
|
452
|
-
const replaced = loginsAt(credentials, url).find((login) => login.account === person.login);
|
|
453
|
-
if (replaced !== undefined && replaced.token !== token) {
|
|
454
|
-
await clientOf(io, url, replaced.token)
|
|
455
|
-
.giveUpToken()
|
|
456
|
-
.catch(() => undefined);
|
|
457
|
-
}
|
|
458
629
|
const next = withLogin(credentials, {
|
|
459
630
|
url,
|
|
460
631
|
account: person.login,
|
|
@@ -463,12 +634,29 @@ say = io.stdout) {
|
|
|
463
634
|
since: new Date(io.now()).toISOString(),
|
|
464
635
|
...(self ? { self: true } : {}),
|
|
465
636
|
timeZone: me.workspace.timeZone ?? undefined,
|
|
466
|
-
}, { default: asDefault });
|
|
467
|
-
|
|
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);
|
|
468
649
|
const standing = next.default === url ? ", the default console here" : "";
|
|
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}`;
|
|
469
657
|
say(self
|
|
470
|
-
? `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
|
|
471
|
-
: `${agent === undefined ? "Signed in" : `Connected as "${agent}"`} to ${me.workspace.name} at ${url} as ${whoOf(person)}${standing}. The token is kept
|
|
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`);
|
|
472
660
|
return EXIT.ok;
|
|
473
661
|
}
|
|
474
662
|
const login = async (args, io) => {
|
|
@@ -477,6 +665,7 @@ const login = async (args, io) => {
|
|
|
477
665
|
agent: { type: "string" },
|
|
478
666
|
self: { type: "boolean" },
|
|
479
667
|
default: { type: "boolean" },
|
|
668
|
+
wait: { type: "string" },
|
|
480
669
|
}, false);
|
|
481
670
|
const credentials = await loadCredentials(io);
|
|
482
671
|
const wanted = text(values, "url") ?? io.env.CONSOLE_URL ?? credentials?.default;
|
|
@@ -495,36 +684,150 @@ const login = async (args, io) => {
|
|
|
495
684
|
// A connection (ADR-0011): a code a person approves on the console's own pages, and the token
|
|
496
685
|
// handed over here once, never shown.
|
|
497
686
|
const client = clientOf(io, url);
|
|
498
|
-
// "<agent> on <machine>": the pages say the agent and keep the machine for a hover.
|
|
499
|
-
const agent = text(values, "agent") ?? agentOf(io.env) ?? "An agent";
|
|
500
687
|
// With --self the command asks to be the account itself (ADR-0084): whoever approves says
|
|
501
688
|
// "this is me", and what is handed over is a session of the command's, in place of a token.
|
|
502
689
|
const self = on(values, "self");
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
io.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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;
|
|
515
712
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
+
}
|
|
732
|
+
for (;;) {
|
|
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));
|
|
519
755
|
}
|
|
520
|
-
throw error;
|
|
521
756
|
}
|
|
522
|
-
|
|
523
|
-
|
|
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`);
|
|
524
777
|
}
|
|
525
|
-
if (
|
|
526
|
-
return
|
|
778
|
+
if (told) {
|
|
779
|
+
return EXIT.ok;
|
|
527
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);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
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;
|
|
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;
|
|
528
831
|
}
|
|
529
832
|
};
|
|
530
833
|
const logout = async (args, io) => {
|
|
@@ -537,7 +840,15 @@ const logout = async (args, io) => {
|
|
|
537
840
|
}
|
|
538
841
|
};
|
|
539
842
|
if (credentials === undefined || credentials.logins.length === 0) {
|
|
540
|
-
|
|
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
|
+
}
|
|
541
852
|
envNote();
|
|
542
853
|
return EXIT.ok;
|
|
543
854
|
}
|
|
@@ -558,7 +869,16 @@ const logout = async (args, io) => {
|
|
|
558
869
|
const chosen = account === undefined ? at : at.filter((login) => login.account === account);
|
|
559
870
|
const [login] = chosen;
|
|
560
871
|
if (login === undefined) {
|
|
561
|
-
|
|
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.`);
|
|
562
882
|
}
|
|
563
883
|
if (chosen.length > 1) {
|
|
564
884
|
throw failed(`Several accounts are signed in at ${url} (${chosen.map((kept) => kept.account ?? "?").join(", ")}); say which: console logout --url ${url} --account <login>`);
|
|
@@ -580,8 +900,10 @@ const logout = async (args, io) => {
|
|
|
580
900
|
outcome = "left";
|
|
581
901
|
}
|
|
582
902
|
}
|
|
583
|
-
|
|
584
|
-
|
|
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)) {
|
|
585
907
|
await io.store.clear();
|
|
586
908
|
}
|
|
587
909
|
else {
|
|
@@ -609,17 +931,36 @@ const logins = async (args, io) => {
|
|
|
609
931
|
since: login.since ?? null,
|
|
610
932
|
default: credentials?.default === login.url,
|
|
611
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
|
+
}));
|
|
612
944
|
if (on(values, "json")) {
|
|
613
|
-
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`);
|
|
614
950
|
return EXIT.ok;
|
|
615
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
|
+
}
|
|
616
960
|
if (kept.length === 0) {
|
|
617
|
-
|
|
618
|
-
return EXIT.ok;
|
|
961
|
+
lines.unshift("Not signed in anywhere here: console login --url <the console's origin>");
|
|
619
962
|
}
|
|
620
|
-
io.stdout(`${
|
|
621
|
-
.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)" : ""}`)
|
|
622
|
-
.join("\n")}\n`);
|
|
963
|
+
io.stdout(`${lines.join("\n")}\n`);
|
|
623
964
|
return EXIT.ok;
|
|
624
965
|
};
|
|
625
966
|
/** The agent the command runs under, where its environment says so: what a connection is named by default. */
|
|
@@ -645,7 +986,8 @@ async function rememberZone(io, session, zone) {
|
|
|
645
986
|
if (kept === undefined || kept.timeZone === zone) {
|
|
646
987
|
return;
|
|
647
988
|
}
|
|
648
|
-
|
|
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));
|
|
649
991
|
}
|
|
650
992
|
const whoami = async (args, io) => {
|
|
651
993
|
const { values } = parse(args, {}, false);
|
|
@@ -656,7 +998,29 @@ const whoami = async (args, io) => {
|
|
|
656
998
|
throw failed("The console does not know this token. Sign in again: console login");
|
|
657
999
|
}
|
|
658
1000
|
await rememberZone(io, session, me.workspace.timeZone ?? undefined);
|
|
659
|
-
|
|
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)}`;
|
|
660
1024
|
const command = parseVersion(io.version);
|
|
661
1025
|
const server = parseVersion(me.console?.version);
|
|
662
1026
|
const verdict = command === undefined || server === undefined
|
|
@@ -673,14 +1037,21 @@ const whoami = async (args, io) => {
|
|
|
673
1037
|
...me,
|
|
674
1038
|
console: me.console ?? null,
|
|
675
1039
|
project: key ?? null,
|
|
1040
|
+
projectName: projectName ?? null,
|
|
1041
|
+
projectSource: named?.source ?? null,
|
|
676
1042
|
command: { version: io.version ?? null, install: io.install ?? null },
|
|
677
1043
|
}, () => [
|
|
678
|
-
`${whoOf(person)} at ${me.workspace.name}, ${session.url}${
|
|
679
|
-
// The
|
|
680
|
-
//
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
|
|
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)}`,
|
|
684
1055
|
`This command is ${io.version ?? "of a version it does not know"}${io.install === undefined ? "" : `, ${describeInstall(io.install)}`}; ${consoleWords}.`,
|
|
685
1056
|
...(verdict === "behind"
|
|
686
1057
|
? [`A newer command exists. Update it: ${updateWords(io, me.console?.version)}`]
|
|
@@ -690,6 +1061,11 @@ const whoami = async (args, io) => {
|
|
|
690
1061
|
]
|
|
691
1062
|
: []),
|
|
692
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
|
+
}
|
|
693
1069
|
return EXIT.ok;
|
|
694
1070
|
};
|
|
695
1071
|
const projects = async (args, io) => {
|
|
@@ -706,23 +1082,21 @@ const use = async (args, io) => {
|
|
|
706
1082
|
const key = theOne(positionals, "Say which project: console use <key> [--url <origin>] [--account <login>]");
|
|
707
1083
|
const session = await open(io, values);
|
|
708
1084
|
const project = await session.client.project(key).get();
|
|
709
|
-
// The directory names the console
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const pinAccount =
|
|
715
|
-
(
|
|
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);
|
|
716
1092
|
const kept = await io.directory.save({
|
|
717
1093
|
project: project.key,
|
|
718
|
-
|
|
719
|
-
...(pinAccount
|
|
1094
|
+
url: session.url,
|
|
1095
|
+
...(pinAccount ? { account: session.account } : {}),
|
|
720
1096
|
});
|
|
721
|
-
const bound =
|
|
722
|
-
? ` at ${session.url}${pinAccount && session.account !== undefined ? ` as ${session.account}` : ""}`
|
|
723
|
-
: "";
|
|
1097
|
+
const bound = ` at ${session.url}${pinAccount ? ` as ${session.account}` : ""}`;
|
|
724
1098
|
answer(io, session, project, () => [
|
|
725
|
-
`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.`,
|
|
726
1100
|
// Nothing sends an agent to the console until the checkout says so; the sentence is the
|
|
727
1101
|
// skill's (references/the-sentence.md), printed here as `skillcdn use` prints its own.
|
|
728
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:",
|
|
@@ -782,7 +1156,7 @@ const tasks = async (args, io) => {
|
|
|
782
1156
|
if (search === "") {
|
|
783
1157
|
throw misuse("Say what to search for: console tasks --search <words>");
|
|
784
1158
|
}
|
|
785
|
-
const
|
|
1159
|
+
const filter = {
|
|
786
1160
|
...(state === undefined ? {} : { state }),
|
|
787
1161
|
...(on(values, "open") || due === "overdue" ? { open: true } : {}),
|
|
788
1162
|
...(worker === undefined ? {} : { worker }),
|
|
@@ -793,9 +1167,20 @@ const tasks = async (args, io) => {
|
|
|
793
1167
|
...(search === undefined ? {} : { q: search }),
|
|
794
1168
|
...(on(values, "archived") ? { archived: true } : {}),
|
|
795
1169
|
...page,
|
|
796
|
-
}
|
|
797
|
-
|
|
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
|
|
798
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
|
|
799
1184
|
: found.items.map(formatTaskLine).join("\n") +
|
|
800
1185
|
formatMore(found.more, page.limit, page.offset));
|
|
801
1186
|
return EXIT.ok;
|
|
@@ -822,321 +1207,378 @@ const categories = async (args, io) => {
|
|
|
822
1207
|
answer(io, session, found, () => found.items.length === 0 ? "No categories." : found.items.map(formatCategoryLine).join("\n"));
|
|
823
1208
|
return EXIT.ok;
|
|
824
1209
|
};
|
|
825
|
-
/** How many pages of a skill, of a file or of a folder the command follows before it stops: far above what one holds. */
|
|
826
|
-
const MAX_SKILL_PAGES = 64;
|
|
827
|
-
/** How many results a search answers at most: what the deployment allows on one page. */
|
|
828
|
-
const MAX_FIND_LIMIT = 25;
|
|
829
|
-
/** How many rows, and how many code blocks, one page of a read as data is asked to end after: the most the console takes. */
|
|
830
|
-
const DATA_PAGE_ROWS = 5000;
|
|
831
|
-
const DATA_PAGE_BLOCKS = 500;
|
|
832
|
-
/** The pack of the project as the console lists it, and what its reads are rendered at; none when the pack did not answer. */
|
|
833
|
-
async function packOf(reader) {
|
|
834
|
-
const listing = await reader.skills();
|
|
835
|
-
return { listing, summary: summaryOf(listing) };
|
|
836
|
-
}
|
|
837
1210
|
const SKILLS_OPTIONS = {
|
|
838
1211
|
search: { type: "string" },
|
|
1212
|
+
path: { type: "string" },
|
|
839
1213
|
limit: { type: "string" },
|
|
840
1214
|
cursor: { type: "string" },
|
|
841
1215
|
rows: { type: "boolean" },
|
|
842
1216
|
code: { type: "boolean" },
|
|
843
1217
|
heading: { type: "string" },
|
|
1218
|
+
format: { type: "string" },
|
|
1219
|
+
grep: { type: "string" },
|
|
844
1220
|
out: { type: "string" },
|
|
845
1221
|
};
|
|
846
1222
|
/**
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
* as
|
|
850
|
-
*
|
|
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.
|
|
851
1227
|
*/
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
answer(io, session, { path: saved, summary }, () => `Saved ${summary} at ${saved}`);
|
|
869
|
-
return EXIT.ok;
|
|
870
|
-
};
|
|
871
|
-
if (asked.what === "rows") {
|
|
872
|
-
const pages = [];
|
|
873
|
-
let next;
|
|
874
|
-
for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
|
|
875
|
-
const page = await reader.skillRows({
|
|
876
|
-
path: asked.path,
|
|
877
|
-
heading: asked.heading,
|
|
878
|
-
cursor: next,
|
|
879
|
-
limit: DATA_PAGE_ROWS,
|
|
880
|
-
});
|
|
881
|
-
const refusal = dataRefusal("tables", page);
|
|
882
|
-
if (refusal !== undefined) {
|
|
883
|
-
throw failed(refusal);
|
|
884
|
-
}
|
|
885
|
-
pages.push(page);
|
|
886
|
-
next = page.read?.status === "ready" ? (page.read.nextCursor ?? undefined) : undefined;
|
|
887
|
-
if (next === undefined) {
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
const whole = joinRows(pages);
|
|
892
|
-
const last = pages[pages.length - 1];
|
|
893
|
-
if (whole === undefined || last === undefined) {
|
|
894
|
-
throw failed("The tables could not be read.");
|
|
895
|
-
}
|
|
896
|
-
if (next !== undefined) {
|
|
897
|
-
throw failed(`The tables under ${where} are more than the command reads at once (${describeRows(whole)} so far): name a folder or a file under it.`);
|
|
898
|
-
}
|
|
899
|
-
if (whole.tables.length === 0 && !session.json) {
|
|
900
|
-
io.stdout(`No tables in ${where}${asked.heading === undefined ? "" : " under that heading"}.\n`);
|
|
901
|
-
return EXIT.ok;
|
|
902
|
-
}
|
|
903
|
-
return give({ ...last, read: whole }, csvOfRows(whole), describeRows(whole), "rows.csv");
|
|
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}`);
|
|
904
1244
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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,
|
|
913
1283
|
});
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1284
|
+
}
|
|
1285
|
+
catch (error) {
|
|
1286
|
+
if (error instanceof ReadMisuse) {
|
|
1287
|
+
throw misuse(error.message);
|
|
917
1288
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
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;
|
|
922
1296
|
}
|
|
1297
|
+
throw options.data === true || refusal.answer === undefined
|
|
1298
|
+
? failed(refusal.words)
|
|
1299
|
+
: refusedRead(io, session, owner, refusal.answer, refusal.words);
|
|
923
1300
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
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;
|
|
928
1332
|
}
|
|
929
|
-
|
|
930
|
-
|
|
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);
|
|
931
1337
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return EXIT.ok;
|
|
1338
|
+
catch {
|
|
1339
|
+
throw failed(`The file could not be written at ${asked.out}.`);
|
|
935
1340
|
}
|
|
936
|
-
|
|
1341
|
+
io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
|
|
1342
|
+
return EXIT.ok;
|
|
937
1343
|
}
|
|
938
1344
|
const SKILL_OPTIONS = {
|
|
939
1345
|
file: { type: "string" },
|
|
940
1346
|
offset: { type: "string" },
|
|
941
1347
|
limit: { type: "string" },
|
|
1348
|
+
cursor: { type: "string" },
|
|
942
1349
|
};
|
|
943
1350
|
/** The line `console skills` ends with: where the plugins' own skills are. */
|
|
944
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.";
|
|
945
1352
|
/**
|
|
946
|
-
* The pack as the words say: whole, a folder of
|
|
947
|
-
* 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).
|
|
948
1357
|
*/
|
|
949
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.`;
|
|
950
1367
|
if (positionals.length > 1) {
|
|
951
1368
|
throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
|
|
952
1369
|
}
|
|
953
1370
|
// The root of the pack is the mounted folder, which the deployment reads as no path at all.
|
|
954
1371
|
const given = positionals[0];
|
|
955
|
-
const folder = given === undefined || given === "/" || given === "." ? undefined : given;
|
|
956
1372
|
const words = text(values, "search");
|
|
1373
|
+
const within = text(values, "path");
|
|
957
1374
|
const limit = text(values, "limit");
|
|
958
1375
|
const cursor = text(values, "cursor");
|
|
959
1376
|
const rows = on(values, "rows");
|
|
960
1377
|
const code = on(values, "code");
|
|
961
1378
|
const heading = text(values, "heading");
|
|
962
1379
|
const out = text(values, "out");
|
|
1380
|
+
const format = text(values, "format");
|
|
1381
|
+
const grep = text(values, "grep");
|
|
963
1382
|
const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
|
|
964
1383
|
if (rows && code) {
|
|
965
1384
|
throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
|
|
966
1385
|
}
|
|
967
|
-
if ((rows || code) &&
|
|
1386
|
+
if ((rows || code) &&
|
|
1387
|
+
(words !== undefined || within !== undefined || limit !== undefined || cursor !== undefined)) {
|
|
968
1388
|
throw misuse(`--rows and --code read a folder or a file whole, and go without --search: ${dataUsage}`);
|
|
969
1389
|
}
|
|
970
1390
|
if (!rows && !code && (heading !== undefined || out !== undefined)) {
|
|
971
1391
|
throw misuse(`--heading and --out go with --rows or --code: ${dataUsage}`);
|
|
972
1392
|
}
|
|
973
|
-
if (
|
|
974
|
-
throw misuse(`--
|
|
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>]`);
|
|
975
1398
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
throw misuse(
|
|
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>]`);
|
|
980
1403
|
}
|
|
981
|
-
|
|
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.
|
|
982
1422
|
if (rows || code) {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
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 },
|
|
987
1430
|
out,
|
|
1431
|
+
owner,
|
|
1432
|
+
words: toolWords,
|
|
988
1433
|
});
|
|
989
1434
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
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]
|
|
994
1447
|
.filter((part) => part !== undefined)
|
|
995
1448
|
.join("\n"));
|
|
996
1449
|
return EXIT.ok;
|
|
997
1450
|
}
|
|
998
1451
|
if (words !== undefined) {
|
|
999
1452
|
// One page of what the words find; more is said, and asked for with --cursor.
|
|
1000
|
-
const found = await
|
|
1001
|
-
|
|
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}`);
|
|
1002
1455
|
return EXIT.ok;
|
|
1003
1456
|
}
|
|
1004
|
-
//
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
}
|
|
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();
|
|
1018
1481
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
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;
|
|
1021
1487
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
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());
|
|
1026
1495
|
}
|
|
1027
1496
|
const skills = async (args, io) => {
|
|
1028
1497
|
const { values, positionals } = parse(args, SKILLS_OPTIONS);
|
|
1029
1498
|
const session = await open(io, values);
|
|
1030
|
-
const
|
|
1031
|
-
return readSkills(io, session,
|
|
1499
|
+
const { reader, owner } = await packNamed(session);
|
|
1500
|
+
return readingPack(owner, () => readSkills(io, session, reader, values, positionals, {
|
|
1032
1501
|
command: "console skills",
|
|
1033
1502
|
own: io.skillsDir,
|
|
1034
1503
|
afterwards: PLUGIN_SKILLS_LINE,
|
|
1035
|
-
|
|
1504
|
+
owner,
|
|
1505
|
+
}));
|
|
1036
1506
|
};
|
|
1037
|
-
/** The most characters one read of a file asks for: what the console's API allows on one page. */
|
|
1038
|
-
const MAX_FILE_LIMIT = 100_000;
|
|
1039
|
-
/** A count given as a flag, within its bounds, or nothing; anything else is not understood. */
|
|
1040
|
-
function countOf(given, name, bounds) {
|
|
1041
|
-
if (given === undefined) {
|
|
1042
|
-
return undefined;
|
|
1043
|
-
}
|
|
1044
|
-
const count = Number(given);
|
|
1045
|
-
if (!Number.isInteger(count) ||
|
|
1046
|
-
count < bounds.least ||
|
|
1047
|
-
(bounds.most !== undefined && count > bounds.most)) {
|
|
1048
|
-
const range = bounds.most === undefined ? `${bounds.least} or more` : `${bounds.least} to ${bounds.most}`;
|
|
1049
|
-
throw misuse(`Not a number for --${name}, ${range}: ${given}`);
|
|
1050
|
-
}
|
|
1051
|
-
return count;
|
|
1052
|
-
}
|
|
1053
1507
|
/**
|
|
1054
|
-
* One skill of the pack
|
|
1055
|
-
*
|
|
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.
|
|
1056
1514
|
*/
|
|
1057
|
-
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);
|
|
1058
1518
|
const file = text(values, "file");
|
|
1519
|
+
const cursor = text(values, "cursor");
|
|
1059
1520
|
// A file is read by its own path from the repository's root; a skill's path beside it would be
|
|
1060
1521
|
// ignored, which reads as if it mattered, so the two together are not understood.
|
|
1061
1522
|
if (file !== undefined && positionals.length > 0) {
|
|
1062
1523
|
throw misuse(`Say one: ${command} <path of its SKILL.md> for a skill, or ${command} --file <path> for a file of the pack.`);
|
|
1063
1524
|
}
|
|
1064
|
-
// 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.
|
|
1065
1526
|
if (file === undefined &&
|
|
1066
1527
|
(text(values, "offset") !== undefined || text(values, "limit") !== undefined)) {
|
|
1067
1528
|
throw misuse(`--offset and --limit go with --file: ${command} --file <path> [--offset <n>] [--limit <n>]`);
|
|
1068
1529
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (summary === undefined) {
|
|
1073
|
-
answer(io, session, listing, () => formatSkills(listing, io.skillsDir));
|
|
1074
|
-
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>]`);
|
|
1075
1533
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
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));
|
|
1083
1540
|
}
|
|
1084
1541
|
if (file !== undefined) {
|
|
1085
|
-
//
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
|
|
1090
|
-
last = await reader.skillFile(file, offset === undefined ? {} : { offset });
|
|
1091
|
-
if (last.read === null) {
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
pages.push(last);
|
|
1095
|
-
if (last.read.kind !== "file" || last.read.nextOffset === null) {
|
|
1096
|
-
break;
|
|
1097
|
-
}
|
|
1098
|
-
offset = last.read.nextOffset;
|
|
1099
|
-
}
|
|
1100
|
-
if (last === undefined) {
|
|
1101
|
-
throw failed("The file could not be read.");
|
|
1102
|
-
}
|
|
1103
|
-
const fileRead = last;
|
|
1104
|
-
const whole = joinFile(pages, summary);
|
|
1105
|
-
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);
|
|
1106
1546
|
return EXIT.ok;
|
|
1107
1547
|
}
|
|
1108
|
-
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);
|
|
1109
1550
|
if ("error" in wanted) {
|
|
1110
1551
|
throw misuse(wanted.error);
|
|
1111
1552
|
}
|
|
1112
|
-
// The skill
|
|
1113
|
-
|
|
1114
|
-
let
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
}
|
|
1130
|
-
const loaded = last;
|
|
1131
|
-
const whole = joinSkill(pages, summary);
|
|
1132
|
-
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);
|
|
1133
1570
|
return EXIT.ok;
|
|
1134
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.";
|
|
1135
1577
|
const skill = async (args, io) => {
|
|
1136
1578
|
const { values, positionals } = parse(args, SKILL_OPTIONS);
|
|
1137
1579
|
const session = await open(io, values);
|
|
1138
|
-
const
|
|
1139
|
-
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)));
|
|
1140
1582
|
};
|
|
1141
1583
|
// ---- The plugins (docs/specs/plugins.md, "The command") ----
|
|
1142
1584
|
// `console plugins` and `console plugin <key> ...` are the two entries: the command sends the
|
|
@@ -1202,7 +1644,7 @@ function splitWords(args, own) {
|
|
|
1202
1644
|
}
|
|
1203
1645
|
return { values, words };
|
|
1204
1646
|
}
|
|
1205
|
-
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.";
|
|
1206
1648
|
const plugin = async (args, io) => {
|
|
1207
1649
|
const { values, words } = splitWords(args, PLUGIN_GLOBAL_FLAGS);
|
|
1208
1650
|
const [key, verb, ...rest] = words;
|
|
@@ -1234,6 +1676,8 @@ const plugin = async (args, io) => {
|
|
|
1234
1676
|
}
|
|
1235
1677
|
case "records":
|
|
1236
1678
|
return pluginRecords(io, session, client, rest, text(values, "project"));
|
|
1679
|
+
case "events":
|
|
1680
|
+
return pluginEvents(io, session, client, rest);
|
|
1237
1681
|
case "skills": {
|
|
1238
1682
|
const parsed = parse(rest, SKILLS_OPTIONS);
|
|
1239
1683
|
return readSkills(io, session, client, parsed.values, parsed.positionals, {
|
|
@@ -1242,7 +1686,7 @@ const plugin = async (args, io) => {
|
|
|
1242
1686
|
}
|
|
1243
1687
|
case "skill": {
|
|
1244
1688
|
const parsed = parse(rest, SKILL_OPTIONS);
|
|
1245
|
-
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));
|
|
1246
1690
|
}
|
|
1247
1691
|
case "enable":
|
|
1248
1692
|
return pluginEnable(io, session, client, rest);
|
|
@@ -1376,6 +1820,37 @@ function whereValueOf(word) {
|
|
|
1376
1820
|
return word;
|
|
1377
1821
|
}
|
|
1378
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
|
+
}
|
|
1379
1854
|
async function pluginRecords(io, session, client, rest, project) {
|
|
1380
1855
|
const { values, positionals } = parse(rest, {
|
|
1381
1856
|
where: { type: "string", multiple: true },
|
|
@@ -1625,19 +2100,26 @@ async function pluginSettings(io, session, client, rest) {
|
|
|
1625
2100
|
* shown never; or takes it away.
|
|
1626
2101
|
*/
|
|
1627
2102
|
async function pluginSecret(io, session, client, rest) {
|
|
1628
|
-
const { values, positionals } = parse(rest, {
|
|
1629
|
-
|
|
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 };
|
|
1630
2112
|
if (on(values, "remove")) {
|
|
1631
|
-
await client.removeSecret(name);
|
|
1632
|
-
answer(io, session, {
|
|
2113
|
+
await client.removeSecret(name, key);
|
|
2114
|
+
answer(io, session, { ...data, set: false }, () => `Removed ${which} of ${client.key}.`);
|
|
1633
2115
|
return EXIT.ok;
|
|
1634
2116
|
}
|
|
1635
|
-
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): `);
|
|
1636
2118
|
if (value.length === 0) {
|
|
1637
|
-
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.`);
|
|
1638
2120
|
}
|
|
1639
|
-
await client.setSecret(name, value);
|
|
1640
|
-
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.`);
|
|
1641
2123
|
return EXIT.ok;
|
|
1642
2124
|
}
|
|
1643
2125
|
/**
|
|
@@ -1701,8 +2183,9 @@ function versionOf(given) {
|
|
|
1701
2183
|
}
|
|
1702
2184
|
return version;
|
|
1703
2185
|
}
|
|
1704
|
-
// The rules of the board (ADR-0023):
|
|
1705
|
-
//
|
|
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.
|
|
1706
2189
|
const rules = async (args, io) => {
|
|
1707
2190
|
const [verb, ...rest] = args;
|
|
1708
2191
|
if (verb === "write") {
|
|
@@ -1719,36 +2202,44 @@ const rules = async (args, io) => {
|
|
|
1719
2202
|
const none = given === "none";
|
|
1720
2203
|
const body = none ? undefined : await bodyOf(io, values, given);
|
|
1721
2204
|
if (!none && body === undefined) {
|
|
1722
|
-
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.");
|
|
1723
2206
|
}
|
|
1724
2207
|
const baseVersion = versionOf(text(values, "base"));
|
|
1725
2208
|
const session = await open(io, values);
|
|
1726
2209
|
if (on(values, "workspace")) {
|
|
1727
2210
|
if (none) {
|
|
1728
2211
|
const put = await session.client.archiveRules();
|
|
1729
|
-
answer(io, session, put, () => "
|
|
2212
|
+
answer(io, session, put, () => "What this organization adds to the rules is put away: the console's stand alone.");
|
|
1730
2213
|
return EXIT.ok;
|
|
1731
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
|
+
}
|
|
1732
2223
|
const written = await session.client.writeRules({
|
|
1733
2224
|
body: body ?? "",
|
|
1734
2225
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
1735
2226
|
});
|
|
1736
2227
|
answer(io, session, written, () => written.page === null
|
|
1737
|
-
? "Nothing written:
|
|
1738
|
-
: `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}.`);
|
|
1739
2230
|
return EXIT.ok;
|
|
1740
2231
|
}
|
|
1741
2232
|
const project = await session.project();
|
|
1742
2233
|
if (none) {
|
|
1743
2234
|
try {
|
|
1744
2235
|
const put = await project.archiveDocument(RULES_PATH);
|
|
1745
|
-
answer(io, session, put, () => "
|
|
2236
|
+
answer(io, session, put, () => "What this project adds to the rules is put away: it adds nothing now.");
|
|
1746
2237
|
}
|
|
1747
2238
|
catch (error) {
|
|
1748
2239
|
if (!(error instanceof ApiError) || error.code !== "document.not_found") {
|
|
1749
2240
|
throw error;
|
|
1750
2241
|
}
|
|
1751
|
-
answer(io, session, null, () => "This project
|
|
2242
|
+
answer(io, session, null, () => "This project adds nothing to the rules: nothing to put away.");
|
|
1752
2243
|
}
|
|
1753
2244
|
return EXIT.ok;
|
|
1754
2245
|
}
|
|
@@ -1757,14 +2248,14 @@ const rules = async (args, io) => {
|
|
|
1757
2248
|
body: body ?? "",
|
|
1758
2249
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
1759
2250
|
});
|
|
1760
|
-
answer(io, session, written, () => `Wrote this project
|
|
2251
|
+
answer(io, session, written, () => `Wrote what this project adds to the rules, version ${written.version}.`);
|
|
1761
2252
|
return EXIT.ok;
|
|
1762
2253
|
}
|
|
1763
2254
|
const { values } = parse(args, {}, false);
|
|
1764
2255
|
const session = await open(io, values);
|
|
1765
2256
|
const key = await session.projectKey();
|
|
1766
2257
|
const [found, me] = await Promise.all([
|
|
1767
|
-
key === undefined ? session.client.rules() : session.
|
|
2258
|
+
key === undefined ? session.client.rules() : (await session.project()).rules(),
|
|
1768
2259
|
session.client.me(),
|
|
1769
2260
|
]);
|
|
1770
2261
|
const read = "workspace" in found
|
|
@@ -1774,15 +2265,24 @@ const rules = async (args, io) => {
|
|
|
1774
2265
|
...(found.plugins === undefined ? {} : { plugins: found.plugins }),
|
|
1775
2266
|
}
|
|
1776
2267
|
: forPerson(found, readingLanguage(me));
|
|
1777
|
-
|
|
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)));
|
|
1778
2270
|
return EXIT.ok;
|
|
1779
2271
|
};
|
|
1780
2272
|
/**
|
|
1781
2273
|
* The rules as they read for the person whose token the command holds: `{language}` filled
|
|
1782
|
-
* 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.
|
|
1783
2276
|
*/
|
|
1784
2277
|
function forPerson(half, language) {
|
|
1785
|
-
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
|
+
};
|
|
1786
2286
|
}
|
|
1787
2287
|
/** The flags that set a task's fields, shared by writing one and changing one. */
|
|
1788
2288
|
const TASK_FIELDS = {
|
|
@@ -1850,8 +2350,24 @@ const newTask = async (args, io) => {
|
|
|
1850
2350
|
...TASK_FIELDS,
|
|
1851
2351
|
body: { type: "string" },
|
|
1852
2352
|
file: { type: "string" },
|
|
2353
|
+
take: { type: "boolean" },
|
|
2354
|
+
agent: { type: "string" },
|
|
2355
|
+
rules: { type: "string" },
|
|
1853
2356
|
});
|
|
1854
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
|
+
}
|
|
1855
2371
|
const body = await bodyOf(io, values, text(values, "body"));
|
|
1856
2372
|
const session = await open(io, values);
|
|
1857
2373
|
const project = await session.project();
|
|
@@ -1859,9 +2375,41 @@ const newTask = async (args, io) => {
|
|
|
1859
2375
|
const made = await project.createTask({
|
|
1860
2376
|
title,
|
|
1861
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" } : {}),
|
|
1862
2380
|
...fields,
|
|
1863
2381
|
});
|
|
1864
|
-
|
|
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);
|
|
1865
2413
|
return EXIT.ok;
|
|
1866
2414
|
};
|
|
1867
2415
|
const editTask = async (args, io) => {
|
|
@@ -1886,7 +2434,8 @@ const editTask = async (args, io) => {
|
|
|
1886
2434
|
}
|
|
1887
2435
|
const found = await project.task(ref);
|
|
1888
2436
|
const changed = await project.updateTask(found.id, patch);
|
|
1889
|
-
|
|
2437
|
+
const page = await taskPage(session, changed.number);
|
|
2438
|
+
answer(io, session, changed, () => formatTask(changed, undefined, undefined, undefined, page));
|
|
1890
2439
|
return EXIT.ok;
|
|
1891
2440
|
};
|
|
1892
2441
|
/** Puts a task away, or every done or dropped task of a goal (ADR-0029); the task by its number or its id. */
|
|
@@ -1939,10 +2488,13 @@ const task = async (args, io) => {
|
|
|
1939
2488
|
const found = await project.task(ref);
|
|
1940
2489
|
const [decisions, runs, comments] = await Promise.all([
|
|
1941
2490
|
project.decisions({ task: found.id }),
|
|
1942
|
-
|
|
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 }),
|
|
1943
2494
|
project.comments(found.id),
|
|
1944
2495
|
]);
|
|
1945
|
-
|
|
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));
|
|
1946
2498
|
return EXIT.ok;
|
|
1947
2499
|
};
|
|
1948
2500
|
/**
|
|
@@ -2030,17 +2582,21 @@ const file = async (args, io) => {
|
|
|
2030
2582
|
}, () => `Saved ${read.name} (${read.bytes.byteLength} bytes, ${read.contentType}) at ${saved}`);
|
|
2031
2583
|
return EXIT.ok;
|
|
2032
2584
|
};
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
const ref = theOne(positionals, "Say which task: console take <number|id>");
|
|
2036
|
-
const session = await open(io, values);
|
|
2037
|
-
const project = await session.project();
|
|
2038
|
-
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) {
|
|
2039
2587
|
const agent = text(values, "agent");
|
|
2040
|
-
|
|
2588
|
+
return project.startRun({
|
|
2041
2589
|
taskId: found.id,
|
|
2042
2590
|
...(agent === undefined ? {} : { agent }),
|
|
2043
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) {
|
|
2044
2600
|
// The rules come with the run, as they read for the person: everything from here acts
|
|
2045
2601
|
// within them (ADR-0023); the task is read again, as it stands now that it is taken.
|
|
2046
2602
|
const [ruling, me, taken, comments, openRuns] = await Promise.all([
|
|
@@ -2048,7 +2604,7 @@ const take = async (args, io) => {
|
|
|
2048
2604
|
session.client.me(),
|
|
2049
2605
|
project.task(ref),
|
|
2050
2606
|
project.comments(found.id),
|
|
2051
|
-
project.
|
|
2607
|
+
project.runBriefs({ open: true, mine: true }),
|
|
2052
2608
|
]);
|
|
2053
2609
|
// Taking a task with a run open on it ends that run (ADR-0020): said when it happened.
|
|
2054
2610
|
const tookOver = found.openRuns > 0
|
|
@@ -2065,19 +2621,48 @@ const take = async (args, io) => {
|
|
|
2065
2621
|
project: forPerson(ruling.project, readingLanguage(me)),
|
|
2066
2622
|
...(ruling.plugins === undefined ? {} : { plugins: ruling.plugins }),
|
|
2067
2623
|
};
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
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);
|
|
2081
2666
|
return EXIT.ok;
|
|
2082
2667
|
};
|
|
2083
2668
|
const report = async (args, io) => {
|
|
@@ -2094,7 +2679,7 @@ const report = async (args, io) => {
|
|
|
2094
2679
|
}
|
|
2095
2680
|
const session = await open(io, values);
|
|
2096
2681
|
const project = await session.project();
|
|
2097
|
-
const runId = await currentRun(project, values);
|
|
2682
|
+
const runId = await currentRun(session, project, values);
|
|
2098
2683
|
const run = await project.report(runId, { body });
|
|
2099
2684
|
answer(io, session, run, () => `Reported on run ${run.id}: ${run.reports.length} report${run.reports.length === 1 ? "" : "s"} so far.`);
|
|
2100
2685
|
return EXIT.ok;
|
|
@@ -2128,7 +2713,7 @@ const handIn = async (args, io) => {
|
|
|
2128
2713
|
const label = text(values, "label");
|
|
2129
2714
|
const session = await open(io, values);
|
|
2130
2715
|
const project = await session.project();
|
|
2131
|
-
const runId = await currentRun(project, values);
|
|
2716
|
+
const runId = await currentRun(session, project, values);
|
|
2132
2717
|
// A URL is handed in as a link, and the console says whether it takes it; anything else
|
|
2133
2718
|
// names a file on this machine.
|
|
2134
2719
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(what)) {
|
|
@@ -2185,7 +2770,7 @@ const ask = async (args, io) => {
|
|
|
2185
2770
|
const files = await attachmentsOf(io, texts(values, "attach"));
|
|
2186
2771
|
const session = await open(io, values);
|
|
2187
2772
|
const project = await session.project();
|
|
2188
|
-
const runId = await currentRun(project, values);
|
|
2773
|
+
const runId = await currentRun(session, project, values);
|
|
2189
2774
|
// Whom the decision is for (ADR-0042, ADR-0057): the person the agent works for, unless --to
|
|
2190
2775
|
// names others of the project, each once; several, and any of them may answer.
|
|
2191
2776
|
const deciderIds = [];
|
|
@@ -2207,11 +2792,25 @@ const ask = async (args, io) => {
|
|
|
2207
2792
|
: { deciderId: deciderIds[0], deciderIds }),
|
|
2208
2793
|
}, files);
|
|
2209
2794
|
const withFiles = files.length === 0 ? "" : `, with ${files.length} file${files.length === 1 ? "" : "s"}`;
|
|
2210
|
-
// 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.
|
|
2211
2797
|
io.stdout(session.json
|
|
2212
2798
|
? `${JSON.stringify(raised, null, 2)}\n`
|
|
2213
|
-
: `Decision ${raised.id} raised on run ${runId}${withFiles}; the run waits for ${deciderLogins(raised)}.\ndecision id: ${raised.id}\n${formatOptions(raised)}\n`);
|
|
2214
|
-
|
|
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);
|
|
2215
2814
|
};
|
|
2216
2815
|
/**
|
|
2217
2816
|
* Writes a person's answer on a decision, in their name through the agent (ADR-0021): the
|
|
@@ -2237,7 +2836,8 @@ const answering = async (args, io) => {
|
|
|
2237
2836
|
...(own === undefined ? { option } : { own }),
|
|
2238
2837
|
...(note === undefined ? {} : { note }),
|
|
2239
2838
|
});
|
|
2240
|
-
|
|
2839
|
+
const page = await decisionPage(session, answered.id, atItsAddress);
|
|
2840
|
+
answer(io, session, answered, () => formatDecision(answered, { atItsAddress, page }));
|
|
2241
2841
|
return EXIT.ok;
|
|
2242
2842
|
};
|
|
2243
2843
|
/** Whether a refusal says the decision is not in the project the command works in, or the project is not the person's. */
|
|
@@ -2280,6 +2880,27 @@ async function reachDecision(session, id) {
|
|
|
2280
2880
|
throw error;
|
|
2281
2881
|
}
|
|
2282
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
|
+
}
|
|
2283
2904
|
/** Writes an answer on a decision as the command reaches it (ADR-0068): in the project, else wherever it is. */
|
|
2284
2905
|
async function answerReached(session, id, input) {
|
|
2285
2906
|
if ((await session.projectKey()) !== undefined) {
|
|
@@ -2329,7 +2950,7 @@ const decision = async (args, io) => {
|
|
|
2329
2950
|
if (tos.length > 0) {
|
|
2330
2951
|
// Whom a decision that waits is for, said anew (ADR-0096): the people named take the place
|
|
2331
2952
|
// of those it was for, each once in the order named.
|
|
2332
|
-
const project = await session
|
|
2953
|
+
const project = await projectOfDecision(session, id);
|
|
2333
2954
|
const deciderIds = [];
|
|
2334
2955
|
for (const to of tos) {
|
|
2335
2956
|
const named = await personIdOf(session, to);
|
|
@@ -2338,22 +2959,33 @@ const decision = async (args, io) => {
|
|
|
2338
2959
|
}
|
|
2339
2960
|
}
|
|
2340
2961
|
const addressed = await project.addressDecision(id, deciderIds);
|
|
2341
|
-
|
|
2962
|
+
const page = await decisionPage(session, addressed.id);
|
|
2963
|
+
answer(io, session, addressed, () => formatDecision(addressed, { page }));
|
|
2342
2964
|
return EXIT.ok;
|
|
2343
2965
|
}
|
|
2344
2966
|
if (outcome !== undefined) {
|
|
2345
2967
|
// What followed the decision: the record grows, and is printed as it stands.
|
|
2346
|
-
const project = await session
|
|
2968
|
+
const project = await projectOfDecision(session, id);
|
|
2347
2969
|
const grown = await project.updateDecision(id, { outcome });
|
|
2348
|
-
|
|
2970
|
+
const page = await decisionPage(session, grown.id);
|
|
2971
|
+
answer(io, session, grown, () => formatDecision(grown, { page }));
|
|
2349
2972
|
return EXIT.ok;
|
|
2350
2973
|
}
|
|
2351
2974
|
const { decision: found, waiter, atItsAddress } = await reachDecision(session, id);
|
|
2352
2975
|
if (seconds === 0) {
|
|
2353
|
-
|
|
2976
|
+
const page = await decisionPage(session, found.id, atItsAddress);
|
|
2977
|
+
answer(io, session, found, () => formatDecision(found, { atItsAddress, page }));
|
|
2354
2978
|
return EXIT.ok;
|
|
2355
2979
|
}
|
|
2356
|
-
|
|
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);
|
|
2357
2989
|
};
|
|
2358
2990
|
const docs = async (args, io) => {
|
|
2359
2991
|
const { values, positionals } = parse(args, {
|
|
@@ -2366,8 +2998,10 @@ const docs = async (args, io) => {
|
|
|
2366
2998
|
const search = text(values, "search");
|
|
2367
2999
|
const session = await open(io, values);
|
|
2368
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(/\/+$/, "");
|
|
2369
3003
|
const found = await project.documents({
|
|
2370
|
-
...(
|
|
3004
|
+
...(folder === undefined || folder === "" ? {} : { folder }),
|
|
2371
3005
|
...(search === undefined ? {} : { q: search }),
|
|
2372
3006
|
...(on(values, "archived") ? { archived: true } : {}),
|
|
2373
3007
|
});
|
|
@@ -2438,7 +3072,10 @@ const write = async (args, io) => {
|
|
|
2438
3072
|
body,
|
|
2439
3073
|
...(baseVersion === undefined ? {} : { baseVersion }),
|
|
2440
3074
|
});
|
|
2441
|
-
|
|
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)}`}`);
|
|
2442
3079
|
return EXIT.ok;
|
|
2443
3080
|
};
|
|
2444
3081
|
const attach = async (args, io) => {
|
|
@@ -2587,7 +3224,9 @@ const goal = async (args, io) => {
|
|
|
2587
3224
|
const session = await open(io, values);
|
|
2588
3225
|
const project = await session.project();
|
|
2589
3226
|
const found = await project.goal(id);
|
|
2590
|
-
const towards =
|
|
3227
|
+
const towards = session.json
|
|
3228
|
+
? await project.tasks({ goal: found.id })
|
|
3229
|
+
: await project.taskBriefs({ goal: found.id });
|
|
2591
3230
|
answer(io, session, { goal: found, tasks: towards.items }, () => formatGoal(found, towards.items));
|
|
2592
3231
|
return EXIT.ok;
|
|
2593
3232
|
};
|
|
@@ -2623,19 +3262,40 @@ const decisions = async (args, io) => {
|
|
|
2623
3262
|
formatMore(found.more, page.limit, page.offset));
|
|
2624
3263
|
return EXIT.ok;
|
|
2625
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
|
+
}
|
|
2626
3288
|
const ending = (status) => async (args, io) => {
|
|
2627
3289
|
const { values } = parse(args, { summary: { type: "string" }, file: { type: "string" }, run: { type: "string" } }, false);
|
|
2628
3290
|
const summary = await bodyOf(io, values, text(values, "summary"));
|
|
2629
3291
|
const session = await open(io, values);
|
|
2630
3292
|
const project = await session.project();
|
|
2631
|
-
const runId = await currentRun(project, values);
|
|
3293
|
+
const runId = await currentRun(session, project, values);
|
|
2632
3294
|
const run = await project.endRun(runId, {
|
|
2633
3295
|
status,
|
|
2634
3296
|
...(summary === undefined ? {} : { summary }),
|
|
2635
3297
|
});
|
|
2636
|
-
|
|
2637
|
-
? `Run ${run.id} finished; the task is up for review.`
|
|
2638
|
-
: `Run ${run.id} failed; the task stays as it is.`);
|
|
3298
|
+
await sayEnded(io, session, project, run, status);
|
|
2639
3299
|
return EXIT.ok;
|
|
2640
3300
|
};
|
|
2641
3301
|
const abandon = async (args, io) => {
|
|
@@ -2650,12 +3310,12 @@ const abandon = async (args, io) => {
|
|
|
2650
3310
|
const summary = await bodyOf(io, values, text(values, "summary"));
|
|
2651
3311
|
const session = await open(io, values);
|
|
2652
3312
|
const project = await session.project();
|
|
2653
|
-
const runId = positionals[0] ?? (await currentRun(project, values));
|
|
3313
|
+
const runId = positionals[0] ?? (await currentRun(session, project, values));
|
|
2654
3314
|
const run = await project.endRun(runId, {
|
|
2655
3315
|
status: "abandoned",
|
|
2656
3316
|
...(summary === undefined ? {} : { summary }),
|
|
2657
3317
|
});
|
|
2658
|
-
|
|
3318
|
+
await sayEnded(io, session, project, run, "abandoned");
|
|
2659
3319
|
return EXIT.ok;
|
|
2660
3320
|
};
|
|
2661
3321
|
const runs = async (args, io) => {
|
|
@@ -2670,17 +3330,46 @@ const runs = async (args, io) => {
|
|
|
2670
3330
|
const project = await session.project();
|
|
2671
3331
|
const ref = text(values, "task");
|
|
2672
3332
|
const taskId = ref === undefined ? undefined : (await project.task(ref)).id;
|
|
2673
|
-
const
|
|
3333
|
+
const mine = on(values, "mine");
|
|
3334
|
+
const filter = {
|
|
2674
3335
|
...(taskId === undefined ? {} : { task: taskId }),
|
|
2675
3336
|
...(on(values, "open") ? { open: true } : {}),
|
|
2676
|
-
...(
|
|
3337
|
+
...(mine ? { mine: true } : {}),
|
|
2677
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}`;
|
|
2678
3358
|
});
|
|
2679
|
-
answer(io, session, found, () => found.items.length === 0
|
|
2680
|
-
? "No runs."
|
|
2681
|
-
: found.items.map(formatRunLine).join("\n") + formatMore(found.more, page.limit, page.offset));
|
|
2682
3359
|
return EXIT.ok;
|
|
2683
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
|
+
}
|
|
2684
3373
|
const run = async (args, io) => {
|
|
2685
3374
|
const { values, positionals } = parse(args, {});
|
|
2686
3375
|
const id = theOne(positionals, "Say which run: console run <id>");
|
|
@@ -2703,12 +3392,16 @@ function portOf(value) {
|
|
|
2703
3392
|
}
|
|
2704
3393
|
/**
|
|
2705
3394
|
* A console of the person's own, served from this machine (ADR-0014): the build's pages here,
|
|
2706
|
-
* 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.
|
|
2707
3397
|
*/
|
|
2708
3398
|
const serve = async (args, io) => {
|
|
2709
|
-
const { values, positionals } = parse(args, {
|
|
3399
|
+
const { values, positionals } = parse(args, {
|
|
3400
|
+
port: { type: "string" },
|
|
3401
|
+
records: { type: "string" },
|
|
3402
|
+
});
|
|
2710
3403
|
if (positionals.length > 1) {
|
|
2711
|
-
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>]");
|
|
2712
3405
|
}
|
|
2713
3406
|
const [dir] = positionals;
|
|
2714
3407
|
const port = portOf(text(values, "port"));
|
|
@@ -2734,16 +3427,37 @@ const serve = async (args, io) => {
|
|
|
2734
3427
|
throw error;
|
|
2735
3428
|
}
|
|
2736
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
|
+
}
|
|
2737
3443
|
const listening = await listen((bound) => createServeHandler({
|
|
2738
3444
|
upstream: session.url,
|
|
2739
3445
|
token: session.token,
|
|
2740
3446
|
fetch: io.fetch,
|
|
2741
3447
|
port: bound,
|
|
2742
3448
|
web,
|
|
3449
|
+
records,
|
|
2743
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.`;
|
|
2744
3458
|
io.stdout(web === undefined
|
|
2745
|
-
? `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
|
|
2746
|
-
: `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`);
|
|
2747
3461
|
await listening.closed;
|
|
2748
3462
|
return EXIT.ok;
|
|
2749
3463
|
};
|
|
@@ -3022,8 +3736,13 @@ const agentNew = async (args, io) => {
|
|
|
3022
3736
|
formatAgentLine(made),
|
|
3023
3737
|
made.person.invited === true
|
|
3024
3738
|
? host === "gh"
|
|
3025
|
-
? // A login at a git host goes to whoever registers it
|
|
3026
|
-
|
|
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.`
|
|
3027
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.`
|
|
3028
3747
|
: `${made.person.login} is an agent account from now on, with everything it did.`,
|
|
3029
3748
|
...(made.onboarding === null || made.onboarding === undefined
|
|
@@ -3103,7 +3822,21 @@ const agentSecrets = async (args, io) => {
|
|
|
3103
3822
|
const { values, positionals } = parse(args, {});
|
|
3104
3823
|
const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle>"));
|
|
3105
3824
|
const session = await open(io, values);
|
|
3106
|
-
|
|
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
|
+
}
|
|
3107
3840
|
answer(io, session, found, () => found.items.length === 0
|
|
3108
3841
|
? `@${handle} keeps no secret yet.`
|
|
3109
3842
|
: found.items.map((item) => formatSecretLine(item)).join("\n"));
|
|
@@ -3491,7 +4224,11 @@ async function signInAsAccount(io, machine, url, setup) {
|
|
|
3491
4224
|
const opened = URL.canParse(begun.url) && new URL(begun.url).origin === url
|
|
3492
4225
|
? await machine.open(begun.url)
|
|
3493
4226
|
: false;
|
|
3494
|
-
|
|
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`);
|
|
3495
4232
|
let secret;
|
|
3496
4233
|
for (;;) {
|
|
3497
4234
|
await io.sleep(begun.interval * 1000);
|
|
@@ -3622,6 +4359,185 @@ const agentSetup = async (args, io) => {
|
|
|
3622
4359
|
}
|
|
3623
4360
|
return EXIT.ok;
|
|
3624
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
|
+
};
|
|
3625
4541
|
// One agent account by its handle; with --avatar, its picture written as a file (ADR-0084): the
|
|
3626
4542
|
// parts are drawn here, by the package's own function, and the console sends no picture.
|
|
3627
4543
|
const agent = async (args, io) => {
|
|
@@ -4261,6 +5177,7 @@ const COMMANDS = {
|
|
|
4261
5177
|
whoami,
|
|
4262
5178
|
serve,
|
|
4263
5179
|
runner,
|
|
5180
|
+
desk,
|
|
4264
5181
|
projects,
|
|
4265
5182
|
use,
|
|
4266
5183
|
work,
|
|
@@ -4314,7 +5231,7 @@ function help(io, name) {
|
|
|
4314
5231
|
io.stdout(usage(io.version, io.skillsDir));
|
|
4315
5232
|
return EXIT.ok;
|
|
4316
5233
|
}
|
|
4317
|
-
const found = helpFor(name);
|
|
5234
|
+
const found = helpFor(name, io.skillsDir);
|
|
4318
5235
|
if (found === undefined) {
|
|
4319
5236
|
throw misuse(`Not a command: ${name}. The commands: ${Object.keys(COMMAND_HELP).join(", ")}`);
|
|
4320
5237
|
}
|
|
@@ -4536,6 +5453,10 @@ export async function runCli(argv, io) {
|
|
|
4536
5453
|
io.stderr(`${error.message}\n`);
|
|
4537
5454
|
return error.exit;
|
|
4538
5455
|
}
|
|
5456
|
+
if (error instanceof UnseenProject) {
|
|
5457
|
+
io.stderr(`${error.words}\n`);
|
|
5458
|
+
return EXIT.failed;
|
|
5459
|
+
}
|
|
4539
5460
|
if (error instanceof ApiError) {
|
|
4540
5461
|
io.stderr(`${error.code}: ${error.message}\n${hintFor(error, io, seen)}`);
|
|
4541
5462
|
return error.code === "client.outdated" ||
|