@joe-broadhead/opencode-mem 0.9.5 → 0.9.12
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 +1281 -0
- package/README.md +105 -31
- package/docs/agent-protocol.md +28 -27
- package/docs/permissions.md +148 -0
- package/package.json +24 -12
- package/skills/mem.pages/SKILL.md +35 -16
- package/skills/mem.sharing/SKILL.md +39 -6
- package/skills/mem.sources/SKILL.md +41 -10
- package/skills/mem.usage/SKILL.md +37 -16
- package/src/backend/records.js +8 -0
- package/src/backend/v3.js +15 -10
- package/src/call-shapes.js +18 -25
- package/src/capture-pause.js +136 -0
- package/src/capture.js +7 -5
- package/src/collector-service.js +212 -35
- package/src/collector.js +186 -47
- package/src/commands.js +37 -0
- package/src/compaction.js +4 -2
- package/src/config.js +151 -1
- package/src/curation.js +6 -10
- package/src/events.js +144 -36
- package/src/forget-purge.js +377 -0
- package/src/forgotten.js +152 -0
- package/src/hooks.js +9 -4
- package/src/index.js +5 -3
- package/src/permissions.js +116 -38
- package/src/protocol.js +21 -11
- package/src/records.js +4 -1
- package/src/runtime.js +202 -15
- package/src/shapes.js +63 -0
- package/src/sources.js +183 -12
- package/src/spaces.js +58 -1
- package/src/spool.js +442 -64
- package/src/stated.js +334 -0
- package/src/storable.js +477 -0
- package/src/tools/aliases.js +36 -147
- package/src/tools/commitments.js +69 -12
- package/src/tools/index.js +25 -43
- package/src/tools/ingest.js +33 -128
- package/src/tools/memory.js +503 -904
- package/src/tools/page-sections.js +147 -0
- package/src/tools/page.js +314 -82
- package/src/tools/recall-browse.js +173 -0
- package/src/tools/recall.js +36 -8
- package/src/tools/share.js +494 -131
- package/src/tools/shared.js +97 -19
- package/src/tools/spaces.js +194 -101
- package/src/tools/status.js +31 -3
- package/src/tools/wiki.js +5 -13
- package/src/util.js +10 -59
- package/src/views/profile.js +2 -3
- package/src/views/records-reads.js +6 -1
- package/src/erase.js +0 -36
package/src/spaces.js
CHANGED
|
@@ -184,14 +184,18 @@ export function createControlClient(input) {
|
|
|
184
184
|
* spaceId?: string,
|
|
185
185
|
* sessionId?: string,
|
|
186
186
|
* agent?: string,
|
|
187
|
+
* bind?: boolean,
|
|
187
188
|
* }} input
|
|
189
|
+
* `bind: true` (with a session) is the one request that changes the
|
|
190
|
+
* session's binding: to `spaceId`, or to the personal space without one.
|
|
188
191
|
*/
|
|
189
|
-
async function resolveContext({ userId, spaceId, sessionId, agent } = {}) {
|
|
192
|
+
async function resolveContext({ userId, spaceId, sessionId, agent, bind } = {}) {
|
|
190
193
|
if (!userId) throw missing("context", "user_id")
|
|
191
194
|
const body = { user_id: String(userId) }
|
|
192
195
|
if (spaceId) body.space_id = String(spaceId)
|
|
193
196
|
if (sessionId) body.session_id = String(sessionId)
|
|
194
197
|
if (agent) body.agent = String(agent)
|
|
198
|
+
if (bind === true && sessionId) body.bind = true
|
|
195
199
|
|
|
196
200
|
const payload = await request("context", "POST", "/v1/context", { body })
|
|
197
201
|
const context = normalizeContext(payload, { userId: body.user_id, spaceId })
|
|
@@ -367,10 +371,63 @@ export function createControlClient(input) {
|
|
|
367
371
|
return extractMemberList(payload).map(normalizeMember).filter((member) => member.user_id)
|
|
368
372
|
}
|
|
369
373
|
|
|
374
|
+
/**
|
|
375
|
+
* One colleague by exact email (mem_share grant and transfer, after the
|
|
376
|
+
* co-member search): `GET /v1/users/lookup?email=`. Answers `{ user_id,
|
|
377
|
+
* name }` for the one active user of the caller's organisation with that
|
|
378
|
+
* address, or null. Control limits each caller (429 lookup_rate_limited);
|
|
379
|
+
* there is no listing (docs/design/adr-user-lookup.md).
|
|
380
|
+
*
|
|
381
|
+
* @param {{ userId: string, email: string }} input
|
|
382
|
+
* @returns {Promise<{ user_id: string, name: string } | null>}
|
|
383
|
+
*/
|
|
384
|
+
async function lookupUser({ userId, email } = {}) {
|
|
385
|
+
if (!userId) throw missing("lookup", "user_id")
|
|
386
|
+
if (!email) throw missing("lookup", "email")
|
|
387
|
+
const payload = await request("lookup", "GET", "/v1/users/lookup", { query: { email: String(email) } })
|
|
388
|
+
const user = isPlainObject(payload?.user) ? payload.user : null
|
|
389
|
+
const id = text(user?.user_id)
|
|
390
|
+
return id ? { user_id: id, name: text(user.name) } : null
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* The records pages and folders others shared with the caller, in every
|
|
395
|
+
* space (mem_share list with "to": "me"): `GET /v1/shared-with-me`. Only
|
|
396
|
+
* display fields are kept.
|
|
397
|
+
*
|
|
398
|
+
* @param {{ userId: string }} input
|
|
399
|
+
*/
|
|
400
|
+
async function sharedWithMe({ userId } = {}) {
|
|
401
|
+
if (!userId) throw missing("shared", "user_id")
|
|
402
|
+
const payload = await request("shared", "GET", "/v1/shared-with-me")
|
|
403
|
+
const rows = Array.isArray(payload?.shares) ? payload.shares : []
|
|
404
|
+
const person = (value) => (isPlainObject(value) && text(value.user_id) ? { user_id: text(value.user_id), name: text(value.name), email: text(value.email) } : null)
|
|
405
|
+
return {
|
|
406
|
+
shares: rows
|
|
407
|
+
.filter((row) => isPlainObject(row) && /^[a-z0-9][a-z0-9/-]{0,300}$/.test(text(row.path)) && text(row.space?.id))
|
|
408
|
+
.map((row) => ({
|
|
409
|
+
path: text(row.path),
|
|
410
|
+
kind: text(row.kind) === "folder" ? "folder" : "page",
|
|
411
|
+
name: text(row.name),
|
|
412
|
+
space_id: text(row.space.id),
|
|
413
|
+
space_name: text(row.space.name),
|
|
414
|
+
space_kind: text(row.space.kind),
|
|
415
|
+
owner: person(row.owner),
|
|
416
|
+
role: text(row.role) === "editor" ? "editor" : "viewer",
|
|
417
|
+
via: text(row.via),
|
|
418
|
+
expires_at: text(row.expires_at),
|
|
419
|
+
grant_id: text(row.grant_id),
|
|
420
|
+
})),
|
|
421
|
+
more: Number.isInteger(payload?.more) ? payload.more : 0,
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
370
425
|
return {
|
|
371
426
|
get controlURL() {
|
|
372
427
|
return controlURLOf()
|
|
373
428
|
},
|
|
429
|
+
lookupUser,
|
|
430
|
+
sharedWithMe,
|
|
374
431
|
listSpaces,
|
|
375
432
|
resolveContext,
|
|
376
433
|
effectiveAccess,
|