@joe-broadhead/opencode-mem 0.9.14 → 0.11.3
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 +1856 -0
- package/README.md +15 -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 +8921 -1070
- 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 +88 -7
- 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 +74 -23
- package/src/tools/held-write.js +46 -19
- package/src/tools/index.js +28 -0
- package/src/tools/ingest.js +38 -2
- package/src/tools/memory.js +56 -25
- package/src/tools/page.js +212 -95
- package/src/tools/recall.js +218 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +84 -6
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +381 -30
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +231 -116
- 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 +1082 -23
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +26 -1
- package/src/views/records-reads.js +520 -41
- package/src/views/rpc.js +153 -25
- package/src/views/shape.js +8 -5
- package/src/views/write-state.js +89 -0
- package/src/wiki-ingest.js +215 -0
- package/src/wiki-state.js +228 -0
- package/views/pages.html +2 -2
package/src/tools/spaces.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
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"
|
|
8
|
+
import { unreachableSpace, spaceUnreachable } from "./shared.js"
|
|
7
9
|
import { renderHealth } from "./status.js"
|
|
10
|
+
import { createSpaceLifecycle } from "./space-lifecycle.js"
|
|
8
11
|
|
|
9
|
-
export const SPACES_ACTIONS = Object.freeze(["current", "list", "members", "access", "health", "sources", "review", "profile"])
|
|
12
|
+
export const SPACES_ACTIONS = Object.freeze(["current", "list", "members", "access", "health", "sources", "jobs", "review", "profile", "create", "rename", "archive", "leave", "handover"])
|
|
13
|
+
/** The actions that change a space itself (DESIGN-CRUD S1, space-lifecycle.js). */
|
|
14
|
+
export const SPACE_LIFECYCLE_ACTIONS = Object.freeze(["create", "rename", "archive", "leave", "handover"])
|
|
10
15
|
const DECISIONS = Object.freeze(["accept", "reject", "edit"])
|
|
16
|
+
/** The `mem_spaces jobs` operations (DESIGN-MEMORY-JOBS §12). */
|
|
17
|
+
export const JOB_OPS = Object.freeze(["list", "get", "runs", "logs", "versions", "draft", "run_now", "pause", "resume", "archive", "activate", "delete"])
|
|
11
18
|
const REVIEW_LIMIT = 20
|
|
12
19
|
|
|
13
20
|
/**
|
|
@@ -33,7 +40,7 @@ export function registerSpaces(editor, toolkit) {
|
|
|
33
40
|
editor.add({
|
|
34
41
|
name: "spaces",
|
|
35
42
|
description:
|
|
36
|
-
"
|
|
43
|
+
"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
44
|
input: {
|
|
38
45
|
type: "object",
|
|
39
46
|
properties: {
|
|
@@ -41,13 +48,15 @@ export function registerSpaces(editor, toolkit) {
|
|
|
41
48
|
type: "string",
|
|
42
49
|
enum: [...SPACES_ACTIONS],
|
|
43
50
|
description:
|
|
44
|
-
'Required.
|
|
51
|
+
'Required. Example: {"action": "health"}',
|
|
45
52
|
},
|
|
46
|
-
space: { type: "string", description: "Space id
|
|
53
|
+
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" },
|
|
54
|
+
name: { type: "string", description: "create, rename: the space's name" },
|
|
55
|
+
user: { type: "string", description: "handover: the new owner, an email or user id; they must already be a member" },
|
|
56
|
+
restore: { type: "boolean", description: "archive: true unarchives the space" },
|
|
47
57
|
bind: {
|
|
48
58
|
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"}}',
|
|
59
|
+
description: 'current: bind this session to a space. sources: ask to collect from one source; the person confirms in the console',
|
|
51
60
|
properties: {
|
|
52
61
|
space: { type: "string", description: 'current: "personal" or a space id from list' },
|
|
53
62
|
source: { type: "string", description: "sources: the source plugin's Code Mode namespace, such as gmail or slack" },
|
|
@@ -57,28 +66,45 @@ export function registerSpaces(editor, toolkit) {
|
|
|
57
66
|
},
|
|
58
67
|
unbind: {
|
|
59
68
|
type: "object",
|
|
60
|
-
description: "sources: stop collecting
|
|
69
|
+
description: "sources: stop collecting and delete that account's events; previews unless confirm",
|
|
61
70
|
properties: {
|
|
62
|
-
source: { type: "string", description: "The source
|
|
71
|
+
source: { type: "string", description: "The source" },
|
|
63
72
|
account: { type: "string", description: 'The account; default "default"' },
|
|
64
73
|
},
|
|
65
74
|
required: ["source"],
|
|
66
75
|
additionalProperties: false,
|
|
67
76
|
},
|
|
68
|
-
confirm: { type: "boolean", description: "unbind: true
|
|
77
|
+
confirm: { type: "boolean", description: "unbind, archive, leave, handover: true acts, after the person agreed; omitted previews" },
|
|
78
|
+
job: {
|
|
79
|
+
type: "object",
|
|
80
|
+
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',
|
|
81
|
+
properties: {
|
|
82
|
+
op: { type: "string", enum: [...JOB_OPS] },
|
|
83
|
+
id: { type: "string" },
|
|
84
|
+
template: { type: "string" },
|
|
85
|
+
project: { type: "string" },
|
|
86
|
+
account: { type: "string" },
|
|
87
|
+
scope: { type: "object", additionalProperties: true },
|
|
88
|
+
every: { type: "string" },
|
|
89
|
+
max_lines: { type: "integer", minimum: 1, maximum: 500 },
|
|
90
|
+
limit: { type: "integer", minimum: 1, maximum: 100 },
|
|
91
|
+
},
|
|
92
|
+
required: ["op"],
|
|
93
|
+
additionalProperties: false,
|
|
94
|
+
},
|
|
69
95
|
decide: {
|
|
70
96
|
type: "object",
|
|
71
|
-
description:
|
|
97
|
+
description: "review: answer one proposal, when the person says",
|
|
72
98
|
properties: {
|
|
73
|
-
id: { type: "string", description: "The proposal id
|
|
99
|
+
id: { type: "string", description: "The proposal id" },
|
|
74
100
|
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
|
|
101
|
+
reason: { type: "string", description: "Why; kept on the proposal" },
|
|
102
|
+
payload: { type: "string", description: "edit: the text to apply instead" },
|
|
77
103
|
},
|
|
78
104
|
required: ["id", "decision"],
|
|
79
105
|
additionalProperties: false,
|
|
80
106
|
},
|
|
81
|
-
limit: { type: "integer", minimum: 1, maximum: 100, description: `review: proposals to list (default ${REVIEW_LIMIT}
|
|
107
|
+
limit: { type: "integer", minimum: 1, maximum: 100, description: `review: proposals to list (default ${REVIEW_LIMIT})` },
|
|
82
108
|
},
|
|
83
109
|
required: ["action"],
|
|
84
110
|
additionalProperties: false,
|
|
@@ -97,6 +123,7 @@ export function registerSpaces(editor, toolkit) {
|
|
|
97
123
|
export function createSpacesActions(toolkit) {
|
|
98
124
|
const { config, control, log, text, fail, resolveSpace, describeSpace, describeCollection } = toolkit
|
|
99
125
|
const records = () => recordsOf(toolkit)
|
|
126
|
+
const lifecycle = createSpaceLifecycle(toolkit)
|
|
100
127
|
const noControl = (what) => text(`control plane not configured; set MEMORY_CONTROL_URL to ${what}`)
|
|
101
128
|
|
|
102
129
|
/**
|
|
@@ -116,7 +143,13 @@ export function createSpacesActions(toolkit) {
|
|
|
116
143
|
const personalId = own?.personal_space_id || (own?.space_kind === "personal" ? own.space_id : "")
|
|
117
144
|
const spaceId = target === "personal" ? personalId : target
|
|
118
145
|
if (!spaceId) return { error: "the control plane returned no personal space" }
|
|
119
|
-
|
|
146
|
+
let targetContext
|
|
147
|
+
try {
|
|
148
|
+
targetContext = spaceId === own?.space_id ? own : await toolkit.resolveContext({ space: spaceId, agent: context?.agent })
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (spaceUnreachable(error)) return { message: unreachableSpace(target) }
|
|
151
|
+
return { error: errorMessage(error) }
|
|
152
|
+
}
|
|
120
153
|
if (!targetContext?.space_id) return { error: "the control plane returned no space context" }
|
|
121
154
|
const narrows = targetContext.space_kind === "personal" && targetContext.space_id === personalId
|
|
122
155
|
if (!narrows) {
|
|
@@ -208,15 +241,58 @@ export function createSpacesActions(toolkit) {
|
|
|
208
241
|
const spaceContext = resolved.context
|
|
209
242
|
if (!spaceContext?.space_id) return fail("the control plane returned no space context")
|
|
210
243
|
const roster = await control.listMembers({ userId: config.user, spaceId: spaceContext.space_id })
|
|
244
|
+
// Who "you" is in the roster (0.10.3 gate B12; review F1). Behind the
|
|
245
|
+
// gateway control renames the caller to its own `usr_…` id, so only the ids
|
|
246
|
+
// the server itself named can match; in direct-control mode the roster is
|
|
247
|
+
// scoped to `config.user` and may answer with it. An id no member carries
|
|
248
|
+
// matches nobody: then no one is marked and nothing is claimed about them.
|
|
249
|
+
const keys = personKeys(spaceContext, config.user)
|
|
250
|
+
const marked = roster.filter((member) => memberIsPerson(member, keys))
|
|
251
|
+
const you = marked.length === 1 ? marked[0] : null
|
|
252
|
+
const others = roster.length - marked.length
|
|
211
253
|
const lines = ["<members>", `space: ${describeSpace(spaceContext)}`]
|
|
212
254
|
if (roster.length === 0) lines.push("(no members visible to you in this space)")
|
|
213
255
|
for (const member of roster) {
|
|
214
|
-
|
|
256
|
+
const role = oneLine(member.role || "member", 40)
|
|
257
|
+
lines.push(
|
|
258
|
+
`- ${oneLine(member.name || member.email || member.user_id, 160)} (${role}${member === you ? ", you" : ""}) user_id=${oneLine(member.user_id, 120)}`,
|
|
259
|
+
)
|
|
215
260
|
}
|
|
261
|
+
// 0.10.5 gate B10: who owns the space, when the roster shows an owner.
|
|
262
|
+
// A handover's confirmer is that person, and a caller who cannot see one
|
|
263
|
+
// is told so rather than left to guess a name.
|
|
264
|
+
const owner = roster.find((member) => String(member.role ?? "").toLowerCase() === "owner") ?? null
|
|
265
|
+
lines.push(`owner: ${owner ? `${oneLine(owner.name || owner.email || owner.user_id, 160)} user_id=${oneLine(owner.user_id, 120)}` : "not visible to you"}`)
|
|
266
|
+
// The count of other people a change here affects, only when the person
|
|
267
|
+
// was found; never a negative about who is or is not in the list.
|
|
268
|
+
if (you) lines.push(`other members: ${others}`)
|
|
216
269
|
lines.push("</members>")
|
|
217
270
|
return text(lines.join("\n"))
|
|
218
271
|
}
|
|
219
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The ids the roster may know the caller by. Behind the gateway (`routing:
|
|
275
|
+
* "gateway"`) the context's own `user_id` is the plugin's, not control's, so
|
|
276
|
+
* only ids the server echoed count; in direct-control mode the roster is
|
|
277
|
+
* scoped to `config.user` and may answer with it.
|
|
278
|
+
*/
|
|
279
|
+
function personKeys(spaceContext, fallback) {
|
|
280
|
+
const keys = new Set()
|
|
281
|
+
for (const id of [spaceContext?.auth_user_id, spaceContext?.upstream_user_id]) if (id) keys.add(String(id))
|
|
282
|
+
if (spaceContext?.routing !== "gateway") {
|
|
283
|
+
if (spaceContext?.user_id) keys.add(String(spaceContext.user_id))
|
|
284
|
+
if (fallback) keys.add(String(fallback))
|
|
285
|
+
}
|
|
286
|
+
keys.delete("")
|
|
287
|
+
return keys
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** True when a roster row is the caller: control's id, or the memory id its records carry. */
|
|
291
|
+
function memberIsPerson(member, keys) {
|
|
292
|
+
if (keys.size === 0) return false
|
|
293
|
+
return [member?.user_id, member?.upstream_user_id].some((id) => Boolean(id) && keys.has(String(id)))
|
|
294
|
+
}
|
|
295
|
+
|
|
220
296
|
async function access(input, context) {
|
|
221
297
|
if (!control) return noControl("read grants")
|
|
222
298
|
const resolved = await resolveSpace(input, context)
|
|
@@ -278,16 +354,45 @@ export function createSpacesActions(toolkit) {
|
|
|
278
354
|
const asked = String(value?.account ?? "").trim()
|
|
279
355
|
const account = asked || DEFAULT_ACCOUNT
|
|
280
356
|
if (!isSourceName(source)) return { error: `"${oneLine(source || "(none)", 60)}" is not a source name: one of ${knownSources().join(", ")}.` }
|
|
281
|
-
if (known && !
|
|
357
|
+
if (known && !bindableSource(source)) {
|
|
358
|
+
// Said plainly, and each for its own reason: a kind this release does not
|
|
359
|
+
// read (G1), or an installed release too old to serve it (G3). A name
|
|
360
|
+
// Memory does not know at all keeps the list.
|
|
361
|
+
const kind = kindProblem(source)
|
|
362
|
+
if (kind) return { error: `${kind.message} ${kind.next}` }
|
|
363
|
+
return { error: `"${oneLine(source, 60)}" is not a source Memory knows: one of ${knownSources().join(", ")}.` }
|
|
364
|
+
}
|
|
282
365
|
if (!isAccountName(account)) return { error: `"${oneLine(account, 60)}" is not an account name.` }
|
|
283
366
|
return { source, account, asked: Boolean(asked) }
|
|
284
367
|
}
|
|
285
368
|
|
|
286
|
-
const describeBinding = (row) => {
|
|
369
|
+
const describeBinding = (row, behind = null) => {
|
|
287
370
|
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
371
|
const state = [row.status || "unknown", row.enabled === true || row.enabled === 1 ? "enabled" : "disabled"].join(", ")
|
|
289
372
|
const cursor = row.cursor_at ? `, last collected ${oneLine(row.cursor_at, 40)}` : ""
|
|
290
|
-
|
|
373
|
+
// The installed release, and the tag that declares `sources` (G3, review S1):
|
|
374
|
+
// the row **informs** and never withholds a read. A git pin reports a commit,
|
|
375
|
+
// which is not a version, so only a real version is shown.
|
|
376
|
+
const entry = sourceEntry(row.source)
|
|
377
|
+
const note = releaseNote(row.source)
|
|
378
|
+
const release = note
|
|
379
|
+
? `, ${note.installed ? `installed ${oneLine(note.installed, 40)}, ` : ""}${oneLine(note.declares, 20)} declares its sources`
|
|
380
|
+
: installedVersionOf(row.source) && entry?.contract === "sources"
|
|
381
|
+
? `, plugin ${oneLine(installedVersionOf(row.source), 40)}`
|
|
382
|
+
: ""
|
|
383
|
+
// A bound source of a kind this release does not read is marked, not left
|
|
384
|
+
// looking healthy (G1, review S4): nothing is collected from it.
|
|
385
|
+
const kind = kindProblem(row.source)
|
|
386
|
+
const notCollected = kind ? `, not collected: ${oneLine(kind.message, 200)}` : ""
|
|
387
|
+
// A named-account binding from before 0.11 records no asked account (review
|
|
388
|
+
// L4-1): its row says so, and how to end it.
|
|
389
|
+
const unknownAsk = row.asked_unknown === true
|
|
390
|
+
? ", connected before 0.11, so Memory does not know which account was asked for. If this account is no longer used, unbind it"
|
|
391
|
+
: ""
|
|
392
|
+
// A run that ended with `more: true` left pages behind (G7): the row says so,
|
|
393
|
+
// and the next run comes sooner.
|
|
394
|
+
const catchingUp = behind?.has(`${row.source}\u0000${row.account || DEFAULT_ACCOUNT}`) ? ", catching up: more waits for the next run" : ""
|
|
395
|
+
return `- ${oneLine(row.source, 64)}:${oneLine(row.account || DEFAULT_ACCOUNT, 128)} ${owner}: ${state}${cursor}${release}${notCollected}${unknownAsk}${catchingUp}`
|
|
291
396
|
}
|
|
292
397
|
|
|
293
398
|
async function listSources(where) {
|
|
@@ -307,10 +412,10 @@ export function createSpacesActions(toolkit) {
|
|
|
307
412
|
const name = `${oneLine(row.source, 64)}:${oneLine(row.account || DEFAULT_ACCOUNT, 128)}`
|
|
308
413
|
const asked = row.requested_at ? ` (asked ${oneLine(row.requested_at, 40)})` : ""
|
|
309
414
|
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)}` : ""}`
|
|
415
|
+
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
416
|
}
|
|
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"}`
|
|
417
|
+
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`
|
|
418
|
+
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
419
|
return `- ${name} bind requested${asked}: waiting for the collector's next run to report the signed-in account`
|
|
315
420
|
}
|
|
316
421
|
|
|
@@ -318,7 +423,7 @@ export function createSpacesActions(toolkit) {
|
|
|
318
423
|
async function syncCollector(rows) {
|
|
319
424
|
if (!toolkit.collector) return ""
|
|
320
425
|
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)}).`
|
|
426
|
+
if (result.action === "failed") return `Collection: the memory-collect schedule could not be updated (${oneLine(errorMessage(result.error), 200)}).`
|
|
322
427
|
if (result.mode === "schedule" && result.action === "removed") return "Collection: no source is enabled, so the memory-collect schedule was removed."
|
|
323
428
|
if (result.mode === "schedule" && (result.action === "created" || result.action === "rewritten")) {
|
|
324
429
|
return `Collection: the host's memory-collect schedule was ${result.action}; it runs every 30 minutes for ${result.sources} source(s).`
|
|
@@ -348,7 +453,10 @@ export function createSpacesActions(toolkit) {
|
|
|
348
453
|
* or token. Here the plugin only asks: it records a bind request when there
|
|
349
454
|
* is none (`sources.request`, which reads and collects nothing; the
|
|
350
455
|
* person's collector then reports the signed-in account), and answers with
|
|
351
|
-
* the console link where the person confirms it.
|
|
456
|
+
* the console link where the person confirms it. The one-binding rule (a
|
|
457
|
+
* legacy alias and the declared sources it stands for are the same account)
|
|
458
|
+
* is the records service's, so this refuses nothing by itself: it shows the
|
|
459
|
+
* server's refusal, with the server's next step.
|
|
352
460
|
*/
|
|
353
461
|
async function bindSource(value, space, rows, requests) {
|
|
354
462
|
const asked = bindingOf(value, { known: true })
|
|
@@ -365,7 +473,7 @@ export function createSpacesActions(toolkit) {
|
|
|
365
473
|
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
474
|
}
|
|
367
475
|
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)})` : ""}.` : ""
|
|
476
|
+
const why = open.state === "attention" || open.state === "failed" ? ` The collector could not read the account yet${open.note ? ` (${oneLine(errorMessage(open.note), 240)})` : ""}.` : ""
|
|
369
477
|
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
478
|
}
|
|
371
479
|
try {
|
|
@@ -458,7 +566,13 @@ export function createSpacesActions(toolkit) {
|
|
|
458
566
|
const sync = await syncCollector(rows)
|
|
459
567
|
const lines = ["<sources>", `space: ${space.label}`]
|
|
460
568
|
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
|
-
|
|
569
|
+
let behind = null
|
|
570
|
+
try {
|
|
571
|
+
behind = typeof toolkit.collector?.behind === "function" ? toolkit.collector.behind() : null
|
|
572
|
+
} catch {
|
|
573
|
+
behind = null
|
|
574
|
+
}
|
|
575
|
+
for (const row of rows) lines.push(describeBinding(row, behind))
|
|
462
576
|
for (const row of requests) lines.push(describeRequest(row))
|
|
463
577
|
lines.push("</sources>")
|
|
464
578
|
if (toolkit.collector) lines.push(toolkit.collector.describe())
|
|
@@ -471,7 +585,61 @@ export function createSpacesActions(toolkit) {
|
|
|
471
585
|
const target = fields.target_path || fields.target_id || ""
|
|
472
586
|
const evidence = Array.isArray(fields.evidence) ? fields.evidence.length : 0
|
|
473
587
|
const what = oneLine(proposal?.title || (typeof fields.payload === "string" ? fields.payload : proposal?.body) || "", 200)
|
|
474
|
-
|
|
588
|
+
// 0.10.6 gate H3: an external proposal (a share an email asked for) is not
|
|
589
|
+
// the routine's suggestion about the person's own work, so the list says
|
|
590
|
+
// so where it is read, and a decision on it needs their words.
|
|
591
|
+
const external = proposal?.stated_by && proposal.stated_by !== "person" ? ", external: decide only when the person says" : ""
|
|
592
|
+
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}`
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* What a decision leaves waiting, named after it (0.10.6 gate H3, the second
|
|
597
|
+
* item): an agent asked to "accept whatever is routine" accepted one
|
|
598
|
+
* proposal and rejected an injected share proposal nobody asked it to
|
|
599
|
+
* decide. The answer now lists what still waits, so "leave the rest
|
|
600
|
+
* pending, and say so" is the path of least resistance. A failed read never
|
|
601
|
+
* fails a decision that already applied.
|
|
602
|
+
*/
|
|
603
|
+
async function stillPending(space, decidedID) {
|
|
604
|
+
let rest
|
|
605
|
+
try {
|
|
606
|
+
rest = (await records().call("review.list", { limit: REVIEW_LIMIT }, space.where))?.proposals ?? []
|
|
607
|
+
} catch (error) {
|
|
608
|
+
log.debug("review list after a decision failed", error)
|
|
609
|
+
return ""
|
|
610
|
+
}
|
|
611
|
+
const waiting = rest.filter((proposal) => String(proposal?.id ?? "") !== decidedID)
|
|
612
|
+
if (waiting.length === 0) return ""
|
|
613
|
+
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:`]
|
|
614
|
+
for (const proposal of waiting) lines.push(describeProposal(proposal))
|
|
615
|
+
return lines.join("\n")
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/** The refusal of a rejection the person's latest message did not ask for (0.10.6 gate H3). */
|
|
619
|
+
const DECLINE_NEEDS_REQUEST = (id) =>
|
|
620
|
+
`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.`
|
|
621
|
+
|
|
622
|
+
/** The refusal of a decision on an external proposal the person did not name (0.10.7 review F1). */
|
|
623
|
+
const EXTERNAL_NEEDS_REQUEST = (id) =>
|
|
624
|
+
`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.`
|
|
625
|
+
|
|
626
|
+
/** The refusal when the guard cannot read the proposal (0.10.7 review R2-2): fail closed. */
|
|
627
|
+
const UNREADABLE_PROPOSAL = (id) =>
|
|
628
|
+
`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.`
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* The proposal a decision would act on, from the open list (the same call the
|
|
632
|
+
* review list makes). `null` when the service did not list it: the decision
|
|
633
|
+
* then goes to the service, which refuses a proposal that is not open.
|
|
634
|
+
*/
|
|
635
|
+
async function openProposal(space, id) {
|
|
636
|
+
try {
|
|
637
|
+
const proposals = (await records().call("review.list", { limit: 100 }, space.where))?.proposals ?? []
|
|
638
|
+
return proposals.find((proposal) => String(proposal?.id ?? "") === id) ?? null
|
|
639
|
+
} catch (error) {
|
|
640
|
+
log.debug("review list for a decision failed", error)
|
|
641
|
+
return null
|
|
642
|
+
}
|
|
475
643
|
}
|
|
476
644
|
|
|
477
645
|
async function review(input, context) {
|
|
@@ -485,8 +653,26 @@ export function createSpacesActions(toolkit) {
|
|
|
485
653
|
const decision = String(input.decide.decision ?? "").trim()
|
|
486
654
|
if (!id) return text("not decided: decide needs the proposal id.")
|
|
487
655
|
if (!DECISIONS.includes(decision)) return text(`not decided: decision is accept, edit or reject, not ${oneLine(decision || "(none)", 40)}.`)
|
|
656
|
+
// The guard, not the description (0.10.7 review R2-1, R2-2, R2-4): a
|
|
657
|
+
// review decision is never exempt, every decision on a proposal that did
|
|
658
|
+
// not come from the person needs their own words naming it as the object
|
|
659
|
+
// of that decision, a reject acts only on the proposal named, and a
|
|
660
|
+
// proposal the guard cannot read is refused. A routine proposal still
|
|
661
|
+
// follows "accept whatever is routine".
|
|
488
662
|
const payload = String(input.decide.payload ?? "").trim()
|
|
489
663
|
if (decision === "edit" && !payload) return text("not decided: an edit needs payload, the text to apply instead.")
|
|
664
|
+
await toolkit.ensureSession?.(context?.sessionID)
|
|
665
|
+
const proposal = await openProposal(space, id)
|
|
666
|
+
const said = latestWord(toolkit.runtime, context?.sessionID, context)
|
|
667
|
+
if (!proposal) {
|
|
668
|
+
// Fail closed: no record, so no provenance and nothing to tie a
|
|
669
|
+
// decision to. Only a model's decision is refused; a host's direct
|
|
670
|
+
// call is refused too, because a review decision is never exempt.
|
|
671
|
+
return text(UNREADABLE_PROPOSAL(id))
|
|
672
|
+
}
|
|
673
|
+
const named = namesProposal(said.text, proposal, decision === "reject" ? "reject" : "accept")
|
|
674
|
+
const asked = decision === "reject" ? asksToDecline(said.text) && named : proposal.stated_by === "person" || named
|
|
675
|
+
if (mustRefuse(said, asked, { modelOnly: false })) return text(decision === "reject" ? DECLINE_NEEDS_REQUEST(id) : EXTERNAL_NEEDS_REQUEST(id))
|
|
490
676
|
const reason = String(input.decide.reason ?? "").trim()
|
|
491
677
|
// A decision in a shared space changes what every member reads, so it
|
|
492
678
|
// goes through the one gate and asks, as a revise does.
|
|
@@ -521,7 +707,8 @@ export function createSpacesActions(toolkit) {
|
|
|
521
707
|
const applied = answer?.applied
|
|
522
708
|
const appliedText = isPlainObject(applied) && applied.id ? ` Applied as ${oneLine(applied.id, 40)}${applied.path ? ` (${oneLine(applied.path, 120)})` : ""}.` : ""
|
|
523
709
|
const learned = decision === "reject" && reason ? " The reason is kept on the proposal only, not as a memory." : ""
|
|
524
|
-
|
|
710
|
+
const rest = await stillPending(space, id)
|
|
711
|
+
return text(`${decision === "reject" ? "rejected" : decision === "edit" ? "edited and applied" : "accepted"} proposal ${oneLine(id, 40)} in ${space.label}.${appliedText}${learned}${rest}`)
|
|
525
712
|
}
|
|
526
713
|
|
|
527
714
|
const limit = Math.min(100, Math.max(1, Number.parseInt(input?.limit, 10) || REVIEW_LIMIT))
|
|
@@ -539,6 +726,165 @@ export function createSpacesActions(toolkit) {
|
|
|
539
726
|
return text(lines.join("\n"))
|
|
540
727
|
}
|
|
541
728
|
|
|
729
|
+
/* ------------------------------------------------------------------ jobs */
|
|
730
|
+
|
|
731
|
+
const JOB_STATUS = { draft: "draft, not running", active: "active", paused: "paused", archived: "archived" }
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* The tiers of the ops that change a job (DESIGN-MEMORY-JOBS §12): `run_now`
|
|
735
|
+
* and `resume` are G1 — they ask, and the person's skipAsks may lift them;
|
|
736
|
+
* `archive` is G2 — it asks, and no setting lifts that. Drafting, pausing and
|
|
737
|
+
* reading ask nothing (G0): a draft never runs, and pausing only narrows.
|
|
738
|
+
*/
|
|
739
|
+
const JOB_GATES = Object.freeze({
|
|
740
|
+
run_now: { action: "job.run", ask: "unless-skipped" },
|
|
741
|
+
resume: { action: "job.resume", ask: "unless-skipped" },
|
|
742
|
+
archive: { action: "job.archive", ask: "always" },
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
function describeJob(job) {
|
|
746
|
+
const next = job.next_due ? `, next ${oneLine(job.next_due, 40)}` : ""
|
|
747
|
+
const draft = job.draft ? `, draft v${job.draft.version}` : ""
|
|
748
|
+
const consent = job.consent ? (job.consent.state === "on" ? "" : `, consent ${oneLine(job.consent.state, 20)}`) : ""
|
|
749
|
+
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}`
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function describeDiff(diff) {
|
|
753
|
+
return (Array.isArray(diff) ? diff : []).slice(0, 8).map((entry) => {
|
|
754
|
+
const from = entry.from === null || entry.from === undefined ? "nothing" : oneLine(JSON.stringify(entry.from), 80)
|
|
755
|
+
const to = entry.to === null || entry.to === undefined ? "nothing" : oneLine(JSON.stringify(entry.to), 80)
|
|
756
|
+
return `- ${oneLine(entry.field, 40)}: ${from} → ${to}`
|
|
757
|
+
})
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* `jobs` (DESIGN-MEMORY-JOBS §12): Memory's scheduled pipelines, folded into
|
|
762
|
+
* `mem_spaces` rather than a new tool. An agent may read, and may draft; a
|
|
763
|
+
* draft never runs. Turning a job on and deleting it are the person's own
|
|
764
|
+
* acts in a browser, so those two answer with the console link and call
|
|
765
|
+
* nothing: there is no agent door to them (§5.5, §5.6).
|
|
766
|
+
*/
|
|
767
|
+
async function jobs(input, context) {
|
|
768
|
+
if (!records()) return text(RECORDS_MISSING)
|
|
769
|
+
const spec = isPlainObject(input?.job) ? input.job : {}
|
|
770
|
+
const op = String(spec.op ?? "").trim()
|
|
771
|
+
if (!JOB_OPS.includes(op)) return text(`jobs needs job.op, one of ${JOB_OPS.join(", ")}. Example: {"action": "jobs", "job": {"op": "list"}}`)
|
|
772
|
+
const space = await recordsSpace(input, context, { personalDefault: true })
|
|
773
|
+
if (space.message) return text(space.message)
|
|
774
|
+
if (space.error) return fail(space.error)
|
|
775
|
+
const link = consoleAt("jobs")
|
|
776
|
+
const id = String(spec.id ?? "").trim() || undefined
|
|
777
|
+
|
|
778
|
+
// The tier's gate, before anything is asked of the records service.
|
|
779
|
+
const gate = JOB_GATES[op]
|
|
780
|
+
if (gate) {
|
|
781
|
+
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 } })
|
|
782
|
+
if (answer.denied) return text(`not ${op === "run_now" ? "run" : op} (approval): ${answer.denied}. Nothing changed.`)
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// 0.10 review: resume and archive change a job, so the records service takes
|
|
786
|
+
// the person's proof — a console session, or the digest of the state this
|
|
787
|
+
// read names (DESIGN-CRUD revision 4). The ask comes first, as for every
|
|
788
|
+
// write; the read only supplies the digest the commit carries.
|
|
789
|
+
let state
|
|
790
|
+
if (op === "resume" || op === "archive") {
|
|
791
|
+
if (!id) return text(`${op} needs the job id: {"action": "jobs", "job": {"op": "list"}} names it.`)
|
|
792
|
+
try {
|
|
793
|
+
state = await records().call("jobs.get", { job_id: id }, space.where)
|
|
794
|
+
} catch (error) {
|
|
795
|
+
log.warn(`spaces jobs ${op}: the state was not read`, error)
|
|
796
|
+
return fail(recordsFailure(error))
|
|
797
|
+
}
|
|
798
|
+
if (!state?.job?.state_digest) return text(`not ${op}: the job's state could not be read, so nothing changed. Try again.`)
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (op === "activate" || op === "delete") {
|
|
802
|
+
const act = op === "activate" ? "activating a job (approving its diff)" : "deleting a job"
|
|
803
|
+
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.`)
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
let answer
|
|
807
|
+
try {
|
|
808
|
+
if (op === "list") {
|
|
809
|
+
const listed = await records().call("jobs.list", {}, space.where)
|
|
810
|
+
const rows = Array.isArray(listed?.jobs) ? listed.jobs : []
|
|
811
|
+
const lines = ["<jobs>", `space: ${space.label}`]
|
|
812
|
+
if (rows.length === 0) lines.push('(no jobs: make one from a template in the console, at ' + link + ")")
|
|
813
|
+
for (const job of rows) lines.push(describeJob(job))
|
|
814
|
+
lines.push("</jobs>")
|
|
815
|
+
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.')
|
|
816
|
+
return text(lines.join("\n"))
|
|
817
|
+
}
|
|
818
|
+
if (op === "get") {
|
|
819
|
+
answer = await records().call("jobs.get", { job_id: id }, space.where)
|
|
820
|
+
} else if (op === "runs" || op === "logs") {
|
|
821
|
+
const limit = Math.min(100, Math.max(1, Number.parseInt(spec.limit, 10) || REVIEW_LIMIT))
|
|
822
|
+
answer = await records().call(op === "runs" ? "jobs.runs" : "jobs.logs", { job_id: id, limit }, space.where)
|
|
823
|
+
} else if (op === "versions") {
|
|
824
|
+
if (!id) return text('versions needs the job id: {"action": "jobs", "job": {"op": "list"}} names it.')
|
|
825
|
+
answer = await records().call("jobs.versions", { job_id: id }, space.where)
|
|
826
|
+
} else if (op === "draft") {
|
|
827
|
+
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 } : {}) }
|
|
828
|
+
answer = await records().call("jobs.draft", body, space.where)
|
|
829
|
+
} else if (op === "run_now") {
|
|
830
|
+
answer = await records().call("jobs.run", { job_id: id }, space.where)
|
|
831
|
+
} else if (op === "resume" || op === "archive") {
|
|
832
|
+
answer = await records().call(`jobs.${op}`, { job_id: id, expected_digest: state.job.state_digest }, space.where)
|
|
833
|
+
} else {
|
|
834
|
+
answer = await records().call(`jobs.${op}`, { job_id: id }, space.where)
|
|
835
|
+
}
|
|
836
|
+
} catch (error) {
|
|
837
|
+
log.warn(`spaces jobs ${op} failed`, error)
|
|
838
|
+
return fail(recordsFailure(error))
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (op === "get") {
|
|
842
|
+
const job = answer?.job
|
|
843
|
+
if (!job) return text("no job was found")
|
|
844
|
+
const lines = ["<job>", describeJob(job)]
|
|
845
|
+
if (answer.draft) {
|
|
846
|
+
lines.push(`draft: v${answer.draft.version}, made by ${oneLine(answer.draft.origin, 20)} against v${answer.draft.base}. What changed:`)
|
|
847
|
+
lines.push(...describeDiff(answer.draft.diff))
|
|
848
|
+
}
|
|
849
|
+
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)}`)
|
|
850
|
+
if (answer.request) lines.push(`request: waiting for the person's host to report the account (${oneLine(answer.request.state, 20)})`)
|
|
851
|
+
if (Array.isArray(answer.runs) && answer.runs.length) {
|
|
852
|
+
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)}` : ""}`))
|
|
853
|
+
}
|
|
854
|
+
lines.push("</job>")
|
|
855
|
+
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.`)
|
|
856
|
+
return text(lines.join("\n"))
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (op === "runs") {
|
|
860
|
+
const rows = Array.isArray(answer?.runs) ? answer.runs : []
|
|
861
|
+
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>"]
|
|
862
|
+
return text(lines.join("\n"))
|
|
863
|
+
}
|
|
864
|
+
if (op === "logs") {
|
|
865
|
+
const rows = Array.isArray(answer?.logs) ? answer.logs : []
|
|
866
|
+
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>"]
|
|
867
|
+
return text(lines.join("\n"))
|
|
868
|
+
}
|
|
869
|
+
if (op === "versions") {
|
|
870
|
+
const rows = Array.isArray(answer?.versions) ? answer.versions : []
|
|
871
|
+
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>"]
|
|
872
|
+
return text(lines.join("\n"))
|
|
873
|
+
}
|
|
874
|
+
if (op === "draft") {
|
|
875
|
+
const job = answer?.job
|
|
876
|
+
if (!job) return text("the draft was not stored")
|
|
877
|
+
const lines = [`drafted v${answer.draft?.version ?? "?"} of ${oneLine(job.id, 40)} (${JOB_STATUS[job.status] ?? oneLine(job.status, 20)}). What changed:`]
|
|
878
|
+
lines.push(...describeDiff(answer.draft?.diff))
|
|
879
|
+
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.`)
|
|
880
|
+
return text(lines.join("\n"))
|
|
881
|
+
}
|
|
882
|
+
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.`)
|
|
883
|
+
const job = answer?.job
|
|
884
|
+
if (!job) return text(`${op}: done.`)
|
|
885
|
+
return text(`${op}: ${oneLine(job.id, 40)} is ${JOB_STATUS[job.status] ?? oneLine(job.status, 20)}.`)
|
|
886
|
+
}
|
|
887
|
+
|
|
542
888
|
/** What Memory holds about the person: the views' `profile.read`, as text. Personal space only; read-only. */
|
|
543
889
|
async function profile(context) {
|
|
544
890
|
const resolved = await toolkit.resolvePrivateSpace({}, context)
|
|
@@ -566,7 +912,12 @@ export function createSpacesActions(toolkit) {
|
|
|
566
912
|
if (action === "access") return await access(input, context)
|
|
567
913
|
if (action === "health") return await health(input, context)
|
|
568
914
|
if (action === "sources") return await sources(input, context)
|
|
915
|
+
if (action === "jobs") return await jobs(input, context)
|
|
569
916
|
if (action === "profile") return await profile(context)
|
|
917
|
+
if (SPACE_LIFECYCLE_ACTIONS.includes(action)) {
|
|
918
|
+
if (!control) return noControl(`${action} a space`)
|
|
919
|
+
return await lifecycle[action](input, context)
|
|
920
|
+
}
|
|
570
921
|
return await review(input, context)
|
|
571
922
|
} catch (error) {
|
|
572
923
|
log.warn(`spaces ${action} failed`, error)
|
|
@@ -574,5 +925,5 @@ export function createSpacesActions(toolkit) {
|
|
|
574
925
|
}
|
|
575
926
|
}
|
|
576
927
|
|
|
577
|
-
return { run, profile, current, list, members, access, health, sources, review }
|
|
928
|
+
return { run, profile, current, list, members, access, health, sources, jobs, review }
|
|
578
929
|
}
|
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
|
}
|