@jungjaehoon/mama-os 0.48.4 → 0.49.1
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 +106 -80
- 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 +7 -9
- 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 +27 -8
- package/dist/agent/tool-registry.js.map +1 -1
- package/dist/agent/types.d.ts +20 -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 +188 -189
- 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 +31 -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 +15 -71
- package/dist/gateways/message-router.d.ts.map +1 -1
- package/dist/gateways/message-router.js +124 -493
- 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 +9 -8
- package/dist/operator/owner-event-loop.d.ts.map +1 -1
- package/dist/operator/owner-event-loop.js +8 -22
- 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 +28 -37
- package/dist/operator/situation-report.js.map +1 -1
- package/dist/operator/task-ledger.d.ts +8 -1
- package/dist/operator/task-ledger.d.ts.map +1 -1
- package/dist/operator/task-ledger.js +51 -16
- package/dist/operator/task-ledger.js.map +1 -1
- package/dist/operator/task-list-views.d.ts.map +1 -1
- package/dist/operator/task-list-views.js +45 -24
- package/dist/operator/task-list-views.js.map +1 -1
- package/dist/operator/task-temporal.d.ts +3 -0
- package/dist/operator/task-temporal.d.ts.map +1 -1
- package/dist/operator/task-temporal.js +12 -0
- package/dist/operator/task-temporal.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/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
|
@@ -65,7 +65,6 @@ exports.buildTurnAgentPolicy = buildTurnAgentPolicy;
|
|
|
65
65
|
exports.bindCodeActParentModelRun = bindCodeActParentModelRun;
|
|
66
66
|
exports.finalizeCodeActParentModelRun = finalizeCodeActParentModelRun;
|
|
67
67
|
exports.failCodeActParentModelRun = failCodeActParentModelRun;
|
|
68
|
-
exports.buildSystemAgentProcessDefaults = buildSystemAgentProcessDefaults;
|
|
69
68
|
exports.resolveOwnerEventTerminalReceipt = resolveOwnerEventTerminalReceipt;
|
|
70
69
|
exports.startCommand = startCommand;
|
|
71
70
|
exports.buildStartOnboardingOutput = buildStartOnboardingOutput;
|
|
@@ -85,7 +84,6 @@ const run_context_registry_js_1 = require("../../agent/code-act/run-context-regi
|
|
|
85
84
|
const index_js_2 = require("../../gateways/index.js");
|
|
86
85
|
const member_effective_scope_js_1 = require("../../gateways/member-effective-scope.js");
|
|
87
86
|
const telegram_report_context_store_js_1 = require("../../gateways/telegram-report-context-store.js");
|
|
88
|
-
const owner_report_inbox_js_1 = require("../../gateways/owner-report-inbox.js");
|
|
89
87
|
const report_delivery_coordinator_js_1 = require("../../operator/report-delivery-coordinator.js");
|
|
90
88
|
const graph_api_js_1 = require("../../api/graph-api.js");
|
|
91
89
|
const sqlite_js_1 = __importDefault(require("../../sqlite.js"));
|
|
@@ -104,7 +102,6 @@ const daemon_js_1 = require("../runtime/daemon.js");
|
|
|
104
102
|
const metrics_init_js_1 = require("../runtime/metrics-init.js");
|
|
105
103
|
const mama_core_init_js_1 = require("../runtime/mama-core-init.js");
|
|
106
104
|
const agent_loop_init_js_1 = require("../runtime/agent-loop-init.js");
|
|
107
|
-
const memory_agent_init_js_1 = require("../runtime/memory-agent-init.js");
|
|
108
105
|
const gateway_init_js_1 = require("../runtime/gateway-init.js");
|
|
109
106
|
const gateway_wiring_js_1 = require("../runtime/gateway-wiring.js");
|
|
110
107
|
const scheduler_init_js_1 = require("../runtime/scheduler-init.js");
|
|
@@ -127,12 +124,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
127
124
|
const debugLogger = __importStar(require("@jungjaehoon/mama-core/debug-logger"));
|
|
128
125
|
const mama_core_1 = require("@jungjaehoon/mama-core");
|
|
129
126
|
const mamaCore = __importStar(require("@jungjaehoon/mama-core"));
|
|
130
|
-
const
|
|
131
|
-
const report_context_js_1 = require("../../operator/report-context.js");
|
|
132
|
-
const changes_projection_js_1 = require("../../operator/changes-projection.js");
|
|
133
|
-
const external_correlation_js_1 = require("../../operator/external-correlation.js");
|
|
134
|
-
const provenance_lookup_js_1 = require("../../operator/provenance-lookup.js");
|
|
135
|
-
const query_tools_js_1 = require("../../connectors/trello/query-tools.js");
|
|
127
|
+
const owner_runtime_js_1 = require("../../operator/owner-runtime.js");
|
|
136
128
|
const console_brief_js_1 = require("../../operator/console-brief.js");
|
|
137
129
|
const task_ledger_js_1 = require("../../operator/task-ledger.js");
|
|
138
130
|
const board_refresh_gate_js_1 = require("../../operator/board-refresh-gate.js");
|
|
@@ -488,7 +480,6 @@ exports.ADMINISTRATION_TOOLS = new Set([
|
|
|
488
480
|
'member_scope_grant',
|
|
489
481
|
'member_scope_revoke',
|
|
490
482
|
'console_brief_update',
|
|
491
|
-
'report_request',
|
|
492
483
|
]);
|
|
493
484
|
/**
|
|
494
485
|
* Per-turn-kind artifact tools, projected by the HOST. These exist only for scheduled
|
|
@@ -613,15 +604,23 @@ exports.TURN_KIND_BLOCKED_TOOLS = {
|
|
|
613
604
|
'obsidian',
|
|
614
605
|
]),
|
|
615
606
|
};
|
|
616
|
-
/**
|
|
617
|
-
* Packet-only reports receive no gateway tools. The host compiles current bounded authorities
|
|
618
|
-
* before model admission; the model spends one turn judging and narrating that packet.
|
|
619
|
-
*/
|
|
607
|
+
/** Progressive evidence primitives for a scheduled owner-runtime report turn. */
|
|
620
608
|
exports.OPERATOR_REPORT_TOOL_POLICY = {
|
|
621
|
-
roleName: '
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
609
|
+
roleName: 'owner_console',
|
|
610
|
+
allowedTools: [
|
|
611
|
+
'code_act',
|
|
612
|
+
'task_list',
|
|
613
|
+
'changes_read',
|
|
614
|
+
'board_read',
|
|
615
|
+
'audit_findings_read',
|
|
616
|
+
'schedule_upcoming',
|
|
617
|
+
'context_compile',
|
|
618
|
+
'mama_recall',
|
|
619
|
+
'mama_provenance',
|
|
620
|
+
'trello_search',
|
|
621
|
+
'trello_card',
|
|
622
|
+
'trello_kanban',
|
|
623
|
+
],
|
|
625
624
|
};
|
|
626
625
|
function requirePrivateConnectorPolicy(privateConnectorPolicy) {
|
|
627
626
|
if (!privateConnectorPolicy) {
|
|
@@ -646,26 +645,36 @@ function buildProjectedLanePrompt(innerTools, surface, privateConnectorPolicy) {
|
|
|
646
645
|
}).prompt;
|
|
647
646
|
}
|
|
648
647
|
/**
|
|
649
|
-
* Build the
|
|
648
|
+
* Build the execution role for one progressive report stimulus. The durable
|
|
649
|
+
* session catalog comes from the full owner role; this role narrows effects.
|
|
650
650
|
*/
|
|
651
|
-
function buildOperatorReportAgentPolicy(model, backend, privateConnectorPolicy) {
|
|
651
|
+
function buildOperatorReportAgentPolicy(model, backend, privateConnectorPolicy, ownerRole = types_js_1.DEFAULT_ROLES.definitions.owner_console) {
|
|
652
652
|
const requiredPrivatePolicy = requirePrivateConnectorPolicy(privateConnectorPolicy);
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
653
|
+
const blockedSet = new Set([
|
|
654
|
+
...exports.ADMINISTRATION_TOOLS,
|
|
655
|
+
...exports.SCHEDULED_TURN_BLOCKED_TOOLS,
|
|
656
|
+
...(ownerRole.blockedTools ?? []),
|
|
657
|
+
]);
|
|
658
|
+
const projectedRole = requiredPrivatePolicy.projectRole('owner_console', {
|
|
659
|
+
...ownerRole,
|
|
660
|
+
model,
|
|
661
|
+
allowedTools: uniqueToolList([
|
|
662
|
+
...ownerRole.allowedTools,
|
|
663
|
+
...exports.OPERATOR_REPORT_TOOL_POLICY.allowedTools,
|
|
664
|
+
]).filter((tool) => !blockedSet.has(tool)),
|
|
665
|
+
blockedTools: [...blockedSet],
|
|
666
|
+
allowedPaths: [...(ownerRole.allowedPaths ?? [])],
|
|
667
|
+
});
|
|
668
|
+
const blockedTools = [...new Set([...(projectedRole.blockedTools ?? []), ...blockedSet])];
|
|
669
|
+
const innerTools = uniqueToolList(projectedRole.allowedTools).filter((tool) => tool !== 'code_act' && !blockedSet.has(tool));
|
|
670
|
+
const allowedTools = uniqueToolList(['code_act', ...innerTools]);
|
|
662
671
|
const agentContext = {
|
|
663
672
|
source: 'operator',
|
|
664
673
|
platform: 'cli',
|
|
665
|
-
roleName: exports.
|
|
674
|
+
roleName: exports.ONE_AGENT_TURN_POLICY.roleName,
|
|
666
675
|
role: { ...projectedRole, allowedTools, blockedTools, model },
|
|
667
676
|
session: {
|
|
668
|
-
sessionId:
|
|
677
|
+
sessionId: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
669
678
|
channelId: 'report',
|
|
670
679
|
startedAt: new Date(),
|
|
671
680
|
},
|
|
@@ -676,7 +685,7 @@ function buildOperatorReportAgentPolicy(model, backend, privateConnectorPolicy)
|
|
|
676
685
|
};
|
|
677
686
|
return {
|
|
678
687
|
agentContext,
|
|
679
|
-
gatewayToolsPrompt: '',
|
|
688
|
+
gatewayToolsPrompt: buildProjectedLanePrompt(innerTools, 'owner_console', requiredPrivatePolicy),
|
|
680
689
|
briefProjectionPolicy: requiredPrivatePolicy,
|
|
681
690
|
};
|
|
682
691
|
}
|
|
@@ -718,7 +727,7 @@ function buildTurnAgentPolicy(kind, model, backend, privateConnectorPolicy, rawC
|
|
|
718
727
|
roleName: exports.ONE_AGENT_TURN_POLICY.roleName,
|
|
719
728
|
role: { ...projectedRole, allowedTools, blockedTools, model },
|
|
720
729
|
session: {
|
|
721
|
-
sessionId:
|
|
730
|
+
sessionId: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
722
731
|
channelId: `worker:${kind}`,
|
|
723
732
|
startedAt: new Date(),
|
|
724
733
|
},
|
|
@@ -782,11 +791,6 @@ function failCodeActParentModelRun(adapter, modelRunId, error) {
|
|
|
782
791
|
}
|
|
783
792
|
(0, mama_core_1.failModelRunInAdapter)(adapter, modelRunId, codeActErrorSummary(error));
|
|
784
793
|
}
|
|
785
|
-
function buildSystemAgentProcessDefaults(config) {
|
|
786
|
-
return {
|
|
787
|
-
dangerouslySkipPermissions: config.multi_agent?.dangerouslySkipPermissions ?? true,
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
794
|
function resolveOwnerEventTerminalReceipt(batch, deps) {
|
|
791
795
|
// Crash-recovery mirror of classifyOwnerEventOutcome. A ledger write that
|
|
792
796
|
// named this batch's events as its cause (evidence_effects) or a confirmed
|
|
@@ -903,7 +907,7 @@ async function printStartOnboardingStatus() {
|
|
|
903
907
|
* Phase 1: Foundation (config, db, oauth, metrics)
|
|
904
908
|
* Phase 2: Session + Tool + Agent Loop
|
|
905
909
|
* Phase 3: MAMA Core API
|
|
906
|
-
* Phase 4:
|
|
910
|
+
* Phase 4: MessageRouter
|
|
907
911
|
* Phase 5: Graph Handler + Embedding
|
|
908
912
|
* Phase 6: Cron Scheduler
|
|
909
913
|
* Phase 7: Gateways
|
|
@@ -920,7 +924,7 @@ async function runAgentLoop(config, options = {}) {
|
|
|
920
924
|
const runtimeBackend = requireRuntimeBackend(config.agent.backend);
|
|
921
925
|
const { connectorConfigLoadResult, privateConnectorPolicy } = (0, connector_bootstrap_js_1.resolveRuntimeConnectorBootstrap)((0, config_loader_js_1.loadConnectorConfig)());
|
|
922
926
|
// ONE owner role for every model turn: chat, event, and scheduled.
|
|
923
|
-
const ownerRole = config.roles?.definitions.owner_console ?? types_js_1.DEFAULT_ROLES.definitions.owner_console;
|
|
927
|
+
const ownerRole = (0, owner_runtime_js_1.projectOwnerRuntimeRole)(config.roles?.definitions.owner_console ?? types_js_1.DEFAULT_ROLES.definitions.owner_console);
|
|
924
928
|
const temporalPolicy = temporalStartup.temporalFlag === 'on'
|
|
925
929
|
? buildTurnAgentPolicy('temporal', config.agent.model, runtimeBackend, privateConnectorPolicy, [], ownerRole)
|
|
926
930
|
: null;
|
|
@@ -967,15 +971,9 @@ async function runAgentLoop(config, options = {}) {
|
|
|
967
971
|
const { metricsStore, metricsCleanup, healthService, healthCheckService, metricsInterval } = await (0, metrics_init_js_1.initMetrics)(config, db, utilities_js_1.EMBEDDING_PORT);
|
|
968
972
|
// ── Phase 2: Session + Tool + Agent Loop ──────────────────────────────────
|
|
969
973
|
const sessionStore = new index_js_2.SessionStore(db);
|
|
970
|
-
// TG-05/TG-06:
|
|
971
|
-
//
|
|
972
|
-
|
|
973
|
-
// transaction (design Decision 4/6).
|
|
974
|
-
const reportContextStore = new telegram_report_context_store_js_1.TelegramReportContextStore(db, {
|
|
975
|
-
// TG-05 Slice K: one-time V2 carry migration; the file is renamed
|
|
976
|
-
// `.migrated` after commit and no component reads or writes V2 afterward.
|
|
977
|
-
legacyCarryPath: (0, config_manager_js_1.expandPath)('~/.mama/operator/last-full-report.json'),
|
|
978
|
-
});
|
|
974
|
+
// TG-05/TG-06: durable report delivery ledger. Conversation continuity is
|
|
975
|
+
// owned by the standing owner runtime, so this store never injects reports.
|
|
976
|
+
const reportContextStore = new telegram_report_context_store_js_1.TelegramReportContextStore(db);
|
|
979
977
|
// Establish one canonical private workspace for gateway files, OCR, Drive,
|
|
980
978
|
// Telegram media, and the persona runtime. An explicit environment override
|
|
981
979
|
// remains authoritative; otherwise honor config.workspace.path.
|
|
@@ -1040,16 +1038,15 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1040
1038
|
memberGrantReader: principalRegistry,
|
|
1041
1039
|
dependencies: {
|
|
1042
1040
|
privateConnectorPolicy,
|
|
1043
|
-
//
|
|
1044
|
-
//
|
|
1045
|
-
// reads or writes V2 afterward. Wiring FileReportCarryStore here would
|
|
1046
|
-
// couple two owners to one file behind an implicit construction order.
|
|
1047
|
-
ownerReportInbox: new owner_report_inbox_js_1.OwnerReportInbox(reportContextStore),
|
|
1041
|
+
// Report delivery is receipted by the delivery ledger. Conversation
|
|
1042
|
+
// recovery belongs only to the owner-runtime journal.
|
|
1048
1043
|
},
|
|
1049
1044
|
});
|
|
1050
1045
|
messageRouter.setSessionsDb(db);
|
|
1051
1046
|
// validationService wired after creation (Phase 5 below)
|
|
1052
|
-
|
|
1047
|
+
// One MAMA: memory judgment stays in the owner turn through mama_save and
|
|
1048
|
+
// deterministic owner-policy observation. Do not boot a second model identity
|
|
1049
|
+
// that re-reads every conversation after the owner agent has answered.
|
|
1053
1050
|
// ── Phase 5: Graph Handler + Embedding ────────────────────────────────────
|
|
1054
1051
|
// Create singleton UI command queue for Agent↔Viewer communication
|
|
1055
1052
|
const uiCommandQueue = new ui_command_handler_js_1.UICommandQueue();
|
|
@@ -1057,7 +1054,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1057
1054
|
const graphHandlerOptions = {
|
|
1058
1055
|
healthService: healthService ?? undefined,
|
|
1059
1056
|
healthCheckService,
|
|
1060
|
-
auditConversation: (job) => messageRouter.auditConversation(job),
|
|
1061
1057
|
sessionsDb: db,
|
|
1062
1058
|
uiCommandQueue,
|
|
1063
1059
|
};
|
|
@@ -1291,7 +1287,74 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1291
1287
|
console.log(`✓ Agent versions seeded (${Object.keys(agents).length} agents)`);
|
|
1292
1288
|
await (0, utilities_js_1.startEmbeddingServerIfAvailable)(messageRouter, sessionStore, graphHandler);
|
|
1293
1289
|
// ── Phase 6: Cron Scheduler ───────────────────────────────────────────────
|
|
1294
|
-
const
|
|
1290
|
+
const backgroundOwnerContext = (0, owner_event_policy_js_1.buildOwnerEventAgentContext)({
|
|
1291
|
+
backend: runtimeBackend,
|
|
1292
|
+
model: config.agent.model,
|
|
1293
|
+
ownerRole,
|
|
1294
|
+
privateConnectorPolicy,
|
|
1295
|
+
});
|
|
1296
|
+
const issueOwnerRuntimeEnvelope = async (channelId, wallSeconds) => {
|
|
1297
|
+
if (!envelopeBootstrap.envelopeAuthority || envelopeBootstrap.metadata.issuance === 'off') {
|
|
1298
|
+
return undefined;
|
|
1299
|
+
}
|
|
1300
|
+
const projectId = (0, reactive_config_js_1.resolveReactiveProjectRoot)(config, process.env);
|
|
1301
|
+
return envelopeBootstrap.envelopeAuthority.buildAndPersist({
|
|
1302
|
+
agent_id: 'mama-owner',
|
|
1303
|
+
instance_id: (0, node_crypto_1.randomUUID)(),
|
|
1304
|
+
source: 'cron',
|
|
1305
|
+
channel_id: channelId,
|
|
1306
|
+
trigger_context: { user_text: `<owner runtime ${channelId} stimulus>` },
|
|
1307
|
+
scope: {
|
|
1308
|
+
project_refs: [{ kind: 'project', id: projectId }],
|
|
1309
|
+
raw_connectors: [
|
|
1310
|
+
...privateConnectorPolicy.projectRawConnectors('owner_console', codeActRawConnectors),
|
|
1311
|
+
],
|
|
1312
|
+
memory_scopes: uniqueMemoryScopes((0, scope_context_js_1.deriveMemoryScopes)({ source: 'operator', channelId, projectId })),
|
|
1313
|
+
allowed_destinations: [],
|
|
1314
|
+
},
|
|
1315
|
+
tier: 1,
|
|
1316
|
+
budget: { wall_seconds: wallSeconds },
|
|
1317
|
+
expires_at: new Date(Date.now() + wallSeconds * 1000 + 30_000).toISOString(),
|
|
1318
|
+
});
|
|
1319
|
+
};
|
|
1320
|
+
const runOwnerStimulus = async (content, channelId) => {
|
|
1321
|
+
return await agentLoop.run(content, {
|
|
1322
|
+
sessionKey: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
1323
|
+
source: 'operator',
|
|
1324
|
+
channelId,
|
|
1325
|
+
agentContext: backgroundOwnerContext,
|
|
1326
|
+
sessionPolicyRole: ownerRole,
|
|
1327
|
+
prepareEnvelope: async () => {
|
|
1328
|
+
const envelope = await issueOwnerRuntimeEnvelope(channelId, 600);
|
|
1329
|
+
if (!envelope)
|
|
1330
|
+
throw new Error(`Owner runtime stimulus ${channelId} requires envelope authority`);
|
|
1331
|
+
return envelope;
|
|
1332
|
+
},
|
|
1333
|
+
requestTimeoutMs: 600_000,
|
|
1334
|
+
});
|
|
1335
|
+
};
|
|
1336
|
+
const cronOwnerRunner = {
|
|
1337
|
+
backendType: runtimeBackend,
|
|
1338
|
+
prompt: async (content) => {
|
|
1339
|
+
const result = await runOwnerStimulus(content, 'cron');
|
|
1340
|
+
return {
|
|
1341
|
+
response: result.response,
|
|
1342
|
+
usage: result.totalUsage,
|
|
1343
|
+
session_id: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
1344
|
+
};
|
|
1345
|
+
},
|
|
1346
|
+
setSessionId: () => { },
|
|
1347
|
+
setSystemPrompt: () => { },
|
|
1348
|
+
isHealthy: () => true,
|
|
1349
|
+
getMetrics: () => ({
|
|
1350
|
+
requestCount: 0,
|
|
1351
|
+
failureCount: 0,
|
|
1352
|
+
avgLatencyMs: 0,
|
|
1353
|
+
lastRequestAt: null,
|
|
1354
|
+
}),
|
|
1355
|
+
stop: () => { },
|
|
1356
|
+
};
|
|
1357
|
+
const { scheduler, cronWorker, cronEmitter } = (0, scheduler_init_js_1.initCronScheduler)(config, () => cronOwnerRunner);
|
|
1295
1358
|
// ── Phase 7: Gateways ────────────────────────────────────────────────────
|
|
1296
1359
|
const gatewayInit = await (0, gateway_init_js_1.initGateways)(config, messageRouter, toolExecutor, agentLoop, runtimeBackend, db, principalResolver);
|
|
1297
1360
|
const { discordGateway, slackGateway, telegramGateway, gateways } = gatewayInit;
|
|
@@ -1309,44 +1372,14 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1309
1372
|
agentLoop,
|
|
1310
1373
|
cronEmitter,
|
|
1311
1374
|
});
|
|
1312
|
-
// ── Phase 8.5: Delegate tool fallback wiring ─────────────────────────────
|
|
1313
|
-
// If no Discord/Slack handler wired the delegate tool, create standalone
|
|
1314
|
-
// DelegationManager + AgentProcessManager so delegate() works from any path
|
|
1315
|
-
// (Viewer, Telegram, iMessage, Terminal).
|
|
1316
|
-
const fallbackMultiAgentConfig = config.multi_agent;
|
|
1317
|
-
const hasSystemRunAgents = Boolean(fallbackMultiAgentConfig?.agents?.['dashboard-agent'] ||
|
|
1318
|
-
fallbackMultiAgentConfig?.agents?.['wiki-agent']);
|
|
1319
|
-
if (fallbackMultiAgentConfig &&
|
|
1320
|
-
!toolExecutor.getAgentProcessManager() &&
|
|
1321
|
-
(fallbackMultiAgentConfig.enabled || hasSystemRunAgents)) {
|
|
1322
|
-
const { AgentProcessManager } = await import('../../multi-agent/agent-process-manager.js');
|
|
1323
|
-
const pm = new AgentProcessManager(fallbackMultiAgentConfig, buildSystemAgentProcessDefaults(config), {
|
|
1324
|
-
backend: runtimeBackend,
|
|
1325
|
-
model: config.agent.model,
|
|
1326
|
-
effort: config.agent.effort,
|
|
1327
|
-
clineCwd: workspaceRoot,
|
|
1328
|
-
clineCommand: process.env.MAMA_CLINE_COMMAND ?? config.agent.cline_command,
|
|
1329
|
-
clineProvider: config.agent.cline_provider,
|
|
1330
|
-
clineDataDir: config.agent.cline_data_dir,
|
|
1331
|
-
privateConnectorPolicy,
|
|
1332
|
-
});
|
|
1333
|
-
toolExecutor.setAgentProcessManager(pm);
|
|
1334
|
-
agentLoop.setAgentProcessManager(pm);
|
|
1335
|
-
graphHandlerOptions.applyMultiAgentConfig = async (rawConfig) => {
|
|
1336
|
-
const nextConfig = rawConfig;
|
|
1337
|
-
pm.updateConfig(nextConfig);
|
|
1338
|
-
};
|
|
1339
|
-
graphHandlerOptions.restartMultiAgentAgent = async (agentId) => {
|
|
1340
|
-
pm.reloadPersona(agentId);
|
|
1341
|
-
};
|
|
1342
|
-
// The delegate wiring was here. Over the full log history it was wired ZERO times and
|
|
1343
|
-
// its only runtime trace was one call refused by role permission. The process manager
|
|
1344
|
-
// above stays: that one IS wired on every boot (113 so far) and runs the dashboard and
|
|
1345
|
-
// wiki agents.
|
|
1346
|
-
console.log('[start] ✓ System agent process manager wired');
|
|
1347
|
-
}
|
|
1348
1375
|
// ── Phase 9: Heartbeat + Connectors ──────────────────────────────────────
|
|
1349
|
-
const { heartbeatScheduler, tokenKeepAlive, healthWarningInterval } = (0, scheduler_init_js_1.initHeartbeat)(config, agentLoop, discordGateway, scheduler, healthCheckService)
|
|
1376
|
+
const { heartbeatScheduler, tokenKeepAlive, healthWarningInterval } = (0, scheduler_init_js_1.initHeartbeat)(config, agentLoop, discordGateway, scheduler, healthCheckService, async () => {
|
|
1377
|
+
return {
|
|
1378
|
+
agentContext: backgroundOwnerContext,
|
|
1379
|
+
sessionPolicyRole: ownerRole,
|
|
1380
|
+
prepareEnvelope: () => issueOwnerRuntimeEnvelope('heartbeat', 300),
|
|
1381
|
+
};
|
|
1382
|
+
});
|
|
1350
1383
|
// M2.4 freshness: the connector sink nudges the trigger loop when a poll indexes new rows. The
|
|
1351
1384
|
// loop is constructed AFTER initConnectors (below), so hand initConnectors a stable forwarder now
|
|
1352
1385
|
// and point it at the loop once it exists. Null until then -> nudge no-ops (no loop = nothing to
|
|
@@ -1668,15 +1701,11 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1668
1701
|
reconcileChannelKey,
|
|
1669
1702
|
privateConnectorPolicy,
|
|
1670
1703
|
});
|
|
1671
|
-
// Worker prompt selects the provider's supported tool path: Claude's
|
|
1672
|
-
// text gateway or Codex's injected native host tools. Both avoid the
|
|
1673
|
-
// spawn-default code-act path, where per-run envelope/capture overrides
|
|
1674
|
-
// cannot reach (shadow-gate §8.2).
|
|
1675
|
-
const { buildWorkerSystemPrompt } = await import('../../operator/worker-run.js');
|
|
1676
1704
|
const workOrderPolicy = buildTurnAgentPolicy(wo.workKind, config.agent.model, runtimeBackend, privateConnectorPolicy, workOrderScope.raw_connectors, ownerRole);
|
|
1677
1705
|
const runOptions = attachWorkOrderAttemptContext({
|
|
1678
|
-
|
|
1706
|
+
gatewayToolsPrompt: workOrderPolicy.gatewayToolsPrompt,
|
|
1679
1707
|
agentContext: workOrderPolicy.agentContext,
|
|
1708
|
+
sessionPolicyRole: ownerRole,
|
|
1680
1709
|
workOrderBriefProjectionPolicy: workOrderPolicy.briefProjectionPolicy,
|
|
1681
1710
|
}, wo.id);
|
|
1682
1711
|
// A temporal run is bound to ONE task on ONE channel, and the packet check
|
|
@@ -1729,7 +1758,8 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1729
1758
|
// failure rejects -> failWorkOrder (no envelope-less fallback run).
|
|
1730
1759
|
if (envelopeBootstrap.envelopeAuthority && envelopeBootstrap.metadata.issuance !== 'off') {
|
|
1731
1760
|
const wallSeconds = Math.min(Math.max(Number(process.env.MAMA_REPORT_WALL_SECONDS) || 900, 60), 1800);
|
|
1732
|
-
|
|
1761
|
+
const workOrderEnvelopeAuthority = envelopeBootstrap.envelopeAuthority;
|
|
1762
|
+
runOptions.prepareEnvelope = () => workOrderEnvelopeAuthority.buildAndPersist({
|
|
1733
1763
|
agent_id: 'mama-owner',
|
|
1734
1764
|
instance_id: (0, node_crypto_1.randomUUID)(),
|
|
1735
1765
|
// 'watch' = daemon-internal issuing source (closed EnvelopeSource
|
|
@@ -1824,7 +1854,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1824
1854
|
// connector_event_index) and after mama-core initDB. Read-only: recall/surface/log.
|
|
1825
1855
|
const { isOperatorTriggerLoopEnabled, resolveOperatorReportChatId } = await import('../../operator/runtime-config.js');
|
|
1826
1856
|
if (isOperatorTriggerLoopEnabled(process.env)) {
|
|
1827
|
-
let stopTriggerAgentRuntime;
|
|
1828
1857
|
// Component isolation (PR #119 review): a trigger-loop bootstrap failure (bad import,
|
|
1829
1858
|
// DB permission, registry constructor) must not abort the whole daemon before Phase
|
|
1830
1859
|
// 10/11 - the gateways/viewer/agent serve independently of this optional leg. The
|
|
@@ -1834,7 +1863,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1834
1863
|
const { ConnectorDeltaRepo } = await import('../../operator/connector-delta-repo.js');
|
|
1835
1864
|
const { TriggerRegistry } = await import('../../operator/trigger-registry.js');
|
|
1836
1865
|
const { createMamaMemoryPort } = await import('../../operator/mama-memory-port.js');
|
|
1837
|
-
const { createTriggerAgentRuntime } = await import('../../operator/trigger-author.js');
|
|
1838
1866
|
const { reviewTriggerCLI } = await import('../../operator/trigger-review.js');
|
|
1839
1867
|
const { ReportScheduler, FileReportScheduleStore, parseReportHours } = await import('../../operator/report-scheduler.js');
|
|
1840
1868
|
// Set when a report is composed, read when that same report is delivered. Safe
|
|
@@ -1851,10 +1879,9 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1851
1879
|
// Owner-report leg (M1.5): destination chat comes from env (~/.mama/start.sh),
|
|
1852
1880
|
// never source. No chat configured or no telegram gateway -> loop stays read-only.
|
|
1853
1881
|
const reportChatId = resolveOperatorReportChatId(process.env, config.telegram?.allowed_chats);
|
|
1854
|
-
// TG-05/TG-06
|
|
1855
|
-
//
|
|
1856
|
-
//
|
|
1857
|
-
// the coordinator owns every Telegram send.
|
|
1882
|
+
// TG-05/TG-06: one durable production boundary for every report mode.
|
|
1883
|
+
// The delivery ledger reserves exact output and the coordinator owns
|
|
1884
|
+
// every Telegram send; no report text is copied into another model.
|
|
1858
1885
|
let reportDelivery;
|
|
1859
1886
|
const reportTarget = reportChatId && telegramGateway
|
|
1860
1887
|
? { source: 'telegram', channelId: reportChatId }
|
|
@@ -1888,49 +1915,32 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1888
1915
|
const fullReportHours = parseReportHours(process.env.MAMA_TRIGGER_LOOP_FULL_REPORT_HOURS || '');
|
|
1889
1916
|
// Constructed whenever the report SINK exists, even with no scheduled
|
|
1890
1917
|
// hours (empty hours -> shouldFire never fires): on-demand reports
|
|
1891
|
-
//
|
|
1892
|
-
//
|
|
1918
|
+
// API-triggered reports need the persistent anchor state regardless of
|
|
1919
|
+
// whether scheduled hours are configured.
|
|
1893
1920
|
const reportScheduler = reportDelivery
|
|
1894
1921
|
? new ReportScheduler(fullReportHours, new FileReportScheduleStore((0, config_manager_js_1.expandPath)('~/.mama/operator/report-schedule-state.json')))
|
|
1895
1922
|
: undefined;
|
|
1896
|
-
const triggerAgentRuntime = createTriggerAgentRuntime(runtimeBackend, {
|
|
1897
|
-
model: config.agent.model,
|
|
1898
|
-
cwd: workspaceRoot,
|
|
1899
|
-
command: runtimeBackend === 'cline'
|
|
1900
|
-
? (process.env.MAMA_CLINE_COMMAND ?? config.agent.cline_command)
|
|
1901
|
-
: process.env.MAMA_CODEX_COMMAND,
|
|
1902
|
-
provider: config.agent.cline_provider,
|
|
1903
|
-
dataDir: config.agent.cline_data_dir,
|
|
1904
|
-
effort: config.agent.effort,
|
|
1905
|
-
});
|
|
1906
|
-
stopTriggerAgentRuntime = () => triggerAgentRuntime.stop();
|
|
1907
1923
|
const ownerEventEnvelopeAuthority = envelopeBootstrap.envelopeAuthority;
|
|
1908
1924
|
const ownerEventExecution = (0, owner_event_policy_js_1.resolveOwnerEventExecution)({
|
|
1909
1925
|
issuance: envelopeBootstrap.metadata.issuance,
|
|
1910
1926
|
hasAuthority: ownerEventEnvelopeAuthority !== undefined,
|
|
1911
1927
|
});
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
return (0, query_tools_js_1.getTrelloKanban)({ maxCardsPerList: 100 });
|
|
1929
|
-
},
|
|
1930
|
-
buildProvenanceLookup: provenance_lookup_js_1.buildProvenanceLookup,
|
|
1931
|
-
correlate: external_correlation_js_1.correlateTasksWithExternalItems,
|
|
1932
|
-
readChanges: (_scope, input, nowMs) => (0, changes_projection_js_1.readChanges)(taskLedger, input, nowMs),
|
|
1933
|
-
now: Date.now,
|
|
1928
|
+
const ownerMaintenanceAsk = async (prompt) => {
|
|
1929
|
+
const result = await agentLoop.run(prompt, {
|
|
1930
|
+
sessionKey: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
1931
|
+
source: 'operator',
|
|
1932
|
+
channelId: 'trigger-maintenance',
|
|
1933
|
+
agentContext: backgroundOwnerContext,
|
|
1934
|
+
sessionPolicyRole: ownerRole,
|
|
1935
|
+
prepareEnvelope: async () => {
|
|
1936
|
+
const envelope = await issueOwnerRuntimeEnvelope('trigger-maintenance', 600);
|
|
1937
|
+
if (!envelope)
|
|
1938
|
+
throw new Error('Owner maintenance requires envelope authority');
|
|
1939
|
+
return envelope;
|
|
1940
|
+
},
|
|
1941
|
+
requestTimeoutMs: 600_000,
|
|
1942
|
+
});
|
|
1943
|
+
return result.response;
|
|
1934
1944
|
};
|
|
1935
1945
|
const triggerLoop = new OperatorTriggerLoop({
|
|
1936
1946
|
backend: runtimeBackend,
|
|
@@ -1938,31 +1948,32 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1938
1948
|
memory: createMamaMemoryPort(),
|
|
1939
1949
|
registry: triggerRegistry,
|
|
1940
1950
|
...(ownerEventExecution.enabled ? { ownerEventInbox } : {}),
|
|
1941
|
-
askAgent:
|
|
1942
|
-
//
|
|
1943
|
-
//
|
|
1944
|
-
//
|
|
1945
|
-
// Full reports run in one fresh, tool-free persona turn. Current state is compiled and
|
|
1946
|
-
// persisted by the host before this call; digest composition remains on the same persona.
|
|
1951
|
+
askAgent: ownerMaintenanceAsk,
|
|
1952
|
+
// TG-03/TG-04/TG-05: a report is another stimulus for the standing
|
|
1953
|
+
// owner subject. It keeps the same backend thread and progressive tool
|
|
1954
|
+
// catalog while the current envelope narrows effects for this delivery.
|
|
1947
1955
|
reportAsk: createPersonaReportAsk({
|
|
1948
1956
|
run: async (prompt, sourceMessageRef) => {
|
|
1949
|
-
const reportAgentPolicy = buildOperatorReportAgentPolicy(config.agent.model, runtimeBackend, privateConnectorPolicy);
|
|
1957
|
+
const reportAgentPolicy = buildOperatorReportAgentPolicy(config.agent.model, runtimeBackend, privateConnectorPolicy, ownerRole);
|
|
1950
1958
|
const result = await agentLoop.runWithContent([{ type: 'text', text: prompt }], {
|
|
1951
|
-
sessionKey:
|
|
1959
|
+
sessionKey: owner_runtime_js_1.OWNER_RUNTIME_SESSION_KEY,
|
|
1952
1960
|
source: 'operator',
|
|
1953
1961
|
channelId: 'report',
|
|
1954
|
-
//
|
|
1955
|
-
//
|
|
1956
|
-
// gather no matter what the prompt instructs (roleAllowsOuterCodeAct
|
|
1957
|
-
// fails closed on an absent role - agent-loop.ts). Same built-in
|
|
1958
|
-
// least-privilege treatment the Stage-2 workers get.
|
|
1962
|
+
// The current report role narrows effect authority; the stable
|
|
1963
|
+
// sessionPolicyRole keeps the owner thread compatible.
|
|
1959
1964
|
agentContext: reportAgentPolicy.agentContext,
|
|
1965
|
+
sessionPolicyRole: ownerRole,
|
|
1960
1966
|
gatewayToolsPrompt: reportAgentPolicy.gatewayToolsPrompt,
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1967
|
+
prepareEnvelope: async () => {
|
|
1968
|
+
const envelope = await issueOwnerRuntimeEnvelope('report', 600);
|
|
1969
|
+
if (!envelope)
|
|
1970
|
+
throw new Error('Owner report requires envelope authority');
|
|
1971
|
+
return envelope;
|
|
1972
|
+
},
|
|
1973
|
+
requestTimeoutMs: 600_000,
|
|
1974
|
+
ownerJournalPrompt: sourceMessageRef
|
|
1975
|
+
? `Report stimulus: ${sourceMessageRef}`
|
|
1976
|
+
: prompt,
|
|
1966
1977
|
...(sourceMessageRef ? { sourceMessageRef } : {}),
|
|
1967
1978
|
});
|
|
1968
1979
|
return {
|
|
@@ -1976,28 +1987,28 @@ async function runAgentLoop(config, options = {}) {
|
|
|
1976
1987
|
...(result.modelRunProvenance === undefined
|
|
1977
1988
|
? {}
|
|
1978
1989
|
: { modelRunProvenance: result.modelRunProvenance }),
|
|
1990
|
+
...(result.ownerJournalProvenance === undefined
|
|
1991
|
+
? {}
|
|
1992
|
+
: { ownerJournalProvenance: result.ownerJournalProvenance }),
|
|
1979
1993
|
};
|
|
1980
1994
|
},
|
|
1981
1995
|
log: (line) => console.log(line),
|
|
1982
1996
|
onRunProvenance: (provenance) => {
|
|
1983
1997
|
lastReportProvenance = provenance;
|
|
1984
1998
|
},
|
|
1999
|
+
onRecoveryFailure: () => {
|
|
2000
|
+
recordIssue({
|
|
2001
|
+
surface: 'delivery',
|
|
2002
|
+
signature: 'journal_commit_failed',
|
|
2003
|
+
severity: 'error',
|
|
2004
|
+
error: 'Report completed but owner runtime recovery journal did not persist',
|
|
2005
|
+
});
|
|
2006
|
+
},
|
|
1985
2007
|
}),
|
|
1986
|
-
review: (trigger, context) => reviewTriggerCLI(trigger, context,
|
|
2008
|
+
review: (trigger, context) => reviewTriggerCLI(trigger, context, ownerMaintenanceAsk),
|
|
1987
2009
|
reportDelivery,
|
|
1988
2010
|
reportTarget,
|
|
1989
2011
|
reportScheduler,
|
|
1990
|
-
fullReportReadScope: (() => {
|
|
1991
|
-
const projectId = (0, reactive_config_js_1.resolveReactiveProjectRoot)(config, process.env);
|
|
1992
|
-
return {
|
|
1993
|
-
projectRefs: [{ kind: 'project', id: projectId }],
|
|
1994
|
-
memoryScopes: uniqueMemoryScopes((0, scope_context_js_1.deriveMemoryScopes)({ source: 'operator', channelId: 'report', projectId })),
|
|
1995
|
-
rawConnectors: [
|
|
1996
|
-
...privateConnectorPolicy.projectRawConnectors('operator-report', codeActRawConnectors),
|
|
1997
|
-
],
|
|
1998
|
-
};
|
|
1999
|
-
})(),
|
|
2000
|
-
compileFullReportContext: async ({ readScope, windowEvidence, since }) => (0, report_context_js_1.compileOwnerReportContext)({ readScope, windowEvidence, since }, reportContextDeps),
|
|
2001
2012
|
// TG-06: composition supplies provenance immediately to the prepared
|
|
2002
2013
|
// delivery; this callback receives that durable artifact only after send success.
|
|
2003
2014
|
fullReportProvenance: () => lastReportProvenance,
|
|
@@ -2038,14 +2049,11 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2038
2049
|
}
|
|
2039
2050
|
const stopTriggerLoop = triggerLoop.start();
|
|
2040
2051
|
stopOwnerEventRuntime = async () => {
|
|
2041
|
-
await
|
|
2052
|
+
await stopTriggerLoop();
|
|
2042
2053
|
};
|
|
2043
2054
|
// M2.4: point the connector sink's forwarder at this loop now that it exists.
|
|
2044
2055
|
triggerLoopNudge.current = () => triggerLoop.nudge();
|
|
2045
2056
|
triggerLoopFullReport.current = () => triggerLoop.startFullReport();
|
|
2046
|
-
// S1-T3: owner-intent forwarder - report_request routes to the SAME
|
|
2047
|
-
// report machinery (fresh session, delta anchor, consume semantics).
|
|
2048
|
-
toolExecutor.setReportRequestHandler(() => triggerLoop.startFullReport());
|
|
2049
2057
|
if (ownerEventExecution.enabled && ownerEventEnvelopeAuthority) {
|
|
2050
2058
|
// MAMA itself owns connector events. This is the same AgentLoop and
|
|
2051
2059
|
// owner operating policy as the owner console, on a durable per-channel
|
|
@@ -2099,17 +2107,11 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2099
2107
|
inbox: ownerEventInbox,
|
|
2100
2108
|
runner: agentLoop,
|
|
2101
2109
|
agentContext: ownerEventContext,
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
channelKey: batch.channelKey,
|
|
2105
|
-
eventIds: batch.eventIds,
|
|
2106
|
-
since: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
|
|
2107
|
-
}, reportContextDeps)),
|
|
2108
|
-
buildPrompt: async (batch, packet) => {
|
|
2110
|
+
ownerRuntimeRole: ownerRole,
|
|
2111
|
+
buildPrompt: async (batch) => {
|
|
2109
2112
|
const readScope = ownerEventReadScope(batch);
|
|
2110
2113
|
return (0, owner_event_prompt_js_1.buildOwnerEventPrompt)({
|
|
2111
2114
|
batch,
|
|
2112
|
-
packet,
|
|
2113
2115
|
learning: await buildLearningBlockFor('event', readScope.memoryScopes, batch.lines.join('\n').slice(0, 500)),
|
|
2114
2116
|
ownerBrief: (0, console_brief_js_1.projectConsoleBriefForPrompt)((0, console_brief_js_1.loadConsoleBrief)(), privateConnectorPolicy),
|
|
2115
2117
|
skillContent: await ownerEventPromptEnhancer.detectSkillMatch(batch.lines.join('\n')),
|
|
@@ -2166,7 +2168,7 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2166
2168
|
// operator DB closes.
|
|
2167
2169
|
if (ownerEventTickPromise)
|
|
2168
2170
|
await ownerEventTickPromise;
|
|
2169
|
-
await
|
|
2171
|
+
await stopTriggerLoop();
|
|
2170
2172
|
};
|
|
2171
2173
|
}
|
|
2172
2174
|
else {
|
|
@@ -2180,7 +2182,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2180
2182
|
catch (error) {
|
|
2181
2183
|
await stopOwnerEventRuntime?.().catch(() => { });
|
|
2182
2184
|
stopOwnerEventRuntime = null;
|
|
2183
|
-
await stopTriggerAgentRuntime?.().catch(() => { });
|
|
2184
2185
|
console.error('[trigger-loop] FAILED to start - daemon continues WITHOUT the trigger loop. Fix and restart:', error);
|
|
2185
2186
|
}
|
|
2186
2187
|
}
|
|
@@ -2193,13 +2194,13 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2193
2194
|
healthCheckService,
|
|
2194
2195
|
rawStore: rawStoreForApi,
|
|
2195
2196
|
enabledConnectors: enabledConnectorNames,
|
|
2196
|
-
agentLoop,
|
|
2197
2197
|
getAdapter,
|
|
2198
2198
|
envelopeMetadata: envelopeBootstrap.metadata,
|
|
2199
2199
|
envelopeAuthority: envelopeBootstrap.envelopeAuthority,
|
|
2200
2200
|
contextCompileService,
|
|
2201
2201
|
connectorConfigLoadResult,
|
|
2202
2202
|
privateConnectorPolicy,
|
|
2203
|
+
runOwnerStimulus,
|
|
2203
2204
|
});
|
|
2204
2205
|
const apiRoutesHandle = await (0, api_routes_init_js_1.registerApiRoutes)({
|
|
2205
2206
|
config,
|
|
@@ -2209,7 +2210,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2209
2210
|
mamaApi,
|
|
2210
2211
|
messageRouter,
|
|
2211
2212
|
reportContextStore,
|
|
2212
|
-
agentLoop,
|
|
2213
2213
|
toolExecutor,
|
|
2214
2214
|
discordGateway,
|
|
2215
2215
|
slackGateway,
|
|
@@ -2251,7 +2251,6 @@ async function runAgentLoop(config, options = {}) {
|
|
|
2251
2251
|
gateways,
|
|
2252
2252
|
pluginLoader,
|
|
2253
2253
|
agentLoop,
|
|
2254
|
-
memoryAgentLoop,
|
|
2255
2254
|
stopExtraction,
|
|
2256
2255
|
sessionStore,
|
|
2257
2256
|
db,
|