@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/complete.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Tab completion: what could come next on the command line, read off the same
|
|
2
|
+
// schema that runs it.
|
|
3
|
+
//
|
|
4
|
+
// Nothing here declares anything a second time. The subcommand names are the
|
|
5
|
+
// tools' nouns and verbs, the options are their input schemas' properties, and
|
|
6
|
+
// what a value may be is whatever the property declares about itself — an
|
|
7
|
+
// `enum` offers its members, a boolean offers true and false, `examples` offer
|
|
8
|
+
// themselves. The two that need the graph — `ref`, which names a component,
|
|
9
|
+
// and `search`, which marks full-text indexed text — are delegated to the
|
|
10
|
+
// caller, because a command-line client has no graph and should not grow one.
|
|
11
|
+
//
|
|
12
|
+
// complete(tools, 'session li') → ['list']
|
|
13
|
+
// complete(tools, 'session list --') → ['--all', '--limit', '--scope']
|
|
14
|
+
// complete(tools, 'session list --status ') → ['done', 'open']
|
|
15
|
+
//
|
|
16
|
+
// A shell's completion hook passes its words; the harness's `:` prompt passes
|
|
17
|
+
// the whole line. Both are the same question, so both go through this one
|
|
18
|
+
// function.
|
|
19
|
+
|
|
20
|
+
import { commandOf, type Prop, type Schema, typeOf } from './tool.js'
|
|
21
|
+
import {
|
|
22
|
+
clearable,
|
|
23
|
+
commandFor,
|
|
24
|
+
type Grammar,
|
|
25
|
+
scanned,
|
|
26
|
+
tokensIn,
|
|
27
|
+
} from './args.js'
|
|
28
|
+
|
|
29
|
+
/** The two answers only a graph can give. Left out, a `ref` or a full-text
|
|
30
|
+
* argument simply offers nothing, which is all a client with no connection
|
|
31
|
+
* knows. */
|
|
32
|
+
export type Lookup = {
|
|
33
|
+
/** the entities carrying `comp`, as the ids a person would type */
|
|
34
|
+
ids?: (comp: string, prefix: string) => string[] | Promise<string[]>
|
|
35
|
+
/** what the full-text index finds for a partial word */
|
|
36
|
+
hits?: (prefix: string) => string[] | Promise<string[]>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Split the line into the words completion is about: the last one is the word
|
|
40
|
+
// being typed, empty where the line ended in a space. An argv array (a shell
|
|
41
|
+
// hook's COMP_WORDS) is already in that form.
|
|
42
|
+
let wordsIn = (line: string | readonly string[]): string[] =>
|
|
43
|
+
typeof line == 'string' ? tokensIn(line, true).map((w) => w.value) : [...line]
|
|
44
|
+
|
|
45
|
+
/** Quote a replacement word so parsing it yields the offered value. Shell
|
|
46
|
+
* argv callers already own quoting and receive raw values instead. */
|
|
47
|
+
export let quoted = (word: string): string => {
|
|
48
|
+
let eq = word.startsWith('--') ? word.indexOf('=') : -1
|
|
49
|
+
if (eq >= 0) return word.slice(0, eq + 1) + quoted(word.slice(eq + 1))
|
|
50
|
+
return /[\s"'\\]/.test(word) || !word
|
|
51
|
+
? '"' + word.replace(/[\\"]/g, '\\$&') + '"'
|
|
52
|
+
: word
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let props = (t: Grammar): Record<string, Prop> =>
|
|
56
|
+
((t.inputSchema ?? {}) as Schema).properties ?? {}
|
|
57
|
+
|
|
58
|
+
// Every word a tool answers to as its first: a two-word tool answers to both
|
|
59
|
+
// of its words, because the two may be typed in either order.
|
|
60
|
+
let firsts = (tools: readonly Grammar[]): string[] =>
|
|
61
|
+
tools.flatMap((t) => t.noun && t.verb ? [t.noun, t.verb] : [commandOf(t)])
|
|
62
|
+
|
|
63
|
+
// The other word of a pair, given one of them.
|
|
64
|
+
let seconds = (tools: readonly Grammar[], said: string): string[] =>
|
|
65
|
+
tools.flatMap((t) =>
|
|
66
|
+
!t.noun || !t.verb
|
|
67
|
+
? []
|
|
68
|
+
: t.noun == said
|
|
69
|
+
? [t.verb]
|
|
70
|
+
: t.verb == said
|
|
71
|
+
? [t.noun]
|
|
72
|
+
: []
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
// What one argument's value may be. Everything but the last two sources is in
|
|
76
|
+
// the schema itself.
|
|
77
|
+
let values = async (
|
|
78
|
+
p: Prop | undefined,
|
|
79
|
+
partial: string,
|
|
80
|
+
look: Lookup,
|
|
81
|
+
): Promise<string[]> => {
|
|
82
|
+
if (!p) return []
|
|
83
|
+
if (p.enum) return p.enum.map(String)
|
|
84
|
+
if (typeOf(p) == 'boolean') return ['true', 'false']
|
|
85
|
+
let said = (p.examples ?? []).map(String)
|
|
86
|
+
if (p.ref && look.ids) said.push(...await look.ids(p.ref, partial))
|
|
87
|
+
if (p.search && look.hits) said.push(...await look.hits(partial))
|
|
88
|
+
return said
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let kept = (said: string[], partial: string): string[] =>
|
|
92
|
+
[...new Set(said)].filter((w) =>
|
|
93
|
+
w.toLowerCase().startsWith(partial.toLowerCase())
|
|
94
|
+
).sort()
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* What could come next, given the tools and the line so far. Each result is a
|
|
98
|
+
* whole word, never the remaining characters — a shell hook and the harness's
|
|
99
|
+
* `:` prompt both replace the word being typed.
|
|
100
|
+
*/
|
|
101
|
+
export let complete = async (
|
|
102
|
+
tools: readonly Grammar[],
|
|
103
|
+
line: string | readonly string[],
|
|
104
|
+
look: Lookup = {},
|
|
105
|
+
): Promise<string[]> => {
|
|
106
|
+
let words = wordsIn(line)
|
|
107
|
+
let partial = words.at(-1) ?? ''
|
|
108
|
+
let head = words.slice(0, -1)
|
|
109
|
+
if (!head.length) return kept(firsts(tools), partial)
|
|
110
|
+
let found = commandFor(tools, head)
|
|
111
|
+
// One word in and no tool matched: it must be half of a two-word pair, and
|
|
112
|
+
// what may follow it is the other half.
|
|
113
|
+
if (!found) {
|
|
114
|
+
return head.length == 1 ? kept(seconds(tools, head[0]), partial) : []
|
|
115
|
+
}
|
|
116
|
+
let t = found.verb
|
|
117
|
+
let names = Object.keys(props(t))
|
|
118
|
+
let clearing = clearable(t)
|
|
119
|
+
if (clearing.length) names.push('clear')
|
|
120
|
+
let state
|
|
121
|
+
try {
|
|
122
|
+
state = scanned(t, found.args, true)
|
|
123
|
+
} catch {
|
|
124
|
+
return []
|
|
125
|
+
}
|
|
126
|
+
let emit = (said: string[]) =>
|
|
127
|
+
typeof line == 'string' ? said.map(quoted) : said
|
|
128
|
+
if (!state.literal && partial.startsWith('--')) {
|
|
129
|
+
if (state.pending) return []
|
|
130
|
+
let [name, ...rest] = partial.slice(2).split('=')
|
|
131
|
+
// `--name=` introduces a value, in the one form that accepts a value
|
|
132
|
+
// beginning with a dash.
|
|
133
|
+
if (rest.length) {
|
|
134
|
+
let said = name == 'clear' && clearing.length
|
|
135
|
+
? clearing
|
|
136
|
+
: await values(props(t)[name], rest.join('='), look)
|
|
137
|
+
return emit(kept(said.map((v) => `--${name}=${v}`), partial))
|
|
138
|
+
}
|
|
139
|
+
return kept(
|
|
140
|
+
names.filter((n) => !state.given.has(n)).map((n) => `--${n}`),
|
|
141
|
+
partial,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
return emit(
|
|
145
|
+
kept(
|
|
146
|
+
state.awaiting == 'clear' && clearing.length
|
|
147
|
+
? clearing
|
|
148
|
+
: await values(props(t)[state.awaiting ?? ''], partial, look),
|
|
149
|
+
partial,
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
}
|
package/config.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as system from "@yaks/process/system";
|
|
2
|
+
import * as disk from "@yaks/file/io";
|
|
3
|
+
// The config file, read. It is the one statement of where a graph IS: the
|
|
4
|
+
// SQLite file, the plugins that read and write it, and how the host behaves.
|
|
5
|
+
//
|
|
6
|
+
// A config file names a graph, not a server. `yak --config yak.json task list`
|
|
7
|
+
// opens that file, imports those plugins and runs the tool in this process —
|
|
8
|
+
// SQLite in WAL mode accepts as many writers as there are `yak` commands
|
|
9
|
+
// running, so nothing has to be listening for a command line to work.
|
|
10
|
+
// `yak serve` is one more process over the same file, the one that serves HTTP
|
|
11
|
+
// requests — and `serve` is a tool like any other, contributed by @yaks/api.
|
|
12
|
+
//
|
|
13
|
+
// That is why this is its own module. A command that only needs to know where
|
|
14
|
+
// the graph is must not import host.ts, which pulls in every plugin a config
|
|
15
|
+
// names — a cost `yak login` should not pay. So the config is read here, by a
|
|
16
|
+
// module that opens no graph.
|
|
17
|
+
import { runtimePath } from "./runtime.js";
|
|
18
|
+
/** Where a machine keeps the config for its own graph. */ export let OWN_CONFIG = '.yak/yak.json';
|
|
19
|
+
/** The person who works at this machine, as the entity the config's `person`
|
|
20
|
+
* names, or nobody where it names none: a machine never guesses who is at its
|
|
21
|
+
* keyboard. What they type at it is written by them. */ export let person = async (host)=>{
|
|
22
|
+
let said = host.config.person;
|
|
23
|
+
return said ? (await host.graph.address([
|
|
24
|
+
said
|
|
25
|
+
])).get(said) ?? said : undefined;
|
|
26
|
+
};
|
|
27
|
+
/** Where this machine keeps the config for its own graph, whether or not it
|
|
28
|
+
* has one yet: under `$HOME`, or nowhere for a process that has none. */ export let ownConfig = (env = system.env.get)=>{
|
|
29
|
+
let home = env('HOME');
|
|
30
|
+
return home ? `${home}/${OWN_CONFIG}` : undefined;
|
|
31
|
+
};
|
|
32
|
+
/** The config a command opens: the path it was given, else `$YAK_CONFIG`,
|
|
33
|
+
* else the one this machine keeps for its own graph. A machine that has a
|
|
34
|
+
* graph is the ordinary case, so a bare `yak task list` there reads from it
|
|
35
|
+
* rather than reaching for a remote server it was never told about. No file
|
|
36
|
+
* there means no config. */ export let configPath = (said, env = system.env.get)=>{
|
|
37
|
+
let named = said ?? env('YAK_CONFIG');
|
|
38
|
+
if (named) return named;
|
|
39
|
+
let own = ownConfig(env);
|
|
40
|
+
if (!own) return undefined;
|
|
41
|
+
// The command may be running without read permission at all; that is no
|
|
42
|
+
// config.
|
|
43
|
+
try {
|
|
44
|
+
return disk.statSync(own).isFile ? own : undefined;
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// A specifier belonging to the config file — `./plugins/mail`, `/srv/mail` —
|
|
50
|
+
// is resolved against the config, so a config file is movable and a bare
|
|
51
|
+
// `@yaks/…` is left to the import map. It names a package, never a file: a
|
|
52
|
+
// plugin's modules are its subpaths, and only a package has those.
|
|
53
|
+
let near = (spec, base)=>runtimePath(spec.startsWith('.') || spec.startsWith('/') ? new URL(spec, base).href : spec);
|
|
54
|
+
export { given, used } from "@yaks/host/config";
|
|
55
|
+
export { exported, located, pluginTui, pluginViews, ships, subpath, subpaths, unexported } from "./facets.js";
|
|
56
|
+
let resolved = (plug, base)=>typeof plug == 'string' ? near(plug, base) : {
|
|
57
|
+
...plug,
|
|
58
|
+
use: near(plug.use, base)
|
|
59
|
+
};
|
|
60
|
+
/** Whether the config at `path` names `part`: a command about that part of a
|
|
61
|
+
* config (a box's process plan, its tracker) is offered only where it does.
|
|
62
|
+
* No config, or one that cannot be read, names nothing.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { assertEquals } from '@std/assert'
|
|
66
|
+
* assertEquals(names(undefined, 'processes'), false)
|
|
67
|
+
* ```
|
|
68
|
+
*/ export let names = (path, part)=>{
|
|
69
|
+
if (!path) return false;
|
|
70
|
+
try {
|
|
71
|
+
return read(path)[part] !== undefined;
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Read a config file. Paths inside it — the database, a relative plugin — are
|
|
78
|
+
* resolved against the file itself.
|
|
79
|
+
*/ export let read = (path)=>{
|
|
80
|
+
let base = new URL(path, `file://${system.cwd()}/`);
|
|
81
|
+
let said;
|
|
82
|
+
try {
|
|
83
|
+
said = JSON.parse(disk.readTextFileSync(base));
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new Error(`${path}: ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
if (!said || typeof said != 'object' || Array.isArray(said)) {
|
|
88
|
+
throw new Error(`${path}: a config is a JSON object`);
|
|
89
|
+
}
|
|
90
|
+
let config = said;
|
|
91
|
+
return {
|
|
92
|
+
...config,
|
|
93
|
+
...config.tracker ? {
|
|
94
|
+
tracker: {
|
|
95
|
+
...config.tracker,
|
|
96
|
+
spool: new URL(config.tracker.spool, base).pathname
|
|
97
|
+
}
|
|
98
|
+
} : {},
|
|
99
|
+
db: config.db && config.db != ':memory:' ? new URL(config.db, base).pathname : config.db,
|
|
100
|
+
plugins: (config.plugins ?? []).map((plug)=>resolved(plug, base)),
|
|
101
|
+
...config.sandboxes ? {
|
|
102
|
+
sandboxes: {
|
|
103
|
+
...config.sandboxes,
|
|
104
|
+
providers: Object.fromEntries(Object.entries(config.sandboxes.providers ?? {}).map(([name, provider])=>[
|
|
105
|
+
name,
|
|
106
|
+
'use' in provider ? {
|
|
107
|
+
...provider,
|
|
108
|
+
use: near(provider.use, base)
|
|
109
|
+
} : provider
|
|
110
|
+
]))
|
|
111
|
+
}
|
|
112
|
+
} : {}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
/** The database a config names. `DB_PATH` is the other way to give it, for a
|
|
116
|
+
* service file that would rather set it in the environment. Neither has a
|
|
117
|
+
* default, because the path anybody would pick as one is somebody's live
|
|
118
|
+
* graph. */ export let dbOf = (config, env = (n)=>system.env.get(n))=>{
|
|
119
|
+
let db = config.db ?? env('DB_PATH');
|
|
120
|
+
if (!db) {
|
|
121
|
+
throw new Error('a host needs a database: `db` in the config, or DB_PATH in the ' + 'environment — there is no default');
|
|
122
|
+
}
|
|
123
|
+
return db;
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=config.js.map
|
package/config.js.map
ADDED
|
@@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MAAM,QAAQ,GACjC,OAAO,EAAE;IACb,SAAS,CAAC,OAAO,OAAO,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,OAAS,SAAS,MAAM;IAC7D,GAAG,OAAO,SAAS,GACf;MACA,WAAW;QACT,GAAG,OAAO,SAAS;QACnB,WAAW,OAAO,WAAW,CAC3B,OAAO,OAAO,CAAC,OAAO,SAAS,CAAC,SAAS,IAAI,CAAC,GAAG,GAAG,CAAC,CACnD,CAAC,MAAM,SAAS,GACb;YACH;YACA,SAAS,WACL;cAAE,GAAG,QAAQ;cAAE,KAAK,KAAK,SAAS,GAAG,EAAE;YAAM,IAC7C;WACL;MAEL;IACF,IACE,CAAC,CAAC;EACR;AACF,EAAC;AAED;;;UAGU,GACV,OAAO,IAAI,OAAO,CAChB,QACA,MAA4C,CAAC,IAAM,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE;EAEpE,IAAI,KAAK,OAAO,EAAE,IAAI,IAAI;EAC1B,IAAI,CAAC,IAAI;IACP,MAAM,IAAI,MACR,oEACE;EAEN;EACA,OAAO;AACT,EAAC"}
|
package/config.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as system from '@yaks/process/system'
|
|
2
|
+
import * as disk from '@yaks/file/io'
|
|
3
|
+
// The config file, read. It is the one statement of where a graph IS: the
|
|
4
|
+
// SQLite file, the plugins that read and write it, and how the host behaves.
|
|
5
|
+
//
|
|
6
|
+
// A config file names a graph, not a server. `yak --config yak.json task list`
|
|
7
|
+
// opens that file, imports those plugins and runs the tool in this process —
|
|
8
|
+
// SQLite in WAL mode accepts as many writers as there are `yak` commands
|
|
9
|
+
// running, so nothing has to be listening for a command line to work.
|
|
10
|
+
// `yak serve` is one more process over the same file, the one that serves HTTP
|
|
11
|
+
// requests — and `serve` is a tool like any other, contributed by @yaks/api.
|
|
12
|
+
//
|
|
13
|
+
// That is why this is its own module. A command that only needs to know where
|
|
14
|
+
// the graph is must not import host.ts, which pulls in every plugin a config
|
|
15
|
+
// names — a cost `yak login` should not pay. So the config is read here, by a
|
|
16
|
+
// module that opens no graph.
|
|
17
|
+
|
|
18
|
+
import { runtimePath } from './runtime.js'
|
|
19
|
+
|
|
20
|
+
export type { Config, Options, Plug } from 'jsr:@yaks/host@0.2.36'
|
|
21
|
+
import type { Config, Plug } from 'jsr:@yaks/host@0.2.36'
|
|
22
|
+
import type { Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
23
|
+
|
|
24
|
+
/** Where a machine keeps the config for its own graph. */
|
|
25
|
+
export let OWN_CONFIG = '.yak/yak.json'
|
|
26
|
+
|
|
27
|
+
/** The person who works at this machine, as the entity the config's `person`
|
|
28
|
+
* names, or nobody where it names none: a machine never guesses who is at its
|
|
29
|
+
* keyboard. What they type at it is written by them. */
|
|
30
|
+
export let person = async (
|
|
31
|
+
host: { config: Pick<Config, 'person'>; graph: Pick<Graph, 'address'> },
|
|
32
|
+
): Promise<Eid | undefined> => {
|
|
33
|
+
let said = host.config.person
|
|
34
|
+
return said ? (await host.graph.address([said])).get(said) ?? said : undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Where this machine keeps the config for its own graph, whether or not it
|
|
38
|
+
* has one yet: under `$HOME`, or nowhere for a process that has none. */
|
|
39
|
+
export let ownConfig = (
|
|
40
|
+
env: (name: string) => string | undefined = system.env.get,
|
|
41
|
+
): string | undefined => {
|
|
42
|
+
let home = env('HOME')
|
|
43
|
+
return home ? `${home}/${OWN_CONFIG}` : undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The config a command opens: the path it was given, else `$YAK_CONFIG`,
|
|
47
|
+
* else the one this machine keeps for its own graph. A machine that has a
|
|
48
|
+
* graph is the ordinary case, so a bare `yak task list` there reads from it
|
|
49
|
+
* rather than reaching for a remote server it was never told about. No file
|
|
50
|
+
* there means no config. */
|
|
51
|
+
export let configPath = (
|
|
52
|
+
said?: string,
|
|
53
|
+
env: (name: string) => string | undefined = system.env.get,
|
|
54
|
+
): string | undefined => {
|
|
55
|
+
let named = said ?? env('YAK_CONFIG')
|
|
56
|
+
if (named) return named
|
|
57
|
+
let own = ownConfig(env)
|
|
58
|
+
if (!own) return undefined
|
|
59
|
+
// The command may be running without read permission at all; that is no
|
|
60
|
+
// config.
|
|
61
|
+
try {
|
|
62
|
+
return disk.statSync(own).isFile ? own : undefined
|
|
63
|
+
} catch {
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A specifier belonging to the config file — `./plugins/mail`, `/srv/mail` —
|
|
69
|
+
// is resolved against the config, so a config file is movable and a bare
|
|
70
|
+
// `@yaks/…` is left to the import map. It names a package, never a file: a
|
|
71
|
+
// plugin's modules are its subpaths, and only a package has those.
|
|
72
|
+
let near = (spec: string, base: URL): string =>
|
|
73
|
+
runtimePath(
|
|
74
|
+
spec.startsWith('.') || spec.startsWith('/')
|
|
75
|
+
? new URL(spec, base).href
|
|
76
|
+
: spec,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
export { given, used } from '@yaks/host/config'
|
|
80
|
+
export {
|
|
81
|
+
exported,
|
|
82
|
+
located,
|
|
83
|
+
pluginTui,
|
|
84
|
+
pluginViews,
|
|
85
|
+
ships,
|
|
86
|
+
subpath,
|
|
87
|
+
subpaths,
|
|
88
|
+
unexported,
|
|
89
|
+
} from './facets.js'
|
|
90
|
+
|
|
91
|
+
let resolved = (plug: Plug, base: URL): Plug =>
|
|
92
|
+
typeof plug == 'string'
|
|
93
|
+
? near(plug, base)
|
|
94
|
+
: { ...plug, use: near(plug.use, base) }
|
|
95
|
+
|
|
96
|
+
/** Whether the config at `path` names `part`: a command about that part of a
|
|
97
|
+
* config (a box's process plan, its tracker) is offered only where it does.
|
|
98
|
+
* No config, or one that cannot be read, names nothing.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { assertEquals } from '@std/assert'
|
|
102
|
+
* assertEquals(names(undefined, 'processes'), false)
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export let names = (path: string | undefined, part: keyof Config): boolean => {
|
|
106
|
+
if (!path) return false
|
|
107
|
+
try {
|
|
108
|
+
return read(path)[part] !== undefined
|
|
109
|
+
} catch {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Read a config file. Paths inside it — the database, a relative plugin — are
|
|
116
|
+
* resolved against the file itself.
|
|
117
|
+
*/
|
|
118
|
+
export let read = (path: string): Config => {
|
|
119
|
+
let base = new URL(path, `file://${system.cwd()}/`)
|
|
120
|
+
let said: unknown
|
|
121
|
+
try {
|
|
122
|
+
said = JSON.parse(disk.readTextFileSync(base))
|
|
123
|
+
} catch (e) {
|
|
124
|
+
throw new Error(`${path}: ${(e as Error).message}`)
|
|
125
|
+
}
|
|
126
|
+
if (!said || typeof said != 'object' || Array.isArray(said)) {
|
|
127
|
+
throw new Error(`${path}: a config is a JSON object`)
|
|
128
|
+
}
|
|
129
|
+
let config = said as Config
|
|
130
|
+
return {
|
|
131
|
+
...config,
|
|
132
|
+
...config.tracker
|
|
133
|
+
? {
|
|
134
|
+
tracker: {
|
|
135
|
+
...config.tracker,
|
|
136
|
+
spool: new URL(config.tracker.spool, base).pathname,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
: {},
|
|
140
|
+
db: config.db && config.db != ':memory:'
|
|
141
|
+
? new URL(config.db, base).pathname
|
|
142
|
+
: config.db,
|
|
143
|
+
plugins: (config.plugins ?? []).map((plug) => resolved(plug, base)),
|
|
144
|
+
...config.sandboxes
|
|
145
|
+
? {
|
|
146
|
+
sandboxes: {
|
|
147
|
+
...config.sandboxes,
|
|
148
|
+
providers: Object.fromEntries(
|
|
149
|
+
Object.entries(config.sandboxes.providers ?? {}).map((
|
|
150
|
+
[name, provider],
|
|
151
|
+
) => [
|
|
152
|
+
name,
|
|
153
|
+
'use' in provider
|
|
154
|
+
? { ...provider, use: near(provider.use, base) }
|
|
155
|
+
: provider,
|
|
156
|
+
]),
|
|
157
|
+
),
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
: {},
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The database a config names. `DB_PATH` is the other way to give it, for a
|
|
165
|
+
* service file that would rather set it in the environment. Neither has a
|
|
166
|
+
* default, because the path anybody would pick as one is somebody's live
|
|
167
|
+
* graph. */
|
|
168
|
+
export let dbOf = (
|
|
169
|
+
config: Config,
|
|
170
|
+
env: (name: string) => string | undefined = (n) => system.env.get(n),
|
|
171
|
+
): string => {
|
|
172
|
+
let db = config.db ?? env('DB_PATH')
|
|
173
|
+
if (!db) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
'a host needs a database: `db` in the config, or DB_PATH in the ' +
|
|
176
|
+
'environment — there is no default',
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
return db
|
|
180
|
+
}
|
package/declarations.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Command declarations are data. The memo keeps neither a vocabulary runtime
|
|
2
|
+
// nor any closures; the chosen command loads its implementation by role.
|
|
3
|
+
import { located, used } from "./config.js";
|
|
4
|
+
import { chosen, facetsOf } from "@yaks/host/config";
|
|
5
|
+
import { remember } from "./memo.js";
|
|
6
|
+
let held = new Map();
|
|
7
|
+
/** A process shares its validated command data between discovery and invocation. */ export let declarations = (config, controls = false)=>{
|
|
8
|
+
// Options are capabilities lent to running factories. They neither change
|
|
9
|
+
// declarations nor belong in a discovery cache's identity or serialization.
|
|
10
|
+
let inputs = (config.plugins ?? []).map((input)=>({
|
|
11
|
+
use: used(input),
|
|
12
|
+
words: chosen(input),
|
|
13
|
+
facets: facetsOf(input)
|
|
14
|
+
}));
|
|
15
|
+
let key = JSON.stringify([
|
|
16
|
+
inputs,
|
|
17
|
+
controls
|
|
18
|
+
]);
|
|
19
|
+
let known = held.get(key) ?? (!controls && held.get(JSON.stringify([
|
|
20
|
+
inputs,
|
|
21
|
+
true
|
|
22
|
+
])));
|
|
23
|
+
if (known) return known;
|
|
24
|
+
let requests = inputs.flatMap((input)=>[
|
|
25
|
+
'vocab',
|
|
26
|
+
...controls ? [
|
|
27
|
+
'cli'
|
|
28
|
+
] : []
|
|
29
|
+
].filter((name)=>facetsOf(input)?.some((facet)=>facet == name) ?? true).map((name)=>[
|
|
30
|
+
used(input),
|
|
31
|
+
name
|
|
32
|
+
]));
|
|
33
|
+
let made = remember([
|
|
34
|
+
inputs,
|
|
35
|
+
controls
|
|
36
|
+
], [
|
|
37
|
+
import.meta.url,
|
|
38
|
+
new URL('./derive.ts', import.meta.url).href,
|
|
39
|
+
...requests
|
|
40
|
+
], async ()=>(await import("./derive.js")).derive({
|
|
41
|
+
...config,
|
|
42
|
+
plugins: inputs
|
|
43
|
+
}, controls), {
|
|
44
|
+
callbacks: {
|
|
45
|
+
cli: [
|
|
46
|
+
'run'
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
// A plugin found where the loader finds it: an installed `yak` names
|
|
50
|
+
// its packages at its own release on JSR (./config.ts `located`). The
|
|
51
|
+
// loader is asked once for a module it finds, which is nearly every
|
|
52
|
+
// one, and a miss tells `located` why.
|
|
53
|
+
resolve: (specifier)=>{
|
|
54
|
+
try {
|
|
55
|
+
return import.meta.resolve(specifier);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return import.meta.resolve(located(specifier, ()=>{
|
|
58
|
+
throw error;
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
held.set(key, made);
|
|
64
|
+
made.catch(()=>held.delete(key));
|
|
65
|
+
return made;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sources":["./declarations.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yEAAyE;AACzE,SAAsB,OAAO,EAAE,IAA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AW;UAC5C,MAAM;QACR;MACF;IACF;EACF;EAEF,KAAK,GAAG,CAAC,KAAK;EACd,KAAK,KAAK,CAAC,IAAM,KAAK,MAAM,CAAC;EAC7B,OAAO;AACT,EAAC"}
|
package/declarations.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Command declarations are data. The memo keeps neither a vocabulary runtime
|
|
2
|
+
// nor any closures; the chosen command loads its implementation by role.
|
|
3
|
+
import { type Config, located, used } from './config.js'
|
|
4
|
+
import { chosen, facetsOf } from '@yaks/host/config'
|
|
5
|
+
import type { Declared } from './words.ts'
|
|
6
|
+
import type { CliCommand, CliFacet } from './host.ts'
|
|
7
|
+
import type { VocabFacet } from 'jsr:@yaks/host@0.2.36'
|
|
8
|
+
import { remember } from './memo.js'
|
|
9
|
+
type Control = Omit<CliCommand, 'run'>
|
|
10
|
+
export type Declarations = {
|
|
11
|
+
facets: Record<string, string[]>
|
|
12
|
+
vocabs: {
|
|
13
|
+
plugin: string
|
|
14
|
+
value: Pick<VocabFacet, 'description' | 'docs' | 'keywords'> | null
|
|
15
|
+
factories: boolean
|
|
16
|
+
}[]
|
|
17
|
+
controls: {
|
|
18
|
+
plugin: string
|
|
19
|
+
value: {
|
|
20
|
+
commands: Control[]
|
|
21
|
+
globals?: CliFacet['globals']
|
|
22
|
+
tools?: string[]
|
|
23
|
+
} | null
|
|
24
|
+
}[]
|
|
25
|
+
tools: Declared[]
|
|
26
|
+
owners: Record<string, string>
|
|
27
|
+
pooled: boolean
|
|
28
|
+
}
|
|
29
|
+
let held = new Map<string, Promise<Declarations>>()
|
|
30
|
+
|
|
31
|
+
/** A process shares its validated command data between discovery and invocation. */
|
|
32
|
+
export let declarations = (
|
|
33
|
+
config: Config,
|
|
34
|
+
controls = false,
|
|
35
|
+
): Promise<Declarations> => {
|
|
36
|
+
// Options are capabilities lent to running factories. They neither change
|
|
37
|
+
// declarations nor belong in a discovery cache's identity or serialization.
|
|
38
|
+
let inputs = (config.plugins ?? []).map((input) => ({
|
|
39
|
+
use: used(input),
|
|
40
|
+
words: chosen(input),
|
|
41
|
+
facets: facetsOf(input),
|
|
42
|
+
}))
|
|
43
|
+
let key = JSON.stringify([inputs, controls])
|
|
44
|
+
let known = held.get(key) ??
|
|
45
|
+
(!controls && held.get(JSON.stringify([inputs, true])))
|
|
46
|
+
if (known) return known
|
|
47
|
+
let requests = inputs.flatMap((input) =>
|
|
48
|
+
['vocab', ...controls ? ['cli'] : []].filter((name) =>
|
|
49
|
+
facetsOf(input)?.some((facet) => facet == name) ?? true
|
|
50
|
+
).map((name) => [used(input), name] as const)
|
|
51
|
+
)
|
|
52
|
+
let made = remember(
|
|
53
|
+
[inputs, controls],
|
|
54
|
+
[
|
|
55
|
+
import.meta.url,
|
|
56
|
+
new URL('./derive.ts', import.meta.url).href,
|
|
57
|
+
...requests,
|
|
58
|
+
],
|
|
59
|
+
async () =>
|
|
60
|
+
(await import('./derive.js')).derive(
|
|
61
|
+
{ ...config, plugins: inputs },
|
|
62
|
+
controls,
|
|
63
|
+
),
|
|
64
|
+
{
|
|
65
|
+
callbacks: { cli: ['run'] },
|
|
66
|
+
// A plugin found where the loader finds it: an installed `yak` names
|
|
67
|
+
// its packages at its own release on JSR (./config.ts `located`). The
|
|
68
|
+
// loader is asked once for a module it finds, which is nearly every
|
|
69
|
+
// one, and a miss tells `located` why.
|
|
70
|
+
resolve: (specifier) => {
|
|
71
|
+
try {
|
|
72
|
+
return import.meta.resolve(specifier)
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return import.meta.resolve(located(specifier, () => {
|
|
75
|
+
throw error
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
held.set(key, made)
|
|
82
|
+
made.catch(() => held.delete(key))
|
|
83
|
+
return made
|
|
84
|
+
}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"compilerOptions":{"lib":["deno.ns","dom","esnext"]},"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/cli","version":"0.2.36","license":"Apache-2.0","description":"The yak command line: it opens the graph a config file names, or connects to an MCP server, and turns every tool it finds there into a subcommand parsed through that tool's own input schema.","exports":{".":"./mod.ts","./yak":"./yak.ts","./main":"./main.ts","./config":"./config.ts","./facets":"./facets.ts","./account-forward":"./account-forward.ts","./host":"./host.ts","./install":"./install.ts","./page":"./page.ts","./memo":"./memo.ts","./release":"./release.ts","./grammar":"./grammar.ts","./answer":"./answer.ts","./terminal":"./terminal.ts","./dependencies":"./dependencies.ts","./vault":"./vault.ts"},"imports":{"@yaks/cli":"./mod.ts","@yaks/cli/yak":"./yak.ts","@yaks/cli/main":"./main.ts","@yaks/cli/config":"./config.ts","@yaks/cli/facets":"./facets.ts","@yaks/cli/account-forward":"./account-forward.ts","@yaks/cli/host":"./host.ts","@yaks/cli/install":"./install.ts","@yaks/cli/page":"./page.ts","@yaks/cli/memo":"./memo.ts","@yaks/cli/release":"./release.ts","@yaks/cli/grammar":"./grammar.ts","@yaks/cli/answer":"./answer.ts","@yaks/cli/terminal":"./terminal.ts","@yaks/cli/dependencies":"./dependencies.ts","@yaks/cli/vault":"./vault.ts"}}
|