memorix 1.2.1 → 1.2.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 +16 -0
- package/README.md +14 -2
- package/README.zh-CN.md +14 -2
- package/TEAM.md +86 -86
- package/dist/cli/index.js +15407 -13779
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +1321 -529
- package/dist/index.js.map +1 -1
- package/dist/maintenance-runner.d.ts +1 -1
- package/dist/maintenance-runner.js +8458 -8087
- package/dist/maintenance-runner.js.map +1 -1
- package/dist/memcode-runtime/CHANGELOG.md +16 -0
- package/dist/sdk.d.ts +7 -2
- package/dist/sdk.js +1349 -535
- package/dist/sdk.js.map +1 -1
- package/dist/types.d.ts +49 -1
- package/dist/types.js.map +1 -1
- package/docs/1.2.2-MEMORY-CONTROL-PLANE.md +434 -0
- package/docs/AGENT_OPERATOR_PLAYBOOK.md +4 -0
- package/docs/API_REFERENCE.md +24 -4
- package/docs/DESIGN_DECISIONS.md +357 -357
- package/docs/README.md +1 -1
- package/docs/dev-log/progress.txt +91 -11
- package/package.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/src/audit/index.ts +156 -156
- package/src/cli/command-guide.ts +192 -0
- package/src/cli/commands/audit-list.ts +89 -89
- package/src/cli/commands/audit.ts +9 -4
- package/src/cli/commands/background.ts +659 -659
- package/src/cli/commands/cleanup.ts +5 -1
- package/src/cli/commands/codegraph.ts +15 -5
- package/src/cli/commands/context.ts +3 -2
- package/src/cli/commands/doctor.ts +4 -2
- package/src/cli/commands/explain.ts +9 -3
- package/src/cli/commands/formation.ts +48 -48
- package/src/cli/commands/git-hook-install.ts +111 -111
- package/src/cli/commands/handoff.ts +75 -61
- package/src/cli/commands/hooks-status.ts +63 -63
- package/src/cli/commands/identity.ts +116 -0
- package/src/cli/commands/ingest-commit.ts +153 -153
- package/src/cli/commands/ingest-image.ts +71 -69
- package/src/cli/commands/ingest-log.ts +180 -180
- package/src/cli/commands/ingest.ts +44 -44
- package/src/cli/commands/integrate-shared.ts +15 -15
- package/src/cli/commands/lock.ts +93 -92
- package/src/cli/commands/memory.ts +58 -21
- package/src/cli/commands/message.ts +123 -118
- package/src/cli/commands/operator-shared.ts +98 -3
- package/src/cli/commands/poll.ts +74 -64
- package/src/cli/commands/purge-all-memory.ts +85 -85
- package/src/cli/commands/purge-project-memory.ts +83 -83
- package/src/cli/commands/reasoning.ts +135 -121
- package/src/cli/commands/retention.ts +9 -4
- package/src/cli/commands/serve-http.ts +8 -2
- package/src/cli/commands/serve-shared.ts +118 -118
- package/src/cli/commands/session.ts +29 -3
- package/src/cli/commands/skills.ts +124 -119
- package/src/cli/commands/status.ts +4 -3
- package/src/cli/commands/task.ts +193 -184
- package/src/cli/commands/team.ts +14 -10
- package/src/cli/commands/transfer.ts +108 -55
- package/src/cli/commands/uninstall-project-artifacts.ts +85 -85
- package/src/cli/identity.ts +89 -0
- package/src/cli/index.ts +96 -19
- package/src/cli/invocation.ts +115 -0
- package/src/cli/tui/ChatView.tsx +234 -234
- package/src/cli/tui/CommandBar.tsx +312 -312
- package/src/cli/tui/ContextRail.tsx +118 -118
- package/src/cli/tui/HeaderBar.tsx +72 -72
- package/src/cli/tui/LogoBanner.tsx +51 -51
- package/src/cli/tui/Sidebar.tsx +179 -179
- package/src/cli/tui/chat-service.ts +41 -18
- package/src/cli/tui/data.ts +23 -44
- package/src/cli/tui/index.ts +41 -41
- package/src/cli/tui/markdown-render.tsx +371 -371
- package/src/cli/tui/operator-context.ts +60 -0
- package/src/cli/tui/use-mouse.ts +157 -157
- package/src/cli/tui/useNavigation.ts +56 -56
- package/src/cli/tui/views/MemoryView.tsx +10 -8
- package/src/cli/update-checker.ts +211 -211
- package/src/cli/version.ts +7 -7
- package/src/cli/workbench.ts +1 -1
- package/src/codegraph/auto-context.ts +31 -2
- package/src/codegraph/context-pack.ts +1 -0
- package/src/codegraph/project-context.ts +2 -0
- package/src/compact/engine.ts +26 -10
- package/src/compact/index-format.ts +25 -2
- package/src/compact/token-budget.ts +74 -74
- package/src/dashboard/project-classification.ts +64 -64
- package/src/dashboard/server.ts +46 -9
- package/src/embedding/fastembed-provider.ts +142 -142
- package/src/embedding/transformers-provider.ts +111 -111
- package/src/git/extractor.ts +209 -209
- package/src/git/hooks-path.ts +85 -85
- package/src/hooks/admission.ts +117 -0
- package/src/hooks/handler.ts +98 -91
- package/src/hooks/pattern-detector.ts +173 -173
- package/src/hooks/significance-filter.ts +250 -250
- package/src/knowledge/context-assembly.ts +97 -0
- package/src/knowledge/workset.ts +179 -10
- package/src/llm/memory-manager.ts +328 -328
- package/src/llm/provider.ts +885 -885
- package/src/llm/quality.ts +248 -248
- package/src/memory/admission.ts +57 -0
- package/src/memory/attribution-guard.ts +249 -249
- package/src/memory/consolidation.ts +13 -2
- package/src/memory/disclosure-policy.ts +140 -135
- package/src/memory/entity-extractor.ts +197 -197
- package/src/memory/export-import.ts +11 -3
- package/src/memory/formation/evaluate.ts +217 -217
- package/src/memory/formation/extract.ts +361 -361
- package/src/memory/formation/index.ts +417 -417
- package/src/memory/formation/resolve.ts +344 -344
- package/src/memory/formation/types.ts +315 -315
- package/src/memory/freshness.ts +122 -122
- package/src/memory/graph-context.ts +8 -2
- package/src/memory/graph.ts +197 -197
- package/src/memory/observations.ts +162 -4
- package/src/memory/quality-audit.ts +2 -0
- package/src/memory/refs.ts +94 -94
- package/src/memory/retention.ts +22 -2
- package/src/memory/secret-filter.ts +79 -79
- package/src/memory/session.ts +5 -2
- package/src/memory/visibility.ts +80 -0
- package/src/multimodal/image-loader.ts +143 -143
- package/src/orchestrate/adapters/claude-stream.ts +192 -192
- package/src/orchestrate/adapters/claude.ts +111 -111
- package/src/orchestrate/adapters/codex-stream.ts +134 -134
- package/src/orchestrate/adapters/codex.ts +41 -41
- package/src/orchestrate/adapters/gemini-stream.ts +166 -166
- package/src/orchestrate/adapters/gemini.ts +42 -42
- package/src/orchestrate/adapters/index.ts +73 -73
- package/src/orchestrate/adapters/opencode-stream.ts +143 -143
- package/src/orchestrate/adapters/opencode.ts +47 -47
- package/src/orchestrate/adapters/spawn-helper.ts +286 -286
- package/src/orchestrate/adapters/types.ts +77 -77
- package/src/orchestrate/capability-router.ts +284 -284
- package/src/orchestrate/context-compact.ts +188 -188
- package/src/orchestrate/cost-tracker.ts +219 -219
- package/src/orchestrate/error-recovery.ts +191 -191
- package/src/orchestrate/evidence.ts +140 -140
- package/src/orchestrate/ledger.ts +110 -110
- package/src/orchestrate/memorix-bridge.ts +378 -340
- package/src/orchestrate/output-budget.ts +80 -80
- package/src/orchestrate/permission.ts +152 -152
- package/src/orchestrate/pipeline-trace.ts +131 -131
- package/src/orchestrate/prompt-builder.ts +155 -155
- package/src/orchestrate/ring-buffer.ts +37 -37
- package/src/orchestrate/task-graph.ts +389 -389
- package/src/orchestrate/worktree.ts +232 -232
- package/src/project/aliases.ts +374 -374
- package/src/project/detector.ts +268 -268
- package/src/rules/adapters/claude-code.ts +99 -99
- package/src/rules/adapters/codex.ts +97 -97
- package/src/rules/adapters/copilot.ts +124 -124
- package/src/rules/adapters/cursor.ts +114 -114
- package/src/rules/adapters/kiro.ts +126 -126
- package/src/rules/adapters/trae.ts +56 -56
- package/src/rules/adapters/windsurf.ts +83 -83
- package/src/rules/syncer.ts +235 -235
- package/src/runtime/control-plane-maintenance.ts +1 -0
- package/src/runtime/isolated-maintenance.ts +1 -0
- package/src/runtime/lifecycle.ts +18 -0
- package/src/runtime/maintenance-jobs.ts +1 -0
- package/src/runtime/maintenance-runner.ts +2 -0
- package/src/runtime/project-maintenance.ts +89 -0
- package/src/sdk.ts +334 -304
- package/src/search/intent-detector.ts +289 -289
- package/src/search/query-expansion.ts +52 -52
- package/src/server/formation-timeout.ts +27 -27
- package/src/server.ts +260 -81
- package/src/skills/mini-skills.ts +386 -386
- package/src/store/chat-store.ts +119 -119
- package/src/store/graph-store.ts +249 -249
- package/src/store/mini-skill-store.ts +349 -349
- package/src/store/orama-store.ts +61 -6
- package/src/store/persistence-json.ts +212 -212
- package/src/store/persistence.ts +291 -291
- package/src/store/project-affinity.ts +195 -195
- package/src/store/sqlite-db.ts +23 -1
- package/src/store/sqlite-store.ts +12 -2
- package/src/team/event-bus.ts +76 -76
- package/src/team/file-locks.ts +173 -173
- package/src/team/handoff.ts +168 -161
- package/src/team/messages.ts +203 -203
- package/src/team/poll.ts +132 -132
- package/src/team/tasks.ts +211 -211
- package/src/types.ts +51 -0
- package/src/wiki/generator.ts +2 -0
- package/src/workspace/mcp-adapters/codex.ts +191 -191
- package/src/workspace/mcp-adapters/copilot.ts +105 -105
- package/src/workspace/mcp-adapters/cursor.ts +53 -53
- package/src/workspace/mcp-adapters/kiro.ts +64 -64
- package/src/workspace/mcp-adapters/opencode.ts +123 -123
- package/src/workspace/mcp-adapters/trae.ts +134 -134
- package/src/workspace/mcp-adapters/windsurf.ts +91 -91
- package/src/workspace/sanitizer.ts +60 -60
- package/src/workspace/workflow-sync.ts +131 -131
|
@@ -1,121 +1,126 @@
|
|
|
1
|
-
import { defineCommand } from 'citty';
|
|
2
|
-
import { emitError, emitResult, getCliProjectContext, shortId } from './operator-shared.js';
|
|
3
|
-
|
|
4
|
-
export default defineCommand({
|
|
5
|
-
meta: {
|
|
6
|
-
name: 'message',
|
|
7
|
-
description: 'Send, broadcast, and read team messages from the CLI',
|
|
8
|
-
},
|
|
9
|
-
args: {
|
|
10
|
-
from: { type: 'string', description: 'Sender agent ID' },
|
|
11
|
-
to: { type: 'string', description: 'Recipient agent ID' },
|
|
12
|
-
type: { type: 'string', description: 'Message type (request, response, info, handoff, etc.)' },
|
|
13
|
-
content: { type: 'string', description: 'Message content' },
|
|
14
|
-
agentId: { type: 'string', description: 'Agent ID for inbox reads' },
|
|
15
|
-
markRead: { type: 'boolean', description: 'Mark inbox messages as read after listing them' },
|
|
16
|
-
toRole: { type: 'string', description: 'Optional role target for the message' },
|
|
17
|
-
handoffStatus: { type: 'string', description: 'Optional handoff status when type=handoff' },
|
|
18
|
-
json: { type: 'boolean', description: 'Emit machine-readable JSON output' },
|
|
19
|
-
},
|
|
20
|
-
run: async ({ args }) => {
|
|
21
|
-
const action = (args._ as string[])?.[0] || '';
|
|
22
|
-
const asJson = !!args.json;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const { project, teamStore } = await getCliProjectContext();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { emitError, emitResult, getCliProjectContext, resolveCliActorId, shortId } from './operator-shared.js';
|
|
3
|
+
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: 'message',
|
|
7
|
+
description: 'Send, broadcast, and read team messages from the CLI',
|
|
8
|
+
},
|
|
9
|
+
args: {
|
|
10
|
+
from: { type: 'string', description: 'Sender agent ID' },
|
|
11
|
+
to: { type: 'string', description: 'Recipient agent ID' },
|
|
12
|
+
type: { type: 'string', description: 'Message type (request, response, info, handoff, etc.)' },
|
|
13
|
+
content: { type: 'string', description: 'Message content' },
|
|
14
|
+
agentId: { type: 'string', description: 'Agent ID for inbox reads' },
|
|
15
|
+
markRead: { type: 'boolean', description: 'Mark inbox messages as read after listing them' },
|
|
16
|
+
toRole: { type: 'string', description: 'Optional role target for the message' },
|
|
17
|
+
handoffStatus: { type: 'string', description: 'Optional handoff status when type=handoff' },
|
|
18
|
+
json: { type: 'boolean', description: 'Emit machine-readable JSON output' },
|
|
19
|
+
},
|
|
20
|
+
run: async ({ args }) => {
|
|
21
|
+
const action = (args._ as string[])?.[0] || '';
|
|
22
|
+
const asJson = !!args.json;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const { project, teamStore, identity } = await getCliProjectContext();
|
|
26
|
+
const senderAgentId = resolveCliActorId(args.from, identity, 'from');
|
|
27
|
+
const inboxAgentId = resolveCliActorId(
|
|
28
|
+
(args.agentId as string | undefined) ?? (args.from as string | undefined),
|
|
29
|
+
identity,
|
|
30
|
+
'agentId',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
switch (action) {
|
|
34
|
+
case 'send': {
|
|
35
|
+
if (!senderAgentId || !args.type || !args.content) {
|
|
36
|
+
emitError('type, content, and an active CLI identity or from agentId are required for "memorix message send"', asJson);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!args.to && !args.toRole) {
|
|
40
|
+
emitError('Either --to or --toRole is required for "memorix message send"', asJson);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const message = teamStore.sendMessage({
|
|
44
|
+
projectId: project.id,
|
|
45
|
+
senderAgentId,
|
|
46
|
+
recipientAgentId: (args.to as string | undefined) ?? null,
|
|
47
|
+
type: args.type as string,
|
|
48
|
+
content: args.content as string,
|
|
49
|
+
toRole: (args.toRole as string | undefined) ?? null,
|
|
50
|
+
handoffStatus:
|
|
51
|
+
(args.handoffStatus as string | undefined) ??
|
|
52
|
+
((args.type as string) === 'handoff' ? 'open' : null),
|
|
53
|
+
});
|
|
54
|
+
if ('error' in message) {
|
|
55
|
+
emitError(message.error, asJson);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
emitResult(
|
|
59
|
+
{ project, message },
|
|
60
|
+
`Message sent: ${shortId(message.id)} to ${args.to ? shortId(args.to as string) : `role ${args.toRole}`}`,
|
|
61
|
+
asJson,
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
case 'broadcast': {
|
|
67
|
+
if (!senderAgentId || !args.type || !args.content) {
|
|
68
|
+
emitError('type, content, and an active CLI identity or from agentId are required for "memorix message broadcast"', asJson);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const message = teamStore.sendMessage({
|
|
72
|
+
projectId: project.id,
|
|
73
|
+
senderAgentId,
|
|
74
|
+
recipientAgentId: null,
|
|
75
|
+
type: args.type as string,
|
|
76
|
+
content: args.content as string,
|
|
77
|
+
});
|
|
78
|
+
if ('error' in message) {
|
|
79
|
+
emitError(message.error, asJson);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
emitResult(
|
|
83
|
+
{ project, message },
|
|
84
|
+
`Broadcast sent: ${shortId(message.id)}`,
|
|
85
|
+
asJson,
|
|
86
|
+
);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
case 'inbox': {
|
|
91
|
+
if (!inboxAgentId) {
|
|
92
|
+
emitError('an active CLI identity or agentId is required for "memorix message inbox"', asJson);
|
|
31
93
|
return;
|
|
32
94
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const message = teamStore.sendMessage({
|
|
38
|
-
projectId: project.id,
|
|
39
|
-
senderAgentId: args.from as string,
|
|
40
|
-
recipientAgentId: (args.to as string | undefined) ?? null,
|
|
41
|
-
type: args.type as string,
|
|
42
|
-
content: args.content as string,
|
|
43
|
-
toRole: (args.toRole as string | undefined) ?? null,
|
|
44
|
-
handoffStatus:
|
|
45
|
-
(args.handoffStatus as string | undefined) ??
|
|
46
|
-
((args.type as string) === 'handoff' ? 'open' : null),
|
|
47
|
-
});
|
|
48
|
-
if ('error' in message) {
|
|
49
|
-
emitError(message.error, asJson);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
emitResult(
|
|
53
|
-
{ project, message },
|
|
54
|
-
`Message sent: ${shortId(message.id)} to ${args.to ? shortId(args.to as string) : `role ${args.toRole}`}`,
|
|
55
|
-
asJson,
|
|
56
|
-
);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
case 'broadcast': {
|
|
61
|
-
if (!args.from || !args.type || !args.content) {
|
|
62
|
-
emitError('from, type, and content are required for "memorix message broadcast"', asJson);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const message = teamStore.sendMessage({
|
|
66
|
-
projectId: project.id,
|
|
67
|
-
senderAgentId: args.from as string,
|
|
68
|
-
recipientAgentId: null,
|
|
69
|
-
type: args.type as string,
|
|
70
|
-
content: args.content as string,
|
|
71
|
-
});
|
|
72
|
-
if ('error' in message) {
|
|
73
|
-
emitError(message.error, asJson);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
emitResult(
|
|
77
|
-
{ project, message },
|
|
78
|
-
`Broadcast sent: ${shortId(message.id)}`,
|
|
79
|
-
asJson,
|
|
80
|
-
);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
case 'inbox': {
|
|
85
|
-
const agentId = (args.agentId as string | undefined) || (args.from as string | undefined);
|
|
86
|
-
if (!agentId) {
|
|
87
|
-
emitError('agentId is required for "memorix message inbox"', asJson);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const messages = teamStore.getInbox(project.id, agentId);
|
|
91
|
-
const unreadCount = teamStore.getUnreadCount(project.id, agentId);
|
|
95
|
+
const messages = teamStore.getInbox(project.id, inboxAgentId);
|
|
96
|
+
const unreadCount = teamStore.getUnreadCount(project.id, inboxAgentId);
|
|
92
97
|
if (args.markRead) {
|
|
93
|
-
teamStore.markAllRead(project.id,
|
|
94
|
-
}
|
|
95
|
-
emitResult(
|
|
96
|
-
{ project, unreadCount, messages },
|
|
97
|
-
messages.length === 0
|
|
98
|
-
? 'Inbox empty.'
|
|
99
|
-
: [`Inbox: ${unreadCount} unread / ${messages.length} total`, '', ...messages.map((message) => {
|
|
100
|
-
const sender = teamStore.getAgent(message.sender_agent_id);
|
|
101
|
-
return `- ${message.read_at ? ' ' : '*'} [${message.type}] from ${sender?.name ?? shortId(message.sender_agent_id)}: ${message.content}`;
|
|
102
|
-
})].join('\n'),
|
|
103
|
-
asJson,
|
|
104
|
-
);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
default:
|
|
109
|
-
console.log('Memorix Message Commands');
|
|
110
|
-
console.log('');
|
|
111
|
-
console.log('Usage:');
|
|
112
|
-
console.log(' memorix message send --from <agentId> --to <agentId> --type info --content "..."');
|
|
113
|
-
console.log(' memorix message send --from <agentId> --toRole reviewer --type handoff --content "..."');
|
|
114
|
-
console.log(' memorix message broadcast --from <agentId> --type announcement --content "..."');
|
|
115
|
-
console.log(' memorix message inbox --agentId <id> [--markRead]');
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
emitError(error instanceof Error ? error.message : String(error), asJson);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
});
|
|
98
|
+
teamStore.markAllRead(project.id, inboxAgentId);
|
|
99
|
+
}
|
|
100
|
+
emitResult(
|
|
101
|
+
{ project, unreadCount, messages },
|
|
102
|
+
messages.length === 0
|
|
103
|
+
? 'Inbox empty.'
|
|
104
|
+
: [`Inbox: ${unreadCount} unread / ${messages.length} total`, '', ...messages.map((message) => {
|
|
105
|
+
const sender = teamStore.getAgent(message.sender_agent_id);
|
|
106
|
+
return `- ${message.read_at ? ' ' : '*'} [${message.type}] from ${sender?.name ?? shortId(message.sender_agent_id)}: ${message.content}`;
|
|
107
|
+
})].join('\n'),
|
|
108
|
+
asJson,
|
|
109
|
+
);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
default:
|
|
114
|
+
console.log('Memorix Message Commands');
|
|
115
|
+
console.log('');
|
|
116
|
+
console.log('Usage:');
|
|
117
|
+
console.log(' memorix message send --from <agentId> --to <agentId> --type info --content "..."');
|
|
118
|
+
console.log(' memorix message send --from <agentId> --toRole reviewer --type handoff --content "..."');
|
|
119
|
+
console.log(' memorix message broadcast --from <agentId> --type announcement --content "..."');
|
|
120
|
+
console.log(' memorix message inbox --agentId <id> [--markRead]');
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
emitError(error instanceof Error ? error.message : String(error), asJson);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
});
|
|
@@ -3,16 +3,33 @@ import { getProjectDataDir } from '../../store/persistence.js';
|
|
|
3
3
|
import { initObservations, prepareSearchIndex } from '../../memory/observations.js';
|
|
4
4
|
import { initSessionStore } from '../../store/session-store.js';
|
|
5
5
|
import { initTeamStore, type TeamStore } from '../../team/team-store.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
ProjectInfo,
|
|
8
|
+
ObservationReader,
|
|
9
|
+
ObservationStatus,
|
|
10
|
+
ObservationType,
|
|
11
|
+
ObservationVisibility,
|
|
12
|
+
} from '../../types.js';
|
|
13
|
+
import { getCliInvocation } from '../invocation.js';
|
|
14
|
+
import { resolveCliIdentity, type CliIdentity } from '../identity.js';
|
|
7
15
|
|
|
8
16
|
export interface CliProjectContext {
|
|
9
17
|
project: ProjectInfo;
|
|
10
18
|
dataDir: string;
|
|
11
19
|
teamStore: TeamStore;
|
|
20
|
+
reader: ObservationReader;
|
|
21
|
+
identity: CliIdentity | null;
|
|
22
|
+
identityWarning?: string;
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
export async function getCliProjectContext(options?: { searchIndex?: boolean; projectRoot?: string }): Promise<CliProjectContext> {
|
|
15
|
-
const
|
|
26
|
+
const invocation = getCliInvocation();
|
|
27
|
+
const detection = detectProjectWithDiagnostics(
|
|
28
|
+
options?.projectRoot
|
|
29
|
+
?? invocation.projectRoot
|
|
30
|
+
?? process.env.MEMORIX_PROJECT_ROOT
|
|
31
|
+
?? process.cwd(),
|
|
32
|
+
);
|
|
16
33
|
if (!detection.project) {
|
|
17
34
|
const detail = detection.failure?.detail ?? 'No git repository found in the current directory.';
|
|
18
35
|
throw new Error(detail);
|
|
@@ -20,6 +37,16 @@ export async function getCliProjectContext(options?: { searchIndex?: boolean; pr
|
|
|
20
37
|
|
|
21
38
|
const project = detection.project;
|
|
22
39
|
const dataDir = await getProjectDataDir(project.id);
|
|
40
|
+
try {
|
|
41
|
+
const { MaintenanceTargetStore } = await import('../../runtime/maintenance-targets.js');
|
|
42
|
+
new MaintenanceTargetStore(dataDir).register({
|
|
43
|
+
projectId: project.id,
|
|
44
|
+
projectRoot: project.rootPath,
|
|
45
|
+
dataDir,
|
|
46
|
+
});
|
|
47
|
+
} catch {
|
|
48
|
+
// CLI reads remain available even if optional background maintenance metadata fails.
|
|
49
|
+
}
|
|
23
50
|
await initObservations(dataDir);
|
|
24
51
|
await initSessionStore(dataDir);
|
|
25
52
|
const teamStore = await initTeamStore(dataDir);
|
|
@@ -28,7 +55,21 @@ export async function getCliProjectContext(options?: { searchIndex?: boolean; pr
|
|
|
28
55
|
await prepareSearchIndex();
|
|
29
56
|
}
|
|
30
57
|
|
|
31
|
-
|
|
58
|
+
const identity = await resolveCliIdentity({
|
|
59
|
+
project,
|
|
60
|
+
dataDir,
|
|
61
|
+
teamStore,
|
|
62
|
+
explicitActorId: invocation.actorId,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
project,
|
|
67
|
+
dataDir,
|
|
68
|
+
teamStore,
|
|
69
|
+
reader: identity.reader,
|
|
70
|
+
identity: identity.identity,
|
|
71
|
+
...(identity.warning ? { identityWarning: identity.warning } : {}),
|
|
72
|
+
};
|
|
32
73
|
}
|
|
33
74
|
|
|
34
75
|
export function emitResult<T>(data: T, text: string, asJson?: boolean): void {
|
|
@@ -108,3 +149,57 @@ export function coerceObservationStatus(input?: string): ObservationStatus {
|
|
|
108
149
|
}
|
|
109
150
|
return normalized;
|
|
110
151
|
}
|
|
152
|
+
|
|
153
|
+
export function coerceObservationVisibility(input?: string): ObservationVisibility {
|
|
154
|
+
const normalized = (input ?? 'project').trim().toLowerCase();
|
|
155
|
+
if (normalized === 'personal' || normalized === 'project' || normalized === 'team') {
|
|
156
|
+
return normalized;
|
|
157
|
+
}
|
|
158
|
+
throw new Error('visibility must be personal, project, or team');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Project scope is deliberately the default. Private and team-scoped records
|
|
163
|
+
* require an identity selected by the operator, so a plain shell does not
|
|
164
|
+
* accidentally gain access to another agent's work.
|
|
165
|
+
*/
|
|
166
|
+
export function resolveCliWriteScope(
|
|
167
|
+
context: Pick<CliProjectContext, 'identity' | 'reader'>,
|
|
168
|
+
visibilityInput?: string,
|
|
169
|
+
): {
|
|
170
|
+
visibility: ObservationVisibility;
|
|
171
|
+
createdByAgentId?: string;
|
|
172
|
+
visibilityReader: ObservationReader;
|
|
173
|
+
} {
|
|
174
|
+
const visibility = coerceObservationVisibility(visibilityInput);
|
|
175
|
+
if (visibility !== 'project' && !context.identity) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`visibility=${visibility} requires an active CLI identity. Run "memorix identity join --agent-type <agent>" or "memorix identity use --agent-id <id>" first.`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (visibility === 'team' && context.reader.isTeamMember !== true) {
|
|
181
|
+
throw new Error('team visibility requires an active coordination identity for this project.');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
visibility,
|
|
186
|
+
...(context.identity ? { createdByAgentId: context.identity.agentId } : {}),
|
|
187
|
+
visibilityReader: context.reader,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Coordination commands can use the current CLI identity implicitly, while
|
|
193
|
+
* retaining explicit IDs for scripts and backwards-compatible invocations.
|
|
194
|
+
*/
|
|
195
|
+
export function resolveCliActorId(
|
|
196
|
+
explicitValue: unknown,
|
|
197
|
+
identity: CliIdentity | null,
|
|
198
|
+
field = 'agentId',
|
|
199
|
+
): string | undefined {
|
|
200
|
+
const explicit = typeof explicitValue === 'string' ? explicitValue.trim() : '';
|
|
201
|
+
if (identity && explicit && explicit !== identity.agentId) {
|
|
202
|
+
throw new Error(`${field} does not match the active CLI identity. Use "memorix identity clear" before acting as a different agent.`);
|
|
203
|
+
}
|
|
204
|
+
return explicit || identity?.agentId;
|
|
205
|
+
}
|
package/src/cli/commands/poll.ts
CHANGED
|
@@ -1,70 +1,80 @@
|
|
|
1
|
-
import { defineCommand } from 'citty';
|
|
2
|
-
import { computePoll, computeWatermark } from '../../team/poll.js';
|
|
3
|
-
import { getObservationStore } from '../../store/obs-store.js';
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { computePoll, computeWatermark } from '../../team/poll.js';
|
|
3
|
+
import { getObservationStore } from '../../store/obs-store.js';
|
|
4
4
|
import { getAllObservations } from '../../memory/observations.js';
|
|
5
5
|
import { withFreshIndex } from '../../memory/freshness.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
import { filterReadableObservations } from '../../memory/visibility.js';
|
|
7
|
+
import { emitError, emitResult, getCliProjectContext, resolveCliActorId, shortId } from './operator-shared.js';
|
|
8
|
+
|
|
9
|
+
export default defineCommand({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'poll',
|
|
12
|
+
description: 'Get a full project coordination snapshot for an agent',
|
|
13
|
+
},
|
|
14
|
+
args: {
|
|
15
|
+
agentId: { type: 'string', description: 'Agent ID for personalized situational awareness' },
|
|
16
|
+
markInboxRead: { type: 'boolean', description: 'Mark all inbox messages as read after returning them' },
|
|
17
|
+
json: { type: 'boolean', description: 'Emit machine-readable JSON output' },
|
|
18
|
+
},
|
|
19
|
+
run: async ({ args }) => {
|
|
20
|
+
const asJson = !!args.json;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const { project, teamStore, identity, reader: activeReader } = await getCliProjectContext();
|
|
24
|
+
const agentId = resolveCliActorId(args.agentId, identity);
|
|
25
|
+
let reader = activeReader;
|
|
26
|
+
|
|
27
|
+
let watermark = computeWatermark(0, 0, 0);
|
|
28
|
+
if (agentId) {
|
|
29
|
+
const agent = teamStore.getAgent(agentId);
|
|
30
|
+
if (!agent || agent.project_id !== project.id) {
|
|
29
31
|
emitError(`Unknown agent "${agentId}"`, asJson);
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
reader = {
|
|
35
|
+
projectId: project.id,
|
|
36
|
+
agentId,
|
|
37
|
+
isTeamMember: agent.status === 'active',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const lastSeen = agent.last_seen_obs_generation;
|
|
41
|
+
const currentGen = getObservationStore().getGeneration();
|
|
42
|
+
const projectObs = await withFreshIndex(() =>
|
|
43
|
+
filterReadableObservations(
|
|
44
|
+
getAllObservations().filter(
|
|
45
|
+
(obs) => obs.projectId === project.id && (obs.writeGeneration ?? 0) > lastSeen,
|
|
46
|
+
),
|
|
47
|
+
reader,
|
|
38
48
|
),
|
|
39
|
-
);
|
|
40
|
-
watermark = computeWatermark(lastSeen, currentGen, projectObs.length);
|
|
41
|
-
teamStore.updateWatermark(agentId, currentGen);
|
|
42
|
-
teamStore.heartbeat(agentId);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const poll = computePoll(teamStore, project.id, agentId ?? null, watermark);
|
|
46
|
-
if (args.markInboxRead && agentId) {
|
|
47
|
-
teamStore.markAllRead(project.id, agentId);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const text = [
|
|
51
|
-
poll.agent ? `You: ${shortId(poll.agent.agentId)} (${poll.agent.status})` : 'Project-level overview',
|
|
52
|
-
poll.watermark.newObservationCount > 0
|
|
53
|
-
? `${poll.watermark.newObservationCount} new observation(s)`
|
|
54
|
-
: 'No unseen observations',
|
|
55
|
-
poll.inbox.unreadCount > 0 ? `${poll.inbox.unreadCount} unread message(s)` : 'Inbox clear',
|
|
56
|
-
poll.tasks.myInProgress.length > 0
|
|
57
|
-
? `${poll.tasks.myInProgress.length} in-progress task(s)`
|
|
58
|
-
: 'No in-progress tasks',
|
|
59
|
-
poll.tasks.availableToClaim.length > 0
|
|
60
|
-
? `${poll.tasks.availableToClaim.length} task(s) available to claim`
|
|
61
|
-
: 'No claimable tasks',
|
|
62
|
-
`Team: ${poll.team.activeAgents.length} active / ${poll.team.totalAgents} total`,
|
|
63
|
-
].join('\n');
|
|
64
|
-
|
|
65
|
-
emitResult({ project, poll }, text, asJson);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
emitError(error instanceof Error ? error.message : String(error), asJson);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
});
|
|
49
|
+
);
|
|
50
|
+
watermark = computeWatermark(lastSeen, currentGen, projectObs.length);
|
|
51
|
+
teamStore.updateWatermark(agentId, currentGen);
|
|
52
|
+
teamStore.heartbeat(agentId);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const poll = computePoll(teamStore, project.id, agentId ?? null, watermark);
|
|
56
|
+
if (args.markInboxRead && agentId) {
|
|
57
|
+
teamStore.markAllRead(project.id, agentId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const text = [
|
|
61
|
+
poll.agent ? `You: ${shortId(poll.agent.agentId)} (${poll.agent.status})` : 'Project-level overview',
|
|
62
|
+
poll.watermark.newObservationCount > 0
|
|
63
|
+
? `${poll.watermark.newObservationCount} new observation(s)`
|
|
64
|
+
: 'No unseen observations',
|
|
65
|
+
poll.inbox.unreadCount > 0 ? `${poll.inbox.unreadCount} unread message(s)` : 'Inbox clear',
|
|
66
|
+
poll.tasks.myInProgress.length > 0
|
|
67
|
+
? `${poll.tasks.myInProgress.length} in-progress task(s)`
|
|
68
|
+
: 'No in-progress tasks',
|
|
69
|
+
poll.tasks.availableToClaim.length > 0
|
|
70
|
+
? `${poll.tasks.availableToClaim.length} task(s) available to claim`
|
|
71
|
+
: 'No claimable tasks',
|
|
72
|
+
`Team: ${poll.team.activeAgents.length} active / ${poll.team.totalAgents} total`,
|
|
73
|
+
].join('\n');
|
|
74
|
+
|
|
75
|
+
emitResult({ project, poll }, text, asJson);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
emitError(error instanceof Error ? error.message : String(error), asJson);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|