@jungjaehoon/mama-os 0.51.2 → 0.52.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 +58 -0
- package/dist/agent/agent-loop.d.ts.map +1 -1
- package/dist/agent/agent-loop.js +503 -142
- package/dist/agent/agent-loop.js.map +1 -1
- package/dist/agent/claude-cli-wrapper.d.ts.map +1 -1
- package/dist/agent/claude-cli-wrapper.js +3 -2
- package/dist/agent/claude-cli-wrapper.js.map +1 -1
- package/dist/agent/cline-cli-adapter.d.ts +2 -0
- package/dist/agent/cline-cli-adapter.d.ts.map +1 -1
- package/dist/agent/cline-cli-adapter.js +2 -0
- package/dist/agent/cline-cli-adapter.js.map +1 -1
- package/dist/agent/code-act/constants.d.ts +1 -1
- package/dist/agent/code-act/constants.d.ts.map +1 -1
- package/dist/agent/code-act/constants.js +5 -2
- package/dist/agent/code-act/constants.js.map +1 -1
- package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
- package/dist/agent/code-act/host-bridge.js +102 -4
- package/dist/agent/code-act/host-bridge.js.map +1 -1
- package/dist/agent/code-act/tool-catalog.d.ts +2 -0
- package/dist/agent/code-act/tool-catalog.d.ts.map +1 -1
- package/dist/agent/code-act/tool-catalog.js +20 -7
- package/dist/agent/code-act/tool-catalog.js.map +1 -1
- package/dist/agent/codex-app-server-process.d.ts +112 -0
- package/dist/agent/codex-app-server-process.d.ts.map +1 -1
- package/dist/agent/codex-app-server-process.js +518 -1
- package/dist/agent/codex-app-server-process.js.map +1 -1
- package/dist/agent/gateway-tool-executor.d.ts +17 -0
- package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
- package/dist/agent/gateway-tool-executor.js +236 -53
- package/dist/agent/gateway-tool-executor.js.map +1 -1
- package/dist/agent/gateway-tools.md +9 -3
- package/dist/agent/model-runner.d.ts +16 -0
- package/dist/agent/model-runner.d.ts.map +1 -1
- package/dist/agent/model-runner.js.map +1 -1
- package/dist/agent/persistent-cli-adapter.d.ts +5 -0
- package/dist/agent/persistent-cli-adapter.d.ts.map +1 -1
- package/dist/agent/persistent-cli-adapter.js +7 -0
- package/dist/agent/persistent-cli-adapter.js.map +1 -1
- package/dist/agent/persistent-cli-process.d.ts.map +1 -1
- package/dist/agent/persistent-cli-process.js +27 -2
- package/dist/agent/persistent-cli-process.js.map +1 -1
- package/dist/agent/skill-loader.d.ts +7 -2
- package/dist/agent/skill-loader.d.ts.map +1 -1
- package/dist/agent/skill-loader.js +29 -8
- package/dist/agent/skill-loader.js.map +1 -1
- package/dist/agent/subagent-run-reconcile.d.ts +23 -0
- package/dist/agent/subagent-run-reconcile.d.ts.map +1 -0
- package/dist/agent/subagent-run-reconcile.js +56 -0
- package/dist/agent/subagent-run-reconcile.js.map +1 -0
- package/dist/agent/tool-registry.d.ts.map +1 -1
- package/dist/agent/tool-registry.js +126 -3
- package/dist/agent/tool-registry.js.map +1 -1
- package/dist/agent/types.d.ts +52 -2
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/api/graph-api.d.ts.map +1 -1
- package/dist/api/graph-api.js +0 -22
- package/dist/api/graph-api.js.map +1 -1
- package/dist/cli/commands/start.d.ts +8 -7
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +154 -74
- 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 +2 -1
- 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 +1 -0
- package/dist/cli/runtime/agent-loop-init.js.map +1 -1
- package/dist/cli/runtime/api-routes-init.d.ts +1 -0
- package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-routes-init.js +82 -58
- package/dist/cli/runtime/api-routes-init.js.map +1 -1
- package/dist/db/migrations/operator-procedures.d.ts +4 -0
- package/dist/db/migrations/operator-procedures.d.ts.map +1 -0
- package/dist/db/migrations/operator-procedures.js +63 -0
- package/dist/db/migrations/operator-procedures.js.map +1 -0
- package/dist/gateways/message-router.d.ts +6 -3
- package/dist/gateways/message-router.d.ts.map +1 -1
- package/dist/gateways/message-router.js +43 -131
- package/dist/gateways/message-router.js.map +1 -1
- package/dist/gateways/telegram-format.d.ts.map +1 -1
- package/dist/gateways/telegram-format.js +2 -0
- package/dist/gateways/telegram-format.js.map +1 -1
- package/dist/gateways/telegram-response-presenter.d.ts.map +1 -1
- package/dist/gateways/telegram-response-presenter.js +4 -0
- package/dist/gateways/telegram-response-presenter.js.map +1 -1
- package/dist/mcp/code-act-mcp-config.d.ts +49 -0
- package/dist/mcp/code-act-mcp-config.d.ts.map +1 -0
- package/dist/mcp/code-act-mcp-config.js +124 -0
- package/dist/mcp/code-act-mcp-config.js.map +1 -0
- package/dist/multi-agent/runtime-process.d.ts +10 -0
- package/dist/multi-agent/runtime-process.d.ts.map +1 -1
- package/dist/multi-agent/runtime-process.js +8 -0
- package/dist/multi-agent/runtime-process.js.map +1 -1
- package/dist/operator/board-delta-gate.d.ts +34 -10
- package/dist/operator/board-delta-gate.d.ts.map +1 -1
- package/dist/operator/board-delta-gate.js +68 -24
- package/dist/operator/board-delta-gate.js.map +1 -1
- package/dist/operator/board-refresh-gate.d.ts +11 -6
- package/dist/operator/board-refresh-gate.d.ts.map +1 -1
- package/dist/operator/board-refresh-gate.js +12 -11
- package/dist/operator/board-refresh-gate.js.map +1 -1
- package/dist/operator/board-slot-instructions.d.ts +30 -0
- package/dist/operator/board-slot-instructions.d.ts.map +1 -1
- package/dist/operator/board-slot-instructions.js +110 -6
- package/dist/operator/board-slot-instructions.js.map +1 -1
- package/dist/operator/console-brief.d.ts +26 -13
- package/dist/operator/console-brief.d.ts.map +1 -1
- package/dist/operator/console-brief.js +159 -83
- package/dist/operator/console-brief.js.map +1 -1
- package/dist/operator/experience-evidence.d.ts +18 -0
- package/dist/operator/experience-evidence.d.ts.map +1 -0
- package/dist/operator/experience-evidence.js +82 -0
- package/dist/operator/experience-evidence.js.map +1 -0
- package/dist/operator/experience-hints.d.ts +44 -0
- package/dist/operator/experience-hints.d.ts.map +1 -0
- package/dist/operator/experience-hints.js +98 -0
- package/dist/operator/experience-hints.js.map +1 -0
- package/dist/operator/mama-memory-port.js +1 -3
- package/dist/operator/mama-memory-port.js.map +1 -1
- package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.js +3 -2
- package/dist/operator/operator-trigger-loop.js.map +1 -1
- package/dist/operator/owner-action-effects.d.ts +13 -1
- package/dist/operator/owner-action-effects.d.ts.map +1 -1
- package/dist/operator/owner-action-effects.js +17 -4
- package/dist/operator/owner-action-effects.js.map +1 -1
- package/dist/operator/owner-event-inbox.d.ts +7 -1
- package/dist/operator/owner-event-inbox.d.ts.map +1 -1
- package/dist/operator/owner-event-inbox.js +8 -0
- package/dist/operator/owner-event-inbox.js.map +1 -1
- package/dist/operator/owner-event-loop.d.ts +28 -2
- package/dist/operator/owner-event-loop.d.ts.map +1 -1
- package/dist/operator/owner-event-loop.js +60 -2
- package/dist/operator/owner-event-loop.js.map +1 -1
- package/dist/operator/owner-event-policy.d.ts +20 -0
- package/dist/operator/owner-event-policy.d.ts.map +1 -1
- package/dist/operator/owner-event-policy.js +34 -5
- package/dist/operator/owner-event-policy.js.map +1 -1
- package/dist/operator/owner-event-prompt.d.ts +13 -4
- package/dist/operator/owner-event-prompt.d.ts.map +1 -1
- package/dist/operator/owner-event-prompt.js +31 -38
- package/dist/operator/owner-event-prompt.js.map +1 -1
- package/dist/operator/owner-runtime-journal.d.ts.map +1 -1
- package/dist/operator/owner-runtime-journal.js +7 -3
- package/dist/operator/owner-runtime-journal.js.map +1 -1
- package/dist/operator/owner-runtime.d.ts +6 -0
- package/dist/operator/owner-runtime.d.ts.map +1 -1
- package/dist/operator/owner-runtime.js +48 -5
- package/dist/operator/owner-runtime.js.map +1 -1
- package/dist/operator/procedure-activation.d.ts +7 -0
- package/dist/operator/procedure-activation.d.ts.map +1 -0
- package/dist/operator/procedure-activation.js +132 -0
- package/dist/operator/procedure-activation.js.map +1 -0
- package/dist/operator/procedure-projection.d.ts +25 -0
- package/dist/operator/procedure-projection.d.ts.map +1 -0
- package/dist/operator/procedure-projection.js +80 -0
- package/dist/operator/procedure-projection.js.map +1 -0
- package/dist/operator/procedure-runtime.d.ts +45 -0
- package/dist/operator/procedure-runtime.d.ts.map +1 -0
- package/dist/operator/procedure-runtime.js +496 -0
- package/dist/operator/procedure-runtime.js.map +1 -0
- package/dist/operator/procedure-store.d.ts +97 -0
- package/dist/operator/procedure-store.d.ts.map +1 -0
- package/dist/operator/procedure-store.js +368 -0
- package/dist/operator/procedure-store.js.map +1 -0
- package/dist/operator/subagent-stimulus.d.ts +34 -0
- package/dist/operator/subagent-stimulus.d.ts.map +1 -0
- package/dist/operator/subagent-stimulus.js +145 -0
- package/dist/operator/subagent-stimulus.js.map +1 -0
- package/dist/operator/task-ledger.d.ts +40 -3
- package/dist/operator/task-ledger.d.ts.map +1 -1
- package/dist/operator/task-ledger.js +63 -10
- package/dist/operator/task-ledger.js.map +1 -1
- package/dist/operator/thread-brief-memory.d.ts +29 -0
- package/dist/operator/thread-brief-memory.d.ts.map +1 -0
- package/dist/operator/thread-brief-memory.js +61 -0
- package/dist/operator/thread-brief-memory.js.map +1 -0
- package/dist/operator/trigger-author.d.ts +2 -1
- package/dist/operator/trigger-author.d.ts.map +1 -1
- package/dist/operator/trigger-author.js +23 -0
- package/dist/operator/trigger-author.js.map +1 -1
- package/dist/operator/trigger-matcher.js +1 -0
- package/dist/operator/trigger-matcher.js.map +1 -1
- package/dist/operator/trigger-registry.d.ts +5 -4
- package/dist/operator/trigger-registry.d.ts.map +1 -1
- package/dist/operator/trigger-registry.js +78 -24
- package/dist/operator/trigger-registry.js.map +1 -1
- package/dist/operator/trigger-review.d.ts +1 -1
- package/dist/operator/trigger-review.d.ts.map +1 -1
- package/dist/operator/trigger-review.js +24 -4
- package/dist/operator/trigger-review.js.map +1 -1
- package/dist/operator/trigger-types.d.ts +10 -1
- package/dist/operator/trigger-types.d.ts.map +1 -1
- package/dist/operator/worker-run.d.ts +13 -1
- package/dist/operator/worker-run.d.ts.map +1 -1
- package/dist/operator/worker-run.js +5 -2
- package/dist/operator/worker-run.js.map +1 -1
- package/dist/operator/workorder-consumer.d.ts +106 -14
- package/dist/operator/workorder-consumer.d.ts.map +1 -1
- package/dist/operator/workorder-consumer.js +295 -93
- package/dist/operator/workorder-consumer.js.map +1 -1
- package/dist/operator/workorder-hooks.d.ts +42 -9
- package/dist/operator/workorder-hooks.d.ts.map +1 -1
- package/dist/operator/workorder-hooks.js +52 -13
- package/dist/operator/workorder-hooks.js.map +1 -1
- package/dist/operator/workorder-publishers.d.ts +9 -1
- package/dist/operator/workorder-publishers.d.ts.map +1 -1
- package/dist/operator/workorder-publishers.js +21 -2
- package/dist/operator/workorder-publishers.js.map +1 -1
- package/package.json +2 -2
- package/dist/operator/learning-context.d.ts +0 -49
- package/dist/operator/learning-context.d.ts.map +0 -1
- package/dist/operator/learning-context.js +0 -129
- package/dist/operator/learning-context.js.map +0 -1
- package/dist/operator/learning-markers.d.ts +0 -19
- package/dist/operator/learning-markers.d.ts.map +0 -1
- package/dist/operator/learning-markers.js +0 -147
- package/dist/operator/learning-markers.js.map +0 -1
- package/dist/operator/learning-read.d.ts +0 -16
- package/dist/operator/learning-read.d.ts.map +0 -1
- package/dist/operator/learning-read.js +0 -18
- package/dist/operator/learning-read.js.map +0 -1
- package/dist/operator/turn-observer.d.ts +0 -34
- package/dist/operator/turn-observer.d.ts.map +0 -1
- package/dist/operator/turn-observer.js +0 -79
- package/dist/operator/turn-observer.js.map +0 -1
- package/templates/skills/heartbeat-report.md +0 -75
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Owner policy and lessons, injected into every turn.
|
|
3
|
-
*
|
|
4
|
-
* Conversation changes operations only if what the owner said reaches the next turn.
|
|
5
|
-
* Two kinds of memory rows do that: `policy:` rows (rules in force, rendered
|
|
6
|
-
* unconditionally for the turn's scope) and `lesson:` rows (corrections, ranked by the
|
|
7
|
-
* turn's query, bounded). Both are OWNER-authored data inside a trusted block, so every
|
|
8
|
-
* rendered value is markup-escaped and every line is budgeted before assembly: a stored
|
|
9
|
-
* string can never close the block or author a tag, and a closing tag is never truncated.
|
|
10
|
-
*/
|
|
11
|
-
import type { MemoryScopeRef, MemoryTruthRow } from '@jungjaehoon/mama-core/memory/types';
|
|
12
|
-
export interface LearningContextInput {
|
|
13
|
-
/** Same scope list the turn's envelope uses; build it with deriveMemoryScopes. */
|
|
14
|
-
scopes: MemoryScopeRef[];
|
|
15
|
-
/** Kept for the audit line; ranking is by recency (see buildLearningContext). */
|
|
16
|
-
query: string;
|
|
17
|
-
/** Bounded reads. `query: ''` returns everything in scope. */
|
|
18
|
-
readClaims: (input: {
|
|
19
|
-
scopes: MemoryScopeRef[];
|
|
20
|
-
query: string;
|
|
21
|
-
}) => Promise<MemoryTruthRow[]>;
|
|
22
|
-
limits?: {
|
|
23
|
-
maxLessons?: number;
|
|
24
|
-
maxSummaryChars?: number;
|
|
25
|
-
maxTotalChars?: number;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export interface LearningContext {
|
|
29
|
-
/** Ready-to-append prompt text. Empty string when nothing qualifies. */
|
|
30
|
-
promptBlock: string;
|
|
31
|
-
policyIds: string[];
|
|
32
|
-
lessonIds: string[];
|
|
33
|
-
/** For the daemon.log prompt-audit line the acceptance test reads. */
|
|
34
|
-
audit: {
|
|
35
|
-
policyCount: number;
|
|
36
|
-
lessonCount: number;
|
|
37
|
-
renderedChars: number;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export declare const POLICY_TOPIC_PREFIX = "policy:";
|
|
41
|
-
export declare const LESSON_TOPIC_PREFIX = "lesson:";
|
|
42
|
-
/** Topics the host owns: only the turn observer writes them (gateway refuses the agent). */
|
|
43
|
-
export declare function isLearningTopic(topic: unknown): boolean;
|
|
44
|
-
/** Owner text is data inside a trusted block: it must not be able to author markup. */
|
|
45
|
-
export declare function escapePromptMarkup(text: string): string;
|
|
46
|
-
export declare function buildLearningContext(input: LearningContextInput): Promise<LearningContext>;
|
|
47
|
-
/** One prompt-audit line per turn; the installed acceptance test greps it. */
|
|
48
|
-
export declare function formatLearningAuditLine(turn: string, channelScopeId: string | null, context: LearningContext): string;
|
|
49
|
-
//# sourceMappingURL=learning-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-context.d.ts","sourceRoot":"","sources":["../../src/operator/learning-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAE1F,MAAM,WAAW,oBAAoB;IACnC,kFAAkF;IAClF,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,UAAU,EAAE,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC9F,MAAM,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpF;AAED,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,sEAAsE;IACtE,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5E;AAED,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAE7C,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMvD;AAMD,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKvD;AAuFD,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAkDhG;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,OAAO,EAAE,eAAe,GACvB,MAAM,CAER"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LESSON_TOPIC_PREFIX = exports.POLICY_TOPIC_PREFIX = void 0;
|
|
4
|
-
exports.isLearningTopic = isLearningTopic;
|
|
5
|
-
exports.escapePromptMarkup = escapePromptMarkup;
|
|
6
|
-
exports.buildLearningContext = buildLearningContext;
|
|
7
|
-
exports.formatLearningAuditLine = formatLearningAuditLine;
|
|
8
|
-
exports.POLICY_TOPIC_PREFIX = 'policy:';
|
|
9
|
-
exports.LESSON_TOPIC_PREFIX = 'lesson:';
|
|
10
|
-
/** Topics the host owns: only the turn observer writes them (gateway refuses the agent). */
|
|
11
|
-
function isLearningTopic(topic) {
|
|
12
|
-
return (typeof topic === 'string' &&
|
|
13
|
-
(topic.trimStart().toLowerCase().startsWith(exports.POLICY_TOPIC_PREFIX) ||
|
|
14
|
-
topic.trimStart().toLowerCase().startsWith(exports.LESSON_TOPIC_PREFIX)));
|
|
15
|
-
}
|
|
16
|
-
const DEFAULT_LIMITS = { maxLessons: 3, maxSummaryChars: 240, maxTotalChars: 2400 };
|
|
17
|
-
const POLICY_INSTRUCTION = 'Owner policy, in force. Apply it. The host still enforces revisions, receipts and destinations.';
|
|
18
|
-
const LESSON_INSTRUCTION = 'Use as lessons, not facts; verify with the packet.';
|
|
19
|
-
/** Owner text is data inside a trusted block: it must not be able to author markup. */
|
|
20
|
-
function escapePromptMarkup(text) {
|
|
21
|
-
return text
|
|
22
|
-
.replace(/&(?!amp;|lt;|gt;|quot;|apos;)/g, '&')
|
|
23
|
-
.replace(/</g, '<')
|
|
24
|
-
.replace(/>/g, '>');
|
|
25
|
-
}
|
|
26
|
-
/** Ported gate: never render a half-formed row. */
|
|
27
|
-
function renderable(row) {
|
|
28
|
-
if (typeof row.effective_summary !== 'string' || row.effective_summary.trim() === '') {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
if (!Array.isArray(row.scope_refs)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (!row.scope_refs.some((scope) => scope.kind === 'project')) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return typeof row.updated_at === 'number' || typeof row.created_at === 'number';
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A turn may carry more than one channel scope (a board reconcile carries the synthetic
|
|
41
|
-
* worker channel AND the channel it judges); a row matches when it names ANY of them.
|
|
42
|
-
*/
|
|
43
|
-
function hasChannelScope(row, turnChannels) {
|
|
44
|
-
return row.scope_refs.some((scope) => scope.kind === 'channel' && turnChannels.has(scope.id));
|
|
45
|
-
}
|
|
46
|
-
/** A policy applies when it names no channel (project- or global-wide) or one of this turn's. */
|
|
47
|
-
function policyScopeMatches(row, turnChannels) {
|
|
48
|
-
const channels = row.scope_refs.filter((scope) => scope.kind === 'channel');
|
|
49
|
-
if (channels.length === 0) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
return hasChannelScope(row, turnChannels);
|
|
53
|
-
}
|
|
54
|
-
function recency(row) {
|
|
55
|
-
return row.updated_at ?? row.created_at ?? 0;
|
|
56
|
-
}
|
|
57
|
-
/** One line per row: a newline in stored text could forge a section heading, so it is collapsed. */
|
|
58
|
-
function renderLine(row, prefix, maxSummaryChars) {
|
|
59
|
-
const name = escapePromptMarkup(row.topic.slice(prefix.length).replace(/\s+/g, ' ').trim() || 'untitled');
|
|
60
|
-
const summary = escapePromptMarkup(row.effective_summary.replace(/\s+/g, ' ').trim().slice(0, maxSummaryChars));
|
|
61
|
-
return `- ${name}: ${summary}`;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Budget each line against the remaining chars and drop whole lines; never slice the
|
|
65
|
-
* assembled string. Returns the block and the rows that made it in.
|
|
66
|
-
*/
|
|
67
|
-
function renderBlock(tag, instruction, rows, prefix, maxSummaryChars, budget) {
|
|
68
|
-
if (rows.length === 0) {
|
|
69
|
-
return { block: '', rendered: [] };
|
|
70
|
-
}
|
|
71
|
-
const open = `<${tag}>`;
|
|
72
|
-
const close = `</${tag}>`;
|
|
73
|
-
const frame = open.length + 1 + instruction.length + 1 + close.length;
|
|
74
|
-
if (frame > budget) {
|
|
75
|
-
return { block: '', rendered: [] };
|
|
76
|
-
}
|
|
77
|
-
let used = frame;
|
|
78
|
-
const lines = [];
|
|
79
|
-
const rendered = [];
|
|
80
|
-
for (const row of rows) {
|
|
81
|
-
const line = renderLine(row, prefix, maxSummaryChars);
|
|
82
|
-
if (used + line.length + 1 > budget) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
used += line.length + 1;
|
|
86
|
-
lines.push(line);
|
|
87
|
-
rendered.push(row);
|
|
88
|
-
}
|
|
89
|
-
if (lines.length === 0) {
|
|
90
|
-
return { block: '', rendered: [] };
|
|
91
|
-
}
|
|
92
|
-
return { block: [open, instruction, ...lines, close].join('\n'), rendered };
|
|
93
|
-
}
|
|
94
|
-
async function buildLearningContext(input) {
|
|
95
|
-
const limits = { ...DEFAULT_LIMITS, ...(input.limits ?? {}) };
|
|
96
|
-
const turnChannels = new Set(input.scopes.filter((scope) => scope.kind === 'channel').map((scope) => scope.id));
|
|
97
|
-
// ONE read with an empty query: it returns every active row in scope, which is a superset
|
|
98
|
-
// of what a ranked lesson read would return, and queryRelevantTruth has no LIMIT - a second
|
|
99
|
-
// scan of the same rows bought nothing. Lessons are channel-bound and few; recency ranks them.
|
|
100
|
-
const rows = await input.readClaims({ scopes: input.scopes, query: '' });
|
|
101
|
-
const policies = rows
|
|
102
|
-
.filter((row) => row.topic.startsWith(exports.POLICY_TOPIC_PREFIX) && renderable(row))
|
|
103
|
-
.filter((row) => policyScopeMatches(row, turnChannels))
|
|
104
|
-
.sort((a, b) => recency(b) - recency(a));
|
|
105
|
-
const lessons = rows
|
|
106
|
-
.filter((row) => row.topic.startsWith(exports.LESSON_TOPIC_PREFIX) && renderable(row))
|
|
107
|
-
.filter((row) => hasChannelScope(row, turnChannels))
|
|
108
|
-
.sort((a, b) => recency(b) - recency(a))
|
|
109
|
-
.slice(0, limits.maxLessons);
|
|
110
|
-
const policyBlock = renderBlock('policy', POLICY_INSTRUCTION, policies, exports.POLICY_TOPIC_PREFIX, limits.maxSummaryChars, limits.maxTotalChars);
|
|
111
|
-
const remaining = limits.maxTotalChars - (policyBlock.block ? policyBlock.block.length + 2 : 0);
|
|
112
|
-
const lessonBlock = renderBlock('lessons', LESSON_INSTRUCTION, lessons, exports.LESSON_TOPIC_PREFIX, limits.maxSummaryChars, remaining);
|
|
113
|
-
const promptBlock = [policyBlock.block, lessonBlock.block].filter(Boolean).join('\n\n');
|
|
114
|
-
return {
|
|
115
|
-
promptBlock,
|
|
116
|
-
policyIds: policyBlock.rendered.map((row) => row.memory_id),
|
|
117
|
-
lessonIds: lessonBlock.rendered.map((row) => row.memory_id),
|
|
118
|
-
audit: {
|
|
119
|
-
policyCount: policyBlock.rendered.length,
|
|
120
|
-
lessonCount: lessonBlock.rendered.length,
|
|
121
|
-
renderedChars: promptBlock.length,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/** One prompt-audit line per turn; the installed acceptance test greps it. */
|
|
126
|
-
function formatLearningAuditLine(turn, channelScopeId, context) {
|
|
127
|
-
return `[learning] turn=${turn} channel=${channelScopeId ?? '-'} policyIds=[${context.policyIds.join(',')}] lessonIds=[${context.lessonIds.join(',')}] chars=${context.audit.renderedChars}`;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=learning-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-context.js","sourceRoot":"","sources":["../../src/operator/learning-context.ts"],"names":[],"mappings":";;;AAmCA,0CAMC;AAOD,gDAKC;AAuFD,oDAkDC;AAGD,0DAMC;AAxKY,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAChC,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAE7C,4FAA4F;AAC5F,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,2BAAmB,CAAC;YAC9D,KAAK,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,2BAAmB,CAAC,CAAC,CACnE,CAAC;AACJ,CAAC;AACD,MAAM,cAAc,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAW,CAAC;AAC7F,MAAM,kBAAkB,GACtB,iGAAiG,CAAC;AACpG,MAAM,kBAAkB,GAAG,oDAAoD,CAAC;AAEhF,uFAAuF;AACvF,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI;SACR,OAAO,CAAC,gCAAgC,EAAE,OAAO,CAAC;SAClD,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,mDAAmD;AACnD,SAAS,UAAU,CAAC,GAAmB;IACrC,IAAI,OAAO,GAAG,CA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EF,MAAM,WAAW,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxF,OAAO;QACL,WAAW;QACX,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3D,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3D,KAAK,EAAE;YACL,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;YACxC,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;YACxC,aAAa,EAAE,WAAW,CAAC,MAAM;SAClC;KACF,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,SAAgB,uBAAuB,CACrC,IAAY,EACZ,cAA6B,EAC7B,OAAwB;IAExB,OAAO,mBAAmB,IAAI,YAAY,cAAc,IAAI,GAAG,eAAe,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;AAC/L,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface LearningMarkerConfig {
|
|
2
|
-
durableRule: string[];
|
|
3
|
-
correction: string[];
|
|
4
|
-
oneOffVeto: string[];
|
|
5
|
-
topicNouns: Record<string, string[]>;
|
|
6
|
-
}
|
|
7
|
-
export declare const DEFAULT_LEARNING_MARKERS: LearningMarkerConfig;
|
|
8
|
-
export interface DurableInstruction {
|
|
9
|
-
kind: 'policy' | 'lesson' | 'none';
|
|
10
|
-
topicNoun?: string;
|
|
11
|
-
matchedMarkers: string[];
|
|
12
|
-
/** Why it was or was not classified; goes into the audit log. */
|
|
13
|
-
reason: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function learningMarkersPath(env?: NodeJS.ProcessEnv): string;
|
|
16
|
-
/** Defaults merged with the owner's overrides; overrides ADD to a list, never replace it. */
|
|
17
|
-
export declare function loadLearningMarkers(env?: NodeJS.ProcessEnv): LearningMarkerConfig;
|
|
18
|
-
export declare function detectDurableInstruction(text: string, cfg?: LearningMarkerConfig): DurableInstruction;
|
|
19
|
-
//# sourceMappingURL=learning-markers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-markers.d.ts","sourceRoot":"","sources":["../../src/operator/learning-markers.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACtC;AAED,eAAO,MAAM,wBAAwB,EAAE,oBAUtC,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAEhF;AAUD,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,oBAAoB,CA2C9F;AAyBD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,oBAA+C,GACnD,kBAAkB,CA0CpB"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_LEARNING_MARKERS = void 0;
|
|
4
|
-
exports.learningMarkersPath = learningMarkersPath;
|
|
5
|
-
exports.loadLearningMarkers = loadLearningMarkers;
|
|
6
|
-
exports.detectDurableInstruction = detectDurableInstruction;
|
|
7
|
-
/**
|
|
8
|
-
* Marker vocabulary for detecting durable owner instructions in chat.
|
|
9
|
-
*
|
|
10
|
-
* Vocabulary is DATA. English defaults ship here; the owner's own language lives in runtime
|
|
11
|
-
* config at ~/.mama/operator/locale.json (or MAMA_OPERATOR_LOCALE_PATH) under the key
|
|
12
|
-
* `learningMarkers`. This file carries no non-English strings and no business vocabulary,
|
|
13
|
-
* and a test pins that.
|
|
14
|
-
*
|
|
15
|
-
* Classification (mechanism ported from Kagemusha's experience-signal extractor): a message
|
|
16
|
-
* classifies only when it carries a TOPIC NOUN and a DURABLE marker and NO one-off veto.
|
|
17
|
-
* A durable-rule marker yields `policy`; a correction marker alone yields `lesson`.
|
|
18
|
-
*/
|
|
19
|
-
const node_fs_1 = require("node:fs");
|
|
20
|
-
const node_os_1 = require("node:os");
|
|
21
|
-
const node_path_1 = require("node:path");
|
|
22
|
-
exports.DEFAULT_LEARNING_MARKERS = {
|
|
23
|
-
durableRule: ['always', 'from now on', 'going forward', 'treat * as', 'every time'],
|
|
24
|
-
correction: ['not * but', "don't", 'do not', 'instead of', 'stop doing', 'never'],
|
|
25
|
-
oneOffVeto: ['today only', 'this time', 'just once', 'for now', 'only now'],
|
|
26
|
-
topicNouns: {
|
|
27
|
-
lifecycle: ['review', 'done', 'complete', 'deadline', 'status', 'lifecycle', 'submitted'],
|
|
28
|
-
report: ['report', 'briefing', 'summary', 'board', 'slot'],
|
|
29
|
-
file: ['file', 'spreadsheet', 'export', 'upload', 'drive'],
|
|
30
|
-
task: ['task', 'ticket', 'card', 'item', 'assignee'],
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
function learningMarkersPath(env = process.env) {
|
|
34
|
-
return env.MAMA_OPERATOR_LOCALE_PATH || (0, node_path_1.join)((0, node_os_1.homedir)(), '.mama', 'operator', 'locale.json');
|
|
35
|
-
}
|
|
36
|
-
/** A marker list; blank entries are dropped (a blank marker would match every message). */
|
|
37
|
-
function stringList(value) {
|
|
38
|
-
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string')) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return value.map((item) => item.trim()).filter((item) => item.length > 0);
|
|
42
|
-
}
|
|
43
|
-
/** Defaults merged with the owner's overrides; overrides ADD to a list, never replace it. */
|
|
44
|
-
function loadLearningMarkers(env = process.env) {
|
|
45
|
-
const path = learningMarkersPath(env);
|
|
46
|
-
const merged = {
|
|
47
|
-
durableRule: [...exports.DEFAULT_LEARNING_MARKERS.durableRule],
|
|
48
|
-
correction: [...exports.DEFAULT_LEARNING_MARKERS.correction],
|
|
49
|
-
oneOffVeto: [...exports.DEFAULT_LEARNING_MARKERS.oneOffVeto],
|
|
50
|
-
topicNouns: Object.fromEntries(Object.entries(exports.DEFAULT_LEARNING_MARKERS.topicNouns).map(([k, v]) => [k, [...v]])),
|
|
51
|
-
};
|
|
52
|
-
if (!(0, node_fs_1.existsSync)(path)) {
|
|
53
|
-
return merged;
|
|
54
|
-
}
|
|
55
|
-
let parsed;
|
|
56
|
-
try {
|
|
57
|
-
parsed = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf-8'));
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
throw new Error(`learning markers: ${path} is not valid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
61
|
-
}
|
|
62
|
-
const section = typeof parsed === 'object' && parsed !== null
|
|
63
|
-
? parsed.learningMarkers
|
|
64
|
-
: undefined;
|
|
65
|
-
if (!section || typeof section !== 'object') {
|
|
66
|
-
return merged;
|
|
67
|
-
}
|
|
68
|
-
for (const key of ['durableRule', 'correction', 'oneOffVeto']) {
|
|
69
|
-
const extra = stringList(section[key]);
|
|
70
|
-
if (extra) {
|
|
71
|
-
merged[key] = [...new Set([...merged[key], ...extra])];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (typeof section.topicNouns === 'object' && section.topicNouns !== null) {
|
|
75
|
-
for (const [noun, words] of Object.entries(section.topicNouns)) {
|
|
76
|
-
const extra = stringList(words);
|
|
77
|
-
if (extra) {
|
|
78
|
-
merged.topicNouns[noun] = [...new Set([...(merged.topicNouns[noun] ?? []), ...extra])];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return merged;
|
|
83
|
-
}
|
|
84
|
-
function escapeRegExp(text) {
|
|
85
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
86
|
-
}
|
|
87
|
-
/** A marker is a phrase; `*` inside it matches a short run of words. */
|
|
88
|
-
function markerRegex(marker) {
|
|
89
|
-
const parts = marker.split('*').map((part) => escapeRegExp(part.trim()));
|
|
90
|
-
const body = parts.join('\\s+\\S+(?:\\s+\\S+){0,3}\\s+');
|
|
91
|
-
return new RegExp(`(^|[^\\p{L}\\p{N}])${body}(?=$|[^\\p{L}\\p{N}])`, 'iu');
|
|
92
|
-
}
|
|
93
|
-
function firstMatch(text, markers) {
|
|
94
|
-
for (const marker of markers) {
|
|
95
|
-
if (!marker.trim()) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (markerRegex(marker).test(text)) {
|
|
99
|
-
return marker;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
function detectDurableInstruction(text, cfg = exports.DEFAULT_LEARNING_MARKERS) {
|
|
105
|
-
const normalized = text.replace(/\s+/g, ' ').trim();
|
|
106
|
-
if (!normalized) {
|
|
107
|
-
return { kind: 'none', matchedMarkers: [], reason: 'empty message' };
|
|
108
|
-
}
|
|
109
|
-
const veto = firstMatch(normalized, cfg.oneOffVeto);
|
|
110
|
-
if (veto) {
|
|
111
|
-
return { kind: 'none', matchedMarkers: [veto], reason: `one-off veto marker: ${veto}` };
|
|
112
|
-
}
|
|
113
|
-
let topicNoun;
|
|
114
|
-
for (const [noun, words] of Object.entries(cfg.topicNouns)) {
|
|
115
|
-
if (firstMatch(normalized, words)) {
|
|
116
|
-
topicNoun = noun;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const durable = firstMatch(normalized, cfg.durableRule);
|
|
121
|
-
const correction = firstMatch(normalized, cfg.correction);
|
|
122
|
-
if (!topicNoun) {
|
|
123
|
-
return {
|
|
124
|
-
kind: 'none',
|
|
125
|
-
matchedMarkers: [durable, correction].filter((m) => m !== null),
|
|
126
|
-
reason: 'no topic noun',
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (durable) {
|
|
130
|
-
return {
|
|
131
|
-
kind: 'policy',
|
|
132
|
-
topicNoun,
|
|
133
|
-
matchedMarkers: [durable, ...(correction ? [correction] : [])],
|
|
134
|
-
reason: `durable-rule marker: ${durable}`,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (correction) {
|
|
138
|
-
return {
|
|
139
|
-
kind: 'lesson',
|
|
140
|
-
topicNoun,
|
|
141
|
-
matchedMarkers: [correction],
|
|
142
|
-
reason: `correction marker: ${correction}`,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
return { kind: 'none', topicNoun, matchedMarkers: [], reason: 'topic noun without a marker' };
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=learning-markers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-markers.js","sourceRoot":"","sources":["../../src/operator/learning-markers.ts"],"names":[],"mappings":";;;AA2CA,kDAEC;AAWD,kDA2CC;AAyBD,4DA6CC;AAzKD;;;;;;;;;;;GAWG;AACH,qCAAmD;AACnD,qCAAkC;AAClC,yCAAiC;AASpB,QAAA,wBAAwB,GAAyB;IAC5D,WAAW,EAAE,CAAC,QAAQ,EA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AI,UAAU,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;YAClC,SAAS,GAAG,IAAI,CAAC;YACjB,MAAM;QACR,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,cAAc,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;YAC5E,MAAM,EAAE,eAAe;SACxB,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,SAAS;YACT,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9D,MAAM,EAAE,wBAAwB,OAAO,EAAE;SAC1C,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,SAAS;YACT,cAAc,EAAE,CAAC,UAAU,CAAC;YAC5B,MAAM,EAAE,sBAAsB,UAAU,EAAE;SAC3C,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,6BAA6B,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bounded truth read for learning injection. queryRelevantTruth has no LIMIT: without a
|
|
3
|
-
* cap every turn would pay a full scan of the project's active decisions and ship them all
|
|
4
|
-
* into the prompt filter. Keep the newest rows; log once per trip so the cost is visible.
|
|
5
|
-
*/
|
|
6
|
-
import type { MemoryScopeRef, MemoryTruthRow } from '@jungjaehoon/mama-core/memory/types';
|
|
7
|
-
export declare const LEARNING_READ_CAP = 200;
|
|
8
|
-
export type TruthReader = (params: {
|
|
9
|
-
query: string;
|
|
10
|
-
scopes: MemoryScopeRef[];
|
|
11
|
-
}) => Promise<MemoryTruthRow[]>;
|
|
12
|
-
export declare function cappedLearningReader(read: TruthReader, log: (line: string) => void, cap?: number): (input: {
|
|
13
|
-
scopes: MemoryScopeRef[];
|
|
14
|
-
query: string;
|
|
15
|
-
}) => Promise<MemoryTruthRow[]>;
|
|
16
|
-
//# sourceMappingURL=learning-read.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-read.d.ts","sourceRoot":"","sources":["../../src/operator/learning-read.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAE1F,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAEhC,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC3B,GAAG,GAAE,MAA0B,GAC9B,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAWnF"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LEARNING_READ_CAP = void 0;
|
|
4
|
-
exports.cappedLearningReader = cappedLearningReader;
|
|
5
|
-
exports.LEARNING_READ_CAP = 200;
|
|
6
|
-
function cappedLearningReader(read, log, cap = exports.LEARNING_READ_CAP) {
|
|
7
|
-
return async (input) => {
|
|
8
|
-
const rows = await read({ query: input.query, scopes: input.scopes });
|
|
9
|
-
if (rows.length <= cap) {
|
|
10
|
-
return rows;
|
|
11
|
-
}
|
|
12
|
-
log(`[learning] read cap tripped: ${rows.length} rows in scope, keeping newest ${cap}`);
|
|
13
|
-
return [...rows]
|
|
14
|
-
.sort((a, b) => (b.updated_at ?? b.created_at ?? 0) - (a.updated_at ?? a.created_at ?? 0))
|
|
15
|
-
.slice(0, cap);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=learning-read.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"learning-read.js","sourceRoot":"","sources":["../../src/operator/learning-read.ts"],"names":[],"mappings":";;;AAcA,oDAeC;AAtBY,QAAA,iBAAiB,GAAG,GAAG,CAAC;AAOrC,SAAgB,oBAAoB,CAClC,IAAiB,EACjB,GAA2B,EAC3B,MAAc,yBAAiB;IAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QACtE,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,GAAG,CAAC,gCAAgC,IAAI,CAAC,MAAM,kCAAkC,GAAG,EAAE,CAAC,CAAC;QACxF,OAAO,CAAC,GAAG,IAAI,CAAC;aACb,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;aACzF,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { MemoryScopeRef, MemorySourceRef, PublicSaveMemoryInput } from '@jungjaehoon/mama-core/memory/types';
|
|
2
|
-
import { type LearningMarkerConfig } from './learning-markers.js';
|
|
3
|
-
export interface ObserveOwnerTurnInput {
|
|
4
|
-
userMessage: string;
|
|
5
|
-
/** Same list the turn used; the channel scope id comes from here, never from a raw key. */
|
|
6
|
-
scopes: MemoryScopeRef[];
|
|
7
|
-
source: MemorySourceRef;
|
|
8
|
-
markers?: LearningMarkerConfig;
|
|
9
|
-
/** false when no reply was committed or the turn threw: nothing is written. */
|
|
10
|
-
turnCommitted: boolean;
|
|
11
|
-
save: (input: PublicSaveMemoryInput) => Promise<{
|
|
12
|
-
memoryId: string;
|
|
13
|
-
}>;
|
|
14
|
-
/** Existing active row with the same derived topic, for supersede-not-duplicate. */
|
|
15
|
-
findExisting: (topic: string) => Promise<{
|
|
16
|
-
memory_id: string;
|
|
17
|
-
} | null>;
|
|
18
|
-
update?: (memoryId: string, input: {
|
|
19
|
-
summary: string;
|
|
20
|
-
details: string;
|
|
21
|
-
}) => Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export interface ObserveOwnerTurnResult {
|
|
24
|
-
kind: 'policy' | 'lesson' | 'none';
|
|
25
|
-
topic?: string;
|
|
26
|
-
memoryId?: string;
|
|
27
|
-
deduped?: boolean;
|
|
28
|
-
reason: string;
|
|
29
|
-
}
|
|
30
|
-
export declare const HOST_LEARNING_SOURCE_TYPE = "owner_turn_observer";
|
|
31
|
-
/** Stable per (channel, text): the same correction twice is one row. */
|
|
32
|
-
export declare function learningTopic(kind: 'policy' | 'lesson', noun: string, channelScopeId: string | null, text: string): string;
|
|
33
|
-
export declare function observeOwnerTurn(input: ObserveOwnerTurnInput): Promise<ObserveOwnerTurnResult>;
|
|
34
|
-
//# sourceMappingURL=turn-observer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"turn-observer.d.ts","sourceRoot":"","sources":["../../src/operator/turn-observer.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,+EAA+E;IAC/E,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtE,oFAAoF;IACpF,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACvE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3F;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,yBAAyB,wBAAwB,CAAC;AAM/D,wEAAwE;AACxE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,GAAG,QAAQ,EACzB,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,IAAI,EAAE,MAAM,GACX,MAAM,CAOR;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,sBAAsB,CAAC,CAoDjC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HOST_LEARNING_SOURCE_TYPE = void 0;
|
|
4
|
-
exports.learningTopic = learningTopic;
|
|
5
|
-
exports.observeOwnerTurn = observeOwnerTurn;
|
|
6
|
-
/**
|
|
7
|
-
* Turn observer: the ONLY writer of `policy:` and `lesson:` memory rows.
|
|
8
|
-
*
|
|
9
|
-
* After an owner chat reply is committed, the owner's message is classified with the marker
|
|
10
|
-
* vocabulary; a durable rule becomes a `policy:` row (kind decision), a correction becomes a
|
|
11
|
-
* `lesson:` row (kind lesson). The row carries the SAME scope list the turn used, so the read
|
|
12
|
-
* in learning-context.ts and this write cannot drift apart, and a host source ref.
|
|
13
|
-
*
|
|
14
|
-
* Two stores, split on purpose: the console brief holds cross-channel OPERATING STYLE and is
|
|
15
|
-
* edited by the owner conversation; `lesson:` rows hold channel-scoped SITUATIONAL lessons.
|
|
16
|
-
* The observer never touches the brief. The gateway refuses agent-written `policy:`/`lesson:`
|
|
17
|
-
* topics (gateway-tool-executor.ts, learning_topic_refused), so standing policy can only come
|
|
18
|
-
* from the owner through this path.
|
|
19
|
-
*/
|
|
20
|
-
const node_crypto_1 = require("node:crypto");
|
|
21
|
-
const learning_markers_js_1 = require("./learning-markers.js");
|
|
22
|
-
const learning_context_js_1 = require("./learning-context.js");
|
|
23
|
-
exports.HOST_LEARNING_SOURCE_TYPE = 'owner_turn_observer';
|
|
24
|
-
function normalizeText(text) {
|
|
25
|
-
return text.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
26
|
-
}
|
|
27
|
-
/** Stable per (channel, text): the same correction twice is one row. */
|
|
28
|
-
function learningTopic(kind, noun, channelScopeId, text) {
|
|
29
|
-
const digest = (0, node_crypto_1.createHash)('sha1')
|
|
30
|
-
.update(`${channelScopeId ?? ''}\0${normalizeText(text)}`)
|
|
31
|
-
.digest('hex')
|
|
32
|
-
.slice(0, 12);
|
|
33
|
-
const prefix = kind === 'policy' ? learning_context_js_1.POLICY_TOPIC_PREFIX : learning_context_js_1.LESSON_TOPIC_PREFIX;
|
|
34
|
-
return `${prefix}${noun}-${digest}`;
|
|
35
|
-
}
|
|
36
|
-
async function observeOwnerTurn(input) {
|
|
37
|
-
if (!input.turnCommitted) {
|
|
38
|
-
return { kind: 'none', reason: 'turn not committed' };
|
|
39
|
-
}
|
|
40
|
-
const detected = (0, learning_markers_js_1.detectDurableInstruction)(input.userMessage, input.markers ?? learning_markers_js_1.DEFAULT_LEARNING_MARKERS);
|
|
41
|
-
if (detected.kind === 'none' || !detected.topicNoun) {
|
|
42
|
-
return { kind: 'none', reason: detected.reason };
|
|
43
|
-
}
|
|
44
|
-
const channelScopeId = input.scopes.find((scope) => scope.kind === 'channel')?.id ?? null;
|
|
45
|
-
// A policy hash is project-wide too: the same rule from any owner channel is one row.
|
|
46
|
-
const topic = learningTopic(detected.kind, detected.topicNoun, detected.kind === 'policy' ? null : channelScopeId, input.userMessage);
|
|
47
|
-
const summary = input.userMessage.replace(/\s+/g, ' ').trim().slice(0, 400);
|
|
48
|
-
const details = `Owner ${detected.kind === 'policy' ? 'rule' : 'correction'} recorded from chat; markers: ${detected.matchedMarkers.join(', ')}.`;
|
|
49
|
-
const existing = await input.findExisting(topic);
|
|
50
|
-
if (existing) {
|
|
51
|
-
if (input.update) {
|
|
52
|
-
await input.update(existing.memory_id, { summary, details });
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
kind: detected.kind,
|
|
56
|
-
topic,
|
|
57
|
-
memoryId: existing.memory_id,
|
|
58
|
-
deduped: true,
|
|
59
|
-
reason: detected.reason,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// A RULE is project-wide: it must reach event and scheduled turns, whose channel scopes
|
|
63
|
-
// are never the owner's chat channel. A CORRECTION stays bound to the channel it was
|
|
64
|
-
// given in. Writing the chat channel onto a policy row was the defect that made every
|
|
65
|
-
// later turn read policyIds=[].
|
|
66
|
-
const scopes = detected.kind === 'policy'
|
|
67
|
-
? input.scopes.filter((scope) => scope.kind !== 'channel')
|
|
68
|
-
: input.scopes;
|
|
69
|
-
const saved = await input.save({
|
|
70
|
-
topic,
|
|
71
|
-
kind: detected.kind === 'policy' ? 'decision' : 'lesson',
|
|
72
|
-
summary,
|
|
73
|
-
details,
|
|
74
|
-
scopes,
|
|
75
|
-
source: { ...input.source, source_type: exports.HOST_LEARNING_SOURCE_TYPE },
|
|
76
|
-
});
|
|
77
|
-
return { kind: detected.kind, topic, memoryId: saved.memoryId, reason: detected.reason };
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=turn-observer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"turn-observer.js","sourceRoot":"","sources":["../../src/operator/turn-observer.ts"],"names":[],"mappings":";;;AAwDA,sCAYC;AAED,4CAsDC;AA5HD;;;;;;;;;;;;;GAaG;AACH,6CAAyC;AAMzC,+DAI+B;AAC/B,+DAAiF;AAwBpE,QAAA,yBAAyB,GAAG,qBAAqB,CAAC;AAE/D,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC;AAED,wEAAwE;AACxE,SAAgB,aAAa,CAC3B,IAAyB,EACzB,IAAY,EACZ,cAA6B,EAC7B,IAAY;IAEZ,MAA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OAAO;QACP,MAAM;QACN,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,iCAAyB,EAAE;KACpE,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: 하트비트 보고서
|
|
3
|
-
description: 채널 활동을 수집하고 보고서 작성
|
|
4
|
-
keywords:
|
|
5
|
-
- 보고서
|
|
6
|
-
- 리포트
|
|
7
|
-
- heartbeat
|
|
8
|
-
- 상황보고
|
|
9
|
-
- 업무현황
|
|
10
|
-
output: text
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
# 하트비트 보고서 스킬
|
|
14
|
-
|
|
15
|
-
슬랙, 챗워크, 트렐로, 구글 드라이브의 활동을 수집하고 보고서를 작성합니다.
|
|
16
|
-
|
|
17
|
-
## 지시사항
|
|
18
|
-
|
|
19
|
-
1. 수집된 데이터를 분석합니다.
|
|
20
|
-
2. 새로운 활동이 있는지 확인합니다.
|
|
21
|
-
3. 보고서 형식에 맞춰 작성합니다.
|
|
22
|
-
|
|
23
|
-
## 보고서 형식
|
|
24
|
-
|
|
25
|
-
### 델타 보고서 (새 활동만)
|
|
26
|
-
|
|
27
|
-
새 메시지가 없으면 `HEARTBEAT_OK`만 응답합니다.
|
|
28
|
-
|
|
29
|
-
새 메시지가 있으면:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
📊 델타 보고서
|
|
33
|
-
|
|
34
|
-
**Slack**
|
|
35
|
-
- #channel-name: 새 메시지 N개
|
|
36
|
-
- [사용자] 메시지 요약...
|
|
37
|
-
|
|
38
|
-
**Chatwork**
|
|
39
|
-
- [룸이름]: 새 메시지 N개
|
|
40
|
-
- [사용자] 메시지 요약...
|
|
41
|
-
|
|
42
|
-
**Trello**
|
|
43
|
-
- 보드명: 변경사항...
|
|
44
|
-
|
|
45
|
-
**Drive**
|
|
46
|
-
- 새 파일/수정된 파일 목록
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### 종합 보고서 (전체 현황)
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
📋 종합 보고서
|
|
53
|
-
|
|
54
|
-
## 프로젝트 현황
|
|
55
|
-
|
|
56
|
-
### [프로젝트 1]
|
|
57
|
-
- 상태: 진행중/완료/대기
|
|
58
|
-
- 최근 활동: ...
|
|
59
|
-
- 다음 단계: ...
|
|
60
|
-
|
|
61
|
-
### [프로젝트 2]
|
|
62
|
-
...
|
|
63
|
-
|
|
64
|
-
## 주요 이슈
|
|
65
|
-
- ...
|
|
66
|
-
|
|
67
|
-
## 액션 아이템
|
|
68
|
-
- [ ] ...
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## 주의사항
|
|
72
|
-
|
|
73
|
-
- Discord 메시지 길이 제한 (2000자) 고려
|
|
74
|
-
- 중요한 내용 우선
|
|
75
|
-
- 이모지로 가독성 향상
|