@prestack/thread 0.1.21 → 0.1.23

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.
Files changed (138) hide show
  1. package/CHANGELOG.md +227 -0
  2. package/dist/core/attach.js +21 -0
  3. package/dist/core/descend.js +6 -3
  4. package/dist/core/generators/commit.js +55 -3
  5. package/dist/core/generators/dev.d.ts +1 -0
  6. package/dist/core/generators/dev.js +69 -0
  7. package/dist/derivation/generators/build.d.ts +3 -1
  8. package/dist/derivation/generators/build.js +104 -22
  9. package/dist/derivation/generators/release.js +74 -25
  10. package/dist/derivation/release.js +3 -3
  11. package/dist/integrations/cli.d.ts +0 -1
  12. package/dist/integrations/cli.js +69 -11
  13. package/dist/integrations/declared.d.ts +2 -0
  14. package/dist/integrations/declared.js +6 -1
  15. package/dist/integrations/pglite.js +13 -3
  16. package/dist/integrations/target.d.ts +3 -0
  17. package/dist/integrity/attach.js +1 -5
  18. package/dist/integrity/slopnators/sl_stale_path.js +10 -0
  19. package/dist/operations/access.js +3 -2
  20. package/dist/operations/capabilities.d.ts +2 -0
  21. package/dist/operations/capabilities.js +2 -0
  22. package/dist/operations/generators/capability.js +237 -24
  23. package/dist/operations/generators/compile.js +150 -50
  24. package/dist/operations/generators/seed.d.ts +3 -0
  25. package/dist/operations/generators/seed.js +25 -3
  26. package/dist/operations/nodes.d.ts +2 -2
  27. package/package.json +1 -1
  28. package/dist/core/actor.ts +0 -21
  29. package/dist/core/attach.ts +0 -613
  30. package/dist/core/chain.ts +0 -145
  31. package/dist/core/condition.ts +0 -227
  32. package/dist/core/descend.ts +0 -1185
  33. package/dist/core/errors/catalogue.ts +0 -314
  34. package/dist/core/errors/classes.ts +0 -51
  35. package/dist/core/errors/error.ts +0 -152
  36. package/dist/core/errors/namespaces.ts +0 -19
  37. package/dist/core/finding.ts +0 -37
  38. package/dist/core/generators/commit.ts +0 -157
  39. package/dist/core/init.ts +0 -222
  40. package/dist/core/invoked.ts +0 -52
  41. package/dist/core/round.ts +0 -74
  42. package/dist/core/rows.ts +0 -506
  43. package/dist/core/scope.ts +0 -20
  44. package/dist/core/thread.ts +0 -29
  45. package/dist/core/tree.ts +0 -90
  46. package/dist/core/types.ts +0 -351
  47. package/dist/derivation/attach.ts +0 -57
  48. package/dist/derivation/generators/build.ts +0 -371
  49. package/dist/derivation/generators/check.ts +0 -118
  50. package/dist/derivation/generators/determinism.ts +0 -145
  51. package/dist/derivation/generators/release.ts +0 -236
  52. package/dist/derivation/release.ts +0 -43
  53. package/dist/integrations/attach.ts +0 -187
  54. package/dist/integrations/cli.ts +0 -606
  55. package/dist/integrations/declared.ts +0 -34
  56. package/dist/integrations/disk.ts +0 -466
  57. package/dist/integrations/generators/read.ts +0 -127
  58. package/dist/integrations/generators/vault.ts +0 -210
  59. package/dist/integrations/https.ts +0 -216
  60. package/dist/integrations/pglite.ts +0 -206
  61. package/dist/integrations/secret.ts +0 -54
  62. package/dist/integrations/target.ts +0 -672
  63. package/dist/integrations/vault.ts +0 -148
  64. package/dist/integrity/attach.ts +0 -150
  65. package/dist/integrity/check-threads.ts +0 -166
  66. package/dist/integrity/constraint.ts +0 -1246
  67. package/dist/integrity/generators/compiler.ts +0 -138
  68. package/dist/integrity/generators/gate.ts +0 -227
  69. package/dist/integrity/generators/issues.ts +0 -160
  70. package/dist/integrity/generators/publish.ts +0 -233
  71. package/dist/integrity/generators/trial.ts +0 -359
  72. package/dist/integrity/lint.ts +0 -214
  73. package/dist/integrity/lsp/bin.ts +0 -44
  74. package/dist/integrity/lsp/diagnostics.ts +0 -92
  75. package/dist/integrity/lsp/findings.ts +0 -63
  76. package/dist/integrity/lsp/lint.ts +0 -124
  77. package/dist/integrity/lsp/protocol.ts +0 -78
  78. package/dist/integrity/lsp/server.ts +0 -224
  79. package/dist/integrity/slopnator.ts +0 -324
  80. package/dist/integrity/slopnators/sl_broken_lineage.ts +0 -38
  81. package/dist/integrity/slopnators/sl_declared_elsewhere.ts +0 -60
  82. package/dist/integrity/slopnators/sl_derived_drift.ts +0 -101
  83. package/dist/integrity/slopnators/sl_door_in_a_node.ts +0 -250
  84. package/dist/integrity/slopnators/sl_hardcoded_style.ts +0 -55
  85. package/dist/integrity/slopnators/sl_inert_island.ts +0 -84
  86. package/dist/integrity/slopnators/sl_inert_slopnator.ts +0 -93
  87. package/dist/integrity/slopnators/sl_missing_row.ts +0 -140
  88. package/dist/integrity/slopnators/sl_no_barrel.ts +0 -48
  89. package/dist/integrity/slopnators/sl_no_child_process.ts +0 -100
  90. package/dist/integrity/slopnators/sl_no_comment.ts +0 -43
  91. package/dist/integrity/slopnators/sl_no_dispatch_bypass.ts +0 -276
  92. package/dist/integrity/slopnators/sl_no_import_cycle.ts +0 -66
  93. package/dist/integrity/slopnators/sl_no_such_command.ts +0 -81
  94. package/dist/integrity/slopnators/sl_only_takes_a_literal.ts +0 -63
  95. package/dist/integrity/slopnators/sl_outside_an_operation.ts +0 -25
  96. package/dist/integrity/slopnators/sl_screen_holds_only_declared.ts +0 -70
  97. package/dist/integrity/slopnators/sl_secret_literal.ts +0 -68
  98. package/dist/integrity/slopnators/sl_stale_path.ts +0 -178
  99. package/dist/integrity/slopnators/sl_twice_meant.ts +0 -57
  100. package/dist/integrity/slopnators/sl_twice_parented.ts +0 -82
  101. package/dist/integrity/slopnators/sl_undeclared_crossing.ts +0 -481
  102. package/dist/integrity/slopnators/sl_undeclared_destination.ts +0 -113
  103. package/dist/integrity/slopnators/sl_undeclared_element.ts +0 -44
  104. package/dist/integrity/slopnators/sl_undeclared_list.ts +0 -358
  105. package/dist/integrity/slopnators/sl_undeclared_node.ts +0 -75
  106. package/dist/integrity/slopnators/sl_undeclared_operation.ts +0 -257
  107. package/dist/integrity/slopnators/sl_undeclared_variant.ts +0 -152
  108. package/dist/integrity/slopnators/sl_undeclared_webhook.ts +0 -108
  109. package/dist/integrity/slopnators/sl_underived_route.ts +0 -72
  110. package/dist/integrity/slopnators/sl_undescribed.ts +0 -65
  111. package/dist/integrity/slopnators/sl_ungoverned_island.ts +0 -60
  112. package/dist/integrity/slopnators/sl_unlisted_program.ts +0 -46
  113. package/dist/integrity/slopnators/sl_unnamed_island.ts +0 -41
  114. package/dist/integrity/slopnators/sl_unpaired_member.ts +0 -139
  115. package/dist/integrity/slopnators/sl_unpaired_slopnator.ts +0 -71
  116. package/dist/integrity/slopnators/sl_unprefixed_member.ts +0 -110
  117. package/dist/integrity/slopnators/sl_unthreaded.ts +0 -421
  118. package/dist/integrity/slopnators/sl_untranslated_key.ts +0 -140
  119. package/dist/integrity/slopnators/sl_unvaulted_secret.ts +0 -132
  120. package/dist/integrity/slopnators/sl_unversioned.ts +0 -52
  121. package/dist/integrity/sweep.ts +0 -395
  122. package/dist/knowledge/attach.ts +0 -327
  123. package/dist/knowledge/generators/docsgen.ts +0 -186
  124. package/dist/knowledge/generators/glossary.ts +0 -73
  125. package/dist/knowledge/glossary.ts +0 -6
  126. package/dist/operations/access.ts +0 -131
  127. package/dist/operations/attach.ts +0 -408
  128. package/dist/operations/capabilities.ts +0 -88
  129. package/dist/operations/dispatch.ts +0 -294
  130. package/dist/operations/error-results.ts +0 -31
  131. package/dist/operations/generators/capability.ts +0 -1054
  132. package/dist/operations/generators/compile.ts +0 -701
  133. package/dist/operations/generators/permits.ts +0 -229
  134. package/dist/operations/generators/seed.ts +0 -359
  135. package/dist/operations/generators/trial.ts +0 -666
  136. package/dist/operations/nodes.ts +0 -53
  137. package/dist/operations/operations.ts +0 -91
  138. package/dist/operations/result.ts +0 -28
