@hasna/mementos 0.14.27 → 0.14.28
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/cli.js +89 -12
- package/dist/index.js +1 -1
- package/dist/mcp-runtime.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -807,14 +807,16 @@ async function runHook(args) {
|
|
|
807
807
|
"user-prompt-submit": "UserPromptSubmit"
|
|
808
808
|
};
|
|
809
809
|
if (subcommand in hookEvents) {
|
|
810
|
-
const
|
|
810
|
+
const hookInput = await readHookInput();
|
|
811
|
+
const query2 = hookInput.query;
|
|
811
812
|
const payload = await client.injectionContext({ query: query2, limit: 12 });
|
|
812
813
|
const block = readTextPayload(payload) ?? formatMemoryInjection(payload);
|
|
814
|
+
const inboxBlock = await readInboxHookContext(hookInput);
|
|
813
815
|
return {
|
|
814
816
|
suppressOutput: true,
|
|
815
817
|
hookSpecificOutput: {
|
|
816
818
|
hookEventName: hookEvents[subcommand],
|
|
817
|
-
additionalContext: block
|
|
819
|
+
additionalContext: combineContextBlocks(inboxBlock, block)
|
|
818
820
|
}
|
|
819
821
|
};
|
|
820
822
|
}
|
|
@@ -824,22 +826,97 @@ async function runHook(args) {
|
|
|
824
826
|
const query = process.env.MEMENTOS_INJECTION_QUERY ?? process.cwd();
|
|
825
827
|
return injectMemory([query]);
|
|
826
828
|
}
|
|
827
|
-
async function
|
|
828
|
-
if (process.env.MEMENTOS_INJECTION_QUERY)
|
|
829
|
-
return
|
|
829
|
+
async function readHookInput() {
|
|
830
|
+
if (process.env.MEMENTOS_INJECTION_QUERY) {
|
|
831
|
+
return {
|
|
832
|
+
agentName: process.env.MEMENTOS_AGENT_NAME,
|
|
833
|
+
query: process.env.MEMENTOS_INJECTION_QUERY
|
|
834
|
+
};
|
|
835
|
+
}
|
|
830
836
|
const stdin = await readOptionalStdin();
|
|
831
|
-
if (!stdin)
|
|
832
|
-
return
|
|
837
|
+
if (!stdin) {
|
|
838
|
+
return {
|
|
839
|
+
agentName: process.env.MEMENTOS_AGENT_NAME,
|
|
840
|
+
query: process.cwd()
|
|
841
|
+
};
|
|
842
|
+
}
|
|
833
843
|
try {
|
|
834
844
|
const parsed = JSON.parse(stdin);
|
|
835
845
|
const prompt = parsed.prompt ?? parsed.userPrompt ?? parsed.message ?? parsed.cwd;
|
|
836
|
-
|
|
837
|
-
|
|
846
|
+
return {
|
|
847
|
+
agentName: readHookText(parsed.agentName ?? parsed.agent ?? parsed.name) ?? process.env.MEMENTOS_AGENT_NAME,
|
|
848
|
+
projectKey: readHookText(parsed.projectKey ?? parsed.project),
|
|
849
|
+
query: typeof prompt === "string" && prompt.trim() ? prompt.trim() : process.cwd(),
|
|
850
|
+
sessionId: readHookText(parsed.sessionId ?? parsed.session_id)
|
|
851
|
+
};
|
|
838
852
|
} catch {
|
|
839
|
-
if (stdin.trim())
|
|
840
|
-
return
|
|
853
|
+
if (stdin.trim()) {
|
|
854
|
+
return {
|
|
855
|
+
agentName: process.env.MEMENTOS_AGENT_NAME,
|
|
856
|
+
query: stdin.trim()
|
|
857
|
+
};
|
|
858
|
+
}
|
|
841
859
|
}
|
|
842
|
-
return
|
|
860
|
+
return {
|
|
861
|
+
agentName: process.env.MEMENTOS_AGENT_NAME,
|
|
862
|
+
query: process.cwd()
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
async function readInboxHookContext(input) {
|
|
866
|
+
if (!input.agentName)
|
|
867
|
+
return;
|
|
868
|
+
const response = await client.listInboxMessages({
|
|
869
|
+
agentName: input.agentName,
|
|
870
|
+
projectKey: input.projectKey,
|
|
871
|
+
sessionId: input.sessionId,
|
|
872
|
+
limit: 10
|
|
873
|
+
});
|
|
874
|
+
const messages = readInboxMessages(response);
|
|
875
|
+
if (messages.length === 0)
|
|
876
|
+
return;
|
|
877
|
+
await Promise.all(messages.map((message) => client.claimInboxMessage(message.id, { agentName: input.agentName })));
|
|
878
|
+
return formatInboxContext(messages);
|
|
879
|
+
}
|
|
880
|
+
function readInboxMessages(payload) {
|
|
881
|
+
if (typeof payload !== "object" || payload === null)
|
|
882
|
+
return [];
|
|
883
|
+
const messages = payload.messages;
|
|
884
|
+
if (!Array.isArray(messages))
|
|
885
|
+
return [];
|
|
886
|
+
return messages.flatMap((message) => {
|
|
887
|
+
if (typeof message !== "object" || message === null)
|
|
888
|
+
return [];
|
|
889
|
+
const record = message;
|
|
890
|
+
const id = readHookText(record.id);
|
|
891
|
+
const value = readHookText(record.message);
|
|
892
|
+
if (!id || !value)
|
|
893
|
+
return [];
|
|
894
|
+
return [{
|
|
895
|
+
id,
|
|
896
|
+
kind: readHookText(record.kind) ?? "directive",
|
|
897
|
+
message: value,
|
|
898
|
+
priority: readHookText(record.priority) ?? "normal",
|
|
899
|
+
title: readHookText(record.title)
|
|
900
|
+
}];
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
function formatInboxContext(messages) {
|
|
904
|
+
return [
|
|
905
|
+
"## mementos.md inbox",
|
|
906
|
+
"Apply these hosted agent directives before continuing. They have been claimed remotely.",
|
|
907
|
+
"",
|
|
908
|
+
...messages.map((message) => `- [${message.priority}] ${message.title ? `${message.title}: ` : ""}${message.message} (${message.kind})`),
|
|
909
|
+
""
|
|
910
|
+
].join(`
|
|
911
|
+
`);
|
|
912
|
+
}
|
|
913
|
+
function combineContextBlocks(...blocks) {
|
|
914
|
+
return blocks.map((block) => block?.trim()).filter(Boolean).join(`
|
|
915
|
+
|
|
916
|
+
`);
|
|
917
|
+
}
|
|
918
|
+
function readHookText(value) {
|
|
919
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
843
920
|
}
|
|
844
921
|
async function readOptionalStdin() {
|
|
845
922
|
if (process.stdin.isTTY)
|
package/dist/index.js
CHANGED
|
@@ -146,7 +146,7 @@ function readErrorMessage(payload, status) {
|
|
|
146
146
|
}
|
|
147
147
|
// src/mcp-runtime.ts
|
|
148
148
|
import { createInterface } from "readline";
|
|
149
|
-
var MEMENTOS_MCP_VERSION = "0.14.
|
|
149
|
+
var MEMENTOS_MCP_VERSION = "0.14.28";
|
|
150
150
|
var AUTHLESS_SCHEMA = {
|
|
151
151
|
type: "object",
|
|
152
152
|
properties: {},
|
package/dist/mcp-runtime.d.ts
CHANGED
package/dist/mcp.js
CHANGED