@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
package/src/tools/spaces.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { contextScopeLabel } from "../scope.js"
|
|
2
2
|
import { DEFAULT_ACCOUNT, isAccountName, isSourceName } from "../collector.js"
|
|
3
|
-
import { knownSources, sourceEntry } from "../sources.js"
|
|
3
|
+
import { bindableSource, installedVersionOf, kindProblem, knownSources, releaseNote, sourceEntry } from "../sources.js"
|
|
4
4
|
import { createProfileReads, profileText } from "../views/profile.js"
|
|
5
|
+
import { asksToDecline, latestWord, mustRefuse, namesProposal } from "../requests.js"
|
|
5
6
|
import { errorMessage, isPlainObject, oneLine } from "../util.js"
|
|
6
7
|
import { RECORDS_MISSING, recordsFailure, recordsOf } from "./share.js"
|
|
7
8
|
import { renderHealth } from "./status.js"
|
|
9
|
+
import { createSpaceLifecycle } from "./space-lifecycle.js"
|
|
8
10
|
|
|
9
|
-
export const SPACES_ACTIONS = Object.freeze(["current", "list", "members", "access", "health", "sources", "review", "profile"])
|
|
11
|
+
export const SPACES_ACTIONS = Object.freeze(["current", "list", "members", "access", "health", "sources", "jobs", "review", "profile", "create", "rename", "archive", "leave", "handover"])
|
|
12
|
+
/** The actions that change a space itself (DESIGN-CRUD S1, space-lifecycle.js). */
|
|
13
|
+
export const SPACE_LIFECYCLE_ACTIONS = Object.freeze(["create", "rename", "archive", "leave", "handover"])
|
|
10
14
|
const DECISIONS = Object.freeze(["accept", "reject", "edit"])
|
|
15
|
+
/** The `mem_spaces jobs` operations (DESIGN-MEMORY-JOBS §12). */
|
|
16
|
+
export const JOB_OPS = Object.freeze(["list", "get", "runs", "logs", "versions", "draft", "run_now", "pause", "resume", "archive", "activate", "delete"])
|
|
11
17
|
const REVIEW_LIMIT = 20
|
|
12
18
|
|
|
13
19
|
/**
|
|
@@ -33,7 +39,7 @@ export function registerSpaces(editor, toolkit) {
|
|
|
33
39
|
editor.add({
|
|
34
40
|
name: "spaces",
|
|
35
41
|
description:
|
|
36
|
-
"
|
|
42
|
+
"Spaces and what flows in. current, list, members, access: need a control plane; current is the active space, and bind {space} binds this session, only when the person asks, a team space first; passing space never binds. health only when memory may be down; sources, jobs and review work without one. profile: what Memory holds about the person, as data. Do not inspect spaces or health to verify a successful read or write. sources: the accounts Memory collects from; bind asks the person's collector and answers with the console link where the person confirms (no agent binds); unbind previews unless confirm. jobs: the scheduled pipelines: list, read, draft, run now, pause, resume, archive; a draft never runs, and turning one on or deleting it answers with the console link, where only the person acts. review: the routine's proposals; decide one only when the person says. A space itself, only when the person asks: create {name} (they own it); rename {space, name}; archive {space} (offline for every member; restore: true brings it back); leave {space}; handover {space, user}. archive, leave and handover preview unless confirm, then ask with the server's preview. Never confirm before the person agrees; never bind an account. Members are added, and spaces deleted, in Memory's console. \"Am I allowed\" is a mem_recall question.",
|
|
37
43
|
input: {
|
|
38
44
|
type: "object",
|
|
39
45
|
properties: {
|
|
@@ -41,13 +47,15 @@ export function registerSpaces(editor, toolkit) {
|
|
|
41
47
|
type: "string",
|
|
42
48
|
enum: [...SPACES_ACTIONS],
|
|
43
49
|
description:
|
|
44
|
-
'Required.
|
|
50
|
+
'Required. Example: {"action": "health"}',
|
|
45
51
|
},
|
|
46
|
-
space: { type: "string", description: "Space id
|
|
52
|
+
space: { type: "string", description: "Space id; defaults to the session space (sources, jobs: personal). rename, archive, leave and handover need it. Never rebinds the session" },
|
|
53
|
+
name: { type: "string", description: "create, rename: the space's name" },
|
|
54
|
+
user: { type: "string", description: "handover: the new owner, an email or user id; they must already be a member" },
|
|
55
|
+
restore: { type: "boolean", description: "archive: true unarchives the space" },
|
|
47
56
|
bind: {
|
|
48
57
|
type: "object",
|
|
49
|
-
description:
|
|
50
|
-
'current: bind this session to a space, only when the person asks. Example: {"action": "current", "bind": {"space": "personal"}}. sources: ask to collect from one source; the person confirms the account in the Memory console, from the link the answer gives. Example: {"action": "sources", "bind": {"source": "gmail", "account": "work"}}',
|
|
58
|
+
description: 'current: bind this session to a space. sources: ask to collect from one source; the person confirms in the console',
|
|
51
59
|
properties: {
|
|
52
60
|
space: { type: "string", description: 'current: "personal" or a space id from list' },
|
|
53
61
|
source: { type: "string", description: "sources: the source plugin's Code Mode namespace, such as gmail or slack" },
|
|
@@ -57,28 +65,45 @@ export function registerSpaces(editor, toolkit) {
|
|
|
57
65
|
},
|
|
58
66
|
unbind: {
|
|
59
67
|
type: "object",
|
|
60
|
-
description: "sources: stop collecting
|
|
68
|
+
description: "sources: stop collecting and delete that account's events; previews unless confirm",
|
|
61
69
|
properties: {
|
|
62
|
-
source: { type: "string", description: "The source
|
|
70
|
+
source: { type: "string", description: "The source" },
|
|
63
71
|
account: { type: "string", description: 'The account; default "default"' },
|
|
64
72
|
},
|
|
65
73
|
required: ["source"],
|
|
66
74
|
additionalProperties: false,
|
|
67
75
|
},
|
|
68
|
-
confirm: { type: "boolean", description: "unbind: true
|
|
76
|
+
confirm: { type: "boolean", description: "unbind, archive, leave, handover: true acts, after the person agreed; omitted previews" },
|
|
77
|
+
job: {
|
|
78
|
+
type: "object",
|
|
79
|
+
description: 'jobs: {"op": "list"}; draft creates (template, project, account, scope) or edits (id, max_lines), never runs; the rest take id; activate and delete answer with the link',
|
|
80
|
+
properties: {
|
|
81
|
+
op: { type: "string", enum: [...JOB_OPS] },
|
|
82
|
+
id: { type: "string" },
|
|
83
|
+
template: { type: "string" },
|
|
84
|
+
project: { type: "string" },
|
|
85
|
+
account: { type: "string" },
|
|
86
|
+
scope: { type: "object", additionalProperties: true },
|
|
87
|
+
every: { type: "string" },
|
|
88
|
+
max_lines: { type: "integer", minimum: 1, maximum: 500 },
|
|
89
|
+
limit: { type: "integer", minimum: 1, maximum: 100 },
|
|
90
|
+
},
|
|
91
|
+
required: ["op"],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
},
|
|
69
94
|
decide: {
|
|
70
95
|
type: "object",
|
|
71
|
-
description:
|
|
96
|
+
description: "review: answer one proposal, when the person says",
|
|
72
97
|
properties: {
|
|
73
|
-
id: { type: "string", description: "The proposal id
|
|
98
|
+
id: { type: "string", description: "The proposal id" },
|
|
74
99
|
decision: { type: "string", enum: [...DECISIONS], description: "accept applies it; edit applies payload instead; reject drops it" },
|
|
75
|
-
reason: { type: "string", description: "Why; kept on the proposal
|
|
76
|
-
payload: { type: "string", description: "edit: the text to apply instead
|
|
100
|
+
reason: { type: "string", description: "Why; kept on the proposal" },
|
|
101
|
+
payload: { type: "string", description: "edit: the text to apply instead" },
|
|
77
102
|
},
|
|
78
103
|
required: ["id", "decision"],
|
|
79
104
|
additionalProperties: false,
|
|
80
105
|
},
|
|
81
|
-
limit: { type: "integer", minimum: 1, maximum: 100, description: `review: proposals to list (default ${REVIEW_LIMIT}
|
|
106
|
+
limit: { type: "integer", minimum: 1, maximum: 100, description: `review: proposals to list (default ${REVIEW_LIMIT})` },
|
|
82
107
|
},
|
|
83
108
|
required: ["action"],
|
|
84
109
|
additionalProperties: false,
|
|
@@ -97,6 +122,7 @@ export function registerSpaces(editor, toolkit) {
|
|
|
97
122
|
export function createSpacesActions(toolkit) {
|
|
98
123
|
const { config, control, log, text, fail, resolveSpace, describeSpace, describeCollection } = toolkit
|
|
99
124
|
const records = () => recordsOf(toolkit)
|
|
125
|
+
const lifecycle = createSpaceLifecycle(toolkit)
|
|
100
126
|
const noControl = (what) => text(`control plane not configured; set MEMORY_CONTROL_URL to ${what}`)
|
|
101
127
|
|
|
102
128
|
/**
|
|
@@ -208,15 +234,58 @@ export function createSpacesActions(toolkit) {
|
|
|
208
234
|
const spaceContext = resolved.context
|
|
209
235
|
if (!spaceContext?.space_id) return fail("the control plane returned no space context")
|
|
210
236
|
const roster = await control.listMembers({ userId: config.user, spaceId: spaceContext.space_id })
|
|
237
|
+
// Who "you" is in the roster (0.10.3 gate B12; review F1). Behind the
|
|
238
|
+
// gateway control renames the caller to its own `usr_…` id, so only the ids
|
|
239
|
+
// the server itself named can match; in direct-control mode the roster is
|
|
240
|
+
// scoped to `config.user` and may answer with it. An id no member carries
|
|
241
|
+
// matches nobody: then no one is marked and nothing is claimed about them.
|
|
242
|
+
const keys = personKeys(spaceContext, config.user)
|
|
243
|
+
const marked = roster.filter((member) => memberIsPerson(member, keys))
|
|
244
|
+
const you = marked.length === 1 ? marked[0] : null
|
|
245
|
+
const others = roster.length - marked.length
|
|
211
246
|
const lines = ["<members>", `space: ${describeSpace(spaceContext)}`]
|
|
212
247
|
if (roster.length === 0) lines.push("(no members visible to you in this space)")
|
|
213
248
|
for (const member of roster) {
|
|
214
|
-
|
|
249
|
+
const role = oneLine(member.role || "member", 40)
|
|
250
|
+
lines.push(
|
|
251
|
+
`- ${oneLine(member.name || member.email || member.user_id, 160)} (${role}${member === you ? ", you" : ""}) user_id=${oneLine(member.user_id, 120)}`,
|
|
252
|
+
)
|
|
215
253
|
}
|
|
254
|
+
// 0.10.5 gate B10: who owns the space, when the roster shows an owner.
|
|
255
|
+
// A handover's confirmer is that person, and a caller who cannot see one
|
|
256
|
+
// is told so rather than left to guess a name.
|
|
257
|
+
const owner = roster.find((member) => String(member.role ?? "").toLowerCase() === "owner") ?? null
|
|
258
|
+
lines.push(`owner: ${owner ? `${oneLine(owner.name || owner.email || owner.user_id, 160)} user_id=${oneLine(owner.user_id, 120)}` : "not visible to you"}`)
|
|
259
|
+
// The count of other people a change here affects, only when the person
|
|
260
|
+
// was found; never a negative about who is or is not in the list.
|
|
261
|
+
if (you) lines.push(`other members: ${others}`)
|
|
216
262
|
lines.push("</members>")
|
|
217
263
|
return text(lines.join("\n"))
|
|
218
264
|
}
|
|
219
265
|
|
|
266
|
+
/**
|
|
267
|
+
* The ids the roster may know the caller by. Behind the gateway (`routing:
|
|
268
|
+
* "gateway"`) the context's own `user_id` is the plugin's, not control's, so
|
|
269
|
+
* only ids the server echoed count; in direct-control mode the roster is
|
|
270
|
+
* scoped to `config.user` and may answer with it.
|
|
271
|
+
*/
|
|
272
|
+
function personKeys(spaceContext, fallback) {
|
|
273
|
+
const keys = new Set()
|
|
274
|
+
for (const id of [spaceContext?.auth_user_id, spaceContext?.upstream_user_id]) if (id) keys.add(String(id))
|
|
275
|
+
if (spaceContext?.routing !== "gateway") {
|
|
276
|
+
if (spaceContext?.user_id) keys.add(String(spaceContext.user_id))
|
|
277
|
+
if (fallback) keys.add(String(fallback))
|
|
278
|
+
}
|
|
279
|
+
keys.delete("")
|
|
280
|
+
return keys
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** True when a roster row is the caller: control's id, or the memory id its records carry. */
|
|
284
|
+
function memberIsPerson(member, keys) {
|
|
285
|
+
if (keys.size === 0) return false
|
|
286
|
+
return [member?.user_id, member?.upstream_user_id].some((id) => Boolean(id) && keys.has(String(id)))
|
|
287
|
+
}
|
|
288
|
+
|
|
220
289
|
async function access(input, context) {
|
|
221
290
|
if (!control) return noControl("read grants")
|
|
222
291
|
const resolved = await resolveSpace(input, context)
|
|
@@ -278,16 +347,45 @@ export function createSpacesActions(toolkit) {
|
|
|
278
347
|
const asked = String(value?.account ?? "").trim()
|
|
279
348
|
const account = asked || DEFAULT_ACCOUNT
|
|
280
349
|
if (!isSourceName(source)) return { error: `"${oneLine(source || "(none)", 60)}" is not a source name: one of ${knownSources().join(", ")}.` }
|
|
281
|
-
if (known && !
|
|
350
|
+
if (known && !bindableSource(source)) {
|
|
351
|
+
// Said plainly, and each for its own reason: a kind this release does not
|
|
352
|
+
// read (G1), or an installed release too old to serve it (G3). A name
|
|
353
|
+
// Memory does not know at all keeps the list.
|
|
354
|
+
const kind = kindProblem(source)
|
|
355
|
+
if (kind) return { error: `${kind.message} ${kind.next}` }
|
|
356
|
+
return { error: `"${oneLine(source, 60)}" is not a source Memory knows: one of ${knownSources().join(", ")}.` }
|
|
357
|
+
}
|
|
282
358
|
if (!isAccountName(account)) return { error: `"${oneLine(account, 60)}" is not an account name.` }
|
|
283
359
|
return { source, account, asked: Boolean(asked) }
|
|
284
360
|
}
|
|
285
361
|
|
|
286
|
-
const describeBinding = (row) => {
|
|
362
|
+
const describeBinding = (row, behind = null) => {
|
|
287
363
|
const owner = row.owner_label || row.owner_id ? `${oneLine(row.owner_label || row.owner_id, 120)}${row.owner_id && row.owner_label && row.owner_label !== row.owner_id ? ` (${oneLine(row.owner_id, 120)})` : ""}` : "owner unknown"
|
|
288
364
|
const state = [row.status || "unknown", row.enabled === true || row.enabled === 1 ? "enabled" : "disabled"].join(", ")
|
|
289
365
|
const cursor = row.cursor_at ? `, last collected ${oneLine(row.cursor_at, 40)}` : ""
|
|
290
|
-
|
|
366
|
+
// The installed release, and the tag that declares `sources` (G3, review S1):
|
|
367
|
+
// the row **informs** and never withholds a read. A git pin reports a commit,
|
|
368
|
+
// which is not a version, so only a real version is shown.
|
|
369
|
+
const entry = sourceEntry(row.source)
|
|
370
|
+
const note = releaseNote(row.source)
|
|
371
|
+
const release = note
|
|
372
|
+
? `, ${note.installed ? `installed ${oneLine(note.installed, 40)}, ` : ""}${oneLine(note.declares, 20)} declares its sources`
|
|
373
|
+
: installedVersionOf(row.source) && entry?.contract === "sources"
|
|
374
|
+
? `, plugin ${oneLine(installedVersionOf(row.source), 40)}`
|
|
375
|
+
: ""
|
|
376
|
+
// A bound source of a kind this release does not read is marked, not left
|
|
377
|
+
// looking healthy (G1, review S4): nothing is collected from it.
|
|
378
|
+
const kind = kindProblem(row.source)
|
|
379
|
+
const notCollected = kind ? `, not collected: ${oneLine(kind.message, 200)}` : ""
|
|
380
|
+
// A named-account binding from before 0.11 records no asked account (review
|
|
381
|
+
// L4-1): its row says so, and how to end it.
|
|
382
|
+
const unknownAsk = row.asked_unknown === true
|
|
383
|
+
? ", connected before 0.11, so Memory does not know which account was asked for. If this account is no longer used, unbind it"
|
|
384
|
+
: ""
|
|
385
|
+
// A run that ended with `more: true` left pages behind (G7): the row says so,
|
|
386
|
+
// and the next run comes sooner.
|
|
387
|
+
const catchingUp = behind?.has(`${row.source}\u0000${row.account || DEFAULT_ACCOUNT}`) ? ", catching up: more waits for the next run" : ""
|
|
388
|
+
return `- ${oneLine(row.source, 64)}:${oneLine(row.account || DEFAULT_ACCOUNT, 128)} ${owner}: ${state}${cursor}${release}${notCollected}${unknownAsk}${catchingUp}`
|
|
291
389
|
}
|
|
292
390
|
|
|
293
391
|
async function listSources(where) {
|
|
@@ -307,10 +405,10 @@ export function createSpacesActions(toolkit) {
|
|
|
307
405
|
const name = `${oneLine(row.source, 64)}:${oneLine(row.account || DEFAULT_ACCOUNT, 128)}`
|
|
308
406
|
const asked = row.requested_at ? ` (asked ${oneLine(row.requested_at, 40)})` : ""
|
|
309
407
|
if (row.state === "reported" && row.owner?.id) {
|
|
310
|
-
return `- ${name} bind requested${asked}: the collector reports it is signed in as ${oneLine(row.owner.label || row.owner.id, 120)}; the person confirms it in ${consoleAt("sources")}${row.note ? `. The source says: ${oneLine(row.note, 240)}` : ""}`
|
|
408
|
+
return `- ${name} bind requested${asked}: the collector reports it is signed in as ${oneLine(row.owner.label || row.owner.id, 120)}; the person confirms it in ${consoleAt("sources")}${row.note ? `. The source says: ${oneLine(errorMessage(row.note), 240)}` : ""}`
|
|
311
409
|
}
|
|
312
|
-
if (row.state === "attention") return `- ${name} bind requested${asked}: needs attention: the collector could not read the account ${Number(row.failures) || 3} times${row.note ? ` (${oneLine(row.note, 240)})` : ""}; it stopped trying. Bind… again in the console once the source is signed in`
|
|
313
|
-
if (row.state === "failed") return `- ${name} bind requested${asked}: the collector could not learn the account${row.note ? ` (${oneLine(row.note, 240)})` : ""}; it tries again${row.retry_at ? ` after ${oneLine(row.retry_at, 40)}` : " on its next run"}`
|
|
410
|
+
if (row.state === "attention") return `- ${name} bind requested${asked}: needs attention: the collector could not read the account ${Number(row.failures) || 3} times${row.note ? ` (${oneLine(errorMessage(row.note), 240)})` : ""}; it stopped trying. Bind… again in the console once the source is signed in`
|
|
411
|
+
if (row.state === "failed") return `- ${name} bind requested${asked}: the collector could not learn the account${row.note ? ` (${oneLine(errorMessage(row.note), 240)})` : ""}; it tries again${row.retry_at ? ` after ${oneLine(row.retry_at, 40)}` : " on its next run"}`
|
|
314
412
|
return `- ${name} bind requested${asked}: waiting for the collector's next run to report the signed-in account`
|
|
315
413
|
}
|
|
316
414
|
|
|
@@ -318,7 +416,7 @@ export function createSpacesActions(toolkit) {
|
|
|
318
416
|
async function syncCollector(rows) {
|
|
319
417
|
if (!toolkit.collector) return ""
|
|
320
418
|
const result = await toolkit.collector.sync(rows)
|
|
321
|
-
if (result.action === "failed") return `Collection: the memory-collect schedule could not be updated (${oneLine(result.error, 200)}).`
|
|
419
|
+
if (result.action === "failed") return `Collection: the memory-collect schedule could not be updated (${oneLine(errorMessage(result.error), 200)}).`
|
|
322
420
|
if (result.mode === "schedule" && result.action === "removed") return "Collection: no source is enabled, so the memory-collect schedule was removed."
|
|
323
421
|
if (result.mode === "schedule" && (result.action === "created" || result.action === "rewritten")) {
|
|
324
422
|
return `Collection: the host's memory-collect schedule was ${result.action}; it runs every 30 minutes for ${result.sources} source(s).`
|
|
@@ -348,7 +446,10 @@ export function createSpacesActions(toolkit) {
|
|
|
348
446
|
* or token. Here the plugin only asks: it records a bind request when there
|
|
349
447
|
* is none (`sources.request`, which reads and collects nothing; the
|
|
350
448
|
* person's collector then reports the signed-in account), and answers with
|
|
351
|
-
* the console link where the person confirms it.
|
|
449
|
+
* the console link where the person confirms it. The one-binding rule (a
|
|
450
|
+
* legacy alias and the declared sources it stands for are the same account)
|
|
451
|
+
* is the records service's, so this refuses nothing by itself: it shows the
|
|
452
|
+
* server's refusal, with the server's next step.
|
|
352
453
|
*/
|
|
353
454
|
async function bindSource(value, space, rows, requests) {
|
|
354
455
|
const asked = bindingOf(value, { known: true })
|
|
@@ -365,7 +466,7 @@ export function createSpacesActions(toolkit) {
|
|
|
365
466
|
return `not bound here: the person's collector reports ${name} is signed in as ${oneLine(open.owner.label || open.owner.id, 120)} (${oneLine(open.owner.id, 120)}). ${confirm}`
|
|
366
467
|
}
|
|
367
468
|
if (open) {
|
|
368
|
-
const why = open.state === "attention" || open.state === "failed" ? ` The collector could not read the account yet${open.note ? ` (${oneLine(open.note, 240)})` : ""}.` : ""
|
|
469
|
+
const why = open.state === "attention" || open.state === "failed" ? ` The collector could not read the account yet${open.note ? ` (${oneLine(errorMessage(open.note), 240)})` : ""}.` : ""
|
|
369
470
|
return `not bound here: a bind request for ${name} is open; the person's collector reports the signed-in account on its next run.${why} ${confirm}`
|
|
370
471
|
}
|
|
371
472
|
try {
|
|
@@ -458,7 +559,13 @@ export function createSpacesActions(toolkit) {
|
|
|
458
559
|
const sync = await syncCollector(rows)
|
|
459
560
|
const lines = ["<sources>", `space: ${space.label}`]
|
|
460
561
|
if (rows.length === 0 && requests.length === 0) lines.push('(no sources: Memory collects nothing. When the person asks, bind one with {"action": "sources", "bind": {"source": "<namespace>"}}.)')
|
|
461
|
-
|
|
562
|
+
let behind = null
|
|
563
|
+
try {
|
|
564
|
+
behind = typeof toolkit.collector?.behind === "function" ? toolkit.collector.behind() : null
|
|
565
|
+
} catch {
|
|
566
|
+
behind = null
|
|
567
|
+
}
|
|
568
|
+
for (const row of rows) lines.push(describeBinding(row, behind))
|
|
462
569
|
for (const row of requests) lines.push(describeRequest(row))
|
|
463
570
|
lines.push("</sources>")
|
|
464
571
|
if (toolkit.collector) lines.push(toolkit.collector.describe())
|
|
@@ -471,7 +578,61 @@ export function createSpacesActions(toolkit) {
|
|
|
471
578
|
const target = fields.target_path || fields.target_id || ""
|
|
472
579
|
const evidence = Array.isArray(fields.evidence) ? fields.evidence.length : 0
|
|
473
580
|
const what = oneLine(proposal?.title || (typeof fields.payload === "string" ? fields.payload : proposal?.body) || "", 200)
|
|
474
|
-
|
|
581
|
+
// 0.10.6 gate H3: an external proposal (a share an email asked for) is not
|
|
582
|
+
// the routine's suggestion about the person's own work, so the list says
|
|
583
|
+
// so where it is read, and a decision on it needs their words.
|
|
584
|
+
const external = proposal?.stated_by && proposal.stated_by !== "person" ? ", external: decide only when the person says" : ""
|
|
585
|
+
return `- ${oneLine(proposal?.id ?? "?", 40)} ${oneLine(fields.action || proposal?.type || "?", 30)}${target ? ` ${oneLine(target, 120)}` : ""}: ${what}${fields.reason ? ` (why: ${oneLine(fields.reason, 160)})` : ""}${evidence ? ` [${evidence} cited]` : ""}${fields.expires ? `, expires ${oneLine(fields.expires, 20)}` : ""}${external}`
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* What a decision leaves waiting, named after it (0.10.6 gate H3, the second
|
|
590
|
+
* item): an agent asked to "accept whatever is routine" accepted one
|
|
591
|
+
* proposal and rejected an injected share proposal nobody asked it to
|
|
592
|
+
* decide. The answer now lists what still waits, so "leave the rest
|
|
593
|
+
* pending, and say so" is the path of least resistance. A failed read never
|
|
594
|
+
* fails a decision that already applied.
|
|
595
|
+
*/
|
|
596
|
+
async function stillPending(space, decidedID) {
|
|
597
|
+
let rest
|
|
598
|
+
try {
|
|
599
|
+
rest = (await records().call("review.list", { limit: REVIEW_LIMIT }, space.where))?.proposals ?? []
|
|
600
|
+
} catch (error) {
|
|
601
|
+
log.debug("review list after a decision failed", error)
|
|
602
|
+
return ""
|
|
603
|
+
}
|
|
604
|
+
const waiting = rest.filter((proposal) => String(proposal?.id ?? "") !== decidedID)
|
|
605
|
+
if (waiting.length === 0) return ""
|
|
606
|
+
const lines = ["", `Still pending, and not decided: ${waiting.length} proposal(s) wait for the person. Deciding one needs their own words; tell them it needs their call:`]
|
|
607
|
+
for (const proposal of waiting) lines.push(describeProposal(proposal))
|
|
608
|
+
return lines.join("\n")
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** The refusal of a rejection the person's latest message did not ask for (0.10.6 gate H3). */
|
|
612
|
+
const DECLINE_NEEDS_REQUEST = (id) =>
|
|
613
|
+
`not decided: rejecting needs the person's request, and this message did not name it as the proposal to reject. proposal ${oneLine(id, 40)} stays pending; tell them it needs their call.`
|
|
614
|
+
|
|
615
|
+
/** The refusal of a decision on an external proposal the person did not name (0.10.7 review F1). */
|
|
616
|
+
const EXTERNAL_NEEDS_REQUEST = (id) =>
|
|
617
|
+
`not decided: this proposal came from outside (not the person), and deciding it needs their own words naming it. proposal ${oneLine(id, 40)} stays pending; tell them it needs their call, and leave it pending unless they name it.`
|
|
618
|
+
|
|
619
|
+
/** The refusal when the guard cannot read the proposal (0.10.7 review R2-2): fail closed. */
|
|
620
|
+
const UNREADABLE_PROPOSAL = (id) =>
|
|
621
|
+
`not decided: the review queue could not be read, so this decision has nothing to check it against. proposal ${oneLine(id, 40)} is untouched; ask the person, and try again once the queue is readable.`
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* The proposal a decision would act on, from the open list (the same call the
|
|
625
|
+
* review list makes). `null` when the service did not list it: the decision
|
|
626
|
+
* then goes to the service, which refuses a proposal that is not open.
|
|
627
|
+
*/
|
|
628
|
+
async function openProposal(space, id) {
|
|
629
|
+
try {
|
|
630
|
+
const proposals = (await records().call("review.list", { limit: 100 }, space.where))?.proposals ?? []
|
|
631
|
+
return proposals.find((proposal) => String(proposal?.id ?? "") === id) ?? null
|
|
632
|
+
} catch (error) {
|
|
633
|
+
log.debug("review list for a decision failed", error)
|
|
634
|
+
return null
|
|
635
|
+
}
|
|
475
636
|
}
|
|
476
637
|
|
|
477
638
|
async function review(input, context) {
|
|
@@ -485,8 +646,26 @@ export function createSpacesActions(toolkit) {
|
|
|
485
646
|
const decision = String(input.decide.decision ?? "").trim()
|
|
486
647
|
if (!id) return text("not decided: decide needs the proposal id.")
|
|
487
648
|
if (!DECISIONS.includes(decision)) return text(`not decided: decision is accept, edit or reject, not ${oneLine(decision || "(none)", 40)}.`)
|
|
649
|
+
// The guard, not the description (0.10.7 review R2-1, R2-2, R2-4): a
|
|
650
|
+
// review decision is never exempt, every decision on a proposal that did
|
|
651
|
+
// not come from the person needs their own words naming it as the object
|
|
652
|
+
// of that decision, a reject acts only on the proposal named, and a
|
|
653
|
+
// proposal the guard cannot read is refused. A routine proposal still
|
|
654
|
+
// follows "accept whatever is routine".
|
|
488
655
|
const payload = String(input.decide.payload ?? "").trim()
|
|
489
656
|
if (decision === "edit" && !payload) return text("not decided: an edit needs payload, the text to apply instead.")
|
|
657
|
+
await toolkit.ensureSession?.(context?.sessionID)
|
|
658
|
+
const proposal = await openProposal(space, id)
|
|
659
|
+
const said = latestWord(toolkit.runtime, context?.sessionID, context)
|
|
660
|
+
if (!proposal) {
|
|
661
|
+
// Fail closed: no record, so no provenance and nothing to tie a
|
|
662
|
+
// decision to. Only a model's decision is refused; a host's direct
|
|
663
|
+
// call is refused too, because a review decision is never exempt.
|
|
664
|
+
return text(UNREADABLE_PROPOSAL(id))
|
|
665
|
+
}
|
|
666
|
+
const named = namesProposal(said.text, proposal, decision === "reject" ? "reject" : "accept")
|
|
667
|
+
const asked = decision === "reject" ? asksToDecline(said.text) && named : proposal.stated_by === "person" || named
|
|
668
|
+
if (mustRefuse(said, asked, { modelOnly: false })) return text(decision === "reject" ? DECLINE_NEEDS_REQUEST(id) : EXTERNAL_NEEDS_REQUEST(id))
|
|
490
669
|
const reason = String(input.decide.reason ?? "").trim()
|
|
491
670
|
// A decision in a shared space changes what every member reads, so it
|
|
492
671
|
// goes through the one gate and asks, as a revise does.
|
|
@@ -521,7 +700,8 @@ export function createSpacesActions(toolkit) {
|
|
|
521
700
|
const applied = answer?.applied
|
|
522
701
|
const appliedText = isPlainObject(applied) && applied.id ? ` Applied as ${oneLine(applied.id, 40)}${applied.path ? ` (${oneLine(applied.path, 120)})` : ""}.` : ""
|
|
523
702
|
const learned = decision === "reject" && reason ? " The reason is kept on the proposal only, not as a memory." : ""
|
|
524
|
-
|
|
703
|
+
const rest = await stillPending(space, id)
|
|
704
|
+
return text(`${decision === "reject" ? "rejected" : decision === "edit" ? "edited and applied" : "accepted"} proposal ${oneLine(id, 40)} in ${space.label}.${appliedText}${learned}${rest}`)
|
|
525
705
|
}
|
|
526
706
|
|
|
527
707
|
const limit = Math.min(100, Math.max(1, Number.parseInt(input?.limit, 10) || REVIEW_LIMIT))
|
|
@@ -539,6 +719,165 @@ export function createSpacesActions(toolkit) {
|
|
|
539
719
|
return text(lines.join("\n"))
|
|
540
720
|
}
|
|
541
721
|
|
|
722
|
+
/* ------------------------------------------------------------------ jobs */
|
|
723
|
+
|
|
724
|
+
const JOB_STATUS = { draft: "draft, not running", active: "active", paused: "paused", archived: "archived" }
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* The tiers of the ops that change a job (DESIGN-MEMORY-JOBS §12): `run_now`
|
|
728
|
+
* and `resume` are G1 — they ask, and the person's skipAsks may lift them;
|
|
729
|
+
* `archive` is G2 — it asks, and no setting lifts that. Drafting, pausing and
|
|
730
|
+
* reading ask nothing (G0): a draft never runs, and pausing only narrows.
|
|
731
|
+
*/
|
|
732
|
+
const JOB_GATES = Object.freeze({
|
|
733
|
+
run_now: { action: "job.run", ask: "unless-skipped" },
|
|
734
|
+
resume: { action: "job.resume", ask: "unless-skipped" },
|
|
735
|
+
archive: { action: "job.archive", ask: "always" },
|
|
736
|
+
})
|
|
737
|
+
|
|
738
|
+
function describeJob(job) {
|
|
739
|
+
const next = job.next_due ? `, next ${oneLine(job.next_due, 40)}` : ""
|
|
740
|
+
const draft = job.draft ? `, draft v${job.draft.version}` : ""
|
|
741
|
+
const consent = job.consent ? (job.consent.state === "on" ? "" : `, consent ${oneLine(job.consent.state, 20)}`) : ""
|
|
742
|
+
return `- ${oneLine(job.id, 40)} [${JOB_STATUS[job.status] ?? oneLine(job.status, 20)}] ${oneLine(job.name, 80)}: writes ${oneLine(job.page, 80)}, ${oneLine(job.connector, 40)} ${oneLine(job.account, 64)}${next}${draft}${consent}`
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function describeDiff(diff) {
|
|
746
|
+
return (Array.isArray(diff) ? diff : []).slice(0, 8).map((entry) => {
|
|
747
|
+
const from = entry.from === null || entry.from === undefined ? "nothing" : oneLine(JSON.stringify(entry.from), 80)
|
|
748
|
+
const to = entry.to === null || entry.to === undefined ? "nothing" : oneLine(JSON.stringify(entry.to), 80)
|
|
749
|
+
return `- ${oneLine(entry.field, 40)}: ${from} → ${to}`
|
|
750
|
+
})
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* `jobs` (DESIGN-MEMORY-JOBS §12): Memory's scheduled pipelines, folded into
|
|
755
|
+
* `mem_spaces` rather than a new tool. An agent may read, and may draft; a
|
|
756
|
+
* draft never runs. Turning a job on and deleting it are the person's own
|
|
757
|
+
* acts in a browser, so those two answer with the console link and call
|
|
758
|
+
* nothing: there is no agent door to them (§5.5, §5.6).
|
|
759
|
+
*/
|
|
760
|
+
async function jobs(input, context) {
|
|
761
|
+
if (!records()) return text(RECORDS_MISSING)
|
|
762
|
+
const spec = isPlainObject(input?.job) ? input.job : {}
|
|
763
|
+
const op = String(spec.op ?? "").trim()
|
|
764
|
+
if (!JOB_OPS.includes(op)) return text(`jobs needs job.op, one of ${JOB_OPS.join(", ")}. Example: {"action": "jobs", "job": {"op": "list"}}`)
|
|
765
|
+
const space = await recordsSpace(input, context, { personalDefault: true })
|
|
766
|
+
if (space.message) return text(space.message)
|
|
767
|
+
if (space.error) return fail(space.error)
|
|
768
|
+
const link = consoleAt("jobs")
|
|
769
|
+
const id = String(spec.id ?? "").trim() || undefined
|
|
770
|
+
|
|
771
|
+
// The tier's gate, before anything is asked of the records service.
|
|
772
|
+
const gate = JOB_GATES[op]
|
|
773
|
+
if (gate) {
|
|
774
|
+
const answer = await toolkit.gateWrite(context, { action: gate.action, spaceContext: space.context, shared: space.shared, ask: gate.ask, resources: id ? [id] : [], metadata: { space: space.spaceId, job: id ?? null } })
|
|
775
|
+
if (answer.denied) return text(`not ${op === "run_now" ? "run" : op} (approval): ${answer.denied}. Nothing changed.`)
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// 0.10 review: resume and archive change a job, so the records service takes
|
|
779
|
+
// the person's proof — a console session, or the digest of the state this
|
|
780
|
+
// read names (DESIGN-CRUD revision 4). The ask comes first, as for every
|
|
781
|
+
// write; the read only supplies the digest the commit carries.
|
|
782
|
+
let state
|
|
783
|
+
if (op === "resume" || op === "archive") {
|
|
784
|
+
if (!id) return text(`${op} needs the job id: {"action": "jobs", "job": {"op": "list"}} names it.`)
|
|
785
|
+
try {
|
|
786
|
+
state = await records().call("jobs.get", { job_id: id }, space.where)
|
|
787
|
+
} catch (error) {
|
|
788
|
+
log.warn(`spaces jobs ${op}: the state was not read`, error)
|
|
789
|
+
return fail(recordsFailure(error))
|
|
790
|
+
}
|
|
791
|
+
if (!state?.job?.state_digest) return text(`not ${op}: the job's state could not be read, so nothing changed. Try again.`)
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (op === "activate" || op === "delete") {
|
|
795
|
+
const act = op === "activate" ? "activating a job (approving its diff)" : "deleting a job"
|
|
796
|
+
return text(`not done: ${act} is the person's own act, in a browser, in Memory's console (Jobs), never an agent's. Send them to ${link}${id ? ` and open job ${oneLine(id, 40)}` : ""}: it shows the version and its diff, and asks them to confirm. Nothing changed.`)
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
let answer
|
|
800
|
+
try {
|
|
801
|
+
if (op === "list") {
|
|
802
|
+
const listed = await records().call("jobs.list", {}, space.where)
|
|
803
|
+
const rows = Array.isArray(listed?.jobs) ? listed.jobs : []
|
|
804
|
+
const lines = ["<jobs>", `space: ${space.label}`]
|
|
805
|
+
if (rows.length === 0) lines.push('(no jobs: make one from a template in the console, at ' + link + ")")
|
|
806
|
+
for (const job of rows) lines.push(describeJob(job))
|
|
807
|
+
lines.push("</jobs>")
|
|
808
|
+
if (rows.length > 0) lines.push('Read one with {"action": "jobs", "job": {"op": "get", "id": "<job id>"}}; an edit is a draft that never runs until the person activates it in the console.')
|
|
809
|
+
return text(lines.join("\n"))
|
|
810
|
+
}
|
|
811
|
+
if (op === "get") {
|
|
812
|
+
answer = await records().call("jobs.get", { job_id: id }, space.where)
|
|
813
|
+
} else if (op === "runs" || op === "logs") {
|
|
814
|
+
const limit = Math.min(100, Math.max(1, Number.parseInt(spec.limit, 10) || REVIEW_LIMIT))
|
|
815
|
+
answer = await records().call(op === "runs" ? "jobs.runs" : "jobs.logs", { job_id: id, limit }, space.where)
|
|
816
|
+
} else if (op === "versions") {
|
|
817
|
+
if (!id) return text('versions needs the job id: {"action": "jobs", "job": {"op": "list"}} names it.')
|
|
818
|
+
answer = await records().call("jobs.versions", { job_id: id }, space.where)
|
|
819
|
+
} else if (op === "draft") {
|
|
820
|
+
const body = { ...(id ? { job_id: id } : {}), ...(spec.template ? { template: spec.template } : {}), ...(spec.project ? { project: spec.project } : {}), ...(spec.account ? { account: spec.account } : {}), ...(isPlainObject(spec.scope) ? { scope: spec.scope } : {}), ...(spec.every ? { every: spec.every } : {}), ...(spec.max_lines ? { max_lines: spec.max_lines } : {}) }
|
|
821
|
+
answer = await records().call("jobs.draft", body, space.where)
|
|
822
|
+
} else if (op === "run_now") {
|
|
823
|
+
answer = await records().call("jobs.run", { job_id: id }, space.where)
|
|
824
|
+
} else if (op === "resume" || op === "archive") {
|
|
825
|
+
answer = await records().call(`jobs.${op}`, { job_id: id, expected_digest: state.job.state_digest }, space.where)
|
|
826
|
+
} else {
|
|
827
|
+
answer = await records().call(`jobs.${op}`, { job_id: id }, space.where)
|
|
828
|
+
}
|
|
829
|
+
} catch (error) {
|
|
830
|
+
log.warn(`spaces jobs ${op} failed`, error)
|
|
831
|
+
return fail(recordsFailure(error))
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (op === "get") {
|
|
835
|
+
const job = answer?.job
|
|
836
|
+
if (!job) return text("no job was found")
|
|
837
|
+
const lines = ["<job>", describeJob(job)]
|
|
838
|
+
if (answer.draft) {
|
|
839
|
+
lines.push(`draft: v${answer.draft.version}, made by ${oneLine(answer.draft.origin, 20)} against v${answer.draft.base}. What changed:`)
|
|
840
|
+
lines.push(...describeDiff(answer.draft.diff))
|
|
841
|
+
}
|
|
842
|
+
if (answer.consent) lines.push(`consent: version ${answer.consent.version}, ${oneLine(answer.consent.state, 20)}, confirmed in a session by ${oneLine(answer.consent.consented_by ?? "the person", 80)}`)
|
|
843
|
+
if (answer.request) lines.push(`request: waiting for the person's host to report the account (${oneLine(answer.request.state, 20)})`)
|
|
844
|
+
if (Array.isArray(answer.runs) && answer.runs.length) {
|
|
845
|
+
lines.push("last run:", ...answer.runs.slice(0, 3).map((run) => `- ${oneLine(run.id, 40)} ${oneLine(run.status, 20)}${run.outcome ? ` (${oneLine(run.outcome, 20)})` : ""}${run.error ? `: ${oneLine(errorMessage(run.error), 120)}` : ""}`))
|
|
846
|
+
}
|
|
847
|
+
lines.push("</job>")
|
|
848
|
+
if (answer.draft) lines.push(`The draft does not run: the person approves it in Memory's console, Jobs (${link}). Nothing an agent drafts runs until they do.`)
|
|
849
|
+
return text(lines.join("\n"))
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (op === "runs") {
|
|
853
|
+
const rows = Array.isArray(answer?.runs) ? answer.runs : []
|
|
854
|
+
const lines = ["<runs>", ...(rows.length ? rows.map((run) => `- ${oneLine(run.id, 40)} ${oneLine(run.status, 20)} v${run.version} ${oneLine(run.started, 40)}${run.error ? `: ${oneLine(errorMessage(run.error), 120)}` : ""}`) : ["(no runs yet)"]) , "</runs>"]
|
|
855
|
+
return text(lines.join("\n"))
|
|
856
|
+
}
|
|
857
|
+
if (op === "logs") {
|
|
858
|
+
const rows = Array.isArray(answer?.logs) ? answer.logs : []
|
|
859
|
+
const lines = ["<logs>", ...(rows.length ? rows.map((row) => `- ${oneLine(row.at, 40)} ${oneLine(row.level, 10)} ${oneLine(row.event, 40)}${row.detail ? `: ${oneLine(errorMessage(row.detail), 160)}` : ""}`) : ["(no runs, so no log)"]), "</logs>"]
|
|
860
|
+
return text(lines.join("\n"))
|
|
861
|
+
}
|
|
862
|
+
if (op === "versions") {
|
|
863
|
+
const rows = Array.isArray(answer?.versions) ? answer.versions : []
|
|
864
|
+
const lines = ["<versions>", ...rows.map((version) => `- v${version.version} ${oneLine(version.state, 20)}, by ${oneLine(version.origin, 20)}${version.approved_at ? `, approved ${oneLine(version.approved_at, 40)}` : ""}`), "</versions>"]
|
|
865
|
+
return text(lines.join("\n"))
|
|
866
|
+
}
|
|
867
|
+
if (op === "draft") {
|
|
868
|
+
const job = answer?.job
|
|
869
|
+
if (!job) return text("the draft was not stored")
|
|
870
|
+
const lines = [`drafted v${answer.draft?.version ?? "?"} of ${oneLine(job.id, 40)} (${JOB_STATUS[job.status] ?? oneLine(job.status, 20)}). What changed:`]
|
|
871
|
+
lines.push(...describeDiff(answer.draft?.diff))
|
|
872
|
+
lines.push(`It does not run. The person confirms it in Memory's console, Jobs (${link}): they see this diff and the account, and nothing an agent drafts runs until they do.`)
|
|
873
|
+
return text(lines.join("\n"))
|
|
874
|
+
}
|
|
875
|
+
if (op === "run_now") return text(`queued: job ${oneLine(answer?.job?.id ?? id ?? "?", 40)} is due now; the person's job host takes it at its next heartbeat (about a minute) and writes when the run finishes.`)
|
|
876
|
+
const job = answer?.job
|
|
877
|
+
if (!job) return text(`${op}: done.`)
|
|
878
|
+
return text(`${op}: ${oneLine(job.id, 40)} is ${JOB_STATUS[job.status] ?? oneLine(job.status, 20)}.`)
|
|
879
|
+
}
|
|
880
|
+
|
|
542
881
|
/** What Memory holds about the person: the views' `profile.read`, as text. Personal space only; read-only. */
|
|
543
882
|
async function profile(context) {
|
|
544
883
|
const resolved = await toolkit.resolvePrivateSpace({}, context)
|
|
@@ -566,7 +905,12 @@ export function createSpacesActions(toolkit) {
|
|
|
566
905
|
if (action === "access") return await access(input, context)
|
|
567
906
|
if (action === "health") return await health(input, context)
|
|
568
907
|
if (action === "sources") return await sources(input, context)
|
|
908
|
+
if (action === "jobs") return await jobs(input, context)
|
|
569
909
|
if (action === "profile") return await profile(context)
|
|
910
|
+
if (SPACE_LIFECYCLE_ACTIONS.includes(action)) {
|
|
911
|
+
if (!control) return noControl(`${action} a space`)
|
|
912
|
+
return await lifecycle[action](input, context)
|
|
913
|
+
}
|
|
570
914
|
return await review(input, context)
|
|
571
915
|
} catch (error) {
|
|
572
916
|
log.warn(`spaces ${action} failed`, error)
|
|
@@ -574,5 +918,5 @@ export function createSpacesActions(toolkit) {
|
|
|
574
918
|
}
|
|
575
919
|
}
|
|
576
920
|
|
|
577
|
-
return { run, profile, current, list, members, access, health, sources, review }
|
|
921
|
+
return { run, profile, current, list, members, access, health, sources, jobs, review }
|
|
578
922
|
}
|
package/src/tools/status.js
CHANGED
|
@@ -82,7 +82,14 @@ async function recordsLines(toolkit, input, context, spaceContext) {
|
|
|
82
82
|
const counts = (map) => [...map].map(([key, count]) => `${oneLine(key, 40)} ${count}`).join(", ")
|
|
83
83
|
lines.push(`records: ${counts(kinds) || "none"}`)
|
|
84
84
|
if (statuses.size > 0) lines.push(`records by status: ${counts(statuses)}`)
|
|
85
|
-
if (isPlainObject(stats?.events))
|
|
85
|
+
if (isPlainObject(stats?.events)) {
|
|
86
|
+
const events = Number(stats.events.total) || 0
|
|
87
|
+
lines.push(`events: ${events}`)
|
|
88
|
+
// The true reading of a nonzero count (0.10.3 gate, A15): collected mail
|
|
89
|
+
// HAS reached Memory, in a layer no recall reads, so a failed collect does
|
|
90
|
+
// not mean it never arrived. Say both.
|
|
91
|
+
if (events > 0) lines.push("collected text: recall does not read events; only a routine turns them into proposals or journal pages")
|
|
92
|
+
}
|
|
86
93
|
if (isPlainObject(stats?.sources)) {
|
|
87
94
|
const sources = stats.sources
|
|
88
95
|
const requested = Number(sources.requested) || 0
|
|
@@ -93,7 +100,7 @@ async function recordsLines(toolkit, input, context, spaceContext) {
|
|
|
93
100
|
lines.push(await routinesLine(records, where, stats))
|
|
94
101
|
const runs = Array.isArray(stats?.last_runs) ? stats.last_runs : []
|
|
95
102
|
for (const run of runs.slice(0, 5)) {
|
|
96
|
-
lines.push(`routine ${oneLine(run?.routine ?? "?", 20)}: ${oneLine(run?.status ?? "?", 20)} ${oneLine(run?.date ?? run?.ended ?? run?.started ?? "", 40)}${run?.error ? ` (${oneLine(run.error, 120)})` : ""}`)
|
|
103
|
+
lines.push(`routine ${oneLine(run?.routine ?? "?", 20)}: ${oneLine(run?.status ?? "?", 20)} ${oneLine(run?.date ?? run?.ended ?? run?.started ?? "", 40)}${run?.error ? ` (${oneLine(errorMessage(run.error), 120)})` : ""}`)
|
|
97
104
|
}
|
|
98
105
|
return lines
|
|
99
106
|
}
|