@joe-broadhead/opencode-mem 0.9.14 → 0.11.2
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 +1805 -0
- package/README.md +14 -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 +7688 -339
- 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 +79 -6
- 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 +37 -4
- package/src/tools/held-write.js +31 -12
- package/src/tools/index.js +27 -0
- package/src/tools/ingest.js +27 -2
- package/src/tools/memory.js +30 -7
- package/src/tools/page.js +95 -9
- package/src/tools/recall.js +208 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +44 -4
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +373 -29
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +34 -4
- 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 +930 -21
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/records-reads.js +355 -38
- package/src/views/rpc.js +118 -8
- package/src/views/shape.js +8 -5
- package/views/pages.html +2 -2
|
@@ -18,9 +18,16 @@ 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
|
+
PROPOSAL_SOURCES_MAX,
|
|
24
31
|
RECENT_CONCURRENCY,
|
|
25
32
|
RECENT_MAX_OFFSET,
|
|
26
33
|
RECENT_PAGE,
|
|
@@ -32,6 +39,7 @@ import {
|
|
|
32
39
|
REVIEW_MAX,
|
|
33
40
|
ROUTINE_OWNER,
|
|
34
41
|
SOURCE_CHARS,
|
|
42
|
+
SPACE_GRANT_ONLY,
|
|
35
43
|
STATUS_CHARS,
|
|
36
44
|
SUMMARY_CHARS,
|
|
37
45
|
TASK_CHARS,
|
|
@@ -46,6 +54,8 @@ import { dayIn } from "../records.js"
|
|
|
46
54
|
import { oneLine } from "../util.js"
|
|
47
55
|
import { ANSWER_BYTES, SPACE_KINDS, clip, clipText, fitList, idOf, jsonBytes, mapLimit, refuse, sourceLabel, spaceOf } from "./shape.js"
|
|
48
56
|
import { PAGE_TYPES } from "../tools/records-kit.js"
|
|
57
|
+
import { communitiesOf } from "./communities.js"
|
|
58
|
+
import { holdsSpaceRead, readOutlinks } from "../outlinks.js"
|
|
49
59
|
|
|
50
60
|
/**
|
|
51
61
|
* The views' reads of the records service (docs/design/memory-v1-contracts.md
|
|
@@ -338,6 +348,39 @@ export function recentFilters(input) {
|
|
|
338
348
|
}
|
|
339
349
|
}
|
|
340
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Name each node's community, from the answer's own nodes and edges
|
|
353
|
+
* (`communitiesOf`): every node of a graph answer carries one, so a host can
|
|
354
|
+
* colour the graph, and a node cut from the answer is in no community.
|
|
355
|
+
*
|
|
356
|
+
* The grouping is the graph's, not the order the service returned it in: the
|
|
357
|
+
* nodes are put in one canonical order first (by path, then id, then their place
|
|
358
|
+
* in the answer) and the edges follow them, so two reads of the same pages give
|
|
359
|
+
* the same communities whatever order they arrive in.
|
|
360
|
+
*
|
|
361
|
+
* @param {{ nodes: Array<Record<string, unknown>>, edges: Array<{ from: number, to: number }> }} answer
|
|
362
|
+
*/
|
|
363
|
+
function addCommunities(answer) {
|
|
364
|
+
const canonical = answer.nodes.map((_, index) => index)
|
|
365
|
+
const key = (index) => String(answer.nodes[index]?.path ?? "")
|
|
366
|
+
const second = (index) => String(answer.nodes[index]?.id ?? "")
|
|
367
|
+
canonical.sort((a, b) => {
|
|
368
|
+
const left = key(a)
|
|
369
|
+
const right = key(b)
|
|
370
|
+
if (left !== right) return left < right ? -1 : 1
|
|
371
|
+
const leftId = second(a)
|
|
372
|
+
const rightId = second(b)
|
|
373
|
+
if (leftId !== rightId) return leftId < rightId ? -1 : 1
|
|
374
|
+
return a - b
|
|
375
|
+
})
|
|
376
|
+
const place = new Map(canonical.map((index, at) => [index, at]))
|
|
377
|
+
const edges = answer.edges
|
|
378
|
+
.map((edge) => ({ from: place.get(edge.from), to: place.get(edge.to) }))
|
|
379
|
+
.sort((a, b) => a.from - b.from || a.to - b.to)
|
|
380
|
+
const groups = communitiesOf(canonical.length, edges)
|
|
381
|
+
for (const [at, index] of canonical.entries()) answer.nodes[index].community = groups[at]
|
|
382
|
+
}
|
|
383
|
+
|
|
341
384
|
/**
|
|
342
385
|
* @param {{ runtime: any, personalScopes: () => Promise<Array<{ context: any }>>, available: () => Promise<void>, describe?: (error: unknown) => string }} input
|
|
343
386
|
* `describe` says a failed read in words (a space that could not be read is
|
|
@@ -375,10 +418,16 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
375
418
|
if (!found) refuse("That space isn't one of yours.")
|
|
376
419
|
return {
|
|
377
420
|
where: { ...(scope ? { scope } : {}), space: spaceId },
|
|
378
|
-
space: {
|
|
421
|
+
space: {
|
|
422
|
+
id: spaceId,
|
|
423
|
+
name: clip(found.name || spaceId, 200),
|
|
424
|
+
kind: SPACE_KINDS.has(found.kind) ? found.kind : "unknown",
|
|
425
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
426
|
+
},
|
|
427
|
+
spaceRead: holdsSpaceRead({ role: found.role, space_kind: found.kind }),
|
|
379
428
|
}
|
|
380
429
|
}
|
|
381
|
-
return { where: whereOf(first), space: spaceOf(first?.context ?? null) }
|
|
430
|
+
return { where: whereOf(first), space: spaceOf(first?.context ?? null), spaceRead: holdsSpaceRead(first?.context ?? null) }
|
|
382
431
|
}
|
|
383
432
|
|
|
384
433
|
/** `{ path }` or `{ id }` from a view's input; one of them, checked. */
|
|
@@ -411,43 +460,78 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
411
460
|
}
|
|
412
461
|
|
|
413
462
|
/**
|
|
414
|
-
* The people in a space,
|
|
415
|
-
*
|
|
416
|
-
*
|
|
463
|
+
* The people in a space, as the space's own member roster names them
|
|
464
|
+
* (`control.listMembers`, which control scopes to a viewer of the space: the
|
|
465
|
+
* person's own, or one they chose, with the caller's own token). Read once
|
|
417
466
|
* per view call and never kept between calls, so no person's read answers with
|
|
418
467
|
* a roster read under someone else's access. A roster that cannot be read is
|
|
419
|
-
* no
|
|
468
|
+
* no members, never a failed read: the page is then named no owner.
|
|
469
|
+
*
|
|
470
|
+
* Keyed by the id a record's `owner` carries, which is not the roster's own. The
|
|
471
|
+
* records service keeps the **upstream** user id the gateway sends it
|
|
472
|
+
* (`x-records-user`, from `context.user.upstream_id`;
|
|
473
|
+
* deploy/auth/records-scope.mjs), while control's roster knows the person by its
|
|
474
|
+
* own `user_id` (`usr_…`). Matching one against the other by equality names
|
|
475
|
+
* nobody, which is why every page carried no owner until the roster learned to
|
|
476
|
+
* carry each member's upstream id too. The member itself is kept so `owner.id`
|
|
477
|
+
* can be control's own `user_id` — the person's id everywhere else (a space's
|
|
478
|
+
* members read, `src/tools/spaces.js`) — and never the core's: an id Jelly
|
|
479
|
+
* cannot relate to a member it can see, and one it should not see at all.
|
|
420
480
|
*/
|
|
421
481
|
async function memberNames(spaceId) {
|
|
422
|
-
const
|
|
482
|
+
const members = new Map()
|
|
423
483
|
const id = idOf(spaceId)
|
|
424
|
-
if (!id || id === "local" || !runtime.control || typeof runtime.control.listMembers !== "function") return
|
|
484
|
+
if (!id || id === "local" || !runtime.control || typeof runtime.control.listMembers !== "function") return members
|
|
425
485
|
try {
|
|
426
|
-
const
|
|
427
|
-
|
|
486
|
+
const roster = (await runtime.control.listMembers({ userId: runtime.config?.user, spaceId: id })) ?? []
|
|
487
|
+
/** Two people answering to one key would name the wrong one; that key names nobody. */
|
|
488
|
+
const shared = new Set()
|
|
489
|
+
const claim = (key, person) => {
|
|
490
|
+
const seen = members.get(key)
|
|
491
|
+
if (seen && seen.id !== person.id) shared.add(key)
|
|
492
|
+
else members.set(key, person)
|
|
493
|
+
}
|
|
494
|
+
for (const member of roster) {
|
|
428
495
|
const user = idOf(member?.user_id)
|
|
429
496
|
const name = typeof member?.name === "string" ? oneLine(member.name, OWNER_NAME_CHARS).trim() : ""
|
|
430
|
-
if (user
|
|
497
|
+
if (!user || !name) continue
|
|
498
|
+
// One key, the one that person's records are written under: their
|
|
499
|
+
// upstream id, or their own user id when control has no upstream id for
|
|
500
|
+
// them (the gateway sends that as `x-records-user` instead). Never both,
|
|
501
|
+
// so a record owned by someone else, whose upstream id happens to equal
|
|
502
|
+
// this member's user id, does not name this member.
|
|
503
|
+
claim(idOf(member?.upstream_user_id) || user, { id: user, name })
|
|
431
504
|
}
|
|
505
|
+
for (const key of shared) members.delete(key)
|
|
432
506
|
} catch (error) {
|
|
433
507
|
runtime.log?.debug?.("view: the space's roster was not read", { space: id, error: error?.message })
|
|
434
508
|
}
|
|
435
|
-
return
|
|
509
|
+
return members
|
|
436
510
|
}
|
|
437
511
|
|
|
438
512
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
513
|
+
* The roster member a record's `owner` names, by the id that record was written
|
|
514
|
+
* under (the roster's key). Null for no owner, for one the roster cannot name,
|
|
515
|
+
* and for the routines' own user (which owns what a routine writes and is no
|
|
516
|
+
* person).
|
|
517
|
+
*/
|
|
518
|
+
const memberFor = (members, owner) => {
|
|
519
|
+
const id = idOf(owner)
|
|
520
|
+
return id && id !== ROUTINE_OWNER ? (members.get(id) ?? null) : null
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* A page's owning person, where Memory can **name** them: the roster member the
|
|
525
|
+
* record's `owner` names (by the upstream id the record holds), shown as
|
|
526
|
+
* control's own `user_id` and the name the roster gives them. `{}` otherwise,
|
|
527
|
+
* and the field is left out rather than filled with an id: an id is not a name.
|
|
442
528
|
* That is the usual answer for a reader with only a page grant, whom control
|
|
443
529
|
* refuses the space's member list (it needs viewer), and it is always the answer
|
|
444
530
|
* for the routines' own user, which owns what a routine writes and is no person.
|
|
445
531
|
*/
|
|
446
532
|
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) } } : {}
|
|
533
|
+
const member = memberFor(await memberNames(spaceId), record?.owner)
|
|
534
|
+
return member ? { owner: { id: clip(member.id, OWNER_ID_CHARS), name: clip(member.name, OWNER_NAME_CHARS) } } : {}
|
|
451
535
|
}
|
|
452
536
|
|
|
453
537
|
/** Today in the person's zone, as a bare date is compared with a page's review day. */
|
|
@@ -561,7 +645,12 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
561
645
|
seen.add(spaceId)
|
|
562
646
|
others.push({
|
|
563
647
|
where: { ...(scope ? { scope } : {}), space: spaceId },
|
|
564
|
-
space: {
|
|
648
|
+
space: {
|
|
649
|
+
id: spaceId,
|
|
650
|
+
name: clip(space.name || spaceId, 200),
|
|
651
|
+
kind: SPACE_KINDS.has(space.kind) ? space.kind : "unknown",
|
|
652
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
653
|
+
},
|
|
565
654
|
})
|
|
566
655
|
}
|
|
567
656
|
const room = Math.max(0, RECENT_SPACES_MAX - 1)
|
|
@@ -733,6 +822,155 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
733
822
|
return out
|
|
734
823
|
}
|
|
735
824
|
|
|
825
|
+
/**
|
|
826
|
+
* The names of the people, projects and teams Memory knows, and the entries
|
|
827
|
+
* its glossary pages state, for a host's dictation vocabulary (0.10.2; Jelly's
|
|
828
|
+
* asks 3 and 6). Read over the same spaces a recent list is
|
|
829
|
+
* (`recentTargets`): the person's own first, then the shared spaces control
|
|
830
|
+
* lists for them, each read on its own and each failure or skipped space named
|
|
831
|
+
* in `incomplete`. No space id, no path and no count is returned: a caller
|
|
832
|
+
* gets what it would say, and nothing about where the page lives.
|
|
833
|
+
*
|
|
834
|
+
* **Every page of a kind, not the newest few.** Each list read asks the service
|
|
835
|
+
* for `NAMES_PAGE_TYPES` only (`person`, `project`, `team`, `glossary`), so a
|
|
836
|
+
* space with thousands of newer journals and topics still offers its people,
|
|
837
|
+
* and follows the cursor for up to `NAMES_SCAN_PAGES` pages. A space with more
|
|
838
|
+
* than that says `more` rather than looking complete.
|
|
839
|
+
*
|
|
840
|
+
* **Order is deterministic: the most referenced name first, then by name.** A
|
|
841
|
+
* name is referenced by the pages of the same read that link to it (`links`,
|
|
842
|
+
* which a list row already carries); a glossary entry takes its glossary
|
|
843
|
+
* page's count. Only pages the caller may read are in the read, so a link from
|
|
844
|
+
* a page outside a grant is never counted. A name two spaces both know is one
|
|
845
|
+
* entry, its aliases together, so the same memory answers the same way every
|
|
846
|
+
* call.
|
|
847
|
+
*
|
|
848
|
+
* Bounded: at most `NAMES_SCAN_PAGES` reads of `NAMES_PAGE` rows per space, at
|
|
849
|
+
* most `NAMES_MAX` names, and no more than `TERM_GLOSSARIES_MAX` glossary
|
|
850
|
+
* bodies read per space (as `terms.list` does).
|
|
851
|
+
*/
|
|
852
|
+
async function namesKnown(input) {
|
|
853
|
+
await available()
|
|
854
|
+
if (input && Object.keys(input).length > 0) refuse("names.known takes no options.")
|
|
855
|
+
const { targets, skipped } = await recentTargets({})
|
|
856
|
+
const results = await mapLimit(targets, RECENT_CONCURRENCY, async (entry) => {
|
|
857
|
+
try {
|
|
858
|
+
const pages = []
|
|
859
|
+
let cursor = null
|
|
860
|
+
let cut = false
|
|
861
|
+
for (let scan = 0; scan < NAMES_SCAN_PAGES; scan += 1) {
|
|
862
|
+
const answer = await records(
|
|
863
|
+
"records.list",
|
|
864
|
+
{ kind: "page", type: [...NAMES_PAGE_TYPES], limit: NAMES_PAGE, ...(cursor ? { cursor } : {}) },
|
|
865
|
+
entry.where,
|
|
866
|
+
)
|
|
867
|
+
pages.push(...(answer?.records ?? []).filter((record) => idOf(record?.path)))
|
|
868
|
+
cursor = typeof answer?.cursor === "string" && answer.cursor ? answer.cursor : null
|
|
869
|
+
if (!cursor) break
|
|
870
|
+
}
|
|
871
|
+
// A cursor still to follow is a space with more pages than one scan reads.
|
|
872
|
+
cut = Boolean(cursor)
|
|
873
|
+
const glossaries = pages.filter((record) => record.type === "glossary")
|
|
874
|
+
const read = glossaries.slice(0, TERM_GLOSSARIES_MAX)
|
|
875
|
+
let bodies = []
|
|
876
|
+
if (read.length > 0) {
|
|
877
|
+
const answer = await records("records.get", { paths: read.map((record) => record.path) }, entry.where)
|
|
878
|
+
bodies = answer?.records ?? []
|
|
879
|
+
}
|
|
880
|
+
return { entry, pages, glossaries: read, bodies, cut, past: glossaries.length > read.length }
|
|
881
|
+
} catch (error) {
|
|
882
|
+
runtime.log?.warn?.(`view names.known: a read in space ${entry.space.id} failed`, error)
|
|
883
|
+
return { entry, error }
|
|
884
|
+
}
|
|
885
|
+
})
|
|
886
|
+
const failed = results.filter((result) => result.error !== undefined)
|
|
887
|
+
if (!results.some((result) => Array.isArray(result.pages))) throw failed[0].error
|
|
888
|
+
// A glossary page's own title is its subject, not a name: only its entries are.
|
|
889
|
+
const kindOf = Object.freeze({ person: "person", project: "project", team: "team" })
|
|
890
|
+
const names = []
|
|
891
|
+
for (const result of results) {
|
|
892
|
+
if (!result.pages) continue
|
|
893
|
+
// How many pages of this space link to each page: a name's references.
|
|
894
|
+
const references = new Map()
|
|
895
|
+
for (const record of result.pages) {
|
|
896
|
+
for (const link of Array.isArray(record?.links) ? record.links : []) {
|
|
897
|
+
const target = String(link ?? "").trim()
|
|
898
|
+
if (!target) continue
|
|
899
|
+
references.set(target, (references.get(target) ?? 0) + 1)
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const refsOf = (record) => Math.max(0, references.get(record.path) ?? 0) + Math.max(0, references.get(idOf(record.id)) ?? 0)
|
|
903
|
+
for (const record of result.pages) {
|
|
904
|
+
const kind = kindOf[record.type]
|
|
905
|
+
if (!kind) continue
|
|
906
|
+
const name = clipText(plainLine(record.title || String(record.path).split("/").pop()), TERM_TEXT_CHARS, 320).text
|
|
907
|
+
if (name) names.push({ name, kind, refs: refsOf(record), space: result.entry.space.id, path: idOf(record.path), aliases: aliasesOf(record, name) })
|
|
908
|
+
}
|
|
909
|
+
// A glossary page's own title is not a name; its entries are, under the page's own count.
|
|
910
|
+
for (const record of result.bodies) {
|
|
911
|
+
const page = result.glossaries.find((glossary) => glossary.path === record?.path)
|
|
912
|
+
const refs = page ? refsOf(page) : 0
|
|
913
|
+
for (const name of glossaryEntries(record?.body)) {
|
|
914
|
+
names.push({ name, kind: "term", refs, space: result.entry.space.id, path: idOf(record?.path), aliases: [] })
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const rank = new Map(NAME_KINDS.map((kind, index) => [kind, index]))
|
|
919
|
+
names.sort(
|
|
920
|
+
(a, b) =>
|
|
921
|
+
b.refs - a.refs ||
|
|
922
|
+
a.name.localeCompare(b.name, "en-GB") ||
|
|
923
|
+
rank.get(a.kind) - rank.get(b.kind) ||
|
|
924
|
+
a.path.localeCompare(b.path) ||
|
|
925
|
+
a.space.localeCompare(b.space),
|
|
926
|
+
)
|
|
927
|
+
// One entry per name: the most referenced one says it, and the aliases of
|
|
928
|
+
// the others join it.
|
|
929
|
+
const merged = new Map()
|
|
930
|
+
for (const name of names) {
|
|
931
|
+
const key = name.name.toLocaleLowerCase("en-GB")
|
|
932
|
+
const kept = merged.get(key)
|
|
933
|
+
if (!kept) {
|
|
934
|
+
merged.set(key, { name: name.name, kind: name.kind, aliases: name.aliases })
|
|
935
|
+
continue
|
|
936
|
+
}
|
|
937
|
+
kept.aliases = [...new Set([...kept.aliases, ...name.aliases])]
|
|
938
|
+
.sort((a, b) => a.localeCompare(b, "en-GB"))
|
|
939
|
+
.slice(0, NAME_ALIASES_MAX)
|
|
940
|
+
}
|
|
941
|
+
const kept = [...merged.values()]
|
|
942
|
+
const out = {
|
|
943
|
+
names: kept.slice(0, NAMES_MAX).map(({ name, kind, aliases }) => ({ name, kind, ...(aliases.length > 0 ? { aliases } : {}) })),
|
|
944
|
+
// A space past the scan, a glossary past its bodies, or more names than one answer holds.
|
|
945
|
+
more: kept.length > NAMES_MAX || results.some((result) => result.cut === true || result.past === true),
|
|
946
|
+
incomplete: [
|
|
947
|
+
...failed.map((result) => ({ id: result.entry.space.id, name: result.entry.space.name, reason: clip(describe(result.error), 200) })),
|
|
948
|
+
...skipped.map((entry) => ({
|
|
949
|
+
id: entry.space.id,
|
|
950
|
+
name: entry.space.name,
|
|
951
|
+
reason: clip(`Not read: a list covers at most ${RECENT_SPACES_MAX} spaces. Choose this space to see its names.`, 200),
|
|
952
|
+
})),
|
|
953
|
+
].slice(0, LIST_MAX),
|
|
954
|
+
}
|
|
955
|
+
return out
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/** A page's own other names (`fields.aliases`), one line each, sorted, never the name itself. */
|
|
959
|
+
function aliasesOf(record, name) {
|
|
960
|
+
const raw = Array.isArray(record?.fields?.aliases) ? record.fields.aliases : []
|
|
961
|
+
const seen = new Set([name.toLocaleLowerCase("en-GB")])
|
|
962
|
+
const aliases = []
|
|
963
|
+
for (const value of raw) {
|
|
964
|
+
if (typeof value !== "string") continue
|
|
965
|
+
const alias = clipText(plainLine(value), TERM_TEXT_CHARS, 320).text
|
|
966
|
+
const key = alias.toLocaleLowerCase("en-GB")
|
|
967
|
+
if (!alias || seen.has(key)) continue
|
|
968
|
+
seen.add(key)
|
|
969
|
+
aliases.push(alias)
|
|
970
|
+
}
|
|
971
|
+
return aliases.sort((a, b) => a.localeCompare(b, "en-GB")).slice(0, NAME_ALIASES_MAX)
|
|
972
|
+
}
|
|
973
|
+
|
|
736
974
|
/**
|
|
737
975
|
* How many memories the personal space keeps (`entry` is the first of
|
|
738
976
|
* `personalScopes()`), for the overview: `{ memories,
|
|
@@ -832,11 +1070,20 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
832
1070
|
function proposalItem(proposal) {
|
|
833
1071
|
const fields = proposal?.fields && typeof proposal.fields === "object" ? proposal.fields : {}
|
|
834
1072
|
const stated = STATED_BY.has(proposal?.stated_by) ? proposal.stated_by : "unknown"
|
|
1073
|
+
// A meeting proposal's citation keeps the moment and the transcript file
|
|
1074
|
+
// (#62), so a host can say when it was said and which recording it came from.
|
|
835
1075
|
const evidence = (Array.isArray(fields.evidence) ? fields.evidence : [])
|
|
836
1076
|
.map((item) => {
|
|
837
1077
|
const kind = ["event", "turn", "record"].find((name) => typeof item?.[name] === "string")
|
|
838
1078
|
const ref = kind ? idOf(item[kind]) : ""
|
|
839
|
-
|
|
1079
|
+
if (!kind || !ref) return null
|
|
1080
|
+
return {
|
|
1081
|
+
kind,
|
|
1082
|
+
ref,
|
|
1083
|
+
quote: clip(item.quote ?? "", 300),
|
|
1084
|
+
...(typeof item.at === "string" && item.at ? { at: clip(item.at, 20) } : {}),
|
|
1085
|
+
...(typeof item.file === "string" && item.file ? { file: clip(item.file, 200) } : {}),
|
|
1086
|
+
}
|
|
840
1087
|
})
|
|
841
1088
|
.filter(Boolean)
|
|
842
1089
|
.slice(0, EVIDENCE_MAX)
|
|
@@ -849,6 +1096,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
849
1096
|
action: clip(fields.action || proposal.type || "", 40),
|
|
850
1097
|
title: clip(proposal.title ?? "", 200),
|
|
851
1098
|
target: clip(fields.target_path || fields.target_id || "", 200),
|
|
1099
|
+
/** The wiki and the folder a page proposal would write to (#63, #76). */
|
|
1100
|
+
...(wikiOf(fields) ? { wiki: wikiOf(fields) } : {}),
|
|
1101
|
+
...(parentOf(fields.target_path) ? { parent: parentOf(fields.target_path) } : {}),
|
|
852
1102
|
reason: clip(fields.reason ?? "", 300),
|
|
853
1103
|
stated_by: stated,
|
|
854
1104
|
...rowSource(proposal.source),
|
|
@@ -858,8 +1108,10 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
858
1108
|
/** Whether Memory holds this write for the person to approve, rather than proposing a record. */
|
|
859
1109
|
held,
|
|
860
1110
|
...(own ? { space: own } : {}),
|
|
1111
|
+
...meetingOf(fields),
|
|
861
1112
|
external: stated === "external",
|
|
862
1113
|
evidence,
|
|
1114
|
+
sources: proposalSources(proposal, evidence),
|
|
863
1115
|
proposed: clipText(proposedText(proposal), 600, 1800).text,
|
|
864
1116
|
expires: clip(fields.expires ?? "", 40),
|
|
865
1117
|
created: clip(proposal.created ?? "", 40),
|
|
@@ -867,6 +1119,59 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
867
1119
|
}
|
|
868
1120
|
}
|
|
869
1121
|
|
|
1122
|
+
/** The wiki a proposal names, where the record carries one the schema takes. */
|
|
1123
|
+
function wikiOf(fields) {
|
|
1124
|
+
const wiki = idOf(fields?.wiki)
|
|
1125
|
+
return wiki ? clip(wiki, 128) : ""
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/** The folder a proposal's path sits in (`projects/harbour` → `projects/`), or "". */
|
|
1129
|
+
function parentOf(path) {
|
|
1130
|
+
const text = typeof path === "string" ? path.trim() : ""
|
|
1131
|
+
const at = text.lastIndexOf("/")
|
|
1132
|
+
return at > 0 ? clip(text.slice(0, at + 1), 300) : ""
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Where a proposal's words came from, as rows the review page lists (#76):
|
|
1137
|
+
* the evidence it cites with its quotes, then the record's own source refs
|
|
1138
|
+
* (an event, a turn, a session, a routine) once each. A quote is the record's
|
|
1139
|
+
* own text, so erasing the record takes it with the rest of the row; a ref is
|
|
1140
|
+
* an id, never a person's name. Bounded by `PROPOSAL_SOURCES_MAX`.
|
|
1141
|
+
*/
|
|
1142
|
+
function proposalSources(proposal, evidence) {
|
|
1143
|
+
const rows = evidence.map((item) => ({ kind: item.kind, ref: item.ref, ...(item.quote ? { quote: item.quote } : {}) }))
|
|
1144
|
+
const seen = new Set(rows.map((row) => `${row.kind} ${row.ref}`))
|
|
1145
|
+
const source = proposal?.source && typeof proposal.source === "object" ? proposal.source : {}
|
|
1146
|
+
for (const kind of ["event", "turn", "session", "routine"]) {
|
|
1147
|
+
const value = typeof source[kind] === "string" ? source[kind].trim() : ""
|
|
1148
|
+
const ref = idOf(value) ? clip(value, 200) : ""
|
|
1149
|
+
if (!ref || seen.has(`${kind} ${ref}`)) continue
|
|
1150
|
+
seen.add(`${kind} ${ref}`)
|
|
1151
|
+
rows.push({ kind, ref })
|
|
1152
|
+
}
|
|
1153
|
+
// A `url` row is safe only while a source removal **withdraws** a waiting
|
|
1154
|
+
// proposal that cites a removed event (`feat/source-removals`): its scrub
|
|
1155
|
+
// drops `fields.evidence` quotes, never `record.source`. If a later change
|
|
1156
|
+
// keeps such proposals listed, drop this row (review R3).
|
|
1157
|
+
const url = typeof source.url === "string" ? source.url.trim() : ""
|
|
1158
|
+
if (url && /^https?:\/\/[^\s<>"']{1,290}$/.test(url) && !seen.has(`url ${url}`)) rows.push({ kind: "url", ref: url })
|
|
1159
|
+
return rows.slice(0, PROPOSAL_SOURCES_MAX)
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* The meeting page a proposal was drawn from (#62): the record's id
|
|
1164
|
+
* (`fields.meeting_id`) and its path (`fields.meeting`), which the meeting
|
|
1165
|
+
* engine writes on every proposal it makes. Absent when the proposal came
|
|
1166
|
+
* from something else, so a page never shows a meeting it does not have.
|
|
1167
|
+
*/
|
|
1168
|
+
function meetingOf(fields) {
|
|
1169
|
+
const id = idOf(fields?.meeting_id)
|
|
1170
|
+
if (!id) return {}
|
|
1171
|
+
const path = typeof fields?.meeting === "string" ? clip(fields.meeting, 300) : ""
|
|
1172
|
+
return { meeting: { id, ...(path ? { path } : {}) } }
|
|
1173
|
+
}
|
|
1174
|
+
|
|
870
1175
|
/**
|
|
871
1176
|
* The space a held team write would be saved in, which the hold recorded from
|
|
872
1177
|
* control (`fields.space_id`, `fields.space_name`: `src/tools/held-write.js`),
|
|
@@ -888,7 +1193,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
888
1193
|
* A proposal's own type (`create`, `append`, `team_write`, `share`, …): what
|
|
889
1194
|
* the record is, for a host that labels an item by it.
|
|
890
1195
|
*/
|
|
891
|
-
const proposalKind = (proposal) => (typeof proposal?.type === "string" && /^[a-zA-Z][a-zA-Z0-9._-]{0,
|
|
1196
|
+
const proposalKind = (proposal) => (typeof proposal?.type === "string" && /^[a-zA-Z][a-zA-Z0-9._-]{0,39}$/.test(proposal.type) ? proposal.type : "")
|
|
892
1197
|
|
|
893
1198
|
/** The session a proposal was made in, where its source names one that could be a session id. */
|
|
894
1199
|
const proposalSession = (proposal) => {
|
|
@@ -933,15 +1238,14 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
933
1238
|
* page whose owner the roster cannot name has no `owner` at all, as in
|
|
934
1239
|
* `pages.read` (an id, or the routines' user, is not a person's name).
|
|
935
1240
|
*/
|
|
936
|
-
const pageRow = (record,
|
|
937
|
-
const
|
|
938
|
-
const name = owner && owner !== ROUTINE_OWNER ? owners.get(owner) : ""
|
|
1241
|
+
const pageRow = (record, members = new Map()) => {
|
|
1242
|
+
const member = memberFor(members, record?.owner)
|
|
939
1243
|
return {
|
|
940
1244
|
path: idOf(record.path),
|
|
941
1245
|
title: clip(record.title || record.path, 200),
|
|
942
1246
|
type: clip(record.type ?? "", 40),
|
|
943
1247
|
updated: clip(record.updated ?? "", 40),
|
|
944
|
-
...(
|
|
1248
|
+
...(member ? { owner: { id: clip(member.id, OWNER_ID_CHARS), name: clip(member.name, OWNER_NAME_CHARS) } } : {}),
|
|
945
1249
|
}
|
|
946
1250
|
}
|
|
947
1251
|
|
|
@@ -1067,16 +1371,17 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1067
1371
|
const record = (answer?.records ?? [])[0]
|
|
1068
1372
|
if (!record || !idOf(record.id)) refuse(ref.path ? "That page isn't in this memory." : "That record isn't in this memory.")
|
|
1069
1373
|
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
|
-
|
|
1374
|
+
// The links' titles and whether any is knowably missing, from the one rule
|
|
1375
|
+
// the tool's page read uses (`src/outlinks.js`): `missing` is null when the
|
|
1376
|
+
// absence is not knowable to this reader, and then the answer says nothing
|
|
1377
|
+
// about existence. A failed backlinks read fails this read: it is never
|
|
1378
|
+
// shown as a page nothing links to.
|
|
1379
|
+
const [{ records: linked, missing }, back] = await Promise.all([
|
|
1380
|
+
readOutlinks({ links: targets, path: record.path, spaceRead: where.spaceRead, call: (method, body) => records(method, body, where.where) }),
|
|
1381
|
+
record.path ? records("records.backlinks", { path: record.path }, where.where) : { records: [] },
|
|
1077
1382
|
])
|
|
1078
1383
|
const known = new Map()
|
|
1079
|
-
for (const found of linked
|
|
1384
|
+
for (const found of linked) {
|
|
1080
1385
|
if (found?.id) known.set(found.id, found)
|
|
1081
1386
|
if (found?.path) known.set(found.path, found)
|
|
1082
1387
|
}
|
|
@@ -1099,7 +1404,13 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1099
1404
|
clipped: false,
|
|
1100
1405
|
outlinks: targets.map((target) => {
|
|
1101
1406
|
const found = known.get(target)
|
|
1102
|
-
|
|
1407
|
+
const row = { target: clip(target, 200), title: clip(found?.title || "", 200) }
|
|
1408
|
+
// `exists` only where it is known: false for a page path this reader can
|
|
1409
|
+
// prove is not there, true for a record it read. Omitted otherwise (a
|
|
1410
|
+
// grant-only reader, a failed lookup, a target past the cap), so the
|
|
1411
|
+
// page never marks a link it cannot answer for.
|
|
1412
|
+
const exists = found ? true : missing?.has(target) ? false : undefined
|
|
1413
|
+
return exists === undefined ? row : { ...row, exists }
|
|
1103
1414
|
}),
|
|
1104
1415
|
backlinks: backlinks.slice(0, LINKS_MAX).map((found) => ({
|
|
1105
1416
|
id: idOf(found.id),
|
|
@@ -1108,6 +1419,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1108
1419
|
type: clip(found.type ?? "", 40),
|
|
1109
1420
|
})),
|
|
1110
1421
|
backlinksMore: backlinks.length > LINKS_MAX || back?.truncated === true,
|
|
1422
|
+
// Only the backlinks this reader can see (the store's own filter): the
|
|
1423
|
+
// page says so rather than "nothing links here".
|
|
1424
|
+
...(where.spaceRead ? {} : { backlinksPartial: true }),
|
|
1111
1425
|
}
|
|
1112
1426
|
const room = Math.max(4_000, ANSWER_BYTES - jsonBytes(out))
|
|
1113
1427
|
const { text, clipped } = clipText(record.body ?? "", RECORD_BODY_CHARS, room)
|
|
@@ -1154,9 +1468,9 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1154
1468
|
* not drawn: its target's own title is not in this read, and a node named by
|
|
1155
1469
|
* half a fact is worse than none. `types` narrows which pages are kept.
|
|
1156
1470
|
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1471
|
+
* Every node then carries its `community` (`addCommunities`): a clustering of
|
|
1472
|
+
* this answer's own pages by their links, computed on the read and never
|
|
1473
|
+
* stored (Jelly's ask 2).
|
|
1160
1474
|
*/
|
|
1161
1475
|
async function folderGraph(folder, where, max, types) {
|
|
1162
1476
|
const answer = await records("records.list", { kind: "page", path_prefix: `${folder}/`, limit: GRAPH_NODES_MAX }, where.where)
|
|
@@ -1200,6 +1514,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1200
1514
|
}
|
|
1201
1515
|
const out = { space: where.space, start: 0, nodes, edges: [], truncated: answer?.truncated === true || Boolean(answer?.cursor) || cut }
|
|
1202
1516
|
if (fitList(out, "edges", edges)) out.truncated = true
|
|
1517
|
+
addCommunities(out)
|
|
1203
1518
|
return out
|
|
1204
1519
|
}
|
|
1205
1520
|
|
|
@@ -1267,6 +1582,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1267
1582
|
}
|
|
1268
1583
|
const out = { space: where.space, start, nodes, edges: [], truncated: answer?.truncated === true || cut }
|
|
1269
1584
|
if (fitList(out, "edges", edges)) out.truncated = true
|
|
1585
|
+
addCommunities(out)
|
|
1270
1586
|
return out
|
|
1271
1587
|
}
|
|
1272
1588
|
|
|
@@ -1284,6 +1600,7 @@ export function createRecordsReads({ runtime, personalScopes, available, describ
|
|
|
1284
1600
|
"pages.history": pagesHistory,
|
|
1285
1601
|
"graph.links": graphLinks,
|
|
1286
1602
|
"terms.list": termsList,
|
|
1603
|
+
"names.known": namesKnown,
|
|
1287
1604
|
},
|
|
1288
1605
|
}
|
|
1289
1606
|
}
|