@geminixiang/mikan 1.0.0-beta.64 → 1.0.0-beta.65
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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/adapters/commands/auto-reply.d.ts.map +1 -1
- package/dist/adapters/commands/auto-reply.js +1 -1
- package/dist/adapters/commands/auto-reply.js.map +1 -1
- package/dist/adapters/commands/model.js +2 -2
- package/dist/adapters/commands/model.js.map +1 -1
- package/dist/adapters/commands/new.js +1 -1
- package/dist/adapters/commands/new.js.map +1 -1
- package/dist/adapters/commands/sandbox.js +2 -2
- package/dist/adapters/commands/sandbox.js.map +1 -1
- package/dist/adapters/commands/types.d.ts +1 -1
- package/dist/adapters/commands/types.d.ts.map +1 -1
- package/dist/adapters/commands/types.js.map +1 -1
- package/dist/adapters/commands/utils.d.ts +1 -1
- package/dist/adapters/commands/utils.d.ts.map +1 -1
- package/dist/adapters/commands/utils.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +2 -2
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +7 -6
- 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 +2 -1
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/discord/types.d.ts +1 -1
- package/dist/adapters/discord/types.d.ts.map +1 -1
- package/dist/adapters/discord/types.js.map +1 -1
- package/dist/adapters/github/bot.d.ts +2 -2
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +1 -1
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/context.d.ts +1 -1
- package/dist/adapters/github/context.d.ts.map +1 -1
- package/dist/adapters/github/context.js +1 -1
- package/dist/adapters/github/context.js.map +1 -1
- package/dist/adapters/github/types.d.ts +1 -1
- package/dist/adapters/github/types.d.ts.map +1 -1
- package/dist/adapters/github/types.js.map +1 -1
- package/dist/{adapter.d.ts → adapters/index.d.ts} +3 -3
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/{adapter.js → adapters/index.js} +2 -2
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/intake.d.ts +1 -1
- package/dist/adapters/intake.d.ts.map +1 -1
- package/dist/adapters/intake.js +1 -1
- package/dist/adapters/intake.js.map +1 -1
- package/dist/{platform-messages.d.ts → adapters/messages.d.ts} +2 -2
- package/dist/adapters/messages.d.ts.map +1 -0
- package/dist/{platform-messages.js → adapters/messages.js} +1 -1
- package/dist/adapters/messages.js.map +1 -0
- package/dist/adapters/progressive-renderer.d.ts +1 -1
- package/dist/adapters/progressive-renderer.d.ts.map +1 -1
- package/dist/adapters/progressive-renderer.js.map +1 -1
- package/dist/adapters/shared.d.ts +3 -1
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +25 -0
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +4 -3
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +9 -6
- package/dist/adapters/slack/bot.js.map +1 -1
- 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 +1 -1
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/persona.d.ts +15 -0
- package/dist/adapters/slack/persona.d.ts.map +1 -0
- package/dist/adapters/slack/persona.js +22 -0
- package/dist/adapters/slack/persona.js.map +1 -0
- package/dist/adapters/slack/response-lifecycle.d.ts +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +21 -0
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/types.d.ts +1 -1
- package/dist/adapters/slack/types.d.ts.map +1 -1
- package/dist/adapters/slack/types.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +2 -2
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +6 -6
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +2 -1
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/telegram/types.d.ts +1 -1
- package/dist/adapters/telegram/types.d.ts.map +1 -1
- package/dist/adapters/telegram/types.js.map +1 -1
- package/dist/adapters/types.d.ts +1 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/web/admin/portal.d.ts +2 -2
- package/dist/adapters/web/admin/portal.d.ts.map +1 -1
- package/dist/adapters/web/admin/portal.js +26 -16
- package/dist/adapters/web/admin/portal.js.map +1 -1
- package/dist/adapters/web/admin/types.d.ts +1 -1
- package/dist/adapters/web/admin/types.d.ts.map +1 -1
- package/dist/adapters/web/admin/types.js.map +1 -1
- package/dist/adapters/web/login/portal.d.ts +1 -1
- package/dist/adapters/web/login/portal.d.ts.map +1 -1
- package/dist/adapters/web/login/portal.js +2 -2
- package/dist/adapters/web/login/portal.js.map +1 -1
- package/dist/adapters/web/login/types.d.ts +1 -1
- package/dist/adapters/web/login/types.d.ts.map +1 -1
- package/dist/adapters/web/login/types.js.map +1 -1
- package/dist/adapters/web/portal-shell.js +2 -2
- package/dist/adapters/web/portal-shell.js.map +1 -1
- package/dist/adapters/web/server.d.ts +1 -1
- package/dist/adapters/web/server.d.ts.map +1 -1
- package/dist/adapters/web/server.js +1 -1
- package/dist/adapters/web/server.js.map +1 -1
- package/dist/adapters/web/session-view/portal.js +1 -1
- package/dist/adapters/web/session-view/portal.js.map +1 -1
- package/dist/adapters/web/session-view/types.d.ts +3 -3
- package/dist/adapters/web/session-view/types.d.ts.map +1 -1
- package/dist/adapters/web/session-view/types.js.map +1 -1
- package/dist/cli/office.js +1 -1
- package/dist/cli/office.js.map +1 -1
- package/dist/cli/onboard.js +2 -2
- package/dist/cli/onboard.js.map +1 -1
- package/dist/cli/process-lifecycle.d.ts.map +1 -0
- package/dist/cli/process-lifecycle.js.map +1 -0
- package/dist/dream/index.js +1 -1
- package/dist/dream/index.js.map +1 -1
- package/dist/dream/types.d.ts +1 -1
- package/dist/dream/types.d.ts.map +1 -1
- package/dist/dream/types.js.map +1 -1
- package/dist/env-manifest.d.ts +6 -0
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +11 -0
- package/dist/env-manifest.js.map +1 -1
- package/dist/events/scheduler.d.ts +1 -1
- package/dist/events/scheduler.d.ts.map +1 -1
- package/dist/events/scheduler.js +1 -1
- package/dist/events/scheduler.js.map +1 -1
- package/dist/file-guards.d.ts +8 -0
- package/dist/file-guards.d.ts.map +1 -1
- package/dist/file-guards.js +31 -0
- package/dist/file-guards.js.map +1 -1
- package/dist/harness/execution-resolver.js +1 -1
- package/dist/harness/execution-resolver.js.map +1 -1
- package/dist/harness/open-connector.js +1 -1
- package/dist/harness/open-connector.js.map +1 -1
- package/dist/harness/presenter.d.ts +2 -2
- package/dist/harness/presenter.d.ts.map +1 -1
- package/dist/harness/presenter.js +26 -0
- package/dist/harness/presenter.js.map +1 -1
- package/dist/harness/prompt.d.ts +1 -1
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js +1 -0
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/runner.js +1 -1
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/subagent-profiles.d.ts.map +1 -1
- package/dist/harness/subagent-profiles.js +14 -14
- package/dist/harness/subagent-profiles.js.map +1 -1
- package/dist/harness/tools/event.d.ts +1 -1
- package/dist/harness/tools/event.d.ts.map +1 -1
- package/dist/harness/tools/event.js.map +1 -1
- package/dist/harness/tools/index.d.ts +1 -1
- package/dist/harness/tools/index.d.ts.map +1 -1
- package/dist/harness/tools/index.js.map +1 -1
- package/dist/harness/tools/task.d.ts +1 -1
- package/dist/harness/tools/task.d.ts.map +1 -1
- package/dist/harness/tools/task.js.map +1 -1
- package/dist/harness/types.d.ts +2 -2
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +4 -2
- package/dist/main.js.map +1 -1
- package/dist/observability/instrument.js +1 -1
- package/dist/observability/instrument.js.map +1 -1
- package/dist/office/projection.d.ts +8 -5
- package/dist/office/projection.d.ts.map +1 -1
- package/dist/office/projection.js +14 -6
- package/dist/office/projection.js.map +1 -1
- package/dist/office/types.d.ts +4 -1
- package/dist/office/types.d.ts.map +1 -1
- package/dist/office/types.js.map +1 -1
- package/dist/runtime/conversation-runtime.js +1 -1
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +1 -1
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +1 -1
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sessions/session-key.d.ts +1 -1
- package/dist/sessions/session-key.d.ts.map +1 -1
- package/dist/sessions/session-key.js.map +1 -1
- package/dist/sessions/types.d.ts +1 -1
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/{settings-mutation.d.ts → settings/apply.d.ts} +4 -4
- package/dist/settings/apply.d.ts.map +1 -0
- package/dist/{settings-mutation.js → settings/apply.js} +2 -2
- package/dist/settings/apply.js.map +1 -0
- package/dist/settings/index.d.ts +118 -0
- package/dist/settings/index.d.ts.map +1 -0
- package/dist/{config.js → settings/index.js} +9 -127
- package/dist/settings/index.js.map +1 -0
- package/dist/settings/migrate.d.ts +21 -0
- package/dist/settings/migrate.d.ts.map +1 -0
- package/dist/settings/migrate.js +86 -0
- package/dist/settings/migrate.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/config.d.ts +0 -92
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/platform-messages.d.ts.map +0 -1
- package/dist/platform-messages.js.map +0 -1
- package/dist/process-lifecycle.d.ts.map +0 -1
- package/dist/process-lifecycle.js.map +0 -1
- package/dist/settings-mutation.d.ts.map +0 -1
- package/dist/settings-mutation.js.map +0 -1
- /package/dist/{process-lifecycle.d.ts → cli/process-lifecycle.d.ts} +0 -0
- /package/dist/{process-lifecycle.js → cli/process-lifecycle.js} +0 -0
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { McpServerConfig } from "../harness/types.js";
|
|
2
2
|
import type { EventScheduleSink } from "../events/index.js";
|
|
3
3
|
import type { PiAgentWrapper, PlatformTrustModel } from "../types.js";
|
|
4
|
-
import type { MessagingBot, ConversationContext, ConversationEvent, MessagingEventHandler, OfficeAddress } from "../
|
|
4
|
+
import type { MessagingBot, ConversationContext, ConversationEvent, MessagingEventHandler, OfficeAddress } from "../types.js";
|
|
5
5
|
import type { AdminTokenStoreLike, CommandHandler, CommandServices, LinkTokenStoreLike, SessionViewTokenStoreLike } from "../adapters/commands/types.js";
|
|
6
6
|
import type { MikanModels } from "../harness/index.js";
|
|
7
7
|
import type { PlatformToolPackFactory } from "../harness/tools/types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE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AC;CAChE;AAED,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/D,uBAAuB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1F,8BAA8B,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC;IAChE,iFAAiF;IACjF,uBAAuB,IAAI;QAAE,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { McpServerConfig } from \"../harness/types.js\";\nimport type { EventScheduleSink } from \"../events/index.js\";\nimport type { PiAgentWrapper, PlatformTrustModel } from \"../types.js\";\nimport type {\n MessagingBot,\n ConversationContext,\n ConversationEvent,\n MessagingEventHandler,\n OfficeAddress,\n} from \"../
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { McpServerConfig } from \"../harness/types.js\";\nimport type { EventScheduleSink } from \"../events/index.js\";\nimport type { PiAgentWrapper, PlatformTrustModel } from \"../types.js\";\nimport type {\n MessagingBot,\n ConversationContext,\n ConversationEvent,\n MessagingEventHandler,\n OfficeAddress,\n} from \"../types.js\";\nimport type {\n AdminTokenStoreLike,\n CommandHandler,\n CommandServices,\n LinkTokenStoreLike,\n SessionViewTokenStoreLike,\n} from \"../adapters/commands/types.js\";\nimport type { MikanModels } from \"../harness/index.js\";\nimport type { PlatformToolPackFactory } from \"../harness/tools/types.js\";\nimport type { VaultManager } from \"../vault/index.js\";\n\nexport interface SessionLifecycleOptions {\n maxSessions?: number;\n idleTimeoutMs?: number;\n now?: () => number;\n}\n\nexport interface ConversationRuntimeState {\n /** The office that owns this runtime state. */\n address: OfficeAddress;\n /** This office's platform session reference (raw session-key grammar). */\n sessionKey: string;\n running: boolean;\n /** Exact settlement of the current run, including post-run response handling. */\n runSettlement?: Promise<void>;\n runner: PiAgentWrapper;\n stopRequested: boolean;\n /** Set when the shutdown deadline aborted this run; the runtime posts a restart notice. */\n shutdownAborted?: boolean;\n /** An explicit stop caller owns its acknowledgement through settlement. */\n stopNoticeOwned?: boolean;\n lastAccessedAt: number;\n sessionFile: string;\n /** Epoch ms when the current run started; 0 when idle. */\n startedAt: number;\n lastActivityAt?: number;\n}\n\nexport interface RunSessionOptions {\n event: ConversationEvent;\n bot: MessagingBot;\n context: ConversationContext;\n}\n\n/** Conversation/session identity used to resolve per-session runner state. */\nexport interface SessionStateOptions {\n /** Canonical office identity; the runtime keys all state by this. */\n address: OfficeAddress;\n sessionKey: string;\n /** Fixed trust boundary for this office's built-in platform path. */\n trustModel: PlatformTrustModel;\n /** Stable platform workspace/team identity when the adapter supplies one. */\n platformWorkspaceId?: string;\n}\n\nexport interface ConversationRuntimeOptions extends Omit<\n CommandServices,\n \"runtime\" | \"vaultManager\" | \"linkTokenStore\" | \"sessionViewTokenStore\" | \"adminTokenStore\"\n> {\n /**\n * Credential vault for sandboxed conversations. Optional for embedders;\n * when omitted the runtime uses an inert, disabled vault.\n */\n vaultManager?: VaultManager;\n /** Login-portal token store; omit when no web portal is hosted. */\n linkTokenStore?: LinkTokenStoreLike;\n /** Session-viewer token store; omit when no web portal is hosted. */\n sessionViewTokenStore?: SessionViewTokenStoreLike;\n /** Admin-portal token store; omit when no web portal is hosted. */\n adminTokenStore?: AdminTokenStoreLike;\n /** Override the default command handlers (e.g., to add /help, /status). */\n commandHandlers?: readonly CommandHandler[];\n /** Model registry override; defaults to the process-wide models.json load. */\n models?: MikanModels;\n /** Deployment default for the `open-connector` MCP entry; settings may override it. */\n openConnector?: McpServerConfig;\n /** Scheduler that office event stores notify; resolved lazily because it starts after the bots. */\n eventScheduler?: () => EventScheduleSink | undefined;\n /**\n * Optional platform capability packs (extra tools + per-run bind), as\n * factories — each runner instantiates its own pack because bind state is\n * per-runner. Assembled at process start (e.g. GitHub PR/CI pack); core\n * stays platform-neutral.\n */\n platformToolPackFactories?: readonly PlatformToolPackFactory[];\n}\n\nexport interface ConversationRuntime extends MessagingEventHandler {\n runSession(options: RunSessionOptions): Promise<void>;\n runDream(address: OfficeAddress, now?: Date): Promise<boolean>;\n switchConversationModel(address: OfficeAddress, provider: string, model: string): boolean;\n refreshConversationEnvironment(address: OfficeAddress): boolean;\n /** Clear idle runners; defer busy conversation invalidation until settlement. */\n refreshAllConversations(): { busy: OfficeAddress[] };\n shutdown(timeoutMs?: number): Promise<void>;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConversationKind } from "../
|
|
1
|
+
import type { ConversationKind } from "../types.js";
|
|
2
2
|
export type { ResolveSessionKeyOptions } from "./types.js";
|
|
3
3
|
import type { ResolveSessionKeyOptions } from "./types.js";
|
|
4
4
|
export declare function assertConversationId(conversationId: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-key.d.ts","sourceRoot":"","sources":["../../src/sessions/session-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"session-key.d.ts","sourceRoot":"","sources":["../../src/sessions/session-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAA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C,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC9D,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/D,CAAC;IAED,0EAA0E;IAC1E,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { ConversationKind } from \"../
|
|
1
|
+
{"version":3,"file":"session-key.js","sourceRoot":"","sources":["../../src/sessions/session-key.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAEH,sFAAsF;AACtF,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC,SAAS,wBAAwB,CAAC,KAAa;IAC7C,KAAK,MAAM,SAAS,IAAI,KAAK,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QAC5C,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa,EAAE,KAAa;IAC1D,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,8CAA8C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClG,CAAC;IACD,IAAI,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,0CAA0C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC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kBAAkB,CAAC,EAAE,CAAC;QACxE,OAAO,oBAAoB,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,CAAC,QAAQ,IAAI,kBAAkB,EAAE,CAAC;QACpC,OAAO,oBAAoB,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,oBAAoB,CAAC,cAAc,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,cAAsB;IAC5E,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC9D,CAAC;IAED,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,OAAO,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC9D,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/D,CAAC;IAED,0EAA0E;IAC1E,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { ConversationKind } from \"../types.js\";\nexport type { ResolveSessionKeyOptions } from \"./types.js\";\nimport type { ResolveSessionKeyOptions } from \"./types.js\";\n\n/**\n * The session-key grammar. A session key is the conversation-scoped runtime\n * identity used to serialize and resume work (see CONTEXT.md):\n *\n * `conversationId` — the persistent conversation session\n * `conversationId:suffix` — a scoped thread session (suffix = thread\n * ts / message id, opaque to this module)\n *\n * This module owns the convention; nothing else may split on \":\". The grammar\n * only works because conversation ids never contain \":\" — that invariant is\n * asserted here at every derivation instead of being assumed everywhere.\n */\n\n/** Characters that can change host path structure or make identity logs ambiguous. */\nconst PATH_SEPARATOR_PATTERN = /[\\\\/]/;\n\nfunction containsControlCharacter(value: string): boolean {\n for (const character of value) {\n const codePoint = character.codePointAt(0)!;\n if (codePoint <= 0x1f || codePoint === 0x7f) return true;\n }\n return false;\n}\n\nfunction assertSafeIdentityPart(value: string, label: string): string {\n if (!value || value === \".\" || value === \"..\") {\n throw new Error(`${label} must be a non-empty identity segment (got ${JSON.stringify(value)})`);\n }\n if (PATH_SEPARATOR_PATTERN.test(value)) {\n throw new Error(`${label} must not contain path separators (got ${JSON.stringify(value)})`);\n }\n if (containsControlCharacter(value)) {\n throw new Error(`${label} must not contain control characters (got ${JSON.stringify(value)})`);\n }\n return value;\n}\n\nexport function assertConversationId(conversationId: string): string {\n assertSafeIdentityPart(conversationId, \"Conversation id\");\n if (conversationId.includes(\":\")) {\n throw new Error(\n `Conversation id must not contain \":\" (got ${JSON.stringify(conversationId)}); ` +\n \"the session-key grammar reserves it for thread suffixes\",\n );\n }\n return conversationId;\n}\n\n/** Validate the opaque scoped suffix without changing its platform value. */\nexport function assertSessionSuffix(suffix: string): string {\n return assertSafeIdentityPart(suffix, \"Session suffix\");\n}\n\n/** Build a scoped thread session key. */\nexport function makeThreadSessionKey(conversationId: string, suffix: string): string {\n return `${assertConversationId(conversationId)}:${assertSessionSuffix(suffix)}`;\n}\n\n/**\n * Validate that a platform-computed session key belongs to its conversation.\n * The key may be the bare conversation id or one of that conversation's\n * scoped keys; callers must not be able to select another conversation's\n * runtime/cache entry.\n */\nexport function assertSessionKeyBelongsToConversation(\n sessionKey: string,\n conversationId: string,\n): string {\n const expectedConversationId = assertConversationId(conversationId);\n const actualConversationId = conversationIdOf(sessionKey);\n if (actualConversationId !== expectedConversationId) {\n throw new Error(\n `Session key ${JSON.stringify(sessionKey)} does not belong to conversation ` +\n JSON.stringify(conversationId),\n );\n }\n const suffix = threadSuffixOf(sessionKey);\n if (suffix !== null) assertSessionSuffix(suffix);\n return sessionKey;\n}\n\n/**\n * The runtime fallback: honor a platform-computed session key, otherwise\n * scope the event to its thread (or to itself for thread-starting messages).\n */\nexport function deriveSessionKey(event: {\n sessionKey?: string;\n conversationId: string;\n thread_ts?: string;\n ts: string;\n}): string {\n if (event.sessionKey !== undefined) {\n return assertSessionKeyBelongsToConversation(event.sessionKey, event.conversationId);\n }\n return makeThreadSessionKey(event.conversationId, event.thread_ts ?? event.ts);\n}\n\nexport function isThreadSessionKey(sessionKey: string): boolean {\n return sessionKey.includes(\":\");\n}\n\n/** The conversation a session key belongs to (identity for bare keys). */\nexport function conversationIdOf(sessionKey: string): string {\n const separator = sessionKey.indexOf(\":\");\n return separator === -1 ? sessionKey : sessionKey.slice(0, separator);\n}\n\n/** The thread suffix of a scoped key, or null for a bare conversation key. */\nexport function threadSuffixOf(sessionKey: string): string | null {\n const separator = sessionKey.indexOf(\":\");\n return separator === -1 ? null : sessionKey.slice(separator + 1);\n}\n\nexport function resolveChatSessionKey(options: ResolveSessionKeyOptions): string {\n const {\n conversationId,\n conversationKind,\n messageId,\n persistentTopLevel,\n scopeDirectThreads,\n threadTs,\n } = options;\n if (conversationKind === \"direct\" && (!threadTs || !scopeDirectThreads)) {\n return assertConversationId(conversationId);\n }\n if (!threadTs && persistentTopLevel) {\n return assertConversationId(conversationId);\n }\n return makeThreadSessionKey(conversationId, threadTs || messageId);\n}\n\nexport function inferConversationKind(platform: string, conversationId: string): ConversationKind {\n if (platform === \"slack\") {\n return conversationId.startsWith(\"D\") ? \"direct\" : \"shared\";\n }\n\n if (platform === \"telegram\") {\n return conversationId.startsWith(\"-\") ? \"shared\" : \"direct\";\n }\n\n if (platform === \"discord\") {\n return conversationId.startsWith(\"DM\") ? \"direct\" : \"shared\";\n }\n\n // github: issues/PRs are always shared within the repo; there are no DMs.\n return \"shared\";\n}\n"]}
|
package/dist/sessions/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConversationKind } from "../
|
|
1
|
+
import type { ConversationKind } from "../types.js";
|
|
2
2
|
import type { AgentMessage, Entry, MessageEntry } from "@earendil-works/pi-agent-core";
|
|
3
3
|
import type { ConversationLogMessage } from "../types.js";
|
|
4
4
|
import type { SessionStore } from "./session-store.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sessions/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sessions/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAID,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO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C;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,OAAO,CAAC;IAChC,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,iBAAiB,GAAG,YAAY,CAAC;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sessions/types.ts"],"names":[],"mappings":"AA8CA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC","sourcesContent":["import type { ConversationKind } from \"../
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sessions/types.ts"],"names":[],"mappings":"AA8CA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC","sourcesContent":["import type { ConversationKind } from \"../types.js\";\nimport type { AgentMessage, Entry, MessageEntry } from \"@earendil-works/pi-agent-core\";\nimport type { ConversationLogMessage } from \"../types.js\";\nimport type { SessionStore } from \"./session-store.js\";\n\n// ── session metadata ─────────────────────────────────────────────────────────\n\nexport interface MikanSessionHeader {\n type?: string;\n version?: number;\n id?: string;\n timestamp?: string;\n cwd?: string;\n parentSession?: string;\n /** Legacy platform-history marker; preserved in mikan's durable session metadata. */\n source?: {\n kind?: string;\n file?: string;\n recentDays?: number;\n };\n}\n\n// ── session policy ───────────────────────────────────────────────────────────\n\nexport interface ResolveSessionKeyOptions {\n conversationId: string;\n conversationKind: ConversationKind;\n messageId: string;\n threadTs?: string;\n persistentTopLevel?: boolean;\n scopeDirectThreads?: boolean;\n}\n\n// ── session store ────────────────────────────────────────────────────────────\n\n/** Model-visible messages reconstructed from the active session branch. */\nexport interface SessionContext {\n messages: AgentMessage[];\n}\n\n/** Message entry as stored in mikan session files (Pi v4). */\nexport type SessionMessageEntry = MessageEntry;\n\n/** Union of entry types mikan reads and writes. Alias of Pi's v4 entry. */\nexport type SessionEntry = Entry;\n\nexport const CURRENT_SESSION_VERSION = 4;\n\nexport interface SessionCreateInfo {\n id?: string;\n parentSession?: string;\n parentSessionId?: string;\n}\n\n/** Immutable session queries available to portals, admin, and migration code. */\nexport interface SessionInspection {\n getHeader(): SessionHeader;\n getEntries(): Promise<Entry[]>;\n getSessionName(): Promise<string | undefined>;\n getBranch(fromId?: string): Promise<Entry[]>;\n buildSessionContext(): Promise<SessionContext>;\n}\n\n/**\n * Compatibility header view synthesized from the v4 file header for callers\n * that read mikan session lineage. `metadata` carries mikan header extras (for\n * example `parentSessionPath` and the legacy `source` marker preserved by\n * the v3 migration).\n */\nexport interface SessionHeader {\n type: \"session\";\n version?: number;\n id: string;\n timestamp: string;\n cwd: string;\n parentSession?: string;\n parentSessionId?: string;\n [extra: string]: unknown;\n}\n\nexport interface ParentSessionRef {\n path: string;\n id: string;\n}\n\nexport interface ThreadRootMessage {\n text?: string;\n userName?: string;\n user?: string;\n loggedAt?: number;\n isMessagingBot?: boolean;\n}\n\nexport interface ResolvedSessionScope {\n sessionDir: string;\n contextFile: string;\n threadRootMessage: ThreadRootMessage | null;\n}\n\n/** One parsed log.jsonl entry with its original line index. */\nexport interface LogRecord {\n message: ConversationLogMessage;\n index: number;\n}\n\n// ── chat history sync ────────────────────────────────────────────────────────\n\n/** What one sync pass actually did — the inspectable result of a sync. */\nexport interface ChatSyncReport {\n /** Log messages appended to the session in this pass. */\n appended: number;\n /** The log message id recorded as the new sync watermark. */\n lastMessageId?: string;\n}\n\nexport interface ChatHistorySyncOptions {\n recentDays?: number;\n maxTopLevelMessages?: number;\n now?: () => Date;\n}\n\nexport interface ResolveChatSessionScopeOptions {\n conversationDir: string;\n sessionKey: string;\n cwd?: string;\n /** The triggering platform message ID. History is capped before this turn to avoid future queued turns. */\n currentMessageId?: string;\n}\n\nexport interface SyncChatSessionOptions {\n conversationDir: string;\n sessionKey: string;\n sessionManager: SessionStore;\n /** The triggering platform message ID. Sync is capped before this turn to avoid future queued turns. */\n currentMessageId?: string;\n}\n\nexport interface ResetChatSessionOptions {\n conversationDir: string;\n sessionKey: string;\n cwd?: string;\n}\n\nexport interface RegisterThreadSessionOptions {\n conversationDir: string;\n sessionKey: string;\n cwd?: string;\n}\n\nexport interface HasMaterializedSessionOptions {\n conversationDir: string;\n sessionKey: string;\n}\n\nexport interface ThreadBootstrapWaitOptions {\n parentSessionKey: string;\n sessionKey: string;\n hasThreadSession: () => boolean;\n isParentRunning: () => boolean;\n sleep?: (ms: number) => Promise<void>;\n pollMs?: number;\n}\n\n// ── v3 migration ─────────────────────────────────────────────────────────────\n\nexport interface MigrateResult {\n file: string;\n status: \"migrated\" | \"already-v4\" | \"skipped\";\n detail?: string;\n}\n\nexport interface Pi084MigrationResult {\n file: string;\n status: \"migrated\" | \"already-current\" | \"not-pi-084\";\n detail?: string;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Office } from "
|
|
2
|
-
import type { AgentConfig, GlobalRunnerCacheControl, OfficeAddress, RunnerCacheControl, SettingsApplyResult } from "
|
|
3
|
-
export type { GlobalRunnerCacheControl, RunnerCacheControl, SettingsApplyResult } from "
|
|
1
|
+
import type { Office } from "../office/index.js";
|
|
2
|
+
import type { AgentConfig, GlobalRunnerCacheControl, OfficeAddress, RunnerCacheControl, SettingsApplyResult } from "../types.js";
|
|
3
|
+
export type { GlobalRunnerCacheControl, RunnerCacheControl, SettingsApplyResult, } from "../types.js";
|
|
4
4
|
export declare function applyConversationSettings(runtime: RunnerCacheControl | undefined, office: Office, patch: Partial<AgentConfig>): SettingsApplyResult;
|
|
5
5
|
export declare function applyGlobalSettings(runtime: GlobalRunnerCacheControl | undefined, patch: Partial<AgentConfig>): {
|
|
6
6
|
ok: true;
|
|
@@ -13,4 +13,4 @@ export declare function applyGlobalSettings(runtime: GlobalRunnerCacheControl |
|
|
|
13
13
|
* the next message when its mount signature no longer matches.
|
|
14
14
|
*/
|
|
15
15
|
export declare function applyOfficeVisibility(runtime: RunnerCacheControl | undefined, office: Office, visibility: "private" | null): SettingsApplyResult;
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/settings/apply.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,WAAW,EACX,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAcrB,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,kBAAkB,GAAG,SAAS,EACvC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAC1B,mBAAmB,CAYrB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,GAAG,SAAS,EAC7C,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,kBAAkB,EAAE,aAAa,EAAE,CAAA;CAAE,CAKnD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,GAAG,SAAS,EACvC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,SAAS,GAAG,IAAI,GAC3B,mBAAmB,CAMrB"}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* their old runner until it settles, are reported as stale, and are cleared
|
|
17
17
|
* automatically before their next turn.
|
|
18
18
|
*/
|
|
19
|
-
import { setOfficeVisibilityOverride, updateConversationSettings, updateGlobalSettings, } from "./
|
|
19
|
+
import { setOfficeVisibilityOverride, updateConversationSettings, updateGlobalSettings, } from "./index.js";
|
|
20
20
|
/** True when a patch touches keys a cached session runner bakes in. */
|
|
21
21
|
function affectsCachedRunner(patch) {
|
|
22
22
|
return (patch.provider !== undefined ||
|
|
@@ -57,4 +57,4 @@ export function applyOfficeVisibility(runtime, office, visibility) {
|
|
|
57
57
|
setOfficeVisibilityOverride(office, visibility);
|
|
58
58
|
return { ok: true, runtimeSwitched: runtime ? true : null };
|
|
59
59
|
}
|
|
60
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/settings/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAgBpB,uEAAuE;AACvE,SAAS,mBAAmB,CAAC,KAA2B;IACtD,OAAO,CACL,KAAK,CAAC,QAAQ,KAAK,SAAS;QAC5B,KAAK,CAAC,KAAK,KAAK,SAAS;QACzB,KAAK,CAAC,aAAa,KAAK,SAAS;QACjC,uEAAuE;QACvE,uCAAuC;QACvC,KAAK,CAAC,UAAU,KAAK,SAAS,CAC/B,CAAC;AACJ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;IAChD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * The one writer seam for settings mutations that affect live conversations.\n * Chat commands (/model, /sandbox) and the Admin portal are adapters here;\n * none of them call updateConversationSettings/updateGlobalSettings directly\n * for these keys anymore.\n *\n * Policy, uniform across all adapters:\n * - llm.* changes bake into cached session runners, so a conversation-scoped\n * change clears the conversation's cached runners BEFORE writing — and\n * refuses (no write, no clear) while the conversation has a running job.\n * Disk and cache never disagree.\n * - Other keys (sandbox mount, slack replyMode, limits) are re-read at use\n * time and write without touching runners.\n * - Global changes always write (the Admin default surface), then clear every\n * idle conversation's cached runners; conversations that were busy keep\n * their old runner until it settles, are reported as stale, and are cleared\n * automatically before their next turn.\n */\nimport {\n setOfficeVisibilityOverride,\n updateConversationSettings,\n updateGlobalSettings,\n} from \"./index.js\";\nimport type { Office } from \"../office/index.js\";\nimport type {\n AgentConfig,\n GlobalRunnerCacheControl,\n OfficeAddress,\n RunnerCacheControl,\n SettingsApplyResult,\n} from \"../types.js\";\n\nexport type {\n GlobalRunnerCacheControl,\n RunnerCacheControl,\n SettingsApplyResult,\n} from \"../types.js\";\n\n/** True when a patch touches keys a cached session runner bakes in. */\nfunction affectsCachedRunner(patch: Partial<AgentConfig>): boolean {\n return (\n patch.provider !== undefined ||\n patch.model !== undefined ||\n patch.thinkingLevel !== undefined ||\n // MCP tools are connected when the runner is built, so a server change\n // only takes effect on a fresh runner.\n patch.mcpServers !== undefined\n );\n}\n\nexport function applyConversationSettings(\n runtime: RunnerCacheControl | undefined,\n office: Office,\n patch: Partial<AgentConfig>,\n): SettingsApplyResult {\n let runtimeSwitched: boolean | null = null;\n if (affectsCachedRunner(patch) && runtime) {\n // Clear-or-refuse before writing. The clear and the write happen in the\n // same synchronous tick, so no runner can be created in between.\n if (!runtime.switchConversationModel(office.address, patch.provider ?? \"\", patch.model ?? \"\")) {\n return { ok: false, reason: \"busy\" };\n }\n runtimeSwitched = true;\n }\n updateConversationSettings(office, patch);\n return { ok: true, runtimeSwitched };\n}\n\nexport function applyGlobalSettings(\n runtime: GlobalRunnerCacheControl | undefined,\n patch: Partial<AgentConfig>,\n): { ok: true; staleConversations: OfficeAddress[] } {\n updateGlobalSettings(patch);\n const staleConversations =\n affectsCachedRunner(patch) && runtime ? runtime.refreshAllConversations().busy : [];\n return { ok: true, staleConversations };\n}\n\n/**\n * Visibility changes follow the same clear-or-refuse contract as model\n * changes: the system prompt bakes the workspace projection, so the cached\n * runner must clear before the write, and the container is re-provisioned on\n * the next message when its mount signature no longer matches.\n */\nexport function applyOfficeVisibility(\n runtime: RunnerCacheControl | undefined,\n office: Office,\n visibility: \"private\" | null,\n): SettingsApplyResult {\n if (runtime && !runtime.refreshConversationEnvironment(office.address)) {\n return { ok: false, reason: \"busy\" };\n }\n setOfficeVisibilityOverride(office, visibility);\n return { ok: true, runtimeSwitched: runtime ? true : null };\n}\n"]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type Static } from "@sinclair/typebox";
|
|
2
|
+
export declare class MissingGlobalSettingsError extends Error {
|
|
3
|
+
readonly settingsPath: string;
|
|
4
|
+
constructor(settingsPath: string);
|
|
5
|
+
}
|
|
6
|
+
export type { AgentConfig, SandboxSettings } from "../types.js";
|
|
7
|
+
import type { AgentConfig } from "../types.js";
|
|
8
|
+
import type { McpServerConfig } from "../harness/types.js";
|
|
9
|
+
import type { OnboardLlmChoice } from "../types.js";
|
|
10
|
+
import type { Office } from "../office/index.js";
|
|
11
|
+
declare const SettingsFileSchema: import("@sinclair/typebox").TObject<{
|
|
12
|
+
llm: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
13
|
+
provider: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
14
|
+
model: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
15
|
+
thinkingLevel: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"off">, import("@sinclair/typebox").TLiteral<"minimal">, import("@sinclair/typebox").TLiteral<"low">, import("@sinclair/typebox").TLiteral<"medium">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"xhigh">, import("@sinclair/typebox").TLiteral<"max">]>>;
|
|
16
|
+
}>>;
|
|
17
|
+
sentry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
18
|
+
dsn: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
19
|
+
}>>;
|
|
20
|
+
slack: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
21
|
+
replyMode: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"top-level">, import("@sinclair/typebox").TLiteral<"thread">]>>;
|
|
22
|
+
}>>;
|
|
23
|
+
/**
|
|
24
|
+
* Conversation-only office policy. `visibility: "private"` marks a
|
|
25
|
+
* platform-public conversation as private; nothing can widen visibility
|
|
26
|
+
* beyond what the platform grants, so "public" is never stored here.
|
|
27
|
+
*/
|
|
28
|
+
office: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
29
|
+
visibility: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"private">>;
|
|
30
|
+
}>>;
|
|
31
|
+
sandbox: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
32
|
+
cpus: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
33
|
+
memory: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
34
|
+
boost: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
35
|
+
cpus: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
36
|
+
memory: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
37
|
+
}>>;
|
|
38
|
+
/**
|
|
39
|
+
* Retired door-policy keys (ADR 0008). Still accepted so existing files
|
|
40
|
+
* load, never copied into AgentConfig, and removed by
|
|
41
|
+
* `mikan office migrate-door-policy`.
|
|
42
|
+
*/
|
|
43
|
+
image: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
44
|
+
workspaceMount: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"private">, import("@sinclair/typebox").TLiteral<"full">]>>;
|
|
45
|
+
}>>;
|
|
46
|
+
workspace: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
47
|
+
doorPolicy: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"isolated">, import("@sinclair/typebox").TLiteral<"trusted">]>>;
|
|
48
|
+
layout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"conversation">, import("@sinclair/typebox").TLiteral<"shared-support">, import("@sinclair/typebox").TLiteral<"full">]>>;
|
|
49
|
+
visibility: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"public">, import("@sinclair/typebox").TLiteral<"private">]>>;
|
|
50
|
+
}>>;
|
|
51
|
+
defaultSharedVault: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
52
|
+
}>>;
|
|
53
|
+
/**
|
|
54
|
+
* MCP servers, keyed by name. Merged per key across scopes: a conversation
|
|
55
|
+
* entry overrides (or, with `disabled: true`, turns off) the same-name
|
|
56
|
+
* global entry; other global entries stay available. `open-connector` is an
|
|
57
|
+
* ordinary entry that the host fills in from `OPENCONNECTOR_ENDPOINT` when
|
|
58
|
+
* neither scope declares it (see `src/harness/open-connector.ts`).
|
|
59
|
+
*/
|
|
60
|
+
mcpServers: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TObject<{
|
|
61
|
+
command: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
62
|
+
args: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
63
|
+
env: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
|
|
64
|
+
url: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
65
|
+
headers: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
|
|
66
|
+
disabled: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
67
|
+
}>>>;
|
|
68
|
+
}>;
|
|
69
|
+
export type SettingsFileConfig = Static<typeof SettingsFileSchema>;
|
|
70
|
+
export type SandboxFileSettings = NonNullable<SettingsFileConfig["sandbox"]>;
|
|
71
|
+
export declare function loadSettingsFile(settingsPath: string): SettingsFileConfig | undefined;
|
|
72
|
+
export declare function loadGlobalSettings(): AgentConfig;
|
|
73
|
+
/**
|
|
74
|
+
* Host-authoritative location of a conversation's settings file:
|
|
75
|
+
* `<office state dir>/settings.json`. The Office value names both the
|
|
76
|
+
* state-dir key and the legacy pre-host-migration location (its workspace
|
|
77
|
+
* dir) — the key is never inferred from a directory basename.
|
|
78
|
+
*
|
|
79
|
+
* Conversation settings used to live at `<conversationDir>/settings.json`,
|
|
80
|
+
* but conversation dirs are bind-mounted read-write into sandbox containers
|
|
81
|
+
* in image mode — code inside the sandbox could edit its own settings.json
|
|
82
|
+
* and flip `sandbox.image.workspaceMount` to "full", remounting the entire
|
|
83
|
+
* workspace into its container (cross-conversation access). Settings are an
|
|
84
|
+
* administrator surface, so they live under the host-only state dir.
|
|
85
|
+
*
|
|
86
|
+
* Migration: on first access per conversation, a legacy
|
|
87
|
+
* `<conversationDir>/settings.json` is moved here. The new file's existence
|
|
88
|
+
* (an empty `{}` is written when there is nothing to migrate) is the
|
|
89
|
+
* migration marker — a legacy file (re)appearing later, e.g. planted from
|
|
90
|
+
* inside the sandbox, is never read again.
|
|
91
|
+
*/
|
|
92
|
+
export declare function conversationSettingsPath(office: Office): string;
|
|
93
|
+
export declare function slackConversationAutoReplyEnabled(office: Office): boolean;
|
|
94
|
+
export declare function setSlackConversationAutoReply(office: Office, enabled: boolean): void;
|
|
95
|
+
export declare function resolveConversationSettings(office: Office): AgentConfig;
|
|
96
|
+
export declare function resolveSentryDsn(): string | undefined;
|
|
97
|
+
export declare function createGlobalSettingsFile(stateDir: string, llm?: OnboardLlmChoice): string;
|
|
98
|
+
export declare function hasDefinedValue(values: Record<string, unknown> | undefined): boolean;
|
|
99
|
+
export declare function compactSettingsConfig(config: SettingsFileConfig): SettingsFileConfig;
|
|
100
|
+
export declare function updateGlobalSettings(patch: Partial<AgentConfig>): void;
|
|
101
|
+
export declare function updateConversationSettings(office: Office, patch: Partial<AgentConfig>): void;
|
|
102
|
+
/**
|
|
103
|
+
* The two scope-level MCP server maps, unmerged: the portal edits each scope's
|
|
104
|
+
* own file, so it needs the raw per-scope values, not the effective merge
|
|
105
|
+
* (`resolveConversationSettings` owns that).
|
|
106
|
+
*/
|
|
107
|
+
export declare function loadScopeMcpServers(office: Office): {
|
|
108
|
+
global: Record<string, McpServerConfig>;
|
|
109
|
+
conversation: Record<string, McpServerConfig>;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* The conversation's own visibility override, or null when it follows the
|
|
113
|
+
* platform. Only "private" can be stored: an operator may narrow a public
|
|
114
|
+
* channel, never widen a private one (see ADR 0008).
|
|
115
|
+
*/
|
|
116
|
+
export declare function loadOfficeVisibilityOverride(office: Office): "private" | null;
|
|
117
|
+
export declare function setOfficeVisibilityOverride(office: Office, visibility: "private" | null): void;
|
|
118
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AM,GAAG,WAAW,CAiBvE;AAOD,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGrD;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAkBzF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,OAAO,CAEpF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAUpF;AAiED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAEtE;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAE5F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC/C,CAKA;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAE7E;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAa9F"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { existsSync, lstatSync, readFileSync, renameSync, rmSync } from "node:fs";
|
|
3
|
-
import { dirname, join
|
|
4
|
-
import { effectiveStateDir } from "
|
|
5
|
-
import { readEnv } from "
|
|
6
|
-
import { ensureDirExists, readJsonSchemaFileIfExists } from "
|
|
7
|
-
import
|
|
8
|
-
import * as log from "./log.js";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { effectiveStateDir } from "../cli/arg-grammar.js";
|
|
5
|
+
import { readEnv } from "../env-manifest.js";
|
|
6
|
+
import { atomicWritePrivateFile, ensureDirExists, readJsonSchemaFileIfExists, } from "../file-guards.js";
|
|
7
|
+
import * as log from "../log.js";
|
|
9
8
|
export class MissingGlobalSettingsError extends Error {
|
|
10
9
|
constructor(settingsPath) {
|
|
11
10
|
super(`Missing global settings file at ${settingsPath}`);
|
|
@@ -13,7 +12,6 @@ export class MissingGlobalSettingsError extends Error {
|
|
|
13
12
|
this.name = "MissingGlobalSettingsError";
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
import { listRegisteredOffices } from "./office/index.js";
|
|
17
15
|
const ONBOARD_SETTINGS = {
|
|
18
16
|
llm: {
|
|
19
17
|
provider: "anthropic",
|
|
@@ -105,7 +103,7 @@ const SettingsFileSchema = Type.Object({
|
|
|
105
103
|
disabled: Type.Optional(Type.Boolean()),
|
|
106
104
|
}))),
|
|
107
105
|
});
|
|
108
|
-
function loadSettingsFile(settingsPath) {
|
|
106
|
+
export function loadSettingsFile(settingsPath) {
|
|
109
107
|
return readJsonSchemaFileIfExists(settingsPath, SettingsFileSchema, (detail) => detail === "unexpected JSON shape"
|
|
110
108
|
? `Malformed settings file at ${settingsPath}: expected a JSON object at the top level`
|
|
111
109
|
: `Malformed settings file at ${settingsPath}: ${detail}`);
|
|
@@ -292,35 +290,6 @@ export function resolveConversationSettings(office) {
|
|
|
292
290
|
...(Object.keys(mcpServers).length > 0 ? { mcpServers } : {}),
|
|
293
291
|
});
|
|
294
292
|
}
|
|
295
|
-
/**
|
|
296
|
-
* True when `child` is `parent` or a path inside it. Purely lexical (no
|
|
297
|
-
* symlink resolution) — used for configuration sanity checks, not as the
|
|
298
|
-
* final security boundary.
|
|
299
|
-
*/
|
|
300
|
-
export function isPathInside(child, parent) {
|
|
301
|
-
const parentPath = resolve(parent);
|
|
302
|
-
const childPath = resolve(child);
|
|
303
|
-
return childPath === parentPath || childPath.startsWith(parentPath + "/");
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* The state dir (settings, office records, vaults) must never live inside
|
|
307
|
-
* the working dir: conversation opt-in "full" mode mounts the entire working
|
|
308
|
-
* dir read-write into sandbox containers, which would expose host-authoritative
|
|
309
|
-
* state and credentials. Fatal under sandboxed modes; host mode has no mounts,
|
|
310
|
-
* so only warn about the bad hygiene.
|
|
311
|
-
*/
|
|
312
|
-
export function assertStateDirOutsideWorkspace(stateDir, workingDir, sandboxType) {
|
|
313
|
-
if (!isPathInside(stateDir, workingDir))
|
|
314
|
-
return;
|
|
315
|
-
const message = `--state-dir (${stateDir}) must not be inside the working directory (${workingDir}): ` +
|
|
316
|
-
`sandbox containers mount the working directory, and a mounted state dir ` +
|
|
317
|
-
`would expose settings, office records, vaults, and credentials to sandboxed code.`;
|
|
318
|
-
if (sandboxType === "host") {
|
|
319
|
-
log.logWarning("Insecure state dir location", message);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
throw new Error(message);
|
|
323
|
-
}
|
|
324
293
|
/** Settings-file DSN wins over SENTRY_DSN env — the rule lives only here. */
|
|
325
294
|
function sentryDsnFrom(fromFile) {
|
|
326
295
|
return fromFile || readEnv("SENTRY_DSN");
|
|
@@ -348,21 +317,10 @@ export function createGlobalSettingsFile(stateDir, llm) {
|
|
|
348
317
|
atomicWritePrivateFile(settingsPath, JSON.stringify(settings, null, 2));
|
|
349
318
|
return settingsPath;
|
|
350
319
|
}
|
|
351
|
-
|
|
352
|
-
* Externally-visible base URL of the link/OAuth server, e.g.
|
|
353
|
-
* `https://mikan.example.com` (no trailing slash). Read from `LINK_URL` or
|
|
354
|
-
* `MIKAN_LINK_URL`, the same env var the bot uses to build credential onboarding links.
|
|
355
|
-
*/
|
|
356
|
-
export function resolveLinkBaseUrl() {
|
|
357
|
-
const raw = readEnv("LINK_URL");
|
|
358
|
-
if (!raw)
|
|
359
|
-
return undefined;
|
|
360
|
-
return raw.replace(/\/+$/, "");
|
|
361
|
-
}
|
|
362
|
-
function hasDefinedValue(values) {
|
|
320
|
+
export function hasDefinedValue(values) {
|
|
363
321
|
return values !== undefined && Object.values(values).some((value) => value !== undefined);
|
|
364
322
|
}
|
|
365
|
-
function compactSettingsConfig(config) {
|
|
323
|
+
export function compactSettingsConfig(config) {
|
|
366
324
|
return {
|
|
367
325
|
...(hasDefinedValue(config.llm) ? { llm: config.llm } : {}),
|
|
368
326
|
...(hasDefinedValue(config.sentry) ? { sentry: config.sentry } : {}),
|
|
@@ -454,80 +412,4 @@ export function setOfficeVisibilityOverride(office, visibility) {
|
|
|
454
412
|
ensureDirExists(dirname(settingsPath));
|
|
455
413
|
atomicWritePrivateFile(settingsPath, JSON.stringify(compactSettingsConfig({ ...rest, ...(visibility ? { office: { visibility } } : {}) }), null, 2));
|
|
456
414
|
}
|
|
457
|
-
|
|
458
|
-
image: "sandbox.image.workspaceMount",
|
|
459
|
-
workspace: "sandbox.workspace",
|
|
460
|
-
};
|
|
461
|
-
/**
|
|
462
|
-
* Strip the retired door-policy keys from one settings file. Returns the
|
|
463
|
-
* removed key paths, or an empty list when nothing had to change (the file is
|
|
464
|
-
* then left byte-for-byte alone, which also preserves `{}` migration markers).
|
|
465
|
-
* The only value carried forward is an explicit shared-support `private`
|
|
466
|
-
* visibility, which maps onto `office.visibility` (ADR 0008). Every other
|
|
467
|
-
* retired combination — `full`, `isolated`, legacy `private` — is dropped
|
|
468
|
-
* without deriving a grant.
|
|
469
|
-
*/
|
|
470
|
-
function stripRetiredDoorPolicy(settingsPath, allowVisibilityCarry) {
|
|
471
|
-
const existing = loadSettingsFile(settingsPath);
|
|
472
|
-
if (!existing?.sandbox)
|
|
473
|
-
return { removed: [] };
|
|
474
|
-
const { image, workspace, ...sandboxRest } = existing.sandbox;
|
|
475
|
-
const removed = [];
|
|
476
|
-
if (image?.workspaceMount !== undefined)
|
|
477
|
-
removed.push(RETIRED_KEYS.image);
|
|
478
|
-
if (workspace !== undefined)
|
|
479
|
-
removed.push(RETIRED_KEYS.workspace);
|
|
480
|
-
if (removed.length === 0)
|
|
481
|
-
return { removed };
|
|
482
|
-
const carry = allowVisibilityCarry &&
|
|
483
|
-
workspace?.doorPolicy === "trusted" &&
|
|
484
|
-
workspace.layout !== "full" &&
|
|
485
|
-
workspace.visibility === "private";
|
|
486
|
-
const { workspaceMount: _mount, ...imageRest } = image ?? {};
|
|
487
|
-
const sandbox = {
|
|
488
|
-
...sandboxRest,
|
|
489
|
-
...(hasDefinedValue(imageRest) ? { image: imageRest } : {}),
|
|
490
|
-
};
|
|
491
|
-
const next = {
|
|
492
|
-
...existing,
|
|
493
|
-
sandbox,
|
|
494
|
-
...(carry ? { office: { ...existing.office, visibility: "private" } } : {}),
|
|
495
|
-
};
|
|
496
|
-
atomicWritePrivateFile(settingsPath, JSON.stringify(compactSettingsConfig(next), null, 2));
|
|
497
|
-
return { removed, ...(carry ? { visibility: "private" } : {}) };
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* One-time removal of the retired door-policy settings from the global file
|
|
501
|
-
* and every registered office (ADR 0008). Run with the daemon stopped.
|
|
502
|
-
*/
|
|
503
|
-
export function migrateLegacyDoorPolicy(workspace) {
|
|
504
|
-
const report = { global: [], conversations: [], skipped: [] };
|
|
505
|
-
try {
|
|
506
|
-
report.global = stripRetiredDoorPolicy(join(workspace.stateDir, "settings.json"), false).removed;
|
|
507
|
-
}
|
|
508
|
-
catch (error) {
|
|
509
|
-
report.skipped.push({
|
|
510
|
-
key: "global",
|
|
511
|
-
reason: error instanceof Error ? error.message : String(error),
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
for (const record of listRegisteredOffices(workspace.stateDir)) {
|
|
515
|
-
const office = workspace.office(record);
|
|
516
|
-
const settingsPath = join(office.stateDir, "settings.json");
|
|
517
|
-
if (!existsSync(settingsPath))
|
|
518
|
-
continue;
|
|
519
|
-
try {
|
|
520
|
-
const result = stripRetiredDoorPolicy(settingsPath, true);
|
|
521
|
-
if (result.removed.length > 0)
|
|
522
|
-
report.conversations.push({ key: office.key, ...result });
|
|
523
|
-
}
|
|
524
|
-
catch (error) {
|
|
525
|
-
report.skipped.push({
|
|
526
|
-
key: office.key,
|
|
527
|
-
reason: error instanceof Error ? error.message : String(error),
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
return report;
|
|
532
|
-
}
|
|
533
|
-
//# sourceMappingURL=config.js.map
|
|
415
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/settings/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAA4B,YAAoB;QAC9C,KAAK,CAAC,mCAAmC,YAAY,EAAE,CAAC,CAAC;4BAD/B,YAAY;QAEtC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAQD,MAAM,gBAAgB,GAAuB;IAC3C,GAAG,EAAE;QACH,QAAQ,EAAE,WAAW;QACrB,KAAK,EAAE,mBAAmB;QAC1B,aAAa,EAAE,KAAK;KACrB;IACD,KAAK,EAAE;QACL,SAAS,EAAE,WAAW;KACvB;IACD,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AAc,EAAE,UAA4B;IACtF,MAAM,YAAY,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAChD,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACvC,sBAAsB,CACpB,YAAY,EACZ,IAAI,CAAC,SAAS,CACZ,qBAAqB,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACrF,IAAI,EACJ,CAAC,CACF,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { Type, type Static } from \"@sinclair/typebox\";\nimport { existsSync, lstatSync, readFileSync, renameSync, rmSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { effectiveStateDir } from \"../cli/arg-grammar.js\";\nimport { readEnv } from \"../env-manifest.js\";\nimport {\n atomicWritePrivateFile,\n ensureDirExists,\n readJsonSchemaFileIfExists,\n} from \"../file-guards.js\";\nimport * as log from \"../log.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 type { AgentConfig, SandboxSettings } from \"../types.js\";\nimport type { AgentConfig, SandboxSettings } from \"../types.js\";\nimport type { McpServerConfig } from \"../harness/types.js\";\nimport type { OnboardLlmChoice } from \"../types.js\";\nimport type { Office } from \"../office/index.js\";\n\nconst ONBOARD_SETTINGS: SettingsFileConfig = {\n llm: {\n provider: \"anthropic\",\n model: \"claude-sonnet-4-6\",\n thinkingLevel: \"off\",\n },\n slack: {\n replyMode: \"top-level\",\n },\n sandbox: {\n cpus: \"0.5\",\n memory: \"1g\",\n boost: {\n cpus: \"2\",\n memory: \"4g\",\n },\n // Office visibility is not a setting here: it follows the platform\n // conversation type (see office/projection resolveOfficeVisibility).\n defaultSharedVault: \"\",\n },\n};\n\nconst SettingsFileSchema = Type.Object({\n llm: Type.Optional(\n Type.Object({\n provider: Type.Optional(Type.String()),\n model: Type.Optional(Type.String()),\n thinkingLevel: Type.Optional(\n Type.Union([\n Type.Literal(\"off\"),\n Type.Literal(\"minimal\"),\n Type.Literal(\"low\"),\n Type.Literal(\"medium\"),\n Type.Literal(\"high\"),\n Type.Literal(\"xhigh\"),\n Type.Literal(\"max\"),\n ]),\n ),\n }),\n ),\n sentry: Type.Optional(\n Type.Object({\n dsn: Type.Optional(Type.String()),\n }),\n ),\n slack: Type.Optional(\n Type.Object({\n replyMode: Type.Optional(Type.Union([Type.Literal(\"top-level\"), Type.Literal(\"thread\")])),\n }),\n ),\n /**\n * Conversation-only office policy. `visibility: \"private\"` marks a\n * platform-public conversation as private; nothing can widen visibility\n * beyond what the platform grants, so \"public\" is never stored here.\n */\n office: Type.Optional(\n Type.Object({\n visibility: Type.Optional(Type.Literal(\"private\")),\n }),\n ),\n sandbox: Type.Optional(\n Type.Object({\n cpus: Type.Optional(Type.String()),\n memory: Type.Optional(Type.String()),\n boost: Type.Optional(\n Type.Object({\n cpus: Type.Optional(Type.String()),\n memory: Type.Optional(Type.String()),\n }),\n ),\n /**\n * Retired door-policy keys (ADR 0008). Still accepted so existing files\n * load, never copied into AgentConfig, and removed by\n * `mikan office migrate-door-policy`.\n */\n image: Type.Optional(\n Type.Object({\n workspaceMount: Type.Optional(\n Type.Union([Type.Literal(\"private\"), Type.Literal(\"full\")]),\n ),\n }),\n ),\n workspace: Type.Optional(\n Type.Object({\n doorPolicy: Type.Optional(\n Type.Union([Type.Literal(\"isolated\"), Type.Literal(\"trusted\")]),\n ),\n layout: Type.Optional(\n Type.Union([\n Type.Literal(\"conversation\"),\n Type.Literal(\"shared-support\"),\n Type.Literal(\"full\"),\n ]),\n ),\n visibility: Type.Optional(Type.Union([Type.Literal(\"public\"), Type.Literal(\"private\")])),\n }),\n ),\n defaultSharedVault: Type.Optional(Type.String()),\n }),\n ),\n /**\n * MCP servers, keyed by name. Merged per key across scopes: a conversation\n * entry overrides (or, with `disabled: true`, turns off) the same-name\n * global entry; other global entries stay available. `open-connector` is an\n * ordinary entry that the host fills in from `OPENCONNECTOR_ENDPOINT` when\n * neither scope declares it (see `src/harness/open-connector.ts`).\n */\n mcpServers: Type.Optional(\n Type.Record(\n Type.String(),\n Type.Object({\n command: Type.Optional(Type.String()),\n args: Type.Optional(Type.Array(Type.String())),\n env: Type.Optional(Type.Record(Type.String(), Type.String())),\n url: Type.Optional(Type.String()),\n headers: Type.Optional(Type.Record(Type.String(), Type.String())),\n disabled: Type.Optional(Type.Boolean()),\n }),\n ),\n ),\n});\n\nexport type SettingsFileConfig = Static<typeof SettingsFileSchema>;\nexport type SandboxFileSettings = NonNullable<SettingsFileConfig[\"sandbox\"]>;\n\nexport function loadSettingsFile(settingsPath: string): SettingsFileConfig | undefined {\n return readJsonSchemaFileIfExists(settingsPath, SettingsFileSchema, (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 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.sentry?.dsn !== undefined ? { sentryDsn: config.sentry.dsn } : {}),\n ...(config.sandbox !== undefined ? { sandbox: normalizeSandboxSettings(config.sandbox) } : {}),\n ...(config.slack !== undefined ? { slack: config.slack } : {}),\n ...(config.mcpServers !== undefined ? { mcpServers: config.mcpServers } : {}),\n };\n}\n\n/**\n * File shape → in-memory shape for the sandbox group. An empty or\n * whitespace-only `defaultSharedVault` means \"no default\" and is dropped;\n * non-empty values are trimmed. Everything else passes through as-is.\n */\nfunction normalizeSandboxSettings(sandbox: SandboxFileSettings): SandboxSettings {\n const defaultSharedVault = sandbox.defaultSharedVault?.trim();\n // Retired `image.workspaceMount` and `workspace` are dropped here: office\n // visibility comes from the platform (ADR 0008), never from these keys.\n return {\n ...(sandbox.cpus !== undefined ? { cpus: sandbox.cpus } : {}),\n ...(sandbox.memory !== undefined ? { memory: sandbox.memory } : {}),\n ...(sandbox.boost !== undefined ? { boost: sandbox.boost } : {}),\n ...(defaultSharedVault ? { defaultSharedVault } : {}),\n };\n}\n\n/**\n * Merge two sandbox settings groups. The merge invariant is LEAF-LEVEL:\n * an override that only sets `sandbox.memory` keeps the base `sandbox.cpus`,\n * and an override that only sets `boost.memory` keeps the base `boost.cpus`\n * (same for `image`). This mirrors how the fields merged when they were\n * flat top-level keys; a group-level spread would silently drop base leaves.\n */\nfunction mergeSandboxSettings(\n base: SandboxSettings | undefined,\n override: SandboxSettings | undefined,\n): SandboxSettings | undefined {\n if (!base) return override;\n if (!override) return base;\n return {\n ...base,\n ...override,\n ...(base.boost || override.boost ? { boost: { ...base.boost, ...override.boost } } : {}),\n };\n}\n\nfunction getSettingsPath(): string {\n return join(effectiveStateDir(), \"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 \\`mikan --onboard\\` to create settings.json.`,\n );\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 = requireString(fromFile.thinkingLevel, \"llm.thinkingLevel\") as ThinkingLevel;\n const sentryDsn = sentryDsnFrom(fromFile.sentryDsn);\n const sandbox = fromFile.sandbox;\n const slack = fromFile.slack;\n const mcpServers = fromFile.mcpServers;\n\n return {\n provider,\n model,\n thinkingLevel,\n sentryDsn,\n sandbox,\n slack,\n mcpServers,\n };\n}\n\nfunction loadRawGlobalSettings(): Partial<AgentConfig> {\n return normalizeSettingsConfig(requireGlobalSettings());\n}\n\nexport function loadGlobalSettings(): AgentConfig {\n return toAgentConfig(loadRawGlobalSettings());\n}\n\n/**\n * Host-authoritative location of a conversation's settings file:\n * `<office state dir>/settings.json`. The Office value names both the\n * state-dir key and the legacy pre-host-migration location (its workspace\n * dir) — the key is never inferred from a directory basename.\n *\n * Conversation settings used to live at `<conversationDir>/settings.json`,\n * but conversation dirs are bind-mounted read-write into sandbox containers\n * in image mode — code inside the sandbox could edit its own settings.json\n * and flip `sandbox.image.workspaceMount` to \"full\", remounting the entire\n * workspace into its container (cross-conversation access). Settings are an\n * administrator surface, so they live under the host-only state dir.\n *\n * Migration: on first access per conversation, a legacy\n * `<conversationDir>/settings.json` is moved here. The new file's existence\n * (an empty `{}` is written when there is nothing to migrate) is the\n * migration marker — a legacy file (re)appearing later, e.g. planted from\n * inside the sandbox, is never read again.\n */\nexport function conversationSettingsPath(office: Office): string {\n const hostPath = join(office.stateDir, \"settings.json\");\n if (existsSync(hostPath)) {\n assertSettingsFile(hostPath, \"Host conversation settings\");\n return hostPath;\n }\n\n ensureDirExists(dirname(hostPath));\n const legacyPath = join(office.dir, \"settings.json\");\n let content = \"{}\\n\";\n let migrated = false;\n if (existsSync(legacyPath)) {\n assertSettingsFile(legacyPath, \"Legacy conversation settings\");\n content = readFileSync(legacyPath, \"utf-8\");\n // Validate before moving the file. A malformed legacy file must fail\n // closed and remain available for an operator to repair.\n loadSettingsFile(legacyPath);\n migrated = true;\n }\n atomicWritePrivateFile(hostPath, content);\n if (migrated) {\n try {\n rmSync(legacyPath);\n } catch (err) {\n log.logWarning(`Could not remove legacy conversation settings: ${legacyPath}`, String(err));\n }\n log.logInfo(`Migrated conversation settings to host-only path: ${hostPath}`);\n }\n return hostPath;\n}\n\nfunction assertSettingsFile(path: string, label: string): void {\n let stats;\n try {\n stats = lstatSync(path);\n } catch (err) {\n throw new Error(`${label} cannot be inspected: ${path}`, { cause: err });\n }\n if (stats.isSymbolicLink() || !stats.isFile()) {\n throw new Error(`${label} must be a regular non-symlink file: ${path}`);\n }\n}\n\nconst AUTO_REPLY_FILE = \"auto-reply\";\nconst AUTO_REPLY_DISABLED_FILE = \"auto-reply.disabled\";\n\nexport function slackConversationAutoReplyEnabled(office: Office): boolean {\n return existsSync(join(office.dir, AUTO_REPLY_FILE));\n}\n\nexport function setSlackConversationAutoReply(office: Office, enabled: boolean): void {\n ensureDirExists(office.dir);\n const enabledPath = join(office.dir, AUTO_REPLY_FILE);\n const disabledPath = join(office.dir, AUTO_REPLY_DISABLED_FILE);\n const targetPath = enabled ? enabledPath : disabledPath;\n const otherPath = enabled ? disabledPath : enabledPath;\n\n if (existsSync(otherPath)) {\n renameSync(otherPath, targetPath);\n return;\n }\n if (enabled && !existsSync(targetPath)) {\n atomicWritePrivateFile(targetPath, \"\");\n }\n}\n\nexport function resolveConversationSettings(office: Office): AgentConfig {\n const globalConfig = loadRawGlobalSettings();\n const conversationConfig = normalizeSettingsConfig(\n loadSettingsFile(conversationSettingsPath(office)) ?? {},\n );\n // MCP servers merge per key: a conversation redefines or disables individual\n // servers without losing the rest of the global set.\n const mcpServers = { ...globalConfig.mcpServers, ...conversationConfig.mcpServers };\n // The sandbox group merges at the leaf level (see mergeSandboxSettings):\n // a conversation that only sets sandbox.memory keeps the global sandbox.cpus.\n const sandbox = mergeSandboxSettings(globalConfig.sandbox, conversationConfig.sandbox);\n return toAgentConfig({\n ...globalConfig,\n ...conversationConfig,\n ...(sandbox ? { sandbox } : {}),\n ...(Object.keys(mcpServers).length > 0 ? { mcpServers } : {}),\n });\n}\n\n/** Settings-file DSN wins over SENTRY_DSN env — the rule lives only here. */\nfunction sentryDsnFrom(fromFile: string | undefined): string | undefined {\n return fromFile || readEnv(\"SENTRY_DSN\");\n}\n\nexport function resolveSentryDsn(): string | undefined {\n const fromFile = normalizeSettingsConfig(loadSettingsFile(getSettingsPath()) ?? {});\n return sentryDsnFrom(fromFile.sentryDsn);\n}\n\nexport function createGlobalSettingsFile(stateDir: string, llm?: OnboardLlmChoice): string {\n const settingsPath = join(stateDir, \"settings.json\");\n if (existsSync(settingsPath)) {\n throw new Error(`Global settings already exists at ${settingsPath}`);\n }\n ensureDirExists(stateDir);\n const settings: SettingsFileConfig = llm\n ? {\n ...ONBOARD_SETTINGS,\n llm: {\n ...ONBOARD_SETTINGS.llm,\n provider: llm.provider,\n model: llm.model,\n },\n }\n : ONBOARD_SETTINGS;\n atomicWritePrivateFile(settingsPath, JSON.stringify(settings, null, 2));\n return settingsPath;\n}\n\nexport function hasDefinedValue(values: Record<string, unknown> | undefined): boolean {\n return values !== undefined && Object.values(values).some((value) => value !== undefined);\n}\n\nexport function compactSettingsConfig(config: SettingsFileConfig): SettingsFileConfig {\n return {\n ...(hasDefinedValue(config.llm) ? { llm: config.llm } : {}),\n ...(hasDefinedValue(config.sentry) ? { sentry: config.sentry } : {}),\n ...(hasDefinedValue(config.sandbox) ? { sandbox: config.sandbox } : {}),\n ...(hasDefinedValue(config.slack) ? { slack: config.slack } : {}),\n ...(hasDefinedValue(config.office) ? { office: config.office } : {}),\n // An empty map means \"all servers removed\".\n ...(config.mcpServers !== undefined ? { mcpServers: config.mcpServers } : {}),\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 sentry: {\n ...existing.sentry,\n ...(config.sentryDsn !== undefined ? { dsn: config.sentryDsn } : {}),\n },\n // Leaf-level merge: a patch that only sets sandbox.boost.memory keeps the\n // existing boost.cpus (and every other existing leaf). compactSettingsConfig\n // drops the group entirely when it ends up with no defined values.\n sandbox: mergeSandboxSettings(existing.sandbox, config.sandbox) ?? {},\n slack: {\n ...existing.slack,\n ...config.slack,\n },\n // Office visibility has its own writer (setOfficeVisibilityOverride); the\n // generic patch must not drop it.\n ...(existing.office !== undefined ? { office: existing.office } : {}),\n // The portal edits the full MCP map, and\n // a merge would make removing a server impossible.\n ...(config.mcpServers !== undefined ? { mcpServers: config.mcpServers } : {}),\n };\n return compactSettingsConfig(patched);\n}\n\nfunction loadSettingsFileForUpdate(\n settingsPath: string,\n defaultSettings: SettingsFileConfig,\n): SettingsFileConfig {\n if (!existsSync(settingsPath)) return defaultSettings;\n try {\n return 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\nfunction updateSettingsFile(\n settingsPath: string,\n patch: Partial<AgentConfig>,\n defaultSettings: SettingsFileConfig,\n): void {\n const existing = loadSettingsFileForUpdate(settingsPath, defaultSettings);\n ensureDirExists(dirname(settingsPath));\n atomicWritePrivateFile(\n settingsPath,\n JSON.stringify(patchSettingsConfig(existing, patch), null, 2),\n );\n}\n\nexport function updateGlobalSettings(patch: Partial<AgentConfig>): void {\n updateSettingsFile(getSettingsPath(), patch, ONBOARD_SETTINGS);\n}\n\nexport function updateConversationSettings(office: Office, patch: Partial<AgentConfig>): void {\n updateSettingsFile(conversationSettingsPath(office), patch, {});\n}\n\n/**\n * The two scope-level MCP server maps, unmerged: the portal edits each scope's\n * own file, so it needs the raw per-scope values, not the effective merge\n * (`resolveConversationSettings` owns that).\n */\nexport function loadScopeMcpServers(office: Office): {\n global: Record<string, McpServerConfig>;\n conversation: Record<string, McpServerConfig>;\n} {\n return {\n global: loadRawGlobalSettings().mcpServers ?? {},\n conversation: loadSettingsFile(conversationSettingsPath(office))?.mcpServers ?? {},\n };\n}\n\n/**\n * The conversation's own visibility override, or null when it follows the\n * platform. Only \"private\" can be stored: an operator may narrow a public\n * channel, never widen a private one (see ADR 0008).\n */\nexport function loadOfficeVisibilityOverride(office: Office): \"private\" | null {\n return loadSettingsFile(conversationSettingsPath(office))?.office?.visibility ?? null;\n}\n\nexport function setOfficeVisibilityOverride(office: Office, visibility: \"private\" | null): void {\n const settingsPath = conversationSettingsPath(office);\n const existing = loadSettingsFileForUpdate(settingsPath, {});\n const { office: _previous, ...rest } = existing;\n ensureDirExists(dirname(settingsPath));\n atomicWritePrivateFile(\n settingsPath,\n JSON.stringify(\n compactSettingsConfig({ ...rest, ...(visibility ? { office: { visibility } } : {}) }),\n null,\n 2,\n ),\n );\n}\n"]}
|