@geminixiang/mama 0.2.0-beta.0 → 0.2.0-beta.10
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/README.md +171 -334
- package/dist/adapter.d.ts +36 -10
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +10 -5
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +349 -114
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/context.d.ts +1 -1
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +102 -31
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/shared.d.ts +71 -0
- package/dist/adapters/shared.d.ts.map +1 -0
- package/dist/adapters/shared.js +168 -0
- package/dist/adapters/shared.js.map +1 -0
- package/dist/adapters/slack/bot.d.ts +29 -22
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +620 -186
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/branch-manager.d.ts +22 -0
- package/dist/adapters/slack/branch-manager.d.ts.map +1 -0
- package/dist/adapters/slack/branch-manager.js +97 -0
- package/dist/adapters/slack/branch-manager.js.map +1 -0
- package/dist/adapters/slack/context.d.ts +1 -1
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +136 -71
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/session.d.ts +3 -0
- package/dist/adapters/slack/session.d.ts.map +1 -0
- package/dist/adapters/slack/session.js +16 -0
- package/dist/adapters/slack/session.js.map +1 -0
- package/dist/adapters/slack/tools/attach.d.ts +1 -1
- package/dist/adapters/slack/tools/attach.d.ts.map +1 -1
- package/dist/adapters/slack/tools/attach.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +2 -0
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +190 -123
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +57 -59
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/telegram/html.d.ts +3 -0
- package/dist/adapters/telegram/html.d.ts.map +1 -0
- package/dist/adapters/telegram/html.js +98 -0
- package/dist/adapters/telegram/html.js.map +1 -0
- package/dist/agent.d.ts +9 -10
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +645 -555
- package/dist/agent.js.map +1 -1
- package/dist/commands/auto-reply.d.ts +16 -0
- package/dist/commands/auto-reply.d.ts.map +1 -0
- package/dist/commands/auto-reply.js +69 -0
- package/dist/commands/auto-reply.js.map +1 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +19 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +76 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/model.d.ts +14 -0
- package/dist/commands/model.d.ts.map +1 -0
- package/dist/commands/model.js +112 -0
- package/dist/commands/model.js.map +1 -0
- package/dist/commands/new.d.ts +9 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +28 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/registry.d.ts +7 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +14 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/sandbox.d.ts +10 -0
- package/dist/commands/sandbox.d.ts.map +1 -0
- package/dist/commands/sandbox.js +88 -0
- package/dist/commands/sandbox.js.map +1 -0
- package/dist/commands/session-view.d.ts +5 -0
- package/dist/commands/session-view.d.ts.map +1 -0
- package/dist/commands/session-view.js +62 -0
- package/dist/commands/session-view.js.map +1 -0
- package/dist/commands/types.d.ts +41 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/utils.d.ts +8 -0
- package/dist/commands/utils.d.ts.map +1 -0
- package/dist/commands/utils.js +14 -0
- package/dist/commands/utils.js.map +1 -0
- package/dist/config.d.ts +53 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +320 -55
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +10 -42
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -128
- package/dist/context.js.map +1 -1
- package/dist/events.d.ts +16 -5
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +127 -58
- package/dist/events.js.map +1 -1
- package/dist/execution-resolver.d.ts +24 -0
- package/dist/execution-resolver.d.ts.map +1 -0
- package/dist/execution-resolver.js +115 -0
- package/dist/execution-resolver.js.map +1 -0
- package/dist/file-guards.d.ts +6 -0
- package/dist/file-guards.d.ts.map +1 -0
- package/dist/file-guards.js +48 -0
- package/dist/file-guards.js.map +1 -0
- package/dist/fs-atomic.d.ts +10 -0
- package/dist/fs-atomic.d.ts.map +1 -0
- package/dist/fs-atomic.js +45 -0
- package/dist/fs-atomic.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/instrument.d.ts.map +1 -1
- package/dist/instrument.js +3 -3
- package/dist/instrument.js.map +1 -1
- package/dist/log.d.ts +3 -7
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +20 -45
- package/dist/log.js.map +1 -1
- package/dist/login/index.d.ts +41 -0
- package/dist/login/index.d.ts.map +1 -0
- package/dist/login/index.js +202 -0
- package/dist/login/index.js.map +1 -0
- package/dist/login/portal.d.ts +19 -0
- package/dist/login/portal.d.ts.map +1 -0
- package/dist/login/portal.js +1453 -0
- package/dist/login/portal.js.map +1 -0
- package/dist/login/session.d.ts +33 -0
- package/dist/login/session.d.ts.map +1 -0
- package/dist/login/session.js +68 -0
- package/dist/login/session.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +229 -264
- package/dist/main.js.map +1 -1
- package/dist/provisioner.d.ts +79 -0
- package/dist/provisioner.d.ts.map +1 -0
- package/dist/provisioner.js +437 -0
- package/dist/provisioner.js.map +1 -0
- package/dist/runtime/conversation-orchestrator.d.ts +42 -0
- package/dist/runtime/conversation-orchestrator.d.ts.map +1 -0
- package/dist/runtime/conversation-orchestrator.js +150 -0
- package/dist/runtime/conversation-orchestrator.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/session-runtime.d.ts +27 -0
- package/dist/runtime/session-runtime.d.ts.map +1 -0
- package/dist/runtime/session-runtime.js +211 -0
- package/dist/runtime/session-runtime.js.map +1 -0
- package/dist/sandbox/cloudflare.d.ts +15 -0
- package/dist/sandbox/cloudflare.d.ts.map +1 -0
- package/dist/sandbox/cloudflare.js +137 -0
- package/dist/sandbox/cloudflare.js.map +1 -0
- package/dist/sandbox/container.d.ts +16 -0
- package/dist/sandbox/container.d.ts.map +1 -0
- package/dist/sandbox/container.js +126 -0
- package/dist/sandbox/container.js.map +1 -0
- package/dist/sandbox/errors.d.ts +6 -0
- package/dist/sandbox/errors.d.ts.map +1 -0
- package/dist/sandbox/errors.js +11 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/firecracker.d.ts +17 -0
- package/dist/sandbox/firecracker.d.ts.map +1 -0
- package/dist/sandbox/firecracker.js +212 -0
- package/dist/sandbox/firecracker.js.map +1 -0
- package/dist/sandbox/host.d.ts +11 -0
- package/dist/sandbox/host.d.ts.map +1 -0
- package/dist/sandbox/host.js +89 -0
- package/dist/sandbox/host.js.map +1 -0
- package/dist/sandbox/image.d.ts +5 -0
- package/dist/sandbox/image.d.ts.map +1 -0
- package/dist/sandbox/image.js +30 -0
- package/dist/sandbox/image.js.map +1 -0
- package/dist/sandbox/index.d.ts +22 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +54 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/path-context.d.ts +4 -0
- package/dist/sandbox/path-context.d.ts.map +1 -0
- package/dist/sandbox/path-context.js +20 -0
- package/dist/sandbox/path-context.js.map +1 -0
- package/dist/sandbox/types.d.ts +67 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +2 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/sandbox/utils.d.ts +4 -0
- package/dist/sandbox/utils.d.ts.map +1 -0
- package/dist/sandbox/utils.js +51 -0
- package/dist/sandbox/utils.js.map +1 -0
- package/dist/sandbox.d.ts +1 -39
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +1 -286
- package/dist/sandbox.js.map +1 -1
- package/dist/sentry.d.ts +2 -2
- package/dist/sentry.d.ts.map +1 -1
- package/dist/sentry.js +6 -4
- package/dist/sentry.js.map +1 -1
- package/dist/session-policy.d.ts +13 -0
- package/dist/session-policy.d.ts.map +1 -0
- package/dist/session-policy.js +23 -0
- package/dist/session-policy.js.map +1 -0
- package/dist/session-store.d.ts +35 -8
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +182 -23
- package/dist/session-store.js.map +1 -1
- package/dist/session-view/command.d.ts +5 -0
- package/dist/session-view/command.d.ts.map +1 -0
- package/dist/session-view/command.js +11 -0
- package/dist/session-view/command.js.map +1 -0
- package/dist/session-view/portal.d.ts +16 -0
- package/dist/session-view/portal.d.ts.map +1 -0
- package/dist/session-view/portal.js +1742 -0
- package/dist/session-view/portal.js.map +1 -0
- package/dist/session-view/service.d.ts +34 -0
- package/dist/session-view/service.d.ts.map +1 -0
- package/dist/session-view/service.js +427 -0
- package/dist/session-view/service.js.map +1 -0
- package/dist/session-view/store.d.ts +18 -0
- package/dist/session-view/store.d.ts.map +1 -0
- package/dist/session-view/store.js +39 -0
- package/dist/session-view/store.js.map +1 -0
- package/dist/store.d.ts +4 -7
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +26 -52
- package/dist/store.js.map +1 -1
- package/dist/tool-diagnostics.d.ts +2 -0
- package/dist/tool-diagnostics.d.ts.map +1 -0
- package/dist/tool-diagnostics.js +7 -0
- package/dist/tool-diagnostics.js.map +1 -0
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/event.d.ts +62 -0
- package/dist/tools/event.d.ts.map +1 -0
- package/dist/tools/event.js +138 -0
- package/dist/tools/event.js.map +1 -0
- package/dist/tools/index.d.ts +8 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read.d.ts +1 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.d.ts +1 -1
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js.map +1 -1
- package/dist/trigger.d.ts +31 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/trigger.js +98 -0
- package/dist/trigger.js.map +1 -0
- package/dist/ui-copy.d.ts +12 -0
- package/dist/ui-copy.d.ts.map +1 -0
- package/dist/ui-copy.js +36 -0
- package/dist/ui-copy.js.map +1 -0
- package/dist/vault-routing.d.ts +4 -0
- package/dist/vault-routing.d.ts.map +1 -0
- package/dist/vault-routing.js +16 -0
- package/dist/vault-routing.js.map +1 -0
- package/dist/vault.d.ts +72 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +264 -0
- package/dist/vault.js.map +1 -0
- package/package.json +16 -13
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Bot, BotAdapters, PlatformName } from "../adapter.js";
|
|
2
|
+
import type { DockerContainerManager } from "../provisioner.js";
|
|
3
|
+
import type { SessionRuntime } from "../runtime/session-runtime.js";
|
|
4
|
+
import type { SandboxConfig } from "../sandbox.js";
|
|
5
|
+
import type { VaultManager } from "../vault.js";
|
|
6
|
+
export interface LinkTokenStoreLike {
|
|
7
|
+
create(platform: PlatformName, platformUserId: string, conversationId: string, vaultId: string, providerId: string): {
|
|
8
|
+
token: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface SessionViewTokenStoreLike {
|
|
12
|
+
create(platform: PlatformName, platformUserId: string, conversationId: string, sessionKey: string, sessionFile: string, platformUserName?: string): {
|
|
13
|
+
token: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface CommandServices {
|
|
17
|
+
workingDir: string;
|
|
18
|
+
runtime?: SessionRuntime;
|
|
19
|
+
sandbox: SandboxConfig;
|
|
20
|
+
vaultManager: VaultManager;
|
|
21
|
+
provisioner?: DockerContainerManager;
|
|
22
|
+
linkTokenStore: LinkTokenStoreLike;
|
|
23
|
+
sessionViewTokenStore: SessionViewTokenStoreLike;
|
|
24
|
+
portalBaseUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CommandContext {
|
|
27
|
+
bot: Bot;
|
|
28
|
+
responseCtx: BotAdapters["responseCtx"];
|
|
29
|
+
platform: PlatformName;
|
|
30
|
+
platformUserId: string;
|
|
31
|
+
conversationId: string;
|
|
32
|
+
vaultConversationId?: string;
|
|
33
|
+
sessionKey: string;
|
|
34
|
+
commandText: string;
|
|
35
|
+
privateConversation: boolean;
|
|
36
|
+
services: CommandServices;
|
|
37
|
+
}
|
|
38
|
+
export interface CommandHandler {
|
|
39
|
+
tryHandle(context: CommandContext): Promise<boolean>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IACjC,MAAM,CACJ,QAAQ,EAAE,YAAY,EACtB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,CACJ,QAAQ,EAAE,YAAY,EACtB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,MAAM,GACxB;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,aAAa,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,CAAC,EAAE,sBAAsB,CAAC;IACrC,cAAc,EAAE,kBAAkB,CAAC;IACnC,qBAAqB,EAAE,yBAAyB,CAAC;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,GAAG,CAAC;IACT,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IACxC,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD","sourcesContent":["import type { Bot, BotAdapters, PlatformName } from \"../adapter.js\";\nimport type { DockerContainerManager } from \"../provisioner.js\";\nimport type { SessionRuntime } from \"../runtime/session-runtime.js\";\nimport type { SandboxConfig } from \"../sandbox.js\";\nimport type { VaultManager } from \"../vault.js\";\n\nexport interface LinkTokenStoreLike {\n create(\n platform: PlatformName,\n platformUserId: string,\n conversationId: string,\n vaultId: string,\n providerId: string,\n ): { token: string };\n}\n\nexport interface SessionViewTokenStoreLike {\n create(\n platform: PlatformName,\n platformUserId: string,\n conversationId: string,\n sessionKey: string,\n sessionFile: string,\n platformUserName?: string,\n ): { token: string };\n}\n\nexport interface CommandServices {\n workingDir: string;\n runtime?: SessionRuntime;\n sandbox: SandboxConfig;\n vaultManager: VaultManager;\n provisioner?: DockerContainerManager;\n linkTokenStore: LinkTokenStoreLike;\n sessionViewTokenStore: SessionViewTokenStoreLike;\n portalBaseUrl?: string;\n}\n\nexport interface CommandContext {\n bot: Bot;\n responseCtx: BotAdapters[\"responseCtx\"];\n platform: PlatformName;\n platformUserId: string;\n conversationId: string;\n vaultConversationId?: string;\n sessionKey: string;\n commandText: string;\n privateConversation: boolean;\n services: CommandServices;\n}\n\nexport interface CommandHandler {\n tryHandle(context: CommandContext): Promise<boolean>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Bot, BotAdapters, PlatformName } from \"../adapter.js\";\nimport type { DockerContainerManager } from \"../provisioner.js\";\nimport type { SessionRuntime } from \"../runtime/session-runtime.js\";\nimport type { SandboxConfig } from \"../sandbox.js\";\nimport type { VaultManager } from \"../vault.js\";\n\nexport interface LinkTokenStoreLike {\n create(\n platform: PlatformName,\n platformUserId: string,\n conversationId: string,\n vaultId: string,\n providerId: string,\n ): { token: string };\n}\n\nexport interface SessionViewTokenStoreLike {\n create(\n platform: PlatformName,\n platformUserId: string,\n conversationId: string,\n sessionKey: string,\n sessionFile: string,\n platformUserName?: string,\n ): { token: string };\n}\n\nexport interface CommandServices {\n workingDir: string;\n runtime?: SessionRuntime;\n sandbox: SandboxConfig;\n vaultManager: VaultManager;\n provisioner?: DockerContainerManager;\n linkTokenStore: LinkTokenStoreLike;\n sessionViewTokenStore: SessionViewTokenStoreLike;\n portalBaseUrl?: string;\n}\n\nexport interface CommandContext {\n bot: Bot;\n responseCtx: BotAdapters[\"responseCtx\"];\n platform: PlatformName;\n platformUserId: string;\n conversationId: string;\n vaultConversationId?: string;\n sessionKey: string;\n commandText: string;\n privateConversation: boolean;\n services: CommandServices;\n}\n\nexport interface CommandHandler {\n tryHandle(context: CommandContext): Promise<boolean>;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BotEvent } from "../adapter.js";
|
|
2
|
+
import type { CommandContext } from "./types.js";
|
|
3
|
+
export declare function replyWithContext(responseCtx: CommandContext["responseCtx"], text: string): Promise<void>;
|
|
4
|
+
export declare function replyDiagnosticWithContext(responseCtx: CommandContext["responseCtx"], text: string, options?: {
|
|
5
|
+
style?: "muted" | "error";
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export declare function isPrivateConversation(event: BotEvent): boolean;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/commands/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,EAC1C,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,EAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,GACtC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAE9D","sourcesContent":["import type { BotEvent } from \"../adapter.js\";\nimport type { CommandContext } from \"./types.js\";\n\nexport async function replyWithContext(\n responseCtx: CommandContext[\"responseCtx\"],\n text: string,\n): Promise<void> {\n await responseCtx.setTyping(false);\n await responseCtx.setWorking(false);\n await responseCtx.respond(text);\n}\n\nexport async function replyDiagnosticWithContext(\n responseCtx: CommandContext[\"responseCtx\"],\n text: string,\n options?: { style?: \"muted\" | \"error\" },\n): Promise<void> {\n await responseCtx.setTyping(false);\n await responseCtx.setWorking(false);\n await responseCtx.respondDiagnostic(text, options);\n}\n\nexport function isPrivateConversation(event: BotEvent): boolean {\n return event.conversationKind === \"direct\" || event.type === \"dm\";\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function replyWithContext(responseCtx, text) {
|
|
2
|
+
await responseCtx.setTyping(false);
|
|
3
|
+
await responseCtx.setWorking(false);
|
|
4
|
+
await responseCtx.respond(text);
|
|
5
|
+
}
|
|
6
|
+
export async function replyDiagnosticWithContext(responseCtx, text, options) {
|
|
7
|
+
await responseCtx.setTyping(false);
|
|
8
|
+
await responseCtx.setWorking(false);
|
|
9
|
+
await responseCtx.respondDiagnostic(text, options);
|
|
10
|
+
}
|
|
11
|
+
export function isPrivateConversation(event) {
|
|
12
|
+
return event.conversationKind === "direct" || event.type === "dm";
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/commands/utils.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,WAA0C,EAC1C,IAAY;IAEZ,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,WAA0C,EAC1C,IAAY,EACZ,OAAuC;IAEvC,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAe;IACnD,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACpE,CAAC","sourcesContent":["import type { BotEvent } from \"../adapter.js\";\nimport type { CommandContext } from \"./types.js\";\n\nexport async function replyWithContext(\n responseCtx: CommandContext[\"responseCtx\"],\n text: string,\n): Promise<void> {\n await responseCtx.setTyping(false);\n await responseCtx.setWorking(false);\n await responseCtx.respond(text);\n}\n\nexport async function replyDiagnosticWithContext(\n responseCtx: CommandContext[\"responseCtx\"],\n text: string,\n options?: { style?: \"muted\" | \"error\" },\n): Promise<void> {\n await responseCtx.setTyping(false);\n await responseCtx.setWorking(false);\n await responseCtx.respondDiagnostic(text, options);\n}\n\nexport function isPrivateConversation(event: BotEvent): boolean {\n return event.conversationKind === \"direct\" || event.type === \"dm\";\n}\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,14 +1,60 @@
|
|
|
1
|
+
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
+
export declare class MissingGlobalSettingsError extends Error {
|
|
3
|
+
readonly settingsPath: string;
|
|
4
|
+
constructor(settingsPath: string);
|
|
5
|
+
}
|
|
1
6
|
export interface AgentConfig {
|
|
2
7
|
provider: string;
|
|
3
8
|
model: string;
|
|
4
|
-
thinkingLevel
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
logLevel?: "trace" | "debug" | "info" | "warn" | "error";
|
|
9
|
+
thinkingLevel: ThinkingLevel;
|
|
10
|
+
logFormat: "console" | "json";
|
|
11
|
+
logLevel: "trace" | "debug" | "info" | "warn" | "error";
|
|
8
12
|
sentryDsn?: string;
|
|
13
|
+
sandboxCpus?: string;
|
|
14
|
+
sandboxMemory?: string;
|
|
15
|
+
sandboxBoostCpus?: string;
|
|
16
|
+
sandboxBoostMemory?: string;
|
|
17
|
+
sandboxImageWorkspaceMount?: "private" | "full";
|
|
18
|
+
}
|
|
19
|
+
export interface AutoReplyConfig {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
rules: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface JudgeModelConfig {
|
|
24
|
+
provider: string;
|
|
25
|
+
model: string;
|
|
9
26
|
}
|
|
10
|
-
export declare function loadAgentConfig(
|
|
27
|
+
export declare function loadAgentConfig(): AgentConfig;
|
|
28
|
+
export declare function loadAgentConfigForConversation(conversationDir: string): AgentConfig;
|
|
29
|
+
export declare function saveConversationModelConfig(conversationDir: string, config: Pick<AgentConfig, "provider" | "model"> & Partial<Pick<AgentConfig, "thinkingLevel">>): void;
|
|
30
|
+
export declare function saveConversationSandboxConfig(conversationDir: string, config: {
|
|
31
|
+
imageWorkspaceMount: AgentConfig["sandboxImageWorkspaceMount"];
|
|
32
|
+
}): void;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the model used to judge auto-reply rules. Falls back to the main
|
|
35
|
+
* llm.{provider,model} when llm.autoReply is not set, so a missing override
|
|
36
|
+
* keeps current behavior.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadAutoReplyJudgeModel(conversationDir?: string): JudgeModelConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Load the mom-compatible auto-reply marker file state for a conversation.
|
|
41
|
+
*
|
|
42
|
+
* - `auto-reply` exists: enabled; empty file means reply to any top-level message.
|
|
43
|
+
* - `auto-reply.disabled` exists: disabled, preserving any rules text for re-enable.
|
|
44
|
+
* - neither exists: disabled.
|
|
45
|
+
*/
|
|
46
|
+
export declare function loadConversationAutoReplyConfig(conversationDir: string): AutoReplyConfig;
|
|
47
|
+
/** Save auto-reply state using mom-compatible marker files. */
|
|
48
|
+
export declare function saveConversationAutoReplyConfig(conversationDir: string, config: AutoReplyConfig): void;
|
|
11
49
|
export declare function resolveWorkspaceDirFromArgv(args?: string[]): string | undefined;
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
50
|
+
export declare function resolveStateDirFromArgv(args?: string[]): string;
|
|
51
|
+
export declare function resolveSentryDsn(): string | undefined;
|
|
52
|
+
export declare function createGlobalSettingsFile(stateDir: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Externally-visible base URL of the link/OAuth server, e.g.
|
|
55
|
+
* `https://mama.example.com` (no trailing slash). Read from `MAMA_LINK_URL`,
|
|
56
|
+
* the same env var the bot uses to build credential onboarding links.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveLinkBaseUrl(): string | undefined;
|
|
59
|
+
export declare function saveAgentConfig(config: Partial<AgentConfig>): void;
|
|
14
60
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA+BD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAYjE;AAED,wBAAgB,2BAA2B,CAAC,IAAI,WAAwB,GAAG,MAAM,GAAG,SAAS,CAuB5F;AAED,wBAAgB,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS1E;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAwBxF","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\n\nexport interface AgentConfig {\n provider: string;\n model: string;\n thinkingLevel?: string;\n sessionScope?: \"thread\" | \"channel\";\n logFormat?: \"console\" | \"json\";\n logLevel?: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\";\n sentryDsn?: string;\n}\n\nconst DEFAULTS: AgentConfig = {\n provider: \"anthropic\",\n model: \"claude-sonnet-4-5\",\n thinkingLevel: \"off\",\n sessionScope: \"thread\",\n logFormat: \"console\",\n logLevel: \"info\",\n};\n\nfunction loadRawAgentConfig(workspaceDir: string): Partial<AgentConfig> {\n const settingsPath = join(workspaceDir, \"settings.json\");\n\n if (!existsSync(settingsPath)) {\n return {};\n }\n\n try {\n const raw = readFileSync(settingsPath, \"utf-8\");\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\") {\n return parsed as Partial<AgentConfig>;\n }\n } catch {\n // Ignore parse errors, fall through to env/defaults\n }\n\n return {};\n}\n\nexport function loadAgentConfig(workspaceDir: string): AgentConfig {\n const fromFile = loadRawAgentConfig(workspaceDir);\n\n const provider = fromFile.provider || process.env.MOM_AI_PROVIDER || DEFAULTS.provider;\n const model = fromFile.model || process.env.MOM_AI_MODEL || DEFAULTS.model;\n const thinkingLevel = fromFile.thinkingLevel ?? DEFAULTS.thinkingLevel;\n const sessionScope = fromFile.sessionScope ?? DEFAULTS.sessionScope;\n const logFormat = fromFile.logFormat ?? DEFAULTS.logFormat;\n const logLevel = fromFile.logLevel ?? DEFAULTS.logLevel;\n const sentryDsn = fromFile.sentryDsn ?? process.env.SENTRY_DSN;\n\n return { provider, model, thinkingLevel, sessionScope, logFormat, logLevel, sentryDsn };\n}\n\nexport function resolveWorkspaceDirFromArgv(args = process.argv.slice(2)): string | undefined {\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n\n if (arg === \"--sandbox\" || arg === \"--download\") {\n i += 1;\n continue;\n }\n\n if (arg === \"--version\" || arg === \"-v\" || arg === \"-V\") {\n continue;\n }\n\n if (arg.startsWith(\"--sandbox=\") || arg.startsWith(\"--download=\")) {\n continue;\n }\n\n if (!arg.startsWith(\"-\")) {\n return arg;\n }\n }\n\n return undefined;\n}\n\nexport function resolveSentryDsn(workspaceDir?: string): string | undefined {\n if (workspaceDir) {\n const fromFile = loadRawAgentConfig(workspaceDir);\n if (fromFile.sentryDsn) {\n return fromFile.sentryDsn;\n }\n }\n\n return process.env.SENTRY_DSN;\n}\n\nexport function saveAgentConfig(workspaceDir: string, config: Partial<AgentConfig>): void {\n const settingsPath = join(workspaceDir, \"settings.json\");\n\n let existing: Partial<AgentConfig> = {};\n if (existsSync(settingsPath)) {\n try {\n const raw = readFileSync(settingsPath, \"utf-8\");\n const parsed = JSON.parse(raw);\n if (parsed && typeof parsed === \"object\") {\n existing = parsed as Partial<AgentConfig>;\n }\n } catch {\n // Start fresh if file is malformed\n }\n }\n\n const merged = { ...existing, ...config };\n\n const dir = dirname(settingsPath);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n writeFileSync(settingsPath, JSON.stringify(merged, null, 2), \"utf-8\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAOnE,qBAAa,0BAA2B,SAAQ,KAAK;aACvB,YAAY,EAAE,MAAM;IAAhD,YAA4B,YAAY,EAAE,MAAM,EAG/C;CACF;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;IAC9B,QAAQ,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0BAA0B,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CACjD;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AA8JD,wBAAgB,eAAe,IAAI,WAAW,CAE7C;AAED,wBAAgB,8BAA8B,CAAC,eAAe,EAAE,MAAM,GAAG,WAAW,CAMnF;AAED,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,GAC5F,IAAI,CAWN;AAED,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE;IAAE,mBAAmB,EAAE,WAAW,CAAC,4BAA4B,CAAC,CAAA;CAAE,GACzE,IAAI,CAiBN;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAUlF;AAUD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,eAAe,EAAE,MAAM,GAAG,eAAe,CAYxF;AAED,+DAA+D;AAC/D,wBAAgB,+BAA+B,CAC7C,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,eAAe,GACtB,IAAI,CAeN;AAED,wBAAgB,2BAA2B,CAAC,IAAI,WAAwB,GAAG,MAAM,GAAG,SAAS,CA2B5F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,WAAwB,GAAG,MAAM,CAY5E;AAED,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAOrD;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUjE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAIvD;AAyDD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAsBlE","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { dirname, join, resolve } from \"path\";\nimport { ensureDirExists, isRecord, readJsonFileIfExists } from \"./file-guards.js\";\nimport { atomicWritePrivateFile } from \"./fs-atomic.js\";\n\nexport class MissingGlobalSettingsError extends Error {\n constructor(public readonly settingsPath: string) {\n super(`Missing global settings file at ${settingsPath}`);\n this.name = \"MissingGlobalSettingsError\";\n }\n}\n\nexport interface AgentConfig {\n provider: string;\n model: string;\n thinkingLevel: ThinkingLevel;\n logFormat: \"console\" | \"json\";\n logLevel: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\";\n sentryDsn?: string;\n sandboxCpus?: string;\n sandboxMemory?: string;\n sandboxBoostCpus?: string;\n sandboxBoostMemory?: string;\n sandboxImageWorkspaceMount?: \"private\" | \"full\";\n}\n\nexport interface AutoReplyConfig {\n enabled: boolean;\n rules: string[];\n}\n\nexport interface JudgeModelConfig {\n provider: string;\n model: string;\n}\n\nconst ONBOARD_SETTINGS: SettingsFileConfig = {\n llm: {\n provider: \"anthropic\",\n model: \"claude-sonnet-4-6\",\n thinkingLevel: \"off\",\n autoReply: {\n provider: \"anthropic\",\n model: \"claude-haiku-4-5\",\n },\n },\n log: {\n format: \"console\",\n level: \"info\",\n },\n sandbox: {\n cpus: \"0.5\",\n memory: \"1g\",\n boost: {\n cpus: \"2\",\n memory: \"4g\",\n },\n image: {\n workspaceMount: \"private\",\n },\n },\n};\n\ninterface SettingsFileConfig {\n llm?: Partial<Pick<AgentConfig, \"provider\" | \"model\" | \"thinkingLevel\">> & {\n autoReply?: { provider?: string; model?: string };\n };\n log?: { format?: AgentConfig[\"logFormat\"]; level?: AgentConfig[\"logLevel\"] };\n sentry?: { dsn?: string };\n sandbox?: {\n cpus?: string;\n memory?: string;\n boost?: { cpus?: string; memory?: string };\n image?: { workspaceMount?: AgentConfig[\"sandboxImageWorkspaceMount\"] };\n };\n autoReply?: {\n enabled?: boolean;\n rules?: string[];\n };\n}\n\nfunction loadSettingsFile(settingsPath: string): SettingsFileConfig | undefined {\n return readJsonFileIfExists(\n settingsPath,\n (value): value is SettingsFileConfig => isRecord(value),\n (detail) =>\n detail === \"unexpected JSON shape\"\n ? `Malformed settings file at ${settingsPath}: expected a JSON object at the top level`\n : `Malformed settings file at ${settingsPath}: ${detail}`,\n );\n}\n\nfunction getStateDir(): string {\n const raw = process.env.MAMA_STATE_DIR?.trim();\n return raw ? resolve(raw) : join(homedir(), \".mama\");\n}\n\nfunction normalizeSettingsConfig(config: SettingsFileConfig): Partial<AgentConfig> {\n return {\n ...(config.llm?.provider !== undefined ? { provider: config.llm.provider } : {}),\n ...(config.llm?.model !== undefined ? { model: config.llm.model } : {}),\n ...(config.llm?.thinkingLevel !== undefined ? { thinkingLevel: config.llm.thinkingLevel } : {}),\n ...(config.log?.format !== undefined ? { logFormat: config.log.format } : {}),\n ...(config.log?.level !== undefined ? { logLevel: config.log.level } : {}),\n ...(config.sentry?.dsn !== undefined ? { sentryDsn: config.sentry.dsn } : {}),\n ...(config.sandbox?.cpus !== undefined ? { sandboxCpus: config.sandbox.cpus } : {}),\n ...(config.sandbox?.memory !== undefined ? { sandboxMemory: config.sandbox.memory } : {}),\n ...(config.sandbox?.boost?.cpus !== undefined\n ? { sandboxBoostCpus: config.sandbox.boost.cpus }\n : {}),\n ...(config.sandbox?.boost?.memory !== undefined\n ? { sandboxBoostMemory: config.sandbox.boost.memory }\n : {}),\n ...(config.sandbox?.image?.workspaceMount !== undefined\n ? { sandboxImageWorkspaceMount: config.sandbox.image.workspaceMount }\n : {}),\n };\n}\n\nfunction getSettingsPath(): string {\n return join(getStateDir(), \"settings.json\");\n}\n\nfunction requireGlobalSettings(): SettingsFileConfig {\n const settingsPath = getSettingsPath();\n const config = loadSettingsFile(settingsPath);\n if (!config) {\n throw new MissingGlobalSettingsError(settingsPath);\n }\n return config;\n}\n\nfunction requireString(value: string | undefined, path: string): string {\n if (!value) {\n throw new Error(\n `Missing required global setting: ${path}. Run \\`mama --onboard\\` to create settings.json.`,\n );\n }\n return value;\n}\n\nfunction requireThinkingLevel(value: ThinkingLevel | undefined): ThinkingLevel {\n return requireString(value, \"llm.thinkingLevel\") as ThinkingLevel;\n}\n\nfunction requireLogFormat(value: AgentConfig[\"logFormat\"] | undefined): AgentConfig[\"logFormat\"] {\n if (value !== \"console\" && value !== \"json\") {\n throw new Error(\"Missing or invalid required global setting: log.format\");\n }\n return value;\n}\n\nfunction requireLogLevel(value: AgentConfig[\"logLevel\"] | undefined): AgentConfig[\"logLevel\"] {\n const allowed = [\"trace\", \"debug\", \"info\", \"warn\", \"error\"];\n if (!value || !allowed.includes(value)) {\n throw new Error(\"Missing or invalid required global setting: log.level\");\n }\n return value;\n}\n\nfunction toAgentConfig(fromFile: Partial<AgentConfig>): AgentConfig {\n const provider = requireString(fromFile.provider, \"llm.provider\");\n const model = requireString(fromFile.model, \"llm.model\");\n const thinkingLevel = requireThinkingLevel(fromFile.thinkingLevel);\n const logFormat = requireLogFormat(fromFile.logFormat);\n const logLevel = requireLogLevel(fromFile.logLevel);\n const sentryDsn = fromFile.sentryDsn ?? process.env.SENTRY_DSN;\n const sandboxCpus = fromFile.sandboxCpus;\n const sandboxMemory = fromFile.sandboxMemory;\n const sandboxBoostCpus = fromFile.sandboxBoostCpus;\n const sandboxBoostMemory = fromFile.sandboxBoostMemory;\n const sandboxImageWorkspaceMount = fromFile.sandboxImageWorkspaceMount;\n\n return {\n provider,\n model,\n thinkingLevel,\n logFormat,\n logLevel,\n sentryDsn,\n sandboxCpus,\n sandboxMemory,\n sandboxBoostCpus,\n sandboxBoostMemory,\n sandboxImageWorkspaceMount,\n };\n}\n\nfunction loadRawAgentConfig(): Partial<AgentConfig> {\n return normalizeSettingsConfig(requireGlobalSettings());\n}\n\nexport function loadAgentConfig(): AgentConfig {\n return toAgentConfig(loadRawAgentConfig());\n}\n\nexport function loadAgentConfigForConversation(conversationDir: string): AgentConfig {\n const globalConfig = loadRawAgentConfig();\n const conversationConfig = normalizeSettingsConfig(\n loadSettingsFile(join(conversationDir, \"settings.json\")) ?? {},\n );\n return toAgentConfig({ ...globalConfig, ...conversationConfig });\n}\n\nexport function saveConversationModelConfig(\n conversationDir: string,\n config: Pick<AgentConfig, \"provider\" | \"model\"> & Partial<Pick<AgentConfig, \"thinkingLevel\">>,\n): void {\n if (!existsSync(conversationDir)) {\n ensureDirExists(conversationDir);\n }\n const settingsPath = join(conversationDir, \"settings.json\");\n const existing = loadSettingsFile(settingsPath) ?? {};\n const scopedConfig: SettingsFileConfig = {\n ...existing,\n llm: { ...existing.llm, ...config },\n };\n atomicWritePrivateFile(settingsPath, JSON.stringify(scopedConfig, null, 2));\n}\n\nexport function saveConversationSandboxConfig(\n conversationDir: string,\n config: { imageWorkspaceMount: AgentConfig[\"sandboxImageWorkspaceMount\"] },\n): void {\n if (!existsSync(conversationDir)) {\n ensureDirExists(conversationDir);\n }\n const settingsPath = join(conversationDir, \"settings.json\");\n const existing = loadSettingsFile(settingsPath) ?? {};\n const scopedConfig: SettingsFileConfig = {\n ...existing,\n sandbox: {\n ...existing.sandbox,\n image: {\n ...existing.sandbox?.image,\n workspaceMount: config.imageWorkspaceMount,\n },\n },\n };\n atomicWritePrivateFile(settingsPath, JSON.stringify(scopedConfig, null, 2));\n}\n\n/**\n * Resolve the model used to judge auto-reply rules. Falls back to the main\n * llm.{provider,model} when llm.autoReply is not set, so a missing override\n * keeps current behavior.\n */\nexport function loadAutoReplyJudgeModel(conversationDir?: string): JudgeModelConfig {\n const global = requireGlobalSettings();\n const local = conversationDir\n ? (loadSettingsFile(join(conversationDir, \"settings.json\")) ?? {})\n : {};\n const merged: SettingsFileConfig[\"llm\"] = { ...global.llm, ...local.llm };\n const judge = { ...global.llm?.autoReply, ...local.llm?.autoReply };\n const provider = requireString(judge.provider ?? merged?.provider, \"llm.autoReply.provider\");\n const model = requireString(judge.model ?? merged?.model, \"llm.autoReply.model\");\n return { provider, model };\n}\n\nconst AUTO_REPLY_FILE = \"auto-reply\";\nconst AUTO_REPLY_DISABLED_FILE = \"auto-reply.disabled\";\n\nfunction readAutoReplyRulesFile(path: string): string[] {\n const text = readFileSync(path, \"utf-8\").trim();\n return text ? [text] : [];\n}\n\n/**\n * Load the mom-compatible auto-reply marker file state for a conversation.\n *\n * - `auto-reply` exists: enabled; empty file means reply to any top-level message.\n * - `auto-reply.disabled` exists: disabled, preserving any rules text for re-enable.\n * - neither exists: disabled.\n */\nexport function loadConversationAutoReplyConfig(conversationDir: string): AutoReplyConfig {\n const enabledPath = join(conversationDir, AUTO_REPLY_FILE);\n if (existsSync(enabledPath)) {\n return { enabled: true, rules: readAutoReplyRulesFile(enabledPath) };\n }\n\n const disabledPath = join(conversationDir, AUTO_REPLY_DISABLED_FILE);\n if (existsSync(disabledPath)) {\n return { enabled: false, rules: readAutoReplyRulesFile(disabledPath) };\n }\n\n return { enabled: false, rules: [] };\n}\n\n/** Save auto-reply state using mom-compatible marker files. */\nexport function saveConversationAutoReplyConfig(\n conversationDir: string,\n config: AutoReplyConfig,\n): void {\n if (!existsSync(conversationDir)) {\n mkdirSync(conversationDir, { recursive: true });\n }\n\n const enabledPath = join(conversationDir, AUTO_REPLY_FILE);\n const disabledPath = join(conversationDir, AUTO_REPLY_DISABLED_FILE);\n const targetPath = config.enabled ? enabledPath : disabledPath;\n const otherPath = config.enabled ? disabledPath : enabledPath;\n\n if (existsSync(otherPath)) {\n renameSync(otherPath, targetPath);\n }\n\n writeFileSync(targetPath, config.rules.join(\"\\n\"), \"utf-8\");\n}\n\nexport function resolveWorkspaceDirFromArgv(args = process.argv.slice(2)): string | undefined {\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n\n if (arg === \"--sandbox\" || arg === \"--download\" || arg === \"--state-dir\") {\n i += 1;\n continue;\n }\n\n if (arg === \"--version\" || arg === \"-v\" || arg === \"-V\" || arg === \"--onboard\") {\n continue;\n }\n\n if (\n arg.startsWith(\"--sandbox=\") ||\n arg.startsWith(\"--download=\") ||\n arg.startsWith(\"--state-dir=\")\n ) {\n continue;\n }\n\n if (!arg.startsWith(\"-\")) {\n return arg;\n }\n }\n\n return undefined;\n}\n\nexport function resolveStateDirFromArgv(args = process.argv.slice(2)): string {\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg.startsWith(\"--state-dir=\")) {\n return resolve(arg.slice(\"--state-dir=\".length));\n }\n if (arg === \"--state-dir\") {\n return resolve(args[++i] || \"\");\n }\n }\n\n return join(homedir(), \".mama\");\n}\n\nexport function resolveSentryDsn(): string | undefined {\n const fromFile = normalizeSettingsConfig(loadSettingsFile(getSettingsPath()) ?? {});\n if (fromFile.sentryDsn) {\n return fromFile.sentryDsn;\n }\n\n return process.env.SENTRY_DSN;\n}\n\nexport function createGlobalSettingsFile(stateDir: string): string {\n const settingsPath = join(stateDir, \"settings.json\");\n if (existsSync(settingsPath)) {\n throw new Error(`Global settings already exists at ${settingsPath}`);\n }\n if (!existsSync(stateDir)) {\n ensureDirExists(stateDir);\n }\n atomicWritePrivateFile(settingsPath, JSON.stringify(ONBOARD_SETTINGS, null, 2));\n return settingsPath;\n}\n\n/**\n * Externally-visible base URL of the link/OAuth server, e.g.\n * `https://mama.example.com` (no trailing slash). Read from `MAMA_LINK_URL`,\n * the same env var the bot uses to build credential onboarding links.\n */\nexport function resolveLinkBaseUrl(): string | undefined {\n const raw = process.env.MAMA_LINK_URL?.trim();\n if (!raw) return undefined;\n return raw.replace(/\\/+$/, \"\");\n}\n\nfunction hasDefinedValue(values: Record<string, unknown> | undefined): boolean {\n return values !== undefined && Object.values(values).some((value) => value !== undefined);\n}\n\nfunction compactSettingsConfig(config: SettingsFileConfig): SettingsFileConfig {\n return {\n ...(hasDefinedValue(config.llm) ? { llm: config.llm } : {}),\n ...(hasDefinedValue(config.log) ? { log: config.log } : {}),\n ...(hasDefinedValue(config.sentry) ? { sentry: config.sentry } : {}),\n ...(hasDefinedValue(config.sandbox) ? { sandbox: config.sandbox } : {}),\n ...(hasDefinedValue(config.autoReply) ? { autoReply: config.autoReply } : {}),\n };\n}\n\nfunction patchSettingsConfig(\n existing: SettingsFileConfig,\n config: Partial<AgentConfig>,\n): SettingsFileConfig {\n const patched: SettingsFileConfig = {\n ...existing,\n llm: {\n ...existing.llm,\n ...(config.provider !== undefined ? { provider: config.provider } : {}),\n ...(config.model !== undefined ? { model: config.model } : {}),\n ...(config.thinkingLevel !== undefined ? { thinkingLevel: config.thinkingLevel } : {}),\n },\n log: {\n ...existing.log,\n ...(config.logFormat !== undefined ? { format: config.logFormat } : {}),\n ...(config.logLevel !== undefined ? { level: config.logLevel } : {}),\n },\n sentry: {\n ...existing.sentry,\n ...(config.sentryDsn !== undefined ? { dsn: config.sentryDsn } : {}),\n },\n sandbox: {\n ...existing.sandbox,\n ...(config.sandboxCpus !== undefined ? { cpus: config.sandboxCpus } : {}),\n ...(config.sandboxMemory !== undefined ? { memory: config.sandboxMemory } : {}),\n ...(config.sandboxBoostCpus !== undefined || config.sandboxBoostMemory !== undefined\n ? {\n boost: {\n ...existing.sandbox?.boost,\n ...(config.sandboxBoostCpus !== undefined ? { cpus: config.sandboxBoostCpus } : {}),\n ...(config.sandboxBoostMemory !== undefined\n ? { memory: config.sandboxBoostMemory }\n : {}),\n },\n }\n : {}),\n },\n };\n return compactSettingsConfig(patched);\n}\n\nexport function saveAgentConfig(config: Partial<AgentConfig>): void {\n const settingsPath = join(getStateDir(), \"settings.json\");\n\n let existing: SettingsFileConfig = ONBOARD_SETTINGS;\n if (existsSync(settingsPath)) {\n try {\n existing = loadSettingsFile(settingsPath) ?? {};\n } catch (err) {\n const detail = err instanceof Error ? err.message : String(err);\n const message = detail.startsWith(\"Malformed settings file\")\n ? detail.replace(\"Malformed settings file\", \"Refusing to overwrite malformed settings file\")\n : detail;\n throw new Error(message, { cause: err });\n }\n }\n\n const merged = patchSettingsConfig(existing, config);\n\n const dir = dirname(settingsPath);\n ensureDirExists(dir);\n\n atomicWritePrivateFile(settingsPath, JSON.stringify(merged, null, 2));\n}\n"]}
|
package/dist/config.js
CHANGED
|
@@ -1,52 +1,238 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { dirname, join, resolve } from "path";
|
|
4
|
+
import { ensureDirExists, isRecord, readJsonFileIfExists } from "./file-guards.js";
|
|
5
|
+
import { atomicWritePrivateFile } from "./fs-atomic.js";
|
|
6
|
+
export class MissingGlobalSettingsError extends Error {
|
|
7
|
+
constructor(settingsPath) {
|
|
8
|
+
super(`Missing global settings file at ${settingsPath}`);
|
|
9
|
+
this.settingsPath = settingsPath;
|
|
10
|
+
this.name = "MissingGlobalSettingsError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const ONBOARD_SETTINGS = {
|
|
14
|
+
llm: {
|
|
15
|
+
provider: "anthropic",
|
|
16
|
+
model: "claude-sonnet-4-6",
|
|
17
|
+
thinkingLevel: "off",
|
|
18
|
+
autoReply: {
|
|
19
|
+
provider: "anthropic",
|
|
20
|
+
model: "claude-haiku-4-5",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
log: {
|
|
24
|
+
format: "console",
|
|
25
|
+
level: "info",
|
|
26
|
+
},
|
|
27
|
+
sandbox: {
|
|
28
|
+
cpus: "0.5",
|
|
29
|
+
memory: "1g",
|
|
30
|
+
boost: {
|
|
31
|
+
cpus: "2",
|
|
32
|
+
memory: "4g",
|
|
33
|
+
},
|
|
34
|
+
image: {
|
|
35
|
+
workspaceMount: "private",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
10
38
|
};
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
function loadSettingsFile(settingsPath) {
|
|
40
|
+
return readJsonFileIfExists(settingsPath, (value) => isRecord(value), (detail) => detail === "unexpected JSON shape"
|
|
41
|
+
? `Malformed settings file at ${settingsPath}: expected a JSON object at the top level`
|
|
42
|
+
: `Malformed settings file at ${settingsPath}: ${detail}`);
|
|
43
|
+
}
|
|
44
|
+
function getStateDir() {
|
|
45
|
+
const raw = process.env.MAMA_STATE_DIR?.trim();
|
|
46
|
+
return raw ? resolve(raw) : join(homedir(), ".mama");
|
|
47
|
+
}
|
|
48
|
+
function normalizeSettingsConfig(config) {
|
|
49
|
+
return {
|
|
50
|
+
...(config.llm?.provider !== undefined ? { provider: config.llm.provider } : {}),
|
|
51
|
+
...(config.llm?.model !== undefined ? { model: config.llm.model } : {}),
|
|
52
|
+
...(config.llm?.thinkingLevel !== undefined ? { thinkingLevel: config.llm.thinkingLevel } : {}),
|
|
53
|
+
...(config.log?.format !== undefined ? { logFormat: config.log.format } : {}),
|
|
54
|
+
...(config.log?.level !== undefined ? { logLevel: config.log.level } : {}),
|
|
55
|
+
...(config.sentry?.dsn !== undefined ? { sentryDsn: config.sentry.dsn } : {}),
|
|
56
|
+
...(config.sandbox?.cpus !== undefined ? { sandboxCpus: config.sandbox.cpus } : {}),
|
|
57
|
+
...(config.sandbox?.memory !== undefined ? { sandboxMemory: config.sandbox.memory } : {}),
|
|
58
|
+
...(config.sandbox?.boost?.cpus !== undefined
|
|
59
|
+
? { sandboxBoostCpus: config.sandbox.boost.cpus }
|
|
60
|
+
: {}),
|
|
61
|
+
...(config.sandbox?.boost?.memory !== undefined
|
|
62
|
+
? { sandboxBoostMemory: config.sandbox.boost.memory }
|
|
63
|
+
: {}),
|
|
64
|
+
...(config.sandbox?.image?.workspaceMount !== undefined
|
|
65
|
+
? { sandboxImageWorkspaceMount: config.sandbox.image.workspaceMount }
|
|
66
|
+
: {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function getSettingsPath() {
|
|
70
|
+
return join(getStateDir(), "settings.json");
|
|
71
|
+
}
|
|
72
|
+
function requireGlobalSettings() {
|
|
73
|
+
const settingsPath = getSettingsPath();
|
|
74
|
+
const config = loadSettingsFile(settingsPath);
|
|
75
|
+
if (!config) {
|
|
76
|
+
throw new MissingGlobalSettingsError(settingsPath);
|
|
77
|
+
}
|
|
78
|
+
return config;
|
|
79
|
+
}
|
|
80
|
+
function requireString(value, path) {
|
|
81
|
+
if (!value) {
|
|
82
|
+
throw new Error(`Missing required global setting: ${path}. Run \`mama --onboard\` to create settings.json.`);
|
|
22
83
|
}
|
|
23
|
-
|
|
24
|
-
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function requireThinkingLevel(value) {
|
|
87
|
+
return requireString(value, "llm.thinkingLevel");
|
|
88
|
+
}
|
|
89
|
+
function requireLogFormat(value) {
|
|
90
|
+
if (value !== "console" && value !== "json") {
|
|
91
|
+
throw new Error("Missing or invalid required global setting: log.format");
|
|
25
92
|
}
|
|
26
|
-
return
|
|
93
|
+
return value;
|
|
27
94
|
}
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
95
|
+
function requireLogLevel(value) {
|
|
96
|
+
const allowed = ["trace", "debug", "info", "warn", "error"];
|
|
97
|
+
if (!value || !allowed.includes(value)) {
|
|
98
|
+
throw new Error("Missing or invalid required global setting: log.level");
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
function toAgentConfig(fromFile) {
|
|
103
|
+
const provider = requireString(fromFile.provider, "llm.provider");
|
|
104
|
+
const model = requireString(fromFile.model, "llm.model");
|
|
105
|
+
const thinkingLevel = requireThinkingLevel(fromFile.thinkingLevel);
|
|
106
|
+
const logFormat = requireLogFormat(fromFile.logFormat);
|
|
107
|
+
const logLevel = requireLogLevel(fromFile.logLevel);
|
|
36
108
|
const sentryDsn = fromFile.sentryDsn ?? process.env.SENTRY_DSN;
|
|
37
|
-
|
|
109
|
+
const sandboxCpus = fromFile.sandboxCpus;
|
|
110
|
+
const sandboxMemory = fromFile.sandboxMemory;
|
|
111
|
+
const sandboxBoostCpus = fromFile.sandboxBoostCpus;
|
|
112
|
+
const sandboxBoostMemory = fromFile.sandboxBoostMemory;
|
|
113
|
+
const sandboxImageWorkspaceMount = fromFile.sandboxImageWorkspaceMount;
|
|
114
|
+
return {
|
|
115
|
+
provider,
|
|
116
|
+
model,
|
|
117
|
+
thinkingLevel,
|
|
118
|
+
logFormat,
|
|
119
|
+
logLevel,
|
|
120
|
+
sentryDsn,
|
|
121
|
+
sandboxCpus,
|
|
122
|
+
sandboxMemory,
|
|
123
|
+
sandboxBoostCpus,
|
|
124
|
+
sandboxBoostMemory,
|
|
125
|
+
sandboxImageWorkspaceMount,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function loadRawAgentConfig() {
|
|
129
|
+
return normalizeSettingsConfig(requireGlobalSettings());
|
|
130
|
+
}
|
|
131
|
+
export function loadAgentConfig() {
|
|
132
|
+
return toAgentConfig(loadRawAgentConfig());
|
|
133
|
+
}
|
|
134
|
+
export function loadAgentConfigForConversation(conversationDir) {
|
|
135
|
+
const globalConfig = loadRawAgentConfig();
|
|
136
|
+
const conversationConfig = normalizeSettingsConfig(loadSettingsFile(join(conversationDir, "settings.json")) ?? {});
|
|
137
|
+
return toAgentConfig({ ...globalConfig, ...conversationConfig });
|
|
138
|
+
}
|
|
139
|
+
export function saveConversationModelConfig(conversationDir, config) {
|
|
140
|
+
if (!existsSync(conversationDir)) {
|
|
141
|
+
ensureDirExists(conversationDir);
|
|
142
|
+
}
|
|
143
|
+
const settingsPath = join(conversationDir, "settings.json");
|
|
144
|
+
const existing = loadSettingsFile(settingsPath) ?? {};
|
|
145
|
+
const scopedConfig = {
|
|
146
|
+
...existing,
|
|
147
|
+
llm: { ...existing.llm, ...config },
|
|
148
|
+
};
|
|
149
|
+
atomicWritePrivateFile(settingsPath, JSON.stringify(scopedConfig, null, 2));
|
|
150
|
+
}
|
|
151
|
+
export function saveConversationSandboxConfig(conversationDir, config) {
|
|
152
|
+
if (!existsSync(conversationDir)) {
|
|
153
|
+
ensureDirExists(conversationDir);
|
|
154
|
+
}
|
|
155
|
+
const settingsPath = join(conversationDir, "settings.json");
|
|
156
|
+
const existing = loadSettingsFile(settingsPath) ?? {};
|
|
157
|
+
const scopedConfig = {
|
|
158
|
+
...existing,
|
|
159
|
+
sandbox: {
|
|
160
|
+
...existing.sandbox,
|
|
161
|
+
image: {
|
|
162
|
+
...existing.sandbox?.image,
|
|
163
|
+
workspaceMount: config.imageWorkspaceMount,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
atomicWritePrivateFile(settingsPath, JSON.stringify(scopedConfig, null, 2));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Resolve the model used to judge auto-reply rules. Falls back to the main
|
|
171
|
+
* llm.{provider,model} when llm.autoReply is not set, so a missing override
|
|
172
|
+
* keeps current behavior.
|
|
173
|
+
*/
|
|
174
|
+
export function loadAutoReplyJudgeModel(conversationDir) {
|
|
175
|
+
const global = requireGlobalSettings();
|
|
176
|
+
const local = conversationDir
|
|
177
|
+
? (loadSettingsFile(join(conversationDir, "settings.json")) ?? {})
|
|
178
|
+
: {};
|
|
179
|
+
const merged = { ...global.llm, ...local.llm };
|
|
180
|
+
const judge = { ...global.llm?.autoReply, ...local.llm?.autoReply };
|
|
181
|
+
const provider = requireString(judge.provider ?? merged?.provider, "llm.autoReply.provider");
|
|
182
|
+
const model = requireString(judge.model ?? merged?.model, "llm.autoReply.model");
|
|
183
|
+
return { provider, model };
|
|
184
|
+
}
|
|
185
|
+
const AUTO_REPLY_FILE = "auto-reply";
|
|
186
|
+
const AUTO_REPLY_DISABLED_FILE = "auto-reply.disabled";
|
|
187
|
+
function readAutoReplyRulesFile(path) {
|
|
188
|
+
const text = readFileSync(path, "utf-8").trim();
|
|
189
|
+
return text ? [text] : [];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Load the mom-compatible auto-reply marker file state for a conversation.
|
|
193
|
+
*
|
|
194
|
+
* - `auto-reply` exists: enabled; empty file means reply to any top-level message.
|
|
195
|
+
* - `auto-reply.disabled` exists: disabled, preserving any rules text for re-enable.
|
|
196
|
+
* - neither exists: disabled.
|
|
197
|
+
*/
|
|
198
|
+
export function loadConversationAutoReplyConfig(conversationDir) {
|
|
199
|
+
const enabledPath = join(conversationDir, AUTO_REPLY_FILE);
|
|
200
|
+
if (existsSync(enabledPath)) {
|
|
201
|
+
return { enabled: true, rules: readAutoReplyRulesFile(enabledPath) };
|
|
202
|
+
}
|
|
203
|
+
const disabledPath = join(conversationDir, AUTO_REPLY_DISABLED_FILE);
|
|
204
|
+
if (existsSync(disabledPath)) {
|
|
205
|
+
return { enabled: false, rules: readAutoReplyRulesFile(disabledPath) };
|
|
206
|
+
}
|
|
207
|
+
return { enabled: false, rules: [] };
|
|
208
|
+
}
|
|
209
|
+
/** Save auto-reply state using mom-compatible marker files. */
|
|
210
|
+
export function saveConversationAutoReplyConfig(conversationDir, config) {
|
|
211
|
+
if (!existsSync(conversationDir)) {
|
|
212
|
+
mkdirSync(conversationDir, { recursive: true });
|
|
213
|
+
}
|
|
214
|
+
const enabledPath = join(conversationDir, AUTO_REPLY_FILE);
|
|
215
|
+
const disabledPath = join(conversationDir, AUTO_REPLY_DISABLED_FILE);
|
|
216
|
+
const targetPath = config.enabled ? enabledPath : disabledPath;
|
|
217
|
+
const otherPath = config.enabled ? disabledPath : enabledPath;
|
|
218
|
+
if (existsSync(otherPath)) {
|
|
219
|
+
renameSync(otherPath, targetPath);
|
|
220
|
+
}
|
|
221
|
+
writeFileSync(targetPath, config.rules.join("\n"), "utf-8");
|
|
38
222
|
}
|
|
39
223
|
export function resolveWorkspaceDirFromArgv(args = process.argv.slice(2)) {
|
|
40
224
|
for (let i = 0; i < args.length; i++) {
|
|
41
225
|
const arg = args[i];
|
|
42
|
-
if (arg === "--sandbox" || arg === "--download") {
|
|
226
|
+
if (arg === "--sandbox" || arg === "--download" || arg === "--state-dir") {
|
|
43
227
|
i += 1;
|
|
44
228
|
continue;
|
|
45
229
|
}
|
|
46
|
-
if (arg === "--version" || arg === "-v" || arg === "-V") {
|
|
230
|
+
if (arg === "--version" || arg === "-v" || arg === "-V" || arg === "--onboard") {
|
|
47
231
|
continue;
|
|
48
232
|
}
|
|
49
|
-
if (arg.startsWith("--sandbox=") ||
|
|
233
|
+
if (arg.startsWith("--sandbox=") ||
|
|
234
|
+
arg.startsWith("--download=") ||
|
|
235
|
+
arg.startsWith("--state-dir=")) {
|
|
50
236
|
continue;
|
|
51
237
|
}
|
|
52
238
|
if (!arg.startsWith("-")) {
|
|
@@ -55,35 +241,114 @@ export function resolveWorkspaceDirFromArgv(args = process.argv.slice(2)) {
|
|
|
55
241
|
}
|
|
56
242
|
return undefined;
|
|
57
243
|
}
|
|
58
|
-
export function
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
return
|
|
244
|
+
export function resolveStateDirFromArgv(args = process.argv.slice(2)) {
|
|
245
|
+
for (let i = 0; i < args.length; i++) {
|
|
246
|
+
const arg = args[i];
|
|
247
|
+
if (arg.startsWith("--state-dir=")) {
|
|
248
|
+
return resolve(arg.slice("--state-dir=".length));
|
|
249
|
+
}
|
|
250
|
+
if (arg === "--state-dir") {
|
|
251
|
+
return resolve(args[++i] || "");
|
|
63
252
|
}
|
|
64
253
|
}
|
|
254
|
+
return join(homedir(), ".mama");
|
|
255
|
+
}
|
|
256
|
+
export function resolveSentryDsn() {
|
|
257
|
+
const fromFile = normalizeSettingsConfig(loadSettingsFile(getSettingsPath()) ?? {});
|
|
258
|
+
if (fromFile.sentryDsn) {
|
|
259
|
+
return fromFile.sentryDsn;
|
|
260
|
+
}
|
|
65
261
|
return process.env.SENTRY_DSN;
|
|
66
262
|
}
|
|
67
|
-
export function
|
|
68
|
-
const settingsPath = join(
|
|
69
|
-
|
|
263
|
+
export function createGlobalSettingsFile(stateDir) {
|
|
264
|
+
const settingsPath = join(stateDir, "settings.json");
|
|
265
|
+
if (existsSync(settingsPath)) {
|
|
266
|
+
throw new Error(`Global settings already exists at ${settingsPath}`);
|
|
267
|
+
}
|
|
268
|
+
if (!existsSync(stateDir)) {
|
|
269
|
+
ensureDirExists(stateDir);
|
|
270
|
+
}
|
|
271
|
+
atomicWritePrivateFile(settingsPath, JSON.stringify(ONBOARD_SETTINGS, null, 2));
|
|
272
|
+
return settingsPath;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Externally-visible base URL of the link/OAuth server, e.g.
|
|
276
|
+
* `https://mama.example.com` (no trailing slash). Read from `MAMA_LINK_URL`,
|
|
277
|
+
* the same env var the bot uses to build credential onboarding links.
|
|
278
|
+
*/
|
|
279
|
+
export function resolveLinkBaseUrl() {
|
|
280
|
+
const raw = process.env.MAMA_LINK_URL?.trim();
|
|
281
|
+
if (!raw)
|
|
282
|
+
return undefined;
|
|
283
|
+
return raw.replace(/\/+$/, "");
|
|
284
|
+
}
|
|
285
|
+
function hasDefinedValue(values) {
|
|
286
|
+
return values !== undefined && Object.values(values).some((value) => value !== undefined);
|
|
287
|
+
}
|
|
288
|
+
function compactSettingsConfig(config) {
|
|
289
|
+
return {
|
|
290
|
+
...(hasDefinedValue(config.llm) ? { llm: config.llm } : {}),
|
|
291
|
+
...(hasDefinedValue(config.log) ? { log: config.log } : {}),
|
|
292
|
+
...(hasDefinedValue(config.sentry) ? { sentry: config.sentry } : {}),
|
|
293
|
+
...(hasDefinedValue(config.sandbox) ? { sandbox: config.sandbox } : {}),
|
|
294
|
+
...(hasDefinedValue(config.autoReply) ? { autoReply: config.autoReply } : {}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function patchSettingsConfig(existing, config) {
|
|
298
|
+
const patched = {
|
|
299
|
+
...existing,
|
|
300
|
+
llm: {
|
|
301
|
+
...existing.llm,
|
|
302
|
+
...(config.provider !== undefined ? { provider: config.provider } : {}),
|
|
303
|
+
...(config.model !== undefined ? { model: config.model } : {}),
|
|
304
|
+
...(config.thinkingLevel !== undefined ? { thinkingLevel: config.thinkingLevel } : {}),
|
|
305
|
+
},
|
|
306
|
+
log: {
|
|
307
|
+
...existing.log,
|
|
308
|
+
...(config.logFormat !== undefined ? { format: config.logFormat } : {}),
|
|
309
|
+
...(config.logLevel !== undefined ? { level: config.logLevel } : {}),
|
|
310
|
+
},
|
|
311
|
+
sentry: {
|
|
312
|
+
...existing.sentry,
|
|
313
|
+
...(config.sentryDsn !== undefined ? { dsn: config.sentryDsn } : {}),
|
|
314
|
+
},
|
|
315
|
+
sandbox: {
|
|
316
|
+
...existing.sandbox,
|
|
317
|
+
...(config.sandboxCpus !== undefined ? { cpus: config.sandboxCpus } : {}),
|
|
318
|
+
...(config.sandboxMemory !== undefined ? { memory: config.sandboxMemory } : {}),
|
|
319
|
+
...(config.sandboxBoostCpus !== undefined || config.sandboxBoostMemory !== undefined
|
|
320
|
+
? {
|
|
321
|
+
boost: {
|
|
322
|
+
...existing.sandbox?.boost,
|
|
323
|
+
...(config.sandboxBoostCpus !== undefined ? { cpus: config.sandboxBoostCpus } : {}),
|
|
324
|
+
...(config.sandboxBoostMemory !== undefined
|
|
325
|
+
? { memory: config.sandboxBoostMemory }
|
|
326
|
+
: {}),
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
: {}),
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
return compactSettingsConfig(patched);
|
|
333
|
+
}
|
|
334
|
+
export function saveAgentConfig(config) {
|
|
335
|
+
const settingsPath = join(getStateDir(), "settings.json");
|
|
336
|
+
let existing = ONBOARD_SETTINGS;
|
|
70
337
|
if (existsSync(settingsPath)) {
|
|
71
338
|
try {
|
|
72
|
-
|
|
73
|
-
const parsed = JSON.parse(raw);
|
|
74
|
-
if (parsed && typeof parsed === "object") {
|
|
75
|
-
existing = parsed;
|
|
76
|
-
}
|
|
339
|
+
existing = loadSettingsFile(settingsPath) ?? {};
|
|
77
340
|
}
|
|
78
|
-
catch {
|
|
79
|
-
|
|
341
|
+
catch (err) {
|
|
342
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
343
|
+
const message = detail.startsWith("Malformed settings file")
|
|
344
|
+
? detail.replace("Malformed settings file", "Refusing to overwrite malformed settings file")
|
|
345
|
+
: detail;
|
|
346
|
+
throw new Error(message, { cause: err });
|
|
80
347
|
}
|
|
81
348
|
}
|
|
82
|
-
const merged =
|
|
349
|
+
const merged = patchSettingsConfig(existing, config);
|
|
83
350
|
const dir = dirname(settingsPath);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
writeFileSync(settingsPath, JSON.stringify(merged, null, 2), "utf-8");
|
|
351
|
+
ensureDirExists(dir);
|
|
352
|
+
atomicWritePrivateFile(settingsPath, JSON.stringify(merged, null, 2));
|
|
88
353
|
}
|
|
89
354
|
//# sourceMappingURL=config.js.map
|