@joe-broadhead/opencode-mem 0.9.12 → 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 +1934 -2
- package/README.md +29 -17
- package/SECURITY.md +3 -1
- package/docs/agent-instructions.md +17 -0
- package/docs/agent-protocol.md +8 -8
- package/docs/permissions.md +22 -4
- package/package.json +7923 -217
- package/shared/page-paths.js +44 -0
- package/skills/mem.pages/SKILL.md +8 -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 +627 -33
- 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 +21 -5
- package/src/recall.js +104 -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 +409 -90
- 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 +47 -5
- package/src/tools/held-write.js +36 -13
- package/src/tools/index.js +27 -0
- package/src/tools/ingest.js +27 -2
- package/src/tools/memory.js +52 -14
- package/src/tools/page.js +95 -9
- package/src/tools/recall.js +208 -4
- package/src/tools/records-kit.js +2 -1
- 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 +1183 -36
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/overdue.js +1 -1
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +81 -0
- package/src/views/records-reads.js +869 -37
- package/src/views/rpc.js +159 -11
- package/src/views/shape.js +8 -5
- package/views/memory.html +16 -3
- package/views/pages.html +2 -2
- package/views/remembered.html +130 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { INBOX_READ_BYTES_MAX } from "./contracts.js"
|
|
2
|
+
import { clip, jsonBytes, refuse } from "./shape.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One Inbox read, held under the host's byte cap.
|
|
6
|
+
*
|
|
7
|
+
* Jelly sizes a plugin RPC answer at 65,536 bytes (`VIEW_DATA_MAX_BYTES`) and
|
|
8
|
+
* refuses a larger one silently, keeping the person's last Inbox
|
|
9
|
+
* (`backend/host/src/plugin-views/rpc.ts:247`).
|
|
10
|
+
*
|
|
11
|
+
* **A guard, not a fix.** Today's read peaks at 28–33 KB and nothing is
|
|
12
|
+
* trimmed. The cap is for the day an Inbox item carries its meeting
|
|
13
|
+
* (`INBOX_ITEM_MEETING`): with those fields on, a full Inbox of proposals whose
|
|
14
|
+
* moments are quoted in CJK comes to about 75–80 KB, and this trims it to about
|
|
15
|
+
* 61 KB.
|
|
16
|
+
*
|
|
17
|
+
* What is given up, from the last item backwards:
|
|
18
|
+
*
|
|
19
|
+
* 1. **`evidence` entries**;
|
|
20
|
+
* 2. then **`meeting`**;
|
|
21
|
+
* 3. then the **words**, `line` and `name`, cut on a character boundary and
|
|
22
|
+
* ending in "…".
|
|
23
|
+
*
|
|
24
|
+
* Stages 1 and 2 are spent across every item before the next begins, so no item
|
|
25
|
+
* is made unreadable while another still carries what it could give up. The
|
|
26
|
+
* words are not: the last item is shortened as far as it needs before the one
|
|
27
|
+
* above is touched at all.
|
|
28
|
+
*
|
|
29
|
+
* **Never an item and never a `key`.** The host replaces its whole copy with
|
|
30
|
+
* each answer, so an item left out is one that vanishes from the person's Inbox
|
|
31
|
+
* while it is still true. When even the trimmed answer cannot be carried, the
|
|
32
|
+
* read refuses as an unreadable part does today, and the host keeps what it
|
|
33
|
+
* had.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/** What goes before the words, in the order it goes. */
|
|
37
|
+
const OPTIONAL = ["evidence", "meeting"]
|
|
38
|
+
|
|
39
|
+
/** The words a too-large answer refuses with: the read fails whole, as an unreadable part does. */
|
|
40
|
+
export const INBOX_TOO_LARGE = "The Inbox is too large to read in one answer, so it has not been read."
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* `answer` (its `items`) held under `limit` UTF-8 bytes of JSON, trimmed as
|
|
44
|
+
* this module's header describes, or a refusal when even that cannot fit.
|
|
45
|
+
*
|
|
46
|
+
* @template {{ items: Array<object> }} Answer
|
|
47
|
+
* @param {Answer} answer
|
|
48
|
+
* @param {number} [limit]
|
|
49
|
+
* @returns {Answer}
|
|
50
|
+
*/
|
|
51
|
+
export function fitInboxRead(answer, limit = INBOX_READ_BYTES_MAX) {
|
|
52
|
+
if (jsonBytes(answer) <= limit) return answer
|
|
53
|
+
const items = answer.items.map((item) => ({ ...item }))
|
|
54
|
+
const fitted = { ...answer, items }
|
|
55
|
+
const over = () => jsonBytes(fitted) > limit
|
|
56
|
+
|
|
57
|
+
for (const field of OPTIONAL) {
|
|
58
|
+
for (let at = items.length - 1; at >= 0 && over(); at -= 1) {
|
|
59
|
+
if (field === "evidence") {
|
|
60
|
+
// One entry at a time, so an answer a single moment over the cap keeps the rest.
|
|
61
|
+
while (over() && Array.isArray(items[at].evidence) && items[at].evidence.length > 0)
|
|
62
|
+
items[at].evidence = items[at].evidence.slice(0, -1)
|
|
63
|
+
} else if (items[at].meeting !== undefined) {
|
|
64
|
+
delete items[at].meeting
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (let at = items.length - 1; at >= 0 && over(); at -= 1) {
|
|
70
|
+
for (const field of ["line", "name"]) {
|
|
71
|
+
const text = items[at][field]
|
|
72
|
+
if (typeof text === "string" && text !== "") items[at][field] = shorten(fitted, items[at], field, text, limit)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (over()) refuse(INBOX_TOO_LARGE)
|
|
77
|
+
return fitted
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `text` shortened to the longest prefix, ending in "…", that keeps `answer`
|
|
82
|
+
* under `limit`; `"…"`, the shortest the words can be, when no prefix does.
|
|
83
|
+
*
|
|
84
|
+
* The search starts at one character: `clip(text, 1)` is `"…"` for any text,
|
|
85
|
+
* and `clip(text, 0)` is not shorter than it (`oneLine` cuts at `max - 1`, a
|
|
86
|
+
* negative index at zero).
|
|
87
|
+
*/
|
|
88
|
+
function shorten(answer, item, field, text, limit) {
|
|
89
|
+
let shortest = null
|
|
90
|
+
let low = 1
|
|
91
|
+
let high = text.length
|
|
92
|
+
while (low <= high) {
|
|
93
|
+
const at = (low + high) >> 1
|
|
94
|
+
item[field] = clip(text, at)
|
|
95
|
+
if (jsonBytes(answer) <= limit) {
|
|
96
|
+
shortest = item[field]
|
|
97
|
+
low = at + 1
|
|
98
|
+
} else {
|
|
99
|
+
high = at - 1
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return shortest ?? "…"
|
|
103
|
+
}
|
package/src/views/overdue.js
CHANGED
|
@@ -118,7 +118,7 @@ export function overdueInboxItems(items, { now, zone, max = OVERDUE_MAX }) {
|
|
|
118
118
|
if (key.length > 200) continue
|
|
119
119
|
const tail = ` · ${ownerWords(found.owner)} · overdue ${found.days} ${found.days === 1 ? "day" : "days"}, due ${formatDay(found.day)}`
|
|
120
120
|
const title = oneLinePlain(found.what, Math.max(10, 120 - tail.length)) || "A commitment"
|
|
121
|
-
out.push({ key, category: OVERDUE_CATEGORY, label: OVERDUE_LABEL, name: "Memory", line: `${title}${tail}`, at })
|
|
121
|
+
out.push({ key, kind: "commitment", category: OVERDUE_CATEGORY, label: OVERDUE_LABEL, name: "Memory", line: `${title}${tail}`, at })
|
|
122
122
|
if (out.length >= max) break
|
|
123
123
|
}
|
|
124
124
|
return out
|
package/src/views/profile.js
CHANGED
|
@@ -9,6 +9,37 @@ import {
|
|
|
9
9
|
} from "./contracts.js"
|
|
10
10
|
import { clip, clipText, fitList, mapLimit, spaceOf } from "./shape.js"
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The erase the person's About-you page offers: a text operation, not a model
|
|
14
|
+
* call. Every line that holds the phrase (case-insensitive, at least
|
|
15
|
+
* `MIN_ERASE_CHARS` long) is removed from the persona and from each scenario,
|
|
16
|
+
* and nothing else. It does not touch the turns and atoms the text was distilled
|
|
17
|
+
* from, so a later consolidation can write it back: the preview says so. These
|
|
18
|
+
* are the same rules the console's Profile page erases by
|
|
19
|
+
* (`deploy/auth/console/profile-area.mjs`).
|
|
20
|
+
*/
|
|
21
|
+
export const MIN_ERASE_CHARS = 4
|
|
22
|
+
|
|
23
|
+
const folded = (text) => String(text ?? "").toLowerCase()
|
|
24
|
+
|
|
25
|
+
/** True when the text holds the phrase, case-insensitively. */
|
|
26
|
+
export function containsPhrase(text, phrase) {
|
|
27
|
+
const needle = folded(phrase).trim()
|
|
28
|
+
return needle.length > 0 && folded(text).includes(needle)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The lines of `content` that hold the phrase, in order. */
|
|
32
|
+
export function matchingLines(content, phrase) {
|
|
33
|
+
return String(content ?? "").split("\n").filter((line) => containsPhrase(line, phrase))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `content` without the lines that hold the phrase, and how many went. */
|
|
37
|
+
export function eraseLines(content, phrase) {
|
|
38
|
+
const lines = String(content ?? "").split("\n")
|
|
39
|
+
const kept = lines.filter((line) => !containsPhrase(line, phrase))
|
|
40
|
+
return { content: kept.join("\n"), removed: lines.length - kept.length }
|
|
41
|
+
}
|
|
42
|
+
|
|
12
43
|
/** Said in `notes` when more is held than the answer shows. */
|
|
13
44
|
const LEFT_OUT = "Some of what Memory holds about you is not shown here, to keep this short."
|
|
14
45
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { idOf, SPACE_KINDS } from "./shape.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The bounded metadata a write's result carries (`metadata.memoryReceipt`),
|
|
5
|
+
* built the way `recallResultView` builds `metadata.memoryRecall`: what a call
|
|
6
|
+
* saved or changed, and nothing else, so a host can count a turn's receipts
|
|
7
|
+
* and the `remembered` tool-result view can draw one.
|
|
8
|
+
*
|
|
9
|
+
* It names the record the call wrote (its id) and the three space fields the
|
|
10
|
+
* views declare, and it shows the record's title in one short line: display
|
|
11
|
+
* metadata for the person who made the write, never a second copy of what the
|
|
12
|
+
* store holds. A call that stored or changed one record answers a receipt; a
|
|
13
|
+
* call that changed several, or that refused before writing, answers none.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The writes that answer a receipt, in the view's own words. */
|
|
17
|
+
export const RECEIPT_ACTIONS = Object.freeze(["remembered", "corrected", "confirmed", "retired", "restored", "committed"])
|
|
18
|
+
|
|
19
|
+
/** The tool verb of each receipt (`mem_remember`, `mem_revise`'s actions, `mem_commitments add`). */
|
|
20
|
+
const VERB_ACTIONS = Object.freeze({ remember: "remembered", correct: "corrected", confirm: "confirmed", retire: "retired", restore: "restored", commit: "committed" })
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The receipt for one write, named by the tool's own verb: the tools call this
|
|
24
|
+
* rather than building the object, so the approval-action reader
|
|
25
|
+
* (`scripts/approval-actions.mjs`) never mistakes a receipt's action for an
|
|
26
|
+
* ask.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} verb remember, correct, confirm, retire, restore or commit
|
|
29
|
+
* @param {{ record?: any, space?: any }} write
|
|
30
|
+
*/
|
|
31
|
+
export function writeReceipt(verb, { record, space } = {}) {
|
|
32
|
+
return receiptView({ action: VERB_ACTIONS[verb], record, space })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Characters of a receipt's title. */
|
|
36
|
+
export const RECEIPT_TITLE_CHARS = 200
|
|
37
|
+
|
|
38
|
+
/** One line, at most `max` characters, with no control character left in it. */
|
|
39
|
+
const line = (value, max) =>
|
|
40
|
+
String(value ?? "")
|
|
41
|
+
.replace(/[\u0000-\u001f\u007f]/g, " ")
|
|
42
|
+
.replace(/\s+/g, " ")
|
|
43
|
+
.trim()
|
|
44
|
+
.slice(0, max)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The receipt a result carries, or undefined when the call has nothing to
|
|
48
|
+
* report as saved (no record id, or an action the view does not know).
|
|
49
|
+
*
|
|
50
|
+
* @param {{ action?: string, record?: any, space?: { id?: string, name?: string, kind?: string } }} input
|
|
51
|
+
* @returns {{ v: 1, action: string, id: string, kind: string, type: string, status: string, space: { id: string, name: string, kind: string }, title: string } | undefined}
|
|
52
|
+
*/
|
|
53
|
+
export function receiptView({ action, record, space } = {}) {
|
|
54
|
+
if (!RECEIPT_ACTIONS.includes(action)) return undefined
|
|
55
|
+
const id = idOf(record?.id)
|
|
56
|
+
if (!id) return undefined
|
|
57
|
+
return {
|
|
58
|
+
v: 1,
|
|
59
|
+
action,
|
|
60
|
+
id,
|
|
61
|
+
kind: line(record?.kind, 20),
|
|
62
|
+
type: line(record?.type, 40),
|
|
63
|
+
status: line(record?.status, 20),
|
|
64
|
+
space: {
|
|
65
|
+
id: idOf(space?.id) || "unknown",
|
|
66
|
+
name: line(space?.name, 200),
|
|
67
|
+
kind: SPACE_KINDS.has(space?.kind) ? space.kind : "unknown",
|
|
68
|
+
},
|
|
69
|
+
title: line(record?.title, RECEIPT_TITLE_CHARS),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A tool result with its receipt beside its text, or the result exactly as it
|
|
75
|
+
* is when the call has nothing to report as saved. `metadata` is the one place
|
|
76
|
+
* a host reads a result's display data (`memoryRecall` uses the same).
|
|
77
|
+
*
|
|
78
|
+
* @param {{ content: string, metadata?: object }} result
|
|
79
|
+
* @param {ReturnType<typeof receiptView>} receipt
|
|
80
|
+
*/
|
|
81
|
+
export const withReceipt = (result, receipt) => (receipt ? { ...result, metadata: { ...(result.metadata ?? {}), memoryReceipt: receipt } } : result)
|