@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/remote.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import * as system from '@yaks/process/system'
|
|
2
|
+
import { importing } from '@yaks/fp/imports'
|
|
3
|
+
// Account selection and delivery belong to the concrete host. Domain tools
|
|
4
|
+
// forward ordinary arguments and never handle credentials or MCP envelopes.
|
|
5
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { CallError } from '@yaks/tools/errors'
|
|
7
|
+
import { tokenFor } from './store.js'
|
|
8
|
+
import { doorUrl, rpc } from './rpc.js'
|
|
9
|
+
import { saidBy } from './roster.js'
|
|
10
|
+
import type { Result } from './roster.js'
|
|
11
|
+
import type { Host } from 'jsr:@yaks/host@0.2.36'
|
|
12
|
+
import { located, person } from './config.js'
|
|
13
|
+
import type { AccountOptions } from './accounts.ts'
|
|
14
|
+
import { adminForward, boxAccount, forwarded } from './account-forward.js'
|
|
15
|
+
|
|
16
|
+
type Selection = {
|
|
17
|
+
as?: string
|
|
18
|
+
via?: string
|
|
19
|
+
host?: string
|
|
20
|
+
state?: string
|
|
21
|
+
config?: string
|
|
22
|
+
env?: AccountOptions['env']
|
|
23
|
+
fetch?: typeof globalThis.fetch
|
|
24
|
+
credential?: (
|
|
25
|
+
host: string,
|
|
26
|
+
as?: string,
|
|
27
|
+
agent?: boolean,
|
|
28
|
+
) => Promise<string | null>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Authenticated JSON delivery shared by HTTP commands and graph tools. */
|
|
32
|
+
export let readJson = async (
|
|
33
|
+
url: string | URL,
|
|
34
|
+
options: Selection = {},
|
|
35
|
+
): Promise<unknown> => {
|
|
36
|
+
let origin = new URL(url)
|
|
37
|
+
if (
|
|
38
|
+
!['http:', 'https:'].includes(origin.protocol) || origin.username ||
|
|
39
|
+
origin.password
|
|
40
|
+
) {
|
|
41
|
+
throw new CallError(
|
|
42
|
+
'arguments',
|
|
43
|
+
'Choose an HTTP(S) origin without credentials',
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
let key =
|
|
47
|
+
options.host && new URL(doorUrl(options.host)).origin == origin.origin
|
|
48
|
+
? options.host
|
|
49
|
+
: origin.host
|
|
50
|
+
let token = options.credential
|
|
51
|
+
? await options.credential(key, options.as, !!options.via)
|
|
52
|
+
: await tokenFor(key, options.state, {
|
|
53
|
+
config: options.config,
|
|
54
|
+
as: options.as,
|
|
55
|
+
env: options.env,
|
|
56
|
+
agent: !!options.via,
|
|
57
|
+
})
|
|
58
|
+
let headers = new Headers({ accept: 'application/json' })
|
|
59
|
+
if (token) headers.set('authorization', `Bearer ${token}`)
|
|
60
|
+
if (options.via) headers.set('x-via', options.via)
|
|
61
|
+
let destination = forwarded(origin.href, token, false, {
|
|
62
|
+
headers,
|
|
63
|
+
redirect: 'error',
|
|
64
|
+
cache: 'no-store',
|
|
65
|
+
})
|
|
66
|
+
let response = await (options.fetch ?? globalThis.fetch)(
|
|
67
|
+
destination.url,
|
|
68
|
+
destination.init,
|
|
69
|
+
)
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
await response.body?.cancel()
|
|
72
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`.trim())
|
|
73
|
+
}
|
|
74
|
+
return await response.json()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export let remote = async (
|
|
78
|
+
name: string,
|
|
79
|
+
args: Record<string, unknown>,
|
|
80
|
+
options: {
|
|
81
|
+
as?: string
|
|
82
|
+
via?: string
|
|
83
|
+
url?: string
|
|
84
|
+
mixedAuth?: boolean
|
|
85
|
+
credential?: Selection['credential']
|
|
86
|
+
state?: string
|
|
87
|
+
config?: string
|
|
88
|
+
} = {},
|
|
89
|
+
): Promise<Bundle[]> => {
|
|
90
|
+
let origin = new URL(options.url ?? 'https://yaks.app')
|
|
91
|
+
if (
|
|
92
|
+
!['http:', 'https:'].includes(origin.protocol) || origin.username ||
|
|
93
|
+
origin.password
|
|
94
|
+
) {
|
|
95
|
+
throw new CallError(
|
|
96
|
+
'arguments',
|
|
97
|
+
'Choose an HTTP(S) origin without credentials',
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
let door = new URL(doorUrl(origin.origin))
|
|
101
|
+
if (options.mixedAuth) door.searchParams.set('auth', 'mixed')
|
|
102
|
+
let ask = rpc({
|
|
103
|
+
url: door.href,
|
|
104
|
+
token: () =>
|
|
105
|
+
options.credential
|
|
106
|
+
? options.credential(origin.origin, options.as, !!options.via)
|
|
107
|
+
: tokenFor(origin.origin, options.state, {
|
|
108
|
+
as: options.as,
|
|
109
|
+
config: options.config,
|
|
110
|
+
agent: !!options.via,
|
|
111
|
+
}),
|
|
112
|
+
via: options.via,
|
|
113
|
+
})
|
|
114
|
+
let reply = await ask('tools/call', { name, arguments: args }) as Result
|
|
115
|
+
if (reply.isError) throw new CallError('remote', saidBy(reply).text)
|
|
116
|
+
let result = (reply.structuredContent as { result?: unknown } | undefined)
|
|
117
|
+
?.result
|
|
118
|
+
if (!Array.isArray(result)) throw new Error(`${name} returned no bundles`)
|
|
119
|
+
return result as Bundle[]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Bind delivery to this host's owner and vault, including nondefault configs. */
|
|
123
|
+
export let delivery = (
|
|
124
|
+
host: Pick<Host, 'graph' | 'config' | 'vault'>,
|
|
125
|
+
): Pick<Host, 'remote' | 'readJson'> => {
|
|
126
|
+
let credential = async (
|
|
127
|
+
name: string,
|
|
128
|
+
as?: string,
|
|
129
|
+
agent?: boolean,
|
|
130
|
+
): Promise<string | null> => {
|
|
131
|
+
let explicit = system.env.get('YAKS_TOKEN')
|
|
132
|
+
if (explicit) return explicit
|
|
133
|
+
let url = new URL(doorUrl(name))
|
|
134
|
+
if (url.origin == 'https://yaks.app') {
|
|
135
|
+
as = boxAccount(host.config, as, agent)
|
|
136
|
+
let forwarded = adminForward(host.config, as)
|
|
137
|
+
if (forwarded) return forwarded
|
|
138
|
+
}
|
|
139
|
+
let owner = await person(host)
|
|
140
|
+
if (!owner || !host.graph.vocab.comp('connection')) return null
|
|
141
|
+
let { accountCredential } = await importing(
|
|
142
|
+
import.meta.resolve(located('@yaks/connections')),
|
|
143
|
+
)
|
|
144
|
+
let integration = url.hostname == 'yaks.app' ? 'yaks.app' : url.href
|
|
145
|
+
return (await accountCredential(host, owner, integration, as))?.bearer ??
|
|
146
|
+
null
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
remote: (name, args, options) =>
|
|
150
|
+
remote(name, args, { ...options, credential }),
|
|
151
|
+
readJson: (url, options) => readJson(url, { ...options, credential }),
|
|
152
|
+
}
|
|
153
|
+
}
|
package/report.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as system from "@yaks/process/system";
|
|
2
|
+
import { command as launchCommand } from "@yaks/process/command";
|
|
3
|
+
import { caught, spool } from "@yaks/tracker/report";
|
|
4
|
+
import { files } from "@yaks/tracker/file";
|
|
5
|
+
import { runtimeRoot, runtimeStack } from "./runtime.js";
|
|
6
|
+
export let revision = async ()=>{
|
|
7
|
+
let pinned = runtimeRoot() ? system.env.get('YAK_RUNTIME_COMMIT') : undefined;
|
|
8
|
+
if (pinned) return pinned;
|
|
9
|
+
if (!import.meta.url.startsWith('file:')) return undefined;
|
|
10
|
+
try {
|
|
11
|
+
let result = await launchCommand('git', {
|
|
12
|
+
args: [
|
|
13
|
+
'rev-parse',
|
|
14
|
+
'HEAD'
|
|
15
|
+
],
|
|
16
|
+
cwd: new URL('../../', import.meta.url),
|
|
17
|
+
stdout: 'piped',
|
|
18
|
+
stderr: 'null'
|
|
19
|
+
}).output();
|
|
20
|
+
return result.code == 0 ? new TextDecoder().decode(result.stdout).trim() : undefined;
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/// command(['serve', '--no-duties']) -> 'yak serve'
|
|
26
|
+
/// command(['graph', 'query', '.bug .order=-bug.hits']) -> 'yak graph query'
|
|
27
|
+
/// command(['memory', 'save', '@/tmp/body.md', '--id', 'M-1']) -> 'yak memory save'
|
|
28
|
+
/// command([]) -> 'yak'
|
|
29
|
+
/** The command a process runs, as its leading words: never an argument's
|
|
30
|
+
* value, which may be anything a person typed. */ export let command = (argv)=>{
|
|
31
|
+
let lead = argv.slice(0, 2), stop = lead.findIndex((w)=>!WORD.test(w));
|
|
32
|
+
return [
|
|
33
|
+
'yak',
|
|
34
|
+
...lead.slice(0, stop < 0 ? 2 : stop)
|
|
35
|
+
].join(' ');
|
|
36
|
+
};
|
|
37
|
+
let WORD = /^[a-z][a-z-]*$/;
|
|
38
|
+
// Callers name their invocation; a supervisor using this spool is not a yak
|
|
39
|
+
// command merely because it shares the CLI's reporting boundary.
|
|
40
|
+
export let reporter = (config, actor, commit, tags = {})=>{
|
|
41
|
+
let file = config.tracker ? spool(files(config.tracker.spool).append) : undefined;
|
|
42
|
+
let pending = new Set();
|
|
43
|
+
let report = async (error, told = {})=>{
|
|
44
|
+
let context = await told;
|
|
45
|
+
try {
|
|
46
|
+
console.error(`${context.tags?.step ?? 'box'} failed —`, error);
|
|
47
|
+
} catch {}
|
|
48
|
+
if (!file) return;
|
|
49
|
+
let at = await commit;
|
|
50
|
+
await caught(error, {
|
|
51
|
+
actor,
|
|
52
|
+
commit: config.tracker?.commit ?? at,
|
|
53
|
+
environment: 'production',
|
|
54
|
+
...context,
|
|
55
|
+
tags: {
|
|
56
|
+
source: 'box',
|
|
57
|
+
...tags,
|
|
58
|
+
...context.tags
|
|
59
|
+
},
|
|
60
|
+
sink: (rows)=>file(rows.map((row)=>{
|
|
61
|
+
let exception = row.exception;
|
|
62
|
+
return typeof exception?.stack == 'string' ? {
|
|
63
|
+
...row,
|
|
64
|
+
exception: {
|
|
65
|
+
...exception,
|
|
66
|
+
stack: runtimeStack(exception.stack)
|
|
67
|
+
}
|
|
68
|
+
} : row;
|
|
69
|
+
}))
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return Object.assign((error, context)=>{
|
|
73
|
+
let delivery = report(error, context);
|
|
74
|
+
pending.add(delivery);
|
|
75
|
+
void delivery.then(()=>pending.delete(delivery));
|
|
76
|
+
return delivery;
|
|
77
|
+
}, {
|
|
78
|
+
close: async ()=>{
|
|
79
|
+
while(pending.size)await Promise.all(pending);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=report.js.map
|
package/report.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sources":["./report.ts"],"names":[],"mappings":"AAAA,YAAY,wCAA6C;AACzD,SAAS,WAAW,aAAa,qCAA0C;AAK3E,SAAS,MAAM,EAAgB,KAAK,oCAAyC;AAC7E,SAAS,KAAK,kCAAuC;AAErD,SAAS,WAAW,EAAE,YAAY,uBAAsB;AAExD,OAAO,IAAI,WAAW;EACpB,IAAI,SAAS,gBAAgB,OAAO,GAAG,CAAC,GAAG,CAAC,wBAAwB;EACpE,IAAI,QAAQ,OAAO;EACnB,IAAI,CAAC,YAAY,GAAG,CAAC,UAAU,CAAC,UAAU,OAAO;EACjD,IAAI;IACF,IAAI,SAAS,MAAM,cAAc,OAAO;MACtC,MAAM;QAAC;QAAa;OAAO;MAC3B,KAAK,IAAI,IAAI,UAAU,YAAY,GAAG;MACtC,QAAQ;MACR,QAAQ;IACV,GAAG,MAAM;IACT,OAAO,OAAO,IAAI,IAAI,IAClB,IAAI,cAAc,MAAM,CAAC,OAAO,MAAM,EAAE,IAAI,KAC5C;EACN,EAAE,OAAM;IACN,OAAO;EACT;AACF,EAAC;AAED,oDAAoD;AACpD,6EAA6E;AAC7E,oFAAoF;AACpF,wBAAwB;AACxB;gDACgD,GAChD,OAAO,IAAI,UAAU,CAAC;EACpB,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,IAAM,CAAC,KAAK,IAAI,CAAC;EACrE,OAAO;IAAC;OAAU,KAAK,KAAK,CAAC,GAAG,OAAO,IAAI,IAAI;GAAM,CAAC,IAAI,CAAC;AAC7D,EAAC;AACD,IAAI,OAAO;AAMX,4EAA4E;AAC5E,iEAAiE;AACjE,OAAO,IAAI,WAAW,CACpB,QACA,OACA,QACA,OAAwB,CAAC,CAAC;EAK1B,IAAI,OAAO,OAAO,OAAO,GACrB,MAAM,MAAM,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,IACxC;EACJ,IAAI,UAAU,IAAI;EAClB,IAAI,SAAS,OAAO,OAAgB,OAAa,CAAC,CAAC;IACjD,IAAI,UAAU,MAAM;IACpB,IAAI;MACF,QAAQ,KAAK,CAAC,GAAG,QAAQ,IAAI,EAAE,QAAQ,MAAM,SAAS,CAAC,EAAE;IAC3D,EAAE,OAAM,CAA0C;IAClD,IAAI,CAAC,MAAM;IACX,IAAI,KAAK,MAAM;IACf,MAAM,OAAO,OAAO;MAClB;MACA,QAAQ,OAAO,OAAO,EAAE,UAAU;MAClC,aAAa;MACb,GAAG,OAAO;MACV,MAAM;QACJ,QAAQ;QACR,GAAG,IAAI;QACP,GAAG,QAAQ,IAAI;MACjB;MACA,MAAM,CAAC,OACL,KAAK,KAAK,GAAG,CAAC,CAAC;UACb,IAAI,YAAY,IAAI,SAAS;UAC7B,OAAO,OAAO,WAAW,SAAS,WAC9B;YACA,GAAG,GAAG;YACN,WAAW;cAAE,GAAG,SAAS;cAAE,OAAO,aAAa,UAAU,KAAK;YAAE;UAClE,IACE;QACN;IACJ;EACF;EACA,OAAO,OAAO,MAAM,CAAC,CAAC,OAAgB;IACpC,IAAI,WAAW,OAAO,OAAO;IAC7B,QAAQ,GAAG,CAAC;IACZ,KAAK,SAAS,IAAI,CAAC,IAAM,QAAQ,MAAM,CAAC;IACxC,OAAO;EACT,GAAG;IACD,OAAO;MACL,MAAO,QAAQ,IAAI,CAAE,MAAM,QAAQ,GAAG,CAAC;IACzC;EACF;AACF,EAAC"}
|
package/report.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as system from '@yaks/process/system'
|
|
2
|
+
import { command as launchCommand } from '@yaks/process/command'
|
|
3
|
+
// Box hosts report to a durable spool without opening the tracker graph. The
|
|
4
|
+
// tracker service owns admission, remote delivery and retry.
|
|
5
|
+
|
|
6
|
+
import type { Actor, Comp } from 'jsr:@yaks/graph@0.2.36'
|
|
7
|
+
import { caught, type Context, spool } from '@yaks/tracker/report'
|
|
8
|
+
import { files } from '@yaks/tracker/file'
|
|
9
|
+
import type { Config } from './config.ts'
|
|
10
|
+
import { runtimeRoot, runtimeStack } from './runtime.js'
|
|
11
|
+
|
|
12
|
+
export let revision = async (): Promise<string | undefined> => {
|
|
13
|
+
let pinned = runtimeRoot() ? system.env.get('YAK_RUNTIME_COMMIT') : undefined
|
|
14
|
+
if (pinned) return pinned
|
|
15
|
+
if (!import.meta.url.startsWith('file:')) return undefined
|
|
16
|
+
try {
|
|
17
|
+
let result = await launchCommand('git', {
|
|
18
|
+
args: ['rev-parse', 'HEAD'],
|
|
19
|
+
cwd: new URL('../../', import.meta.url),
|
|
20
|
+
stdout: 'piped',
|
|
21
|
+
stderr: 'null',
|
|
22
|
+
}).output()
|
|
23
|
+
return result.code == 0
|
|
24
|
+
? new TextDecoder().decode(result.stdout).trim()
|
|
25
|
+
: undefined
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// command(['serve', '--no-duties']) -> 'yak serve'
|
|
32
|
+
/// command(['graph', 'query', '.bug .order=-bug.hits']) -> 'yak graph query'
|
|
33
|
+
/// command(['memory', 'save', '@/tmp/body.md', '--id', 'M-1']) -> 'yak memory save'
|
|
34
|
+
/// command([]) -> 'yak'
|
|
35
|
+
/** The command a process runs, as its leading words: never an argument's
|
|
36
|
+
* value, which may be anything a person typed. */
|
|
37
|
+
export let command = (argv: readonly string[]): string => {
|
|
38
|
+
let lead = argv.slice(0, 2), stop = lead.findIndex((w) => !WORD.test(w))
|
|
39
|
+
return ['yak', ...lead.slice(0, stop < 0 ? 2 : stop)].join(' ')
|
|
40
|
+
}
|
|
41
|
+
let WORD = /^[a-z][a-z-]*$/
|
|
42
|
+
|
|
43
|
+
// What a report is told about its failure, or a promise of it while the
|
|
44
|
+
// caller is still learning: the reporter's close waits for that too.
|
|
45
|
+
type Told = Partial<Context> | Promise<Partial<Context>>
|
|
46
|
+
|
|
47
|
+
// Callers name their invocation; a supervisor using this spool is not a yak
|
|
48
|
+
// command merely because it shares the CLI's reporting boundary.
|
|
49
|
+
export let reporter = (
|
|
50
|
+
config: Config,
|
|
51
|
+
actor?: Actor,
|
|
52
|
+
commit?: string | Promise<string | undefined>,
|
|
53
|
+
tags: Context['tags'] = {},
|
|
54
|
+
): {
|
|
55
|
+
(error: unknown, context?: Told): Promise<void>
|
|
56
|
+
close: () => Promise<void>
|
|
57
|
+
} => {
|
|
58
|
+
let file = config.tracker
|
|
59
|
+
? spool(files(config.tracker.spool).append)
|
|
60
|
+
: undefined
|
|
61
|
+
let pending = new Set<Promise<void>>()
|
|
62
|
+
let report = async (error: unknown, told: Told = {}) => {
|
|
63
|
+
let context = await told
|
|
64
|
+
try {
|
|
65
|
+
console.error(`${context.tags?.step ?? 'box'} failed —`, error)
|
|
66
|
+
} catch { /* telemetry cannot break the caller */ }
|
|
67
|
+
if (!file) return
|
|
68
|
+
let at = await commit
|
|
69
|
+
await caught(error, {
|
|
70
|
+
actor,
|
|
71
|
+
commit: config.tracker?.commit ?? at,
|
|
72
|
+
environment: 'production',
|
|
73
|
+
...context,
|
|
74
|
+
tags: {
|
|
75
|
+
source: 'box',
|
|
76
|
+
...tags,
|
|
77
|
+
...context.tags,
|
|
78
|
+
},
|
|
79
|
+
sink: (rows) =>
|
|
80
|
+
file(rows.map((row) => {
|
|
81
|
+
let exception = row.exception as Comp | undefined
|
|
82
|
+
return typeof exception?.stack == 'string'
|
|
83
|
+
? {
|
|
84
|
+
...row,
|
|
85
|
+
exception: { ...exception, stack: runtimeStack(exception.stack) },
|
|
86
|
+
}
|
|
87
|
+
: row
|
|
88
|
+
})),
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
return Object.assign((error: unknown, context?: Told) => {
|
|
92
|
+
let delivery = report(error, context)
|
|
93
|
+
pending.add(delivery)
|
|
94
|
+
void delivery.then(() => pending.delete(delivery))
|
|
95
|
+
return delivery
|
|
96
|
+
}, {
|
|
97
|
+
close: async () => {
|
|
98
|
+
while (pending.size) await Promise.all(pending)
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
}
|
package/reported.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// A server's vocabulary drawn with this machine's copies of its packages'
|
|
2
|
+
// views: the one place a remote answer meets the plugin loader.
|
|
3
|
+
import { loadVocab } from "@yaks/vocab/runtime";
|
|
4
|
+
import { understood } from "@yaks/host/keywords";
|
|
5
|
+
import { registry } from "./answer.js";
|
|
6
|
+
import { subpath, subpaths } from "./config.js";
|
|
7
|
+
// A package a server named that this machine has no copy of: its plugins are
|
|
8
|
+
// its own, so an answer is drawn with the views that are here.
|
|
9
|
+
let elsewhere = (error)=>error instanceof TypeError && error.message.includes('not a dependency');
|
|
10
|
+
/** A vocabulary a server reported (`graph_schema`), read the way a host reads
|
|
11
|
+
* its own — with the keywords every host understands — and the views of the
|
|
12
|
+
* packages it says declared its components, where this machine has them. */ export let reported = async (doc)=>{
|
|
13
|
+
let vocab = loadVocab([
|
|
14
|
+
doc
|
|
15
|
+
], understood());
|
|
16
|
+
let plugins = vocab.all.flatMap((n)=>vocab.comp(n)?.namespace?.label ?? []);
|
|
17
|
+
let named = [
|
|
18
|
+
...new Set(plugins)
|
|
19
|
+
];
|
|
20
|
+
await subpaths(named.map((p)=>[
|
|
21
|
+
p,
|
|
22
|
+
'views'
|
|
23
|
+
])).catch((error)=>elsewhere(error) ? null : Promise.reject(error));
|
|
24
|
+
let load = (plugin)=>subpath(plugin, 'views').catch((error)=>elsewhere(error) ? null : Promise.reject(error));
|
|
25
|
+
let views = await registry(named, load);
|
|
26
|
+
return {
|
|
27
|
+
views,
|
|
28
|
+
vocab,
|
|
29
|
+
components: ()=>registry(named, load, undefined, true)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=reported.js.map
|
package/reported.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reported.js","sources":["./reported.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gEAAgE;AAChE,SAAS,SAAS,mCAAmE;AACrF,SAAS,UAAU,mCAAwC;AAE3D,SAAoB,QAAQ,sBAAiD;AAC7E,SAAS,OAAO,EAAE,QAAQ,sBAAqB;AAE/C,6EAA6E;AAC7E,+DAA+D;AAC/D,IAAI,YAAY,CAAC,QACf,iBAAiB,aAAa,MAAM,OAAO,CAAC,QAAQ,CAAC;AAEvD;;0EAE0E,GAC1E,OAAO,IAAI,WAAW,OACpB;EAIA,IAAI,QAAQ,UAAU;IAAC;GAAI,EAAE;EAC7B,IAAI,UAAU,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,IAAM,MAAM,IAAI,CAAC,IAAI,WAAW,SAAS,EAAE;EAC5E,IAAI,QAAQ;OAAI,IAAI,IAAI;GAAS;EACjC,MAAM,SAAS,MAAM,GAAG,CAAC,CAAC,IAAM;MAAC;MAAG;KAAQ,GAAY,KAAK,CAAC,CAAC,QAC7D,UAAU,SAAS,OAAO,QAAQ,MAAM,CAAC;EAE3C,IAAI,OAAc,CAAC,SACjB,QAAmB,QAAQ,SAAS,KAAK,CAAC,CAAC,QACzC,UAAU,SAAS,OAAO,QAAQ,MAAM,CAAC;EAE7C,IAAI,QAAQ,MAAM,SAAS,OAAO;EAClC,OAAO;IACL;IACA;IACA,YAAY,IAAM,SAAS,OAAO,MAAM,WAAW;EACrD;AACF,EAAC"}
|
package/reported.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// A server's vocabulary drawn with this machine's copies of its packages'
|
|
2
|
+
// views: the one place a remote answer meets the plugin loader.
|
|
3
|
+
import { loadVocab, type Vocab, type VocabDoc } from '@yaks/vocab/runtime'
|
|
4
|
+
import { understood } from '@yaks/host/keywords'
|
|
5
|
+
import type { Registry } from 'jsr:@yaks/render@0.2.36'
|
|
6
|
+
import { type Held, registry, type ViewFacet, type Views } from './answer.js'
|
|
7
|
+
import { subpath, subpaths } from './config.js'
|
|
8
|
+
|
|
9
|
+
// A package a server named that this machine has no copy of: its plugins are
|
|
10
|
+
// its own, so an answer is drawn with the views that are here.
|
|
11
|
+
let elsewhere = (error: unknown): boolean =>
|
|
12
|
+
error instanceof TypeError && error.message.includes('not a dependency')
|
|
13
|
+
|
|
14
|
+
/** A vocabulary a server reported (`graph_schema`), read the way a host reads
|
|
15
|
+
* its own — with the keywords every host understands — and the views of the
|
|
16
|
+
* packages it says declared its components, where this machine has them. */
|
|
17
|
+
export let reported = async (
|
|
18
|
+
doc: VocabDoc,
|
|
19
|
+
): Promise<
|
|
20
|
+
{ views: Registry; vocab: Vocab; components: () => Promise<Held> }
|
|
21
|
+
> => {
|
|
22
|
+
let vocab = loadVocab([doc], understood())
|
|
23
|
+
let plugins = vocab.all.flatMap((n) => vocab.comp(n)?.namespace?.label ?? [])
|
|
24
|
+
let named = [...new Set(plugins)]
|
|
25
|
+
await subpaths(named.map((p) => [p, 'views'] as const)).catch((error) =>
|
|
26
|
+
elsewhere(error) ? null : Promise.reject(error)
|
|
27
|
+
)
|
|
28
|
+
let load: Views = (plugin) =>
|
|
29
|
+
subpath<ViewFacet>(plugin, 'views').catch((error) =>
|
|
30
|
+
elsewhere(error) ? null : Promise.reject(error)
|
|
31
|
+
)
|
|
32
|
+
let views = await registry(named, load)
|
|
33
|
+
return {
|
|
34
|
+
views,
|
|
35
|
+
vocab,
|
|
36
|
+
components: () => registry(named, load, undefined, true),
|
|
37
|
+
}
|
|
38
|
+
}
|