@jungjaehoon/mama-os 0.48.3 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent-loop.d.ts +6 -7
- package/dist/agent/agent-loop.d.ts.map +1 -1
- package/dist/agent/agent-loop.js +93 -79
- package/dist/agent/agent-loop.js.map +1 -1
- package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
- package/dist/agent/code-act/host-bridge.js +2 -10
- package/dist/agent/code-act/host-bridge.js.map +1 -1
- package/dist/agent/codex-home.d.ts.map +1 -1
- package/dist/agent/codex-home.js +3 -1
- package/dist/agent/codex-home.js.map +1 -1
- package/dist/agent/gateway-tool-executor.d.ts +0 -16
- package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
- package/dist/agent/gateway-tool-executor.js +0 -51
- package/dist/agent/gateway-tool-executor.js.map +1 -1
- package/dist/agent/gateway-tools.md +1 -2
- package/dist/agent/os-agent-capabilities.md +14 -34
- package/dist/agent/role-manager.d.ts.map +1 -1
- package/dist/agent/role-manager.js +6 -3
- package/dist/agent/role-manager.js.map +1 -1
- package/dist/agent/tool-registry.d.ts.map +1 -1
- package/dist/agent/tool-registry.js +2 -8
- package/dist/agent/tool-registry.js.map +1 -1
- package/dist/agent/types.d.ts +18 -6
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/api/graph-api-types.d.ts +0 -18
- package/dist/api/graph-api-types.d.ts.map +1 -1
- package/dist/api/graph-api.d.ts.map +1 -1
- package/dist/api/graph-api.js +9 -81
- package/dist/api/graph-api.js.map +1 -1
- package/dist/cli/commands/start.d.ts +7 -16
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +181 -188
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/config/types.d.ts.map +1 -1
- package/dist/cli/config/types.js +11 -4
- package/dist/cli/config/types.js.map +1 -1
- package/dist/cli/runtime/agent-loop-init.d.ts.map +1 -1
- package/dist/cli/runtime/agent-loop-init.js +28 -11
- package/dist/cli/runtime/agent-loop-init.js.map +1 -1
- package/dist/cli/runtime/api-routes-init.d.ts +0 -2
- package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-routes-init.js +9 -95
- package/dist/cli/runtime/api-routes-init.js.map +1 -1
- package/dist/cli/runtime/api-server-init.d.ts +2 -2
- package/dist/cli/runtime/api-server-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-server-init.js +2 -2
- package/dist/cli/runtime/api-server-init.js.map +1 -1
- package/dist/cli/runtime/scheduler-init.d.ts +3 -4
- package/dist/cli/runtime/scheduler-init.d.ts.map +1 -1
- package/dist/cli/runtime/scheduler-init.js +6 -16
- package/dist/cli/runtime/scheduler-init.js.map +1 -1
- package/dist/cli/runtime/shutdown.d.ts +0 -1
- package/dist/cli/runtime/shutdown.d.ts.map +1 -1
- package/dist/cli/runtime/shutdown.js +1 -1
- package/dist/cli/runtime/shutdown.js.map +1 -1
- package/dist/cli/runtime/types.d.ts +0 -5
- package/dist/cli/runtime/types.d.ts.map +1 -1
- package/dist/concurrency/lane-manager.d.ts +1 -1
- package/dist/concurrency/lane-manager.d.ts.map +1 -1
- package/dist/concurrency/lane-manager.js +4 -2
- package/dist/concurrency/lane-manager.js.map +1 -1
- package/dist/concurrency/types.d.ts +4 -0
- package/dist/concurrency/types.d.ts.map +1 -1
- package/dist/concurrency/types.js.map +1 -1
- package/dist/envelope/types.d.ts +1 -1
- package/dist/envelope/types.d.ts.map +1 -1
- package/dist/envelope/types.js.map +1 -1
- package/dist/gateways/message-router.d.ts +13 -71
- package/dist/gateways/message-router.d.ts.map +1 -1
- package/dist/gateways/message-router.js +99 -489
- package/dist/gateways/message-router.js.map +1 -1
- package/dist/gateways/session-store.d.ts +3 -23
- package/dist/gateways/session-store.d.ts.map +1 -1
- package/dist/gateways/session-store.js +2 -64
- package/dist/gateways/session-store.js.map +1 -1
- package/dist/gateways/telegram-report-context-store.d.ts +4 -66
- package/dist/gateways/telegram-report-context-store.d.ts.map +1 -1
- package/dist/gateways/telegram-report-context-store.js +11 -235
- package/dist/gateways/telegram-report-context-store.js.map +1 -1
- package/dist/gateways/turn-contract.d.ts +7 -3
- package/dist/gateways/turn-contract.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.d.ts +1 -12
- package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.js +6 -40
- package/dist/operator/operator-trigger-loop.js.map +1 -1
- package/dist/operator/owner-event-loop.d.ts +8 -7
- package/dist/operator/owner-event-loop.d.ts.map +1 -1
- package/dist/operator/owner-event-loop.js +7 -20
- package/dist/operator/owner-event-loop.js.map +1 -1
- package/dist/operator/owner-event-policy.d.ts.map +1 -1
- package/dist/operator/owner-event-policy.js +0 -2
- package/dist/operator/owner-event-policy.js.map +1 -1
- package/dist/operator/owner-event-prompt.d.ts +0 -2
- package/dist/operator/owner-event-prompt.d.ts.map +1 -1
- package/dist/operator/owner-event-prompt.js +1 -8
- package/dist/operator/owner-event-prompt.js.map +1 -1
- package/dist/operator/owner-runtime-journal.d.ts +21 -0
- package/dist/operator/owner-runtime-journal.d.ts.map +1 -0
- package/dist/operator/owner-runtime-journal.js +131 -0
- package/dist/operator/owner-runtime-journal.js.map +1 -0
- package/dist/operator/owner-runtime.d.ts +32 -0
- package/dist/operator/owner-runtime.d.ts.map +1 -0
- package/dist/operator/owner-runtime.js +31 -0
- package/dist/operator/owner-runtime.js.map +1 -0
- package/dist/operator/pending-report-store.d.ts +2 -2
- package/dist/operator/pending-report-store.d.ts.map +1 -1
- package/dist/operator/pending-report-store.js +4 -1
- package/dist/operator/pending-report-store.js.map +1 -1
- package/dist/operator/report-run.d.ts +7 -10
- package/dist/operator/report-run.d.ts.map +1 -1
- package/dist/operator/report-run.js +5 -26
- package/dist/operator/report-run.js.map +1 -1
- package/dist/operator/situation-report.d.ts +25 -6
- package/dist/operator/situation-report.d.ts.map +1 -1
- package/dist/operator/situation-report.js +25 -37
- package/dist/operator/situation-report.js.map +1 -1
- package/dist/operator/trigger-author.d.ts +0 -45
- package/dist/operator/trigger-author.d.ts.map +1 -1
- package/dist/operator/trigger-author.js +0 -122
- package/dist/operator/trigger-author.js.map +1 -1
- package/dist/operator/worker-run.d.ts +9 -23
- package/dist/operator/worker-run.d.ts.map +1 -1
- package/dist/operator/worker-run.js +18 -74
- package/dist/operator/worker-run.js.map +1 -1
- package/dist/operator/workorder-consumer.d.ts.map +1 -1
- package/dist/operator/workorder-consumer.js +7 -0
- package/dist/operator/workorder-consumer.js.map +1 -1
- package/dist/scheduler/cron-worker.d.ts +0 -3
- package/dist/scheduler/cron-worker.d.ts.map +1 -1
- package/dist/scheduler/cron-worker.js +2 -13
- package/dist/scheduler/cron-worker.js.map +1 -1
- package/dist/scheduler/heartbeat.d.ts +3 -1
- package/dist/scheduler/heartbeat.d.ts.map +1 -1
- package/dist/scheduler/heartbeat.js +13 -4
- package/dist/scheduler/heartbeat.js.map +1 -1
- package/dist/validation/types.d.ts +1 -1
- package/dist/validation/types.js +1 -1
- package/dist/wiki/wiki-turn-contract.d.ts.map +1 -1
- package/dist/wiki/wiki-turn-contract.js +1 -0
- package/dist/wiki/wiki-turn-contract.js.map +1 -1
- package/dist/wiki-artifacts/wiki-publish-adapter.d.ts.map +1 -1
- package/dist/wiki-artifacts/wiki-publish-adapter.js +11 -1
- package/dist/wiki-artifacts/wiki-publish-adapter.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/runtime/memory-agent-init.d.ts +0 -37
- package/dist/cli/runtime/memory-agent-init.d.ts.map +0 -1
- package/dist/cli/runtime/memory-agent-init.js +0 -202
- package/dist/cli/runtime/memory-agent-init.js.map +0 -1
- package/dist/gateways/owner-report-inbox.d.ts +0 -40
- package/dist/gateways/owner-report-inbox.d.ts.map +0 -1
- package/dist/gateways/owner-report-inbox.js +0 -128
- package/dist/gateways/owner-report-inbox.js.map +0 -1
- package/dist/multi-agent/memory-agent-persona.d.ts +0 -11
- package/dist/multi-agent/memory-agent-persona.d.ts.map +0 -1
- package/dist/multi-agent/memory-agent-persona.js +0 -175
- package/dist/multi-agent/memory-agent-persona.js.map +0 -1
- package/dist/operator/report-context.d.ts +0 -184
- package/dist/operator/report-context.d.ts.map +0 -1
- package/dist/operator/report-context.js +0 -1052
- package/dist/operator/report-context.js.map +0 -1
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Memory Agent initialization.
|
|
4
|
-
*
|
|
5
|
-
* Extracted from cli/commands/start.ts to keep the orchestrator thin.
|
|
6
|
-
* All logic and function signatures are unchanged.
|
|
7
|
-
*
|
|
8
|
-
* Responsibilities:
|
|
9
|
-
* 1. Loads memory agent persona via ensureMemoryPersona()
|
|
10
|
-
* 2. Creates memoryAgentContext (AgentContext)
|
|
11
|
-
* 3. Constructs a new AgentLoop for the memory agent (model: claude-sonnet-4-6, maxTurns: 3, tools: mama_search/mama_save)
|
|
12
|
-
* 4. Creates memoryProcessManager with getSharedProcess().sendMessage() implementation:
|
|
13
|
-
* - Bootstrap delivery (first-time only, with lock)
|
|
14
|
-
* - Decision count tracking (before/after)
|
|
15
|
-
* - buildMemoryAuditAckFromAgentResult for ack classification
|
|
16
|
-
* 5. Wires to messageRouter.setMemoryAgent()
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.initMemoryAgent = initMemoryAgent;
|
|
20
|
-
const node_fs_1 = require("node:fs");
|
|
21
|
-
const node_os_1 = require("node:os");
|
|
22
|
-
const config_manager_js_1 = require("../config/config-manager.js");
|
|
23
|
-
const index_js_1 = require("../../agent/index.js");
|
|
24
|
-
const backend_model_policy_js_1 = require("../../agent/backend-model-policy.js");
|
|
25
|
-
const bootstrap_context_js_1 = require("../../memory/bootstrap-context.js");
|
|
26
|
-
const memory_agent_ack_js_1 = require("../../memory/memory-agent-ack.js");
|
|
27
|
-
const scope_context_js_1 = require("../../memory/scope-context.js");
|
|
28
|
-
function isBackendType(value) {
|
|
29
|
-
return value === 'claude' || value === 'codex' || value === 'cline';
|
|
30
|
-
}
|
|
31
|
-
function resolveMemoryBackend(configuredBackend, runtimeBackend) {
|
|
32
|
-
if (isBackendType(configuredBackend)) {
|
|
33
|
-
return configuredBackend;
|
|
34
|
-
}
|
|
35
|
-
if (isBackendType(runtimeBackend)) {
|
|
36
|
-
return runtimeBackend;
|
|
37
|
-
}
|
|
38
|
-
return 'claude';
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Initialize the memory agent (persistent process for fact extraction).
|
|
42
|
-
*
|
|
43
|
-
* On success, wires memoryProcessManager into messageRouter via setMemoryAgent().
|
|
44
|
-
* On failure, logs a non-fatal warning and returns { memoryAgentLoop: null }.
|
|
45
|
-
*/
|
|
46
|
-
async function initMemoryAgent(oauthManager, config,
|
|
47
|
-
// Task 7: the memory agent no longer carries a private executor built around
|
|
48
|
-
// this mamaApi - it shares the boot executor (already wired via setMamaApi),
|
|
49
|
-
// so the positional arg is retained for the call signature but unused here.
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
-
_mamaApi, mamaApiClient, messageRouter, runtimeBackend, toolExecutor) {
|
|
52
|
-
// getAdapter is used directly for DB queries after initDB has run
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
54
|
-
const { getAdapter } = require('@jungjaehoon/mama-core/db-manager');
|
|
55
|
-
let memoryAgentLoop = null;
|
|
56
|
-
// Initialize memory agent (persistent process for fact extraction)
|
|
57
|
-
try {
|
|
58
|
-
const { ensureMemoryPersona } = await import('../../multi-agent/memory-agent-persona.js');
|
|
59
|
-
const personaPath = ensureMemoryPersona();
|
|
60
|
-
const memoryPersona = (0, node_fs_1.readFileSync)(personaPath, 'utf-8');
|
|
61
|
-
const memoryAgentConfig = config.multi_agent?.agents?.memory;
|
|
62
|
-
const memoryBackend = resolveMemoryBackend(memoryAgentConfig?.backend, runtimeBackend);
|
|
63
|
-
const memoryAgentContext = {
|
|
64
|
-
source: 'memory-agent',
|
|
65
|
-
platform: 'cli',
|
|
66
|
-
roleName: 'memory_agent',
|
|
67
|
-
role: {
|
|
68
|
-
allowedTools: memoryBackend === 'cline'
|
|
69
|
-
? ['code_act', 'mama_search', 'mama_save']
|
|
70
|
-
: ['mama_search', 'mama_save'],
|
|
71
|
-
blockedTools: ['Read', 'Write', 'Bash', 'Grep', 'Glob', 'Edit'],
|
|
72
|
-
systemControl: false,
|
|
73
|
-
sensitiveAccess: false,
|
|
74
|
-
},
|
|
75
|
-
session: {
|
|
76
|
-
sessionId: 'memory-agent:shared',
|
|
77
|
-
channelId: 'shared',
|
|
78
|
-
startedAt: new Date(),
|
|
79
|
-
},
|
|
80
|
-
capabilities: memoryBackend === 'cline'
|
|
81
|
-
? ['code_act', 'mama_search', 'mama_save']
|
|
82
|
-
: ['mama_search', 'mama_save'],
|
|
83
|
-
limitations: ['No file or shell access'],
|
|
84
|
-
tier: 2,
|
|
85
|
-
backend: memoryBackend,
|
|
86
|
-
};
|
|
87
|
-
const memoryModel = (0, backend_model_policy_js_1.resolveBackendScopedModel)({
|
|
88
|
-
backend: memoryBackend,
|
|
89
|
-
model: memoryAgentConfig?.model,
|
|
90
|
-
inheritedBackend: isBackendType(runtimeBackend) ? runtimeBackend : config.agent.backend,
|
|
91
|
-
inheritedModel: config.agent.model,
|
|
92
|
-
});
|
|
93
|
-
memoryAgentLoop = new index_js_1.AgentLoop(oauthManager, {
|
|
94
|
-
systemPrompt: memoryPersona,
|
|
95
|
-
model: memoryModel,
|
|
96
|
-
maxTurns: 3,
|
|
97
|
-
backend: memoryBackend,
|
|
98
|
-
useCodeAct: memoryBackend === 'cline',
|
|
99
|
-
// A codex memory agent writes the shared managed config like every other
|
|
100
|
-
// Codex process, so it has to agree on the effort or it flips theirs.
|
|
101
|
-
codexEffort: (0, backend_model_policy_js_1.codexEffortForBackend)(memoryBackend, config.agent.effort),
|
|
102
|
-
clineCommand: process.env.MAMA_CLINE_COMMAND ?? config.agent.cline_command,
|
|
103
|
-
clineProvider: config.agent.cline_provider,
|
|
104
|
-
clineDataDir: config.agent.cline_data_dir,
|
|
105
|
-
toolsConfig: {
|
|
106
|
-
gateway: ['mama_search', 'mama_save'],
|
|
107
|
-
mcp: [],
|
|
108
|
-
},
|
|
109
|
-
// Fold into the boot-wired shared executor (Task 7): the private twin
|
|
110
|
-
// existed ONLY to carry the initMamaCore mamaApi (now on the shared
|
|
111
|
-
// executor via setMamaApi), while the shared executor otherwise lazily
|
|
112
|
-
// built a second API/adapter stack against the same DB. The memory
|
|
113
|
-
// agent's tool restriction lives in toolsConfig + per-call context, not
|
|
114
|
-
// executor instance state, so sharing is safe (Task 1 per-call model).
|
|
115
|
-
executor: toolExecutor,
|
|
116
|
-
});
|
|
117
|
-
memoryAgentLoop.setSessionKey('memory-agent:shared');
|
|
118
|
-
let memoryBootstrapDelivered = false;
|
|
119
|
-
let memoryBootstrapLock = null;
|
|
120
|
-
const memoryWorkspaceProjectId = process.env.MAMA_WORKSPACE ||
|
|
121
|
-
(0, config_manager_js_1.expandPath)(config.workspace?.path || `${(0, node_os_1.homedir)()}/.mama/workspace`);
|
|
122
|
-
const memoryProcessManager = {
|
|
123
|
-
async getSharedProcess() {
|
|
124
|
-
return {
|
|
125
|
-
async sendMessage(content, options) {
|
|
126
|
-
if (!memoryAgentLoop) {
|
|
127
|
-
throw new Error('Memory agent loop is not initialized');
|
|
128
|
-
}
|
|
129
|
-
if (!memoryBootstrapDelivered && memoryBootstrapLock) {
|
|
130
|
-
await memoryBootstrapLock;
|
|
131
|
-
}
|
|
132
|
-
// Safe: initDB() completed before memoryProcessManager is created.
|
|
133
|
-
const adapter = getAdapter();
|
|
134
|
-
const beforeDecisionCount = Number(adapter.prepare('SELECT COUNT(*) AS count FROM decisions').get().count);
|
|
135
|
-
let prompt = content;
|
|
136
|
-
let shouldDeliverBootstrap = false;
|
|
137
|
-
let resolveBootstrapLock;
|
|
138
|
-
let rejectBootstrapLock;
|
|
139
|
-
if (!memoryBootstrapDelivered) {
|
|
140
|
-
shouldDeliverBootstrap = true;
|
|
141
|
-
memoryBootstrapLock = new Promise((resolve, reject) => {
|
|
142
|
-
resolveBootstrapLock = resolve;
|
|
143
|
-
rejectBootstrapLock = reject;
|
|
144
|
-
});
|
|
145
|
-
const bootstrap = await (0, bootstrap_context_js_1.buildStandaloneMemoryBootstrap)({
|
|
146
|
-
mamaApi: mamaApiClient,
|
|
147
|
-
scopes: (0, scope_context_js_1.deriveMemoryScopes)({
|
|
148
|
-
source: 'memory-agent',
|
|
149
|
-
channelId: 'shared',
|
|
150
|
-
projectId: memoryWorkspaceProjectId,
|
|
151
|
-
}),
|
|
152
|
-
currentGoal: 'Maintain current memory truth and audit ongoing conversations',
|
|
153
|
-
mainAgentState: {
|
|
154
|
-
active_goal: 'Maintain current memory truth and audit ongoing conversations',
|
|
155
|
-
active_channel: 'shared',
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
prompt = `${(0, bootstrap_context_js_1.formatMemoryBootstrap)(bootstrap)}\n\n---\n\n${content}`;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const result = await memoryAgentLoop.run(prompt, {
|
|
162
|
-
source: 'memory-agent',
|
|
163
|
-
channelId: 'shared',
|
|
164
|
-
agentContext: memoryAgentContext,
|
|
165
|
-
stopAfterSuccessfulTools: ['mama_save'],
|
|
166
|
-
sourceTurnId: options?.sourceTurnId,
|
|
167
|
-
sourceMessageRef: options?.sourceMessageRef,
|
|
168
|
-
parentModelRunId: options?.parentModelRunId,
|
|
169
|
-
});
|
|
170
|
-
const afterDecisionCount = Number(adapter.prepare('SELECT COUNT(*) AS count FROM decisions').get().count);
|
|
171
|
-
const ack = (0, memory_agent_ack_js_1.buildMemoryAuditAckFromAgentResult)(result, beforeDecisionCount, afterDecisionCount);
|
|
172
|
-
if (shouldDeliverBootstrap) {
|
|
173
|
-
memoryBootstrapDelivered = true;
|
|
174
|
-
if (resolveBootstrapLock) {
|
|
175
|
-
resolveBootstrapLock();
|
|
176
|
-
}
|
|
177
|
-
memoryBootstrapLock = null;
|
|
178
|
-
}
|
|
179
|
-
return { response: result.response, ack };
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
if (shouldDeliverBootstrap) {
|
|
183
|
-
if (rejectBootstrapLock) {
|
|
184
|
-
rejectBootstrapLock(error);
|
|
185
|
-
}
|
|
186
|
-
memoryBootstrapLock = null;
|
|
187
|
-
}
|
|
188
|
-
throw error;
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
messageRouter.setMemoryAgent(memoryProcessManager);
|
|
195
|
-
console.log('✓ Memory agent initialized');
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
console.warn(`[memory-agent] Init failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
199
|
-
}
|
|
200
|
-
return { memoryAgentLoop };
|
|
201
|
-
}
|
|
202
|
-
//# sourceMappingURL=memory-agent-init.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-agent-init.js","sourceRoot":"","sources":["../../../src/cli/runtime/memory-agent-init.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAyDH,0CA+LC;AAtPD,qCAAuC;AACvC,qCAAkC;AAGlC,mEAAyD;AAEzD,mDAAiD;AAGjD,iFAG6C;AAI7C,4EAG2C;AAC3C,0EAAsF;AACtF,oEAAmE;AAWnE,SAAS,aAAa,CAAC,KAAyB;IAC9C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC;AACtE,CAAC;AAED,SAAS,oBAAoB,CAC3B,iBAAqC,EACrC,cAAsB;IAEtB,IAAI,aAAa,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACrC,OAA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AAC;gCACzB,CAAC;gCACD,mBAAmB,GAAG,IAAI,CAAC;4BAC7B,CAAC;4BAED,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC;wBAC5C,CAAC;wBAAC,OAAO,KAAK,EAAE,CAAC;4BACf,IAAI,sBAAsB,EAAE,CAAC;gCAC3B,IAAI,mBAAmB,EAAE,CAAC;oCACxB,mBAAmB,CAAC,KAAK,CAAC,CAAC;gCAC7B,CAAC;gCACD,mBAAmB,GAAG,IAAI,CAAC;4BAC7B,CAAC;4BACD,MAAM,KAAK,CAAC;wBACd,CAAC;oBACH,CAAC;iBACF,CAAC;YACJ,CAAC;SACF,CAAC;QAEF,aAAa,CAAC,cAAc,CAAC,oBAAqD,CAAC,CAAC;QACpF,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CACV,2CAA2C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9F,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TG-05/TG-06: owner-report inbox - the read surface a verified owner turn
|
|
3
|
-
* uses to consume delivered-pending reports as bounded model context
|
|
4
|
-
* (docs/development/telegram-outbound-context-inbox-design.md, Decision 5-6).
|
|
5
|
-
*
|
|
6
|
-
* Lookup must happen only after the Telegram owner-console trust check; the
|
|
7
|
-
* caller (MessageRouter) gates on the resolved role, and the store scopes
|
|
8
|
-
* every read to one exact target.
|
|
9
|
-
*/
|
|
10
|
-
import type { ReportContextTarget, TelegramReportContextStore } from './telegram-report-context-store.js';
|
|
11
|
-
import type { ConversationTurn } from './types.js';
|
|
12
|
-
export interface OwnerReportSnapshot {
|
|
13
|
-
version: 'v1';
|
|
14
|
-
/** The exact complete Projection V1 block. */
|
|
15
|
-
text: string;
|
|
16
|
-
/** Lowercase hex SHA-256 over the exact UTF-8 bytes of `text`. */
|
|
17
|
-
projectionHash: string;
|
|
18
|
-
/** Ordered delivery IDs rendered in the block - the only consumable set. */
|
|
19
|
-
deliveryIds: string[];
|
|
20
|
-
}
|
|
21
|
-
export interface OwnerReportInboxPort {
|
|
22
|
-
snapshot(target: ReportContextTarget): OwnerReportSnapshot | null;
|
|
23
|
-
/** Committed-projection history for an actual new backend conversation. */
|
|
24
|
-
historyBlock(target: ReportContextTarget, turns: ConversationTurn[], nowIso?: string): string;
|
|
25
|
-
}
|
|
26
|
-
export declare class OwnerReportInbox implements OwnerReportInboxPort {
|
|
27
|
-
private readonly store;
|
|
28
|
-
constructor(store: TelegramReportContextStore);
|
|
29
|
-
snapshot(target: ReportContextTarget): OwnerReportSnapshot | null;
|
|
30
|
-
/**
|
|
31
|
-
* Startup restoration for an actual new backend conversation (design
|
|
32
|
-
* Decision 7): emit the already-committed Projection V1 text of the
|
|
33
|
-
* restored final turns' receipts, grouped in messenger-turn order. Bounded
|
|
34
|
-
* by 48,000 code points, 64 events, and five normal receipts; the newest
|
|
35
|
-
* complete receipt suffix that fits is taken and a receipt projection is
|
|
36
|
-
* never sliced. Returns '' when nothing restores.
|
|
37
|
-
*/
|
|
38
|
-
historyBlock(target: ReportContextTarget, turns: ConversationTurn[], nowIso?: string): string;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=owner-report-inbox.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"owner-report-inbox.d.ts","sourceRoot":"","sources":["../../src/gateways/owner-report-inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAsBnD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,IAAI,CAAC;IACd,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,cAAc,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAAC;IAClE,2EAA2E;IAC3E,YAAY,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/F;AAED,qBAAa,gBAAiB,YAAW,oBAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,0BAA0B;IAE9D,QAAQ,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI;IAiBjE;;;;;;;OAOG;IACH,YAAY,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAsE9F"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* TG-05/TG-06: owner-report inbox - the read surface a verified owner turn
|
|
4
|
-
* uses to consume delivered-pending reports as bounded model context
|
|
5
|
-
* (docs/development/telegram-outbound-context-inbox-design.md, Decision 5-6).
|
|
6
|
-
*
|
|
7
|
-
* Lookup must happen only after the Telegram owner-console trust check; the
|
|
8
|
-
* caller (MessageRouter) gates on the resolved role, and the store scopes
|
|
9
|
-
* every read to one exact target.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.OwnerReportInbox = void 0;
|
|
13
|
-
const node_crypto_1 = require("node:crypto");
|
|
14
|
-
const report_projection_v1_js_1 = require("./report-projection-v1.js");
|
|
15
|
-
/** Design Decision 7 startup-history caps. */
|
|
16
|
-
const HISTORY_CAP_CP = 48_000;
|
|
17
|
-
const HISTORY_MAX_EVENTS = 64;
|
|
18
|
-
const HISTORY_MAX_RECEIPTS = 5;
|
|
19
|
-
const HISTORY_OPEN_TAG = '<recent_owner_report_history projection="v1">';
|
|
20
|
-
const HISTORY_CLOSE_TAG = '</recent_owner_report_history>';
|
|
21
|
-
function countCodePoints(text) {
|
|
22
|
-
let count = 0;
|
|
23
|
-
let index = 0;
|
|
24
|
-
while (index < text.length) {
|
|
25
|
-
const codePoint = text.codePointAt(index);
|
|
26
|
-
count += 1;
|
|
27
|
-
index += codePoint > 0xffff ? 2 : 1;
|
|
28
|
-
}
|
|
29
|
-
return count;
|
|
30
|
-
}
|
|
31
|
-
class OwnerReportInbox {
|
|
32
|
-
store;
|
|
33
|
-
constructor(store) {
|
|
34
|
-
this.store = store;
|
|
35
|
-
}
|
|
36
|
-
snapshot(target) {
|
|
37
|
-
const pending = this.store.listDeliveredPending(target);
|
|
38
|
-
if (pending.length === 0) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const projection = (0, report_projection_v1_js_1.buildOwnerReportProjectionV1)(pending);
|
|
42
|
-
if (projection.text === '' || projection.selectedDeliveryIds.length === 0) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
version: 'v1',
|
|
47
|
-
text: projection.text,
|
|
48
|
-
projectionHash: projection.projectionHash,
|
|
49
|
-
deliveryIds: projection.selectedDeliveryIds,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Startup restoration for an actual new backend conversation (design
|
|
54
|
-
* Decision 7): emit the already-committed Projection V1 text of the
|
|
55
|
-
* restored final turns' receipts, grouped in messenger-turn order. Bounded
|
|
56
|
-
* by 48,000 code points, 64 events, and five normal receipts; the newest
|
|
57
|
-
* complete receipt suffix that fits is taken and a receipt projection is
|
|
58
|
-
* never sliced. Returns '' when nothing restores.
|
|
59
|
-
*/
|
|
60
|
-
historyBlock(target, turns, nowIso) {
|
|
61
|
-
const now = nowIso ?? new Date().toISOString();
|
|
62
|
-
const refs = turns
|
|
63
|
-
.filter((turn) => turn.state !== 'provisional' && turn.sourceMessageRef)
|
|
64
|
-
.map((turn) => turn.sourceMessageRef);
|
|
65
|
-
const receipts = refs.length > 0 ? this.store.listReceiptsByRefs(refs) : [];
|
|
66
|
-
const legacy = this.store.listLegacyRestorations(target, now);
|
|
67
|
-
if (receipts.length === 0 && legacy.length === 0) {
|
|
68
|
-
return '';
|
|
69
|
-
}
|
|
70
|
-
const groups = [
|
|
71
|
-
...legacy.map((entry) => ({
|
|
72
|
-
kind: 'legacy',
|
|
73
|
-
time: entry.consumedAtIso ?? entry.deliveredAtIso,
|
|
74
|
-
tieBreak: entry.deliveryId,
|
|
75
|
-
eventCount: 1,
|
|
76
|
-
render: `[legacy_v2_consumed delivery_sha256=${sha256Hex(entry.deliveryId)} consumed_at=${entry.consumedAtIso}]\n${entry.restorationText}`,
|
|
77
|
-
})),
|
|
78
|
-
...receipts.map((receipt) => ({
|
|
79
|
-
kind: 'receipt',
|
|
80
|
-
time: receipt.committedAtIso,
|
|
81
|
-
tieBreak: receipt.sourceMessageRef,
|
|
82
|
-
eventCount: receipt.deliveryIds.length,
|
|
83
|
-
render: `[before_turn source_message_ref_sha256=${sha256Hex(receipt.sourceMessageRef)}]\n${receipt.projectionText}`,
|
|
84
|
-
})),
|
|
85
|
-
].sort((a, b) => {
|
|
86
|
-
if (a.time !== b.time)
|
|
87
|
-
return a.time < b.time ? -1 : 1;
|
|
88
|
-
if (a.kind !== b.kind)
|
|
89
|
-
return a.kind === 'legacy' ? -1 : 1;
|
|
90
|
-
return a.tieBreak < b.tieBreak ? -1 : 1;
|
|
91
|
-
});
|
|
92
|
-
// Newest complete suffix under the caps: 48k code points and 64 events in
|
|
93
|
-
// aggregate, at most five NORMAL receipts. A group is never sliced.
|
|
94
|
-
const selected = [];
|
|
95
|
-
let eventCount = 0;
|
|
96
|
-
let receiptCount = 0;
|
|
97
|
-
for (let index = groups.length - 1; index >= 0; index -= 1) {
|
|
98
|
-
const group = groups[index];
|
|
99
|
-
if (group.kind === 'receipt' && receiptCount + 1 > HISTORY_MAX_RECEIPTS) {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
if (eventCount + group.eventCount > HISTORY_MAX_EVENTS) {
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
const candidate = [group, ...selected];
|
|
106
|
-
if (countCodePoints(renderHistoryBlock(candidate)) > HISTORY_CAP_CP) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
selected.unshift(group);
|
|
110
|
-
eventCount += group.eventCount;
|
|
111
|
-
if (group.kind === 'receipt') {
|
|
112
|
-
receiptCount += 1;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (selected.length === 0) {
|
|
116
|
-
return '';
|
|
117
|
-
}
|
|
118
|
-
return renderHistoryBlock(selected);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.OwnerReportInbox = OwnerReportInbox;
|
|
122
|
-
function sha256Hex(text) {
|
|
123
|
-
return (0, node_crypto_1.createHash)('sha256').update(text, 'utf8').digest('hex');
|
|
124
|
-
}
|
|
125
|
-
function renderHistoryBlock(groups) {
|
|
126
|
-
return `${HISTORY_OPEN_TAG}\n${groups.map((group) => group.render).join('\n\n')}\n${HISTORY_CLOSE_TAG}`;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=owner-report-inbox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"owner-report-inbox.js","sourceRoot":"","sources":["../../src/gateways/owner-report-inbox.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,6CAAyC;AAMzC,uEAAyE;AAEzE,8CAA8C;AAC9C,MAAM,cAAc,GAAG,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,UAAU,GAAG,kBAAkB,EAAE,CAAC;gBACvD,MAAM;YACR,CAAC;YACD,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;YACvC,IAAI,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;gBACpE,MAAM;YACR,CAAC;YACD,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACxB,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC;YAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC7B,YAAY,IAAI,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF;AAlGD,4CAkGC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAiC;IAC3D,OAAO,GAAG,gBAAgB,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,EAAE,CAAC;AAC1G,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default persona for the memory agent.
|
|
3
|
-
* Written to ~/.mama/personas/memory.md on first use if not present.
|
|
4
|
-
*/
|
|
5
|
-
export declare const MEMORY_AGENT_PERSONA = "<!-- MAMA managed memory persona v6 -->\n\nYou are MAMA's memory auditor and curator \u2014 an internal agent that watches conversations, maintains current truth, and advises the main agent when memory matters.\n\n## Your Role\n- Observe every conversation turn between users and the main agent\n- Distinguish time-ordered memory history from current truth\n- Use memory tools directly to inspect, evolve, and save memory\n- Notify the main agent only when evidence-backed memory findings are relevant\n- Never rely on the caller to parse JSON and save for you\n\n## Topic Rules\n- MUST reuse existing topic if same subject (provided in context)\n- Use lowercase snake_case: auth_strategy, database_choice\n- Same topic = evolution chain (supersedes)\n- Related topic = builds_on or synthesizes\n\n## Mandatory Tool Workflow\nKeep the workflow minimal and terminate quickly.\n\n**Step 1 \u2014 ALWAYS call `mama_search` first.**\nSearch for existing memories related to the conversation topic. This is mandatory even if you believe nothing is worth saving \u2014 you need context to make that judgment.\n\n**Step 2 \u2014 Decide: save or no-op.**\nBased on search results and the conversation, decide whether to save or skip.\n\n**Step 3 \u2014 Call `mama_save` when the conversation contains ANY of these:**\n- A decision, preference, or technical choice\n- A constraint, requirement, or lesson learned\n- A fact about architecture, tooling, or workflow\n- A change that supersedes a prior memory\n\nWhen calling `mama_save`, always include the `scopes` field from the Memory scopes listed at the top of the prompt. Parse the scope entries (e.g., \"project:/path, channel:telegram:123\") into `[{kind: \"project\", id: \"/path\"}, {kind: \"channel\", id: \"telegram:123\"}]`.\n\n**Step 4 \u2014 Only skip (no-op) when the conversation is ALL of these:**\n- Pure greeting, thanks, or confirmation (\"ok\", \"got it\", \"thanks\")\n- Contains zero decisions, preferences, facts, or choices\n- Even then, you must have called `mama_search` first before deciding to skip\n\n## Strict Limits\n- Call `mama_search` at most once per audit.\n- Call `mama_save` at most once per audit.\n- Do NOT call resource discovery tools such as `list_mcp_resources` or `list_mcp_resource_templates`.\n- Do NOT ask follow-up questions.\n- Do NOT continue reasoning after the required tool calls finish.\n- After finishing tool work, respond with exactly one token:\n - `DONE` if a save occurred\n - `SKIP` if nothing should be saved\n\n## Relationship Types\n- supersedes: replaces a previous decision on same topic\n- builds_on: adds information to existing topic without replacing\n- synthesizes: merges multiple decisions or infers connections\n\n## Truth Model\n- Preserve history, but maintain current truth separately\n- Old memories may remain in history while becoming stale, contradicted, or superseded\n- When uncertain about relationship type, prefer builds_on over supersedes to avoid data loss\n\n## Temporal Marker Extraction\n\nWhen the conversation contains relative time expressions, extract an explicit event_date and include it in `mama_save` as the `event_date` field (ISO 8601: \"YYYY-MM-DD\").\n\n**Extract event_date when you see:**\n- Yesterday \u2192 today - 1 day\n- Last week / last month \u2192 approximate Monday or 1st of previous period\n- \"In March\", \"in January 2023\" \u2192 first day of that month (e.g., \"2023-03-01\")\n- \"A year ago\", \"3 months ago\" \u2192 today minus that duration\n- \"On Tuesday\", \"last Friday\" \u2192 nearest past occurrence of that weekday\n- An explicit date mentioned in the conversation (e.g., \"December 28th\")\n\n**How to apply:**\n1. Identify the most precise date derivable from context\n2. Pass `event_date: \"YYYY-MM-DD\"` in `mama_save` alongside the decision\n3. If no temporal marker is present, omit event_date (system defaults to created_at)\n\n## What to Save\n- Architecture decisions, technical choices, tooling preferences\n- User preferences and working style\n- Constraints, requirements, lessons learned\n- Decision changes that should supersede prior memory\n\n## What to Skip\n- Greetings, casual chat, thanks\n- Questions without answers\n- Temporary debugging steps\n- Code snippets\n\n## Response Rules\n- You MUST call at least `mama_search` before any text response.\n- Do not return JSON for the caller to parse\n- Do the memory work yourself with tools, then terminate immediately with `DONE` or `SKIP`\n- When in doubt, save \u2014 false negatives (missing a memory) are worse than false positives\n- You are an internal subagent, not the user-facing assistant\n\n## PROMOTION RUN mode\nWhen an incoming message begins with \"PROMOTION RUN\", it is a scheduled batch\npass over recent business data, NOT a turn audit. In this mode ONLY:\n- The per-audit limits above do not apply: you may call mama_search several\n times and mama_save up to 5 times, and you gather evidence yourself with\n the business-data tools projected for this run plus agent_notices as the run\n instructions describe.\n- Promote ONLY durable judgments: pricing/scope agreements, a client's standing\n preference or boundary, a process rule, a recurring risk pattern. Things that\n change how future work is done.\n- NEVER promote task lifecycle states (\"X was submitted\", \"Y is in progress\") --\n the task board owns those. Never promote greetings, scheduling chatter, or\n one-off logistics.\n- Every save needs scopes (parse from the run instructions or the source\n channel) and an event_date for when the judgment was actually made.\n- Reuse existing topics found via mama_search so evolution chains stay intact.\n- Finish with exactly one line: `PROMOTED <n>` (n = number of saves) or\n `NO_UPDATE` when nothing qualifies. When in doubt in THIS mode, do NOT save --\n promotion is curation, and a wrong policy in memory misleads every consumer.";
|
|
6
|
-
/**
|
|
7
|
-
* Ensure persona file exists at ~/.mama/personas/memory.md
|
|
8
|
-
* Creates it from default if not present and upgrades legacy managed personas.
|
|
9
|
-
*/
|
|
10
|
-
export declare function ensureMemoryPersona(mamaHomeDir?: string): string;
|
|
11
|
-
//# sourceMappingURL=memory-agent-persona.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-agent-persona.d.ts","sourceRoot":"","sources":["../../src/multi-agent/memory-agent-persona.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,eAAO,MAAM,oBAAoB,uyLAiH8C,CAAC;AA2BhF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,MAAiC,GAAG,MAAM,CA4B1F"}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Default persona for the memory agent.
|
|
4
|
-
* Written to ~/.mama/personas/memory.md on first use if not present.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.MEMORY_AGENT_PERSONA = void 0;
|
|
8
|
-
exports.ensureMemoryPersona = ensureMemoryPersona;
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const os_1 = require("os");
|
|
12
|
-
const MANAGED_MEMORY_PERSONA_MARKER = '<!-- MAMA managed memory persona v6 -->';
|
|
13
|
-
exports.MEMORY_AGENT_PERSONA = `${MANAGED_MEMORY_PERSONA_MARKER}
|
|
14
|
-
|
|
15
|
-
You are MAMA's memory auditor and curator — an internal agent that watches conversations, maintains current truth, and advises the main agent when memory matters.
|
|
16
|
-
|
|
17
|
-
## Your Role
|
|
18
|
-
- Observe every conversation turn between users and the main agent
|
|
19
|
-
- Distinguish time-ordered memory history from current truth
|
|
20
|
-
- Use memory tools directly to inspect, evolve, and save memory
|
|
21
|
-
- Notify the main agent only when evidence-backed memory findings are relevant
|
|
22
|
-
- Never rely on the caller to parse JSON and save for you
|
|
23
|
-
|
|
24
|
-
## Topic Rules
|
|
25
|
-
- MUST reuse existing topic if same subject (provided in context)
|
|
26
|
-
- Use lowercase snake_case: auth_strategy, database_choice
|
|
27
|
-
- Same topic = evolution chain (supersedes)
|
|
28
|
-
- Related topic = builds_on or synthesizes
|
|
29
|
-
|
|
30
|
-
## Mandatory Tool Workflow
|
|
31
|
-
Keep the workflow minimal and terminate quickly.
|
|
32
|
-
|
|
33
|
-
**Step 1 — ALWAYS call \`mama_search\` first.**
|
|
34
|
-
Search for existing memories related to the conversation topic. This is mandatory even if you believe nothing is worth saving — you need context to make that judgment.
|
|
35
|
-
|
|
36
|
-
**Step 2 — Decide: save or no-op.**
|
|
37
|
-
Based on search results and the conversation, decide whether to save or skip.
|
|
38
|
-
|
|
39
|
-
**Step 3 — Call \`mama_save\` when the conversation contains ANY of these:**
|
|
40
|
-
- A decision, preference, or technical choice
|
|
41
|
-
- A constraint, requirement, or lesson learned
|
|
42
|
-
- A fact about architecture, tooling, or workflow
|
|
43
|
-
- A change that supersedes a prior memory
|
|
44
|
-
|
|
45
|
-
When calling \`mama_save\`, always include the \`scopes\` field from the Memory scopes listed at the top of the prompt. Parse the scope entries (e.g., "project:/path, channel:telegram:123") into \`[{kind: "project", id: "/path"}, {kind: "channel", id: "telegram:123"}]\`.
|
|
46
|
-
|
|
47
|
-
**Step 4 — Only skip (no-op) when the conversation is ALL of these:**
|
|
48
|
-
- Pure greeting, thanks, or confirmation ("ok", "got it", "thanks")
|
|
49
|
-
- Contains zero decisions, preferences, facts, or choices
|
|
50
|
-
- Even then, you must have called \`mama_search\` first before deciding to skip
|
|
51
|
-
|
|
52
|
-
## Strict Limits
|
|
53
|
-
- Call \`mama_search\` at most once per audit.
|
|
54
|
-
- Call \`mama_save\` at most once per audit.
|
|
55
|
-
- Do NOT call resource discovery tools such as \`list_mcp_resources\` or \`list_mcp_resource_templates\`.
|
|
56
|
-
- Do NOT ask follow-up questions.
|
|
57
|
-
- Do NOT continue reasoning after the required tool calls finish.
|
|
58
|
-
- After finishing tool work, respond with exactly one token:
|
|
59
|
-
- \`DONE\` if a save occurred
|
|
60
|
-
- \`SKIP\` if nothing should be saved
|
|
61
|
-
|
|
62
|
-
## Relationship Types
|
|
63
|
-
- supersedes: replaces a previous decision on same topic
|
|
64
|
-
- builds_on: adds information to existing topic without replacing
|
|
65
|
-
- synthesizes: merges multiple decisions or infers connections
|
|
66
|
-
|
|
67
|
-
## Truth Model
|
|
68
|
-
- Preserve history, but maintain current truth separately
|
|
69
|
-
- Old memories may remain in history while becoming stale, contradicted, or superseded
|
|
70
|
-
- When uncertain about relationship type, prefer builds_on over supersedes to avoid data loss
|
|
71
|
-
|
|
72
|
-
## Temporal Marker Extraction
|
|
73
|
-
|
|
74
|
-
When the conversation contains relative time expressions, extract an explicit event_date and include it in \`mama_save\` as the \`event_date\` field (ISO 8601: "YYYY-MM-DD").
|
|
75
|
-
|
|
76
|
-
**Extract event_date when you see:**
|
|
77
|
-
- Yesterday → today - 1 day
|
|
78
|
-
- Last week / last month → approximate Monday or 1st of previous period
|
|
79
|
-
- "In March", "in January 2023" → first day of that month (e.g., "2023-03-01")
|
|
80
|
-
- "A year ago", "3 months ago" → today minus that duration
|
|
81
|
-
- "On Tuesday", "last Friday" → nearest past occurrence of that weekday
|
|
82
|
-
- An explicit date mentioned in the conversation (e.g., "December 28th")
|
|
83
|
-
|
|
84
|
-
**How to apply:**
|
|
85
|
-
1. Identify the most precise date derivable from context
|
|
86
|
-
2. Pass \`event_date: "YYYY-MM-DD"\` in \`mama_save\` alongside the decision
|
|
87
|
-
3. If no temporal marker is present, omit event_date (system defaults to created_at)
|
|
88
|
-
|
|
89
|
-
## What to Save
|
|
90
|
-
- Architecture decisions, technical choices, tooling preferences
|
|
91
|
-
- User preferences and working style
|
|
92
|
-
- Constraints, requirements, lessons learned
|
|
93
|
-
- Decision changes that should supersede prior memory
|
|
94
|
-
|
|
95
|
-
## What to Skip
|
|
96
|
-
- Greetings, casual chat, thanks
|
|
97
|
-
- Questions without answers
|
|
98
|
-
- Temporary debugging steps
|
|
99
|
-
- Code snippets
|
|
100
|
-
|
|
101
|
-
## Response Rules
|
|
102
|
-
- You MUST call at least \`mama_search\` before any text response.
|
|
103
|
-
- Do not return JSON for the caller to parse
|
|
104
|
-
- Do the memory work yourself with tools, then terminate immediately with \`DONE\` or \`SKIP\`
|
|
105
|
-
- When in doubt, save — false negatives (missing a memory) are worse than false positives
|
|
106
|
-
- You are an internal subagent, not the user-facing assistant
|
|
107
|
-
|
|
108
|
-
## PROMOTION RUN mode
|
|
109
|
-
When an incoming message begins with "PROMOTION RUN", it is a scheduled batch
|
|
110
|
-
pass over recent business data, NOT a turn audit. In this mode ONLY:
|
|
111
|
-
- The per-audit limits above do not apply: you may call mama_search several
|
|
112
|
-
times and mama_save up to 5 times, and you gather evidence yourself with
|
|
113
|
-
the business-data tools projected for this run plus agent_notices as the run
|
|
114
|
-
instructions describe.
|
|
115
|
-
- Promote ONLY durable judgments: pricing/scope agreements, a client's standing
|
|
116
|
-
preference or boundary, a process rule, a recurring risk pattern. Things that
|
|
117
|
-
change how future work is done.
|
|
118
|
-
- NEVER promote task lifecycle states ("X was submitted", "Y is in progress") --
|
|
119
|
-
the task board owns those. Never promote greetings, scheduling chatter, or
|
|
120
|
-
one-off logistics.
|
|
121
|
-
- Every save needs scopes (parse from the run instructions or the source
|
|
122
|
-
channel) and an event_date for when the judgment was actually made.
|
|
123
|
-
- Reuse existing topics found via mama_search so evolution chains stay intact.
|
|
124
|
-
- Finish with exactly one line: \`PROMOTED <n>\` (n = number of saves) or
|
|
125
|
-
\`NO_UPDATE\` when nothing qualifies. When in doubt in THIS mode, do NOT save --
|
|
126
|
-
promotion is curation, and a wrong policy in memory misleads every consumer.`;
|
|
127
|
-
function isLegacyManagedPersona(content) {
|
|
128
|
-
// v1: old JSON-return persona
|
|
129
|
-
if (content.includes("You are MAMA's memory agent") &&
|
|
130
|
-
(content.includes('Return ONLY a JSON object') ||
|
|
131
|
-
content.includes('Return ONLY JSON') ||
|
|
132
|
-
content.includes('Return ONLY the JSON'))) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
// v2: soft tool instructions (didn't enforce tool calls)
|
|
136
|
-
if (content.includes('<!-- MAMA managed memory persona v2 -->')) {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
// v3: allowed too many follow-up turns and resource-discovery loops
|
|
140
|
-
if (content.includes('<!-- MAMA managed memory persona v3 -->')) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
// v4: missing temporal marker extraction
|
|
144
|
-
if (content.includes('<!-- MAMA managed memory persona v4 -->')) {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Ensure persona file exists at ~/.mama/personas/memory.md
|
|
151
|
-
* Creates it from default if not present and upgrades legacy managed personas.
|
|
152
|
-
*/
|
|
153
|
-
function ensureMemoryPersona(mamaHomeDir = (0, path_1.join)((0, os_1.homedir)(), '.mama')) {
|
|
154
|
-
const personaDir = (0, path_1.join)(mamaHomeDir, 'personas');
|
|
155
|
-
const personaPath = (0, path_1.join)(personaDir, 'memory.md');
|
|
156
|
-
if (!(0, fs_1.existsSync)(personaDir)) {
|
|
157
|
-
(0, fs_1.mkdirSync)(personaDir, { recursive: true });
|
|
158
|
-
}
|
|
159
|
-
if (!(0, fs_1.existsSync)(personaPath)) {
|
|
160
|
-
(0, fs_1.writeFileSync)(personaPath, exports.MEMORY_AGENT_PERSONA, 'utf-8');
|
|
161
|
-
return personaPath;
|
|
162
|
-
}
|
|
163
|
-
const existingContent = (0, fs_1.readFileSync)(personaPath, 'utf-8');
|
|
164
|
-
if (isLegacyManagedPersona(existingContent)) {
|
|
165
|
-
(0, fs_1.writeFileSync)(personaPath, exports.MEMORY_AGENT_PERSONA, 'utf-8');
|
|
166
|
-
}
|
|
167
|
-
// Upgrade ANY older managed persona version (match the marker prefix, not the
|
|
168
|
-
// exact current version -- an exact match can never upgrade v5 -> v6).
|
|
169
|
-
if (existingContent.includes('<!-- MAMA managed memory persona') &&
|
|
170
|
-
existingContent !== exports.MEMORY_AGENT_PERSONA) {
|
|
171
|
-
(0, fs_1.writeFileSync)(personaPath, exports.MEMORY_AGENT_PERSONA, 'utf-8');
|
|
172
|
-
}
|
|
173
|
-
return personaPath;
|
|
174
|
-
}
|
|
175
|
-
//# sourceMappingURL=memory-agent-persona.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-agent-persona.js","sourceRoot":"","sources":["../../src/multi-agent/memory-agent-persona.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwJH,kDA4BC;AAlLD,2BAAwE;AACxE,+BAA4B;AAC5B,2BAA6B;AAE7B,MAAM,6BAA6B,GAAG,yCAAyC,CAAC;AAEnE,QAAA,oBAAoB,GAAG,GAAG,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+EAiHW,CAAC;AAEhF,SAAS,sBAAsB,CAAC,OAAe;IAC7C,8BAA8B;IAC9B,IACE,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC;QAC/C,CAAC,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAC;YAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YACpC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,EAC3C,CAAC;QACD,OAAO,IAA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