@@ -1,466 +0,0 @@
1
- import * as disk from 'node:fs'
2
- import { basename, dirname, isAbsolute, relative, resolve } from 'node:path'
3
- import { env, pid } from 'node:process'
4
-
5
- import { ORDERS, type Answer, type Attached, type Answering, type Kind, type Listed, type Measured, type Order, type Ran } from '../integrations/target.ts'
6
-
7
- export type { Answering, Kind, Listed, Measured, Ran } from '../integrations/target.ts'
8
-
9
- export const CHANNEL = 'THREAD_CHANNEL'
10
-
11
- export const FOLDER = 'THREAD_FOLDER'
12
-
13
- const WAITING = 180_000
14
-
15
- const WORKING = 600_000
16
-
17
- const ASKING = '-asking'
18
-
19
- const ORDER = '-order'
20
-
21
- const ANSWER = '-answer'
22
-
23
- function overFiles(dir: string): Attached {
24
- const idle = new Int32Array(new SharedArrayBuffer(4))
25
- let spun = 0
26
-
27
- const ask = (body: Order): Answer => {
28
- spun += 1
29
- const name = dir + '/' + String(pid) + '-' + String(spun)
30
- const long = body.order === 'fetch' ? true : body.order === 'run'
31
- const waits = long ? WORKING : WAITING
32
- disk.writeFileSync(name + ASKING, JSON.stringify(body))
33
- disk.renameSync(name + ASKING, name + ORDER)
34
- const until = Date.now() + waits
35
- for (;;) {
36
- let held = ''
37
- try {
38
- held = disk.readFileSync(name + ANSWER, 'utf8')
39
- } catch {
40
- held = ''
41
- }
42
- if (held !== '') {
43
- disk.rmSync(name + ANSWER, { force: true })
44
- const said = JSON.parse(held) as Answer
45
- if (said.answered === 'refused') throw new Error(String(said.because))
46
- return said
47
- }
48
- if (Date.now() > until) {
49
- throw new Error(
50
- 'nothing answered ' + body.order + ' ' + body.at + ' for ' + String(Math.round(waits / 60_000)) +
51
- ' minutes, so this stopped waiting rather than spinning forever. Whoever was answering is gone. ' +
52
- 'Nothing here is half-written: one order is one file, and it was either answered or it was not.',
53
- )
54
- }
55
- Atomics.wait(idle, 0, 0, 2)
56
- }
57
- }
58
-
59
- const took = (body: Order): Answer => {
60
- const said = ask(body)
61
- const want = ORDERS[body.order]
62
- if (said.answered !== want) {
63
- throw new Error(
64
- body.order + ' ' + body.at + ' was answered as ' + said.answered + ', and that order is answered as ' + want +
65
- '. Whatever answered is not the copy of prestack this server sends orders to.',
66
- )
67
- }
68
- return said
69
- }
70
-
71
- const kinds = new Map<string, Kind>()
72
- const listed = new Map<string, readonly Listed[]>()
73
- const reals = new Map<string, string>()
74
-
75
- const listing = (at: string): readonly Listed[] => {
76
- const held = listed.get(at)
77
- if (held !== undefined) return held
78
- const found = took({ order: 'list', at }).found as readonly Listed[]
79
- listed.set(at, found)
80
- return found
81
- }
82
-
83
- const kindOf = (at: string): Kind => {
84
- const held = kinds.get(at)
85
- if (held !== undefined) return held
86
- const up = dirname(at)
87
- if (up !== at && across(up)) {
88
- const one = kindOf(up) === 'folder' ? listing(up).find((each) => each.name === basename(at)) : undefined
89
- if (one === undefined) {
90
- kinds.set(at, 'none')
91
- return 'none'
92
- }
93
- if (one.kind !== 'other') {
94
- kinds.set(at, one.kind)
95
- return one.kind
96
- }
97
- }
98
- const found = took({ order: 'kind', at }).found as Kind
99
- kinds.set(at, found)
100
- return found
101
- }
102
-
103
- const wrote = (at: string): void => {
104
- kinds.set(at, 'file')
105
- for (let child = at, up = dirname(at); up !== child && across(up); child = up, up = dirname(up)) {
106
- const inside = listed.get(up)
107
- if (inside !== undefined && !inside.some((each) => each.name === basename(child))) {
108
- listed.set(up, [...inside, { name: basename(child), kind: child === at ? 'file' : 'folder' }])
109
- }
110
- kinds.set(up, 'folder')
111
- }
112
- }
113
-
114
- const removed = (at: string): void => {
115
- for (const key of [...kinds.keys()]) if (key.startsWith(at + '/')) kinds.delete(key)
116
- for (const key of [...listed.keys()]) if (key === at || key.startsWith(at + '/')) listed.delete(key)
117
- reals.clear()
118
- kinds.set(at, 'none')
119
- const inside = listed.get(dirname(at))
120
- if (inside !== undefined) listed.set(dirname(at), inside.filter((each) => each.name !== basename(at)))
121
- }
122
-
123
- const unknown = (): void => {
124
- kinds.clear()
125
- listed.clear()
126
- reals.clear()
127
- }
128
-
129
- return {
130
- kind: kindOf,
131
- read: (at) => String(took({ order: 'read', at }).said),
132
- write: (at, said, mode) => {
133
- took(mode === undefined ? { order: 'write', at, said } : { order: 'write', at, said, mode })
134
- wrote(at)
135
- },
136
- list: listing,
137
- stat: (at) => took({ order: 'stat', at }).found as Measured,
138
- remove: (at) => {
139
- took({ order: 'remove', at })
140
- removed(at)
141
- },
142
- real: (at) => {
143
- const held = reals.get(at)
144
- if (held !== undefined) return held
145
- const found = String(took({ order: 'real', at }).at)
146
- reals.set(at, found)
147
- return found
148
- },
149
- fetch: (at, words) => {
150
- try {
151
- return String(took(words === undefined ? { order: 'fetch', at } : { order: 'fetch', at, words }).said)
152
- } finally {
153
- unknown()
154
- }
155
- },
156
- run: (at, words) => {
157
- try {
158
- return took({ order: 'run', at, words }).found as Ran
159
- } finally {
160
- unknown()
161
- }
162
- },
163
- }
164
- }
165
-
166
- const seam: { held?: Attached } = {}
167
-
168
- const WHERE = env[CHANNEL]
169
-
170
- if (WHERE !== undefined && WHERE !== '') seam.held = overFiles(WHERE)
171
-
172
- export function answeredBy(one?: Attached): void {
173
- seam.held = one
174
- }
175
-
176
- const placed = (at: string): string => {
177
- const root = env[FOLDER] ?? ''
178
- return root === '' ? at : resolve(root, at)
179
- }
180
-
181
- const within = (root: string, at: string): boolean => {
182
- const step = relative(resolve(root), resolve(root, at))
183
- return step === '' || (!step.startsWith('..') && !isAbsolute(step))
184
- }
185
-
186
- export function across(at: string): boolean {
187
- const root = env[FOLDER] ?? ''
188
- return seam.held !== undefined && root !== '' && within(root, at)
189
- }
190
-
191
- export function beyond(at: string): boolean {
192
- const root = env[FOLDER] ?? ''
193
- return seam.held !== undefined && root !== '' && !within(root, at)
194
- }
195
-
196
- function asked(at: unknown): Attached | undefined {
197
- const one = seam.held
198
- if (one === undefined) return undefined
199
- const root = env[FOLDER] ?? ''
200
- if (root === '') return typeof at === 'string' ? one : undefined
201
- if (typeof at !== 'string') {
202
- throw new Error('a path given as anything but text cannot be held to ' + root + ', the folder this answers for, so it was not used.')
203
- }
204
- if (within(root, at)) return one
205
- throw new Error(
206
- at + ' is outside ' + root + ', the folder this answers for. A command answering for a folder on another machine ' +
207
- 'reaches that folder and nothing else, so nothing was read, written or removed.',
208
- )
209
- }
210
-
211
- export function attached(): boolean {
212
- return seam.held !== undefined
213
- }
214
-
215
- export function here(): Attached {
216
- return seam.held ?? HERE
217
- }
218
-
219
- export function kind(at: string): Kind {
220
- const one = asked(at)
221
- return one === undefined ? HERE.kind(at) : one.kind(placed(at))
222
- }
223
-
224
- export function existsSync(at: disk.PathLike): boolean {
225
- return typeof at === 'string' ? kind(at) !== 'none' : asked(at) === undefined && disk.existsSync(at)
226
- }
227
-
228
- export function readFileSync(at: disk.PathOrFileDescriptor, how?: BufferEncoding): string {
229
- const one = asked(at)
230
- return one === undefined ? disk.readFileSync(at, how ?? 'utf8') : one.read(placed(at as string))
231
- }
232
-
233
- export function writeFileSync(
234
- at: disk.PathOrFileDescriptor,
235
- said: string,
236
- how?: BufferEncoding | { readonly encoding?: BufferEncoding; readonly mode?: number },
237
- ): void {
238
- const held = how === undefined || typeof how === 'string' ? { encoding: how, mode: undefined } : how
239
- const one = asked(at)
240
- if (one !== undefined) {
241
- one.write(placed(at as string), said, held.mode)
242
- return
243
- }
244
- if (typeof at === 'string') disk.mkdirSync(dirname(at), { recursive: true })
245
- disk.writeFileSync(at, said, { encoding: held.encoding ?? 'utf8', ...(held.mode === undefined ? {} : { mode: held.mode }) })
246
- }
247
-
248
- export function createFileSync(at: string, said: string): boolean {
249
- if (asked(at) !== undefined) {
250
- throw new Error(at + ' is on a machine that answers orders, and only a file on this machine can be created for one command alone.')
251
- }
252
- disk.mkdirSync(dirname(at), { recursive: true })
253
- try {
254
- disk.writeFileSync(at, said, { encoding: 'utf8', flag: 'wx' })
255
- return true
256
- } catch (thrown) {
257
- if ((thrown as NodeJS.ErrnoException).code === 'EEXIST') return false
258
- throw thrown
259
- }
260
- }
261
-
262
- export interface Named {
263
- readonly name: string
264
- readonly isFile: () => boolean
265
- readonly isDirectory: () => boolean
266
- }
267
-
268
- export function readdirSync(at: disk.PathLike): string[]
269
- export function readdirSync(at: disk.PathLike, how: { readonly withFileTypes: true }): readonly Named[]
270
- export function readdirSync(at: disk.PathLike, how?: { readonly withFileTypes: true }): string[] | readonly Named[] {
271
- const one = asked(at)
272
- if (one === undefined) return how === undefined ? disk.readdirSync(at) : disk.readdirSync(at, how)
273
- const held = one.list(placed(at as string))
274
- return how === undefined
275
- ? held.map((each) => each.name)
276
- : held.map((each) => ({ name: each.name, isFile: () => each.kind === 'file', isDirectory: () => each.kind === 'folder' }))
277
- }
278
-
279
- export interface Held extends Named, Measured {
280
- readonly mtimeMs: number
281
- }
282
-
283
- export function statSync(at: disk.PathLike): Held
284
- export function statSync(at: disk.PathLike, how: { readonly throwIfNoEntry: false }): Held | undefined
285
- export function statSync(at: disk.PathLike, how?: { readonly throwIfNoEntry: false }): Held | undefined {
286
- const one = asked(at)
287
- if (one === undefined) return (how === undefined ? disk.statSync(at) : disk.statSync(at, how)) as Held | undefined
288
- const path = placed(at as string)
289
- const held = one.kind(path)
290
- if (held === 'none') {
291
- if (how !== undefined) return undefined
292
- throw new Error(`${path} is not there, so nothing can be said about it.`)
293
- }
294
- const measured = one.stat(path)
295
- return {
296
- name: path,
297
- size: measured.size,
298
- modified: measured.modified,
299
- mtimeMs: measured.modified,
300
- isFile: () => held === 'file',
301
- isDirectory: () => held === 'folder',
302
- }
303
- }
304
-
305
- export function rmSync(at: disk.PathLike, how?: disk.RmOptions): void {
306
- const one = asked(at)
307
- if (one === undefined) disk.rmSync(at, how)
308
- else one.remove(placed(at as string))
309
- }
310
-
311
- export function rmdirSync(at: disk.PathLike): void {
312
- const one = asked(at)
313
- if (one === undefined) disk.rmdirSync(at)
314
- else one.remove(placed(at as string))
315
- }
316
-
317
- export function renameSync(from: disk.PathLike, to: disk.PathLike): void {
318
- const one = asked(from)
319
- if (one === undefined) {
320
- if (typeof to === 'string') disk.mkdirSync(dirname(to), { recursive: true })
321
- disk.renameSync(from, to)
322
- return
323
- }
324
- asked(to)
325
- one.write(placed(to as string), one.read(placed(from as string)))
326
- one.remove(placed(from as string))
327
- }
328
-
329
- export function appendFileSync(at: disk.PathOrFileDescriptor, said: string): void {
330
- const one = asked(at)
331
- if (one === undefined) {
332
- disk.appendFileSync(at, said)
333
- return
334
- }
335
- const path = placed(at as string)
336
- one.write(path, `${one.kind(path) === 'none' ? '' : one.read(path)}${said}`)
337
- }
338
-
339
- export function realpathSync(at: disk.PathLike): string {
340
- const one = asked(at)
341
- return one === undefined ? disk.realpathSync(at as string) : one.real(placed(at as string))
342
- }
343
-
344
- const FILES_ONLY = ' is on this disk, and a disk holds files. '
345
-
346
- export const HERE: Attached = {
347
- kind: (at) => {
348
- let held: disk.Stats | undefined
349
- try {
350
- held = disk.statSync(at, { throwIfNoEntry: false })
351
- } catch (thrown) {
352
- const code = (thrown as NodeJS.ErrnoException).code
353
- if (code === 'ERR_ACCESS_DENIED' || code === 'ENAMETOOLONG') return 'none'
354
- throw thrown
355
- }
356
- if (held === undefined) return 'none'
357
- return held.isFile() ? 'file' : held.isDirectory() ? 'folder' : 'other'
358
- },
359
- read: (at) => disk.readFileSync(at, 'utf8'),
360
- write: (at, said, mode) => {
361
- disk.mkdirSync(dirname(at), { recursive: true })
362
- disk.writeFileSync(at, said, { encoding: 'utf8', ...(mode === undefined ? {} : { mode }) })
363
- },
364
- list: (at) =>
365
- disk.readdirSync(at, { withFileTypes: true }).map((one) => ({
366
- name: one.name,
367
- kind: one.isFile() ? 'file' : one.isDirectory() ? 'folder' : 'other',
368
- })),
369
- stat: (at) => {
370
- const held = disk.statSync(at)
371
- return { size: held.size, modified: held.mtimeMs }
372
- },
373
- remove: (at) => {
374
- if (disk.lstatSync(at, { throwIfNoEntry: false })?.isDirectory() === true) disk.rmdirSync(at)
375
- else disk.rmSync(at)
376
- },
377
- real: (at) => disk.realpathSync(at),
378
- fetch: (at) => {
379
- throw new Error(at + FILES_ONLY + 'Installing what a tree depends on happens where somebody typed the command, so it cannot be ordered of this disk.')
380
- },
381
- run: (at) => {
382
- throw new Error(at + FILES_ONLY + 'A program is started where somebody typed the command, so running one cannot be ordered of this disk.')
383
- },
384
- }
385
-
386
- const GONE = 'is not in the scenario this trial stands, and while it runs the scenario is the whole tree.'
387
-
388
- const MADE_UP = 'a trial answers orders against a tree it made up, so there is nowhere here to '
389
-
390
- export function standing(root: string, given: ReadonlyMap<string, string>): Attached {
391
- const flat = (at: string): string => {
392
- let path = at
393
- while (path.length > 1 && path.endsWith('/')) path = path.slice(0, -1)
394
- return path
395
- }
396
- const under = (at: string): boolean => at.startsWith(root) || `${at}/` === root
397
- const own = (at: string): boolean => under(at) && !at.slice(root.length).split('/').includes('node_modules')
398
- const beside = (at: string): readonly Listed[] => {
399
- try {
400
- return HERE.list(at)
401
- } catch {
402
- return []
403
- }
404
- }
405
-
406
- const held = new Map<string, string>(given)
407
- const folders = new Set<string>()
408
- const parents = (at: string): void => {
409
- for (let up = dirname(at); under(`${up}/`); up = dirname(up)) folders.add(up)
410
- }
411
- for (const at of held.keys()) parents(at)
412
-
413
- const answers: Answering = {
414
- kind: (at) => (held.has(at) ? 'file' : folders.has(at) ? 'folder' : own(at) ? 'none' : HERE.kind(at)),
415
- read: (at) => {
416
- const said = held.get(at)
417
- if (said !== undefined) return said
418
- if (own(at)) throw new Error(`${at} ${GONE}`)
419
- return HERE.read(at)
420
- },
421
- write: (at, said) => {
422
- held.set(at, said)
423
- parents(at)
424
- },
425
- list: (at) => {
426
- const inside = new Map<string, Listed>()
427
- const found = own(at) ? [] : folders.has(at) ? beside(at) : HERE.list(at)
428
- for (const one of found) inside.set(one.name, { name: one.name, kind: one.kind === 'folder' ? 'folder' : 'file' })
429
- for (const path of folders) if (dirname(path) === at) inside.set(basename(path), { name: basename(path), kind: 'folder' })
430
- for (const path of held.keys()) if (dirname(path) === at) inside.set(basename(path), { name: basename(path), kind: 'file' })
431
- return [...inside.values()]
432
- },
433
- stat: (at) => {
434
- const said = held.get(at)
435
- if (said !== undefined) return { size: said.length, modified: 0 }
436
- if (folders.has(at)) return { size: 0, modified: 0 }
437
- if (own(at)) throw new Error(`${at} ${GONE}`)
438
- return HERE.stat(at)
439
- },
440
- remove: (at) => {
441
- held.delete(at)
442
- folders.delete(at)
443
- },
444
- real: (at) => (own(at) || held.has(at) || folders.has(at) ? at : HERE.real(at)),
445
- }
446
-
447
- return {
448
- kind: (at) => answers.kind(flat(at)),
449
- read: (at) => answers.read(flat(at)),
450
- write: (at, said) => {
451
- answers.write(flat(at), said)
452
- },
453
- list: (at) => answers.list(flat(at)),
454
- stat: (at) => answers.stat(flat(at)),
455
- remove: (at) => {
456
- answers.remove(flat(at))
457
- },
458
- real: (at) => answers.real(flat(at)),
459
- fetch: () => {
460
- throw new Error(MADE_UP + 'install anything into.')
461
- },
462
- run: () => {
463
- throw new Error(MADE_UP + 'run anything in.')
464
- },
465
- }
466
- }
@@ -1,127 +0,0 @@
1
- import { argv, stdout } from 'node:process'
2
-
3
- import { exit } from '../../core/invoked.ts'
4
- import { descend, type Row } from '../../core/descend.ts'
5
- import { THING as TYPED } from '../../core/scope.ts'
6
-
7
- const words = argv.slice(2).filter((one) => !one.startsWith('-'))
8
-
9
- const looking = words.join(' ').trim().toLowerCase()
10
-
11
- const pass = descend()
12
-
13
- const said = (one: Row): string => (one.describes ?? '').replace(/\s+/g, ' ')
14
-
15
- const carries = (one: Row, list: string, file: string): boolean => {
16
- if (looking === '') return true
17
- const held = [one.id ?? '', one.at ?? '', said(one), one.by ?? '', one.runs ?? '', list, file, ...(one.requires ?? []), ...(one.takes ?? [])]
18
- return held.some((each) => each.toLowerCase().includes(looking))
19
- }
20
-
21
- const shown = (one: Row, list: string, pad: string, alone = false): readonly string[] => {
22
- const marks = [
23
- ...(one.by === undefined ? [] : [`${list === 'stated' ? 'answers' : 'written by'} \`${one.by}\``]),
24
- ...(one.runs === undefined ? [] : [`checked by \`${one.runs}\``]),
25
- ...((one.requires ?? []).length === 0 ? [] : [`requires ${(one.requires ?? []).join(', ')}`]),
26
- ...((one.takes ?? []).length === 0 ? [] : [`takes ${(one.takes ?? []).join(', ')}`]),
27
- ]
28
- const sentence = said(one)
29
- return [
30
- `${pad}${one.id ?? '(unnamed)'} [${list}]`,
31
- ...(marks.length === 0 ? [] : [`${pad} ${marks.join(' · ')}`]),
32
-
33
- ...(sentence === ''
34
- ? []
35
- : [`${pad} ${alone || sentence.length <= 160 ? sentence : `${sentence.slice(0, 157)}...`}`]),
36
- ]
37
- }
38
-
39
- const files = [...pass.threaded.keys()].sort()
40
-
41
- const matched =
42
- files.reduce((sum, file) => sum + (pass.threaded.get(file) ?? []).filter((each) => carries(each.row, each.list, file)).length, 0) +
43
- [...pass.stated.entries()].filter(
44
- ([, one]) =>
45
- !files.some((file) => (pass.threaded.get(file) ?? []).some((each) => each.row === one)) && carries(one, 'stated', one.at ?? ''),
46
- ).length
47
-
48
- const only = matched === 1
49
-
50
- let rows = 0
51
- const out: string[] = []
52
-
53
- if (looking === '') {
54
- for (const file of files) {
55
- const held = pass.threaded.get(file) ?? []
56
- if (held.length === 0) continue
57
- rows += held.length
58
- out.push(` ${String(held.length).padStart(4)} ${file}`)
59
- }
60
- out.unshift(`${String(files.length)} sheet(s) in this tree, and what each holds:`, '')
61
- out.push(
62
- '',
63
- 'Name a word to read the rows themselves — every row whose id, sentence, path, command or',
64
- 'requirement carries it, each with what it means:',
65
- '',
66
- ` ${TYPED} inspect element`,
67
- ` ${TYPED} inspect variant`,
68
- ` ${TYPED} inspect <any word above, or any word this tree coins>`,
69
- '',
70
- )
71
- stdout.write(`${out.join('\n')}\n`)
72
- stdout.write(
73
- `read: ${String(rows)} row(s) across ${String(pass.declarations)} declaration(s), ` +
74
- `and ${String(pass.findings.length)} finding(s) the gate would report.\n`,
75
- )
76
- exit(0)
77
- }
78
-
79
- for (const file of files) {
80
- const held = (pass.threaded.get(file) ?? []).filter((each) => carries(each.row, each.list, file))
81
- if (held.length === 0) continue
82
- out.push(file)
83
- for (const each of held) {
84
- rows += 1
85
- out.push(...shown(each.row, each.list, ' ', only))
86
- }
87
- out.push('')
88
- }
89
-
90
- const loose = [...pass.stated.entries()]
91
- .filter(([, one]) => !files.some((file) => (pass.threaded.get(file) ?? []).some((each) => each.row === one)))
92
- .filter(([, one]) => carries(one, 'stated', one.at ?? ''))
93
-
94
- if (loose.length > 0) {
95
- out.push('stated outright, in no parent\'s list')
96
- for (const [, one] of loose) {
97
- rows += 1
98
- out.push(...shown(one, 'stated', ' ', only))
99
- }
100
- out.push('')
101
- }
102
-
103
- if (looking !== '') {
104
- const coined = [...pass.coined.entries()].filter(([word]) => word.toLowerCase().includes(looking))
105
- if (coined.length > 0) {
106
- out.push('words this tree coins')
107
- for (const [word, held] of coined) out.push(` ${word} — declared under ${held.under}`)
108
- out.push('')
109
- }
110
- }
111
-
112
- stdout.write(`${out.join('\n')}\n`)
113
-
114
- if (rows === 0) {
115
- stdout.write(
116
- looking === ''
117
- ? 'read: this tree declares nothing yet. Attach a package with `thread attach`.\n'
118
- : `read: nothing in this tree carries "${looking}" — not an id, a sentence, a path, a command, a requirement or a thing taken.\n`,
119
- )
120
- exit(0)
121
- }
122
-
123
- stdout.write(
124
- `read: ${String(rows)} row(s)${looking === '' ? '' : ` carrying "${looking}"`} across ` +
125
- `${String(pass.declarations)} declaration(s), and ${String(pass.findings.length)} finding(s) the gate would report.\n`,
126
- )
127
- exit(0)