@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/runtime.ts
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
// A command from a checkout pins its source tree: deferred imports must never
|
|
2
|
+
// read a checkout that can land. What a launch loads before it runs the
|
|
3
|
+
// snapshot is loaded with it (./yak.ts), under the checkout's land lock, and
|
|
4
|
+
// the snapshot loads its own copy of every module it runs.
|
|
5
|
+
import * as system from '@yaks/process/system'
|
|
6
|
+
import * as disk from '@yaks/file/io'
|
|
7
|
+
import { command as launchCommand } from '@yaks/process/command'
|
|
8
|
+
import { registerHooks } from 'node:module'
|
|
9
|
+
import { isAbsolute } from 'node:path'
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
11
|
+
|
|
12
|
+
let ROOT = new URL('../../', import.meta.url)
|
|
13
|
+
let decode = (bytes: Uint8Array) => new TextDecoder().decode(bytes)
|
|
14
|
+
let hex = (bytes: Uint8Array) =>
|
|
15
|
+
Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')
|
|
16
|
+
let digest = async (bytes: Uint8Array) =>
|
|
17
|
+
hex(
|
|
18
|
+
new Uint8Array(
|
|
19
|
+
await crypto.subtle.digest('SHA-256', new Uint8Array(bytes)),
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
/** Runtime metadata belongs only to code loaded from that runtime's tree,
|
|
24
|
+
* not to another checkout invoked with an inherited environment. */
|
|
25
|
+
export let runtimeRoot = (): boolean =>
|
|
26
|
+
system.env.get('YAK_RUNTIME_ROOT') == ROOT.href.replace(/\/$/, '')
|
|
27
|
+
|
|
28
|
+
// A launcher called by Git can inherit the caller's repository. Its snapshot
|
|
29
|
+
// commands still read the yak checkout and use only their own index override.
|
|
30
|
+
let gitEnv = (over?: Record<string, string>) => ({
|
|
31
|
+
...Object.fromEntries(
|
|
32
|
+
Object.entries(system.env.toObject()).filter(([key]) =>
|
|
33
|
+
!key.startsWith('GIT_')
|
|
34
|
+
),
|
|
35
|
+
),
|
|
36
|
+
...over,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
let run = async (
|
|
40
|
+
command: string,
|
|
41
|
+
args: string[],
|
|
42
|
+
cwd?: string,
|
|
43
|
+
env?: Record<string, string>,
|
|
44
|
+
) => {
|
|
45
|
+
let result = await launchCommand(command, {
|
|
46
|
+
args,
|
|
47
|
+
cwd,
|
|
48
|
+
env: gitEnv(env),
|
|
49
|
+
clearEnv: true,
|
|
50
|
+
stdout: 'piped',
|
|
51
|
+
stderr: 'piped',
|
|
52
|
+
}).output()
|
|
53
|
+
if (!result.success) throw new Error(decode(result.stderr).trim())
|
|
54
|
+
return result.stdout
|
|
55
|
+
}
|
|
56
|
+
let git = (root: string, ...args: string[]) => run('git', args, root)
|
|
57
|
+
let feed = async (
|
|
58
|
+
command: string,
|
|
59
|
+
args: string[],
|
|
60
|
+
bytes: Uint8Array,
|
|
61
|
+
cwd?: string,
|
|
62
|
+
) => {
|
|
63
|
+
let child = launchCommand(command, {
|
|
64
|
+
args,
|
|
65
|
+
cwd,
|
|
66
|
+
env: gitEnv(),
|
|
67
|
+
clearEnv: true,
|
|
68
|
+
stdin: 'piped',
|
|
69
|
+
stdout: 'null',
|
|
70
|
+
stderr: 'piped',
|
|
71
|
+
}).spawn()
|
|
72
|
+
let writer = child.stdin.getWriter()
|
|
73
|
+
await writer.write(bytes)
|
|
74
|
+
await writer.close()
|
|
75
|
+
let result = await child.output()
|
|
76
|
+
if (!result.success) throw new Error(decode(result.stderr).trim())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Which slot a launch runs from, and which idle entries go. A slot already
|
|
80
|
+
* holding these sources is shared. Otherwise the lowest number no live process
|
|
81
|
+
* runs from is rewritten: its paths repeat, so Deno's emits and the CLI's memo
|
|
82
|
+
* for unchanged files are reused, and the cache holds one tree per running
|
|
83
|
+
* version. Nothing a live process runs from is ever touched.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { assertEquals } from '@std/assert'
|
|
87
|
+
* let used = new Set(['0'])
|
|
88
|
+
* assertEquals(
|
|
89
|
+
* slot([{ name: '0', hash: 'a' }, { name: '1', hash: 'b' }], used, 'b'),
|
|
90
|
+
* { name: '1', fresh: false, prune: [] },
|
|
91
|
+
* )
|
|
92
|
+
* assertEquals(
|
|
93
|
+
* slot([{ name: '0', hash: 'a' }, { name: '9f2c' }], used, 'c'),
|
|
94
|
+
* { name: '1', fresh: true, prune: ['9f2c'] },
|
|
95
|
+
* )
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export let slot = (
|
|
99
|
+
entries: { name: string; hash?: string }[],
|
|
100
|
+
used: Set<string>,
|
|
101
|
+
hash: string,
|
|
102
|
+
): { name: string; fresh: boolean; prune: string[] } => {
|
|
103
|
+
let hit = entries.find((e) => /^\d+$/.test(e.name) && e.hash == hash)
|
|
104
|
+
let n = 0
|
|
105
|
+
while (!hit && used.has(String(n))) n++
|
|
106
|
+
let name = hit?.name ?? String(n)
|
|
107
|
+
return {
|
|
108
|
+
name,
|
|
109
|
+
fresh: !hit,
|
|
110
|
+
prune: entries.map((e) => e.name).filter((e) => e != name && !used.has(e)),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
115
|
+
|
|
116
|
+
/** The cache entries a live process runs from: a launch holds its slot's
|
|
117
|
+
* `.live` lock while it runs, and a process started from a slot's `yak.ts`
|
|
118
|
+
* names it on its command line. When processes can't be listed, every entry
|
|
119
|
+
* counts as live. */
|
|
120
|
+
let live = async (cache: string, names: string[]): Promise<Set<string>> => {
|
|
121
|
+
let used: Set<string>
|
|
122
|
+
try {
|
|
123
|
+
let { stdout } = await launchCommand('ps', {
|
|
124
|
+
args: ['-axww', '-o', 'command='],
|
|
125
|
+
stdout: 'piped',
|
|
126
|
+
stderr: 'null',
|
|
127
|
+
}).output()
|
|
128
|
+
let named = new RegExp(`${escape(cache)}/([^/\\s]+)`, 'g')
|
|
129
|
+
used = new Set([...decode(stdout).matchAll(named)].map((m) => m[1]))
|
|
130
|
+
} catch {
|
|
131
|
+
return new Set(names)
|
|
132
|
+
}
|
|
133
|
+
for (let name of names) {
|
|
134
|
+
if (used.has(name)) continue
|
|
135
|
+
let file = await disk.open(`${cache}/${name}/.live`, { write: true })
|
|
136
|
+
.catch(absent)
|
|
137
|
+
if (!file) continue
|
|
138
|
+
if (!(await file.tryLock(true))) used.add(name)
|
|
139
|
+
file.close()
|
|
140
|
+
}
|
|
141
|
+
return used
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// The commit a checkout stands at, its tracked edits as a binary patch, and
|
|
145
|
+
// its untracked files' bytes. A clean checkout, the common case, costs one
|
|
146
|
+
// status and nothing else.
|
|
147
|
+
let capture = async (root: string) => {
|
|
148
|
+
// Besides naming the commit and every change, status refreshes the index's
|
|
149
|
+
// record of each file's stat and writes it back when it can take the
|
|
150
|
+
// index's lock; a diff refreshes it only in memory. In a checkout whose
|
|
151
|
+
// index is no newer than its files (racily clean, as a new worktree's can
|
|
152
|
+
// be), a diff alone hashed every tracked file again on every launch.
|
|
153
|
+
let lines = decode(
|
|
154
|
+
await git(
|
|
155
|
+
root,
|
|
156
|
+
'status',
|
|
157
|
+
'--porcelain=v2',
|
|
158
|
+
'--branch',
|
|
159
|
+
'-z',
|
|
160
|
+
'--no-renames',
|
|
161
|
+
'--untracked-files=all',
|
|
162
|
+
),
|
|
163
|
+
).split('\0')
|
|
164
|
+
let commit = lines.find((line) => line.startsWith('# branch.oid '))!
|
|
165
|
+
.slice(13)
|
|
166
|
+
let untracked = lines.filter((line) => line.startsWith('? '))
|
|
167
|
+
.map((line) => line.slice(2))
|
|
168
|
+
let patch = lines.some((line) => /^[12u] /.test(line))
|
|
169
|
+
? await git(root, 'diff', '--binary', commit)
|
|
170
|
+
: new Uint8Array()
|
|
171
|
+
let files = await Promise.all(
|
|
172
|
+
untracked.sort().map(async (name) => ({
|
|
173
|
+
name,
|
|
174
|
+
bytes: await disk.readFile(`${root}/${name}`),
|
|
175
|
+
mode: (await disk.stat(`${root}/${name}`)).mode,
|
|
176
|
+
})),
|
|
177
|
+
)
|
|
178
|
+
return { commit, patch, files }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Capture committed sources plus the worktree's edits into a runtime slot.
|
|
182
|
+
* A slot never changes while a process runs from it. `whole` releases the
|
|
183
|
+
* checkout's land lock, held shared by the caller (./yak.ts), once the
|
|
184
|
+
* checkout is read: a landing writes it under that lock, held exclusively, so
|
|
185
|
+
* a launch never captures half a merge, and the capture's own index write
|
|
186
|
+
* never takes the index from a landing. The cache's lock keeps other
|
|
187
|
+
* launchers out until `release`, called once the command holds its slot.
|
|
188
|
+
* What runs from the slot resolves its workspace over this tree; its cwd and
|
|
189
|
+
* graph config still name the caller's data. */
|
|
190
|
+
export let snapshot = async (
|
|
191
|
+
root: string,
|
|
192
|
+
whole: () => void = () => {},
|
|
193
|
+
): Promise<
|
|
194
|
+
{ root: string; commit: string; hash: string; release: () => void }
|
|
195
|
+
> => {
|
|
196
|
+
let { commit, patch, files } = await capture(root).finally(whole)
|
|
197
|
+
let hash = await digest(new TextEncoder().encode(JSON.stringify([
|
|
198
|
+
1,
|
|
199
|
+
root,
|
|
200
|
+
commit,
|
|
201
|
+
await digest(patch),
|
|
202
|
+
await Promise.all(
|
|
203
|
+
files.map(async (
|
|
204
|
+
{ name, bytes, mode },
|
|
205
|
+
) => [name, mode, await digest(bytes)]),
|
|
206
|
+
),
|
|
207
|
+
])))
|
|
208
|
+
let cache = system.env.get('YAK_RUNTIME_CACHE') ??
|
|
209
|
+
`${
|
|
210
|
+
system.env.get('XDG_CACHE_HOME') ?? `${system.env.get('HOME')}/.cache`
|
|
211
|
+
}/yak/runtime`
|
|
212
|
+
await disk.mkdir(cache, { recursive: true })
|
|
213
|
+
let lock = await disk.open(`${cache}/.lock`, { create: true, write: true })
|
|
214
|
+
await lock.lock(true)
|
|
215
|
+
let held = true
|
|
216
|
+
let release = () => {
|
|
217
|
+
if (held) lock.close()
|
|
218
|
+
held = false
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
let entries = []
|
|
222
|
+
for await (let { name, isDirectory } of disk.readDir(cache)) {
|
|
223
|
+
if (name == '.lock') continue
|
|
224
|
+
// Every slot is a directory a launch made. Anything else was put here
|
|
225
|
+
// by something else: no slot, and not this launcher's to remove.
|
|
226
|
+
if (!isDirectory) {
|
|
227
|
+
console.error(`yak: ${cache}/${name} is no runtime slot; left alone`)
|
|
228
|
+
continue
|
|
229
|
+
}
|
|
230
|
+
let mark = await disk.readTextFile(`${cache}/${name}/.hash`)
|
|
231
|
+
.catch(() => undefined)
|
|
232
|
+
entries.push({ name, hash: mark })
|
|
233
|
+
}
|
|
234
|
+
// A slot that holds these sources is the whole cost of a warm launch:
|
|
235
|
+
// which processes are live matters only to a slot about to be written.
|
|
236
|
+
let hit = entries.find((e) => /^\d+$/.test(e.name) && e.hash == hash)
|
|
237
|
+
if (hit) return { root: `${cache}/${hit.name}`, commit, hash, release }
|
|
238
|
+
let pick = slot(
|
|
239
|
+
entries,
|
|
240
|
+
await live(cache, entries.map((e) => e.name)),
|
|
241
|
+
hash,
|
|
242
|
+
)
|
|
243
|
+
let target = `${cache}/${pick.name}`
|
|
244
|
+
for (let name of pick.prune) {
|
|
245
|
+
await disk.remove(`${cache}/${name}`, { recursive: true })
|
|
246
|
+
}
|
|
247
|
+
await build({ root, commit, patch, files, target, hash })
|
|
248
|
+
return { root: target, commit, hash, release }
|
|
249
|
+
} catch (error) {
|
|
250
|
+
release()
|
|
251
|
+
throw error
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let absent = (error: unknown): undefined => {
|
|
256
|
+
if (!(error instanceof disk.errors.NotFound)) throw error
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Write a slot, its node_modules linked from pnpm's store. A slot holds its
|
|
260
|
+
* own Git index (`.index`), and one that held a commit alone (`.base`) moves
|
|
261
|
+
* to the next as Git moves a checkout, writing only the files that differ,
|
|
262
|
+
* so the first launch after a landing writes what landed and keeps its
|
|
263
|
+
* node_modules. Any other slot is written from scratch. Its `.hash` comes
|
|
264
|
+
* last, so a slot cut short while building is never matched and is rewritten
|
|
265
|
+
* by the next launch. */
|
|
266
|
+
let build = async ({ root, commit, patch, files, target, hash }: {
|
|
267
|
+
root: string
|
|
268
|
+
commit: string
|
|
269
|
+
patch: Uint8Array
|
|
270
|
+
files: { name: string; bytes: Uint8Array; mode: number | null }[]
|
|
271
|
+
target: string
|
|
272
|
+
hash: string
|
|
273
|
+
}) => {
|
|
274
|
+
let base = await disk.readTextFile(`${target}/.base`).catch(() => undefined)
|
|
275
|
+
for (let mark of ['.hash', '.base']) {
|
|
276
|
+
await disk.remove(`${target}/${mark}`).catch(absent)
|
|
277
|
+
}
|
|
278
|
+
let tree = (...args: string[]) =>
|
|
279
|
+
run('git', ['--work-tree', target, 'read-tree', ...args], root, {
|
|
280
|
+
GIT_INDEX_FILE: `${target}/.index`,
|
|
281
|
+
})
|
|
282
|
+
let moved = !!base && await tree('-m', '-u', base, commit).then(
|
|
283
|
+
() => true,
|
|
284
|
+
() => false,
|
|
285
|
+
)
|
|
286
|
+
if (!moved) {
|
|
287
|
+
await disk.remove(target, { recursive: true }).catch(absent)
|
|
288
|
+
await disk.mkdir(target)
|
|
289
|
+
await tree('--reset', '-u', commit)
|
|
290
|
+
}
|
|
291
|
+
if (patch.length) await feed('git', ['apply', '--binary', '-'], patch, target)
|
|
292
|
+
for (let { name, bytes, mode } of files) {
|
|
293
|
+
let to = `${target}/${name}`
|
|
294
|
+
await disk.mkdir(to.slice(0, to.lastIndexOf('/')), { recursive: true })
|
|
295
|
+
await disk.writeFile(to, bytes, { mode: mode ?? undefined })
|
|
296
|
+
}
|
|
297
|
+
let { installed } = await import('./dependencies.js')
|
|
298
|
+
await installed(target, root)
|
|
299
|
+
if (!patch.length && !files.length) {
|
|
300
|
+
await disk.writeTextFile(`${target}/.base`, commit)
|
|
301
|
+
}
|
|
302
|
+
await disk.writeTextFile(`${target}/.hash`, hash)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** A file plugin inside the checkout follows the runtime's private tree too.
|
|
306
|
+
* Paths outside it, including the graph's database, keep their own identity.
|
|
307
|
+
* An absolute path stays a path, since `require` takes no URL. */
|
|
308
|
+
export let runtimePath = (
|
|
309
|
+
spec: string,
|
|
310
|
+
from = runtimeRoot() ? system.env.get('YAK_RUNTIME_FROM') : undefined,
|
|
311
|
+
to = runtimeRoot() ? system.env.get('YAK_RUNTIME_ROOT') : undefined,
|
|
312
|
+
): string => {
|
|
313
|
+
if (isAbsolute(spec)) {
|
|
314
|
+
let url = pathToFileURL(spec).href
|
|
315
|
+
let moved = runtimePath(url, from, to)
|
|
316
|
+
return moved == url ? spec : fileURLToPath(moved)
|
|
317
|
+
}
|
|
318
|
+
return from && to && spec.startsWith(from + '/')
|
|
319
|
+
? to + spec.slice(from.length)
|
|
320
|
+
: spec
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Deferred imports in a pinned runtime keep the same source tree, including
|
|
324
|
+
// absolute file imports from a provider outside that tree.
|
|
325
|
+
if (runtimeRoot()) {
|
|
326
|
+
registerHooks({
|
|
327
|
+
resolve: (specifier, context, next) =>
|
|
328
|
+
next(runtimePath(specifier), context),
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/// runtimeSource('file:///cache/0/packages/', 'file:///src', 'file:///cache/0') -> 'file:///src/packages/'
|
|
333
|
+
/// runtimeSource('file:///elsewhere/a.ts', 'file:///src', 'file:///cache/0') -> 'file:///elsewhere/a.ts'
|
|
334
|
+
/** The checkout a URL in this runtime's private tree was copied from, the
|
|
335
|
+
* inverse of {@link runtimePath}: what a plugin running git or a checkout's
|
|
336
|
+
* tools asks for, since the private tree has no `.git`. */
|
|
337
|
+
export let runtimeSource = (
|
|
338
|
+
url: string,
|
|
339
|
+
from: string | undefined = runtimeRoot()
|
|
340
|
+
? system.env.get('YAK_RUNTIME_FROM')
|
|
341
|
+
: undefined,
|
|
342
|
+
to: string | undefined = runtimeRoot()
|
|
343
|
+
? system.env.get('YAK_RUNTIME_ROOT')
|
|
344
|
+
: undefined,
|
|
345
|
+
): string =>
|
|
346
|
+
from && to && url.startsWith(to + '/') ? from + url.slice(to.length) : url
|
|
347
|
+
|
|
348
|
+
/** The private tree this runtime runs from, as a path, and the digest that
|
|
349
|
+
* names its contents (a slot's `.hash`): a slot is rewritten only while no
|
|
350
|
+
* process runs from it, so nothing inside it changes while this one runs. */
|
|
351
|
+
export let runtimeTree = (): { root: string; id: string } | undefined => {
|
|
352
|
+
let id = runtimeRoot() ? system.env.get('YAK_RUNTIME_TREE') : undefined
|
|
353
|
+
return id ? { root: fileURLToPath(ROOT).replace(/\/$/, ''), id } : undefined
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Stack traces keep the checkout's source addresses for the code catalog. */
|
|
357
|
+
export let runtimeStack = (
|
|
358
|
+
stack: string,
|
|
359
|
+
from = runtimeRoot() ? system.env.get('YAK_RUNTIME_FROM') : undefined,
|
|
360
|
+
to = runtimeRoot() ? system.env.get('YAK_RUNTIME_ROOT') : undefined,
|
|
361
|
+
): string => from && to ? stack.replaceAll(to + '/', from + '/') : stack
|
|
362
|
+
|
|
363
|
+
/** A worker's inspector is local and opt-in at launch, never a live signal:
|
|
364
|
+
* `YAK_WORK_INSPECT` names its port, 0 for any free one. */
|
|
365
|
+
export let inspector = (port: string): number => {
|
|
366
|
+
if (!/^\d+$/.test(port) || Number(port) < 0 || Number(port) > 65535) {
|
|
367
|
+
throw new Error('YAK_WORK_INSPECT must be a local port (0..65535)')
|
|
368
|
+
}
|
|
369
|
+
return Number(port)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// The flags `yak` runs with, beside its deno.json.
|
|
373
|
+
// TODO: deno.json's "no-legacy-abort" says this; Deno 2.9.1 ignores it there
|
|
374
|
+
// (./install.ts).
|
|
375
|
+
export let FLAGS = ['-q', '-A', '--unstable-no-legacy-abort']
|
|
376
|
+
|
|
377
|
+
// The open `.live` file of the slot this process runs from (`live`).
|
|
378
|
+
let held: disk.FsFile | undefined
|
|
379
|
+
|
|
380
|
+
/** Run a CLI command from immutable sources: its snapshot's own `yak.ts`, in
|
|
381
|
+
* this process. Deno resolves the snapshot's imports through the snapshot's
|
|
382
|
+
* own node_modules, so nothing the command loads comes from the checkout.
|
|
383
|
+
* `whole` releases the checkout's land lock the caller holds (./yak.ts) once
|
|
384
|
+
* the checkout is read. Deno read the checkout's deno.json as this process
|
|
385
|
+
* started, before that lock: when a landing has written it since, the command
|
|
386
|
+
* starts afresh from its snapshot in a process of its own, which names the
|
|
387
|
+
* slot on its command line. JSR releases are already immutable and never
|
|
388
|
+
* launch. */
|
|
389
|
+
export let launch = async (
|
|
390
|
+
argv: string[],
|
|
391
|
+
whole: () => void,
|
|
392
|
+
): Promise<void> => {
|
|
393
|
+
let root = fileURLToPath(ROOT).replace(/\/$/, '')
|
|
394
|
+
let { root: dir, commit, hash, release } = await snapshot(root, whole)
|
|
395
|
+
let url = pathToFileURL(dir).href
|
|
396
|
+
let env = {
|
|
397
|
+
YAK_RUNTIME_FROM: ROOT.href.replace(/\/$/, ''),
|
|
398
|
+
YAK_RUNTIME_ROOT: url,
|
|
399
|
+
YAK_RUNTIME_COMMIT: commit,
|
|
400
|
+
YAK_RUNTIME_TREE: hash,
|
|
401
|
+
}
|
|
402
|
+
let config = (await disk.stat(`${root}/deno.json`)).mtime
|
|
403
|
+
if (config && config.getTime() >= performance.timeOrigin) {
|
|
404
|
+
let child = launchCommand(system.execPath(), {
|
|
405
|
+
args: [
|
|
406
|
+
'run',
|
|
407
|
+
...FLAGS,
|
|
408
|
+
'--config',
|
|
409
|
+
`${dir}/deno.json`,
|
|
410
|
+
`${dir}/packages/cli/yak.ts`,
|
|
411
|
+
...argv,
|
|
412
|
+
],
|
|
413
|
+
env,
|
|
414
|
+
stdin: 'inherit',
|
|
415
|
+
stdout: 'inherit',
|
|
416
|
+
stderr: 'inherit',
|
|
417
|
+
}).spawn()
|
|
418
|
+
release()
|
|
419
|
+
// A terminal's interrupt reaches the command itself, which winds down.
|
|
420
|
+
system.addSignalListener('SIGINT', () => {})
|
|
421
|
+
system.addSignalListener('SIGTERM', () => child.kill('SIGTERM'))
|
|
422
|
+
return system.exit((await child.status).code)
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
held = await disk.open(`${dir}/.live`, { create: true, write: true })
|
|
426
|
+
await held.lock(false)
|
|
427
|
+
} finally {
|
|
428
|
+
release()
|
|
429
|
+
}
|
|
430
|
+
for (let [name, value] of Object.entries(env)) system.env.set(name, value)
|
|
431
|
+
let { start } = await import(`${url}/packages/cli/yak.ts`)
|
|
432
|
+
await start(argv)
|
|
433
|
+
}
|
package/sandboxes.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Bind sandbox intentions separately from existing computer transports.
|
|
2
|
+
import { Refused } from "@yaks/graph";
|
|
3
|
+
import { unlent } from "@yaks/machine/targets";
|
|
4
|
+
import { resolveOptions } from "@yaks/sandbox/configuration";
|
|
5
|
+
import { sandboxNew } from "@yaks/sandbox/lifecycle";
|
|
6
|
+
export let sandboxCapabilities = (host, config)=>({
|
|
7
|
+
request: async (id, request = {})=>{
|
|
8
|
+
let provider = request.provider ?? config.sandboxes?.defaultProvider;
|
|
9
|
+
if (!provider) {
|
|
10
|
+
throw await unlent(host.graph);
|
|
11
|
+
}
|
|
12
|
+
let { providers } = await resolveOptions(host, config.sandboxes);
|
|
13
|
+
let binding = providers[provider];
|
|
14
|
+
if (!binding) {
|
|
15
|
+
throw new Refused('Sandbox provider is not configured: ' + provider);
|
|
16
|
+
}
|
|
17
|
+
await sandboxNew(host.graph, providers, {
|
|
18
|
+
...request,
|
|
19
|
+
id,
|
|
20
|
+
provider,
|
|
21
|
+
machine: binding.machine
|
|
22
|
+
});
|
|
23
|
+
return id;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=sandboxes.js.map
|
package/sandboxes.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandboxes.js","sources":["./sandboxes.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,SAAS,OAAO,2BAAgC;AAChD,SAAS,MAAM,qCAA0C;AAEzD,SAAS,cAAc,2CAAgD;AACvE,SAAS,UAAU,uCAA4C;AAE/D,OAAO,IAAI,sBAAsB,CAC/B,MACA,SACmC,CAAC;IACpC,SAAS,OAAO,IAAI,UAAU,CAAC,CAAC;MAC9B,IAAI,WAAW,QAAQ,QAAQ,IAAI,OAAO,SAAS,EAAE;MACrD,IAAI,CAAC,UAAU;QACb,MAAM,MAAM,OAAO,KAAK,KAAK;MAC/B;MACA,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,eAAe,MAAM,OAAO,SAAS;MAC/D,IAAI,UAAU,SAAS,CAAC,SAAS;MACjC,IAAI,CAAC,SAAS;QACZ,MAAM,IAAI,QAAQ,yCAAyC;MAC7D;MACA,MAAM,WAAW,KAAK,KAAK,EAAE,WAAW;QACtC,GAAG,OAAO;QACV;QACA;QACA,SAAS,QAAQ,OAAO;MAC1B;MACA,OAAO;IACT;EACF,CAAC,EAAC"}
|
package/sandboxes.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Bind sandbox intentions separately from existing computer transports.
|
|
2
|
+
import { Refused } from '@yaks/graph'
|
|
3
|
+
import { unlent } from '@yaks/machine/targets'
|
|
4
|
+
import type { Config, Host } from 'jsr:@yaks/host@0.2.36'
|
|
5
|
+
import { resolveOptions } from '@yaks/sandbox/configuration'
|
|
6
|
+
import { sandboxNew } from '@yaks/sandbox/lifecycle'
|
|
7
|
+
|
|
8
|
+
export let sandboxCapabilities = (
|
|
9
|
+
host: Pick<Host, 'graph'>,
|
|
10
|
+
config: Config,
|
|
11
|
+
): NonNullable<Host['sandboxes']> => ({
|
|
12
|
+
request: async (id, request = {}) => {
|
|
13
|
+
let provider = request.provider ?? config.sandboxes?.defaultProvider
|
|
14
|
+
if (!provider) {
|
|
15
|
+
throw await unlent(host.graph)
|
|
16
|
+
}
|
|
17
|
+
let { providers } = await resolveOptions(host, config.sandboxes)
|
|
18
|
+
let binding = providers[provider]
|
|
19
|
+
if (!binding) {
|
|
20
|
+
throw new Refused('Sandbox provider is not configured: ' + provider)
|
|
21
|
+
}
|
|
22
|
+
await sandboxNew(host.graph, providers, {
|
|
23
|
+
...request,
|
|
24
|
+
id,
|
|
25
|
+
provider,
|
|
26
|
+
machine: binding.machine,
|
|
27
|
+
})
|
|
28
|
+
return id
|
|
29
|
+
},
|
|
30
|
+
})
|
package/searching.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The search tool's answer: the words' text hits and their meaning's, ranked
|
|
2
|
+
// together and said one line a row. Each half reads the store alone, so a
|
|
3
|
+
// host reading through two lanes runs them at once (./read_thread.ts), and
|
|
4
|
+
// the rows they rank are read and said where they are read: text a line
|
|
5
|
+
// never shows is never copied out, nor its read token hashed.
|
|
6
|
+
import { meaningWords } from "@yaks/fts/term";
|
|
7
|
+
/** A search from how its literal and semantic halves find, each asked for
|
|
8
|
+
* `count`, and how the best `limit` of what they found are said.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { searching } from './searching.ts'
|
|
12
|
+
* import { equal } from '@yaks/testing'
|
|
13
|
+
*
|
|
14
|
+
* let asked: [string, number, string][] = []
|
|
15
|
+
* let search = searching(
|
|
16
|
+
* (words, count, semantic) =>
|
|
17
|
+
* (asked.push([words, count, semantic]), Promise.resolve({ words: [], meaning: [] })),
|
|
18
|
+
* (_, __, limit) => Promise.resolve([{ entity: { eid: `${limit}` } }]),
|
|
19
|
+
* )
|
|
20
|
+
* equal(await search('mossvale', { limit: 300 }), [{ entity: { eid: '100' } }])
|
|
21
|
+
* equal(await search('mossvale', { limit: 0 }), [])
|
|
22
|
+
* await search('aster end of life', { limit: 5 })
|
|
23
|
+
* equal(asked, [
|
|
24
|
+
* ['mossvale', 200, 'mossvale'],
|
|
25
|
+
* ['aster end of life', 20, 'aster sunset'],
|
|
26
|
+
* ])
|
|
27
|
+
* ```
|
|
28
|
+
*/ export let searching = (find, say)=>async (words, opts)=>{
|
|
29
|
+
let limit = Math.max(0, Math.min(100, Math.trunc(opts?.limit ?? 20)));
|
|
30
|
+
if (!limit) return [];
|
|
31
|
+
return say(words, await find(words, Math.max(20, limit * 2), meaningWords(words)), limit);
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=searching.js.map
|
package/searching.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searching.js","sources":["./searching.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,2EAA2E;AAC3E,wEAAwE;AACxE,8DAA8D;AAK9D,SAAS,YAAY,8BAAmC;AAMxD;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,IAAI,YAAY,CACrB,MACA,MAEF,OAAO,OAAO;IACZ,IAAI,QAAQ,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC,MAAM,SAAS;IAChE,IAAI,CAAC,OAAO,OAAO,EAAE;IACrB,OAAO,IACL,OACA,MAAM,KAAK,OAAO,KAAK,GAAG,CAAC,IAAI,QAAQ,IAAI,aAAa,SACxD;EAEJ,EAAC"}
|
package/searching.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The search tool's answer: the words' text hits and their meaning's, ranked
|
|
2
|
+
// together and said one line a row. Each half reads the store alone, so a
|
|
3
|
+
// host reading through two lanes runs them at once (./read_thread.ts), and
|
|
4
|
+
// the rows they rank are read and said where they are read: text a line
|
|
5
|
+
// never shows is never copied out, nor its read token hashed.
|
|
6
|
+
|
|
7
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
8
|
+
import type { Search } from 'jsr:@yaks/graph@0.2.36/tools'
|
|
9
|
+
import type { Hit } from 'jsr:@yaks/fts@0.2.36'
|
|
10
|
+
import { meaningWords } from '@yaks/fts/term'
|
|
11
|
+
import type { MeaningHit } from 'jsr:@yaks/host@0.2.36'
|
|
12
|
+
|
|
13
|
+
/** What the two halves found for some words. */
|
|
14
|
+
export type Found = { words: Hit[]; meaning: MeaningHit[] }
|
|
15
|
+
|
|
16
|
+
/** A search from how its literal and semantic halves find, each asked for
|
|
17
|
+
* `count`, and how the best `limit` of what they found are said.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { searching } from './searching.ts'
|
|
21
|
+
* import { equal } from '@yaks/testing'
|
|
22
|
+
*
|
|
23
|
+
* let asked: [string, number, string][] = []
|
|
24
|
+
* let search = searching(
|
|
25
|
+
* (words, count, semantic) =>
|
|
26
|
+
* (asked.push([words, count, semantic]), Promise.resolve({ words: [], meaning: [] })),
|
|
27
|
+
* (_, __, limit) => Promise.resolve([{ entity: { eid: `${limit}` } }]),
|
|
28
|
+
* )
|
|
29
|
+
* equal(await search('mossvale', { limit: 300 }), [{ entity: { eid: '100' } }])
|
|
30
|
+
* equal(await search('mossvale', { limit: 0 }), [])
|
|
31
|
+
* await search('aster end of life', { limit: 5 })
|
|
32
|
+
* equal(asked, [
|
|
33
|
+
* ['mossvale', 200, 'mossvale'],
|
|
34
|
+
* ['aster end of life', 20, 'aster sunset'],
|
|
35
|
+
* ])
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export let searching = (
|
|
39
|
+
find: (words: string, count: number, semantic: string) => Promise<Found>,
|
|
40
|
+
say: (words: string, found: Found, limit: number) => Promise<Bundle[]>,
|
|
41
|
+
): Search =>
|
|
42
|
+
async (words, opts) => {
|
|
43
|
+
let limit = Math.max(0, Math.min(100, Math.trunc(opts?.limit ?? 20)))
|
|
44
|
+
if (!limit) return []
|
|
45
|
+
return say(
|
|
46
|
+
words,
|
|
47
|
+
await find(words, Math.max(20, limit * 2), meaningWords(words)),
|
|
48
|
+
limit,
|
|
49
|
+
)
|
|
50
|
+
}
|