@joe-broadhead/opencode-mem 0.9.14 → 0.11.3
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/CHANGELOG.md +1856 -0
- package/README.md +15 -7
- package/SECURITY.md +3 -1
- package/docs/agent-instructions.md +1 -1
- package/docs/agent-protocol.md +7 -7
- package/docs/permissions.md +16 -0
- package/package.json +8921 -1070
- package/shared/page-paths.js +44 -0
- package/skills/mem.pages/SKILL.md +3 -1
- package/skills/mem.usage/SKILL.md +15 -15
- package/src/action-grant-keys.js +159 -0
- package/src/action-grant.js +439 -0
- package/src/actions.js +1690 -0
- package/src/backend/records.js +25 -2
- package/src/backend/v3.js +76 -22
- package/src/call-shapes.js +17 -16
- package/src/collector-lock.js +533 -62
- package/src/collector-service.js +153 -26
- package/src/collector.js +623 -30
- package/src/config.js +88 -7
- package/src/connect.js +106 -8
- package/src/credentials.js +123 -25
- package/src/events.js +174 -3
- package/src/forget-turn.js +141 -0
- package/src/host-refusal.js +78 -0
- package/src/index.js +209 -22
- package/src/jobs/host.js +557 -0
- package/src/ops/codes.js +110 -0
- package/src/ops/copy-lineage.js +42 -0
- package/src/ops/index.js +28 -0
- package/src/ops/space-ops.js +1936 -0
- package/src/outlinks.js +103 -0
- package/src/p2-reservation.js +151 -0
- package/src/permissions.js +30 -0
- package/src/plugins/descriptor.js +62 -0
- package/src/plugins/discovery.js +318 -0
- package/src/plugins/grants.js +178 -0
- package/src/plugins/locate.js +319 -0
- package/src/plugins/manifest.js +1162 -0
- package/src/plugins/source-contract/index.js +34 -0
- package/src/plugins/source-contract/policy.js +102 -0
- package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
- package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
- package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
- package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
- package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
- package/src/plugins/source-contract/vendor/broker-client.js +93 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/plugins/source-contract/vendor/cursor.js +26 -0
- package/src/plugins/source-contract/vendor/descriptor.js +34 -0
- package/src/plugins/source-contract/vendor/events.js +257 -0
- package/src/plugins/source-contract/vendor/index.js +10 -0
- package/src/plugins/source-contract/vendor/params.js +22 -0
- package/src/plugins/source-contract/vendor/permission.js +28 -0
- package/src/plugins/source-contract/vendor/pick.js +22 -0
- package/src/plugins/source-contract/vendor/read.js +29 -0
- package/src/plugins/source-contract/vendor/registry.js +23 -0
- package/src/plugins/source-contract/vendor/schema.js +17 -0
- package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
- package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
- package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
- package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
- package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
- package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
- package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
- package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
- package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
- package/src/plugins/source-contract/vendor/schemas.js +19 -0
- package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
- package/src/plugins/verify.js +56 -0
- package/src/protocol.js +11 -6
- package/src/recall.js +92 -5
- package/src/records.js +61 -2
- package/src/requests.js +216 -0
- package/src/runtime.js +89 -7
- package/src/setup-time.js +68 -0
- package/src/skills.js +230 -8
- package/src/source-ids.js +25 -0
- package/src/sources/declaration.js +365 -0
- package/src/sources/reads.js +772 -0
- package/src/sources/rpc.js +151 -0
- package/src/sources.js +389 -92
- package/src/spaces.js +283 -11
- package/src/spool.js +61 -4
- package/src/stated.js +10 -5
- package/src/storable.js +139 -0
- package/src/tools/commitments.js +74 -23
- package/src/tools/held-write.js +46 -19
- package/src/tools/index.js +28 -0
- package/src/tools/ingest.js +38 -2
- package/src/tools/memory.js +56 -25
- package/src/tools/page.js +212 -95
- package/src/tools/recall.js +218 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +84 -6
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +381 -30
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +231 -116
- package/src/util.js +110 -6
- package/src/vendor/source-contract/README.md +24 -0
- package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
- package/src/vendor/source-contract/VENDOR.json +81 -0
- package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/vendor/source-contract/cursor.js +26 -0
- package/src/vendor/source-contract/events.js +257 -0
- package/src/vendor/source-contract/registry.js +23 -0
- package/src/vendor/source-contract/tools-rpc.js +42 -0
- package/src/views/access-reads.js +256 -0
- package/src/views/communities.js +77 -0
- package/src/views/contracts.js +1082 -23
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +26 -1
- package/src/views/records-reads.js +520 -41
- package/src/views/rpc.js +153 -25
- package/src/views/shape.js +8 -5
- package/src/views/write-state.js +89 -0
- package/src/wiki-ingest.js +215 -0
- package/src/wiki-state.js +228 -0
- package/views/pages.html +2 -2
|
@@ -18,9 +18,17 @@ import {
|
|
|
18
18
|
LINKS_MAX,
|
|
19
19
|
LIST_MAX,
|
|
20
20
|
MEMORY_TEXT_CHARS,
|
|
21
|
+
NAME_ALIASES_MAX,
|
|
22
|
+
NAME_KINDS,
|
|
23
|
+
NAMES_MAX,
|
|
24
|
+
NAMES_PAGE,
|
|
25
|
+
NAMES_PAGE_TYPES,
|
|
26
|
+
NAMES_SCAN_PAGES,
|
|
21
27
|
OWNER_ID_CHARS,
|
|
22
28
|
OWNER_NAME_CHARS,
|
|
23
29
|
PAGES_MAX,
|
|
30
|
+
PROJECTS_MAX,
|
|
31
|
+
PROPOSAL_SOURCES_MAX,
|
|
24
32
|
RECENT_CONCURRENCY,
|
|
25
33
|
RECENT_MAX_OFFSET,
|
|
26
34
|
RECENT_PAGE,
|
|
@@ -32,6 +40,7 @@ import {
|
|
|
32
40
|
REVIEW_MAX,
|
|
33
41
|
ROUTINE_OWNER,
|
|
34
42
|
SOURCE_CHARS,
|
|
43
|
+
SPACE_GRANT_ONLY,
|
|
35
44
|
STATUS_CHARS,
|
|
36
45
|
SUMMARY_CHARS,
|
|
37
46
|
TASK_CHARS,
|
|
@@ -46,6 +55,8 @@ import { dayIn } from "../records.js"
|
|
|
46
55
|
import { oneLine } from "../util.js"
|
|
47
56
|
import { ANSWER_BYTES, SPACE_KINDS, clip, clipText, fitList, idOf, jsonBytes, mapLimit, refuse, sourceLabel, spaceOf } from "./shape.js"
|
|
48
57
|
import { PAGE_TYPES } from "../tools/records-kit.js"
|
|
58
|
+
import { communitiesOf } from "./communities.js"
|
|
59
|
+
import { holdsSpaceRead, readOutlinks } from "../outlinks.js"
|
|
49
60
|
|
|
50
61
|
/**
|
|
51
62
|
* The views' reads of the records service (docs/design/memory-v1-contracts.md
|
|
@@ -338,6 +349,39 @@ export function recentFilters(input) {
|
|
|
338
349
|
}
|
|
339
350
|
}
|
|
340
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Name each node's community, from the answer's own nodes and edges
|
|
354
|
+
* (`communitiesOf`): every node of a graph answer carries one, so a host can
|
|
355
|
+
* colour the graph, and a node cut from the answer is in no community.
|
|
356
|
+
*
|
|
357
|
+
* The grouping is the graph's, not the order the service returned it in: the
|
|
358
|
+
* nodes are put in one canonical order first (by path, then id, then their place
|
|
359
|
+
* in the answer) and the edges follow them, so two reads of the same pages give
|
|
360
|
+
* the same communities whatever order they arrive in.
|
|
361
|
+
*
|
|
362
|
+
* @param {{ nodes: Array<Record<string, unknown>>, edges: Array<{ from: number, to: number }> }} answer
|
|
363
|
+
*/
|
|
364
|
+
function addCommunities(answer) {
|
|
365
|
+
const canonical = answer.nodes.map((_, index) => index)
|
|
366
|
+
const key = (index) => String(answer.nodes[index]?.path ?? "")
|
|
367
|
+
const second = (index) => String(answer.nodes[index]?.id ?? "")
|
|
368
|
+
canonical.sort((a, b) => {
|
|
369
|
+
const left = key(a)
|
|
370
|
+
const right = key(b)
|
|
371
|
+
if (left !== right) return left < right ? -1 : 1
|
|
372
|
+
const leftId = second(a)
|
|
373
|
+
const rightId = second(b)
|
|
374
|
+
if (leftId !== rightId) return leftId < rightId ? -1 : 1
|
|
375
|
+
return a - b
|
|
376
|
+
})
|
|
377
|
+
const place = new Map(canonical.map((index, at) => [index, at]))
|
|
378
|
+
const edges = answer.edges
|
|
379
|
+
.map((edge) => ({ from: place.get(edge.from), to: place.get(edge.to) }))
|
|
380
|
+
.sort((a, b) => a.from - b.from || a.to - b.to)
|
|
381
|
+
const groups = communitiesOf(canonical.length, edges)
|
|
382
|
+
for (const [at, index] of canonical.entries()) answer.nodes[index].community = groups[at]
|
|
383
|
+
}
|
|
384
|
+
|
|
341
385
|
/**
|
|
342
386
|
* @param {{ runtime: any, personalScopes: () => Promise<Array<{ context: any }>>, available: () => Promise<void>, describe?: (error: unknown) => string }} input
|
|
343
387
|
* `describe` says a failed read in words (a space that could not be read is
|
|
@@ -375,10 +419,16 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
375
419
|
if (!found) refuse("That space isn't one of yours.")
|
|
376
420
|
return {
|
|
377
421
|
where: { ...(scope ? { scope } : {}), space: spaceId },
|
|
378
|
-
space: {
|
|
422
|
+
space: {
|
|
423
|
+
id: spaceId,
|
|
424
|
+
name: clip(found.name || spaceId, 200),
|
|
425
|
+
kind: SPACE_KINDS.has(found.kind) ? found.kind : "unknown",
|
|
426
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
427
|
+
},
|
|
428
|
+
spaceRead: holdsSpaceRead({ role: found.role, space_kind: found.kind }),
|
|
379
429
|
}
|
|
380
430
|
}
|
|
381
|
-
return { where: whereOf(first), space: spaceOf(first?.context ?? null) }
|
|
431
|
+
return { where: whereOf(first), space: spaceOf(first?.context ?? null), spaceRead: holdsSpaceRead(first?.context ?? null) }
|
|
382
432
|
}
|
|
383
433
|
|
|
384
434
|
/** `{ path }` or `{ id }` from a view's input; one of them, checked. */
|
|
@@ -411,43 +461,78 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
411
461
|
}
|
|
412
462
|
|
|
413
463
|
/**
|
|
414
|
-
* The people in a space,
|
|
415
|
-
*
|
|
416
|
-
*
|
|
464
|
+
* The people in a space, as the space's own member roster names them
|
|
465
|
+
* (`control.listMembers`, which control scopes to a viewer of the space: the
|
|
466
|
+
* person's own, or one they chose, with the caller's own token). Read once
|
|
417
467
|
* per view call and never kept between calls, so no person's read answers with
|
|
418
468
|
* a roster read under someone else's access. A roster that cannot be read is
|
|
419
|
-
* no
|
|
469
|
+
* no members, never a failed read: the page is then named no owner.
|
|
470
|
+
*
|
|
471
|
+
* Keyed by the id a record's `owner` carries, which is not the roster's own. The
|
|
472
|
+
* records service keeps the **upstream** user id the gateway sends it
|
|
473
|
+
* (`x-records-user`, from `context.user.upstream_id`;
|
|
474
|
+
* deploy/auth/records-scope.mjs), while control's roster knows the person by its
|
|
475
|
+
* own `user_id` (`usr_…`). Matching one against the other by equality names
|
|
476
|
+
* nobody, which is why every page carried no owner until the roster learned to
|
|
477
|
+
* carry each member's upstream id too. The member itself is kept so `owner.id`
|
|
478
|
+
* can be control's own `user_id` — the person's id everywhere else (a space's
|
|
479
|
+
* members read, `src/tools/spaces.js`) — and never the core's: an id Jelly
|
|
480
|
+
* cannot relate to a member it can see, and one it should not see at all.
|
|
420
481
|
*/
|
|
421
482
|
async function memberNames(spaceId) {
|
|
422
|
-
const
|
|
483
|
+
const members = new Map()
|
|
423
484
|
const id = idOf(spaceId)
|
|
424
|
-
if (!id || id === "local" || !runtime.control || typeof runtime.control.listMembers !== "function") return
|
|
485
|
+
if (!id || id === "local" || !runtime.control || typeof runtime.control.listMembers !== "function") return members
|
|
425
486
|
try {
|
|
426
|
-
const
|
|
427
|
-
|
|
487
|
+
const roster = (await runtime.control.listMembers({ userId: runtime.config?.user, spaceId: id })) ?? []
|
|
488
|
+
/** Two people answering to one key would name the wrong one; that key names nobody. */
|
|
489
|
+
const shared = new Set()
|
|
490
|
+
const claim = (key, person) => {
|
|
491
|
+
const seen = members.get(key)
|
|
492
|
+
if (seen && seen.id !== person.id) shared.add(key)
|
|
493
|
+
else members.set(key, person)
|
|
494
|
+
}
|
|
495
|
+
for (const member of roster) {
|
|
428
496
|
const user = idOf(member?.user_id)
|
|
429
497
|
const name = typeof member?.name === "string" ? oneLine(member.name, OWNER_NAME_CHARS).trim() : ""
|
|
430
|
-
if (user
|
|
498
|
+
if (!user || !name) continue
|
|
499
|
+
// One key, the one that person's records are written under: their
|
|
500
|
+
// upstream id, or their own user id when control has no upstream id for
|
|
501
|
+
// them (the gateway sends that as `x-records-user` instead). Never both,
|
|
502
|
+
// so a record owned by someone else, whose upstream id happens to equal
|
|
503
|
+
// this member's user id, does not name this member.
|
|
504
|
+
claim(idOf(member?.upstream_user_id) || user, { id: user, name })
|
|
431
505
|
}
|
|
506
|
+
for (const key of shared) members.delete(key)
|
|
432
507
|
} catch (error) {
|
|
433
508
|
runtime.log?.debug?.("view: the space's roster was not read", { space: id, error: error?.message })
|
|
434
509
|
}
|
|
435
|
-
return
|
|
510
|
+
return members
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The roster member a record's `owner` names, by the id that record was written
|
|
515
|
+
* under (the roster's key). Null for no owner, for one the roster cannot name,
|
|
516
|
+
* and for the routines' own user (which owns what a routine writes and is no
|
|
517
|
+
* person).
|
|
518
|
+
*/
|
|
519
|
+
const memberFor = (members, owner) => {
|
|
520
|
+
const id = idOf(owner)
|
|
521
|
+
return id && id !== ROUTINE_OWNER ? (members.get(id) ?? null) : null
|
|
436
522
|
}
|
|
437
523
|
|
|
438
524
|
/**
|
|
439
|
-
* A page's owning person, where Memory can **name** them: the
|
|
440
|
-
* record
|
|
441
|
-
*
|
|
525
|
+
* A page's owning person, where Memory can **name** them: the roster member the
|
|
526
|
+
* record's `owner` names (by the upstream id the record holds), shown as
|
|
527
|
+
* control's own `user_id` and the name the roster gives them. `{}` otherwise,
|
|
528
|
+
* and the field is left out rather than filled with an id: an id is not a name.
|
|
442
529
|
* That is the usual answer for a reader with only a page grant, whom control
|
|
443
530
|
* refuses the space's member list (it needs viewer), and it is always the answer
|
|
444
531
|
* for the routines' own user, which owns what a routine writes and is no person.
|
|
445
532
|
*/
|
|
446
533
|
async function ownerOf(record, spaceId) {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
const name = (await memberNames(spaceId)).get(id)
|
|
450
|
-
return name ? { owner: { id: clip(id, OWNER_ID_CHARS), name: clip(name, OWNER_NAME_CHARS) } } : {}
|
|
534
|
+
const member = memberFor(await memberNames(spaceId), record?.owner)
|
|
535
|
+
return member ? { owner: { id: clip(member.id, OWNER_ID_CHARS), name: clip(member.name, OWNER_NAME_CHARS) } } : {}
|
|
451
536
|
}
|
|
452
537
|
|
|
453
538
|
/** Today in the person's zone, as a bare date is compared with a page's review day. */
|
|
@@ -561,7 +646,12 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
561
646
|
seen.add(spaceId)
|
|
562
647
|
others.push({
|
|
563
648
|
where: { ...(scope ? { scope } : {}), space: spaceId },
|
|
564
|
-
space: {
|
|
649
|
+
space: {
|
|
650
|
+
id: spaceId,
|
|
651
|
+
name: clip(space.name || spaceId, 200),
|
|
652
|
+
kind: SPACE_KINDS.has(space.kind) ? space.kind : "unknown",
|
|
653
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
654
|
+
},
|
|
565
655
|
})
|
|
566
656
|
}
|
|
567
657
|
const room = Math.max(0, RECENT_SPACES_MAX - 1)
|
|
@@ -733,6 +823,155 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
733
823
|
return out
|
|
734
824
|
}
|
|
735
825
|
|
|
826
|
+
/**
|
|
827
|
+
* The names of the people, projects and teams Memory knows, and the entries
|
|
828
|
+
* its glossary pages state, for a host's dictation vocabulary (0.10.2; Jelly's
|
|
829
|
+
* asks 3 and 6). Read over the same spaces a recent list is
|
|
830
|
+
* (`recentTargets`): the person's own first, then the shared spaces control
|
|
831
|
+
* lists for them, each read on its own and each failure or skipped space named
|
|
832
|
+
* in `incomplete`. No space id, no path and no count is returned: a caller
|
|
833
|
+
* gets what it would say, and nothing about where the page lives.
|
|
834
|
+
*
|
|
835
|
+
* **Every page of a kind, not the newest few.** Each list read asks the service
|
|
836
|
+
* for `NAMES_PAGE_TYPES` only (`person`, `project`, `team`, `glossary`), so a
|
|
837
|
+
* space with thousands of newer journals and topics still offers its people,
|
|
838
|
+
* and follows the cursor for up to `NAMES_SCAN_PAGES` pages. A space with more
|
|
839
|
+
* than that says `more` rather than looking complete.
|
|
840
|
+
*
|
|
841
|
+
* **Order is deterministic: the most referenced name first, then by name.** A
|
|
842
|
+
* name is referenced by the pages of the same read that link to it (`links`,
|
|
843
|
+
* which a list row already carries); a glossary entry takes its glossary
|
|
844
|
+
* page's count. Only pages the caller may read are in the read, so a link from
|
|
845
|
+
* a page outside a grant is never counted. A name two spaces both know is one
|
|
846
|
+
* entry, its aliases together, so the same memory answers the same way every
|
|
847
|
+
* call.
|
|
848
|
+
*
|
|
849
|
+
* Bounded: at most `NAMES_SCAN_PAGES` reads of `NAMES_PAGE` rows per space, at
|
|
850
|
+
* most `NAMES_MAX` names, and no more than `TERM_GLOSSARIES_MAX` glossary
|
|
851
|
+
* bodies read per space (as `terms.list` does).
|
|
852
|
+
*/
|
|
853
|
+
async function namesKnown(input) {
|
|
854
|
+
await available()
|
|
855
|
+
if (input && Object.keys(input).length > 0) refuse("names.known takes no options.")
|
|
856
|
+
const { targets, skipped } = await recentTargets({})
|
|
857
|
+
const results = await mapLimit(targets, RECENT_CONCURRENCY, async (entry) => {
|
|
858
|
+
try {
|
|
859
|
+
const pages = []
|
|
860
|
+
let cursor = null
|
|
861
|
+
let cut = false
|
|
862
|
+
for (let scan = 0; scan < NAMES_SCAN_PAGES; scan += 1) {
|
|
863
|
+
const answer = await records(
|
|
864
|
+
"records.list",
|
|
865
|
+
{ kind: "page", type: [...NAMES_PAGE_TYPES], limit: NAMES_PAGE, ...(cursor ? { cursor } : {}) },
|
|
866
|
+
entry.where,
|
|
867
|
+
)
|
|
868
|
+
pages.push(...(answer?.records ?? []).filter((record) => idOf(record?.path)))
|
|
869
|
+
cursor = typeof answer?.cursor === "string" && answer.cursor ? answer.cursor : null
|
|
870
|
+
if (!cursor) break
|
|
871
|
+
}
|
|
872
|
+
// A cursor still to follow is a space with more pages than one scan reads.
|
|
873
|
+
cut = Boolean(cursor)
|
|
874
|
+
const glossaries = pages.filter((record) => record.type === "glossary")
|
|
875
|
+
const read = glossaries.slice(0, TERM_GLOSSARIES_MAX)
|
|
876
|
+
let bodies = []
|
|
877
|
+
if (read.length > 0) {
|
|
878
|
+
const answer = await records("records.get", { paths: read.map((record) => record.path) }, entry.where)
|
|
879
|
+
bodies = answer?.records ?? []
|
|
880
|
+
}
|
|
881
|
+
return { entry, pages, glossaries: read, bodies, cut, past: glossaries.length > read.length }
|
|
882
|
+
} catch (error) {
|
|
883
|
+
runtime.log?.warn?.(`view names.known: a read in space ${entry.space.id} failed`, error)
|
|
884
|
+
return { entry, error }
|
|
885
|
+
}
|
|
886
|
+
})
|
|
887
|
+
const failed = results.filter((result) => result.error !== undefined)
|
|
888
|
+
if (!results.some((result) => Array.isArray(result.pages))) throw failed[0].error
|
|
889
|
+
// A glossary page's own title is its subject, not a name: only its entries are.
|
|
890
|
+
const kindOf = Object.freeze({ person: "person", project: "project", team: "team" })
|
|
891
|
+
const names = []
|
|
892
|
+
for (const result of results) {
|
|
893
|
+
if (!result.pages) continue
|
|
894
|
+
// How many pages of this space link to each page: a name's references.
|
|
895
|
+
const references = new Map()
|
|
896
|
+
for (const record of result.pages) {
|
|
897
|
+
for (const link of Array.isArray(record?.links) ? record.links : []) {
|
|
898
|
+
const target = String(link ?? "").trim()
|
|
899
|
+
if (!target) continue
|
|
900
|
+
references.set(target, (references.get(target) ?? 0) + 1)
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const refsOf = (record) => Math.max(0, references.get(record.path) ?? 0) + Math.max(0, references.get(idOf(record.id)) ?? 0)
|
|
904
|
+
for (const record of result.pages) {
|
|
905
|
+
const kind = kindOf[record.type]
|
|
906
|
+
if (!kind) continue
|
|
907
|
+
const name = clipText(plainLine(record.title || String(record.path).split("/").pop()), TERM_TEXT_CHARS, 320).text
|
|
908
|
+
if (name) names.push({ name, kind, refs: refsOf(record), space: result.entry.space.id, path: idOf(record.path), aliases: aliasesOf(record, name) })
|
|
909
|
+
}
|
|
910
|
+
// A glossary page's own title is not a name; its entries are, under the page's own count.
|
|
911
|
+
for (const record of result.bodies) {
|
|
912
|
+
const page = result.glossaries.find((glossary) => glossary.path === record?.path)
|
|
913
|
+
const refs = page ? refsOf(page) : 0
|
|
914
|
+
for (const name of glossaryEntries(record?.body)) {
|
|
915
|
+
names.push({ name, kind: "term", refs, space: result.entry.space.id, path: idOf(record?.path), aliases: [] })
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const rank = new Map(NAME_KINDS.map((kind, index) => [kind, index]))
|
|
920
|
+
names.sort(
|
|
921
|
+
(a, b) =>
|
|
922
|
+
b.refs - a.refs ||
|
|
923
|
+
a.name.localeCompare(b.name, "en-GB") ||
|
|
924
|
+
rank.get(a.kind) - rank.get(b.kind) ||
|
|
925
|
+
a.path.localeCompare(b.path) ||
|
|
926
|
+
a.space.localeCompare(b.space),
|
|
927
|
+
)
|
|
928
|
+
// One entry per name: the most referenced one says it, and the aliases of
|
|
929
|
+
// the others join it.
|
|
930
|
+
const merged = new Map()
|
|
931
|
+
for (const name of names) {
|
|
932
|
+
const key = name.name.toLocaleLowerCase("en-GB")
|
|
933
|
+
const kept = merged.get(key)
|
|
934
|
+
if (!kept) {
|
|
935
|
+
merged.set(key, { name: name.name, kind: name.kind, aliases: name.aliases })
|
|
936
|
+
continue
|
|
937
|
+
}
|
|
938
|
+
kept.aliases = [...new Set([...kept.aliases, ...name.aliases])]
|
|
939
|
+
.sort((a, b) => a.localeCompare(b, "en-GB"))
|
|
940
|
+
.slice(0, NAME_ALIASES_MAX)
|
|
941
|
+
}
|
|
942
|
+
const kept = [...merged.values()]
|
|
943
|
+
const out = {
|
|
944
|
+
names: kept.slice(0, NAMES_MAX).map(({ name, kind, aliases }) => ({ name, kind, ...(aliases.length > 0 ? { aliases } : {}) })),
|
|
945
|
+
// A space past the scan, a glossary past its bodies, or more names than one answer holds.
|
|
946
|
+
more: kept.length > NAMES_MAX || results.some((result) => result.cut === true || result.past === true),
|
|
947
|
+
incomplete: [
|
|
948
|
+
...failed.map((result) => ({ id: result.entry.space.id, name: result.entry.space.name, reason: clip(describe(result.error), 200) })),
|
|
949
|
+
...skipped.map((entry) => ({
|
|
950
|
+
id: entry.space.id,
|
|
951
|
+
name: entry.space.name,
|
|
952
|
+
reason: clip(`Not read: a list covers at most ${RECENT_SPACES_MAX} spaces. Choose this space to see its names.`, 200),
|
|
953
|
+
})),
|
|
954
|
+
].slice(0, LIST_MAX),
|
|
955
|
+
}
|
|
956
|
+
return out
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/** A page's own other names (`fields.aliases`), one line each, sorted, never the name itself. */
|
|
960
|
+
function aliasesOf(record, name) {
|
|
961
|
+
const raw = Array.isArray(record?.fields?.aliases) ? record.fields.aliases : []
|
|
962
|
+
const seen = new Set([name.toLocaleLowerCase("en-GB")])
|
|
963
|
+
const aliases = []
|
|
964
|
+
for (const value of raw) {
|
|
965
|
+
if (typeof value !== "string") continue
|
|
966
|
+
const alias = clipText(plainLine(value), TERM_TEXT_CHARS, 320).text
|
|
967
|
+
const key = alias.toLocaleLowerCase("en-GB")
|
|
968
|
+
if (!alias || seen.has(key)) continue
|
|
969
|
+
seen.add(key)
|
|
970
|
+
aliases.push(alias)
|
|
971
|
+
}
|
|
972
|
+
return aliases.sort((a, b) => a.localeCompare(b, "en-GB")).slice(0, NAME_ALIASES_MAX)
|
|
973
|
+
}
|
|
974
|
+
|
|
736
975
|
/**
|
|
737
976
|
* How many memories the personal space keeps (`entry` is the first of
|
|
738
977
|
* `personalScopes()`), for the overview: `{ memories,
|
|
@@ -832,11 +1071,20 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
832
1071
|
function proposalItem(proposal) {
|
|
833
1072
|
const fields = proposal?.fields && typeof proposal.fields === "object" ? proposal.fields : {}
|
|
834
1073
|
const stated = STATED_BY.has(proposal?.stated_by) ? proposal.stated_by : "unknown"
|
|
1074
|
+
// A meeting proposal's citation keeps the moment and the transcript file
|
|
1075
|
+
// (#62), so a host can say when it was said and which recording it came from.
|
|
835
1076
|
const evidence = (Array.isArray(fields.evidence) ? fields.evidence : [])
|
|
836
1077
|
.map((item) => {
|
|
837
1078
|
const kind = ["event", "turn", "record"].find((name) => typeof item?.[name] === "string")
|
|
838
1079
|
const ref = kind ? idOf(item[kind]) : ""
|
|
839
|
-
|
|
1080
|
+
if (!kind || !ref) return null
|
|
1081
|
+
return {
|
|
1082
|
+
kind,
|
|
1083
|
+
ref,
|
|
1084
|
+
quote: clip(item.quote ?? "", 300),
|
|
1085
|
+
...(typeof item.at === "string" && item.at ? { at: clip(item.at, 20) } : {}),
|
|
1086
|
+
...(typeof item.file === "string" && item.file ? { file: clip(item.file, 200) } : {}),
|
|
1087
|
+
}
|
|
840
1088
|
})
|
|
841
1089
|
.filter(Boolean)
|
|
842
1090
|
.slice(0, EVIDENCE_MAX)
|
|
@@ -849,6 +1097,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
849
1097
|
action: clip(fields.action || proposal.type || "", 40),
|
|
850
1098
|
title: clip(proposal.title ?? "", 200),
|
|
851
1099
|
target: clip(fields.target_path || fields.target_id || "", 200),
|
|
1100
|
+
/** The wiki and the folder a page proposal would write to (#63, #76). */
|
|
1101
|
+
...(wikiOf(fields) ? { wiki: wikiOf(fields) } : {}),
|
|
1102
|
+
...(parentOf(fields.target_path) ? { parent: parentOf(fields.target_path) } : {}),
|
|
852
1103
|
reason: clip(fields.reason ?? "", 300),
|
|
853
1104
|
stated_by: stated,
|
|
854
1105
|
...rowSource(proposal.source),
|
|
@@ -858,15 +1109,71 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
858
1109
|
/** Whether Memory holds this write for the person to approve, rather than proposing a record. */
|
|
859
1110
|
held,
|
|
860
1111
|
...(own ? { space: own } : {}),
|
|
1112
|
+
...meetingOf(fields),
|
|
861
1113
|
external: stated === "external",
|
|
862
1114
|
evidence,
|
|
1115
|
+
sources: proposalSources(proposal, evidence),
|
|
863
1116
|
proposed: clipText(proposedText(proposal), 600, 1800).text,
|
|
864
1117
|
expires: clip(fields.expires ?? "", 40),
|
|
865
1118
|
created: clip(proposal.created ?? "", 40),
|
|
1119
|
+
at: clip(proposal.created ?? "", 40),
|
|
866
1120
|
...(payload ? { payload } : {}),
|
|
867
1121
|
}
|
|
868
1122
|
}
|
|
869
1123
|
|
|
1124
|
+
/** The wiki a proposal names, where the record carries one the schema takes. */
|
|
1125
|
+
function wikiOf(fields) {
|
|
1126
|
+
const wiki = idOf(fields?.wiki)
|
|
1127
|
+
return wiki ? clip(wiki, 128) : ""
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/** The folder a proposal's path sits in (`projects/harbour` → `projects/`), or "". */
|
|
1131
|
+
function parentOf(path) {
|
|
1132
|
+
const text = typeof path === "string" ? path.trim() : ""
|
|
1133
|
+
const at = text.lastIndexOf("/")
|
|
1134
|
+
return at > 0 ? clip(text.slice(0, at + 1), 300) : ""
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Where a proposal's words came from, as rows the review page lists (#76):
|
|
1139
|
+
* the evidence it cites with its quotes, then the record's own source refs
|
|
1140
|
+
* (an event, a turn, a session, a routine) once each. A quote is the record's
|
|
1141
|
+
* own text, so erasing the record takes it with the rest of the row; a ref is
|
|
1142
|
+
* an id, never a person's name. Bounded by `PROPOSAL_SOURCES_MAX`.
|
|
1143
|
+
*/
|
|
1144
|
+
function proposalSources(proposal, evidence) {
|
|
1145
|
+
const rows = evidence.map((item) => ({ kind: item.kind, ref: item.ref, ...(item.quote ? { quote: item.quote } : {}) }))
|
|
1146
|
+
const seen = new Set(rows.map((row) => `${row.kind} ${row.ref}`))
|
|
1147
|
+
const source = proposal?.source && typeof proposal.source === "object" ? proposal.source : {}
|
|
1148
|
+
for (const kind of ["event", "turn", "session", "routine"]) {
|
|
1149
|
+
const value = typeof source[kind] === "string" ? source[kind].trim() : ""
|
|
1150
|
+
const ref = idOf(value) ? clip(value, 200) : ""
|
|
1151
|
+
if (!ref || seen.has(`${kind} ${ref}`)) continue
|
|
1152
|
+
seen.add(`${kind} ${ref}`)
|
|
1153
|
+
rows.push({ kind, ref })
|
|
1154
|
+
}
|
|
1155
|
+
// A `url` row is safe only while a source removal **withdraws** a waiting
|
|
1156
|
+
// proposal that cites a removed event (`feat/source-removals`): its scrub
|
|
1157
|
+
// drops `fields.evidence` quotes, never `record.source`. If a later change
|
|
1158
|
+
// keeps such proposals listed, drop this row (review R3).
|
|
1159
|
+
const url = typeof source.url === "string" ? source.url.trim() : ""
|
|
1160
|
+
if (url && /^https?:\/\/[^\s<>"']{1,290}$/.test(url) && !seen.has(`url ${url}`)) rows.push({ kind: "url", ref: url })
|
|
1161
|
+
return rows.slice(0, PROPOSAL_SOURCES_MAX)
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* The meeting page a proposal was drawn from (#62): the record's id
|
|
1166
|
+
* (`fields.meeting_id`) and its path (`fields.meeting`), which the meeting
|
|
1167
|
+
* engine writes on every proposal it makes. Absent when the proposal came
|
|
1168
|
+
* from something else, so a page never shows a meeting it does not have.
|
|
1169
|
+
*/
|
|
1170
|
+
function meetingOf(fields) {
|
|
1171
|
+
const id = idOf(fields?.meeting_id)
|
|
1172
|
+
if (!id) return {}
|
|
1173
|
+
const path = typeof fields?.meeting === "string" ? clip(fields.meeting, 300) : ""
|
|
1174
|
+
return { meeting: { id, ...(path ? { path } : {}) } }
|
|
1175
|
+
}
|
|
1176
|
+
|
|
870
1177
|
/**
|
|
871
1178
|
* The space a held team write would be saved in, which the hold recorded from
|
|
872
1179
|
* control (`fields.space_id`, `fields.space_name`: `src/tools/held-write.js`),
|
|
@@ -888,7 +1195,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
888
1195
|
* A proposal's own type (`create`, `append`, `team_write`, `share`, …): what
|
|
889
1196
|
* the record is, for a host that labels an item by it.
|
|
890
1197
|
*/
|
|
891
|
-
const proposalKind = (proposal) => (typeof proposal?.type === "string" && /^[a-zA-Z][a-zA-Z0-9._-]{0,
|
|
1198
|
+
const proposalKind = (proposal) => (typeof proposal?.type === "string" && /^[a-zA-Z][a-zA-Z0-9._-]{0,39}$/.test(proposal.type) ? proposal.type : "")
|
|
892
1199
|
|
|
893
1200
|
/** The session a proposal was made in, where its source names one that could be a session id. */
|
|
894
1201
|
const proposalSession = (proposal) => {
|
|
@@ -903,11 +1210,19 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
903
1210
|
* `src/tools/held-write.js`), so a host can ask in that session's composer.
|
|
904
1211
|
* `review.list` returns the declared items; the Inbox adds the rest.
|
|
905
1212
|
*/
|
|
906
|
-
async function reviewWith(input) {
|
|
1213
|
+
async function reviewWith(input, { oldest = false } = {}) {
|
|
907
1214
|
await available()
|
|
908
1215
|
const where = await target(input)
|
|
909
1216
|
const answer = await records("review.list", { limit: REVIEW_MAX + 1 }, where.where)
|
|
910
|
-
|
|
1217
|
+
// A review queue reads oldest first, ties by id; the Inbox keeps the
|
|
1218
|
+
// service's newest-first order it had (`oldest` false).
|
|
1219
|
+
const proposals = (answer?.proposals ?? [])
|
|
1220
|
+
.filter((proposal) => idOf(proposal?.id))
|
|
1221
|
+
.sort((a, b) =>
|
|
1222
|
+
oldest
|
|
1223
|
+
? String(a.created ?? "").localeCompare(String(b.created ?? "")) || String(a.id).localeCompare(String(b.id))
|
|
1224
|
+
: 0,
|
|
1225
|
+
)
|
|
911
1226
|
const out = { space: where.space, items: [], more: false }
|
|
912
1227
|
const fitted = fitList(
|
|
913
1228
|
out,
|
|
@@ -923,25 +1238,172 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
923
1238
|
}
|
|
924
1239
|
|
|
925
1240
|
async function reviewList(input) {
|
|
926
|
-
const { space, items, more } = await reviewWith(input)
|
|
1241
|
+
const { space, items, more } = await reviewWith(input, { oldest: true })
|
|
927
1242
|
return { space, items: items.map((entry) => entry.item), more }
|
|
928
1243
|
}
|
|
929
1244
|
|
|
1245
|
+
/** One meeting page's row, from the record the store keeps. */
|
|
1246
|
+
function meetingRowOf(record) {
|
|
1247
|
+
const fields = record?.fields && typeof record.fields === "object" ? record.fields : {}
|
|
1248
|
+
const meeting = fields.meeting && typeof fields.meeting === "object" && !Array.isArray(fields.meeting) ? fields.meeting : {}
|
|
1249
|
+
const at = typeof meeting.startedAt === "string" ? clip(meeting.startedAt, 40) : clip(record?.created ?? record?.updated ?? "", 40)
|
|
1250
|
+
const people = (Array.isArray(fields.attendees) ? fields.attendees : [])
|
|
1251
|
+
.map((entry) => (typeof entry === "string" ? entry : entry?.name))
|
|
1252
|
+
.filter((name) => typeof name === "string" && name.trim())
|
|
1253
|
+
.map((name) => clip(name, 200))
|
|
1254
|
+
.slice(0, 50)
|
|
1255
|
+
return {
|
|
1256
|
+
id: idOf(record?.id),
|
|
1257
|
+
path: clip(record?.path ?? "", 300),
|
|
1258
|
+
title: clip(record?.title ?? record?.path ?? "", 200),
|
|
1259
|
+
at,
|
|
1260
|
+
...(typeof meeting.endedAt === "string" ? { endsAt: clip(meeting.endedAt, 40) } : {}),
|
|
1261
|
+
...(people.length ? { people } : {}),
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* The project pages the caller can read, by name (jelly's ask 11): the
|
|
1267
|
+
* person's own space and every space they can reach, read one space at a
|
|
1268
|
+
* time. Each row is the page's own id, its title, its path and the space it
|
|
1269
|
+
* lives in. `records.list` applies the space's own visibility before it
|
|
1270
|
+
* answers, and a space control does not list for the caller is never read,
|
|
1271
|
+
* so another member's private pages are never named.
|
|
1272
|
+
*/
|
|
1273
|
+
async function projectsList(input) {
|
|
1274
|
+
await available()
|
|
1275
|
+
const { targets, skipped } = await recentTargets(input)
|
|
1276
|
+
const results = await mapLimit(targets, RECENT_CONCURRENCY, async (entry) => {
|
|
1277
|
+
const space = { id: entry.space.id, name: entry.space.name }
|
|
1278
|
+
try {
|
|
1279
|
+
const answer = await records("records.list", { kind: "page", type: "project", limit: PROJECTS_MAX }, entry.where)
|
|
1280
|
+
const projects = []
|
|
1281
|
+
for (const record of answer?.records ?? []) {
|
|
1282
|
+
if (record?.type !== "project") continue
|
|
1283
|
+
const id = idOf(record.id)
|
|
1284
|
+
const path = idOf(record.path)
|
|
1285
|
+
if (!id || !path) continue
|
|
1286
|
+
const name = clip(plainLine(record.title || String(path).split("/").pop() || ""), 200)
|
|
1287
|
+
if (name) projects.push({ id, name, path, space })
|
|
1288
|
+
}
|
|
1289
|
+
return { projects, past: Boolean(answer?.cursor) }
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
runtime.log?.warn?.(`view projects.list: a read in space ${entry.space.id} failed`, error)
|
|
1292
|
+
return { error }
|
|
1293
|
+
}
|
|
1294
|
+
})
|
|
1295
|
+
const failed = results.filter((result) => result.error !== undefined)
|
|
1296
|
+
if (!results.some((result) => Array.isArray(result.projects))) throw failed[0].error
|
|
1297
|
+
const order = new Map(targets.map((entry, index) => [entry.space.id, index]))
|
|
1298
|
+
const projects = results
|
|
1299
|
+
.flatMap((result) => result.projects ?? [])
|
|
1300
|
+
.sort(
|
|
1301
|
+
(a, b) =>
|
|
1302
|
+
a.name.localeCompare(b.name, "en-GB") ||
|
|
1303
|
+
order.get(a.space.id) - order.get(b.space.id) ||
|
|
1304
|
+
a.path.localeCompare(b.path),
|
|
1305
|
+
)
|
|
1306
|
+
const out = {
|
|
1307
|
+
items: [],
|
|
1308
|
+
more: projects.length > PROJECTS_MAX || results.some((result) => result.past === true),
|
|
1309
|
+
incomplete: [
|
|
1310
|
+
...failed.map((result) => ({ id: result.entry.space.id, name: result.entry.space.name, reason: clip(describe(result.error), 200) })),
|
|
1311
|
+
...skipped.map((entry) => ({
|
|
1312
|
+
id: entry.space.id,
|
|
1313
|
+
name: entry.space.name,
|
|
1314
|
+
reason: clip(`Not read: a list covers at most ${RECENT_SPACES_MAX} spaces. Choose this space to see its projects.`, 200),
|
|
1315
|
+
})),
|
|
1316
|
+
].slice(0, LIST_MAX),
|
|
1317
|
+
}
|
|
1318
|
+
const fitted = fitList(out, "items", projects.slice(0, PROJECTS_MAX))
|
|
1319
|
+
if (fitted) out.more = true
|
|
1320
|
+
return out
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
async function meetingsList(input) {
|
|
1324
|
+
await available()
|
|
1325
|
+
const where = await target(input)
|
|
1326
|
+
const cursor = typeof input?.cursor === "string" ? input.cursor.trim() : ""
|
|
1327
|
+
if (cursor && cursor.length > CURSOR_CHARS) refuse("That is not a listing cursor.")
|
|
1328
|
+
const answer = await records("records.list", { kind: "page", type: "meeting", limit: 100, ...(cursor ? { cursor } : {}) }, where.where)
|
|
1329
|
+
const rows = (answer?.records ?? [])
|
|
1330
|
+
.filter((record) => idOf(record?.id) && record.type === "meeting")
|
|
1331
|
+
.map(meetingRowOf)
|
|
1332
|
+
.sort((a, b) => String(b.at).localeCompare(String(a.at)))
|
|
1333
|
+
return { space: where.space, items: rows, more: Boolean(answer?.cursor), ...(answer?.cursor ? { cursor: clip(answer.cursor, CURSOR_CHARS) } : {}) }
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
async function meetingsRead(input) {
|
|
1337
|
+
await available()
|
|
1338
|
+
const where = await target(input)
|
|
1339
|
+
const id = idOf(input?.id)
|
|
1340
|
+
if (!id) refuse("That is not a meeting id.")
|
|
1341
|
+
const answer = await records("records.get", { ids: [id] }, where.where)
|
|
1342
|
+
const record = (answer?.records ?? []).find((entry) => entry?.id === id && entry?.type === "meeting")
|
|
1343
|
+
if (!record) refuse("That meeting isn't in this space.")
|
|
1344
|
+
const fields = record.fields && typeof record.fields === "object" ? record.fields : {}
|
|
1345
|
+
const transcript = typeof fields.transcript === "string" ? clip(fields.transcript, 12_000) : ""
|
|
1346
|
+
return {
|
|
1347
|
+
space: where.space,
|
|
1348
|
+
...meetingRowOf(record),
|
|
1349
|
+
body: clip(record.body ?? "", 40_000),
|
|
1350
|
+
transcript,
|
|
1351
|
+
transcriptMore: typeof fields.transcript === "string" && fields.transcript.length > 12_000,
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* The hand-over requests addressed to the caller. Control lists both the
|
|
1357
|
+
* requests a person sent and the ones they received; only the received ones
|
|
1358
|
+
* are this read's subject, so a Share -> Decide page never offers a request
|
|
1359
|
+
* the person cannot answer.
|
|
1360
|
+
*/
|
|
1361
|
+
async function shareRequests() {
|
|
1362
|
+
await available()
|
|
1363
|
+
if (!runtime.control || typeof runtime.control.listTransfers !== "function") return { requests: [] }
|
|
1364
|
+
const answer = await runtime.control.listTransfers({ userId: runtime.config?.user })
|
|
1365
|
+
const rows = (Array.isArray(answer?.requests) ? answer.requests : [])
|
|
1366
|
+
.filter((row) => row?.direction === "received" || (!row?.direction && row?.to?.user_id === runtime.config?.user))
|
|
1367
|
+
.filter((row) => idOf(row?.id) || String(row?.id ?? "").trim())
|
|
1368
|
+
.sort((a, b) => {
|
|
1369
|
+
const left = a?.state === "pending" ? 0 : 1
|
|
1370
|
+
const right = b?.state === "pending" ? 0 : 1
|
|
1371
|
+
if (left !== right) return left - right
|
|
1372
|
+
return String(b?.requested_at ?? "").localeCompare(String(a?.requested_at ?? ""))
|
|
1373
|
+
})
|
|
1374
|
+
.slice(0, 100)
|
|
1375
|
+
.map((row) => ({
|
|
1376
|
+
id: String(row?.id ?? "").slice(0, 200),
|
|
1377
|
+
state: ["pending", "accepted", "declined"].includes(row?.state) ? row.state : "pending",
|
|
1378
|
+
target: {
|
|
1379
|
+
type: row?.target?.type === "page" ? "page" : "space",
|
|
1380
|
+
id: clip(row?.target?.id ?? "", 200),
|
|
1381
|
+
label: clip(row?.target?.name || row?.target?.id || "", 300),
|
|
1382
|
+
...(row?.target?.space ? { space: clip(row.target.space, 200) } : {}),
|
|
1383
|
+
},
|
|
1384
|
+
from: { user_id: clip(row?.from?.user_id ?? "", 200), ...(row?.from?.name ? { name: clip(row.from.name, 200) } : {}) },
|
|
1385
|
+
to: { user_id: clip(row?.to?.user_id ?? "", 200), ...(row?.to?.name ? { name: clip(row.to.name, 200) } : {}) },
|
|
1386
|
+
at: clip(row?.requested_at ?? "", 40),
|
|
1387
|
+
...(row?.note ? { note: clip(row.note, 300) } : {}),
|
|
1388
|
+
}))
|
|
1389
|
+
return { requests: rows }
|
|
1390
|
+
}
|
|
1391
|
+
|
|
930
1392
|
/**
|
|
931
1393
|
* A listed page. Its owner is named from the space's roster, which the listing
|
|
932
1394
|
* reads once (`memberNames`), so a page of a hundred rows asks control once; a
|
|
933
1395
|
* page whose owner the roster cannot name has no `owner` at all, as in
|
|
934
1396
|
* `pages.read` (an id, or the routines' user, is not a person's name).
|
|
935
1397
|
*/
|
|
936
|
-
const pageRow = (record,
|
|
937
|
-
const
|
|
938
|
-
const name = owner && owner !== ROUTINE_OWNER ? owners.get(owner) : ""
|
|
1398
|
+
const pageRow = (record, members = new Map()) => {
|
|
1399
|
+
const member = memberFor(members, record?.owner)
|
|
939
1400
|
return {
|
|
940
1401
|
path: idOf(record.path),
|
|
941
1402
|
title: clip(record.title || record.path, 200),
|
|
942
1403
|
type: clip(record.type ?? "", 40),
|
|
943
1404
|
updated: clip(record.updated ?? "", 40),
|
|
944
|
-
...(
|
|
1405
|
+
...(/^\d{4}-\d{2}-\d{2}T/.test(String(record.updated ?? "")) ? { changedAt: clip(record.updated, 40) } : {}),
|
|
1406
|
+
...(member ? { owner: { id: clip(member.id, OWNER_ID_CHARS), name: clip(member.name, OWNER_NAME_CHARS) } } : {}),
|
|
945
1407
|
}
|
|
946
1408
|
}
|
|
947
1409
|
|
|
@@ -1067,16 +1529,17 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1067
1529
|
const record = (answer?.records ?? [])[0]
|
|
1068
1530
|
if (!record || !idOf(record.id)) refuse(ref.path ? "That page isn't in this memory." : "That record isn't in this memory.")
|
|
1069
1531
|
const targets = [...new Set((Array.isArray(record.links) ? record.links : []).map((link) => String(link ?? "").trim()).filter(Boolean))].slice(0, LINKS_MAX)
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1532
|
+
// The links' titles and whether any is knowably missing, from the one rule
|
|
1533
|
+
// the tool's page read uses (`src/outlinks.js`): `missing` is null when the
|
|
1534
|
+
// absence is not knowable to this reader, and then the answer says nothing
|
|
1535
|
+
// about existence. A failed backlinks read fails this read: it is never
|
|
1536
|
+
// shown as a page nothing links to.
|
|
1537
|
+
const [{ records: linked, missing }, back] = await Promise.all([
|
|
1538
|
+
readOutlinks({ links: targets, path: record.path, spaceRead: where.spaceRead, call: (method, body) => records(method, body, where.where) }),
|
|
1539
|
+
record.path ? records("records.backlinks", { path: record.path }, where.where) : { records: [] },
|
|
1077
1540
|
])
|
|
1078
1541
|
const known = new Map()
|
|
1079
|
-
for (const found of linked
|
|
1542
|
+
for (const found of linked) {
|
|
1080
1543
|
if (found?.id) known.set(found.id, found)
|
|
1081
1544
|
if (found?.path) known.set(found.path, found)
|
|
1082
1545
|
}
|
|
@@ -1099,7 +1562,13 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1099
1562
|
clipped: false,
|
|
1100
1563
|
outlinks: targets.map((target) => {
|
|
1101
1564
|
const found = known.get(target)
|
|
1102
|
-
|
|
1565
|
+
const row = { target: clip(target, 200), title: clip(found?.title || "", 200) }
|
|
1566
|
+
// `exists` only where it is known: false for a page path this reader can
|
|
1567
|
+
// prove is not there, true for a record it read. Omitted otherwise (a
|
|
1568
|
+
// grant-only reader, a failed lookup, a target past the cap), so the
|
|
1569
|
+
// page never marks a link it cannot answer for.
|
|
1570
|
+
const exists = found ? true : missing?.has(target) ? false : undefined
|
|
1571
|
+
return exists === undefined ? row : { ...row, exists }
|
|
1103
1572
|
}),
|
|
1104
1573
|
backlinks: backlinks.slice(0, LINKS_MAX).map((found) => ({
|
|
1105
1574
|
id: idOf(found.id),
|
|
@@ -1108,6 +1577,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1108
1577
|
type: clip(found.type ?? "", 40),
|
|
1109
1578
|
})),
|
|
1110
1579
|
backlinksMore: backlinks.length > LINKS_MAX || back?.truncated === true,
|
|
1580
|
+
// Only the backlinks this reader can see (the store's own filter): the
|
|
1581
|
+
// page says so rather than "nothing links here".
|
|
1582
|
+
...(where.spaceRead ? {} : { backlinksPartial: true }),
|
|
1111
1583
|
}
|
|
1112
1584
|
const room = Math.max(4_000, ANSWER_BYTES - jsonBytes(out))
|
|
1113
1585
|
const { text, clipped } = clipText(record.body ?? "", RECORD_BODY_CHARS, room)
|
|
@@ -1154,9 +1626,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1154
1626
|
* not drawn: its target's own title is not in this read, and a node named by
|
|
1155
1627
|
* half a fact is worse than none. `types` narrows which pages are kept.
|
|
1156
1628
|
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1629
|
+
* Every node then carries its `community` (`addCommunities`): a clustering of
|
|
1630
|
+
* this answer's own pages by their links, computed on the read and never
|
|
1631
|
+
* stored (Jelly's ask 2).
|
|
1160
1632
|
*/
|
|
1161
1633
|
async function folderGraph(folder, where, max, types) {
|
|
1162
1634
|
const answer = await records("records.list", { kind: "page", path_prefix: `${folder}/`, limit: GRAPH_NODES_MAX }, where.where)
|
|
@@ -1200,6 +1672,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1200
1672
|
}
|
|
1201
1673
|
const out = { space: where.space, start: 0, nodes, edges: [], truncated: answer?.truncated === true || Boolean(answer?.cursor) || cut }
|
|
1202
1674
|
if (fitList(out, "edges", edges)) out.truncated = true
|
|
1675
|
+
addCommunities(out)
|
|
1203
1676
|
return out
|
|
1204
1677
|
}
|
|
1205
1678
|
|
|
@@ -1267,6 +1740,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1267
1740
|
}
|
|
1268
1741
|
const out = { space: where.space, start, nodes, edges: [], truncated: answer?.truncated === true || cut }
|
|
1269
1742
|
if (fitList(out, "edges", edges)) out.truncated = true
|
|
1743
|
+
addCommunities(out)
|
|
1270
1744
|
return out
|
|
1271
1745
|
}
|
|
1272
1746
|
|
|
@@ -1279,11 +1753,16 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1279
1753
|
"journal.list": journalList,
|
|
1280
1754
|
"journal.read": journalRead,
|
|
1281
1755
|
"review.list": reviewList,
|
|
1756
|
+
"projects.list": projectsList,
|
|
1757
|
+
"meetings.list": meetingsList,
|
|
1758
|
+
"meetings.read": meetingsRead,
|
|
1759
|
+
"share.requests": shareRequests,
|
|
1282
1760
|
"pages.list": pagesList,
|
|
1283
1761
|
"pages.read": pagesRead,
|
|
1284
1762
|
"pages.history": pagesHistory,
|
|
1285
1763
|
"graph.links": graphLinks,
|
|
1286
1764
|
"terms.list": termsList,
|
|
1765
|
+
"names.known": namesKnown,
|
|
1287
1766
|
},
|
|
1288
1767
|
}
|
|
1289
1768
|
}
|