@yaks/cli 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1059 -2
- package/_dist/account-forward.d.ts +12 -0
- package/_dist/account-forward.d.ts.map +1 -0
- package/_dist/accounts.d.ts +23 -0
- package/_dist/accounts.d.ts.map +1 -0
- package/_dist/answer.d.ts +88 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/apply.d.ts +17 -0
- package/_dist/apply.d.ts.map +1 -0
- package/_dist/args.d.ts +86 -0
- package/_dist/args.d.ts.map +1 -0
- package/_dist/commands.d.ts +15 -0
- package/_dist/commands.d.ts.map +1 -0
- package/_dist/complete.d.ts +15 -0
- package/_dist/complete.d.ts.map +1 -0
- package/_dist/config.d.ts +37 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/dependencies.d.ts +6 -0
- package/_dist/dependencies.d.ts.map +1 -0
- package/_dist/facets.d.ts +71 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/grammar.d.ts +5 -0
- package/_dist/grammar.d.ts.map +1 -0
- package/_dist/host.d.ts +164 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/install.d.ts +43 -0
- package/_dist/install.d.ts.map +1 -0
- package/_dist/main.d.ts +16 -0
- package/_dist/main.d.ts.map +1 -0
- package/_dist/memo.d.ts +60 -0
- package/_dist/memo.d.ts.map +1 -0
- package/_dist/mod.d.ts +46 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/page.d.ts +73 -0
- package/_dist/page.d.ts.map +1 -0
- package/_dist/platform.d.ts +27 -0
- package/_dist/platform.d.ts.map +1 -0
- package/_dist/reader.d.ts +10 -0
- package/_dist/reader.d.ts.map +1 -0
- package/_dist/release.d.ts +48 -0
- package/_dist/release.d.ts.map +1 -0
- package/_dist/remote.d.ts +13 -0
- package/_dist/remote.d.ts.map +1 -0
- package/_dist/reported.d.ts +11 -0
- package/_dist/reported.d.ts.map +1 -0
- package/_dist/roles.d.ts +2 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/roster.d.ts +41 -0
- package/_dist/roster.d.ts.map +1 -0
- package/_dist/rpc.d.ts +29 -0
- package/_dist/rpc.d.ts.map +1 -0
- package/_dist/run.d.ts +164 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/runtime.d.ts +4 -0
- package/_dist/runtime.d.ts.map +1 -0
- package/_dist/searching.d.ts +7 -0
- package/_dist/searching.d.ts.map +1 -0
- package/_dist/show.d.ts +22 -0
- package/_dist/show.d.ts.map +1 -0
- package/_dist/store.d.ts +25 -0
- package/_dist/store.d.ts.map +1 -0
- package/_dist/terminal.d.ts +17 -0
- package/_dist/terminal.d.ts.map +1 -0
- package/_dist/tool.d.ts +55 -0
- package/_dist/tool.d.ts.map +1 -0
- package/_dist/tty.d.ts +3 -0
- package/_dist/tty.d.ts.map +1 -0
- package/_dist/vault.d.ts +9 -0
- package/_dist/vault.d.ts.map +1 -0
- package/_dist/words.d.ts +11 -0
- package/_dist/words.d.ts.map +1 -0
- package/_dist/yak.d.ts +10 -0
- package/_dist/yak.d.ts.map +1 -0
- package/account-forward.js +40 -0
- package/account-forward.js.map +1 -0
- package/account-forward.ts +50 -0
- package/accounts.js +162 -0
- package/accounts.js.map +1 -0
- package/accounts.ts +228 -0
- package/answer.js +394 -0
- package/answer.js.map +1 -0
- package/answer.ts +569 -0
- package/apply.js +49 -0
- package/apply.js.map +1 -0
- package/apply.ts +54 -0
- package/args.js +420 -0
- package/args.js.map +1 -0
- package/args.ts +494 -0
- package/code.js +209 -0
- package/code.js.map +1 -0
- package/code.ts +227 -0
- package/commands.js +131 -0
- package/commands.js.map +1 -0
- package/commands.ts +142 -0
- package/complete.js +104 -0
- package/complete.js.map +1 -0
- package/complete.ts +152 -0
- package/config.js +125 -0
- package/config.js.map +1 -0
- package/config.ts +180 -0
- package/declarations.js +67 -0
- package/declarations.js.map +1 -0
- package/declarations.ts +84 -0
- package/deno.json +1 -0
- package/dependencies.js +126 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +141 -0
- package/derive.js +102 -0
- package/derive.js.map +1 -0
- package/derive.ts +125 -0
- package/drain.js +83 -0
- package/drain.js.map +1 -0
- package/drain.ts +115 -0
- package/duties.ts +17 -0
- package/exports.json +1486 -0
- package/external.js +373 -0
- package/external.js.map +1 -0
- package/external.ts +435 -0
- package/facets.js +214 -0
- package/facets.js.map +1 -0
- package/facets.ts +232 -0
- package/feedback.js +54 -0
- package/feedback.js.map +1 -0
- package/feedback.ts +57 -0
- package/files.js +84 -0
- package/files.js.map +1 -0
- package/files.ts +112 -0
- package/get_starts.js +31 -0
- package/get_starts.js.map +1 -0
- package/get_starts.ts +34 -0
- package/git-credential.js +79 -0
- package/git-credential.js.map +1 -0
- package/git-credential.ts +77 -0
- package/grammar.js +4 -0
- package/grammar.js.map +1 -0
- package/grammar.ts +5 -0
- package/held.js +51 -0
- package/held.js.map +1 -0
- package/held.ts +66 -0
- package/host.js +1174 -0
- package/host.js.map +1 -0
- package/host.ts +1343 -0
- package/init.js +138 -0
- package/init.js.map +1 -0
- package/init.ts +139 -0
- package/install.js +216 -0
- package/install.js.map +1 -0
- package/install.ts +223 -0
- package/lifetime.js +56 -0
- package/lifetime.js.map +1 -0
- package/lifetime.ts +66 -0
- package/local-page.ts +114 -0
- package/local.js +417 -0
- package/local.js.map +1 -0
- package/local.ts +537 -0
- package/lockfile.js +20 -0
- package/lockfile.js.map +1 -0
- package/lockfile.ts +32 -0
- package/machines.js +33 -0
- package/machines.js.map +1 -0
- package/machines.ts +51 -0
- package/made/4f855610bdabcd736100d34e4e467ea5.json +1 -0
- package/main.js +534 -0
- package/main.js.map +1 -0
- package/main.ts +547 -0
- package/mcp.js +108 -0
- package/mcp.js.map +1 -0
- package/mcp.ts +113 -0
- package/member.js +103 -0
- package/member.js.map +1 -0
- package/member.ts +133 -0
- package/memo.js +503 -0
- package/memo.js.map +1 -0
- package/memo.ts +634 -0
- package/mod.js +46 -0
- package/mod.js.map +1 -0
- package/mod.ts +99 -0
- package/operations.js +53 -0
- package/operations.js.map +1 -0
- package/operations.ts +68 -0
- package/package.json +115 -4
- package/page.js +211 -0
- package/page.js.map +1 -0
- package/page.ts +308 -0
- package/parser.js +45 -0
- package/parser.js.map +1 -0
- package/parser.ts +77 -0
- package/people-search.js +112 -0
- package/people-search.js.map +1 -0
- package/people-search.ts +162 -0
- package/platform.js +184 -0
- package/platform.js.map +1 -0
- package/platform.ts +224 -0
- package/platform_effects.js +5 -0
- package/platform_effects.js.map +1 -0
- package/platform_effects.ts +13 -0
- package/prepare.js +40 -0
- package/prepare.js.map +1 -0
- package/prepare.ts +46 -0
- package/read_activity.js +54 -0
- package/read_activity.js.map +1 -0
- package/read_activity.ts +61 -0
- package/read_thread.js +387 -0
- package/read_thread.js.map +1 -0
- package/read_thread.ts +506 -0
- package/read_worker.ts +164 -0
- package/reader.js +48 -0
- package/reader.js.map +1 -0
- package/reader.ts +57 -0
- package/release.js +82 -0
- package/release.js.map +1 -0
- package/release.json +127 -0
- package/release.ts +98 -0
- package/remote-page.ts +70 -0
- package/remote.js +96 -0
- package/remote.js.map +1 -0
- package/remote.ts +153 -0
- package/report.js +83 -0
- package/report.js.map +1 -0
- package/report.ts +101 -0
- package/reported.js +32 -0
- package/reported.js.map +1 -0
- package/reported.ts +38 -0
- package/restart.js +349 -0
- package/restart.js.map +1 -0
- package/restart.ts +478 -0
- package/restore.js +32 -0
- package/restore.js.map +1 -0
- package/restore.ts +38 -0
- package/roles.js +32 -0
- package/roles.js.map +1 -0
- package/roles.ts +49 -0
- package/roster.js +65 -0
- package/roster.js.map +1 -0
- package/roster.ts +84 -0
- package/rpc.js +113 -0
- package/rpc.js.map +1 -0
- package/rpc.ts +159 -0
- package/run.js +533 -0
- package/run.js.map +1 -0
- package/run.ts +741 -0
- package/runtime.js +381 -0
- package/runtime.js.map +1 -0
- package/runtime.ts +433 -0
- package/sandboxes.js +26 -0
- package/sandboxes.js.map +1 -0
- package/sandboxes.ts +30 -0
- package/searching.js +33 -0
- package/searching.js.map +1 -0
- package/searching.ts +50 -0
- package/show.js +109 -0
- package/show.js.map +1 -0
- package/show.ts +144 -0
- package/shown.js +13 -0
- package/shown.js.map +1 -0
- package/shown.ts +44 -0
- package/stall.js +90 -0
- package/stall.js.map +1 -0
- package/stall.ts +156 -0
- package/stall_profile.js +113 -0
- package/stall_profile.js.map +1 -0
- package/stall_profile.ts +142 -0
- package/stall_wait.js +183 -0
- package/stall_wait.js.map +1 -0
- package/stall_wait.ts +249 -0
- package/stall_wait_worker.ts +11 -0
- package/start.js +349 -0
- package/start.js.map +1 -0
- package/start.ts +343 -0
- package/starvation.js +147 -0
- package/starvation.js.map +1 -0
- package/starvation.ts +224 -0
- package/store.js +118 -0
- package/store.js.map +1 -0
- package/store.ts +193 -0
- package/subcommands.js +62 -0
- package/subcommands.js.map +1 -0
- package/subcommands.ts +77 -0
- package/terminal.js +93 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +128 -0
- package/text.js +20 -0
- package/text.js.map +1 -0
- package/text.ts +37 -0
- package/tool.js +76 -0
- package/tool.js.map +1 -0
- package/tool.ts +157 -0
- package/trace_control.js +231 -0
- package/trace_control.js.map +1 -0
- package/trace_control.ts +233 -0
- package/traces.js +138 -0
- package/traces.js.map +1 -0
- package/traces.ts +160 -0
- package/tracker.js +22 -0
- package/tracker.js.map +1 -0
- package/tracker.ts +27 -0
- package/tty.js +82 -0
- package/tty.js.map +1 -0
- package/tty.ts +142 -0
- package/unit_failure.js +178 -0
- package/unit_failure.js.map +1 -0
- package/unit_failure.ts +191 -0
- package/upkeep_thread.js +32 -0
- package/upkeep_thread.js.map +1 -0
- package/upkeep_thread.ts +35 -0
- package/upkeep_worker.ts +27 -0
- package/vault.js +186 -0
- package/vault.js.map +1 -0
- package/vault.ts +220 -0
- package/vocab-ids.js +63 -0
- package/vocab-ids.js.map +1 -0
- package/vocab-ids.ts +62 -0
- package/vocab.json +35 -0
- package/warm.js +138 -0
- package/warm.js.map +1 -0
- package/warm.ts +171 -0
- package/watch_revision.js +25 -0
- package/watch_revision.js.map +1 -0
- package/watch_revision.ts +30 -0
- package/words.js +29 -0
- package/words.js.map +1 -0
- package/words.ts +41 -0
- package/workspaces.js +40 -0
- package/workspaces.js.map +1 -0
- package/workspaces.ts +58 -0
- package/yak-unit-failure.conf +6 -0
- package/yak-unit-handoff.conf +2 -0
- package/yak.js +123 -0
- package/yak.js.map +1 -0
- package/yak.ts +136 -0
package/terminal.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Portable answer preparation and text output. The CLI supplies its terminal
|
|
2
|
+
// presentation from ./tty.ts.
|
|
3
|
+
import { whole } from "@yaks/query";
|
|
4
|
+
import { prepared } from "@yaks/render";
|
|
5
|
+
import { nearOf, nearQuery, NONE, nothing, parted, printed, referenced, standing, viewOf } from "./answer.js";
|
|
6
|
+
let none = {
|
|
7
|
+
lookup: ()=>[],
|
|
8
|
+
query: ()=>[]
|
|
9
|
+
};
|
|
10
|
+
/** Prepare an answer's views and the references and queries they read, then
|
|
11
|
+
* present it through `present`, or print its portable text. A tool that wrote
|
|
12
|
+
* draws its answer as it now stands, and a page draws a lone entity whole,
|
|
13
|
+
* beside the links and comments its page asks for. */ export let show = async (c, views, vocab, said, held = {}, from = none, tool = {
|
|
14
|
+
readOnly: true
|
|
15
|
+
}, present)=>{
|
|
16
|
+
let answer = tool.readOnly ? said : await standing(said, from);
|
|
17
|
+
// A read that found nothing says so: a blank answer reads as a command
|
|
18
|
+
// that did nothing, or one still working.
|
|
19
|
+
if (tool.readOnly && !answer.length && !c.tui) {
|
|
20
|
+
return c.tty ? c.tty.write(NONE) : c.out(NONE);
|
|
21
|
+
}
|
|
22
|
+
let them = parted(answer).them;
|
|
23
|
+
let lone = viewOf(them, !!tool.page) == 'Page' ? them[0] : undefined;
|
|
24
|
+
let asked = lone ? nearQuery(vocab, lone.entity.eid) : null;
|
|
25
|
+
let page = !lone ? undefined : asked ? nearOf(lone.entity.eid, await from.query(asked)) : nothing;
|
|
26
|
+
let near = page ?? nothing;
|
|
27
|
+
// Portable renderers are pure. Discover the references and queries the
|
|
28
|
+
// drawing reads, including nested views and declared needs, rather than
|
|
29
|
+
// fetching every reference carried by a bundle that a tile never shows. A
|
|
30
|
+
// terminal paints with what the printout read, and the references its
|
|
31
|
+
// components may read beside it.
|
|
32
|
+
let known = new Set([
|
|
33
|
+
...answer,
|
|
34
|
+
...near.links,
|
|
35
|
+
...near.comments
|
|
36
|
+
].map((b)=>b.entity.eid));
|
|
37
|
+
let painting = c.tui || c.tty;
|
|
38
|
+
let refs = painting ? referenced(vocab, [
|
|
39
|
+
...answer,
|
|
40
|
+
...near.links,
|
|
41
|
+
...near.comments
|
|
42
|
+
], held.views ?? views, lone?.entity.eid) : [];
|
|
43
|
+
let named = refs.length ? await from.lookup(refs) : [];
|
|
44
|
+
named.forEach((b)=>known.add(b.entity.eid));
|
|
45
|
+
let answers = new Map();
|
|
46
|
+
let text = '';
|
|
47
|
+
while(true){
|
|
48
|
+
let pending = new Set();
|
|
49
|
+
let asking = new Set();
|
|
50
|
+
let loading = new Set();
|
|
51
|
+
try {
|
|
52
|
+
text = printed(views, vocab, answer, named, page, {
|
|
53
|
+
answers,
|
|
54
|
+
eid: (eid)=>eid && !known.has(eid) && pending.add(eid),
|
|
55
|
+
query: (q)=>asking.add(q),
|
|
56
|
+
deferred: (r)=>loading.add(r)
|
|
57
|
+
});
|
|
58
|
+
} catch (error) {
|
|
59
|
+
// A drawing may require a declared or newly-read dependency before
|
|
60
|
+
// it can finish. Retry after those reads; failures without new reads
|
|
61
|
+
// remain drawing errors, including required references that are gone.
|
|
62
|
+
if (!pending.size && !loading.size && !asking.size) throw error;
|
|
63
|
+
}
|
|
64
|
+
if (!pending.size && !loading.size && !asking.size) break;
|
|
65
|
+
let ids = [
|
|
66
|
+
...pending
|
|
67
|
+
];
|
|
68
|
+
ids.forEach((id)=>known.add(id));
|
|
69
|
+
let [ready, found, said] = await Promise.all([
|
|
70
|
+
loading.size ? prepared(views, [
|
|
71
|
+
...loading
|
|
72
|
+
]) : views,
|
|
73
|
+
ids.length ? from.lookup(ids) : [],
|
|
74
|
+
Promise.all([
|
|
75
|
+
...asking
|
|
76
|
+
].map(async (q)=>// A renderer's declared query, as its author wrote it.
|
|
77
|
+
[
|
|
78
|
+
q,
|
|
79
|
+
await Promise.resolve(from.query(whole(q))).catch(()=>[])
|
|
80
|
+
]))
|
|
81
|
+
]);
|
|
82
|
+
views = ready;
|
|
83
|
+
named.push(...found);
|
|
84
|
+
found.forEach((b)=>known.add(b.entity.eid));
|
|
85
|
+
said.forEach(([q, rows])=>answers.set(q, rows));
|
|
86
|
+
}
|
|
87
|
+
if (present) return await present(views, answer, named, page, answers);
|
|
88
|
+
if (text) {
|
|
89
|
+
if (c.tty) c.tty.write(text);
|
|
90
|
+
else c.out(text);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=terminal.js.map
|
package/terminal.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.js","sources":["./terminal.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8BAA8B;AAE9B,SAAS,KAAK,2BAAgC;AAC9C,SAAS,QAAQ,4BAA+D;AAEhF,SAIE,MAAM,EACN,SAAS,EACT,IAAI,EACJ,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EAEV,QAAQ,EAER,MAAM,sBACY;AAWpB,IAAI,OAAe;EAAE,QAAQ,IAAM,EAAE;EAAE,OAAO,IAAM,EAAE;AAAC;AAEvD;;;oDAGoD,GACpD,OAAO,IAAI,OAAO,OAChB,GACA,OACA,OACA,MACA,OAA0C,CAAC,CAAC,EAC5C,OAAe,IAAI,EACnB,OAAc;EAAE,UAAU;AAAK,CAAC,EAChC;EAEA,IAAI,SAAS,KAAK,QAAQ,GAAG,OAAO,MAAM,SAAS,MAAM;EACzD,uE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,KAAK,CAAC;SAClB,EAAE,GAAG,CAAC;EACb;AACF,EAAC"}
|
package/terminal.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Portable answer preparation and text output. The CLI supplies its terminal
|
|
2
|
+
// presentation from ./tty.ts.
|
|
3
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
4
|
+
import { whole } from '@yaks/query'
|
|
5
|
+
import { prepared, type Registry, type Renderer } from '@yaks/render'
|
|
6
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36/runtime'
|
|
7
|
+
import {
|
|
8
|
+
type Drawn,
|
|
9
|
+
type Held,
|
|
10
|
+
type Near,
|
|
11
|
+
nearOf,
|
|
12
|
+
nearQuery,
|
|
13
|
+
NONE,
|
|
14
|
+
nothing,
|
|
15
|
+
parted,
|
|
16
|
+
printed,
|
|
17
|
+
referenced,
|
|
18
|
+
type Source,
|
|
19
|
+
standing,
|
|
20
|
+
type Tty,
|
|
21
|
+
viewOf,
|
|
22
|
+
} from './answer.js'
|
|
23
|
+
|
|
24
|
+
/** A prepared answer, handed to the caller's presentation boundary. */
|
|
25
|
+
export type Presentation = (
|
|
26
|
+
views: Registry,
|
|
27
|
+
answer: Bundle[],
|
|
28
|
+
named: Bundle[],
|
|
29
|
+
page: Near | undefined,
|
|
30
|
+
answers: ReadonlyMap<string, Bundle[]>,
|
|
31
|
+
) => void | Promise<void>
|
|
32
|
+
|
|
33
|
+
let none: Source = { lookup: () => [], query: () => [] }
|
|
34
|
+
|
|
35
|
+
/** Prepare an answer's views and the references and queries they read, then
|
|
36
|
+
* present it through `present`, or print its portable text. A tool that wrote
|
|
37
|
+
* draws its answer as it now stands, and a page draws a lone entity whole,
|
|
38
|
+
* beside the links and comments its page asks for. */
|
|
39
|
+
export let show = async (
|
|
40
|
+
c: { tui: boolean; tty?: Tty; out: (line: string) => void },
|
|
41
|
+
views: Registry,
|
|
42
|
+
vocab: Vocab,
|
|
43
|
+
said: Bundle[],
|
|
44
|
+
held: { views?: Held; config?: string } = {},
|
|
45
|
+
from: Source = none,
|
|
46
|
+
tool: Drawn = { readOnly: true },
|
|
47
|
+
present?: Presentation,
|
|
48
|
+
): Promise<void> => {
|
|
49
|
+
let answer = tool.readOnly ? said : await standing(said, from)
|
|
50
|
+
// A read that found nothing says so: a blank answer reads as a command
|
|
51
|
+
// that did nothing, or one still working.
|
|
52
|
+
if (tool.readOnly && !answer.length && !c.tui) {
|
|
53
|
+
return c.tty ? c.tty.write(NONE) : c.out(NONE)
|
|
54
|
+
}
|
|
55
|
+
let them = parted(answer).them
|
|
56
|
+
let lone = viewOf(them, !!tool.page) == 'Page' ? them[0] : undefined
|
|
57
|
+
let asked = lone ? nearQuery(vocab, lone.entity.eid) : null
|
|
58
|
+
let page = !lone
|
|
59
|
+
? undefined
|
|
60
|
+
: asked
|
|
61
|
+
? nearOf(lone.entity.eid, await from.query(asked))
|
|
62
|
+
: nothing
|
|
63
|
+
let near = page ?? nothing
|
|
64
|
+
// Portable renderers are pure. Discover the references and queries the
|
|
65
|
+
// drawing reads, including nested views and declared needs, rather than
|
|
66
|
+
// fetching every reference carried by a bundle that a tile never shows. A
|
|
67
|
+
// terminal paints with what the printout read, and the references its
|
|
68
|
+
// components may read beside it.
|
|
69
|
+
let known = new Set(
|
|
70
|
+
[...answer, ...near.links, ...near.comments].map((b) => b.entity.eid),
|
|
71
|
+
)
|
|
72
|
+
let painting = c.tui || c.tty
|
|
73
|
+
let refs = painting
|
|
74
|
+
? referenced(
|
|
75
|
+
vocab,
|
|
76
|
+
[...answer, ...near.links, ...near.comments],
|
|
77
|
+
held.views ?? views,
|
|
78
|
+
lone?.entity.eid,
|
|
79
|
+
)
|
|
80
|
+
: []
|
|
81
|
+
let named: Bundle[] = refs.length ? await from.lookup(refs) : []
|
|
82
|
+
named.forEach((b) => known.add(b.entity.eid))
|
|
83
|
+
let answers = new Map<string, Bundle[]>()
|
|
84
|
+
let text = ''
|
|
85
|
+
while (true) {
|
|
86
|
+
let pending = new Set<string>()
|
|
87
|
+
let asking = new Set<string>()
|
|
88
|
+
let loading = new Set<Renderer>()
|
|
89
|
+
try {
|
|
90
|
+
text = printed(views, vocab, answer, named, page, {
|
|
91
|
+
answers,
|
|
92
|
+
eid: (eid) => eid && !known.has(eid) && pending.add(eid),
|
|
93
|
+
query: (q) => asking.add(q),
|
|
94
|
+
deferred: (r) => loading.add(r),
|
|
95
|
+
})
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// A drawing may require a declared or newly-read dependency before
|
|
98
|
+
// it can finish. Retry after those reads; failures without new reads
|
|
99
|
+
// remain drawing errors, including required references that are gone.
|
|
100
|
+
if (!pending.size && !loading.size && !asking.size) throw error
|
|
101
|
+
}
|
|
102
|
+
if (!pending.size && !loading.size && !asking.size) break
|
|
103
|
+
let ids = [...pending]
|
|
104
|
+
ids.forEach((id) => known.add(id))
|
|
105
|
+
let [ready, found, said] = await Promise.all([
|
|
106
|
+
loading.size ? prepared(views, [...loading]) : views,
|
|
107
|
+
ids.length ? from.lookup(ids) : [],
|
|
108
|
+
Promise.all(
|
|
109
|
+
[...asking].map(async (q) =>
|
|
110
|
+
// A renderer's declared query, as its author wrote it.
|
|
111
|
+
[
|
|
112
|
+
q,
|
|
113
|
+
await Promise.resolve(from.query(whole(q))).catch(() => []),
|
|
114
|
+
] as const
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
])
|
|
118
|
+
views = ready
|
|
119
|
+
named.push(...found)
|
|
120
|
+
found.forEach((b) => known.add(b.entity.eid))
|
|
121
|
+
said.forEach(([q, rows]) => answers.set(q, rows))
|
|
122
|
+
}
|
|
123
|
+
if (present) return await present(views, answer, named, page, answers)
|
|
124
|
+
if (text) {
|
|
125
|
+
if (c.tty) c.tty.write(text)
|
|
126
|
+
else c.out(text)
|
|
127
|
+
}
|
|
128
|
+
}
|
package/text.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Plain tool answers, shared by the CLI and HTTP consumers of a host.
|
|
2
|
+
import { registry } from "./answer.js";
|
|
3
|
+
import { show } from "./terminal.js";
|
|
4
|
+
import { pluginViews, used } from "./config.js";
|
|
5
|
+
export let text = (host)=>{
|
|
6
|
+
let views;
|
|
7
|
+
return async (answer, tool, on)=>{
|
|
8
|
+
views ??= registry((host.config.plugins ?? []).map(used), pluginViews, host.observe);
|
|
9
|
+
let lines = [];
|
|
10
|
+
await show({
|
|
11
|
+
tui: false,
|
|
12
|
+
out: (line)=>lines.push(line)
|
|
13
|
+
}, await views, host.vocab, answer, {}, {
|
|
14
|
+
lookup: (ids)=>host.graph.get(ids, undefined, on),
|
|
15
|
+
query: (q)=>host.graph.read(q, on)
|
|
16
|
+
}, tool);
|
|
17
|
+
return lines.join('\n');
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=text.js.map
|
package/text.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sources":["./text.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAGtE,SAAqB,QAAQ,sBAAqB;AAClD,SAAS,IAAI,wBAAuB;AACpC,SAAS,WAAW,EAAE,IAAI,sBAAqB;AAE/C,OAAO,IAAI,OAAO,CAChB;EAEA,IAAI;EACJ,OAAO,OACL,QACA,MACA;IAEA,UAAU,SACR,CAAC,KAAK,MAAM,CAAC,OAAO,IAAI,EAAE,EAAE,GAAG,CAAC,OAChC,aACA,KAAK,OAAO;IAEd,IAAI,QAAkB,EAAE;IACxB,MAAM,KACJ;MAAE,KAAK;MAAO,KAAK,CAAC,OAAS,MAAM,IAAI,CAAC;IAAM,GAC9C,MAAM,OACN,KAAK,KAAK,EACV,QACA,CAAC,GACD;MACE,QAAQ,CAAC,MAAQ,KAAK,KAAK,CAAC,GAAG,CAAC,KAAK,WAAW;MAChD,OAAO,CAAC,IAAM,KAAK,KAAK,CAAC,IAAI,CAAC,GAAG;IACnC,GACA;IAEF,OAAO,MAAM,IAAI,CAAC;EACpB;AACF,EAAC"}
|
package/text.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Plain tool answers, shared by the CLI and HTTP consumers of a host.
|
|
2
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
3
|
+
import type { Host } from 'jsr:@yaks/host@0.2.36'
|
|
4
|
+
import { type Drawn, registry } from './answer.js'
|
|
5
|
+
import { show } from './terminal.js'
|
|
6
|
+
import { pluginViews, used } from './config.js'
|
|
7
|
+
|
|
8
|
+
export let text = (
|
|
9
|
+
host: Pick<Host, 'config' | 'graph' | 'vocab' | 'observe'>,
|
|
10
|
+
) => {
|
|
11
|
+
let views: ReturnType<typeof registry> | undefined
|
|
12
|
+
return async (
|
|
13
|
+
answer: Bundle[],
|
|
14
|
+
tool?: Drawn,
|
|
15
|
+
on?: { branch?: number },
|
|
16
|
+
): Promise<string> => {
|
|
17
|
+
views ??= registry(
|
|
18
|
+
(host.config.plugins ?? []).map(used),
|
|
19
|
+
pluginViews,
|
|
20
|
+
host.observe,
|
|
21
|
+
)
|
|
22
|
+
let lines: string[] = []
|
|
23
|
+
await show(
|
|
24
|
+
{ tui: false, out: (line) => lines.push(line) },
|
|
25
|
+
await views,
|
|
26
|
+
host.vocab,
|
|
27
|
+
answer,
|
|
28
|
+
{},
|
|
29
|
+
{
|
|
30
|
+
lookup: (ids) => host.graph.get(ids, undefined, on),
|
|
31
|
+
query: (q) => host.graph.read(q, on),
|
|
32
|
+
},
|
|
33
|
+
tool,
|
|
34
|
+
)
|
|
35
|
+
return lines.join('\n')
|
|
36
|
+
}
|
|
37
|
+
}
|
package/tool.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// What a tool an MCP server lists looks like to this client: the two fields
|
|
2
|
+
// `tools/list` always carries, the input schema it publishes, and nothing
|
|
3
|
+
// about what the tool does. A `Listed` is not yet something to run —
|
|
4
|
+
// platform.ts is what turns one into a @yaks/graph `Tool` whose `run` makes
|
|
5
|
+
// the call — but the argument parser (args.ts), the help pages (show.ts) and
|
|
6
|
+
// the cache (store.ts) read both shapes through the types here, so a field the
|
|
7
|
+
// server adds costs nothing to carry and a field it drops is a type error in
|
|
8
|
+
// one place.
|
|
9
|
+
/** One property of an input schema, as much of it as this client reads:
|
|
10
|
+
* enough to decide how the argument on the command line becomes a value. */ /** The `_meta` key the command-line grammar is sent under (@yaks/mcp
|
|
11
|
+
* `COMMAND`). Written out here rather than imported: a client reading a
|
|
12
|
+
* listing should not have to depend on the server that wrote it. */ export let COMMAND = 'yak.sh/command';
|
|
13
|
+
/**
|
|
14
|
+
* The two words a tool is typed as, and how its arguments are written — what
|
|
15
|
+
* the tool declared, carried through `tools/list` in `_meta`. A listing
|
|
16
|
+
* without it is a tool with one flat name, which is what every other MCP
|
|
17
|
+
* server sends.
|
|
18
|
+
*/ export let spelling = (t)=>{
|
|
19
|
+
let said = t._meta?.[COMMAND];
|
|
20
|
+
let positional = said?.positional;
|
|
21
|
+
if (!positional && said?.options) {
|
|
22
|
+
let { positional: names = [], rest } = said.options;
|
|
23
|
+
positional = [
|
|
24
|
+
...names.filter((n)=>n != rest),
|
|
25
|
+
...rest ? [
|
|
26
|
+
rest + '...'
|
|
27
|
+
] : []
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
let inputSchema = t.inputSchema;
|
|
31
|
+
let hints = said?.input ?? Object.fromEntries(Object.entries(said?.options?.short ?? {}).map(([short, name])=>[
|
|
32
|
+
name,
|
|
33
|
+
{
|
|
34
|
+
short
|
|
35
|
+
}
|
|
36
|
+
]));
|
|
37
|
+
if (inputSchema?.properties && Object.keys(hints).length) {
|
|
38
|
+
inputSchema = {
|
|
39
|
+
...inputSchema,
|
|
40
|
+
properties: Object.fromEntries(Object.entries(inputSchema.properties).map(([name, p])=>[
|
|
41
|
+
name,
|
|
42
|
+
{
|
|
43
|
+
...p,
|
|
44
|
+
...hints[name]
|
|
45
|
+
}
|
|
46
|
+
]))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
noun: said?.noun,
|
|
51
|
+
verb: said?.verb,
|
|
52
|
+
positional,
|
|
53
|
+
forward: said?.forward ?? said?.options?.forward,
|
|
54
|
+
inputSchema,
|
|
55
|
+
page: said?.page === true
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/** The short label a listing shows beside a tool's name: its title, or the
|
|
59
|
+
* first sentence of its description. */ export let titleOf = (t)=>{
|
|
60
|
+
let said = t.title ?? t.annotations?.title;
|
|
61
|
+
if (said) return said;
|
|
62
|
+
let first = (t.description ?? '').split(/(?<=\.)\s/)[0];
|
|
63
|
+
return first.trim();
|
|
64
|
+
};
|
|
65
|
+
/** The type a value should be converted to, as one word. A schema naming
|
|
66
|
+
* several (`['string', 'null']`) is read as the first that is not `null`. */ export let typeOf = (p)=>{
|
|
67
|
+
let said = p?.type;
|
|
68
|
+
if (Array.isArray(said)) return said.find((t)=>t != 'null') ?? 'string';
|
|
69
|
+
return said ?? 'string';
|
|
70
|
+
};
|
|
71
|
+
/** What a person types to name a tool: its two words where it has them, the
|
|
72
|
+
* one word where it declared a noun or a verb alone, its name otherwise.
|
|
73
|
+
* `toolName` (@yaks/graph) answers the same question for MCP, which writes a
|
|
74
|
+
* pair as `noun_verb`; a command line can afford a space, and a single word is
|
|
75
|
+
* the same word in both places. */ export let commandOf = (t)=>t.noun && t.verb ? `${t.noun} ${t.verb}` : t.noun ?? t.verb ?? t.name ?? '';
|
|
76
|
+
//# sourceMappingURL=tool.js.map
|
package/tool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sources":["./tool.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,qEAAqE;AACrE,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,aAAa;AAEb;0EAC0E,GAmD1E;;kEAEkE,GAClE,OAAO,IAAI,UAAU,iBAAgB;AAErC;;;;;CAKC,GACD,OAAO,IA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ACd,IAAI,MAAM,OAAO,CAAC,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,IAAM,KAAK,WAAW;EACjE,OAAO,QAAQ;AACjB,EAAC;AAED;;;;iCAIiC,GACjC,OAAO,IAAI,YAAY,CACrB,IAEA,EAAE,IAAI,IAAI,EAAE,IAAI,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,IAAI,IAAI,EAAE,IAAI,IAAI,GAAE"}
|
package/tool.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// What a tool an MCP server lists looks like to this client: the two fields
|
|
2
|
+
// `tools/list` always carries, the input schema it publishes, and nothing
|
|
3
|
+
// about what the tool does. A `Listed` is not yet something to run —
|
|
4
|
+
// platform.ts is what turns one into a @yaks/graph `Tool` whose `run` makes
|
|
5
|
+
// the call — but the argument parser (args.ts), the help pages (show.ts) and
|
|
6
|
+
// the cache (store.ts) read both shapes through the types here, so a field the
|
|
7
|
+
// server adds costs nothing to carry and a field it drops is a type error in
|
|
8
|
+
// one place.
|
|
9
|
+
|
|
10
|
+
/** One property of an input schema, as much of it as this client reads:
|
|
11
|
+
* enough to decide how the argument on the command line becomes a value. */
|
|
12
|
+
export type Prop = {
|
|
13
|
+
type?: string | string[]
|
|
14
|
+
short?: string
|
|
15
|
+
description?: string
|
|
16
|
+
enum?: unknown[]
|
|
17
|
+
items?: Prop
|
|
18
|
+
default?: unknown
|
|
19
|
+
/** standard JSON Schema, and what tab completion offers when nothing else
|
|
20
|
+
* narrows the argument (@yaks/vocab: a text property's examples are unioned
|
|
21
|
+
* with its own stored values) */
|
|
22
|
+
examples?: unknown[]
|
|
23
|
+
/** the component whose entities this argument names — where tab completion
|
|
24
|
+
* reads ids from */
|
|
25
|
+
ref?: string
|
|
26
|
+
/** true = this text is full-text indexed, so tab completion asks the
|
|
27
|
+
* index */
|
|
28
|
+
search?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A tool's input schema — an object schema, or nothing when it takes no
|
|
32
|
+
* arguments. */
|
|
33
|
+
export type Schema = {
|
|
34
|
+
type?: string
|
|
35
|
+
properties?: Record<string, Prop>
|
|
36
|
+
required?: string[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How a tool's arguments are written on a command line: which bare words
|
|
40
|
+
* fill which properties, and which single letters it accepts. */
|
|
41
|
+
export type Spelling = {
|
|
42
|
+
positional?: readonly string[]
|
|
43
|
+
forward?: string
|
|
44
|
+
input?: Record<string, { short?: string }>
|
|
45
|
+
/** a lone entity it answers is drawn whole (@yaks/vocab `page`) */
|
|
46
|
+
page?: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A tool as an MCP server lists it. */
|
|
50
|
+
export type Listed = {
|
|
51
|
+
name: string
|
|
52
|
+
title?: string
|
|
53
|
+
description?: string
|
|
54
|
+
inputSchema?: Schema
|
|
55
|
+
outputSchema?: Schema
|
|
56
|
+
annotations?: { title?: string; readOnlyHint?: boolean }
|
|
57
|
+
/** what MCP carries beside the schemas — where a tool's two words and its
|
|
58
|
+
* command-line argument layout are sent (see {@link spelling}) */
|
|
59
|
+
_meta?: Record<string, unknown>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The `_meta` key the command-line grammar is sent under (@yaks/mcp
|
|
63
|
+
* `COMMAND`). Written out here rather than imported: a client reading a
|
|
64
|
+
* listing should not have to depend on the server that wrote it. */
|
|
65
|
+
export let COMMAND = 'yak.sh/command'
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The two words a tool is typed as, and how its arguments are written — what
|
|
69
|
+
* the tool declared, carried through `tools/list` in `_meta`. A listing
|
|
70
|
+
* without it is a tool with one flat name, which is what every other MCP
|
|
71
|
+
* server sends.
|
|
72
|
+
*/
|
|
73
|
+
export let spelling = (
|
|
74
|
+
t: Listed,
|
|
75
|
+
): {
|
|
76
|
+
noun?: string
|
|
77
|
+
verb?: string
|
|
78
|
+
positional?: readonly string[]
|
|
79
|
+
forward?: string
|
|
80
|
+
inputSchema?: Schema
|
|
81
|
+
page: boolean
|
|
82
|
+
} => {
|
|
83
|
+
let said = t._meta?.[COMMAND] as
|
|
84
|
+
| (Spelling & {
|
|
85
|
+
noun?: string
|
|
86
|
+
verb?: string
|
|
87
|
+
// Listings from a server running the previous vocabulary format.
|
|
88
|
+
options?: {
|
|
89
|
+
positional?: readonly string[]
|
|
90
|
+
rest?: string
|
|
91
|
+
forward?: string
|
|
92
|
+
short?: Record<string, string>
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
| undefined
|
|
96
|
+
let positional = said?.positional
|
|
97
|
+
if (!positional && said?.options) {
|
|
98
|
+
let { positional: names = [], rest } = said.options
|
|
99
|
+
positional = [
|
|
100
|
+
...names.filter((n) => n != rest),
|
|
101
|
+
...rest ? [rest + '...'] : [],
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
let inputSchema = t.inputSchema
|
|
105
|
+
let hints = said?.input ?? Object.fromEntries(
|
|
106
|
+
Object.entries(said?.options?.short ?? {}).map((
|
|
107
|
+
[short, name],
|
|
108
|
+
) => [name, { short }]),
|
|
109
|
+
)
|
|
110
|
+
if (inputSchema?.properties && Object.keys(hints).length) {
|
|
111
|
+
inputSchema = {
|
|
112
|
+
...inputSchema,
|
|
113
|
+
properties: Object.fromEntries(
|
|
114
|
+
Object.entries(inputSchema.properties).map((
|
|
115
|
+
[name, p],
|
|
116
|
+
) => [name, { ...p, ...hints[name] }]),
|
|
117
|
+
),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
noun: said?.noun,
|
|
122
|
+
verb: said?.verb,
|
|
123
|
+
positional,
|
|
124
|
+
forward: said?.forward ?? said?.options?.forward,
|
|
125
|
+
inputSchema,
|
|
126
|
+
page: said?.page === true,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The short label a listing shows beside a tool's name: its title, or the
|
|
131
|
+
* first sentence of its description. */
|
|
132
|
+
export let titleOf = (
|
|
133
|
+
t: { title?: string; description?: string; annotations?: { title?: string } },
|
|
134
|
+
): string => {
|
|
135
|
+
let said = t.title ?? t.annotations?.title
|
|
136
|
+
if (said) return said
|
|
137
|
+
let first = (t.description ?? '').split(/(?<=\.)\s/)[0]
|
|
138
|
+
return first.trim()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The type a value should be converted to, as one word. A schema naming
|
|
142
|
+
* several (`['string', 'null']`) is read as the first that is not `null`. */
|
|
143
|
+
export let typeOf = (p: Prop | undefined): string => {
|
|
144
|
+
let said = p?.type
|
|
145
|
+
if (Array.isArray(said)) return said.find((t) => t != 'null') ?? 'string'
|
|
146
|
+
return said ?? 'string'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** What a person types to name a tool: its two words where it has them, the
|
|
150
|
+
* one word where it declared a noun or a verb alone, its name otherwise.
|
|
151
|
+
* `toolName` (@yaks/graph) answers the same question for MCP, which writes a
|
|
152
|
+
* pair as `noun_verb`; a command line can afford a space, and a single word is
|
|
153
|
+
* the same word in both places. */
|
|
154
|
+
export let commandOf = (
|
|
155
|
+
t: { name?: string; noun?: string; verb?: string },
|
|
156
|
+
): string =>
|
|
157
|
+
t.noun && t.verb ? `${t.noun} ${t.verb}` : t.noun ?? t.verb ?? t.name ?? ''
|