@skillcdn/console 0.6.3 → 0.6.4
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 +6 -6
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +7 -3
- package/dist/agent-page.js.map +1 -1
- package/dist/api.d.ts +5 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +5 -4
- package/dist/api.js.map +1 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +660 -138
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/format.d.ts +32 -4
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +125 -4
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +91 -29
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/pack.d.ts +11 -10
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +27 -41
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +8 -5
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/runner-files.d.ts.map +1 -1
- package/dist/cli/runner-files.js +15 -0
- package/dist/cli/runner-files.js.map +1 -1
- package/dist/cli/skill-path.d.ts +11 -0
- package/dist/cli/skill-path.d.ts.map +1 -0
- package/dist/cli/skill-path.js +44 -0
- package/dist/cli/skill-path.js.map +1 -0
- package/dist/client.d.ts +17 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +67 -5
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +161 -14
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/agents.d.ts +3 -4
- package/dist/components/agents.d.ts.map +1 -1
- package/dist/components/agents.js +7 -6
- package/dist/components/agents.js.map +1 -1
- package/dist/components/people.d.ts.map +1 -1
- package/dist/components/people.js +7 -2
- package/dist/components/people.js.map +1 -1
- package/dist/components/picker.d.ts +16 -0
- package/dist/components/picker.d.ts.map +1 -1
- package/dist/components/picker.js +69 -4
- package/dist/components/picker.js.map +1 -1
- package/dist/console.css +40 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +1 -1
- package/dist/console.js.map +1 -1
- package/dist/i18n/en.d.ts +19 -5
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +26 -12
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +22 -10
- package/dist/i18n/ko.js.map +1 -1
- package/dist/limits.d.ts +16 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +16 -0
- package/dist/limits.js.map +1 -1
- package/dist/onboarding.d.ts +18 -6
- package/dist/onboarding.d.ts.map +1 -1
- package/dist/onboarding.js +42 -7
- package/dist/onboarding.js.map +1 -1
- package/dist/plugin/args.d.ts +24 -2
- package/dist/plugin/args.d.ts.map +1 -1
- package/dist/plugin/args.js +20 -2
- package/dist/plugin/args.js.map +1 -1
- package/dist/plugin/define.d.ts.map +1 -1
- package/dist/plugin/define.js +12 -3
- package/dist/plugin/define.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +2 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +1 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/routes.d.ts +2 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +2 -0
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +4 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +5 -2
- package/dist/rules.js.map +1 -1
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +48 -0
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +4 -1
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +5 -4
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/runner.d.ts +16 -0
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +157 -8
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/slack.d.ts.map +1 -1
- package/dist/runner/slack.js +14 -3
- package/dist/runner/slack.js.map +1 -1
- package/dist/runner/types.d.ts +19 -0
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js.map +1 -1
- package/dist/schemas.d.ts +475 -5
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +117 -12
- package/dist/schemas.js.map +1 -1
- package/dist/secret-file.d.ts +21 -0
- package/dist/secret-file.d.ts.map +1 -0
- package/dist/secret-file.js +59 -0
- package/dist/secret-file.js.map +1 -0
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +3 -2
- package/dist/services.js.map +1 -1
- package/dist/setup-guide.d.ts +2 -2
- package/dist/setup-guide.d.ts.map +1 -1
- package/dist/setup-guide.js +6 -5
- package/dist/setup-guide.js.map +1 -1
- package/dist/vocabulary.d.ts +10 -2
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +9 -2
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +22 -16
- package/docs/specs/plugins.md +5 -4
- package/docs/specs/rest.md +24 -12
- package/docs/specs/runner.md +19 -12
- package/docs/start.md +4 -3
- package/package.json +3 -3
- package/skills/building-a-plugin/SKILL.md +2 -2
- package/skills/keeping-the-pack/SKILL.md +87 -0
- package/skills/planning-the-board/SKILL.md +6 -6
- package/skills/planning-the-board/references/a-task.md +1 -1
- package/skills/planning-the-board/references/setting-up.md +9 -5
- package/skills/running-an-agent/SKILL.md +15 -14
- package/skills/running-an-agent/references/preparing-the-machine.md +3 -2
- package/skills/running-an-agent/references/several-tasks.md +8 -2
- package/skills/running-an-agent/references/slack-app.md +10 -4
- package/skills/running-an-agent/references/the-account-and-the-invitation.md +1 -1
- package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -1
- package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +3 -3
- package/skills/running-an-agent/references/your-first-task.md +4 -3
- package/skills/working-the-board/SKILL.md +4 -4
- package/skills/working-the-board/references/terms.md +3 -1
- package/skills/working-the-board/references/the-pack.md +12 -5
- package/src/agent-page.tsx +19 -3
- package/src/api.ts +27 -0
- package/src/cli/cli.ts +847 -192
- package/src/cli/format.ts +158 -4
- package/src/cli/help.ts +102 -28
- package/src/cli/pack.ts +49 -58
- package/src/cli/plugin-cli.ts +8 -5
- package/src/cli/runner-files.ts +17 -0
- package/src/cli/skill-path.ts +51 -0
- package/src/client.ts +50 -0
- package/src/components/agent-page.tsx +309 -30
- package/src/components/agents.tsx +7 -23
- package/src/components/people.tsx +7 -3
- package/src/components/picker.tsx +79 -5
- package/src/console.tsx +0 -1
- package/src/i18n/en.ts +28 -13
- package/src/i18n/ko.ts +24 -10
- package/src/limits.ts +16 -0
- package/src/onboarding.ts +60 -21
- package/src/plugin/args.ts +29 -3
- package/src/plugin/define.ts +18 -3
- package/src/plugin/rest-schemas.ts +3 -0
- package/src/routes.ts +2 -0
- package/src/rules.ts +5 -2
- package/src/runner/claude.ts +53 -0
- package/src/runner/codex.ts +4 -1
- package/src/runner/desk.ts +5 -4
- package/src/runner/runner.ts +199 -9
- package/src/runner/slack.ts +18 -7
- package/src/runner/types.ts +16 -0
- package/src/schemas.ts +148 -10
- package/src/secret-file.ts +76 -0
- package/src/services.ts +3 -2
- package/src/setup-guide.ts +6 -5
- package/src/styles/README.md +1 -1
- package/src/styles/pages/agents.css +40 -0
- package/src/vocabulary.ts +12 -2
- package/dist/cli/command-words.d.ts +0 -20
- package/dist/cli/command-words.d.ts.map +0 -1
- package/dist/cli/command-words.js +0 -51
- package/dist/cli/command-words.js.map +0 -1
- package/src/cli/command-words.ts +0 -56
package/src/cli/cli.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import { basename, extname, isAbsolute } from "node:path";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { deflateSync } from "node:zlib";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type PackRead,
|
|
7
|
-
ReadMisuse,
|
|
8
|
-
type ReadOutput,
|
|
9
|
-
readNumber,
|
|
10
|
-
readPack,
|
|
11
|
-
wroteLine,
|
|
12
|
-
} from "@skillcdn/cli";
|
|
13
|
-
import {
|
|
14
|
-
BROWSE_MAX_LIMIT,
|
|
15
|
-
FIND_MAX_LIMIT,
|
|
16
|
-
READ_FILE_MAX_LIMIT,
|
|
17
|
-
type ToolWords,
|
|
18
|
-
utf8Length,
|
|
19
|
-
} from "@skillcdn/core";
|
|
4
|
+
import type { PackRead, ReadOutput } from "@skillcdn/cli";
|
|
5
|
+
import type { ToolWords } from "@skillcdn/core";
|
|
20
6
|
import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
|
|
21
7
|
import {
|
|
22
8
|
ApiError,
|
|
@@ -47,12 +33,18 @@ import {
|
|
|
47
33
|
EVENTS_PAGE_LIMIT,
|
|
48
34
|
LIST_LIMIT,
|
|
49
35
|
MAX_DECIDERS,
|
|
36
|
+
MAX_OPTION_LABEL_LENGTH,
|
|
50
37
|
MAX_OPTIONS,
|
|
51
38
|
MAX_OWN_WAKE_DAYS,
|
|
39
|
+
MAX_PACK_NOTE_LENGTH,
|
|
40
|
+
MAX_PACK_NOTE_OUTCOME_LENGTH,
|
|
41
|
+
MAX_PACK_NOTES_PAGE_LIMIT,
|
|
42
|
+
MAX_QUESTION_LENGTH,
|
|
52
43
|
MAX_RUNNER_LINE_LENGTH,
|
|
53
44
|
MAX_SIGNALS_PAGE_LIMIT,
|
|
54
45
|
MIN_OPTIONS,
|
|
55
46
|
OWN_WAKE_KEY,
|
|
47
|
+
PACK_NOTES_PAGE_LIMIT,
|
|
56
48
|
} from "../limits.js";
|
|
57
49
|
import {
|
|
58
50
|
MAX_NOTIFICATIONS_PAGE,
|
|
@@ -80,6 +72,8 @@ import { createRunner, GIT_TOKEN_SECRET, type Runner, type RunnerEnd } from "../
|
|
|
80
72
|
import type { ServiceCommand } from "../runner/types.js";
|
|
81
73
|
import {
|
|
82
74
|
hostOfLogin,
|
|
75
|
+
isPackNotePath,
|
|
76
|
+
type RestAgentInput,
|
|
83
77
|
type RestAgentSetup,
|
|
84
78
|
type RestAnswerInput,
|
|
85
79
|
type RestClaim,
|
|
@@ -98,7 +92,9 @@ import {
|
|
|
98
92
|
type RestSignal,
|
|
99
93
|
type RestTask,
|
|
100
94
|
type RestTaskPatch,
|
|
95
|
+
type RestWorkspace,
|
|
101
96
|
} from "../schemas.js";
|
|
97
|
+
import { secretOfText } from "../secret-file.js";
|
|
102
98
|
import { agentLoginOf, deskRemoteOf } from "../services.js";
|
|
103
99
|
import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
|
|
104
100
|
import {
|
|
@@ -126,7 +122,6 @@ import {
|
|
|
126
122
|
WEEK_STARTS,
|
|
127
123
|
} from "../vocabulary.js";
|
|
128
124
|
import { loadWebRoot, type WebRoot, WebRootError } from "../web.js";
|
|
129
|
-
import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
|
|
130
125
|
import {
|
|
131
126
|
type CredentialStore,
|
|
132
127
|
type Credentials,
|
|
@@ -173,6 +168,9 @@ import {
|
|
|
173
168
|
formatNotifications,
|
|
174
169
|
formatOptions,
|
|
175
170
|
formatOwnWakeLine,
|
|
171
|
+
formatPackNoteClosed,
|
|
172
|
+
formatPackNoteLeft,
|
|
173
|
+
formatPackNotes,
|
|
176
174
|
formatPersonLine,
|
|
177
175
|
formatPersonWork,
|
|
178
176
|
formatPlugin,
|
|
@@ -203,6 +201,7 @@ import {
|
|
|
203
201
|
formatVersionLine,
|
|
204
202
|
formatWork,
|
|
205
203
|
formatWorkspace,
|
|
204
|
+
type KeeperCalled,
|
|
206
205
|
localized,
|
|
207
206
|
moment,
|
|
208
207
|
pageLine,
|
|
@@ -228,19 +227,7 @@ import {
|
|
|
228
227
|
standsInTheWay,
|
|
229
228
|
} from "./machine-check.js";
|
|
230
229
|
import type { NoticeStore } from "./notices.js";
|
|
231
|
-
import {
|
|
232
|
-
type ConsolePack,
|
|
233
|
-
consolePack,
|
|
234
|
-
formatSkills,
|
|
235
|
-
holdsNothing,
|
|
236
|
-
ORGANIZATION_PACK_LINE,
|
|
237
|
-
type PackOwner,
|
|
238
|
-
PackRefusal,
|
|
239
|
-
packWords,
|
|
240
|
-
refusalWords,
|
|
241
|
-
skillPathIn,
|
|
242
|
-
skillsAround,
|
|
243
|
-
} from "./pack.js";
|
|
230
|
+
import type { ConsolePack, PackOwner } from "./pack.js";
|
|
244
231
|
import { keptBySourceOf, keptFileOf, runnerStateOf } from "./runner-files.js";
|
|
245
232
|
import { type RunnerHost, workPath } from "./runner-host.js";
|
|
246
233
|
import { secretNotes } from "./secret-notes.js";
|
|
@@ -253,6 +240,7 @@ import {
|
|
|
253
240
|
RecordsRootError,
|
|
254
241
|
} from "./serve.js";
|
|
255
242
|
import type { Ran, SetupMachine } from "./setup-machine.js";
|
|
243
|
+
import { skillPathIn } from "./skill-path.js";
|
|
256
244
|
|
|
257
245
|
// The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
|
|
258
246
|
// the REST API with no logic of its own: every command is one or two requests and the words to
|
|
@@ -419,12 +407,36 @@ function parse(args: readonly string[], options: OptionSpec, allowPositionals =
|
|
|
419
407
|
options: { ...GLOBAL_OPTIONS, ...options },
|
|
420
408
|
allowPositionals,
|
|
421
409
|
strict: true,
|
|
410
|
+
// The words in the order they were typed, for a search, whose words are every bare word.
|
|
411
|
+
tokens: true,
|
|
422
412
|
});
|
|
423
413
|
} catch (error) {
|
|
424
414
|
throw misuse(refusedByParser(error, options));
|
|
425
415
|
}
|
|
426
416
|
}
|
|
427
417
|
|
|
418
|
+
/**
|
|
419
|
+
* The words of a search as they were typed (ADR-0179): what `--search` was given and every
|
|
420
|
+
* bare word, in their order, as the skillcdn command takes every word after `find` as the
|
|
421
|
+
* query. So `--search card news` asks for two words, where the second was once read as a
|
|
422
|
+
* folder and the search, of one word in a folder nobody named, found nothing. Nothing where no
|
|
423
|
+
* `--search` was typed: a bare word is then the command's own to read.
|
|
424
|
+
*/
|
|
425
|
+
function searchTyped(parsed: ReturnType<typeof parse>): string | undefined {
|
|
426
|
+
if (typeof parsed.values.search !== "string") {
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
const typed: string[] = [];
|
|
430
|
+
for (const token of parsed.tokens) {
|
|
431
|
+
if (token.kind === "positional") {
|
|
432
|
+
typed.push(token.value);
|
|
433
|
+
} else if (token.kind === "option" && token.name === "search" && token.value !== undefined) {
|
|
434
|
+
typed.push(token.value);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return typed.join(" ").trim();
|
|
438
|
+
}
|
|
439
|
+
|
|
428
440
|
/**
|
|
429
441
|
* What the parser refused, in the command's own words (ADR-0167): an option that is none of
|
|
430
442
|
* the command's is answered with those it takes, so that the next try needs no page of help;
|
|
@@ -1673,11 +1685,15 @@ const projects: Command = async (args, io) => {
|
|
|
1673
1685
|
const { values } = parse(args, {}, false);
|
|
1674
1686
|
const session = await open(io, values);
|
|
1675
1687
|
const found = await session.client.projects();
|
|
1676
|
-
|
|
1688
|
+
// In none: an administrator makes one, and anyone else is listed in one by an administrator.
|
|
1689
|
+
// Asked only then, so that a listing costs no request more.
|
|
1690
|
+
const none =
|
|
1677
1691
|
found.items.length === 0
|
|
1678
|
-
?
|
|
1679
|
-
|
|
1680
|
-
|
|
1692
|
+
? (await session.client.me()).person?.role === "admin"
|
|
1693
|
+
? 'No projects you may work in. Make one: console project new <key> "<name>"'
|
|
1694
|
+
: "No projects you may work in. An administrator lists you in one, or opens one to the workspace, which has everyone in it."
|
|
1695
|
+
: undefined;
|
|
1696
|
+
answer(io, session, found, () => none ?? found.items.map(formatProjectLine).join("\n"));
|
|
1681
1697
|
return EXIT.ok;
|
|
1682
1698
|
};
|
|
1683
1699
|
|
|
@@ -1737,23 +1753,40 @@ async function endOfWeek(io: CliIo, session: Session, today: string): Promise<st
|
|
|
1737
1753
|
return weekOf(today, firstDayOfWeek(language, me.workspace.weekStart ?? "auto")).at(-1) ?? today;
|
|
1738
1754
|
}
|
|
1739
1755
|
|
|
1756
|
+
/**
|
|
1757
|
+
* The words a listing is searched by (ADR-0179): what `--search` was given and every bare word,
|
|
1758
|
+
* in the order typed, for a listing that takes no word of its own. A bare word without
|
|
1759
|
+
* `--search` is not understood, and the answer says where the words of a search go.
|
|
1760
|
+
*/
|
|
1761
|
+
function listingSearch(parsed: ReturnType<typeof parse>, command: string): string | undefined {
|
|
1762
|
+
const search = searchTyped(parsed);
|
|
1763
|
+
if (search === undefined && parsed.positionals.length > 0) {
|
|
1764
|
+
throw misuse(
|
|
1765
|
+
`This command takes no word beside its options: ${parsed.positionals[0]}. The words of a search go after --search: ${command} --search "<words>"`,
|
|
1766
|
+
);
|
|
1767
|
+
}
|
|
1768
|
+
if (search === "") {
|
|
1769
|
+
throw misuse(`Say what to search for: ${command} --search "<words>"`);
|
|
1770
|
+
}
|
|
1771
|
+
return search;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1740
1774
|
const tasks: Command = async (args, io) => {
|
|
1741
|
-
const
|
|
1742
|
-
|
|
1743
|
-
{
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
);
|
|
1775
|
+
const parsed = parse(args, {
|
|
1776
|
+
state: { type: "string" },
|
|
1777
|
+
open: { type: "boolean" },
|
|
1778
|
+
mine: { type: "boolean" },
|
|
1779
|
+
unassigned: { type: "boolean" },
|
|
1780
|
+
category: { type: "string" },
|
|
1781
|
+
goal: { type: "string" },
|
|
1782
|
+
due: { type: "string" },
|
|
1783
|
+
search: { type: "string" },
|
|
1784
|
+
archived: { type: "boolean" },
|
|
1785
|
+
...PAGE_OPTIONS,
|
|
1786
|
+
});
|
|
1787
|
+
const { values } = parsed;
|
|
1788
|
+
// Every bare word is of the search where --search was typed, and no word goes without it.
|
|
1789
|
+
const search = listingSearch(parsed, "console tasks");
|
|
1757
1790
|
const state = stateOf(text(values, "state"));
|
|
1758
1791
|
if (on(values, "mine") && on(values, "unassigned")) {
|
|
1759
1792
|
throw misuse(
|
|
@@ -1775,10 +1808,6 @@ const tasks: Command = async (args, io) => {
|
|
|
1775
1808
|
? await endOfWeek(io, session, today)
|
|
1776
1809
|
: (dayOf(io, due) ?? undefined);
|
|
1777
1810
|
const worker = on(values, "mine") ? ((await personIdOf(session, "me")) ?? undefined) : undefined;
|
|
1778
|
-
const search = text(values, "search")?.trim();
|
|
1779
|
-
if (search === "") {
|
|
1780
|
-
throw misuse("Say what to search for: console tasks --search <words>");
|
|
1781
|
-
}
|
|
1782
1811
|
const filter = {
|
|
1783
1812
|
...(state === undefined ? {} : { state }),
|
|
1784
1813
|
...(on(values, "open") || due === "overdue" ? { open: true } : {}),
|
|
@@ -1841,13 +1870,41 @@ const categories: Command = async (args, io) => {
|
|
|
1841
1870
|
/** What reads a pack: a project's client, a plugin's, whose skills are a pack of their own, or the console's for the organization's. */
|
|
1842
1871
|
type PackReader = PackClient;
|
|
1843
1872
|
|
|
1873
|
+
/**
|
|
1874
|
+
* The reads of a pack, with the skillcdn command's own library behind them (ADR-0124), loaded
|
|
1875
|
+
* by the commands that read a pack and by no other (ADR-0179): importing it loads the whole of
|
|
1876
|
+
* @skillcdn/cli and @skillcdn/core, a quarter of a second that a report, a take or a page of
|
|
1877
|
+
* help would pay for nothing.
|
|
1878
|
+
*/
|
|
1879
|
+
type PackReads = typeof import("./pack.js");
|
|
1880
|
+
const packReads = (): Promise<PackReads> => import("./pack.js");
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* The reads of a pack where only a word is to be spelled, after an act that is done: nothing
|
|
1884
|
+
* where the library does not load, so that what was done is said all the same and the words
|
|
1885
|
+
* are named in a sentence, never a line, as where a word has no spelling every shell takes.
|
|
1886
|
+
*/
|
|
1887
|
+
async function packReadsAfter(): Promise<PackReads | undefined> {
|
|
1888
|
+
try {
|
|
1889
|
+
return await packReads();
|
|
1890
|
+
} catch {
|
|
1891
|
+
return undefined;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
/** The flags `whereGiven` names, said in words: `--project and --url`. */
|
|
1896
|
+
const flagNamesOf = (given: readonly string[]): string =>
|
|
1897
|
+
given.filter((_, index) => index % 2 === 0).join(" and ");
|
|
1898
|
+
|
|
1844
1899
|
const SKILLS_OPTIONS: OptionSpec = {
|
|
1845
1900
|
search: { type: "string" },
|
|
1846
1901
|
path: { type: "string" },
|
|
1902
|
+
full: { type: "boolean" },
|
|
1847
1903
|
limit: { type: "string" },
|
|
1848
1904
|
cursor: { type: "string" },
|
|
1849
1905
|
rows: { type: "boolean" },
|
|
1850
1906
|
code: { type: "boolean" },
|
|
1907
|
+
kinds: { type: "boolean" },
|
|
1851
1908
|
heading: { type: "string" },
|
|
1852
1909
|
format: { type: "string" },
|
|
1853
1910
|
grep: { type: "string" },
|
|
@@ -1861,6 +1918,7 @@ const SKILLS_OPTIONS: OptionSpec = {
|
|
|
1861
1918
|
* the status. Thrown by the caller, so that nothing follows it.
|
|
1862
1919
|
*/
|
|
1863
1920
|
function refusedRead(
|
|
1921
|
+
reads: PackReads,
|
|
1864
1922
|
io: CliIo,
|
|
1865
1923
|
session: Session,
|
|
1866
1924
|
owner: PackOwner,
|
|
@@ -1870,7 +1928,7 @@ function refusedRead(
|
|
|
1870
1928
|
if (session.json) {
|
|
1871
1929
|
io.stdout(`${JSON.stringify(answered, null, 2)}\n`);
|
|
1872
1930
|
}
|
|
1873
|
-
return failed(owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words}` : words);
|
|
1931
|
+
return failed(owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words}` : words);
|
|
1874
1932
|
}
|
|
1875
1933
|
|
|
1876
1934
|
/** A whole number a flag carries, within its bounds; nothing when it is not given. */
|
|
@@ -1899,11 +1957,16 @@ function countOf(
|
|
|
1899
1957
|
* A number a read of a pack takes, checked as the skillcdn command checks it and said in its
|
|
1900
1958
|
* words, before anything is asked of the console.
|
|
1901
1959
|
*/
|
|
1902
|
-
function checkedNumber(
|
|
1960
|
+
function checkedNumber(
|
|
1961
|
+
reads: PackReads,
|
|
1962
|
+
given: string | undefined,
|
|
1963
|
+
name: string,
|
|
1964
|
+
most: number,
|
|
1965
|
+
): void {
|
|
1903
1966
|
try {
|
|
1904
|
-
readNumber(given, name, most);
|
|
1967
|
+
reads.readNumber(given, name, most);
|
|
1905
1968
|
} catch (error) {
|
|
1906
|
-
throw error instanceof ReadMisuse ? misuse(error.message) : error;
|
|
1969
|
+
throw error instanceof reads.ReadMisuse ? misuse(error.message) : error;
|
|
1907
1970
|
}
|
|
1908
1971
|
}
|
|
1909
1972
|
|
|
@@ -1929,6 +1992,7 @@ function whereGiven(values: Readonly<Record<string, unknown>>): readonly string[
|
|
|
1929
1992
|
* the whole output is one a host shows whole.
|
|
1930
1993
|
*/
|
|
1931
1994
|
async function readThrough(
|
|
1995
|
+
reads: PackReads,
|
|
1932
1996
|
io: CliIo,
|
|
1933
1997
|
session: Session,
|
|
1934
1998
|
owner: PackOwner,
|
|
@@ -1938,26 +2002,30 @@ async function readThrough(
|
|
|
1938
2002
|
readonly words: ToolWords;
|
|
1939
2003
|
readonly nextPart?: ((cursor: string) => string) | undefined;
|
|
1940
2004
|
readonly browseFolder?: ((path: string) => string) | undefined;
|
|
2005
|
+
readonly readFile?: ((path: string) => string) | undefined;
|
|
2006
|
+
readonly loadFound?: string | undefined;
|
|
1941
2007
|
readonly data?: boolean | undefined;
|
|
1942
2008
|
readonly beside?: readonly (string | undefined)[] | undefined;
|
|
1943
2009
|
},
|
|
1944
2010
|
): Promise<ReadOutput> {
|
|
1945
2011
|
try {
|
|
1946
|
-
return await readPack(pack, read, {
|
|
2012
|
+
return await reads.readPack(pack, read, {
|
|
1947
2013
|
words: options.words,
|
|
1948
2014
|
json: session.json,
|
|
1949
2015
|
nextPart: options.nextPart,
|
|
1950
2016
|
browseFolder: options.browseFolder,
|
|
1951
|
-
|
|
2017
|
+
readFile: options.readFile,
|
|
2018
|
+
loadFound: options.loadFound,
|
|
2019
|
+
room: roomFor(reads, owner, options.beside ?? []),
|
|
1952
2020
|
});
|
|
1953
2021
|
} catch (error) {
|
|
1954
|
-
if (error instanceof ReadMisuse) {
|
|
2022
|
+
if (error instanceof reads.ReadMisuse) {
|
|
1955
2023
|
throw misuse(error.message);
|
|
1956
2024
|
}
|
|
1957
2025
|
const refusal =
|
|
1958
|
-
error instanceof PackRefusal
|
|
1959
|
-
? { answer: error.answer, words: refusalWords(error.what, error.answer, owner) }
|
|
1960
|
-
: error instanceof PackError
|
|
2026
|
+
error instanceof reads.PackRefusal
|
|
2027
|
+
? { answer: error.answer, words: reads.refusalWords(error.what, error.answer, owner) }
|
|
2028
|
+
: error instanceof reads.PackError
|
|
1961
2029
|
? { answer: pack.answered(), words: `${error.code}: ${error.message}` }
|
|
1962
2030
|
: undefined;
|
|
1963
2031
|
if (refusal === undefined) {
|
|
@@ -1965,7 +2033,7 @@ async function readThrough(
|
|
|
1965
2033
|
}
|
|
1966
2034
|
throw options.data === true || refusal.answer === undefined
|
|
1967
2035
|
? failed(refusal.words)
|
|
1968
|
-
: refusedRead(io, session, owner, refusal.answer, refusal.words);
|
|
2036
|
+
: refusedRead(reads, io, session, owner, refusal.answer, refusal.words);
|
|
1969
2037
|
}
|
|
1970
2038
|
}
|
|
1971
2039
|
|
|
@@ -1974,10 +2042,14 @@ async function readThrough(
|
|
|
1974
2042
|
* its own with the break that sets it apart, and the line that says the pack is the
|
|
1975
2043
|
* organization's where it is.
|
|
1976
2044
|
*/
|
|
1977
|
-
function roomFor(
|
|
1978
|
-
|
|
2045
|
+
function roomFor(
|
|
2046
|
+
reads: PackReads,
|
|
2047
|
+
owner: PackOwner,
|
|
2048
|
+
beside: readonly (string | undefined)[],
|
|
2049
|
+
): number {
|
|
2050
|
+
const lines = [owner === "organization" ? reads.ORGANIZATION_PACK_LINE : undefined, ...beside];
|
|
1979
2051
|
return lines.reduce(
|
|
1980
|
-
(bytes, line) => (line === undefined ? bytes : bytes + utf8Length(line) + 1),
|
|
2052
|
+
(bytes, line) => (line === undefined ? bytes : bytes + reads.utf8Length(line) + 1),
|
|
1981
2053
|
0,
|
|
1982
2054
|
);
|
|
1983
2055
|
}
|
|
@@ -1997,6 +2069,7 @@ function jsonOfRead(session: Session, pack: ConsolePack, output: ReadOutput): un
|
|
|
1997
2069
|
* refusal: a read the pack refused fails with why.
|
|
1998
2070
|
*/
|
|
1999
2071
|
async function readData(
|
|
2072
|
+
reads: PackReads,
|
|
2000
2073
|
io: CliIo,
|
|
2001
2074
|
session: Session,
|
|
2002
2075
|
pack: ConsolePack,
|
|
@@ -2008,12 +2081,12 @@ async function readData(
|
|
|
2008
2081
|
},
|
|
2009
2082
|
): Promise<number> {
|
|
2010
2083
|
const { read } = asked;
|
|
2011
|
-
const output = await readThrough(io, session, asked.owner, pack, read, {
|
|
2084
|
+
const output = await readThrough(reads, io, session, asked.owner, pack, read, {
|
|
2012
2085
|
words: asked.words,
|
|
2013
2086
|
data: true,
|
|
2014
2087
|
});
|
|
2015
2088
|
// Nothing is printed for nothing, which a program takes as it is; a line beside it says so.
|
|
2016
|
-
if (holdsNothing(output.holds) && asked.out === undefined && !session.json) {
|
|
2089
|
+
if (reads.holdsNothing(output.holds) && asked.out === undefined && !session.json) {
|
|
2017
2090
|
io.stderr(
|
|
2018
2091
|
`No ${read.read === "rows" ? "tables" : "code blocks"} in ${read.path ?? "the pack"}${read.heading === undefined ? "" : " under that heading"}.\n`,
|
|
2019
2092
|
);
|
|
@@ -2034,7 +2107,7 @@ async function readData(
|
|
|
2034
2107
|
} catch {
|
|
2035
2108
|
throw failed(`The file could not be written at ${asked.out}.`);
|
|
2036
2109
|
}
|
|
2037
|
-
io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
|
|
2110
|
+
io.stdout(`${reads.wroteLine(output.holds ?? "", saved)}\n`);
|
|
2038
2111
|
return EXIT.ok;
|
|
2039
2112
|
}
|
|
2040
2113
|
|
|
@@ -2050,17 +2123,28 @@ const PLUGIN_SKILLS_LINE =
|
|
|
2050
2123
|
"The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
|
|
2051
2124
|
|
|
2052
2125
|
/**
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2056
|
-
|
|
2126
|
+
* What stands in place of the line that reads on from a cursor where a word of it has no
|
|
2127
|
+
* spelling every shell takes: the cursor, and what to give it to. Its reader ran the command,
|
|
2128
|
+
* so it has the other words.
|
|
2129
|
+
*/
|
|
2130
|
+
const readOnWithoutLine = (reads: PackReads, cursor: string): string =>
|
|
2131
|
+
`the command you ran, with --cursor ${reads.commandLine("", [cursor])?.trim() ?? JSON.stringify(cursor)} in place of any it had, each word quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
|
|
2132
|
+
|
|
2133
|
+
/** A folder or a file of a pack as it was typed, without the slashes it may end with: `design/` is `design`, and `/` the root. */
|
|
2134
|
+
const folderOf = (typed: string | undefined): string | undefined => typed?.replace(/\/+$/, "");
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* The pack as the words say: whole, its kinds of work, a page of a folder or of a file's
|
|
2138
|
+
* outline, or what words find; for the project's pack as `console skills`, and for a plugin's
|
|
2139
|
+
* as `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
|
|
2140
|
+
* (ADR-0124), and asked for by that command's own arguments after the flag that names the read
|
|
2141
|
+
* (ADR-0179): with `--search`, every bare word is of the query and a folder is `--path`.
|
|
2057
2142
|
*/
|
|
2058
2143
|
async function readSkills(
|
|
2059
2144
|
io: CliIo,
|
|
2060
2145
|
session: Session,
|
|
2061
2146
|
reader: PackReader,
|
|
2062
|
-
|
|
2063
|
-
positionals: readonly string[],
|
|
2147
|
+
parsed: ReturnType<typeof parse>,
|
|
2064
2148
|
extras: {
|
|
2065
2149
|
/** The command these words came after, for what is said when they are not understood. */
|
|
2066
2150
|
readonly command: string;
|
|
@@ -2074,31 +2158,58 @@ async function readSkills(
|
|
|
2074
2158
|
readonly again?: readonly string[] | undefined;
|
|
2075
2159
|
},
|
|
2076
2160
|
): Promise<number> {
|
|
2161
|
+
const { values, positionals } = parsed;
|
|
2162
|
+
const reads = await packReads();
|
|
2077
2163
|
const owner = extras.owner ?? "project";
|
|
2164
|
+
const again = extras.again ?? [];
|
|
2078
2165
|
const say = (value: unknown, words: () => string): void =>
|
|
2079
|
-
answerPack(io, session, owner, value, words);
|
|
2166
|
+
answerPack(reads, io, session, owner, value, words);
|
|
2080
2167
|
// The reads by the names of this pack's own commands: a plugin's are not the project's.
|
|
2081
2168
|
const skillCommand = extras.command.replace(/skills$/, "skill");
|
|
2082
|
-
const toolWords = packWords(extras.command, skillCommand);
|
|
2083
|
-
// How a skill is loaded, said after a listing
|
|
2084
|
-
//
|
|
2169
|
+
const toolWords = reads.packWords(extras.command, skillCommand);
|
|
2170
|
+
// How a skill is loaded, said after a listing: the pack's own words there name how a section
|
|
2171
|
+
// is read, and a skill read as a file comes without its rules. A search says its next step
|
|
2172
|
+
// itself, once (`loadFound`).
|
|
2085
2173
|
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.`;
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
const
|
|
2091
|
-
const words = text(values, "search");
|
|
2092
|
-
const within = text(values, "path");
|
|
2174
|
+
const words = searchTyped(parsed);
|
|
2175
|
+
// A folder is taken as the pack prints it, `design/`, and as it is named, `design`, as a
|
|
2176
|
+
// folder of the documents is: the deployment refuses a path that ends with a slash.
|
|
2177
|
+
const within = folderOf(text(values, "path"));
|
|
2178
|
+
const full = on(values, "full");
|
|
2093
2179
|
const limit = text(values, "limit");
|
|
2094
2180
|
const cursor = text(values, "cursor");
|
|
2095
2181
|
const rows = on(values, "rows");
|
|
2096
2182
|
const code = on(values, "code");
|
|
2183
|
+
const kinds = on(values, "kinds");
|
|
2097
2184
|
const heading = text(values, "heading");
|
|
2098
2185
|
const out = text(values, "out");
|
|
2099
2186
|
const format = text(values, "format");
|
|
2100
2187
|
const grep = text(values, "grep");
|
|
2188
|
+
const searchUsage = `${extras.command} --search "<words>" [--path <folder>] [--full] [--limit <n>]`;
|
|
2189
|
+
// With --search every bare word is of the query; without it, the one bare word is a folder
|
|
2190
|
+
// or a file of the pack.
|
|
2191
|
+
if (words === undefined && positionals.length > 1) {
|
|
2192
|
+
throw misuse(
|
|
2193
|
+
`Say one folder, or the words of a search after --search: ${extras.command} [<folder>], or ${searchUsage}`,
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
if (words !== undefined && words.length === 0) {
|
|
2197
|
+
throw misuse(`Say what to search for: ${searchUsage}`);
|
|
2198
|
+
}
|
|
2199
|
+
// The root of the pack is the mounted folder, which the deployment reads as no path at all.
|
|
2200
|
+
const given = words === undefined ? folderOf(positionals[0]) : undefined;
|
|
2101
2201
|
const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
|
|
2202
|
+
// The kinds of work are of the pack whole, and are said in a few lines: nothing narrows them.
|
|
2203
|
+
if (
|
|
2204
|
+
kinds &&
|
|
2205
|
+
(given !== undefined ||
|
|
2206
|
+
rows ||
|
|
2207
|
+
code ||
|
|
2208
|
+
full ||
|
|
2209
|
+
[words, within, limit, cursor, heading, out, format, grep].some((one) => one !== undefined))
|
|
2210
|
+
) {
|
|
2211
|
+
throw misuse(`--kinds goes alone: ${extras.command} --kinds`);
|
|
2212
|
+
}
|
|
2102
2213
|
if (rows && code) {
|
|
2103
2214
|
throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
|
|
2104
2215
|
}
|
|
@@ -2123,20 +2234,18 @@ async function readSkills(
|
|
|
2123
2234
|
`--grep goes with --code: ${extras.command} --code [<folder|file>] [--grep <pattern>]`,
|
|
2124
2235
|
);
|
|
2125
2236
|
}
|
|
2126
|
-
// The folder a search keeps to is said
|
|
2127
|
-
//
|
|
2237
|
+
// The folder a search keeps to is said with --path, as the skillcdn command takes it, and
|
|
2238
|
+
// everything a search prints of a result with --full.
|
|
2128
2239
|
if (within !== undefined && words === undefined) {
|
|
2129
2240
|
throw misuse(
|
|
2130
|
-
`--path goes with --search; a folder is read with ${extras.command} <folder>: ${
|
|
2241
|
+
`--path goes with --search; a folder is read with ${extras.command} <folder>: ${searchUsage}`,
|
|
2131
2242
|
);
|
|
2132
2243
|
}
|
|
2133
|
-
if (
|
|
2134
|
-
throw misuse(
|
|
2135
|
-
`Say the folder once: after the words, or with --path: ${extras.command} --search <words> [<folder>]`,
|
|
2136
|
-
);
|
|
2244
|
+
if (full && words === undefined) {
|
|
2245
|
+
throw misuse(`--full goes with --search: ${searchUsage}`);
|
|
2137
2246
|
}
|
|
2138
2247
|
const named = given ?? within;
|
|
2139
|
-
const folder = named === undefined || named === "
|
|
2248
|
+
const folder = named === undefined || named === "" || named === "." ? undefined : named;
|
|
2140
2249
|
// The listing is as long as one read prints, and goes on from the cursor its page ended with.
|
|
2141
2250
|
if (words === undefined && given === undefined && limit !== undefined) {
|
|
2142
2251
|
throw misuse(
|
|
@@ -2144,20 +2253,25 @@ async function readSkills(
|
|
|
2144
2253
|
);
|
|
2145
2254
|
}
|
|
2146
2255
|
// A page of what words find, or of what a folder holds: the bounds of each, as the pack has them.
|
|
2147
|
-
checkedNumber(
|
|
2256
|
+
checkedNumber(
|
|
2257
|
+
reads,
|
|
2258
|
+
limit,
|
|
2259
|
+
"limit",
|
|
2260
|
+
words === undefined ? reads.BROWSE_MAX_LIMIT : reads.FIND_MAX_LIMIT,
|
|
2261
|
+
);
|
|
2148
2262
|
const listing = await reader.skills();
|
|
2149
2263
|
// With --json the console's own addresses stay in a document's outline; in words, the
|
|
2150
2264
|
// commands that read its tables and its code blocks.
|
|
2151
|
-
const pack = consolePack(reader, listing, {
|
|
2265
|
+
const pack = reads.consolePack(reader, listing, {
|
|
2152
2266
|
url: session.url,
|
|
2153
2267
|
dataCommand: session.json ? undefined : extras.command,
|
|
2154
2268
|
});
|
|
2155
2269
|
// As data: a read the pack refused fails with why, and nothing is printed.
|
|
2156
2270
|
if (rows || code) {
|
|
2157
2271
|
if (pack === undefined) {
|
|
2158
|
-
throw failed(refusalWords(rows ? "tables" : "code blocks", listing, owner));
|
|
2272
|
+
throw failed(reads.refusalWords(rows ? "tables" : "code blocks", listing, owner));
|
|
2159
2273
|
}
|
|
2160
|
-
return readData(io, session, pack, {
|
|
2274
|
+
return readData(reads, io, session, pack, {
|
|
2161
2275
|
read: rows
|
|
2162
2276
|
? { read: "rows", path: folder, heading, format }
|
|
2163
2277
|
: { read: "code", path: folder, heading, grep },
|
|
@@ -2169,15 +2283,50 @@ async function readSkills(
|
|
|
2169
2283
|
// A pack that does not answer: said as that, which a folder or a search would meet too.
|
|
2170
2284
|
if (pack === undefined) {
|
|
2171
2285
|
throw refusedRead(
|
|
2286
|
+
reads,
|
|
2172
2287
|
io,
|
|
2173
2288
|
session,
|
|
2174
2289
|
owner,
|
|
2175
2290
|
listing,
|
|
2176
|
-
[formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
|
|
2291
|
+
[reads.formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
|
|
2177
2292
|
.filter((part): part is string => part !== undefined)
|
|
2178
2293
|
.join("\n"),
|
|
2179
2294
|
);
|
|
2180
2295
|
}
|
|
2296
|
+
// A file of the pack is named by the line that reads it, whole, asked as this read was
|
|
2297
|
+
// (SkillCDN 0.6.4): the page a pack says to start from, an overview, the manifest.
|
|
2298
|
+
const readFile = (path: string): string =>
|
|
2299
|
+
reads.commandLine(skillCommand, ["--file", path, ...again]) ??
|
|
2300
|
+
`${skillCommand} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
|
|
2301
|
+
if (kinds) {
|
|
2302
|
+
// The kinds of work the pack has skills for (ADR-0176), as the skillcdn command reads them
|
|
2303
|
+
// (ADR-0179): its lines, its bound and its closing sentence, in the words of this pack's
|
|
2304
|
+
// commands, made of the one answer the console already has. Read once in a conversation.
|
|
2305
|
+
// --json is the kinds as that command prints them as data. The search and the load it
|
|
2306
|
+
// names are asked where this read was: without --project a desk reads the organization's
|
|
2307
|
+
// pack, which may be another than the one these kinds are of.
|
|
2308
|
+
const where = again.length === 0 ? "" : reads.commandLine("", again);
|
|
2309
|
+
const told = await readThrough(
|
|
2310
|
+
reads,
|
|
2311
|
+
io,
|
|
2312
|
+
session,
|
|
2313
|
+
owner,
|
|
2314
|
+
pack,
|
|
2315
|
+
{ read: "kinds" },
|
|
2316
|
+
{
|
|
2317
|
+
words:
|
|
2318
|
+
where === undefined
|
|
2319
|
+
? {
|
|
2320
|
+
...toolWords,
|
|
2321
|
+
search: `${extras.command} --search, asked with ${flagNamesOf(again)} as this read was and quoted for your shell,`,
|
|
2322
|
+
load: `${skillCommand}, asked so too,`,
|
|
2323
|
+
}
|
|
2324
|
+
: reads.packWords(`${extras.command}${where}`, `${skillCommand}${where}`),
|
|
2325
|
+
},
|
|
2326
|
+
);
|
|
2327
|
+
say(session.json ? JSON.parse(told.text) : undefined, () => told.text);
|
|
2328
|
+
return EXIT.ok;
|
|
2329
|
+
}
|
|
2181
2330
|
if (words === undefined && given === undefined) {
|
|
2182
2331
|
// --json is the console's listing as it answered it, whole; the words are the pack's own,
|
|
2183
2332
|
// read once more from that answer, a listing longer than one read prints in pages.
|
|
@@ -2187,7 +2336,7 @@ async function readSkills(
|
|
|
2187
2336
|
}
|
|
2188
2337
|
// The console's own lines stand around the first page, and the read keeps room for them
|
|
2189
2338
|
// and for the empty lines that set them apart.
|
|
2190
|
-
const around = skillsAround(listing, extras.own, toolWords);
|
|
2339
|
+
const around = reads.skillsAround(listing, extras.own, toolWords);
|
|
2191
2340
|
const own = [
|
|
2192
2341
|
...around.host,
|
|
2193
2342
|
...around.own,
|
|
@@ -2195,6 +2344,7 @@ async function readSkills(
|
|
|
2195
2344
|
...(extras.afterwards === undefined ? [] : [extras.afterwards]),
|
|
2196
2345
|
];
|
|
2197
2346
|
const told = await readThrough(
|
|
2347
|
+
reads,
|
|
2198
2348
|
io,
|
|
2199
2349
|
session,
|
|
2200
2350
|
owner,
|
|
@@ -2203,9 +2353,10 @@ async function readSkills(
|
|
|
2203
2353
|
{
|
|
2204
2354
|
words: toolWords,
|
|
2205
2355
|
beside: cursor === undefined ? [around.head, ...own, "", "", ""] : [],
|
|
2356
|
+
readFile,
|
|
2206
2357
|
nextPart: (next) =>
|
|
2207
|
-
commandLine(extras.command, ["--cursor", next, ...
|
|
2208
|
-
`${extras.command} with --cursor ${
|
|
2358
|
+
reads.commandLine(extras.command, ["--cursor", next, ...again]) ??
|
|
2359
|
+
`${extras.command} with --cursor ${reads.commandLine("", [next])?.trim() ?? JSON.stringify(next)}, each word quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
|
|
2209
2360
|
},
|
|
2210
2361
|
);
|
|
2211
2362
|
say(listing, () => {
|
|
@@ -2219,7 +2370,7 @@ async function readSkills(
|
|
|
2219
2370
|
// lines stand above the listing then, and after it where it is whole.
|
|
2220
2371
|
return told.next === undefined
|
|
2221
2372
|
? [
|
|
2222
|
-
formatSkills(listing, told.text, extras.own, owner, toolWords),
|
|
2373
|
+
reads.formatSkills(listing, told.text, extras.own, owner, toolWords),
|
|
2223
2374
|
loading,
|
|
2224
2375
|
...(extras.afterwards === undefined ? [] : [extras.afterwards]),
|
|
2225
2376
|
].join("\n")
|
|
@@ -2229,52 +2380,63 @@ async function readSkills(
|
|
|
2229
2380
|
}
|
|
2230
2381
|
// The command that reads the next page of a folder or of a search (SkillCDN 0.6.3): this
|
|
2231
2382
|
// one again, asked as it was, with the cursor the page ended on. Where a word of it has no
|
|
2232
|
-
// spelling
|
|
2383
|
+
// spelling every shell takes, the command that was run is run again, and the line says why.
|
|
2233
2384
|
const nextPage =
|
|
2234
2385
|
(asked: readonly string[]) =>
|
|
2235
2386
|
(next: string): string =>
|
|
2236
|
-
commandLine(extras.command, [
|
|
2387
|
+
reads.commandLine(extras.command, [
|
|
2237
2388
|
...asked,
|
|
2238
2389
|
...(limit === undefined ? [] : ["--limit", limit]),
|
|
2390
|
+
...(full ? ["--full"] : []),
|
|
2239
2391
|
"--cursor",
|
|
2240
2392
|
next,
|
|
2241
|
-
...
|
|
2242
|
-
]) ??
|
|
2243
|
-
`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}`;
|
|
2393
|
+
...again,
|
|
2394
|
+
]) ?? readOnWithoutLine(reads, next);
|
|
2244
2395
|
if (words !== undefined) {
|
|
2245
|
-
// One page of what the words find,
|
|
2246
|
-
//
|
|
2396
|
+
// One page of what the words find, as the skillcdn command prints it (ADR-0179): each
|
|
2397
|
+
// result with what choosing needs and how it matches, and, where a skill was found, the
|
|
2398
|
+
// next step once, the command that loads it, asked as this search was. A page that ends
|
|
2399
|
+
// before the results do ends with the command that reads the next: the words as one word
|
|
2400
|
+
// of the line, which every version of the command reads as the query, the folder as --path.
|
|
2401
|
+
const where = reads.commandLine("", again);
|
|
2247
2402
|
const found = await readThrough(
|
|
2403
|
+
reads,
|
|
2248
2404
|
io,
|
|
2249
2405
|
session,
|
|
2250
2406
|
owner,
|
|
2251
2407
|
pack,
|
|
2252
|
-
{ read: "find", words, path: folder, cursor, limit },
|
|
2408
|
+
{ read: "find", words, path: folder, cursor, limit, full },
|
|
2253
2409
|
{
|
|
2254
2410
|
words: toolWords,
|
|
2255
|
-
|
|
2411
|
+
readFile,
|
|
2412
|
+
loadFound:
|
|
2413
|
+
where === undefined
|
|
2414
|
+
? `${skillCommand} with its path and where this pack is read, each quoted for your shell. ${reads.NO_LINE_TO_RUN}`
|
|
2415
|
+
: `${skillCommand} <its path>${where}`,
|
|
2256
2416
|
nextPart: nextPage([
|
|
2257
2417
|
"--search",
|
|
2258
2418
|
words,
|
|
2259
|
-
...(
|
|
2260
|
-
...(within === undefined ? [] : ["--path", within]),
|
|
2419
|
+
...(folder === undefined ? [] : ["--path", folder]),
|
|
2261
2420
|
]),
|
|
2262
2421
|
},
|
|
2263
2422
|
);
|
|
2264
|
-
say(jsonOfRead(session, pack, found), () =>
|
|
2265
|
-
found.next === undefined ? `${found.text}\n${loading}` : `${loading}\n${found.text}`,
|
|
2266
|
-
);
|
|
2423
|
+
say(jsonOfRead(session, pack, found), () => found.text);
|
|
2267
2424
|
return EXIT.ok;
|
|
2268
2425
|
}
|
|
2269
2426
|
// One page of the folder, or of a file's outline, as the skillcdn command browses: a page
|
|
2270
2427
|
// that ends before the folder does ends with the command that reads the next.
|
|
2271
2428
|
const browsed = await readThrough(
|
|
2429
|
+
reads,
|
|
2272
2430
|
io,
|
|
2273
2431
|
session,
|
|
2274
2432
|
owner,
|
|
2275
2433
|
pack,
|
|
2276
2434
|
{ read: "browse", path: folder, cursor, limit },
|
|
2277
|
-
{
|
|
2435
|
+
{
|
|
2436
|
+
words: toolWords,
|
|
2437
|
+
readFile,
|
|
2438
|
+
nextPart: nextPage(folder === undefined ? [] : [folder]),
|
|
2439
|
+
},
|
|
2278
2440
|
);
|
|
2279
2441
|
say(jsonOfRead(session, pack, browsed), () => browsed.text);
|
|
2280
2442
|
return EXIT.ok;
|
|
@@ -2298,6 +2460,7 @@ async function packNamed(
|
|
|
2298
2460
|
* the line that says so. `--json` stays what the console answered.
|
|
2299
2461
|
*/
|
|
2300
2462
|
function answerPack(
|
|
2463
|
+
reads: PackReads,
|
|
2301
2464
|
io: CliIo,
|
|
2302
2465
|
session: Session,
|
|
2303
2466
|
owner: PackOwner,
|
|
@@ -2305,15 +2468,158 @@ function answerPack(
|
|
|
2305
2468
|
words: () => string,
|
|
2306
2469
|
): void {
|
|
2307
2470
|
answer(io, session, value, () =>
|
|
2308
|
-
owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words()}` : words(),
|
|
2471
|
+
owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words()}` : words(),
|
|
2472
|
+
);
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
/**
|
|
2476
|
+
* What the console answers of the notes on the pack (ADR-0178), where it has them: one of
|
|
2477
|
+
* before answers their path as nothing, which is said as what it is, with where the finding
|
|
2478
|
+
* goes meanwhile, since a skill's load named the command whatever the console is.
|
|
2479
|
+
*/
|
|
2480
|
+
async function ofPackNotes<T>(io: CliIo, asked: Promise<T>): Promise<T> {
|
|
2481
|
+
try {
|
|
2482
|
+
return await asked;
|
|
2483
|
+
} catch (error) {
|
|
2484
|
+
if (noSuchRoute(error)) {
|
|
2485
|
+
const version = io.consoleVersion?.();
|
|
2486
|
+
throw failed(
|
|
2487
|
+
`This console${version === undefined ? "" : `, ${version},`} takes no notes on the pack yet: it is older than the command. Say what the run showed where the work is reported.`,
|
|
2488
|
+
);
|
|
2489
|
+
}
|
|
2490
|
+
throw error;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
/** What `console skills --notes` takes beside what a read of the pack takes. */
|
|
2495
|
+
const SKILLS_NOTES_OPTIONS: OptionSpec = {
|
|
2496
|
+
notes: { type: "boolean" },
|
|
2497
|
+
all: { type: "boolean" },
|
|
2498
|
+
mine: { type: "boolean" },
|
|
2499
|
+
offset: { type: "string" },
|
|
2500
|
+
};
|
|
2501
|
+
const SKILLS_NOTES_USAGE =
|
|
2502
|
+
"console skills --notes [<folder|path>] [--all] [--mine] [--limit <n>] [--offset <n>]";
|
|
2503
|
+
|
|
2504
|
+
/** How a keeper closes a note, and how an author takes one back: said under a list of them. */
|
|
2505
|
+
const NOTE_CLOSING =
|
|
2506
|
+
'Close one with what became of it: console skill note <id> --done "<what changed, and where>", or --drop "<why nothing was>".';
|
|
2507
|
+
const NOTE_TAKING_BACK =
|
|
2508
|
+
'These are your own; whoever keeps the skills reads everyone\'s. Take one back: console skill note <id> --drop "<why>".';
|
|
2509
|
+
|
|
2510
|
+
/**
|
|
2511
|
+
* The notes on the pack (ADR-0178), as the asker reads them: everyone's for whoever keeps the
|
|
2512
|
+
* skills and for an administrator, their own for anyone else. To whoever keeps them, the list
|
|
2513
|
+
* ends with how one is closed and where a keeper's work is written, the skill keeping-the-pack
|
|
2514
|
+
* with its place on this machine: a keeper woken for a round reads it from here, and nobody
|
|
2515
|
+
* else pays for a word of it.
|
|
2516
|
+
*/
|
|
2517
|
+
async function listNotes(
|
|
2518
|
+
io: CliIo,
|
|
2519
|
+
session: Session,
|
|
2520
|
+
values: Values,
|
|
2521
|
+
positionals: readonly string[],
|
|
2522
|
+
): Promise<number> {
|
|
2523
|
+
if (positionals.length > 1) {
|
|
2524
|
+
throw misuse(`Say one folder or path: ${SKILLS_NOTES_USAGE}`);
|
|
2525
|
+
}
|
|
2526
|
+
if (
|
|
2527
|
+
["search", "path", "cursor", "heading", "format", "grep", "out"].some(
|
|
2528
|
+
(name) => text(values, name) !== undefined,
|
|
2529
|
+
) ||
|
|
2530
|
+
["rows", "code", "kinds", "full"].some((name) => on(values, name))
|
|
2531
|
+
) {
|
|
2532
|
+
throw misuse(
|
|
2533
|
+
`--notes lists the notes on the pack, and reads nothing of it: ${SKILLS_NOTES_USAGE}`,
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
const limit = numberOf(text(values, "limit"), "limit", 1, MAX_PACK_NOTES_PAGE_LIMIT);
|
|
2537
|
+
const offset = numberOf(text(values, "offset"), "offset", 0, 1_000_000);
|
|
2538
|
+
const all = on(values, "all");
|
|
2539
|
+
const page = { limit: limit ?? PACK_NOTES_PAGE_LIMIT, offset: offset ?? 0, all };
|
|
2540
|
+
const found = await ofPackNotes(
|
|
2541
|
+
io,
|
|
2542
|
+
session.client.packNotes({
|
|
2543
|
+
state: all ? "all" : "open",
|
|
2544
|
+
mine: on(values, "mine"),
|
|
2545
|
+
path: positionals[0] === undefined ? undefined : notePathOf(positionals[0]),
|
|
2546
|
+
limit: page.limit,
|
|
2547
|
+
offset: page.offset,
|
|
2548
|
+
}),
|
|
2309
2549
|
);
|
|
2550
|
+
const closing = found.everyones
|
|
2551
|
+
? [
|
|
2552
|
+
NOTE_CLOSING,
|
|
2553
|
+
`What whoever keeps the skills changes alone, what waits for a person and what a round may spend is the skill keeping-the-pack, shipped with this command${io.skillsDir === undefined ? " (in the skills folder of the package @skillcdn/console, which this build has none of beside it)." : `: ${ownSkillPath(io.skillsDir, "keeping-the-pack")}`}`,
|
|
2554
|
+
]
|
|
2555
|
+
: found.items.length === 0
|
|
2556
|
+
? []
|
|
2557
|
+
: [NOTE_TAKING_BACK];
|
|
2558
|
+
answer(io, session, found, () => formatPackNotes(found, page, closing));
|
|
2559
|
+
return EXIT.ok;
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
/** A whole number a flag names, within its bounds; nothing where the flag was not given. */
|
|
2563
|
+
function numberOf(
|
|
2564
|
+
given: string | undefined,
|
|
2565
|
+
name: string,
|
|
2566
|
+
least: number,
|
|
2567
|
+
most: number,
|
|
2568
|
+
): number | undefined {
|
|
2569
|
+
if (given === undefined) {
|
|
2570
|
+
return undefined;
|
|
2571
|
+
}
|
|
2572
|
+
const value = Number(given);
|
|
2573
|
+
if (!/^\d+$/.test(given) || value < least || value > most) {
|
|
2574
|
+
throw misuse(`--${name} is a whole number from ${least} to ${most}: ${given}`);
|
|
2575
|
+
}
|
|
2576
|
+
return value;
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* A path of the pack as a note names it: from the root, with no slash at either end, and a
|
|
2581
|
+
* skill by its folder, which is what a skill is called, whether its `SKILL.md` or its folder
|
|
2582
|
+
* was said. A URI the pack names a skill by is its path.
|
|
2583
|
+
*/
|
|
2584
|
+
function notePathOf(given: string): string {
|
|
2585
|
+
const named = skillPathIn(given, null);
|
|
2586
|
+
if ("error" in named) {
|
|
2587
|
+
throw misuse(named.error);
|
|
2588
|
+
}
|
|
2589
|
+
const from = (given.startsWith("skill://") ? named.path : given)
|
|
2590
|
+
.trim()
|
|
2591
|
+
.replace(/^(?:\.\/)+/, "")
|
|
2592
|
+
.replace(/^\/+|\/+$/g, "");
|
|
2593
|
+
// A pack that is one skill has it at its root, which the load's own line calls `.`.
|
|
2594
|
+
if (from === "." || from === "SKILL.md") {
|
|
2595
|
+
return ".";
|
|
2596
|
+
}
|
|
2597
|
+
const path = from.replace(/\/SKILL\.md$/, "");
|
|
2598
|
+
if (path.length === 0) {
|
|
2599
|
+
throw misuse(
|
|
2600
|
+
'Say which skill or page the note is on, by its path in the pack; for a job no skill fit: console skill note --none "<the job, and the words searched>"',
|
|
2601
|
+
);
|
|
2602
|
+
}
|
|
2603
|
+
if (!isPackNotePath(path)) {
|
|
2604
|
+
throw misuse(
|
|
2605
|
+
`Not a path of the pack: ${given}. Say the skill's folder or the page's path from the pack's root, as console skills lists it, with no . or .. among its parts.`,
|
|
2606
|
+
);
|
|
2607
|
+
}
|
|
2608
|
+
return path;
|
|
2310
2609
|
}
|
|
2311
2610
|
|
|
2312
2611
|
const skills: Command = async (args, io) => {
|
|
2313
|
-
const
|
|
2612
|
+
const parsed = parse(args, { ...SKILLS_OPTIONS, ...SKILLS_NOTES_OPTIONS });
|
|
2613
|
+
const { values, positionals } = parsed;
|
|
2614
|
+
if (on(values, "notes")) {
|
|
2615
|
+
return listNotes(io, await open(io, values), values, positionals);
|
|
2616
|
+
}
|
|
2617
|
+
if (on(values, "all") || on(values, "mine") || text(values, "offset") !== undefined) {
|
|
2618
|
+
throw misuse(`--all, --mine and --offset go with --notes: ${SKILLS_NOTES_USAGE}`);
|
|
2619
|
+
}
|
|
2314
2620
|
const session = await open(io, values);
|
|
2315
2621
|
const { reader, owner } = await packNamed(session);
|
|
2316
|
-
return readSkills(io, session, reader,
|
|
2622
|
+
return readSkills(io, session, reader, parsed, {
|
|
2317
2623
|
command: "console skills",
|
|
2318
2624
|
own: io.skillsDir,
|
|
2319
2625
|
afterwards: PLUGIN_SKILLS_LINE,
|
|
@@ -2340,9 +2646,10 @@ async function readSkill(
|
|
|
2340
2646
|
owner: PackOwner = "project",
|
|
2341
2647
|
again: readonly string[] = [],
|
|
2342
2648
|
): Promise<number> {
|
|
2649
|
+
const reads = await packReads();
|
|
2343
2650
|
const say = (value: unknown, words: () => string): void =>
|
|
2344
|
-
answerPack(io, session, owner, value, words);
|
|
2345
|
-
const toolWords = packWords(`${command}s`, command);
|
|
2651
|
+
answerPack(reads, io, session, owner, value, words);
|
|
2652
|
+
const toolWords = reads.packWords(`${command}s`, command);
|
|
2346
2653
|
const file = text(values, "file");
|
|
2347
2654
|
const cursor = text(values, "cursor");
|
|
2348
2655
|
// A file is read by its own path from the repository's root; a skill's path beside it would be
|
|
@@ -2367,29 +2674,36 @@ async function readSkill(
|
|
|
2367
2674
|
`--cursor reads the next part of a skill; a file reads on from --offset: ${command} --file <path> [--offset <n>] [--limit <n>]`,
|
|
2368
2675
|
);
|
|
2369
2676
|
}
|
|
2370
|
-
checkedNumber(text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
|
|
2371
|
-
checkedNumber(text(values, "limit"), "limit", READ_FILE_MAX_LIMIT);
|
|
2677
|
+
checkedNumber(reads, text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
|
|
2678
|
+
checkedNumber(reads, text(values, "limit"), "limit", reads.READ_FILE_MAX_LIMIT);
|
|
2372
2679
|
const listing = await reader.skills();
|
|
2373
|
-
const pack = consolePack(reader, listing, { url: session.url });
|
|
2680
|
+
const pack = reads.consolePack(reader, listing, { url: session.url });
|
|
2374
2681
|
if (pack === undefined) {
|
|
2375
2682
|
throw refusedRead(
|
|
2683
|
+
reads,
|
|
2376
2684
|
io,
|
|
2377
2685
|
session,
|
|
2378
2686
|
owner,
|
|
2379
2687
|
listing,
|
|
2380
|
-
formatSkills(listing, undefined, io.skillsDir, owner, toolWords),
|
|
2688
|
+
reads.formatSkills(listing, undefined, io.skillsDir, owner, toolWords),
|
|
2381
2689
|
);
|
|
2382
2690
|
}
|
|
2691
|
+
// A file of the pack is named by the line that reads it, whole, asked as this read was
|
|
2692
|
+
// (SkillCDN 0.6.4): the source a skill names, and what a folder read as a file holds.
|
|
2693
|
+
const readFile = (path: string): string =>
|
|
2694
|
+
reads.commandLine(command, ["--file", path, ...again]) ??
|
|
2695
|
+
`${command} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
|
|
2383
2696
|
if (file !== undefined) {
|
|
2384
2697
|
// A page of the file, as the skillcdn command reads one: from --offset, as long as a host
|
|
2385
2698
|
// shows whole where --limit says nothing, and where the next begins when the file goes on.
|
|
2386
2699
|
const page = await readThrough(
|
|
2700
|
+
reads,
|
|
2387
2701
|
io,
|
|
2388
2702
|
session,
|
|
2389
2703
|
owner,
|
|
2390
2704
|
pack,
|
|
2391
2705
|
{ read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") },
|
|
2392
|
-
{ words: toolWords },
|
|
2706
|
+
{ words: toolWords, readFile },
|
|
2393
2707
|
);
|
|
2394
2708
|
say(jsonOfRead(session, pack, page), () => page.text);
|
|
2395
2709
|
return EXIT.ok;
|
|
@@ -2406,32 +2720,151 @@ async function readSkill(
|
|
|
2406
2720
|
// the cursor. A part says how many pages of the skill follow it and ends with the command
|
|
2407
2721
|
// that reads the next, asked as this one was, and the last says that it is the last: the
|
|
2408
2722
|
// words are the skillcdn command's own (SkillCDN 0.6.2), and only the line is made here.
|
|
2723
|
+
// What a load of the project's or the organization's pack ends with (ADR-0178): the command
|
|
2724
|
+
// that leaves a note on this skill, with its folder in it, read by whoever is about to use
|
|
2725
|
+
// the skill and nobody else. A plugin's pack is its package's, and takes no note here.
|
|
2726
|
+
const noting =
|
|
2727
|
+
command === "console skill" && !session.json
|
|
2728
|
+
? noteLineFor(reads, skillFolderOf(wanted.path), again)
|
|
2729
|
+
: undefined;
|
|
2409
2730
|
const loaded = await readThrough(
|
|
2731
|
+
reads,
|
|
2410
2732
|
io,
|
|
2411
2733
|
session,
|
|
2412
2734
|
owner,
|
|
2413
2735
|
pack,
|
|
2414
2736
|
{ read: "skill", path: wanted.path, cursor },
|
|
2415
2737
|
{
|
|
2738
|
+
beside: [noting],
|
|
2416
2739
|
words: toolWords,
|
|
2417
|
-
|
|
2418
|
-
//
|
|
2740
|
+
readFile,
|
|
2741
|
+
// Spelled so that every shell runs it as it is; where a word has no such spelling, the
|
|
2742
|
+
// command that was run is run again, with the cursor, and the line says why.
|
|
2419
2743
|
nextPart: (next) =>
|
|
2420
|
-
commandLine(command, [given, "--cursor", next, ...again]) ??
|
|
2421
|
-
|
|
2744
|
+
reads.commandLine(command, [given, "--cursor", next, ...again]) ??
|
|
2745
|
+
readOnWithoutLine(reads, next),
|
|
2422
2746
|
// The skill's own folder, where it does not list every file of it, as the command that
|
|
2423
2747
|
// lists a folder of this pack (SkillCDN 0.6.3): the dot for the root, since the command
|
|
2424
2748
|
// without a folder is the listing.
|
|
2425
2749
|
browseFolder: (path) =>
|
|
2426
|
-
commandLine(`${command}s`, [path.length === 0 ? "." : path, ...again]) ??
|
|
2427
|
-
`${command}s with this skill's folder, quoted for your shell. ${NO_LINE_TO_RUN}`,
|
|
2750
|
+
reads.commandLine(`${command}s`, [path.length === 0 ? "." : path, ...again]) ??
|
|
2751
|
+
`${command}s with this skill's folder, quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
|
|
2428
2752
|
},
|
|
2429
2753
|
);
|
|
2430
|
-
|
|
2754
|
+
// After the last part alone: a part that is not the last ends with the command for the next.
|
|
2755
|
+
say(jsonOfRead(session, pack, loaded), () =>
|
|
2756
|
+
noting === undefined || loaded.next !== undefined
|
|
2757
|
+
? loaded.text
|
|
2758
|
+
: `${loaded.text.replace(/\n+$/, "")}\n${noting}`,
|
|
2759
|
+
);
|
|
2760
|
+
return EXIT.ok;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
/** A skill's folder, which is what a skill is called, from the path of its `SKILL.md`. */
|
|
2764
|
+
const skillFolderOf = (path: string): string => path.replace(/(?:^|\/)SKILL\.md$/, "") || ".";
|
|
2765
|
+
|
|
2766
|
+
/**
|
|
2767
|
+
* The line a skill's load ends with: where a run shows the skill wrong or lacking, the command
|
|
2768
|
+
* that says so to whoever keeps the pack, asked as this load was. The words are a placeholder,
|
|
2769
|
+
* so the line is printed whole only where the folder has a spelling every shell takes.
|
|
2770
|
+
*/
|
|
2771
|
+
function noteLineFor(reads: PackReads, folder: string, again: readonly string[]): string {
|
|
2772
|
+
const line = reads.commandLine("console skill note", [folder]);
|
|
2773
|
+
const where = reads.commandLine("", again)?.trim() ?? "";
|
|
2774
|
+
return `Where a run shows this skill wrong or lacking, say so for whoever keeps the pack, as behavior and without the run's own material: ${line ?? "console skill note <this skill's folder>"} "<what the run showed>"${where.length === 0 ? "" : ` ${where}`}`;
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
const SKILL_NOTE_USAGE =
|
|
2778
|
+
'console skill note <path> "<what a run showed>" | console skill note --none "<the job, and the words searched>" | console skill note <id> --done "<what changed>" | console skill note <id> --drop "<why nothing was>"';
|
|
2779
|
+
const NOTE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2780
|
+
|
|
2781
|
+
/** What a note says, given as a word or, as `-`, on standard input: something, after its edges are trimmed. */
|
|
2782
|
+
async function noteWords(io: CliIo, given: string): Promise<string> {
|
|
2783
|
+
const words = (given === "-" ? await io.readStdin() : given).trim();
|
|
2784
|
+
if (words.length === 0) {
|
|
2785
|
+
throw misuse(`A note says something: ${SKILL_NOTE_USAGE}`);
|
|
2786
|
+
}
|
|
2787
|
+
if (words.length > MAX_PACK_NOTE_LENGTH) {
|
|
2788
|
+
throw misuse(
|
|
2789
|
+
`A note is at most ${MAX_PACK_NOTE_LENGTH} characters, and this is ${words.length}: say what the run showed in a few sentences, as behavior, without the run's own material.`,
|
|
2790
|
+
);
|
|
2791
|
+
}
|
|
2792
|
+
return words;
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
/**
|
|
2796
|
+
* A note on the pack (ADR-0178): left on a skill or a page of it, or with `--none` for a job no
|
|
2797
|
+
* skill fit, by anyone who works through the console; and closed, by its id, with what became
|
|
2798
|
+
* of it, by whoever keeps the skills, or taken back by its author. It is left on the pack the
|
|
2799
|
+
* command reads: the project's where one is named, else the organization's.
|
|
2800
|
+
*/
|
|
2801
|
+
async function skillNote(args: readonly string[], io: CliIo): Promise<number> {
|
|
2802
|
+
const { values, positionals } = parse(args, {
|
|
2803
|
+
none: { type: "boolean" },
|
|
2804
|
+
done: { type: "string" },
|
|
2805
|
+
drop: { type: "string" },
|
|
2806
|
+
});
|
|
2807
|
+
const done = text(values, "done");
|
|
2808
|
+
const drop = text(values, "drop");
|
|
2809
|
+
const none = on(values, "none");
|
|
2810
|
+
if (done !== undefined || drop !== undefined) {
|
|
2811
|
+
if ((done !== undefined && drop !== undefined) || none) {
|
|
2812
|
+
throw misuse(`Say one of --done and --drop, with the note's id: ${SKILL_NOTE_USAGE}`);
|
|
2813
|
+
}
|
|
2814
|
+
const id = theOne(
|
|
2815
|
+
positionals,
|
|
2816
|
+
`Say which note, by its id as console skills --notes lists it: ${SKILL_NOTE_USAGE}`,
|
|
2817
|
+
);
|
|
2818
|
+
if (!NOTE_ID.test(id)) {
|
|
2819
|
+
throw misuse(
|
|
2820
|
+
`Not a note's id: ${id}. console skills --notes lists the notes with their ids.`,
|
|
2821
|
+
);
|
|
2822
|
+
}
|
|
2823
|
+
const outcome = (done ?? drop ?? "").trim();
|
|
2824
|
+
if (outcome.length === 0 || outcome.length > MAX_PACK_NOTE_OUTCOME_LENGTH) {
|
|
2825
|
+
throw misuse(
|
|
2826
|
+
`Say what became of the note, in up to ${MAX_PACK_NOTE_OUTCOME_LENGTH} characters: ${SKILL_NOTE_USAGE}`,
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
const session = await open(io, values);
|
|
2830
|
+
const closed = await ofPackNotes(
|
|
2831
|
+
io,
|
|
2832
|
+
session.client.closePackNote(id, {
|
|
2833
|
+
state: done === undefined ? "dropped" : "done",
|
|
2834
|
+
outcome,
|
|
2835
|
+
}),
|
|
2836
|
+
);
|
|
2837
|
+
answer(io, session, closed, () => formatPackNoteClosed(closed));
|
|
2838
|
+
return EXIT.ok;
|
|
2839
|
+
}
|
|
2840
|
+
// `console skill note` alone read, before this form, as the load of a skill whose folder is
|
|
2841
|
+
// called note: that load is still there, by the path of its file, and the sentence says so.
|
|
2842
|
+
const [path, words] = none
|
|
2843
|
+
? [undefined, theOne(positionals, `Say the job no skill fit: ${SKILL_NOTE_USAGE}`)]
|
|
2844
|
+
: theTwo(
|
|
2845
|
+
positionals,
|
|
2846
|
+
`Say what the note is on, and what it says: ${SKILL_NOTE_USAGE}${positionals.length === 0 ? " | a skill in a folder called note is loaded by its file: console skill note/SKILL.md" : ""}`,
|
|
2847
|
+
);
|
|
2848
|
+
const body = await noteWords(io, words);
|
|
2849
|
+
const on_ = path === undefined ? undefined : notePathOf(path);
|
|
2850
|
+
const session = await open(io, values);
|
|
2851
|
+
const project = await session.projectKey();
|
|
2852
|
+
const left = await ofPackNotes(
|
|
2853
|
+
io,
|
|
2854
|
+
session.client.leavePackNote({
|
|
2855
|
+
...(on_ === undefined ? {} : { path: on_ }),
|
|
2856
|
+
body,
|
|
2857
|
+
...(project === undefined ? {} : { project }),
|
|
2858
|
+
}),
|
|
2859
|
+
);
|
|
2860
|
+
answer(io, session, left, () => formatPackNoteLeft(left));
|
|
2431
2861
|
return EXIT.ok;
|
|
2432
2862
|
}
|
|
2433
2863
|
|
|
2434
2864
|
const skill: Command = async (args, io) => {
|
|
2865
|
+
if (args[0] === "note") {
|
|
2866
|
+
return skillNote(args.slice(1), io);
|
|
2867
|
+
}
|
|
2435
2868
|
const { values, positionals } = parse(args, SKILL_OPTIONS);
|
|
2436
2869
|
const session = await open(io, values);
|
|
2437
2870
|
const { reader, owner } = await packNamed(session);
|
|
@@ -2559,8 +2992,7 @@ const plugin: Command = async (args, io) => {
|
|
|
2559
2992
|
case "events":
|
|
2560
2993
|
return pluginEvents(io, session, client, rest);
|
|
2561
2994
|
case "skills": {
|
|
2562
|
-
|
|
2563
|
-
return readSkills(io, session, client, parsed.values, parsed.positionals, {
|
|
2995
|
+
return readSkills(io, session, client, parse(rest, SKILLS_OPTIONS), {
|
|
2564
2996
|
command: `console plugin ${key} skills`,
|
|
2565
2997
|
again: whereGiven(values),
|
|
2566
2998
|
});
|
|
@@ -2779,10 +3211,18 @@ async function pluginRecords(
|
|
|
2779
3211
|
const [collection, id, ...more] = positionals;
|
|
2780
3212
|
if (collection === undefined || more.length > 0) {
|
|
2781
3213
|
throw misuse(
|
|
2782
|
-
`Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search <words>] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`,
|
|
3214
|
+
`Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search "<words>"] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`,
|
|
2783
3215
|
);
|
|
2784
3216
|
}
|
|
2785
3217
|
if (id !== undefined) {
|
|
3218
|
+
// A second word is a record's id, and a record is read alone: a search beside it would be
|
|
3219
|
+
// dropped without a line, and the second word of a search was read so (`--search annual
|
|
3220
|
+
// leave` read the record "leave"). Here the words of a search are one word (ADR-0179).
|
|
3221
|
+
if (text(values, "search") !== undefined) {
|
|
3222
|
+
throw misuse(
|
|
3223
|
+
`A record is read by its id alone, and ${id} was read as one: --search goes with a collection, its words as one word in quotes: console plugin ${client.key} records ${collection} --search "<words>"`,
|
|
3224
|
+
);
|
|
3225
|
+
}
|
|
2786
3226
|
if (on(values, "versions")) {
|
|
2787
3227
|
const versions = await client.recordVersions(collection, id);
|
|
2788
3228
|
answer(io, session, versions, () => formatPluginRecordVersions(versions));
|
|
@@ -3862,6 +4302,27 @@ interface Taking {
|
|
|
3862
4302
|
words: () => string;
|
|
3863
4303
|
}
|
|
3864
4304
|
|
|
4305
|
+
/**
|
|
4306
|
+
* What a take says first of what to do next (ADR-0176): the job's skill, before anything is
|
|
4307
|
+
* made. The rules say that a job begins with its skill; a take says the two commands, at the
|
|
4308
|
+
* moment the work begins and at every take, a later one of a session that left the rules out
|
|
4309
|
+
* among them. The one the task names is loaded; where it names none, the search is the
|
|
4310
|
+
* agent's, by words it chooses for the job, and a take runs none itself: a title is not the
|
|
4311
|
+
* words a skill is found by, and every take would pay for the read. The reads are of the
|
|
4312
|
+
* project the take named: where the pack is read is said as it was given, since without it a
|
|
4313
|
+
* desk reads the organization's pack, which may be another. Those words are spelled by the
|
|
4314
|
+
* skillcdn command's own rule, whose library a take loads only where it has a word to spell
|
|
4315
|
+
* (ADR-0179).
|
|
4316
|
+
*/
|
|
4317
|
+
async function skillStep(values: Values): Promise<string> {
|
|
4318
|
+
const given = whereGiven(values);
|
|
4319
|
+
const where = given.length === 0 ? "" : (await packReadsAfter())?.commandLine("", given);
|
|
4320
|
+
if (where === undefined) {
|
|
4321
|
+
return `First, the job's skill: console skill <path> for the one the task names; else console skills --kinds says whether the pack has skills for a job of this kind, and how one is found; each asked with ${flagNamesOf(given)} as this take was, quoted for your shell. Of another kind, or where none fits, go on.`;
|
|
4322
|
+
}
|
|
4323
|
+
return `First, the job's skill: console skill <path>${where} for the one the task names; else console skills --kinds${where} says whether the pack has skills for a job of this kind, and how one is found. Of another kind, or where none fits, go on.`;
|
|
4324
|
+
}
|
|
4325
|
+
|
|
3865
4326
|
/** Begins a run on a task, as the agent `--agent` names where it is said: the take itself. */
|
|
3866
4327
|
function runOn(project: ProjectClient, found: RestTask, values: Values): Promise<RestRun> {
|
|
3867
4328
|
const agent = text(values, "agent");
|
|
@@ -3925,6 +4386,7 @@ async function taking(
|
|
|
3925
4386
|
held === undefined ? [] : [held === mark ? formatRulesLeftOut(mark) : formatRulesChanged(held)];
|
|
3926
4387
|
const ruled = held === mark ? [] : [formatRules(rules, language), ""];
|
|
3927
4388
|
const page = await taskPage(session, taken.number);
|
|
4389
|
+
const first = await skillStep(values);
|
|
3928
4390
|
return {
|
|
3929
4391
|
value: { run, task: taken, comments: comments.items, rules: { ...rules, mark } },
|
|
3930
4392
|
words: () =>
|
|
@@ -3938,6 +4400,7 @@ async function taking(
|
|
|
3938
4400
|
formatTask(taken, undefined, undefined, comments.items, page),
|
|
3939
4401
|
"",
|
|
3940
4402
|
...ruled,
|
|
4403
|
+
first,
|
|
3941
4404
|
'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
|
|
3942
4405
|
'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>".',
|
|
3943
4406
|
].join("\n"),
|
|
@@ -4086,6 +4549,18 @@ const ask: Command = async (args, io) => {
|
|
|
4086
4549
|
if (options.length < MIN_OPTIONS || options.length > MAX_OPTIONS) {
|
|
4087
4550
|
throw misuse(`Give ${MIN_OPTIONS} to ${MAX_OPTIONS} options, one --option each.`);
|
|
4088
4551
|
}
|
|
4552
|
+
// Said before the console is asked, with where the rest goes: its refusal names a field.
|
|
4553
|
+
if (question.length > MAX_QUESTION_LENGTH) {
|
|
4554
|
+
throw misuse(
|
|
4555
|
+
`The question is ${question.length} characters, and one is at most ${MAX_QUESTION_LENGTH}: ask it in a line, and put what the person needs to know, the exact values among it, in --body or --file, which take Markdown.`,
|
|
4556
|
+
);
|
|
4557
|
+
}
|
|
4558
|
+
const long = options.find((label) => label.length > MAX_OPTION_LABEL_LENGTH);
|
|
4559
|
+
if (long !== undefined) {
|
|
4560
|
+
throw misuse(
|
|
4561
|
+
`An option is ${long.length} characters, and one is at most ${MAX_OPTION_LABEL_LENGTH}: name it in a few words, and say what it means in --body or --file.`,
|
|
4562
|
+
);
|
|
4563
|
+
}
|
|
4089
4564
|
const seconds = secondsOf(text(values, "wait"), DEFAULT_ASK_WAIT_SECONDS);
|
|
4090
4565
|
const body = await bodyOf(io, values, text(values, "body"));
|
|
4091
4566
|
// The files put on the decision (ADR-0055): a picture of what is to be chosen between, for one.
|
|
@@ -4342,24 +4817,40 @@ const decision: Command = async (args, io) => {
|
|
|
4342
4817
|
};
|
|
4343
4818
|
|
|
4344
4819
|
const docs: Command = async (args, io) => {
|
|
4345
|
-
const
|
|
4820
|
+
const parsed = parse(args, {
|
|
4346
4821
|
search: { type: "string" },
|
|
4347
4822
|
archived: { type: "boolean" },
|
|
4348
4823
|
});
|
|
4349
|
-
|
|
4350
|
-
|
|
4824
|
+
const { values, positionals } = parsed;
|
|
4825
|
+
// A search is of every page of the project, and every bare word is of it (ADR-0179): a
|
|
4826
|
+
// folder beside the words narrowed nothing, and its word was dropped without a line.
|
|
4827
|
+
const search = searchTyped(parsed);
|
|
4828
|
+
if (search === undefined && positionals.length > 1) {
|
|
4829
|
+
throw misuse(
|
|
4830
|
+
'Say one folder, or the words of a search after --search: console docs [<folder>] [--archived], or console docs --search "<words>"',
|
|
4831
|
+
);
|
|
4832
|
+
}
|
|
4833
|
+
if (search === "") {
|
|
4834
|
+
throw misuse('Say what to search for: console docs --search "<words>"');
|
|
4351
4835
|
}
|
|
4352
|
-
const search = text(values, "search");
|
|
4353
4836
|
const session = await open(io, values);
|
|
4354
4837
|
const project = await session.project();
|
|
4355
4838
|
// A folder is taken as the listing prints it, `guides/`, and as it is named, `guides`.
|
|
4356
|
-
const folder = positionals[0]?.replace(/\/+$/, "");
|
|
4839
|
+
const folder = search === undefined ? positionals[0]?.replace(/\/+$/, "") : undefined;
|
|
4357
4840
|
const found = await project.documents({
|
|
4358
4841
|
...(folder === undefined || folder === "" ? {} : { folder }),
|
|
4359
4842
|
...(search === undefined ? {} : { q: search }),
|
|
4360
4843
|
...(on(values, "archived") ? { archived: true } : {}),
|
|
4361
4844
|
});
|
|
4362
|
-
|
|
4845
|
+
// A search that finds nothing says what it looked for, as one of the tasks does: a word
|
|
4846
|
+
// typed as a folder is a word of the search, and every word must be on a page.
|
|
4847
|
+
answer(io, session, found, () =>
|
|
4848
|
+
search !== undefined && found.folders.length === 0 && found.items.length === 0
|
|
4849
|
+
? /\s/.test(search.trim())
|
|
4850
|
+
? `No pages: none holds every word of "${search.trim()}". A search is of every page of the project, whatever its folder, and fewer words find more.`
|
|
4851
|
+
: `No pages: none holds "${search.trim()}".`
|
|
4852
|
+
: formatDocuments(found),
|
|
4853
|
+
);
|
|
4363
4854
|
return EXIT.ok;
|
|
4364
4855
|
};
|
|
4365
4856
|
|
|
@@ -4529,22 +5020,17 @@ const restore: Command = async (args, io) => {
|
|
|
4529
5020
|
const DOC_FORMS: Readonly<Record<string, Command>> = { write, attach, archive, restore };
|
|
4530
5021
|
|
|
4531
5022
|
const goals: Command = async (args, io) => {
|
|
4532
|
-
const
|
|
4533
|
-
|
|
4534
|
-
{
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
},
|
|
4540
|
-
false,
|
|
4541
|
-
);
|
|
5023
|
+
const parsed = parse(args, {
|
|
5024
|
+
category: { type: "string" },
|
|
5025
|
+
state: { type: "string" },
|
|
5026
|
+
search: { type: "string" },
|
|
5027
|
+
...PAGE_OPTIONS,
|
|
5028
|
+
});
|
|
5029
|
+
const { values } = parsed;
|
|
4542
5030
|
const state = goalStateOf(text(values, "state"));
|
|
4543
5031
|
const category = text(values, "category");
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
throw misuse("Say what to search for: console goals --search <words>");
|
|
4547
|
-
}
|
|
5032
|
+
// Every bare word is of the search where --search was typed, and no word goes without it.
|
|
5033
|
+
const search = listingSearch(parsed, "console goals");
|
|
4548
5034
|
const page = pageOf(values);
|
|
4549
5035
|
const session = await open(io, values);
|
|
4550
5036
|
const project = await session.project();
|
|
@@ -5093,6 +5579,10 @@ const runner: Command = async (args, io) => {
|
|
|
5093
5579
|
installed: io.version === undefined ? undefined : io.installedVersion,
|
|
5094
5580
|
// What installs the console's version here, the way this command was installed.
|
|
5095
5581
|
updateCommand: () => updateWords(io, io.consoleVersion?.()),
|
|
5582
|
+
// What the console said its version is, on the answers the runner gets anyway: where it
|
|
5583
|
+
// is newer than this command, the agent is told once (ADR-0182). A runner whose own
|
|
5584
|
+
// version is not known has nothing to hold it against.
|
|
5585
|
+
consoleVersion: io.version === undefined ? undefined : io.consoleVersion,
|
|
5096
5586
|
now: io.now,
|
|
5097
5587
|
random: host.random,
|
|
5098
5588
|
time: (iso) => clock.format(new Date(iso)),
|
|
@@ -5231,7 +5721,7 @@ const manager: Command = async (args, io) => {
|
|
|
5231
5721
|
if (found.manager === null || found.manager.status !== "active") {
|
|
5232
5722
|
lines.push(
|
|
5233
5723
|
found.administrators.length === 0
|
|
5234
|
-
? "No administrator
|
|
5724
|
+
? "No administrator stands in."
|
|
5235
5725
|
: "The administrators, who stand in:",
|
|
5236
5726
|
...found.administrators.map((person) => ` ${formatPersonLine(person)}`),
|
|
5237
5727
|
);
|
|
@@ -5260,10 +5750,27 @@ const agents: Command = async (args, io) => {
|
|
|
5260
5750
|
const AGENT_USAGE =
|
|
5261
5751
|
"Say which agent account, or what to do: console agent <handle>, or console agent new|tell|interrupt|stop|restart|reset|wake|set|signals|messages|secrets|secret|invite|setup ...";
|
|
5262
5752
|
|
|
5753
|
+
/**
|
|
5754
|
+
* Whether a console refused an agent account for the project it was not sent: one before 0.6.4,
|
|
5755
|
+
* which made an account in a project (ADR-0088) where a console now makes it in none
|
|
5756
|
+
* (ADR-0181), and says so as any body it cannot read, by the field's name.
|
|
5757
|
+
*/
|
|
5758
|
+
/** The console's version as a sentence names it, `, 0.6.3,`, where it said one. */
|
|
5759
|
+
const consoleNamed = (io: CliIo): string => {
|
|
5760
|
+
const version = io.consoleVersion?.();
|
|
5761
|
+
return version === undefined ? "" : `, ${version},`;
|
|
5762
|
+
};
|
|
5763
|
+
|
|
5764
|
+
const asksForProject = (error: unknown): boolean =>
|
|
5765
|
+
error instanceof ApiError &&
|
|
5766
|
+
error.status === 400 &&
|
|
5767
|
+
error.code === "request.invalid" &&
|
|
5768
|
+
error.message.startsWith("project:");
|
|
5769
|
+
|
|
5263
5770
|
// An administrator makes an agent account with flags, where the pages make one from a form
|
|
5264
5771
|
// (ADR-0084): the member's row at once, its login let in. What is left out is proposed: the
|
|
5265
5772
|
// name is the handle's, capitalized, and the console rolls the avatar from the seed, or from one
|
|
5266
|
-
// of its own.
|
|
5773
|
+
// of its own. It is made in no project (ADR-0181), and the console leaves it its first message.
|
|
5267
5774
|
const agentNew = async (args: readonly string[], io: CliIo): Promise<number> => {
|
|
5268
5775
|
const { values, positionals } = parse(args, {
|
|
5269
5776
|
login: { type: "string" },
|
|
@@ -5287,21 +5794,15 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5287
5794
|
const login = text(values, "login") ?? derived?.login;
|
|
5288
5795
|
if (login === undefined) {
|
|
5289
5796
|
throw misuse(
|
|
5290
|
-
`Say the account it will sign in with: console agent new ${handle} --login <login
|
|
5797
|
+
`Say the account it will sign in with: console agent new ${handle} --login <login>`,
|
|
5291
5798
|
);
|
|
5292
5799
|
}
|
|
5293
5800
|
const chosen = text(values, "host");
|
|
5294
5801
|
const host = chosen === undefined ? (derived?.host ?? hostOfLogin(login)) : providerOf(chosen);
|
|
5295
|
-
const project = await session.projectKey();
|
|
5296
|
-
if (project === undefined) {
|
|
5297
|
-
throw misuse(
|
|
5298
|
-
`Say the project it starts in: console agent new ${handle} --login ${login} --project <key>`,
|
|
5299
|
-
);
|
|
5300
|
-
}
|
|
5301
5802
|
const manager = text(values, "manager");
|
|
5302
5803
|
const seed = text(values, "seed");
|
|
5303
5804
|
const title = text(values, "title");
|
|
5304
|
-
const
|
|
5805
|
+
const input: RestAgentInput = {
|
|
5305
5806
|
host,
|
|
5306
5807
|
login,
|
|
5307
5808
|
handle,
|
|
@@ -5311,9 +5812,26 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5311
5812
|
...(manager === undefined || manager === "me"
|
|
5312
5813
|
? {}
|
|
5313
5814
|
: { managerId: (await personOf(session, manager)).id }),
|
|
5314
|
-
project,
|
|
5315
5815
|
// A member who carries the login becomes the account only where that is said (ADR-0104).
|
|
5316
5816
|
...(on(values, "convert") ? { convert: true } : {}),
|
|
5817
|
+
};
|
|
5818
|
+
/** The project a console of before made the account in, with a task for its setup. */
|
|
5819
|
+
let before: string | undefined;
|
|
5820
|
+
const made = await session.client.createAgent(input).catch(async (error: unknown) => {
|
|
5821
|
+
if (!asksForProject(error)) {
|
|
5822
|
+
throw error;
|
|
5823
|
+
}
|
|
5824
|
+
// A console of before, which made nothing of what it refused: it is sent the project this
|
|
5825
|
+
// directory or --project names, and does with it what it did; where none is named, the
|
|
5826
|
+
// answer says what to type.
|
|
5827
|
+
const project = await session.projectKey();
|
|
5828
|
+
before = project;
|
|
5829
|
+
if (project === undefined) {
|
|
5830
|
+
throw failed(
|
|
5831
|
+
`This console${consoleNamed(io)} is older than the command and makes an agent account in a project. Name one: console agent new ${handle} --login ${login} --project <key>`,
|
|
5832
|
+
);
|
|
5833
|
+
}
|
|
5834
|
+
return session.client.createAgent({ ...input, project });
|
|
5317
5835
|
});
|
|
5318
5836
|
answer(io, session, made, () =>
|
|
5319
5837
|
[
|
|
@@ -5329,11 +5847,24 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5329
5847
|
: `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: not confirmed, since this console reads no organization at the git host. 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.`
|
|
5330
5848
|
: `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.`
|
|
5331
5849
|
: `${made.person.login} is an agent account from now on, with everything it did.`,
|
|
5332
|
-
|
|
5850
|
+
// What setting it up takes: a console of now left it as its first message to the
|
|
5851
|
+
// account, made in no project; one of before wrote a task, which it answers where it did.
|
|
5852
|
+
// A console of before lists the account in the project named here, a private one too:
|
|
5853
|
+
// said, since nothing was asked of a project.
|
|
5854
|
+
...(before === undefined
|
|
5333
5855
|
? []
|
|
5334
5856
|
: [
|
|
5335
|
-
`
|
|
5857
|
+
`This console${consoleNamed(io)} is older than the command and makes an agent account in a project: it is in ${before}, ${typeof values.project === "string" ? "which --project names" : "the project named here"}. Where it is not to work there: console member remove ${made.person.login} --project ${before}`,
|
|
5336
5858
|
]),
|
|
5859
|
+
...(made.onboarding !== null && made.onboarding !== undefined
|
|
5860
|
+
? [
|
|
5861
|
+
`Its first task is #${made.onboarding.number} in ${made.onboarding.project}, with what setting it up takes; its runner is woken with it when it first starts.`,
|
|
5862
|
+
]
|
|
5863
|
+
: before !== undefined
|
|
5864
|
+
? []
|
|
5865
|
+
: [
|
|
5866
|
+
`What setting it up takes waits on its record as the console's first message to it, which its runner hands it when it first starts. It is made in no project, and a private one lists it as any member: console member add ${made.person.login} --project <key>`,
|
|
5867
|
+
]),
|
|
5337
5868
|
`Next, a machine: console agent invite ${handle} makes the invitation that leads one to it.`,
|
|
5338
5869
|
].join("\n"),
|
|
5339
5870
|
);
|
|
@@ -5355,7 +5886,8 @@ async function secretValue(io: CliIo, values: Values, prompt: string): Promise<s
|
|
|
5355
5886
|
const value =
|
|
5356
5887
|
file === undefined
|
|
5357
5888
|
? await secretGiven(io, prompt)
|
|
5358
|
-
:
|
|
5889
|
+
: // What a file comes to as a value is said once, for the command and the pages (ADR-0184).
|
|
5890
|
+
secretOfText(await io.readFile(file));
|
|
5359
5891
|
if (value.length === 0) {
|
|
5360
5892
|
throw failed("No value was given.");
|
|
5361
5893
|
}
|
|
@@ -5777,6 +6309,41 @@ const ownReset = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5777
6309
|
return EXIT.ok;
|
|
5778
6310
|
};
|
|
5779
6311
|
|
|
6312
|
+
/**
|
|
6313
|
+
* What an account is told that asks of itself what its supervisors do (ADR-0180): a tell, an
|
|
6314
|
+
* interruption, a stop, a start, a setting, an invitation. Said before anything is sent where it
|
|
6315
|
+
* names itself `me`, which no such form takes, and where the console refused it by its handle.
|
|
6316
|
+
*/
|
|
6317
|
+
const NOBODY_SUPERVISES_THEMSELVES =
|
|
6318
|
+
'Nobody supervises themselves (ADR-0180): a tell, an interruption, a stop, a start, a setting and an invitation are an account\'s supervisors\', never its own, whatever its role. What you raise for yourself is a wake, console agent wake me ["<words>"], and a new conversation, console agent reset me "<why>".';
|
|
6319
|
+
|
|
6320
|
+
/** Whether a word names the account itself where a supervisor's form wants a handle. */
|
|
6321
|
+
const namesItself = (word: string | undefined): boolean => word === "me" || word === "@me";
|
|
6322
|
+
|
|
6323
|
+
/**
|
|
6324
|
+
* A supervisor's act on an agent account (ADR-0084), refused as what it is. The console's
|
|
6325
|
+
* refusal says that only a supervisor may, and the hint after it would say the step is an
|
|
6326
|
+
* administrator's: of the account's own handle, the account is told that nobody supervises
|
|
6327
|
+
* themselves, which an account that administers is not told otherwise; of another's, whose the
|
|
6328
|
+
* step is. `me` is asked only on a refusal, so that the act costs no request more.
|
|
6329
|
+
*/
|
|
6330
|
+
async function supervising<T>(session: Session, handle: string, act: () => Promise<T>): Promise<T> {
|
|
6331
|
+
try {
|
|
6332
|
+
return await act();
|
|
6333
|
+
} catch (error) {
|
|
6334
|
+
if (!(error instanceof ApiError) || error.code !== "auth.forbidden") {
|
|
6335
|
+
throw error;
|
|
6336
|
+
}
|
|
6337
|
+
const me = await session.client.me().catch(() => undefined);
|
|
6338
|
+
if (me?.person?.handle === handle) {
|
|
6339
|
+
throw failed(`auth.forbidden: ${NOBODY_SUPERVISES_THEMSELVES}`);
|
|
6340
|
+
}
|
|
6341
|
+
throw failed(
|
|
6342
|
+
`auth.forbidden: ${error.message}\nWhat a supervisor does to an agent account is its manager's, whoever is above them in the reporting line and the administrators': hand the step to one of them.`,
|
|
6343
|
+
);
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
|
|
5780
6347
|
/** The kinds of signal a supervisor sends with words: which need them, and which take them. */
|
|
5781
6348
|
const WORDED_SIGNALS: Readonly<Record<string, { readonly needs: boolean }>> = {
|
|
5782
6349
|
tell: { needs: true },
|
|
@@ -5824,6 +6391,9 @@ const agentSignal = async (
|
|
|
5824
6391
|
const [given, words, ...rest] = positionals;
|
|
5825
6392
|
const needs = WORDED_SIGNALS[kind]?.needs === true;
|
|
5826
6393
|
const usage = `Say whom${needs ? " and what" : ""}: console agent ${kind} <handle> ${needs ? '"<words>"' : '["<words>"]'} [--file <path>]`;
|
|
6394
|
+
if (namesItself(given)) {
|
|
6395
|
+
throw misuse(NOBODY_SUPERVISES_THEMSELVES);
|
|
6396
|
+
}
|
|
5827
6397
|
if (given === undefined || rest.length > 0) {
|
|
5828
6398
|
throw misuse(usage);
|
|
5829
6399
|
}
|
|
@@ -5833,10 +6403,12 @@ const agentSignal = async (
|
|
|
5833
6403
|
}
|
|
5834
6404
|
const handle = handleOf(given);
|
|
5835
6405
|
const session = await open(io, values);
|
|
5836
|
-
const sent = await session
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
6406
|
+
const sent = await supervising(session, handle, () =>
|
|
6407
|
+
session.client.sendSignal(handle, {
|
|
6408
|
+
kind,
|
|
6409
|
+
...(said.length === 0 ? {} : { text: said }),
|
|
6410
|
+
}),
|
|
6411
|
+
);
|
|
5840
6412
|
answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
|
|
5841
6413
|
return EXIT.ok;
|
|
5842
6414
|
};
|
|
@@ -5850,6 +6422,9 @@ const agentSet = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5850
6422
|
});
|
|
5851
6423
|
const usage =
|
|
5852
6424
|
"Say whom and what: console agent set <handle> [--model <name|none>] [--effort <level|none>]";
|
|
6425
|
+
if (namesItself(positionals[0])) {
|
|
6426
|
+
throw misuse(NOBODY_SUPERVISES_THEMSELVES);
|
|
6427
|
+
}
|
|
5853
6428
|
const handle = handleOf(theOne(positionals, usage));
|
|
5854
6429
|
const model = orNone(text(values, "model"));
|
|
5855
6430
|
const effort = orNone(text(values, "effort"));
|
|
@@ -5857,13 +6432,15 @@ const agentSet = async (args: readonly string[], io: CliIo): Promise<number> =>
|
|
|
5857
6432
|
throw misuse(usage);
|
|
5858
6433
|
}
|
|
5859
6434
|
const session = await open(io, values);
|
|
5860
|
-
const sent = await session
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
6435
|
+
const sent = await supervising(session, handle, () =>
|
|
6436
|
+
session.client.sendSignal(handle, {
|
|
6437
|
+
kind: "set",
|
|
6438
|
+
set: {
|
|
6439
|
+
...(model === undefined ? {} : { model }),
|
|
6440
|
+
...(effort === undefined ? {} : { effort }),
|
|
6441
|
+
},
|
|
6442
|
+
}),
|
|
6443
|
+
);
|
|
5867
6444
|
answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
|
|
5868
6445
|
return EXIT.ok;
|
|
5869
6446
|
};
|
|
@@ -6018,6 +6595,9 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
|
|
|
6018
6595
|
revoke: { type: "boolean" },
|
|
6019
6596
|
out: { type: "string" },
|
|
6020
6597
|
});
|
|
6598
|
+
if (namesItself(positionals[0])) {
|
|
6599
|
+
throw misuse(NOBODY_SUPERVISES_THEMSELVES);
|
|
6600
|
+
}
|
|
6021
6601
|
const handle = handleOf(
|
|
6022
6602
|
theOne(positionals, "Say whose: console agent invite <handle> [--out <path>] | --revoke"),
|
|
6023
6603
|
);
|
|
@@ -6029,7 +6609,7 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
|
|
|
6029
6609
|
}
|
|
6030
6610
|
const session = await open(io, values);
|
|
6031
6611
|
if (on(values, "revoke")) {
|
|
6032
|
-
await session.client.revokeAgentInvitation(handle);
|
|
6612
|
+
await supervising(session, handle, () => session.client.revokeAgentInvitation(handle));
|
|
6033
6613
|
answer(
|
|
6034
6614
|
io,
|
|
6035
6615
|
session,
|
|
@@ -6054,7 +6634,7 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
|
|
|
6054
6634
|
);
|
|
6055
6635
|
}
|
|
6056
6636
|
}
|
|
6057
|
-
const made = await session.client.inviteAgent(handle);
|
|
6637
|
+
const made = await supervising(session, handle, () => session.client.inviteAgent(handle));
|
|
6058
6638
|
const until = `good until ${moment(made.invitation.expiresAt)} or until its command has signed in`;
|
|
6059
6639
|
const guide = `${session.url}/setup/${made.code}`;
|
|
6060
6640
|
if (file === undefined) {
|
|
@@ -6091,8 +6671,11 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
|
|
|
6091
6671
|
`The invitation of @${handle} is made, and its line could not be written at ${file}, so nobody has it. Make the invitation again with a path that can be written: it takes the place of this one.`,
|
|
6092
6672
|
);
|
|
6093
6673
|
}
|
|
6094
|
-
// The path as
|
|
6095
|
-
|
|
6674
|
+
// The path as every shell takes it whole, by the skillcdn command's own rule; where it has
|
|
6675
|
+
// no such spelling, it is named in words.
|
|
6676
|
+
const path =
|
|
6677
|
+
(await packReadsAfter())?.commandLine("", [written])?.trim() ??
|
|
6678
|
+
"<the file's path, quoted for your shell>";
|
|
6096
6679
|
answer(io, session, { handle, invitation: made.invitation, file: written }, () =>
|
|
6097
6680
|
[
|
|
6098
6681
|
`An invitation for @${handle}, ${until}. Its line is written to ${written} and is not shown here: it carries the code, which is shown nowhere else.`,
|
|
@@ -6584,6 +7167,8 @@ async function handOver(
|
|
|
6584
7167
|
await io.sleep(FIRST_SESSION_PAUSE_MS);
|
|
6585
7168
|
}
|
|
6586
7169
|
}
|
|
7170
|
+
// The task for its setup, where its plate holds one: an account a console before 0.6.4 made
|
|
7171
|
+
// has the one that console wrote, and keeps it (ADR-0181).
|
|
6587
7172
|
const plate = await client.work().catch(() => undefined);
|
|
6588
7173
|
const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
|
|
6589
7174
|
const inTheWay = await standsInTheWay(machine);
|
|
@@ -7182,7 +7767,28 @@ function serviceOf(word: string): {
|
|
|
7182
7767
|
}
|
|
7183
7768
|
return { role: role as ServiceRole, service };
|
|
7184
7769
|
}
|
|
7185
|
-
const
|
|
7770
|
+
const PACK_KEEPER_USAGE =
|
|
7771
|
+
"console workspace pack-keeper <login|none> [--round <HH:MM|none>] | console workspace pack-keeper --round <HH:MM|none>";
|
|
7772
|
+
const WORKSPACE_USAGE = `Say what to do: console workspace | console workspace edit [${WORKSPACE_FLAGS.replaceAll(", ", "] [")}] | console workspace pack-token --connect|--stdin|--remove | ${PACK_KEEPER_USAGE}`;
|
|
7773
|
+
|
|
7774
|
+
/**
|
|
7775
|
+
* What the member who keeps the organization's skills is called (ADR-0178), and whether they
|
|
7776
|
+
* are out, for the line that says who does: looked up among the people the asker sees, and
|
|
7777
|
+
* nothing where the workspace names nobody, or somebody the asker does not see.
|
|
7778
|
+
*/
|
|
7779
|
+
async function keeperOf(
|
|
7780
|
+
session: Session,
|
|
7781
|
+
workspace: RestWorkspace,
|
|
7782
|
+
): Promise<KeeperCalled | undefined> {
|
|
7783
|
+
const id = workspace.skills.keeperId;
|
|
7784
|
+
if (typeof id !== "string") {
|
|
7785
|
+
return undefined;
|
|
7786
|
+
}
|
|
7787
|
+
const keeper = (await session.client.people()).items.find((one) => one.id === id);
|
|
7788
|
+
return keeper === undefined
|
|
7789
|
+
? undefined
|
|
7790
|
+
: { called: calledOf(keeper), away: keeper.status !== "active" };
|
|
7791
|
+
}
|
|
7186
7792
|
|
|
7187
7793
|
const workspace: Command = async (args, io) => {
|
|
7188
7794
|
const [verb, ...rest] = args;
|
|
@@ -7191,7 +7797,56 @@ const workspace: Command = async (args, io) => {
|
|
|
7191
7797
|
const session = await open(io, values);
|
|
7192
7798
|
const me = await session.client.me();
|
|
7193
7799
|
await rememberZone(io, session, me.workspace.timeZone ?? undefined);
|
|
7194
|
-
|
|
7800
|
+
const keeper = session.json ? undefined : await keeperOf(session, me.workspace);
|
|
7801
|
+
answer(io, session, me.workspace, () => formatWorkspace(me.workspace, keeper));
|
|
7802
|
+
return EXIT.ok;
|
|
7803
|
+
}
|
|
7804
|
+
if (verb === "pack-keeper") {
|
|
7805
|
+
// Who keeps the organization's skills, and the hour of their round (ADR-0178): an
|
|
7806
|
+
// administrator's to say, as the workspace's other settings are.
|
|
7807
|
+
const { values, positionals } = parse(rest, { round: { type: "string" } });
|
|
7808
|
+
const round = text(values, "round");
|
|
7809
|
+
if (positionals.length > 1 || (positionals.length === 0 && round === undefined)) {
|
|
7810
|
+
throw misuse(
|
|
7811
|
+
`Say who keeps the organization's skills, or the hour of their round: ${PACK_KEEPER_USAGE}`,
|
|
7812
|
+
);
|
|
7813
|
+
}
|
|
7814
|
+
if (
|
|
7815
|
+
round !== undefined &&
|
|
7816
|
+
round !== "none" &&
|
|
7817
|
+
!/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/.test(round)
|
|
7818
|
+
) {
|
|
7819
|
+
throw misuse(`Not an hour of the day: ${round}. Say --round <HH:MM>, as 03:00, or none.`);
|
|
7820
|
+
}
|
|
7821
|
+
const session = await open(io, values);
|
|
7822
|
+
const [login] = positionals;
|
|
7823
|
+
const keeperId =
|
|
7824
|
+
login === undefined
|
|
7825
|
+
? undefined
|
|
7826
|
+
: login === "none"
|
|
7827
|
+
? null
|
|
7828
|
+
: (await personOf(session, login)).id;
|
|
7829
|
+
const changed = await session.client
|
|
7830
|
+
.updateWorkspace({
|
|
7831
|
+
...(keeperId === undefined ? {} : { packKeeperId: keeperId }),
|
|
7832
|
+
...(round === undefined ? {} : { packRoundAt: round === "none" ? null : round }),
|
|
7833
|
+
})
|
|
7834
|
+
.catch((error: unknown) => {
|
|
7835
|
+
// A console of before reads neither setting, and answers the change as one of nothing.
|
|
7836
|
+
if (
|
|
7837
|
+
error instanceof ApiError &&
|
|
7838
|
+
error.code === "request.invalid" &&
|
|
7839
|
+
error.message.startsWith("The patch names nothing to change")
|
|
7840
|
+
) {
|
|
7841
|
+
const version = io.consoleVersion?.();
|
|
7842
|
+
throw failed(
|
|
7843
|
+
`This console${version === undefined ? "" : `, ${version},`} names nobody who keeps the organization's skills yet: it is older than the command.`,
|
|
7844
|
+
);
|
|
7845
|
+
}
|
|
7846
|
+
throw error;
|
|
7847
|
+
});
|
|
7848
|
+
const keeper = session.json ? undefined : await keeperOf(session, changed);
|
|
7849
|
+
answer(io, session, changed, () => formatWorkspace(changed, keeper));
|
|
7195
7850
|
return EXIT.ok;
|
|
7196
7851
|
}
|
|
7197
7852
|
if (verb === "edit") {
|
|
@@ -8068,7 +8723,7 @@ function hintFor(error: ApiError, io: CliIo, seen: ConsoleSeen): string {
|
|
|
8068
8723
|
case "category.in_use":
|
|
8069
8724
|
return "Tasks are sorted into the category. Move them out first: console task edit <number> --category <other|none>\n";
|
|
8070
8725
|
case "person.last_admin":
|
|
8071
|
-
return "The board keeps at least one administrator in. Make another one first.\n";
|
|
8726
|
+
return "The board keeps at least one administrator in who is a person. Make another person one first.\n";
|
|
8072
8727
|
case "person.of_organization":
|
|
8073
8728
|
return "The organization says who is in: a person it let in comes and goes with it, and is listed by login to stay.\n";
|
|
8074
8729
|
case "agent.login_is_member":
|