@awebai/oats 0.59.0 → 0.61.0
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 +14 -18
- package/bin/oats.mjs +42 -10
- package/docs/configuration.md +9 -0
- package/docs/desktop-cli-api.md +40 -10
- package/docs/desktop.md +7 -0
- package/docs/execution-targets.md +7 -2
- package/docs/first-team.md +8 -0
- package/docs/implementation.md +1 -0
- package/docs/integrations.md +1 -1
- package/docs/official-catalog.md +2 -2
- package/docs/packages.md +7 -7
- package/docs/release-notes/v0.60.0.md +104 -0
- package/docs/release-notes/v0.61.0.md +155 -0
- package/docs/tui.md +133 -19
- package/docs/workspaces.md +1 -1
- package/lib/core.mjs +42 -15
- package/lib/session-input.mjs +45 -28
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/capability-catalog.mjs +93 -0
- package/packages/client/capability-facts.mjs +59 -0
- package/packages/client/capability-rows.mjs +121 -0
- package/packages/client/catalog-messages.mjs +12 -0
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/instance-presentation.mjs +10 -0
- package/packages/client/instance-tree.mjs +48 -6
- package/packages/client/soul-catalog.mjs +8 -0
- package/packages/client/soul-facts.mjs +7 -0
- package/packages/client/spawn-messages.mjs +8 -0
- package/packages/client/subsequence-score.mjs +15 -0
- package/packages/tui/README.md +1 -1
- package/packages/tui/lib/actions.mjs +1 -1
- package/packages/tui/lib/client.mjs +9 -4
- package/packages/tui/lib/main.mjs +58 -9
- package/packages/tui/lib/model.mjs +150 -50
- package/packages/tui/lib/store.mjs +133 -16
- package/packages/tui/lib/views/capabilities.mjs +239 -0
- package/packages/tui/lib/views/frame.mjs +55 -20
- package/packages/tui/lib/views/help.mjs +9 -4
- package/packages/tui/lib/views/palette.mjs +13 -4
- package/packages/tui/lib/views/souls.mjs +6 -4
- package/packages/tui/lib/views/spawn.mjs +5 -3
- package/skills/oats-getting-started/SKILL.md +1 -1
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
// in. What it adds is the TUI's: the window, the clock times, and which fact stands on which line.
|
|
8
8
|
import {
|
|
9
9
|
TERMS, panelData, displayLine, DETAIL_WITHHELD, originLead, instanceId, instanceVisibleInTree, waitingRollup, collapseKey, filterInstanceTree,
|
|
10
|
-
hasInstanceChildren, heldHome, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts,
|
|
10
|
+
hasInstanceChildren, heldHome, instanceSiblings, siblingText, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts,
|
|
11
11
|
waitingClaim, waitingLabel, waitedText, waitingClock, waitingBelowText, instanceActs, rowReason,
|
|
12
12
|
identityMemory, viewModel, workspaceChoices, workspaceChoiceRows, choiceMatches, UNMATCHED_SECTION, shortPath,
|
|
13
13
|
openAct, deployments as heldDeployments, attachExit, preflightFailure, kernelLines,
|
|
14
14
|
startGate, launchFlagIgnored, flagIgnoredNotice, retainedStartMessage, retiringRows, soulRows, soulFacts, spawnRefusal,
|
|
15
|
-
defaultSpawnChoices, spawnProblem, outcomeWords, previewFacts, deploymentLabel,
|
|
15
|
+
defaultSpawnChoices, spawnProblem, outcomeWords, previewFacts, deploymentLabel, subsequenceScore, soulMatches, soulCatalogFailure, catalogFailure,
|
|
16
|
+
memberNames, capabilitySource, groupCapabilities, hostKeyOf, capabilitySections, matchCapabilities, soulsComposition, rosterAgentName, layerLabel, capabilityUsers,
|
|
17
|
+
capabilityFacts, CAPABILITY_COPY,
|
|
16
18
|
} from "./client.mjs";
|
|
17
19
|
import { LEADER, keyLabel } from "./actions.mjs";
|
|
18
20
|
import { ownEllipsis, shownLines } from "./term/text.mjs";
|
|
@@ -127,6 +129,12 @@ function build(state, at) {
|
|
|
127
129
|
const sectionOf = new Map(), ordered = [];
|
|
128
130
|
for (const part of rosterSections(instances, instances, deployments, TERMS)) for (const group of part.groups) for (const cluster of group.clusters) for (const row of cluster.instances) { sectionOf.set(instanceId(row), part.deployment?.id ?? null); ordered.push(row); }
|
|
129
131
|
const section = (row) => sectionOf.get(instanceId(row)) ?? null;
|
|
132
|
+
// Each instance's siblings by explicit link, both ends, as the shared home resolves them (#1312):
|
|
133
|
+
// asked of each section's full roster on its own, whatever is filtered or folded, so a name never
|
|
134
|
+
// resolves to an instance of another deployment, nor a dropped row makes an ambiguous name unique.
|
|
135
|
+
const bySection = new Map();
|
|
136
|
+
for (const row of instances) { const key = section(row); if (!bySection.has(key)) bySection.set(key, []); bySection.get(key).push(row); }
|
|
137
|
+
const siblings = new Map([...bySection.values()].flatMap((own) => [...instanceSiblings(own)]));
|
|
130
138
|
const matched = soul !== null ? filterInstanceTree(instances, soul.name, (row) => soul.names.includes(row.agent)) : filterInstanceTree(instances, query);
|
|
131
139
|
const visible = matched.filter((i) => instanceVisibleInTree(i, instances, state.collapsed, state.open, filtering, { section }));
|
|
132
140
|
const sections = rosterSections(instances, visible, deployments, TERMS);
|
|
@@ -211,7 +219,7 @@ function build(state, at) {
|
|
|
211
219
|
// observed, nor for a machine that is not live and has no row kept. Each has only its reason.
|
|
212
220
|
const observed = panel !== null && !gone && (local ? status === "observed" : live || instances.length > 0);
|
|
213
221
|
return {
|
|
214
|
-
panel, gone, instances, ordered, deployments, multi, parts, rows, filtering, stale, section, live, observed, folded,
|
|
222
|
+
panel, gone, instances, ordered, deployments, multi, parts, rows, filtering, stale, section, siblings, live, observed, folded,
|
|
215
223
|
below: waitingRollup(instances, state.collapsed, state.open, { filtering, stale, section }),
|
|
216
224
|
status,
|
|
217
225
|
workspace: text(panel?.workspace?.name) ? panel.workspace.name : "",
|
|
@@ -365,13 +373,8 @@ function groupsOf(state) {
|
|
|
365
373
|
return { tabs, shown };
|
|
366
374
|
});
|
|
367
375
|
}
|
|
368
|
-
/**
|
|
369
|
-
* hold, and what to run until then, the help's commands (views/help.mjs VIEWS), in the TUI's own
|
|
370
|
-
* words; each command is whole, never broken over two rows. */
|
|
376
|
+
/** A command in a line of the TUI's own: whole, never broken over two rows. */
|
|
371
377
|
const command = (text) => Object.freeze({ own: `\`${text}\``, whole: true });
|
|
372
|
-
export const NOT_BUILT = Object.freeze({
|
|
373
|
-
capabilities: Object.freeze({ said: Object.freeze([{ own: "This view will list the capabilities this machine has. It is not in this version: " }, command("oats capabilities"), { own: " lists them." }]), under: Object.freeze([]) }),
|
|
374
|
-
});
|
|
375
378
|
/** A sentence from outside (a reason of the shared home's, the preflight table's), as a text
|
|
376
379
|
* under the line: drawn as the detail draws a reason, wrapped on the reason's rows, never as one
|
|
377
380
|
* unbroken part (a part is a name). */
|
|
@@ -493,7 +496,7 @@ function detailOf(state, r, item, now, acts) {
|
|
|
493
496
|
add("harness", `${[row.harness, row.model].filter(text).join(", ")}${text(row.model) && text(row.modelFrom) ? ` (${row.modelFrom})` : ""}`);
|
|
494
497
|
add("work", [row.work, row.branch].filter(text).join(", "));
|
|
495
498
|
add("team", row.team);
|
|
496
|
-
add("parent", [row.parentInstance,
|
|
499
|
+
add("parent", [row.parentInstance, siblingText(r.siblings.get(item.id))].filter(text).join(", "));
|
|
497
500
|
if (text(row.startedAt)) add("started", waitingClock(row.startedAt, now));
|
|
498
501
|
add("home", row.home, "end");
|
|
499
502
|
return { title: row.instance, facts };
|
|
@@ -538,22 +541,6 @@ export function switcher(state, at = new Date(0).toISOString()) {
|
|
|
538
541
|
};
|
|
539
542
|
}
|
|
540
543
|
|
|
541
|
-
/** The house fuzzy matcher of the Desktop's palette, the same function
|
|
542
|
-
* (packages/desktop/renderer/overlay-picker.mjs subsequenceScore): the TUI cannot import the
|
|
543
|
-
* Desktop's renderer, and test/tui-palette.test.mjs holds the two to the same answers. Lower is
|
|
544
|
-
* better, null is no match, and a prefix match gets a strong (negative) bonus. */
|
|
545
|
-
export function subsequenceScore(text, query) {
|
|
546
|
-
const t = String(text).toLowerCase();
|
|
547
|
-
const s = String(query).toLowerCase();
|
|
548
|
-
let ti = 0, gaps = 0;
|
|
549
|
-
for (const ch of s) {
|
|
550
|
-
const found = t.indexOf(ch, ti);
|
|
551
|
-
if (found < 0) return null;
|
|
552
|
-
gaps += found - ti; ti = found + 1;
|
|
553
|
-
}
|
|
554
|
-
return gaps + (t.startsWith(s) ? -100 : 0);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
544
|
/** The palette's views and commands, each a row's label and the action it runs. */
|
|
558
545
|
const PALETTE_VIEWS = Object.freeze([["instances", "Instances"], ["souls", "Souls"], ["capabilities", "Capabilities"]]);
|
|
559
546
|
const PALETTE_COMMANDS = Object.freeze([["spawn", "Spawn an agent"], ["workspaces", "Workspaces"], ["refresh", "Refresh"], ["help", "Help"]]);
|
|
@@ -566,12 +553,12 @@ const PALETTE_ACTS = Object.freeze({ stop: "Stop", restart: "Restart", retire: "
|
|
|
566
553
|
|
|
567
554
|
/** THE PALETTE'S ROWS (docs/tui.md, "The palette"), in this order: the instances that can be
|
|
568
555
|
* opened (the most recently opened in this run first, then the shared order), the souls of the
|
|
569
|
-
* open workspace once its catalog was read, the views, the acts
|
|
556
|
+
* open workspace once its catalog was read, its capabilities once theirs was, the views, the acts
|
|
570
557
|
* the palette's instance offers (the open terminal's, when the palette came from its focus; else
|
|
571
558
|
* the selected one) and, once the catalog lists its soul, another of that soul, then spawning an
|
|
572
559
|
* agent, workspaces, refresh and help, and the split's that apply. With a query, each group keeps the rows the
|
|
573
560
|
* Desktop's subsequence score matches, the best first (a prefix first); a tie keeps that order.
|
|
574
|
-
* A row: `{ key, kind, label, does?, id?, name?, machine?, mark? }`; `selected` is the key the
|
|
561
|
+
* A row: `{ key, kind, label, does?, id?, name?, machine?, mark?, sibling?, capability?, source? }`; `selected` is the key the
|
|
575
562
|
* selection stands on (the first row when the palette's own is not listed). */
|
|
576
563
|
export function paletteItems(state, at = new Date(0).toISOString()) {
|
|
577
564
|
const p = state.palette;
|
|
@@ -584,12 +571,24 @@ export function paletteItems(state, at = new Date(0).toISOString()) {
|
|
|
584
571
|
const openable = r.ordered.filter((row) => openDecision(state, row, instanceActs(row)).open);
|
|
585
572
|
groups.push(openable.map((row, i) => ({ row, i })).sort((a, b) => rank(a.row) - rank(b.row) || a.i - b.i).map(({ row }) => {
|
|
586
573
|
const machine = elsewhere(row) ? row.deployment?.machine ?? row.server : null;
|
|
587
|
-
|
|
574
|
+
// `sibling`: the shared words for its siblings, or null; never part of what a query matches.
|
|
575
|
+
return {
|
|
576
|
+
key: `instance\u0000${instanceId(row)}`, kind: "instance", label: row.instance, id: instanceId(row), name: row.instance, machine, mark: markOf(row),
|
|
577
|
+
sibling: siblingText(r.siblings.get(instanceId(row))), text: `${row.instance} ${machine ?? ""}`,
|
|
578
|
+
};
|
|
588
579
|
}));
|
|
589
580
|
}
|
|
590
581
|
// The souls of the open workspace, once its catalog was read (the Souls view opened): choosing
|
|
591
582
|
// one shows the Souls view with it selected. A palette never reads the catalog.
|
|
592
583
|
groups.push(soulsOf(state).all.map((row) => ({ key: `soul\u0000${row.name}`, kind: "soul", label: row.name, name: row.name, text: row.name })));
|
|
584
|
+
// The capabilities of the open workspace, once its catalog was read (the Capabilities view opened):
|
|
585
|
+
// choosing one shows that view with it selected. Each says where it comes from (a package's and a
|
|
586
|
+
// member's may share a name).
|
|
587
|
+
const c = capabilitiesOf(state), names = memberNames(c.status);
|
|
588
|
+
groups.push(c.all.map((row) => {
|
|
589
|
+
const capability = capabilityKey(row, names);
|
|
590
|
+
return { key: `capability\u0000${capability}`, kind: "capability", label: row.name, name: row.name, capability, source: capabilitySource(row, names).label, text: row.name };
|
|
591
|
+
}));
|
|
593
592
|
groups.push(PALETTE_VIEWS.map(([does, label]) => ({ key: `view\u0000${does}`, kind: "view", label, does, text: label })));
|
|
594
593
|
const id = p.from === "terminal" && state.terminal !== null ? state.terminal.id : state.selected;
|
|
595
594
|
const row = id === null || state.open === null ? null : roster(state, at).instances.find((each) => instanceId(each) === id) ?? null;
|
|
@@ -642,7 +641,7 @@ export function model(state, { page, now, at, cols }) {
|
|
|
642
641
|
const common = {
|
|
643
642
|
view: state.view, focus: state.focus, ascii: state.ascii, actions: state.actions,
|
|
644
643
|
// The filter of the view shown: the Souls view has one of its own.
|
|
645
|
-
filter: state.view === "souls" ? state.souls.filter : state.filter,
|
|
644
|
+
filter: state.view === "souls" ? state.souls.filter : state.view === "capabilities" ? state.capabilities.filter : state.filter,
|
|
646
645
|
workspace: r.workspace, machines: r.machines, here: r.here, machine: r.machine, counts: r.counts, readAt: r.readAt, notice: r.notice, note: r.note, empty: r.empty, observed: r.observed,
|
|
647
646
|
detailTop: state.detailTop, helpTop: state.helpTop, open: state.open !== null,
|
|
648
647
|
detachKey: state.detachKey, opening: state.opening, openable: false, actable: [],
|
|
@@ -655,8 +654,8 @@ export function model(state, { page, now, at, cols }) {
|
|
|
655
654
|
act: state.view === "act" && state.act ? actView(state) : null,
|
|
656
655
|
// The leader waits for its key (the footer is its hint), and the palette, while it is open.
|
|
657
656
|
leader: state.leader?.waiting === true, palette: state.palette === null ? null : paletteView(state, page, at),
|
|
658
|
-
body: state.view === "capabilities" ? NOT_BUILT.capabilities : null,
|
|
659
657
|
souls: state.view === "souls" ? soulsView(state, page, at) : null,
|
|
658
|
+
capabilities: state.view === "capabilities" ? capabilitiesView(state, page, at) : null,
|
|
660
659
|
spawn: state.spawn === null ? null : spawnView(state, page, at),
|
|
661
660
|
// The line above the panes: the last outcome, else a spawn under way (outcomeOf).
|
|
662
661
|
outcome: outcomeOf(state),
|
|
@@ -889,24 +888,14 @@ export function actView(state) {
|
|
|
889
888
|
|
|
890
889
|
// ── THE SOULS VIEW (docs/tui.md, "The Souls view") ───────────────────────────────────────────────
|
|
891
890
|
|
|
892
|
-
/** The sentence of a catalog read that failed: the Desktop's own (packages/desktop/renderer/views/
|
|
893
|
-
* spawn.mjs catalogReasonText), copied until the shared home has it; the kernel's message in it is
|
|
894
|
-
* text from outside, which the view draws through the display filter. */
|
|
895
|
-
export function catalogFailure(reason) {
|
|
896
|
-
const message = typeof reason?.message === "string" && reason.message ? reason.message : "";
|
|
897
|
-
return message ? `Couldn't read this workspace's souls: ${message}` : "Couldn't read this workspace's souls.";
|
|
898
|
-
}
|
|
899
|
-
|
|
900
891
|
/** The names an instance's soul (its row's `agent`) may carry for a soul row: its name, and for a
|
|
901
|
-
* package soul the kernel's key
|
|
892
|
+
* package soul the kernel's key, its qualified name and its name in the roster, `<package>--<soul>`
|
|
893
|
+
* (the shared rosterAgentName: the agent directory a package soul's instances are made under). The
|
|
894
|
+
* exact soul filter, the count of a soul's instances and "Used by" match these. */
|
|
902
895
|
export function soulNames(row) {
|
|
903
|
-
return [...new Set([row.name, row.key, row.qualifiedName].filter(text))];
|
|
896
|
+
return [...new Set([row.name, row.key, row.qualifiedName, rosterAgentName(row)].filter(text))];
|
|
904
897
|
}
|
|
905
898
|
|
|
906
|
-
/** Whether a soul row matches the Souls view's filter: its name, its description or where it comes
|
|
907
|
-
* from contains the text, case aside, as the Desktop's soul grid filters (views/spawn.mjs). */
|
|
908
|
-
const soulMatches = (row, needle) => [row.name, row.description, row.repoName].some((value) => String(value || "").toLowerCase().includes(needle));
|
|
909
|
-
|
|
910
899
|
/** The souls of the open workspace as the store and the view read them: the shared rows
|
|
911
900
|
* (soul-rows.mjs soulRows) of the catalog the loop holds for it, filtered by the view's own
|
|
912
901
|
* filter. Only a workspace of this machine has souls here (`local`). `held` is what the loop
|
|
@@ -914,8 +903,9 @@ const soulMatches = (row, needle) => [row.name, row.description, row.repoName].s
|
|
|
914
903
|
* row the selection stands on: the store's, while it is listed, else the first. */
|
|
915
904
|
export function soulsOf(state) {
|
|
916
905
|
const { local, deployment, held, all } = catalogOf(state, state.open);
|
|
917
|
-
|
|
918
|
-
const
|
|
906
|
+
// The Souls view's filter is the Desktop's soul grid's (soulMatches), on the trimmed text.
|
|
907
|
+
const query = state.souls.filter.query.trim();
|
|
908
|
+
const rows = query ? all.filter((row) => soulMatches(row, query)) : all;
|
|
919
909
|
const selected = rows.find((row) => row.name === state.souls.selected) ?? rows[0] ?? null;
|
|
920
910
|
return { local, deployment, held, all, rows, selected };
|
|
921
911
|
}
|
|
@@ -976,9 +966,9 @@ function soulsView(state, page, at) {
|
|
|
976
966
|
const entry = s.held?.entry ?? null, reason = entry?.reason ?? null;
|
|
977
967
|
if (!Array.isArray(entry?.souls)) {
|
|
978
968
|
// Nothing held: the first read is in flight (or the deployment not read yet), or it failed.
|
|
979
|
-
return reason && !s.held.reading ? { ...base, state: "failed", failure:
|
|
969
|
+
return reason && !s.held.reading ? { ...base, state: "failed", failure: soulCatalogFailure(reason) } : { ...base, state: "reading" };
|
|
980
970
|
}
|
|
981
|
-
const heading = reason ? { label: "Souls", path: null, state: null, short:
|
|
971
|
+
const heading = reason ? { label: "Souls", path: null, state: null, short: soulCatalogFailure(reason), readAt: clockTime(entry.observedAt) } : null;
|
|
982
972
|
const state_ = !s.all.length ? "none" : !s.rows.length ? "nomatch" : "rows";
|
|
983
973
|
const height = Math.max(1, page - (heading ? 1 : 0));
|
|
984
974
|
const at_ = s.selected ? s.rows.indexOf(s.selected) : -1;
|
|
@@ -996,6 +986,116 @@ function soulsView(state, page, at) {
|
|
|
996
986
|
};
|
|
997
987
|
}
|
|
998
988
|
|
|
989
|
+
// ── THE CAPABILITIES VIEW (docs/tui.md, "The Capabilities view"; Spec 7) ──────────────────────────
|
|
990
|
+
|
|
991
|
+
/** A capability's identity in the view: its source's key and its name, since a package's capability
|
|
992
|
+
* and a member's may share a name (Spec 7, Settled 8). */
|
|
993
|
+
export const capabilityKey = (row, names) => `${capabilitySource(row, names).key}\u0000${row.name}`;
|
|
994
|
+
|
|
995
|
+
/** The view's sections, in the order they stand (the Desktop's): Workspace owned, Repo owned, Packages. */
|
|
996
|
+
const SECTION_ORDER = Object.freeze(["workspace", "repo", "packages"]);
|
|
997
|
+
|
|
998
|
+
/** The capabilities of the open workspace as the store and the view read them: the rows of the
|
|
999
|
+
* catalog the loop holds for it (`held`, `{ entry, reading }`), filtered by the view's own filter
|
|
1000
|
+
* (the shared matchCapabilities), in the shared sections (capabilitySections) and groups
|
|
1001
|
+
* (groupCapabilities), as `items` in drawn order: `{ section }` (a section's heading), `{ group, note }`
|
|
1002
|
+
* (a repository's or a package's), and `{ key, row }` (a capability). A section or a group with no
|
|
1003
|
+
* row is not listed. `keys` are the capabilities in order, `selected` the key the selection stands
|
|
1004
|
+
* on (the store's while it is listed, else the first) and `row` its row; `heading` whether a failed
|
|
1005
|
+
* re-read's heading stands above the rows. Only a workspace of this machine has them (`local`). */
|
|
1006
|
+
export function capabilitiesOf(state) {
|
|
1007
|
+
const id = state.open, local = id !== null && state.ctxs.includes(id);
|
|
1008
|
+
const entry = local ? state.entries.get(id) ?? null : null;
|
|
1009
|
+
const deployment = entry?.deployment?.status === "observed" ? entry.deployment : null;
|
|
1010
|
+
const held = local ? state.capabilities.held.get(id) ?? null : null;
|
|
1011
|
+
const status = deployment?.workspaceStatus ?? null;
|
|
1012
|
+
const listed = deployment !== null && Array.isArray(held?.entry?.capabilities?.capabilities);
|
|
1013
|
+
const all = listed ? held.entry.capabilities.capabilities : [];
|
|
1014
|
+
const names = memberNames(status), hostKey = hostKeyOf(status);
|
|
1015
|
+
const sections = capabilitySections(matchCapabilities(all, state.capabilities.filter.query));
|
|
1016
|
+
const items = [];
|
|
1017
|
+
for (const section of SECTION_ORDER) {
|
|
1018
|
+
if (!sections[section].length) continue;
|
|
1019
|
+
items.push({ section });
|
|
1020
|
+
for (const group of groupCapabilities(sections[section], names, hostKey)) {
|
|
1021
|
+
items.push({ group: group.name, note: group.note });
|
|
1022
|
+
for (const row of group.rows) items.push({ key: capabilityKey(row, names), row });
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
const keys = items.filter((item) => item.key !== undefined).map((item) => item.key);
|
|
1026
|
+
const selected = keys.includes(state.capabilities.selected) ? state.capabilities.selected : keys[0] ?? null;
|
|
1027
|
+
const row = selected === null ? null : items.find((item) => item.key === selected).row;
|
|
1028
|
+
return { local, deployment, status, held, listed, all, items, keys, selected, row, heading: listed && Boolean(held.entry.reason) };
|
|
1029
|
+
}
|
|
1030
|
+
/** The rows the list of capabilities has in a pane `page` rows tall: a failed re-read's heading takes one. */
|
|
1031
|
+
export const capabilitiesHeight = (c, page) => Math.max(1, page - (c.heading ? 1 : 0));
|
|
1032
|
+
|
|
1033
|
+
/** "Used by" of capability `row` (capability-rows.mjs capabilityUsers): with the kernel's
|
|
1034
|
+
* souls-capabilities, the souls of the open workspace's catalog whose composition includes it; before
|
|
1035
|
+
* it, the souls whose instances carry it. `instances` are this machine's rows of the open workspace.
|
|
1036
|
+
* Each user is drawn by its catalog row (soulOfAgent maps an instance's agent name to it): its name
|
|
1037
|
+
* and colour, and the soul Enter shows in the Souls view (`soul`, null when no row matches); `count`
|
|
1038
|
+
* its instances carrying the capability, and `behind` the shared words for those on an older
|
|
1039
|
+
* version, or null. Until the souls catalog is read the souls are not known (`reading`, or `failed`
|
|
1040
|
+
* with its sentence): nothing claims that no soul includes it. */
|
|
1041
|
+
export function capabilityUsersOf(state, at, row) {
|
|
1042
|
+
const composition = soulsComposition(state.cli), souls = catalogOf(state, state.open), entry = souls.held?.entry ?? null;
|
|
1043
|
+
const none = { shown: [], more: 0, count: null, empty: null, failure: null };
|
|
1044
|
+
if (composition && !Array.isArray(entry?.souls)) return { ...none, state: entry?.reason && !souls.held.reading ? "failed" : "reading", failure: entry?.reason && !souls.held.reading ? soulCatalogFailure(entry.reason) : null };
|
|
1045
|
+
const instances = roster(state, at).ordered.filter((each) => !elsewhere(each) && each.deployment?.id === state.open);
|
|
1046
|
+
const users = capabilityUsers(row, { souls: souls.all, instances, composition }).map(({ soul, carrying, behind }) => {
|
|
1047
|
+
const found = composition ? soul : soulOfAgent(state, state.open, soul.name);
|
|
1048
|
+
return { name: found?.name ?? soul.name, color: found ? SOUL_COLOURS[found.color] ?? null : null, count: carrying.length, behind: behind > 0 ? CAPABILITY_COPY.behind(behind) : null, soul: found?.name ?? null };
|
|
1049
|
+
});
|
|
1050
|
+
return {
|
|
1051
|
+
...none, state: "known", shown: users.slice(0, INSTANCES_NAMED), more: Math.max(0, users.length - INSTANCES_NAMED), count: CAPABILITY_COPY.souls(users.length),
|
|
1052
|
+
empty: users.length ? null : composition ? CAPABILITY_COPY.noSoul : CAPABILITY_COPY.noInstance,
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/** The selected capability's detail, from its row and the shared facts (capability-facts.mjs
|
|
1057
|
+
* capabilityFacts) in the shared words (CAPABILITY_COPY): nothing of a capability is worded here. A
|
|
1058
|
+
* kind of Provides the kernel could not list (`names` null) says CAPABILITY_COPY.unlistable, and one
|
|
1059
|
+
* with no name CAPABILITY_COPY.none. `comesFrom` holds the facts' "Comes from" rows as `{ label,
|
|
1060
|
+
* value }`, the shortened value (not `origin`: in this package that names a reason's speaker, which
|
|
1061
|
+
* test/tui-boundary.test.mjs holds to originLead). */
|
|
1062
|
+
function capabilityDetail(state, at, c) {
|
|
1063
|
+
const row = c.row, { origin, provides } = capabilityFacts(row, { status: c.status });
|
|
1064
|
+
return {
|
|
1065
|
+
name: row.name, layer: text(row.layer) ? layerLabel(row.layer) : null, description: row.description ?? "",
|
|
1066
|
+
words: { comesFrom: CAPABILITY_COPY.comesFrom, provides: CAPABILITY_COPY.provides, usedBy: CAPABILITY_COPY.usedBy },
|
|
1067
|
+
comesFrom: origin.map(([label, value]) => ({ label, value })),
|
|
1068
|
+
provides: provides.map(([label, names]) => ({ label, names: names ?? [], said: names === null ? CAPABILITY_COPY.unlistable : names.length ? null : CAPABILITY_COPY.none })),
|
|
1069
|
+
used: capabilityUsersOf(state, at, row),
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/** What the Capabilities view draws, in a list pane `page` rows tall (views/capabilities.mjs): the
|
|
1074
|
+
* state of the catalog, the window of its items, and the selected capability's detail with the soul
|
|
1075
|
+
* of "Used by" that has the detail's mark (`mark`, an index of its listed souls). A failed re-read
|
|
1076
|
+
* keeps the rows it held, under a heading that says so, as the Souls view's does. */
|
|
1077
|
+
function capabilitiesView(state, page, at) {
|
|
1078
|
+
const c = capabilitiesOf(state), v = state.capabilities;
|
|
1079
|
+
const base = { local: c.local, failure: null, heading: null, list: [], above: 0, below: 0, focus: v.focus, filter: v.filter, detail: null, detailTop: v.detailTop, keep: !v.detailLoose, mark: v.mark };
|
|
1080
|
+
if (!c.local) return { ...base, state: "none" };
|
|
1081
|
+
const entry = c.held?.entry ?? null, reason = entry?.reason ?? null;
|
|
1082
|
+
if (!c.listed) return reason && !c.held.reading ? { ...base, state: "failed", failure: catalogFailure("capabilities", reason) } : { ...base, state: "reading" };
|
|
1083
|
+
const heading = c.heading ? { label: "Capabilities", path: null, state: null, short: catalogFailure("capabilities", reason), readAt: clockTime(entry.observedAt) } : null;
|
|
1084
|
+
const state_ = !c.all.length ? "none" : !c.keys.length ? "nomatch" : "rows";
|
|
1085
|
+
const at_ = c.items.findIndex((item) => item.key !== undefined && item.key === c.selected);
|
|
1086
|
+
const win = windowOf({ top: v.top, count: c.items.length, height: capabilitiesHeight(c, page), keep: v.loose ? -1 : at_ });
|
|
1087
|
+
const detail = c.row ? capabilityDetail(state, at, c) : null;
|
|
1088
|
+
return {
|
|
1089
|
+
...base, state: state_, heading,
|
|
1090
|
+
list: c.items.slice(win.top, win.top + win.size).map((item) => (item.key === undefined ? item
|
|
1091
|
+
: { name: item.row.name, layer: text(item.row.layer) ? layerLabel(item.row.layer) : null, selected: item.key === c.selected })),
|
|
1092
|
+
above: win.above, below: win.below,
|
|
1093
|
+
detail: detail && { ...detail, failure: heading ? heading.short : null },
|
|
1094
|
+
// The mark stands on a listed soul only: the store keeps it inside them.
|
|
1095
|
+
mark: detail && v.focus === "detail" && detail.used.shown.length ? Math.min(v.mark, detail.used.shown.length - 1) : -1,
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
|
|
999
1099
|
// ── SPAWNING (docs/tui.md, "Spawning an agent"; Spec 6-spawn) ───────────────────────────────────
|
|
1000
1100
|
|
|
1001
1101
|
/** A shared sentence as parts the outcome line wraps (views/frame.mjs partRows): each word is
|
|
@@ -1145,7 +1245,7 @@ function spawnView(state, page, at) {
|
|
|
1145
1245
|
rows: list.items.slice(win.top, win.top + win.size).map((item) => ({ name: item.name, refused: item.refused, refusal: item.refused ? soulFacts(item.row, null, state.cli, TERMS).refusalLine : null, selected: item.name === list.selected })),
|
|
1146
1246
|
above: win.above, below: win.below,
|
|
1147
1247
|
state: failed ? "failed" : reading ? "reading" : !c.all.length ? "none" : !list.items.length ? "nomatch" : "rows",
|
|
1148
|
-
failure: failed ?
|
|
1248
|
+
failure: failed ? soulCatalogFailure(entry.reason) : null,
|
|
1149
1249
|
};
|
|
1150
1250
|
}
|
|
1151
1251
|
const facts = spawnFacts(state, p, at), ring = spawnRing(p);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { ACTIONS, LEADER_KEYS, bindings } from "./actions.mjs";
|
|
13
13
|
import { collapseKey, displayLine, instanceActs, instanceId, outcomeWords, pendingEntry, spawnProblem } from "./client.mjs";
|
|
14
14
|
import { DETACH_KEY } from "./config.mjs";
|
|
15
|
-
import { BUTTON_ORDER, SPAWN_WORDS, SPLIT_WORDS, TAB_WORDS, actDecision, disclosure, openDecision, paletteItems, preflightLine, returnedLine, roster, soulNames, soulOfAgent, soulsOf, spawnChoices, spawnChoicesKey, spawnLine, spawnPickerItems, spawnReady, spawnRing, spawnSelector, spawnedRow, switcher } from "./model.mjs";
|
|
15
|
+
import { BUTTON_ORDER, SPAWN_WORDS, SPLIT_WORDS, TAB_WORDS, actDecision, capabilitiesHeight, capabilitiesOf, capabilityUsersOf, disclosure, openDecision, paletteItems, preflightLine, returnedLine, roster, soulNames, soulOfAgent, soulsOf, spawnChoices, spawnChoicesKey, spawnLine, spawnPickerItems, spawnReady, spawnRing, spawnSelector, spawnedRow, switcher } from "./model.mjs";
|
|
16
16
|
import { backKeyId } from "./term/through.mjs";
|
|
17
17
|
import { windowOf } from "./views/scroll.mjs";
|
|
18
18
|
import { SPLIT_MIN, splitFits } from "./views/split.mjs";
|
|
@@ -32,6 +32,13 @@ const NO_FILTER = Object.freeze({ editing: false, query: "" });
|
|
|
32
32
|
* and whether a read of it is in flight), and the selection (a soul's name), the scroll, the focus
|
|
33
33
|
* and the filter of the view, kept when it is left and found again, for the run. */
|
|
34
34
|
const NO_SOULS = Object.freeze({ wanted: false, held: new Map(), selected: null, top: 0, loose: false, focus: "list", detailTop: 0, filter: Object.freeze({ editing: false, query: "" }) });
|
|
35
|
+
/** The Capabilities view's own (docs/tui.md, "The Capabilities view"; Spec 7), as the Souls view's:
|
|
36
|
+
* whether its catalog was ever wanted, what the loop holds of each workspace's (`held`), and the
|
|
37
|
+
* selection (a capability's key, lib/model.mjs capabilityKey), the list's scroll (`top`, `loose` as
|
|
38
|
+
* the switcher's), the focus, the filter, and in the detail its scroll (`detailTop`, the row it was
|
|
39
|
+
* last drawn from) and the mark on a soul of "Used by" (`mark`, an index of the listed souls;
|
|
40
|
+
* `detailLoose` while the detail was scrolled away from it on purpose). Kept for the run. */
|
|
41
|
+
const NO_CAPABILITIES = Object.freeze({ wanted: false, held: new Map(), selected: null, top: 0, loose: false, focus: "list", detailTop: 0, detailLoose: false, mark: 0, filter: Object.freeze({ editing: false, query: "" }) });
|
|
35
42
|
|
|
36
43
|
/** The state before the first answer. `deployment` is the one `oats tui` was started in or was
|
|
37
44
|
* told of, with its shared pending entry (lib/main.mjs makes it); null for a run started outside
|
|
@@ -97,7 +104,7 @@ export function initialState({ deployment = null, cli, home, entry = null, actio
|
|
|
97
104
|
switcher: Object.freeze({ editing: false, query: "", selected: null, top: 0, loose: false, line: null, refused: null }),
|
|
98
105
|
offered: Object.freeze({ offered: Object.freeze([]), limited: false }),
|
|
99
106
|
helpTop: 0, actions, ascii, detachKey, opening: null, terminal: null, outcome: null, act: null, acted: 0, starting: new Map(), retiring: new Set(),
|
|
100
|
-
leaderKey: backKeyId(detachKey), leader: null, palette: null, recent: Object.freeze([]), souls: NO_SOULS,
|
|
107
|
+
leaderKey: backKeyId(detachKey), leader: null, palette: null, recent: Object.freeze([]), souls: NO_SOULS, capabilities: NO_CAPABILITIES,
|
|
101
108
|
spawn: null, spawning: null, spawnCheck: null, arriving: null, previews: 0, tabs: Object.freeze([]), split: null, group: 0, aside: null,
|
|
102
109
|
});
|
|
103
110
|
}
|
|
@@ -258,6 +265,11 @@ const FIELDS = Object.freeze({
|
|
|
258
265
|
put: (state, query) => (query === state.souls.filter.query ? state : soulsWith(state, { filter: Object.freeze({ ...state.souls.filter, query }), top: 0, loose: false, detailTop: 0 })),
|
|
259
266
|
close: (state, query) => soulsWith(state, { filter: Object.freeze({ editing: false, query }), top: 0, loose: false }),
|
|
260
267
|
}),
|
|
268
|
+
capabilities: Object.freeze({
|
|
269
|
+
query: (state) => state.capabilities.filter.query,
|
|
270
|
+
put: (state, query) => (query === state.capabilities.filter.query ? state : capabilitiesWith(state, { filter: Object.freeze({ ...state.capabilities.filter, query }), top: 0, loose: false, detailTop: 0, mark: 0 })),
|
|
271
|
+
close: (state, query) => capabilitiesWith(state, { filter: Object.freeze({ editing: false, query }), top: 0, loose: false }),
|
|
272
|
+
}),
|
|
261
273
|
switcher: Object.freeze({
|
|
262
274
|
query: (state) => state.switcher.query,
|
|
263
275
|
put: (state, query) => (query === state.switcher.query ? state : next(state, { switcher: Object.freeze({ ...state.switcher, query, top: 0, loose: false }) })),
|
|
@@ -267,7 +279,8 @@ const FIELDS = Object.freeze({
|
|
|
267
279
|
/** The filter field that is open now, or null. */
|
|
268
280
|
const fieldOf = (state) => (state.view === "instances" && state.filter.editing ? FIELDS.instances
|
|
269
281
|
: state.view === "switcher" && state.switcher.editing ? FIELDS.switcher
|
|
270
|
-
: state.view === "souls" && state.souls.filter.editing ? FIELDS.souls
|
|
282
|
+
: state.view === "souls" && state.souls.filter.editing ? FIELDS.souls
|
|
283
|
+
: state.view === "capabilities" && state.capabilities.filter.editing ? FIELDS.capabilities : null);
|
|
271
284
|
|
|
272
285
|
/** A key while a filter field is open. A key that is text is text, whatever the action table
|
|
273
286
|
* says, so `q` and `j` can be typed; Backspace removes one grapheme, Enter keeps the filter and
|
|
@@ -346,6 +359,100 @@ function inSouls(state, action, event, page, scrolled) {
|
|
|
346
359
|
}
|
|
347
360
|
}
|
|
348
361
|
|
|
362
|
+
/** The Souls view with the soul named `name` selected, as the palette's soul row and the Capabilities
|
|
363
|
+
* view's "Used by" show it. A kept filter of the view that hides it is cleared: the soul chosen is
|
|
364
|
+
* the one shown, and the one `i` acts on. */
|
|
365
|
+
function soulChosen(state, name) {
|
|
366
|
+
const step = soulsShown(state), chosen = soulsWith(step.state, { selected: name, loose: false, detailTop: 0 });
|
|
367
|
+
const shown = soulsOf(chosen).selected?.name === name ? chosen : soulsWith(chosen, { filter: Object.freeze({ editing: false, query: "" }), top: 0 });
|
|
368
|
+
return { state: shown, effect: step.effect };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** The Capabilities view's own state with what changes of it. */
|
|
372
|
+
const capabilitiesWith = (state, changes) => next(state, { capabilities: Object.freeze({ ...state.capabilities, ...changes }) });
|
|
373
|
+
|
|
374
|
+
/** The Capabilities view shown (docs/tui.md, "The Capabilities view"): from now on its catalog is
|
|
375
|
+
* wanted, and so is the souls catalog its "Used by" reads, the same flag the Souls view and a spawn
|
|
376
|
+
* set; the loop settles both for the open workspace (`capabilities: "settle"`, `souls: "settle"`),
|
|
377
|
+
* each read only when nothing is held for the workspace as it is now (each its own key). */
|
|
378
|
+
function capabilitiesShown(state) {
|
|
379
|
+
// Come back to from another view, it shows its list: what was selected and filtered stays.
|
|
380
|
+
const shown = state.view === "capabilities" ? state : next(state, { view: "capabilities", back: "capabilities", capabilities: Object.freeze({ ...state.capabilities, focus: "list" }) });
|
|
381
|
+
return { state: soulsWith(capabilitiesWith(shown, { wanted: true }), { wanted: true }), effect: { souls: "settle", capabilities: "settle" } };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** What the loop holds of a workspace's capabilities catalog, told: `{ id, entry, reading }`, as
|
|
385
|
+
* soulsHeard. Only a served workspace's is kept. */
|
|
386
|
+
function capabilitiesHeard(state, { id, entry, reading }) {
|
|
387
|
+
if (!state.ctxs.includes(id)) return { state, effect: null };
|
|
388
|
+
return { state: capabilitiesWith(state, { held: new Map(state.capabilities.held).set(id, Object.freeze({ entry: entry ?? null, reading: reading === true })) }), effect: null };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** The row the capability detail was drawn from, told by the loop once the frame is written (the
|
|
392
|
+
* view keeps the marked soul in sight, so the store's `detailTop` may not be what was drawn): the
|
|
393
|
+
* detail scrolls on from there. */
|
|
394
|
+
function capabilitiesTop(state, top) {
|
|
395
|
+
if (state.view !== "capabilities" || !Number.isInteger(top) || top < 0 || state.capabilities.detailTop === top) return { state, effect: null };
|
|
396
|
+
return { state: capabilitiesWith(state, { detailTop: top }), effect: null };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** A key in the Capabilities view (docs/tui.md, "The Capabilities view"). The list's keys move among
|
|
400
|
+
* the capabilities the filter keeps, passing over the headings of the sections and the groups (the
|
|
401
|
+
* switcher's way: what stands above the first comes into the pane with it, and with nothing further
|
|
402
|
+
* to go to the list scrolls). Enter gives the detail the focus, its mark on the first soul of "Used
|
|
403
|
+
* by"; there Up and Down move that mark among the listed souls, and Enter shows the marked soul in
|
|
404
|
+
* the Souls view. Past the first or the last soul, with none listed, and for the other movement
|
|
405
|
+
* keys, the detail scrolls. `/`
|
|
406
|
+
* opens the view's own filter field; `r` reads the catalog again (`capabilities: "reread"`, which
|
|
407
|
+
* starts nothing while a read is in flight); Esc closes the detail, then clears a kept filter, then
|
|
408
|
+
* goes back to the instances (to the switcher when no workspace is open), as `1` does. */
|
|
409
|
+
function inCapabilities(state, action, event, page, scrolled) {
|
|
410
|
+
const stay = { state, effect: null }, v = state.capabilities;
|
|
411
|
+
const c = capabilitiesOf(state), at = c.selected === null ? -1 : c.keys.indexOf(c.selected);
|
|
412
|
+
const back = () => ({ state: state.open === null ? toSwitcher(next(state, { back: "switcher" })) : next(state, { view: "instances", back: "instances" }), effect: null });
|
|
413
|
+
const put = (changes) => ({ state: capabilitiesWith(state, changes), effect: null });
|
|
414
|
+
const toDetail = { focus: "detail", mark: 0, detailTop: 0, detailLoose: false };
|
|
415
|
+
switch (action) {
|
|
416
|
+
case "instances": return back();
|
|
417
|
+
case "close":
|
|
418
|
+
if (v.focus === "detail") return put({ focus: "list" });
|
|
419
|
+
if (v.filter.query !== "") return put({ filter: Object.freeze({ editing: false, query: "" }), top: 0, loose: false });
|
|
420
|
+
return back();
|
|
421
|
+
case "filter": return c.local ? put({ focus: "list", filter: Object.freeze({ ...v.filter, editing: true }) }) : stay;
|
|
422
|
+
case "refresh": return c.local ? { state, effect: { capabilities: "reread" } } : stay;
|
|
423
|
+
case "open": {
|
|
424
|
+
if (at < 0) return stay;
|
|
425
|
+
if (v.focus !== "detail") return put(toDetail);
|
|
426
|
+
const listed = capabilityUsersOf(state, undefined, c.row).shown;
|
|
427
|
+
const soul = listed[Math.min(v.mark, listed.length - 1)]?.soul ?? null;
|
|
428
|
+
return soul === null ? stay : soulChosen(state, soul);
|
|
429
|
+
}
|
|
430
|
+
case "detail": return at < 0 ? stay : put(v.focus === "detail" ? { focus: "list" } : toDetail);
|
|
431
|
+
case "up": case "down": case "top": case "bottom": case "page-up": case "page-down": {
|
|
432
|
+
if (v.focus === "detail") {
|
|
433
|
+
const listed = at < 0 ? 0 : capabilityUsersOf(state, undefined, c.row).shown.length;
|
|
434
|
+
// The mark moves while it has a soul to go to; past the first or the last, the detail scrolls.
|
|
435
|
+
const to = Math.min(v.mark, listed - 1) + (action === "up" ? -1 : 1);
|
|
436
|
+
if (listed && (action === "up" || action === "down") && to >= 0 && to < listed) return put({ mark: to, detailLoose: false });
|
|
437
|
+
return put({ detailTop: scrolled(v.detailTop), detailLoose: true });
|
|
438
|
+
}
|
|
439
|
+
const count = c.items.length, height = capabilitiesHeight(c, page);
|
|
440
|
+
const drawn = windowOf({ top: v.top, count, height, keep: v.loose ? -1 : c.items.findIndex((item) => item.key !== undefined && item.key === c.selected) }).top;
|
|
441
|
+
const key = c.keys.length ? c.keys[Math.min(Math.max(0, moved(action, Math.max(0, at), c.keys.length, page)), c.keys.length - 1)] : null;
|
|
442
|
+
// No capability to go to in that direction: the rows scroll instead.
|
|
443
|
+
if (key === null || key === c.selected) {
|
|
444
|
+
const top = windowOf({ top: moved(action, drawn, count, height), count, height }).top;
|
|
445
|
+
return top === drawn ? stay : put({ top, loose: true });
|
|
446
|
+
}
|
|
447
|
+
const index = c.items.findIndex((item) => item.key === key);
|
|
448
|
+
// The headings above the first capability come into the pane with it, and what stands under the last one.
|
|
449
|
+
const top = windowOf({ top: key === c.keys[0] ? 0 : key === c.keys.at(-1) ? count : drawn, count, height, keep: index }).top;
|
|
450
|
+
return put({ selected: key, top, loose: false, detailTop: 0, mark: 0, detailLoose: false });
|
|
451
|
+
}
|
|
452
|
+
default: return stay;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
349
456
|
const MOVES = Object.freeze(["up", "down", "top", "bottom", "page-up", "page-down"]);
|
|
350
457
|
/** Where a movement key takes a position `from` among `count` rows, a page being `page` rows. */
|
|
351
458
|
function moved(action, from, count, page) {
|
|
@@ -1003,11 +1110,12 @@ function ranFromPalette(state, item, event, keymap) {
|
|
|
1003
1110
|
const from = state.palette.from;
|
|
1004
1111
|
const settled = item.kind === "instance" || item.kind === "act" ? toInstances(state) : toList(state), shut = settled.state;
|
|
1005
1112
|
const then = (step) => ({ state: step.state, effect: both(settled.effect, step.effect) });
|
|
1006
|
-
// A soul: the Souls view, with it selected.
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
const
|
|
1113
|
+
// A soul: the Souls view, with it selected (soulChosen).
|
|
1114
|
+
if (item.kind === "soul") return then(soulChosen(shut, item.name));
|
|
1115
|
+
// A capability: the Capabilities view, with it selected, as a soul is shown.
|
|
1116
|
+
if (item.kind === "capability") {
|
|
1117
|
+
const step = capabilitiesShown(shut), chosen = capabilitiesWith(step.state, { selected: item.capability, loose: false, detailTop: 0, mark: 0, detailLoose: false });
|
|
1118
|
+
const shown = capabilitiesOf(chosen).selected === item.capability ? chosen : capabilitiesWith(chosen, { filter: Object.freeze({ editing: false, query: "" }), top: 0 });
|
|
1011
1119
|
return then({ state: shown, effect: step.effect });
|
|
1012
1120
|
}
|
|
1013
1121
|
if (item.kind === "instance" || item.kind === "act") {
|
|
@@ -1045,8 +1153,11 @@ function reduced(state, event, keymap) {
|
|
|
1045
1153
|
if (event.admitted !== undefined) return { state: admitted(state, event), effect: { refresh: { live: true } } };
|
|
1046
1154
|
if (event.refused !== undefined) return { state: next(state, { switcher: Object.freeze({ ...state.switcher, refused: event.refused }) }), effect: null };
|
|
1047
1155
|
if (event.souls !== undefined) return soulsHeard(state, event.souls);
|
|
1156
|
+
if (event.capabilities !== undefined) return capabilitiesHeard(state, event.capabilities);
|
|
1157
|
+
if (event.capabilitiesTop !== undefined) return capabilitiesTop(state, event.capabilitiesTop);
|
|
1048
1158
|
if (event.spawnRead !== undefined) return spawnRead(state, event.spawnRead);
|
|
1049
1159
|
if (event.spawnDrawn !== undefined) return spawnDrawn(state, event.spawnDrawn);
|
|
1160
|
+
if (event.spawnTop !== undefined) return spawnTop(state, event.spawnTop);
|
|
1050
1161
|
if (event.spawnProgress !== undefined) return { state: state.spawning?.phase === "submitting" ? next(state, { spawning: Object.freeze({ ...state.spawning, phase: "spawning" }) }) : state, effect: null };
|
|
1051
1162
|
if (event.spawnDone !== undefined) return spawnDone(state, event.spawnDone);
|
|
1052
1163
|
// An action the leader or the palette runs comes as `{ action }`, with no key: whatever field or
|
|
@@ -1073,25 +1184,21 @@ function reduced(state, event, keymap) {
|
|
|
1073
1184
|
switch (action) {
|
|
1074
1185
|
case "quit": case "suspend": case "redraw": return { state, effect: action };
|
|
1075
1186
|
// In the switcher the folders of ~/Agents are listed again too.
|
|
1076
|
-
// In the Souls view it reads the souls again, and nothing else.
|
|
1077
|
-
case "refresh": return state.view === "souls" ? inSouls(state, action, event, page, scrolled) : { state, effect: { refresh: { live: true }, ...((state.view === "help" ? state.back : state.view) === "switcher" ? { offer: true } : {}) } };
|
|
1187
|
+
// In the Souls view it reads the souls again, and nothing else; in the Capabilities view, the capabilities.
|
|
1188
|
+
case "refresh": return state.view === "souls" ? inSouls(state, action, event, page, scrolled) : state.view === "capabilities" ? inCapabilities(state, action, event, page, scrolled) : { state, effect: { refresh: { live: true }, ...((state.view === "help" ? state.back : state.view) === "switcher" ? { offer: true } : {}) } };
|
|
1078
1189
|
case "help": return { state: next(state, state.view === "help" ? { view: state.back } : { view: "help", back: state.view, helpTop: 0 }), effect: null };
|
|
1079
1190
|
case "workspaces": return state.view === "switcher" ? stay : { state: toSwitcher(next(state, { back: "switcher" })), effect: { offer: true } };
|
|
1080
1191
|
case "palette": return { state: paletteOpened(state, event, "list"), effect: null };
|
|
1081
1192
|
// Souls and Capabilities are views of this machine, whatever workspace is open, or none.
|
|
1082
1193
|
case "souls": return soulsShown(state);
|
|
1083
|
-
case "capabilities": return
|
|
1194
|
+
case "capabilities": return capabilitiesShown(state);
|
|
1084
1195
|
// A spawn starts from the list of instances or the Souls view (the leader reaches them from anywhere).
|
|
1085
1196
|
case "spawn": case "spawn-another": return state.view === "instances" || state.view === "souls" ? spawnAsked(state, event, action, spawnTarget(state)) : stay;
|
|
1086
1197
|
case "spawn-check": return spawnChecked(state);
|
|
1087
1198
|
default:
|
|
1088
1199
|
}
|
|
1089
1200
|
if (state.view === "souls") return inSouls(state, action, event, page, scrolled);
|
|
1090
|
-
if (state.view === "capabilities")
|
|
1091
|
-
// Esc and 1 go back to the instances, or to the switcher when no workspace is open.
|
|
1092
|
-
if (action !== "close" && action !== "instances") return stay;
|
|
1093
|
-
return { state: state.open === null ? toSwitcher(next(state, { back: "switcher" })) : next(state, { view: "instances", back: "instances" }), effect: null };
|
|
1094
|
-
}
|
|
1201
|
+
if (state.view === "capabilities") return inCapabilities(state, action, event, page, scrolled);
|
|
1095
1202
|
if (state.view === "help") {
|
|
1096
1203
|
if (action === "close") return { state: next(state, { view: state.back }), effect: null };
|
|
1097
1204
|
if (action === "instances") return state.open === null ? stay : { state: next(state, { view: "instances", back: "instances" }), effect: null };
|
|
@@ -1250,6 +1357,16 @@ function spawnDrawn(state, { n, read }) {
|
|
|
1250
1357
|
return { state: spawnWith(state, { shownIn: read }), effect: null };
|
|
1251
1358
|
}
|
|
1252
1359
|
|
|
1360
|
+
/** The preview's window as a frame painted it (`{ n, top }`): it keeps the fold with the focus in
|
|
1361
|
+
* sight, so it may stand where `top` does not. Taken once for each frame painted, `top` is then
|
|
1362
|
+
* that window, and the movement keys go on from it, each from where the one before left it,
|
|
1363
|
+
* painted or not (round 1 of the polish's review). */
|
|
1364
|
+
function spawnTop(state, { n, top }) {
|
|
1365
|
+
const p = state.spawn;
|
|
1366
|
+
if (p === null || p.step !== "preview" || p.n !== n || !Number.isInteger(top) || top < 0 || p.top === top) return { state, effect: null };
|
|
1367
|
+
return { state: spawnWith(state, { top }), effect: null };
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1253
1370
|
/** The name field's text left as it is now: when it is not what the preview was read with, the
|
|
1254
1371
|
* preview is read again. A changed choice puts away what an earlier spawn's outcome said. */
|
|
1255
1372
|
function nameKept(state) {
|