@joe-broadhead/opencode-mem 0.7.1 → 0.8.0
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/README.md +28 -3
- package/docs/agent-protocol.md +166 -170
- package/package.json +125 -2
- package/skills/mem-usage/SKILL.md +443 -357
- package/src/bootstrap.js +10 -2
- package/src/call-shapes.js +30 -0
- package/src/config.js +39 -0
- package/src/curation.js +45 -9
- package/src/protocol.js +12 -11
- package/src/recall.js +85 -24
- package/src/records-store.js +207 -0
- package/src/records.js +440 -0
- package/src/runtime.js +38 -2
- package/src/skills.js +10 -2
- package/src/tools/commitments.js +209 -0
- package/src/tools/index.js +9 -2
- package/src/tools/knowledge.js +19 -3
- package/src/tools/memory.js +96 -16
- package/src/tools/recall.js +5 -1
- package/src/tools/shared.js +1 -1
- package/src/tools/spaces.js +3 -3
- package/src/tools/status.js +1 -1
- package/src/tools/wiki.js +166 -30
- package/src/views/contracts.js +54 -1
- package/src/views/rpc.js +48 -2
- package/views/commitments.html +226 -0
- package/views/memory.html +77 -1
package/src/tools/wiki.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { quarantineNote, quarantineText } from "../curation.js"
|
|
2
|
+
import { RECORDS_FILE, RECORDS_WIKI, isRecordsText } from "../records.js"
|
|
3
|
+
import { errorMessage, neutralizeFenceClosers, oneLine, redactSecrets } from "../util.js"
|
|
4
|
+
import { discoverKnowledge, isRecordsWikiName, searchKnowledge } from "./knowledge.js"
|
|
3
5
|
|
|
4
6
|
const MAX_FILE_BYTES = 512 * 1024
|
|
5
7
|
const DEFAULT_FILE = "README.md"
|
|
8
|
+
/** The wiki actions that change knowledge; every other action only reads. */
|
|
9
|
+
export const WIKI_WRITE_ACTIONS = Object.freeze(["create", "write", "append"])
|
|
10
|
+
/** How much of a team write the approval shows. */
|
|
11
|
+
const APPROVAL_EXCERPT_CHARS = 400
|
|
12
|
+
const RECORDS_REFUSAL = `the "${RECORDS_WIKI}" wiki holds commitments; use mem_commitments to list, add, update, or delete them.`
|
|
6
13
|
/** Plugin guidance after search hits, outside the untrusted fence. */
|
|
7
14
|
const READ_HINT =
|
|
8
15
|
"To read a wiki hit in full: mem_wiki with action \"read\", wiki_id = the hit's source, ref = the hit's path."
|
|
@@ -11,9 +18,10 @@ const READ_HINT =
|
|
|
11
18
|
* `mem_wiki`: read, search, and write durable knowledge pages.
|
|
12
19
|
*
|
|
13
20
|
* Memory is for atomic decisions and constraints; the wiki is for the coherent
|
|
14
|
-
* synthesis that would otherwise be re-derived:
|
|
15
|
-
* decision
|
|
16
|
-
*
|
|
21
|
+
* synthesis that would otherwise be re-derived: project, person, team,
|
|
22
|
+
* decision, runbook, and glossary pages in one knowledge wiki per space. Where
|
|
23
|
+
* a project stands goes in its page's dated Status section; things to do are
|
|
24
|
+
* commitments (mem_commitments), never a checklist on a page.
|
|
17
25
|
*
|
|
18
26
|
* @param {any} editor
|
|
19
27
|
* @param {ReturnType<import("./shared.js").createToolkit>} toolkit
|
|
@@ -46,7 +54,36 @@ export function registerWiki(editor, toolkit) {
|
|
|
46
54
|
return oneLine(raw, 240)
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
/**
|
|
58
|
+
* The source file a write or append changes. A model that read a page by the
|
|
59
|
+
* path a search showed ("wiki/projects/harbour.md") passes that path back;
|
|
60
|
+
* the source file is "projects/harbour.md". With no name at all a write is
|
|
61
|
+
* refused rather than landing in README.md.
|
|
62
|
+
*/
|
|
63
|
+
function writeTarget(input) {
|
|
64
|
+
const given = input?.filename ?? input?.path ?? input?.ref
|
|
65
|
+
if (given === undefined || given === null || String(given).trim() === "") return { missing: true }
|
|
66
|
+
const name = filenameOf({ filename: String(given).trim().replace(/^\/*wiki\//, "") })
|
|
67
|
+
return name ? { filename: name } : { invalid: true }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What a team write's approval shows: the action, the file, the size, and
|
|
72
|
+
* the start of the text (secrets redacted), so the person sees what lands in
|
|
73
|
+
* the team's wiki before it does.
|
|
74
|
+
*/
|
|
75
|
+
function approvalOf(action, input, filename, content) {
|
|
76
|
+
return {
|
|
77
|
+
kind: "wiki",
|
|
78
|
+
action,
|
|
79
|
+
filename,
|
|
80
|
+
...(action === "create" ? { name: oneLine(input?.name, 200) } : {}),
|
|
81
|
+
bytes: Buffer.byteLength(content),
|
|
82
|
+
excerpt: redactSecrets(content.slice(0, APPROVAL_EXCERPT_CHARS)),
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function resolveWrite(input, context, visibility, approval) {
|
|
50
87
|
const resolved = await resolveWriteSpace(input, context, visibility)
|
|
51
88
|
if (resolved.invalid) return { invalid: resolved.invalid }
|
|
52
89
|
if (resolved.error) return { error: resolved.error }
|
|
@@ -58,7 +95,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
58
95
|
// and mem_forget already do, and the wiki is the more durable of the three.
|
|
59
96
|
if (visibility === "team") {
|
|
60
97
|
try {
|
|
61
|
-
await assertTeamWrite(context, "wiki.write", [spaceContext?.space_id ?? "team"],
|
|
98
|
+
await assertTeamWrite(context, "wiki.write", [spaceContext?.space_id ?? "team"], approval)
|
|
62
99
|
} catch (error) {
|
|
63
100
|
return { denied: errorMessage(error) }
|
|
64
101
|
}
|
|
@@ -107,7 +144,10 @@ export function registerWiki(editor, toolkit) {
|
|
|
107
144
|
if (given) return { wikiID: given, note: "" }
|
|
108
145
|
const ids = [...new Set(await discoverKnowledge(backend, log, "llm_wiki", scoped))]
|
|
109
146
|
if (ids.length === 1) return { wikiID: ids[0], note: `(wiki_id not given; using the only visible wiki, ${oneLine(ids[0], 80)})\n` }
|
|
110
|
-
|
|
147
|
+
// No wiki at all: a read or status answers like list and search do (what
|
|
148
|
+
// was checked, and that nothing more exists), so the agent does not list,
|
|
149
|
+
// ask for a status, or search to make sure. A write keeps the refusal.
|
|
150
|
+
if (ids.length === 0) return { empty: true, error: `wiki_id is required for ${action}; no wiki is visible in this scope` }
|
|
111
151
|
return {
|
|
112
152
|
error: `wiki_id is required for ${action}; visible wikis: ${ids
|
|
113
153
|
.slice(0, 10)
|
|
@@ -143,6 +183,35 @@ export function registerWiki(editor, toolkit) {
|
|
|
143
183
|
return { source: `${wikiID}/${filename}`, content: item.content }
|
|
144
184
|
}
|
|
145
185
|
|
|
186
|
+
/**
|
|
187
|
+
* The answer when a space has no wiki or code graph. Like recall's miss, it
|
|
188
|
+
* says what was checked and what that means, so the agent does not list
|
|
189
|
+
* again with another visibility, ask for a status, or search to make sure.
|
|
190
|
+
*/
|
|
191
|
+
function emptyKnowledge(input, spaceContext) {
|
|
192
|
+
// Knowledge belongs to a space, not an agent: name the space.
|
|
193
|
+
const where = spaceContext ? toolkit.describeSpace(spaceContext) : "the local scope"
|
|
194
|
+
const checked =
|
|
195
|
+
input?.visibility === "private" || input?.visibility === "team"
|
|
196
|
+
? `only ${input.visibility} knowledge was checked; a list without visibility checks both`
|
|
197
|
+
: "private and shared knowledge were both checked"
|
|
198
|
+
return `no accessible knowledge assets in ${where}: ${checked}. No wiki or page exists here yet, so there is nothing to read or search; listing again finds nothing more. Create the space's knowledge wiki with action "create" when a page is needed.`
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A wiki's source file names, at most `max`; [] when the listing fails. */
|
|
202
|
+
async function sourceFiles(scoped, wikiID, max = 15) {
|
|
203
|
+
try {
|
|
204
|
+
const sources = await backend.knowledgeCall({ knowledgeID: wikiID, toolName: "list_raw", params: {}, scope: scoped })
|
|
205
|
+
const names = (Array.isArray(sources) ? sources : sources?.items ?? [])
|
|
206
|
+
.map((item) => (typeof item === "string" ? item : item?.filename))
|
|
207
|
+
.filter(Boolean)
|
|
208
|
+
.sort()
|
|
209
|
+
return { names: names.slice(0, max), more: Math.max(0, names.length - max) }
|
|
210
|
+
} catch {
|
|
211
|
+
return { names: [], more: 0 }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
146
215
|
/** What exists, so the next read can name it. */
|
|
147
216
|
async function notFound(scoped, wikiID, name) {
|
|
148
217
|
const [pages, sources] = await Promise.all([
|
|
@@ -165,28 +234,36 @@ export function registerWiki(editor, toolkit) {
|
|
|
165
234
|
editor.add({
|
|
166
235
|
name: "wiki",
|
|
167
236
|
description:
|
|
168
|
-
"Read, search, or write
|
|
237
|
+
"Read, search, or write knowledge pages. Each space has one knowledge wiki (\"My knowledge\" in the personal space) holding index.md, log.md, projects/<slug>.md, people/<slug>.md (private only), teams/, decisions/, runbooks/, and glossary.md. Use list/search/read for documentation, architecture, ownership, runbooks, a project's status, and call-graph questions; read index.md before creating a page and extend an existing one. Use write to replace a page (one write per page per session) and append for log.md. Where a project stands goes in its page's dated Status section, replaced on update; things to do go in mem_commitments, never as a checklist on a page. A team write asks the person and shows the file and an excerpt.",
|
|
169
238
|
input: {
|
|
170
239
|
type: "object",
|
|
171
240
|
properties: {
|
|
172
241
|
action: {
|
|
173
242
|
type: "string",
|
|
174
243
|
enum: ["list", "search", "create", "write", "append", "read", "status"],
|
|
175
|
-
description:
|
|
244
|
+
description:
|
|
245
|
+
'Required. Read-only: list, search, read, status. Writes: create, write, append. Example: {"action": "search", "query": "onboarding guide"}',
|
|
176
246
|
},
|
|
177
247
|
query: { type: "string", description: "Search query (required for action=search)" },
|
|
178
248
|
knowledge_id: {
|
|
179
249
|
type: "string",
|
|
180
250
|
description: "Restrict a search to one id returned by action=list (the wiki/code-graph id, not an ACL asset id)",
|
|
181
251
|
},
|
|
182
|
-
wiki_id: { type: "string", description: "Wiki id for write/append
|
|
252
|
+
wiki_id: { type: "string", description: "Wiki id for read/status/write/append; optional when exactly one wiki is visible (the answer names it)" },
|
|
183
253
|
name: { type: "string", description: "Human-readable wiki name for action=create" },
|
|
184
|
-
filename: {
|
|
185
|
-
|
|
254
|
+
filename: {
|
|
255
|
+
type: "string",
|
|
256
|
+
description: `Source file to create, write, or append, for example "projects/harbour.md" (required for write and append; create defaults to ${DEFAULT_FILE}). Read takes it too. Path traversal is rejected`,
|
|
257
|
+
},
|
|
258
|
+
content: {
|
|
259
|
+
type: "string",
|
|
260
|
+
description:
|
|
261
|
+
"Markdown for create, write (replaces the file), or append. A project page (projects/<slug>.md) is: # Name; Updated YYYY-MM-DD · Owner · Tracker; ## Purpose; ## Status (as of YYYY-MM-DD), replaced on every update; ## Decisions (- YYYY-MM-DD: decision, because why); ## Open questions; ## People; ## Links; ## Log (one line appended per change). No checkboxes: things to do are mem_commitments",
|
|
262
|
+
},
|
|
186
263
|
ingest: { type: "boolean", description: "Trigger extraction after write/append (default true)" },
|
|
187
264
|
ref: {
|
|
188
265
|
type: "string",
|
|
189
|
-
description: "Page to read (action=read): the `path` a search hit shows, or a page id from status",
|
|
266
|
+
description: "Page to read (action=read): the `path` a search hit shows (its source file is read first, so a page just written reads current), or a page id from status",
|
|
190
267
|
},
|
|
191
268
|
path: { type: "string", description: "Same as ref: the page path a search hit shows" },
|
|
192
269
|
visibility: {
|
|
@@ -205,12 +282,22 @@ export function registerWiki(editor, toolkit) {
|
|
|
205
282
|
const action = String(input?.action ?? "list")
|
|
206
283
|
const visibility = visibilityOf(input)
|
|
207
284
|
|
|
208
|
-
if (
|
|
285
|
+
if (WIKI_WRITE_ACTIONS.includes(action)) {
|
|
209
286
|
const content = String(input?.content ?? "")
|
|
210
287
|
if (action !== "create" && !content.trim()) return text(`nothing to ${action}: content is empty`)
|
|
211
288
|
if (Buffer.byteLength(content) > MAX_FILE_BYTES) return text("wiki content is too large (max 512 KB)")
|
|
289
|
+
const target = action === "create" ? filenameOf(input) : writeTarget(input).filename ?? ""
|
|
290
|
+
// The records wiki is mem_commitments' store: never written here.
|
|
291
|
+
if (
|
|
292
|
+
(action === "create" && isRecordsWikiName(oneLine(input?.name, 200).trim())) ||
|
|
293
|
+
toolkit.runtime.records?.isRecordsWiki(input?.wiki_id) ||
|
|
294
|
+
target === RECORDS_FILE ||
|
|
295
|
+
isRecordsText(content)
|
|
296
|
+
) {
|
|
297
|
+
return text(`not written: ${RECORDS_REFUSAL}`)
|
|
298
|
+
}
|
|
212
299
|
|
|
213
|
-
const resolved = await resolveWrite(input, context, visibility)
|
|
300
|
+
const resolved = await resolveWrite(input, context, visibility, approvalOf(action, input, target, content))
|
|
214
301
|
if (resolved.invalid) return text(resolved.invalid)
|
|
215
302
|
if (resolved.error) return fail(resolved.error)
|
|
216
303
|
if (resolved.denied) return text(`wiki write denied: ${resolved.denied}`)
|
|
@@ -247,10 +334,17 @@ export function registerWiki(editor, toolkit) {
|
|
|
247
334
|
)
|
|
248
335
|
}
|
|
249
336
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
337
|
+
// As read does: with one visible wiki, it is the target, and the
|
|
338
|
+
// answer names it. With none or several, the refusal lists them.
|
|
339
|
+
const target = await wikiFor(input, resolved.scoped, action)
|
|
340
|
+
if (target.error) return text(target.error)
|
|
341
|
+
const { wikiID, note } = target
|
|
342
|
+
if (toolkit.runtime.records?.isRecordsWiki(wikiID)) return text(`not written: ${RECORDS_REFUSAL}`)
|
|
343
|
+
const chosen = writeTarget(input)
|
|
344
|
+
if (chosen.missing) return text(`filename is required for ${action}: the source file, for example "projects/harbour.md"`)
|
|
345
|
+
if (chosen.invalid) return text("invalid filename")
|
|
346
|
+
const filename = chosen.filename
|
|
347
|
+
if (filename === RECORDS_FILE) return text(`not written: ${RECORDS_REFUSAL}`)
|
|
254
348
|
|
|
255
349
|
let body = content
|
|
256
350
|
if (action === "append") {
|
|
@@ -261,8 +355,12 @@ export function registerWiki(editor, toolkit) {
|
|
|
261
355
|
}
|
|
262
356
|
|
|
263
357
|
const written = await writeRaw(resolved.scoped, wikiID, filename, body, input?.ingest !== false)
|
|
358
|
+
// Say what the write guarantees, so the agent does not read its own
|
|
359
|
+
// write back to check it: the source file now holds exactly this.
|
|
264
360
|
return text(
|
|
265
|
-
`${action === "append" ? "appended to" : "wrote"} ${filename} in wiki ${wikiID}
|
|
361
|
+
`${note}${action === "append" ? "appended to" : "wrote"} ${filename} in wiki ${wikiID}: the source file now holds ${
|
|
362
|
+
action === "append" ? "its earlier text and then" : "exactly"
|
|
363
|
+
} the content you sent (${Buffer.byteLength(body)} bytes), and a read of it returns that; ${
|
|
266
364
|
written.ingested ? "ingestion started (asynchronous)" : "ingestion not started"
|
|
267
365
|
}${written.ingestError ? ` (${written.ingestError})` : ""}`,
|
|
268
366
|
)
|
|
@@ -315,6 +413,11 @@ export function registerWiki(editor, toolkit) {
|
|
|
315
413
|
// agent that copies an id from this list gets a hit, not a 404.
|
|
316
414
|
const knowledgeID = String(asset.content_ref ?? asset.asset_id ?? "")
|
|
317
415
|
if (!knowledgeID || seen.has(knowledgeID)) continue
|
|
416
|
+
if (asset.asset_type === "llm_wiki" && isRecordsWikiName(asset.name)) {
|
|
417
|
+
toolkit.runtime.records?.noteRecordsWiki(knowledgeID)
|
|
418
|
+
seen.add(knowledgeID)
|
|
419
|
+
continue
|
|
420
|
+
}
|
|
318
421
|
seen.add(knowledgeID)
|
|
319
422
|
const assetNote =
|
|
320
423
|
asset.content_ref && asset.asset_id && String(asset.content_ref) !== String(asset.asset_id)
|
|
@@ -331,6 +434,11 @@ export function registerWiki(editor, toolkit) {
|
|
|
331
434
|
for (const wiki of wikis?.items ?? []) {
|
|
332
435
|
const wikiID = String(wiki.wiki_id ?? "")
|
|
333
436
|
if (!wikiID || seen.has(wikiID)) continue
|
|
437
|
+
if (isRecordsWikiName(wiki.name)) {
|
|
438
|
+
toolkit.runtime.records?.noteRecordsWiki(wikiID)
|
|
439
|
+
seen.add(wikiID)
|
|
440
|
+
continue
|
|
441
|
+
}
|
|
334
442
|
seen.add(wikiID)
|
|
335
443
|
lines.push(
|
|
336
444
|
`- ${neutralizeFenceClosers(oneLine(wikiID, 120))} [wiki] ${neutralizeFenceClosers(
|
|
@@ -348,27 +456,54 @@ export function registerWiki(editor, toolkit) {
|
|
|
348
456
|
)} (${neutralizeFenceClosers(oneLine(graph.status ?? "?", 40))})`,
|
|
349
457
|
)
|
|
350
458
|
}
|
|
351
|
-
if (lines.length === 0) return text(
|
|
459
|
+
if (lines.length === 0) return text(emptyKnowledge(input, spaceContext))
|
|
460
|
+
// Each wiki's source files, so the next call can read a page by name
|
|
461
|
+
// (filename) instead of searching for its path first. Bounded: the
|
|
462
|
+
// first five wikis, fifteen names each.
|
|
463
|
+
const wikiRows = lines.map((line, index) => ({ line, index, id: line.match(/^- (\S+) \[(?:llm_wiki|wiki)\]/)?.[1] })).filter((row) => row.id)
|
|
464
|
+
const listed = await Promise.all(wikiRows.slice(0, 5).map((row) => sourceFiles(scoped, row.id)))
|
|
465
|
+
wikiRows.slice(0, 5).forEach((row, index) => {
|
|
466
|
+
const { names, more } = listed[index]
|
|
467
|
+
if (names.length === 0) return
|
|
468
|
+
lines[row.index] = `${row.line}\n files (pass as filename): ${names.map((name) => neutralizeFenceClosers(oneLine(name, 120))).join(", ")}${more ? `, +${more} more` : ""}`
|
|
469
|
+
})
|
|
352
470
|
return text(["<knowledge_assets>", ...lines, "</knowledge_assets>"].join("\n"))
|
|
353
471
|
}
|
|
354
472
|
|
|
355
473
|
if (action === "read") {
|
|
356
474
|
const target = await wikiFor(input, scoped, "read")
|
|
475
|
+
if (target.empty) return text(emptyKnowledge(input, spaceContext))
|
|
357
476
|
if (target.error) return text(target.error)
|
|
358
477
|
const { wikiID, note } = target
|
|
478
|
+
if (toolkit.runtime.records?.isRecordsWiki(wikiID)) return text(RECORDS_REFUSAL)
|
|
359
479
|
const ref = String(input?.ref ?? input?.path ?? "").trim()
|
|
360
480
|
const name = ref || filenameOf(input)
|
|
361
481
|
if (!name) return text("invalid filename")
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
482
|
+
// The source file first: it is what the agent writes, and it is
|
|
483
|
+
// current at once, while the extracted page lags until ingestion
|
|
484
|
+
// finishes (a model that re-read the page after a write saw the old
|
|
485
|
+
// text and wrote again). A search hit's path ("wiki/<file>") names the
|
|
486
|
+
// same source file. Then the extracted page, so a page with no source
|
|
487
|
+
// file of that name still reads.
|
|
488
|
+
const sourceName = name.replace(/^\/*wiki\//, "")
|
|
489
|
+
const order = [
|
|
490
|
+
[readSource, sourceName],
|
|
491
|
+
[readPage, name],
|
|
492
|
+
...(sourceName !== name ? [[readSource, name]] : []),
|
|
493
|
+
]
|
|
494
|
+
for (const [read, target] of order) {
|
|
495
|
+
const found = await read(scoped, wikiID, target)
|
|
496
|
+
if (found && isRecordsText(found.content)) {
|
|
497
|
+
toolkit.runtime.records?.noteRecordsWiki(wikiID)
|
|
498
|
+
return text(RECORDS_REFUSAL)
|
|
499
|
+
}
|
|
367
500
|
if (found) {
|
|
501
|
+
const safe = quarantineText(found.content.slice(0, 12_000))
|
|
502
|
+
const after = quarantineNote(safe.removed)
|
|
368
503
|
return text(
|
|
369
504
|
`${note}<knowledge source="${neutralizeFenceClosers(oneLine(found.source, 120))}">\n${neutralizeFenceClosers(
|
|
370
|
-
|
|
371
|
-
)}\n</knowledge
|
|
505
|
+
safe.text,
|
|
506
|
+
)}\n</knowledge>${after ? `\n${after}` : ""}`,
|
|
372
507
|
)
|
|
373
508
|
}
|
|
374
509
|
}
|
|
@@ -377,6 +512,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
377
512
|
|
|
378
513
|
if (action === "status") {
|
|
379
514
|
const target = await wikiFor(input, scoped, "status")
|
|
515
|
+
if (target.empty) return text(emptyKnowledge(input, spaceContext))
|
|
380
516
|
if (target.error) return text(target.error)
|
|
381
517
|
const { wikiID } = target
|
|
382
518
|
const [wiki, pages] = await Promise.all([
|
|
@@ -397,7 +533,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
397
533
|
const ids = input?.knowledge_id
|
|
398
534
|
? [String(input.knowledge_id)]
|
|
399
535
|
: await discoverKnowledge(backend, log, assetType, scoped)
|
|
400
|
-
if (ids.length === 0) return text(
|
|
536
|
+
if (ids.length === 0) return text(emptyKnowledge(input, spaceContext))
|
|
401
537
|
const result = await searchKnowledge(backend, ids.slice(0, 8), query, scoped, {
|
|
402
538
|
maxChars: config.recallChars,
|
|
403
539
|
})
|
package/src/views/contracts.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* before the plugin sees it, so every method reads under the permission of the
|
|
11
11
|
* tool that makes the same read: the overview under `mem_status`, the space
|
|
12
12
|
* list under `mem_spaces`, recent memories under `mem_recall`, the wiki under
|
|
13
|
-
* `mem_wiki`. None of them writes: a write starts as a message the person sends
|
|
13
|
+
* `mem_wiki`, commitments under `mem_commitments`. None of them writes: a write starts as a message the person sends
|
|
14
14
|
* (`open-agent`), and the agent's tool runs under the person's rules.
|
|
15
15
|
*
|
|
16
16
|
* The schemas are JSON Schema documents Jelly reads as data, checked on every
|
|
@@ -35,6 +35,8 @@ export const MEMORY_TEXT_CHARS = 600
|
|
|
35
35
|
export const PAGE_TEXT_CHARS = 48_000
|
|
36
36
|
/** The most wikis, pages and spaces one answer lists. */
|
|
37
37
|
export const LIST_MAX = 100
|
|
38
|
+
/** The most commitments one answer lists (the Home card shows fewer). */
|
|
39
|
+
export const COMMITMENTS_MAX = 100
|
|
38
40
|
|
|
39
41
|
const empty = { type: "object", additionalProperties: false, properties: {} }
|
|
40
42
|
const id = { type: "string", maxLength: 200 }
|
|
@@ -176,6 +178,50 @@ const wikiReadOutput = {
|
|
|
176
178
|
properties: { ref: id, content: line(PAGE_TEXT_CHARS), clipped: { type: "boolean" } },
|
|
177
179
|
}
|
|
178
180
|
|
|
181
|
+
const commitmentsInput = {
|
|
182
|
+
type: "object",
|
|
183
|
+
additionalProperties: false,
|
|
184
|
+
properties: {
|
|
185
|
+
/** open (default): what is still to do; closed: done or cancelled, newest first. */
|
|
186
|
+
state: { type: "string", enum: ["open", "closed"] },
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const commitmentsOutput = {
|
|
191
|
+
type: "object",
|
|
192
|
+
additionalProperties: false,
|
|
193
|
+
required: ["today", "items", "more"],
|
|
194
|
+
properties: {
|
|
195
|
+
/** Today in the agent's time zone, as "Thu 5 Nov". */
|
|
196
|
+
today: line(40),
|
|
197
|
+
items: {
|
|
198
|
+
type: "array",
|
|
199
|
+
maxItems: COMMITMENTS_MAX,
|
|
200
|
+
items: {
|
|
201
|
+
type: "object",
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
required: ["id", "what", "owner", "state", "when", "overdue", "dueToday"],
|
|
204
|
+
properties: {
|
|
205
|
+
id,
|
|
206
|
+
what: line(300),
|
|
207
|
+
/** "user", "agent", or a person's name; the page words it. */
|
|
208
|
+
owner: line(80),
|
|
209
|
+
state: { type: "string", enum: ["open", "done", "cancelled"] },
|
|
210
|
+
/** The due day as "Fri 6 Nov" (with a time for a date-time), or "" when undated. */
|
|
211
|
+
when: line(40),
|
|
212
|
+
overdue: { type: "boolean" },
|
|
213
|
+
dueToday: { type: "boolean" },
|
|
214
|
+
trigger: line(200),
|
|
215
|
+
project: line(80),
|
|
216
|
+
/** The day it was closed, as "Tue 3 Nov"; closed items only. */
|
|
217
|
+
closed: line(40),
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
more: { type: "boolean" },
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
|
|
179
225
|
/**
|
|
180
226
|
* The methods, in the order `package.json` declares them.
|
|
181
227
|
* @type {ReadonlyArray<{ name: string, label: string, permission: string, input: object, output: object }>}
|
|
@@ -221,6 +267,13 @@ export const VIEW_METHODS = Object.freeze([
|
|
|
221
267
|
},
|
|
222
268
|
output: wikiReadOutput,
|
|
223
269
|
},
|
|
270
|
+
{
|
|
271
|
+
name: "commitments.list",
|
|
272
|
+
label: "list your commitments",
|
|
273
|
+
permission: "mem_commitments",
|
|
274
|
+
input: commitmentsInput,
|
|
275
|
+
output: commitmentsOutput,
|
|
276
|
+
},
|
|
224
277
|
])
|
|
225
278
|
|
|
226
279
|
/** The refusal a page can show in the plugin's own words (`call.error`). */
|
package/src/views/rpc.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { originOf, PACKAGE_NAME, SOURCES } from "../credentials.js"
|
|
2
|
+
import { dayIn, dueDay, filterItems, formatDay, formatDue } from "../records.js"
|
|
3
|
+
import { isRecordsWikiName } from "../tools/knowledge.js"
|
|
2
4
|
import { oneLine } from "../util.js"
|
|
3
5
|
import {
|
|
6
|
+
COMMITMENTS_MAX,
|
|
4
7
|
ID_PATTERN,
|
|
5
8
|
LIST_MAX,
|
|
6
9
|
MEMORY_TEXT_CHARS,
|
|
@@ -286,7 +289,8 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
286
289
|
const data = await backend.listWiki({ scope })
|
|
287
290
|
return {
|
|
288
291
|
wikis: (data?.items ?? [])
|
|
289
|
-
|
|
292
|
+
// The records wiki is commitments' store, shown by commitments.list.
|
|
293
|
+
.filter((item) => idOf(item?.wiki_id) && !isRecordsWikiName(item?.name))
|
|
290
294
|
.slice(0, LIST_MAX)
|
|
291
295
|
.map((item) => ({
|
|
292
296
|
id: idOf(item.wiki_id),
|
|
@@ -301,7 +305,9 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
301
305
|
const wiki = idOf(value)
|
|
302
306
|
if (!wiki) refuse("That is not a wiki id.")
|
|
303
307
|
const data = await backend.listWiki({ scope })
|
|
304
|
-
if (!(data?.items ?? []).some((item) => item?.wiki_id === wiki))
|
|
308
|
+
if (!(data?.items ?? []).some((item) => item?.wiki_id === wiki && !isRecordsWikiName(item?.name))) {
|
|
309
|
+
refuse("That wiki isn't in your memory.")
|
|
310
|
+
}
|
|
305
311
|
return wiki
|
|
306
312
|
}
|
|
307
313
|
|
|
@@ -332,7 +338,47 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
332
338
|
return { ref, content: text, clipped }
|
|
333
339
|
}
|
|
334
340
|
|
|
341
|
+
/**
|
|
342
|
+
* The person's commitments, from their personal space's records wiki: open
|
|
343
|
+
* ones overdue first, or closed ones newest first. Only the caller's own
|
|
344
|
+
* space is read; a view can change nothing (closing one opens the agent).
|
|
345
|
+
*/
|
|
346
|
+
async function commitmentsList(input) {
|
|
347
|
+
available()
|
|
348
|
+
const state = input?.state === "closed" ? "closed" : "open"
|
|
349
|
+
const [first] = await personalScopes()
|
|
350
|
+
const records = (await runtime.records.read(first.scope)).records
|
|
351
|
+
const zone = runtime.clock.zone
|
|
352
|
+
const today = dayIn(runtime.clock.now(), zone)
|
|
353
|
+
let items = filterItems(records.items, { state: state === "open" ? "open" : "all" }, zone)
|
|
354
|
+
if (state === "closed") {
|
|
355
|
+
items = items
|
|
356
|
+
.filter((item) => item.state !== "open")
|
|
357
|
+
.sort((a, b) => String(b.closed ?? b.updated ?? "").localeCompare(String(a.closed ?? a.updated ?? "")))
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
today: formatDay(today),
|
|
361
|
+
items: items.slice(0, COMMITMENTS_MAX).map((item) => {
|
|
362
|
+
const day = dueDay(item.due, zone)
|
|
363
|
+
return {
|
|
364
|
+
id: idOf(item.id) || "cmt_unknown",
|
|
365
|
+
what: clip(item.what, 300),
|
|
366
|
+
owner: clip(item.owner || "user", 80),
|
|
367
|
+
state: ["open", "done", "cancelled"].includes(item.state) ? item.state : "open",
|
|
368
|
+
when: clip(item.due ? formatDue(item.due, zone) : "", 40),
|
|
369
|
+
overdue: item.state === "open" && Boolean(day) && day < today,
|
|
370
|
+
dueToday: item.state === "open" && day === today,
|
|
371
|
+
...(item.trigger ? { trigger: clip(item.trigger, 200) } : {}),
|
|
372
|
+
...(item.project ? { project: clip(item.project, 80) } : {}),
|
|
373
|
+
...(item.state !== "open" && (item.closed || item.updated) ? { closed: clip(formatDay(item.closed ?? item.updated), 40) } : {}),
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
376
|
+
more: items.length > COMMITMENTS_MAX,
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
335
380
|
return {
|
|
381
|
+
"commitments.list": commitmentsList,
|
|
336
382
|
"memory.overview": overview,
|
|
337
383
|
"spaces.list": spacesList,
|
|
338
384
|
"memories.recent": recent,
|