@geminixiang/mikan 1.0.0-beta.4 → 1.0.0-beta.41
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 +714 -0
- package/README.md +99 -36
- package/dist/adapter.d.ts +11 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +18 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +6 -7
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +88 -122
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/components.d.ts +33 -0
- package/dist/adapters/discord/components.d.ts.map +1 -0
- package/dist/adapters/discord/components.js +32 -0
- package/dist/adapters/discord/components.js.map +1 -0
- package/dist/adapters/discord/context.d.ts +3 -1
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +66 -217
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/discord/format.d.ts +3 -0
- package/dist/adapters/discord/format.d.ts.map +1 -0
- package/dist/adapters/discord/format.js +86 -0
- package/dist/adapters/discord/format.js.map +1 -0
- package/dist/adapters/github/bot.d.ts +89 -0
- package/dist/adapters/github/bot.d.ts.map +1 -0
- package/dist/adapters/github/bot.js +653 -0
- package/dist/adapters/github/bot.js.map +1 -0
- package/dist/adapters/github/client.d.ts +122 -0
- package/dist/adapters/github/client.d.ts.map +1 -0
- package/dist/adapters/github/client.js +314 -0
- package/dist/adapters/github/client.js.map +1 -0
- package/dist/adapters/github/cloudbuild.d.ts +19 -0
- package/dist/adapters/github/cloudbuild.d.ts.map +1 -0
- package/dist/adapters/github/cloudbuild.js +71 -0
- package/dist/adapters/github/cloudbuild.js.map +1 -0
- package/dist/adapters/github/context.d.ts +12 -0
- package/dist/adapters/github/context.d.ts.map +1 -0
- package/dist/adapters/github/context.js +101 -0
- package/dist/adapters/github/context.js.map +1 -0
- package/dist/adapters/github/gcp-auth.d.ts +28 -0
- package/dist/adapters/github/gcp-auth.d.ts.map +1 -0
- package/dist/adapters/github/gcp-auth.js +196 -0
- package/dist/adapters/github/gcp-auth.js.map +1 -0
- package/dist/adapters/github/github-ops.d.ts +91 -0
- package/dist/adapters/github/github-ops.d.ts.map +1 -0
- package/dist/adapters/github/github-ops.js +406 -0
- package/dist/adapters/github/github-ops.js.map +1 -0
- package/dist/adapters/github/ids.d.ts +34 -0
- package/dist/adapters/github/ids.d.ts.map +1 -0
- package/dist/adapters/github/ids.js +57 -0
- package/dist/adapters/github/ids.js.map +1 -0
- package/dist/adapters/github/repo.d.ts +33 -0
- package/dist/adapters/github/repo.d.ts.map +1 -0
- package/dist/adapters/github/repo.js +141 -0
- package/dist/adapters/github/repo.js.map +1 -0
- package/dist/adapters/github/tool-pack.d.ts +14 -0
- package/dist/adapters/github/tool-pack.d.ts.map +1 -0
- package/dist/adapters/github/tool-pack.js +56 -0
- package/dist/adapters/github/tool-pack.js.map +1 -0
- package/dist/adapters/github/tools/checks.d.ts +19 -0
- package/dist/adapters/github/tools/checks.d.ts.map +1 -0
- package/dist/adapters/github/tools/checks.js +105 -0
- package/dist/adapters/github/tools/checks.js.map +1 -0
- package/dist/adapters/github/tools/issue.d.ts +21 -0
- package/dist/adapters/github/tools/issue.d.ts.map +1 -0
- package/dist/adapters/github/tools/issue.js +48 -0
- package/dist/adapters/github/tools/issue.js.map +1 -0
- package/dist/adapters/github/tools/pr.d.ts +22 -0
- package/dist/adapters/github/tools/pr.d.ts.map +1 -0
- package/dist/adapters/github/tools/pr.js +48 -0
- package/dist/adapters/github/tools/pr.js.map +1 -0
- package/dist/adapters/github/tools/read.d.ts +21 -0
- package/dist/adapters/github/tools/read.d.ts.map +1 -0
- package/dist/adapters/github/tools/read.js +141 -0
- package/dist/adapters/github/tools/read.js.map +1 -0
- package/dist/adapters/github/tools/review-reply.d.ts +17 -0
- package/dist/adapters/github/tools/review-reply.d.ts.map +1 -0
- package/dist/adapters/github/tools/review-reply.js +38 -0
- package/dist/adapters/github/tools/review-reply.js.map +1 -0
- package/dist/adapters/github/tools/sync.d.ts +17 -0
- package/dist/adapters/github/tools/sync.d.ts.map +1 -0
- package/dist/adapters/github/tools/sync.js +34 -0
- package/dist/adapters/github/tools/sync.js.map +1 -0
- package/dist/adapters/github/types.d.ts +373 -0
- package/dist/adapters/github/types.d.ts.map +1 -0
- package/dist/adapters/github/types.js +2 -0
- package/dist/adapters/github/types.js.map +1 -0
- package/dist/adapters/intake.d.ts +16 -5
- package/dist/adapters/intake.d.ts.map +1 -1
- package/dist/adapters/intake.js +86 -23
- package/dist/adapters/intake.js.map +1 -1
- package/dist/adapters/markdown-tables.d.ts +37 -0
- package/dist/adapters/markdown-tables.d.ts.map +1 -0
- package/dist/adapters/markdown-tables.js +164 -0
- package/dist/adapters/markdown-tables.js.map +1 -0
- package/dist/adapters/progressive-renderer.d.ts +7 -0
- package/dist/adapters/progressive-renderer.d.ts.map +1 -0
- package/dist/adapters/progressive-renderer.js +440 -0
- package/dist/adapters/progressive-renderer.js.map +1 -0
- package/dist/adapters/shared.d.ts +23 -10
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +60 -22
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/slack/assistant.d.ts +101 -0
- package/dist/adapters/slack/assistant.d.ts.map +1 -0
- package/dist/adapters/slack/assistant.js +204 -0
- package/dist/adapters/slack/assistant.js.map +1 -0
- package/dist/adapters/slack/blocks.d.ts +14 -0
- package/dist/adapters/slack/blocks.d.ts.map +1 -1
- package/dist/adapters/slack/blocks.js +105 -147
- package/dist/adapters/slack/blocks.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +95 -13
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +545 -211
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/context.d.ts +3 -1
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +11 -17
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +197 -323
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/session.d.ts.map +1 -1
- package/dist/adapters/slack/session.js +7 -11
- package/dist/adapters/slack/session.js.map +1 -1
- package/dist/adapters/slack/stream-limits.d.ts +35 -0
- package/dist/adapters/slack/stream-limits.d.ts.map +1 -0
- package/dist/adapters/slack/stream-limits.js +56 -0
- package/dist/adapters/slack/stream-limits.js.map +1 -0
- package/dist/adapters/slack/tool-pack.d.ts +11 -0
- package/dist/adapters/slack/tool-pack.d.ts.map +1 -0
- package/dist/adapters/slack/tool-pack.js +45 -0
- package/dist/adapters/slack/tool-pack.js.map +1 -0
- package/dist/adapters/slack/tools/attach.js +1 -1
- package/dist/adapters/slack/tools/attach.js.map +1 -1
- package/dist/adapters/slack/tools/blockkit.d.ts +14 -0
- package/dist/adapters/slack/tools/blockkit.d.ts.map +1 -0
- package/dist/adapters/slack/tools/blockkit.js +106 -0
- package/dist/adapters/slack/tools/blockkit.js.map +1 -0
- package/dist/adapters/slack/types.d.ts +40 -2
- 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 +8 -9
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +115 -163
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts +2 -0
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +53 -188
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/types.d.ts +132 -12
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/agent-events.d.ts +3 -2
- package/dist/agent-events.d.ts.map +1 -1
- package/dist/agent-events.js +19 -1
- package/dist/agent-events.js.map +1 -1
- package/dist/agent.d.ts +14 -19
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +841 -298
- package/dist/agent.js.map +1 -1
- package/dist/cli/arg-grammar.d.ts +25 -0
- package/dist/cli/arg-grammar.d.ts.map +1 -0
- package/dist/cli/arg-grammar.js +61 -0
- package/dist/cli/arg-grammar.js.map +1 -0
- package/dist/cli/boot.d.ts +5 -0
- package/dist/cli/boot.d.ts.map +1 -0
- package/dist/cli/boot.js +117 -0
- package/dist/cli/boot.js.map +1 -0
- package/dist/cli/download.d.ts.map +1 -0
- package/dist/{download.js → cli/download.js} +2 -0
- package/dist/cli/download.js.map +1 -0
- package/dist/cli/ext-dev.d.ts +2 -0
- package/dist/cli/ext-dev.d.ts.map +1 -0
- package/dist/cli/ext-dev.js +188 -0
- package/dist/cli/ext-dev.js.map +1 -0
- package/dist/cli/ext.d.ts +2 -0
- package/dist/cli/ext.d.ts.map +1 -0
- package/dist/cli/ext.js +324 -0
- package/dist/cli/ext.js.map +1 -0
- package/dist/cli/office.d.ts +2 -0
- package/dist/cli/office.d.ts.map +1 -0
- package/dist/cli/office.js +91 -0
- package/dist/cli/office.js.map +1 -0
- package/dist/cli/types.d.ts +16 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +3 -2
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/auto-reply.d.ts.map +1 -1
- package/dist/commands/auto-reply.js +5 -9
- package/dist/commands/auto-reply.js.map +1 -1
- package/dist/commands/extensions.d.ts +18 -6
- package/dist/commands/extensions.d.ts.map +1 -1
- package/dist/commands/extensions.js +64 -14
- package/dist/commands/extensions.js.map +1 -1
- package/dist/commands/login.d.ts +2 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +40 -5
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/manifest.d.ts +37 -0
- package/dist/commands/manifest.d.ts.map +1 -0
- package/dist/commands/manifest.js +151 -0
- package/dist/commands/manifest.js.map +1 -0
- package/dist/commands/model.d.ts +2 -3
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +63 -24
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +15 -3
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/registry.d.ts +2 -2
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +1 -2
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +83 -33
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/session-view.d.ts.map +1 -1
- package/dist/commands/session-view.js +6 -3
- package/dist/commands/session-view.js.map +1 -1
- package/dist/commands/types.d.ts +79 -7
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/config.d.ts +23 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +222 -135
- package/dist/config.js.map +1 -1
- package/dist/env-manifest.d.ts +30 -0
- package/dist/env-manifest.d.ts.map +1 -0
- package/dist/env-manifest.js +233 -0
- package/dist/env-manifest.js.map +1 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +20 -81
- package/dist/events.js.map +1 -1
- package/dist/execution-resolver.d.ts +7 -8
- package/dist/execution-resolver.d.ts.map +1 -1
- package/dist/execution-resolver.js +106 -110
- package/dist/execution-resolver.js.map +1 -1
- package/dist/extension-schedules.d.ts +31 -0
- package/dist/extension-schedules.d.ts.map +1 -0
- package/dist/extension-schedules.js +229 -0
- package/dist/extension-schedules.js.map +1 -0
- package/dist/harness/auth.d.ts +2 -1
- package/dist/harness/auth.d.ts.map +1 -1
- package/dist/harness/auth.js +11 -5
- package/dist/harness/auth.js.map +1 -1
- package/dist/harness/event-format.d.ts +27 -0
- package/dist/harness/event-format.d.ts.map +1 -0
- package/dist/harness/event-format.js +160 -0
- package/dist/harness/event-format.js.map +1 -0
- package/dist/harness/extensions/loader.d.ts +27 -49
- package/dist/harness/extensions/loader.d.ts.map +1 -1
- package/dist/harness/extensions/loader.js +486 -130
- package/dist/harness/extensions/loader.js.map +1 -1
- package/dist/harness/extensions/registry.d.ts +107 -2
- package/dist/harness/extensions/registry.d.ts.map +1 -1
- package/dist/harness/extensions/registry.js +316 -0
- package/dist/harness/extensions/registry.js.map +1 -1
- package/dist/harness/extensions/types.d.ts +482 -42
- package/dist/harness/extensions/types.d.ts.map +1 -1
- package/dist/harness/extensions/types.js.map +1 -1
- package/dist/harness/index.d.ts +18 -8
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +7 -4
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/models.d.ts +7 -4
- package/dist/harness/models.d.ts.map +1 -1
- package/dist/harness/models.js +46 -24
- package/dist/harness/models.js.map +1 -1
- package/dist/harness/runner.d.ts +50 -54
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +232 -46
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session-store.d.ts +11 -5
- package/dist/harness/session-store.d.ts.map +1 -1
- package/dist/harness/session-store.js +141 -36
- package/dist/harness/session-store.js.map +1 -1
- package/dist/harness/settings.d.ts +2 -20
- package/dist/harness/settings.d.ts.map +1 -1
- package/dist/harness/settings.js +12 -1
- package/dist/harness/settings.js.map +1 -1
- package/dist/harness/skills.d.ts +10 -29
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +48 -6
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/subagent-profiles.d.ts +8 -0
- package/dist/harness/subagent-profiles.d.ts.map +1 -0
- package/dist/harness/subagent-profiles.js +299 -0
- package/dist/harness/subagent-profiles.js.map +1 -0
- package/dist/harness/subagent-runner.d.ts +45 -0
- package/dist/harness/subagent-runner.d.ts.map +1 -0
- package/dist/harness/subagent-runner.js +680 -0
- package/dist/harness/subagent-runner.js.map +1 -0
- package/dist/harness/types.d.ts +267 -1
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/usage.d.ts +6 -0
- package/dist/harness/usage.d.ts.map +1 -0
- package/dist/harness/usage.js +32 -0
- package/dist/harness/usage.js.map +1 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/main.js +391 -127
- package/dist/main.js.map +1 -1
- package/dist/observability/instrument.js +7 -5
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/sentry.d.ts +2 -0
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +10 -2
- package/dist/observability/sentry.js.map +1 -1
- package/dist/office/address.d.ts +31 -0
- package/dist/office/address.d.ts.map +1 -0
- package/dist/office/address.js +113 -0
- package/dist/office/address.js.map +1 -0
- package/dist/office/index.d.ts +11 -0
- package/dist/office/index.d.ts.map +1 -0
- package/dist/office/index.js +11 -0
- package/dist/office/index.js.map +1 -0
- package/dist/office/layout.d.ts +27 -0
- package/dist/office/layout.d.ts.map +1 -0
- package/dist/office/layout.js +97 -0
- package/dist/office/layout.js.map +1 -0
- package/dist/office/migration.d.ts +44 -0
- package/dist/office/migration.d.ts.map +1 -0
- package/dist/office/migration.js +255 -0
- package/dist/office/migration.js.map +1 -0
- package/dist/office/registry.d.ts +75 -0
- package/dist/office/registry.d.ts.map +1 -0
- package/dist/office/registry.js +646 -0
- package/dist/office/registry.js.map +1 -0
- package/dist/office/types.d.ts +71 -0
- package/dist/office/types.d.ts.map +1 -0
- package/dist/office/types.js +2 -0
- package/dist/office/types.js.map +1 -0
- package/dist/packages/admin.d.ts +17 -0
- package/dist/packages/admin.d.ts.map +1 -0
- package/dist/packages/admin.js +98 -0
- package/dist/packages/admin.js.map +1 -0
- package/dist/packages/index.d.ts +6 -0
- package/dist/packages/index.d.ts.map +1 -0
- package/dist/packages/index.js +6 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/inspect.d.ts +11 -0
- package/dist/packages/inspect.d.ts.map +1 -0
- package/dist/packages/inspect.js +98 -0
- package/dist/packages/inspect.js.map +1 -0
- package/dist/packages/materialize.d.ts +40 -0
- package/dist/packages/materialize.d.ts.map +1 -0
- package/dist/packages/materialize.js +297 -0
- package/dist/packages/materialize.js.map +1 -0
- package/dist/packages/resolve.d.ts +25 -0
- package/dist/packages/resolve.d.ts.map +1 -0
- package/dist/packages/resolve.js +208 -0
- package/dist/packages/resolve.js.map +1 -0
- package/dist/packages/source.d.ts +39 -0
- package/dist/packages/source.d.ts.map +1 -0
- package/dist/packages/source.js +189 -0
- package/dist/packages/source.js.map +1 -0
- package/dist/packages/types.d.ts +104 -0
- package/dist/packages/types.d.ts.map +1 -0
- package/dist/packages/types.js +2 -0
- package/dist/packages/types.js.map +1 -0
- package/dist/provisioner.d.ts +66 -0
- package/dist/provisioner.d.ts.map +1 -1
- package/dist/provisioner.js +335 -13
- package/dist/provisioner.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +562 -118
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts +38 -0
- package/dist/runtime/session-lifecycle.d.ts.map +1 -0
- package/dist/runtime/session-lifecycle.js +193 -0
- package/dist/runtime/session-lifecycle.js.map +1 -0
- package/dist/runtime/types.d.ts +66 -7
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sandbox/cloudflare.d.ts +3 -0
- package/dist/sandbox/cloudflare.d.ts.map +1 -1
- package/dist/sandbox/cloudflare.js +13 -1
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts +4 -0
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +13 -3
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/firecracker.d.ts +3 -0
- package/dist/sandbox/firecracker.d.ts.map +1 -1
- package/dist/sandbox/firecracker.js +13 -2
- package/dist/sandbox/firecracker.js.map +1 -1
- package/dist/sandbox/gondolin.d.ts +57 -0
- package/dist/sandbox/gondolin.d.ts.map +1 -0
- package/dist/sandbox/gondolin.js +764 -0
- package/dist/sandbox/gondolin.js.map +1 -0
- package/dist/sandbox/host.d.ts +3 -0
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +18 -3
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/identity.d.ts +44 -0
- package/dist/sandbox/identity.d.ts.map +1 -0
- package/dist/sandbox/identity.js +68 -0
- package/dist/sandbox/identity.js.map +1 -0
- package/dist/sandbox/image.d.ts.map +1 -1
- package/dist/sandbox/image.js +2 -0
- package/dist/sandbox/image.js.map +1 -1
- package/dist/sandbox/index.d.ts +17 -4
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +37 -3
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/types.d.ts +65 -1
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +14 -0
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +68 -1
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts +25 -0
- package/dist/sessions/chat-history-sync.d.ts.map +1 -0
- package/dist/sessions/{agent-memory-file-manager.js → chat-history-sync.js} +135 -131
- package/dist/sessions/chat-history-sync.js.map +1 -0
- package/dist/sessions/conversation-log.d.ts +9 -0
- package/dist/sessions/conversation-log.d.ts.map +1 -0
- package/dist/sessions/conversation-log.js +50 -0
- package/dist/sessions/conversation-log.js.map +1 -0
- package/dist/sessions/history-line.d.ts +29 -0
- package/dist/sessions/history-line.d.ts.map +1 -0
- package/dist/sessions/history-line.js +45 -0
- package/dist/sessions/history-line.js.map +1 -0
- package/dist/sessions/rotation.d.ts +2 -0
- package/dist/sessions/rotation.d.ts.map +1 -0
- package/dist/sessions/rotation.js +39 -0
- package/dist/sessions/rotation.js.map +1 -0
- package/dist/sessions/session-key.d.ts +33 -0
- package/dist/sessions/session-key.d.ts.map +1 -0
- package/dist/sessions/session-key.js +115 -0
- package/dist/sessions/session-key.js.map +1 -0
- package/dist/sessions/store.d.ts +15 -7
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +127 -36
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +19 -5
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/settings-mutation.d.ts +40 -0
- package/dist/settings-mutation.d.ts.map +1 -0
- package/dist/settings-mutation.js +61 -0
- package/dist/settings-mutation.js.map +1 -0
- package/dist/subagent-progress.d.ts +39 -0
- package/dist/subagent-progress.d.ts.map +1 -0
- package/dist/subagent-progress.js +225 -0
- package/dist/subagent-progress.js.map +1 -0
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +26 -18
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +14 -13
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/event.d.ts +1 -1
- package/dist/tools/event.d.ts.map +1 -1
- package/dist/tools/event.js +58 -45
- package/dist/tools/event.js.map +1 -1
- package/dist/tools/generate-image.d.ts +23 -0
- package/dist/tools/generate-image.d.ts.map +1 -0
- package/dist/tools/generate-image.js +65 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/host-fn-tool.d.ts +21 -0
- package/dist/tools/host-fn-tool.d.ts.map +1 -0
- package/dist/tools/host-fn-tool.js +32 -0
- package/dist/tools/host-fn-tool.js.map +1 -0
- package/dist/tools/index.d.ts +19 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +25 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/react.d.ts +15 -0
- package/dist/tools/react.d.ts.map +1 -0
- package/dist/tools/react.js +29 -0
- package/dist/tools/react.js.map +1 -0
- package/dist/tools/read.d.ts +1 -0
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +39 -33
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/sandbox.d.ts +2 -2
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +14 -9
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/subagent-slots.d.ts +28 -0
- package/dist/tools/subagent-slots.d.ts.map +1 -0
- package/dist/tools/subagent-slots.js +72 -0
- package/dist/tools/subagent-slots.js.map +1 -0
- package/dist/tools/subagent.d.ts +61 -0
- package/dist/tools/subagent.d.ts.map +1 -0
- package/dist/tools/subagent.js +434 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/types.d.ts +40 -32
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +2 -8
- package/dist/tools/write.js.map +1 -1
- package/dist/trigger.d.ts +2 -1
- package/dist/trigger.d.ts.map +1 -1
- package/dist/trigger.js +6 -9
- package/dist/trigger.js.map +1 -1
- package/dist/types.d.ts +411 -59
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/utils/file-guards.d.ts +9 -0
- package/dist/utils/file-guards.d.ts.map +1 -1
- package/dist/utils/file-guards.js +44 -1
- package/dist/utils/file-guards.js.map +1 -1
- package/dist/vault/disabled.d.ts +9 -0
- package/dist/vault/disabled.d.ts.map +1 -0
- package/dist/vault/disabled.js +25 -0
- package/dist/vault/disabled.js.map +1 -0
- package/dist/vault/index.d.ts +45 -2
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +127 -36
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/types.d.ts +6 -2
- package/dist/vault/types.d.ts.map +1 -1
- package/dist/vault/types.js.map +1 -1
- package/dist/web/admin/portal.d.ts +31 -3
- package/dist/web/admin/portal.d.ts.map +1 -1
- package/dist/web/admin/portal.js +850 -345
- package/dist/web/admin/portal.js.map +1 -1
- package/dist/web/admin/provider-models.js +1 -1
- package/dist/web/admin/provider-models.js.map +1 -1
- package/dist/web/admin/types.d.ts +23 -3
- package/dist/web/admin/types.d.ts.map +1 -1
- package/dist/web/admin/types.js.map +1 -1
- package/dist/web/login/oauth.d.ts +2 -3
- package/dist/web/login/oauth.d.ts.map +1 -1
- package/dist/web/login/oauth.js +1 -32
- package/dist/web/login/oauth.js.map +1 -1
- package/dist/web/login/portal.d.ts +1 -1
- package/dist/web/login/portal.d.ts.map +1 -1
- package/dist/web/login/portal.js +13 -36
- package/dist/web/login/portal.js.map +1 -1
- package/dist/web/login/types.d.ts +0 -11
- package/dist/web/login/types.d.ts.map +1 -1
- package/dist/web/login/types.js.map +1 -1
- package/dist/web/portal-shell.d.ts +21 -0
- package/dist/web/portal-shell.d.ts.map +1 -0
- package/dist/{portal-shell.js → web/portal-shell.js} +67 -2
- package/dist/web/portal-shell.js.map +1 -0
- package/dist/web/server.d.ts +3 -2
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +11 -4
- package/dist/web/server.js.map +1 -1
- package/dist/web/session-view/portal.d.ts +1 -1
- package/dist/web/session-view/portal.d.ts.map +1 -1
- package/dist/web/session-view/portal.js +37 -28
- package/dist/web/session-view/portal.js.map +1 -1
- package/dist/web/session-view/service.d.ts +1 -1
- package/dist/web/session-view/service.d.ts.map +1 -1
- package/dist/web/session-view/service.js +61 -18
- package/dist/web/session-view/service.js.map +1 -1
- package/dist/web/session-view/types.d.ts +0 -3
- package/dist/web/session-view/types.d.ts.map +1 -1
- package/dist/web/session-view/types.js.map +1 -1
- package/dist/web/token-store.js +1 -1
- package/dist/web/token-store.js.map +1 -1
- package/dist/workspace-projection/index.d.ts +10 -0
- package/dist/workspace-projection/index.d.ts.map +1 -0
- package/dist/workspace-projection/index.js +120 -0
- package/dist/workspace-projection/index.js.map +1 -0
- package/dist/workspace-projection/types.d.ts +16 -0
- package/dist/workspace-projection/types.d.ts.map +1 -0
- package/dist/workspace-projection/types.js +2 -0
- package/dist/workspace-projection/types.js.map +1 -0
- package/package.json +68 -37
- package/dist/adapters/streaming.d.ts +0 -18
- package/dist/adapters/streaming.d.ts.map +0 -1
- package/dist/adapters/streaming.js +0 -44
- package/dist/adapters/streaming.js.map +0 -1
- package/dist/adapters/telegram/html.d.ts +0 -3
- package/dist/adapters/telegram/html.d.ts.map +0 -1
- package/dist/adapters/telegram/html.js +0 -98
- package/dist/adapters/telegram/html.js.map +0 -1
- package/dist/commands/parse.d.ts +0 -7
- package/dist/commands/parse.d.ts.map +0 -1
- package/dist/commands/parse.js +0 -14
- package/dist/commands/parse.js.map +0 -1
- package/dist/download.d.ts.map +0 -1
- package/dist/download.js.map +0 -1
- package/dist/model-registry.d.ts +0 -4
- package/dist/model-registry.d.ts.map +0 -1
- package/dist/model-registry.js +0 -7
- package/dist/model-registry.js.map +0 -1
- package/dist/portal-shell.d.ts +0 -4
- package/dist/portal-shell.d.ts.map +0 -1
- package/dist/portal-shell.js.map +0 -1
- package/dist/runtime/agent-run-controller.d.ts +0 -31
- package/dist/runtime/agent-run-controller.d.ts.map +0 -1
- package/dist/runtime/agent-run-controller.js +0 -195
- package/dist/runtime/agent-run-controller.js.map +0 -1
- package/dist/sandbox/path-context.d.ts +0 -3
- package/dist/sandbox/path-context.d.ts.map +0 -1
- package/dist/sandbox/path-context.js +0 -20
- package/dist/sandbox/path-context.js.map +0 -1
- package/dist/sessions/agent-memory-file-manager.d.ts +0 -19
- package/dist/sessions/agent-memory-file-manager.d.ts.map +0 -1
- package/dist/sessions/agent-memory-file-manager.js.map +0 -1
- package/dist/sessions/metadata.d.ts +0 -3
- package/dist/sessions/metadata.d.ts.map +0 -1
- package/dist/sessions/metadata.js +0 -11
- package/dist/sessions/metadata.js.map +0 -1
- package/dist/sessions/policy.d.ts +0 -6
- package/dist/sessions/policy.d.ts.map +0 -1
- package/dist/sessions/policy.js +0 -23
- package/dist/sessions/policy.js.map +0 -1
- package/dist/store.d.ts +0 -46
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -177
- package/dist/store.js.map +0 -1
- package/dist/tools/truncate.d.ts +0 -33
- package/dist/tools/truncate.d.ts.map +0 -1
- package/dist/tools/truncate.js +0 -184
- package/dist/tools/truncate.js.map +0 -1
- package/dist/utils/date.d.ts +0 -10
- package/dist/utils/date.d.ts.map +0 -1
- package/dist/utils/date.js +0 -23
- package/dist/utils/date.js.map +0 -1
- package/dist/utils/env.d.ts +0 -3
- package/dist/utils/env.d.ts.map +0 -1
- package/dist/utils/env.js +0 -12
- package/dist/utils/env.js.map +0 -1
- package/dist/utils/fs-atomic.d.ts +0 -10
- package/dist/utils/fs-atomic.d.ts.map +0 -1
- package/dist/utils/fs-atomic.js +0 -45
- package/dist/utils/fs-atomic.js.map +0 -1
- package/dist/utils/html.d.ts +0 -2
- package/dist/utils/html.d.ts.map +0 -1
- package/dist/utils/html.js +0 -4
- package/dist/utils/html.js.map +0 -1
- package/dist/utils/http-body.d.ts +0 -10
- package/dist/utils/http-body.d.ts.map +0 -1
- package/dist/utils/http-body.js +0 -34
- package/dist/utils/http-body.js.map +0 -1
- package/dist/vault/routing.d.ts +0 -3
- package/dist/vault/routing.d.ts.map +0 -1
- package/dist/vault/routing.js +0 -13
- package/dist/vault/routing.js.map +0 -1
- package/dist/web/agent-events/portal.d.ts +0 -3
- package/dist/web/agent-events/portal.d.ts.map +0 -1
- package/dist/web/agent-events/portal.js +0 -18
- package/dist/web/agent-events/portal.js.map +0 -1
- package/dist/web/request.d.ts +0 -3
- package/dist/web/request.d.ts.map +0 -1
- package/dist/web/request.js +0 -13
- package/dist/web/request.js.map +0 -1
- package/dist/web/session-view/command.d.ts +0 -4
- package/dist/web/session-view/command.d.ts.map +0 -1
- package/dist/web/session-view/command.js +0 -7
- package/dist/web/session-view/command.js.map +0 -1
- /package/dist/{download.d.ts → cli/download.d.ts} +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a parsed source into a directory on the host.
|
|
3
|
+
*
|
|
4
|
+
* Materialization is an explicit, reported step — it happens when a human adds
|
|
5
|
+
* or updates a package, not lazily while a conversation is waiting for a
|
|
6
|
+
* reply. Failures (bad URL, missing ref, no such subpath) therefore surface in
|
|
7
|
+
* front of the person who typed the source instead of as a silently absent
|
|
8
|
+
* feature in a chat.
|
|
9
|
+
*
|
|
10
|
+
* Everything lands under the host-only state dir, never the workspace: this
|
|
11
|
+
* code is imported into the mikan process, so a mounted location would let
|
|
12
|
+
* sandboxed code write what the host executes.
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { cpSync, existsSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
18
|
+
import { ensureDirExists, readTextFileIfExists } from "../utils/file-guards.js";
|
|
19
|
+
import * as log from "../log.js";
|
|
20
|
+
import { gitRepoPath, parseSource, sourceIdentity } from "./source.js";
|
|
21
|
+
import { officeStateDir } from "../office/index.js";
|
|
22
|
+
/** Git operations get a bounded wall clock so a hung remote cannot wedge a save. */
|
|
23
|
+
const GIT_TIMEOUT_MS = 120_000;
|
|
24
|
+
const NPM_TIMEOUT_MS = 300_000;
|
|
25
|
+
const MATERIALIZED_REF_FILE = "mikan-ref";
|
|
26
|
+
/**
|
|
27
|
+
* How far materialization may go to produce the package's files.
|
|
28
|
+
*
|
|
29
|
+
* - `offline`: use what is already on disk; never touch the network. This is
|
|
30
|
+
* what a conversation load uses, so no chat reply can ever wait on a remote.
|
|
31
|
+
* - `fetch`: clone a package that is not on disk yet, reuse an existing clone
|
|
32
|
+
* when it already has the requested ref, or switch it to a new ref. What the
|
|
33
|
+
* portal uses when a source is added.
|
|
34
|
+
* - `refresh`: additionally re-fetch an existing clone, resetting and cleaning
|
|
35
|
+
* it first. What the portal's Update action uses.
|
|
36
|
+
*
|
|
37
|
+
* One mode rather than two booleans: "re-fetch an existing clone but refuse to
|
|
38
|
+
* create a missing one" is not a state any caller wants, and expressing it
|
|
39
|
+
* should not be possible.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Root of a scope's host-only assets: `<stateDir>/global` or
|
|
43
|
+
* `<stateDir>/conversations/<id>`. The two are isomorphic by design — both
|
|
44
|
+
* hold `extensions/`, `extension-data/`, and now `git/`. See
|
|
45
|
+
* `src/harness/extensions/LAYOUT.md`.
|
|
46
|
+
*/
|
|
47
|
+
export function packageScopeDir(scope, address, stateDir) {
|
|
48
|
+
if (scope === "global")
|
|
49
|
+
return join(stateDir, "global");
|
|
50
|
+
if (!address)
|
|
51
|
+
throw new Error("A conversation-scoped package needs an office address");
|
|
52
|
+
return officeStateDir(stateDir, address);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where a git checkout lives.
|
|
56
|
+
*
|
|
57
|
+
* The unpinned checkout keeps the original path for compatibility. Explicit
|
|
58
|
+
* refs get a sibling keyed by the ref, so two refs can never reset each
|
|
59
|
+
* other's working tree; subpaths of one ref therefore still share a checkout.
|
|
60
|
+
*/
|
|
61
|
+
export function gitCloneDir(url, scopeDir, ref) {
|
|
62
|
+
const repoPath = gitRepoPath(url).split("/");
|
|
63
|
+
const repoName = repoPath[repoPath.length - 1] ?? "repo";
|
|
64
|
+
const parent = repoPath.slice(0, -1);
|
|
65
|
+
const checkoutName = ref === undefined || ref === "HEAD"
|
|
66
|
+
? repoName
|
|
67
|
+
: `${repoName}.mikan-${createHash("sha256").update(ref).digest("hex")}`;
|
|
68
|
+
return join(scopeDir, "git", ...parent, checkoutName);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Materialize one source and return where its files ended up. Throws with a
|
|
72
|
+
* message meant to be shown to a human — callers render it next to the input
|
|
73
|
+
* that produced it.
|
|
74
|
+
*/
|
|
75
|
+
export function materializeSource(source, options) {
|
|
76
|
+
const parsed = parseSource(source);
|
|
77
|
+
const scopeDir = packageScopeDir(options.scope, options.address, options.stateDir);
|
|
78
|
+
const dir = parsed.type === "local"
|
|
79
|
+
? materializeLocal(parsed)
|
|
80
|
+
: materializeGit(parsed, scopeDir, options.mode ?? "fetch");
|
|
81
|
+
return {
|
|
82
|
+
source,
|
|
83
|
+
parsed,
|
|
84
|
+
identity: sourceIdentity(parsed),
|
|
85
|
+
dir,
|
|
86
|
+
scope: options.scope,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function materializeLocal(parsed) {
|
|
90
|
+
if (!existsSync(parsed.path)) {
|
|
91
|
+
throw new Error(`Path does not exist on the mikan host: ${parsed.path}`);
|
|
92
|
+
}
|
|
93
|
+
if (!statSync(parsed.path).isDirectory()) {
|
|
94
|
+
throw new Error(`Package path must be a directory: ${parsed.path}`);
|
|
95
|
+
}
|
|
96
|
+
return parsed.path;
|
|
97
|
+
}
|
|
98
|
+
function materializeGit(parsed, scopeDir, mode) {
|
|
99
|
+
const requestedRef = parsed.ref ?? "HEAD";
|
|
100
|
+
const cloneDir = gitCloneDir(parsed.url, scopeDir, requestedRef);
|
|
101
|
+
migrateLegacyCheckout(parsed.url, scopeDir, cloneDir, requestedRef);
|
|
102
|
+
const alreadyCloned = existsSync(join(cloneDir, ".git"));
|
|
103
|
+
const markerPath = join(cloneDir, ".git", MATERIALIZED_REF_FILE);
|
|
104
|
+
const recordedRef = alreadyCloned ? readTextFileIfExists(markerPath)?.trim() : undefined;
|
|
105
|
+
const canReuse = alreadyCloned &&
|
|
106
|
+
mode !== "refresh" &&
|
|
107
|
+
(recordedRef === requestedRef ||
|
|
108
|
+
(mode === "offline" &&
|
|
109
|
+
recordedRef === undefined &&
|
|
110
|
+
markerlessCheckoutMatchesRef(cloneDir, requestedRef)));
|
|
111
|
+
if (canReuse) {
|
|
112
|
+
return resolveSubpath(cloneDir, parsed);
|
|
113
|
+
}
|
|
114
|
+
if (mode === "offline") {
|
|
115
|
+
throw new Error(`Not fetched on this host yet: ${describeRef(parsed)}`);
|
|
116
|
+
}
|
|
117
|
+
// An incomplete checkout must not retain a marker from an earlier attempt:
|
|
118
|
+
// otherwise a retry could mistake a failed dependency install for success.
|
|
119
|
+
if (alreadyCloned)
|
|
120
|
+
rmSync(markerPath, { force: true });
|
|
121
|
+
if (!alreadyCloned) {
|
|
122
|
+
// A leftover directory without .git means a previous attempt died partway.
|
|
123
|
+
if (existsSync(cloneDir))
|
|
124
|
+
rmSync(cloneDir, { recursive: true, force: true });
|
|
125
|
+
ensureDirExists(cloneDir);
|
|
126
|
+
git(cloneDir, ["init", "-q"]);
|
|
127
|
+
git(cloneDir, ["remote", "add", "origin", parsed.url]);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Reconcile: drop anything a previous checkout left behind so the new ref
|
|
131
|
+
// lands on a clean tree.
|
|
132
|
+
git(cloneDir, ["remote", "set-url", "origin", parsed.url]);
|
|
133
|
+
git(cloneDir, ["reset", "--hard", "-q"]);
|
|
134
|
+
git(cloneDir, ["clean", "-qfd"]);
|
|
135
|
+
}
|
|
136
|
+
// One fetch shape for every kind of ref — tag, branch, or commit sha — and
|
|
137
|
+
// `HEAD` for "whatever the remote's default branch is now".
|
|
138
|
+
try {
|
|
139
|
+
git(cloneDir, ["fetch", "--depth", "1", "origin", requestedRef]);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (!alreadyCloned)
|
|
143
|
+
rmSync(cloneDir, { recursive: true, force: true });
|
|
144
|
+
throw new Error(`Could not fetch ${describeRef(parsed)}: ${gitErrorText(err)}`, { cause: err });
|
|
145
|
+
}
|
|
146
|
+
git(cloneDir, ["checkout", "-q", "--detach", "FETCH_HEAD"]);
|
|
147
|
+
const dir = resolveSubpath(cloneDir, parsed);
|
|
148
|
+
installDependencies(dir);
|
|
149
|
+
// This is the completion marker, not merely a fetched-ref marker. Write it
|
|
150
|
+
// last so a failed npm install is retried by the next materialization.
|
|
151
|
+
writeFileSync(markerPath, `${requestedRef}\n`);
|
|
152
|
+
return dir;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Before keyed checkout paths existed, every ref used the legacy repo path.
|
|
156
|
+
* Copy a matching complete checkout on first use of its keyed path so offline
|
|
157
|
+
* loads keep working. Markerless legacy checkouts are accepted only when git
|
|
158
|
+
* can prove the requested ref is the checked-out commit; a different or
|
|
159
|
+
* unprovable pinned ref is rebuilt by fetch/refresh instead.
|
|
160
|
+
*/
|
|
161
|
+
function migrateLegacyCheckout(url, scopeDir, cloneDir, requestedRef) {
|
|
162
|
+
const legacyDir = gitCloneDir(url, scopeDir);
|
|
163
|
+
if (cloneDir === legacyDir || existsSync(cloneDir))
|
|
164
|
+
return;
|
|
165
|
+
const legacyMarker = join(legacyDir, ".git", MATERIALIZED_REF_FILE);
|
|
166
|
+
if (!existsSync(join(legacyDir, ".git")))
|
|
167
|
+
return;
|
|
168
|
+
const recordedRef = readTextFileIfExists(legacyMarker)?.trim();
|
|
169
|
+
if (recordedRef !== requestedRef) {
|
|
170
|
+
if (recordedRef !== undefined || !markerlessCheckoutMatchesRef(legacyDir, requestedRef)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
ensureDirExists(dirname(cloneDir));
|
|
175
|
+
cpSync(legacyDir, cloneDir, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Legacy checkouts have no completion marker. Accept them offline only when
|
|
179
|
+
* the checkout is clean and the local git metadata identifies the requested
|
|
180
|
+
* commit/ref; never infer a pinned ref from HEAD alone.
|
|
181
|
+
*/
|
|
182
|
+
function markerlessCheckoutMatchesRef(cloneDir, requestedRef) {
|
|
183
|
+
let head;
|
|
184
|
+
try {
|
|
185
|
+
head = git(cloneDir, ["rev-parse", "--verify", "HEAD"]).trim();
|
|
186
|
+
if (!head || git(cloneDir, ["status", "--porcelain", "--untracked-files=no"]).trim()) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (requestedRef === "HEAD")
|
|
194
|
+
return true;
|
|
195
|
+
try {
|
|
196
|
+
if (git(cloneDir, ["rev-parse", "--verify", `${requestedRef}^{commit}`]).trim() === head) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// A shallow legacy fetch may retain only FETCH_HEAD, not a local ref.
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
if (git(cloneDir, ["symbolic-ref", "--quiet", "--short", "HEAD"]).trim() === requestedRef) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
// Detached checkouts do not have a symbolic branch.
|
|
210
|
+
}
|
|
211
|
+
const fetchHead = readTextFileIfExists(join(cloneDir, ".git", "FETCH_HEAD"));
|
|
212
|
+
if (!fetchHead)
|
|
213
|
+
return false;
|
|
214
|
+
return fetchHead.split("\n").some((line) => {
|
|
215
|
+
const match = /^(\w+)\s+.*(?:branch|tag) '([^']+)'/.exec(line);
|
|
216
|
+
return match?.[1] === head && match[2] === requestedRef;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function resolveSubpath(cloneDir, parsed) {
|
|
220
|
+
if (!parsed.subpath)
|
|
221
|
+
return cloneDir;
|
|
222
|
+
const dir = join(cloneDir, parsed.subpath);
|
|
223
|
+
if (!existsSync(dir)) {
|
|
224
|
+
throw new Error(`Subpath not found in repository: ${parsed.subpath}`);
|
|
225
|
+
}
|
|
226
|
+
// A symlink inside the repository must not select files outside the clone:
|
|
227
|
+
// the returned directory is imported (extensions) or mounted, so follow
|
|
228
|
+
// links before deciding the subpath stayed inside.
|
|
229
|
+
const relation = relative(realpathSync(cloneDir), realpathSync(dir));
|
|
230
|
+
if (isAbsolute(relation) || relation === ".." || relation.startsWith(`..${sep}`)) {
|
|
231
|
+
throw new Error(`Subpath escapes repository: ${parsed.subpath}`);
|
|
232
|
+
}
|
|
233
|
+
return dir;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Install runtime dependencies when the package declares any. This runs npm
|
|
237
|
+
* on the host against code that was just fetched from a remote, which is the
|
|
238
|
+
* same trust level as importing the package itself — but it is worth being
|
|
239
|
+
* explicit that it happens, because it also runs the dependencies' install
|
|
240
|
+
* scripts.
|
|
241
|
+
*/
|
|
242
|
+
function installDependencies(dir) {
|
|
243
|
+
if (!hasDependencies(dir))
|
|
244
|
+
return;
|
|
245
|
+
log.logInfo(`Installing package dependencies in ${dir}`);
|
|
246
|
+
try {
|
|
247
|
+
execFileSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund"], {
|
|
248
|
+
cwd: dir,
|
|
249
|
+
timeout: NPM_TIMEOUT_MS,
|
|
250
|
+
encoding: "utf-8",
|
|
251
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
throw new Error(`npm install failed for the package: ${gitErrorText(err)}`, { cause: err });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function hasDependencies(dir) {
|
|
259
|
+
const raw = readTextFileIfExists(join(dir, "package.json"));
|
|
260
|
+
if (raw === undefined)
|
|
261
|
+
return false;
|
|
262
|
+
try {
|
|
263
|
+
const pkg = JSON.parse(raw);
|
|
264
|
+
return Boolean(pkg.dependencies && Object.keys(pkg.dependencies).length > 0);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function git(cwd, args) {
|
|
271
|
+
return execFileSync("git", args, {
|
|
272
|
+
cwd,
|
|
273
|
+
timeout: GIT_TIMEOUT_MS,
|
|
274
|
+
encoding: "utf-8",
|
|
275
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
276
|
+
env: {
|
|
277
|
+
...process.env,
|
|
278
|
+
// Never block a portal save on an interactive credential prompt.
|
|
279
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
280
|
+
GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND ?? "ssh -o BatchMode=yes -o ConnectTimeout=10",
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function describeRef(parsed) {
|
|
285
|
+
return parsed.ref ? `${parsed.url} at ${parsed.ref}` : parsed.url;
|
|
286
|
+
}
|
|
287
|
+
/** Prefer git's stderr over the generic "Command failed" wrapper. */
|
|
288
|
+
function gitErrorText(err) {
|
|
289
|
+
if (err && typeof err === "object" && "stderr" in err) {
|
|
290
|
+
const stderr = err.stderr;
|
|
291
|
+
const text = typeof stderr === "string" ? stderr.trim() : "";
|
|
292
|
+
if (text)
|
|
293
|
+
return text.split("\n").slice(-3).join(" ");
|
|
294
|
+
}
|
|
295
|
+
return err instanceof Error ? err.message : String(err);
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=materialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materialize.js","sourceRoot":"","sources":["../../src/packages/materialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;A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,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * Turning a parsed source into a directory on the host.\n *\n * Materialization is an explicit, reported step — it happens when a human adds\n * or updates a package, not lazily while a conversation is waiting for a\n * reply. Failures (bad URL, missing ref, no such subpath) therefore surface in\n * front of the person who typed the source instead of as a silently absent\n * feature in a chat.\n *\n * Everything lands under the host-only state dir, never the workspace: this\n * code is imported into the mikan process, so a mounted location would let\n * sandboxed code write what the host executes.\n */\nimport { execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { cpSync, existsSync, realpathSync, rmSync, statSync, writeFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, relative, sep } from \"node:path\";\nimport { ensureDirExists, readTextFileIfExists } from \"../utils/file-guards.js\";\nimport * as log from \"../log.js\";\nimport { gitRepoPath, parseSource, sourceIdentity } from \"./source.js\";\nimport { officeStateDir } from \"../office/index.js\";\nimport type { OfficeAddress } from \"../types.js\";\nimport type {\n MaterializeMode,\n MaterializeOptions,\n MaterializedPackage,\n PackageScope,\n PackageSourceString,\n ParsedSource,\n} from \"./types.js\";\n\nexport type { MaterializeOptions } from \"./types.js\";\n\n/** Git operations get a bounded wall clock so a hung remote cannot wedge a save. */\nconst GIT_TIMEOUT_MS = 120_000;\nconst NPM_TIMEOUT_MS = 300_000;\nconst MATERIALIZED_REF_FILE = \"mikan-ref\";\n\n/**\n * How far materialization may go to produce the package's files.\n *\n * - `offline`: use what is already on disk; never touch the network. This is\n * what a conversation load uses, so no chat reply can ever wait on a remote.\n * - `fetch`: clone a package that is not on disk yet, reuse an existing clone\n * when it already has the requested ref, or switch it to a new ref. What the\n * portal uses when a source is added.\n * - `refresh`: additionally re-fetch an existing clone, resetting and cleaning\n * it first. What the portal's Update action uses.\n *\n * One mode rather than two booleans: \"re-fetch an existing clone but refuse to\n * create a missing one\" is not a state any caller wants, and expressing it\n * should not be possible.\n */\n/**\n * Root of a scope's host-only assets: `<stateDir>/global` or\n * `<stateDir>/conversations/<id>`. The two are isomorphic by design — both\n * hold `extensions/`, `extension-data/`, and now `git/`. See\n * `src/harness/extensions/LAYOUT.md`.\n */\nexport function packageScopeDir(\n scope: PackageScope,\n address: OfficeAddress | undefined,\n stateDir: string,\n): string {\n if (scope === \"global\") return join(stateDir, \"global\");\n if (!address) throw new Error(\"A conversation-scoped package needs an office address\");\n return officeStateDir(stateDir, address);\n}\n\n/**\n * Where a git checkout lives.\n *\n * The unpinned checkout keeps the original path for compatibility. Explicit\n * refs get a sibling keyed by the ref, so two refs can never reset each\n * other's working tree; subpaths of one ref therefore still share a checkout.\n */\nexport function gitCloneDir(url: string, scopeDir: string, ref?: string): string {\n const repoPath = gitRepoPath(url).split(\"/\");\n const repoName = repoPath[repoPath.length - 1] ?? \"repo\";\n const parent = repoPath.slice(0, -1);\n const checkoutName =\n ref === undefined || ref === \"HEAD\"\n ? repoName\n : `${repoName}.mikan-${createHash(\"sha256\").update(ref).digest(\"hex\")}`;\n return join(scopeDir, \"git\", ...parent, checkoutName);\n}\n\n/**\n * Materialize one source and return where its files ended up. Throws with a\n * message meant to be shown to a human — callers render it next to the input\n * that produced it.\n */\nexport function materializeSource(\n source: PackageSourceString,\n options: MaterializeOptions,\n): MaterializedPackage {\n const parsed = parseSource(source);\n const scopeDir = packageScopeDir(options.scope, options.address, options.stateDir);\n const dir =\n parsed.type === \"local\"\n ? materializeLocal(parsed)\n : materializeGit(parsed, scopeDir, options.mode ?? \"fetch\");\n\n return {\n source,\n parsed,\n identity: sourceIdentity(parsed),\n dir,\n scope: options.scope,\n };\n}\n\nfunction materializeLocal(parsed: Extract<ParsedSource, { type: \"local\" }>): string {\n if (!existsSync(parsed.path)) {\n throw new Error(`Path does not exist on the mikan host: ${parsed.path}`);\n }\n if (!statSync(parsed.path).isDirectory()) {\n throw new Error(`Package path must be a directory: ${parsed.path}`);\n }\n return parsed.path;\n}\n\nfunction materializeGit(\n parsed: Extract<ParsedSource, { type: \"git\" }>,\n scopeDir: string,\n mode: MaterializeMode,\n): string {\n const requestedRef = parsed.ref ?? \"HEAD\";\n const cloneDir = gitCloneDir(parsed.url, scopeDir, requestedRef);\n migrateLegacyCheckout(parsed.url, scopeDir, cloneDir, requestedRef);\n const alreadyCloned = existsSync(join(cloneDir, \".git\"));\n const markerPath = join(cloneDir, \".git\", MATERIALIZED_REF_FILE);\n const recordedRef = alreadyCloned ? readTextFileIfExists(markerPath)?.trim() : undefined;\n const canReuse =\n alreadyCloned &&\n mode !== \"refresh\" &&\n (recordedRef === requestedRef ||\n (mode === \"offline\" &&\n recordedRef === undefined &&\n markerlessCheckoutMatchesRef(cloneDir, requestedRef)));\n\n if (canReuse) {\n return resolveSubpath(cloneDir, parsed);\n }\n if (mode === \"offline\") {\n throw new Error(`Not fetched on this host yet: ${describeRef(parsed)}`);\n }\n\n // An incomplete checkout must not retain a marker from an earlier attempt:\n // otherwise a retry could mistake a failed dependency install for success.\n if (alreadyCloned) rmSync(markerPath, { force: true });\n\n if (!alreadyCloned) {\n // A leftover directory without .git means a previous attempt died partway.\n if (existsSync(cloneDir)) rmSync(cloneDir, { recursive: true, force: true });\n ensureDirExists(cloneDir);\n git(cloneDir, [\"init\", \"-q\"]);\n git(cloneDir, [\"remote\", \"add\", \"origin\", parsed.url]);\n } else {\n // Reconcile: drop anything a previous checkout left behind so the new ref\n // lands on a clean tree.\n git(cloneDir, [\"remote\", \"set-url\", \"origin\", parsed.url]);\n git(cloneDir, [\"reset\", \"--hard\", \"-q\"]);\n git(cloneDir, [\"clean\", \"-qfd\"]);\n }\n\n // One fetch shape for every kind of ref — tag, branch, or commit sha — and\n // `HEAD` for \"whatever the remote's default branch is now\".\n try {\n git(cloneDir, [\"fetch\", \"--depth\", \"1\", \"origin\", requestedRef]);\n } catch (err) {\n if (!alreadyCloned) rmSync(cloneDir, { recursive: true, force: true });\n throw new Error(`Could not fetch ${describeRef(parsed)}: ${gitErrorText(err)}`, { cause: err });\n }\n git(cloneDir, [\"checkout\", \"-q\", \"--detach\", \"FETCH_HEAD\"]);\n\n const dir = resolveSubpath(cloneDir, parsed);\n installDependencies(dir);\n // This is the completion marker, not merely a fetched-ref marker. Write it\n // last so a failed npm install is retried by the next materialization.\n writeFileSync(markerPath, `${requestedRef}\\n`);\n return dir;\n}\n\n/**\n * Before keyed checkout paths existed, every ref used the legacy repo path.\n * Copy a matching complete checkout on first use of its keyed path so offline\n * loads keep working. Markerless legacy checkouts are accepted only when git\n * can prove the requested ref is the checked-out commit; a different or\n * unprovable pinned ref is rebuilt by fetch/refresh instead.\n */\nfunction migrateLegacyCheckout(\n url: string,\n scopeDir: string,\n cloneDir: string,\n requestedRef: string,\n): void {\n const legacyDir = gitCloneDir(url, scopeDir);\n if (cloneDir === legacyDir || existsSync(cloneDir)) return;\n const legacyMarker = join(legacyDir, \".git\", MATERIALIZED_REF_FILE);\n if (!existsSync(join(legacyDir, \".git\"))) return;\n const recordedRef = readTextFileIfExists(legacyMarker)?.trim();\n if (recordedRef !== requestedRef) {\n if (recordedRef !== undefined || !markerlessCheckoutMatchesRef(legacyDir, requestedRef)) {\n return;\n }\n }\n\n ensureDirExists(dirname(cloneDir));\n cpSync(legacyDir, cloneDir, { recursive: true });\n}\n\n/**\n * Legacy checkouts have no completion marker. Accept them offline only when\n * the checkout is clean and the local git metadata identifies the requested\n * commit/ref; never infer a pinned ref from HEAD alone.\n */\nfunction markerlessCheckoutMatchesRef(cloneDir: string, requestedRef: string): boolean {\n let head: string;\n try {\n head = git(cloneDir, [\"rev-parse\", \"--verify\", \"HEAD\"]).trim();\n if (!head || git(cloneDir, [\"status\", \"--porcelain\", \"--untracked-files=no\"]).trim()) {\n return false;\n }\n } catch {\n return false;\n }\n\n if (requestedRef === \"HEAD\") return true;\n\n try {\n if (git(cloneDir, [\"rev-parse\", \"--verify\", `${requestedRef}^{commit}`]).trim() === head) {\n return true;\n }\n } catch {\n // A shallow legacy fetch may retain only FETCH_HEAD, not a local ref.\n }\n\n try {\n if (git(cloneDir, [\"symbolic-ref\", \"--quiet\", \"--short\", \"HEAD\"]).trim() === requestedRef) {\n return true;\n }\n } catch {\n // Detached checkouts do not have a symbolic branch.\n }\n\n const fetchHead = readTextFileIfExists(join(cloneDir, \".git\", \"FETCH_HEAD\"));\n if (!fetchHead) return false;\n return fetchHead.split(\"\\n\").some((line) => {\n const match = /^(\\w+)\\s+.*(?:branch|tag) '([^']+)'/.exec(line);\n return match?.[1] === head && match[2] === requestedRef;\n });\n}\n\nfunction resolveSubpath(cloneDir: string, parsed: Extract<ParsedSource, { type: \"git\" }>): string {\n if (!parsed.subpath) return cloneDir;\n const dir = join(cloneDir, parsed.subpath);\n if (!existsSync(dir)) {\n throw new Error(`Subpath not found in repository: ${parsed.subpath}`);\n }\n // A symlink inside the repository must not select files outside the clone:\n // the returned directory is imported (extensions) or mounted, so follow\n // links before deciding the subpath stayed inside.\n const relation = relative(realpathSync(cloneDir), realpathSync(dir));\n if (isAbsolute(relation) || relation === \"..\" || relation.startsWith(`..${sep}`)) {\n throw new Error(`Subpath escapes repository: ${parsed.subpath}`);\n }\n return dir;\n}\n\n/**\n * Install runtime dependencies when the package declares any. This runs npm\n * on the host against code that was just fetched from a remote, which is the\n * same trust level as importing the package itself — but it is worth being\n * explicit that it happens, because it also runs the dependencies' install\n * scripts.\n */\nfunction installDependencies(dir: string): void {\n if (!hasDependencies(dir)) return;\n log.logInfo(`Installing package dependencies in ${dir}`);\n try {\n execFileSync(\"npm\", [\"install\", \"--omit=dev\", \"--no-audit\", \"--no-fund\"], {\n cwd: dir,\n timeout: NPM_TIMEOUT_MS,\n encoding: \"utf-8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n } catch (err) {\n throw new Error(`npm install failed for the package: ${gitErrorText(err)}`, { cause: err });\n }\n}\n\nfunction hasDependencies(dir: string): boolean {\n const raw = readTextFileIfExists(join(dir, \"package.json\"));\n if (raw === undefined) return false;\n try {\n const pkg = JSON.parse(raw) as { dependencies?: Record<string, string> };\n return Boolean(pkg.dependencies && Object.keys(pkg.dependencies).length > 0);\n } catch {\n return false;\n }\n}\n\nfunction git(cwd: string, args: string[]): string {\n return execFileSync(\"git\", args, {\n cwd,\n timeout: GIT_TIMEOUT_MS,\n encoding: \"utf-8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n env: {\n ...process.env,\n // Never block a portal save on an interactive credential prompt.\n GIT_TERMINAL_PROMPT: \"0\",\n GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND ?? \"ssh -o BatchMode=yes -o ConnectTimeout=10\",\n },\n });\n}\n\nfunction describeRef(parsed: Extract<ParsedSource, { type: \"git\" }>): string {\n return parsed.ref ? `${parsed.url} at ${parsed.ref}` : parsed.url;\n}\n\n/** Prefer git's stderr over the generic \"Command failed\" wrapper. */\nfunction gitErrorText(err: unknown): string {\n if (err && typeof err === \"object\" && \"stderr\" in err) {\n const stderr = (err as { stderr?: unknown }).stderr;\n const text = typeof stderr === \"string\" ? stderr.trim() : \"\";\n if (text) return text.split(\"\\n\").slice(-3).join(\" \");\n }\n return err instanceof Error ? err.message : String(err);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ResolvePackagesOptions, ResolvedPackages } from "./types.js";
|
|
2
|
+
export type { ResolvePackagesOptions, ResolvedPackages } from "./types.js";
|
|
3
|
+
/** Runtime path a package's skills directory is mounted at. */
|
|
4
|
+
export declare function packageSkillRuntimeDir(slug: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Read-only mounts exposing every resolved package's skills to the sandbox.
|
|
7
|
+
*
|
|
8
|
+
* Read-only rather than read-write because the host owns these files: the
|
|
9
|
+
* directory is a git checkout that an update replaces wholesale, so an agent
|
|
10
|
+
* edit would be silently discarded on the next refresh. Making the filesystem
|
|
11
|
+
* refuse the write turns a confusing data-loss bug into an obvious error.
|
|
12
|
+
*
|
|
13
|
+
* Resolution is offline, so building the mount list never reaches the network.
|
|
14
|
+
*/
|
|
15
|
+
export declare function conversationPackageSkillMounts(options: ResolvePackagesOptions): Array<{
|
|
16
|
+
source: string;
|
|
17
|
+
target: string;
|
|
18
|
+
readOnly: true;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the package set for one conversation. Reads both scopes' settings,
|
|
22
|
+
* dedups, and reports the directories to load from.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveConversationPackages(options: ResolvePackagesOptions): ResolvedPackages;
|
|
25
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/packages/resolve.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAKV,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAwB3E,+DAA+D;AAC/D,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,GAC9B,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAC,CAM3D;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,CAkC7F"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a conversation actually loads: the two scopes' declared packages
|
|
3
|
+
* combined, collisions resolved, and each surviving package turned into the
|
|
4
|
+
* directories the extension loader and the skill loader consume.
|
|
5
|
+
*
|
|
6
|
+
* Two rules do all the work here:
|
|
7
|
+
*
|
|
8
|
+
* - **Additive scopes.** `global` packages load for every conversation; a
|
|
9
|
+
* conversation's packages load on top. Neither list replaces the other.
|
|
10
|
+
* - **Narrower scope wins.** When both scopes declare the same package
|
|
11
|
+
* ({@link sourceIdentity}, which ignores the ref), only the conversation's
|
|
12
|
+
* copy loads. That is what makes "pin this one channel to v2 while everyone
|
|
13
|
+
* else stays on v1" work, and it is why the same package installed twice
|
|
14
|
+
* cannot activate twice.
|
|
15
|
+
*
|
|
16
|
+
* Resolution never throws. A conversation with one malformed or unfetchable
|
|
17
|
+
* source still loads every other package, and the failure is reported through
|
|
18
|
+
* {@link ResolvedPackages.errors} for the portal and the logs. The alternative
|
|
19
|
+
* — one bad string in settings taking a conversation offline — is a far worse
|
|
20
|
+
* failure mode than a missing feature.
|
|
21
|
+
*/
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import { existsSync, statSync } from "node:fs";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import { loadGlobalSettings, resolveConversationSettings } from "../config.js";
|
|
26
|
+
import * as log from "../log.js";
|
|
27
|
+
import { materializeSource, packageScopeDir } from "./materialize.js";
|
|
28
|
+
import { parseSource, sourceIdentity } from "./source.js";
|
|
29
|
+
/** Conventional resource directories inside a package, mirroring pi's layout. */
|
|
30
|
+
const EXTENSIONS_SUBDIR = "extensions";
|
|
31
|
+
const SKILLS_SUBDIR = "skills";
|
|
32
|
+
/** Slug length cap; long identities keep a digest tail instead of colliding. */
|
|
33
|
+
const SLUG_MAX_LENGTH = 96;
|
|
34
|
+
/**
|
|
35
|
+
* Where package resources appear inside the sandbox.
|
|
36
|
+
*
|
|
37
|
+
* Deliberately OUTSIDE `/workspace`. In `full` workspace-mount mode
|
|
38
|
+
* `/workspace` is the entire working directory, so a `/workspace/packages`
|
|
39
|
+
* mount would shadow a real `packages/` directory in the user's tree — mikan's
|
|
40
|
+
* own repository has one. Living outside also keeps
|
|
41
|
+
* `translateMountedRuntimePathToHost` correct by construction: it maps only
|
|
42
|
+
* the `/workspace` prefix and returns everything else untouched, so a package
|
|
43
|
+
* path can never be mistranslated into a host path that does not exist.
|
|
44
|
+
*
|
|
45
|
+
* Skills are referenced by absolute path in the system prompt, so the location
|
|
46
|
+
* costs nothing in usability.
|
|
47
|
+
*/
|
|
48
|
+
const PACKAGE_RUNTIME_ROOT = "/mikan/packages";
|
|
49
|
+
/** Runtime path a package's skills directory is mounted at. */
|
|
50
|
+
export function packageSkillRuntimeDir(slug) {
|
|
51
|
+
return `${PACKAGE_RUNTIME_ROOT}/${slug}/${SKILLS_SUBDIR}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Read-only mounts exposing every resolved package's skills to the sandbox.
|
|
55
|
+
*
|
|
56
|
+
* Read-only rather than read-write because the host owns these files: the
|
|
57
|
+
* directory is a git checkout that an update replaces wholesale, so an agent
|
|
58
|
+
* edit would be silently discarded on the next refresh. Making the filesystem
|
|
59
|
+
* refuse the write turns a confusing data-loss bug into an obvious error.
|
|
60
|
+
*
|
|
61
|
+
* Resolution is offline, so building the mount list never reaches the network.
|
|
62
|
+
*/
|
|
63
|
+
export function conversationPackageSkillMounts(options) {
|
|
64
|
+
return resolveConversationPackages(options).skillDirs.map(({ slug, dir }) => ({
|
|
65
|
+
source: dir,
|
|
66
|
+
target: packageSkillRuntimeDir(slug),
|
|
67
|
+
readOnly: true,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve the package set for one conversation. Reads both scopes' settings,
|
|
72
|
+
* dedups, and reports the directories to load from.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveConversationPackages(options) {
|
|
75
|
+
const declarations = [...readScope("global", options), ...readScope("conversation", options)];
|
|
76
|
+
const errors = [];
|
|
77
|
+
const byIdentity = new Map();
|
|
78
|
+
for (const declaration of declarations) {
|
|
79
|
+
let identity;
|
|
80
|
+
try {
|
|
81
|
+
identity = sourceIdentity(parseSource(declaration.source));
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
errors.push({ source: declaration.source, message: messageOf(err) });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// Later scopes overwrite earlier ones: global is read first, so a
|
|
88
|
+
// conversation declaring the same package shadows it.
|
|
89
|
+
const existing = byIdentity.get(identity);
|
|
90
|
+
if (existing && existing.scope !== declaration.scope) {
|
|
91
|
+
log.logInfo(`Package ${identity} declared in both scopes; using the conversation's copy`);
|
|
92
|
+
}
|
|
93
|
+
const materialized = materialize(declaration, options, errors);
|
|
94
|
+
if (materialized)
|
|
95
|
+
byIdentity.set(identity, materialized);
|
|
96
|
+
else
|
|
97
|
+
byIdentity.delete(identity);
|
|
98
|
+
}
|
|
99
|
+
const packages = [...byIdentity.values()].toSorted(scopeOrder);
|
|
100
|
+
const targets = packages.map(packageExtensionTargets);
|
|
101
|
+
return {
|
|
102
|
+
packages,
|
|
103
|
+
extensionDirs: [...scopeConventionDirs(options), ...targets.flatMap((target) => target.dirs)],
|
|
104
|
+
extensionRoots: targets.flatMap((target) => target.roots),
|
|
105
|
+
skillDirs: packages.flatMap(packageSkillDir),
|
|
106
|
+
errors,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function readScope(scope, options) {
|
|
110
|
+
try {
|
|
111
|
+
const sources = scope === "global"
|
|
112
|
+
? loadGlobalSettings().packages
|
|
113
|
+
: resolveConversationSettings(options.office).packages;
|
|
114
|
+
return (sources ?? []).map((source) => ({ source, scope }));
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
// Unreadable settings must not take the conversation down; the other
|
|
118
|
+
// scope, and the convention directories, still load.
|
|
119
|
+
log.logWarning(`Could not read ${scope} package list`, messageOf(err));
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function materialize(declaration, options, errors) {
|
|
124
|
+
try {
|
|
125
|
+
return materializeSource(declaration.source, {
|
|
126
|
+
scope: declaration.scope,
|
|
127
|
+
address: options.office.address,
|
|
128
|
+
stateDir: options.office.workspace.stateDir,
|
|
129
|
+
mode: options.fetchMissing ? "fetch" : "offline",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
errors.push({ source: declaration.source, message: messageOf(err) });
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The convention directories that need no declaration:
|
|
139
|
+
* `<stateDir>/global/extensions` and
|
|
140
|
+
* `<stateDir>/conversations/<id>/extensions`. These are the directories
|
|
141
|
+
* `mikan ext install` writes into, so CLI installs and portal-declared
|
|
142
|
+
* packages coexist.
|
|
143
|
+
*/
|
|
144
|
+
function scopeConventionDirs(options) {
|
|
145
|
+
return [
|
|
146
|
+
join(packageScopeDir("global", undefined, options.office.workspace.stateDir), EXTENSIONS_SUBDIR),
|
|
147
|
+
join(options.office.stateDir, EXTENSIONS_SUBDIR),
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* How a package contributes extensions. Two shapes are accepted, and which one
|
|
152
|
+
* applies is decided by the package's own layout rather than by configuration:
|
|
153
|
+
*
|
|
154
|
+
* - **Collection**: an `extensions/` subdirectory, scanned for named children.
|
|
155
|
+
* This is the shape a repository shipping several extensions has.
|
|
156
|
+
* - **Single extension**: no `extensions/` subdirectory, but the package root
|
|
157
|
+
* is itself a loadable extension (an index file, or a `package.json` with
|
|
158
|
+
* `mikan.extensions`). This is what a one-extension repo looks like, and it
|
|
159
|
+
* is what a developer's working copy looks like — so `mikan ext dev` needs
|
|
160
|
+
* no special case.
|
|
161
|
+
*
|
|
162
|
+
* The slug comes from the package directory name in the single-extension
|
|
163
|
+
* shape, so a repo named for its extension gets the identity its author
|
|
164
|
+
* expects.
|
|
165
|
+
*/
|
|
166
|
+
function packageExtensionTargets(pkg) {
|
|
167
|
+
const collection = join(pkg.dir, EXTENSIONS_SUBDIR);
|
|
168
|
+
if (existsSync(collection))
|
|
169
|
+
return { dirs: [collection], roots: [] };
|
|
170
|
+
return { dirs: [], roots: [pkg.dir] };
|
|
171
|
+
}
|
|
172
|
+
function packageSkillDir(pkg) {
|
|
173
|
+
const dir = join(pkg.dir, SKILLS_SUBDIR);
|
|
174
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory())
|
|
175
|
+
return [];
|
|
176
|
+
return [{ slug: packageSlug(pkg), dir }];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Filesystem-safe, collision-resistant name for a package, used as the mount
|
|
180
|
+
* path segment for its skills. Derived from the identity rather than the
|
|
181
|
+
* source string so the same package spelled two ways gets one name.
|
|
182
|
+
*/
|
|
183
|
+
function packageSlug(pkg) {
|
|
184
|
+
const readable = pkg.identity
|
|
185
|
+
.replace(/^(git|local):/, "")
|
|
186
|
+
.toLowerCase()
|
|
187
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
188
|
+
.replace(/^-+|-+$/g, "");
|
|
189
|
+
if (readable.length <= SLUG_MAX_LENGTH)
|
|
190
|
+
return readable;
|
|
191
|
+
// Truncation alone would let two long identities sharing a prefix (deeply
|
|
192
|
+
// nested self-hosted groups, file:// paths) land on the same slug — and
|
|
193
|
+
// therefore the same mount target, where one package's skills would quietly
|
|
194
|
+
// replace the other's. The digest makes the tail collision-resistant.
|
|
195
|
+
const digest = createHash("sha256").update(pkg.identity).digest("hex").slice(0, 8);
|
|
196
|
+
return `${readable.slice(0, SLUG_MAX_LENGTH - digest.length - 1)}-${digest}`;
|
|
197
|
+
}
|
|
198
|
+
/** Global packages load before conversation ones. */
|
|
199
|
+
function scopeRank(scope) {
|
|
200
|
+
return scope === "global" ? 0 : 1;
|
|
201
|
+
}
|
|
202
|
+
function scopeOrder(a, b) {
|
|
203
|
+
return scopeRank(a.scope) - scopeRank(b.scope);
|
|
204
|
+
}
|
|
205
|
+
function messageOf(err) {
|
|
206
|
+
return err instanceof Error ? err.message : String(err);
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/packages/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAY1D,iFAAiF;AACjF,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,aAAa,GAAG,QAAQ,CAAC;AAC/B,gFAAgF;AAChF,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAE/C,+DAA+D;AAC/D,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,GAAG,oBAAoB,IAAI,IAAI,IAAI,aAAa,EAAE,CAAC;AAC5D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B;IAE/B,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE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AED,SAAS,SAAS,CAAC,GAAY;IAC7B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * What a conversation actually loads: the two scopes' declared packages\n * combined, collisions resolved, and each surviving package turned into the\n * directories the extension loader and the skill loader consume.\n *\n * Two rules do all the work here:\n *\n * - **Additive scopes.** `global` packages load for every conversation; a\n * conversation's packages load on top. Neither list replaces the other.\n * - **Narrower scope wins.** When both scopes declare the same package\n * ({@link sourceIdentity}, which ignores the ref), only the conversation's\n * copy loads. That is what makes \"pin this one channel to v2 while everyone\n * else stays on v1\" work, and it is why the same package installed twice\n * cannot activate twice.\n *\n * Resolution never throws. A conversation with one malformed or unfetchable\n * source still loads every other package, and the failure is reported through\n * {@link ResolvedPackages.errors} for the portal and the logs. The alternative\n * — one bad string in settings taking a conversation offline — is a far worse\n * failure mode than a missing feature.\n */\nimport { createHash } from \"node:crypto\";\nimport { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { loadGlobalSettings, resolveConversationSettings } from \"../config.js\";\nimport * as log from \"../log.js\";\nimport { materializeSource, packageScopeDir } from \"./materialize.js\";\nimport { parseSource, sourceIdentity } from \"./source.js\";\nimport type {\n MaterializedPackage,\n PackageError,\n PackageScope,\n PackageSkillDir,\n ResolvePackagesOptions,\n ResolvedPackages,\n} from \"./types.js\";\n\nexport type { ResolvePackagesOptions, ResolvedPackages } from \"./types.js\";\n\n/** Conventional resource directories inside a package, mirroring pi's layout. */\nconst EXTENSIONS_SUBDIR = \"extensions\";\nconst SKILLS_SUBDIR = \"skills\";\n/** Slug length cap; long identities keep a digest tail instead of colliding. */\nconst SLUG_MAX_LENGTH = 96;\n\n/**\n * Where package resources appear inside the sandbox.\n *\n * Deliberately OUTSIDE `/workspace`. In `full` workspace-mount mode\n * `/workspace` is the entire working directory, so a `/workspace/packages`\n * mount would shadow a real `packages/` directory in the user's tree — mikan's\n * own repository has one. Living outside also keeps\n * `translateMountedRuntimePathToHost` correct by construction: it maps only\n * the `/workspace` prefix and returns everything else untouched, so a package\n * path can never be mistranslated into a host path that does not exist.\n *\n * Skills are referenced by absolute path in the system prompt, so the location\n * costs nothing in usability.\n */\nconst PACKAGE_RUNTIME_ROOT = \"/mikan/packages\";\n\n/** Runtime path a package's skills directory is mounted at. */\nexport function packageSkillRuntimeDir(slug: string): string {\n return `${PACKAGE_RUNTIME_ROOT}/${slug}/${SKILLS_SUBDIR}`;\n}\n\n/**\n * Read-only mounts exposing every resolved package's skills to the sandbox.\n *\n * Read-only rather than read-write because the host owns these files: the\n * directory is a git checkout that an update replaces wholesale, so an agent\n * edit would be silently discarded on the next refresh. Making the filesystem\n * refuse the write turns a confusing data-loss bug into an obvious error.\n *\n * Resolution is offline, so building the mount list never reaches the network.\n */\nexport function conversationPackageSkillMounts(\n options: ResolvePackagesOptions,\n): Array<{ source: string; target: string; readOnly: true }> {\n return resolveConversationPackages(options).skillDirs.map(({ slug, dir }) => ({\n source: dir,\n target: packageSkillRuntimeDir(slug),\n readOnly: true,\n }));\n}\n\n/**\n * Resolve the package set for one conversation. Reads both scopes' settings,\n * dedups, and reports the directories to load from.\n */\nexport function resolveConversationPackages(options: ResolvePackagesOptions): ResolvedPackages {\n const declarations = [...readScope(\"global\", options), ...readScope(\"conversation\", options)];\n\n const errors: PackageError[] = [];\n const byIdentity = new Map<string, MaterializedPackage>();\n\n for (const declaration of declarations) {\n let identity: string;\n try {\n identity = sourceIdentity(parseSource(declaration.source));\n } catch (err) {\n errors.push({ source: declaration.source, message: messageOf(err) });\n continue;\n }\n // Later scopes overwrite earlier ones: global is read first, so a\n // conversation declaring the same package shadows it.\n const existing = byIdentity.get(identity);\n if (existing && existing.scope !== declaration.scope) {\n log.logInfo(`Package ${identity} declared in both scopes; using the conversation's copy`);\n }\n const materialized = materialize(declaration, options, errors);\n if (materialized) byIdentity.set(identity, materialized);\n else byIdentity.delete(identity);\n }\n\n const packages = [...byIdentity.values()].toSorted(scopeOrder);\n const targets = packages.map(packageExtensionTargets);\n return {\n packages,\n extensionDirs: [...scopeConventionDirs(options), ...targets.flatMap((target) => target.dirs)],\n extensionRoots: targets.flatMap((target) => target.roots),\n skillDirs: packages.flatMap(packageSkillDir),\n errors,\n };\n}\n\ninterface Declaration {\n source: string;\n scope: PackageScope;\n}\n\nfunction readScope(scope: PackageScope, options: ResolvePackagesOptions): Declaration[] {\n try {\n const sources =\n scope === \"global\"\n ? loadGlobalSettings().packages\n : resolveConversationSettings(options.office).packages;\n return (sources ?? []).map((source) => ({ source, scope }));\n } catch (err) {\n // Unreadable settings must not take the conversation down; the other\n // scope, and the convention directories, still load.\n log.logWarning(`Could not read ${scope} package list`, messageOf(err));\n return [];\n }\n}\n\nfunction materialize(\n declaration: Declaration,\n options: ResolvePackagesOptions,\n errors: PackageError[],\n): MaterializedPackage | undefined {\n try {\n return materializeSource(declaration.source, {\n scope: declaration.scope,\n address: options.office.address,\n stateDir: options.office.workspace.stateDir,\n mode: options.fetchMissing ? \"fetch\" : \"offline\",\n });\n } catch (err) {\n errors.push({ source: declaration.source, message: messageOf(err) });\n return undefined;\n }\n}\n\n/**\n * The convention directories that need no declaration:\n * `<stateDir>/global/extensions` and\n * `<stateDir>/conversations/<id>/extensions`. These are the directories\n * `mikan ext install` writes into, so CLI installs and portal-declared\n * packages coexist.\n */\nfunction scopeConventionDirs(options: ResolvePackagesOptions): string[] {\n return [\n join(\n packageScopeDir(\"global\", undefined, options.office.workspace.stateDir),\n EXTENSIONS_SUBDIR,\n ),\n join(options.office.stateDir, EXTENSIONS_SUBDIR),\n ];\n}\n\n/**\n * How a package contributes extensions. Two shapes are accepted, and which one\n * applies is decided by the package's own layout rather than by configuration:\n *\n * - **Collection**: an `extensions/` subdirectory, scanned for named children.\n * This is the shape a repository shipping several extensions has.\n * - **Single extension**: no `extensions/` subdirectory, but the package root\n * is itself a loadable extension (an index file, or a `package.json` with\n * `mikan.extensions`). This is what a one-extension repo looks like, and it\n * is what a developer's working copy looks like — so `mikan ext dev` needs\n * no special case.\n *\n * The slug comes from the package directory name in the single-extension\n * shape, so a repo named for its extension gets the identity its author\n * expects.\n */\nfunction packageExtensionTargets(pkg: MaterializedPackage): { dirs: string[]; roots: string[] } {\n const collection = join(pkg.dir, EXTENSIONS_SUBDIR);\n if (existsSync(collection)) return { dirs: [collection], roots: [] };\n return { dirs: [], roots: [pkg.dir] };\n}\n\nfunction packageSkillDir(pkg: MaterializedPackage): PackageSkillDir[] {\n const dir = join(pkg.dir, SKILLS_SUBDIR);\n if (!existsSync(dir) || !statSync(dir).isDirectory()) return [];\n return [{ slug: packageSlug(pkg), dir }];\n}\n\n/**\n * Filesystem-safe, collision-resistant name for a package, used as the mount\n * path segment for its skills. Derived from the identity rather than the\n * source string so the same package spelled two ways gets one name.\n */\nfunction packageSlug(pkg: MaterializedPackage): string {\n const readable = pkg.identity\n .replace(/^(git|local):/, \"\")\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n if (readable.length <= SLUG_MAX_LENGTH) return readable;\n // Truncation alone would let two long identities sharing a prefix (deeply\n // nested self-hosted groups, file:// paths) land on the same slug — and\n // therefore the same mount target, where one package's skills would quietly\n // replace the other's. The digest makes the tail collision-resistant.\n const digest = createHash(\"sha256\").update(pkg.identity).digest(\"hex\").slice(0, 8);\n return `${readable.slice(0, SLUG_MAX_LENGTH - digest.length - 1)}-${digest}`;\n}\n\n/** Global packages load before conversation ones. */\nfunction scopeRank(scope: PackageScope): number {\n return scope === \"global\" ? 0 : 1;\n}\n\nfunction scopeOrder(a: MaterializedPackage, b: MaterializedPackage): number {\n return scopeRank(a.scope) - scopeRank(b.scope);\n}\n\nfunction messageOf(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PackageIdentity, ParsedSource } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a source string spells a git source (vs a local path) — the one
|
|
4
|
+
* home of the prefix rule. Classification only; `parseSource` still owns
|
|
5
|
+
* validation and error messages.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isGitSourceString(source: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Parse a source string. Throws with a user-facing message rather than
|
|
10
|
+
* returning undefined: every caller (portal, settings load, CLI) needs to tell
|
|
11
|
+
* the human what was wrong with what they typed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseSource(source: string): ParsedSource;
|
|
14
|
+
/**
|
|
15
|
+
* Identity of the package a source refers to — the key for deduplication and
|
|
16
|
+
* for letting a conversation's copy shadow the global one.
|
|
17
|
+
*
|
|
18
|
+
* Deliberate choices:
|
|
19
|
+
* - The ref is excluded: the same repo pinned to two refs in two scopes is one
|
|
20
|
+
* package installed twice, and the narrower scope wins.
|
|
21
|
+
* - The subpath is included: two extensions living at different paths in one
|
|
22
|
+
* monorepo are two packages.
|
|
23
|
+
* - Transport is excluded: `git@github.com:o/r`, `https://github.com/o/r.git`
|
|
24
|
+
* and `ssh://git@github.com/o/r` all identify the same package, so mixing
|
|
25
|
+
* SSH and HTTPS spellings across scopes still dedups.
|
|
26
|
+
*/
|
|
27
|
+
export declare function sourceIdentity(parsed: ParsedSource): PackageIdentity;
|
|
28
|
+
/**
|
|
29
|
+
* Transport-independent `<host>/<path>` of a git URL, lowercased host, no
|
|
30
|
+
* `.git` suffix, no credentials. It is the base of the on-disk clone layout,
|
|
31
|
+
* so it must stay free of anything that is not a safe path segment.
|
|
32
|
+
*/
|
|
33
|
+
export declare function gitRepoPath(url: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Canonical string form, used when writing settings so the stored value is
|
|
36
|
+
* stable regardless of how the human spelled it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatSource(parsed: ParsedSource): string;
|
|
39
|
+
//# sourceMappingURL=source.d.ts.map
|