@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/code.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sources":["./code.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,gCAAqC;AACnD,YAAY,+BAAoC;AAChD,SAAS,UAAU,6BAAkC;AACrD,SAAS,YAAY,gCAAqC;AAC1D,SAAS,OAAO,qCAA0C;AAC1D,YAAY,wCAA6C;AACzD,SAAS,UAAU,QAAQ,cAAa;AACxC,SAAS,aAAa,QAAQ,WAAU;AACxC,SAAS,WAAW,uBAAsB;AA6B1C,4DAA4D,GAC5D,OAAO,IAAI,QAAQ,sBAAqB;AAExC,wDAAwD;AACxD,IAAI,SAAS;EAAC;EAAa;EAAa;EAAgB;CAAiB;AAEzE,iFAAiF;AACjF,yEAAyE,GACzE,OAAO,IAAI,WAAW,CAAC,QACrB,MAAM,OAAO,CAAC,YAAY,MAAM,QAAO;AAEzC,IAAI,MAAM,CAAC,QACT,WAAW,UAAU,MAAM,CAAC,OAAO,MAAM,CAAC;AAE5C,IAAI,SAAS,CAAC,OAAiB,KAAK,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,IAAM;AAEnE,kEAAkE;AAClE,kDAAkD;AAClD,2DAA2D;AAC3D,6CAA6C;AAC7C;eACe,GACf,OAAO,IAAI,SAAS,CAAC,MAAc;EACjC,IAAI,OAAO,cAAc,OAAO,GAAG,UAAU,CAAC,WAC1C,cAAc,MACd,KAAK,OAAO,CAAC;EACjB,IAAI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import * as disk from '@yaks/file/io'
|
|
3
|
+
import { watchReads } from '@yaks/file/io'
|
|
4
|
+
import { watchImports } from '@yaks/fp/imports'
|
|
5
|
+
import { modules } from '@yaks/process/modules'
|
|
6
|
+
import * as system from '@yaks/process/system'
|
|
7
|
+
import { createHash } from 'node:crypto'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import { runtimeTree } from './runtime.js'
|
|
10
|
+
// What a supervised process runs, so `yak restart` replaces only one whose
|
|
11
|
+
// code or config changed (./restart.ts). A process in a pinned runtime
|
|
12
|
+
// (./runtime.ts) runs from a tree nothing rewrites while it runs. What it can
|
|
13
|
+
// run from that tree is its entry's module graph, and beyond what any graph
|
|
14
|
+
// names: a module it imports by a computed specifier (a plugin's facet, a
|
|
15
|
+
// bundler, through @yaks/fp/imports), a module a bundler reads for the
|
|
16
|
+
// browser (reported the same way), and a file it reads (@yaks/file/io). A
|
|
17
|
+
// process given `--ready` keeps each, as a path in its tree, in its code
|
|
18
|
+
// record beside its ready file, rewritten as it learns more.
|
|
19
|
+
//
|
|
20
|
+
// A record is proved against another tree the way the test runner proves a
|
|
21
|
+
// pass (@yaks/testing/deps): the module graph of its roots, computed in the
|
|
22
|
+
// tree it ran from, with every file it reaches, the configs over them and
|
|
23
|
+
// every file it read compared byte for byte.
|
|
24
|
+
|
|
25
|
+
/** What a process runs: the tree it runs from, by path and by id, the roots
|
|
26
|
+
* beyond its entry and the files it read there, as paths in the tree, the
|
|
27
|
+
* digest of its config, and the files the module graph of some of its roots
|
|
28
|
+
* reaches, once resolved. */
|
|
29
|
+
export type Code = {
|
|
30
|
+
root: string
|
|
31
|
+
tree: string
|
|
32
|
+
imports: string[]
|
|
33
|
+
reads: string[]
|
|
34
|
+
config?: { path: string; sum: string }
|
|
35
|
+
graph?: { roots: string[]; files: string[] }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The entry every `yak` process starts from, in its tree. */
|
|
39
|
+
export let ENTRY = 'packages/cli/yak.ts'
|
|
40
|
+
|
|
41
|
+
// What every module shares, beside the configs over it.
|
|
42
|
+
let SHARED = ['deno.json', 'deno.lock', 'package.json', 'pnpm-lock.yaml']
|
|
43
|
+
|
|
44
|
+
/// codeFile('/run/user/1000/yak-web-1.ready') -> '/run/user/1000/yak-web-1.code'
|
|
45
|
+
/** Where the process whose ready file is `ready` keeps its code record. */
|
|
46
|
+
export let codeFile = (ready: string): string =>
|
|
47
|
+
ready.replace(/\.ready$/, '') + '.code'
|
|
48
|
+
|
|
49
|
+
let sum = (bytes: Uint8Array) =>
|
|
50
|
+
createHash('sha256').update(bytes).digest('hex')
|
|
51
|
+
|
|
52
|
+
let digest = (path: string) => disk.readFile(path).then(sum, () => undefined)
|
|
53
|
+
|
|
54
|
+
/// inside('/c/0', 'file:///c/0/packages/a.ts') -> 'packages/a.ts'
|
|
55
|
+
/// inside('/c/0', '/c/0/packages/') -> 'packages'
|
|
56
|
+
/// inside('/c/0', '/c/0/node_modules/x/a.js') -> undefined
|
|
57
|
+
/// inside('/c/0', '/c/01/a.ts') -> undefined
|
|
58
|
+
/** A path in the tree at `root`, outside its `node_modules`, which its lock
|
|
59
|
+
* speaks for. */
|
|
60
|
+
export let inside = (root: string, at: string | URL): string | undefined => {
|
|
61
|
+
let path = at instanceof URL || at.startsWith('file:')
|
|
62
|
+
? fileURLToPath(at)
|
|
63
|
+
: disk.resolve(at)
|
|
64
|
+
if (!path.startsWith(`${root}/`)) return
|
|
65
|
+
let rel = path.slice(root.length + 1).replace(/\/$/, '')
|
|
66
|
+
return /(^|\/)node_modules(\/|$)/.test(rel) || !rel ? undefined : rel
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The files in the tree at `root` that the module graph of `roots` (paths
|
|
70
|
+
// in it) reaches, or undefined when deno can't say.
|
|
71
|
+
let reach = async (root: string, roots: string[]) => {
|
|
72
|
+
let graph = await modules(roots.map((p) => `file://${root}/${p}`), root)
|
|
73
|
+
if (!graph) return
|
|
74
|
+
let files = new Set<string>()
|
|
75
|
+
for (let m of graph.modules) {
|
|
76
|
+
let rel = m.local ? inside(root, m.local) : undefined
|
|
77
|
+
if (rel) files.add(rel)
|
|
78
|
+
}
|
|
79
|
+
return files
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Keep what this process runs in `file`, if it runs from a pinned tree,
|
|
83
|
+
* from now until `stop` removes it; `now` is what it holds. The record is
|
|
84
|
+
* rewritten, whole, within a second of learning more, and its graph
|
|
85
|
+
* resolved once no import has been learned for `quiet` milliseconds. */
|
|
86
|
+
export let record = (
|
|
87
|
+
file: string,
|
|
88
|
+
config?: string,
|
|
89
|
+
tree = runtimeTree(),
|
|
90
|
+
quiet = 10_000,
|
|
91
|
+
): { now: () => Code | undefined; stop: () => Promise<void> } => {
|
|
92
|
+
if (!tree) return { now: () => undefined, stop: async () => {} }
|
|
93
|
+
let imports = new Set<string>(), reads = new Set<string>()
|
|
94
|
+
let graphed = new Set<string>(), reached = new Set<string>()
|
|
95
|
+
let said = config
|
|
96
|
+
? { path: disk.resolve(config), sum: sum(disk.readFileSync(config)) }
|
|
97
|
+
: undefined
|
|
98
|
+
let now = (): Code => ({
|
|
99
|
+
root: tree.root,
|
|
100
|
+
tree: tree.id,
|
|
101
|
+
imports: [...imports].sort(),
|
|
102
|
+
reads: [...reads].sort(),
|
|
103
|
+
...said ? { config: said } : {},
|
|
104
|
+
...graphed.size
|
|
105
|
+
? { graph: { roots: [...graphed].sort(), files: [...reached].sort() } }
|
|
106
|
+
: {},
|
|
107
|
+
})
|
|
108
|
+
let pending: ReturnType<typeof setTimeout> | undefined
|
|
109
|
+
let settling: ReturnType<typeof setTimeout> | undefined
|
|
110
|
+
let resolving = false
|
|
111
|
+
let written = Promise.resolve()
|
|
112
|
+
let stopped = false
|
|
113
|
+
let write = () => {
|
|
114
|
+
pending = undefined
|
|
115
|
+
written = written.then(async () => {
|
|
116
|
+
if (stopped) return
|
|
117
|
+
let next = `${file}.${crypto.randomUUID()}`
|
|
118
|
+
await disk.writeTextFile(next, JSON.stringify(now()))
|
|
119
|
+
await disk.rename(next, file)
|
|
120
|
+
}).catch((error) => fault(error, `writing ${file}`))
|
|
121
|
+
}
|
|
122
|
+
let later = () => {
|
|
123
|
+
if (pending || stopped) return
|
|
124
|
+
pending = setTimeout(write, 1000)
|
|
125
|
+
system.unrefTimer(pending)
|
|
126
|
+
}
|
|
127
|
+
// One resolution at a time, of the roots not yet graphed; roots learned
|
|
128
|
+
// meanwhile settle again after it.
|
|
129
|
+
let graph = async () => {
|
|
130
|
+
settling = undefined
|
|
131
|
+
let roots = [ENTRY, ...imports].filter((p) => !graphed.has(p))
|
|
132
|
+
if (stopped || resolving || !roots.length) return
|
|
133
|
+
resolving = true
|
|
134
|
+
try {
|
|
135
|
+
let files = await reach(tree.root, roots)
|
|
136
|
+
if (!files || stopped) return
|
|
137
|
+
for (let p of roots) graphed.add(p)
|
|
138
|
+
for (let f of files) reached.add(f)
|
|
139
|
+
later()
|
|
140
|
+
} catch (error) {
|
|
141
|
+
fault(error, `resolving what ${file} runs`)
|
|
142
|
+
} finally {
|
|
143
|
+
resolving = false
|
|
144
|
+
}
|
|
145
|
+
if (!settling && [ENTRY, ...imports].some((p) => !graphed.has(p))) settle()
|
|
146
|
+
}
|
|
147
|
+
let settle = () => {
|
|
148
|
+
if (stopped) return
|
|
149
|
+
clearTimeout(settling)
|
|
150
|
+
settling = setTimeout(graph, quiet)
|
|
151
|
+
system.unrefTimer(settling)
|
|
152
|
+
}
|
|
153
|
+
let learn = (into: Set<string>, at: string | URL) => {
|
|
154
|
+
let rel = inside(tree.root, at)
|
|
155
|
+
if (!rel || into.has(rel)) return
|
|
156
|
+
into.add(rel)
|
|
157
|
+
if (into == imports) settle()
|
|
158
|
+
later()
|
|
159
|
+
}
|
|
160
|
+
let offImports = watchImports((specifier) => {
|
|
161
|
+
if (specifier.startsWith('file:')) learn(imports, specifier)
|
|
162
|
+
})
|
|
163
|
+
let offReads = watchReads((path) => learn(reads, path))
|
|
164
|
+
write()
|
|
165
|
+
settle()
|
|
166
|
+
return {
|
|
167
|
+
now,
|
|
168
|
+
stop: async () => {
|
|
169
|
+
stopped = true
|
|
170
|
+
offImports()
|
|
171
|
+
offReads()
|
|
172
|
+
clearTimeout(pending)
|
|
173
|
+
clearTimeout(settling)
|
|
174
|
+
await written
|
|
175
|
+
await disk.remove(file).catch(() => {})
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// A file's bytes, a directory's listing, or nothing.
|
|
181
|
+
let held = async (path: string): Promise<string | undefined> => {
|
|
182
|
+
let info = await disk.stat(path).catch(() => undefined)
|
|
183
|
+
if (!info) return
|
|
184
|
+
if (!info.isDirectory) return digest(path)
|
|
185
|
+
let names = []
|
|
186
|
+
for await (let entry of disk.readDir(path)) names.push(entry.name)
|
|
187
|
+
return names.sort().join('\n')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Why the process `code` describes would run differently from one started
|
|
191
|
+
* from the tree `tree`, or undefined when it runs the same: the config, or
|
|
192
|
+
* the first file, that differs. Only the roots its record's graph doesn't
|
|
193
|
+
* cover are resolved here. */
|
|
194
|
+
export let stale = async (
|
|
195
|
+
code: Code,
|
|
196
|
+
tree: { root: string; id: string },
|
|
197
|
+
): Promise<string | undefined> => {
|
|
198
|
+
if (code.config && (await digest(code.config.path)) != code.config.sum) {
|
|
199
|
+
return `${code.config.path} differs`
|
|
200
|
+
}
|
|
201
|
+
if (code.tree == tree.id) return
|
|
202
|
+
let covered = new Set(code.graph?.roots)
|
|
203
|
+
let rest = [ENTRY, ...code.imports].filter((p) => !covered.has(p))
|
|
204
|
+
if (!(await disk.stat(code.root).then(() => true, () => false))) {
|
|
205
|
+
return `${code.root} is gone`
|
|
206
|
+
}
|
|
207
|
+
let reached = rest.length ? await reach(code.root, rest) : new Set<string>()
|
|
208
|
+
if (!reached) return `deno can't say what ${code.root} loads`
|
|
209
|
+
let files = new Set([...SHARED, ...code.reads])
|
|
210
|
+
for (let rel of [...code.graph?.files ?? [], ...reached]) {
|
|
211
|
+
files.add(rel)
|
|
212
|
+
for (let dir = rel; dir.includes('/');) {
|
|
213
|
+
dir = dir.slice(0, dir.lastIndexOf('/'))
|
|
214
|
+
files.add(`${dir}/deno.json`)
|
|
215
|
+
files.add(`${dir}/package.json`)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Every file at once, the first that differs in order reported.
|
|
219
|
+
let sorted = [...files].sort()
|
|
220
|
+
let same = await Promise.all(
|
|
221
|
+
sorted.map(async (rel) =>
|
|
222
|
+
(await held(`${code.root}/${rel}`)) == (await held(`${tree.root}/${rel}`))
|
|
223
|
+
),
|
|
224
|
+
)
|
|
225
|
+
let first = same.indexOf(false)
|
|
226
|
+
if (first >= 0) return `${sorted[first]} differs`
|
|
227
|
+
}
|
package/commands.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Remote tools and apps' commands use the same grammar as local commands.
|
|
2
|
+
// The outer command keeps only its selector flags; the receiving schema is
|
|
3
|
+
// fetched before the remaining words are parsed by argsFor.
|
|
4
|
+
import { valueIn } from "@yaks/tools/value";
|
|
5
|
+
import { argsFor, Usage } from "./args.js";
|
|
6
|
+
import { printed } from "./platform.js";
|
|
7
|
+
import { Refused } from "./rpc.js";
|
|
8
|
+
import { saidBy } from "./roster.js";
|
|
9
|
+
import { spelling } from "./tool.js";
|
|
10
|
+
/** Fetch a tool's schema, parse its words with the CLI grammar, and call it.
|
|
11
|
+
* Connector tools take precedence over the commands of reachable apps. The
|
|
12
|
+
* caller supplies the RPC door, so login and admin account selection share
|
|
13
|
+
* this whole path. */ export let toolCall = async (ask, name, words, o = {})=>{
|
|
14
|
+
let listed = await ask('tools/list');
|
|
15
|
+
let tool = listed.tools.find((t)=>t.name == name);
|
|
16
|
+
if (tool) {
|
|
17
|
+
// The selected app is an argument only to a tool that takes one, and the
|
|
18
|
+
// tool's own words come after it, so its own --app wins.
|
|
19
|
+
let spelt = spelling(tool);
|
|
20
|
+
let takes = o.app && spelt.inputSchema?.properties?.app;
|
|
21
|
+
let args = await argsFor({
|
|
22
|
+
name,
|
|
23
|
+
...spelt
|
|
24
|
+
}, [
|
|
25
|
+
...takes ? [
|
|
26
|
+
'--app',
|
|
27
|
+
o.app
|
|
28
|
+
] : [],
|
|
29
|
+
...words
|
|
30
|
+
], o.reads);
|
|
31
|
+
return await ask('tools/call', {
|
|
32
|
+
name,
|
|
33
|
+
arguments: args
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
let answer = await ask('tools/call', {
|
|
37
|
+
name: 'commands',
|
|
38
|
+
arguments: o.app ? {
|
|
39
|
+
app: o.app
|
|
40
|
+
} : {}
|
|
41
|
+
});
|
|
42
|
+
if (answer.isError) throw new Refused(saidBy(answer).text);
|
|
43
|
+
let result = answer.structuredContent?.result;
|
|
44
|
+
let commands = result && valueIn(result)?.commands;
|
|
45
|
+
if (!Array.isArray(commands)) {
|
|
46
|
+
throw new Refused('commands returned no command schemas');
|
|
47
|
+
}
|
|
48
|
+
let found = commands.filter((t)=>t.name == name);
|
|
49
|
+
if (!found.length) throw new Usage(`No tool or app command named ${name}`);
|
|
50
|
+
if (found.length > 1) {
|
|
51
|
+
throw new Usage(`${name} is in ${found.map((t)=>t.at).join(', ')} — choose one with --app`);
|
|
52
|
+
}
|
|
53
|
+
let command = found[0];
|
|
54
|
+
let args = await argsFor({
|
|
55
|
+
name,
|
|
56
|
+
inputSchema: command.input,
|
|
57
|
+
positional: command.positional
|
|
58
|
+
}, words, o.reads);
|
|
59
|
+
return await ask('tools/call', {
|
|
60
|
+
name: 'command',
|
|
61
|
+
arguments: {
|
|
62
|
+
name,
|
|
63
|
+
app: command.at,
|
|
64
|
+
args
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
let called = async (c, given, app)=>{
|
|
69
|
+
let answer = await toolCall(c.ask, String(given.name), given.args ?? [], {
|
|
70
|
+
app: app ?? given.app,
|
|
71
|
+
reads: c.reads
|
|
72
|
+
});
|
|
73
|
+
return printed(c, null, 'command', answer);
|
|
74
|
+
};
|
|
75
|
+
let ABOUT = `Run a connector tool or one of an app's own commands. ` + `--as selects a saved yaks.app account by its whole address or the part before @; ` + `\`yak connection list <owner>\` lists connections (owner id or name); use a yaks.app entry’s account. ` + `On the shared box, a session defaults to checks. Select --as admin for platform operations. ` + `Outside a session, it is your own email, else the oldest connection. ` + `Connector tools come first; \`yak commands\` lists app commands and their schemas. ` + `Use positionals and --flags; --app chooses an app when two share a command. ` + `Values follow the schema's types; @path reads a file and - reads stdin.`;
|
|
76
|
+
let schema = (app)=>({
|
|
77
|
+
type: 'object',
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
required: [
|
|
80
|
+
'name'
|
|
81
|
+
],
|
|
82
|
+
properties: {
|
|
83
|
+
name: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'the tool or app command to run'
|
|
86
|
+
},
|
|
87
|
+
...app ? {
|
|
88
|
+
app: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'which app'
|
|
91
|
+
}
|
|
92
|
+
} : {},
|
|
93
|
+
args: {
|
|
94
|
+
type: 'array',
|
|
95
|
+
items: {
|
|
96
|
+
type: 'string'
|
|
97
|
+
},
|
|
98
|
+
description: 'the command’s arguments'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
/** Remote tools and apps' commands, as subcommands of this program. */ export let appTools = [
|
|
103
|
+
{
|
|
104
|
+
name: 'command',
|
|
105
|
+
title: 'run a remote tool or app command',
|
|
106
|
+
description: ABOUT,
|
|
107
|
+
inputSchema: schema(true),
|
|
108
|
+
positional: [
|
|
109
|
+
'name'
|
|
110
|
+
],
|
|
111
|
+
forward: 'args',
|
|
112
|
+
run: (args, c)=>called(c, args)
|
|
113
|
+
}
|
|
114
|
+
];
|
|
115
|
+
/** `yak <app> <command>`: only reached when no command or command noun claims
|
|
116
|
+
* the first word, so a tool or noun of the same name always wins. */ export let appStray = (app, args)=>{
|
|
117
|
+
let name = args[0];
|
|
118
|
+
if (!name || name.startsWith('-')) return undefined;
|
|
119
|
+
return {
|
|
120
|
+
name: app,
|
|
121
|
+
title: `a command of the ${app} app`,
|
|
122
|
+
description: ABOUT,
|
|
123
|
+
inputSchema: schema(false),
|
|
124
|
+
positional: [
|
|
125
|
+
'name'
|
|
126
|
+
],
|
|
127
|
+
forward: 'args',
|
|
128
|
+
run: (given, c)=>called(c, given, app)
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=commands.js.map
|
package/commands.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sources":["./commands.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,4DAA4D;AAC5D,SAAS,OAAO,iCAAsC;AAEtD,SAAS,OAAO,EAA4B,KAAK,oBAAmB;AAEpE,SAAS,OAAO,wBAAuB;AACvC,SAAS,OAAO,mBAA4B;AAC5C,SAAsB,MAAM,sBAAqB;AACjD,SAAmC,QAAQ,oBAAmB;AAS9D;;;oBAGoB,GACpB,OAAO,IAAI,WAAW,OACpB,KACA,MACA,OACA,IAAqC,CAAC,CAAC;EAEvC,IAAI,SAAS,MAAM,IAAI;EACvB,IAAI,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAM,EAAE,IAAI,IAAI;EAC9C,IAAI,MAAM;IACR,yEAAyE;IACzE,yDAAyD;IACzD,IAAI,QAAQ,SAAS;IACrB,IAAI,QAAQ,EAAE,GAAG,IAAI,MAAM,WAAW,EAAE,YAAY;IACpD,IAAI,OAAO,MAAM,QACf;MAAE;MAAM,GAAG,KAAK;IAAC,GACjB;SAAI,QAAQ;QAAC;QAAS,EAAE,GAAG;OAAE,GAAG,EAAE;SAAK;KAAM,EAC7C,EAAE,KAAK;IAET,OAAO,MAAM,IAAI,cAAc;MAAE;MAAM,WAAW;IAAK;EACzD;EACA,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,sGAAsG,CAAC,GACxG,CAAC,4FAA4F,CAAC,GAC9F,CAAC,qEAAqE,CAAC,GACvE,CAAC,mFAAmF,CAAC,GACrF,CAAC,4EAA4E,CAAC,GAC9E,CAAC,uEAAuE,CAAC;AAE3E,IAAI,SAAS,CAAC,MAA0C,CAAC;IACvD,MAAM;IACN,sBAAsB;IACtB,UAAU;MAAC;KAAO;IAClB,YAAY;MACV,MAAM;QAAE,MAAM;QAAU,aAAa;MAAiC;MACtE,GAAI,MAAM;QAAE,KAAK;UAAE,MAAM;UAAU,aAAa;QAAY;MAAE,IAAI,CAAC,CAAC;MACpE,MAAM;QACJ,MAAM;QACN,OAAO;UAAE,MAAM;QAAS;QACxB,aAAa;MACf;IACF;EACF,CAAC;AAED,qEAAqE,GACrE,OAAO,IAAI,WAAsB;EAAC;IAChC,MAAM;IACN,OAAO;IACP,aAAa;IACb,aAAa,OAAO;IACpB,YAAY;MAAC;KAAO;IACpB,SAAS;IACT,KAAK,CAAC,MAAM,IAAM,OAAO,GAAG;EAC9B;CAAE,CAAA;AAEF;mEACmE,GACnE,OAAO,IAAI,WAAW,CAAC,KAAa;EAClC,IAAI,OAAO,IAAI,CAAC,EAAE;EAClB,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC,MAAM,OAAO;EAC1C,OAAO;IACL,MAAM;IACN,OAAO,CAAC,iBAAiB,EAAE,IAAI,IAAI,CAAC;IACpC,aAAa;IACb,aAAa,OAAO;IACpB,YAAY;MAAC;KAAO;IACpB,SAAS;IACT,KAAK,CAAC,OAAO,IAAM,OAAO,GAAG,OAAO;EACtC;AACF,EAAC"}
|
package/commands.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Remote tools and apps' commands use the same grammar as local commands.
|
|
2
|
+
// The outer command keeps only its selector flags; the receiving schema is
|
|
3
|
+
// fetched before the remaining words are parsed by argsFor.
|
|
4
|
+
import { valueIn } from '@yaks/tools/value'
|
|
5
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { argsFor, type Grammar, type Reads, Usage } from './args.js'
|
|
7
|
+
import type { Command, Ctx } from './run.ts'
|
|
8
|
+
import { printed } from './platform.js'
|
|
9
|
+
import { Refused, type Rpc } from './rpc.js'
|
|
10
|
+
import { type Result, saidBy } from './roster.js'
|
|
11
|
+
import { type Listed, type Schema, spelling } from './tool.js'
|
|
12
|
+
|
|
13
|
+
type AppCommand = {
|
|
14
|
+
name: string
|
|
15
|
+
at: string
|
|
16
|
+
input: Schema
|
|
17
|
+
positional?: Grammar['positional']
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Fetch a tool's schema, parse its words with the CLI grammar, and call it.
|
|
21
|
+
* Connector tools take precedence over the commands of reachable apps. The
|
|
22
|
+
* caller supplies the RPC door, so login and admin account selection share
|
|
23
|
+
* this whole path. */
|
|
24
|
+
export let toolCall = async (
|
|
25
|
+
ask: Rpc,
|
|
26
|
+
name: string,
|
|
27
|
+
words: string[],
|
|
28
|
+
o: { app?: string; reads?: Reads } = {},
|
|
29
|
+
): Promise<Result> => {
|
|
30
|
+
let listed = await ask('tools/list') as { tools: Listed[] }
|
|
31
|
+
let tool = listed.tools.find((t) => t.name == name)
|
|
32
|
+
if (tool) {
|
|
33
|
+
// The selected app is an argument only to a tool that takes one, and the
|
|
34
|
+
// tool's own words come after it, so its own --app wins.
|
|
35
|
+
let spelt = spelling(tool)
|
|
36
|
+
let takes = o.app && spelt.inputSchema?.properties?.app
|
|
37
|
+
let args = await argsFor(
|
|
38
|
+
{ name, ...spelt },
|
|
39
|
+
[...takes ? ['--app', o.app!] : [], ...words],
|
|
40
|
+
o.reads,
|
|
41
|
+
)
|
|
42
|
+
return await ask('tools/call', { name, arguments: args }) as Result
|
|
43
|
+
}
|
|
44
|
+
let answer = await ask('tools/call', {
|
|
45
|
+
name: 'commands',
|
|
46
|
+
arguments: o.app ? { app: o.app } : {},
|
|
47
|
+
}) as Result
|
|
48
|
+
if (answer.isError) throw new Refused(saidBy(answer).text)
|
|
49
|
+
let result = (answer.structuredContent as { result?: Bundle[] } | undefined)
|
|
50
|
+
?.result
|
|
51
|
+
let commands = result && valueIn(result)?.commands as AppCommand[] | undefined
|
|
52
|
+
if (!Array.isArray(commands)) {
|
|
53
|
+
throw new Refused('commands returned no command schemas')
|
|
54
|
+
}
|
|
55
|
+
let found = commands.filter((t) => t.name == name)
|
|
56
|
+
if (!found.length) throw new Usage(`No tool or app command named ${name}`)
|
|
57
|
+
if (found.length > 1) {
|
|
58
|
+
throw new Usage(
|
|
59
|
+
`${name} is in ${
|
|
60
|
+
found.map((t) => t.at).join(', ')
|
|
61
|
+
} — choose one with --app`,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
let command = found[0]
|
|
65
|
+
let args = await argsFor(
|
|
66
|
+
{ name, inputSchema: command.input, positional: command.positional },
|
|
67
|
+
words,
|
|
68
|
+
o.reads,
|
|
69
|
+
)
|
|
70
|
+
return await ask('tools/call', {
|
|
71
|
+
name: 'command',
|
|
72
|
+
arguments: { name, app: command.at, args },
|
|
73
|
+
}) as Result
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let called = async (
|
|
77
|
+
c: Ctx,
|
|
78
|
+
given: Record<string, unknown>,
|
|
79
|
+
app?: string,
|
|
80
|
+
): Promise<number> => {
|
|
81
|
+
let answer = await toolCall(
|
|
82
|
+
c.ask,
|
|
83
|
+
String(given.name),
|
|
84
|
+
(given.args ?? []) as string[],
|
|
85
|
+
{
|
|
86
|
+
app: app ?? given.app as string | undefined,
|
|
87
|
+
reads: c.reads,
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
return printed(c, null, 'command', answer)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let ABOUT = `Run a connector tool or one of an app's own commands. ` +
|
|
94
|
+
`--as selects a saved yaks.app account by its whole address or the part before @; ` +
|
|
95
|
+
`\`yak connection list <owner>\` lists connections (owner id or name); use a yaks.app entry’s account. ` +
|
|
96
|
+
`On the shared box, a session defaults to checks. Select --as admin for platform operations. ` +
|
|
97
|
+
`Outside a session, it is your own email, else the oldest connection. ` +
|
|
98
|
+
`Connector tools come first; \`yak commands\` lists app commands and their schemas. ` +
|
|
99
|
+
`Use positionals and --flags; --app chooses an app when two share a command. ` +
|
|
100
|
+
`Values follow the schema's types; @path reads a file and - reads stdin.`
|
|
101
|
+
|
|
102
|
+
let schema = (app: boolean): Record<string, unknown> => ({
|
|
103
|
+
type: 'object',
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
required: ['name'],
|
|
106
|
+
properties: {
|
|
107
|
+
name: { type: 'string', description: 'the tool or app command to run' },
|
|
108
|
+
...(app ? { app: { type: 'string', description: 'which app' } } : {}),
|
|
109
|
+
args: {
|
|
110
|
+
type: 'array',
|
|
111
|
+
items: { type: 'string' },
|
|
112
|
+
description: 'the command’s arguments',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
/** Remote tools and apps' commands, as subcommands of this program. */
|
|
118
|
+
export let appTools: Command[] = [{
|
|
119
|
+
name: 'command',
|
|
120
|
+
title: 'run a remote tool or app command',
|
|
121
|
+
description: ABOUT,
|
|
122
|
+
inputSchema: schema(true),
|
|
123
|
+
positional: ['name'],
|
|
124
|
+
forward: 'args',
|
|
125
|
+
run: (args, c) => called(c, args),
|
|
126
|
+
}]
|
|
127
|
+
|
|
128
|
+
/** `yak <app> <command>`: only reached when no command or command noun claims
|
|
129
|
+
* the first word, so a tool or noun of the same name always wins. */
|
|
130
|
+
export let appStray = (app: string, args: string[]): Command | undefined => {
|
|
131
|
+
let name = args[0]
|
|
132
|
+
if (!name || name.startsWith('-')) return undefined
|
|
133
|
+
return {
|
|
134
|
+
name: app,
|
|
135
|
+
title: `a command of the ${app} app`,
|
|
136
|
+
description: ABOUT,
|
|
137
|
+
inputSchema: schema(false),
|
|
138
|
+
positional: ['name'],
|
|
139
|
+
forward: 'args',
|
|
140
|
+
run: (given, c) => called(c, given, app),
|
|
141
|
+
}
|
|
142
|
+
}
|
package/complete.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
import { commandOf, typeOf } from "./tool.js";
|
|
20
|
+
import { clearable, commandFor, scanned, tokensIn } from "./args.js";
|
|
21
|
+
// Split the line into the words completion is about: the last one is the word
|
|
22
|
+
// being typed, empty where the line ended in a space. An argv array (a shell
|
|
23
|
+
// hook's COMP_WORDS) is already in that form.
|
|
24
|
+
let wordsIn = (line)=>typeof line == 'string' ? tokensIn(line, true).map((w)=>w.value) : [
|
|
25
|
+
...line
|
|
26
|
+
];
|
|
27
|
+
/** Quote a replacement word so parsing it yields the offered value. Shell
|
|
28
|
+
* argv callers already own quoting and receive raw values instead. */ export let quoted = (word)=>{
|
|
29
|
+
let eq = word.startsWith('--') ? word.indexOf('=') : -1;
|
|
30
|
+
if (eq >= 0) return word.slice(0, eq + 1) + quoted(word.slice(eq + 1));
|
|
31
|
+
return /[\s"'\\]/.test(word) || !word ? '"' + word.replace(/[\\"]/g, '\\$&') + '"' : word;
|
|
32
|
+
};
|
|
33
|
+
let props = (t)=>(t.inputSchema ?? {}).properties ?? {};
|
|
34
|
+
// Every word a tool answers to as its first: a two-word tool answers to both
|
|
35
|
+
// of its words, because the two may be typed in either order.
|
|
36
|
+
let firsts = (tools)=>tools.flatMap((t)=>t.noun && t.verb ? [
|
|
37
|
+
t.noun,
|
|
38
|
+
t.verb
|
|
39
|
+
] : [
|
|
40
|
+
commandOf(t)
|
|
41
|
+
]);
|
|
42
|
+
// The other word of a pair, given one of them.
|
|
43
|
+
let seconds = (tools, said)=>tools.flatMap((t)=>!t.noun || !t.verb ? [] : t.noun == said ? [
|
|
44
|
+
t.verb
|
|
45
|
+
] : t.verb == said ? [
|
|
46
|
+
t.noun
|
|
47
|
+
] : []);
|
|
48
|
+
// What one argument's value may be. Everything but the last two sources is in
|
|
49
|
+
// the schema itself.
|
|
50
|
+
let values = async (p, partial, look)=>{
|
|
51
|
+
if (!p) return [];
|
|
52
|
+
if (p.enum) return p.enum.map(String);
|
|
53
|
+
if (typeOf(p) == 'boolean') return [
|
|
54
|
+
'true',
|
|
55
|
+
'false'
|
|
56
|
+
];
|
|
57
|
+
let said = (p.examples ?? []).map(String);
|
|
58
|
+
if (p.ref && look.ids) said.push(...await look.ids(p.ref, partial));
|
|
59
|
+
if (p.search && look.hits) said.push(...await look.hits(partial));
|
|
60
|
+
return said;
|
|
61
|
+
};
|
|
62
|
+
let kept = (said, partial)=>[
|
|
63
|
+
...new Set(said)
|
|
64
|
+
].filter((w)=>w.toLowerCase().startsWith(partial.toLowerCase())).sort();
|
|
65
|
+
/**
|
|
66
|
+
* What could come next, given the tools and the line so far. Each result is a
|
|
67
|
+
* whole word, never the remaining characters — a shell hook and the harness's
|
|
68
|
+
* `:` prompt both replace the word being typed.
|
|
69
|
+
*/ export let complete = async (tools, line, look = {})=>{
|
|
70
|
+
let words = wordsIn(line);
|
|
71
|
+
let partial = words.at(-1) ?? '';
|
|
72
|
+
let head = words.slice(0, -1);
|
|
73
|
+
if (!head.length) return kept(firsts(tools), partial);
|
|
74
|
+
let found = commandFor(tools, head);
|
|
75
|
+
// One word in and no tool matched: it must be half of a two-word pair, and
|
|
76
|
+
// what may follow it is the other half.
|
|
77
|
+
if (!found) {
|
|
78
|
+
return head.length == 1 ? kept(seconds(tools, head[0]), partial) : [];
|
|
79
|
+
}
|
|
80
|
+
let t = found.verb;
|
|
81
|
+
let names = Object.keys(props(t));
|
|
82
|
+
let clearing = clearable(t);
|
|
83
|
+
if (clearing.length) names.push('clear');
|
|
84
|
+
let state;
|
|
85
|
+
try {
|
|
86
|
+
state = scanned(t, found.args, true);
|
|
87
|
+
} catch {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
let emit = (said)=>typeof line == 'string' ? said.map(quoted) : said;
|
|
91
|
+
if (!state.literal && partial.startsWith('--')) {
|
|
92
|
+
if (state.pending) return [];
|
|
93
|
+
let [name, ...rest] = partial.slice(2).split('=');
|
|
94
|
+
// `--name=` introduces a value, in the one form that accepts a value
|
|
95
|
+
// beginning with a dash.
|
|
96
|
+
if (rest.length) {
|
|
97
|
+
let said = name == 'clear' && clearing.length ? clearing : await values(props(t)[name], rest.join('='), look);
|
|
98
|
+
return emit(kept(said.map((v)=>`--${name}=${v}`), partial));
|
|
99
|
+
}
|
|
100
|
+
return kept(names.filter((n)=>!state.given.has(n)).map((n)=>`--${n}`), partial);
|
|
101
|
+
}
|
|
102
|
+
return emit(kept(state.awaiting == 'clear' && clearing.length ? clearing : await values(props(t)[state.awaiting ?? ''], partial, look), partial));
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=complete.js.map
|
package/complete.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.js","sources":["./complete.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,uBAAuB;AACvB,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,0EAA0E;AAC1E,+EAA+E;A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